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"
39 #include "intervals.h"
41 #include "blockinput.h"
44 #include "termhooks.h"
49 #include "bitmaps/gray.xbm"
55 #define max(a, b) ((a) > (b) ? (a) : (b))
57 extern void free_frame_menubar ();
58 extern double atof ();
59 extern int w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
);
62 /* A definition of XColor for non-X frames. */
63 #ifndef HAVE_X_WINDOWS
66 unsigned short red
, green
, blue
;
72 extern char *lispy_function_keys
[];
74 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
75 it, and including `bitmaps/gray' more than once is a problem when
76 config.h defines `static' as an empty replacement string. */
78 int gray_bitmap_width
= gray_width
;
79 int gray_bitmap_height
= gray_height
;
80 unsigned char *gray_bitmap_bits
= gray_bits
;
82 /* The colormap for converting color names to RGB values */
83 Lisp_Object Vw32_color_map
;
85 /* Non nil if alt key presses are passed on to Windows. */
86 Lisp_Object Vw32_pass_alt_to_system
;
88 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
90 Lisp_Object Vw32_alt_is_meta
;
92 /* If non-zero, the windows virtual key code for an alternative quit key. */
93 Lisp_Object Vw32_quit_key
;
95 /* Non nil if left window key events are passed on to Windows (this only
96 affects whether "tapping" the key opens the Start menu). */
97 Lisp_Object Vw32_pass_lwindow_to_system
;
99 /* Non nil if right window key events are passed on to Windows (this
100 only affects whether "tapping" the key opens the Start menu). */
101 Lisp_Object Vw32_pass_rwindow_to_system
;
103 /* Virtual key code used to generate "phantom" key presses in order
104 to stop system from acting on Windows key events. */
105 Lisp_Object Vw32_phantom_key_code
;
107 /* Modifier associated with the left "Windows" key, or nil to act as a
109 Lisp_Object Vw32_lwindow_modifier
;
111 /* Modifier associated with the right "Windows" key, or nil to act as a
113 Lisp_Object Vw32_rwindow_modifier
;
115 /* Modifier associated with the "Apps" key, or nil to act as a normal
117 Lisp_Object Vw32_apps_modifier
;
119 /* Value is nil if Num Lock acts as a function key. */
120 Lisp_Object Vw32_enable_num_lock
;
122 /* Value is nil if Caps Lock acts as a function key. */
123 Lisp_Object Vw32_enable_caps_lock
;
125 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
126 Lisp_Object Vw32_scroll_lock_modifier
;
128 /* Switch to control whether we inhibit requests for synthesized bold
129 and italic versions of fonts. */
130 Lisp_Object Vw32_enable_synthesized_fonts
;
132 /* Enable palette management. */
133 Lisp_Object Vw32_enable_palette
;
135 /* Control how close left/right button down events must be to
136 be converted to a middle button down event. */
137 Lisp_Object Vw32_mouse_button_tolerance
;
139 /* Minimum interval between mouse movement (and scroll bar drag)
140 events that are passed on to the event loop. */
141 Lisp_Object Vw32_mouse_move_interval
;
143 /* The name we're using in resource queries. */
144 Lisp_Object Vx_resource_name
;
146 /* Non nil if no window manager is in use. */
147 Lisp_Object Vx_no_window_manager
;
149 /* Non-zero means we're allowed to display a hourglass pointer. */
151 int display_hourglass_p
;
153 /* The background and shape of the mouse pointer, and shape when not
154 over text or in the modeline. */
156 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
157 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
159 /* The shape when over mouse-sensitive text. */
161 Lisp_Object Vx_sensitive_text_pointer_shape
;
163 /* Color of chars displayed in cursor box. */
165 Lisp_Object Vx_cursor_fore_pixel
;
167 /* Nonzero if using Windows. */
169 static int w32_in_use
;
171 /* Search path for bitmap files. */
173 Lisp_Object Vx_bitmap_file_path
;
175 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
177 Lisp_Object Vx_pixel_size_width_font_regexp
;
179 /* Alist of bdf fonts and the files that define them. */
180 Lisp_Object Vw32_bdf_filename_alist
;
182 Lisp_Object Vw32_system_coding_system
;
184 /* A flag to control whether fonts are matched strictly or not. */
185 int w32_strict_fontnames
;
187 /* A flag to control whether we should only repaint if GetUpdateRect
188 indicates there is an update region. */
189 int w32_strict_painting
;
191 /* Associative list linking character set strings to Windows codepages. */
192 Lisp_Object Vw32_charset_info_alist
;
194 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
195 #ifndef VIETNAMESE_CHARSET
196 #define VIETNAMESE_CHARSET 163
199 Lisp_Object Qauto_raise
;
200 Lisp_Object Qauto_lower
;
202 Lisp_Object Qborder_color
;
203 Lisp_Object Qborder_width
;
205 Lisp_Object Qcursor_color
;
206 Lisp_Object Qcursor_type
;
207 Lisp_Object Qgeometry
;
208 Lisp_Object Qicon_left
;
209 Lisp_Object Qicon_top
;
210 Lisp_Object Qicon_type
;
211 Lisp_Object Qicon_name
;
212 Lisp_Object Qinternal_border_width
;
215 Lisp_Object Qmouse_color
;
217 Lisp_Object Qparent_id
;
218 Lisp_Object Qscroll_bar_width
;
219 Lisp_Object Qsuppress_icon
;
220 Lisp_Object Qundefined_color
;
221 Lisp_Object Qvertical_scroll_bars
;
222 Lisp_Object Qvisibility
;
223 Lisp_Object Qwindow_id
;
224 Lisp_Object Qx_frame_parameter
;
225 Lisp_Object Qx_resource_name
;
226 Lisp_Object Quser_position
;
227 Lisp_Object Quser_size
;
228 Lisp_Object Qscreen_gamma
;
229 Lisp_Object Qline_spacing
;
231 Lisp_Object Qcancel_timer
;
237 Lisp_Object Qcontrol
;
240 Lisp_Object Qw32_charset_ansi
;
241 Lisp_Object Qw32_charset_default
;
242 Lisp_Object Qw32_charset_symbol
;
243 Lisp_Object Qw32_charset_shiftjis
;
244 Lisp_Object Qw32_charset_hangeul
;
245 Lisp_Object Qw32_charset_gb2312
;
246 Lisp_Object Qw32_charset_chinesebig5
;
247 Lisp_Object Qw32_charset_oem
;
249 #ifndef JOHAB_CHARSET
250 #define JOHAB_CHARSET 130
253 Lisp_Object Qw32_charset_easteurope
;
254 Lisp_Object Qw32_charset_turkish
;
255 Lisp_Object Qw32_charset_baltic
;
256 Lisp_Object Qw32_charset_russian
;
257 Lisp_Object Qw32_charset_arabic
;
258 Lisp_Object Qw32_charset_greek
;
259 Lisp_Object Qw32_charset_hebrew
;
260 Lisp_Object Qw32_charset_vietnamese
;
261 Lisp_Object Qw32_charset_thai
;
262 Lisp_Object Qw32_charset_johab
;
263 Lisp_Object Qw32_charset_mac
;
266 #ifdef UNICODE_CHARSET
267 Lisp_Object Qw32_charset_unicode
;
270 extern Lisp_Object Qtop
;
271 extern Lisp_Object Qdisplay
;
272 extern Lisp_Object Qtool_bar_lines
;
274 /* State variables for emulating a three button mouse. */
279 static int button_state
= 0;
280 static W32Msg saved_mouse_button_msg
;
281 static unsigned mouse_button_timer
; /* non-zero when timer is active */
282 static W32Msg saved_mouse_move_msg
;
283 static unsigned mouse_move_timer
;
285 /* W95 mousewheel handler */
286 unsigned int msh_mousewheel
= 0;
288 #define MOUSE_BUTTON_ID 1
289 #define MOUSE_MOVE_ID 2
291 /* The below are defined in frame.c. */
293 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
294 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
, Qbuffer_predicate
, Qtitle
;
295 extern Lisp_Object Qtool_bar_lines
;
297 extern Lisp_Object Vwindow_system_version
;
299 Lisp_Object Qface_set_after_frame_default
;
302 int image_cache_refcount
, dpyinfo_refcount
;
306 /* From w32term.c. */
307 extern Lisp_Object Vw32_num_mouse_buttons
;
308 extern Lisp_Object Vw32_recognize_altgr
;
311 /* Error if we are not connected to MS-Windows. */
316 error ("MS-Windows not in use or not initialized");
319 /* Nonzero if we can use mouse menus.
320 You should not call this unless HAVE_MENUS is defined. */
328 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
329 and checking validity for W32. */
332 check_x_frame (frame
)
338 frame
= selected_frame
;
339 CHECK_LIVE_FRAME (frame
, 0);
341 if (! FRAME_W32_P (f
))
342 error ("non-w32 frame used");
346 /* Let the user specify an display with a frame.
347 nil stands for the selected frame--or, if that is not a w32 frame,
348 the first display on the list. */
350 static struct w32_display_info
*
351 check_x_display_info (frame
)
356 struct frame
*sf
= XFRAME (selected_frame
);
358 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
359 return FRAME_W32_DISPLAY_INFO (sf
);
361 return &one_w32_display_info
;
363 else if (STRINGP (frame
))
364 return x_display_info_for_name (frame
);
369 CHECK_LIVE_FRAME (frame
, 0);
371 if (! FRAME_W32_P (f
))
372 error ("non-w32 frame used");
373 return FRAME_W32_DISPLAY_INFO (f
);
377 /* Return the Emacs frame-object corresponding to an w32 window.
378 It could be the frame's main window or an icon window. */
380 /* This function can be called during GC, so use GC_xxx type test macros. */
383 x_window_to_frame (dpyinfo
, wdesc
)
384 struct w32_display_info
*dpyinfo
;
387 Lisp_Object tail
, frame
;
390 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
393 if (!GC_FRAMEP (frame
))
396 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
398 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
401 /* TODO: Check tooltips when supported. */
402 if (FRAME_W32_WINDOW (f
) == wdesc
)
410 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
411 id, which is just an int that this section returns. Bitmaps are
412 reference counted so they can be shared among frames.
414 Bitmap indices are guaranteed to be > 0, so a negative number can
415 be used to indicate no bitmap.
417 If you use x_create_bitmap_from_data, then you must keep track of
418 the bitmaps yourself. That is, creating a bitmap from the same
419 data more than once will not be caught. */
422 /* Functions to access the contents of a bitmap, given an id. */
425 x_bitmap_height (f
, id
)
429 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
433 x_bitmap_width (f
, id
)
437 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
441 x_bitmap_pixmap (f
, id
)
445 return (int) FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
449 /* Allocate a new bitmap record. Returns index of new record. */
452 x_allocate_bitmap_record (f
)
455 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
458 if (dpyinfo
->bitmaps
== NULL
)
460 dpyinfo
->bitmaps_size
= 10;
462 = (struct w32_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
463 dpyinfo
->bitmaps_last
= 1;
467 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
468 return ++dpyinfo
->bitmaps_last
;
470 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
471 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
474 dpyinfo
->bitmaps_size
*= 2;
476 = (struct w32_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
477 dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
478 return ++dpyinfo
->bitmaps_last
;
481 /* Add one reference to the reference count of the bitmap with id ID. */
484 x_reference_bitmap (f
, id
)
488 ++FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
491 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
494 x_create_bitmap_from_data (f
, bits
, width
, height
)
497 unsigned int width
, height
;
499 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
503 bitmap
= CreateBitmap (width
, height
,
504 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_planes
,
505 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_cbits
,
511 id
= x_allocate_bitmap_record (f
);
512 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
513 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
514 dpyinfo
->bitmaps
[id
- 1].hinst
= NULL
;
515 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
516 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
517 dpyinfo
->bitmaps
[id
- 1].height
= height
;
518 dpyinfo
->bitmaps
[id
- 1].width
= width
;
523 /* Create bitmap from file FILE for frame F. */
526 x_create_bitmap_from_file (f
, file
)
531 #if 0 /* TODO : bitmap support */
532 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
533 unsigned int width
, height
;
535 int xhot
, yhot
, result
, id
;
541 /* Look for an existing bitmap with the same name. */
542 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
544 if (dpyinfo
->bitmaps
[id
].refcount
545 && dpyinfo
->bitmaps
[id
].file
546 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) XSTRING (file
)->data
))
548 ++dpyinfo
->bitmaps
[id
].refcount
;
553 /* Search bitmap-file-path for the file, if appropriate. */
554 fd
= openp (Vx_bitmap_file_path
, file
, "", &found
, 0);
559 filename
= (char *) XSTRING (found
)->data
;
561 hinst
= LoadLibraryEx (filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
567 result
= XReadBitmapFile (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
568 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
569 if (result
!= BitmapSuccess
)
572 id
= x_allocate_bitmap_record (f
);
573 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
574 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
575 dpyinfo
->bitmaps
[id
- 1].file
= (char *) xmalloc (XSTRING (file
)->size
+ 1);
576 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
577 dpyinfo
->bitmaps
[id
- 1].height
= height
;
578 dpyinfo
->bitmaps
[id
- 1].width
= width
;
579 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, XSTRING (file
)->data
);
585 /* Remove reference to bitmap with id number ID. */
588 x_destroy_bitmap (f
, id
)
592 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
596 --dpyinfo
->bitmaps
[id
- 1].refcount
;
597 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
600 DeleteObject (dpyinfo
->bitmaps
[id
- 1].pixmap
);
601 if (dpyinfo
->bitmaps
[id
- 1].file
)
603 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
604 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
611 /* Free all the bitmaps for the display specified by DPYINFO. */
614 x_destroy_all_bitmaps (dpyinfo
)
615 struct w32_display_info
*dpyinfo
;
618 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
619 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
621 DeleteObject (dpyinfo
->bitmaps
[i
].pixmap
);
622 if (dpyinfo
->bitmaps
[i
].file
)
623 xfree (dpyinfo
->bitmaps
[i
].file
);
625 dpyinfo
->bitmaps_last
= 0;
628 /* Connect the frame-parameter names for W32 frames
629 to the ways of passing the parameter values to the window system.
631 The name of a parameter, as a Lisp symbol,
632 has an `x-frame-parameter' property which is an integer in Lisp
633 but can be interpreted as an `enum x_frame_parm' in C. */
637 X_PARM_FOREGROUND_COLOR
,
638 X_PARM_BACKGROUND_COLOR
,
645 X_PARM_INTERNAL_BORDER_WIDTH
,
649 X_PARM_VERT_SCROLL_BAR
,
651 X_PARM_MENU_BAR_LINES
655 struct x_frame_parm_table
658 void (*setter
) P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
661 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
662 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
663 static void x_change_window_heights
P_ ((Lisp_Object
, int));
664 /* TODO: Native Input Method support; see x_create_im. */
665 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
666 static void x_set_line_spacing
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
667 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
668 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
669 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
670 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
671 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
672 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
673 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
674 void x_set_font
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
675 void x_set_border_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
676 void x_set_internal_border_width
P_ ((struct frame
*, Lisp_Object
,
678 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
679 void x_set_autoraise
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
680 void x_set_autolower
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
681 void x_set_vertical_scroll_bars
P_ ((struct frame
*, Lisp_Object
,
683 void x_set_visibility
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
684 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
685 void x_set_scroll_bar_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
686 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
687 void x_set_unsplittable
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
688 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
689 static void x_set_screen_gamma
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
691 static struct x_frame_parm_table x_frame_parms
[] =
693 "auto-raise", x_set_autoraise
,
694 "auto-lower", x_set_autolower
,
695 "background-color", x_set_background_color
,
696 "border-color", x_set_border_color
,
697 "border-width", x_set_border_width
,
698 "cursor-color", x_set_cursor_color
,
699 "cursor-type", x_set_cursor_type
,
701 "foreground-color", x_set_foreground_color
,
702 "icon-name", x_set_icon_name
,
703 "icon-type", x_set_icon_type
,
704 "internal-border-width", x_set_internal_border_width
,
705 "menu-bar-lines", x_set_menu_bar_lines
,
706 "mouse-color", x_set_mouse_color
,
707 "name", x_explicitly_set_name
,
708 "scroll-bar-width", x_set_scroll_bar_width
,
709 "title", x_set_title
,
710 "unsplittable", x_set_unsplittable
,
711 "vertical-scroll-bars", x_set_vertical_scroll_bars
,
712 "visibility", x_set_visibility
,
713 "tool-bar-lines", x_set_tool_bar_lines
,
714 "screen-gamma", x_set_screen_gamma
,
715 "line-spacing", x_set_line_spacing
718 /* Attach the `x-frame-parameter' properties to
719 the Lisp symbol names of parameters relevant to W32. */
722 init_x_parm_symbols ()
726 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
727 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
731 /* Change the parameters of frame F as specified by ALIST.
732 If a parameter is not specially recognized, do nothing;
733 otherwise call the `x_set_...' function for that parameter. */
736 x_set_frame_parameters (f
, alist
)
742 /* If both of these parameters are present, it's more efficient to
743 set them both at once. So we wait until we've looked at the
744 entire list before we set them. */
748 Lisp_Object left
, top
;
750 /* Same with these. */
751 Lisp_Object icon_left
, icon_top
;
753 /* Record in these vectors all the parms specified. */
757 int left_no_change
= 0, top_no_change
= 0;
758 int icon_left_no_change
= 0, icon_top_no_change
= 0;
760 struct gcpro gcpro1
, gcpro2
;
763 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
766 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
767 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
769 /* Extract parm names and values into those vectors. */
772 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
777 parms
[i
] = Fcar (elt
);
778 values
[i
] = Fcdr (elt
);
781 /* TAIL and ALIST are not used again below here. */
784 GCPRO2 (*parms
, *values
);
788 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
789 because their values appear in VALUES and strings are not valid. */
790 top
= left
= Qunbound
;
791 icon_left
= icon_top
= Qunbound
;
793 /* Provide default values for HEIGHT and WIDTH. */
794 if (FRAME_NEW_WIDTH (f
))
795 width
= FRAME_NEW_WIDTH (f
);
797 width
= FRAME_WIDTH (f
);
799 if (FRAME_NEW_HEIGHT (f
))
800 height
= FRAME_NEW_HEIGHT (f
);
802 height
= FRAME_HEIGHT (f
);
804 /* Process foreground_color and background_color before anything else.
805 They are independent of other properties, but other properties (e.g.,
806 cursor_color) are dependent upon them. */
807 for (p
= 0; p
< i
; p
++)
809 Lisp_Object prop
, val
;
813 if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
815 register Lisp_Object param_index
, old_value
;
817 param_index
= Fget (prop
, Qx_frame_parameter
);
818 old_value
= get_frame_param (f
, prop
);
819 store_frame_param (f
, prop
, val
);
820 if (NATNUMP (param_index
)
821 && (XFASTINT (param_index
)
822 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
823 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
827 /* Now process them in reverse of specified order. */
828 for (i
--; i
>= 0; i
--)
830 Lisp_Object prop
, val
;
835 if (EQ (prop
, Qwidth
) && NUMBERP (val
))
836 width
= XFASTINT (val
);
837 else if (EQ (prop
, Qheight
) && NUMBERP (val
))
838 height
= XFASTINT (val
);
839 else if (EQ (prop
, Qtop
))
841 else if (EQ (prop
, Qleft
))
843 else if (EQ (prop
, Qicon_top
))
845 else if (EQ (prop
, Qicon_left
))
847 else if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
848 /* Processed above. */
852 register Lisp_Object param_index
, old_value
;
854 param_index
= Fget (prop
, Qx_frame_parameter
);
855 old_value
= get_frame_param (f
, prop
);
856 store_frame_param (f
, prop
, val
);
857 if (NATNUMP (param_index
)
858 && (XFASTINT (param_index
)
859 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
860 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
864 /* Don't die if just one of these was set. */
865 if (EQ (left
, Qunbound
))
868 if (f
->output_data
.w32
->left_pos
< 0)
869 left
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->left_pos
), Qnil
));
871 XSETINT (left
, f
->output_data
.w32
->left_pos
);
873 if (EQ (top
, Qunbound
))
876 if (f
->output_data
.w32
->top_pos
< 0)
877 top
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->top_pos
), Qnil
));
879 XSETINT (top
, f
->output_data
.w32
->top_pos
);
882 /* If one of the icon positions was not set, preserve or default it. */
883 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
885 icon_left_no_change
= 1;
886 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
887 if (NILP (icon_left
))
888 XSETINT (icon_left
, 0);
890 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
892 icon_top_no_change
= 1;
893 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
895 XSETINT (icon_top
, 0);
898 /* Don't set these parameters unless they've been explicitly
899 specified. The window might be mapped or resized while we're in
900 this function, and we don't want to override that unless the lisp
901 code has asked for it.
903 Don't set these parameters unless they actually differ from the
904 window's current parameters; the window may not actually exist
909 check_frame_size (f
, &height
, &width
);
911 XSETFRAME (frame
, f
);
913 if (width
!= FRAME_WIDTH (f
)
914 || height
!= FRAME_HEIGHT (f
)
915 || FRAME_NEW_HEIGHT (f
) || FRAME_NEW_WIDTH (f
))
916 Fset_frame_size (frame
, make_number (width
), make_number (height
));
918 if ((!NILP (left
) || !NILP (top
))
919 && ! (left_no_change
&& top_no_change
)
920 && ! (NUMBERP (left
) && XINT (left
) == f
->output_data
.w32
->left_pos
921 && NUMBERP (top
) && XINT (top
) == f
->output_data
.w32
->top_pos
))
926 /* Record the signs. */
927 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
928 if (EQ (left
, Qminus
))
929 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
930 else if (INTEGERP (left
))
932 leftpos
= XINT (left
);
934 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
936 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
937 && CONSP (XCDR (left
))
938 && INTEGERP (XCAR (XCDR (left
))))
940 leftpos
= - XINT (XCAR (XCDR (left
)));
941 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
943 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
944 && CONSP (XCDR (left
))
945 && INTEGERP (XCAR (XCDR (left
))))
947 leftpos
= XINT (XCAR (XCDR (left
)));
950 if (EQ (top
, Qminus
))
951 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
952 else if (INTEGERP (top
))
956 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
958 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
959 && CONSP (XCDR (top
))
960 && INTEGERP (XCAR (XCDR (top
))))
962 toppos
= - XINT (XCAR (XCDR (top
)));
963 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
965 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
966 && CONSP (XCDR (top
))
967 && INTEGERP (XCAR (XCDR (top
))))
969 toppos
= XINT (XCAR (XCDR (top
)));
973 /* Store the numeric value of the position. */
974 f
->output_data
.w32
->top_pos
= toppos
;
975 f
->output_data
.w32
->left_pos
= leftpos
;
977 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
979 /* Actually set that position, and convert to absolute. */
980 x_set_offset (f
, leftpos
, toppos
, -1);
983 if ((!NILP (icon_left
) || !NILP (icon_top
))
984 && ! (icon_left_no_change
&& icon_top_no_change
))
985 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
991 /* Store the screen positions of frame F into XPTR and YPTR.
992 These are the positions of the containing window manager window,
993 not Emacs's own window. */
996 x_real_positions (f
, xptr
, yptr
)
1005 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
1006 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
1012 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
1018 /* Insert a description of internally-recorded parameters of frame X
1019 into the parameter alist *ALISTPTR that is to be given to the user.
1020 Only parameters that are specific to W32
1021 and whose values are not correctly recorded in the frame's
1022 param_alist need to be considered here. */
1025 x_report_frame_params (f
, alistptr
)
1027 Lisp_Object
*alistptr
;
1032 /* Represent negative positions (off the top or left screen edge)
1033 in a way that Fmodify_frame_parameters will understand correctly. */
1034 XSETINT (tem
, f
->output_data
.w32
->left_pos
);
1035 if (f
->output_data
.w32
->left_pos
>= 0)
1036 store_in_alist (alistptr
, Qleft
, tem
);
1038 store_in_alist (alistptr
, Qleft
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1040 XSETINT (tem
, f
->output_data
.w32
->top_pos
);
1041 if (f
->output_data
.w32
->top_pos
>= 0)
1042 store_in_alist (alistptr
, Qtop
, tem
);
1044 store_in_alist (alistptr
, Qtop
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1046 store_in_alist (alistptr
, Qborder_width
,
1047 make_number (f
->output_data
.w32
->border_width
));
1048 store_in_alist (alistptr
, Qinternal_border_width
,
1049 make_number (f
->output_data
.w32
->internal_border_width
));
1050 sprintf (buf
, "%ld", (long) FRAME_W32_WINDOW (f
));
1051 store_in_alist (alistptr
, Qwindow_id
,
1052 build_string (buf
));
1053 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
1054 FRAME_SAMPLE_VISIBILITY (f
);
1055 store_in_alist (alistptr
, Qvisibility
,
1056 (FRAME_VISIBLE_P (f
) ? Qt
1057 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
1058 store_in_alist (alistptr
, Qdisplay
,
1059 XCAR (FRAME_W32_DISPLAY_INFO (f
)->name_list_element
));
1063 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
, Sw32_define_rgb_color
, 4, 4, 0,
1064 "Convert RGB numbers to a windows color reference and associate with NAME (a string).\n\
1065 This adds or updates a named color to w32-color-map, making it available for use.\n\
1066 The original entry's RGB ref is returned, or nil if the entry is new.")
1067 (red
, green
, blue
, name
)
1068 Lisp_Object red
, green
, blue
, name
;
1071 Lisp_Object oldrgb
= Qnil
;
1074 CHECK_NUMBER (red
, 0);
1075 CHECK_NUMBER (green
, 0);
1076 CHECK_NUMBER (blue
, 0);
1077 CHECK_STRING (name
, 0);
1079 XSET (rgb
, Lisp_Int
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
1083 /* replace existing entry in w32-color-map or add new entry. */
1084 entry
= Fassoc (name
, Vw32_color_map
);
1087 entry
= Fcons (name
, rgb
);
1088 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
1092 oldrgb
= Fcdr (entry
);
1093 Fsetcdr (entry
, rgb
);
1101 DEFUN ("w32-load-color-file", Fw32_load_color_file
, Sw32_load_color_file
, 1, 1, 0,
1102 "Create an alist of color entries from an external file (ie. rgb.txt).\n\
1103 Assign this value to w32-color-map to replace the existing color map.\n\
1105 The file should define one named RGB color per line like so:\
1107 where R,G,B are numbers between 0 and 255 and name is an arbitrary string.")
1109 Lisp_Object filename
;
1112 Lisp_Object cmap
= Qnil
;
1113 Lisp_Object abspath
;
1115 CHECK_STRING (filename
, 0);
1116 abspath
= Fexpand_file_name (filename
, Qnil
);
1118 fp
= fopen (XSTRING (filename
)->data
, "rt");
1122 int red
, green
, blue
;
1127 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
1128 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
1130 char *name
= buf
+ num
;
1131 num
= strlen (name
) - 1;
1132 if (name
[num
] == '\n')
1134 cmap
= Fcons (Fcons (build_string (name
),
1135 make_number (RGB (red
, green
, blue
))),
1147 /* The default colors for the w32 color map */
1148 typedef struct colormap_t
1154 colormap_t w32_color_map
[] =
1156 {"snow" , PALETTERGB (255,250,250)},
1157 {"ghost white" , PALETTERGB (248,248,255)},
1158 {"GhostWhite" , PALETTERGB (248,248,255)},
1159 {"white smoke" , PALETTERGB (245,245,245)},
1160 {"WhiteSmoke" , PALETTERGB (245,245,245)},
1161 {"gainsboro" , PALETTERGB (220,220,220)},
1162 {"floral white" , PALETTERGB (255,250,240)},
1163 {"FloralWhite" , PALETTERGB (255,250,240)},
1164 {"old lace" , PALETTERGB (253,245,230)},
1165 {"OldLace" , PALETTERGB (253,245,230)},
1166 {"linen" , PALETTERGB (250,240,230)},
1167 {"antique white" , PALETTERGB (250,235,215)},
1168 {"AntiqueWhite" , PALETTERGB (250,235,215)},
1169 {"papaya whip" , PALETTERGB (255,239,213)},
1170 {"PapayaWhip" , PALETTERGB (255,239,213)},
1171 {"blanched almond" , PALETTERGB (255,235,205)},
1172 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
1173 {"bisque" , PALETTERGB (255,228,196)},
1174 {"peach puff" , PALETTERGB (255,218,185)},
1175 {"PeachPuff" , PALETTERGB (255,218,185)},
1176 {"navajo white" , PALETTERGB (255,222,173)},
1177 {"NavajoWhite" , PALETTERGB (255,222,173)},
1178 {"moccasin" , PALETTERGB (255,228,181)},
1179 {"cornsilk" , PALETTERGB (255,248,220)},
1180 {"ivory" , PALETTERGB (255,255,240)},
1181 {"lemon chiffon" , PALETTERGB (255,250,205)},
1182 {"LemonChiffon" , PALETTERGB (255,250,205)},
1183 {"seashell" , PALETTERGB (255,245,238)},
1184 {"honeydew" , PALETTERGB (240,255,240)},
1185 {"mint cream" , PALETTERGB (245,255,250)},
1186 {"MintCream" , PALETTERGB (245,255,250)},
1187 {"azure" , PALETTERGB (240,255,255)},
1188 {"alice blue" , PALETTERGB (240,248,255)},
1189 {"AliceBlue" , PALETTERGB (240,248,255)},
1190 {"lavender" , PALETTERGB (230,230,250)},
1191 {"lavender blush" , PALETTERGB (255,240,245)},
1192 {"LavenderBlush" , PALETTERGB (255,240,245)},
1193 {"misty rose" , PALETTERGB (255,228,225)},
1194 {"MistyRose" , PALETTERGB (255,228,225)},
1195 {"white" , PALETTERGB (255,255,255)},
1196 {"black" , PALETTERGB ( 0, 0, 0)},
1197 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
1198 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
1199 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
1200 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
1201 {"dim gray" , PALETTERGB (105,105,105)},
1202 {"DimGray" , PALETTERGB (105,105,105)},
1203 {"dim grey" , PALETTERGB (105,105,105)},
1204 {"DimGrey" , PALETTERGB (105,105,105)},
1205 {"slate gray" , PALETTERGB (112,128,144)},
1206 {"SlateGray" , PALETTERGB (112,128,144)},
1207 {"slate grey" , PALETTERGB (112,128,144)},
1208 {"SlateGrey" , PALETTERGB (112,128,144)},
1209 {"light slate gray" , PALETTERGB (119,136,153)},
1210 {"LightSlateGray" , PALETTERGB (119,136,153)},
1211 {"light slate grey" , PALETTERGB (119,136,153)},
1212 {"LightSlateGrey" , PALETTERGB (119,136,153)},
1213 {"gray" , PALETTERGB (190,190,190)},
1214 {"grey" , PALETTERGB (190,190,190)},
1215 {"light grey" , PALETTERGB (211,211,211)},
1216 {"LightGrey" , PALETTERGB (211,211,211)},
1217 {"light gray" , PALETTERGB (211,211,211)},
1218 {"LightGray" , PALETTERGB (211,211,211)},
1219 {"midnight blue" , PALETTERGB ( 25, 25,112)},
1220 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
1221 {"navy" , PALETTERGB ( 0, 0,128)},
1222 {"navy blue" , PALETTERGB ( 0, 0,128)},
1223 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
1224 {"cornflower blue" , PALETTERGB (100,149,237)},
1225 {"CornflowerBlue" , PALETTERGB (100,149,237)},
1226 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
1227 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
1228 {"slate blue" , PALETTERGB (106, 90,205)},
1229 {"SlateBlue" , PALETTERGB (106, 90,205)},
1230 {"medium slate blue" , PALETTERGB (123,104,238)},
1231 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
1232 {"light slate blue" , PALETTERGB (132,112,255)},
1233 {"LightSlateBlue" , PALETTERGB (132,112,255)},
1234 {"medium blue" , PALETTERGB ( 0, 0,205)},
1235 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
1236 {"royal blue" , PALETTERGB ( 65,105,225)},
1237 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
1238 {"blue" , PALETTERGB ( 0, 0,255)},
1239 {"dodger blue" , PALETTERGB ( 30,144,255)},
1240 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
1241 {"deep sky blue" , PALETTERGB ( 0,191,255)},
1242 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
1243 {"sky blue" , PALETTERGB (135,206,235)},
1244 {"SkyBlue" , PALETTERGB (135,206,235)},
1245 {"light sky blue" , PALETTERGB (135,206,250)},
1246 {"LightSkyBlue" , PALETTERGB (135,206,250)},
1247 {"steel blue" , PALETTERGB ( 70,130,180)},
1248 {"SteelBlue" , PALETTERGB ( 70,130,180)},
1249 {"light steel blue" , PALETTERGB (176,196,222)},
1250 {"LightSteelBlue" , PALETTERGB (176,196,222)},
1251 {"light blue" , PALETTERGB (173,216,230)},
1252 {"LightBlue" , PALETTERGB (173,216,230)},
1253 {"powder blue" , PALETTERGB (176,224,230)},
1254 {"PowderBlue" , PALETTERGB (176,224,230)},
1255 {"pale turquoise" , PALETTERGB (175,238,238)},
1256 {"PaleTurquoise" , PALETTERGB (175,238,238)},
1257 {"dark turquoise" , PALETTERGB ( 0,206,209)},
1258 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
1259 {"medium turquoise" , PALETTERGB ( 72,209,204)},
1260 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
1261 {"turquoise" , PALETTERGB ( 64,224,208)},
1262 {"cyan" , PALETTERGB ( 0,255,255)},
1263 {"light cyan" , PALETTERGB (224,255,255)},
1264 {"LightCyan" , PALETTERGB (224,255,255)},
1265 {"cadet blue" , PALETTERGB ( 95,158,160)},
1266 {"CadetBlue" , PALETTERGB ( 95,158,160)},
1267 {"medium aquamarine" , PALETTERGB (102,205,170)},
1268 {"MediumAquamarine" , PALETTERGB (102,205,170)},
1269 {"aquamarine" , PALETTERGB (127,255,212)},
1270 {"dark green" , PALETTERGB ( 0,100, 0)},
1271 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
1272 {"dark olive green" , PALETTERGB ( 85,107, 47)},
1273 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
1274 {"dark sea green" , PALETTERGB (143,188,143)},
1275 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
1276 {"sea green" , PALETTERGB ( 46,139, 87)},
1277 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
1278 {"medium sea green" , PALETTERGB ( 60,179,113)},
1279 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
1280 {"light sea green" , PALETTERGB ( 32,178,170)},
1281 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
1282 {"pale green" , PALETTERGB (152,251,152)},
1283 {"PaleGreen" , PALETTERGB (152,251,152)},
1284 {"spring green" , PALETTERGB ( 0,255,127)},
1285 {"SpringGreen" , PALETTERGB ( 0,255,127)},
1286 {"lawn green" , PALETTERGB (124,252, 0)},
1287 {"LawnGreen" , PALETTERGB (124,252, 0)},
1288 {"green" , PALETTERGB ( 0,255, 0)},
1289 {"chartreuse" , PALETTERGB (127,255, 0)},
1290 {"medium spring green" , PALETTERGB ( 0,250,154)},
1291 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
1292 {"green yellow" , PALETTERGB (173,255, 47)},
1293 {"GreenYellow" , PALETTERGB (173,255, 47)},
1294 {"lime green" , PALETTERGB ( 50,205, 50)},
1295 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
1296 {"yellow green" , PALETTERGB (154,205, 50)},
1297 {"YellowGreen" , PALETTERGB (154,205, 50)},
1298 {"forest green" , PALETTERGB ( 34,139, 34)},
1299 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
1300 {"olive drab" , PALETTERGB (107,142, 35)},
1301 {"OliveDrab" , PALETTERGB (107,142, 35)},
1302 {"dark khaki" , PALETTERGB (189,183,107)},
1303 {"DarkKhaki" , PALETTERGB (189,183,107)},
1304 {"khaki" , PALETTERGB (240,230,140)},
1305 {"pale goldenrod" , PALETTERGB (238,232,170)},
1306 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
1307 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
1308 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
1309 {"light yellow" , PALETTERGB (255,255,224)},
1310 {"LightYellow" , PALETTERGB (255,255,224)},
1311 {"yellow" , PALETTERGB (255,255, 0)},
1312 {"gold" , PALETTERGB (255,215, 0)},
1313 {"light goldenrod" , PALETTERGB (238,221,130)},
1314 {"LightGoldenrod" , PALETTERGB (238,221,130)},
1315 {"goldenrod" , PALETTERGB (218,165, 32)},
1316 {"dark goldenrod" , PALETTERGB (184,134, 11)},
1317 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
1318 {"rosy brown" , PALETTERGB (188,143,143)},
1319 {"RosyBrown" , PALETTERGB (188,143,143)},
1320 {"indian red" , PALETTERGB (205, 92, 92)},
1321 {"IndianRed" , PALETTERGB (205, 92, 92)},
1322 {"saddle brown" , PALETTERGB (139, 69, 19)},
1323 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
1324 {"sienna" , PALETTERGB (160, 82, 45)},
1325 {"peru" , PALETTERGB (205,133, 63)},
1326 {"burlywood" , PALETTERGB (222,184,135)},
1327 {"beige" , PALETTERGB (245,245,220)},
1328 {"wheat" , PALETTERGB (245,222,179)},
1329 {"sandy brown" , PALETTERGB (244,164, 96)},
1330 {"SandyBrown" , PALETTERGB (244,164, 96)},
1331 {"tan" , PALETTERGB (210,180,140)},
1332 {"chocolate" , PALETTERGB (210,105, 30)},
1333 {"firebrick" , PALETTERGB (178,34, 34)},
1334 {"brown" , PALETTERGB (165,42, 42)},
1335 {"dark salmon" , PALETTERGB (233,150,122)},
1336 {"DarkSalmon" , PALETTERGB (233,150,122)},
1337 {"salmon" , PALETTERGB (250,128,114)},
1338 {"light salmon" , PALETTERGB (255,160,122)},
1339 {"LightSalmon" , PALETTERGB (255,160,122)},
1340 {"orange" , PALETTERGB (255,165, 0)},
1341 {"dark orange" , PALETTERGB (255,140, 0)},
1342 {"DarkOrange" , PALETTERGB (255,140, 0)},
1343 {"coral" , PALETTERGB (255,127, 80)},
1344 {"light coral" , PALETTERGB (240,128,128)},
1345 {"LightCoral" , PALETTERGB (240,128,128)},
1346 {"tomato" , PALETTERGB (255, 99, 71)},
1347 {"orange red" , PALETTERGB (255, 69, 0)},
1348 {"OrangeRed" , PALETTERGB (255, 69, 0)},
1349 {"red" , PALETTERGB (255, 0, 0)},
1350 {"hot pink" , PALETTERGB (255,105,180)},
1351 {"HotPink" , PALETTERGB (255,105,180)},
1352 {"deep pink" , PALETTERGB (255, 20,147)},
1353 {"DeepPink" , PALETTERGB (255, 20,147)},
1354 {"pink" , PALETTERGB (255,192,203)},
1355 {"light pink" , PALETTERGB (255,182,193)},
1356 {"LightPink" , PALETTERGB (255,182,193)},
1357 {"pale violet red" , PALETTERGB (219,112,147)},
1358 {"PaleVioletRed" , PALETTERGB (219,112,147)},
1359 {"maroon" , PALETTERGB (176, 48, 96)},
1360 {"medium violet red" , PALETTERGB (199, 21,133)},
1361 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
1362 {"violet red" , PALETTERGB (208, 32,144)},
1363 {"VioletRed" , PALETTERGB (208, 32,144)},
1364 {"magenta" , PALETTERGB (255, 0,255)},
1365 {"violet" , PALETTERGB (238,130,238)},
1366 {"plum" , PALETTERGB (221,160,221)},
1367 {"orchid" , PALETTERGB (218,112,214)},
1368 {"medium orchid" , PALETTERGB (186, 85,211)},
1369 {"MediumOrchid" , PALETTERGB (186, 85,211)},
1370 {"dark orchid" , PALETTERGB (153, 50,204)},
1371 {"DarkOrchid" , PALETTERGB (153, 50,204)},
1372 {"dark violet" , PALETTERGB (148, 0,211)},
1373 {"DarkViolet" , PALETTERGB (148, 0,211)},
1374 {"blue violet" , PALETTERGB (138, 43,226)},
1375 {"BlueViolet" , PALETTERGB (138, 43,226)},
1376 {"purple" , PALETTERGB (160, 32,240)},
1377 {"medium purple" , PALETTERGB (147,112,219)},
1378 {"MediumPurple" , PALETTERGB (147,112,219)},
1379 {"thistle" , PALETTERGB (216,191,216)},
1380 {"gray0" , PALETTERGB ( 0, 0, 0)},
1381 {"grey0" , PALETTERGB ( 0, 0, 0)},
1382 {"dark grey" , PALETTERGB (169,169,169)},
1383 {"DarkGrey" , PALETTERGB (169,169,169)},
1384 {"dark gray" , PALETTERGB (169,169,169)},
1385 {"DarkGray" , PALETTERGB (169,169,169)},
1386 {"dark blue" , PALETTERGB ( 0, 0,139)},
1387 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
1388 {"dark cyan" , PALETTERGB ( 0,139,139)},
1389 {"DarkCyan" , PALETTERGB ( 0,139,139)},
1390 {"dark magenta" , PALETTERGB (139, 0,139)},
1391 {"DarkMagenta" , PALETTERGB (139, 0,139)},
1392 {"dark red" , PALETTERGB (139, 0, 0)},
1393 {"DarkRed" , PALETTERGB (139, 0, 0)},
1394 {"light green" , PALETTERGB (144,238,144)},
1395 {"LightGreen" , PALETTERGB (144,238,144)},
1398 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
1399 0, 0, 0, "Return the default color map.")
1403 colormap_t
*pc
= w32_color_map
;
1410 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
1412 cmap
= Fcons (Fcons (build_string (pc
->name
),
1413 make_number (pc
->colorref
)),
1422 w32_to_x_color (rgb
)
1427 CHECK_NUMBER (rgb
, 0);
1431 color
= Frassq (rgb
, Vw32_color_map
);
1436 return (Fcar (color
));
1442 w32_color_map_lookup (colorname
)
1445 Lisp_Object tail
, ret
= Qnil
;
1449 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
1451 register Lisp_Object elt
, tem
;
1454 if (!CONSP (elt
)) continue;
1458 if (lstrcmpi (XSTRING (tem
)->data
, colorname
) == 0)
1460 ret
= XUINT (Fcdr (elt
));
1474 x_to_w32_color (colorname
)
1477 register Lisp_Object ret
= Qnil
;
1481 if (colorname
[0] == '#')
1483 /* Could be an old-style RGB Device specification. */
1486 color
= colorname
+ 1;
1488 size
= strlen(color
);
1489 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
1497 for (i
= 0; i
< 3; i
++)
1501 unsigned long value
;
1503 /* The check for 'x' in the following conditional takes into
1504 account the fact that strtol allows a "0x" in front of
1505 our numbers, and we don't. */
1506 if (!isxdigit(color
[0]) || color
[1] == 'x')
1510 value
= strtoul(color
, &end
, 16);
1512 if (errno
== ERANGE
|| end
- color
!= size
)
1517 value
= value
* 0x10;
1528 colorval
|= (value
<< pos
);
1539 else if (strnicmp(colorname
, "rgb:", 4) == 0)
1547 color
= colorname
+ 4;
1548 for (i
= 0; i
< 3; i
++)
1551 unsigned long value
;
1553 /* The check for 'x' in the following conditional takes into
1554 account the fact that strtol allows a "0x" in front of
1555 our numbers, and we don't. */
1556 if (!isxdigit(color
[0]) || color
[1] == 'x')
1558 value
= strtoul(color
, &end
, 16);
1559 if (errno
== ERANGE
)
1561 switch (end
- color
)
1564 value
= value
* 0x10 + value
;
1577 if (value
== ULONG_MAX
)
1579 colorval
|= (value
<< pos
);
1593 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1595 /* This is an RGB Intensity specification. */
1602 color
= colorname
+ 5;
1603 for (i
= 0; i
< 3; i
++)
1609 value
= strtod(color
, &end
);
1610 if (errno
== ERANGE
)
1612 if (value
< 0.0 || value
> 1.0)
1614 val
= (UINT
)(0x100 * value
);
1615 /* We used 0x100 instead of 0xFF to give an continuous
1616 range between 0.0 and 1.0 inclusive. The next statement
1617 fixes the 1.0 case. */
1620 colorval
|= (val
<< pos
);
1634 /* I am not going to attempt to handle any of the CIE color schemes
1635 or TekHVC, since I don't know the algorithms for conversion to
1638 /* If we fail to lookup the color name in w32_color_map, then check the
1639 colorname to see if it can be crudely approximated: If the X color
1640 ends in a number (e.g., "darkseagreen2"), strip the number and
1641 return the result of looking up the base color name. */
1642 ret
= w32_color_map_lookup (colorname
);
1645 int len
= strlen (colorname
);
1647 if (isdigit (colorname
[len
- 1]))
1649 char *ptr
, *approx
= alloca (len
);
1651 strcpy (approx
, colorname
);
1652 ptr
= &approx
[len
- 1];
1653 while (ptr
> approx
&& isdigit (*ptr
))
1656 ret
= w32_color_map_lookup (approx
);
1666 w32_regenerate_palette (FRAME_PTR f
)
1668 struct w32_palette_entry
* list
;
1669 LOGPALETTE
* log_palette
;
1670 HPALETTE new_palette
;
1673 /* don't bother trying to create palette if not supported */
1674 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1677 log_palette
= (LOGPALETTE
*)
1678 alloca (sizeof (LOGPALETTE
) +
1679 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1680 log_palette
->palVersion
= 0x300;
1681 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1683 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1685 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1686 i
++, list
= list
->next
)
1687 log_palette
->palPalEntry
[i
] = list
->entry
;
1689 new_palette
= CreatePalette (log_palette
);
1693 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1694 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1695 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1697 /* Realize display palette and garbage all frames. */
1698 release_frame_dc (f
, get_frame_dc (f
));
1703 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1704 #define SET_W32_COLOR(pe, color) \
1707 pe.peRed = GetRValue (color); \
1708 pe.peGreen = GetGValue (color); \
1709 pe.peBlue = GetBValue (color); \
1714 /* Keep these around in case we ever want to track color usage. */
1716 w32_map_color (FRAME_PTR f
, COLORREF color
)
1718 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1720 if (NILP (Vw32_enable_palette
))
1723 /* check if color is already mapped */
1726 if (W32_COLOR (list
->entry
) == color
)
1734 /* not already mapped, so add to list and recreate Windows palette */
1735 list
= (struct w32_palette_entry
*)
1736 xmalloc (sizeof (struct w32_palette_entry
));
1737 SET_W32_COLOR (list
->entry
, color
);
1739 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1740 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1741 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1743 /* set flag that palette must be regenerated */
1744 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1748 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1750 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1751 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1753 if (NILP (Vw32_enable_palette
))
1756 /* check if color is already mapped */
1759 if (W32_COLOR (list
->entry
) == color
)
1761 if (--list
->refcount
== 0)
1765 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1775 /* set flag that palette must be regenerated */
1776 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1781 /* Gamma-correct COLOR on frame F. */
1784 gamma_correct (f
, color
)
1790 *color
= PALETTERGB (
1791 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1792 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1793 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1798 /* Decide if color named COLOR is valid for the display associated with
1799 the selected frame; if so, return the rgb values in COLOR_DEF.
1800 If ALLOC is nonzero, allocate a new colormap cell. */
1803 w32_defined_color (f
, color
, color_def
, alloc
)
1809 register Lisp_Object tem
;
1810 COLORREF w32_color_ref
;
1812 tem
= x_to_w32_color (color
);
1818 /* Apply gamma correction. */
1819 w32_color_ref
= XUINT (tem
);
1820 gamma_correct (f
, &w32_color_ref
);
1821 XSETINT (tem
, w32_color_ref
);
1824 /* Map this color to the palette if it is enabled. */
1825 if (!NILP (Vw32_enable_palette
))
1827 struct w32_palette_entry
* entry
=
1828 one_w32_display_info
.color_list
;
1829 struct w32_palette_entry
** prev
=
1830 &one_w32_display_info
.color_list
;
1832 /* check if color is already mapped */
1835 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1837 prev
= &entry
->next
;
1838 entry
= entry
->next
;
1841 if (entry
== NULL
&& alloc
)
1843 /* not already mapped, so add to list */
1844 entry
= (struct w32_palette_entry
*)
1845 xmalloc (sizeof (struct w32_palette_entry
));
1846 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1849 one_w32_display_info
.num_colors
++;
1851 /* set flag that palette must be regenerated */
1852 one_w32_display_info
.regen_palette
= TRUE
;
1855 /* Ensure COLORREF value is snapped to nearest color in (default)
1856 palette by simulating the PALETTERGB macro. This works whether
1857 or not the display device has a palette. */
1858 w32_color_ref
= XUINT (tem
) | 0x2000000;
1860 color_def
->pixel
= w32_color_ref
;
1861 color_def
->red
= GetRValue (w32_color_ref
);
1862 color_def
->green
= GetGValue (w32_color_ref
);
1863 color_def
->blue
= GetBValue (w32_color_ref
);
1873 /* Given a string ARG naming a color, compute a pixel value from it
1874 suitable for screen F.
1875 If F is not a color screen, return DEF (default) regardless of what
1879 x_decode_color (f
, arg
, def
)
1886 CHECK_STRING (arg
, 0);
1888 if (strcmp (XSTRING (arg
)->data
, "black") == 0)
1889 return BLACK_PIX_DEFAULT (f
);
1890 else if (strcmp (XSTRING (arg
)->data
, "white") == 0)
1891 return WHITE_PIX_DEFAULT (f
);
1893 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1896 /* w32_defined_color is responsible for coping with failures
1897 by looking for a near-miss. */
1898 if (w32_defined_color (f
, XSTRING (arg
)->data
, &cdef
, 1))
1901 /* defined_color failed; return an ultimate default. */
1905 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
1906 the previous value of that parameter, NEW_VALUE is the new value. */
1909 x_set_line_spacing (f
, new_value
, old_value
)
1911 Lisp_Object new_value
, old_value
;
1913 if (NILP (new_value
))
1914 f
->extra_line_spacing
= 0;
1915 else if (NATNUMP (new_value
))
1916 f
->extra_line_spacing
= XFASTINT (new_value
);
1918 Fsignal (Qerror
, Fcons (build_string ("Invalid line-spacing"),
1919 Fcons (new_value
, Qnil
)));
1920 if (FRAME_VISIBLE_P (f
))
1925 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
1926 the previous value of that parameter, NEW_VALUE is the new value. */
1929 x_set_screen_gamma (f
, new_value
, old_value
)
1931 Lisp_Object new_value
, old_value
;
1933 if (NILP (new_value
))
1935 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
1936 /* The value 0.4545 is the normal viewing gamma. */
1937 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
1939 Fsignal (Qerror
, Fcons (build_string ("Invalid screen-gamma"),
1940 Fcons (new_value
, Qnil
)));
1942 clear_face_cache (0);
1946 /* Functions called only from `x_set_frame_param'
1947 to set individual parameters.
1949 If FRAME_W32_WINDOW (f) is 0,
1950 the frame is being created and its window does not exist yet.
1951 In that case, just record the parameter's new value
1952 in the standard place; do not attempt to change the window. */
1955 x_set_foreground_color (f
, arg
, oldval
)
1957 Lisp_Object arg
, oldval
;
1959 FRAME_FOREGROUND_PIXEL (f
)
1960 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1962 if (FRAME_W32_WINDOW (f
) != 0)
1964 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1965 if (FRAME_VISIBLE_P (f
))
1971 x_set_background_color (f
, arg
, oldval
)
1973 Lisp_Object arg
, oldval
;
1975 FRAME_BACKGROUND_PIXEL (f
)
1976 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1978 if (FRAME_W32_WINDOW (f
) != 0)
1980 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1981 FRAME_BACKGROUND_PIXEL (f
));
1983 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1985 if (FRAME_VISIBLE_P (f
))
1991 x_set_mouse_color (f
, arg
, oldval
)
1993 Lisp_Object arg
, oldval
;
1995 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
1999 if (!EQ (Qnil
, arg
))
2000 f
->output_data
.w32
->mouse_pixel
2001 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2002 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
2004 /* Don't let pointers be invisible. */
2005 if (mask_color
== f
->output_data
.w32
->mouse_pixel
2006 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
2007 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
2009 #if 0 /* TODO : cursor changes */
2012 /* It's not okay to crash if the user selects a screwy cursor. */
2013 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
2015 if (!EQ (Qnil
, Vx_pointer_shape
))
2017 CHECK_NUMBER (Vx_pointer_shape
, 0);
2018 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
2021 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2022 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
2024 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
2026 CHECK_NUMBER (Vx_nontext_pointer_shape
, 0);
2027 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2028 XINT (Vx_nontext_pointer_shape
));
2031 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
2032 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2034 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
2036 CHECK_NUMBER (Vx_hourglass_pointer_shape
, 0);
2037 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2038 XINT (Vx_hourglass_pointer_shape
));
2041 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
2042 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
2044 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2045 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
2047 CHECK_NUMBER (Vx_mode_pointer_shape
, 0);
2048 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2049 XINT (Vx_mode_pointer_shape
));
2052 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2053 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
2055 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
2057 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
, 0);
2059 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2060 XINT (Vx_sensitive_text_pointer_shape
));
2063 cross_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
2065 if (!NILP (Vx_window_horizontal_drag_shape
))
2067 CHECK_NUMBER (Vx_window_horizontal_drag_shape
, 0);
2068 horizontal_drag_cursor
2069 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
2070 XINT (Vx_window_horizontal_drag_shape
));
2073 horizontal_drag_cursor
2074 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
2076 /* Check and report errors with the above calls. */
2077 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
2078 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
2081 XColor fore_color
, back_color
;
2083 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
2084 back_color
.pixel
= mask_color
;
2085 XQueryColor (FRAME_W32_DISPLAY (f
),
2086 DefaultColormap (FRAME_W32_DISPLAY (f
),
2087 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2089 XQueryColor (FRAME_W32_DISPLAY (f
),
2090 DefaultColormap (FRAME_W32_DISPLAY (f
),
2091 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2093 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
2094 &fore_color
, &back_color
);
2095 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
2096 &fore_color
, &back_color
);
2097 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
2098 &fore_color
, &back_color
);
2099 XRecolorCursor (FRAME_W32_DISPLAY (f
), cross_cursor
,
2100 &fore_color
, &back_color
);
2101 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
2102 &fore_color
, &back_color
);
2105 if (FRAME_W32_WINDOW (f
) != 0)
2106 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
2108 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
2109 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
2110 f
->output_data
.w32
->text_cursor
= cursor
;
2112 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
2113 && f
->output_data
.w32
->nontext_cursor
!= 0)
2114 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
2115 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
2117 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
2118 && f
->output_data
.w32
->hourglass_cursor
!= 0)
2119 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
2120 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
2122 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
2123 && f
->output_data
.w32
->modeline_cursor
!= 0)
2124 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
2125 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
2127 if (cross_cursor
!= f
->output_data
.w32
->cross_cursor
2128 && f
->output_data
.w32
->cross_cursor
!= 0)
2129 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->cross_cursor
);
2130 f
->output_data
.w32
->cross_cursor
= cross_cursor
;
2132 XFlush (FRAME_W32_DISPLAY (f
));
2135 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
2139 /* Defined in w32term.c. */
2140 void x_update_cursor (struct frame
*f
, int on_p
);
2143 x_set_cursor_color (f
, arg
, oldval
)
2145 Lisp_Object arg
, oldval
;
2147 unsigned long fore_pixel
, pixel
;
2149 if (!NILP (Vx_cursor_fore_pixel
))
2150 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
2151 WHITE_PIX_DEFAULT (f
));
2153 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2155 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2157 /* Make sure that the cursor color differs from the background color. */
2158 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
2160 pixel
= f
->output_data
.w32
->mouse_pixel
;
2161 if (pixel
== fore_pixel
)
2162 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2165 FRAME_FOREGROUND_PIXEL (f
) = fore_pixel
;
2166 f
->output_data
.w32
->cursor_pixel
= pixel
;
2168 if (FRAME_W32_WINDOW (f
) != 0)
2170 if (FRAME_VISIBLE_P (f
))
2172 x_update_cursor (f
, 0);
2173 x_update_cursor (f
, 1);
2177 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
2180 /* Set the border-color of frame F to pixel value PIX.
2181 Note that this does not fully take effect if done before
2184 x_set_border_pixel (f
, pix
)
2188 f
->output_data
.w32
->border_pixel
= pix
;
2190 if (FRAME_W32_WINDOW (f
) != 0 && f
->output_data
.w32
->border_width
> 0)
2192 if (FRAME_VISIBLE_P (f
))
2197 /* Set the border-color of frame F to value described by ARG.
2198 ARG can be a string naming a color.
2199 The border-color is used for the border that is drawn by the server.
2200 Note that this does not fully take effect if done before
2201 F has a window; it must be redone when the window is created. */
2204 x_set_border_color (f
, arg
, oldval
)
2206 Lisp_Object arg
, oldval
;
2210 CHECK_STRING (arg
, 0);
2211 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2212 x_set_border_pixel (f
, pix
);
2213 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
2216 /* Value is the internal representation of the specified cursor type
2217 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
2218 of the bar cursor. */
2220 enum text_cursor_kinds
2221 x_specified_cursor_type (arg
, width
)
2225 enum text_cursor_kinds type
;
2232 else if (CONSP (arg
)
2233 && EQ (XCAR (arg
), Qbar
)
2234 && INTEGERP (XCDR (arg
))
2235 && XINT (XCDR (arg
)) >= 0)
2238 *width
= XINT (XCDR (arg
));
2240 else if (NILP (arg
))
2243 /* Treat anything unknown as "box cursor".
2244 It was bad to signal an error; people have trouble fixing
2245 .Xdefaults with Emacs, when it has something bad in it. */
2246 type
= FILLED_BOX_CURSOR
;
2252 x_set_cursor_type (f
, arg
, oldval
)
2254 Lisp_Object arg
, oldval
;
2258 FRAME_DESIRED_CURSOR (f
) = x_specified_cursor_type (arg
, &width
);
2259 f
->output_data
.w32
->cursor_width
= width
;
2261 /* Make sure the cursor gets redrawn. This is overkill, but how
2262 often do people change cursor types? */
2263 update_mode_lines
++;
2267 x_set_icon_type (f
, arg
, oldval
)
2269 Lisp_Object arg
, oldval
;
2273 if (NILP (arg
) && NILP (oldval
))
2276 if (STRINGP (arg
) && STRINGP (oldval
)
2277 && EQ (Fstring_equal (oldval
, arg
), Qt
))
2280 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
2285 result
= x_bitmap_icon (f
, arg
);
2289 error ("No icon window available");
2295 /* Return non-nil if frame F wants a bitmap icon. */
2303 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
2311 x_set_icon_name (f
, arg
, oldval
)
2313 Lisp_Object arg
, oldval
;
2317 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
2320 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
2326 if (f
->output_data
.w32
->icon_bitmap
!= 0)
2331 result
= x_text_icon (f
,
2332 (char *) XSTRING ((!NILP (f
->icon_name
)
2341 error ("No icon window available");
2344 /* If the window was unmapped (and its icon was mapped),
2345 the new icon is not mapped, so map the window in its stead. */
2346 if (FRAME_VISIBLE_P (f
))
2348 #ifdef USE_X_TOOLKIT
2349 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
2351 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
2354 XFlush (FRAME_W32_DISPLAY (f
));
2359 extern Lisp_Object
x_new_font ();
2360 extern Lisp_Object
x_new_fontset();
2363 x_set_font (f
, arg
, oldval
)
2365 Lisp_Object arg
, oldval
;
2368 Lisp_Object fontset_name
;
2371 CHECK_STRING (arg
, 1);
2373 fontset_name
= Fquery_fontset (arg
, Qnil
);
2376 result
= (STRINGP (fontset_name
)
2377 ? x_new_fontset (f
, XSTRING (fontset_name
)->data
)
2378 : x_new_font (f
, XSTRING (arg
)->data
));
2381 if (EQ (result
, Qnil
))
2382 error ("Font `%s' is not defined", XSTRING (arg
)->data
);
2383 else if (EQ (result
, Qt
))
2384 error ("The characters of the given font have varying widths");
2385 else if (STRINGP (result
))
2387 if (!NILP (Fequal (result
, oldval
)))
2389 store_frame_param (f
, Qfont
, result
);
2390 recompute_basic_faces (f
);
2395 do_pending_window_change (0);
2397 /* Don't call `face-set-after-frame-default' when faces haven't been
2398 initialized yet. This is the case when called from
2399 Fx_create_frame. In that case, the X widget or window doesn't
2400 exist either, and we can end up in x_report_frame_params with a
2401 null widget which gives a segfault. */
2402 if (FRAME_FACE_CACHE (f
))
2404 XSETFRAME (frame
, f
);
2405 call1 (Qface_set_after_frame_default
, frame
);
2410 x_set_border_width (f
, arg
, oldval
)
2412 Lisp_Object arg
, oldval
;
2414 CHECK_NUMBER (arg
, 0);
2416 if (XINT (arg
) == f
->output_data
.w32
->border_width
)
2419 if (FRAME_W32_WINDOW (f
) != 0)
2420 error ("Cannot change the border width of a window");
2422 f
->output_data
.w32
->border_width
= XINT (arg
);
2426 x_set_internal_border_width (f
, arg
, oldval
)
2428 Lisp_Object arg
, oldval
;
2430 int old
= f
->output_data
.w32
->internal_border_width
;
2432 CHECK_NUMBER (arg
, 0);
2433 f
->output_data
.w32
->internal_border_width
= XINT (arg
);
2434 if (f
->output_data
.w32
->internal_border_width
< 0)
2435 f
->output_data
.w32
->internal_border_width
= 0;
2437 if (f
->output_data
.w32
->internal_border_width
== old
)
2440 if (FRAME_W32_WINDOW (f
) != 0)
2442 x_set_window_size (f
, 0, f
->width
, f
->height
);
2443 SET_FRAME_GARBAGED (f
);
2444 do_pending_window_change (0);
2449 x_set_visibility (f
, value
, oldval
)
2451 Lisp_Object value
, oldval
;
2454 XSETFRAME (frame
, f
);
2457 Fmake_frame_invisible (frame
, Qt
);
2458 else if (EQ (value
, Qicon
))
2459 Ficonify_frame (frame
);
2461 Fmake_frame_visible (frame
);
2465 /* Change window heights in windows rooted in WINDOW by N lines. */
2468 x_change_window_heights (window
, n
)
2472 struct window
*w
= XWINDOW (window
);
2474 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
2475 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
2477 if (INTEGERP (w
->orig_top
))
2478 XSETFASTINT (w
->orig_top
, XFASTINT (w
->orig_top
) + n
);
2479 if (INTEGERP (w
->orig_height
))
2480 XSETFASTINT (w
->orig_height
, XFASTINT (w
->orig_height
) - n
);
2482 /* Handle just the top child in a vertical split. */
2483 if (!NILP (w
->vchild
))
2484 x_change_window_heights (w
->vchild
, n
);
2486 /* Adjust all children in a horizontal split. */
2487 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2489 w
= XWINDOW (window
);
2490 x_change_window_heights (window
, n
);
2495 x_set_menu_bar_lines (f
, value
, oldval
)
2497 Lisp_Object value
, oldval
;
2500 int olines
= FRAME_MENU_BAR_LINES (f
);
2502 /* Right now, menu bars don't work properly in minibuf-only frames;
2503 most of the commands try to apply themselves to the minibuffer
2504 frame itself, and get an error because you can't switch buffers
2505 in or split the minibuffer window. */
2506 if (FRAME_MINIBUF_ONLY_P (f
))
2509 if (INTEGERP (value
))
2510 nlines
= XINT (value
);
2514 FRAME_MENU_BAR_LINES (f
) = 0;
2516 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2519 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2520 free_frame_menubar (f
);
2521 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2523 /* Adjust the frame size so that the client (text) dimensions
2524 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
2526 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2527 do_pending_window_change (0);
2533 /* Set the number of lines used for the tool bar of frame F to VALUE.
2534 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2535 is the old number of tool bar lines. This function changes the
2536 height of all windows on frame F to match the new tool bar height.
2537 The frame's height doesn't change. */
2540 x_set_tool_bar_lines (f
, value
, oldval
)
2542 Lisp_Object value
, oldval
;
2544 int delta
, nlines
, root_height
;
2545 Lisp_Object root_window
;
2547 /* Treat tool bars like menu bars. */
2548 if (FRAME_MINIBUF_ONLY_P (f
))
2551 /* Use VALUE only if an integer >= 0. */
2552 if (INTEGERP (value
) && XINT (value
) >= 0)
2553 nlines
= XFASTINT (value
);
2557 /* Make sure we redisplay all windows in this frame. */
2558 ++windows_or_buffers_changed
;
2560 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2562 /* Don't resize the tool-bar to more than we have room for. */
2563 root_window
= FRAME_ROOT_WINDOW (f
);
2564 root_height
= XINT (XWINDOW (root_window
)->height
);
2565 if (root_height
- delta
< 1)
2567 delta
= root_height
- 1;
2568 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
2571 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2572 x_change_window_heights (root_window
, delta
);
2575 /* We also have to make sure that the internal border at the top of
2576 the frame, below the menu bar or tool bar, is redrawn when the
2577 tool bar disappears. This is so because the internal border is
2578 below the tool bar if one is displayed, but is below the menu bar
2579 if there isn't a tool bar. The tool bar draws into the area
2580 below the menu bar. */
2581 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
2585 clear_current_matrices (f
);
2586 updating_frame
= NULL
;
2589 /* If the tool bar gets smaller, the internal border below it
2590 has to be cleared. It was formerly part of the display
2591 of the larger tool bar, and updating windows won't clear it. */
2594 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2595 int width
= PIXEL_WIDTH (f
);
2596 int y
= nlines
* CANON_Y_UNIT (f
);
2600 HDC hdc
= get_frame_dc (f
);
2601 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
2602 release_frame_dc (f
, hdc
);
2609 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2612 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2613 name; if NAME is a string, set F's name to NAME and set
2614 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2616 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2617 suggesting a new name, which lisp code should override; if
2618 F->explicit_name is set, ignore the new name; otherwise, set it. */
2621 x_set_name (f
, name
, explicit)
2626 /* Make sure that requests from lisp code override requests from
2627 Emacs redisplay code. */
2630 /* If we're switching from explicit to implicit, we had better
2631 update the mode lines and thereby update the title. */
2632 if (f
->explicit_name
&& NILP (name
))
2633 update_mode_lines
= 1;
2635 f
->explicit_name
= ! NILP (name
);
2637 else if (f
->explicit_name
)
2640 /* If NAME is nil, set the name to the w32_id_name. */
2643 /* Check for no change needed in this very common case
2644 before we do any consing. */
2645 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
2646 XSTRING (f
->name
)->data
))
2648 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
2651 CHECK_STRING (name
, 0);
2653 /* Don't change the name if it's already NAME. */
2654 if (! NILP (Fstring_equal (name
, f
->name
)))
2659 /* For setting the frame title, the title parameter should override
2660 the name parameter. */
2661 if (! NILP (f
->title
))
2664 if (FRAME_W32_WINDOW (f
))
2666 if (STRING_MULTIBYTE (name
))
2667 name
= ENCODE_SYSTEM (name
);
2670 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2675 /* This function should be called when the user's lisp code has
2676 specified a name for the frame; the name will override any set by the
2679 x_explicitly_set_name (f
, arg
, oldval
)
2681 Lisp_Object arg
, oldval
;
2683 x_set_name (f
, arg
, 1);
2686 /* This function should be called by Emacs redisplay code to set the
2687 name; names set this way will never override names set by the user's
2690 x_implicitly_set_name (f
, arg
, oldval
)
2692 Lisp_Object arg
, oldval
;
2694 x_set_name (f
, arg
, 0);
2697 /* Change the title of frame F to NAME.
2698 If NAME is nil, use the frame name as the title.
2700 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2701 name; if NAME is a string, set F's name to NAME and set
2702 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2704 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2705 suggesting a new name, which lisp code should override; if
2706 F->explicit_name is set, ignore the new name; otherwise, set it. */
2709 x_set_title (f
, name
, old_name
)
2711 Lisp_Object name
, old_name
;
2713 /* Don't change the title if it's already NAME. */
2714 if (EQ (name
, f
->title
))
2717 update_mode_lines
= 1;
2724 if (FRAME_W32_WINDOW (f
))
2726 if (STRING_MULTIBYTE (name
))
2727 name
= ENCODE_SYSTEM (name
);
2730 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2736 x_set_autoraise (f
, arg
, oldval
)
2738 Lisp_Object arg
, oldval
;
2740 f
->auto_raise
= !EQ (Qnil
, arg
);
2744 x_set_autolower (f
, arg
, oldval
)
2746 Lisp_Object arg
, oldval
;
2748 f
->auto_lower
= !EQ (Qnil
, arg
);
2752 x_set_unsplittable (f
, arg
, oldval
)
2754 Lisp_Object arg
, oldval
;
2756 f
->no_split
= !NILP (arg
);
2760 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2762 Lisp_Object arg
, oldval
;
2764 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2765 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2766 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2767 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2769 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = NILP (arg
) ?
2770 vertical_scroll_bar_none
:
2771 /* Put scroll bars on the right by default, as is conventional
2774 ? vertical_scroll_bar_left
2775 : vertical_scroll_bar_right
;
2777 /* We set this parameter before creating the window for the
2778 frame, so we can get the geometry right from the start.
2779 However, if the window hasn't been created yet, we shouldn't
2780 call x_set_window_size. */
2781 if (FRAME_W32_WINDOW (f
))
2782 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2783 do_pending_window_change (0);
2788 x_set_scroll_bar_width (f
, arg
, oldval
)
2790 Lisp_Object arg
, oldval
;
2792 int wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
2796 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2797 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) +
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);
2803 else if (INTEGERP (arg
) && XINT (arg
) > 0
2804 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2806 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2807 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2809 if (FRAME_W32_WINDOW (f
))
2810 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2811 do_pending_window_change (0);
2813 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2814 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2815 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2818 /* Subroutines of creating an frame. */
2820 /* Make sure that Vx_resource_name is set to a reasonable value.
2821 Fix it up, or set it to `emacs' if it is too hopeless. */
2824 validate_x_resource_name ()
2827 /* Number of valid characters in the resource name. */
2829 /* Number of invalid characters in the resource name. */
2834 if (STRINGP (Vx_resource_name
))
2836 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
2839 len
= STRING_BYTES (XSTRING (Vx_resource_name
));
2841 /* Only letters, digits, - and _ are valid in resource names.
2842 Count the valid characters and count the invalid ones. */
2843 for (i
= 0; i
< len
; i
++)
2846 if (! ((c
>= 'a' && c
<= 'z')
2847 || (c
>= 'A' && c
<= 'Z')
2848 || (c
>= '0' && c
<= '9')
2849 || c
== '-' || c
== '_'))
2856 /* Not a string => completely invalid. */
2857 bad_count
= 5, good_count
= 0;
2859 /* If name is valid already, return. */
2863 /* If name is entirely invalid, or nearly so, use `emacs'. */
2865 || (good_count
== 1 && bad_count
> 0))
2867 Vx_resource_name
= build_string ("emacs");
2871 /* Name is partly valid. Copy it and replace the invalid characters
2872 with underscores. */
2874 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
2876 for (i
= 0; i
< len
; i
++)
2878 int c
= XSTRING (new)->data
[i
];
2879 if (! ((c
>= 'a' && c
<= 'z')
2880 || (c
>= 'A' && c
<= 'Z')
2881 || (c
>= '0' && c
<= '9')
2882 || c
== '-' || c
== '_'))
2883 XSTRING (new)->data
[i
] = '_';
2888 extern char *x_get_string_resource ();
2890 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
2891 "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
2892 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
2893 class, where INSTANCE is the name under which Emacs was invoked, or\n\
2894 the name specified by the `-name' or `-rn' command-line arguments.\n\
2896 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
2897 class, respectively. You must specify both of them or neither.\n\
2898 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
2899 and the class is `Emacs.CLASS.SUBCLASS'.")
2900 (attribute
, class, component
, subclass
)
2901 Lisp_Object attribute
, class, component
, subclass
;
2903 register char *value
;
2907 CHECK_STRING (attribute
, 0);
2908 CHECK_STRING (class, 0);
2910 if (!NILP (component
))
2911 CHECK_STRING (component
, 1);
2912 if (!NILP (subclass
))
2913 CHECK_STRING (subclass
, 2);
2914 if (NILP (component
) != NILP (subclass
))
2915 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
2917 validate_x_resource_name ();
2919 /* Allocate space for the components, the dots which separate them,
2920 and the final '\0'. Make them big enough for the worst case. */
2921 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vx_resource_name
))
2922 + (STRINGP (component
)
2923 ? STRING_BYTES (XSTRING (component
)) : 0)
2924 + STRING_BYTES (XSTRING (attribute
))
2927 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2928 + STRING_BYTES (XSTRING (class))
2929 + (STRINGP (subclass
)
2930 ? STRING_BYTES (XSTRING (subclass
)) : 0)
2933 /* Start with emacs.FRAMENAME for the name (the specific one)
2934 and with `Emacs' for the class key (the general one). */
2935 strcpy (name_key
, XSTRING (Vx_resource_name
)->data
);
2936 strcpy (class_key
, EMACS_CLASS
);
2938 strcat (class_key
, ".");
2939 strcat (class_key
, XSTRING (class)->data
);
2941 if (!NILP (component
))
2943 strcat (class_key
, ".");
2944 strcat (class_key
, XSTRING (subclass
)->data
);
2946 strcat (name_key
, ".");
2947 strcat (name_key
, XSTRING (component
)->data
);
2950 strcat (name_key
, ".");
2951 strcat (name_key
, XSTRING (attribute
)->data
);
2953 value
= x_get_string_resource (Qnil
,
2954 name_key
, class_key
);
2956 if (value
!= (char *) 0)
2957 return build_string (value
);
2962 /* Used when C code wants a resource value. */
2965 x_get_resource_string (attribute
, class)
2966 char *attribute
, *class;
2970 struct frame
*sf
= SELECTED_FRAME ();
2972 /* Allocate space for the components, the dots which separate them,
2973 and the final '\0'. */
2974 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vinvocation_name
))
2975 + strlen (attribute
) + 2);
2976 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2977 + strlen (class) + 2);
2979 sprintf (name_key
, "%s.%s",
2980 XSTRING (Vinvocation_name
)->data
,
2982 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
2984 return x_get_string_resource (sf
, name_key
, class_key
);
2987 /* Types we might convert a resource string into. */
2997 /* Return the value of parameter PARAM.
2999 First search ALIST, then Vdefault_frame_alist, then the X defaults
3000 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3002 Convert the resource to the type specified by desired_type.
3004 If no default is specified, return Qunbound. If you call
3005 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
3006 and don't let it get stored in any Lisp-visible variables! */
3009 w32_get_arg (alist
, param
, attribute
, class, type
)
3010 Lisp_Object alist
, param
;
3013 enum resource_types type
;
3015 register Lisp_Object tem
;
3017 tem
= Fassq (param
, alist
);
3019 tem
= Fassq (param
, Vdefault_frame_alist
);
3025 tem
= Fx_get_resource (build_string (attribute
),
3026 build_string (class),
3034 case RES_TYPE_NUMBER
:
3035 return make_number (atoi (XSTRING (tem
)->data
));
3037 case RES_TYPE_FLOAT
:
3038 return make_float (atof (XSTRING (tem
)->data
));
3040 case RES_TYPE_BOOLEAN
:
3041 tem
= Fdowncase (tem
);
3042 if (!strcmp (XSTRING (tem
)->data
, "on")
3043 || !strcmp (XSTRING (tem
)->data
, "true"))
3048 case RES_TYPE_STRING
:
3051 case RES_TYPE_SYMBOL
:
3052 /* As a special case, we map the values `true' and `on'
3053 to Qt, and `false' and `off' to Qnil. */
3056 lower
= Fdowncase (tem
);
3057 if (!strcmp (XSTRING (lower
)->data
, "on")
3058 || !strcmp (XSTRING (lower
)->data
, "true"))
3060 else if (!strcmp (XSTRING (lower
)->data
, "off")
3061 || !strcmp (XSTRING (lower
)->data
, "false"))
3064 return Fintern (tem
, Qnil
);
3077 /* Record in frame F the specified or default value according to ALIST
3078 of the parameter named PROP (a Lisp symbol).
3079 If no value is specified for PROP, look for an X default for XPROP
3080 on the frame named NAME.
3081 If that is not found either, use the value DEFLT. */
3084 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3091 enum resource_types type
;
3095 tem
= w32_get_arg (alist
, prop
, xprop
, xclass
, type
);
3096 if (EQ (tem
, Qunbound
))
3098 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3102 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3103 "Parse an X-style geometry string STRING.\n\
3104 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
3105 The properties returned may include `top', `left', `height', and `width'.\n\
3106 The value of `left' or `top' may be an integer,\n\
3107 or a list (+ N) meaning N pixels relative to top/left corner,\n\
3108 or a list (- N) meaning -N pixels relative to bottom/right corner.")
3113 unsigned int width
, height
;
3116 CHECK_STRING (string
, 0);
3118 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
3119 &x
, &y
, &width
, &height
);
3122 if (geometry
& XValue
)
3124 Lisp_Object element
;
3126 if (x
>= 0 && (geometry
& XNegative
))
3127 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3128 else if (x
< 0 && ! (geometry
& XNegative
))
3129 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3131 element
= Fcons (Qleft
, make_number (x
));
3132 result
= Fcons (element
, result
);
3135 if (geometry
& YValue
)
3137 Lisp_Object element
;
3139 if (y
>= 0 && (geometry
& YNegative
))
3140 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3141 else if (y
< 0 && ! (geometry
& YNegative
))
3142 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3144 element
= Fcons (Qtop
, make_number (y
));
3145 result
= Fcons (element
, result
);
3148 if (geometry
& WidthValue
)
3149 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3150 if (geometry
& HeightValue
)
3151 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3156 /* Calculate the desired size and position of this window,
3157 and return the flags saying which aspects were specified.
3159 This function does not make the coordinates positive. */
3161 #define DEFAULT_ROWS 40
3162 #define DEFAULT_COLS 80
3165 x_figure_window_size (f
, parms
)
3169 register Lisp_Object tem0
, tem1
, tem2
;
3170 long window_prompting
= 0;
3172 /* Default values if we fall through.
3173 Actually, if that happens we should get
3174 window manager prompting. */
3175 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3176 f
->height
= DEFAULT_ROWS
;
3177 /* Window managers expect that if program-specified
3178 positions are not (0,0), they're intentional, not defaults. */
3179 f
->output_data
.w32
->top_pos
= 0;
3180 f
->output_data
.w32
->left_pos
= 0;
3182 /* Ensure that old new_width and new_height will not override the
3184 FRAME_NEW_WIDTH (f
) = 0;
3185 FRAME_NEW_HEIGHT (f
) = 0;
3187 tem0
= w32_get_arg (parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3188 tem1
= w32_get_arg (parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3189 tem2
= w32_get_arg (parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3190 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3192 if (!EQ (tem0
, Qunbound
))
3194 CHECK_NUMBER (tem0
, 0);
3195 f
->height
= XINT (tem0
);
3197 if (!EQ (tem1
, Qunbound
))
3199 CHECK_NUMBER (tem1
, 0);
3200 SET_FRAME_WIDTH (f
, XINT (tem1
));
3202 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3203 window_prompting
|= USSize
;
3205 window_prompting
|= PSize
;
3208 f
->output_data
.w32
->vertical_scroll_bar_extra
3209 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3211 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3212 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3213 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
3214 f
->output_data
.w32
->flags_areas_extra
3215 = FRAME_FLAGS_AREA_WIDTH (f
);
3216 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3217 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3219 tem0
= w32_get_arg (parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3220 tem1
= w32_get_arg (parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3221 tem2
= w32_get_arg (parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3222 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3224 if (EQ (tem0
, Qminus
))
3226 f
->output_data
.w32
->top_pos
= 0;
3227 window_prompting
|= YNegative
;
3229 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3230 && CONSP (XCDR (tem0
))
3231 && INTEGERP (XCAR (XCDR (tem0
))))
3233 f
->output_data
.w32
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3234 window_prompting
|= YNegative
;
3236 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3237 && CONSP (XCDR (tem0
))
3238 && INTEGERP (XCAR (XCDR (tem0
))))
3240 f
->output_data
.w32
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3242 else if (EQ (tem0
, Qunbound
))
3243 f
->output_data
.w32
->top_pos
= 0;
3246 CHECK_NUMBER (tem0
, 0);
3247 f
->output_data
.w32
->top_pos
= XINT (tem0
);
3248 if (f
->output_data
.w32
->top_pos
< 0)
3249 window_prompting
|= YNegative
;
3252 if (EQ (tem1
, Qminus
))
3254 f
->output_data
.w32
->left_pos
= 0;
3255 window_prompting
|= XNegative
;
3257 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3258 && CONSP (XCDR (tem1
))
3259 && INTEGERP (XCAR (XCDR (tem1
))))
3261 f
->output_data
.w32
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3262 window_prompting
|= XNegative
;
3264 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3265 && CONSP (XCDR (tem1
))
3266 && INTEGERP (XCAR (XCDR (tem1
))))
3268 f
->output_data
.w32
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3270 else if (EQ (tem1
, Qunbound
))
3271 f
->output_data
.w32
->left_pos
= 0;
3274 CHECK_NUMBER (tem1
, 0);
3275 f
->output_data
.w32
->left_pos
= XINT (tem1
);
3276 if (f
->output_data
.w32
->left_pos
< 0)
3277 window_prompting
|= XNegative
;
3280 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3281 window_prompting
|= USPosition
;
3283 window_prompting
|= PPosition
;
3286 return window_prompting
;
3291 extern LRESULT CALLBACK
w32_wnd_proc ();
3294 w32_init_class (hinst
)
3299 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3300 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
3302 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
3303 wc
.hInstance
= hinst
;
3304 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
3305 wc
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
3306 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
3307 wc
.lpszMenuName
= NULL
;
3308 wc
.lpszClassName
= EMACS_CLASS
;
3310 return (RegisterClass (&wc
));
3314 w32_createscrollbar (f
, bar
)
3316 struct scroll_bar
* bar
;
3318 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
3319 /* Position and size of scroll bar. */
3320 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3322 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3324 FRAME_W32_WINDOW (f
),
3331 w32_createwindow (f
)
3337 rect
.left
= rect
.top
= 0;
3338 rect
.right
= PIXEL_WIDTH (f
);
3339 rect
.bottom
= PIXEL_HEIGHT (f
);
3341 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3342 FRAME_EXTERNAL_MENU_BAR (f
));
3344 /* Do first time app init */
3348 w32_init_class (hinst
);
3351 FRAME_W32_WINDOW (f
) = hwnd
3352 = CreateWindow (EMACS_CLASS
,
3354 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
3355 f
->output_data
.w32
->left_pos
,
3356 f
->output_data
.w32
->top_pos
,
3357 rect
.right
- rect
.left
,
3358 rect
.bottom
- rect
.top
,
3366 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
3367 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
3368 SetWindowLong (hwnd
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
3369 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
3370 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3372 /* Enable drag-n-drop. */
3373 DragAcceptFiles (hwnd
, TRUE
);
3375 /* Do this to discard the default setting specified by our parent. */
3376 ShowWindow (hwnd
, SW_HIDE
);
3381 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
3388 wmsg
->msg
.hwnd
= hwnd
;
3389 wmsg
->msg
.message
= msg
;
3390 wmsg
->msg
.wParam
= wParam
;
3391 wmsg
->msg
.lParam
= lParam
;
3392 wmsg
->msg
.time
= GetMessageTime ();
3397 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
3398 between left and right keys as advertised. We test for this
3399 support dynamically, and set a flag when the support is absent. If
3400 absent, we keep track of the left and right control and alt keys
3401 ourselves. This is particularly necessary on keyboards that rely
3402 upon the AltGr key, which is represented as having the left control
3403 and right alt keys pressed. For these keyboards, we need to know
3404 when the left alt key has been pressed in addition to the AltGr key
3405 so that we can properly support M-AltGr-key sequences (such as M-@
3406 on Swedish keyboards). */
3408 #define EMACS_LCONTROL 0
3409 #define EMACS_RCONTROL 1
3410 #define EMACS_LMENU 2
3411 #define EMACS_RMENU 3
3413 static int modifiers
[4];
3414 static int modifiers_recorded
;
3415 static int modifier_key_support_tested
;
3418 test_modifier_support (unsigned int wparam
)
3422 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
3424 if (wparam
== VK_CONTROL
)
3434 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
3435 modifiers_recorded
= 1;
3437 modifiers_recorded
= 0;
3438 modifier_key_support_tested
= 1;
3442 record_keydown (unsigned int wparam
, unsigned int lparam
)
3446 if (!modifier_key_support_tested
)
3447 test_modifier_support (wparam
);
3449 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3452 if (wparam
== VK_CONTROL
)
3453 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3455 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3461 record_keyup (unsigned int wparam
, unsigned int lparam
)
3465 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3468 if (wparam
== VK_CONTROL
)
3469 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3471 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3476 /* Emacs can lose focus while a modifier key has been pressed. When
3477 it regains focus, be conservative and clear all modifiers since
3478 we cannot reconstruct the left and right modifier state. */
3484 if (GetFocus () == NULL
)
3485 /* Emacs doesn't have keyboard focus. Do nothing. */
3488 ctrl
= GetAsyncKeyState (VK_CONTROL
);
3489 alt
= GetAsyncKeyState (VK_MENU
);
3491 if (!(ctrl
& 0x08000))
3492 /* Clear any recorded control modifier state. */
3493 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3495 if (!(alt
& 0x08000))
3496 /* Clear any recorded alt modifier state. */
3497 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3499 /* Update the state of all modifier keys, because modifiers used in
3500 hot-key combinations can get stuck on if Emacs loses focus as a
3501 result of a hot-key being pressed. */
3505 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
3507 GetKeyboardState (keystate
);
3508 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
3509 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
3510 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
3511 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
3512 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
3513 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
3514 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
3515 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
3516 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
3517 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
3518 SetKeyboardState (keystate
);
3522 /* Synchronize modifier state with what is reported with the current
3523 keystroke. Even if we cannot distinguish between left and right
3524 modifier keys, we know that, if no modifiers are set, then neither
3525 the left or right modifier should be set. */
3529 if (!modifiers_recorded
)
3532 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
3533 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3535 if (!(GetKeyState (VK_MENU
) & 0x8000))
3536 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3540 modifier_set (int vkey
)
3542 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
3543 return (GetKeyState (vkey
) & 0x1);
3544 if (!modifiers_recorded
)
3545 return (GetKeyState (vkey
) & 0x8000);
3550 return modifiers
[EMACS_LCONTROL
];
3552 return modifiers
[EMACS_RCONTROL
];
3554 return modifiers
[EMACS_LMENU
];
3556 return modifiers
[EMACS_RMENU
];
3558 return (GetKeyState (vkey
) & 0x8000);
3561 /* Convert between the modifier bits W32 uses and the modifier bits
3565 w32_key_to_modifier (int key
)
3567 Lisp_Object key_mapping
;
3572 key_mapping
= Vw32_lwindow_modifier
;
3575 key_mapping
= Vw32_rwindow_modifier
;
3578 key_mapping
= Vw32_apps_modifier
;
3581 key_mapping
= Vw32_scroll_lock_modifier
;
3587 /* NB. This code runs in the input thread, asychronously to the lisp
3588 thread, so we must be careful to ensure access to lisp data is
3589 thread-safe. The following code is safe because the modifier
3590 variable values are updated atomically from lisp and symbols are
3591 not relocated by GC. Also, we don't have to worry about seeing GC
3593 if (EQ (key_mapping
, Qhyper
))
3594 return hyper_modifier
;
3595 if (EQ (key_mapping
, Qsuper
))
3596 return super_modifier
;
3597 if (EQ (key_mapping
, Qmeta
))
3598 return meta_modifier
;
3599 if (EQ (key_mapping
, Qalt
))
3600 return alt_modifier
;
3601 if (EQ (key_mapping
, Qctrl
))
3602 return ctrl_modifier
;
3603 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
3604 return ctrl_modifier
;
3605 if (EQ (key_mapping
, Qshift
))
3606 return shift_modifier
;
3608 /* Don't generate any modifier if not explicitly requested. */
3613 w32_get_modifiers ()
3615 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
3616 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
3617 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
3618 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
3619 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
3620 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
3621 (modifier_set (VK_MENU
) ?
3622 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
3625 /* We map the VK_* modifiers into console modifier constants
3626 so that we can use the same routines to handle both console
3627 and window input. */
3630 construct_console_modifiers ()
3635 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
3636 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
3637 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
3638 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
3639 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
3640 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
3641 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
3642 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
3643 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
3644 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
3645 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
3651 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
3655 /* Convert to emacs modifiers. */
3656 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
3662 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
3664 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
3667 if (virt_key
== VK_RETURN
)
3668 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
3670 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
3671 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
3673 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
3674 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
3676 if (virt_key
== VK_CLEAR
)
3677 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
3682 /* List of special key combinations which w32 would normally capture,
3683 but emacs should grab instead. Not directly visible to lisp, to
3684 simplify synchronization. Each item is an integer encoding a virtual
3685 key code and modifier combination to capture. */
3686 Lisp_Object w32_grabbed_keys
;
3688 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
3689 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
3690 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
3691 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
3693 /* Register hot-keys for reserved key combinations when Emacs has
3694 keyboard focus, since this is the only way Emacs can receive key
3695 combinations like Alt-Tab which are used by the system. */
3698 register_hot_keys (hwnd
)
3701 Lisp_Object keylist
;
3703 /* Use GC_CONSP, since we are called asynchronously. */
3704 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3706 Lisp_Object key
= XCAR (keylist
);
3708 /* Deleted entries get set to nil. */
3709 if (!INTEGERP (key
))
3712 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
3713 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
3718 unregister_hot_keys (hwnd
)
3721 Lisp_Object keylist
;
3723 /* Use GC_CONSP, since we are called asynchronously. */
3724 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3726 Lisp_Object key
= XCAR (keylist
);
3728 if (!INTEGERP (key
))
3731 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
3735 /* Main message dispatch loop. */
3738 w32_msg_pump (deferred_msg
* msg_buf
)
3744 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
3746 while (GetMessage (&msg
, NULL
, 0, 0))
3748 if (msg
.hwnd
== NULL
)
3750 switch (msg
.message
)
3753 /* Produced by complete_deferred_msg; just ignore. */
3755 case WM_EMACS_CREATEWINDOW
:
3756 w32_createwindow ((struct frame
*) msg
.wParam
);
3757 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3760 case WM_EMACS_SETLOCALE
:
3761 SetThreadLocale (msg
.wParam
);
3762 /* Reply is not expected. */
3764 case WM_EMACS_SETKEYBOARDLAYOUT
:
3765 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
3766 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3770 case WM_EMACS_REGISTER_HOT_KEY
:
3771 focus_window
= GetFocus ();
3772 if (focus_window
!= NULL
)
3773 RegisterHotKey (focus_window
,
3774 HOTKEY_ID (msg
.wParam
),
3775 HOTKEY_MODIFIERS (msg
.wParam
),
3776 HOTKEY_VK_CODE (msg
.wParam
));
3777 /* Reply is not expected. */
3779 case WM_EMACS_UNREGISTER_HOT_KEY
:
3780 focus_window
= GetFocus ();
3781 if (focus_window
!= NULL
)
3782 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
3783 /* Mark item as erased. NB: this code must be
3784 thread-safe. The next line is okay because the cons
3785 cell is never made into garbage and is not relocated by
3787 XCAR ((Lisp_Object
) msg
.lParam
) = Qnil
;
3788 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3791 case WM_EMACS_TOGGLE_LOCK_KEY
:
3793 int vk_code
= (int) msg
.wParam
;
3794 int cur_state
= (GetKeyState (vk_code
) & 1);
3795 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
3797 /* NB: This code must be thread-safe. It is safe to
3798 call NILP because symbols are not relocated by GC,
3799 and pointer here is not touched by GC (so the markbit
3800 can't be set). Numbers are safe because they are
3801 immediate values. */
3802 if (NILP (new_state
)
3803 || (NUMBERP (new_state
)
3804 && ((XUINT (new_state
)) & 1) != cur_state
))
3806 one_w32_display_info
.faked_key
= vk_code
;
3808 keybd_event ((BYTE
) vk_code
,
3809 (BYTE
) MapVirtualKey (vk_code
, 0),
3810 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3811 keybd_event ((BYTE
) vk_code
,
3812 (BYTE
) MapVirtualKey (vk_code
, 0),
3813 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3814 keybd_event ((BYTE
) vk_code
,
3815 (BYTE
) MapVirtualKey (vk_code
, 0),
3816 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3817 cur_state
= !cur_state
;
3819 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3825 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
3830 DispatchMessage (&msg
);
3833 /* Exit nested loop when our deferred message has completed. */
3834 if (msg_buf
->completed
)
3839 deferred_msg
* deferred_msg_head
;
3841 static deferred_msg
*
3842 find_deferred_msg (HWND hwnd
, UINT msg
)
3844 deferred_msg
* item
;
3846 /* Don't actually need synchronization for read access, since
3847 modification of single pointer is always atomic. */
3848 /* enter_crit (); */
3850 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3851 if (item
->w32msg
.msg
.hwnd
== hwnd
3852 && item
->w32msg
.msg
.message
== msg
)
3855 /* leave_crit (); */
3861 send_deferred_msg (deferred_msg
* msg_buf
,
3867 /* Only input thread can send deferred messages. */
3868 if (GetCurrentThreadId () != dwWindowsThreadId
)
3871 /* It is an error to send a message that is already deferred. */
3872 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3875 /* Enforced synchronization is not needed because this is the only
3876 function that alters deferred_msg_head, and the following critical
3877 section is guaranteed to only be serially reentered (since only the
3878 input thread can call us). */
3880 /* enter_crit (); */
3882 msg_buf
->completed
= 0;
3883 msg_buf
->next
= deferred_msg_head
;
3884 deferred_msg_head
= msg_buf
;
3885 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
3887 /* leave_crit (); */
3889 /* Start a new nested message loop to process other messages until
3890 this one is completed. */
3891 w32_msg_pump (msg_buf
);
3893 deferred_msg_head
= msg_buf
->next
;
3895 return msg_buf
->result
;
3899 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
3901 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
3903 if (msg_buf
== NULL
)
3904 /* Message may have been cancelled, so don't abort(). */
3907 msg_buf
->result
= result
;
3908 msg_buf
->completed
= 1;
3910 /* Ensure input thread is woken so it notices the completion. */
3911 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3915 cancel_all_deferred_msgs ()
3917 deferred_msg
* item
;
3919 /* Don't actually need synchronization for read access, since
3920 modification of single pointer is always atomic. */
3921 /* enter_crit (); */
3923 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3926 item
->completed
= 1;
3929 /* leave_crit (); */
3931 /* Ensure input thread is woken so it notices the completion. */
3932 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3940 deferred_msg dummy_buf
;
3942 /* Ensure our message queue is created */
3944 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
3946 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3949 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
3950 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
3951 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
3953 /* This is the inital message loop which should only exit when the
3954 application quits. */
3955 w32_msg_pump (&dummy_buf
);
3961 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
3971 wmsg
.dwModifiers
= modifiers
;
3973 /* Detect quit_char and set quit-flag directly. Note that we
3974 still need to post a message to ensure the main thread will be
3975 woken up if blocked in sys_select(), but we do NOT want to post
3976 the quit_char message itself (because it will usually be as if
3977 the user had typed quit_char twice). Instead, we post a dummy
3978 message that has no particular effect. */
3981 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
3982 c
= make_ctrl_char (c
) & 0377;
3984 || (wmsg
.dwModifiers
== 0 &&
3985 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
3989 /* The choice of message is somewhat arbitrary, as long as
3990 the main thread handler just ignores it. */
3993 /* Interrupt any blocking system calls. */
3996 /* As a safety precaution, forcibly complete any deferred
3997 messages. This is a kludge, but I don't see any particularly
3998 clean way to handle the situation where a deferred message is
3999 "dropped" in the lisp thread, and will thus never be
4000 completed, eg. by the user trying to activate the menubar
4001 when the lisp thread is busy, and then typing C-g when the
4002 menubar doesn't open promptly (with the result that the
4003 menubar never responds at all because the deferred
4004 WM_INITMENU message is never completed). Another problem
4005 situation is when the lisp thread calls SendMessage (to send
4006 a window manager command) when a message has been deferred;
4007 the lisp thread gets blocked indefinitely waiting for the
4008 deferred message to be completed, which itself is waiting for
4009 the lisp thread to respond.
4011 Note that we don't want to block the input thread waiting for
4012 a reponse from the lisp thread (although that would at least
4013 solve the deadlock problem above), because we want to be able
4014 to receive C-g to interrupt the lisp thread. */
4015 cancel_all_deferred_msgs ();
4019 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4022 /* Main window procedure */
4025 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
4032 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4034 int windows_translate
;
4037 /* Note that it is okay to call x_window_to_frame, even though we are
4038 not running in the main lisp thread, because frame deletion
4039 requires the lisp thread to synchronize with this thread. Thus, if
4040 a frame struct is returned, it can be used without concern that the
4041 lisp thread might make it disappear while we are using it.
4043 NB. Walking the frame list in this thread is safe (as long as
4044 writes of Lisp_Object slots are atomic, which they are on Windows).
4045 Although delete-frame can destructively modify the frame list while
4046 we are walking it, a garbage collection cannot occur until after
4047 delete-frame has synchronized with this thread.
4049 It is also safe to use functions that make GDI calls, such as
4050 w32_clear_rect, because these functions must obtain a DC handle
4051 from the frame struct using get_frame_dc which is thread-aware. */
4056 f
= x_window_to_frame (dpyinfo
, hwnd
);
4059 HDC hdc
= get_frame_dc (f
);
4060 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
4061 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
4062 release_frame_dc (f
, hdc
);
4064 #if defined (W32_DEBUG_DISPLAY)
4065 DebPrint (("WM_ERASEBKGND: erasing %d,%d-%d,%d\n",
4066 wmsg
.rect
.left
, wmsg
.rect
.top
, wmsg
.rect
.right
,
4068 #endif /* W32_DEBUG_DISPLAY */
4071 case WM_PALETTECHANGED
:
4072 /* ignore our own changes */
4073 if ((HWND
)wParam
!= hwnd
)
4075 f
= x_window_to_frame (dpyinfo
, hwnd
);
4077 /* get_frame_dc will realize our palette and force all
4078 frames to be redrawn if needed. */
4079 release_frame_dc (f
, get_frame_dc (f
));
4084 PAINTSTRUCT paintStruct
;
4087 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
4088 fails. Apparently this can happen under some
4090 if (!w32_strict_painting
|| GetUpdateRect (hwnd
, &update_rect
, FALSE
))
4093 BeginPaint (hwnd
, &paintStruct
);
4095 if (w32_strict_painting
)
4096 /* The rectangles returned by GetUpdateRect and BeginPaint
4097 do not always match. GetUpdateRect seems to be the
4098 more reliable of the two. */
4099 wmsg
.rect
= update_rect
;
4101 wmsg
.rect
= paintStruct
.rcPaint
;
4103 #if defined (W32_DEBUG_DISPLAY)
4104 DebPrint (("WM_PAINT: painting %d,%d-%d,%d\n", wmsg
.rect
.left
,
4105 wmsg
.rect
.top
, wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4106 DebPrint (("WM_PAINT: update region is %d,%d-%d,%d\n",
4107 update_rect
.left
, update_rect
.top
,
4108 update_rect
.right
, update_rect
.bottom
));
4110 EndPaint (hwnd
, &paintStruct
);
4113 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4118 /* If GetUpdateRect returns 0 (meaning there is no update
4119 region), assume the whole window needs to be repainted. */
4120 GetClientRect(hwnd
, &wmsg
.rect
);
4121 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4125 case WM_INPUTLANGCHANGE
:
4126 /* Inform lisp thread of keyboard layout changes. */
4127 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4129 /* Clear dead keys in the keyboard state; for simplicity only
4130 preserve modifier key states. */
4135 GetKeyboardState (keystate
);
4136 for (i
= 0; i
< 256; i
++)
4153 SetKeyboardState (keystate
);
4158 /* Synchronize hot keys with normal input. */
4159 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
4164 record_keyup (wParam
, lParam
);
4169 /* Ignore keystrokes we fake ourself; see below. */
4170 if (dpyinfo
->faked_key
== wParam
)
4172 dpyinfo
->faked_key
= 0;
4173 /* Make sure TranslateMessage sees them though (as long as
4174 they don't produce WM_CHAR messages). This ensures that
4175 indicator lights are toggled promptly on Windows 9x, for
4177 if (lispy_function_keys
[wParam
] != 0)
4179 windows_translate
= 1;
4185 /* Synchronize modifiers with current keystroke. */
4187 record_keydown (wParam
, lParam
);
4188 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
4190 windows_translate
= 0;
4195 if (NILP (Vw32_pass_lwindow_to_system
))
4197 /* Prevent system from acting on keyup (which opens the
4198 Start menu if no other key was pressed) by simulating a
4199 press of Space which we will ignore. */
4200 if (GetAsyncKeyState (wParam
) & 1)
4202 if (NUMBERP (Vw32_phantom_key_code
))
4203 key
= XUINT (Vw32_phantom_key_code
) & 255;
4206 dpyinfo
->faked_key
= key
;
4207 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4210 if (!NILP (Vw32_lwindow_modifier
))
4214 if (NILP (Vw32_pass_rwindow_to_system
))
4216 if (GetAsyncKeyState (wParam
) & 1)
4218 if (NUMBERP (Vw32_phantom_key_code
))
4219 key
= XUINT (Vw32_phantom_key_code
) & 255;
4222 dpyinfo
->faked_key
= key
;
4223 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4226 if (!NILP (Vw32_rwindow_modifier
))
4230 if (!NILP (Vw32_apps_modifier
))
4234 if (NILP (Vw32_pass_alt_to_system
))
4235 /* Prevent DefWindowProc from activating the menu bar if an
4236 Alt key is pressed and released by itself. */
4238 windows_translate
= 1;
4241 /* Decide whether to treat as modifier or function key. */
4242 if (NILP (Vw32_enable_caps_lock
))
4243 goto disable_lock_key
;
4244 windows_translate
= 1;
4247 /* Decide whether to treat as modifier or function key. */
4248 if (NILP (Vw32_enable_num_lock
))
4249 goto disable_lock_key
;
4250 windows_translate
= 1;
4253 /* Decide whether to treat as modifier or function key. */
4254 if (NILP (Vw32_scroll_lock_modifier
))
4255 goto disable_lock_key
;
4256 windows_translate
= 1;
4259 /* Ensure the appropriate lock key state (and indicator light)
4260 remains in the same state. We do this by faking another
4261 press of the relevant key. Apparently, this really is the
4262 only way to toggle the state of the indicator lights. */
4263 dpyinfo
->faked_key
= wParam
;
4264 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4265 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4266 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4267 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4268 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4269 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4270 /* Ensure indicator lights are updated promptly on Windows 9x
4271 (TranslateMessage apparently does this), after forwarding
4273 post_character_message (hwnd
, msg
, wParam
, lParam
,
4274 w32_get_key_modifiers (wParam
, lParam
));
4275 windows_translate
= 1;
4279 case VK_PROCESSKEY
: /* Generated by IME. */
4280 windows_translate
= 1;
4283 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
4284 which is confusing for purposes of key binding; convert
4285 VK_CANCEL events into VK_PAUSE events. */
4289 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
4290 for purposes of key binding; convert these back into
4291 VK_NUMLOCK events, at least when we want to see NumLock key
4292 presses. (Note that there is never any possibility that
4293 VK_PAUSE with Ctrl really is C-Pause as per above.) */
4294 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
4295 wParam
= VK_NUMLOCK
;
4298 /* If not defined as a function key, change it to a WM_CHAR message. */
4299 if (lispy_function_keys
[wParam
] == 0)
4301 DWORD modifiers
= construct_console_modifiers ();
4303 if (!NILP (Vw32_recognize_altgr
)
4304 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
4306 /* Always let TranslateMessage handle AltGr key chords;
4307 for some reason, ToAscii doesn't always process AltGr
4308 chords correctly. */
4309 windows_translate
= 1;
4311 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
4313 /* Handle key chords including any modifiers other
4314 than shift directly, in order to preserve as much
4315 modifier information as possible. */
4316 if ('A' <= wParam
&& wParam
<= 'Z')
4318 /* Don't translate modified alphabetic keystrokes,
4319 so the user doesn't need to constantly switch
4320 layout to type control or meta keystrokes when
4321 the normal layout translates alphabetic
4322 characters to non-ascii characters. */
4323 if (!modifier_set (VK_SHIFT
))
4324 wParam
+= ('a' - 'A');
4329 /* Try to handle other keystrokes by determining the
4330 base character (ie. translating the base key plus
4334 KEY_EVENT_RECORD key
;
4336 key
.bKeyDown
= TRUE
;
4337 key
.wRepeatCount
= 1;
4338 key
.wVirtualKeyCode
= wParam
;
4339 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
4340 key
.uChar
.AsciiChar
= 0;
4341 key
.dwControlKeyState
= modifiers
;
4343 add
= w32_kbd_patch_key (&key
);
4344 /* 0 means an unrecognised keycode, negative means
4345 dead key. Ignore both. */
4348 /* Forward asciified character sequence. */
4349 post_character_message
4350 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
4351 w32_get_key_modifiers (wParam
, lParam
));
4352 w32_kbd_patch_key (&key
);
4359 /* Let TranslateMessage handle everything else. */
4360 windows_translate
= 1;
4366 if (windows_translate
)
4368 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
4370 windows_msg
.time
= GetMessageTime ();
4371 TranslateMessage (&windows_msg
);
4379 post_character_message (hwnd
, msg
, wParam
, lParam
,
4380 w32_get_key_modifiers (wParam
, lParam
));
4383 /* Simulate middle mouse button events when left and right buttons
4384 are used together, but only if user has two button mouse. */
4385 case WM_LBUTTONDOWN
:
4386 case WM_RBUTTONDOWN
:
4387 if (XINT (Vw32_num_mouse_buttons
) > 2)
4388 goto handle_plain_button
;
4391 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
4392 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
4394 if (button_state
& this)
4397 if (button_state
== 0)
4400 button_state
|= this;
4402 if (button_state
& other
)
4404 if (mouse_button_timer
)
4406 KillTimer (hwnd
, mouse_button_timer
);
4407 mouse_button_timer
= 0;
4409 /* Generate middle mouse event instead. */
4410 msg
= WM_MBUTTONDOWN
;
4411 button_state
|= MMOUSE
;
4413 else if (button_state
& MMOUSE
)
4415 /* Ignore button event if we've already generated a
4416 middle mouse down event. This happens if the
4417 user releases and press one of the two buttons
4418 after we've faked a middle mouse event. */
4423 /* Flush out saved message. */
4424 post_msg (&saved_mouse_button_msg
);
4426 wmsg
.dwModifiers
= w32_get_modifiers ();
4427 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4429 /* Clear message buffer. */
4430 saved_mouse_button_msg
.msg
.hwnd
= 0;
4434 /* Hold onto message for now. */
4435 mouse_button_timer
=
4436 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
4437 XINT (Vw32_mouse_button_tolerance
), NULL
);
4438 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
4439 saved_mouse_button_msg
.msg
.message
= msg
;
4440 saved_mouse_button_msg
.msg
.wParam
= wParam
;
4441 saved_mouse_button_msg
.msg
.lParam
= lParam
;
4442 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
4443 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
4450 if (XINT (Vw32_num_mouse_buttons
) > 2)
4451 goto handle_plain_button
;
4454 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
4455 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
4457 if ((button_state
& this) == 0)
4460 button_state
&= ~this;
4462 if (button_state
& MMOUSE
)
4464 /* Only generate event when second button is released. */
4465 if ((button_state
& other
) == 0)
4468 button_state
&= ~MMOUSE
;
4470 if (button_state
) abort ();
4477 /* Flush out saved message if necessary. */
4478 if (saved_mouse_button_msg
.msg
.hwnd
)
4480 post_msg (&saved_mouse_button_msg
);
4483 wmsg
.dwModifiers
= w32_get_modifiers ();
4484 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4486 /* Always clear message buffer and cancel timer. */
4487 saved_mouse_button_msg
.msg
.hwnd
= 0;
4488 KillTimer (hwnd
, mouse_button_timer
);
4489 mouse_button_timer
= 0;
4491 if (button_state
== 0)
4496 case WM_MBUTTONDOWN
:
4498 handle_plain_button
:
4503 if (parse_button (msg
, &button
, &up
))
4505 if (up
) ReleaseCapture ();
4506 else SetCapture (hwnd
);
4507 button
= (button
== 0) ? LMOUSE
:
4508 ((button
== 1) ? MMOUSE
: RMOUSE
);
4510 button_state
&= ~button
;
4512 button_state
|= button
;
4516 wmsg
.dwModifiers
= w32_get_modifiers ();
4517 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4522 if (XINT (Vw32_mouse_move_interval
) <= 0
4523 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4525 wmsg
.dwModifiers
= w32_get_modifiers ();
4526 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4530 /* Hang onto mouse move and scroll messages for a bit, to avoid
4531 sending such events to Emacs faster than it can process them.
4532 If we get more events before the timer from the first message
4533 expires, we just replace the first message. */
4535 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4537 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4538 XINT (Vw32_mouse_move_interval
), NULL
);
4540 /* Hold onto message for now. */
4541 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4542 saved_mouse_move_msg
.msg
.message
= msg
;
4543 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4544 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4545 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4546 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4551 wmsg
.dwModifiers
= w32_get_modifiers ();
4552 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4556 wmsg
.dwModifiers
= w32_get_modifiers ();
4557 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4561 /* Flush out saved messages if necessary. */
4562 if (wParam
== mouse_button_timer
)
4564 if (saved_mouse_button_msg
.msg
.hwnd
)
4566 post_msg (&saved_mouse_button_msg
);
4567 saved_mouse_button_msg
.msg
.hwnd
= 0;
4569 KillTimer (hwnd
, mouse_button_timer
);
4570 mouse_button_timer
= 0;
4572 else if (wParam
== mouse_move_timer
)
4574 if (saved_mouse_move_msg
.msg
.hwnd
)
4576 post_msg (&saved_mouse_move_msg
);
4577 saved_mouse_move_msg
.msg
.hwnd
= 0;
4579 KillTimer (hwnd
, mouse_move_timer
);
4580 mouse_move_timer
= 0;
4585 /* Windows doesn't send us focus messages when putting up and
4586 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4587 The only indication we get that something happened is receiving
4588 this message afterwards. So this is a good time to reset our
4589 keyboard modifiers' state. */
4596 /* We must ensure menu bar is fully constructed and up to date
4597 before allowing user interaction with it. To achieve this
4598 we send this message to the lisp thread and wait for a
4599 reply (whose value is not actually needed) to indicate that
4600 the menu bar is now ready for use, so we can now return.
4602 To remain responsive in the meantime, we enter a nested message
4603 loop that can process all other messages.
4605 However, we skip all this if the message results from calling
4606 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4607 thread a message because it is blocked on us at this point. We
4608 set menubar_active before calling TrackPopupMenu to indicate
4609 this (there is no possibility of confusion with real menubar
4612 f
= x_window_to_frame (dpyinfo
, hwnd
);
4614 && (f
->output_data
.w32
->menubar_active
4615 /* We can receive this message even in the absence of a
4616 menubar (ie. when the system menu is activated) - in this
4617 case we do NOT want to forward the message, otherwise it
4618 will cause the menubar to suddenly appear when the user
4619 had requested it to be turned off! */
4620 || f
->output_data
.w32
->menubar_widget
== NULL
))
4624 deferred_msg msg_buf
;
4626 /* Detect if message has already been deferred; in this case
4627 we cannot return any sensible value to ignore this. */
4628 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4631 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4634 case WM_EXITMENULOOP
:
4635 f
= x_window_to_frame (dpyinfo
, hwnd
);
4637 /* Indicate that menubar can be modified again. */
4639 f
->output_data
.w32
->menubar_active
= 0;
4643 wmsg
.dwModifiers
= w32_get_modifiers ();
4644 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4647 case WM_MEASUREITEM
:
4648 f
= x_window_to_frame (dpyinfo
, hwnd
);
4651 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4653 if (pMis
->CtlType
== ODT_MENU
)
4655 /* Work out dimensions for popup menu titles. */
4656 char * title
= (char *) pMis
->itemData
;
4657 HDC hdc
= GetDC (hwnd
);
4658 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4659 LOGFONT menu_logfont
;
4663 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4664 menu_logfont
.lfWeight
= FW_BOLD
;
4665 menu_font
= CreateFontIndirect (&menu_logfont
);
4666 old_font
= SelectObject (hdc
, menu_font
);
4668 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4671 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4672 pMis
->itemWidth
= size
.cx
;
4673 if (pMis
->itemHeight
< size
.cy
)
4674 pMis
->itemHeight
= size
.cy
;
4677 pMis
->itemWidth
= 0;
4679 SelectObject (hdc
, old_font
);
4680 DeleteObject (menu_font
);
4681 ReleaseDC (hwnd
, hdc
);
4688 f
= x_window_to_frame (dpyinfo
, hwnd
);
4691 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4693 if (pDis
->CtlType
== ODT_MENU
)
4695 /* Draw popup menu title. */
4696 char * title
= (char *) pDis
->itemData
;
4699 HDC hdc
= pDis
->hDC
;
4700 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4701 LOGFONT menu_logfont
;
4704 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4705 menu_logfont
.lfWeight
= FW_BOLD
;
4706 menu_font
= CreateFontIndirect (&menu_logfont
);
4707 old_font
= SelectObject (hdc
, menu_font
);
4709 /* Always draw title as if not selected. */
4712 + GetSystemMetrics (SM_CXMENUCHECK
),
4714 ETO_OPAQUE
, &pDis
->rcItem
,
4715 title
, strlen (title
), NULL
);
4717 SelectObject (hdc
, old_font
);
4718 DeleteObject (menu_font
);
4726 /* Still not right - can't distinguish between clicks in the
4727 client area of the frame from clicks forwarded from the scroll
4728 bars - may have to hook WM_NCHITTEST to remember the mouse
4729 position and then check if it is in the client area ourselves. */
4730 case WM_MOUSEACTIVATE
:
4731 /* Discard the mouse click that activates a frame, allowing the
4732 user to click anywhere without changing point (or worse!).
4733 Don't eat mouse clicks on scrollbars though!! */
4734 if (LOWORD (lParam
) == HTCLIENT
)
4735 return MA_ACTIVATEANDEAT
;
4739 case WM_ACTIVATEAPP
:
4741 case WM_WINDOWPOSCHANGED
:
4743 /* Inform lisp thread that a frame might have just been obscured
4744 or exposed, so should recheck visibility of all frames. */
4745 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4749 dpyinfo
->faked_key
= 0;
4751 register_hot_keys (hwnd
);
4754 unregister_hot_keys (hwnd
);
4761 wmsg
.dwModifiers
= w32_get_modifiers ();
4762 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4766 wmsg
.dwModifiers
= w32_get_modifiers ();
4767 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4770 case WM_WINDOWPOSCHANGING
:
4773 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
4775 wp
.length
= sizeof (WINDOWPLACEMENT
);
4776 GetWindowPlacement (hwnd
, &wp
);
4778 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
4785 DWORD internal_border
;
4786 DWORD scrollbar_extra
;
4789 wp
.length
= sizeof(wp
);
4790 GetWindowRect (hwnd
, &wr
);
4794 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
4795 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
4796 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
4797 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
4801 memset (&rect
, 0, sizeof (rect
));
4802 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
4803 GetMenu (hwnd
) != NULL
);
4805 /* Force width and height of client area to be exact
4806 multiples of the character cell dimensions. */
4807 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
4808 - 2 * internal_border
- scrollbar_extra
)
4810 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
4811 - 2 * internal_border
)
4816 /* For right/bottom sizing we can just fix the sizes.
4817 However for top/left sizing we will need to fix the X
4818 and Y positions as well. */
4823 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
4824 && (lppos
->flags
& SWP_NOMOVE
) == 0)
4826 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
4833 lppos
->flags
|= SWP_NOMOVE
;
4844 case WM_GETMINMAXINFO
:
4845 /* Hack to correct bug that allows Emacs frames to be resized
4846 below the Minimum Tracking Size. */
4847 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
4848 /* Hack to allow resizing the Emacs frame above the screen size.
4849 Note that Windows 9x limits coordinates to 16-bits. */
4850 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
4851 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
4854 case WM_EMACS_CREATESCROLLBAR
:
4855 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
4856 (struct scroll_bar
*) lParam
);
4858 case WM_EMACS_SHOWWINDOW
:
4859 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4861 case WM_EMACS_SETFOREGROUND
:
4863 HWND foreground_window
;
4864 DWORD foreground_thread
, retval
;
4866 /* On NT 5.0, and apparently Windows 98, it is necessary to
4867 attach to the thread that currently has focus in order to
4868 pull the focus away from it. */
4869 foreground_window
= GetForegroundWindow ();
4870 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4871 if (!foreground_window
4872 || foreground_thread
== GetCurrentThreadId ()
4873 || !AttachThreadInput (GetCurrentThreadId (),
4874 foreground_thread
, TRUE
))
4875 foreground_thread
= 0;
4877 retval
= SetForegroundWindow ((HWND
) wParam
);
4879 /* Detach from the previous foreground thread. */
4880 if (foreground_thread
)
4881 AttachThreadInput (GetCurrentThreadId (),
4882 foreground_thread
, FALSE
);
4887 case WM_EMACS_SETWINDOWPOS
:
4889 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4890 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4891 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4894 case WM_EMACS_DESTROYWINDOW
:
4895 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4896 return DestroyWindow ((HWND
) wParam
);
4898 case WM_EMACS_TRACKPOPUPMENU
:
4903 pos
= (POINT
*)lParam
;
4904 flags
= TPM_CENTERALIGN
;
4905 if (button_state
& LMOUSE
)
4906 flags
|= TPM_LEFTBUTTON
;
4907 else if (button_state
& RMOUSE
)
4908 flags
|= TPM_RIGHTBUTTON
;
4910 /* Remember we did a SetCapture on the initial mouse down event,
4911 so for safety, we make sure the capture is cancelled now. */
4915 /* Use menubar_active to indicate that WM_INITMENU is from
4916 TrackPopupMenu below, and should be ignored. */
4917 f
= x_window_to_frame (dpyinfo
, hwnd
);
4919 f
->output_data
.w32
->menubar_active
= 1;
4921 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4925 /* Eat any mouse messages during popupmenu */
4926 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4928 /* Get the menu selection, if any */
4929 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4931 retval
= LOWORD (amsg
.wParam
);
4947 /* Check for messages registered at runtime. */
4948 if (msg
== msh_mousewheel
)
4950 wmsg
.dwModifiers
= w32_get_modifiers ();
4951 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4956 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
4960 /* The most common default return code for handled messages is 0. */
4965 my_create_window (f
)
4970 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4972 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4975 /* Create and set up the w32 window for frame F. */
4978 w32_window (f
, window_prompting
, minibuffer_only
)
4980 long window_prompting
;
4981 int minibuffer_only
;
4985 /* Use the resource name as the top-level window name
4986 for looking up resources. Make a non-Lisp copy
4987 for the window manager, so GC relocation won't bother it.
4989 Elsewhere we specify the window name for the window manager. */
4992 char *str
= (char *) XSTRING (Vx_resource_name
)->data
;
4993 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4994 strcpy (f
->namebuf
, str
);
4997 my_create_window (f
);
4999 validate_x_resource_name ();
5001 /* x_set_name normally ignores requests to set the name if the
5002 requested name is the same as the current name. This is the one
5003 place where that assumption isn't correct; f->name is set, but
5004 the server hasn't been told. */
5007 int explicit = f
->explicit_name
;
5009 f
->explicit_name
= 0;
5012 x_set_name (f
, name
, explicit);
5017 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
5018 initialize_frame_menubar (f
);
5020 if (FRAME_W32_WINDOW (f
) == 0)
5021 error ("Unable to create window");
5024 /* Handle the icon stuff for this window. Perhaps later we might
5025 want an x_set_icon_position which can be called interactively as
5033 Lisp_Object icon_x
, icon_y
;
5035 /* Set the position of the icon. Note that Windows 95 groups all
5036 icons in the tray. */
5037 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
5038 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
5039 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
5041 CHECK_NUMBER (icon_x
, 0);
5042 CHECK_NUMBER (icon_y
, 0);
5044 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
5045 error ("Both left and top icon corners of icon must be specified");
5049 if (! EQ (icon_x
, Qunbound
))
5050 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
5053 /* Start up iconic or window? */
5054 x_wm_set_window_state
5055 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
5059 x_text_icon (f
, (char *) XSTRING ((!NILP (f
->icon_name
)
5072 XGCValues gc_values
;
5076 /* Create the GC's of this frame.
5077 Note that many default values are used. */
5080 gc_values
.font
= f
->output_data
.w32
->font
;
5082 /* Cursor has cursor-color background, background-color foreground. */
5083 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
5084 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
5085 f
->output_data
.w32
->cursor_gc
5086 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
5087 (GCFont
| GCForeground
| GCBackground
),
5091 f
->output_data
.w32
->white_relief
.gc
= 0;
5092 f
->output_data
.w32
->black_relief
.gc
= 0;
5098 /* Handler for signals raised during x_create_frame and
5099 x_create_top_frame. FRAME is the frame which is partially
5103 unwind_create_frame (frame
)
5106 struct frame
*f
= XFRAME (frame
);
5108 /* If frame is ``official'', nothing to do. */
5109 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
5112 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5115 x_free_frame_resources (f
);
5117 /* Check that reference counts are indeed correct. */
5118 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
5119 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
5128 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
5130 "Make a new window, which is called a \"frame\" in Emacs terms.\n\
5131 Returns an Emacs frame object.\n\
5132 ALIST is an alist of frame parameters.\n\
5133 If the parameters specify that the frame should not have a minibuffer,\n\
5134 and do not specify a specific minibuffer window to use,\n\
5135 then `default-minibuffer-frame' must be a frame whose minibuffer can\n\
5136 be shared by the new frame.\n\
5138 This function is an internal primitive--use `make-frame' instead.")
5143 Lisp_Object frame
, tem
;
5145 int minibuffer_only
= 0;
5146 long window_prompting
= 0;
5148 int count
= BINDING_STACK_SIZE ();
5149 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5150 Lisp_Object display
;
5151 struct w32_display_info
*dpyinfo
= NULL
;
5157 /* Use this general default value to start with
5158 until we know if this frame has a specified name. */
5159 Vx_resource_name
= Vinvocation_name
;
5161 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
5162 if (EQ (display
, Qunbound
))
5164 dpyinfo
= check_x_display_info (display
);
5166 kb
= dpyinfo
->kboard
;
5168 kb
= &the_only_kboard
;
5171 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5173 && ! EQ (name
, Qunbound
)
5175 error ("Invalid frame name--not a string or nil");
5178 Vx_resource_name
= name
;
5180 /* See if parent window is specified. */
5181 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
5182 if (EQ (parent
, Qunbound
))
5184 if (! NILP (parent
))
5185 CHECK_NUMBER (parent
, 0);
5187 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
5188 /* No need to protect DISPLAY because that's not used after passing
5189 it to make_frame_without_minibuffer. */
5191 GCPRO4 (parms
, parent
, name
, frame
);
5192 tem
= w32_get_arg (parms
, Qminibuffer
, "minibuffer", "Minibuffer",
5194 if (EQ (tem
, Qnone
) || NILP (tem
))
5195 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
5196 else if (EQ (tem
, Qonly
))
5198 f
= make_minibuffer_frame ();
5199 minibuffer_only
= 1;
5201 else if (WINDOWP (tem
))
5202 f
= make_frame_without_minibuffer (tem
, kb
, display
);
5206 XSETFRAME (frame
, f
);
5208 /* Note that Windows does support scroll bars. */
5209 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
5210 /* By default, make scrollbars the system standard width. */
5211 f
->scroll_bar_pixel_width
= GetSystemMetrics (SM_CXVSCROLL
);
5213 f
->output_method
= output_w32
;
5214 f
->output_data
.w32
=
5215 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5216 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5217 FRAME_FONTSET (f
) = -1;
5218 record_unwind_protect (unwind_create_frame
, frame
);
5221 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
5222 if (! STRINGP (f
->icon_name
))
5223 f
->icon_name
= Qnil
;
5225 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
5227 FRAME_KBOARD (f
) = kb
;
5230 /* Specify the parent under which to make this window. */
5234 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
5235 f
->output_data
.w32
->explicit_parent
= 1;
5239 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5240 f
->output_data
.w32
->explicit_parent
= 0;
5243 /* Set the name; the functions to which we pass f expect the name to
5245 if (EQ (name
, Qunbound
) || NILP (name
))
5247 f
->name
= build_string (dpyinfo
->w32_id_name
);
5248 f
->explicit_name
= 0;
5253 f
->explicit_name
= 1;
5254 /* use the frame's title when getting resources for this frame. */
5255 specbind (Qx_resource_name
, name
);
5258 /* Extract the window parameters from the supplied values
5259 that are needed to determine window geometry. */
5263 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
5266 /* First, try whatever font the caller has specified. */
5269 tem
= Fquery_fontset (font
, Qnil
);
5271 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
5273 font
= x_new_font (f
, XSTRING (font
)->data
);
5275 /* Try out a font which we hope has bold and italic variations. */
5276 if (!STRINGP (font
))
5277 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
5278 if (! STRINGP (font
))
5279 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5280 /* If those didn't work, look for something which will at least work. */
5281 if (! STRINGP (font
))
5282 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
5284 if (! STRINGP (font
))
5285 font
= build_string ("Fixedsys");
5287 x_default_parameter (f
, parms
, Qfont
, font
,
5288 "font", "Font", RES_TYPE_STRING
);
5291 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5292 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5293 /* This defaults to 2 in order to match xterm. We recognize either
5294 internalBorderWidth or internalBorder (which is what xterm calls
5296 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5300 value
= w32_get_arg (parms
, Qinternal_border_width
,
5301 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
5302 if (! EQ (value
, Qunbound
))
5303 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5306 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5307 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
5308 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
5309 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qright
,
5310 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5312 /* Also do the stuff which must be set before the window exists. */
5313 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5314 "foreground", "Foreground", RES_TYPE_STRING
);
5315 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5316 "background", "Background", RES_TYPE_STRING
);
5317 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5318 "pointerColor", "Foreground", RES_TYPE_STRING
);
5319 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5320 "cursorColor", "Foreground", RES_TYPE_STRING
);
5321 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5322 "borderColor", "BorderColor", RES_TYPE_STRING
);
5323 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
5324 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5325 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
5326 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
5329 /* Init faces before x_default_parameter is called for scroll-bar
5330 parameters because that function calls x_set_scroll_bar_width,
5331 which calls change_frame_size, which calls Fset_window_buffer,
5332 which runs hooks, which call Fvertical_motion. At the end, we
5333 end up in init_iterator with a null face cache, which should not
5335 init_frame_faces (f
);
5337 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
5338 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
5339 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (0),
5340 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
5341 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
5342 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5343 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
5344 "title", "Title", RES_TYPE_STRING
);
5346 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5347 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5348 window_prompting
= x_figure_window_size (f
, parms
);
5350 if (window_prompting
& XNegative
)
5352 if (window_prompting
& YNegative
)
5353 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
5355 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
5359 if (window_prompting
& YNegative
)
5360 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
5362 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
5365 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
5367 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5368 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5370 w32_window (f
, window_prompting
, minibuffer_only
);
5375 /* Now consider the frame official. */
5376 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5377 Vframe_list
= Fcons (frame
, Vframe_list
);
5379 /* We need to do this after creating the window, so that the
5380 icon-creation functions can say whose icon they're describing. */
5381 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
5382 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5384 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5385 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5386 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5387 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5388 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5389 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5390 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
5391 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5393 /* Dimensions, especially f->height, must be done via change_frame_size.
5394 Change will not be effected unless different from the current
5399 /* Add the tool-bar height to the initial frame height so that the
5400 user gets a text display area of the size he specified with -g or
5401 via .Xdefaults. Later changes of the tool-bar height don't
5402 change the frame size. This is done so that users can create
5403 tall Emacs frames without having to guess how tall the tool-bar
5405 if (FRAME_TOOL_BAR_LINES (f
))
5407 int margin
, relief
, bar_height
;
5409 relief
= (tool_bar_button_relief
> 0
5410 ? tool_bar_button_relief
5411 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
5413 if (INTEGERP (Vtool_bar_button_margin
)
5414 && XINT (Vtool_bar_button_margin
) > 0)
5415 margin
= XFASTINT (Vtool_bar_button_margin
);
5416 else if (CONSP (Vtool_bar_button_margin
)
5417 && INTEGERP (XCDR (Vtool_bar_button_margin
))
5418 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
5419 margin
= XFASTINT (XCDR (Vtool_bar_button_margin
));
5423 bar_height
= DEFAULT_TOOL_BAR_IMAGE_HEIGHT
+ 2 * margin
+ 2 * relief
;
5424 height
+= (bar_height
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
5428 SET_FRAME_WIDTH (f
, 0);
5429 change_frame_size (f
, height
, width
, 1, 0, 0);
5431 /* Tell the server what size and position, etc, we want, and how
5432 badly we want them. This should be done after we have the menu
5433 bar so that its size can be taken into account. */
5435 x_wm_set_size_hint (f
, window_prompting
, 0);
5438 /* Set up faces after all frame parameters are known. This call
5439 also merges in face attributes specified for new frames. If we
5440 don't do this, the `menu' face for instance won't have the right
5441 colors, and the menu bar won't appear in the specified colors for
5443 call1 (Qface_set_after_frame_default
, frame
);
5445 /* Make the window appear on the frame and enable display, unless
5446 the caller says not to. However, with explicit parent, Emacs
5447 cannot control visibility, so don't try. */
5448 if (! f
->output_data
.w32
->explicit_parent
)
5450 Lisp_Object visibility
;
5452 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5453 if (EQ (visibility
, Qunbound
))
5456 if (EQ (visibility
, Qicon
))
5457 x_iconify_frame (f
);
5458 else if (! NILP (visibility
))
5459 x_make_frame_visible (f
);
5461 /* Must have been Qnil. */
5465 return unbind_to (count
, frame
);
5468 /* FRAME is used only to get a handle on the X display. We don't pass the
5469 display info directly because we're called from frame.c, which doesn't
5470 know about that structure. */
5472 x_get_focus_frame (frame
)
5473 struct frame
*frame
;
5475 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
5477 if (! dpyinfo
->w32_focus_frame
)
5480 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5484 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
5485 "Give FRAME input focus, raising to foreground if necessary.")
5489 x_focus_on_frame (check_x_frame (frame
));
5494 /* Return the charset portion of a font name. */
5495 char * xlfd_charset_of_font (char * fontname
)
5497 char *charset
, *encoding
;
5499 encoding
= strrchr(fontname
, '-');
5500 if (!encoding
|| encoding
== fontname
)
5503 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
5504 if (*charset
== '-')
5507 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
5513 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
5514 int size
, char* filename
);
5515 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
5516 BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
, char * charset
);
5518 static struct font_info
*
5519 w32_load_system_font (f
,fontname
,size
)
5524 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5525 Lisp_Object font_names
;
5527 /* Get a list of all the fonts that match this name. Once we
5528 have a list of matching fonts, we compare them against the fonts
5529 we already have loaded by comparing names. */
5530 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
5532 if (!NILP (font_names
))
5537 /* First check if any are already loaded, as that is cheaper
5538 than loading another one. */
5539 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5540 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
5541 if (dpyinfo
->font_table
[i
].name
5542 && (!strcmp (dpyinfo
->font_table
[i
].name
,
5543 XSTRING (XCAR (tail
))->data
)
5544 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
5545 XSTRING (XCAR (tail
))->data
)))
5546 return (dpyinfo
->font_table
+ i
);
5548 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
5550 else if (w32_strict_fontnames
)
5552 /* If EnumFontFamiliesEx was available, we got a full list of
5553 fonts back so stop now to avoid the possibility of loading a
5554 random font. If we had to fall back to EnumFontFamilies, the
5555 list is incomplete, so continue whether the font we want was
5557 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5558 FARPROC enum_font_families_ex
5559 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
5560 if (enum_font_families_ex
)
5564 /* Load the font and add it to the table. */
5566 char *full_name
, *encoding
, *charset
;
5568 struct font_info
*fontp
;
5573 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
5576 if (!*lf
.lfFaceName
)
5577 /* If no name was specified for the font, we get a random font
5578 from CreateFontIndirect - this is not particularly
5579 desirable, especially since CreateFontIndirect does not
5580 fill out the missing name in lf, so we never know what we
5584 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
5585 bzero (font
, sizeof (*font
));
5587 /* Set bdf to NULL to indicate that this is a Windows font. */
5592 font
->hfont
= CreateFontIndirect (&lf
);
5594 if (font
->hfont
== NULL
)
5602 int codepage
= w32_codepage_for_font (fontname
);
5604 hdc
= GetDC (dpyinfo
->root_window
);
5605 oldobj
= SelectObject (hdc
, font
->hfont
);
5607 ok
= GetTextMetrics (hdc
, &font
->tm
);
5608 if (codepage
== CP_UNICODE
)
5609 font
->double_byte_p
= 1;
5611 font
->double_byte_p
= GetFontLanguageInfo(hdc
) & GCP_DBCS
;
5613 SelectObject (hdc
, oldobj
);
5614 ReleaseDC (dpyinfo
->root_window
, hdc
);
5615 /* Fill out details in lf according to the font that was
5617 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
5618 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
5619 lf
.lfWeight
= font
->tm
.tmWeight
;
5620 lf
.lfItalic
= font
->tm
.tmItalic
;
5621 lf
.lfCharSet
= font
->tm
.tmCharSet
;
5622 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
5623 ? VARIABLE_PITCH
: FIXED_PITCH
);
5624 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
5625 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
5627 w32_cache_char_metrics (font
);
5634 w32_unload_font (dpyinfo
, font
);
5638 /* Find a free slot in the font table. */
5639 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
5640 if (dpyinfo
->font_table
[i
].name
== NULL
)
5643 /* If no free slot found, maybe enlarge the font table. */
5644 if (i
== dpyinfo
->n_fonts
5645 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
5648 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
5649 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
5651 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
5654 fontp
= dpyinfo
->font_table
+ i
;
5655 if (i
== dpyinfo
->n_fonts
)
5658 /* Now fill in the slots of *FONTP. */
5661 fontp
->font_idx
= i
;
5662 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
5663 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
5665 charset
= xlfd_charset_of_font (fontname
);
5667 /* Work out the font's full name. */
5668 full_name
= (char *)xmalloc (100);
5669 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
5670 fontp
->full_name
= full_name
;
5673 /* If all else fails - just use the name we used to load it. */
5675 fontp
->full_name
= fontp
->name
;
5678 fontp
->size
= FONT_WIDTH (font
);
5679 fontp
->height
= FONT_HEIGHT (font
);
5681 /* The slot `encoding' specifies how to map a character
5682 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
5683 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
5684 (0:0x20..0x7F, 1:0xA0..0xFF,
5685 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
5686 2:0xA020..0xFF7F). For the moment, we don't know which charset
5687 uses this font. So, we set information in fontp->encoding[1]
5688 which is never used by any charset. If mapping can't be
5689 decided, set FONT_ENCODING_NOT_DECIDED. */
5691 /* SJIS fonts need to be set to type 4, all others seem to work as
5692 type FONT_ENCODING_NOT_DECIDED. */
5693 encoding
= strrchr (fontp
->name
, '-');
5694 if (encoding
&& stricmp (encoding
+1, "sjis") == 0)
5695 fontp
->encoding
[1] = 4;
5697 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
5699 /* The following three values are set to 0 under W32, which is
5700 what they get set to if XGetFontProperty fails under X. */
5701 fontp
->baseline_offset
= 0;
5702 fontp
->relative_compose
= 0;
5703 fontp
->default_ascent
= 0;
5705 /* Set global flag fonts_changed_p to non-zero if the font loaded
5706 has a character with a smaller width than any other character
5707 before, or if the font loaded has a smalle>r height than any
5708 other font loaded before. If this happens, it will make a
5709 glyph matrix reallocation necessary. */
5710 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
5716 /* Load font named FONTNAME of size SIZE for frame F, and return a
5717 pointer to the structure font_info while allocating it dynamically.
5718 If loading fails, return NULL. */
5720 w32_load_font (f
,fontname
,size
)
5725 Lisp_Object bdf_fonts
;
5726 struct font_info
*retval
= NULL
;
5728 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
5730 while (!retval
&& CONSP (bdf_fonts
))
5732 char *bdf_name
, *bdf_file
;
5733 Lisp_Object bdf_pair
;
5735 bdf_name
= XSTRING (XCAR (bdf_fonts
))->data
;
5736 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
5737 bdf_file
= XSTRING (XCDR (bdf_pair
))->data
;
5739 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
5741 bdf_fonts
= XCDR (bdf_fonts
);
5747 return w32_load_system_font(f
, fontname
, size
);
5752 w32_unload_font (dpyinfo
, font
)
5753 struct w32_display_info
*dpyinfo
;
5758 if (font
->per_char
) xfree (font
->per_char
);
5759 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
5761 if (font
->hfont
) DeleteObject(font
->hfont
);
5766 /* The font conversion stuff between x and w32 */
5768 /* X font string is as follows (from faces.el)
5772 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
5773 * (weight\? "\\([^-]*\\)") ; 1
5774 * (slant "\\([ior]\\)") ; 2
5775 * (slant\? "\\([^-]?\\)") ; 2
5776 * (swidth "\\([^-]*\\)") ; 3
5777 * (adstyle "[^-]*") ; 4
5778 * (pixelsize "[0-9]+")
5779 * (pointsize "[0-9][0-9]+")
5780 * (resx "[0-9][0-9]+")
5781 * (resy "[0-9][0-9]+")
5782 * (spacing "[cmp?*]")
5783 * (avgwidth "[0-9]+")
5784 * (registry "[^-]+")
5785 * (encoding "[^-]+")
5790 x_to_w32_weight (lpw
)
5793 if (!lpw
) return (FW_DONTCARE
);
5795 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
5796 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
5797 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
5798 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
5799 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
5800 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
5801 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
5802 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
5803 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
5804 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
5811 w32_to_x_weight (fnweight
)
5814 if (fnweight
>= FW_HEAVY
) return "heavy";
5815 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
5816 if (fnweight
>= FW_BOLD
) return "bold";
5817 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
5818 if (fnweight
>= FW_MEDIUM
) return "medium";
5819 if (fnweight
>= FW_NORMAL
) return "normal";
5820 if (fnweight
>= FW_LIGHT
) return "light";
5821 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
5822 if (fnweight
>= FW_THIN
) return "thin";
5828 x_to_w32_charset (lpcs
)
5831 Lisp_Object this_entry
, w32_charset
;
5833 /* Look through w32-charset-info-alist for the character set.
5834 Format of each entry is
5835 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5837 this_entry
= Fassoc (build_string(lpcs
), Vw32_charset_info_alist
);
5839 if (NILP(this_entry
))
5841 /* At startup, we want iso8859-1 fonts to come up properly. */
5842 if (stricmp(lpcs
, "iso8859-1") == 0)
5843 return ANSI_CHARSET
;
5845 return DEFAULT_CHARSET
;
5848 w32_charset
= Fcar (Fcdr (this_entry
));
5850 // Translate Lisp symbol to number.
5851 if (w32_charset
== Qw32_charset_ansi
)
5852 return ANSI_CHARSET
;
5853 if (w32_charset
== Qw32_charset_symbol
)
5854 return SYMBOL_CHARSET
;
5855 if (w32_charset
== Qw32_charset_shiftjis
)
5856 return SHIFTJIS_CHARSET
;
5857 if (w32_charset
== Qw32_charset_hangeul
)
5858 return HANGEUL_CHARSET
;
5859 if (w32_charset
== Qw32_charset_chinesebig5
)
5860 return CHINESEBIG5_CHARSET
;
5861 if (w32_charset
== Qw32_charset_gb2312
)
5862 return GB2312_CHARSET
;
5863 if (w32_charset
== Qw32_charset_oem
)
5865 #ifdef JOHAB_CHARSET
5866 if (w32_charset
== Qw32_charset_johab
)
5867 return JOHAB_CHARSET
;
5868 if (w32_charset
== Qw32_charset_easteurope
)
5869 return EASTEUROPE_CHARSET
;
5870 if (w32_charset
== Qw32_charset_turkish
)
5871 return TURKISH_CHARSET
;
5872 if (w32_charset
== Qw32_charset_baltic
)
5873 return BALTIC_CHARSET
;
5874 if (w32_charset
== Qw32_charset_russian
)
5875 return RUSSIAN_CHARSET
;
5876 if (w32_charset
== Qw32_charset_arabic
)
5877 return ARABIC_CHARSET
;
5878 if (w32_charset
== Qw32_charset_greek
)
5879 return GREEK_CHARSET
;
5880 if (w32_charset
== Qw32_charset_hebrew
)
5881 return HEBREW_CHARSET
;
5882 if (w32_charset
== Qw32_charset_vietnamese
)
5883 return VIETNAMESE_CHARSET
;
5884 if (w32_charset
== Qw32_charset_thai
)
5885 return THAI_CHARSET
;
5886 if (w32_charset
== Qw32_charset_mac
)
5888 #endif /* JOHAB_CHARSET */
5889 #ifdef UNICODE_CHARSET
5890 if (w32_charset
== Qw32_charset_unicode
)
5891 return UNICODE_CHARSET
;
5894 return DEFAULT_CHARSET
;
5899 w32_to_x_charset (fncharset
)
5902 static char buf
[16];
5903 Lisp_Object charset_type
;
5908 /* Handle startup case of w32-charset-info-alist not
5909 being set up yet. */
5910 if (NILP(Vw32_charset_info_alist
))
5912 charset_type
= Qw32_charset_ansi
;
5914 case DEFAULT_CHARSET
:
5915 charset_type
= Qw32_charset_default
;
5917 case SYMBOL_CHARSET
:
5918 charset_type
= Qw32_charset_symbol
;
5920 case SHIFTJIS_CHARSET
:
5921 charset_type
= Qw32_charset_shiftjis
;
5923 case HANGEUL_CHARSET
:
5924 charset_type
= Qw32_charset_hangeul
;
5926 case GB2312_CHARSET
:
5927 charset_type
= Qw32_charset_gb2312
;
5929 case CHINESEBIG5_CHARSET
:
5930 charset_type
= Qw32_charset_chinesebig5
;
5933 charset_type
= Qw32_charset_oem
;
5936 /* More recent versions of Windows (95 and NT4.0) define more
5938 #ifdef EASTEUROPE_CHARSET
5939 case EASTEUROPE_CHARSET
:
5940 charset_type
= Qw32_charset_easteurope
;
5942 case TURKISH_CHARSET
:
5943 charset_type
= Qw32_charset_turkish
;
5945 case BALTIC_CHARSET
:
5946 charset_type
= Qw32_charset_baltic
;
5948 case RUSSIAN_CHARSET
:
5949 charset_type
= Qw32_charset_russian
;
5951 case ARABIC_CHARSET
:
5952 charset_type
= Qw32_charset_arabic
;
5955 charset_type
= Qw32_charset_greek
;
5957 case HEBREW_CHARSET
:
5958 charset_type
= Qw32_charset_hebrew
;
5960 case VIETNAMESE_CHARSET
:
5961 charset_type
= Qw32_charset_vietnamese
;
5964 charset_type
= Qw32_charset_thai
;
5967 charset_type
= Qw32_charset_mac
;
5970 charset_type
= Qw32_charset_johab
;
5974 #ifdef UNICODE_CHARSET
5975 case UNICODE_CHARSET
:
5976 charset_type
= Qw32_charset_unicode
;
5980 /* Encode numerical value of unknown charset. */
5981 sprintf (buf
, "*-#%u", fncharset
);
5987 char * best_match
= NULL
;
5989 /* Look through w32-charset-info-alist for the character set.
5990 Prefer ISO codepages, and prefer lower numbers in the ISO
5991 range. Only return charsets for codepages which are installed.
5993 Format of each entry is
5994 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5996 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5999 Lisp_Object w32_charset
;
6000 Lisp_Object codepage
;
6002 Lisp_Object this_entry
= XCAR (rest
);
6004 /* Skip invalid entries in alist. */
6005 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
6006 || !CONSP (XCDR (this_entry
))
6007 || !SYMBOLP (XCAR (XCDR (this_entry
))))
6010 x_charset
= XSTRING (XCAR (this_entry
))->data
;
6011 w32_charset
= XCAR (XCDR (this_entry
));
6012 codepage
= XCDR (XCDR (this_entry
));
6014 /* Look for Same charset and a valid codepage (or non-int
6015 which means ignore). */
6016 if (w32_charset
== charset_type
6017 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
6018 || IsValidCodePage (XINT (codepage
))))
6020 /* If we don't have a match already, then this is the
6023 best_match
= x_charset
;
6024 /* If this is an ISO codepage, and the best so far isn't,
6025 then this is better. */
6026 else if (stricmp (best_match
, "iso") != 0
6027 && stricmp (x_charset
, "iso") == 0)
6028 best_match
= x_charset
;
6029 /* If both are ISO8859 codepages, choose the one with the
6030 lowest number in the encoding field. */
6031 else if (stricmp (best_match
, "iso8859-") == 0
6032 && stricmp (x_charset
, "iso8859-") == 0)
6034 int best_enc
= atoi (best_match
+ 8);
6035 int this_enc
= atoi (x_charset
+ 8);
6036 if (this_enc
> 0 && this_enc
< best_enc
)
6037 best_match
= x_charset
;
6042 /* If no match, encode the numeric value. */
6045 sprintf (buf
, "*-#%u", fncharset
);
6049 strncpy(buf
, best_match
, 15);
6056 /* Get the Windows codepage corresponding to the specified font. The
6057 charset info in the font name is used to look up
6058 w32-charset-to-codepage-alist. */
6060 w32_codepage_for_font (char *fontname
)
6062 Lisp_Object codepage
, entry
;
6063 char *charset_str
, *charset
, *end
;
6065 if (NILP (Vw32_charset_info_alist
))
6068 /* Extract charset part of font string. */
6069 charset
= xlfd_charset_of_font (fontname
);
6074 charset_str
= (char *) alloca (strlen (charset
));
6075 strcpy (charset_str
, charset
);
6077 /* Remove leading "*-". */
6078 if (strncmp ("*-", charset_str
, 2) == 0)
6079 charset
= charset_str
+ 2;
6081 charset
= charset_str
;
6083 /* Stop match at wildcard (including preceding '-'). */
6084 if (end
= strchr (charset
, '*'))
6086 if (end
> charset
&& *(end
-1) == '-')
6091 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6095 codepage
= Fcdr (Fcdr (entry
));
6097 if (NILP (codepage
))
6099 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
6101 else if (INTEGERP (codepage
))
6102 return XINT (codepage
);
6109 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
6110 LOGFONT
* lplogfont
;
6113 char * specific_charset
;
6117 char height_pixels
[8];
6119 char width_pixels
[8];
6120 char *fontname_dash
;
6121 int display_resy
= one_w32_display_info
.resy
;
6122 int display_resx
= one_w32_display_info
.resx
;
6124 struct coding_system coding
;
6126 if (!lpxstr
) abort ();
6131 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
6132 fonttype
= "raster";
6133 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
6134 fonttype
= "outline";
6136 fonttype
= "unknown";
6138 setup_coding_system (Fcheck_coding_system (Vw32_system_coding_system
),
6140 coding
.src_multibyte
= 0;
6141 coding
.dst_multibyte
= 1;
6142 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6143 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
6145 fontname
= alloca(sizeof(*fontname
) * bufsz
);
6146 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
6147 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
6148 *(fontname
+ coding
.produced
) = '\0';
6150 /* Replace dashes with underscores so the dashes are not
6152 fontname_dash
= fontname
;
6153 while (fontname_dash
= strchr (fontname_dash
, '-'))
6154 *fontname_dash
= '_';
6156 if (lplogfont
->lfHeight
)
6158 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
6159 sprintf (height_dpi
, "%u",
6160 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
6164 strcpy (height_pixels
, "*");
6165 strcpy (height_dpi
, "*");
6167 if (lplogfont
->lfWidth
)
6168 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
6170 strcpy (width_pixels
, "*");
6172 _snprintf (lpxstr
, len
- 1,
6173 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
6174 fonttype
, /* foundry */
6175 fontname
, /* family */
6176 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
6177 lplogfont
->lfItalic
?'i':'r', /* slant */
6179 /* add style name */
6180 height_pixels
, /* pixel size */
6181 height_dpi
, /* point size */
6182 display_resx
, /* resx */
6183 display_resy
, /* resy */
6184 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
6185 ? 'p' : 'c', /* spacing */
6186 width_pixels
, /* avg width */
6187 specific_charset
? specific_charset
6188 : w32_to_x_charset (lplogfont
->lfCharSet
)
6189 /* charset registry and encoding */
6192 lpxstr
[len
- 1] = 0; /* just to be sure */
6197 x_to_w32_font (lpxstr
, lplogfont
)
6199 LOGFONT
* lplogfont
;
6201 struct coding_system coding
;
6203 if (!lplogfont
) return (FALSE
);
6205 memset (lplogfont
, 0, sizeof (*lplogfont
));
6207 /* Set default value for each field. */
6209 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
6210 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
6211 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
6213 /* go for maximum quality */
6214 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
6215 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
6216 lplogfont
->lfQuality
= PROOF_QUALITY
;
6219 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
6220 lplogfont
->lfWeight
= FW_DONTCARE
;
6221 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
6226 /* Provide a simple escape mechanism for specifying Windows font names
6227 * directly -- if font spec does not beginning with '-', assume this
6229 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
6235 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
6236 width
[10], resy
[10], remainder
[20];
6238 int dpi
= one_w32_display_info
.resy
;
6240 fields
= sscanf (lpxstr
,
6241 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%19s",
6242 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
6243 if (fields
== EOF
) return (FALSE
);
6245 /* If wildcards cover more than one field, we don't know which
6246 field is which, so don't fill any in. */
6251 if (fields
> 0 && name
[0] != '*')
6257 (Fcheck_coding_system (Vw32_system_coding_system
), &coding
);
6258 coding
.src_multibyte
= 1;
6259 coding
.dst_multibyte
= 1;
6260 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
6261 buf
= (unsigned char *) alloca (bufsize
);
6262 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6263 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
6264 if (coding
.produced
>= LF_FACESIZE
)
6265 coding
.produced
= LF_FACESIZE
- 1;
6266 buf
[coding
.produced
] = 0;
6267 strcpy (lplogfont
->lfFaceName
, buf
);
6271 lplogfont
->lfFaceName
[0] = '\0';
6276 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6280 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
6284 if (fields
> 0 && pixels
[0] != '*')
6285 lplogfont
->lfHeight
= atoi (pixels
);
6289 if (fields
> 0 && resy
[0] != '*')
6292 if (tem
> 0) dpi
= tem
;
6295 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
6296 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
6299 lplogfont
->lfPitchAndFamily
=
6300 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
6304 if (fields
> 0 && width
[0] != '*')
6305 lplogfont
->lfWidth
= atoi (width
) / 10;
6309 /* Strip the trailing '-' if present. (it shouldn't be, as it
6310 fails the test against xlfd-tight-regexp in fontset.el). */
6312 int len
= strlen (remainder
);
6313 if (len
> 0 && remainder
[len
-1] == '-')
6314 remainder
[len
-1] = 0;
6316 encoding
= remainder
;
6317 if (strncmp (encoding
, "*-", 2) == 0)
6319 lplogfont
->lfCharSet
= x_to_w32_charset (fields
> 0 ? encoding
: "");
6324 char name
[100], height
[10], width
[10], weight
[20];
6326 fields
= sscanf (lpxstr
,
6327 "%99[^:]:%9[^:]:%9[^:]:%19s",
6328 name
, height
, width
, weight
);
6330 if (fields
== EOF
) return (FALSE
);
6334 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
6335 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
6339 lplogfont
->lfFaceName
[0] = 0;
6345 lplogfont
->lfHeight
= atoi (height
);
6350 lplogfont
->lfWidth
= atoi (width
);
6354 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6357 /* This makes TrueType fonts work better. */
6358 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
6363 /* Strip the pixel height and point height from the given xlfd, and
6364 return the pixel height. If no pixel height is specified, calculate
6365 one from the point height, or if that isn't defined either, return
6366 0 (which usually signifies a scalable font).
6369 xlfd_strip_height (char *fontname
)
6371 int pixel_height
, field_number
;
6372 char *read_from
, *write_to
;
6376 pixel_height
= field_number
= 0;
6379 /* Look for height fields. */
6380 for (read_from
= fontname
; *read_from
; read_from
++)
6382 if (*read_from
== '-')
6385 if (field_number
== 7) /* Pixel height. */
6388 write_to
= read_from
;
6390 /* Find end of field. */
6391 for (;*read_from
&& *read_from
!= '-'; read_from
++)
6394 /* Split the fontname at end of field. */
6400 pixel_height
= atoi (write_to
);
6401 /* Blank out field. */
6402 if (read_from
> write_to
)
6407 /* If the pixel height field is at the end (partial xlfd),
6410 return pixel_height
;
6412 /* If we got a pixel height, the point height can be
6413 ignored. Just blank it out and break now. */
6416 /* Find end of point size field. */
6417 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6423 /* Blank out the point size field. */
6424 if (read_from
> write_to
)
6430 return pixel_height
;
6434 /* If the point height is already blank, break now. */
6435 if (*read_from
== '-')
6441 else if (field_number
== 8)
6443 /* If we didn't get a pixel height, try to get the point
6444 height and convert that. */
6446 char *point_size_start
= read_from
++;
6448 /* Find end of field. */
6449 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6458 point_size
= atoi (point_size_start
);
6460 /* Convert to pixel height. */
6461 pixel_height
= point_size
6462 * one_w32_display_info
.height_in
/ 720;
6464 /* Blank out this field and break. */
6472 /* Shift the rest of the font spec into place. */
6473 if (write_to
&& read_from
> write_to
)
6475 for (; *read_from
; read_from
++, write_to
++)
6476 *write_to
= *read_from
;
6480 return pixel_height
;
6483 /* Assume parameter 1 is fully qualified, no wildcards. */
6485 w32_font_match (fontname
, pattern
)
6489 char *regex
= alloca (strlen (pattern
) * 2 + 3);
6490 char *font_name_copy
= alloca (strlen (fontname
) + 1);
6493 /* Copy fontname so we can modify it during comparison. */
6494 strcpy (font_name_copy
, fontname
);
6499 /* Turn pattern into a regexp and do a regexp match. */
6500 for (; *pattern
; pattern
++)
6502 if (*pattern
== '?')
6504 else if (*pattern
== '*')
6515 /* Strip out font heights and compare them seperately, since
6516 rounding error can cause mismatches. This also allows a
6517 comparison between a font that declares only a pixel height and a
6518 pattern that declares the point height.
6521 int font_height
, pattern_height
;
6523 font_height
= xlfd_strip_height (font_name_copy
);
6524 pattern_height
= xlfd_strip_height (regex
);
6526 /* Compare now, and don't bother doing expensive regexp matching
6527 if the heights differ. */
6528 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
6532 return (fast_c_string_match_ignore_case (build_string (regex
),
6533 font_name_copy
) >= 0);
6536 /* Callback functions, and a structure holding info they need, for
6537 listing system fonts on W32. We need one set of functions to do the
6538 job properly, but these don't work on NT 3.51 and earlier, so we
6539 have a second set which don't handle character sets properly to
6542 In both cases, there are two passes made. The first pass gets one
6543 font from each family, the second pass lists all the fonts from
6546 typedef struct enumfont_t
6551 XFontStruct
*size_ref
;
6552 Lisp_Object
*pattern
;
6557 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
6559 NEWTEXTMETRIC
* lptm
;
6563 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
6566 /* Check that the character set matches if it was specified */
6567 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6568 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6573 Lisp_Object width
= Qnil
;
6574 char *charset
= NULL
;
6576 /* Truetype fonts do not report their true metrics until loaded */
6577 if (FontType
!= RASTER_FONTTYPE
)
6579 if (!NILP (*(lpef
->pattern
)))
6581 /* Scalable fonts are as big as you want them to be. */
6582 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6583 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6584 width
= make_number (lpef
->logfont
.lfWidth
);
6588 lplf
->elfLogFont
.lfHeight
= 0;
6589 lplf
->elfLogFont
.lfWidth
= 0;
6593 /* Make sure the height used here is the same as everywhere
6594 else (ie character height, not cell height). */
6595 if (lplf
->elfLogFont
.lfHeight
> 0)
6597 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6598 if (FontType
== RASTER_FONTTYPE
)
6599 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6601 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6604 if (!NILP (*(lpef
->pattern
)))
6606 charset
= xlfd_charset_of_font (XSTRING(*(lpef
->pattern
))->data
);
6608 /* Ensure that charset is valid for this font. */
6610 && (x_to_w32_charset (charset
) != lplf
->elfLogFont
.lfCharSet
))
6614 /* TODO: List all relevant charsets if charset not specified. */
6615 if (!w32_to_x_font (&(lplf
->elfLogFont
), buf
, 100, charset
))
6618 if (NILP (*(lpef
->pattern
))
6619 || w32_font_match (buf
, XSTRING (*(lpef
->pattern
))->data
))
6621 *lpef
->tail
= Fcons (Fcons (build_string (buf
), width
), Qnil
);
6622 lpef
->tail
= &(XCDR (*lpef
->tail
));
6631 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6633 NEWTEXTMETRIC
* lptm
;
6637 return EnumFontFamilies (lpef
->hdc
,
6638 lplf
->elfLogFont
.lfFaceName
,
6639 (FONTENUMPROC
) enum_font_cb2
,
6645 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6646 ENUMLOGFONTEX
* lplf
;
6647 NEWTEXTMETRICEX
* lptm
;
6651 /* We are not interested in the extra info we get back from the 'Ex
6652 version - only the fact that we get character set variations
6653 enumerated seperately. */
6654 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6659 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6660 ENUMLOGFONTEX
* lplf
;
6661 NEWTEXTMETRICEX
* lptm
;
6665 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6666 FARPROC enum_font_families_ex
6667 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6668 /* We don't really expect EnumFontFamiliesEx to disappear once we
6669 get here, so don't bother handling it gracefully. */
6670 if (enum_font_families_ex
== NULL
)
6671 error ("gdi32.dll has disappeared!");
6672 return enum_font_families_ex (lpef
->hdc
,
6674 (FONTENUMPROC
) enum_fontex_cb2
,
6678 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6679 and xterm.c in Emacs 20.3) */
6681 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6683 char *fontname
, *ptnstr
;
6684 Lisp_Object list
, tem
, newlist
= Qnil
;
6687 list
= Vw32_bdf_filename_alist
;
6688 ptnstr
= XSTRING (pattern
)->data
;
6690 for ( ; CONSP (list
); list
= XCDR (list
))
6694 fontname
= XSTRING (XCAR (tem
))->data
;
6695 else if (STRINGP (tem
))
6696 fontname
= XSTRING (tem
)->data
;
6700 if (w32_font_match (fontname
, ptnstr
))
6702 newlist
= Fcons (XCAR (tem
), newlist
);
6704 if (n_fonts
>= max_names
)
6712 static Lisp_Object
w32_list_synthesized_fonts (FRAME_PTR f
,
6713 Lisp_Object pattern
,
6714 int size
, int max_names
);
6716 /* Return a list of names of available fonts matching PATTERN on frame
6717 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6718 to be listed. Frame F NULL means we have not yet created any
6719 frame, which means we can't get proper size info, as we don't have
6720 a device context to use for GetTextMetrics.
6721 MAXNAMES sets a limit on how many fonts to match. */
6724 w32_list_fonts (f
, pattern
, size
, maxnames
)
6726 Lisp_Object pattern
;
6730 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6731 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6732 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6735 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6736 if (NILP (patterns
))
6737 patterns
= Fcons (pattern
, Qnil
);
6739 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6744 tpat
= XCAR (patterns
);
6746 if (!STRINGP (tpat
))
6749 /* Avoid expensive EnumFontFamilies functions if we are not
6750 going to be able to output one of these anyway. */
6751 codepage
= w32_codepage_for_font (XSTRING (tpat
)->data
);
6752 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6753 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6754 && !IsValidCodePage(codepage
))
6757 /* See if we cached the result for this particular query.
6758 The cache is an alist of the form:
6759 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6761 if (tem
= XCDR (dpyinfo
->name_list_element
),
6762 !NILP (list
= Fassoc (tpat
, tem
)))
6764 list
= Fcdr_safe (list
);
6765 /* We have a cached list. Don't have to get the list again. */
6770 /* At first, put PATTERN in the cache. */
6776 /* Use EnumFontFamiliesEx where it is available, as it knows
6777 about character sets. Fall back to EnumFontFamilies for
6778 older versions of NT that don't support the 'Ex function. */
6779 x_to_w32_font (XSTRING (tpat
)->data
, &ef
.logfont
);
6781 LOGFONT font_match_pattern
;
6782 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6783 FARPROC enum_font_families_ex
6784 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6786 /* We do our own pattern matching so we can handle wildcards. */
6787 font_match_pattern
.lfFaceName
[0] = 0;
6788 font_match_pattern
.lfPitchAndFamily
= 0;
6789 /* We can use the charset, because if it is a wildcard it will
6790 be DEFAULT_CHARSET anyway. */
6791 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6793 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6795 if (enum_font_families_ex
)
6796 enum_font_families_ex (ef
.hdc
,
6797 &font_match_pattern
,
6798 (FONTENUMPROC
) enum_fontex_cb1
,
6801 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6804 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6809 /* Make a list of the fonts we got back.
6810 Store that in the font cache for the display. */
6811 XCDR (dpyinfo
->name_list_element
)
6812 = Fcons (Fcons (tpat
, list
),
6813 XCDR (dpyinfo
->name_list_element
));
6816 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6818 newlist
= second_best
= Qnil
;
6820 /* Make a list of the fonts that have the right width. */
6821 for (; CONSP (list
); list
= XCDR (list
))
6828 if (NILP (XCAR (tem
)))
6832 newlist
= Fcons (XCAR (tem
), newlist
);
6834 if (n_fonts
>= maxnames
)
6839 if (!INTEGERP (XCDR (tem
)))
6841 /* Since we don't yet know the size of the font, we must
6842 load it and try GetTextMetrics. */
6843 W32FontStruct thisinfo
;
6848 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
6852 thisinfo
.bdf
= NULL
;
6853 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6854 if (thisinfo
.hfont
== NULL
)
6857 hdc
= GetDC (dpyinfo
->root_window
);
6858 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6859 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6860 XCDR (tem
) = make_number (FONT_WIDTH (&thisinfo
));
6862 XCDR (tem
) = make_number (0);
6863 SelectObject (hdc
, oldobj
);
6864 ReleaseDC (dpyinfo
->root_window
, hdc
);
6865 DeleteObject(thisinfo
.hfont
);
6868 found_size
= XINT (XCDR (tem
));
6869 if (found_size
== size
)
6871 newlist
= Fcons (XCAR (tem
), newlist
);
6873 if (n_fonts
>= maxnames
)
6876 /* keep track of the closest matching size in case
6877 no exact match is found. */
6878 else if (found_size
> 0)
6880 if (NILP (second_best
))
6883 else if (found_size
< size
)
6885 if (XINT (XCDR (second_best
)) > size
6886 || XINT (XCDR (second_best
)) < found_size
)
6891 if (XINT (XCDR (second_best
)) > size
6892 && XINT (XCDR (second_best
)) >
6899 if (!NILP (newlist
))
6901 else if (!NILP (second_best
))
6903 newlist
= Fcons (XCAR (second_best
), Qnil
);
6908 /* Include any bdf fonts. */
6909 if (n_fonts
< maxnames
)
6911 Lisp_Object combined
[2];
6912 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6913 combined
[1] = newlist
;
6914 newlist
= Fnconc(2, combined
);
6917 /* If we can't find a font that matches, check if Windows would be
6918 able to synthesize it from a different style. */
6919 if (NILP (newlist
) && !NILP (Vw32_enable_synthesized_fonts
))
6920 newlist
= w32_list_synthesized_fonts (f
, pattern
, size
, maxnames
);
6926 w32_list_synthesized_fonts (f
, pattern
, size
, max_names
)
6928 Lisp_Object pattern
;
6933 char *full_pattn
, *new_pattn
, foundary
[50], family
[50], *pattn_part2
;
6934 char style
[20], slant
;
6935 Lisp_Object matches
, tem
, synthed_matches
= Qnil
;
6937 full_pattn
= XSTRING (pattern
)->data
;
6939 pattn_part2
= alloca (XSTRING (pattern
)->size
);
6940 /* Allow some space for wildcard expansion. */
6941 new_pattn
= alloca (XSTRING (pattern
)->size
+ 100);
6943 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%19[^-]-%c-%s",
6944 foundary
, family
, style
, &slant
, pattn_part2
);
6945 if (fields
== EOF
|| fields
< 5)
6948 /* If the style and slant are wildcards already there is no point
6949 checking again (and we don't want to keep recursing). */
6950 if (*style
== '*' && slant
== '*')
6953 sprintf (new_pattn
, "-%s-%s-*-*-%s", foundary
, family
, pattn_part2
);
6955 matches
= w32_list_fonts (f
, build_string (new_pattn
), size
, max_names
);
6957 for ( ; CONSP (matches
); matches
= XCDR (matches
))
6959 tem
= XCAR (matches
);
6963 full_pattn
= XSTRING (tem
)->data
;
6964 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%*[^-]-%*c-%s",
6965 foundary
, family
, pattn_part2
);
6966 if (fields
== EOF
|| fields
< 3)
6969 sprintf (new_pattn
, "-%s-%s-%s-%c-%s", foundary
, family
, style
,
6970 slant
, pattn_part2
);
6972 synthed_matches
= Fcons (build_string (new_pattn
),
6976 return synthed_matches
;
6980 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6982 w32_get_font_info (f
, font_idx
)
6986 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6991 w32_query_font (struct frame
*f
, char *fontname
)
6994 struct font_info
*pfi
;
6996 pfi
= FRAME_W32_FONT_TABLE (f
);
6998 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
7000 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
7006 /* Find a CCL program for a font specified by FONTP, and set the member
7007 `encoder' of the structure. */
7010 w32_find_ccl_program (fontp
)
7011 struct font_info
*fontp
;
7013 Lisp_Object list
, elt
;
7015 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
7019 && STRINGP (XCAR (elt
))
7020 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
7026 struct ccl_program
*ccl
7027 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
7029 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
7032 fontp
->font_encoder
= ccl
;
7037 /* Find BDF files in a specified directory. (use GCPRO when calling,
7038 as this calls lisp to get a directory listing). */
7040 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
7042 Lisp_Object filelist
, list
= Qnil
;
7045 if (!STRINGP(directory
))
7048 filelist
= Fdirectory_files (directory
, Qt
,
7049 build_string (".*\\.[bB][dD][fF]"), Qt
);
7051 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
7053 Lisp_Object filename
= XCAR (filelist
);
7054 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
7055 store_in_alist (&list
, build_string (fontname
), filename
);
7060 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
7062 "Return a list of BDF fonts in DIR, suitable for appending to\n\
7063 w32-bdf-filename-alist. Fonts which do not contain an xlfd description\n\
7064 will not be included in the list. DIR may be a list of directories.")
7066 Lisp_Object directory
;
7068 Lisp_Object list
= Qnil
;
7069 struct gcpro gcpro1
, gcpro2
;
7071 if (!CONSP (directory
))
7072 return w32_find_bdf_fonts_in_dir (directory
);
7074 for ( ; CONSP (directory
); directory
= XCDR (directory
))
7076 Lisp_Object pair
[2];
7079 GCPRO2 (directory
, list
);
7080 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
7081 list
= Fnconc( 2, pair
);
7088 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
7089 "Internal function called by `color-defined-p', which see.")
7091 Lisp_Object color
, frame
;
7094 FRAME_PTR f
= check_x_frame (frame
);
7096 CHECK_STRING (color
, 1);
7098 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7104 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
7105 "Internal function called by `color-values', which see.")
7107 Lisp_Object color
, frame
;
7110 FRAME_PTR f
= check_x_frame (frame
);
7112 CHECK_STRING (color
, 1);
7114 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7118 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
7119 | GetRValue (foo
.pixel
));
7120 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
7121 | GetGValue (foo
.pixel
));
7122 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
7123 | GetBValue (foo
.pixel
));
7124 return Flist (3, rgb
);
7130 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
7131 "Internal function called by `display-color-p', which see.")
7133 Lisp_Object display
;
7135 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7137 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
7143 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
7145 "Return t if the X display supports shades of gray.\n\
7146 Note that color displays do support shades of gray.\n\
7147 The optional argument DISPLAY specifies which display to ask about.\n\
7148 DISPLAY should be either a frame or a display name (a string).\n\
7149 If omitted or nil, that stands for the selected frame's display.")
7151 Lisp_Object display
;
7153 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7155 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
7161 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
7163 "Returns the width in pixels of the X display DISPLAY.\n\
7164 The optional argument DISPLAY specifies which display to ask about.\n\
7165 DISPLAY should be either a frame or a display name (a string).\n\
7166 If omitted or nil, that stands for the selected frame's display.")
7168 Lisp_Object display
;
7170 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7172 return make_number (dpyinfo
->width
);
7175 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
7176 Sx_display_pixel_height
, 0, 1, 0,
7177 "Returns the height in pixels of the X display DISPLAY.\n\
7178 The optional argument DISPLAY specifies which display to ask about.\n\
7179 DISPLAY should be either a frame or a display name (a string).\n\
7180 If omitted or nil, that stands for the selected frame's display.")
7182 Lisp_Object display
;
7184 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7186 return make_number (dpyinfo
->height
);
7189 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
7191 "Returns the number of bitplanes of the display DISPLAY.\n\
7192 The optional argument DISPLAY specifies which display to ask about.\n\
7193 DISPLAY should be either a frame or a display name (a string).\n\
7194 If omitted or nil, that stands for the selected frame's display.")
7196 Lisp_Object display
;
7198 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7200 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7203 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
7205 "Returns the number of color cells of the display DISPLAY.\n\
7206 The optional argument DISPLAY specifies which display to ask about.\n\
7207 DISPLAY should be either a frame or a display name (a string).\n\
7208 If omitted or nil, that stands for the selected frame's display.")
7210 Lisp_Object display
;
7212 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7216 hdc
= GetDC (dpyinfo
->root_window
);
7217 if (dpyinfo
->has_palette
)
7218 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
7220 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
7223 cap
= 1 << (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7225 ReleaseDC (dpyinfo
->root_window
, hdc
);
7227 return make_number (cap
);
7230 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
7231 Sx_server_max_request_size
,
7233 "Returns the maximum request size of the server of display DISPLAY.\n\
7234 The optional argument DISPLAY specifies which display to ask about.\n\
7235 DISPLAY should be either a frame or a display name (a string).\n\
7236 If omitted or nil, that stands for the selected frame's display.")
7238 Lisp_Object display
;
7240 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7242 return make_number (1);
7245 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
7246 "Returns the vendor ID string of the W32 system (Microsoft).\n\
7247 The optional argument DISPLAY specifies which display to ask about.\n\
7248 DISPLAY should be either a frame or a display name (a string).\n\
7249 If omitted or nil, that stands for the selected frame's display.")
7251 Lisp_Object display
;
7253 return build_string ("Microsoft Corp.");
7256 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
7257 "Returns the version numbers of the server of display DISPLAY.\n\
7258 The value is a list of three integers: the major and minor\n\
7259 version numbers, and the vendor-specific release\n\
7260 number. See also the function `x-server-vendor'.\n\n\
7261 The optional argument DISPLAY specifies which display to ask about.\n\
7262 DISPLAY should be either a frame or a display name (a string).\n\
7263 If omitted or nil, that stands for the selected frame's display.")
7265 Lisp_Object display
;
7267 return Fcons (make_number (w32_major_version
),
7268 Fcons (make_number (w32_minor_version
),
7269 Fcons (make_number (w32_build_number
), Qnil
)));
7272 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
7273 "Returns the number of screens on the server of display DISPLAY.\n\
7274 The optional argument DISPLAY specifies which display to ask about.\n\
7275 DISPLAY should be either a frame or a display name (a string).\n\
7276 If omitted or nil, that stands for the selected frame's display.")
7278 Lisp_Object display
;
7280 return make_number (1);
7283 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
7284 "Returns the height in millimeters of the X display DISPLAY.\n\
7285 The optional argument DISPLAY specifies which display to ask about.\n\
7286 DISPLAY should be either a frame or a display name (a string).\n\
7287 If omitted or nil, that stands for the selected frame's display.")
7289 Lisp_Object display
;
7291 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7295 hdc
= GetDC (dpyinfo
->root_window
);
7297 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
7299 ReleaseDC (dpyinfo
->root_window
, hdc
);
7301 return make_number (cap
);
7304 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
7305 "Returns the width in millimeters of the X display DISPLAY.\n\
7306 The optional argument DISPLAY specifies which display to ask about.\n\
7307 DISPLAY should be either a frame or a display name (a string).\n\
7308 If omitted or nil, that stands for the selected frame's display.")
7310 Lisp_Object display
;
7312 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7317 hdc
= GetDC (dpyinfo
->root_window
);
7319 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
7321 ReleaseDC (dpyinfo
->root_window
, hdc
);
7323 return make_number (cap
);
7326 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
7327 Sx_display_backing_store
, 0, 1, 0,
7328 "Returns an indication of whether display DISPLAY does backing store.\n\
7329 The value may be `always', `when-mapped', or `not-useful'.\n\
7330 The optional argument DISPLAY specifies which display to ask about.\n\
7331 DISPLAY should be either a frame or a display name (a string).\n\
7332 If omitted or nil, that stands for the selected frame's display.")
7334 Lisp_Object display
;
7336 return intern ("not-useful");
7339 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
7340 Sx_display_visual_class
, 0, 1, 0,
7341 "Returns the visual class of the display DISPLAY.\n\
7342 The value is one of the symbols `static-gray', `gray-scale',\n\
7343 `static-color', `pseudo-color', `true-color', or `direct-color'.\n\n\
7344 The optional argument DISPLAY specifies which display to ask about.\n\
7345 DISPLAY should be either a frame or a display name (a string).\n\
7346 If omitted or nil, that stands for the selected frame's display.")
7348 Lisp_Object display
;
7350 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7351 Lisp_Object result
= Qnil
;
7353 if (dpyinfo
->has_palette
)
7354 result
= intern ("pseudo-color");
7355 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
7356 result
= intern ("static-grey");
7357 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
7358 result
= intern ("static-color");
7359 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
7360 result
= intern ("true-color");
7365 DEFUN ("x-display-save-under", Fx_display_save_under
,
7366 Sx_display_save_under
, 0, 1, 0,
7367 "Returns t if the display DISPLAY supports the save-under feature.\n\
7368 The optional argument DISPLAY specifies which display to ask about.\n\
7369 DISPLAY should be either a frame or a display name (a string).\n\
7370 If omitted or nil, that stands for the selected frame's display.")
7372 Lisp_Object display
;
7379 register struct frame
*f
;
7381 return PIXEL_WIDTH (f
);
7386 register struct frame
*f
;
7388 return PIXEL_HEIGHT (f
);
7393 register struct frame
*f
;
7395 return FONT_WIDTH (f
->output_data
.w32
->font
);
7400 register struct frame
*f
;
7402 return f
->output_data
.w32
->line_height
;
7407 register struct frame
*f
;
7409 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
7412 /* Return the display structure for the display named NAME.
7413 Open a new connection if necessary. */
7415 struct w32_display_info
*
7416 x_display_info_for_name (name
)
7420 struct w32_display_info
*dpyinfo
;
7422 CHECK_STRING (name
, 0);
7424 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
7426 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
7429 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
7434 /* Use this general default value to start with. */
7435 Vx_resource_name
= Vinvocation_name
;
7437 validate_x_resource_name ();
7439 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
7440 (char *) XSTRING (Vx_resource_name
)->data
);
7443 error ("Cannot connect to server %s", XSTRING (name
)->data
);
7446 XSETFASTINT (Vwindow_system_version
, 3);
7451 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
7452 1, 3, 0, "Open a connection to a server.\n\
7453 DISPLAY is the name of the display to connect to.\n\
7454 Optional second arg XRM-STRING is a string of resources in xrdb format.\n\
7455 If the optional third arg MUST-SUCCEED is non-nil,\n\
7456 terminate Emacs if we can't open the connection.")
7457 (display
, xrm_string
, must_succeed
)
7458 Lisp_Object display
, xrm_string
, must_succeed
;
7460 unsigned char *xrm_option
;
7461 struct w32_display_info
*dpyinfo
;
7463 CHECK_STRING (display
, 0);
7464 if (! NILP (xrm_string
))
7465 CHECK_STRING (xrm_string
, 1);
7467 if (! EQ (Vwindow_system
, intern ("w32")))
7468 error ("Not using Microsoft Windows");
7470 /* Allow color mapping to be defined externally; first look in user's
7471 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
7473 Lisp_Object color_file
;
7474 struct gcpro gcpro1
;
7476 color_file
= build_string("~/rgb.txt");
7478 GCPRO1 (color_file
);
7480 if (NILP (Ffile_readable_p (color_file
)))
7482 Fexpand_file_name (build_string ("rgb.txt"),
7483 Fsymbol_value (intern ("data-directory")));
7485 Vw32_color_map
= Fw32_load_color_file (color_file
);
7489 if (NILP (Vw32_color_map
))
7490 Vw32_color_map
= Fw32_default_color_map ();
7492 if (! NILP (xrm_string
))
7493 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
7495 xrm_option
= (unsigned char *) 0;
7497 /* Use this general default value to start with. */
7498 /* First remove .exe suffix from invocation-name - it looks ugly. */
7500 char basename
[ MAX_PATH
], *str
;
7502 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
7503 str
= strrchr (basename
, '.');
7505 Vinvocation_name
= build_string (basename
);
7507 Vx_resource_name
= Vinvocation_name
;
7509 validate_x_resource_name ();
7511 /* This is what opens the connection and sets x_current_display.
7512 This also initializes many symbols, such as those used for input. */
7513 dpyinfo
= w32_term_init (display
, xrm_option
,
7514 (char *) XSTRING (Vx_resource_name
)->data
);
7518 if (!NILP (must_succeed
))
7519 fatal ("Cannot connect to server %s.\n",
7520 XSTRING (display
)->data
);
7522 error ("Cannot connect to server %s", XSTRING (display
)->data
);
7527 XSETFASTINT (Vwindow_system_version
, 3);
7531 DEFUN ("x-close-connection", Fx_close_connection
,
7532 Sx_close_connection
, 1, 1, 0,
7533 "Close the connection to DISPLAY's server.\n\
7534 For DISPLAY, specify either a frame or a display name (a string).\n\
7535 If DISPLAY is nil, that stands for the selected frame's display.")
7537 Lisp_Object display
;
7539 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7542 if (dpyinfo
->reference_count
> 0)
7543 error ("Display still has frames on it");
7546 /* Free the fonts in the font table. */
7547 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7548 if (dpyinfo
->font_table
[i
].name
)
7550 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7551 xfree (dpyinfo
->font_table
[i
].full_name
);
7552 xfree (dpyinfo
->font_table
[i
].name
);
7553 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7555 x_destroy_all_bitmaps (dpyinfo
);
7557 x_delete_display (dpyinfo
);
7563 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7564 "Return the list of display names that Emacs has connections to.")
7567 Lisp_Object tail
, result
;
7570 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
7571 result
= Fcons (XCAR (XCAR (tail
)), result
);
7576 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7577 "If ON is non-nil, report errors as soon as the erring request is made.\n\
7578 If ON is nil, allow buffering of requests.\n\
7579 This is a noop on W32 systems.\n\
7580 The optional second argument DISPLAY specifies which display to act on.\n\
7581 DISPLAY should be either a frame or a display name (a string).\n\
7582 If DISPLAY is omitted or nil, that stands for the selected frame's display.")
7584 Lisp_Object display
, on
;
7591 /***********************************************************************
7593 ***********************************************************************/
7595 /* Value is the number of elements of vector VECTOR. */
7597 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
7599 /* List of supported image types. Use define_image_type to add new
7600 types. Use lookup_image_type to find a type for a given symbol. */
7602 static struct image_type
*image_types
;
7604 /* The symbol `image' which is the car of the lists used to represent
7607 extern Lisp_Object Qimage
;
7609 /* The symbol `xbm' which is used as the type symbol for XBM images. */
7615 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
7616 extern Lisp_Object QCdata
;
7617 Lisp_Object QCtype
, QCascent
, QCmargin
, QCrelief
;
7618 Lisp_Object QCconversion
, QCcolor_symbols
, QCheuristic_mask
;
7619 Lisp_Object QCindex
;
7621 /* Other symbols. */
7623 Lisp_Object Qlaplace
;
7625 /* Time in seconds after which images should be removed from the cache
7626 if not displayed. */
7628 Lisp_Object Vimage_cache_eviction_delay
;
7630 /* Function prototypes. */
7632 static void define_image_type
P_ ((struct image_type
*type
));
7633 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
7634 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
7635 static void x_laplace
P_ ((struct frame
*, struct image
*));
7636 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
7640 /* Define a new image type from TYPE. This adds a copy of TYPE to
7641 image_types and adds the symbol *TYPE->type to Vimage_types. */
7644 define_image_type (type
)
7645 struct image_type
*type
;
7647 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
7648 The initialized data segment is read-only. */
7649 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
7650 bcopy (type
, p
, sizeof *p
);
7651 p
->next
= image_types
;
7653 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
7657 /* Look up image type SYMBOL, and return a pointer to its image_type
7658 structure. Value is null if SYMBOL is not a known image type. */
7660 static INLINE
struct image_type
*
7661 lookup_image_type (symbol
)
7664 struct image_type
*type
;
7666 for (type
= image_types
; type
; type
= type
->next
)
7667 if (EQ (symbol
, *type
->type
))
7674 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
7675 valid image specification is a list whose car is the symbol
7676 `image', and whose rest is a property list. The property list must
7677 contain a value for key `:type'. That value must be the name of a
7678 supported image type. The rest of the property list depends on the
7682 valid_image_p (object
)
7687 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
7689 Lisp_Object symbol
= Fplist_get (XCDR (object
), QCtype
);
7690 struct image_type
*type
= lookup_image_type (symbol
);
7693 valid_p
= type
->valid_p (object
);
7700 /* Log error message with format string FORMAT and argument ARG.
7701 Signaling an error, e.g. when an image cannot be loaded, is not a
7702 good idea because this would interrupt redisplay, and the error
7703 message display would lead to another redisplay. This function
7704 therefore simply displays a message. */
7707 image_error (format
, arg1
, arg2
)
7709 Lisp_Object arg1
, arg2
;
7711 add_to_log (format
, arg1
, arg2
);
7716 /***********************************************************************
7717 Image specifications
7718 ***********************************************************************/
7720 enum image_value_type
7722 IMAGE_DONT_CHECK_VALUE_TYPE
,
7725 IMAGE_POSITIVE_INTEGER_VALUE
,
7726 IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
,
7727 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
7729 IMAGE_INTEGER_VALUE
,
7730 IMAGE_FUNCTION_VALUE
,
7735 /* Structure used when parsing image specifications. */
7737 struct image_keyword
7739 /* Name of keyword. */
7742 /* The type of value allowed. */
7743 enum image_value_type type
;
7745 /* Non-zero means key must be present. */
7748 /* Used to recognize duplicate keywords in a property list. */
7751 /* The value that was found. */
7756 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
7758 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
7761 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
7762 has the format (image KEYWORD VALUE ...). One of the keyword/
7763 value pairs must be `:type TYPE'. KEYWORDS is a vector of
7764 image_keywords structures of size NKEYWORDS describing other
7765 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
7768 parse_image_spec (spec
, keywords
, nkeywords
, type
)
7770 struct image_keyword
*keywords
;
7777 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
7780 plist
= XCDR (spec
);
7781 while (CONSP (plist
))
7783 Lisp_Object key
, value
;
7785 /* First element of a pair must be a symbol. */
7787 plist
= XCDR (plist
);
7791 /* There must follow a value. */
7794 value
= XCAR (plist
);
7795 plist
= XCDR (plist
);
7797 /* Find key in KEYWORDS. Error if not found. */
7798 for (i
= 0; i
< nkeywords
; ++i
)
7799 if (strcmp (keywords
[i
].name
, XSYMBOL (key
)->name
->data
) == 0)
7805 /* Record that we recognized the keyword. If a keywords
7806 was found more than once, it's an error. */
7807 keywords
[i
].value
= value
;
7808 ++keywords
[i
].count
;
7810 if (keywords
[i
].count
> 1)
7813 /* Check type of value against allowed type. */
7814 switch (keywords
[i
].type
)
7816 case IMAGE_STRING_VALUE
:
7817 if (!STRINGP (value
))
7821 case IMAGE_SYMBOL_VALUE
:
7822 if (!SYMBOLP (value
))
7826 case IMAGE_POSITIVE_INTEGER_VALUE
:
7827 if (!INTEGERP (value
) || XINT (value
) <= 0)
7831 case IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
:
7832 if (INTEGERP (value
) && XINT (value
) >= 0)
7835 && INTEGERP (XCAR (value
)) && INTEGERP (XCDR (value
))
7836 && XINT (XCAR (value
)) >= 0 && XINT (XCDR (value
)) >= 0)
7840 case IMAGE_ASCENT_VALUE
:
7841 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
7843 else if (INTEGERP (value
)
7844 && XINT (value
) >= 0
7845 && XINT (value
) <= 100)
7849 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
7850 if (!INTEGERP (value
) || XINT (value
) < 0)
7854 case IMAGE_DONT_CHECK_VALUE_TYPE
:
7857 case IMAGE_FUNCTION_VALUE
:
7858 value
= indirect_function (value
);
7860 || COMPILEDP (value
)
7861 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
7865 case IMAGE_NUMBER_VALUE
:
7866 if (!INTEGERP (value
) && !FLOATP (value
))
7870 case IMAGE_INTEGER_VALUE
:
7871 if (!INTEGERP (value
))
7875 case IMAGE_BOOL_VALUE
:
7876 if (!NILP (value
) && !EQ (value
, Qt
))
7885 if (EQ (key
, QCtype
) && !EQ (type
, value
))
7889 /* Check that all mandatory fields are present. */
7890 for (i
= 0; i
< nkeywords
; ++i
)
7891 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
7894 return NILP (plist
);
7898 /* Return the value of KEY in image specification SPEC. Value is nil
7899 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
7900 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
7903 image_spec_value (spec
, key
, found
)
7904 Lisp_Object spec
, key
;
7909 xassert (valid_image_p (spec
));
7911 for (tail
= XCDR (spec
);
7912 CONSP (tail
) && CONSP (XCDR (tail
));
7913 tail
= XCDR (XCDR (tail
)))
7915 if (EQ (XCAR (tail
), key
))
7919 return XCAR (XCDR (tail
));
7931 /***********************************************************************
7932 Image type independent image structures
7933 ***********************************************************************/
7935 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
7936 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
7939 /* Allocate and return a new image structure for image specification
7940 SPEC. SPEC has a hash value of HASH. */
7942 static struct image
*
7943 make_image (spec
, hash
)
7947 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
7949 xassert (valid_image_p (spec
));
7950 bzero (img
, sizeof *img
);
7951 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
7952 xassert (img
->type
!= NULL
);
7954 img
->data
.lisp_val
= Qnil
;
7955 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
7961 /* Free image IMG which was used on frame F, including its resources. */
7970 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7972 /* Remove IMG from the hash table of its cache. */
7974 img
->prev
->next
= img
->next
;
7976 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
7979 img
->next
->prev
= img
->prev
;
7981 c
->images
[img
->id
] = NULL
;
7983 /* Free resources, then free IMG. */
7984 img
->type
->free (f
, img
);
7990 /* Prepare image IMG for display on frame F. Must be called before
7991 drawing an image. */
7994 prepare_image_for_display (f
, img
)
8000 /* We're about to display IMG, so set its timestamp to `now'. */
8002 img
->timestamp
= EMACS_SECS (t
);
8004 /* If IMG doesn't have a pixmap yet, load it now, using the image
8005 type dependent loader function. */
8006 if (img
->pixmap
== 0 && !img
->load_failed_p
)
8007 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8011 /* Value is the number of pixels for the ascent of image IMG when
8012 drawn in face FACE. */
8015 image_ascent (img
, face
)
8019 int height
= img
->height
+ img
->vmargin
;
8022 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
8025 ascent
= height
/ 2 - (FONT_DESCENT(face
->font
)
8026 - FONT_BASE(face
->font
)) / 2;
8028 ascent
= height
/ 2;
8031 ascent
= height
* img
->ascent
/ 100.0;
8038 /***********************************************************************
8039 Helper functions for X image types
8040 ***********************************************************************/
8042 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
8043 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
8045 Lisp_Object color_name
,
8046 unsigned long dflt
));
8048 /* Free X resources of image IMG which is used on frame F. */
8051 x_clear_image (f
, img
)
8055 #if 0 /* TODO: W32 image support */
8060 XFreePixmap (NULL
, img
->pixmap
);
8067 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
8069 /* If display has an immutable color map, freeing colors is not
8070 necessary and some servers don't allow it. So don't do it. */
8071 if (class != StaticColor
8072 && class != StaticGray
8073 && class != TrueColor
)
8077 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
8078 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
8083 xfree (img
->colors
);
8091 /* Allocate color COLOR_NAME for image IMG on frame F. If color
8092 cannot be allocated, use DFLT. Add a newly allocated color to
8093 IMG->colors, so that it can be freed again. Value is the pixel
8096 static unsigned long
8097 x_alloc_image_color (f
, img
, color_name
, dflt
)
8100 Lisp_Object color_name
;
8103 #if 0 /* TODO: allocing colors. */
8105 unsigned long result
;
8107 xassert (STRINGP (color_name
));
8109 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
8111 /* This isn't called frequently so we get away with simply
8112 reallocating the color vector to the needed size, here. */
8115 (unsigned long *) xrealloc (img
->colors
,
8116 img
->ncolors
* sizeof *img
->colors
);
8117 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
8118 result
= color
.pixel
;
8129 /***********************************************************************
8131 ***********************************************************************/
8133 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
8136 /* Return a new, initialized image cache that is allocated from the
8137 heap. Call free_image_cache to free an image cache. */
8139 struct image_cache
*
8142 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
8145 bzero (c
, sizeof *c
);
8147 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
8148 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
8149 c
->buckets
= (struct image
**) xmalloc (size
);
8150 bzero (c
->buckets
, size
);
8155 /* Free image cache of frame F. Be aware that X frames share images
8159 free_image_cache (f
)
8162 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8167 /* Cache should not be referenced by any frame when freed. */
8168 xassert (c
->refcount
== 0);
8170 for (i
= 0; i
< c
->used
; ++i
)
8171 free_image (f
, c
->images
[i
]);
8175 FRAME_X_IMAGE_CACHE (f
) = NULL
;
8180 /* Clear image cache of frame F. FORCE_P non-zero means free all
8181 images. FORCE_P zero means clear only images that haven't been
8182 displayed for some time. Should be called from time to time to
8183 reduce the number of loaded images. If image-eviction-seconds is
8184 non-nil, this frees images in the cache which weren't displayed for
8185 at least that many seconds. */
8188 clear_image_cache (f
, force_p
)
8192 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8194 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
8198 int i
, any_freed_p
= 0;
8201 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
8203 for (i
= 0; i
< c
->used
; ++i
)
8205 struct image
*img
= c
->images
[i
];
8208 || (img
->timestamp
> old
)))
8210 free_image (f
, img
);
8215 /* We may be clearing the image cache because, for example,
8216 Emacs was iconified for a longer period of time. In that
8217 case, current matrices may still contain references to
8218 images freed above. So, clear these matrices. */
8221 clear_current_matrices (f
);
8222 ++windows_or_buffers_changed
;
8228 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
8230 "Clear the image cache of FRAME.\n\
8231 FRAME nil or omitted means use the selected frame.\n\
8232 FRAME t means clear the image caches of all frames.")
8240 FOR_EACH_FRAME (tail
, frame
)
8241 if (FRAME_W32_P (XFRAME (frame
)))
8242 clear_image_cache (XFRAME (frame
), 1);
8245 clear_image_cache (check_x_frame (frame
), 1);
8251 /* Return the id of image with Lisp specification SPEC on frame F.
8252 SPEC must be a valid Lisp image specification (see valid_image_p). */
8255 lookup_image (f
, spec
)
8259 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8263 struct gcpro gcpro1
;
8266 /* F must be a window-system frame, and SPEC must be a valid image
8268 xassert (FRAME_WINDOW_P (f
));
8269 xassert (valid_image_p (spec
));
8273 /* Look up SPEC in the hash table of the image cache. */
8274 hash
= sxhash (spec
, 0);
8275 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8277 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
8278 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
8281 /* If not found, create a new image and cache it. */
8285 img
= make_image (spec
, hash
);
8286 cache_image (f
, img
);
8287 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8289 /* If we can't load the image, and we don't have a width and
8290 height, use some arbitrary width and height so that we can
8291 draw a rectangle for it. */
8292 if (img
->load_failed_p
)
8296 value
= image_spec_value (spec
, QCwidth
, NULL
);
8297 img
->width
= (INTEGERP (value
)
8298 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
8299 value
= image_spec_value (spec
, QCheight
, NULL
);
8300 img
->height
= (INTEGERP (value
)
8301 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
8305 /* Handle image type independent image attributes
8306 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF'. */
8307 Lisp_Object ascent
, margin
, relief
;
8309 ascent
= image_spec_value (spec
, QCascent
, NULL
);
8310 if (INTEGERP (ascent
))
8311 img
->ascent
= XFASTINT (ascent
);
8312 else if (EQ (ascent
, Qcenter
))
8313 img
->ascent
= CENTERED_IMAGE_ASCENT
;
8315 margin
= image_spec_value (spec
, QCmargin
, NULL
);
8316 if (INTEGERP (margin
) && XINT (margin
) >= 0)
8317 img
->vmargin
= img
->hmargin
= XFASTINT (margin
);
8318 else if (CONSP (margin
) && INTEGERP (XCAR (margin
))
8319 && INTEGERP (XCDR (margin
)))
8321 if (XINT (XCAR (margin
)) > 0)
8322 img
->hmargin
= XFASTINT (XCAR (margin
));
8323 if (XINT (XCDR (margin
)) > 0)
8324 img
->vmargin
= XFASTINT (XCDR (margin
));
8327 relief
= image_spec_value (spec
, QCrelief
, NULL
);
8328 if (INTEGERP (relief
))
8330 img
->relief
= XINT (relief
);
8331 img
->hmargin
+= abs (img
->relief
);
8332 img
->vmargin
+= abs (img
->relief
);
8335 #if 0 /* TODO: image mask and algorithm. */
8336 /* Manipulation of the image's mask. */
8339 /* `:heuristic-mask t'
8341 means build a mask heuristically.
8342 `:heuristic-mask (R G B)'
8343 `:mask (heuristic (R G B))'
8344 means build a mask from color (R G B) in the
8347 means remove a mask, if any. */
8351 mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
8353 x_build_heuristic_mask (f
, img
, mask
);
8358 mask
= image_spec_value (spec
, QCmask
, &found_p
);
8360 if (EQ (mask
, Qheuristic
))
8361 x_build_heuristic_mask (f
, img
, Qt
);
8362 else if (CONSP (mask
)
8363 && EQ (XCAR (mask
), Qheuristic
))
8365 if (CONSP (XCDR (mask
)))
8366 x_build_heuristic_mask (f
, img
, XCAR (XCDR (mask
)));
8368 x_build_heuristic_mask (f
, img
, XCDR (mask
));
8370 else if (NILP (mask
) && found_p
&& img
->mask
)
8372 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
8378 /* Should we apply an image transformation algorithm? */
8381 Lisp_Object conversion
;
8383 algorithm
= image_spec_value (spec
, QCconversion
, NULL
);
8384 if (EQ (conversion
, Qdisabled
))
8385 x_disable_image (f
, img
);
8386 else if (EQ (conversion
, Qlaplace
))
8388 else if (EQ (conversion
, Qemboss
))
8390 else if (CONSP (conversion
)
8391 && EQ (XCAR (conversion
), Qedge_detection
))
8394 tem
= XCDR (conversion
);
8396 x_edge_detection (f
, img
,
8397 Fplist_get (tem
, QCmatrix
),
8398 Fplist_get (tem
, QCcolor_adjustment
));
8404 xassert (!interrupt_input_blocked
);
8407 /* We're using IMG, so set its timestamp to `now'. */
8408 EMACS_GET_TIME (now
);
8409 img
->timestamp
= EMACS_SECS (now
);
8413 /* Value is the image id. */
8418 /* Cache image IMG in the image cache of frame F. */
8421 cache_image (f
, img
)
8425 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8428 /* Find a free slot in c->images. */
8429 for (i
= 0; i
< c
->used
; ++i
)
8430 if (c
->images
[i
] == NULL
)
8433 /* If no free slot found, maybe enlarge c->images. */
8434 if (i
== c
->used
&& c
->used
== c
->size
)
8437 c
->images
= (struct image
**) xrealloc (c
->images
,
8438 c
->size
* sizeof *c
->images
);
8441 /* Add IMG to c->images, and assign IMG an id. */
8447 /* Add IMG to the cache's hash table. */
8448 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8449 img
->next
= c
->buckets
[i
];
8451 img
->next
->prev
= img
;
8453 c
->buckets
[i
] = img
;
8457 /* Call FN on every image in the image cache of frame F. Used to mark
8458 Lisp Objects in the image cache. */
8461 forall_images_in_image_cache (f
, fn
)
8463 void (*fn
) P_ ((struct image
*img
));
8465 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
8467 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8471 for (i
= 0; i
< c
->used
; ++i
)
8480 /***********************************************************************
8482 ***********************************************************************/
8484 #if 0 /* TODO: W32 specific image code. */
8486 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
8487 XImage
**, Pixmap
*));
8488 static void x_destroy_x_image
P_ ((XImage
*));
8489 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
8492 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
8493 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
8494 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
8495 via xmalloc. Print error messages via image_error if an error
8496 occurs. Value is non-zero if successful. */
8499 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
8501 int width
, height
, depth
;
8505 #if 0 /* TODO: Image support for W32 */
8506 Display
*display
= FRAME_W32_DISPLAY (f
);
8507 Screen
*screen
= FRAME_X_SCREEN (f
);
8508 Window window
= FRAME_W32_WINDOW (f
);
8510 xassert (interrupt_input_blocked
);
8513 depth
= DefaultDepthOfScreen (screen
);
8514 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
8515 depth
, ZPixmap
, 0, NULL
, width
, height
,
8516 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
8519 image_error ("Unable to allocate X image", Qnil
, Qnil
);
8523 /* Allocate image raster. */
8524 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
8526 /* Allocate a pixmap of the same size. */
8527 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
8530 x_destroy_x_image (*ximg
);
8532 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
8540 /* Destroy XImage XIMG. Free XIMG->data. */
8543 x_destroy_x_image (ximg
)
8546 xassert (interrupt_input_blocked
);
8551 XDestroyImage (ximg
);
8556 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
8557 are width and height of both the image and pixmap. */
8560 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
8567 xassert (interrupt_input_blocked
);
8568 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
8569 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
8576 /***********************************************************************
8578 ***********************************************************************/
8580 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
8582 /* Find image file FILE. Look in data-directory, then
8583 x-bitmap-file-path. Value is the full name of the file found, or
8584 nil if not found. */
8587 x_find_image_file (file
)
8590 Lisp_Object file_found
, search_path
;
8591 struct gcpro gcpro1
, gcpro2
;
8595 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
8596 GCPRO2 (file_found
, search_path
);
8598 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
8599 fd
= openp (search_path
, file
, "", &file_found
, 0);
8612 /***********************************************************************
8614 ***********************************************************************/
8616 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
8617 static int xbm_load_image_from_file
P_ ((struct frame
*f
, struct image
*img
,
8619 static int xbm_image_p
P_ ((Lisp_Object object
));
8620 static int xbm_read_bitmap_file_data
P_ ((char *, int *, int *,
8624 /* Indices of image specification fields in xbm_format, below. */
8626 enum xbm_keyword_index
8643 /* Vector of image_keyword structures describing the format
8644 of valid XBM image specifications. */
8646 static struct image_keyword xbm_format
[XBM_LAST
] =
8648 {":type", IMAGE_SYMBOL_VALUE
, 1},
8649 {":file", IMAGE_STRING_VALUE
, 0},
8650 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8651 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8652 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8653 {":foreground", IMAGE_STRING_VALUE
, 0},
8654 {":background", IMAGE_STRING_VALUE
, 0},
8655 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
8656 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
8657 {":relief", IMAGE_INTEGER_VALUE
, 0},
8658 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8659 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
8662 /* Structure describing the image type XBM. */
8664 static struct image_type xbm_type
=
8673 /* Tokens returned from xbm_scan. */
8682 /* Return non-zero if OBJECT is a valid XBM-type image specification.
8683 A valid specification is a list starting with the symbol `image'
8684 The rest of the list is a property list which must contain an
8687 If the specification specifies a file to load, it must contain
8688 an entry `:file FILENAME' where FILENAME is a string.
8690 If the specification is for a bitmap loaded from memory it must
8691 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
8692 WIDTH and HEIGHT are integers > 0. DATA may be:
8694 1. a string large enough to hold the bitmap data, i.e. it must
8695 have a size >= (WIDTH + 7) / 8 * HEIGHT
8697 2. a bool-vector of size >= WIDTH * HEIGHT
8699 3. a vector of strings or bool-vectors, one for each line of the
8702 Both the file and data forms may contain the additional entries
8703 `:background COLOR' and `:foreground COLOR'. If not present,
8704 foreground and background of the frame on which the image is
8705 displayed, is used. */
8708 xbm_image_p (object
)
8711 struct image_keyword kw
[XBM_LAST
];
8713 bcopy (xbm_format
, kw
, sizeof kw
);
8714 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
8717 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
8719 if (kw
[XBM_FILE
].count
)
8721 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
8729 /* Entries for `:width', `:height' and `:data' must be present. */
8730 if (!kw
[XBM_WIDTH
].count
8731 || !kw
[XBM_HEIGHT
].count
8732 || !kw
[XBM_DATA
].count
)
8735 data
= kw
[XBM_DATA
].value
;
8736 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
8737 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
8739 /* Check type of data, and width and height against contents of
8745 /* Number of elements of the vector must be >= height. */
8746 if (XVECTOR (data
)->size
< height
)
8749 /* Each string or bool-vector in data must be large enough
8750 for one line of the image. */
8751 for (i
= 0; i
< height
; ++i
)
8753 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
8757 if (XSTRING (elt
)->size
8758 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
8761 else if (BOOL_VECTOR_P (elt
))
8763 if (XBOOL_VECTOR (elt
)->size
< width
)
8770 else if (STRINGP (data
))
8772 if (XSTRING (data
)->size
8773 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
8776 else if (BOOL_VECTOR_P (data
))
8778 if (XBOOL_VECTOR (data
)->size
< width
* height
)
8785 /* Baseline must be a value between 0 and 100 (a percentage). */
8786 if (kw
[XBM_ASCENT
].count
8787 && XFASTINT (kw
[XBM_ASCENT
].value
) > 100)
8794 /* Scan a bitmap file. FP is the stream to read from. Value is
8795 either an enumerator from enum xbm_token, or a character for a
8796 single-character token, or 0 at end of file. If scanning an
8797 identifier, store the lexeme of the identifier in SVAL. If
8798 scanning a number, store its value in *IVAL. */
8801 xbm_scan (fp
, sval
, ival
)
8808 /* Skip white space. */
8809 while ((c
= fgetc (fp
)) != EOF
&& isspace (c
))
8814 else if (isdigit (c
))
8816 int value
= 0, digit
;
8821 if (c
== 'x' || c
== 'X')
8823 while ((c
= fgetc (fp
)) != EOF
)
8827 else if (c
>= 'a' && c
<= 'f')
8828 digit
= c
- 'a' + 10;
8829 else if (c
>= 'A' && c
<= 'F')
8830 digit
= c
- 'A' + 10;
8833 value
= 16 * value
+ digit
;
8836 else if (isdigit (c
))
8839 while ((c
= fgetc (fp
)) != EOF
8841 value
= 8 * value
+ c
- '0';
8847 while ((c
= fgetc (fp
)) != EOF
8849 value
= 10 * value
+ c
- '0';
8857 else if (isalpha (c
) || c
== '_')
8860 while ((c
= fgetc (fp
)) != EOF
8861 && (isalnum (c
) || c
== '_'))
8873 /* Replacement for XReadBitmapFileData which isn't available under old
8874 X versions. FILE is the name of the bitmap file to read. Set
8875 *WIDTH and *HEIGHT to the width and height of the image. Return in
8876 *DATA the bitmap data allocated with xmalloc. Value is non-zero if
8880 xbm_read_bitmap_file_data (file
, width
, height
, data
)
8882 int *width
, *height
;
8883 unsigned char **data
;
8886 char buffer
[BUFSIZ
];
8889 int bytes_per_line
, i
, nbytes
;
8895 LA1 = xbm_scan (fp, buffer, &value)
8897 #define expect(TOKEN) \
8898 if (LA1 != (TOKEN)) \
8903 #define expect_ident(IDENT) \
8904 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
8909 fp
= fopen (file
, "r");
8913 *width
= *height
= -1;
8915 LA1
= xbm_scan (fp
, buffer
, &value
);
8917 /* Parse defines for width, height and hot-spots. */
8921 expect_ident ("define");
8922 expect (XBM_TK_IDENT
);
8924 if (LA1
== XBM_TK_NUMBER
);
8926 char *p
= strrchr (buffer
, '_');
8927 p
= p
? p
+ 1 : buffer
;
8928 if (strcmp (p
, "width") == 0)
8930 else if (strcmp (p
, "height") == 0)
8933 expect (XBM_TK_NUMBER
);
8936 if (*width
< 0 || *height
< 0)
8939 /* Parse bits. Must start with `static'. */
8940 expect_ident ("static");
8941 if (LA1
== XBM_TK_IDENT
)
8943 if (strcmp (buffer
, "unsigned") == 0)
8946 expect_ident ("char");
8948 else if (strcmp (buffer
, "short") == 0)
8952 if (*width
% 16 && *width
% 16 < 9)
8955 else if (strcmp (buffer
, "char") == 0)
8963 expect (XBM_TK_IDENT
);
8969 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
8970 nbytes
= bytes_per_line
* *height
;
8971 p
= *data
= (char *) xmalloc (nbytes
);
8976 for (i
= 0; i
< nbytes
; i
+= 2)
8979 expect (XBM_TK_NUMBER
);
8982 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
8985 if (LA1
== ',' || LA1
== '}')
8993 for (i
= 0; i
< nbytes
; ++i
)
8996 expect (XBM_TK_NUMBER
);
9000 if (LA1
== ',' || LA1
== '}')
9026 /* Load XBM image IMG which will be displayed on frame F from file
9027 SPECIFIED_FILE. Value is non-zero if successful. */
9030 xbm_load_image_from_file (f
, img
, specified_file
)
9033 Lisp_Object specified_file
;
9036 unsigned char *data
;
9039 struct gcpro gcpro1
;
9041 xassert (STRINGP (specified_file
));
9045 file
= x_find_image_file (specified_file
);
9046 if (!STRINGP (file
))
9048 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9053 rc
= xbm_read_bitmap_file_data (XSTRING (file
)->data
, &img
->width
,
9054 &img
->height
, &data
);
9057 int depth
= one_w32_display_info
.n_cbits
;
9058 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
9059 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
9062 xassert (img
->width
> 0 && img
->height
> 0);
9064 /* Get foreground and background colors, maybe allocate colors. */
9065 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
9067 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
9069 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
9071 background
= x_alloc_image_color (f
, img
, value
, background
);
9073 #if 0 /* TODO : Port image display to W32 */
9076 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
9077 FRAME_W32_WINDOW (f
),
9079 img
->width
, img
->height
,
9080 foreground
, background
,
9084 if (img
->pixmap
== 0)
9086 x_clear_image (f
, img
);
9087 image_error ("Unable to create X pixmap for `%s'", file
, Qnil
);
9096 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
9103 /* Fill image IMG which is used on frame F with pixmap data. Value is
9104 non-zero if successful. */
9112 Lisp_Object file_name
;
9114 xassert (xbm_image_p (img
->spec
));
9116 /* If IMG->spec specifies a file name, create a non-file spec from it. */
9117 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
9118 if (STRINGP (file_name
))
9119 success_p
= xbm_load_image_from_file (f
, img
, file_name
);
9122 struct image_keyword fmt
[XBM_LAST
];
9125 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
9126 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
9130 /* Parse the list specification. */
9131 bcopy (xbm_format
, fmt
, sizeof fmt
);
9132 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
9135 /* Get specified width, and height. */
9136 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
9137 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
9138 xassert (img
->width
> 0 && img
->height
> 0);
9142 if (fmt
[XBM_ASCENT
].count
)
9143 img
->ascent
= XFASTINT (fmt
[XBM_ASCENT
].value
);
9145 /* Get foreground and background colors, maybe allocate colors. */
9146 if (fmt
[XBM_FOREGROUND
].count
)
9147 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
9149 if (fmt
[XBM_BACKGROUND
].count
)
9150 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
9153 /* Set bits to the bitmap image data. */
9154 data
= fmt
[XBM_DATA
].value
;
9159 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
9161 p
= bits
= (char *) alloca (nbytes
* img
->height
);
9162 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
9164 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
9166 bcopy (XSTRING (line
)->data
, p
, nbytes
);
9168 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
9171 else if (STRINGP (data
))
9172 bits
= XSTRING (data
)->data
;
9174 bits
= XBOOL_VECTOR (data
)->data
;
9176 #if 0 /* TODO : W32 XPM code */
9177 /* Create the pixmap. */
9178 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
9180 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
9181 FRAME_W32_WINDOW (f
),
9183 img
->width
, img
->height
,
9184 foreground
, background
,
9192 image_error ("Unable to create pixmap for XBM image `%s'",
9194 x_clear_image (f
, img
);
9205 /***********************************************************************
9207 ***********************************************************************/
9211 static int xpm_image_p
P_ ((Lisp_Object object
));
9212 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
9213 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
9215 #include "X11/xpm.h"
9217 /* The symbol `xpm' identifying XPM-format images. */
9221 /* Indices of image specification fields in xpm_format, below. */
9223 enum xpm_keyword_index
9237 /* Vector of image_keyword structures describing the format
9238 of valid XPM image specifications. */
9240 static struct image_keyword xpm_format
[XPM_LAST
] =
9242 {":type", IMAGE_SYMBOL_VALUE
, 1},
9243 {":file", IMAGE_STRING_VALUE
, 0},
9244 {":data", IMAGE_STRING_VALUE
, 0},
9245 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9246 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9247 {":relief", IMAGE_INTEGER_VALUE
, 0},
9248 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9249 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9250 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9253 /* Structure describing the image type XBM. */
9255 static struct image_type xpm_type
=
9265 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
9266 for XPM images. Such a list must consist of conses whose car and
9270 xpm_valid_color_symbols_p (color_symbols
)
9271 Lisp_Object color_symbols
;
9273 while (CONSP (color_symbols
))
9275 Lisp_Object sym
= XCAR (color_symbols
);
9277 || !STRINGP (XCAR (sym
))
9278 || !STRINGP (XCDR (sym
)))
9280 color_symbols
= XCDR (color_symbols
);
9283 return NILP (color_symbols
);
9287 /* Value is non-zero if OBJECT is a valid XPM image specification. */
9290 xpm_image_p (object
)
9293 struct image_keyword fmt
[XPM_LAST
];
9294 bcopy (xpm_format
, fmt
, sizeof fmt
);
9295 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
9296 /* Either `:file' or `:data' must be present. */
9297 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
9298 /* Either no `:color-symbols' or it's a list of conses
9299 whose car and cdr are strings. */
9300 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
9301 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
9302 && (fmt
[XPM_ASCENT
].count
== 0
9303 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
9307 /* Load image IMG which will be displayed on frame F. Value is
9308 non-zero if successful. */
9316 XpmAttributes attrs
;
9317 Lisp_Object specified_file
, color_symbols
;
9319 /* Configure the XPM lib. Use the visual of frame F. Allocate
9320 close colors. Return colors allocated. */
9321 bzero (&attrs
, sizeof attrs
);
9322 attrs
.visual
= FRAME_X_VISUAL (f
);
9323 attrs
.colormap
= FRAME_X_COLORMAP (f
);
9324 attrs
.valuemask
|= XpmVisual
;
9325 attrs
.valuemask
|= XpmColormap
;
9326 attrs
.valuemask
|= XpmReturnAllocPixels
;
9327 #ifdef XpmAllocCloseColors
9328 attrs
.alloc_close_colors
= 1;
9329 attrs
.valuemask
|= XpmAllocCloseColors
;
9331 attrs
.closeness
= 600;
9332 attrs
.valuemask
|= XpmCloseness
;
9335 /* If image specification contains symbolic color definitions, add
9336 these to `attrs'. */
9337 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
9338 if (CONSP (color_symbols
))
9341 XpmColorSymbol
*xpm_syms
;
9344 attrs
.valuemask
|= XpmColorSymbols
;
9346 /* Count number of symbols. */
9347 attrs
.numsymbols
= 0;
9348 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
9351 /* Allocate an XpmColorSymbol array. */
9352 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
9353 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
9354 bzero (xpm_syms
, size
);
9355 attrs
.colorsymbols
= xpm_syms
;
9357 /* Fill the color symbol array. */
9358 for (tail
= color_symbols
, i
= 0;
9360 ++i
, tail
= XCDR (tail
))
9362 Lisp_Object name
= XCAR (XCAR (tail
));
9363 Lisp_Object color
= XCDR (XCAR (tail
));
9364 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
9365 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
9366 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
9367 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
9371 /* Create a pixmap for the image, either from a file, or from a
9372 string buffer containing data in the same format as an XPM file. */
9374 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9375 if (STRINGP (specified_file
))
9377 Lisp_Object file
= x_find_image_file (specified_file
);
9378 if (!STRINGP (file
))
9380 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9385 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
9386 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
9391 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
9392 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
9393 XSTRING (buffer
)->data
,
9394 &img
->pixmap
, &img
->mask
,
9399 if (rc
== XpmSuccess
)
9401 /* Remember allocated colors. */
9402 img
->ncolors
= attrs
.nalloc_pixels
;
9403 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
9404 * sizeof *img
->colors
);
9405 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
9406 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
9408 img
->width
= attrs
.width
;
9409 img
->height
= attrs
.height
;
9410 xassert (img
->width
> 0 && img
->height
> 0);
9412 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
9414 XpmFreeAttributes (&attrs
);
9422 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
9425 case XpmFileInvalid
:
9426 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
9430 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
9433 case XpmColorFailed
:
9434 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
9438 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
9443 return rc
== XpmSuccess
;
9446 #endif /* HAVE_XPM != 0 */
9449 #if 0 /* TODO : Color tables on W32. */
9450 /***********************************************************************
9452 ***********************************************************************/
9454 /* An entry in the color table mapping an RGB color to a pixel color. */
9459 unsigned long pixel
;
9461 /* Next in color table collision list. */
9462 struct ct_color
*next
;
9465 /* The bucket vector size to use. Must be prime. */
9469 /* Value is a hash of the RGB color given by R, G, and B. */
9471 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
9473 /* The color hash table. */
9475 struct ct_color
**ct_table
;
9477 /* Number of entries in the color table. */
9479 int ct_colors_allocated
;
9481 /* Function prototypes. */
9483 static void init_color_table
P_ ((void));
9484 static void free_color_table
P_ ((void));
9485 static unsigned long *colors_in_color_table
P_ ((int *n
));
9486 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
9487 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
9490 /* Initialize the color table. */
9495 int size
= CT_SIZE
* sizeof (*ct_table
);
9496 ct_table
= (struct ct_color
**) xmalloc (size
);
9497 bzero (ct_table
, size
);
9498 ct_colors_allocated
= 0;
9502 /* Free memory associated with the color table. */
9508 struct ct_color
*p
, *next
;
9510 for (i
= 0; i
< CT_SIZE
; ++i
)
9511 for (p
= ct_table
[i
]; p
; p
= next
)
9522 /* Value is a pixel color for RGB color R, G, B on frame F. If an
9523 entry for that color already is in the color table, return the
9524 pixel color of that entry. Otherwise, allocate a new color for R,
9525 G, B, and make an entry in the color table. */
9527 static unsigned long
9528 lookup_rgb_color (f
, r
, g
, b
)
9532 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
9533 int i
= hash
% CT_SIZE
;
9536 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9537 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
9546 color
= PALETTERGB (r
, g
, b
);
9548 ++ct_colors_allocated
;
9550 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9555 p
->next
= ct_table
[i
];
9563 /* Look up pixel color PIXEL which is used on frame F in the color
9564 table. If not already present, allocate it. Value is PIXEL. */
9566 static unsigned long
9567 lookup_pixel_color (f
, pixel
)
9569 unsigned long pixel
;
9571 int i
= pixel
% CT_SIZE
;
9574 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9575 if (p
->pixel
== pixel
)
9586 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9587 color
.pixel
= pixel
;
9588 XQueryColor (NULL
, cmap
, &color
);
9589 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
9594 ++ct_colors_allocated
;
9596 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9601 p
->next
= ct_table
[i
];
9605 return FRAME_FOREGROUND_PIXEL (f
);
9611 /* Value is a vector of all pixel colors contained in the color table,
9612 allocated via xmalloc. Set *N to the number of colors. */
9614 static unsigned long *
9615 colors_in_color_table (n
)
9620 unsigned long *colors
;
9622 if (ct_colors_allocated
== 0)
9629 colors
= (unsigned long *) xmalloc (ct_colors_allocated
9631 *n
= ct_colors_allocated
;
9633 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
9634 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9635 colors
[j
++] = p
->pixel
;
9644 /***********************************************************************
9646 ***********************************************************************/
9648 #if 0 /* TODO : W32 versions of low level algorithms */
9649 static void x_laplace_write_row
P_ ((struct frame
*, long *,
9650 int, XImage
*, int));
9651 static void x_laplace_read_row
P_ ((struct frame
*, Colormap
,
9652 XColor
*, int, XImage
*, int));
9655 /* Fill COLORS with RGB colors from row Y of image XIMG. F is the
9656 frame we operate on, CMAP is the color-map in effect, and WIDTH is
9657 the width of one row in the image. */
9660 x_laplace_read_row (f
, cmap
, colors
, width
, ximg
, y
)
9670 for (x
= 0; x
< width
; ++x
)
9671 colors
[x
].pixel
= XGetPixel (ximg
, x
, y
);
9673 XQueryColors (NULL
, cmap
, colors
, width
);
9677 /* Write row Y of image XIMG. PIXELS is an array of WIDTH longs
9678 containing the pixel colors to write. F is the frame we are
9682 x_laplace_write_row (f
, pixels
, width
, ximg
, y
)
9691 for (x
= 0; x
< width
; ++x
)
9692 XPutPixel (ximg
, x
, y
, pixels
[x
]);
9696 /* Transform image IMG which is used on frame F with a Laplace
9697 edge-detection algorithm. The result is an image that can be used
9698 to draw disabled buttons, for example. */
9705 #if 0 /* TODO : W32 version */
9706 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9707 XImage
*ximg
, *oimg
;
9713 int in_y
, out_y
, rc
;
9718 /* Get the X image IMG->pixmap. */
9719 ximg
= XGetImage (NULL
, img
->pixmap
,
9720 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
9722 /* Allocate 3 input rows, and one output row of colors. */
9723 for (i
= 0; i
< 3; ++i
)
9724 in
[i
] = (XColor
*) alloca (img
->width
* sizeof (XColor
));
9725 out
= (long *) alloca (img
->width
* sizeof (long));
9727 /* Create an X image for output. */
9728 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
9731 /* Fill first two rows. */
9732 x_laplace_read_row (f
, cmap
, in
[0], img
->width
, ximg
, 0);
9733 x_laplace_read_row (f
, cmap
, in
[1], img
->width
, ximg
, 1);
9736 /* Write first row, all zeros. */
9737 init_color_table ();
9738 pixel
= lookup_rgb_color (f
, 0, 0, 0);
9739 for (x
= 0; x
< img
->width
; ++x
)
9741 x_laplace_write_row (f
, out
, img
->width
, oimg
, 0);
9744 for (y
= 2; y
< img
->height
; ++y
)
9747 int rowb
= (y
+ 2) % 3;
9749 x_laplace_read_row (f
, cmap
, in
[rowa
], img
->width
, ximg
, in_y
++);
9751 for (x
= 0; x
< img
->width
- 2; ++x
)
9753 int r
= in
[rowa
][x
].red
+ mv2
- in
[rowb
][x
+ 2].red
;
9754 int g
= in
[rowa
][x
].green
+ mv2
- in
[rowb
][x
+ 2].green
;
9755 int b
= in
[rowa
][x
].blue
+ mv2
- in
[rowb
][x
+ 2].blue
;
9757 out
[x
+ 1] = lookup_rgb_color (f
, r
& 0xffff, g
& 0xffff,
9761 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
++);
9764 /* Write last line, all zeros. */
9765 for (x
= 0; x
< img
->width
; ++x
)
9767 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
);
9769 /* Free the input image, and free resources of IMG. */
9770 XDestroyImage (ximg
);
9771 x_clear_image (f
, img
);
9773 /* Put the output image into pixmap, and destroy it. */
9774 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
9775 x_destroy_x_image (oimg
);
9777 /* Remember new pixmap and colors in IMG. */
9778 img
->pixmap
= pixmap
;
9779 img
->colors
= colors_in_color_table (&img
->ncolors
);
9780 free_color_table ();
9787 /* Build a mask for image IMG which is used on frame F. FILE is the
9788 name of an image file, for error messages. HOW determines how to
9789 determine the background color of IMG. If it is a list '(R G B)',
9790 with R, G, and B being integers >= 0, take that as the color of the
9791 background. Otherwise, determine the background color of IMG
9792 heuristically. Value is non-zero if successful. */
9795 x_build_heuristic_mask (f
, img
, how
)
9800 #if 0 /* TODO : W32 version */
9801 Display
*dpy
= FRAME_W32_DISPLAY (f
);
9802 XImage
*ximg
, *mask_img
;
9803 int x
, y
, rc
, look_at_corners_p
;
9808 /* Create an image and pixmap serving as mask. */
9809 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
9810 &mask_img
, &img
->mask
);
9817 /* Get the X image of IMG->pixmap. */
9818 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
9821 /* Determine the background color of ximg. If HOW is `(R G B)'
9822 take that as color. Otherwise, try to determine the color
9824 look_at_corners_p
= 1;
9832 && NATNUMP (XCAR (how
)))
9834 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
9838 if (i
== 3 && NILP (how
))
9840 char color_name
[30];
9841 XColor exact
, color
;
9844 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
9846 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9847 if (XLookupColor (dpy
, cmap
, color_name
, &exact
, &color
))
9850 look_at_corners_p
= 0;
9855 if (look_at_corners_p
)
9857 unsigned long corners
[4];
9860 /* Get the colors at the corners of ximg. */
9861 corners
[0] = XGetPixel (ximg
, 0, 0);
9862 corners
[1] = XGetPixel (ximg
, img
->width
- 1, 0);
9863 corners
[2] = XGetPixel (ximg
, img
->width
- 1, img
->height
- 1);
9864 corners
[3] = XGetPixel (ximg
, 0, img
->height
- 1);
9866 /* Choose the most frequently found color as background. */
9867 for (i
= best_count
= 0; i
< 4; ++i
)
9871 for (j
= n
= 0; j
< 4; ++j
)
9872 if (corners
[i
] == corners
[j
])
9876 bg
= corners
[i
], best_count
= n
;
9880 /* Set all bits in mask_img to 1 whose color in ximg is different
9881 from the background color bg. */
9882 for (y
= 0; y
< img
->height
; ++y
)
9883 for (x
= 0; x
< img
->width
; ++x
)
9884 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
9886 /* Put mask_img into img->mask. */
9887 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
9888 x_destroy_x_image (mask_img
);
9889 XDestroyImage (ximg
);
9899 /***********************************************************************
9900 PBM (mono, gray, color)
9901 ***********************************************************************/
9904 static int pbm_image_p
P_ ((Lisp_Object object
));
9905 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
9906 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
9908 /* The symbol `pbm' identifying images of this type. */
9912 /* Indices of image specification fields in gs_format, below. */
9914 enum pbm_keyword_index
9927 /* Vector of image_keyword structures describing the format
9928 of valid user-defined image specifications. */
9930 static struct image_keyword pbm_format
[PBM_LAST
] =
9932 {":type", IMAGE_SYMBOL_VALUE
, 1},
9933 {":file", IMAGE_STRING_VALUE
, 0},
9934 {":data", IMAGE_STRING_VALUE
, 0},
9935 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9936 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9937 {":relief", IMAGE_INTEGER_VALUE
, 0},
9938 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9939 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9942 /* Structure describing the image type `pbm'. */
9944 static struct image_type pbm_type
=
9954 /* Return non-zero if OBJECT is a valid PBM image specification. */
9957 pbm_image_p (object
)
9960 struct image_keyword fmt
[PBM_LAST
];
9962 bcopy (pbm_format
, fmt
, sizeof fmt
);
9964 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
9965 || (fmt
[PBM_ASCENT
].count
9966 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
9969 /* Must specify either :data or :file. */
9970 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
9974 /* Scan a decimal number from *S and return it. Advance *S while
9975 reading the number. END is the end of the string. Value is -1 at
9979 pbm_scan_number (s
, end
)
9980 unsigned char **s
, *end
;
9986 /* Skip white-space. */
9987 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
9992 /* Skip comment to end of line. */
9993 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
9996 else if (isdigit (c
))
9998 /* Read decimal number. */
10000 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
10001 val
= 10 * val
+ c
- '0';
10012 /* Read FILE into memory. Value is a pointer to a buffer allocated
10013 with xmalloc holding FILE's contents. Value is null if an error
10014 occured. *SIZE is set to the size of the file. */
10017 pbm_read_file (file
, size
)
10025 if (stat (XSTRING (file
)->data
, &st
) == 0
10026 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
10027 && (buf
= (char *) xmalloc (st
.st_size
),
10028 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
10030 *size
= st
.st_size
;
10048 /* Load PBM image IMG for use on frame F. */
10056 int width
, height
, max_color_idx
= 0;
10058 Lisp_Object file
, specified_file
;
10059 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
10060 struct gcpro gcpro1
;
10061 unsigned char *contents
= NULL
;
10062 unsigned char *end
, *p
;
10065 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10069 if (STRINGP (specified_file
))
10071 file
= x_find_image_file (specified_file
);
10072 if (!STRINGP (file
))
10074 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10079 contents
= pbm_read_file (file
, &size
);
10080 if (contents
== NULL
)
10082 image_error ("Error reading `%s'", file
, Qnil
);
10088 end
= contents
+ size
;
10093 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10094 p
= XSTRING (data
)->data
;
10095 end
= p
+ STRING_BYTES (XSTRING (data
));
10098 /* Check magic number. */
10099 if (end
- p
< 2 || *p
++ != 'P')
10101 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
10111 raw_p
= 0, type
= PBM_MONO
;
10115 raw_p
= 0, type
= PBM_GRAY
;
10119 raw_p
= 0, type
= PBM_COLOR
;
10123 raw_p
= 1, type
= PBM_MONO
;
10127 raw_p
= 1, type
= PBM_GRAY
;
10131 raw_p
= 1, type
= PBM_COLOR
;
10135 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
10139 /* Read width, height, maximum color-component. Characters
10140 starting with `#' up to the end of a line are ignored. */
10141 width
= pbm_scan_number (&p
, end
);
10142 height
= pbm_scan_number (&p
, end
);
10144 if (type
!= PBM_MONO
)
10146 max_color_idx
= pbm_scan_number (&p
, end
);
10147 if (raw_p
&& max_color_idx
> 255)
10148 max_color_idx
= 255;
10153 || (type
!= PBM_MONO
&& max_color_idx
< 0))
10157 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
10158 &ximg
, &img
->pixmap
))
10164 /* Initialize the color hash table. */
10165 init_color_table ();
10167 if (type
== PBM_MONO
)
10171 for (y
= 0; y
< height
; ++y
)
10172 for (x
= 0; x
< width
; ++x
)
10182 g
= pbm_scan_number (&p
, end
);
10184 XPutPixel (ximg
, x
, y
, (g
10185 ? FRAME_FOREGROUND_PIXEL (f
)
10186 : FRAME_BACKGROUND_PIXEL (f
)));
10191 for (y
= 0; y
< height
; ++y
)
10192 for (x
= 0; x
< width
; ++x
)
10196 if (type
== PBM_GRAY
)
10197 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
10206 r
= pbm_scan_number (&p
, end
);
10207 g
= pbm_scan_number (&p
, end
);
10208 b
= pbm_scan_number (&p
, end
);
10211 if (r
< 0 || g
< 0 || b
< 0)
10213 xfree (ximg
->data
);
10215 XDestroyImage (ximg
);
10217 image_error ("Invalid pixel value in image `%s'",
10222 /* RGB values are now in the range 0..max_color_idx.
10223 Scale this to the range 0..0xffff supported by X. */
10224 r
= (double) r
* 65535 / max_color_idx
;
10225 g
= (double) g
* 65535 / max_color_idx
;
10226 b
= (double) b
* 65535 / max_color_idx
;
10227 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10231 /* Store in IMG->colors the colors allocated for the image, and
10232 free the color table. */
10233 img
->colors
= colors_in_color_table (&img
->ncolors
);
10234 free_color_table ();
10236 /* Put the image into a pixmap. */
10237 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10238 x_destroy_x_image (ximg
);
10241 img
->width
= width
;
10242 img
->height
= height
;
10248 #endif /* HAVE_PBM */
10251 /***********************************************************************
10253 ***********************************************************************/
10259 /* Function prototypes. */
10261 static int png_image_p
P_ ((Lisp_Object object
));
10262 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
10264 /* The symbol `png' identifying images of this type. */
10268 /* Indices of image specification fields in png_format, below. */
10270 enum png_keyword_index
10279 PNG_HEURISTIC_MASK
,
10283 /* Vector of image_keyword structures describing the format
10284 of valid user-defined image specifications. */
10286 static struct image_keyword png_format
[PNG_LAST
] =
10288 {":type", IMAGE_SYMBOL_VALUE
, 1},
10289 {":data", IMAGE_STRING_VALUE
, 0},
10290 {":file", IMAGE_STRING_VALUE
, 0},
10291 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10292 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
10293 {":relief", IMAGE_INTEGER_VALUE
, 0},
10294 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10295 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10298 /* Structure describing the image type `png'. */
10300 static struct image_type png_type
=
10310 /* Return non-zero if OBJECT is a valid PNG image specification. */
10313 png_image_p (object
)
10314 Lisp_Object object
;
10316 struct image_keyword fmt
[PNG_LAST
];
10317 bcopy (png_format
, fmt
, sizeof fmt
);
10319 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
10320 || (fmt
[PNG_ASCENT
].count
10321 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
10324 /* Must specify either the :data or :file keyword. */
10325 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
10329 /* Error and warning handlers installed when the PNG library
10333 my_png_error (png_ptr
, msg
)
10334 png_struct
*png_ptr
;
10337 xassert (png_ptr
!= NULL
);
10338 image_error ("PNG error: %s", build_string (msg
), Qnil
);
10339 longjmp (png_ptr
->jmpbuf
, 1);
10344 my_png_warning (png_ptr
, msg
)
10345 png_struct
*png_ptr
;
10348 xassert (png_ptr
!= NULL
);
10349 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
10352 /* Memory source for PNG decoding. */
10354 struct png_memory_storage
10356 unsigned char *bytes
; /* The data */
10357 size_t len
; /* How big is it? */
10358 int index
; /* Where are we? */
10362 /* Function set as reader function when reading PNG image from memory.
10363 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
10364 bytes from the input to DATA. */
10367 png_read_from_memory (png_ptr
, data
, length
)
10368 png_structp png_ptr
;
10372 struct png_memory_storage
*tbr
10373 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
10375 if (length
> tbr
->len
- tbr
->index
)
10376 png_error (png_ptr
, "Read error");
10378 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
10379 tbr
->index
= tbr
->index
+ length
;
10382 /* Load PNG image IMG for use on frame F. Value is non-zero if
10390 Lisp_Object file
, specified_file
;
10391 Lisp_Object specified_data
;
10393 XImage
*ximg
, *mask_img
= NULL
;
10394 struct gcpro gcpro1
;
10395 png_struct
*png_ptr
= NULL
;
10396 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
10399 png_byte
*pixels
= NULL
;
10400 png_byte
**rows
= NULL
;
10401 png_uint_32 width
, height
;
10402 int bit_depth
, color_type
, interlace_type
;
10404 png_uint_32 row_bytes
;
10407 double screen_gamma
, image_gamma
;
10409 struct png_memory_storage tbr
; /* Data to be read */
10411 /* Find out what file to load. */
10412 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10413 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10417 if (NILP (specified_data
))
10419 file
= x_find_image_file (specified_file
);
10420 if (!STRINGP (file
))
10422 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10427 /* Open the image file. */
10428 fp
= fopen (XSTRING (file
)->data
, "rb");
10431 image_error ("Cannot open image file `%s'", file
, Qnil
);
10437 /* Check PNG signature. */
10438 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
10439 || !png_check_sig (sig
, sizeof sig
))
10441 image_error ("Not a PNG file:` %s'", file
, Qnil
);
10449 /* Read from memory. */
10450 tbr
.bytes
= XSTRING (specified_data
)->data
;
10451 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
10454 /* Check PNG signature. */
10455 if (tbr
.len
< sizeof sig
10456 || !png_check_sig (tbr
.bytes
, sizeof sig
))
10458 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
10463 /* Need to skip past the signature. */
10464 tbr
.bytes
+= sizeof (sig
);
10467 /* Initialize read and info structs for PNG lib. */
10468 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
10469 my_png_error
, my_png_warning
);
10472 if (fp
) fclose (fp
);
10477 info_ptr
= png_create_info_struct (png_ptr
);
10480 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
10481 if (fp
) fclose (fp
);
10486 end_info
= png_create_info_struct (png_ptr
);
10489 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
10490 if (fp
) fclose (fp
);
10495 /* Set error jump-back. We come back here when the PNG library
10496 detects an error. */
10497 if (setjmp (png_ptr
->jmpbuf
))
10501 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10504 if (fp
) fclose (fp
);
10509 /* Read image info. */
10510 if (!NILP (specified_data
))
10511 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
10513 png_init_io (png_ptr
, fp
);
10515 png_set_sig_bytes (png_ptr
, sizeof sig
);
10516 png_read_info (png_ptr
, info_ptr
);
10517 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
10518 &interlace_type
, NULL
, NULL
);
10520 /* If image contains simply transparency data, we prefer to
10521 construct a clipping mask. */
10522 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
10527 /* This function is easier to write if we only have to handle
10528 one data format: RGB or RGBA with 8 bits per channel. Let's
10529 transform other formats into that format. */
10531 /* Strip more than 8 bits per channel. */
10532 if (bit_depth
== 16)
10533 png_set_strip_16 (png_ptr
);
10535 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
10537 png_set_expand (png_ptr
);
10539 /* Convert grayscale images to RGB. */
10540 if (color_type
== PNG_COLOR_TYPE_GRAY
10541 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
10542 png_set_gray_to_rgb (png_ptr
);
10544 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
10545 gamma_str
= getenv ("SCREEN_GAMMA");
10546 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
10548 /* Tell the PNG lib to handle gamma correction for us. */
10550 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
10551 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
10552 /* There is a special chunk in the image specifying the gamma. */
10553 png_set_sRGB (png_ptr
, info_ptr
, intent
);
10556 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
10557 /* Image contains gamma information. */
10558 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
10560 /* Use a default of 0.5 for the image gamma. */
10561 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
10563 /* Handle alpha channel by combining the image with a background
10564 color. Do this only if a real alpha channel is supplied. For
10565 simple transparency, we prefer a clipping mask. */
10566 if (!transparent_p
)
10568 png_color_16
*image_background
;
10570 if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
10571 /* Image contains a background color with which to
10572 combine the image. */
10573 png_set_background (png_ptr
, image_background
,
10574 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
10577 /* Image does not contain a background color with which
10578 to combine the image data via an alpha channel. Use
10579 the frame's background instead. */
10582 png_color_16 frame_background
;
10585 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10586 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
10587 XQueryColor (FRAME_W32_DISPLAY (f
), cmap
, &color
);
10590 bzero (&frame_background
, sizeof frame_background
);
10591 frame_background
.red
= color
.red
;
10592 frame_background
.green
= color
.green
;
10593 frame_background
.blue
= color
.blue
;
10595 png_set_background (png_ptr
, &frame_background
,
10596 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
10600 /* Update info structure. */
10601 png_read_update_info (png_ptr
, info_ptr
);
10603 /* Get number of channels. Valid values are 1 for grayscale images
10604 and images with a palette, 2 for grayscale images with transparency
10605 information (alpha channel), 3 for RGB images, and 4 for RGB
10606 images with alpha channel, i.e. RGBA. If conversions above were
10607 sufficient we should only have 3 or 4 channels here. */
10608 channels
= png_get_channels (png_ptr
, info_ptr
);
10609 xassert (channels
== 3 || channels
== 4);
10611 /* Number of bytes needed for one row of the image. */
10612 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
10614 /* Allocate memory for the image. */
10615 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
10616 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
10617 for (i
= 0; i
< height
; ++i
)
10618 rows
[i
] = pixels
+ i
* row_bytes
;
10620 /* Read the entire image. */
10621 png_read_image (png_ptr
, rows
);
10622 png_read_end (png_ptr
, info_ptr
);
10631 /* Create the X image and pixmap. */
10632 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10639 /* Create an image and pixmap serving as mask if the PNG image
10640 contains an alpha channel. */
10643 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
10644 &mask_img
, &img
->mask
))
10646 x_destroy_x_image (ximg
);
10647 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
10653 /* Fill the X image and mask from PNG data. */
10654 init_color_table ();
10656 for (y
= 0; y
< height
; ++y
)
10658 png_byte
*p
= rows
[y
];
10660 for (x
= 0; x
< width
; ++x
)
10667 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10669 /* An alpha channel, aka mask channel, associates variable
10670 transparency with an image. Where other image formats
10671 support binary transparency---fully transparent or fully
10672 opaque---PNG allows up to 254 levels of partial transparency.
10673 The PNG library implements partial transparency by combining
10674 the image with a specified background color.
10676 I'm not sure how to handle this here nicely: because the
10677 background on which the image is displayed may change, for
10678 real alpha channel support, it would be necessary to create
10679 a new image for each possible background.
10681 What I'm doing now is that a mask is created if we have
10682 boolean transparency information. Otherwise I'm using
10683 the frame's background color to combine the image with. */
10688 XPutPixel (mask_img
, x
, y
, *p
> 0);
10694 /* Remember colors allocated for this image. */
10695 img
->colors
= colors_in_color_table (&img
->ncolors
);
10696 free_color_table ();
10699 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10703 img
->width
= width
;
10704 img
->height
= height
;
10706 /* Put the image into the pixmap, then free the X image and its buffer. */
10707 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10708 x_destroy_x_image (ximg
);
10710 /* Same for the mask. */
10713 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10714 x_destroy_x_image (mask_img
);
10722 #endif /* HAVE_PNG != 0 */
10726 /***********************************************************************
10728 ***********************************************************************/
10732 /* Work around a warning about HAVE_STDLIB_H being redefined in
10734 #ifdef HAVE_STDLIB_H
10735 #define HAVE_STDLIB_H_1
10736 #undef HAVE_STDLIB_H
10737 #endif /* HAVE_STLIB_H */
10739 #include <jpeglib.h>
10740 #include <jerror.h>
10741 #include <setjmp.h>
10743 #ifdef HAVE_STLIB_H_1
10744 #define HAVE_STDLIB_H 1
10747 static int jpeg_image_p
P_ ((Lisp_Object object
));
10748 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
10750 /* The symbol `jpeg' identifying images of this type. */
10754 /* Indices of image specification fields in gs_format, below. */
10756 enum jpeg_keyword_index
10765 JPEG_HEURISTIC_MASK
,
10769 /* Vector of image_keyword structures describing the format
10770 of valid user-defined image specifications. */
10772 static struct image_keyword jpeg_format
[JPEG_LAST
] =
10774 {":type", IMAGE_SYMBOL_VALUE
, 1},
10775 {":data", IMAGE_STRING_VALUE
, 0},
10776 {":file", IMAGE_STRING_VALUE
, 0},
10777 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10778 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
10779 {":relief", IMAGE_INTEGER_VALUE
, 0},
10780 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10781 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10784 /* Structure describing the image type `jpeg'. */
10786 static struct image_type jpeg_type
=
10796 /* Return non-zero if OBJECT is a valid JPEG image specification. */
10799 jpeg_image_p (object
)
10800 Lisp_Object object
;
10802 struct image_keyword fmt
[JPEG_LAST
];
10804 bcopy (jpeg_format
, fmt
, sizeof fmt
);
10806 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
10807 || (fmt
[JPEG_ASCENT
].count
10808 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
10811 /* Must specify either the :data or :file keyword. */
10812 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
10816 struct my_jpeg_error_mgr
10818 struct jpeg_error_mgr pub
;
10819 jmp_buf setjmp_buffer
;
10823 my_error_exit (cinfo
)
10824 j_common_ptr cinfo
;
10826 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
10827 longjmp (mgr
->setjmp_buffer
, 1);
10830 /* Init source method for JPEG data source manager. Called by
10831 jpeg_read_header() before any data is actually read. See
10832 libjpeg.doc from the JPEG lib distribution. */
10835 our_init_source (cinfo
)
10836 j_decompress_ptr cinfo
;
10841 /* Fill input buffer method for JPEG data source manager. Called
10842 whenever more data is needed. We read the whole image in one step,
10843 so this only adds a fake end of input marker at the end. */
10846 our_fill_input_buffer (cinfo
)
10847 j_decompress_ptr cinfo
;
10849 /* Insert a fake EOI marker. */
10850 struct jpeg_source_mgr
*src
= cinfo
->src
;
10851 static JOCTET buffer
[2];
10853 buffer
[0] = (JOCTET
) 0xFF;
10854 buffer
[1] = (JOCTET
) JPEG_EOI
;
10856 src
->next_input_byte
= buffer
;
10857 src
->bytes_in_buffer
= 2;
10862 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
10863 is the JPEG data source manager. */
10866 our_skip_input_data (cinfo
, num_bytes
)
10867 j_decompress_ptr cinfo
;
10870 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10874 if (num_bytes
> src
->bytes_in_buffer
)
10875 ERREXIT (cinfo
, JERR_INPUT_EOF
);
10877 src
->bytes_in_buffer
-= num_bytes
;
10878 src
->next_input_byte
+= num_bytes
;
10883 /* Method to terminate data source. Called by
10884 jpeg_finish_decompress() after all data has been processed. */
10887 our_term_source (cinfo
)
10888 j_decompress_ptr cinfo
;
10893 /* Set up the JPEG lib for reading an image from DATA which contains
10894 LEN bytes. CINFO is the decompression info structure created for
10895 reading the image. */
10898 jpeg_memory_src (cinfo
, data
, len
)
10899 j_decompress_ptr cinfo
;
10903 struct jpeg_source_mgr
*src
;
10905 if (cinfo
->src
== NULL
)
10907 /* First time for this JPEG object? */
10908 cinfo
->src
= (struct jpeg_source_mgr
*)
10909 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
10910 sizeof (struct jpeg_source_mgr
));
10911 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10912 src
->next_input_byte
= data
;
10915 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10916 src
->init_source
= our_init_source
;
10917 src
->fill_input_buffer
= our_fill_input_buffer
;
10918 src
->skip_input_data
= our_skip_input_data
;
10919 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
10920 src
->term_source
= our_term_source
;
10921 src
->bytes_in_buffer
= len
;
10922 src
->next_input_byte
= data
;
10926 /* Load image IMG for use on frame F. Patterned after example.c
10927 from the JPEG lib. */
10934 struct jpeg_decompress_struct cinfo
;
10935 struct my_jpeg_error_mgr mgr
;
10936 Lisp_Object file
, specified_file
;
10937 Lisp_Object specified_data
;
10940 int row_stride
, x
, y
;
10941 XImage
*ximg
= NULL
;
10943 unsigned long *colors
;
10945 struct gcpro gcpro1
;
10947 /* Open the JPEG file. */
10948 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10949 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10953 if (NILP (specified_data
))
10955 file
= x_find_image_file (specified_file
);
10956 if (!STRINGP (file
))
10958 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10963 fp
= fopen (XSTRING (file
)->data
, "r");
10966 image_error ("Cannot open `%s'", file
, Qnil
);
10972 /* Customize libjpeg's error handling to call my_error_exit when an
10973 error is detected. This function will perform a longjmp. */
10974 mgr
.pub
.error_exit
= my_error_exit
;
10975 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
10977 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
10981 /* Called from my_error_exit. Display a JPEG error. */
10982 char buffer
[JMSG_LENGTH_MAX
];
10983 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
10984 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
10985 build_string (buffer
));
10988 /* Close the input file and destroy the JPEG object. */
10991 jpeg_destroy_decompress (&cinfo
);
10995 /* If we already have an XImage, free that. */
10996 x_destroy_x_image (ximg
);
10998 /* Free pixmap and colors. */
10999 x_clear_image (f
, img
);
11006 /* Create the JPEG decompression object. Let it read from fp.
11007 Read the JPEG image header. */
11008 jpeg_create_decompress (&cinfo
);
11010 if (NILP (specified_data
))
11011 jpeg_stdio_src (&cinfo
, fp
);
11013 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
11014 STRING_BYTES (XSTRING (specified_data
)));
11016 jpeg_read_header (&cinfo
, TRUE
);
11018 /* Customize decompression so that color quantization will be used.
11019 Start decompression. */
11020 cinfo
.quantize_colors
= TRUE
;
11021 jpeg_start_decompress (&cinfo
);
11022 width
= img
->width
= cinfo
.output_width
;
11023 height
= img
->height
= cinfo
.output_height
;
11027 /* Create X image and pixmap. */
11028 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
11032 longjmp (mgr
.setjmp_buffer
, 2);
11035 /* Allocate colors. When color quantization is used,
11036 cinfo.actual_number_of_colors has been set with the number of
11037 colors generated, and cinfo.colormap is a two-dimensional array
11038 of color indices in the range 0..cinfo.actual_number_of_colors.
11039 No more than 255 colors will be generated. */
11043 if (cinfo
.out_color_components
> 2)
11044 ir
= 0, ig
= 1, ib
= 2;
11045 else if (cinfo
.out_color_components
> 1)
11046 ir
= 0, ig
= 1, ib
= 0;
11048 ir
= 0, ig
= 0, ib
= 0;
11050 /* Use the color table mechanism because it handles colors that
11051 cannot be allocated nicely. Such colors will be replaced with
11052 a default color, and we don't have to care about which colors
11053 can be freed safely, and which can't. */
11054 init_color_table ();
11055 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
11058 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
11060 /* Multiply RGB values with 255 because X expects RGB values
11061 in the range 0..0xffff. */
11062 int r
= cinfo
.colormap
[ir
][i
] << 8;
11063 int g
= cinfo
.colormap
[ig
][i
] << 8;
11064 int b
= cinfo
.colormap
[ib
][i
] << 8;
11065 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11068 /* Remember those colors actually allocated. */
11069 img
->colors
= colors_in_color_table (&img
->ncolors
);
11070 free_color_table ();
11074 row_stride
= width
* cinfo
.output_components
;
11075 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
11077 for (y
= 0; y
< height
; ++y
)
11079 jpeg_read_scanlines (&cinfo
, buffer
, 1);
11080 for (x
= 0; x
< cinfo
.output_width
; ++x
)
11081 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
11085 jpeg_finish_decompress (&cinfo
);
11086 jpeg_destroy_decompress (&cinfo
);
11090 /* Put the image into the pixmap. */
11091 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11092 x_destroy_x_image (ximg
);
11098 #endif /* HAVE_JPEG */
11102 /***********************************************************************
11104 ***********************************************************************/
11108 #include <tiffio.h>
11110 static int tiff_image_p
P_ ((Lisp_Object object
));
11111 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
11113 /* The symbol `tiff' identifying images of this type. */
11117 /* Indices of image specification fields in tiff_format, below. */
11119 enum tiff_keyword_index
11128 TIFF_HEURISTIC_MASK
,
11132 /* Vector of image_keyword structures describing the format
11133 of valid user-defined image specifications. */
11135 static struct image_keyword tiff_format
[TIFF_LAST
] =
11137 {":type", IMAGE_SYMBOL_VALUE
, 1},
11138 {":data", IMAGE_STRING_VALUE
, 0},
11139 {":file", IMAGE_STRING_VALUE
, 0},
11140 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11141 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11142 {":relief", IMAGE_INTEGER_VALUE
, 0},
11143 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11144 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11147 /* Structure describing the image type `tiff'. */
11149 static struct image_type tiff_type
=
11159 /* Return non-zero if OBJECT is a valid TIFF image specification. */
11162 tiff_image_p (object
)
11163 Lisp_Object object
;
11165 struct image_keyword fmt
[TIFF_LAST
];
11166 bcopy (tiff_format
, fmt
, sizeof fmt
);
11168 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
11169 || (fmt
[TIFF_ASCENT
].count
11170 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
11173 /* Must specify either the :data or :file keyword. */
11174 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
11178 /* Reading from a memory buffer for TIFF images Based on the PNG
11179 memory source, but we have to provide a lot of extra functions.
11182 We really only need to implement read and seek, but I am not
11183 convinced that the TIFF library is smart enough not to destroy
11184 itself if we only hand it the function pointers we need to
11189 unsigned char *bytes
;
11193 tiff_memory_source
;
11196 tiff_read_from_memory (data
, buf
, size
)
11201 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11203 if (size
> src
->len
- src
->index
)
11204 return (size_t) -1;
11205 bcopy (src
->bytes
+ src
->index
, buf
, size
);
11206 src
->index
+= size
;
11211 tiff_write_from_memory (data
, buf
, size
)
11216 return (size_t) -1;
11220 tiff_seek_in_memory (data
, off
, whence
)
11225 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11230 case SEEK_SET
: /* Go from beginning of source. */
11234 case SEEK_END
: /* Go from end of source. */
11235 idx
= src
->len
+ off
;
11238 case SEEK_CUR
: /* Go from current position. */
11239 idx
= src
->index
+ off
;
11242 default: /* Invalid `whence'. */
11246 if (idx
> src
->len
|| idx
< 0)
11254 tiff_close_memory (data
)
11262 tiff_mmap_memory (data
, pbase
, psize
)
11267 /* It is already _IN_ memory. */
11272 tiff_unmap_memory (data
, base
, size
)
11277 /* We don't need to do this. */
11281 tiff_size_of_memory (data
)
11284 return ((tiff_memory_source
*) data
)->len
;
11287 /* Load TIFF image IMG for use on frame F. Value is non-zero if
11295 Lisp_Object file
, specified_file
;
11296 Lisp_Object specified_data
;
11298 int width
, height
, x
, y
;
11302 struct gcpro gcpro1
;
11303 tiff_memory_source memsrc
;
11305 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11306 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11310 if (NILP (specified_data
))
11312 /* Read from a file */
11313 file
= x_find_image_file (specified_file
);
11314 if (!STRINGP (file
))
11316 image_error ("Cannot find image file `%s'", file
, Qnil
);
11321 /* Try to open the image file. */
11322 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
11325 image_error ("Cannot open `%s'", file
, Qnil
);
11332 /* Memory source! */
11333 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11334 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11337 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
11338 (TIFFReadWriteProc
) tiff_read_from_memory
,
11339 (TIFFReadWriteProc
) tiff_write_from_memory
,
11340 tiff_seek_in_memory
,
11342 tiff_size_of_memory
,
11344 tiff_unmap_memory
);
11348 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
11354 /* Get width and height of the image, and allocate a raster buffer
11355 of width x height 32-bit values. */
11356 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
11357 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
11358 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
11360 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
11364 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
11372 /* Create the X image and pixmap. */
11373 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11381 /* Initialize the color table. */
11382 init_color_table ();
11384 /* Process the pixel raster. Origin is in the lower-left corner. */
11385 for (y
= 0; y
< height
; ++y
)
11387 uint32
*row
= buf
+ y
* width
;
11389 for (x
= 0; x
< width
; ++x
)
11391 uint32 abgr
= row
[x
];
11392 int r
= TIFFGetR (abgr
) << 8;
11393 int g
= TIFFGetG (abgr
) << 8;
11394 int b
= TIFFGetB (abgr
) << 8;
11395 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
11399 /* Remember the colors allocated for the image. Free the color table. */
11400 img
->colors
= colors_in_color_table (&img
->ncolors
);
11401 free_color_table ();
11403 /* Put the image into the pixmap, then free the X image and its buffer. */
11404 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11405 x_destroy_x_image (ximg
);
11409 img
->width
= width
;
11410 img
->height
= height
;
11416 #endif /* HAVE_TIFF != 0 */
11420 /***********************************************************************
11422 ***********************************************************************/
11426 #include <gif_lib.h>
11428 static int gif_image_p
P_ ((Lisp_Object object
));
11429 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
11431 /* The symbol `gif' identifying images of this type. */
11435 /* Indices of image specification fields in gif_format, below. */
11437 enum gif_keyword_index
11446 GIF_HEURISTIC_MASK
,
11451 /* Vector of image_keyword structures describing the format
11452 of valid user-defined image specifications. */
11454 static struct image_keyword gif_format
[GIF_LAST
] =
11456 {":type", IMAGE_SYMBOL_VALUE
, 1},
11457 {":data", IMAGE_STRING_VALUE
, 0},
11458 {":file", IMAGE_STRING_VALUE
, 0},
11459 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11460 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11461 {":relief", IMAGE_INTEGER_VALUE
, 0},
11462 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11463 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11464 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0}
11467 /* Structure describing the image type `gif'. */
11469 static struct image_type gif_type
=
11478 /* Return non-zero if OBJECT is a valid GIF image specification. */
11481 gif_image_p (object
)
11482 Lisp_Object object
;
11484 struct image_keyword fmt
[GIF_LAST
];
11485 bcopy (gif_format
, fmt
, sizeof fmt
);
11487 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
11488 || (fmt
[GIF_ASCENT
].count
11489 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
11492 /* Must specify either the :data or :file keyword. */
11493 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
11496 /* Reading a GIF image from memory
11497 Based on the PNG memory stuff to a certain extent. */
11501 unsigned char *bytes
;
11507 /* Make the current memory source available to gif_read_from_memory.
11508 It's done this way because not all versions of libungif support
11509 a UserData field in the GifFileType structure. */
11510 static gif_memory_source
*current_gif_memory_src
;
11513 gif_read_from_memory (file
, buf
, len
)
11518 gif_memory_source
*src
= current_gif_memory_src
;
11520 if (len
> src
->len
- src
->index
)
11523 bcopy (src
->bytes
+ src
->index
, buf
, len
);
11529 /* Load GIF image IMG for use on frame F. Value is non-zero if
11537 Lisp_Object file
, specified_file
;
11538 Lisp_Object specified_data
;
11539 int rc
, width
, height
, x
, y
, i
;
11541 ColorMapObject
*gif_color_map
;
11542 unsigned long pixel_colors
[256];
11544 struct gcpro gcpro1
;
11546 int ino
, image_left
, image_top
, image_width
, image_height
;
11547 gif_memory_source memsrc
;
11548 unsigned char *raster
;
11550 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11551 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11555 if (NILP (specified_data
))
11557 file
= x_find_image_file (specified_file
);
11558 if (!STRINGP (file
))
11560 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11565 /* Open the GIF file. */
11566 gif
= DGifOpenFileName (XSTRING (file
)->data
);
11569 image_error ("Cannot open `%s'", file
, Qnil
);
11576 /* Read from memory! */
11577 current_gif_memory_src
= &memsrc
;
11578 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11579 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11582 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
11585 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
11591 /* Read entire contents. */
11592 rc
= DGifSlurp (gif
);
11593 if (rc
== GIF_ERROR
)
11595 image_error ("Error reading `%s'", img
->spec
, Qnil
);
11596 DGifCloseFile (gif
);
11601 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
11602 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
11603 if (ino
>= gif
->ImageCount
)
11605 image_error ("Invalid image number `%s' in image `%s'",
11607 DGifCloseFile (gif
);
11612 width
= img
->width
= gif
->SWidth
;
11613 height
= img
->height
= gif
->SHeight
;
11617 /* Create the X image and pixmap. */
11618 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11621 DGifCloseFile (gif
);
11626 /* Allocate colors. */
11627 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
11628 if (!gif_color_map
)
11629 gif_color_map
= gif
->SColorMap
;
11630 init_color_table ();
11631 bzero (pixel_colors
, sizeof pixel_colors
);
11633 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
11635 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
11636 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
11637 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
11638 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11641 img
->colors
= colors_in_color_table (&img
->ncolors
);
11642 free_color_table ();
11644 /* Clear the part of the screen image that are not covered by
11645 the image from the GIF file. Full animated GIF support
11646 requires more than can be done here (see the gif89 spec,
11647 disposal methods). Let's simply assume that the part
11648 not covered by a sub-image is in the frame's background color. */
11649 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
11650 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
11651 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
11652 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
11654 for (y
= 0; y
< image_top
; ++y
)
11655 for (x
= 0; x
< width
; ++x
)
11656 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11658 for (y
= image_top
+ image_height
; y
< height
; ++y
)
11659 for (x
= 0; x
< width
; ++x
)
11660 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11662 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
11664 for (x
= 0; x
< image_left
; ++x
)
11665 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11666 for (x
= image_left
+ image_width
; x
< width
; ++x
)
11667 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11670 /* Read the GIF image into the X image. We use a local variable
11671 `raster' here because RasterBits below is a char *, and invites
11672 problems with bytes >= 0x80. */
11673 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
11675 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
11677 static int interlace_start
[] = {0, 4, 2, 1};
11678 static int interlace_increment
[] = {8, 8, 4, 2};
11680 int row
= interlace_start
[0];
11684 for (y
= 0; y
< image_height
; y
++)
11686 if (row
>= image_height
)
11688 row
= interlace_start
[++pass
];
11689 while (row
>= image_height
)
11690 row
= interlace_start
[++pass
];
11693 for (x
= 0; x
< image_width
; x
++)
11695 int i
= raster
[(y
* image_width
) + x
];
11696 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
11700 row
+= interlace_increment
[pass
];
11705 for (y
= 0; y
< image_height
; ++y
)
11706 for (x
= 0; x
< image_width
; ++x
)
11708 int i
= raster
[y
* image_width
+ x
];
11709 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
11713 DGifCloseFile (gif
);
11715 /* Put the image into the pixmap, then free the X image and its buffer. */
11716 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11717 x_destroy_x_image (ximg
);
11724 #endif /* HAVE_GIF != 0 */
11728 /***********************************************************************
11730 ***********************************************************************/
11732 #ifdef HAVE_GHOSTSCRIPT
11733 static int gs_image_p
P_ ((Lisp_Object object
));
11734 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
11735 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
11737 /* The symbol `postscript' identifying images of this type. */
11739 Lisp_Object Qpostscript
;
11741 /* Keyword symbols. */
11743 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
11745 /* Indices of image specification fields in gs_format, below. */
11747 enum gs_keyword_index
11763 /* Vector of image_keyword structures describing the format
11764 of valid user-defined image specifications. */
11766 static struct image_keyword gs_format
[GS_LAST
] =
11768 {":type", IMAGE_SYMBOL_VALUE
, 1},
11769 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11770 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11771 {":file", IMAGE_STRING_VALUE
, 1},
11772 {":loader", IMAGE_FUNCTION_VALUE
, 0},
11773 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
11774 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11775 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11776 {":relief", IMAGE_INTEGER_VALUE
, 0},
11777 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11778 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11781 /* Structure describing the image type `ghostscript'. */
11783 static struct image_type gs_type
=
11793 /* Free X resources of Ghostscript image IMG which is used on frame F. */
11796 gs_clear_image (f
, img
)
11800 /* IMG->data.ptr_val may contain a recorded colormap. */
11801 xfree (img
->data
.ptr_val
);
11802 x_clear_image (f
, img
);
11806 /* Return non-zero if OBJECT is a valid Ghostscript image
11810 gs_image_p (object
)
11811 Lisp_Object object
;
11813 struct image_keyword fmt
[GS_LAST
];
11817 bcopy (gs_format
, fmt
, sizeof fmt
);
11819 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
11820 || (fmt
[GS_ASCENT
].count
11821 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
11824 /* Bounding box must be a list or vector containing 4 integers. */
11825 tem
= fmt
[GS_BOUNDING_BOX
].value
;
11828 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
11829 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
11834 else if (VECTORP (tem
))
11836 if (XVECTOR (tem
)->size
!= 4)
11838 for (i
= 0; i
< 4; ++i
)
11839 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
11849 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
11858 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
11859 struct gcpro gcpro1
, gcpro2
;
11861 double in_width
, in_height
;
11862 Lisp_Object pixel_colors
= Qnil
;
11864 /* Compute pixel size of pixmap needed from the given size in the
11865 image specification. Sizes in the specification are in pt. 1 pt
11866 = 1/72 in, xdpi and ydpi are stored in the frame's X display
11868 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
11869 in_width
= XFASTINT (pt_width
) / 72.0;
11870 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
11871 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
11872 in_height
= XFASTINT (pt_height
) / 72.0;
11873 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
11875 /* Create the pixmap. */
11877 xassert (img
->pixmap
== 0);
11878 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11879 img
->width
, img
->height
,
11880 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
11885 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
11889 /* Call the loader to fill the pixmap. It returns a process object
11890 if successful. We do not record_unwind_protect here because
11891 other places in redisplay like calling window scroll functions
11892 don't either. Let the Lisp loader use `unwind-protect' instead. */
11893 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
11895 sprintf (buffer
, "%lu %lu",
11896 (unsigned long) FRAME_W32_WINDOW (f
),
11897 (unsigned long) img
->pixmap
);
11898 window_and_pixmap_id
= build_string (buffer
);
11900 sprintf (buffer
, "%lu %lu",
11901 FRAME_FOREGROUND_PIXEL (f
),
11902 FRAME_BACKGROUND_PIXEL (f
));
11903 pixel_colors
= build_string (buffer
);
11905 XSETFRAME (frame
, f
);
11906 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
11908 loader
= intern ("gs-load-image");
11910 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
11911 make_number (img
->width
),
11912 make_number (img
->height
),
11913 window_and_pixmap_id
,
11916 return PROCESSP (img
->data
.lisp_val
);
11920 /* Kill the Ghostscript process that was started to fill PIXMAP on
11921 frame F. Called from XTread_socket when receiving an event
11922 telling Emacs that Ghostscript has finished drawing. */
11925 x_kill_gs_process (pixmap
, f
)
11929 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
11933 /* Find the image containing PIXMAP. */
11934 for (i
= 0; i
< c
->used
; ++i
)
11935 if (c
->images
[i
]->pixmap
== pixmap
)
11938 /* Kill the GS process. We should have found PIXMAP in the image
11939 cache and its image should contain a process object. */
11940 xassert (i
< c
->used
);
11941 img
= c
->images
[i
];
11942 xassert (PROCESSP (img
->data
.lisp_val
));
11943 Fkill_process (img
->data
.lisp_val
, Qnil
);
11944 img
->data
.lisp_val
= Qnil
;
11946 /* On displays with a mutable colormap, figure out the colors
11947 allocated for the image by looking at the pixels of an XImage for
11949 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
11950 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
11956 /* Try to get an XImage for img->pixmep. */
11957 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
11958 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
11963 /* Initialize the color table. */
11964 init_color_table ();
11966 /* For each pixel of the image, look its color up in the
11967 color table. After having done so, the color table will
11968 contain an entry for each color used by the image. */
11969 for (y
= 0; y
< img
->height
; ++y
)
11970 for (x
= 0; x
< img
->width
; ++x
)
11972 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
11973 lookup_pixel_color (f
, pixel
);
11976 /* Record colors in the image. Free color table and XImage. */
11977 img
->colors
= colors_in_color_table (&img
->ncolors
);
11978 free_color_table ();
11979 XDestroyImage (ximg
);
11981 #if 0 /* This doesn't seem to be the case. If we free the colors
11982 here, we get a BadAccess later in x_clear_image when
11983 freeing the colors. */
11984 /* We have allocated colors once, but Ghostscript has also
11985 allocated colors on behalf of us. So, to get the
11986 reference counts right, free them once. */
11989 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
11990 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
,
11991 img
->colors
, img
->ncolors
, 0);
11996 image_error ("Cannot get X image of `%s'; colors will not be freed",
12003 #endif /* HAVE_GHOSTSCRIPT */
12006 /***********************************************************************
12008 ***********************************************************************/
12010 DEFUN ("x-change-window-property", Fx_change_window_property
,
12011 Sx_change_window_property
, 2, 3, 0,
12012 "Change window property PROP to VALUE on the X window of FRAME.\n\
12013 PROP and VALUE must be strings. FRAME nil or omitted means use the\n\
12014 selected frame. Value is VALUE.")
12015 (prop
, value
, frame
)
12016 Lisp_Object frame
, prop
, value
;
12018 #if 0 /* TODO : port window properties to W32 */
12019 struct frame
*f
= check_x_frame (frame
);
12022 CHECK_STRING (prop
, 1);
12023 CHECK_STRING (value
, 2);
12026 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12027 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12028 prop_atom
, XA_STRING
, 8, PropModeReplace
,
12029 XSTRING (value
)->data
, XSTRING (value
)->size
);
12031 /* Make sure the property is set when we return. */
12032 XFlush (FRAME_W32_DISPLAY (f
));
12041 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
12042 Sx_delete_window_property
, 1, 2, 0,
12043 "Remove window property PROP from X window of FRAME.\n\
12044 FRAME nil or omitted means use the selected frame. Value is PROP.")
12046 Lisp_Object prop
, frame
;
12048 #if 0 /* TODO : port window properties to W32 */
12050 struct frame
*f
= check_x_frame (frame
);
12053 CHECK_STRING (prop
, 1);
12055 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12056 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
12058 /* Make sure the property is removed when we return. */
12059 XFlush (FRAME_W32_DISPLAY (f
));
12067 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
12069 "Value is the value of window property PROP on FRAME.\n\
12070 If FRAME is nil or omitted, use the selected frame. Value is nil\n\
12071 if FRAME hasn't a property with name PROP or if PROP has no string\n\
12074 Lisp_Object prop
, frame
;
12076 #if 0 /* TODO : port window properties to W32 */
12078 struct frame
*f
= check_x_frame (frame
);
12081 Lisp_Object prop_value
= Qnil
;
12082 char *tmp_data
= NULL
;
12085 unsigned long actual_size
, bytes_remaining
;
12087 CHECK_STRING (prop
, 1);
12089 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12090 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12091 prop_atom
, 0, 0, False
, XA_STRING
,
12092 &actual_type
, &actual_format
, &actual_size
,
12093 &bytes_remaining
, (unsigned char **) &tmp_data
);
12096 int size
= bytes_remaining
;
12101 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12102 prop_atom
, 0, bytes_remaining
,
12104 &actual_type
, &actual_format
,
12105 &actual_size
, &bytes_remaining
,
12106 (unsigned char **) &tmp_data
);
12108 prop_value
= make_string (tmp_data
, size
);
12123 /***********************************************************************
12125 ***********************************************************************/
12127 /* If non-null, an asynchronous timer that, when it expires, displays
12128 an hourglass cursor on all frames. */
12130 static struct atimer
*hourglass_atimer
;
12132 /* Non-zero means an hourglass cursor is currently shown. */
12134 static int hourglass_shown_p
;
12136 /* Number of seconds to wait before displaying an hourglass cursor. */
12138 static Lisp_Object Vhourglass_delay
;
12140 /* Default number of seconds to wait before displaying an hourglass
12143 #define DEFAULT_HOURGLASS_DELAY 1
12145 /* Function prototypes. */
12147 static void show_hourglass
P_ ((struct atimer
*));
12148 static void hide_hourglass
P_ ((void));
12151 /* Cancel a currently active hourglass timer, and start a new one. */
12156 #if 0 /* TODO: cursor shape changes. */
12158 int secs
, usecs
= 0;
12160 cancel_hourglass ();
12162 if (INTEGERP (Vhourglass_delay
)
12163 && XINT (Vhourglass_delay
) > 0)
12164 secs
= XFASTINT (Vhourglass_delay
);
12165 else if (FLOATP (Vhourglass_delay
)
12166 && XFLOAT_DATA (Vhourglass_delay
) > 0)
12169 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
12170 secs
= XFASTINT (tem
);
12171 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
12174 secs
= DEFAULT_HOURGLASS_DELAY
;
12176 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
12177 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
12178 show_hourglass
, NULL
);
12183 /* Cancel the hourglass cursor timer if active, hide an hourglass
12184 cursor if shown. */
12187 cancel_hourglass ()
12189 if (hourglass_atimer
)
12191 cancel_atimer (hourglass_atimer
);
12192 hourglass_atimer
= NULL
;
12195 if (hourglass_shown_p
)
12200 /* Timer function of hourglass_atimer. TIMER is equal to
12203 Display an hourglass cursor on all frames by mapping the frames'
12204 hourglass_window. Set the hourglass_p flag in the frames'
12205 output_data.x structure to indicate that an hourglass cursor is
12206 shown on the frames. */
12209 show_hourglass (timer
)
12210 struct atimer
*timer
;
12212 #if 0 /* TODO: cursor shape changes. */
12213 /* The timer implementation will cancel this timer automatically
12214 after this function has run. Set hourglass_atimer to null
12215 so that we know the timer doesn't have to be canceled. */
12216 hourglass_atimer
= NULL
;
12218 if (!hourglass_shown_p
)
12220 Lisp_Object rest
, frame
;
12224 FOR_EACH_FRAME (rest
, frame
)
12225 if (FRAME_W32_P (XFRAME (frame
)))
12227 struct frame
*f
= XFRAME (frame
);
12229 f
->output_data
.w32
->hourglass_p
= 1;
12231 if (!f
->output_data
.w32
->hourglass_window
)
12233 unsigned long mask
= CWCursor
;
12234 XSetWindowAttributes attrs
;
12236 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
12238 f
->output_data
.w32
->hourglass_window
12239 = XCreateWindow (FRAME_X_DISPLAY (f
),
12240 FRAME_OUTER_WINDOW (f
),
12241 0, 0, 32000, 32000, 0, 0,
12247 XMapRaised (FRAME_X_DISPLAY (f
),
12248 f
->output_data
.w32
->hourglass_window
);
12249 XFlush (FRAME_X_DISPLAY (f
));
12252 hourglass_shown_p
= 1;
12259 /* Hide the hourglass cursor on all frames, if it is currently shown. */
12264 #if 0 /* TODO: cursor shape changes. */
12265 if (hourglass_shown_p
)
12267 Lisp_Object rest
, frame
;
12270 FOR_EACH_FRAME (rest
, frame
)
12272 struct frame
*f
= XFRAME (frame
);
12274 if (FRAME_W32_P (f
)
12275 /* Watch out for newly created frames. */
12276 && f
->output_data
.x
->hourglass_window
)
12278 XUnmapWindow (FRAME_X_DISPLAY (f
),
12279 f
->output_data
.x
->hourglass_window
);
12280 /* Sync here because XTread_socket looks at the
12281 hourglass_p flag that is reset to zero below. */
12282 XSync (FRAME_X_DISPLAY (f
), False
);
12283 f
->output_data
.x
->hourglass_p
= 0;
12287 hourglass_shown_p
= 0;
12295 /***********************************************************************
12297 ***********************************************************************/
12299 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
12302 /* The frame of a currently visible tooltip, or null. */
12304 Lisp_Object tip_frame
;
12306 /* If non-nil, a timer started that hides the last tooltip when it
12309 Lisp_Object tip_timer
;
12313 unwind_create_tip_frame (frame
)
12316 Lisp_Object deleted
;
12318 deleted
= unwind_create_frame (frame
);
12319 if (EQ (deleted
, Qt
))
12329 /* Create a frame for a tooltip on the display described by DPYINFO.
12330 PARMS is a list of frame parameters. Value is the frame.
12332 Note that functions called here, esp. x_default_parameter can
12333 signal errors, for instance when a specified color name is
12334 undefined. We have to make sure that we're in a consistent state
12335 when this happens. */
12338 x_create_tip_frame (dpyinfo
, parms
)
12339 struct w32_display_info
*dpyinfo
;
12342 #if 0 /* TODO : w32 version */
12344 Lisp_Object frame
, tem
;
12346 long window_prompting
= 0;
12348 int count
= BINDING_STACK_SIZE ();
12349 struct gcpro gcpro1
, gcpro2
, gcpro3
;
12354 /* Use this general default value to start with until we know if
12355 this frame has a specified name. */
12356 Vx_resource_name
= Vinvocation_name
;
12358 #ifdef MULTI_KBOARD
12359 kb
= dpyinfo
->kboard
;
12361 kb
= &the_only_kboard
;
12364 /* Get the name of the frame to use for resource lookup. */
12365 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
12366 if (!STRINGP (name
)
12367 && !EQ (name
, Qunbound
)
12369 error ("Invalid frame name--not a string or nil");
12370 Vx_resource_name
= name
;
12373 GCPRO3 (parms
, name
, frame
);
12374 f
= make_frame (1);
12375 XSETFRAME (frame
, f
);
12376 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
12377 record_unwind_protect (unwind_create_tip_frame
, frame
);
12379 f
->output_method
= output_w32
;
12380 f
->output_data
.w32
=
12381 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
12382 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
12384 f
->output_data
.w32
->icon_bitmap
= -1;
12386 f
->output_data
.w32
->fontset
= -1;
12387 f
->icon_name
= Qnil
;
12390 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
12391 dpyinfo_refcount
= dpyinfo
->reference_count
;
12392 #endif /* GLYPH_DEBUG */
12393 #ifdef MULTI_KBOARD
12394 FRAME_KBOARD (f
) = kb
;
12396 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12397 f
->output_data
.w32
->explicit_parent
= 0;
12399 /* Set the name; the functions to which we pass f expect the name to
12401 if (EQ (name
, Qunbound
) || NILP (name
))
12403 f
->name
= build_string (dpyinfo
->x_id_name
);
12404 f
->explicit_name
= 0;
12409 f
->explicit_name
= 1;
12410 /* use the frame's title when getting resources for this frame. */
12411 specbind (Qx_resource_name
, name
);
12414 /* Extract the window parameters from the supplied values
12415 that are needed to determine window geometry. */
12419 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
12422 /* First, try whatever font the caller has specified. */
12423 if (STRINGP (font
))
12425 tem
= Fquery_fontset (font
, Qnil
);
12427 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
12429 font
= x_new_font (f
, XSTRING (font
)->data
);
12432 /* Try out a font which we hope has bold and italic variations. */
12433 if (!STRINGP (font
))
12434 font
= x_new_font (f
, "-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
12435 if (!STRINGP (font
))
12436 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12437 if (! STRINGP (font
))
12438 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12439 if (! STRINGP (font
))
12440 /* This was formerly the first thing tried, but it finds too many fonts
12441 and takes too long. */
12442 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
12443 /* If those didn't work, look for something which will at least work. */
12444 if (! STRINGP (font
))
12445 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
12447 if (! STRINGP (font
))
12448 font
= build_string ("fixed");
12450 x_default_parameter (f
, parms
, Qfont
, font
,
12451 "font", "Font", RES_TYPE_STRING
);
12454 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
12455 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
12457 /* This defaults to 2 in order to match xterm. We recognize either
12458 internalBorderWidth or internalBorder (which is what xterm calls
12460 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12464 value
= w32_get_arg (parms
, Qinternal_border_width
,
12465 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
12466 if (! EQ (value
, Qunbound
))
12467 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
12471 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
12472 "internalBorderWidth", "internalBorderWidth",
12475 /* Also do the stuff which must be set before the window exists. */
12476 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
12477 "foreground", "Foreground", RES_TYPE_STRING
);
12478 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
12479 "background", "Background", RES_TYPE_STRING
);
12480 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
12481 "pointerColor", "Foreground", RES_TYPE_STRING
);
12482 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
12483 "cursorColor", "Foreground", RES_TYPE_STRING
);
12484 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
12485 "borderColor", "BorderColor", RES_TYPE_STRING
);
12487 /* Init faces before x_default_parameter is called for scroll-bar
12488 parameters because that function calls x_set_scroll_bar_width,
12489 which calls change_frame_size, which calls Fset_window_buffer,
12490 which runs hooks, which call Fvertical_motion. At the end, we
12491 end up in init_iterator with a null face cache, which should not
12493 init_frame_faces (f
);
12495 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12496 window_prompting
= x_figure_window_size (f
, parms
);
12498 if (window_prompting
& XNegative
)
12500 if (window_prompting
& YNegative
)
12501 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
12503 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
12507 if (window_prompting
& YNegative
)
12508 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
12510 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
12513 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
12515 XSetWindowAttributes attrs
;
12516 unsigned long mask
;
12519 mask
= CWBackPixel
| CWOverrideRedirect
| CWSaveUnder
| CWEventMask
;
12520 /* Window managers looks at the override-redirect flag to
12521 determine whether or net to give windows a decoration (Xlib
12523 attrs
.override_redirect
= True
;
12524 attrs
.save_under
= True
;
12525 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
12526 /* Arrange for getting MapNotify and UnmapNotify events. */
12527 attrs
.event_mask
= StructureNotifyMask
;
12529 = FRAME_W32_WINDOW (f
)
12530 = XCreateWindow (FRAME_W32_DISPLAY (f
),
12531 FRAME_W32_DISPLAY_INFO (f
)->root_window
,
12532 /* x, y, width, height */
12536 CopyFromParent
, InputOutput
, CopyFromParent
,
12543 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
12544 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12545 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
12546 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12547 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
12548 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
12550 /* Dimensions, especially f->height, must be done via change_frame_size.
12551 Change will not be effected unless different from the current
12554 height
= f
->height
;
12556 SET_FRAME_WIDTH (f
, 0);
12557 change_frame_size (f
, height
, width
, 1, 0, 0);
12563 /* It is now ok to make the frame official even if we get an error
12564 below. And the frame needs to be on Vframe_list or making it
12565 visible won't work. */
12566 Vframe_list
= Fcons (frame
, Vframe_list
);
12569 /* Now that the frame is official, it counts as a reference to
12571 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
12573 return unbind_to (count
, frame
);
12578 #ifdef TODO /* Tooltip support not complete. */
12579 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
12580 "Show STRING in a \"tooltip\" window on frame FRAME.\n\
12581 A tooltip window is a small window displaying a string.\n\
12583 FRAME nil or omitted means use the selected frame.\n\
12585 PARMS is an optional list of frame parameters which can be\n\
12586 used to change the tooltip's appearance.\n\
12588 Automatically hide the tooltip after TIMEOUT seconds.\n\
12589 TIMEOUT nil means use the default timeout of 5 seconds.\n\
12591 If the list of frame parameters PARAMS contains a `left' parameters,\n\
12592 the tooltip is displayed at that x-position. Otherwise it is\n\
12593 displayed at the mouse position, with offset DX added (default is 5 if\n\
12594 DX isn't specified). Likewise for the y-position; if a `top' frame\n\
12595 parameter is specified, it determines the y-position of the tooltip\n\
12596 window, otherwise it is displayed at the mouse position, with offset\n\
12597 DY added (default is 10).")
12598 (string
, frame
, parms
, timeout
, dx
, dy
)
12599 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
12603 Window root
, child
;
12604 Lisp_Object buffer
, top
, left
;
12605 struct buffer
*old_buffer
;
12606 struct text_pos pos
;
12607 int i
, width
, height
;
12608 int root_x
, root_y
, win_x
, win_y
;
12610 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
12611 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
12612 int count
= specpdl_ptr
- specpdl
;
12614 specbind (Qinhibit_redisplay
, Qt
);
12616 GCPRO4 (string
, parms
, frame
, timeout
);
12618 CHECK_STRING (string
, 0);
12619 f
= check_x_frame (frame
);
12620 if (NILP (timeout
))
12621 timeout
= make_number (5);
12623 CHECK_NATNUM (timeout
, 2);
12626 dx
= make_number (5);
12628 CHECK_NUMBER (dx
, 5);
12631 dy
= make_number (-10);
12633 CHECK_NUMBER (dy
, 6);
12635 if (NILP (last_show_tip_args
))
12636 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
12638 if (!NILP (tip_frame
))
12640 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
12641 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
12642 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
12644 if (EQ (frame
, last_frame
)
12645 && !NILP (Fequal (last_string
, string
))
12646 && !NILP (Fequal (last_parms
, parms
)))
12648 struct frame
*f
= XFRAME (tip_frame
);
12650 /* Only DX and DY have changed. */
12651 if (!NILP (tip_timer
))
12653 Lisp_Object timer
= tip_timer
;
12655 call1 (Qcancel_timer
, timer
);
12659 compute_tip_xy (f
, parms
, dx
, dy
, &root_x
, &root_y
);
12660 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12661 root_x
, root_y
- PIXEL_HEIGHT (f
));
12667 /* Hide a previous tip, if any. */
12670 ASET (last_show_tip_args
, 0, string
);
12671 ASET (last_show_tip_args
, 1, frame
);
12672 ASET (last_show_tip_args
, 2, parms
);
12674 /* Add default values to frame parameters. */
12675 if (NILP (Fassq (Qname
, parms
)))
12676 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
12677 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12678 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
12679 if (NILP (Fassq (Qborder_width
, parms
)))
12680 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
12681 if (NILP (Fassq (Qborder_color
, parms
)))
12682 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
12683 if (NILP (Fassq (Qbackground_color
, parms
)))
12684 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
12687 /* Create a frame for the tooltip, and record it in the global
12688 variable tip_frame. */
12689 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
);
12690 f
= XFRAME (frame
);
12692 /* Set up the frame's root window. Currently we use a size of 80
12693 columns x 40 lines. If someone wants to show a larger tip, he
12694 will loose. I don't think this is a realistic case. */
12695 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
12696 w
->left
= w
->top
= make_number (0);
12697 w
->width
= make_number (80);
12698 w
->height
= make_number (40);
12700 w
->pseudo_window_p
= 1;
12702 /* Display the tooltip text in a temporary buffer. */
12703 buffer
= Fget_buffer_create (build_string (" *tip*"));
12704 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
12705 old_buffer
= current_buffer
;
12706 set_buffer_internal_1 (XBUFFER (buffer
));
12708 Finsert (1, &string
);
12709 clear_glyph_matrix (w
->desired_matrix
);
12710 clear_glyph_matrix (w
->current_matrix
);
12711 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
12712 try_window (FRAME_ROOT_WINDOW (f
), pos
);
12714 /* Compute width and height of the tooltip. */
12715 width
= height
= 0;
12716 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
12718 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
12719 struct glyph
*last
;
12722 /* Stop at the first empty row at the end. */
12723 if (!row
->enabled_p
|| !row
->displays_text_p
)
12726 /* Let the row go over the full width of the frame. */
12727 row
->full_width_p
= 1;
12729 /* There's a glyph at the end of rows that is use to place
12730 the cursor there. Don't include the width of this glyph. */
12731 if (row
->used
[TEXT_AREA
])
12733 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
12734 row_width
= row
->pixel_width
- last
->pixel_width
;
12737 row_width
= row
->pixel_width
;
12739 height
+= row
->height
;
12740 width
= max (width
, row_width
);
12743 /* Add the frame's internal border to the width and height the X
12744 window should have. */
12745 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12746 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12748 /* Move the tooltip window where the mouse pointer is. Resize and
12750 compute_tip_xy (f
, parms
, dx
, dy
, &root_x
, &root_y
);
12752 #if 0 /* TODO : W32 specifics */
12754 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12755 root_x
, root_y
- height
, width
, height
);
12756 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12760 /* Draw into the window. */
12761 w
->must_be_updated_p
= 1;
12762 update_single_window (w
, 1);
12764 /* Restore original current buffer. */
12765 set_buffer_internal_1 (old_buffer
);
12766 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
12769 /* Let the tip disappear after timeout seconds. */
12770 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
12771 intern ("x-hide-tip"));
12774 return unbind_to (count
, Qnil
);
12778 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
12779 "Hide the current tooltip window, if there is any.\n\
12780 Value is t is tooltip was open, nil otherwise.")
12784 Lisp_Object deleted
, frame
, timer
;
12785 struct gcpro gcpro1
, gcpro2
;
12787 /* Return quickly if nothing to do. */
12788 if (NILP (tip_timer
) && NILP (tip_frame
))
12793 GCPRO2 (frame
, timer
);
12794 tip_frame
= tip_timer
= deleted
= Qnil
;
12796 count
= BINDING_STACK_SIZE ();
12797 specbind (Qinhibit_redisplay
, Qt
);
12798 specbind (Qinhibit_quit
, Qt
);
12801 call1 (Qcancel_timer
, timer
);
12803 if (FRAMEP (frame
))
12805 Fdelete_frame (frame
, Qnil
);
12810 return unbind_to (count
, deleted
);
12816 /***********************************************************************
12817 File selection dialog
12818 ***********************************************************************/
12820 extern Lisp_Object Qfile_name_history
;
12822 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
12823 "Read file name, prompting with PROMPT in directory DIR.\n\
12824 Use a file selection dialog.\n\
12825 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
12826 specified. Don't let the user enter a file name in the file\n\
12827 selection dialog's entry field, if MUSTMATCH is non-nil.")
12828 (prompt
, dir
, default_filename
, mustmatch
)
12829 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
12831 struct frame
*f
= SELECTED_FRAME ();
12832 Lisp_Object file
= Qnil
;
12833 int count
= specpdl_ptr
- specpdl
;
12834 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
12835 char filename
[MAX_PATH
+ 1];
12836 char init_dir
[MAX_PATH
+ 1];
12837 int use_dialog_p
= 1;
12839 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
12840 CHECK_STRING (prompt
, 0);
12841 CHECK_STRING (dir
, 1);
12843 /* Create the dialog with PROMPT as title, using DIR as initial
12844 directory and using "*" as pattern. */
12845 dir
= Fexpand_file_name (dir
, Qnil
);
12846 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
12847 init_dir
[MAX_PATH
] = '\0';
12848 unixtodos_filename (init_dir
);
12850 if (STRINGP (default_filename
))
12852 char *file_name_only
;
12853 char *full_path_name
= XSTRING (default_filename
)->data
;
12855 unixtodos_filename (full_path_name
);
12857 file_name_only
= strrchr (full_path_name
, '\\');
12858 if (!file_name_only
)
12859 file_name_only
= full_path_name
;
12864 /* If default_file_name is a directory, don't use the open
12865 file dialog, as it does not support selecting
12867 if (!(*file_name_only
))
12871 strncpy (filename
, file_name_only
, MAX_PATH
);
12872 filename
[MAX_PATH
] = '\0';
12875 filename
[0] = '\0';
12879 OPENFILENAME file_details
;
12881 /* Prevent redisplay. */
12882 specbind (Qinhibit_redisplay
, Qt
);
12885 bzero (&file_details
, sizeof (file_details
));
12886 file_details
.lStructSize
= sizeof (file_details
);
12887 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
12888 file_details
.lpstrFile
= filename
;
12889 file_details
.nMaxFile
= sizeof (filename
);
12890 file_details
.lpstrInitialDir
= init_dir
;
12891 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
12892 file_details
.Flags
= OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
;
12894 if (!NILP (mustmatch
))
12895 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
12897 if (GetOpenFileName (&file_details
))
12899 dostounix_filename (filename
);
12900 file
= build_string (filename
);
12906 file
= unbind_to (count
, file
);
12908 /* Open File dialog will not allow folders to be selected, so resort
12909 to minibuffer completing reads for directories. */
12911 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
12912 dir
, mustmatch
, dir
, Qfile_name_history
,
12913 default_filename
, Qnil
);
12917 /* Make "Cancel" equivalent to C-g. */
12919 Fsignal (Qquit
, Qnil
);
12921 return unbind_to (count
, file
);
12926 /***********************************************************************
12928 ***********************************************************************/
12932 DEFUN ("imagep", Fimagep
, Simagep
, 1, 1, 0,
12933 "Value is non-nil if SPEC is a valid image specification.")
12937 return valid_image_p (spec
) ? Qt
: Qnil
;
12941 DEFUN ("lookup-image", Flookup_image
, Slookup_image
, 1, 1, 0, "")
12947 if (valid_image_p (spec
))
12948 id
= lookup_image (SELECTED_FRAME (), spec
);
12950 debug_print (spec
);
12951 return make_number (id
);
12954 #endif /* GLYPH_DEBUG != 0 */
12958 /***********************************************************************
12959 w32 specialized functions
12960 ***********************************************************************/
12962 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 1, 0,
12963 "This will display the W32 font dialog and return an X font string corresponding to the selection.")
12967 FRAME_PTR f
= check_x_frame (frame
);
12975 bzero (&cf
, sizeof (cf
));
12976 bzero (&lf
, sizeof (lf
));
12978 cf
.lStructSize
= sizeof (cf
);
12979 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
12980 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
;
12981 cf
.lpLogFont
= &lf
;
12983 /* Initialize as much of the font details as we can from the current
12985 hdc
= GetDC (FRAME_W32_WINDOW (f
));
12986 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
12987 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
12988 if (GetTextMetrics (hdc
, &tm
))
12990 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
12991 lf
.lfWeight
= tm
.tmWeight
;
12992 lf
.lfItalic
= tm
.tmItalic
;
12993 lf
.lfUnderline
= tm
.tmUnderlined
;
12994 lf
.lfStrikeOut
= tm
.tmStruckOut
;
12995 lf
.lfCharSet
= tm
.tmCharSet
;
12996 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
12998 SelectObject (hdc
, oldobj
);
12999 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
13001 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
13004 return build_string (buf
);
13007 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
, Sw32_send_sys_command
, 1, 2, 0,
13008 "Send frame a Windows WM_SYSCOMMAND message of type COMMAND.\n\
13009 Some useful values for command are 0xf030 to maximise frame (0xf020\n\
13010 to minimize), 0xf120 to restore frame to original size, and 0xf100\n\
13011 to activate the menubar for keyboard access. 0xf140 activates the\n\
13012 screen saver if defined.\n\
13014 If optional parameter FRAME is not specified, use selected frame.")
13016 Lisp_Object command
, frame
;
13018 FRAME_PTR f
= check_x_frame (frame
);
13020 CHECK_NUMBER (command
, 0);
13022 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
13027 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
13028 "Get Windows to perform OPERATION on DOCUMENT.\n\
13029 This is a wrapper around the ShellExecute system function, which\n\
13030 invokes the application registered to handle OPERATION for DOCUMENT.\n\
13031 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be\n\
13032 nil for the default action), and DOCUMENT is typically the name of a\n\
13033 document file or URL, but can also be a program executable to run or\n\
13034 a directory to open in the Windows Explorer.\n\
13036 If DOCUMENT is a program executable, PARAMETERS can be a string\n\
13037 containing command line parameters, but otherwise should be nil.\n\
13039 SHOW-FLAG can be used to control whether the invoked application is hidden\n\
13040 or minimized. If SHOW-FLAG is nil, the application is displayed normally,\n\
13041 otherwise it is an integer representing a ShowWindow flag:\n\
13043 0 - start hidden\n\
13044 1 - start normally\n\
13045 3 - start maximized\n\
13046 6 - start minimized")
13047 (operation
, document
, parameters
, show_flag
)
13048 Lisp_Object operation
, document
, parameters
, show_flag
;
13050 Lisp_Object current_dir
;
13052 CHECK_STRING (document
, 0);
13054 /* Encode filename and current directory. */
13055 current_dir
= ENCODE_FILE (current_buffer
->directory
);
13056 document
= ENCODE_FILE (document
);
13057 if ((int) ShellExecute (NULL
,
13058 (STRINGP (operation
) ?
13059 XSTRING (operation
)->data
: NULL
),
13060 XSTRING (document
)->data
,
13061 (STRINGP (parameters
) ?
13062 XSTRING (parameters
)->data
: NULL
),
13063 XSTRING (current_dir
)->data
,
13064 (INTEGERP (show_flag
) ?
13065 XINT (show_flag
) : SW_SHOWDEFAULT
))
13068 error ("ShellExecute failed: %s", w32_strerror (0));
13071 /* Lookup virtual keycode from string representing the name of a
13072 non-ascii keystroke into the corresponding virtual key, using
13073 lispy_function_keys. */
13075 lookup_vk_code (char *key
)
13079 for (i
= 0; i
< 256; i
++)
13080 if (lispy_function_keys
[i
] != 0
13081 && strcmp (lispy_function_keys
[i
], key
) == 0)
13087 /* Convert a one-element vector style key sequence to a hot key
13090 w32_parse_hot_key (key
)
13093 /* Copied from Fdefine_key and store_in_keymap. */
13094 register Lisp_Object c
;
13096 int lisp_modifiers
;
13098 struct gcpro gcpro1
;
13100 CHECK_VECTOR (key
, 0);
13102 if (XFASTINT (Flength (key
)) != 1)
13107 c
= Faref (key
, make_number (0));
13109 if (CONSP (c
) && lucid_event_type_list_p (c
))
13110 c
= Fevent_convert_list (c
);
13114 if (! INTEGERP (c
) && ! SYMBOLP (c
))
13115 error ("Key definition is invalid");
13117 /* Work out the base key and the modifiers. */
13120 c
= parse_modifiers (c
);
13121 lisp_modifiers
= Fcar (Fcdr (c
));
13125 vk_code
= lookup_vk_code (XSYMBOL (c
)->name
->data
);
13127 else if (INTEGERP (c
))
13129 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
13130 /* Many ascii characters are their own virtual key code. */
13131 vk_code
= XINT (c
) & CHARACTERBITS
;
13134 if (vk_code
< 0 || vk_code
> 255)
13137 if ((lisp_modifiers
& meta_modifier
) != 0
13138 && !NILP (Vw32_alt_is_meta
))
13139 lisp_modifiers
|= alt_modifier
;
13141 /* Supply defs missing from mingw32. */
13143 #define MOD_ALT 0x0001
13144 #define MOD_CONTROL 0x0002
13145 #define MOD_SHIFT 0x0004
13146 #define MOD_WIN 0x0008
13149 /* Convert lisp modifiers to Windows hot-key form. */
13150 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
13151 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
13152 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
13153 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
13155 return HOTKEY (vk_code
, w32_modifiers
);
13158 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
, Sw32_register_hot_key
, 1, 1, 0,
13159 "Register KEY as a hot-key combination.\n\
13160 Certain key combinations like Alt-Tab are reserved for system use on\n\
13161 Windows, and therefore are normally intercepted by the system. However,\n\
13162 most of these key combinations can be received by registering them as\n\
13163 hot-keys, overriding their special meaning.\n\
13165 KEY must be a one element key definition in vector form that would be\n\
13166 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta\n\
13167 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper\n\
13168 is always interpreted as the Windows modifier keys.\n\
13170 The return value is the hotkey-id if registered, otherwise nil.")
13174 key
= w32_parse_hot_key (key
);
13176 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
13178 /* Reuse an empty slot if possible. */
13179 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
13181 /* Safe to add new key to list, even if we have focus. */
13183 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
13187 /* Notify input thread about new hot-key definition, so that it
13188 takes effect without needing to switch focus. */
13189 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
13196 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
, Sw32_unregister_hot_key
, 1, 1, 0,
13197 "Unregister HOTKEY as a hot-key combination.")
13203 if (!INTEGERP (key
))
13204 key
= w32_parse_hot_key (key
);
13206 item
= Fmemq (key
, w32_grabbed_keys
);
13210 /* Notify input thread about hot-key definition being removed, so
13211 that it takes effect without needing focus switch. */
13212 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
13213 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
13216 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13223 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
, Sw32_registered_hot_keys
, 0, 0, 0,
13224 "Return list of registered hot-key IDs.")
13227 return Fcopy_sequence (w32_grabbed_keys
);
13230 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
, Sw32_reconstruct_hot_key
, 1, 1, 0,
13231 "Convert hot-key ID to a lisp key combination.")
13233 Lisp_Object hotkeyid
;
13235 int vk_code
, w32_modifiers
;
13238 CHECK_NUMBER (hotkeyid
, 0);
13240 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
13241 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
13243 if (lispy_function_keys
[vk_code
])
13244 key
= intern (lispy_function_keys
[vk_code
]);
13246 key
= make_number (vk_code
);
13248 key
= Fcons (key
, Qnil
);
13249 if (w32_modifiers
& MOD_SHIFT
)
13250 key
= Fcons (Qshift
, key
);
13251 if (w32_modifiers
& MOD_CONTROL
)
13252 key
= Fcons (Qctrl
, key
);
13253 if (w32_modifiers
& MOD_ALT
)
13254 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
13255 if (w32_modifiers
& MOD_WIN
)
13256 key
= Fcons (Qhyper
, key
);
13261 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
, Sw32_toggle_lock_key
, 1, 2, 0,
13262 "Toggle the state of the lock key KEY.\n\
13263 KEY can be `capslock', `kp-numlock', or `scroll'.\n\
13264 If the optional parameter NEW-STATE is a number, then the state of KEY\n\
13265 is set to off if the low bit of NEW-STATE is zero, otherwise on.")
13267 Lisp_Object key
, new_state
;
13271 if (EQ (key
, intern ("capslock")))
13272 vk_code
= VK_CAPITAL
;
13273 else if (EQ (key
, intern ("kp-numlock")))
13274 vk_code
= VK_NUMLOCK
;
13275 else if (EQ (key
, intern ("scroll")))
13276 vk_code
= VK_SCROLL
;
13280 if (!dwWindowsThreadId
)
13281 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
13283 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
13284 (WPARAM
) vk_code
, (LPARAM
) new_state
))
13287 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13288 return make_number (msg
.wParam
);
13293 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
13294 "Return storage information about the file system FILENAME is on.\n\
13295 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total\n\
13296 storage of the file system, FREE is the free storage, and AVAIL is the\n\
13297 storage available to a non-superuser. All 3 numbers are in bytes.\n\
13298 If the underlying system call fails, value is nil.")
13300 Lisp_Object filename
;
13302 Lisp_Object encoded
, value
;
13304 CHECK_STRING (filename
, 0);
13305 filename
= Fexpand_file_name (filename
, Qnil
);
13306 encoded
= ENCODE_FILE (filename
);
13310 /* Determining the required information on Windows turns out, sadly,
13311 to be more involved than one would hope. The original Win32 api
13312 call for this will return bogus information on some systems, but we
13313 must dynamically probe for the replacement api, since that was
13314 added rather late on. */
13316 HMODULE hKernel
= GetModuleHandle ("kernel32");
13317 BOOL (*pfn_GetDiskFreeSpaceEx
)
13318 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
13319 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
13321 /* On Windows, we may need to specify the root directory of the
13322 volume holding FILENAME. */
13323 char rootname
[MAX_PATH
];
13324 char *name
= XSTRING (encoded
)->data
;
13326 /* find the root name of the volume if given */
13327 if (isalpha (name
[0]) && name
[1] == ':')
13329 rootname
[0] = name
[0];
13330 rootname
[1] = name
[1];
13331 rootname
[2] = '\\';
13334 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
13336 char *str
= rootname
;
13340 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
13350 if (pfn_GetDiskFreeSpaceEx
)
13352 LARGE_INTEGER availbytes
;
13353 LARGE_INTEGER freebytes
;
13354 LARGE_INTEGER totalbytes
;
13356 if (pfn_GetDiskFreeSpaceEx(rootname
,
13360 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
13361 make_float ((double) freebytes
.QuadPart
),
13362 make_float ((double) availbytes
.QuadPart
));
13366 DWORD sectors_per_cluster
;
13367 DWORD bytes_per_sector
;
13368 DWORD free_clusters
;
13369 DWORD total_clusters
;
13371 if (GetDiskFreeSpace(rootname
,
13372 §ors_per_cluster
,
13376 value
= list3 (make_float ((double) total_clusters
13377 * sectors_per_cluster
* bytes_per_sector
),
13378 make_float ((double) free_clusters
13379 * sectors_per_cluster
* bytes_per_sector
),
13380 make_float ((double) free_clusters
13381 * sectors_per_cluster
* bytes_per_sector
));
13390 /* This is zero if not using MS-Windows. */
13393 /* The section below is built by the lisp expression at the top of the file,
13394 just above where these variables are declared. */
13395 /*&&& init symbols here &&&*/
13396 Qauto_raise
= intern ("auto-raise");
13397 staticpro (&Qauto_raise
);
13398 Qauto_lower
= intern ("auto-lower");
13399 staticpro (&Qauto_lower
);
13400 Qbar
= intern ("bar");
13402 Qborder_color
= intern ("border-color");
13403 staticpro (&Qborder_color
);
13404 Qborder_width
= intern ("border-width");
13405 staticpro (&Qborder_width
);
13406 Qbox
= intern ("box");
13408 Qcursor_color
= intern ("cursor-color");
13409 staticpro (&Qcursor_color
);
13410 Qcursor_type
= intern ("cursor-type");
13411 staticpro (&Qcursor_type
);
13412 Qgeometry
= intern ("geometry");
13413 staticpro (&Qgeometry
);
13414 Qicon_left
= intern ("icon-left");
13415 staticpro (&Qicon_left
);
13416 Qicon_top
= intern ("icon-top");
13417 staticpro (&Qicon_top
);
13418 Qicon_type
= intern ("icon-type");
13419 staticpro (&Qicon_type
);
13420 Qicon_name
= intern ("icon-name");
13421 staticpro (&Qicon_name
);
13422 Qinternal_border_width
= intern ("internal-border-width");
13423 staticpro (&Qinternal_border_width
);
13424 Qleft
= intern ("left");
13425 staticpro (&Qleft
);
13426 Qright
= intern ("right");
13427 staticpro (&Qright
);
13428 Qmouse_color
= intern ("mouse-color");
13429 staticpro (&Qmouse_color
);
13430 Qnone
= intern ("none");
13431 staticpro (&Qnone
);
13432 Qparent_id
= intern ("parent-id");
13433 staticpro (&Qparent_id
);
13434 Qscroll_bar_width
= intern ("scroll-bar-width");
13435 staticpro (&Qscroll_bar_width
);
13436 Qsuppress_icon
= intern ("suppress-icon");
13437 staticpro (&Qsuppress_icon
);
13438 Qundefined_color
= intern ("undefined-color");
13439 staticpro (&Qundefined_color
);
13440 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
13441 staticpro (&Qvertical_scroll_bars
);
13442 Qvisibility
= intern ("visibility");
13443 staticpro (&Qvisibility
);
13444 Qwindow_id
= intern ("window-id");
13445 staticpro (&Qwindow_id
);
13446 Qx_frame_parameter
= intern ("x-frame-parameter");
13447 staticpro (&Qx_frame_parameter
);
13448 Qx_resource_name
= intern ("x-resource-name");
13449 staticpro (&Qx_resource_name
);
13450 Quser_position
= intern ("user-position");
13451 staticpro (&Quser_position
);
13452 Quser_size
= intern ("user-size");
13453 staticpro (&Quser_size
);
13454 Qscreen_gamma
= intern ("screen-gamma");
13455 staticpro (&Qscreen_gamma
);
13456 Qline_spacing
= intern ("line-spacing");
13457 staticpro (&Qline_spacing
);
13458 Qcenter
= intern ("center");
13459 staticpro (&Qcenter
);
13460 Qcancel_timer
= intern ("cancel-timer");
13461 staticpro (&Qcancel_timer
);
13462 /* This is the end of symbol initialization. */
13464 Qhyper
= intern ("hyper");
13465 staticpro (&Qhyper
);
13466 Qsuper
= intern ("super");
13467 staticpro (&Qsuper
);
13468 Qmeta
= intern ("meta");
13469 staticpro (&Qmeta
);
13470 Qalt
= intern ("alt");
13472 Qctrl
= intern ("ctrl");
13473 staticpro (&Qctrl
);
13474 Qcontrol
= intern ("control");
13475 staticpro (&Qcontrol
);
13476 Qshift
= intern ("shift");
13477 staticpro (&Qshift
);
13479 /* Text property `display' should be nonsticky by default. */
13480 Vtext_property_default_nonsticky
13481 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
13484 Qlaplace
= intern ("laplace");
13485 staticpro (&Qlaplace
);
13487 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
13488 staticpro (&Qface_set_after_frame_default
);
13490 Fput (Qundefined_color
, Qerror_conditions
,
13491 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
13492 Fput (Qundefined_color
, Qerror_message
,
13493 build_string ("Undefined color"));
13495 staticpro (&w32_grabbed_keys
);
13496 w32_grabbed_keys
= Qnil
;
13498 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
13499 "An array of color name mappings for windows.");
13500 Vw32_color_map
= Qnil
;
13502 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
13503 "Non-nil if alt key presses are passed on to Windows.\n\
13504 When non-nil, for example, alt pressed and released and then space will\n\
13505 open the System menu. When nil, Emacs silently swallows alt key events.");
13506 Vw32_pass_alt_to_system
= Qnil
;
13508 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
13509 "Non-nil if the alt key is to be considered the same as the meta key.\n\
13510 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta.");
13511 Vw32_alt_is_meta
= Qt
;
13513 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
13514 "If non-zero, the virtual key code for an alternative quit key.");
13515 XSETINT (Vw32_quit_key
, 0);
13517 DEFVAR_LISP ("w32-pass-lwindow-to-system",
13518 &Vw32_pass_lwindow_to_system
,
13519 "Non-nil if the left \"Windows\" key is passed on to Windows.\n\
13520 When non-nil, the Start menu is opened by tapping the key.");
13521 Vw32_pass_lwindow_to_system
= Qt
;
13523 DEFVAR_LISP ("w32-pass-rwindow-to-system",
13524 &Vw32_pass_rwindow_to_system
,
13525 "Non-nil if the right \"Windows\" key is passed on to Windows.\n\
13526 When non-nil, the Start menu is opened by tapping the key.");
13527 Vw32_pass_rwindow_to_system
= Qt
;
13529 DEFVAR_INT ("w32-phantom-key-code",
13530 &Vw32_phantom_key_code
,
13531 "Virtual key code used to generate \"phantom\" key presses.\n\
13532 Value is a number between 0 and 255.\n\
13534 Phantom key presses are generated in order to stop the system from\n\
13535 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or\n\
13536 `w32-pass-rwindow-to-system' is nil.");
13537 /* Although 255 is technically not a valid key code, it works and
13538 means that this hack won't interfere with any real key code. */
13539 Vw32_phantom_key_code
= 255;
13541 DEFVAR_LISP ("w32-enable-num-lock",
13542 &Vw32_enable_num_lock
,
13543 "Non-nil if Num Lock should act normally.\n\
13544 Set to nil to see Num Lock as the key `kp-numlock'.");
13545 Vw32_enable_num_lock
= Qt
;
13547 DEFVAR_LISP ("w32-enable-caps-lock",
13548 &Vw32_enable_caps_lock
,
13549 "Non-nil if Caps Lock should act normally.\n\
13550 Set to nil to see Caps Lock as the key `capslock'.");
13551 Vw32_enable_caps_lock
= Qt
;
13553 DEFVAR_LISP ("w32-scroll-lock-modifier",
13554 &Vw32_scroll_lock_modifier
,
13555 "Modifier to use for the Scroll Lock on state.\n\
13556 The value can be hyper, super, meta, alt, control or shift for the\n\
13557 respective modifier, or nil to see Scroll Lock as the key `scroll'.\n\
13558 Any other value will cause the key to be ignored.");
13559 Vw32_scroll_lock_modifier
= Qt
;
13561 DEFVAR_LISP ("w32-lwindow-modifier",
13562 &Vw32_lwindow_modifier
,
13563 "Modifier to use for the left \"Windows\" key.\n\
13564 The value can be hyper, super, meta, alt, control or shift for the\n\
13565 respective modifier, or nil to appear as the key `lwindow'.\n\
13566 Any other value will cause the key to be ignored.");
13567 Vw32_lwindow_modifier
= Qnil
;
13569 DEFVAR_LISP ("w32-rwindow-modifier",
13570 &Vw32_rwindow_modifier
,
13571 "Modifier to use for the right \"Windows\" key.\n\
13572 The value can be hyper, super, meta, alt, control or shift for the\n\
13573 respective modifier, or nil to appear as the key `rwindow'.\n\
13574 Any other value will cause the key to be ignored.");
13575 Vw32_rwindow_modifier
= Qnil
;
13577 DEFVAR_LISP ("w32-apps-modifier",
13578 &Vw32_apps_modifier
,
13579 "Modifier to use for the \"Apps\" key.\n\
13580 The value can be hyper, super, meta, alt, control or shift for the\n\
13581 respective modifier, or nil to appear as the key `apps'.\n\
13582 Any other value will cause the key to be ignored.");
13583 Vw32_apps_modifier
= Qnil
;
13585 DEFVAR_LISP ("w32-enable-synthesized-fonts", &Vw32_enable_synthesized_fonts
,
13586 "Non-nil enables selection of artificially italicized and bold fonts.");
13587 Vw32_enable_synthesized_fonts
= Qnil
;
13589 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
13590 "Non-nil enables Windows palette management to map colors exactly.");
13591 Vw32_enable_palette
= Qt
;
13593 DEFVAR_INT ("w32-mouse-button-tolerance",
13594 &Vw32_mouse_button_tolerance
,
13595 "Analogue of double click interval for faking middle mouse events.\n\
13596 The value is the minimum time in milliseconds that must elapse between\n\
13597 left/right button down events before they are considered distinct events.\n\
13598 If both mouse buttons are depressed within this interval, a middle mouse\n\
13599 button down event is generated instead.");
13600 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
13602 DEFVAR_INT ("w32-mouse-move-interval",
13603 &Vw32_mouse_move_interval
,
13604 "Minimum interval between mouse move events.\n\
13605 The value is the minimum time in milliseconds that must elapse between\n\
13606 successive mouse move (or scroll bar drag) events before they are\n\
13607 reported as lisp events.");
13608 XSETINT (Vw32_mouse_move_interval
, 0);
13610 init_x_parm_symbols ();
13612 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
13613 "List of directories to search for bitmap files for w32.");
13614 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
13616 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
13617 "The shape of the pointer when over text.\n\
13618 Changing the value does not affect existing frames\n\
13619 unless you set the mouse color.");
13620 Vx_pointer_shape
= Qnil
;
13622 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
13623 "The name Emacs uses to look up resources; for internal use only.\n\
13624 `x-get-resource' uses this as the first component of the instance name\n\
13625 when requesting resource values.\n\
13626 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
13627 was invoked, or to the value specified with the `-name' or `-rn'\n\
13628 switches, if present.");
13629 Vx_resource_name
= Qnil
;
13631 Vx_nontext_pointer_shape
= Qnil
;
13633 Vx_mode_pointer_shape
= Qnil
;
13635 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
13636 "The shape of the pointer when Emacs is busy.\n\
13637 This variable takes effect when you create a new frame\n\
13638 or when you set the mouse color.");
13639 Vx_hourglass_pointer_shape
= Qnil
;
13641 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
13642 "Non-zero means Emacs displays an hourglass pointer on window systems.");
13643 display_hourglass_p
= 1;
13645 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
13646 "*Seconds to wait before displaying an hourglass pointer.\n\
13647 Value must be an integer or float.");
13648 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
13650 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
13651 &Vx_sensitive_text_pointer_shape
,
13652 "The shape of the pointer when over mouse-sensitive text.\n\
13653 This variable takes effect when you create a new frame\n\
13654 or when you set the mouse color.");
13655 Vx_sensitive_text_pointer_shape
= Qnil
;
13657 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
13658 &Vx_window_horizontal_drag_shape
,
13659 "Pointer shape to use for indicating a window can be dragged horizontally.\n\
13660 This variable takes effect when you create a new frame\n\
13661 or when you set the mouse color.");
13662 Vx_window_horizontal_drag_shape
= Qnil
;
13664 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
13665 "A string indicating the foreground color of the cursor box.");
13666 Vx_cursor_fore_pixel
= Qnil
;
13668 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
13669 "Non-nil if no window manager is in use.\n\
13670 Emacs doesn't try to figure this out; this is always nil\n\
13671 unless you set it to something else.");
13672 /* We don't have any way to find this out, so set it to nil
13673 and maybe the user would like to set it to t. */
13674 Vx_no_window_manager
= Qnil
;
13676 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
13677 &Vx_pixel_size_width_font_regexp
,
13678 "Regexp matching a font name whose width is the same as `PIXEL_SIZE'.\n\
13680 Since Emacs gets width of a font matching with this regexp from\n\
13681 PIXEL_SIZE field of the name, font finding mechanism gets faster for\n\
13682 such a font. This is especially effective for such large fonts as\n\
13683 Chinese, Japanese, and Korean.");
13684 Vx_pixel_size_width_font_regexp
= Qnil
;
13686 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
13687 "Time after which cached images are removed from the cache.\n\
13688 When an image has not been displayed this many seconds, remove it\n\
13689 from the image cache. Value must be an integer or nil with nil\n\
13690 meaning don't clear the cache.");
13691 Vimage_cache_eviction_delay
= make_number (30 * 60);
13693 DEFVAR_LISP ("w32-bdf-filename-alist",
13694 &Vw32_bdf_filename_alist
,
13695 "List of bdf fonts and their corresponding filenames.");
13696 Vw32_bdf_filename_alist
= Qnil
;
13698 DEFVAR_BOOL ("w32-strict-fontnames",
13699 &w32_strict_fontnames
,
13700 "Non-nil means only use fonts that are exact matches for those requested.\n\
13701 Default is nil, which allows old fontnames that are not XLFD compliant,\n\
13702 and allows third-party CJK display to work by specifying false charset\n\
13703 fields to trick Emacs into translating to Big5, SJIS etc.\n\
13704 Setting this to t will prevent wrong fonts being selected when\n\
13705 fontsets are automatically created.");
13706 w32_strict_fontnames
= 0;
13708 DEFVAR_BOOL ("w32-strict-painting",
13709 &w32_strict_painting
,
13710 "Non-nil means use strict rules for repainting frames.\n\
13711 Set this to nil to get the old behaviour for repainting; this should\n\
13712 only be necessary if the default setting causes problems.");
13713 w32_strict_painting
= 1;
13715 DEFVAR_LISP ("w32-system-coding-system",
13716 &Vw32_system_coding_system
,
13717 "Coding system used by Windows system functions, such as for font names.");
13718 Vw32_system_coding_system
= Qnil
;
13720 DEFVAR_LISP ("w32-charset-info-alist",
13721 &Vw32_charset_info_alist
,
13722 "Alist linking Emacs character sets to Windows fonts\n\
13723 and codepages. Each entry should be of the form:\n\
13725 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))\n\
13727 where CHARSET_NAME is a string used in font names to identify the charset,\n\
13728 WINDOWS_CHARSET is a symbol that can be one of:\n\
13729 w32-charset-ansi, w32-charset-default, w32-charset-symbol,\n\
13730 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,\n\
13731 w32-charset-chinesebig5, "
13732 #ifdef JOHAB_CHARSET
13733 "w32-charset-johab, w32-charset-hebrew,\n\
13734 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,\n\
13735 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,\n\
13736 w32-charset-russian, w32-charset-mac, w32-charset-baltic,\n"
13738 #ifdef UNICODE_CHARSET
13739 "w32-charset-unicode, "
13741 "or w32-charset-oem.\n\
13742 CODEPAGE should be an integer specifying the codepage that should be used\n\
13743 to display the character set, t to do no translation and output as Unicode,\n\
13744 or nil to do no translation and output as 8 bit (or multibyte on far-east\n\
13745 versions of Windows) characters.");
13746 Vw32_charset_info_alist
= Qnil
;
13748 staticpro (&Qw32_charset_ansi
);
13749 Qw32_charset_ansi
= intern ("w32-charset-ansi");
13750 staticpro (&Qw32_charset_symbol
);
13751 Qw32_charset_symbol
= intern ("w32-charset-symbol");
13752 staticpro (&Qw32_charset_shiftjis
);
13753 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
13754 staticpro (&Qw32_charset_hangeul
);
13755 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
13756 staticpro (&Qw32_charset_chinesebig5
);
13757 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
13758 staticpro (&Qw32_charset_gb2312
);
13759 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
13760 staticpro (&Qw32_charset_oem
);
13761 Qw32_charset_oem
= intern ("w32-charset-oem");
13763 #ifdef JOHAB_CHARSET
13765 static int w32_extra_charsets_defined
= 1;
13766 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
, "");
13768 staticpro (&Qw32_charset_johab
);
13769 Qw32_charset_johab
= intern ("w32-charset-johab");
13770 staticpro (&Qw32_charset_easteurope
);
13771 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
13772 staticpro (&Qw32_charset_turkish
);
13773 Qw32_charset_turkish
= intern ("w32-charset-turkish");
13774 staticpro (&Qw32_charset_baltic
);
13775 Qw32_charset_baltic
= intern ("w32-charset-baltic");
13776 staticpro (&Qw32_charset_russian
);
13777 Qw32_charset_russian
= intern ("w32-charset-russian");
13778 staticpro (&Qw32_charset_arabic
);
13779 Qw32_charset_arabic
= intern ("w32-charset-arabic");
13780 staticpro (&Qw32_charset_greek
);
13781 Qw32_charset_greek
= intern ("w32-charset-greek");
13782 staticpro (&Qw32_charset_hebrew
);
13783 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
13784 staticpro (&Qw32_charset_vietnamese
);
13785 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
13786 staticpro (&Qw32_charset_thai
);
13787 Qw32_charset_thai
= intern ("w32-charset-thai");
13788 staticpro (&Qw32_charset_mac
);
13789 Qw32_charset_mac
= intern ("w32-charset-mac");
13793 #ifdef UNICODE_CHARSET
13795 static int w32_unicode_charset_defined
= 1;
13796 DEFVAR_BOOL ("w32-unicode-charset-defined",
13797 &w32_unicode_charset_defined
, "");
13799 staticpro (&Qw32_charset_unicode
);
13800 Qw32_charset_unicode
= intern ("w32-charset-unicode");
13803 defsubr (&Sx_get_resource
);
13804 #if 0 /* TODO: Port to W32 */
13805 defsubr (&Sx_change_window_property
);
13806 defsubr (&Sx_delete_window_property
);
13807 defsubr (&Sx_window_property
);
13809 defsubr (&Sxw_display_color_p
);
13810 defsubr (&Sx_display_grayscale_p
);
13811 defsubr (&Sxw_color_defined_p
);
13812 defsubr (&Sxw_color_values
);
13813 defsubr (&Sx_server_max_request_size
);
13814 defsubr (&Sx_server_vendor
);
13815 defsubr (&Sx_server_version
);
13816 defsubr (&Sx_display_pixel_width
);
13817 defsubr (&Sx_display_pixel_height
);
13818 defsubr (&Sx_display_mm_width
);
13819 defsubr (&Sx_display_mm_height
);
13820 defsubr (&Sx_display_screens
);
13821 defsubr (&Sx_display_planes
);
13822 defsubr (&Sx_display_color_cells
);
13823 defsubr (&Sx_display_visual_class
);
13824 defsubr (&Sx_display_backing_store
);
13825 defsubr (&Sx_display_save_under
);
13826 defsubr (&Sx_parse_geometry
);
13827 defsubr (&Sx_create_frame
);
13828 defsubr (&Sx_open_connection
);
13829 defsubr (&Sx_close_connection
);
13830 defsubr (&Sx_display_list
);
13831 defsubr (&Sx_synchronize
);
13833 /* W32 specific functions */
13835 defsubr (&Sw32_focus_frame
);
13836 defsubr (&Sw32_select_font
);
13837 defsubr (&Sw32_define_rgb_color
);
13838 defsubr (&Sw32_default_color_map
);
13839 defsubr (&Sw32_load_color_file
);
13840 defsubr (&Sw32_send_sys_command
);
13841 defsubr (&Sw32_shell_execute
);
13842 defsubr (&Sw32_register_hot_key
);
13843 defsubr (&Sw32_unregister_hot_key
);
13844 defsubr (&Sw32_registered_hot_keys
);
13845 defsubr (&Sw32_reconstruct_hot_key
);
13846 defsubr (&Sw32_toggle_lock_key
);
13847 defsubr (&Sw32_find_bdf_fonts
);
13849 defsubr (&Sfile_system_info
);
13851 /* Setting callback functions for fontset handler. */
13852 get_font_info_func
= w32_get_font_info
;
13854 #if 0 /* This function pointer doesn't seem to be used anywhere.
13855 And the pointer assigned has the wrong type, anyway. */
13856 list_fonts_func
= w32_list_fonts
;
13859 load_font_func
= w32_load_font
;
13860 find_ccl_program_func
= w32_find_ccl_program
;
13861 query_font_func
= w32_query_font
;
13862 set_frame_fontset_func
= x_set_font
;
13863 check_window_system_func
= check_w32
;
13865 #if 0 /* TODO Image support for W32 */
13867 Qxbm
= intern ("xbm");
13869 QCtype
= intern (":type");
13870 staticpro (&QCtype
);
13871 QCconversion
= intern (":conversion");
13872 staticpro (&QCconversion
);
13873 QCheuristic_mask
= intern (":heuristic-mask");
13874 staticpro (&QCheuristic_mask
);
13875 QCcolor_symbols
= intern (":color-symbols");
13876 staticpro (&QCcolor_symbols
);
13877 QCascent
= intern (":ascent");
13878 staticpro (&QCascent
);
13879 QCmargin
= intern (":margin");
13880 staticpro (&QCmargin
);
13881 QCrelief
= intern (":relief");
13882 staticpro (&QCrelief
);
13883 Qpostscript
= intern ("postscript");
13884 staticpro (&Qpostscript
);
13885 QCloader
= intern (":loader");
13886 staticpro (&QCloader
);
13887 QCbounding_box
= intern (":bounding-box");
13888 staticpro (&QCbounding_box
);
13889 QCpt_width
= intern (":pt-width");
13890 staticpro (&QCpt_width
);
13891 QCpt_height
= intern (":pt-height");
13892 staticpro (&QCpt_height
);
13893 QCindex
= intern (":index");
13894 staticpro (&QCindex
);
13895 Qpbm
= intern ("pbm");
13899 Qxpm
= intern ("xpm");
13904 Qjpeg
= intern ("jpeg");
13905 staticpro (&Qjpeg
);
13909 Qtiff
= intern ("tiff");
13910 staticpro (&Qtiff
);
13914 Qgif
= intern ("gif");
13919 Qpng
= intern ("png");
13923 defsubr (&Sclear_image_cache
);
13926 defsubr (&Simagep
);
13927 defsubr (&Slookup_image
);
13931 hourglass_atimer
= NULL
;
13932 hourglass_shown_p
= 0;
13933 #ifdef TODO /* Tooltip support not complete. */
13934 defsubr (&Sx_show_tip
);
13935 defsubr (&Sx_hide_tip
);
13938 staticpro (&tip_timer
);
13940 staticpro (&tip_frame
);
13942 defsubr (&Sx_file_dialog
);
13949 image_types
= NULL
;
13950 Vimage_types
= Qnil
;
13952 #if 0 /* TODO : Image support for W32 */
13953 define_image_type (&xbm_type
);
13954 define_image_type (&gs_type
);
13955 define_image_type (&pbm_type
);
13958 define_image_type (&xpm_type
);
13962 define_image_type (&jpeg_type
);
13966 define_image_type (&tiff_type
);
13970 define_image_type (&gif_type
);
13974 define_image_type (&png_type
);
13985 button
= MessageBox (NULL
,
13986 "A fatal error has occurred!\n\n"
13987 "Select Abort to exit, Retry to debug, Ignore to continue",
13988 "Emacs Abort Dialog",
13989 MB_ICONEXCLAMATION
| MB_TASKMODAL
13990 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
14005 /* For convenience when debugging. */
14009 return GetLastError ();