1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 92, 93, 94, 95, 1996, 1997, 1998, 1999
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 */
38 #include "dispextern.h"
39 #include "intervals.h"
41 #include "blockinput.h"
44 #include "termhooks.h"
49 #include "bitmaps/gray.xbm"
55 extern void free_frame_menubar ();
56 extern double atof ();
57 extern struct scroll_bar
*x_window_to_scroll_bar ();
58 extern int w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
);
61 /* A definition of XColor for non-X frames. */
62 #ifndef HAVE_X_WINDOWS
65 unsigned short red
, green
, blue
;
71 extern char *lispy_function_keys
[];
73 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
74 it, and including `bitmaps/gray' more than once is a problem when
75 config.h defines `static' as an empty replacement string. */
77 int gray_bitmap_width
= gray_width
;
78 int gray_bitmap_height
= gray_height
;
79 unsigned char *gray_bitmap_bits
= gray_bits
;
81 /* The colormap for converting color names to RGB values */
82 Lisp_Object Vw32_color_map
;
84 /* Non nil if alt key presses are passed on to Windows. */
85 Lisp_Object Vw32_pass_alt_to_system
;
87 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
89 Lisp_Object Vw32_alt_is_meta
;
91 /* If non-zero, the windows virtual key code for an alternative quit key. */
92 Lisp_Object Vw32_quit_key
;
94 /* Non nil if left window key events are passed on to Windows (this only
95 affects whether "tapping" the key opens the Start menu). */
96 Lisp_Object Vw32_pass_lwindow_to_system
;
98 /* Non nil if right window key events are passed on to Windows (this
99 only affects whether "tapping" the key opens the Start menu). */
100 Lisp_Object Vw32_pass_rwindow_to_system
;
102 /* Virtual key code used to generate "phantom" key presses in order
103 to stop system from acting on Windows key events. */
104 Lisp_Object Vw32_phantom_key_code
;
106 /* Modifier associated with the left "Windows" key, or nil to act as a
108 Lisp_Object Vw32_lwindow_modifier
;
110 /* Modifier associated with the right "Windows" key, or nil to act as a
112 Lisp_Object Vw32_rwindow_modifier
;
114 /* Modifier associated with the "Apps" key, or nil to act as a normal
116 Lisp_Object Vw32_apps_modifier
;
118 /* Value is nil if Num Lock acts as a function key. */
119 Lisp_Object Vw32_enable_num_lock
;
121 /* Value is nil if Caps Lock acts as a function key. */
122 Lisp_Object Vw32_enable_caps_lock
;
124 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
125 Lisp_Object Vw32_scroll_lock_modifier
;
127 /* Switch to control whether we inhibit requests for synthesyzed bold
128 and italic versions of fonts. */
129 Lisp_Object Vw32_enable_synthesized_fonts
;
131 /* Enable palette management. */
132 Lisp_Object Vw32_enable_palette
;
134 /* Control how close left/right button down events must be to
135 be converted to a middle button down event. */
136 Lisp_Object Vw32_mouse_button_tolerance
;
138 /* Minimum interval between mouse movement (and scroll bar drag)
139 events that are passed on to the event loop. */
140 Lisp_Object Vw32_mouse_move_interval
;
142 /* The name we're using in resource queries. */
143 Lisp_Object Vx_resource_name
;
145 /* Non nil if no window manager is in use. */
146 Lisp_Object Vx_no_window_manager
;
148 /* Non-zero means we're allowed to display a busy cursor. */
149 int display_busy_cursor_p
;
151 /* The background and shape of the mouse pointer, and shape when not
152 over text or in the modeline. */
153 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
154 Lisp_Object Vx_busy_pointer_shape
;
156 /* The shape when over mouse-sensitive text. */
157 Lisp_Object Vx_sensitive_text_pointer_shape
;
159 /* Color of chars displayed in cursor box. */
160 Lisp_Object Vx_cursor_fore_pixel
;
162 /* Nonzero if using Windows. */
163 static int w32_in_use
;
165 /* Search path for bitmap files. */
166 Lisp_Object Vx_bitmap_file_path
;
168 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
169 Lisp_Object Vx_pixel_size_width_font_regexp
;
171 /* Alist of bdf fonts and the files that define them. */
172 Lisp_Object Vw32_bdf_filename_alist
;
174 Lisp_Object Vw32_system_coding_system
;
176 /* A flag to control whether fonts are matched strictly or not. */
177 int w32_strict_fontnames
;
179 /* A flag to control whether we should only repaint if GetUpdateRect
180 indicates there is an update region. */
181 int w32_strict_painting
;
183 /* Evaluate this expression to rebuild the section of syms_of_w32fns
184 that initializes and staticpros the symbols declared below. Note
185 that Emacs 18 has a bug that keeps C-x C-e from being able to
186 evaluate this expression.
189 ;; Accumulate a list of the symbols we want to initialize from the
190 ;; declarations at the top of the file.
191 (goto-char (point-min))
192 (search-forward "/\*&&& symbols declared here &&&*\/\n")
194 (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
196 (cons (buffer-substring (match-beginning 1) (match-end 1))
199 (setq symbol-list (nreverse symbol-list))
200 ;; Delete the section of syms_of_... where we initialize the symbols.
201 (search-forward "\n /\*&&& init symbols here &&&*\/\n")
202 (let ((start (point)))
203 (while (looking-at "^ Q")
205 (kill-region start (point)))
206 ;; Write a new symbol initialization section.
208 (insert (format " %s = intern (\"" (car symbol-list)))
209 (let ((start (point)))
210 (insert (substring (car symbol-list) 1))
211 (subst-char-in-region start (point) ?_ ?-))
212 (insert (format "\");\n staticpro (&%s);\n" (car symbol-list)))
213 (setq symbol-list (cdr symbol-list)))))
217 /*&&& symbols declared here &&&*/
218 Lisp_Object Qauto_raise
;
219 Lisp_Object Qauto_lower
;
221 Lisp_Object Qborder_color
;
222 Lisp_Object Qborder_width
;
224 Lisp_Object Qcursor_color
;
225 Lisp_Object Qcursor_type
;
226 Lisp_Object Qgeometry
;
227 Lisp_Object Qicon_left
;
228 Lisp_Object Qicon_top
;
229 Lisp_Object Qicon_type
;
230 Lisp_Object Qicon_name
;
231 Lisp_Object Qinternal_border_width
;
234 Lisp_Object Qmouse_color
;
236 Lisp_Object Qparent_id
;
237 Lisp_Object Qscroll_bar_width
;
238 Lisp_Object Qsuppress_icon
;
239 Lisp_Object Qundefined_color
;
240 Lisp_Object Qvertical_scroll_bars
;
241 Lisp_Object Qvisibility
;
242 Lisp_Object Qwindow_id
;
243 Lisp_Object Qx_frame_parameter
;
244 Lisp_Object Qx_resource_name
;
245 Lisp_Object Quser_position
;
246 Lisp_Object Quser_size
;
247 Lisp_Object Qscreen_gamma
;
253 Lisp_Object Qcontrol
;
256 extern Lisp_Object Qtop
;
257 extern Lisp_Object Qdisplay
;
258 extern Lisp_Object Qtool_bar_lines
;
260 /* State variables for emulating a three button mouse. */
265 static int button_state
= 0;
266 static W32Msg saved_mouse_button_msg
;
267 static unsigned mouse_button_timer
; /* non-zero when timer is active */
268 static W32Msg saved_mouse_move_msg
;
269 static unsigned mouse_move_timer
;
271 /* W95 mousewheel handler */
272 unsigned int msh_mousewheel
= 0;
274 #define MOUSE_BUTTON_ID 1
275 #define MOUSE_MOVE_ID 2
277 /* The below are defined in frame.c. */
278 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
279 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
, Qbuffer_predicate
, Qtitle
;
280 extern Lisp_Object Qtool_bar_lines
;
282 extern Lisp_Object Vwindow_system_version
;
284 Lisp_Object Qface_set_after_frame_default
;
286 extern Lisp_Object last_mouse_scroll_bar
;
287 extern int last_mouse_scroll_bar_pos
;
289 /* From w32term.c. */
290 extern Lisp_Object Vw32_num_mouse_buttons
;
291 extern Lisp_Object Vw32_recognize_altgr
;
294 /* Error if we are not connected to MS-Windows. */
299 error ("MS-Windows not in use or not initialized");
302 /* Nonzero if we can use mouse menus.
303 You should not call this unless HAVE_MENUS is defined. */
311 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
312 and checking validity for W32. */
315 check_x_frame (frame
)
321 frame
= selected_frame
;
322 CHECK_LIVE_FRAME (frame
, 0);
324 if (! FRAME_W32_P (f
))
325 error ("non-w32 frame used");
329 /* Let the user specify an display with a frame.
330 nil stands for the selected frame--or, if that is not a w32 frame,
331 the first display on the list. */
333 static struct w32_display_info
*
334 check_x_display_info (frame
)
339 struct frame
*sf
= XFRAME (selected_frame
);
341 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
342 return FRAME_W32_DISPLAY_INFO (sf
);
344 return &one_w32_display_info
;
346 else if (STRINGP (frame
))
347 return x_display_info_for_name (frame
);
352 CHECK_LIVE_FRAME (frame
, 0);
354 if (! FRAME_W32_P (f
))
355 error ("non-w32 frame used");
356 return FRAME_W32_DISPLAY_INFO (f
);
360 /* Return the Emacs frame-object corresponding to an w32 window.
361 It could be the frame's main window or an icon window. */
363 /* This function can be called during GC, so use GC_xxx type test macros. */
366 x_window_to_frame (dpyinfo
, wdesc
)
367 struct w32_display_info
*dpyinfo
;
370 Lisp_Object tail
, frame
;
373 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
376 if (!GC_FRAMEP (frame
))
379 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
381 if (FRAME_W32_WINDOW (f
) == wdesc
)
389 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
390 id, which is just an int that this section returns. Bitmaps are
391 reference counted so they can be shared among frames.
393 Bitmap indices are guaranteed to be > 0, so a negative number can
394 be used to indicate no bitmap.
396 If you use x_create_bitmap_from_data, then you must keep track of
397 the bitmaps yourself. That is, creating a bitmap from the same
398 data more than once will not be caught. */
401 /* Functions to access the contents of a bitmap, given an id. */
404 x_bitmap_height (f
, id
)
408 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
412 x_bitmap_width (f
, id
)
416 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
420 x_bitmap_pixmap (f
, id
)
424 return (int) FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
428 /* Allocate a new bitmap record. Returns index of new record. */
431 x_allocate_bitmap_record (f
)
434 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
437 if (dpyinfo
->bitmaps
== NULL
)
439 dpyinfo
->bitmaps_size
= 10;
441 = (struct w32_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
442 dpyinfo
->bitmaps_last
= 1;
446 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
447 return ++dpyinfo
->bitmaps_last
;
449 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
450 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
453 dpyinfo
->bitmaps_size
*= 2;
455 = (struct w32_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
456 dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
457 return ++dpyinfo
->bitmaps_last
;
460 /* Add one reference to the reference count of the bitmap with id ID. */
463 x_reference_bitmap (f
, id
)
467 ++FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
470 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
473 x_create_bitmap_from_data (f
, bits
, width
, height
)
476 unsigned int width
, height
;
478 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
482 bitmap
= CreateBitmap (width
, height
,
483 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_planes
,
484 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_cbits
,
490 id
= x_allocate_bitmap_record (f
);
491 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
492 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
493 dpyinfo
->bitmaps
[id
- 1].hinst
= NULL
;
494 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
495 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
496 dpyinfo
->bitmaps
[id
- 1].height
= height
;
497 dpyinfo
->bitmaps
[id
- 1].width
= width
;
502 /* Create bitmap from file FILE for frame F. */
505 x_create_bitmap_from_file (f
, file
)
510 #if 0 /* NTEMACS_TODO : bitmap support */
511 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
512 unsigned int width
, height
;
514 int xhot
, yhot
, result
, id
;
520 /* Look for an existing bitmap with the same name. */
521 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
523 if (dpyinfo
->bitmaps
[id
].refcount
524 && dpyinfo
->bitmaps
[id
].file
525 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) XSTRING (file
)->data
))
527 ++dpyinfo
->bitmaps
[id
].refcount
;
532 /* Search bitmap-file-path for the file, if appropriate. */
533 fd
= openp (Vx_bitmap_file_path
, file
, "", &found
, 0);
536 /* LoadLibraryEx won't handle special files handled by Emacs handler. */
541 filename
= (char *) XSTRING (found
)->data
;
543 hinst
= LoadLibraryEx (filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
549 result
= XReadBitmapFile (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
550 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
551 if (result
!= BitmapSuccess
)
554 id
= x_allocate_bitmap_record (f
);
555 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
556 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
557 dpyinfo
->bitmaps
[id
- 1].file
= (char *) xmalloc (XSTRING (file
)->size
+ 1);
558 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
559 dpyinfo
->bitmaps
[id
- 1].height
= height
;
560 dpyinfo
->bitmaps
[id
- 1].width
= width
;
561 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, XSTRING (file
)->data
);
564 #endif /* NTEMACS_TODO */
567 /* Remove reference to bitmap with id number ID. */
570 x_destroy_bitmap (f
, id
)
574 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
578 --dpyinfo
->bitmaps
[id
- 1].refcount
;
579 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
582 DeleteObject (dpyinfo
->bitmaps
[id
- 1].pixmap
);
583 if (dpyinfo
->bitmaps
[id
- 1].file
)
585 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
586 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
593 /* Free all the bitmaps for the display specified by DPYINFO. */
596 x_destroy_all_bitmaps (dpyinfo
)
597 struct w32_display_info
*dpyinfo
;
600 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
601 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
603 DeleteObject (dpyinfo
->bitmaps
[i
].pixmap
);
604 if (dpyinfo
->bitmaps
[i
].file
)
605 xfree (dpyinfo
->bitmaps
[i
].file
);
607 dpyinfo
->bitmaps_last
= 0;
610 /* Connect the frame-parameter names for W32 frames
611 to the ways of passing the parameter values to the window system.
613 The name of a parameter, as a Lisp symbol,
614 has an `x-frame-parameter' property which is an integer in Lisp
615 but can be interpreted as an `enum x_frame_parm' in C. */
619 X_PARM_FOREGROUND_COLOR
,
620 X_PARM_BACKGROUND_COLOR
,
627 X_PARM_INTERNAL_BORDER_WIDTH
,
631 X_PARM_VERT_SCROLL_BAR
,
633 X_PARM_MENU_BAR_LINES
637 struct x_frame_parm_table
640 void (*setter
) P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
643 /* NTEMACS_TODO: Native Input Method support; see x_create_im. */
644 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
645 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
646 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
647 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
648 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
649 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
650 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
651 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
652 void x_set_font
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
653 void x_set_border_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
654 void x_set_internal_border_width
P_ ((struct frame
*, Lisp_Object
,
656 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
657 void x_set_autoraise
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
658 void x_set_autolower
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
659 void x_set_vertical_scroll_bars
P_ ((struct frame
*, Lisp_Object
,
661 void x_set_visibility
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
662 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
663 void x_set_scroll_bar_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
664 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
665 void x_set_unsplittable
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
666 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
667 static void x_set_screen_gamma
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
669 static struct x_frame_parm_table x_frame_parms
[] =
671 "auto-raise", x_set_autoraise
,
672 "auto-lower", x_set_autolower
,
673 "background-color", x_set_background_color
,
674 "border-color", x_set_border_color
,
675 "border-width", x_set_border_width
,
676 "cursor-color", x_set_cursor_color
,
677 "cursor-type", x_set_cursor_type
,
679 "foreground-color", x_set_foreground_color
,
680 "icon-name", x_set_icon_name
,
681 "icon-type", x_set_icon_type
,
682 "internal-border-width", x_set_internal_border_width
,
683 "menu-bar-lines", x_set_menu_bar_lines
,
684 "mouse-color", x_set_mouse_color
,
685 "name", x_explicitly_set_name
,
686 "scroll-bar-width", x_set_scroll_bar_width
,
687 "title", x_set_title
,
688 "unsplittable", x_set_unsplittable
,
689 "vertical-scroll-bars", x_set_vertical_scroll_bars
,
690 "visibility", x_set_visibility
,
691 "tool-bar-lines", x_set_tool_bar_lines
,
692 "screen-gamma", x_set_screen_gamma
695 /* Attach the `x-frame-parameter' properties to
696 the Lisp symbol names of parameters relevant to W32. */
698 init_x_parm_symbols ()
702 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
703 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
707 /* Change the parameters of FRAME as specified by ALIST.
708 If a parameter is not specially recognized, do nothing;
709 otherwise call the `x_set_...' function for that parameter. */
712 x_set_frame_parameters (f
, alist
)
718 /* If both of these parameters are present, it's more efficient to
719 set them both at once. So we wait until we've looked at the
720 entire list before we set them. */
724 Lisp_Object left
, top
;
726 /* Same with these. */
727 Lisp_Object icon_left
, icon_top
;
729 /* Record in these vectors all the parms specified. */
733 int left_no_change
= 0, top_no_change
= 0;
734 int icon_left_no_change
= 0, icon_top_no_change
= 0;
736 struct gcpro gcpro1
, gcpro2
;
739 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
742 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
743 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
745 /* Extract parm names and values into those vectors. */
748 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
753 parms
[i
] = Fcar (elt
);
754 values
[i
] = Fcdr (elt
);
758 /* TAIL and ALIST are not used again below here. */
761 GCPRO2 (*parms
, *values
);
765 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
766 because their values appear in VALUES and strings are not valid. */
767 top
= left
= Qunbound
;
768 icon_left
= icon_top
= Qunbound
;
770 /* Provide default values for HEIGHT and WIDTH. */
771 width
= FRAME_WIDTH (f
);
772 height
= FRAME_HEIGHT (f
);
774 /* Process foreground_color and background_color before anything else.
775 They are independent of other properties, but other properties (e.g.,
776 cursor_color) are dependent upon them. */
777 for (p
= 0; p
< i
; p
++)
779 Lisp_Object prop
, val
;
783 if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
785 register Lisp_Object param_index
, old_value
;
787 param_index
= Fget (prop
, Qx_frame_parameter
);
788 old_value
= get_frame_param (f
, prop
);
789 store_frame_param (f
, prop
, val
);
790 if (NATNUMP (param_index
)
791 && (XFASTINT (param_index
)
792 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
793 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
797 /* Now process them in reverse of specified order. */
798 for (i
--; i
>= 0; i
--)
800 Lisp_Object prop
, val
;
805 if (EQ (prop
, Qwidth
) && NUMBERP (val
))
806 width
= XFASTINT (val
);
807 else if (EQ (prop
, Qheight
) && NUMBERP (val
))
808 height
= XFASTINT (val
);
809 else if (EQ (prop
, Qtop
))
811 else if (EQ (prop
, Qleft
))
813 else if (EQ (prop
, Qicon_top
))
815 else if (EQ (prop
, Qicon_left
))
817 else if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
818 /* Processed above. */
822 register Lisp_Object param_index
, old_value
;
824 param_index
= Fget (prop
, Qx_frame_parameter
);
825 old_value
= get_frame_param (f
, prop
);
826 store_frame_param (f
, prop
, val
);
827 if (NATNUMP (param_index
)
828 && (XFASTINT (param_index
)
829 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
830 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
834 /* Don't die if just one of these was set. */
835 if (EQ (left
, Qunbound
))
838 if (f
->output_data
.w32
->left_pos
< 0)
839 left
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->left_pos
), Qnil
));
841 XSETINT (left
, f
->output_data
.w32
->left_pos
);
843 if (EQ (top
, Qunbound
))
846 if (f
->output_data
.w32
->top_pos
< 0)
847 top
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->top_pos
), Qnil
));
849 XSETINT (top
, f
->output_data
.w32
->top_pos
);
852 /* If one of the icon positions was not set, preserve or default it. */
853 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
855 icon_left_no_change
= 1;
856 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
857 if (NILP (icon_left
))
858 XSETINT (icon_left
, 0);
860 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
862 icon_top_no_change
= 1;
863 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
865 XSETINT (icon_top
, 0);
868 /* Don't set these parameters unless they've been explicitly
869 specified. The window might be mapped or resized while we're in
870 this function, and we don't want to override that unless the lisp
871 code has asked for it.
873 Don't set these parameters unless they actually differ from the
874 window's current parameters; the window may not actually exist
879 check_frame_size (f
, &height
, &width
);
881 XSETFRAME (frame
, f
);
883 if (XINT (width
) != FRAME_WIDTH (f
)
884 || XINT (height
) != FRAME_HEIGHT (f
))
885 Fset_frame_size (frame
, make_number (width
), make_number (height
));
887 if ((!NILP (left
) || !NILP (top
))
888 && ! (left_no_change
&& top_no_change
)
889 && ! (NUMBERP (left
) && XINT (left
) == f
->output_data
.w32
->left_pos
890 && NUMBERP (top
) && XINT (top
) == f
->output_data
.w32
->top_pos
))
895 /* Record the signs. */
896 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
897 if (EQ (left
, Qminus
))
898 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
899 else if (INTEGERP (left
))
901 leftpos
= XINT (left
);
903 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
905 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
906 && CONSP (XCDR (left
))
907 && INTEGERP (XCAR (XCDR (left
))))
909 leftpos
= - XINT (XCAR (XCDR (left
)));
910 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
912 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
913 && CONSP (XCDR (left
))
914 && INTEGERP (XCAR (XCDR (left
))))
916 leftpos
= XINT (XCAR (XCDR (left
)));
919 if (EQ (top
, Qminus
))
920 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
921 else if (INTEGERP (top
))
925 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
927 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
928 && CONSP (XCDR (top
))
929 && INTEGERP (XCAR (XCDR (top
))))
931 toppos
= - XINT (XCAR (XCDR (top
)));
932 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
934 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
935 && CONSP (XCDR (top
))
936 && INTEGERP (XCAR (XCDR (top
))))
938 toppos
= XINT (XCAR (XCDR (top
)));
942 /* Store the numeric value of the position. */
943 f
->output_data
.w32
->top_pos
= toppos
;
944 f
->output_data
.w32
->left_pos
= leftpos
;
946 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
948 /* Actually set that position, and convert to absolute. */
949 x_set_offset (f
, leftpos
, toppos
, -1);
952 if ((!NILP (icon_left
) || !NILP (icon_top
))
953 && ! (icon_left_no_change
&& icon_top_no_change
))
954 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
960 /* Store the screen positions of frame F into XPTR and YPTR.
961 These are the positions of the containing window manager window,
962 not Emacs's own window. */
965 x_real_positions (f
, xptr
, yptr
)
974 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
975 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
981 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
987 /* Insert a description of internally-recorded parameters of frame X
988 into the parameter alist *ALISTPTR that is to be given to the user.
989 Only parameters that are specific to W32
990 and whose values are not correctly recorded in the frame's
991 param_alist need to be considered here. */
993 x_report_frame_params (f
, alistptr
)
995 Lisp_Object
*alistptr
;
1000 /* Represent negative positions (off the top or left screen edge)
1001 in a way that Fmodify_frame_parameters will understand correctly. */
1002 XSETINT (tem
, f
->output_data
.w32
->left_pos
);
1003 if (f
->output_data
.w32
->left_pos
>= 0)
1004 store_in_alist (alistptr
, Qleft
, tem
);
1006 store_in_alist (alistptr
, Qleft
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1008 XSETINT (tem
, f
->output_data
.w32
->top_pos
);
1009 if (f
->output_data
.w32
->top_pos
>= 0)
1010 store_in_alist (alistptr
, Qtop
, tem
);
1012 store_in_alist (alistptr
, Qtop
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1014 store_in_alist (alistptr
, Qborder_width
,
1015 make_number (f
->output_data
.w32
->border_width
));
1016 store_in_alist (alistptr
, Qinternal_border_width
,
1017 make_number (f
->output_data
.w32
->internal_border_width
));
1018 sprintf (buf
, "%ld", (long) FRAME_W32_WINDOW (f
));
1019 store_in_alist (alistptr
, Qwindow_id
,
1020 build_string (buf
));
1021 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
1022 FRAME_SAMPLE_VISIBILITY (f
);
1023 store_in_alist (alistptr
, Qvisibility
,
1024 (FRAME_VISIBLE_P (f
) ? Qt
1025 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
1026 store_in_alist (alistptr
, Qdisplay
,
1027 XCAR (FRAME_W32_DISPLAY_INFO (f
)->name_list_element
));
1031 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
, Sw32_define_rgb_color
, 4, 4, 0,
1032 "Convert RGB numbers to a windows color reference and associate with NAME (a string).\n\
1033 This adds or updates a named color to w32-color-map, making it available for use.\n\
1034 The original entry's RGB ref is returned, or nil if the entry is new.")
1035 (red
, green
, blue
, name
)
1036 Lisp_Object red
, green
, blue
, name
;
1039 Lisp_Object oldrgb
= Qnil
;
1042 CHECK_NUMBER (red
, 0);
1043 CHECK_NUMBER (green
, 0);
1044 CHECK_NUMBER (blue
, 0);
1045 CHECK_STRING (name
, 0);
1047 XSET (rgb
, Lisp_Int
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
1051 /* replace existing entry in w32-color-map or add new entry. */
1052 entry
= Fassoc (name
, Vw32_color_map
);
1055 entry
= Fcons (name
, rgb
);
1056 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
1060 oldrgb
= Fcdr (entry
);
1061 Fsetcdr (entry
, rgb
);
1069 DEFUN ("w32-load-color-file", Fw32_load_color_file
, Sw32_load_color_file
, 1, 1, 0,
1070 "Create an alist of color entries from an external file (ie. rgb.txt).\n\
1071 Assign this value to w32-color-map to replace the existing color map.\n\
1073 The file should define one named RGB color per line like so:\
1075 where R,G,B are numbers between 0 and 255 and name is an arbitrary string.")
1077 Lisp_Object filename
;
1080 Lisp_Object cmap
= Qnil
;
1081 Lisp_Object abspath
;
1083 CHECK_STRING (filename
, 0);
1084 abspath
= Fexpand_file_name (filename
, Qnil
);
1086 fp
= fopen (XSTRING (filename
)->data
, "rt");
1090 int red
, green
, blue
;
1095 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
1096 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
1098 char *name
= buf
+ num
;
1099 num
= strlen (name
) - 1;
1100 if (name
[num
] == '\n')
1102 cmap
= Fcons (Fcons (build_string (name
),
1103 make_number (RGB (red
, green
, blue
))),
1115 /* The default colors for the w32 color map */
1116 typedef struct colormap_t
1122 colormap_t w32_color_map
[] =
1124 {"snow" , PALETTERGB (255,250,250)},
1125 {"ghost white" , PALETTERGB (248,248,255)},
1126 {"GhostWhite" , PALETTERGB (248,248,255)},
1127 {"white smoke" , PALETTERGB (245,245,245)},
1128 {"WhiteSmoke" , PALETTERGB (245,245,245)},
1129 {"gainsboro" , PALETTERGB (220,220,220)},
1130 {"floral white" , PALETTERGB (255,250,240)},
1131 {"FloralWhite" , PALETTERGB (255,250,240)},
1132 {"old lace" , PALETTERGB (253,245,230)},
1133 {"OldLace" , PALETTERGB (253,245,230)},
1134 {"linen" , PALETTERGB (250,240,230)},
1135 {"antique white" , PALETTERGB (250,235,215)},
1136 {"AntiqueWhite" , PALETTERGB (250,235,215)},
1137 {"papaya whip" , PALETTERGB (255,239,213)},
1138 {"PapayaWhip" , PALETTERGB (255,239,213)},
1139 {"blanched almond" , PALETTERGB (255,235,205)},
1140 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
1141 {"bisque" , PALETTERGB (255,228,196)},
1142 {"peach puff" , PALETTERGB (255,218,185)},
1143 {"PeachPuff" , PALETTERGB (255,218,185)},
1144 {"navajo white" , PALETTERGB (255,222,173)},
1145 {"NavajoWhite" , PALETTERGB (255,222,173)},
1146 {"moccasin" , PALETTERGB (255,228,181)},
1147 {"cornsilk" , PALETTERGB (255,248,220)},
1148 {"ivory" , PALETTERGB (255,255,240)},
1149 {"lemon chiffon" , PALETTERGB (255,250,205)},
1150 {"LemonChiffon" , PALETTERGB (255,250,205)},
1151 {"seashell" , PALETTERGB (255,245,238)},
1152 {"honeydew" , PALETTERGB (240,255,240)},
1153 {"mint cream" , PALETTERGB (245,255,250)},
1154 {"MintCream" , PALETTERGB (245,255,250)},
1155 {"azure" , PALETTERGB (240,255,255)},
1156 {"alice blue" , PALETTERGB (240,248,255)},
1157 {"AliceBlue" , PALETTERGB (240,248,255)},
1158 {"lavender" , PALETTERGB (230,230,250)},
1159 {"lavender blush" , PALETTERGB (255,240,245)},
1160 {"LavenderBlush" , PALETTERGB (255,240,245)},
1161 {"misty rose" , PALETTERGB (255,228,225)},
1162 {"MistyRose" , PALETTERGB (255,228,225)},
1163 {"white" , PALETTERGB (255,255,255)},
1164 {"black" , PALETTERGB ( 0, 0, 0)},
1165 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
1166 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
1167 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
1168 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
1169 {"dim gray" , PALETTERGB (105,105,105)},
1170 {"DimGray" , PALETTERGB (105,105,105)},
1171 {"dim grey" , PALETTERGB (105,105,105)},
1172 {"DimGrey" , PALETTERGB (105,105,105)},
1173 {"slate gray" , PALETTERGB (112,128,144)},
1174 {"SlateGray" , PALETTERGB (112,128,144)},
1175 {"slate grey" , PALETTERGB (112,128,144)},
1176 {"SlateGrey" , PALETTERGB (112,128,144)},
1177 {"light slate gray" , PALETTERGB (119,136,153)},
1178 {"LightSlateGray" , PALETTERGB (119,136,153)},
1179 {"light slate grey" , PALETTERGB (119,136,153)},
1180 {"LightSlateGrey" , PALETTERGB (119,136,153)},
1181 {"gray" , PALETTERGB (190,190,190)},
1182 {"grey" , PALETTERGB (190,190,190)},
1183 {"light grey" , PALETTERGB (211,211,211)},
1184 {"LightGrey" , PALETTERGB (211,211,211)},
1185 {"light gray" , PALETTERGB (211,211,211)},
1186 {"LightGray" , PALETTERGB (211,211,211)},
1187 {"midnight blue" , PALETTERGB ( 25, 25,112)},
1188 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
1189 {"navy" , PALETTERGB ( 0, 0,128)},
1190 {"navy blue" , PALETTERGB ( 0, 0,128)},
1191 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
1192 {"cornflower blue" , PALETTERGB (100,149,237)},
1193 {"CornflowerBlue" , PALETTERGB (100,149,237)},
1194 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
1195 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
1196 {"slate blue" , PALETTERGB (106, 90,205)},
1197 {"SlateBlue" , PALETTERGB (106, 90,205)},
1198 {"medium slate blue" , PALETTERGB (123,104,238)},
1199 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
1200 {"light slate blue" , PALETTERGB (132,112,255)},
1201 {"LightSlateBlue" , PALETTERGB (132,112,255)},
1202 {"medium blue" , PALETTERGB ( 0, 0,205)},
1203 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
1204 {"royal blue" , PALETTERGB ( 65,105,225)},
1205 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
1206 {"blue" , PALETTERGB ( 0, 0,255)},
1207 {"dodger blue" , PALETTERGB ( 30,144,255)},
1208 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
1209 {"deep sky blue" , PALETTERGB ( 0,191,255)},
1210 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
1211 {"sky blue" , PALETTERGB (135,206,235)},
1212 {"SkyBlue" , PALETTERGB (135,206,235)},
1213 {"light sky blue" , PALETTERGB (135,206,250)},
1214 {"LightSkyBlue" , PALETTERGB (135,206,250)},
1215 {"steel blue" , PALETTERGB ( 70,130,180)},
1216 {"SteelBlue" , PALETTERGB ( 70,130,180)},
1217 {"light steel blue" , PALETTERGB (176,196,222)},
1218 {"LightSteelBlue" , PALETTERGB (176,196,222)},
1219 {"light blue" , PALETTERGB (173,216,230)},
1220 {"LightBlue" , PALETTERGB (173,216,230)},
1221 {"powder blue" , PALETTERGB (176,224,230)},
1222 {"PowderBlue" , PALETTERGB (176,224,230)},
1223 {"pale turquoise" , PALETTERGB (175,238,238)},
1224 {"PaleTurquoise" , PALETTERGB (175,238,238)},
1225 {"dark turquoise" , PALETTERGB ( 0,206,209)},
1226 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
1227 {"medium turquoise" , PALETTERGB ( 72,209,204)},
1228 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
1229 {"turquoise" , PALETTERGB ( 64,224,208)},
1230 {"cyan" , PALETTERGB ( 0,255,255)},
1231 {"light cyan" , PALETTERGB (224,255,255)},
1232 {"LightCyan" , PALETTERGB (224,255,255)},
1233 {"cadet blue" , PALETTERGB ( 95,158,160)},
1234 {"CadetBlue" , PALETTERGB ( 95,158,160)},
1235 {"medium aquamarine" , PALETTERGB (102,205,170)},
1236 {"MediumAquamarine" , PALETTERGB (102,205,170)},
1237 {"aquamarine" , PALETTERGB (127,255,212)},
1238 {"dark green" , PALETTERGB ( 0,100, 0)},
1239 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
1240 {"dark olive green" , PALETTERGB ( 85,107, 47)},
1241 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
1242 {"dark sea green" , PALETTERGB (143,188,143)},
1243 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
1244 {"sea green" , PALETTERGB ( 46,139, 87)},
1245 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
1246 {"medium sea green" , PALETTERGB ( 60,179,113)},
1247 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
1248 {"light sea green" , PALETTERGB ( 32,178,170)},
1249 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
1250 {"pale green" , PALETTERGB (152,251,152)},
1251 {"PaleGreen" , PALETTERGB (152,251,152)},
1252 {"spring green" , PALETTERGB ( 0,255,127)},
1253 {"SpringGreen" , PALETTERGB ( 0,255,127)},
1254 {"lawn green" , PALETTERGB (124,252, 0)},
1255 {"LawnGreen" , PALETTERGB (124,252, 0)},
1256 {"green" , PALETTERGB ( 0,255, 0)},
1257 {"chartreuse" , PALETTERGB (127,255, 0)},
1258 {"medium spring green" , PALETTERGB ( 0,250,154)},
1259 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
1260 {"green yellow" , PALETTERGB (173,255, 47)},
1261 {"GreenYellow" , PALETTERGB (173,255, 47)},
1262 {"lime green" , PALETTERGB ( 50,205, 50)},
1263 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
1264 {"yellow green" , PALETTERGB (154,205, 50)},
1265 {"YellowGreen" , PALETTERGB (154,205, 50)},
1266 {"forest green" , PALETTERGB ( 34,139, 34)},
1267 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
1268 {"olive drab" , PALETTERGB (107,142, 35)},
1269 {"OliveDrab" , PALETTERGB (107,142, 35)},
1270 {"dark khaki" , PALETTERGB (189,183,107)},
1271 {"DarkKhaki" , PALETTERGB (189,183,107)},
1272 {"khaki" , PALETTERGB (240,230,140)},
1273 {"pale goldenrod" , PALETTERGB (238,232,170)},
1274 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
1275 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
1276 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
1277 {"light yellow" , PALETTERGB (255,255,224)},
1278 {"LightYellow" , PALETTERGB (255,255,224)},
1279 {"yellow" , PALETTERGB (255,255, 0)},
1280 {"gold" , PALETTERGB (255,215, 0)},
1281 {"light goldenrod" , PALETTERGB (238,221,130)},
1282 {"LightGoldenrod" , PALETTERGB (238,221,130)},
1283 {"goldenrod" , PALETTERGB (218,165, 32)},
1284 {"dark goldenrod" , PALETTERGB (184,134, 11)},
1285 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
1286 {"rosy brown" , PALETTERGB (188,143,143)},
1287 {"RosyBrown" , PALETTERGB (188,143,143)},
1288 {"indian red" , PALETTERGB (205, 92, 92)},
1289 {"IndianRed" , PALETTERGB (205, 92, 92)},
1290 {"saddle brown" , PALETTERGB (139, 69, 19)},
1291 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
1292 {"sienna" , PALETTERGB (160, 82, 45)},
1293 {"peru" , PALETTERGB (205,133, 63)},
1294 {"burlywood" , PALETTERGB (222,184,135)},
1295 {"beige" , PALETTERGB (245,245,220)},
1296 {"wheat" , PALETTERGB (245,222,179)},
1297 {"sandy brown" , PALETTERGB (244,164, 96)},
1298 {"SandyBrown" , PALETTERGB (244,164, 96)},
1299 {"tan" , PALETTERGB (210,180,140)},
1300 {"chocolate" , PALETTERGB (210,105, 30)},
1301 {"firebrick" , PALETTERGB (178,34, 34)},
1302 {"brown" , PALETTERGB (165,42, 42)},
1303 {"dark salmon" , PALETTERGB (233,150,122)},
1304 {"DarkSalmon" , PALETTERGB (233,150,122)},
1305 {"salmon" , PALETTERGB (250,128,114)},
1306 {"light salmon" , PALETTERGB (255,160,122)},
1307 {"LightSalmon" , PALETTERGB (255,160,122)},
1308 {"orange" , PALETTERGB (255,165, 0)},
1309 {"dark orange" , PALETTERGB (255,140, 0)},
1310 {"DarkOrange" , PALETTERGB (255,140, 0)},
1311 {"coral" , PALETTERGB (255,127, 80)},
1312 {"light coral" , PALETTERGB (240,128,128)},
1313 {"LightCoral" , PALETTERGB (240,128,128)},
1314 {"tomato" , PALETTERGB (255, 99, 71)},
1315 {"orange red" , PALETTERGB (255, 69, 0)},
1316 {"OrangeRed" , PALETTERGB (255, 69, 0)},
1317 {"red" , PALETTERGB (255, 0, 0)},
1318 {"hot pink" , PALETTERGB (255,105,180)},
1319 {"HotPink" , PALETTERGB (255,105,180)},
1320 {"deep pink" , PALETTERGB (255, 20,147)},
1321 {"DeepPink" , PALETTERGB (255, 20,147)},
1322 {"pink" , PALETTERGB (255,192,203)},
1323 {"light pink" , PALETTERGB (255,182,193)},
1324 {"LightPink" , PALETTERGB (255,182,193)},
1325 {"pale violet red" , PALETTERGB (219,112,147)},
1326 {"PaleVioletRed" , PALETTERGB (219,112,147)},
1327 {"maroon" , PALETTERGB (176, 48, 96)},
1328 {"medium violet red" , PALETTERGB (199, 21,133)},
1329 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
1330 {"violet red" , PALETTERGB (208, 32,144)},
1331 {"VioletRed" , PALETTERGB (208, 32,144)},
1332 {"magenta" , PALETTERGB (255, 0,255)},
1333 {"violet" , PALETTERGB (238,130,238)},
1334 {"plum" , PALETTERGB (221,160,221)},
1335 {"orchid" , PALETTERGB (218,112,214)},
1336 {"medium orchid" , PALETTERGB (186, 85,211)},
1337 {"MediumOrchid" , PALETTERGB (186, 85,211)},
1338 {"dark orchid" , PALETTERGB (153, 50,204)},
1339 {"DarkOrchid" , PALETTERGB (153, 50,204)},
1340 {"dark violet" , PALETTERGB (148, 0,211)},
1341 {"DarkViolet" , PALETTERGB (148, 0,211)},
1342 {"blue violet" , PALETTERGB (138, 43,226)},
1343 {"BlueViolet" , PALETTERGB (138, 43,226)},
1344 {"purple" , PALETTERGB (160, 32,240)},
1345 {"medium purple" , PALETTERGB (147,112,219)},
1346 {"MediumPurple" , PALETTERGB (147,112,219)},
1347 {"thistle" , PALETTERGB (216,191,216)},
1348 {"gray0" , PALETTERGB ( 0, 0, 0)},
1349 {"grey0" , PALETTERGB ( 0, 0, 0)},
1350 {"dark grey" , PALETTERGB (169,169,169)},
1351 {"DarkGrey" , PALETTERGB (169,169,169)},
1352 {"dark gray" , PALETTERGB (169,169,169)},
1353 {"DarkGray" , PALETTERGB (169,169,169)},
1354 {"dark blue" , PALETTERGB ( 0, 0,139)},
1355 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
1356 {"dark cyan" , PALETTERGB ( 0,139,139)},
1357 {"DarkCyan" , PALETTERGB ( 0,139,139)},
1358 {"dark magenta" , PALETTERGB (139, 0,139)},
1359 {"DarkMagenta" , PALETTERGB (139, 0,139)},
1360 {"dark red" , PALETTERGB (139, 0, 0)},
1361 {"DarkRed" , PALETTERGB (139, 0, 0)},
1362 {"light green" , PALETTERGB (144,238,144)},
1363 {"LightGreen" , PALETTERGB (144,238,144)},
1366 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
1367 0, 0, 0, "Return the default color map.")
1371 colormap_t
*pc
= w32_color_map
;
1378 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
1380 cmap
= Fcons (Fcons (build_string (pc
->name
),
1381 make_number (pc
->colorref
)),
1390 w32_to_x_color (rgb
)
1395 CHECK_NUMBER (rgb
, 0);
1399 color
= Frassq (rgb
, Vw32_color_map
);
1404 return (Fcar (color
));
1410 w32_color_map_lookup (colorname
)
1413 Lisp_Object tail
, ret
= Qnil
;
1417 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
1419 register Lisp_Object elt
, tem
;
1422 if (!CONSP (elt
)) continue;
1426 if (lstrcmpi (XSTRING (tem
)->data
, colorname
) == 0)
1428 ret
= XUINT (Fcdr (elt
));
1442 x_to_w32_color (colorname
)
1445 register Lisp_Object tail
, ret
= Qnil
;
1449 if (colorname
[0] == '#')
1451 /* Could be an old-style RGB Device specification. */
1454 color
= colorname
+ 1;
1456 size
= strlen(color
);
1457 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
1465 for (i
= 0; i
< 3; i
++)
1469 unsigned long value
;
1471 /* The check for 'x' in the following conditional takes into
1472 account the fact that strtol allows a "0x" in front of
1473 our numbers, and we don't. */
1474 if (!isxdigit(color
[0]) || color
[1] == 'x')
1478 value
= strtoul(color
, &end
, 16);
1480 if (errno
== ERANGE
|| end
- color
!= size
)
1485 value
= value
* 0x10;
1496 colorval
|= (value
<< pos
);
1507 else if (strnicmp(colorname
, "rgb:", 4) == 0)
1515 color
= colorname
+ 4;
1516 for (i
= 0; i
< 3; i
++)
1519 unsigned long value
;
1521 /* The check for 'x' in the following conditional takes into
1522 account the fact that strtol allows a "0x" in front of
1523 our numbers, and we don't. */
1524 if (!isxdigit(color
[0]) || color
[1] == 'x')
1526 value
= strtoul(color
, &end
, 16);
1527 if (errno
== ERANGE
)
1529 switch (end
- color
)
1532 value
= value
* 0x10 + value
;
1545 if (value
== ULONG_MAX
)
1547 colorval
|= (value
<< pos
);
1561 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1563 /* This is an RGB Intensity specification. */
1570 color
= colorname
+ 5;
1571 for (i
= 0; i
< 3; i
++)
1577 value
= strtod(color
, &end
);
1578 if (errno
== ERANGE
)
1580 if (value
< 0.0 || value
> 1.0)
1582 val
= (UINT
)(0x100 * value
);
1583 /* We used 0x100 instead of 0xFF to give an continuous
1584 range between 0.0 and 1.0 inclusive. The next statement
1585 fixes the 1.0 case. */
1588 colorval
|= (val
<< pos
);
1602 /* I am not going to attempt to handle any of the CIE color schemes
1603 or TekHVC, since I don't know the algorithms for conversion to
1606 /* If we fail to lookup the color name in w32_color_map, then check the
1607 colorname to see if it can be crudely approximated: If the X color
1608 ends in a number (e.g., "darkseagreen2"), strip the number and
1609 return the result of looking up the base color name. */
1610 ret
= w32_color_map_lookup (colorname
);
1613 int len
= strlen (colorname
);
1615 if (isdigit (colorname
[len
- 1]))
1617 char *ptr
, *approx
= alloca (len
);
1619 strcpy (approx
, colorname
);
1620 ptr
= &approx
[len
- 1];
1621 while (ptr
> approx
&& isdigit (*ptr
))
1624 ret
= w32_color_map_lookup (approx
);
1634 w32_regenerate_palette (FRAME_PTR f
)
1636 struct w32_palette_entry
* list
;
1637 LOGPALETTE
* log_palette
;
1638 HPALETTE new_palette
;
1641 /* don't bother trying to create palette if not supported */
1642 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1645 log_palette
= (LOGPALETTE
*)
1646 alloca (sizeof (LOGPALETTE
) +
1647 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1648 log_palette
->palVersion
= 0x300;
1649 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1651 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1653 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1654 i
++, list
= list
->next
)
1655 log_palette
->palPalEntry
[i
] = list
->entry
;
1657 new_palette
= CreatePalette (log_palette
);
1661 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1662 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1663 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1665 /* Realize display palette and garbage all frames. */
1666 release_frame_dc (f
, get_frame_dc (f
));
1671 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1672 #define SET_W32_COLOR(pe, color) \
1675 pe.peRed = GetRValue (color); \
1676 pe.peGreen = GetGValue (color); \
1677 pe.peBlue = GetBValue (color); \
1682 /* Keep these around in case we ever want to track color usage. */
1684 w32_map_color (FRAME_PTR f
, COLORREF color
)
1686 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1688 if (NILP (Vw32_enable_palette
))
1691 /* check if color is already mapped */
1694 if (W32_COLOR (list
->entry
) == color
)
1702 /* not already mapped, so add to list and recreate Windows palette */
1703 list
= (struct w32_palette_entry
*)
1704 xmalloc (sizeof (struct w32_palette_entry
));
1705 SET_W32_COLOR (list
->entry
, color
);
1707 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1708 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1709 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1711 /* set flag that palette must be regenerated */
1712 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1716 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1718 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1719 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1721 if (NILP (Vw32_enable_palette
))
1724 /* check if color is already mapped */
1727 if (W32_COLOR (list
->entry
) == color
)
1729 if (--list
->refcount
== 0)
1733 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1743 /* set flag that palette must be regenerated */
1744 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1749 /* Gamma-correct COLOR on frame F. */
1752 gamma_correct (f
, color
)
1758 *color
= PALETTERGB (
1759 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1760 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1761 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1766 /* Decide if color named COLOR is valid for the display associated with
1767 the selected frame; if so, return the rgb values in COLOR_DEF.
1768 If ALLOC is nonzero, allocate a new colormap cell. */
1771 w32_defined_color (f
, color
, color_def
, alloc
)
1777 register Lisp_Object tem
;
1778 COLORREF w32_color_ref
;
1780 tem
= x_to_w32_color (color
);
1784 /* Apply gamma correction. */
1785 w32_color_ref
= XUINT (tem
);
1786 gamma_correct (f
, &w32_color_ref
);
1787 XSETINT (tem
, w32_color_ref
);
1789 /* Map this color to the palette if it is enabled. */
1790 if (!NILP (Vw32_enable_palette
))
1792 struct w32_palette_entry
* entry
=
1793 FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1794 struct w32_palette_entry
** prev
=
1795 &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1797 /* check if color is already mapped */
1800 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1802 prev
= &entry
->next
;
1803 entry
= entry
->next
;
1806 if (entry
== NULL
&& alloc
)
1808 /* not already mapped, so add to list */
1809 entry
= (struct w32_palette_entry
*)
1810 xmalloc (sizeof (struct w32_palette_entry
));
1811 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1814 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1816 /* set flag that palette must be regenerated */
1817 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1820 /* Ensure COLORREF value is snapped to nearest color in (default)
1821 palette by simulating the PALETTERGB macro. This works whether
1822 or not the display device has a palette. */
1823 w32_color_ref
= XUINT (tem
) | 0x2000000;
1825 color_def
->pixel
= w32_color_ref
;
1826 color_def
->red
= GetRValue (w32_color_ref
);
1827 color_def
->green
= GetGValue (w32_color_ref
);
1828 color_def
->blue
= GetBValue (w32_color_ref
);
1838 /* Given a string ARG naming a color, compute a pixel value from it
1839 suitable for screen F.
1840 If F is not a color screen, return DEF (default) regardless of what
1844 x_decode_color (f
, arg
, def
)
1851 CHECK_STRING (arg
, 0);
1853 if (strcmp (XSTRING (arg
)->data
, "black") == 0)
1854 return BLACK_PIX_DEFAULT (f
);
1855 else if (strcmp (XSTRING (arg
)->data
, "white") == 0)
1856 return WHITE_PIX_DEFAULT (f
);
1858 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1861 /* w32_defined_color is responsible for coping with failures
1862 by looking for a near-miss. */
1863 if (w32_defined_color (f
, XSTRING (arg
)->data
, &cdef
, 1))
1866 /* defined_color failed; return an ultimate default. */
1870 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
1871 the previous value of that parameter, NEW_VALUE is the new value. */
1874 x_set_screen_gamma (f
, new_value
, old_value
)
1876 Lisp_Object new_value
, old_value
;
1878 if (NILP (new_value
))
1880 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
1881 /* The value 0.4545 is the normal viewing gamma. */
1882 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
1884 Fsignal (Qerror
, Fcons (build_string ("Illegal screen-gamma"),
1885 Fcons (new_value
, Qnil
)));
1887 clear_face_cache (0);
1891 /* Functions called only from `x_set_frame_param'
1892 to set individual parameters.
1894 If FRAME_W32_WINDOW (f) is 0,
1895 the frame is being created and its window does not exist yet.
1896 In that case, just record the parameter's new value
1897 in the standard place; do not attempt to change the window. */
1900 x_set_foreground_color (f
, arg
, oldval
)
1902 Lisp_Object arg
, oldval
;
1904 FRAME_FOREGROUND_PIXEL (f
)
1905 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1907 if (FRAME_W32_WINDOW (f
) != 0)
1909 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1910 if (FRAME_VISIBLE_P (f
))
1916 x_set_background_color (f
, arg
, oldval
)
1918 Lisp_Object arg
, oldval
;
1920 FRAME_BACKGROUND_PIXEL (f
)
1921 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1923 if (FRAME_W32_WINDOW (f
) != 0)
1925 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1926 FRAME_BACKGROUND_PIXEL (f
));
1928 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1930 if (FRAME_VISIBLE_P (f
))
1936 x_set_mouse_color (f
, arg
, oldval
)
1938 Lisp_Object arg
, oldval
;
1941 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
1945 if (!EQ (Qnil
, arg
))
1946 f
->output_data
.w32
->mouse_pixel
1947 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1948 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
1950 /* Don't let pointers be invisible. */
1951 if (mask_color
== f
->output_data
.w32
->mouse_pixel
1952 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
1953 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
1955 #if 0 /* NTEMACS_TODO : cursor changes */
1958 /* It's not okay to crash if the user selects a screwy cursor. */
1959 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
1961 if (!EQ (Qnil
, Vx_pointer_shape
))
1963 CHECK_NUMBER (Vx_pointer_shape
, 0);
1964 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
1967 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1968 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
1970 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1972 CHECK_NUMBER (Vx_nontext_pointer_shape
, 0);
1973 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1974 XINT (Vx_nontext_pointer_shape
));
1977 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
1978 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1980 if (!EQ (Qnil
, Vx_busy_pointer_shape
))
1982 CHECK_NUMBER (Vx_busy_pointer_shape
, 0);
1983 busy_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1984 XINT (Vx_busy_pointer_shape
));
1987 busy_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
1988 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
1990 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
1991 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1993 CHECK_NUMBER (Vx_mode_pointer_shape
, 0);
1994 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
1995 XINT (Vx_mode_pointer_shape
));
1998 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
1999 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
2001 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
2003 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
, 0);
2005 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2006 XINT (Vx_sensitive_text_pointer_shape
));
2009 cross_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
2011 /* Check and report errors with the above calls. */
2012 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
2013 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
2016 XColor fore_color
, back_color
;
2018 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
2019 back_color
.pixel
= mask_color
;
2020 XQueryColor (FRAME_W32_DISPLAY (f
),
2021 DefaultColormap (FRAME_W32_DISPLAY (f
),
2022 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2024 XQueryColor (FRAME_W32_DISPLAY (f
),
2025 DefaultColormap (FRAME_W32_DISPLAY (f
),
2026 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2028 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
2029 &fore_color
, &back_color
);
2030 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
2031 &fore_color
, &back_color
);
2032 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
2033 &fore_color
, &back_color
);
2034 XRecolorCursor (FRAME_W32_DISPLAY (f
), cross_cursor
,
2035 &fore_color
, &back_color
);
2036 XRecolorCursor (FRAME_W32_DISPLAY (f
), busy_cursor
,
2037 &fore_color
, &back_color
);
2040 if (FRAME_W32_WINDOW (f
) != 0)
2041 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
2043 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
2044 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
2045 f
->output_data
.w32
->text_cursor
= cursor
;
2047 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
2048 && f
->output_data
.w32
->nontext_cursor
!= 0)
2049 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
2050 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
2052 if (busy_cursor
!= f
->output_data
.w32
->busy_cursor
2053 && f
->output_data
.w32
->busy_cursor
!= 0)
2054 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->busy_cursor
);
2055 f
->output_data
.w32
->busy_cursor
= busy_cursor
;
2057 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
2058 && f
->output_data
.w32
->modeline_cursor
!= 0)
2059 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
2060 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
2062 if (cross_cursor
!= f
->output_data
.w32
->cross_cursor
2063 && f
->output_data
.w32
->cross_cursor
!= 0)
2064 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->cross_cursor
);
2065 f
->output_data
.w32
->cross_cursor
= cross_cursor
;
2067 XFlush (FRAME_W32_DISPLAY (f
));
2070 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
2071 #endif /* NTEMACS_TODO */
2075 x_set_cursor_color (f
, arg
, oldval
)
2077 Lisp_Object arg
, oldval
;
2079 unsigned long fore_pixel
;
2081 if (!EQ (Vx_cursor_fore_pixel
, Qnil
))
2082 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
2083 WHITE_PIX_DEFAULT (f
));
2085 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2086 f
->output_data
.w32
->cursor_pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2088 /* Make sure that the cursor color differs from the background color. */
2089 if (f
->output_data
.w32
->cursor_pixel
== FRAME_BACKGROUND_PIXEL (f
))
2091 f
->output_data
.w32
->cursor_pixel
= f
->output_data
.w32
->mouse_pixel
;
2092 if (f
->output_data
.w32
->cursor_pixel
== fore_pixel
)
2093 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2095 FRAME_FOREGROUND_PIXEL (f
) = fore_pixel
;
2097 if (FRAME_W32_WINDOW (f
) != 0)
2099 if (FRAME_VISIBLE_P (f
))
2101 x_display_cursor (f
, 0);
2102 x_display_cursor (f
, 1);
2106 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
2109 /* Set the border-color of frame F to pixel value PIX.
2110 Note that this does not fully take effect if done before
2113 x_set_border_pixel (f
, pix
)
2117 f
->output_data
.w32
->border_pixel
= pix
;
2119 if (FRAME_W32_WINDOW (f
) != 0 && f
->output_data
.w32
->border_width
> 0)
2121 if (FRAME_VISIBLE_P (f
))
2126 /* Set the border-color of frame F to value described by ARG.
2127 ARG can be a string naming a color.
2128 The border-color is used for the border that is drawn by the server.
2129 Note that this does not fully take effect if done before
2130 F has a window; it must be redone when the window is created. */
2133 x_set_border_color (f
, arg
, oldval
)
2135 Lisp_Object arg
, oldval
;
2139 CHECK_STRING (arg
, 0);
2140 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2141 x_set_border_pixel (f
, pix
);
2142 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
2146 x_set_cursor_type (f
, arg
, oldval
)
2148 Lisp_Object arg
, oldval
;
2152 FRAME_DESIRED_CURSOR (f
) = BAR_CURSOR
;
2153 f
->output_data
.w32
->cursor_width
= 2;
2155 else if (CONSP (arg
) && EQ (XCAR (arg
), Qbar
)
2156 && INTEGERP (XCDR (arg
)))
2158 FRAME_DESIRED_CURSOR (f
) = BAR_CURSOR
;
2159 f
->output_data
.w32
->cursor_width
= XINT (XCDR (arg
));
2162 /* Treat anything unknown as "box cursor".
2163 It was bad to signal an error; people have trouble fixing
2164 .Xdefaults with Emacs, when it has something bad in it. */
2165 FRAME_DESIRED_CURSOR (f
) = FILLED_BOX_CURSOR
;
2167 /* Make sure the cursor gets redrawn. This is overkill, but how
2168 often do people change cursor types? */
2169 update_mode_lines
++;
2173 x_set_icon_type (f
, arg
, oldval
)
2175 Lisp_Object arg
, oldval
;
2179 if (NILP (arg
) && NILP (oldval
))
2182 if (STRINGP (arg
) && STRINGP (oldval
)
2183 && EQ (Fstring_equal (oldval
, arg
), Qt
))
2186 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
2191 result
= x_bitmap_icon (f
, arg
);
2195 error ("No icon window available");
2201 /* Return non-nil if frame F wants a bitmap icon. */
2209 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
2217 x_set_icon_name (f
, arg
, oldval
)
2219 Lisp_Object arg
, oldval
;
2225 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
2228 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
2234 if (f
->output_data
.w32
->icon_bitmap
!= 0)
2239 result
= x_text_icon (f
,
2240 (char *) XSTRING ((!NILP (f
->icon_name
)
2249 error ("No icon window available");
2252 /* If the window was unmapped (and its icon was mapped),
2253 the new icon is not mapped, so map the window in its stead. */
2254 if (FRAME_VISIBLE_P (f
))
2256 #ifdef USE_X_TOOLKIT
2257 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
2259 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
2262 XFlush (FRAME_W32_DISPLAY (f
));
2267 extern Lisp_Object
x_new_font ();
2268 extern Lisp_Object
x_new_fontset();
2271 x_set_font (f
, arg
, oldval
)
2273 Lisp_Object arg
, oldval
;
2276 Lisp_Object fontset_name
;
2279 CHECK_STRING (arg
, 1);
2281 fontset_name
= Fquery_fontset (arg
, Qnil
);
2284 result
= (STRINGP (fontset_name
)
2285 ? x_new_fontset (f
, XSTRING (fontset_name
)->data
)
2286 : x_new_font (f
, XSTRING (arg
)->data
));
2289 if (EQ (result
, Qnil
))
2290 error ("Font \"%s\" is not defined", XSTRING (arg
)->data
);
2291 else if (EQ (result
, Qt
))
2292 error ("the characters of the given font have varying widths");
2293 else if (STRINGP (result
))
2295 store_frame_param (f
, Qfont
, result
);
2296 recompute_basic_faces (f
);
2301 do_pending_window_change (0);
2303 /* Don't call `face-set-after-frame-default' when faces haven't been
2304 initialized yet. This is the case when called from
2305 Fx_create_frame. In that case, the X widget or window doesn't
2306 exist either, and we can end up in x_report_frame_params with a
2307 null widget which gives a segfault. */
2308 if (FRAME_FACE_CACHE (f
))
2310 XSETFRAME (frame
, f
);
2311 call1 (Qface_set_after_frame_default
, frame
);
2316 x_set_border_width (f
, arg
, oldval
)
2318 Lisp_Object arg
, oldval
;
2320 CHECK_NUMBER (arg
, 0);
2322 if (XINT (arg
) == f
->output_data
.w32
->border_width
)
2325 if (FRAME_W32_WINDOW (f
) != 0)
2326 error ("Cannot change the border width of a window");
2328 f
->output_data
.w32
->border_width
= XINT (arg
);
2332 x_set_internal_border_width (f
, arg
, oldval
)
2334 Lisp_Object arg
, oldval
;
2336 int old
= f
->output_data
.w32
->internal_border_width
;
2338 CHECK_NUMBER (arg
, 0);
2339 f
->output_data
.w32
->internal_border_width
= XINT (arg
);
2340 if (f
->output_data
.w32
->internal_border_width
< 0)
2341 f
->output_data
.w32
->internal_border_width
= 0;
2343 if (f
->output_data
.w32
->internal_border_width
== old
)
2346 if (FRAME_W32_WINDOW (f
) != 0)
2348 x_set_window_size (f
, 0, f
->width
, f
->height
);
2349 SET_FRAME_GARBAGED (f
);
2350 do_pending_window_change (0);
2355 x_set_visibility (f
, value
, oldval
)
2357 Lisp_Object value
, oldval
;
2360 XSETFRAME (frame
, f
);
2363 Fmake_frame_invisible (frame
, Qt
);
2364 else if (EQ (value
, Qicon
))
2365 Ficonify_frame (frame
);
2367 Fmake_frame_visible (frame
);
2371 x_set_menu_bar_lines (f
, value
, oldval
)
2373 Lisp_Object value
, oldval
;
2376 int olines
= FRAME_MENU_BAR_LINES (f
);
2378 /* Right now, menu bars don't work properly in minibuf-only frames;
2379 most of the commands try to apply themselves to the minibuffer
2380 frame itself, and get an error because you can't switch buffers
2381 in or split the minibuffer window. */
2382 if (FRAME_MINIBUF_ONLY_P (f
))
2385 if (INTEGERP (value
))
2386 nlines
= XINT (value
);
2390 FRAME_MENU_BAR_LINES (f
) = 0;
2392 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2395 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2396 free_frame_menubar (f
);
2397 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2399 /* Adjust the frame size so that the client (text) dimensions
2400 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
2402 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2403 do_pending_window_change (0);
2409 /* Set the number of lines used for the tool bar of frame F to VALUE.
2410 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2411 is the old number of tool bar lines. This function changes the
2412 height of all windows on frame F to match the new tool bar height.
2413 The frame's height doesn't change. */
2416 x_set_tool_bar_lines (f
, value
, oldval
)
2418 Lisp_Object value
, oldval
;
2422 /* Use VALUE only if an integer >= 0. */
2423 if (INTEGERP (value
) && XINT (value
) >= 0)
2424 nlines
= XFASTINT (value
);
2428 /* Make sure we redisplay all windows in this frame. */
2429 ++windows_or_buffers_changed
;
2431 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2432 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2433 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2434 do_pending_window_change (0);
2439 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2442 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2443 name; if NAME is a string, set F's name to NAME and set
2444 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2446 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2447 suggesting a new name, which lisp code should override; if
2448 F->explicit_name is set, ignore the new name; otherwise, set it. */
2451 x_set_name (f
, name
, explicit)
2456 /* Make sure that requests from lisp code override requests from
2457 Emacs redisplay code. */
2460 /* If we're switching from explicit to implicit, we had better
2461 update the mode lines and thereby update the title. */
2462 if (f
->explicit_name
&& NILP (name
))
2463 update_mode_lines
= 1;
2465 f
->explicit_name
= ! NILP (name
);
2467 else if (f
->explicit_name
)
2470 /* If NAME is nil, set the name to the w32_id_name. */
2473 /* Check for no change needed in this very common case
2474 before we do any consing. */
2475 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
2476 XSTRING (f
->name
)->data
))
2478 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
2481 CHECK_STRING (name
, 0);
2483 /* Don't change the name if it's already NAME. */
2484 if (! NILP (Fstring_equal (name
, f
->name
)))
2489 /* For setting the frame title, the title parameter should override
2490 the name parameter. */
2491 if (! NILP (f
->title
))
2494 if (FRAME_W32_WINDOW (f
))
2496 if (STRING_MULTIBYTE (name
))
2497 name
= string_make_unibyte (name
);
2500 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2505 /* This function should be called when the user's lisp code has
2506 specified a name for the frame; the name will override any set by the
2509 x_explicitly_set_name (f
, arg
, oldval
)
2511 Lisp_Object arg
, oldval
;
2513 x_set_name (f
, arg
, 1);
2516 /* This function should be called by Emacs redisplay code to set the
2517 name; names set this way will never override names set by the user's
2520 x_implicitly_set_name (f
, arg
, oldval
)
2522 Lisp_Object arg
, oldval
;
2524 x_set_name (f
, arg
, 0);
2527 /* Change the title of frame F to NAME.
2528 If NAME is nil, use the frame name as the title.
2530 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2531 name; if NAME is a string, set F's name to NAME and set
2532 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2534 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2535 suggesting a new name, which lisp code should override; if
2536 F->explicit_name is set, ignore the new name; otherwise, set it. */
2539 x_set_title (f
, name
, old_name
)
2541 Lisp_Object name
, old_name
;
2543 /* Don't change the title if it's already NAME. */
2544 if (EQ (name
, f
->title
))
2547 update_mode_lines
= 1;
2554 if (FRAME_W32_WINDOW (f
))
2556 if (STRING_MULTIBYTE (name
))
2557 name
= string_make_unibyte (name
);
2560 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2566 x_set_autoraise (f
, arg
, oldval
)
2568 Lisp_Object arg
, oldval
;
2570 f
->auto_raise
= !EQ (Qnil
, arg
);
2574 x_set_autolower (f
, arg
, oldval
)
2576 Lisp_Object arg
, oldval
;
2578 f
->auto_lower
= !EQ (Qnil
, arg
);
2582 x_set_unsplittable (f
, arg
, oldval
)
2584 Lisp_Object arg
, oldval
;
2586 f
->no_split
= !NILP (arg
);
2590 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2592 Lisp_Object arg
, oldval
;
2594 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2595 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2596 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2597 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2599 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = NILP (arg
) ?
2600 vertical_scroll_bar_none
:
2601 /* Put scroll bars on the right by default, as is conventional
2604 ? vertical_scroll_bar_left
2605 : vertical_scroll_bar_right
;
2607 /* We set this parameter before creating the window for the
2608 frame, so we can get the geometry right from the start.
2609 However, if the window hasn't been created yet, we shouldn't
2610 call x_set_window_size. */
2611 if (FRAME_W32_WINDOW (f
))
2612 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2613 do_pending_window_change (0);
2618 x_set_scroll_bar_width (f
, arg
, oldval
)
2620 Lisp_Object arg
, oldval
;
2622 int wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
2626 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2627 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) +
2629 if (FRAME_W32_WINDOW (f
))
2630 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2631 do_pending_window_change (0);
2633 else if (INTEGERP (arg
) && XINT (arg
) > 0
2634 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2636 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2637 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2639 if (FRAME_W32_WINDOW (f
))
2640 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2641 do_pending_window_change (0);
2643 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2644 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2645 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2648 /* Subroutines of creating an frame. */
2650 /* Make sure that Vx_resource_name is set to a reasonable value.
2651 Fix it up, or set it to `emacs' if it is too hopeless. */
2654 validate_x_resource_name ()
2657 /* Number of valid characters in the resource name. */
2659 /* Number of invalid characters in the resource name. */
2664 if (STRINGP (Vx_resource_name
))
2666 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
2669 len
= XSTRING (Vx_resource_name
)->size
;
2671 /* Only letters, digits, - and _ are valid in resource names.
2672 Count the valid characters and count the invalid ones. */
2673 for (i
= 0; i
< len
; i
++)
2676 if (! ((c
>= 'a' && c
<= 'z')
2677 || (c
>= 'A' && c
<= 'Z')
2678 || (c
>= '0' && c
<= '9')
2679 || c
== '-' || c
== '_'))
2686 /* Not a string => completely invalid. */
2687 bad_count
= 5, good_count
= 0;
2689 /* If name is valid already, return. */
2693 /* If name is entirely invalid, or nearly so, use `emacs'. */
2695 || (good_count
== 1 && bad_count
> 0))
2697 Vx_resource_name
= build_string ("emacs");
2701 /* Name is partly valid. Copy it and replace the invalid characters
2702 with underscores. */
2704 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
2706 for (i
= 0; i
< len
; i
++)
2708 int c
= XSTRING (new)->data
[i
];
2709 if (! ((c
>= 'a' && c
<= 'z')
2710 || (c
>= 'A' && c
<= 'Z')
2711 || (c
>= '0' && c
<= '9')
2712 || c
== '-' || c
== '_'))
2713 XSTRING (new)->data
[i
] = '_';
2718 extern char *x_get_string_resource ();
2720 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
2721 "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
2722 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
2723 class, where INSTANCE is the name under which Emacs was invoked, or\n\
2724 the name specified by the `-name' or `-rn' command-line arguments.\n\
2726 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
2727 class, respectively. You must specify both of them or neither.\n\
2728 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
2729 and the class is `Emacs.CLASS.SUBCLASS'.")
2730 (attribute
, class, component
, subclass
)
2731 Lisp_Object attribute
, class, component
, subclass
;
2733 register char *value
;
2737 CHECK_STRING (attribute
, 0);
2738 CHECK_STRING (class, 0);
2740 if (!NILP (component
))
2741 CHECK_STRING (component
, 1);
2742 if (!NILP (subclass
))
2743 CHECK_STRING (subclass
, 2);
2744 if (NILP (component
) != NILP (subclass
))
2745 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
2747 validate_x_resource_name ();
2749 /* Allocate space for the components, the dots which separate them,
2750 and the final '\0'. Make them big enough for the worst case. */
2751 name_key
= (char *) alloca (XSTRING (Vx_resource_name
)->size
2752 + (STRINGP (component
)
2753 ? XSTRING (component
)->size
: 0)
2754 + XSTRING (attribute
)->size
2757 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2758 + XSTRING (class)->size
2759 + (STRINGP (subclass
)
2760 ? XSTRING (subclass
)->size
: 0)
2763 /* Start with emacs.FRAMENAME for the name (the specific one)
2764 and with `Emacs' for the class key (the general one). */
2765 strcpy (name_key
, XSTRING (Vx_resource_name
)->data
);
2766 strcpy (class_key
, EMACS_CLASS
);
2768 strcat (class_key
, ".");
2769 strcat (class_key
, XSTRING (class)->data
);
2771 if (!NILP (component
))
2773 strcat (class_key
, ".");
2774 strcat (class_key
, XSTRING (subclass
)->data
);
2776 strcat (name_key
, ".");
2777 strcat (name_key
, XSTRING (component
)->data
);
2780 strcat (name_key
, ".");
2781 strcat (name_key
, XSTRING (attribute
)->data
);
2783 value
= x_get_string_resource (Qnil
,
2784 name_key
, class_key
);
2786 if (value
!= (char *) 0)
2787 return build_string (value
);
2792 /* Used when C code wants a resource value. */
2795 x_get_resource_string (attribute
, class)
2796 char *attribute
, *class;
2800 struct frame
*sf
= SELECTED_FRAME ();
2802 /* Allocate space for the components, the dots which separate them,
2803 and the final '\0'. */
2804 name_key
= (char *) alloca (XSTRING (Vinvocation_name
)->size
2805 + strlen (attribute
) + 2);
2806 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2807 + strlen (class) + 2);
2809 sprintf (name_key
, "%s.%s",
2810 XSTRING (Vinvocation_name
)->data
,
2812 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
2814 return x_get_string_resource (sf
, name_key
, class_key
);
2817 /* Types we might convert a resource string into. */
2827 /* Return the value of parameter PARAM.
2829 First search ALIST, then Vdefault_frame_alist, then the X defaults
2830 database, using ATTRIBUTE as the attribute name and CLASS as its class.
2832 Convert the resource to the type specified by desired_type.
2834 If no default is specified, return Qunbound. If you call
2835 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
2836 and don't let it get stored in any Lisp-visible variables! */
2839 w32_get_arg (alist
, param
, attribute
, class, type
)
2840 Lisp_Object alist
, param
;
2843 enum resource_types type
;
2845 register Lisp_Object tem
;
2847 tem
= Fassq (param
, alist
);
2849 tem
= Fassq (param
, Vdefault_frame_alist
);
2855 tem
= Fx_get_resource (build_string (attribute
),
2856 build_string (class),
2864 case RES_TYPE_NUMBER
:
2865 return make_number (atoi (XSTRING (tem
)->data
));
2867 case RES_TYPE_FLOAT
:
2868 return make_float (atof (XSTRING (tem
)->data
));
2870 case RES_TYPE_BOOLEAN
:
2871 tem
= Fdowncase (tem
);
2872 if (!strcmp (XSTRING (tem
)->data
, "on")
2873 || !strcmp (XSTRING (tem
)->data
, "true"))
2878 case RES_TYPE_STRING
:
2881 case RES_TYPE_SYMBOL
:
2882 /* As a special case, we map the values `true' and `on'
2883 to Qt, and `false' and `off' to Qnil. */
2886 lower
= Fdowncase (tem
);
2887 if (!strcmp (XSTRING (lower
)->data
, "on")
2888 || !strcmp (XSTRING (lower
)->data
, "true"))
2890 else if (!strcmp (XSTRING (lower
)->data
, "off")
2891 || !strcmp (XSTRING (lower
)->data
, "false"))
2894 return Fintern (tem
, Qnil
);
2907 /* Record in frame F the specified or default value according to ALIST
2908 of the parameter named PARAM (a Lisp symbol).
2909 If no value is specified for PARAM, look for an X default for XPROP
2910 on the frame named NAME.
2911 If that is not found either, use the value DEFLT. */
2914 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
2921 enum resource_types type
;
2925 tem
= w32_get_arg (alist
, prop
, xprop
, xclass
, type
);
2926 if (EQ (tem
, Qunbound
))
2928 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
2932 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
2933 "Parse an X-style geometry string STRING.\n\
2934 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
2935 The properties returned may include `top', `left', `height', and `width'.\n\
2936 The value of `left' or `top' may be an integer,\n\
2937 or a list (+ N) meaning N pixels relative to top/left corner,\n\
2938 or a list (- N) meaning -N pixels relative to bottom/right corner.")
2943 unsigned int width
, height
;
2946 CHECK_STRING (string
, 0);
2948 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
2949 &x
, &y
, &width
, &height
);
2952 if (geometry
& XValue
)
2954 Lisp_Object element
;
2956 if (x
>= 0 && (geometry
& XNegative
))
2957 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
2958 else if (x
< 0 && ! (geometry
& XNegative
))
2959 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
2961 element
= Fcons (Qleft
, make_number (x
));
2962 result
= Fcons (element
, result
);
2965 if (geometry
& YValue
)
2967 Lisp_Object element
;
2969 if (y
>= 0 && (geometry
& YNegative
))
2970 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
2971 else if (y
< 0 && ! (geometry
& YNegative
))
2972 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
2974 element
= Fcons (Qtop
, make_number (y
));
2975 result
= Fcons (element
, result
);
2978 if (geometry
& WidthValue
)
2979 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
2980 if (geometry
& HeightValue
)
2981 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
2986 /* Calculate the desired size and position of this window,
2987 and return the flags saying which aspects were specified.
2989 This function does not make the coordinates positive. */
2991 #define DEFAULT_ROWS 40
2992 #define DEFAULT_COLS 80
2995 x_figure_window_size (f
, parms
)
2999 register Lisp_Object tem0
, tem1
, tem2
;
3000 long window_prompting
= 0;
3002 /* Default values if we fall through.
3003 Actually, if that happens we should get
3004 window manager prompting. */
3005 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3006 f
->height
= DEFAULT_ROWS
;
3007 /* Window managers expect that if program-specified
3008 positions are not (0,0), they're intentional, not defaults. */
3009 f
->output_data
.w32
->top_pos
= 0;
3010 f
->output_data
.w32
->left_pos
= 0;
3012 tem0
= w32_get_arg (parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3013 tem1
= w32_get_arg (parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3014 tem2
= w32_get_arg (parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3015 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3017 if (!EQ (tem0
, Qunbound
))
3019 CHECK_NUMBER (tem0
, 0);
3020 f
->height
= XINT (tem0
);
3022 if (!EQ (tem1
, Qunbound
))
3024 CHECK_NUMBER (tem1
, 0);
3025 SET_FRAME_WIDTH (f
, XINT (tem1
));
3027 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3028 window_prompting
|= USSize
;
3030 window_prompting
|= PSize
;
3033 f
->output_data
.w32
->vertical_scroll_bar_extra
3034 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3036 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3037 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3038 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
3039 f
->output_data
.w32
->flags_areas_extra
3040 = FRAME_FLAGS_AREA_WIDTH (f
);
3041 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3042 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3044 tem0
= w32_get_arg (parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3045 tem1
= w32_get_arg (parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3046 tem2
= w32_get_arg (parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3047 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3049 if (EQ (tem0
, Qminus
))
3051 f
->output_data
.w32
->top_pos
= 0;
3052 window_prompting
|= YNegative
;
3054 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3055 && CONSP (XCDR (tem0
))
3056 && INTEGERP (XCAR (XCDR (tem0
))))
3058 f
->output_data
.w32
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3059 window_prompting
|= YNegative
;
3061 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3062 && CONSP (XCDR (tem0
))
3063 && INTEGERP (XCAR (XCDR (tem0
))))
3065 f
->output_data
.w32
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3067 else if (EQ (tem0
, Qunbound
))
3068 f
->output_data
.w32
->top_pos
= 0;
3071 CHECK_NUMBER (tem0
, 0);
3072 f
->output_data
.w32
->top_pos
= XINT (tem0
);
3073 if (f
->output_data
.w32
->top_pos
< 0)
3074 window_prompting
|= YNegative
;
3077 if (EQ (tem1
, Qminus
))
3079 f
->output_data
.w32
->left_pos
= 0;
3080 window_prompting
|= XNegative
;
3082 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3083 && CONSP (XCDR (tem1
))
3084 && INTEGERP (XCAR (XCDR (tem1
))))
3086 f
->output_data
.w32
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3087 window_prompting
|= XNegative
;
3089 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3090 && CONSP (XCDR (tem1
))
3091 && INTEGERP (XCAR (XCDR (tem1
))))
3093 f
->output_data
.w32
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3095 else if (EQ (tem1
, Qunbound
))
3096 f
->output_data
.w32
->left_pos
= 0;
3099 CHECK_NUMBER (tem1
, 0);
3100 f
->output_data
.w32
->left_pos
= XINT (tem1
);
3101 if (f
->output_data
.w32
->left_pos
< 0)
3102 window_prompting
|= XNegative
;
3105 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3106 window_prompting
|= USPosition
;
3108 window_prompting
|= PPosition
;
3111 return window_prompting
;
3116 extern LRESULT CALLBACK
w32_wnd_proc ();
3119 w32_init_class (hinst
)
3124 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3125 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
3127 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
3128 wc
.hInstance
= hinst
;
3129 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
3130 wc
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
3131 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
3132 wc
.lpszMenuName
= NULL
;
3133 wc
.lpszClassName
= EMACS_CLASS
;
3135 return (RegisterClass (&wc
));
3139 w32_createscrollbar (f
, bar
)
3141 struct scroll_bar
* bar
;
3143 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
3144 /* Position and size of scroll bar. */
3145 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3147 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3149 FRAME_W32_WINDOW (f
),
3156 w32_createwindow (f
)
3162 rect
.left
= rect
.top
= 0;
3163 rect
.right
= PIXEL_WIDTH (f
);
3164 rect
.bottom
= PIXEL_HEIGHT (f
);
3166 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3167 FRAME_EXTERNAL_MENU_BAR (f
));
3169 /* Do first time app init */
3173 w32_init_class (hinst
);
3176 FRAME_W32_WINDOW (f
) = hwnd
3177 = CreateWindow (EMACS_CLASS
,
3179 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
3180 f
->output_data
.w32
->left_pos
,
3181 f
->output_data
.w32
->top_pos
,
3182 rect
.right
- rect
.left
,
3183 rect
.bottom
- rect
.top
,
3191 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
3192 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
3193 SetWindowLong (hwnd
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
3194 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
3195 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3197 /* Enable drag-n-drop. */
3198 DragAcceptFiles (hwnd
, TRUE
);
3200 /* Do this to discard the default setting specified by our parent. */
3201 ShowWindow (hwnd
, SW_HIDE
);
3206 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
3213 wmsg
->msg
.hwnd
= hwnd
;
3214 wmsg
->msg
.message
= msg
;
3215 wmsg
->msg
.wParam
= wParam
;
3216 wmsg
->msg
.lParam
= lParam
;
3217 wmsg
->msg
.time
= GetMessageTime ();
3222 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
3223 between left and right keys as advertised. We test for this
3224 support dynamically, and set a flag when the support is absent. If
3225 absent, we keep track of the left and right control and alt keys
3226 ourselves. This is particularly necessary on keyboards that rely
3227 upon the AltGr key, which is represented as having the left control
3228 and right alt keys pressed. For these keyboards, we need to know
3229 when the left alt key has been pressed in addition to the AltGr key
3230 so that we can properly support M-AltGr-key sequences (such as M-@
3231 on Swedish keyboards). */
3233 #define EMACS_LCONTROL 0
3234 #define EMACS_RCONTROL 1
3235 #define EMACS_LMENU 2
3236 #define EMACS_RMENU 3
3238 static int modifiers
[4];
3239 static int modifiers_recorded
;
3240 static int modifier_key_support_tested
;
3243 test_modifier_support (unsigned int wparam
)
3247 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
3249 if (wparam
== VK_CONTROL
)
3259 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
3260 modifiers_recorded
= 1;
3262 modifiers_recorded
= 0;
3263 modifier_key_support_tested
= 1;
3267 record_keydown (unsigned int wparam
, unsigned int lparam
)
3271 if (!modifier_key_support_tested
)
3272 test_modifier_support (wparam
);
3274 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3277 if (wparam
== VK_CONTROL
)
3278 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3280 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3286 record_keyup (unsigned int wparam
, unsigned int lparam
)
3290 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3293 if (wparam
== VK_CONTROL
)
3294 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3296 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3301 /* Emacs can lose focus while a modifier key has been pressed. When
3302 it regains focus, be conservative and clear all modifiers since
3303 we cannot reconstruct the left and right modifier state. */
3309 if (GetFocus () == NULL
)
3310 /* Emacs doesn't have keyboard focus. Do nothing. */
3313 ctrl
= GetAsyncKeyState (VK_CONTROL
);
3314 alt
= GetAsyncKeyState (VK_MENU
);
3316 if (!(ctrl
& 0x08000))
3317 /* Clear any recorded control modifier state. */
3318 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3320 if (!(alt
& 0x08000))
3321 /* Clear any recorded alt modifier state. */
3322 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3324 /* Update the state of all modifier keys, because modifiers used in
3325 hot-key combinations can get stuck on if Emacs loses focus as a
3326 result of a hot-key being pressed. */
3330 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
3332 GetKeyboardState (keystate
);
3333 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
3334 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
3335 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
3336 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
3337 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
3338 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
3339 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
3340 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
3341 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
3342 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
3343 SetKeyboardState (keystate
);
3347 /* Synchronize modifier state with what is reported with the current
3348 keystroke. Even if we cannot distinguish between left and right
3349 modifier keys, we know that, if no modifiers are set, then neither
3350 the left or right modifier should be set. */
3354 if (!modifiers_recorded
)
3357 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
3358 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3360 if (!(GetKeyState (VK_MENU
) & 0x8000))
3361 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3365 modifier_set (int vkey
)
3367 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
3368 return (GetKeyState (vkey
) & 0x1);
3369 if (!modifiers_recorded
)
3370 return (GetKeyState (vkey
) & 0x8000);
3375 return modifiers
[EMACS_LCONTROL
];
3377 return modifiers
[EMACS_RCONTROL
];
3379 return modifiers
[EMACS_LMENU
];
3381 return modifiers
[EMACS_RMENU
];
3383 return (GetKeyState (vkey
) & 0x8000);
3386 /* Convert between the modifier bits W32 uses and the modifier bits
3390 w32_key_to_modifier (int key
)
3392 Lisp_Object key_mapping
;
3397 key_mapping
= Vw32_lwindow_modifier
;
3400 key_mapping
= Vw32_rwindow_modifier
;
3403 key_mapping
= Vw32_apps_modifier
;
3406 key_mapping
= Vw32_scroll_lock_modifier
;
3412 /* NB. This code runs in the input thread, asychronously to the lisp
3413 thread, so we must be careful to ensure access to lisp data is
3414 thread-safe. The following code is safe because the modifier
3415 variable values are updated atomically from lisp and symbols are
3416 not relocated by GC. Also, we don't have to worry about seeing GC
3418 if (EQ (key_mapping
, Qhyper
))
3419 return hyper_modifier
;
3420 if (EQ (key_mapping
, Qsuper
))
3421 return super_modifier
;
3422 if (EQ (key_mapping
, Qmeta
))
3423 return meta_modifier
;
3424 if (EQ (key_mapping
, Qalt
))
3425 return alt_modifier
;
3426 if (EQ (key_mapping
, Qctrl
))
3427 return ctrl_modifier
;
3428 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
3429 return ctrl_modifier
;
3430 if (EQ (key_mapping
, Qshift
))
3431 return shift_modifier
;
3433 /* Don't generate any modifier if not explicitly requested. */
3438 w32_get_modifiers ()
3440 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
3441 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
3442 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
3443 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
3444 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
3445 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
3446 (modifier_set (VK_MENU
) ?
3447 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
3450 /* We map the VK_* modifiers into console modifier constants
3451 so that we can use the same routines to handle both console
3452 and window input. */
3455 construct_console_modifiers ()
3460 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
3461 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
3462 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
3463 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
3464 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
3465 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
3466 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
3467 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
3468 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
3469 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
3470 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
3476 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
3480 /* Convert to emacs modifiers. */
3481 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
3487 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
3489 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
3492 if (virt_key
== VK_RETURN
)
3493 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
3495 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
3496 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
3498 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
3499 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
3501 if (virt_key
== VK_CLEAR
)
3502 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
3507 /* List of special key combinations which w32 would normally capture,
3508 but emacs should grab instead. Not directly visible to lisp, to
3509 simplify synchronization. Each item is an integer encoding a virtual
3510 key code and modifier combination to capture. */
3511 Lisp_Object w32_grabbed_keys
;
3513 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
3514 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
3515 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
3516 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
3518 /* Register hot-keys for reserved key combinations when Emacs has
3519 keyboard focus, since this is the only way Emacs can receive key
3520 combinations like Alt-Tab which are used by the system. */
3523 register_hot_keys (hwnd
)
3526 Lisp_Object keylist
;
3528 /* Use GC_CONSP, since we are called asynchronously. */
3529 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3531 Lisp_Object key
= XCAR (keylist
);
3533 /* Deleted entries get set to nil. */
3534 if (!INTEGERP (key
))
3537 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
3538 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
3543 unregister_hot_keys (hwnd
)
3546 Lisp_Object keylist
;
3548 /* Use GC_CONSP, since we are called asynchronously. */
3549 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3551 Lisp_Object key
= XCAR (keylist
);
3553 if (!INTEGERP (key
))
3556 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
3560 /* Main message dispatch loop. */
3563 w32_msg_pump (deferred_msg
* msg_buf
)
3569 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
3571 while (GetMessage (&msg
, NULL
, 0, 0))
3573 if (msg
.hwnd
== NULL
)
3575 switch (msg
.message
)
3578 /* Produced by complete_deferred_msg; just ignore. */
3580 case WM_EMACS_CREATEWINDOW
:
3581 w32_createwindow ((struct frame
*) msg
.wParam
);
3582 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3585 case WM_EMACS_SETLOCALE
:
3586 SetThreadLocale (msg
.wParam
);
3587 /* Reply is not expected. */
3589 case WM_EMACS_SETKEYBOARDLAYOUT
:
3590 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
3591 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3595 case WM_EMACS_REGISTER_HOT_KEY
:
3596 focus_window
= GetFocus ();
3597 if (focus_window
!= NULL
)
3598 RegisterHotKey (focus_window
,
3599 HOTKEY_ID (msg
.wParam
),
3600 HOTKEY_MODIFIERS (msg
.wParam
),
3601 HOTKEY_VK_CODE (msg
.wParam
));
3602 /* Reply is not expected. */
3604 case WM_EMACS_UNREGISTER_HOT_KEY
:
3605 focus_window
= GetFocus ();
3606 if (focus_window
!= NULL
)
3607 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
3608 /* Mark item as erased. NB: this code must be
3609 thread-safe. The next line is okay because the cons
3610 cell is never made into garbage and is not relocated by
3612 XCAR ((Lisp_Object
) msg
.lParam
) = Qnil
;
3613 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3616 case WM_EMACS_TOGGLE_LOCK_KEY
:
3618 int vk_code
= (int) msg
.wParam
;
3619 int cur_state
= (GetKeyState (vk_code
) & 1);
3620 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
3622 /* NB: This code must be thread-safe. It is safe to
3623 call NILP because symbols are not relocated by GC,
3624 and pointer here is not touched by GC (so the markbit
3625 can't be set). Numbers are safe because they are
3626 immediate values. */
3627 if (NILP (new_state
)
3628 || (NUMBERP (new_state
)
3629 && (XUINT (new_state
)) & 1 != cur_state
))
3631 one_w32_display_info
.faked_key
= vk_code
;
3633 keybd_event ((BYTE
) vk_code
,
3634 (BYTE
) MapVirtualKey (vk_code
, 0),
3635 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3636 keybd_event ((BYTE
) vk_code
,
3637 (BYTE
) MapVirtualKey (vk_code
, 0),
3638 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3639 keybd_event ((BYTE
) vk_code
,
3640 (BYTE
) MapVirtualKey (vk_code
, 0),
3641 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3642 cur_state
= !cur_state
;
3644 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3650 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
3655 DispatchMessage (&msg
);
3658 /* Exit nested loop when our deferred message has completed. */
3659 if (msg_buf
->completed
)
3664 deferred_msg
* deferred_msg_head
;
3666 static deferred_msg
*
3667 find_deferred_msg (HWND hwnd
, UINT msg
)
3669 deferred_msg
* item
;
3671 /* Don't actually need synchronization for read access, since
3672 modification of single pointer is always atomic. */
3673 /* enter_crit (); */
3675 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3676 if (item
->w32msg
.msg
.hwnd
== hwnd
3677 && item
->w32msg
.msg
.message
== msg
)
3680 /* leave_crit (); */
3686 send_deferred_msg (deferred_msg
* msg_buf
,
3692 /* Only input thread can send deferred messages. */
3693 if (GetCurrentThreadId () != dwWindowsThreadId
)
3696 /* It is an error to send a message that is already deferred. */
3697 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3700 /* Enforced synchronization is not needed because this is the only
3701 function that alters deferred_msg_head, and the following critical
3702 section is guaranteed to only be serially reentered (since only the
3703 input thread can call us). */
3705 /* enter_crit (); */
3707 msg_buf
->completed
= 0;
3708 msg_buf
->next
= deferred_msg_head
;
3709 deferred_msg_head
= msg_buf
;
3710 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
3712 /* leave_crit (); */
3714 /* Start a new nested message loop to process other messages until
3715 this one is completed. */
3716 w32_msg_pump (msg_buf
);
3718 deferred_msg_head
= msg_buf
->next
;
3720 return msg_buf
->result
;
3724 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
3726 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
3728 if (msg_buf
== NULL
)
3729 /* Message may have been cancelled, so don't abort(). */
3732 msg_buf
->result
= result
;
3733 msg_buf
->completed
= 1;
3735 /* Ensure input thread is woken so it notices the completion. */
3736 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3740 cancel_all_deferred_msgs ()
3742 deferred_msg
* item
;
3744 /* Don't actually need synchronization for read access, since
3745 modification of single pointer is always atomic. */
3746 /* enter_crit (); */
3748 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3751 item
->completed
= 1;
3754 /* leave_crit (); */
3756 /* Ensure input thread is woken so it notices the completion. */
3757 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3765 deferred_msg dummy_buf
;
3767 /* Ensure our message queue is created */
3769 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
3771 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3774 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
3775 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
3776 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
3778 /* This is the inital message loop which should only exit when the
3779 application quits. */
3780 w32_msg_pump (&dummy_buf
);
3786 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
3796 wmsg
.dwModifiers
= modifiers
;
3798 /* Detect quit_char and set quit-flag directly. Note that we
3799 still need to post a message to ensure the main thread will be
3800 woken up if blocked in sys_select(), but we do NOT want to post
3801 the quit_char message itself (because it will usually be as if
3802 the user had typed quit_char twice). Instead, we post a dummy
3803 message that has no particular effect. */
3806 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
3807 c
= make_ctrl_char (c
) & 0377;
3809 || (wmsg
.dwModifiers
== 0 &&
3810 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
3814 /* The choice of message is somewhat arbitrary, as long as
3815 the main thread handler just ignores it. */
3818 /* Interrupt any blocking system calls. */
3821 /* As a safety precaution, forcibly complete any deferred
3822 messages. This is a kludge, but I don't see any particularly
3823 clean way to handle the situation where a deferred message is
3824 "dropped" in the lisp thread, and will thus never be
3825 completed, eg. by the user trying to activate the menubar
3826 when the lisp thread is busy, and then typing C-g when the
3827 menubar doesn't open promptly (with the result that the
3828 menubar never responds at all because the deferred
3829 WM_INITMENU message is never completed). Another problem
3830 situation is when the lisp thread calls SendMessage (to send
3831 a window manager command) when a message has been deferred;
3832 the lisp thread gets blocked indefinitely waiting for the
3833 deferred message to be completed, which itself is waiting for
3834 the lisp thread to respond.
3836 Note that we don't want to block the input thread waiting for
3837 a reponse from the lisp thread (although that would at least
3838 solve the deadlock problem above), because we want to be able
3839 to receive C-g to interrupt the lisp thread. */
3840 cancel_all_deferred_msgs ();
3844 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3847 /* Main window procedure */
3850 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
3857 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
3859 int windows_translate
;
3862 /* Note that it is okay to call x_window_to_frame, even though we are
3863 not running in the main lisp thread, because frame deletion
3864 requires the lisp thread to synchronize with this thread. Thus, if
3865 a frame struct is returned, it can be used without concern that the
3866 lisp thread might make it disappear while we are using it.
3868 NB. Walking the frame list in this thread is safe (as long as
3869 writes of Lisp_Object slots are atomic, which they are on Windows).
3870 Although delete-frame can destructively modify the frame list while
3871 we are walking it, a garbage collection cannot occur until after
3872 delete-frame has synchronized with this thread.
3874 It is also safe to use functions that make GDI calls, such as
3875 w32_clear_rect, because these functions must obtain a DC handle
3876 from the frame struct using get_frame_dc which is thread-aware. */
3881 f
= x_window_to_frame (dpyinfo
, hwnd
);
3884 HDC hdc
= get_frame_dc (f
);
3885 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
3886 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
3887 release_frame_dc (f
, hdc
);
3889 #if defined (W32_DEBUG_DISPLAY)
3890 DebPrint (("WM_ERASEBKGND: erasing %d,%d-%d,%d\n",
3891 wmsg
.rect
.left
, wmsg
.rect
.top
, wmsg
.rect
.right
,
3893 #endif /* W32_DEBUG_DISPLAY */
3896 case WM_PALETTECHANGED
:
3897 /* ignore our own changes */
3898 if ((HWND
)wParam
!= hwnd
)
3900 f
= x_window_to_frame (dpyinfo
, hwnd
);
3902 /* get_frame_dc will realize our palette and force all
3903 frames to be redrawn if needed. */
3904 release_frame_dc (f
, get_frame_dc (f
));
3909 PAINTSTRUCT paintStruct
;
3912 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
3913 fails. Apparently this can happen under some
3915 if (!w32_strict_painting
|| GetUpdateRect (hwnd
, &update_rect
, FALSE
))
3918 BeginPaint (hwnd
, &paintStruct
);
3920 if (w32_strict_painting
)
3921 /* The rectangles returned by GetUpdateRect and BeginPaint
3922 do not always match. GetUpdateRect seems to be the
3923 more reliable of the two. */
3924 wmsg
.rect
= update_rect
;
3926 wmsg
.rect
= paintStruct
.rcPaint
;
3928 #if defined (W32_DEBUG_DISPLAY)
3929 DebPrint (("WM_PAINT: painting %d,%d-%d,%d\n", wmsg
.rect
.left
,
3930 wmsg
.rect
.top
, wmsg
.rect
.right
, wmsg
.rect
.bottom
));
3931 DebPrint (("WM_PAINT: update region is %d,%d-%d,%d\n",
3932 update_rect
.left
, update_rect
.top
,
3933 update_rect
.right
, update_rect
.bottom
));
3935 EndPaint (hwnd
, &paintStruct
);
3938 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3943 /* If GetUpdateRect returns 0 (meaning there is no update
3944 region), assume the whole window needs to be repainted. */
3945 GetClientRect(hwnd
, &wmsg
.rect
);
3946 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3950 case WM_INPUTLANGCHANGE
:
3951 /* Inform lisp thread of keyboard layout changes. */
3952 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3954 /* Clear dead keys in the keyboard state; for simplicity only
3955 preserve modifier key states. */
3960 GetKeyboardState (keystate
);
3961 for (i
= 0; i
< 256; i
++)
3978 SetKeyboardState (keystate
);
3983 /* Synchronize hot keys with normal input. */
3984 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
3989 record_keyup (wParam
, lParam
);
3994 /* Ignore keystrokes we fake ourself; see below. */
3995 if (dpyinfo
->faked_key
== wParam
)
3997 dpyinfo
->faked_key
= 0;
3998 /* Make sure TranslateMessage sees them though (as long as
3999 they don't produce WM_CHAR messages). This ensures that
4000 indicator lights are toggled promptly on Windows 9x, for
4002 if (lispy_function_keys
[wParam
] != 0)
4004 windows_translate
= 1;
4010 /* Synchronize modifiers with current keystroke. */
4012 record_keydown (wParam
, lParam
);
4013 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
4015 windows_translate
= 0;
4020 if (NILP (Vw32_pass_lwindow_to_system
))
4022 /* Prevent system from acting on keyup (which opens the
4023 Start menu if no other key was pressed) by simulating a
4024 press of Space which we will ignore. */
4025 if (GetAsyncKeyState (wParam
) & 1)
4027 if (NUMBERP (Vw32_phantom_key_code
))
4028 key
= XUINT (Vw32_phantom_key_code
) & 255;
4031 dpyinfo
->faked_key
= key
;
4032 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4035 if (!NILP (Vw32_lwindow_modifier
))
4039 if (NILP (Vw32_pass_rwindow_to_system
))
4041 if (GetAsyncKeyState (wParam
) & 1)
4043 if (NUMBERP (Vw32_phantom_key_code
))
4044 key
= XUINT (Vw32_phantom_key_code
) & 255;
4047 dpyinfo
->faked_key
= key
;
4048 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4051 if (!NILP (Vw32_rwindow_modifier
))
4055 if (!NILP (Vw32_apps_modifier
))
4059 if (NILP (Vw32_pass_alt_to_system
))
4060 /* Prevent DefWindowProc from activating the menu bar if an
4061 Alt key is pressed and released by itself. */
4063 windows_translate
= 1;
4066 /* Decide whether to treat as modifier or function key. */
4067 if (NILP (Vw32_enable_caps_lock
))
4068 goto disable_lock_key
;
4069 windows_translate
= 1;
4072 /* Decide whether to treat as modifier or function key. */
4073 if (NILP (Vw32_enable_num_lock
))
4074 goto disable_lock_key
;
4075 windows_translate
= 1;
4078 /* Decide whether to treat as modifier or function key. */
4079 if (NILP (Vw32_scroll_lock_modifier
))
4080 goto disable_lock_key
;
4081 windows_translate
= 1;
4084 /* Ensure the appropriate lock key state (and indicator light)
4085 remains in the same state. We do this by faking another
4086 press of the relevant key. Apparently, this really is the
4087 only way to toggle the state of the indicator lights. */
4088 dpyinfo
->faked_key
= wParam
;
4089 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4090 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4091 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4092 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4093 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4094 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4095 /* Ensure indicator lights are updated promptly on Windows 9x
4096 (TranslateMessage apparently does this), after forwarding
4098 post_character_message (hwnd
, msg
, wParam
, lParam
,
4099 w32_get_key_modifiers (wParam
, lParam
));
4100 windows_translate
= 1;
4104 case VK_PROCESSKEY
: /* Generated by IME. */
4105 windows_translate
= 1;
4108 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
4109 which is confusing for purposes of key binding; convert
4110 VK_CANCEL events into VK_PAUSE events. */
4114 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
4115 for purposes of key binding; convert these back into
4116 VK_NUMLOCK events, at least when we want to see NumLock key
4117 presses. (Note that there is never any possibility that
4118 VK_PAUSE with Ctrl really is C-Pause as per above.) */
4119 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
4120 wParam
= VK_NUMLOCK
;
4123 /* If not defined as a function key, change it to a WM_CHAR message. */
4124 if (lispy_function_keys
[wParam
] == 0)
4126 DWORD modifiers
= construct_console_modifiers ();
4128 if (!NILP (Vw32_recognize_altgr
)
4129 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
4131 /* Always let TranslateMessage handle AltGr key chords;
4132 for some reason, ToAscii doesn't always process AltGr
4133 chords correctly. */
4134 windows_translate
= 1;
4136 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
4138 /* Handle key chords including any modifiers other
4139 than shift directly, in order to preserve as much
4140 modifier information as possible. */
4141 if ('A' <= wParam
&& wParam
<= 'Z')
4143 /* Don't translate modified alphabetic keystrokes,
4144 so the user doesn't need to constantly switch
4145 layout to type control or meta keystrokes when
4146 the normal layout translates alphabetic
4147 characters to non-ascii characters. */
4148 if (!modifier_set (VK_SHIFT
))
4149 wParam
+= ('a' - 'A');
4154 /* Try to handle other keystrokes by determining the
4155 base character (ie. translating the base key plus
4159 KEY_EVENT_RECORD key
;
4161 key
.bKeyDown
= TRUE
;
4162 key
.wRepeatCount
= 1;
4163 key
.wVirtualKeyCode
= wParam
;
4164 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
4165 key
.uChar
.AsciiChar
= 0;
4166 key
.dwControlKeyState
= modifiers
;
4168 add
= w32_kbd_patch_key (&key
);
4169 /* 0 means an unrecognised keycode, negative means
4170 dead key. Ignore both. */
4173 /* Forward asciified character sequence. */
4174 post_character_message
4175 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
4176 w32_get_key_modifiers (wParam
, lParam
));
4177 w32_kbd_patch_key (&key
);
4184 /* Let TranslateMessage handle everything else. */
4185 windows_translate
= 1;
4191 if (windows_translate
)
4193 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
4195 windows_msg
.time
= GetMessageTime ();
4196 TranslateMessage (&windows_msg
);
4204 post_character_message (hwnd
, msg
, wParam
, lParam
,
4205 w32_get_key_modifiers (wParam
, lParam
));
4208 /* Simulate middle mouse button events when left and right buttons
4209 are used together, but only if user has two button mouse. */
4210 case WM_LBUTTONDOWN
:
4211 case WM_RBUTTONDOWN
:
4212 if (XINT (Vw32_num_mouse_buttons
) == 3)
4213 goto handle_plain_button
;
4216 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
4217 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
4219 if (button_state
& this)
4222 if (button_state
== 0)
4225 button_state
|= this;
4227 if (button_state
& other
)
4229 if (mouse_button_timer
)
4231 KillTimer (hwnd
, mouse_button_timer
);
4232 mouse_button_timer
= 0;
4234 /* Generate middle mouse event instead. */
4235 msg
= WM_MBUTTONDOWN
;
4236 button_state
|= MMOUSE
;
4238 else if (button_state
& MMOUSE
)
4240 /* Ignore button event if we've already generated a
4241 middle mouse down event. This happens if the
4242 user releases and press one of the two buttons
4243 after we've faked a middle mouse event. */
4248 /* Flush out saved message. */
4249 post_msg (&saved_mouse_button_msg
);
4251 wmsg
.dwModifiers
= w32_get_modifiers ();
4252 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4254 /* Clear message buffer. */
4255 saved_mouse_button_msg
.msg
.hwnd
= 0;
4259 /* Hold onto message for now. */
4260 mouse_button_timer
=
4261 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
4262 XINT (Vw32_mouse_button_tolerance
), NULL
);
4263 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
4264 saved_mouse_button_msg
.msg
.message
= msg
;
4265 saved_mouse_button_msg
.msg
.wParam
= wParam
;
4266 saved_mouse_button_msg
.msg
.lParam
= lParam
;
4267 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
4268 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
4275 if (XINT (Vw32_num_mouse_buttons
) == 3)
4276 goto handle_plain_button
;
4279 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
4280 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
4282 if ((button_state
& this) == 0)
4285 button_state
&= ~this;
4287 if (button_state
& MMOUSE
)
4289 /* Only generate event when second button is released. */
4290 if ((button_state
& other
) == 0)
4293 button_state
&= ~MMOUSE
;
4295 if (button_state
) abort ();
4302 /* Flush out saved message if necessary. */
4303 if (saved_mouse_button_msg
.msg
.hwnd
)
4305 post_msg (&saved_mouse_button_msg
);
4308 wmsg
.dwModifiers
= w32_get_modifiers ();
4309 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4311 /* Always clear message buffer and cancel timer. */
4312 saved_mouse_button_msg
.msg
.hwnd
= 0;
4313 KillTimer (hwnd
, mouse_button_timer
);
4314 mouse_button_timer
= 0;
4316 if (button_state
== 0)
4321 case WM_MBUTTONDOWN
:
4323 handle_plain_button
:
4328 if (parse_button (msg
, &button
, &up
))
4330 if (up
) ReleaseCapture ();
4331 else SetCapture (hwnd
);
4332 button
= (button
== 0) ? LMOUSE
:
4333 ((button
== 1) ? MMOUSE
: RMOUSE
);
4335 button_state
&= ~button
;
4337 button_state
|= button
;
4341 wmsg
.dwModifiers
= w32_get_modifiers ();
4342 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4347 if (XINT (Vw32_mouse_move_interval
) <= 0
4348 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4350 wmsg
.dwModifiers
= w32_get_modifiers ();
4351 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4355 /* Hang onto mouse move and scroll messages for a bit, to avoid
4356 sending such events to Emacs faster than it can process them.
4357 If we get more events before the timer from the first message
4358 expires, we just replace the first message. */
4360 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4362 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4363 XINT (Vw32_mouse_move_interval
), NULL
);
4365 /* Hold onto message for now. */
4366 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4367 saved_mouse_move_msg
.msg
.message
= msg
;
4368 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4369 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4370 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4371 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4376 wmsg
.dwModifiers
= w32_get_modifiers ();
4377 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4381 wmsg
.dwModifiers
= w32_get_modifiers ();
4382 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4386 /* Flush out saved messages if necessary. */
4387 if (wParam
== mouse_button_timer
)
4389 if (saved_mouse_button_msg
.msg
.hwnd
)
4391 post_msg (&saved_mouse_button_msg
);
4392 saved_mouse_button_msg
.msg
.hwnd
= 0;
4394 KillTimer (hwnd
, mouse_button_timer
);
4395 mouse_button_timer
= 0;
4397 else if (wParam
== mouse_move_timer
)
4399 if (saved_mouse_move_msg
.msg
.hwnd
)
4401 post_msg (&saved_mouse_move_msg
);
4402 saved_mouse_move_msg
.msg
.hwnd
= 0;
4404 KillTimer (hwnd
, mouse_move_timer
);
4405 mouse_move_timer
= 0;
4410 /* Windows doesn't send us focus messages when putting up and
4411 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4412 The only indication we get that something happened is receiving
4413 this message afterwards. So this is a good time to reset our
4414 keyboard modifiers' state. */
4421 /* We must ensure menu bar is fully constructed and up to date
4422 before allowing user interaction with it. To achieve this
4423 we send this message to the lisp thread and wait for a
4424 reply (whose value is not actually needed) to indicate that
4425 the menu bar is now ready for use, so we can now return.
4427 To remain responsive in the meantime, we enter a nested message
4428 loop that can process all other messages.
4430 However, we skip all this if the message results from calling
4431 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4432 thread a message because it is blocked on us at this point. We
4433 set menubar_active before calling TrackPopupMenu to indicate
4434 this (there is no possibility of confusion with real menubar
4437 f
= x_window_to_frame (dpyinfo
, hwnd
);
4439 && (f
->output_data
.w32
->menubar_active
4440 /* We can receive this message even in the absence of a
4441 menubar (ie. when the system menu is activated) - in this
4442 case we do NOT want to forward the message, otherwise it
4443 will cause the menubar to suddenly appear when the user
4444 had requested it to be turned off! */
4445 || f
->output_data
.w32
->menubar_widget
== NULL
))
4449 deferred_msg msg_buf
;
4451 /* Detect if message has already been deferred; in this case
4452 we cannot return any sensible value to ignore this. */
4453 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4456 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4459 case WM_EXITMENULOOP
:
4460 f
= x_window_to_frame (dpyinfo
, hwnd
);
4462 /* Indicate that menubar can be modified again. */
4464 f
->output_data
.w32
->menubar_active
= 0;
4467 case WM_MEASUREITEM
:
4468 f
= x_window_to_frame (dpyinfo
, hwnd
);
4471 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4473 if (pMis
->CtlType
== ODT_MENU
)
4475 /* Work out dimensions for popup menu titles. */
4476 char * title
= (char *) pMis
->itemData
;
4477 HDC hdc
= GetDC (hwnd
);
4478 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4479 LOGFONT menu_logfont
;
4483 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4484 menu_logfont
.lfWeight
= FW_BOLD
;
4485 menu_font
= CreateFontIndirect (&menu_logfont
);
4486 old_font
= SelectObject (hdc
, menu_font
);
4488 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4489 pMis
->itemWidth
= size
.cx
;
4490 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4491 if (pMis
->itemHeight
< size
.cy
)
4492 pMis
->itemHeight
= size
.cy
;
4494 SelectObject (hdc
, old_font
);
4495 DeleteObject (menu_font
);
4496 ReleaseDC (hwnd
, hdc
);
4503 f
= x_window_to_frame (dpyinfo
, hwnd
);
4506 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4508 if (pDis
->CtlType
== ODT_MENU
)
4510 /* Draw popup menu title. */
4511 char * title
= (char *) pDis
->itemData
;
4512 HDC hdc
= pDis
->hDC
;
4513 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4514 LOGFONT menu_logfont
;
4517 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4518 menu_logfont
.lfWeight
= FW_BOLD
;
4519 menu_font
= CreateFontIndirect (&menu_logfont
);
4520 old_font
= SelectObject (hdc
, menu_font
);
4522 /* Always draw title as if not selected. */
4524 pDis
->rcItem
.left
+ GetSystemMetrics (SM_CXMENUCHECK
),
4526 ETO_OPAQUE
, &pDis
->rcItem
,
4527 title
, strlen (title
), NULL
);
4529 SelectObject (hdc
, old_font
);
4530 DeleteObject (menu_font
);
4537 /* Still not right - can't distinguish between clicks in the
4538 client area of the frame from clicks forwarded from the scroll
4539 bars - may have to hook WM_NCHITTEST to remember the mouse
4540 position and then check if it is in the client area ourselves. */
4541 case WM_MOUSEACTIVATE
:
4542 /* Discard the mouse click that activates a frame, allowing the
4543 user to click anywhere without changing point (or worse!).
4544 Don't eat mouse clicks on scrollbars though!! */
4545 if (LOWORD (lParam
) == HTCLIENT
)
4546 return MA_ACTIVATEANDEAT
;
4550 case WM_ACTIVATEAPP
:
4552 case WM_WINDOWPOSCHANGED
:
4554 /* Inform lisp thread that a frame might have just been obscured
4555 or exposed, so should recheck visibility of all frames. */
4556 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4560 dpyinfo
->faked_key
= 0;
4562 register_hot_keys (hwnd
);
4565 unregister_hot_keys (hwnd
);
4572 wmsg
.dwModifiers
= w32_get_modifiers ();
4573 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4577 wmsg
.dwModifiers
= w32_get_modifiers ();
4578 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4581 case WM_WINDOWPOSCHANGING
:
4584 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
4586 wp
.length
= sizeof (WINDOWPLACEMENT
);
4587 GetWindowPlacement (hwnd
, &wp
);
4589 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
4596 DWORD internal_border
;
4597 DWORD scrollbar_extra
;
4600 wp
.length
= sizeof(wp
);
4601 GetWindowRect (hwnd
, &wr
);
4605 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
4606 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
4607 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
4608 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
4612 memset (&rect
, 0, sizeof (rect
));
4613 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
4614 GetMenu (hwnd
) != NULL
);
4616 /* Force width and height of client area to be exact
4617 multiples of the character cell dimensions. */
4618 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
4619 - 2 * internal_border
- scrollbar_extra
)
4621 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
4622 - 2 * internal_border
)
4627 /* For right/bottom sizing we can just fix the sizes.
4628 However for top/left sizing we will need to fix the X
4629 and Y positions as well. */
4634 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
4635 && (lppos
->flags
& SWP_NOMOVE
) == 0)
4637 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
4644 lppos
->flags
|= SWP_NOMOVE
;
4655 case WM_GETMINMAXINFO
:
4656 /* Hack to correct bug that allows Emacs frames to be resized
4657 below the Minimum Tracking Size. */
4658 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
4661 case WM_EMACS_CREATESCROLLBAR
:
4662 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
4663 (struct scroll_bar
*) lParam
);
4665 case WM_EMACS_SHOWWINDOW
:
4666 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4668 case WM_EMACS_SETFOREGROUND
:
4670 HWND foreground_window
;
4671 DWORD foreground_thread
, retval
;
4673 /* On NT 5.0, and apparently Windows 98, it is necessary to
4674 attach to the thread that currently has focus in order to
4675 pull the focus away from it. */
4676 foreground_window
= GetForegroundWindow ();
4677 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4678 if (!foreground_window
4679 || foreground_thread
== GetCurrentThreadId ()
4680 || !AttachThreadInput (GetCurrentThreadId (),
4681 foreground_thread
, TRUE
))
4682 foreground_thread
= 0;
4684 retval
= SetForegroundWindow ((HWND
) wParam
);
4686 /* Detach from the previous foreground thread. */
4687 if (foreground_thread
)
4688 AttachThreadInput (GetCurrentThreadId (),
4689 foreground_thread
, FALSE
);
4694 case WM_EMACS_SETWINDOWPOS
:
4696 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4697 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4698 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4701 case WM_EMACS_DESTROYWINDOW
:
4702 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4703 return DestroyWindow ((HWND
) wParam
);
4705 case WM_EMACS_TRACKPOPUPMENU
:
4710 pos
= (POINT
*)lParam
;
4711 flags
= TPM_CENTERALIGN
;
4712 if (button_state
& LMOUSE
)
4713 flags
|= TPM_LEFTBUTTON
;
4714 else if (button_state
& RMOUSE
)
4715 flags
|= TPM_RIGHTBUTTON
;
4717 /* Remember we did a SetCapture on the initial mouse down event,
4718 so for safety, we make sure the capture is cancelled now. */
4722 /* Use menubar_active to indicate that WM_INITMENU is from
4723 TrackPopupMenu below, and should be ignored. */
4724 f
= x_window_to_frame (dpyinfo
, hwnd
);
4726 f
->output_data
.w32
->menubar_active
= 1;
4728 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4732 /* Eat any mouse messages during popupmenu */
4733 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4735 /* Get the menu selection, if any */
4736 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4738 retval
= LOWORD (amsg
.wParam
);
4754 /* Check for messages registered at runtime. */
4755 if (msg
== msh_mousewheel
)
4757 wmsg
.dwModifiers
= w32_get_modifiers ();
4758 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4763 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
4767 /* The most common default return code for handled messages is 0. */
4772 my_create_window (f
)
4777 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4779 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4782 /* Create and set up the w32 window for frame F. */
4785 w32_window (f
, window_prompting
, minibuffer_only
)
4787 long window_prompting
;
4788 int minibuffer_only
;
4792 /* Use the resource name as the top-level window name
4793 for looking up resources. Make a non-Lisp copy
4794 for the window manager, so GC relocation won't bother it.
4796 Elsewhere we specify the window name for the window manager. */
4799 char *str
= (char *) XSTRING (Vx_resource_name
)->data
;
4800 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4801 strcpy (f
->namebuf
, str
);
4804 my_create_window (f
);
4806 validate_x_resource_name ();
4808 /* x_set_name normally ignores requests to set the name if the
4809 requested name is the same as the current name. This is the one
4810 place where that assumption isn't correct; f->name is set, but
4811 the server hasn't been told. */
4814 int explicit = f
->explicit_name
;
4816 f
->explicit_name
= 0;
4819 x_set_name (f
, name
, explicit);
4824 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4825 initialize_frame_menubar (f
);
4827 if (FRAME_W32_WINDOW (f
) == 0)
4828 error ("Unable to create window");
4831 /* Handle the icon stuff for this window. Perhaps later we might
4832 want an x_set_icon_position which can be called interactively as
4840 Lisp_Object icon_x
, icon_y
;
4842 /* Set the position of the icon. Note that Windows 95 groups all
4843 icons in the tray. */
4844 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4845 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4846 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4848 CHECK_NUMBER (icon_x
, 0);
4849 CHECK_NUMBER (icon_y
, 0);
4851 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4852 error ("Both left and top icon corners of icon must be specified");
4856 if (! EQ (icon_x
, Qunbound
))
4857 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4860 /* Start up iconic or window? */
4861 x_wm_set_window_state
4862 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4866 x_text_icon (f
, (char *) XSTRING ((!NILP (f
->icon_name
)
4879 XGCValues gc_values
;
4883 /* Create the GC's of this frame.
4884 Note that many default values are used. */
4887 gc_values
.font
= f
->output_data
.w32
->font
;
4889 /* Cursor has cursor-color background, background-color foreground. */
4890 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
4891 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
4892 f
->output_data
.w32
->cursor_gc
4893 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
4894 (GCFont
| GCForeground
| GCBackground
),
4898 f
->output_data
.w32
->white_relief
.gc
= 0;
4899 f
->output_data
.w32
->black_relief
.gc
= 0;
4905 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4907 "Make a new window, which is called a \"frame\" in Emacs terms.\n\
4908 Returns an Emacs frame object.\n\
4909 ALIST is an alist of frame parameters.\n\
4910 If the parameters specify that the frame should not have a minibuffer,\n\
4911 and do not specify a specific minibuffer window to use,\n\
4912 then `default-minibuffer-frame' must be a frame whose minibuffer can\n\
4913 be shared by the new frame.\n\
4915 This function is an internal primitive--use `make-frame' instead.")
4920 Lisp_Object frame
, tem
;
4922 int minibuffer_only
= 0;
4923 long window_prompting
= 0;
4925 int count
= specpdl_ptr
- specpdl
;
4926 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4927 Lisp_Object display
;
4928 struct w32_display_info
*dpyinfo
= NULL
;
4934 /* Use this general default value to start with
4935 until we know if this frame has a specified name. */
4936 Vx_resource_name
= Vinvocation_name
;
4938 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4939 if (EQ (display
, Qunbound
))
4941 dpyinfo
= check_x_display_info (display
);
4943 kb
= dpyinfo
->kboard
;
4945 kb
= &the_only_kboard
;
4948 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4950 && ! EQ (name
, Qunbound
)
4952 error ("Invalid frame name--not a string or nil");
4955 Vx_resource_name
= name
;
4957 /* See if parent window is specified. */
4958 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4959 if (EQ (parent
, Qunbound
))
4961 if (! NILP (parent
))
4962 CHECK_NUMBER (parent
, 0);
4964 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4965 /* No need to protect DISPLAY because that's not used after passing
4966 it to make_frame_without_minibuffer. */
4968 GCPRO4 (parms
, parent
, name
, frame
);
4969 tem
= w32_get_arg (parms
, Qminibuffer
, 0, 0, RES_TYPE_SYMBOL
);
4970 if (EQ (tem
, Qnone
) || NILP (tem
))
4971 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4972 else if (EQ (tem
, Qonly
))
4974 f
= make_minibuffer_frame ();
4975 minibuffer_only
= 1;
4977 else if (WINDOWP (tem
))
4978 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4982 XSETFRAME (frame
, f
);
4984 /* Note that Windows does support scroll bars. */
4985 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4986 /* By default, make scrollbars the system standard width. */
4987 f
->scroll_bar_pixel_width
= GetSystemMetrics (SM_CXVSCROLL
);
4989 f
->output_method
= output_w32
;
4990 f
->output_data
.w32
=
4991 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
4992 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
4994 FRAME_FONTSET (f
) = -1;
4997 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
4998 if (! STRINGP (f
->icon_name
))
4999 f
->icon_name
= Qnil
;
5001 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
5003 FRAME_KBOARD (f
) = kb
;
5006 /* Specify the parent under which to make this window. */
5010 f
->output_data
.w32
->parent_desc
= (Window
) parent
;
5011 f
->output_data
.w32
->explicit_parent
= 1;
5015 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5016 f
->output_data
.w32
->explicit_parent
= 0;
5019 /* Set the name; the functions to which we pass f expect the name to
5021 if (EQ (name
, Qunbound
) || NILP (name
))
5023 f
->name
= build_string (dpyinfo
->w32_id_name
);
5024 f
->explicit_name
= 0;
5029 f
->explicit_name
= 1;
5030 /* use the frame's title when getting resources for this frame. */
5031 specbind (Qx_resource_name
, name
);
5034 /* Create fontsets from `global_fontset_alist' before handling fonts. */
5035 for (tem
= Vglobal_fontset_alist
; CONSP (tem
); tem
= XCDR (tem
))
5036 fs_register_fontset (f
, XCAR (tem
));
5038 /* Extract the window parameters from the supplied values
5039 that are needed to determine window geometry. */
5043 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
5046 /* First, try whatever font the caller has specified. */
5049 tem
= Fquery_fontset (font
, Qnil
);
5051 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
5053 font
= x_new_font (f
, XSTRING (font
)->data
);
5055 /* Try out a font which we hope has bold and italic variations. */
5056 if (!STRINGP (font
))
5057 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5058 if (! STRINGP (font
))
5059 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5060 /* If those didn't work, look for something which will at least work. */
5061 if (! STRINGP (font
))
5062 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
5064 if (! STRINGP (font
))
5065 font
= build_string ("Fixedsys");
5067 x_default_parameter (f
, parms
, Qfont
, font
,
5068 "font", "Font", RES_TYPE_STRING
);
5071 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5072 "borderwidth", "BorderWidth", RES_TYPE_NUMBER
);
5073 /* This defaults to 2 in order to match xterm. We recognize either
5074 internalBorderWidth or internalBorder (which is what xterm calls
5076 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5080 value
= w32_get_arg (parms
, Qinternal_border_width
,
5081 "internalBorder", "BorderWidth", RES_TYPE_NUMBER
);
5082 if (! EQ (value
, Qunbound
))
5083 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5086 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5087 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
5088 "internalBorderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5089 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qt
,
5090 "verticalScrollBars", "ScrollBars", RES_TYPE_BOOLEAN
);
5092 /* Also do the stuff which must be set before the window exists. */
5093 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5094 "foreground", "Foreground", RES_TYPE_STRING
);
5095 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5096 "background", "Background", RES_TYPE_STRING
);
5097 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5098 "pointerColor", "Foreground", RES_TYPE_STRING
);
5099 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5100 "cursorColor", "Foreground", RES_TYPE_STRING
);
5101 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5102 "borderColor", "BorderColor", RES_TYPE_STRING
);
5103 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
5104 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5107 /* Init faces before x_default_parameter is called for scroll-bar
5108 parameters because that function calls x_set_scroll_bar_width,
5109 which calls change_frame_size, which calls Fset_window_buffer,
5110 which runs hooks, which call Fvertical_motion. At the end, we
5111 end up in init_iterator with a null face cache, which should not
5113 init_frame_faces (f
);
5115 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
5116 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
5117 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (0),
5118 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
5119 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
5120 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5121 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
5122 "title", "Title", RES_TYPE_STRING
);
5124 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5125 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5126 window_prompting
= x_figure_window_size (f
, parms
);
5128 if (window_prompting
& XNegative
)
5130 if (window_prompting
& YNegative
)
5131 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
5133 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
5137 if (window_prompting
& YNegative
)
5138 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
5140 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
5143 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
5145 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5146 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5148 /* Create the window. Add the tool-bar height to the initial frame
5149 height so that the user gets a text display area of the size he
5150 specified with -g or via the registry. Later changes of the
5151 tool-bar height don't change the frame size. This is done so that
5152 users can create tall Emacs frames without having to guess how
5153 tall the tool-bar will get. */
5154 f
->height
+= FRAME_TOOL_BAR_LINES (f
);
5155 w32_window (f
, window_prompting
, minibuffer_only
);
5160 /* Now consider the frame official. */
5161 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5162 Vframe_list
= Fcons (frame
, Vframe_list
);
5164 /* We need to do this after creating the window, so that the
5165 icon-creation functions can say whose icon they're describing. */
5166 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
5167 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5169 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5170 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5171 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5172 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5173 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5174 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5175 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
5176 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5178 /* Dimensions, especially f->height, must be done via change_frame_size.
5179 Change will not be effected unless different from the current
5184 SET_FRAME_WIDTH (f
, 0);
5185 change_frame_size (f
, height
, width
, 1, 0, 0);
5187 /* Set up faces after all frame parameters are known. */
5188 call1 (Qface_set_after_frame_default
, frame
);
5190 /* Tell the server what size and position, etc, we want, and how
5191 badly we want them. This should be done after we have the menu
5192 bar so that its size can be taken into account. */
5194 x_wm_set_size_hint (f
, window_prompting
, 0);
5197 /* Make the window appear on the frame and enable display, unless
5198 the caller says not to. However, with explicit parent, Emacs
5199 cannot control visibility, so don't try. */
5200 if (! f
->output_data
.w32
->explicit_parent
)
5202 Lisp_Object visibility
;
5204 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5205 if (EQ (visibility
, Qunbound
))
5208 if (EQ (visibility
, Qicon
))
5209 x_iconify_frame (f
);
5210 else if (! NILP (visibility
))
5211 x_make_frame_visible (f
);
5213 /* Must have been Qnil. */
5217 return unbind_to (count
, frame
);
5220 /* FRAME is used only to get a handle on the X display. We don't pass the
5221 display info directly because we're called from frame.c, which doesn't
5222 know about that structure. */
5224 x_get_focus_frame (frame
)
5225 struct frame
*frame
;
5227 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
5229 if (! dpyinfo
->w32_focus_frame
)
5232 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5236 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
5237 "Give FRAME input focus, raising to foreground if necessary.")
5241 x_focus_on_frame (check_x_frame (frame
));
5246 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
5247 int size
, char* filename
);
5250 w32_load_system_font (f
,fontname
,size
)
5255 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5256 Lisp_Object font_names
;
5258 /* Get a list of all the fonts that match this name. Once we
5259 have a list of matching fonts, we compare them against the fonts
5260 we already have loaded by comparing names. */
5261 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
5263 if (!NILP (font_names
))
5268 /* First check if any are already loaded, as that is cheaper
5269 than loading another one. */
5270 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5271 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
5272 if (dpyinfo
->font_table
[i
].name
5273 && (!strcmp (dpyinfo
->font_table
[i
].name
,
5274 XSTRING (XCAR (tail
))->data
)
5275 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
5276 XSTRING (XCAR (tail
))->data
)))
5277 return (dpyinfo
->font_table
+ i
);
5279 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
5281 else if (w32_strict_fontnames
)
5283 /* If EnumFontFamiliesEx was available, we got a full list of
5284 fonts back so stop now to avoid the possibility of loading a
5285 random font. If we had to fall back to EnumFontFamilies, the
5286 list is incomplete, so continue whether the font we want was
5288 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5289 FARPROC enum_font_families_ex
5290 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
5291 if (enum_font_families_ex
)
5295 /* Load the font and add it to the table. */
5297 char *full_name
, *encoding
;
5299 struct font_info
*fontp
;
5304 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
5307 if (!*lf
.lfFaceName
)
5308 /* If no name was specified for the font, we get a random font
5309 from CreateFontIndirect - this is not particularly
5310 desirable, especially since CreateFontIndirect does not
5311 fill out the missing name in lf, so we never know what we
5315 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
5317 /* Set bdf to NULL to indicate that this is a Windows font. */
5322 font
->hfont
= CreateFontIndirect (&lf
);
5324 if (font
->hfont
== NULL
)
5333 hdc
= GetDC (dpyinfo
->root_window
);
5334 oldobj
= SelectObject (hdc
, font
->hfont
);
5335 ok
= GetTextMetrics (hdc
, &font
->tm
);
5336 SelectObject (hdc
, oldobj
);
5337 ReleaseDC (dpyinfo
->root_window
, hdc
);
5338 /* Fill out details in lf according to the font that was
5340 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
5341 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
5342 lf
.lfWeight
= font
->tm
.tmWeight
;
5343 lf
.lfItalic
= font
->tm
.tmItalic
;
5344 lf
.lfCharSet
= font
->tm
.tmCharSet
;
5345 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
5346 ? FIXED_PITCH
: VARIABLE_PITCH
);
5347 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
5348 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
5355 w32_unload_font (dpyinfo
, font
);
5359 /* Find a free slot in the font table. */
5360 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
5361 if (dpyinfo
->font_table
[i
].name
== NULL
)
5364 /* If no free slot found, maybe enlarge the font table. */
5365 if (i
== dpyinfo
->n_fonts
5366 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
5369 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
5370 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
5372 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
5375 fontp
= dpyinfo
->font_table
+ i
;
5376 if (i
== dpyinfo
->n_fonts
)
5379 /* Now fill in the slots of *FONTP. */
5382 fontp
->font_idx
= i
;
5383 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
5384 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
5386 /* Work out the font's full name. */
5387 full_name
= (char *)xmalloc (100);
5388 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100))
5389 fontp
->full_name
= full_name
;
5392 /* If all else fails - just use the name we used to load it. */
5394 fontp
->full_name
= fontp
->name
;
5397 fontp
->size
= FONT_WIDTH (font
);
5398 fontp
->height
= FONT_HEIGHT (font
);
5400 /* The slot `encoding' specifies how to map a character
5401 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
5402 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF, 0:0x2020..0x7F7F,
5403 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF,
5404 0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, or
5405 2:0xA020..0xFF7F). For the moment, we don't know which charset
5406 uses this font. So, we set information in fontp->encoding[1]
5407 which is never used by any charset. If mapping can't be
5408 decided, set FONT_ENCODING_NOT_DECIDED. */
5410 /* SJIS fonts need to be set to type 4, all others seem to work as
5411 type FONT_ENCODING_NOT_DECIDED. */
5412 encoding
= strrchr (fontp
->name
, '-');
5413 if (encoding
&& stricmp (encoding
+1, "sjis") == 0)
5414 fontp
->encoding
[1] = 4;
5416 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
5418 /* The following three values are set to 0 under W32, which is
5419 what they get set to if XGetFontProperty fails under X. */
5420 fontp
->baseline_offset
= 0;
5421 fontp
->relative_compose
= 0;
5422 fontp
->default_ascent
= 0;
5424 /* Set global flag fonts_changed_p to non-zero if the font loaded
5425 has a character with a smaller width than any other character
5426 before, or if the font loaded has a smalle>r height than any
5427 other font loaded before. If this happens, it will make a
5428 glyph matrix reallocation necessary. */
5429 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
5435 /* Load font named FONTNAME of size SIZE for frame F, and return a
5436 pointer to the structure font_info while allocating it dynamically.
5437 If loading fails, return NULL. */
5439 w32_load_font (f
,fontname
,size
)
5444 Lisp_Object bdf_fonts
;
5445 struct font_info
*retval
= NULL
;
5447 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
));
5449 while (!retval
&& CONSP (bdf_fonts
))
5451 char *bdf_name
, *bdf_file
;
5452 Lisp_Object bdf_pair
;
5454 bdf_name
= XSTRING (XCAR (bdf_fonts
))->data
;
5455 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
5456 bdf_file
= XSTRING (XCDR (bdf_pair
))->data
;
5458 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
5460 bdf_fonts
= XCDR (bdf_fonts
);
5466 return w32_load_system_font(f
, fontname
, size
);
5471 w32_unload_font (dpyinfo
, font
)
5472 struct w32_display_info
*dpyinfo
;
5477 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
5479 if (font
->hfont
) DeleteObject(font
->hfont
);
5484 /* The font conversion stuff between x and w32 */
5486 /* X font string is as follows (from faces.el)
5490 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
5491 * (weight\? "\\([^-]*\\)") ; 1
5492 * (slant "\\([ior]\\)") ; 2
5493 * (slant\? "\\([^-]?\\)") ; 2
5494 * (swidth "\\([^-]*\\)") ; 3
5495 * (adstyle "[^-]*") ; 4
5496 * (pixelsize "[0-9]+")
5497 * (pointsize "[0-9][0-9]+")
5498 * (resx "[0-9][0-9]+")
5499 * (resy "[0-9][0-9]+")
5500 * (spacing "[cmp?*]")
5501 * (avgwidth "[0-9]+")
5502 * (registry "[^-]+")
5503 * (encoding "[^-]+")
5505 * (setq x-font-regexp
5506 * (concat "\\`\\*?[-?*]"
5507 * foundry - family - weight\? - slant\? - swidth - adstyle -
5508 * pixelsize - pointsize - resx - resy - spacing - registry -
5509 * encoding "[-?*]\\*?\\'"
5511 * (setq x-font-regexp-head
5512 * (concat "\\`[-?*]" foundry - family - weight\? - slant\?
5513 * "\\([-*?]\\|\\'\\)"))
5514 * (setq x-font-regexp-slant (concat - slant -))
5515 * (setq x-font-regexp-weight (concat - weight -))
5519 #define FONT_START "[-?]"
5520 #define FONT_FOUNDRY "[^-]+"
5521 #define FONT_FAMILY "\\([^-]+\\)" /* 1 */
5522 #define FONT_WEIGHT "\\(bold\\|demibold\\|medium\\)" /* 2 */
5523 #define FONT_WEIGHT_Q "\\([^-]*\\)" /* 2 */
5524 #define FONT_SLANT "\\([ior]\\)" /* 3 */
5525 #define FONT_SLANT_Q "\\([^-]?\\)" /* 3 */
5526 #define FONT_SWIDTH "\\([^-]*\\)" /* 4 */
5527 #define FONT_ADSTYLE "[^-]*"
5528 #define FONT_PIXELSIZE "[^-]*"
5529 #define FONT_POINTSIZE "\\([0-9][0-9]+\\|\\*\\)" /* 5 */
5530 #define FONT_RESX "[0-9][0-9]+"
5531 #define FONT_RESY "[0-9][0-9]+"
5532 #define FONT_SPACING "[cmp?*]"
5533 #define FONT_AVGWIDTH "[0-9]+"
5534 #define FONT_REGISTRY "[^-]+"
5535 #define FONT_ENCODING "[^-]+"
5537 #define FONT_REGEXP ("\\`\\*?[-?*]" \
5544 FONT_PIXELSIZE "-" \
5545 FONT_POINTSIZE "-" \
5548 #define FONT_REGEXP_HEAD ("\\`[-?*]" \
5553 "\\([-*?]\\|\\'\\)")
5555 #define FONT_REGEXP_SLANT "-" FONT_SLANT "-"
5556 #define FONT_REGEXP_WEIGHT "-" FONT_WEIGHT "-"
5559 x_to_w32_weight (lpw
)
5562 if (!lpw
) return (FW_DONTCARE
);
5564 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
5565 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
5566 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
5567 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
5568 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
5569 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
5570 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
5571 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
5572 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
5573 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
5580 w32_to_x_weight (fnweight
)
5583 if (fnweight
>= FW_HEAVY
) return "heavy";
5584 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
5585 if (fnweight
>= FW_BOLD
) return "bold";
5586 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
5587 if (fnweight
>= FW_MEDIUM
) return "medium";
5588 if (fnweight
>= FW_NORMAL
) return "normal";
5589 if (fnweight
>= FW_LIGHT
) return "light";
5590 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
5591 if (fnweight
>= FW_THIN
) return "thin";
5597 x_to_w32_charset (lpcs
)
5600 if (!lpcs
) return (0);
5602 if (stricmp (lpcs
,"ansi") == 0) return ANSI_CHARSET
;
5603 else if (stricmp (lpcs
,"iso8859-1") == 0) return ANSI_CHARSET
;
5604 else if (stricmp (lpcs
, "ms-symbol") == 0) return SYMBOL_CHARSET
;
5605 /* Map all Japanese charsets to the Windows Shift-JIS charset. */
5606 else if (strnicmp (lpcs
, "jis", 3) == 0) return SHIFTJIS_CHARSET
;
5607 /* Map all GB charsets to the Windows GB2312 charset. */
5608 else if (strnicmp (lpcs
, "gb2312", 6) == 0) return GB2312_CHARSET
;
5609 /* Map all Big5 charsets to the Windows Big5 charset. */
5610 else if (strnicmp (lpcs
, "big5", 4) == 0) return CHINESEBIG5_CHARSET
;
5611 else if (stricmp (lpcs
, "ksc5601.1987") == 0) return HANGEUL_CHARSET
;
5612 else if (stricmp (lpcs
, "ms-oem") == 0) return OEM_CHARSET
;
5614 #ifdef EASTEUROPE_CHARSET
5615 else if (stricmp (lpcs
, "iso8859-2") == 0) return EASTEUROPE_CHARSET
;
5616 else if (stricmp (lpcs
, "iso8859-3") == 0) return TURKISH_CHARSET
;
5617 else if (stricmp (lpcs
, "iso8859-4") == 0) return BALTIC_CHARSET
;
5618 else if (stricmp (lpcs
, "iso8859-5") == 0) return RUSSIAN_CHARSET
;
5619 else if (stricmp (lpcs
, "koi8") == 0) return RUSSIAN_CHARSET
;
5620 else if (stricmp (lpcs
, "iso8859-6") == 0) return ARABIC_CHARSET
;
5621 else if (stricmp (lpcs
, "iso8859-7") == 0) return GREEK_CHARSET
;
5622 else if (stricmp (lpcs
, "iso8859-8") == 0) return HEBREW_CHARSET
;
5623 else if (stricmp (lpcs
, "iso8859-9") == 0) return TURKISH_CHARSET
;
5624 #ifndef VIETNAMESE_CHARSET
5625 #define VIETNAMESE_CHARSET 163
5627 /* Map all Viscii charsets to the Windows Vietnamese charset. */
5628 else if (strnicmp (lpcs
, "viscii", 6) == 0) return VIETNAMESE_CHARSET
;
5629 else if (strnicmp (lpcs
, "vscii", 5) == 0) return VIETNAMESE_CHARSET
;
5630 /* Map all TIS charsets to the Windows Thai charset. */
5631 else if (strnicmp (lpcs
, "tis620", 6) == 0) return THAI_CHARSET
;
5632 else if (stricmp (lpcs
, "mac") == 0) return MAC_CHARSET
;
5633 else if (stricmp (lpcs
, "ksc5601.1992") == 0) return JOHAB_CHARSET
;
5634 /* For backwards compatibility with previous 20.4 pretests, map
5635 non-specific KSC charsets to the Windows Hangeul charset. */
5636 else if (strnicmp (lpcs
, "ksc5601", 7) == 0) return HANGEUL_CHARSET
;
5637 else if (stricmp (lpcs
, "johab") == 0) return JOHAB_CHARSET
;
5640 #ifdef UNICODE_CHARSET
5641 else if (stricmp (lpcs
,"iso10646") == 0) return UNICODE_CHARSET
;
5642 else if (stricmp (lpcs
, "unicode") == 0) return UNICODE_CHARSET
;
5644 else if (lpcs
[0] == '#') return atoi (lpcs
+ 1);
5646 return DEFAULT_CHARSET
;
5650 w32_to_x_charset (fncharset
)
5653 static char buf
[16];
5657 /* ansi is considered iso8859-1, as most modern ansi fonts are. */
5658 case ANSI_CHARSET
: return "iso8859-1";
5659 case DEFAULT_CHARSET
: return "ascii-*";
5660 case SYMBOL_CHARSET
: return "ms-symbol";
5661 case SHIFTJIS_CHARSET
: return "jisx0208-sjis";
5662 case HANGEUL_CHARSET
: return "ksc5601.1987-*";
5663 case GB2312_CHARSET
: return "gb2312-*";
5664 case CHINESEBIG5_CHARSET
: return "big5-*";
5665 case OEM_CHARSET
: return "ms-oem";
5667 /* More recent versions of Windows (95 and NT4.0) define more
5669 #ifdef EASTEUROPE_CHARSET
5670 case EASTEUROPE_CHARSET
: return "iso8859-2";
5671 case TURKISH_CHARSET
: return "iso8859-9";
5672 case BALTIC_CHARSET
: return "iso8859-4";
5674 /* W95 with international support but not IE4 often has the
5675 KOI8-R codepage but not ISO8859-5. */
5676 case RUSSIAN_CHARSET
:
5677 if (!IsValidCodePage(28595) && IsValidCodePage(20886))
5681 case ARABIC_CHARSET
: return "iso8859-6";
5682 case GREEK_CHARSET
: return "iso8859-7";
5683 case HEBREW_CHARSET
: return "iso8859-8";
5684 case VIETNAMESE_CHARSET
: return "viscii1.1-*";
5685 case THAI_CHARSET
: return "tis620-*";
5686 case MAC_CHARSET
: return "mac-*";
5687 case JOHAB_CHARSET
: return "ksc5601.1992-*";
5691 #ifdef UNICODE_CHARSET
5692 case UNICODE_CHARSET
: return "iso10646-unicode";
5695 /* Encode numerical value of unknown charset. */
5696 sprintf (buf
, "*-#%u", fncharset
);
5701 w32_to_x_font (lplogfont
, lpxstr
, len
)
5702 LOGFONT
* lplogfont
;
5708 char height_pixels
[8];
5710 char width_pixels
[8];
5711 char *fontname_dash
;
5712 int display_resy
= one_w32_display_info
.height_in
;
5713 int display_resx
= one_w32_display_info
.width_in
;
5715 struct coding_system coding
;
5717 if (!lpxstr
) abort ();
5722 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5723 fonttype
= "raster";
5724 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5725 fonttype
= "outline";
5727 fonttype
= "unknown";
5729 setup_coding_system (Fcheck_coding_system (Vw32_system_coding_system
),
5731 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5732 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
5734 fontname
= alloca(sizeof(*fontname
) * bufsz
);
5735 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
5736 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
5737 *(fontname
+ coding
.produced
) = '\0';
5739 /* Replace dashes with underscores so the dashes are not
5741 fontname_dash
= fontname
;
5742 while (fontname_dash
= strchr (fontname_dash
, '-'))
5743 *fontname_dash
= '_';
5745 if (lplogfont
->lfHeight
)
5747 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
5748 sprintf (height_dpi
, "%u",
5749 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
5753 strcpy (height_pixels
, "*");
5754 strcpy (height_dpi
, "*");
5756 if (lplogfont
->lfWidth
)
5757 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
5759 strcpy (width_pixels
, "*");
5761 _snprintf (lpxstr
, len
- 1,
5762 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
5763 fonttype
, /* foundry */
5764 fontname
, /* family */
5765 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
5766 lplogfont
->lfItalic
?'i':'r', /* slant */
5768 /* add style name */
5769 height_pixels
, /* pixel size */
5770 height_dpi
, /* point size */
5771 display_resx
, /* resx */
5772 display_resy
, /* resy */
5773 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
5774 ? 'p' : 'c', /* spacing */
5775 width_pixels
, /* avg width */
5776 w32_to_x_charset (lplogfont
->lfCharSet
) /* charset registry
5780 lpxstr
[len
- 1] = 0; /* just to be sure */
5785 x_to_w32_font (lpxstr
, lplogfont
)
5787 LOGFONT
* lplogfont
;
5789 struct coding_system coding
;
5791 if (!lplogfont
) return (FALSE
);
5793 memset (lplogfont
, 0, sizeof (*lplogfont
));
5795 /* Set default value for each field. */
5797 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
5798 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
5799 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
5801 /* go for maximum quality */
5802 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
5803 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
5804 lplogfont
->lfQuality
= PROOF_QUALITY
;
5807 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
5808 lplogfont
->lfWeight
= FW_DONTCARE
;
5809 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
5814 /* Provide a simple escape mechanism for specifying Windows font names
5815 * directly -- if font spec does not beginning with '-', assume this
5817 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
5823 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
5824 width
[10], resy
[10], remainder
[20];
5826 int dpi
= one_w32_display_info
.height_in
;
5828 fields
= sscanf (lpxstr
,
5829 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%19s",
5830 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
5831 if (fields
== EOF
) return (FALSE
);
5833 /* If wildcards cover more than one field, we don't know which
5834 field is which, so don't fill any in. */
5839 if (fields
> 0 && name
[0] != '*')
5845 (Fcheck_coding_system (Vw32_system_coding_system
), &coding
);
5846 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
5847 buf
= (unsigned char *) alloca (bufsize
);
5848 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
5849 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
5850 if (coding
.produced
>= LF_FACESIZE
)
5851 coding
.produced
= LF_FACESIZE
- 1;
5852 buf
[coding
.produced
] = 0;
5853 strcpy (lplogfont
->lfFaceName
, buf
);
5857 lplogfont
->lfFaceName
[0] = '\0';
5862 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5866 if (!NILP (Vw32_enable_synthesized_fonts
))
5867 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
5871 if (fields
> 0 && pixels
[0] != '*')
5872 lplogfont
->lfHeight
= atoi (pixels
);
5876 if (fields
> 0 && resy
[0] != '*')
5879 if (tem
> 0) dpi
= tem
;
5882 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
5883 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
5886 lplogfont
->lfPitchAndFamily
=
5887 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
5891 if (fields
> 0 && width
[0] != '*')
5892 lplogfont
->lfWidth
= atoi (width
) / 10;
5896 /* Strip the trailing '-' if present. (it shouldn't be, as it
5897 fails the test against xlfn-tight-regexp in fontset.el). */
5899 int len
= strlen (remainder
);
5900 if (len
> 0 && remainder
[len
-1] == '-')
5901 remainder
[len
-1] = 0;
5903 encoding
= remainder
;
5904 if (strncmp (encoding
, "*-", 2) == 0)
5906 lplogfont
->lfCharSet
= x_to_w32_charset (fields
> 0 ? encoding
: "");
5911 char name
[100], height
[10], width
[10], weight
[20];
5913 fields
= sscanf (lpxstr
,
5914 "%99[^:]:%9[^:]:%9[^:]:%19s",
5915 name
, height
, width
, weight
);
5917 if (fields
== EOF
) return (FALSE
);
5921 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
5922 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
5926 lplogfont
->lfFaceName
[0] = 0;
5932 lplogfont
->lfHeight
= atoi (height
);
5937 lplogfont
->lfWidth
= atoi (width
);
5941 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
5944 /* This makes TrueType fonts work better. */
5945 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
5950 /* Assume parameter 1 is fully qualified, no wildcards. */
5952 w32_font_match (fontname
, pattern
)
5956 char *regex
= alloca (strlen (pattern
) * 2);
5962 /* Turn pattern into a regexp and do a regexp match. */
5963 for (; *pattern
; pattern
++)
5965 if (*pattern
== '?')
5967 else if (*pattern
== '*')
5978 return (fast_c_string_match_ignore_case (build_string (regex
),
5982 /* Callback functions, and a structure holding info they need, for
5983 listing system fonts on W32. We need one set of functions to do the
5984 job properly, but these don't work on NT 3.51 and earlier, so we
5985 have a second set which don't handle character sets properly to
5988 In both cases, there are two passes made. The first pass gets one
5989 font from each family, the second pass lists all the fonts from
5992 typedef struct enumfont_t
5997 XFontStruct
*size_ref
;
5998 Lisp_Object
*pattern
;
6003 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
6005 NEWTEXTMETRIC
* lptm
;
6009 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
6012 /* Check that the character set matches if it was specified */
6013 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6014 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6019 Lisp_Object width
= Qnil
;
6021 /* Truetype fonts do not report their true metrics until loaded */
6022 if (FontType
!= RASTER_FONTTYPE
)
6024 if (!NILP (*(lpef
->pattern
)))
6026 /* Scalable fonts are as big as you want them to be. */
6027 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6028 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6029 width
= make_number (lpef
->logfont
.lfWidth
);
6033 lplf
->elfLogFont
.lfHeight
= 0;
6034 lplf
->elfLogFont
.lfWidth
= 0;
6038 /* Make sure the height used here is the same as everywhere
6039 else (ie character height, not cell height). */
6040 if (lplf
->elfLogFont
.lfHeight
> 0)
6042 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6043 if (FontType
== RASTER_FONTTYPE
)
6044 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6046 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6049 if (!w32_to_x_font (&(lplf
->elfLogFont
), buf
, 100))
6052 if (NILP (*(lpef
->pattern
))
6053 || w32_font_match (buf
, XSTRING (*(lpef
->pattern
))->data
))
6055 *lpef
->tail
= Fcons (Fcons (build_string (buf
), width
), Qnil
);
6056 lpef
->tail
= &(XCDR (*lpef
->tail
));
6065 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6067 NEWTEXTMETRIC
* lptm
;
6071 return EnumFontFamilies (lpef
->hdc
,
6072 lplf
->elfLogFont
.lfFaceName
,
6073 (FONTENUMPROC
) enum_font_cb2
,
6079 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6080 ENUMLOGFONTEX
* lplf
;
6081 NEWTEXTMETRICEX
* lptm
;
6085 /* We are not interested in the extra info we get back from the 'Ex
6086 version - only the fact that we get character set variations
6087 enumerated seperately. */
6088 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6093 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6094 ENUMLOGFONTEX
* lplf
;
6095 NEWTEXTMETRICEX
* lptm
;
6099 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6100 FARPROC enum_font_families_ex
6101 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6102 /* We don't really expect EnumFontFamiliesEx to disappear once we
6103 get here, so don't bother handling it gracefully. */
6104 if (enum_font_families_ex
== NULL
)
6105 error ("gdi32.dll has disappeared!");
6106 return enum_font_families_ex (lpef
->hdc
,
6108 (FONTENUMPROC
) enum_fontex_cb2
,
6112 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6113 and xterm.c in Emacs 20.3) */
6115 Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6117 char *fontname
, *ptnstr
;
6118 Lisp_Object list
, tem
, newlist
= Qnil
;
6121 list
= Vw32_bdf_filename_alist
;
6122 ptnstr
= XSTRING (pattern
)->data
;
6124 for ( ; CONSP (list
); list
= XCDR (list
))
6128 fontname
= XSTRING (XCAR (tem
))->data
;
6129 else if (STRINGP (tem
))
6130 fontname
= XSTRING (tem
)->data
;
6134 if (w32_font_match (fontname
, ptnstr
))
6136 newlist
= Fcons (XCAR (tem
), newlist
);
6138 if (n_fonts
>= max_names
)
6146 Lisp_Object
w32_list_synthesized_fonts (FRAME_PTR f
, Lisp_Object pattern
,
6147 int size
, int max_names
);
6149 /* Return a list of names of available fonts matching PATTERN on frame
6150 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6151 to be listed. Frame F NULL means we have not yet created any
6152 frame, which means we can't get proper size info, as we don't have
6153 a device context to use for GetTextMetrics.
6154 MAXNAMES sets a limit on how many fonts to match. */
6157 w32_list_fonts (FRAME_PTR f
, Lisp_Object pattern
, int size
, int maxnames
)
6159 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6160 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6161 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6164 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6165 if (NILP (patterns
))
6166 patterns
= Fcons (pattern
, Qnil
);
6168 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6172 tpat
= XCAR (patterns
);
6174 /* See if we cached the result for this particular query.
6175 The cache is an alist of the form:
6176 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6178 if (tem
= XCDR (dpyinfo
->name_list_element
),
6179 !NILP (list
= Fassoc (tpat
, tem
)))
6181 list
= Fcdr_safe (list
);
6182 /* We have a cached list. Don't have to get the list again. */
6187 /* At first, put PATTERN in the cache. */
6193 /* Use EnumFontFamiliesEx where it is available, as it knows
6194 about character sets. Fall back to EnumFontFamilies for
6195 older versions of NT that don't support the 'Ex function. */
6196 x_to_w32_font (STRINGP (tpat
) ? XSTRING (tpat
)->data
:
6199 LOGFONT font_match_pattern
;
6200 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6201 FARPROC enum_font_families_ex
6202 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6204 /* We do our own pattern matching so we can handle wildcards. */
6205 font_match_pattern
.lfFaceName
[0] = 0;
6206 font_match_pattern
.lfPitchAndFamily
= 0;
6207 /* We can use the charset, because if it is a wildcard it will
6208 be DEFAULT_CHARSET anyway. */
6209 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6211 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6213 if (enum_font_families_ex
)
6214 enum_font_families_ex (ef
.hdc
,
6215 &font_match_pattern
,
6216 (FONTENUMPROC
) enum_fontex_cb1
,
6219 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6222 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6227 /* Make a list of the fonts we got back.
6228 Store that in the font cache for the display. */
6229 XCDR (dpyinfo
->name_list_element
)
6230 = Fcons (Fcons (tpat
, list
),
6231 XCDR (dpyinfo
->name_list_element
));
6234 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6236 newlist
= second_best
= Qnil
;
6238 /* Make a list of the fonts that have the right width. */
6239 for (; CONSP (list
); list
= XCDR (list
))
6246 if (NILP (XCAR (tem
)))
6250 newlist
= Fcons (XCAR (tem
), newlist
);
6252 if (n_fonts
>= maxnames
)
6257 if (!INTEGERP (XCDR (tem
)))
6259 /* Since we don't yet know the size of the font, we must
6260 load it and try GetTextMetrics. */
6261 W32FontStruct thisinfo
;
6266 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
6270 thisinfo
.bdf
= NULL
;
6271 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6272 if (thisinfo
.hfont
== NULL
)
6275 hdc
= GetDC (dpyinfo
->root_window
);
6276 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6277 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6278 XCDR (tem
) = make_number (FONT_WIDTH (&thisinfo
));
6280 XCDR (tem
) = make_number (0);
6281 SelectObject (hdc
, oldobj
);
6282 ReleaseDC (dpyinfo
->root_window
, hdc
);
6283 DeleteObject(thisinfo
.hfont
);
6286 found_size
= XINT (XCDR (tem
));
6287 if (found_size
== size
)
6289 newlist
= Fcons (XCAR (tem
), newlist
);
6291 if (n_fonts
>= maxnames
)
6294 /* keep track of the closest matching size in case
6295 no exact match is found. */
6296 else if (found_size
> 0)
6298 if (NILP (second_best
))
6301 else if (found_size
< size
)
6303 if (XINT (XCDR (second_best
)) > size
6304 || XINT (XCDR (second_best
)) < found_size
)
6309 if (XINT (XCDR (second_best
)) > size
6310 && XINT (XCDR (second_best
)) >
6317 if (!NILP (newlist
))
6319 else if (!NILP (second_best
))
6321 newlist
= Fcons (XCAR (second_best
), Qnil
);
6326 /* Include any bdf fonts. */
6327 if (n_fonts
< maxnames
)
6329 Lisp_Object combined
[2];
6330 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6331 combined
[1] = newlist
;
6332 newlist
= Fnconc(2, combined
);
6335 /* If we can't find a font that matches, check if Windows would be
6336 able to synthesize it from a different style. */
6337 if (NILP (newlist
) && !NILP (Vw32_enable_synthesized_fonts
))
6338 newlist
= w32_list_synthesized_fonts (f
, pattern
, size
, maxnames
);
6344 w32_list_synthesized_fonts (f
, pattern
, size
, max_names
)
6346 Lisp_Object pattern
;
6351 char *full_pattn
, *new_pattn
, foundary
[50], family
[50], *pattn_part2
;
6352 char style
[20], slant
;
6353 Lisp_Object matches
, match
, tem
, synthed_matches
= Qnil
;
6355 full_pattn
= XSTRING (pattern
)->data
;
6357 pattn_part2
= alloca (XSTRING (pattern
)->size
);
6358 /* Allow some space for wildcard expansion. */
6359 new_pattn
= alloca (XSTRING (pattern
)->size
+ 100);
6361 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%19[^-]-%c-%s",
6362 foundary
, family
, style
, &slant
, pattn_part2
);
6363 if (fields
== EOF
|| fields
< 5)
6366 /* If the style and slant are wildcards already there is no point
6367 checking again (and we don't want to keep recursing). */
6368 if (*style
== '*' && slant
== '*')
6371 sprintf (new_pattn
, "-%s-%s-*-*-%s", foundary
, family
, pattn_part2
);
6373 matches
= w32_list_fonts (f
, build_string (new_pattn
), size
, max_names
);
6375 for ( ; CONSP (matches
); matches
= XCDR (matches
))
6377 tem
= XCAR (matches
);
6381 full_pattn
= XSTRING (tem
)->data
;
6382 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%*[^-]-%*c-%s",
6383 foundary
, family
, pattn_part2
);
6384 if (fields
== EOF
|| fields
< 3)
6387 sprintf (new_pattn
, "-%s-%s-%s-%c-%s", foundary
, family
, style
,
6388 slant
, pattn_part2
);
6390 synthed_matches
= Fcons (build_string (new_pattn
),
6394 return synthed_matches
;
6398 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6400 w32_get_font_info (f
, font_idx
)
6404 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6409 w32_query_font (struct frame
*f
, char *fontname
)
6412 struct font_info
*pfi
;
6414 pfi
= FRAME_W32_FONT_TABLE (f
);
6416 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6418 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
6424 /* Find a CCL program for a font specified by FONTP, and set the member
6425 `encoder' of the structure. */
6428 w32_find_ccl_program (fontp
)
6429 struct font_info
*fontp
;
6431 Lisp_Object list
, elt
;
6433 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6437 && STRINGP (XCAR (elt
))
6438 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6444 struct ccl_program
*ccl
6445 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6447 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6450 fontp
->font_encoder
= ccl
;
6455 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6457 "Return a list of BDF fonts in DIR, suitable for appending to\n\
6458 w32-bdf-filename-alist. Fonts which do not contain an xfld description\n\
6459 will not be included in the list. DIR may be a list of directories.")
6461 Lisp_Object directory
;
6463 Lisp_Object list
= Qnil
;
6464 struct gcpro gcpro1
, gcpro2
;
6466 if (!CONSP (directory
))
6467 return w32_find_bdf_fonts_in_dir (directory
);
6469 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6471 Lisp_Object pair
[2];
6474 GCPRO2 (directory
, list
);
6475 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6476 list
= Fnconc( 2, pair
);
6482 /* Find BDF files in a specified directory. (use GCPRO when calling,
6483 as this calls lisp to get a directory listing). */
6484 Lisp_Object
w32_find_bdf_fonts_in_dir( Lisp_Object directory
)
6486 Lisp_Object filelist
, list
= Qnil
;
6489 if (!STRINGP(directory
))
6492 filelist
= Fdirectory_files (directory
, Qt
,
6493 build_string (".*\\.[bB][dD][fF]"), Qt
);
6495 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6497 Lisp_Object filename
= XCAR (filelist
);
6498 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
6499 store_in_alist (&list
, build_string (fontname
), filename
);
6505 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6506 "Return non-nil if color COLOR is supported on frame FRAME.\n\
6507 If FRAME is omitted or nil, use the selected frame.")
6509 Lisp_Object color
, frame
;
6512 FRAME_PTR f
= check_x_frame (frame
);
6514 CHECK_STRING (color
, 1);
6516 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
6522 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6523 "Return a description of the color named COLOR on frame FRAME.\n\
6524 The value is a list of integer RGB values--(RED GREEN BLUE).\n\
6525 These values appear to range from 0 to 65280 or 65535, depending\n\
6526 on the system; white is (65280 65280 65280) or (65535 65535 65535).\n\
6527 If FRAME is omitted or nil, use the selected frame.")
6529 Lisp_Object color
, frame
;
6532 FRAME_PTR f
= check_x_frame (frame
);
6534 CHECK_STRING (color
, 1);
6536 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
6540 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
6541 | GetRValue (foo
.pixel
));
6542 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
6543 | GetGValue (foo
.pixel
));
6544 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
6545 | GetBValue (foo
.pixel
));
6546 return Flist (3, rgb
);
6552 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6553 "Return t if the X display supports color.\n\
6554 The optional argument DISPLAY specifies which display to ask about.\n\
6555 DISPLAY should be either a frame or a display name (a string).\n\
6556 If omitted or nil, that stands for the selected frame's display.")
6558 Lisp_Object display
;
6560 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6562 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6568 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
6570 "Return t if the X display supports shades of gray.\n\
6571 Note that color displays do support shades of gray.\n\
6572 The optional argument DISPLAY specifies which display to ask about.\n\
6573 DISPLAY should be either a frame or a display name (a string).\n\
6574 If omitted or nil, that stands for the selected frame's display.")
6576 Lisp_Object display
;
6578 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6580 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
6586 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
6588 "Returns the width in pixels of the X display DISPLAY.\n\
6589 The optional argument DISPLAY specifies which display to ask about.\n\
6590 DISPLAY should be either a frame or a display name (a string).\n\
6591 If omitted or nil, that stands for the selected frame's display.")
6593 Lisp_Object display
;
6595 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6597 return make_number (dpyinfo
->width
);
6600 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
6601 Sx_display_pixel_height
, 0, 1, 0,
6602 "Returns the height in pixels of the X display DISPLAY.\n\
6603 The optional argument DISPLAY specifies which display to ask about.\n\
6604 DISPLAY should be either a frame or a display name (a string).\n\
6605 If omitted or nil, that stands for the selected frame's display.")
6607 Lisp_Object display
;
6609 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6611 return make_number (dpyinfo
->height
);
6614 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
6616 "Returns the number of bitplanes of the display DISPLAY.\n\
6617 The optional argument DISPLAY specifies which display to ask about.\n\
6618 DISPLAY should be either a frame or a display name (a string).\n\
6619 If omitted or nil, that stands for the selected frame's display.")
6621 Lisp_Object display
;
6623 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6625 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
6628 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
6630 "Returns the number of color cells of the display DISPLAY.\n\
6631 The optional argument DISPLAY specifies which display to ask about.\n\
6632 DISPLAY should be either a frame or a display name (a string).\n\
6633 If omitted or nil, that stands for the selected frame's display.")
6635 Lisp_Object display
;
6637 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6641 hdc
= GetDC (dpyinfo
->root_window
);
6642 if (dpyinfo
->has_palette
)
6643 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
6645 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
6647 ReleaseDC (dpyinfo
->root_window
, hdc
);
6649 return make_number (cap
);
6652 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
6653 Sx_server_max_request_size
,
6655 "Returns the maximum request size of the server of display DISPLAY.\n\
6656 The optional argument DISPLAY specifies which display to ask about.\n\
6657 DISPLAY should be either a frame or a display name (a string).\n\
6658 If omitted or nil, that stands for the selected frame's display.")
6660 Lisp_Object display
;
6662 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6664 return make_number (1);
6667 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
6668 "Returns the vendor ID string of the W32 system (Microsoft).\n\
6669 The optional argument DISPLAY specifies which display to ask about.\n\
6670 DISPLAY should be either a frame or a display name (a string).\n\
6671 If omitted or nil, that stands for the selected frame's display.")
6673 Lisp_Object display
;
6675 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6676 char *vendor
= "Microsoft Corp.";
6678 if (! vendor
) vendor
= "";
6679 return build_string (vendor
);
6682 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
6683 "Returns the version numbers of the server of display DISPLAY.\n\
6684 The value is a list of three integers: the major and minor\n\
6685 version numbers, and the vendor-specific release\n\
6686 number. See also the function `x-server-vendor'.\n\n\
6687 The optional argument DISPLAY specifies which display to ask about.\n\
6688 DISPLAY should be either a frame or a display name (a string).\n\
6689 If omitted or nil, that stands for the selected frame's display.")
6691 Lisp_Object display
;
6693 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6695 return Fcons (make_number (w32_major_version
),
6696 Fcons (make_number (w32_minor_version
), Qnil
));
6699 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
6700 "Returns the number of screens on the server of display DISPLAY.\n\
6701 The optional argument DISPLAY specifies which display to ask about.\n\
6702 DISPLAY should be either a frame or a display name (a string).\n\
6703 If omitted or nil, that stands for the selected frame's display.")
6705 Lisp_Object display
;
6707 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6709 return make_number (1);
6712 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
6713 "Returns the height in millimeters of the X display DISPLAY.\n\
6714 The optional argument DISPLAY specifies which display to ask about.\n\
6715 DISPLAY should be either a frame or a display name (a string).\n\
6716 If omitted or nil, that stands for the selected frame's display.")
6718 Lisp_Object display
;
6720 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6724 hdc
= GetDC (dpyinfo
->root_window
);
6726 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
6728 ReleaseDC (dpyinfo
->root_window
, hdc
);
6730 return make_number (cap
);
6733 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
6734 "Returns the width in millimeters of the X display DISPLAY.\n\
6735 The optional argument DISPLAY specifies which display to ask about.\n\
6736 DISPLAY should be either a frame or a display name (a string).\n\
6737 If omitted or nil, that stands for the selected frame's display.")
6739 Lisp_Object display
;
6741 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6746 hdc
= GetDC (dpyinfo
->root_window
);
6748 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
6750 ReleaseDC (dpyinfo
->root_window
, hdc
);
6752 return make_number (cap
);
6755 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
6756 Sx_display_backing_store
, 0, 1, 0,
6757 "Returns an indication of whether display DISPLAY does backing store.\n\
6758 The value may be `always', `when-mapped', or `not-useful'.\n\
6759 The optional argument DISPLAY specifies which display to ask about.\n\
6760 DISPLAY should be either a frame or a display name (a string).\n\
6761 If omitted or nil, that stands for the selected frame's display.")
6763 Lisp_Object display
;
6765 return intern ("not-useful");
6768 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
6769 Sx_display_visual_class
, 0, 1, 0,
6770 "Returns the visual class of the display DISPLAY.\n\
6771 The value is one of the symbols `static-gray', `gray-scale',\n\
6772 `static-color', `pseudo-color', `true-color', or `direct-color'.\n\n\
6773 The optional argument DISPLAY specifies which display to ask about.\n\
6774 DISPLAY should be either a frame or a display name (a string).\n\
6775 If omitted or nil, that stands for the selected frame's display.")
6777 Lisp_Object display
;
6779 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6782 switch (dpyinfo
->visual
->class)
6784 case StaticGray
: return (intern ("static-gray"));
6785 case GrayScale
: return (intern ("gray-scale"));
6786 case StaticColor
: return (intern ("static-color"));
6787 case PseudoColor
: return (intern ("pseudo-color"));
6788 case TrueColor
: return (intern ("true-color"));
6789 case DirectColor
: return (intern ("direct-color"));
6791 error ("Display has an unknown visual class");
6795 error ("Display has an unknown visual class");
6798 DEFUN ("x-display-save-under", Fx_display_save_under
,
6799 Sx_display_save_under
, 0, 1, 0,
6800 "Returns t if the display DISPLAY supports the save-under feature.\n\
6801 The optional argument DISPLAY specifies which display to ask about.\n\
6802 DISPLAY should be either a frame or a display name (a string).\n\
6803 If omitted or nil, that stands for the selected frame's display.")
6805 Lisp_Object display
;
6807 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6814 register struct frame
*f
;
6816 return PIXEL_WIDTH (f
);
6821 register struct frame
*f
;
6823 return PIXEL_HEIGHT (f
);
6828 register struct frame
*f
;
6830 return FONT_WIDTH (f
->output_data
.w32
->font
);
6835 register struct frame
*f
;
6837 return f
->output_data
.w32
->line_height
;
6842 register struct frame
*f
;
6844 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
6847 /* Return the display structure for the display named NAME.
6848 Open a new connection if necessary. */
6850 struct w32_display_info
*
6851 x_display_info_for_name (name
)
6855 struct w32_display_info
*dpyinfo
;
6857 CHECK_STRING (name
, 0);
6859 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
6861 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
6864 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
6869 /* Use this general default value to start with. */
6870 Vx_resource_name
= Vinvocation_name
;
6872 validate_x_resource_name ();
6874 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
6875 (char *) XSTRING (Vx_resource_name
)->data
);
6878 error ("Cannot connect to server %s", XSTRING (name
)->data
);
6881 XSETFASTINT (Vwindow_system_version
, 3);
6886 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
6887 1, 3, 0, "Open a connection to a server.\n\
6888 DISPLAY is the name of the display to connect to.\n\
6889 Optional second arg XRM-STRING is a string of resources in xrdb format.\n\
6890 If the optional third arg MUST-SUCCEED is non-nil,\n\
6891 terminate Emacs if we can't open the connection.")
6892 (display
, xrm_string
, must_succeed
)
6893 Lisp_Object display
, xrm_string
, must_succeed
;
6895 unsigned char *xrm_option
;
6896 struct w32_display_info
*dpyinfo
;
6898 CHECK_STRING (display
, 0);
6899 if (! NILP (xrm_string
))
6900 CHECK_STRING (xrm_string
, 1);
6902 if (! EQ (Vwindow_system
, intern ("w32")))
6903 error ("Not using Microsoft Windows");
6905 /* Allow color mapping to be defined externally; first look in user's
6906 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
6908 Lisp_Object color_file
;
6909 struct gcpro gcpro1
;
6911 color_file
= build_string("~/rgb.txt");
6913 GCPRO1 (color_file
);
6915 if (NILP (Ffile_readable_p (color_file
)))
6917 Fexpand_file_name (build_string ("rgb.txt"),
6918 Fsymbol_value (intern ("data-directory")));
6920 Vw32_color_map
= Fw32_load_color_file (color_file
);
6924 if (NILP (Vw32_color_map
))
6925 Vw32_color_map
= Fw32_default_color_map ();
6927 if (! NILP (xrm_string
))
6928 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
6930 xrm_option
= (unsigned char *) 0;
6932 /* Use this general default value to start with. */
6933 /* First remove .exe suffix from invocation-name - it looks ugly. */
6935 char basename
[ MAX_PATH
], *str
;
6937 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
6938 str
= strrchr (basename
, '.');
6940 Vinvocation_name
= build_string (basename
);
6942 Vx_resource_name
= Vinvocation_name
;
6944 validate_x_resource_name ();
6946 /* This is what opens the connection and sets x_current_display.
6947 This also initializes many symbols, such as those used for input. */
6948 dpyinfo
= w32_term_init (display
, xrm_option
,
6949 (char *) XSTRING (Vx_resource_name
)->data
);
6953 if (!NILP (must_succeed
))
6954 fatal ("Cannot connect to server %s.\n",
6955 XSTRING (display
)->data
);
6957 error ("Cannot connect to server %s", XSTRING (display
)->data
);
6962 XSETFASTINT (Vwindow_system_version
, 3);
6966 DEFUN ("x-close-connection", Fx_close_connection
,
6967 Sx_close_connection
, 1, 1, 0,
6968 "Close the connection to DISPLAY's server.\n\
6969 For DISPLAY, specify either a frame or a display name (a string).\n\
6970 If DISPLAY is nil, that stands for the selected frame's display.")
6972 Lisp_Object display
;
6974 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6977 if (dpyinfo
->reference_count
> 0)
6978 error ("Display still has frames on it");
6981 /* Free the fonts in the font table. */
6982 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6983 if (dpyinfo
->font_table
[i
].name
)
6985 xfree (dpyinfo
->font_table
[i
].name
);
6986 /* Don't free the full_name string;
6987 it is always shared with something else. */
6988 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
6990 x_destroy_all_bitmaps (dpyinfo
);
6992 x_delete_display (dpyinfo
);
6998 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
6999 "Return the list of display names that Emacs has connections to.")
7002 Lisp_Object tail
, result
;
7005 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
7006 result
= Fcons (XCAR (XCAR (tail
)), result
);
7011 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7012 "If ON is non-nil, report errors as soon as the erring request is made.\n\
7013 If ON is nil, allow buffering of requests.\n\
7014 This is a noop on W32 systems.\n\
7015 The optional second argument DISPLAY specifies which display to act on.\n\
7016 DISPLAY should be either a frame or a display name (a string).\n\
7017 If DISPLAY is omitted or nil, that stands for the selected frame's display.")
7019 Lisp_Object display
, on
;
7021 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7028 /***********************************************************************
7030 ***********************************************************************/
7032 /* Value is the number of elements of vector VECTOR. */
7034 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
7036 /* List of supported image types. Use define_image_type to add new
7037 types. Use lookup_image_type to find a type for a given symbol. */
7039 static struct image_type
*image_types
;
7041 /* A list of symbols, one for each supported image type. */
7043 Lisp_Object Vimage_types
;
7045 /* The symbol `image' which is the car of the lists used to represent
7048 extern Lisp_Object Qimage
;
7050 /* The symbol `xbm' which is used as the type symbol for XBM images. */
7056 Lisp_Object QCtype
, QCdata
, QCascent
, QCmargin
, QCrelief
;
7057 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
7058 Lisp_Object QCalgorithm
, QCcolor_symbols
, QCheuristic_mask
;
7059 extern Lisp_Object QCindex
;
7061 /* Other symbols. */
7063 Lisp_Object Qlaplace
;
7065 /* Time in seconds after which images should be removed from the cache
7066 if not displayed. */
7068 Lisp_Object Vimage_cache_eviction_delay
;
7070 /* Function prototypes. */
7072 static void define_image_type
P_ ((struct image_type
*type
));
7073 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
7074 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
7075 static void x_laplace
P_ ((struct frame
*, struct image
*));
7076 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
7079 /* Define a new image type from TYPE. This adds a copy of TYPE to
7080 image_types and adds the symbol *TYPE->type to Vimage_types. */
7083 define_image_type (type
)
7084 struct image_type
*type
;
7086 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
7087 The initialized data segment is read-only. */
7088 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
7089 bcopy (type
, p
, sizeof *p
);
7090 p
->next
= image_types
;
7092 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
7096 /* Look up image type SYMBOL, and return a pointer to its image_type
7097 structure. Value is null if SYMBOL is not a known image type. */
7099 static INLINE
struct image_type
*
7100 lookup_image_type (symbol
)
7103 struct image_type
*type
;
7105 for (type
= image_types
; type
; type
= type
->next
)
7106 if (EQ (symbol
, *type
->type
))
7113 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
7114 valid image specification is a list whose car is the symbol
7115 `image', and whose rest is a property list. The property list must
7116 contain a value for key `:type'. That value must be the name of a
7117 supported image type. The rest of the property list depends on the
7121 valid_image_p (object
)
7126 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
7128 Lisp_Object symbol
= Fplist_get (XCDR (object
), QCtype
);
7129 struct image_type
*type
= lookup_image_type (symbol
);
7132 valid_p
= type
->valid_p (object
);
7139 /* Log error message with format string FORMAT and argument ARG.
7140 Signaling an error, e.g. when an image cannot be loaded, is not a
7141 good idea because this would interrupt redisplay, and the error
7142 message display would lead to another redisplay. This function
7143 therefore simply displays a message. */
7146 image_error (format
, arg1
, arg2
)
7148 Lisp_Object arg1
, arg2
;
7150 add_to_log (format
, arg1
, arg2
);
7155 /***********************************************************************
7156 Image specifications
7157 ***********************************************************************/
7159 enum image_value_type
7161 IMAGE_DONT_CHECK_VALUE_TYPE
,
7164 IMAGE_POSITIVE_INTEGER_VALUE
,
7165 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
7166 IMAGE_INTEGER_VALUE
,
7167 IMAGE_FUNCTION_VALUE
,
7172 /* Structure used when parsing image specifications. */
7174 struct image_keyword
7176 /* Name of keyword. */
7179 /* The type of value allowed. */
7180 enum image_value_type type
;
7182 /* Non-zero means key must be present. */
7185 /* Used to recognize duplicate keywords in a property list. */
7188 /* The value that was found. */
7193 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
7195 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
7198 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
7199 has the format (image KEYWORD VALUE ...). One of the keyword/
7200 value pairs must be `:type TYPE'. KEYWORDS is a vector of
7201 image_keywords structures of size NKEYWORDS describing other
7202 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
7205 parse_image_spec (spec
, keywords
, nkeywords
, type
)
7207 struct image_keyword
*keywords
;
7214 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
7217 plist
= XCDR (spec
);
7218 while (CONSP (plist
))
7220 Lisp_Object key
, value
;
7222 /* First element of a pair must be a symbol. */
7224 plist
= XCDR (plist
);
7228 /* There must follow a value. */
7231 value
= XCAR (plist
);
7232 plist
= XCDR (plist
);
7234 /* Find key in KEYWORDS. Error if not found. */
7235 for (i
= 0; i
< nkeywords
; ++i
)
7236 if (strcmp (keywords
[i
].name
, XSYMBOL (key
)->name
->data
) == 0)
7242 /* Record that we recognized the keyword. If a keywords
7243 was found more than once, it's an error. */
7244 keywords
[i
].value
= value
;
7245 ++keywords
[i
].count
;
7247 if (keywords
[i
].count
> 1)
7250 /* Check type of value against allowed type. */
7251 switch (keywords
[i
].type
)
7253 case IMAGE_STRING_VALUE
:
7254 if (!STRINGP (value
))
7258 case IMAGE_SYMBOL_VALUE
:
7259 if (!SYMBOLP (value
))
7263 case IMAGE_POSITIVE_INTEGER_VALUE
:
7264 if (!INTEGERP (value
) || XINT (value
) <= 0)
7268 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
7269 if (!INTEGERP (value
) || XINT (value
) < 0)
7273 case IMAGE_DONT_CHECK_VALUE_TYPE
:
7276 case IMAGE_FUNCTION_VALUE
:
7277 value
= indirect_function (value
);
7279 || COMPILEDP (value
)
7280 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
7284 case IMAGE_NUMBER_VALUE
:
7285 if (!INTEGERP (value
) && !FLOATP (value
))
7289 case IMAGE_INTEGER_VALUE
:
7290 if (!INTEGERP (value
))
7294 case IMAGE_BOOL_VALUE
:
7295 if (!NILP (value
) && !EQ (value
, Qt
))
7304 if (EQ (key
, QCtype
) && !EQ (type
, value
))
7308 /* Check that all mandatory fields are present. */
7309 for (i
= 0; i
< nkeywords
; ++i
)
7310 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
7313 return NILP (plist
);
7317 /* Return the value of KEY in image specification SPEC. Value is nil
7318 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
7319 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
7322 image_spec_value (spec
, key
, found
)
7323 Lisp_Object spec
, key
;
7328 xassert (valid_image_p (spec
));
7330 for (tail
= XCDR (spec
);
7331 CONSP (tail
) && CONSP (XCDR (tail
));
7332 tail
= XCDR (XCDR (tail
)))
7334 if (EQ (XCAR (tail
), key
))
7338 return XCAR (XCDR (tail
));
7350 /***********************************************************************
7351 Image type independent image structures
7352 ***********************************************************************/
7354 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
7355 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
7358 /* Allocate and return a new image structure for image specification
7359 SPEC. SPEC has a hash value of HASH. */
7361 static struct image
*
7362 make_image (spec
, hash
)
7366 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
7368 xassert (valid_image_p (spec
));
7369 bzero (img
, sizeof *img
);
7370 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
7371 xassert (img
->type
!= NULL
);
7373 img
->data
.lisp_val
= Qnil
;
7374 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
7380 /* Free image IMG which was used on frame F, including its resources. */
7389 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7391 /* Remove IMG from the hash table of its cache. */
7393 img
->prev
->next
= img
->next
;
7395 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
7398 img
->next
->prev
= img
->prev
;
7400 c
->images
[img
->id
] = NULL
;
7402 /* Free resources, then free IMG. */
7403 img
->type
->free (f
, img
);
7409 /* Prepare image IMG for display on frame F. Must be called before
7410 drawing an image. */
7413 prepare_image_for_display (f
, img
)
7419 /* We're about to display IMG, so set its timestamp to `now'. */
7421 img
->timestamp
= EMACS_SECS (t
);
7423 /* If IMG doesn't have a pixmap yet, load it now, using the image
7424 type dependent loader function. */
7425 if (img
->pixmap
== 0 && !img
->load_failed_p
)
7426 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
7431 /***********************************************************************
7432 Helper functions for X image types
7433 ***********************************************************************/
7435 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
7436 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
7438 Lisp_Object color_name
,
7439 unsigned long dflt
));
7441 /* Free X resources of image IMG which is used on frame F. */
7444 x_clear_image (f
, img
)
7448 #if 0 /* NTEMACS_TODO: W32 image support */
7453 XFreePixmap (NULL
, img
->pixmap
);
7460 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
7462 /* If display has an immutable color map, freeing colors is not
7463 necessary and some servers don't allow it. So don't do it. */
7464 if (class != StaticColor
7465 && class != StaticGray
7466 && class != TrueColor
)
7470 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
7471 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
7476 xfree (img
->colors
);
7484 /* Allocate color COLOR_NAME for image IMG on frame F. If color
7485 cannot be allocated, use DFLT. Add a newly allocated color to
7486 IMG->colors, so that it can be freed again. Value is the pixel
7489 static unsigned long
7490 x_alloc_image_color (f
, img
, color_name
, dflt
)
7493 Lisp_Object color_name
;
7496 #if 0 /* NTEMACS_TODO: allocing colors. */
7498 unsigned long result
;
7500 xassert (STRINGP (color_name
));
7502 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
7504 /* This isn't called frequently so we get away with simply
7505 reallocating the color vector to the needed size, here. */
7508 (unsigned long *) xrealloc (img
->colors
,
7509 img
->ncolors
* sizeof *img
->colors
);
7510 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
7511 result
= color
.pixel
;
7522 /***********************************************************************
7524 ***********************************************************************/
7526 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
7529 /* Return a new, initialized image cache that is allocated from the
7530 heap. Call free_image_cache to free an image cache. */
7532 struct image_cache
*
7535 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
7538 bzero (c
, sizeof *c
);
7540 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
7541 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
7542 c
->buckets
= (struct image
**) xmalloc (size
);
7543 bzero (c
->buckets
, size
);
7548 /* Free image cache of frame F. Be aware that X frames share images
7552 free_image_cache (f
)
7555 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7560 /* Cache should not be referenced by any frame when freed. */
7561 xassert (c
->refcount
== 0);
7563 for (i
= 0; i
< c
->used
; ++i
)
7564 free_image (f
, c
->images
[i
]);
7568 FRAME_X_IMAGE_CACHE (f
) = NULL
;
7573 /* Clear image cache of frame F. FORCE_P non-zero means free all
7574 images. FORCE_P zero means clear only images that haven't been
7575 displayed for some time. Should be called from time to time to
7576 reduce the number of loaded images. If image-cache-eveiction-delay
7577 is non-nil, this frees images in the cache which weren't displayed for
7578 at least that many seconds. */
7581 clear_image_cache (f
, force_p
)
7585 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7587 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
7591 int i
, any_freed_p
= 0;
7594 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
7596 for (i
= 0; i
< c
->used
; ++i
)
7598 struct image
*img
= c
->images
[i
];
7601 || (img
->timestamp
> old
)))
7603 free_image (f
, img
);
7608 /* We may be clearing the image cache because, for example,
7609 Emacs was iconified for a longer period of time. In that
7610 case, current matrices may still contain references to
7611 images freed above. So, clear these matrices. */
7614 clear_current_matrices (f
);
7615 ++windows_or_buffers_changed
;
7621 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
7623 "Clear the image cache of FRAME.\n\
7624 FRAME nil or omitted means use the selected frame.\n\
7625 FRAME t means clear the image caches of all frames.")
7633 FOR_EACH_FRAME (tail
, frame
)
7634 if (FRAME_W32_P (XFRAME (frame
)))
7635 clear_image_cache (XFRAME (frame
), 1);
7638 clear_image_cache (check_x_frame (frame
), 1);
7644 /* Return the id of image with Lisp specification SPEC on frame F.
7645 SPEC must be a valid Lisp image specification (see valid_image_p). */
7648 lookup_image (f
, spec
)
7652 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7656 struct gcpro gcpro1
;
7659 /* F must be a window-system frame, and SPEC must be a valid image
7661 xassert (FRAME_WINDOW_P (f
));
7662 xassert (valid_image_p (spec
));
7666 /* Look up SPEC in the hash table of the image cache. */
7667 hash
= sxhash (spec
, 0);
7668 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
7670 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
7671 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
7674 /* If not found, create a new image and cache it. */
7677 img
= make_image (spec
, hash
);
7678 cache_image (f
, img
);
7679 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
7680 xassert (!interrupt_input_blocked
);
7682 /* If we can't load the image, and we don't have a width and
7683 height, use some arbitrary width and height so that we can
7684 draw a rectangle for it. */
7685 if (img
->load_failed_p
)
7689 value
= image_spec_value (spec
, QCwidth
, NULL
);
7690 img
->width
= (INTEGERP (value
)
7691 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
7692 value
= image_spec_value (spec
, QCheight
, NULL
);
7693 img
->height
= (INTEGERP (value
)
7694 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
7698 /* Handle image type independent image attributes
7699 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF'. */
7700 Lisp_Object ascent
, margin
, relief
, algorithm
, heuristic_mask
;
7703 ascent
= image_spec_value (spec
, QCascent
, NULL
);
7704 if (INTEGERP (ascent
))
7705 img
->ascent
= XFASTINT (ascent
);
7707 margin
= image_spec_value (spec
, QCmargin
, NULL
);
7708 if (INTEGERP (margin
) && XINT (margin
) >= 0)
7709 img
->margin
= XFASTINT (margin
);
7711 relief
= image_spec_value (spec
, QCrelief
, NULL
);
7712 if (INTEGERP (relief
))
7714 img
->relief
= XINT (relief
);
7715 img
->margin
+= abs (img
->relief
);
7718 /* Should we apply a Laplace edge-detection algorithm? */
7719 algorithm
= image_spec_value (spec
, QCalgorithm
, NULL
);
7720 if (img
->pixmap
&& EQ (algorithm
, Qlaplace
))
7723 /* Should we built a mask heuristically? */
7724 heuristic_mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
7725 if (img
->pixmap
&& !img
->mask
&& !NILP (heuristic_mask
))
7726 x_build_heuristic_mask (f
, img
, heuristic_mask
);
7730 /* We're using IMG, so set its timestamp to `now'. */
7731 EMACS_GET_TIME (now
);
7732 img
->timestamp
= EMACS_SECS (now
);
7736 /* Value is the image id. */
7741 /* Cache image IMG in the image cache of frame F. */
7744 cache_image (f
, img
)
7748 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7751 /* Find a free slot in c->images. */
7752 for (i
= 0; i
< c
->used
; ++i
)
7753 if (c
->images
[i
] == NULL
)
7756 /* If no free slot found, maybe enlarge c->images. */
7757 if (i
== c
->used
&& c
->used
== c
->size
)
7760 c
->images
= (struct image
**) xrealloc (c
->images
,
7761 c
->size
* sizeof *c
->images
);
7764 /* Add IMG to c->images, and assign IMG an id. */
7770 /* Add IMG to the cache's hash table. */
7771 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
7772 img
->next
= c
->buckets
[i
];
7774 img
->next
->prev
= img
;
7776 c
->buckets
[i
] = img
;
7780 /* Call FN on every image in the image cache of frame F. Used to mark
7781 Lisp Objects in the image cache. */
7784 forall_images_in_image_cache (f
, fn
)
7786 void (*fn
) P_ ((struct image
*img
));
7788 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
7790 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7794 for (i
= 0; i
< c
->used
; ++i
)
7803 /***********************************************************************
7805 ***********************************************************************/
7807 #if 0 /* NTEMACS_TODO: W32 specific image code. */
7809 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
7810 XImage
**, Pixmap
*));
7811 static void x_destroy_x_image
P_ ((XImage
*));
7812 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
7815 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
7816 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
7817 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
7818 via xmalloc. Print error messages via image_error if an error
7819 occurs. Value is non-zero if successful. */
7822 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
7824 int width
, height
, depth
;
7828 #if 0 /* NTEMACS_TODO: Image support for W32 */
7829 Display
*display
= FRAME_W32_DISPLAY (f
);
7830 Screen
*screen
= FRAME_X_SCREEN (f
);
7831 Window window
= FRAME_W32_WINDOW (f
);
7833 xassert (interrupt_input_blocked
);
7836 depth
= DefaultDepthOfScreen (screen
);
7837 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
7838 depth
, ZPixmap
, 0, NULL
, width
, height
,
7839 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
7842 image_error ("Unable to allocate X image", Qnil
, Qnil
);
7846 /* Allocate image raster. */
7847 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
7849 /* Allocate a pixmap of the same size. */
7850 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
7853 x_destroy_x_image (*ximg
);
7855 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
7863 /* Destroy XImage XIMG. Free XIMG->data. */
7866 x_destroy_x_image (ximg
)
7869 xassert (interrupt_input_blocked
);
7874 XDestroyImage (ximg
);
7879 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
7880 are width and height of both the image and pixmap. */
7883 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
7890 xassert (interrupt_input_blocked
);
7891 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
7892 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
7899 /***********************************************************************
7901 ***********************************************************************/
7903 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
7905 /* Find image file FILE. Look in data-directory, then
7906 x-bitmap-file-path. Value is the full name of the file found, or
7907 nil if not found. */
7910 x_find_image_file (file
)
7913 Lisp_Object file_found
, search_path
;
7914 struct gcpro gcpro1
, gcpro2
;
7918 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
7919 GCPRO2 (file_found
, search_path
);
7921 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
7922 fd
= openp (search_path
, file
, "", &file_found
, 0);
7935 /***********************************************************************
7937 ***********************************************************************/
7939 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
7940 static int xbm_load_image_from_file
P_ ((struct frame
*f
, struct image
*img
,
7942 static int xbm_image_p
P_ ((Lisp_Object object
));
7943 static int xbm_read_bitmap_file_data
P_ ((char *, int *, int *,
7947 /* Indices of image specification fields in xbm_format, below. */
7949 enum xbm_keyword_index
7966 /* Vector of image_keyword structures describing the format
7967 of valid XBM image specifications. */
7969 static struct image_keyword xbm_format
[XBM_LAST
] =
7971 {":type", IMAGE_SYMBOL_VALUE
, 1},
7972 {":file", IMAGE_STRING_VALUE
, 0},
7973 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
7974 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
7975 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7976 {":foreground", IMAGE_STRING_VALUE
, 0},
7977 {":background", IMAGE_STRING_VALUE
, 0},
7978 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
7979 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
7980 {":relief", IMAGE_INTEGER_VALUE
, 0},
7981 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7982 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
7985 /* Structure describing the image type XBM. */
7987 static struct image_type xbm_type
=
7996 /* Tokens returned from xbm_scan. */
8005 /* Return non-zero if OBJECT is a valid XBM-type image specification.
8006 A valid specification is a list starting with the symbol `image'
8007 The rest of the list is a property list which must contain an
8010 If the specification specifies a file to load, it must contain
8011 an entry `:file FILENAME' where FILENAME is a string.
8013 If the specification is for a bitmap loaded from memory it must
8014 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
8015 WIDTH and HEIGHT are integers > 0. DATA may be:
8017 1. a string large enough to hold the bitmap data, i.e. it must
8018 have a size >= (WIDTH + 7) / 8 * HEIGHT
8020 2. a bool-vector of size >= WIDTH * HEIGHT
8022 3. a vector of strings or bool-vectors, one for each line of the
8025 Both the file and data forms may contain the additional entries
8026 `:background COLOR' and `:foreground COLOR'. If not present,
8027 foreground and background of the frame on which the image is
8028 displayed, is used. */
8031 xbm_image_p (object
)
8034 struct image_keyword kw
[XBM_LAST
];
8036 bcopy (xbm_format
, kw
, sizeof kw
);
8037 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
8040 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
8042 if (kw
[XBM_FILE
].count
)
8044 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
8052 /* Entries for `:width', `:height' and `:data' must be present. */
8053 if (!kw
[XBM_WIDTH
].count
8054 || !kw
[XBM_HEIGHT
].count
8055 || !kw
[XBM_DATA
].count
)
8058 data
= kw
[XBM_DATA
].value
;
8059 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
8060 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
8062 /* Check type of data, and width and height against contents of
8068 /* Number of elements of the vector must be >= height. */
8069 if (XVECTOR (data
)->size
< height
)
8072 /* Each string or bool-vector in data must be large enough
8073 for one line of the image. */
8074 for (i
= 0; i
< height
; ++i
)
8076 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
8080 if (XSTRING (elt
)->size
8081 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
8084 else if (BOOL_VECTOR_P (elt
))
8086 if (XBOOL_VECTOR (elt
)->size
< width
)
8093 else if (STRINGP (data
))
8095 if (XSTRING (data
)->size
8096 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
8099 else if (BOOL_VECTOR_P (data
))
8101 if (XBOOL_VECTOR (data
)->size
< width
* height
)
8108 /* Baseline must be a value between 0 and 100 (a percentage). */
8109 if (kw
[XBM_ASCENT
].count
8110 && XFASTINT (kw
[XBM_ASCENT
].value
) > 100)
8117 /* Scan a bitmap file. FP is the stream to read from. Value is
8118 either an enumerator from enum xbm_token, or a character for a
8119 single-character token, or 0 at end of file. If scanning an
8120 identifier, store the lexeme of the identifier in SVAL. If
8121 scanning a number, store its value in *IVAL. */
8124 xbm_scan (fp
, sval
, ival
)
8131 /* Skip white space. */
8132 while ((c
= fgetc (fp
)) != EOF
&& isspace (c
))
8137 else if (isdigit (c
))
8139 int value
= 0, digit
;
8144 if (c
== 'x' || c
== 'X')
8146 while ((c
= fgetc (fp
)) != EOF
)
8150 else if (c
>= 'a' && c
<= 'f')
8151 digit
= c
- 'a' + 10;
8152 else if (c
>= 'A' && c
<= 'F')
8153 digit
= c
- 'A' + 10;
8156 value
= 16 * value
+ digit
;
8159 else if (isdigit (c
))
8162 while ((c
= fgetc (fp
)) != EOF
8164 value
= 8 * value
+ c
- '0';
8170 while ((c
= fgetc (fp
)) != EOF
8172 value
= 10 * value
+ c
- '0';
8180 else if (isalpha (c
) || c
== '_')
8183 while ((c
= fgetc (fp
)) != EOF
8184 && (isalnum (c
) || c
== '_'))
8196 /* Replacement for XReadBitmapFileData which isn't available under old
8197 X versions. FILE is the name of the bitmap file to read. Set
8198 *WIDTH and *HEIGHT to the width and height of the image. Return in
8199 *DATA the bitmap data allocated with xmalloc. Value is non-zero if
8203 xbm_read_bitmap_file_data (file
, width
, height
, data
)
8205 int *width
, *height
;
8206 unsigned char **data
;
8209 char buffer
[BUFSIZ
];
8212 int bytes_per_line
, i
, nbytes
;
8218 LA1 = xbm_scan (fp, buffer, &value)
8220 #define expect(TOKEN) \
8221 if (LA1 != (TOKEN)) \
8226 #define expect_ident(IDENT) \
8227 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
8232 fp
= fopen (file
, "r");
8236 *width
= *height
= -1;
8238 LA1
= xbm_scan (fp
, buffer
, &value
);
8240 /* Parse defines for width, height and hot-spots. */
8244 expect_ident ("define");
8245 expect (XBM_TK_IDENT
);
8247 if (LA1
== XBM_TK_NUMBER
);
8249 char *p
= strrchr (buffer
, '_');
8250 p
= p
? p
+ 1 : buffer
;
8251 if (strcmp (p
, "width") == 0)
8253 else if (strcmp (p
, "height") == 0)
8256 expect (XBM_TK_NUMBER
);
8259 if (*width
< 0 || *height
< 0)
8262 /* Parse bits. Must start with `static'. */
8263 expect_ident ("static");
8264 if (LA1
== XBM_TK_IDENT
)
8266 if (strcmp (buffer
, "unsigned") == 0)
8269 expect_ident ("char");
8271 else if (strcmp (buffer
, "short") == 0)
8275 if (*width
% 16 && *width
% 16 < 9)
8278 else if (strcmp (buffer
, "char") == 0)
8286 expect (XBM_TK_IDENT
);
8292 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
8293 nbytes
= bytes_per_line
* *height
;
8294 p
= *data
= (char *) xmalloc (nbytes
);
8299 for (i
= 0; i
< nbytes
; i
+= 2)
8302 expect (XBM_TK_NUMBER
);
8305 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
8308 if (LA1
== ',' || LA1
== '}')
8316 for (i
= 0; i
< nbytes
; ++i
)
8319 expect (XBM_TK_NUMBER
);
8323 if (LA1
== ',' || LA1
== '}')
8349 /* Load XBM image IMG which will be displayed on frame F from file
8350 SPECIFIED_FILE. Value is non-zero if successful. */
8353 xbm_load_image_from_file (f
, img
, specified_file
)
8356 Lisp_Object specified_file
;
8359 unsigned char *data
;
8362 struct gcpro gcpro1
;
8364 xassert (STRINGP (specified_file
));
8368 file
= x_find_image_file (specified_file
);
8369 if (!STRINGP (file
))
8371 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8376 rc
= xbm_read_bitmap_file_data (XSTRING (file
)->data
, &img
->width
,
8377 &img
->height
, &data
);
8380 int depth
= one_w32_display_info
.n_cbits
;
8381 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
8382 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
8385 xassert (img
->width
> 0 && img
->height
> 0);
8387 /* Get foreground and background colors, maybe allocate colors. */
8388 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
8390 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
8392 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
8394 background
= x_alloc_image_color (f
, img
, value
, background
);
8396 #if 0 /* NTEMACS_TODO : Port image display to W32 */
8399 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
8400 FRAME_W32_WINDOW (f
),
8402 img
->width
, img
->height
,
8403 foreground
, background
,
8407 if (img
->pixmap
== 0)
8409 x_clear_image (f
, img
);
8410 image_error ("Unable to create X pixmap for `%s'", file
, Qnil
);
8419 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
8426 /* Fill image IMG which is used on frame F with pixmap data. Value is
8427 non-zero if successful. */
8435 Lisp_Object file_name
;
8437 xassert (xbm_image_p (img
->spec
));
8439 /* If IMG->spec specifies a file name, create a non-file spec from it. */
8440 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
8441 if (STRINGP (file_name
))
8442 success_p
= xbm_load_image_from_file (f
, img
, file_name
);
8445 struct image_keyword fmt
[XBM_LAST
];
8448 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
8449 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
8453 /* Parse the list specification. */
8454 bcopy (xbm_format
, fmt
, sizeof fmt
);
8455 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
8458 /* Get specified width, and height. */
8459 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
8460 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
8461 xassert (img
->width
> 0 && img
->height
> 0);
8465 if (fmt
[XBM_ASCENT
].count
)
8466 img
->ascent
= XFASTINT (fmt
[XBM_ASCENT
].value
);
8468 /* Get foreground and background colors, maybe allocate colors. */
8469 if (fmt
[XBM_FOREGROUND
].count
)
8470 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
8472 if (fmt
[XBM_BACKGROUND
].count
)
8473 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
8476 /* Set bits to the bitmap image data. */
8477 data
= fmt
[XBM_DATA
].value
;
8482 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
8484 p
= bits
= (char *) alloca (nbytes
* img
->height
);
8485 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
8487 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
8489 bcopy (XSTRING (line
)->data
, p
, nbytes
);
8491 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
8494 else if (STRINGP (data
))
8495 bits
= XSTRING (data
)->data
;
8497 bits
= XBOOL_VECTOR (data
)->data
;
8499 #if 0 /* NTEMACS_TODO : W32 XPM code */
8500 /* Create the pixmap. */
8501 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
8503 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
8504 FRAME_W32_WINDOW (f
),
8506 img
->width
, img
->height
,
8507 foreground
, background
,
8509 #endif /* NTEMACS_TODO */
8515 image_error ("Unable to create pixmap for XBM image `%s'",
8517 x_clear_image (f
, img
);
8528 /***********************************************************************
8530 ***********************************************************************/
8534 static int xpm_image_p
P_ ((Lisp_Object object
));
8535 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
8536 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
8538 #include "X11/xpm.h"
8540 /* The symbol `xpm' identifying XPM-format images. */
8544 /* Indices of image specification fields in xpm_format, below. */
8546 enum xpm_keyword_index
8560 /* Vector of image_keyword structures describing the format
8561 of valid XPM image specifications. */
8563 static struct image_keyword xpm_format
[XPM_LAST
] =
8565 {":type", IMAGE_SYMBOL_VALUE
, 1},
8566 {":file", IMAGE_STRING_VALUE
, 0},
8567 {":data", IMAGE_STRING_VALUE
, 0},
8568 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
8569 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8570 {":relief", IMAGE_INTEGER_VALUE
, 0},
8571 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8572 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8573 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
8576 /* Structure describing the image type XBM. */
8578 static struct image_type xpm_type
=
8588 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
8589 for XPM images. Such a list must consist of conses whose car and
8593 xpm_valid_color_symbols_p (color_symbols
)
8594 Lisp_Object color_symbols
;
8596 while (CONSP (color_symbols
))
8598 Lisp_Object sym
= XCAR (color_symbols
);
8600 || !STRINGP (XCAR (sym
))
8601 || !STRINGP (XCDR (sym
)))
8603 color_symbols
= XCDR (color_symbols
);
8606 return NILP (color_symbols
);
8610 /* Value is non-zero if OBJECT is a valid XPM image specification. */
8613 xpm_image_p (object
)
8616 struct image_keyword fmt
[XPM_LAST
];
8617 bcopy (xpm_format
, fmt
, sizeof fmt
);
8618 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
8619 /* Either `:file' or `:data' must be present. */
8620 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
8621 /* Either no `:color-symbols' or it's a list of conses
8622 whose car and cdr are strings. */
8623 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
8624 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
8625 && (fmt
[XPM_ASCENT
].count
== 0
8626 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
8630 /* Load image IMG which will be displayed on frame F. Value is
8631 non-zero if successful. */
8639 XpmAttributes attrs
;
8640 Lisp_Object specified_file
, color_symbols
;
8642 /* Configure the XPM lib. Use the visual of frame F. Allocate
8643 close colors. Return colors allocated. */
8644 bzero (&attrs
, sizeof attrs
);
8645 attrs
.visual
= FRAME_W32_DISPLAY_INFO (f
)->visual
;
8646 attrs
.valuemask
|= XpmVisual
;
8647 attrs
.valuemask
|= XpmReturnAllocPixels
;
8648 attrs
.alloc_close_colors
= 1;
8649 attrs
.valuemask
|= XpmAllocCloseColors
;
8651 /* If image specification contains symbolic color definitions, add
8652 these to `attrs'. */
8653 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
8654 if (CONSP (color_symbols
))
8657 XpmColorSymbol
*xpm_syms
;
8660 attrs
.valuemask
|= XpmColorSymbols
;
8662 /* Count number of symbols. */
8663 attrs
.numsymbols
= 0;
8664 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
8667 /* Allocate an XpmColorSymbol array. */
8668 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
8669 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
8670 bzero (xpm_syms
, size
);
8671 attrs
.colorsymbols
= xpm_syms
;
8673 /* Fill the color symbol array. */
8674 for (tail
= color_symbols
, i
= 0;
8676 ++i
, tail
= XCDR (tail
))
8678 Lisp_Object name
= XCAR (XCAR (tail
));
8679 Lisp_Object color
= XCDR (XCAR (tail
));
8680 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
8681 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
8682 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
8683 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
8687 /* Create a pixmap for the image, either from a file, or from a
8688 string buffer containing data in the same format as an XPM file. */
8690 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
8691 if (STRINGP (specified_file
))
8693 Lisp_Object file
= x_find_image_file (specified_file
);
8694 if (!STRINGP (file
))
8696 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8701 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
8702 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
8707 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
8708 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
8709 XSTRING (buffer
)->data
,
8710 &img
->pixmap
, &img
->mask
,
8715 if (rc
== XpmSuccess
)
8717 /* Remember allocated colors. */
8718 img
->ncolors
= attrs
.nalloc_pixels
;
8719 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
8720 * sizeof *img
->colors
);
8721 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
8722 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
8724 img
->width
= attrs
.width
;
8725 img
->height
= attrs
.height
;
8726 xassert (img
->width
> 0 && img
->height
> 0);
8728 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
8730 XpmFreeAttributes (&attrs
);
8738 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
8741 case XpmFileInvalid
:
8742 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
8746 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
8749 case XpmColorFailed
:
8750 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
8754 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
8759 return rc
== XpmSuccess
;
8762 #endif /* HAVE_XPM != 0 */
8765 #if 0 /* NTEMACS_TODO : Color tables on W32. */
8766 /***********************************************************************
8768 ***********************************************************************/
8770 /* An entry in the color table mapping an RGB color to a pixel color. */
8775 unsigned long pixel
;
8777 /* Next in color table collision list. */
8778 struct ct_color
*next
;
8781 /* The bucket vector size to use. Must be prime. */
8785 /* Value is a hash of the RGB color given by R, G, and B. */
8787 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
8789 /* The color hash table. */
8791 struct ct_color
**ct_table
;
8793 /* Number of entries in the color table. */
8795 int ct_colors_allocated
;
8797 /* Function prototypes. */
8799 static void init_color_table
P_ ((void));
8800 static void free_color_table
P_ ((void));
8801 static unsigned long *colors_in_color_table
P_ ((int *n
));
8802 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
8803 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
8806 /* Initialize the color table. */
8811 int size
= CT_SIZE
* sizeof (*ct_table
);
8812 ct_table
= (struct ct_color
**) xmalloc (size
);
8813 bzero (ct_table
, size
);
8814 ct_colors_allocated
= 0;
8818 /* Free memory associated with the color table. */
8824 struct ct_color
*p
, *next
;
8826 for (i
= 0; i
< CT_SIZE
; ++i
)
8827 for (p
= ct_table
[i
]; p
; p
= next
)
8838 /* Value is a pixel color for RGB color R, G, B on frame F. If an
8839 entry for that color already is in the color table, return the
8840 pixel color of that entry. Otherwise, allocate a new color for R,
8841 G, B, and make an entry in the color table. */
8843 static unsigned long
8844 lookup_rgb_color (f
, r
, g
, b
)
8848 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
8849 int i
= hash
% CT_SIZE
;
8852 for (p
= ct_table
[i
]; p
; p
= p
->next
)
8853 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
8862 color
= PALETTERGB (r
, g
, b
);
8864 ++ct_colors_allocated
;
8866 p
= (struct ct_color
*) xmalloc (sizeof *p
);
8871 p
->next
= ct_table
[i
];
8879 /* Look up pixel color PIXEL which is used on frame F in the color
8880 table. If not already present, allocate it. Value is PIXEL. */
8882 static unsigned long
8883 lookup_pixel_color (f
, pixel
)
8885 unsigned long pixel
;
8887 int i
= pixel
% CT_SIZE
;
8890 for (p
= ct_table
[i
]; p
; p
= p
->next
)
8891 if (p
->pixel
== pixel
)
8902 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
8903 color
.pixel
= pixel
;
8904 XQueryColor (NULL
, cmap
, &color
);
8905 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
8910 ++ct_colors_allocated
;
8912 p
= (struct ct_color
*) xmalloc (sizeof *p
);
8917 p
->next
= ct_table
[i
];
8921 return FRAME_FOREGROUND_PIXEL (f
);
8927 /* Value is a vector of all pixel colors contained in the color table,
8928 allocated via xmalloc. Set *N to the number of colors. */
8930 static unsigned long *
8931 colors_in_color_table (n
)
8936 unsigned long *colors
;
8938 if (ct_colors_allocated
== 0)
8945 colors
= (unsigned long *) xmalloc (ct_colors_allocated
8947 *n
= ct_colors_allocated
;
8949 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
8950 for (p
= ct_table
[i
]; p
; p
= p
->next
)
8951 colors
[j
++] = p
->pixel
;
8957 #endif /* NTEMACS_TODO */
8960 /***********************************************************************
8962 ***********************************************************************/
8964 #if 0 /* NTEMACS_TODO : W32 versions of low level algorithms */
8965 static void x_laplace_write_row
P_ ((struct frame
*, long *,
8966 int, XImage
*, int));
8967 static void x_laplace_read_row
P_ ((struct frame
*, Colormap
,
8968 XColor
*, int, XImage
*, int));
8971 /* Fill COLORS with RGB colors from row Y of image XIMG. F is the
8972 frame we operate on, CMAP is the color-map in effect, and WIDTH is
8973 the width of one row in the image. */
8976 x_laplace_read_row (f
, cmap
, colors
, width
, ximg
, y
)
8986 for (x
= 0; x
< width
; ++x
)
8987 colors
[x
].pixel
= XGetPixel (ximg
, x
, y
);
8989 XQueryColors (NULL
, cmap
, colors
, width
);
8993 /* Write row Y of image XIMG. PIXELS is an array of WIDTH longs
8994 containing the pixel colors to write. F is the frame we are
8998 x_laplace_write_row (f
, pixels
, width
, ximg
, y
)
9007 for (x
= 0; x
< width
; ++x
)
9008 XPutPixel (ximg
, x
, y
, pixels
[x
]);
9012 /* Transform image IMG which is used on frame F with a Laplace
9013 edge-detection algorithm. The result is an image that can be used
9014 to draw disabled buttons, for example. */
9021 #if 0 /* NTEMACS_TODO : W32 version */
9022 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9023 XImage
*ximg
, *oimg
;
9029 int in_y
, out_y
, rc
;
9034 /* Get the X image IMG->pixmap. */
9035 ximg
= XGetImage (NULL
, img
->pixmap
,
9036 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
9038 /* Allocate 3 input rows, and one output row of colors. */
9039 for (i
= 0; i
< 3; ++i
)
9040 in
[i
] = (XColor
*) alloca (img
->width
* sizeof (XColor
));
9041 out
= (long *) alloca (img
->width
* sizeof (long));
9043 /* Create an X image for output. */
9044 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
9047 /* Fill first two rows. */
9048 x_laplace_read_row (f
, cmap
, in
[0], img
->width
, ximg
, 0);
9049 x_laplace_read_row (f
, cmap
, in
[1], img
->width
, ximg
, 1);
9052 /* Write first row, all zeros. */
9053 init_color_table ();
9054 pixel
= lookup_rgb_color (f
, 0, 0, 0);
9055 for (x
= 0; x
< img
->width
; ++x
)
9057 x_laplace_write_row (f
, out
, img
->width
, oimg
, 0);
9060 for (y
= 2; y
< img
->height
; ++y
)
9063 int rowb
= (y
+ 2) % 3;
9065 x_laplace_read_row (f
, cmap
, in
[rowa
], img
->width
, ximg
, in_y
++);
9067 for (x
= 0; x
< img
->width
- 2; ++x
)
9069 int r
= in
[rowa
][x
].red
+ mv2
- in
[rowb
][x
+ 2].red
;
9070 int g
= in
[rowa
][x
].green
+ mv2
- in
[rowb
][x
+ 2].green
;
9071 int b
= in
[rowa
][x
].blue
+ mv2
- in
[rowb
][x
+ 2].blue
;
9073 out
[x
+ 1] = lookup_rgb_color (f
, r
& 0xffff, g
& 0xffff,
9077 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
++);
9080 /* Write last line, all zeros. */
9081 for (x
= 0; x
< img
->width
; ++x
)
9083 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
);
9085 /* Free the input image, and free resources of IMG. */
9086 XDestroyImage (ximg
);
9087 x_clear_image (f
, img
);
9089 /* Put the output image into pixmap, and destroy it. */
9090 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
9091 x_destroy_x_image (oimg
);
9093 /* Remember new pixmap and colors in IMG. */
9094 img
->pixmap
= pixmap
;
9095 img
->colors
= colors_in_color_table (&img
->ncolors
);
9096 free_color_table ();
9099 #endif /* NTEMACS_TODO */
9103 /* Build a mask for image IMG which is used on frame F. FILE is the
9104 name of an image file, for error messages. HOW determines how to
9105 determine the background color of IMG. If it is a list '(R G B)',
9106 with R, G, and B being integers >= 0, take that as the color of the
9107 background. Otherwise, determine the background color of IMG
9108 heuristically. Value is non-zero if successful. */
9111 x_build_heuristic_mask (f
, img
, how
)
9116 #if 0 /* NTEMACS_TODO : W32 version */
9117 Display
*dpy
= FRAME_W32_DISPLAY (f
);
9118 XImage
*ximg
, *mask_img
;
9119 int x
, y
, rc
, look_at_corners_p
;
9124 /* Create an image and pixmap serving as mask. */
9125 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
9126 &mask_img
, &img
->mask
);
9133 /* Get the X image of IMG->pixmap. */
9134 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
9137 /* Determine the background color of ximg. If HOW is `(R G B)'
9138 take that as color. Otherwise, try to determine the color
9140 look_at_corners_p
= 1;
9148 && NATNUMP (XCAR (how
)))
9150 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
9154 if (i
== 3 && NILP (how
))
9156 char color_name
[30];
9157 XColor exact
, color
;
9160 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
9162 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9163 if (XLookupColor (dpy
, cmap
, color_name
, &exact
, &color
))
9166 look_at_corners_p
= 0;
9171 if (look_at_corners_p
)
9173 unsigned long corners
[4];
9176 /* Get the colors at the corners of ximg. */
9177 corners
[0] = XGetPixel (ximg
, 0, 0);
9178 corners
[1] = XGetPixel (ximg
, img
->width
- 1, 0);
9179 corners
[2] = XGetPixel (ximg
, img
->width
- 1, img
->height
- 1);
9180 corners
[3] = XGetPixel (ximg
, 0, img
->height
- 1);
9182 /* Choose the most frequently found color as background. */
9183 for (i
= best_count
= 0; i
< 4; ++i
)
9187 for (j
= n
= 0; j
< 4; ++j
)
9188 if (corners
[i
] == corners
[j
])
9192 bg
= corners
[i
], best_count
= n
;
9196 /* Set all bits in mask_img to 1 whose color in ximg is different
9197 from the background color bg. */
9198 for (y
= 0; y
< img
->height
; ++y
)
9199 for (x
= 0; x
< img
->width
; ++x
)
9200 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
9202 /* Put mask_img into img->mask. */
9203 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
9204 x_destroy_x_image (mask_img
);
9205 XDestroyImage (ximg
);
9208 #endif /* NTEMACS_TODO */
9215 /***********************************************************************
9216 PBM (mono, gray, color)
9217 ***********************************************************************/
9220 static int pbm_image_p
P_ ((Lisp_Object object
));
9221 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
9222 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
9224 /* The symbol `pbm' identifying images of this type. */
9228 /* Indices of image specification fields in gs_format, below. */
9230 enum pbm_keyword_index
9243 /* Vector of image_keyword structures describing the format
9244 of valid user-defined image specifications. */
9246 static struct image_keyword pbm_format
[PBM_LAST
] =
9248 {":type", IMAGE_SYMBOL_VALUE
, 1},
9249 {":file", IMAGE_STRING_VALUE
, 0},
9250 {":data", IMAGE_STRING_VALUE
, 0},
9251 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9252 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9253 {":relief", IMAGE_INTEGER_VALUE
, 0},
9254 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9255 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9258 /* Structure describing the image type `pbm'. */
9260 static struct image_type pbm_type
=
9270 /* Return non-zero if OBJECT is a valid PBM image specification. */
9273 pbm_image_p (object
)
9276 struct image_keyword fmt
[PBM_LAST
];
9278 bcopy (pbm_format
, fmt
, sizeof fmt
);
9280 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
9281 || (fmt
[PBM_ASCENT
].count
9282 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
9285 /* Must specify either :data or :file. */
9286 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
9290 /* Scan a decimal number from *S and return it. Advance *S while
9291 reading the number. END is the end of the string. Value is -1 at
9295 pbm_scan_number (s
, end
)
9296 unsigned char **s
, *end
;
9302 /* Skip white-space. */
9303 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
9308 /* Skip comment to end of line. */
9309 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
9312 else if (isdigit (c
))
9314 /* Read decimal number. */
9316 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
9317 val
= 10 * val
+ c
- '0';
9328 /* Read FILE into memory. Value is a pointer to a buffer allocated
9329 with xmalloc holding FILE's contents. Value is null if an error
9330 occured. *SIZE is set to the size of the file. */
9333 pbm_read_file (file
, size
)
9341 if (stat (XSTRING (file
)->data
, &st
) == 0
9342 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
9343 && (buf
= (char *) xmalloc (st
.st_size
),
9344 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
9364 /* Load PBM image IMG for use on frame F. */
9372 int width
, height
, max_color_idx
= 0;
9374 Lisp_Object file
, specified_file
;
9375 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
9376 struct gcpro gcpro1
;
9377 unsigned char *contents
= NULL
;
9378 unsigned char *end
, *p
;
9381 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9385 if (STRINGP (specified_file
))
9387 file
= x_find_image_file (specified_file
);
9388 if (!STRINGP (file
))
9390 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9395 contents
= pbm_read_file (file
, &size
);
9396 if (contents
== NULL
)
9398 image_error ("Error reading `%s'", file
, Qnil
);
9404 end
= contents
+ size
;
9409 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
9410 p
= XSTRING (data
)->data
;
9411 end
= p
+ STRING_BYTES (XSTRING (data
));
9414 /* Check magic number. */
9415 if (end
- p
< 2 || *p
++ != 'P')
9417 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
9427 image_error ("Not a PBM image file: %s", file
, Qnil
);
9435 raw_p
= 0, type
= PBM_MONO
;
9439 raw_p
= 0, type
= PBM_GRAY
;
9443 raw_p
= 0, type
= PBM_COLOR
;
9447 raw_p
= 1, type
= PBM_MONO
;
9451 raw_p
= 1, type
= PBM_GRAY
;
9455 raw_p
= 1, type
= PBM_COLOR
;
9459 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
9463 /* Read width, height, maximum color-component. Characters
9464 starting with `#' up to the end of a line are ignored. */
9465 width
= pbm_scan_number (&p
, end
);
9466 height
= pbm_scan_number (&p
, end
);
9468 if (type
!= PBM_MONO
)
9470 max_color_idx
= pbm_scan_number (&p
, end
);
9471 if (raw_p
&& max_color_idx
> 255)
9472 max_color_idx
= 255;
9477 || (type
!= PBM_MONO
&& max_color_idx
< 0))
9481 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
9482 &ximg
, &img
->pixmap
))
9488 /* Initialize the color hash table. */
9489 init_color_table ();
9491 if (type
== PBM_MONO
)
9495 for (y
= 0; y
< height
; ++y
)
9496 for (x
= 0; x
< width
; ++x
)
9506 g
= pbm_scan_number (&p
, end
);
9508 XPutPixel (ximg
, x
, y
, (g
9509 ? FRAME_FOREGROUND_PIXEL (f
)
9510 : FRAME_BACKGROUND_PIXEL (f
)));
9515 for (y
= 0; y
< height
; ++y
)
9516 for (x
= 0; x
< width
; ++x
)
9520 if (type
== PBM_GRAY
)
9521 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
9530 r
= pbm_scan_number (&p
, end
);
9531 g
= pbm_scan_number (&p
, end
);
9532 b
= pbm_scan_number (&p
, end
);
9535 if (r
< 0 || g
< 0 || b
< 0)
9537 b
xfree (ximg
->data
);
9539 XDestroyImage (ximg
);
9541 image_error ("Invalid pixel value in image `%s'",
9546 /* RGB values are now in the range 0..max_color_idx.
9547 Scale this to the range 0..0xffff supported by X. */
9548 r
= (double) r
* 65535 / max_color_idx
;
9549 g
= (double) g
* 65535 / max_color_idx
;
9550 b
= (double) b
* 65535 / max_color_idx
;
9551 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
9555 /* Store in IMG->colors the colors allocated for the image, and
9556 free the color table. */
9557 img
->colors
= colors_in_color_table (&img
->ncolors
);
9558 free_color_table ();
9560 /* Put the image into a pixmap. */
9561 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
9562 x_destroy_x_image (ximg
);
9566 img
->height
= height
;
9572 #endif /* HAVE_PBM */
9575 /***********************************************************************
9577 ***********************************************************************/
9583 /* Function prototypes. */
9585 static int png_image_p
P_ ((Lisp_Object object
));
9586 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
9588 /* The symbol `png' identifying images of this type. */
9592 /* Indices of image specification fields in png_format, below. */
9594 enum png_keyword_index
9607 /* Vector of image_keyword structures describing the format
9608 of valid user-defined image specifications. */
9610 static struct image_keyword png_format
[PNG_LAST
] =
9612 {":type", IMAGE_SYMBOL_VALUE
, 1},
9613 {":data", IMAGE_STRING_VALUE
, 0},
9614 {":file", IMAGE_STRING_VALUE
, 0},
9615 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9616 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9617 {":relief", IMAGE_INTEGER_VALUE
, 0},
9618 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9619 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9622 /* Structure describing the image type `png'. */
9624 static struct image_type png_type
=
9634 /* Return non-zero if OBJECT is a valid PNG image specification. */
9637 png_image_p (object
)
9640 struct image_keyword fmt
[PNG_LAST
];
9641 bcopy (png_format
, fmt
, sizeof fmt
);
9643 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
9644 || (fmt
[PNG_ASCENT
].count
9645 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
9648 /* Must specify either the :data or :file keyword. */
9649 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
9653 /* Error and warning handlers installed when the PNG library
9657 my_png_error (png_ptr
, msg
)
9658 png_struct
*png_ptr
;
9661 xassert (png_ptr
!= NULL
);
9662 image_error ("PNG error: %s", build_string (msg
), Qnil
);
9663 longjmp (png_ptr
->jmpbuf
, 1);
9668 my_png_warning (png_ptr
, msg
)
9669 png_struct
*png_ptr
;
9672 xassert (png_ptr
!= NULL
);
9673 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
9677 /* Memory source for PNG decoding. */
9679 struct png_memory_storage
9681 unsigned char *bytes
; /* The data */
9682 size_t len
; /* How big is it? */
9683 int index
; /* Where are we? */
9687 /* Function set as reader function when reading PNG image from memory.
9688 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
9689 bytes from the input to DATA. */
9692 png_read_from_memory (png_ptr
, data
, length
)
9693 png_structp png_ptr
;
9697 struct png_memory_storage
*tbr
9698 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
9700 if (length
> tbr
->len
- tbr
->index
)
9701 png_error (png_ptr
, "Read error");
9703 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
9704 tbr
->index
= tbr
->index
+ length
;
9708 /* Load PNG image IMG for use on frame F. Value is non-zero if
9716 Lisp_Object file
, specified_file
;
9717 Lisp_Object specified_data
;
9719 XImage
*ximg
, *mask_img
= NULL
;
9720 struct gcpro gcpro1
;
9721 png_struct
*png_ptr
= NULL
;
9722 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
9725 png_byte
*pixels
= NULL
;
9726 png_byte
**rows
= NULL
;
9727 png_uint_32 width
, height
;
9728 int bit_depth
, color_type
, interlace_type
;
9730 png_uint_32 row_bytes
;
9733 double screen_gamma
, image_gamma
;
9735 struct png_memory_storage tbr
; /* Data to be read */
9737 /* Find out what file to load. */
9738 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9739 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
9743 if (NILP (specified_data
))
9745 file
= x_find_image_file (specified_file
);
9746 if (!STRINGP (file
))
9748 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9753 /* Open the image file. */
9754 fp
= fopen (XSTRING (file
)->data
, "rb");
9757 image_error ("Cannot open image file `%s'", file
, Qnil
);
9763 /* Check PNG signature. */
9764 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
9765 || !png_check_sig (sig
, sizeof sig
))
9767 image_error ("Not a PNG file:` %s'", file
, Qnil
);
9775 /* Read from memory. */
9776 tbr
.bytes
= XSTRING (specified_data
)->data
;
9777 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
9780 /* Check PNG signature. */
9781 if (tbr
.len
< sizeof sig
9782 || !png_check_sig (tbr
.bytes
, sizeof sig
))
9784 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
9789 /* Need to skip past the signature. */
9790 tbr
.bytes
+= sizeof (sig
);
9794 /* Initialize read and info structs for PNG lib. */
9795 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
9796 my_png_error
, my_png_warning
);
9799 if (fp
) fclose (fp
);
9804 info_ptr
= png_create_info_struct (png_ptr
);
9807 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
9808 if (fp
) fclose (fp
);
9813 end_info
= png_create_info_struct (png_ptr
);
9816 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
9817 if (fp
) fclose (fp
);
9822 /* Set error jump-back. We come back here when the PNG library
9823 detects an error. */
9824 if (setjmp (png_ptr
->jmpbuf
))
9828 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
9831 if (fp
) fclose (fp
);
9836 /* Read image info. */
9837 if (!NILP (specified_data
))
9838 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
9840 png_init_io (png_ptr
, fp
);
9842 png_set_sig_bytes (png_ptr
, sizeof sig
);
9843 png_read_info (png_ptr
, info_ptr
);
9844 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
9845 &interlace_type
, NULL
, NULL
);
9847 /* If image contains simply transparency data, we prefer to
9848 construct a clipping mask. */
9849 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
9854 /* This function is easier to write if we only have to handle
9855 one data format: RGB or RGBA with 8 bits per channel. Let's
9856 transform other formats into that format. */
9858 /* Strip more than 8 bits per channel. */
9859 if (bit_depth
== 16)
9860 png_set_strip_16 (png_ptr
);
9862 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
9864 png_set_expand (png_ptr
);
9866 /* Convert grayscale images to RGB. */
9867 if (color_type
== PNG_COLOR_TYPE_GRAY
9868 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
9869 png_set_gray_to_rgb (png_ptr
);
9871 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
9872 gamma_str
= getenv ("SCREEN_GAMMA");
9873 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
9875 /* Tell the PNG lib to handle gamma correction for us. */
9877 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
9878 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
9879 /* There is a special chunk in the image specifying the gamma. */
9880 png_set_sRGB (png_ptr
, info_ptr
, intent
);
9883 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
9884 /* Image contains gamma information. */
9885 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
9887 /* Use a default of 0.5 for the image gamma. */
9888 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
9890 /* Handle alpha channel by combining the image with a background
9891 color. Do this only if a real alpha channel is supplied. For
9892 simple transparency, we prefer a clipping mask. */
9895 png_color_16
*image_background
;
9897 if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
9898 /* Image contains a background color with which to
9899 combine the image. */
9900 png_set_background (png_ptr
, image_background
,
9901 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
9904 /* Image does not contain a background color with which
9905 to combine the image data via an alpha channel. Use
9906 the frame's background instead. */
9909 png_color_16 frame_background
;
9912 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9913 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
9914 XQueryColor (FRAME_W32_DISPLAY (f
), cmap
, &color
);
9917 bzero (&frame_background
, sizeof frame_background
);
9918 frame_background
.red
= color
.red
;
9919 frame_background
.green
= color
.green
;
9920 frame_background
.blue
= color
.blue
;
9922 png_set_background (png_ptr
, &frame_background
,
9923 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
9927 /* Update info structure. */
9928 png_read_update_info (png_ptr
, info_ptr
);
9930 /* Get number of channels. Valid values are 1 for grayscale images
9931 and images with a palette, 2 for grayscale images with transparency
9932 information (alpha channel), 3 for RGB images, and 4 for RGB
9933 images with alpha channel, i.e. RGBA. If conversions above were
9934 sufficient we should only have 3 or 4 channels here. */
9935 channels
= png_get_channels (png_ptr
, info_ptr
);
9936 xassert (channels
== 3 || channels
== 4);
9938 /* Number of bytes needed for one row of the image. */
9939 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
9941 /* Allocate memory for the image. */
9942 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
9943 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
9944 for (i
= 0; i
< height
; ++i
)
9945 rows
[i
] = pixels
+ i
* row_bytes
;
9947 /* Read the entire image. */
9948 png_read_image (png_ptr
, rows
);
9949 png_read_end (png_ptr
, info_ptr
);
9958 /* Create the X image and pixmap. */
9959 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
9966 /* Create an image and pixmap serving as mask if the PNG image
9967 contains an alpha channel. */
9970 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
9971 &mask_img
, &img
->mask
))
9973 x_destroy_x_image (ximg
);
9974 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
9980 /* Fill the X image and mask from PNG data. */
9981 init_color_table ();
9983 for (y
= 0; y
< height
; ++y
)
9985 png_byte
*p
= rows
[y
];
9987 for (x
= 0; x
< width
; ++x
)
9994 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
9996 /* An alpha channel, aka mask channel, associates variable
9997 transparency with an image. Where other image formats
9998 support binary transparency---fully transparent or fully
9999 opaque---PNG allows up to 254 levels of partial transparency.
10000 The PNG library implements partial transparency by combining
10001 the image with a specified background color.
10003 I'm not sure how to handle this here nicely: because the
10004 background on which the image is displayed may change, for
10005 real alpha channel support, it would be necessary to create
10006 a new image for each possible background.
10008 What I'm doing now is that a mask is created if we have
10009 boolean transparency information. Otherwise I'm using
10010 the frame's background color to combine the image with. */
10015 XPutPixel (mask_img
, x
, y
, *p
> 0);
10021 /* Remember colors allocated for this image. */
10022 img
->colors
= colors_in_color_table (&img
->ncolors
);
10023 free_color_table ();
10026 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10030 img
->width
= width
;
10031 img
->height
= height
;
10033 /* Put the image into the pixmap, then free the X image and its buffer. */
10034 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10035 x_destroy_x_image (ximg
);
10037 /* Same for the mask. */
10040 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10041 x_destroy_x_image (mask_img
);
10049 #endif /* HAVE_PNG != 0 */
10053 /***********************************************************************
10055 ***********************************************************************/
10059 /* Work around a warning about HAVE_STDLIB_H being redefined in
10061 #ifdef HAVE_STDLIB_H
10062 #define HAVE_STDLIB_H_1
10063 #undef HAVE_STDLIB_H
10064 #endif /* HAVE_STLIB_H */
10066 #include <jpeglib.h>
10067 #include <jerror.h>
10068 #include <setjmp.h>
10070 #ifdef HAVE_STLIB_H_1
10071 #define HAVE_STDLIB_H 1
10074 static int jpeg_image_p
P_ ((Lisp_Object object
));
10075 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
10077 /* The symbol `jpeg' identifying images of this type. */
10081 /* Indices of image specification fields in gs_format, below. */
10083 enum jpeg_keyword_index
10092 JPEG_HEURISTIC_MASK
,
10096 /* Vector of image_keyword structures describing the format
10097 of valid user-defined image specifications. */
10099 static struct image_keyword jpeg_format
[JPEG_LAST
] =
10101 {":type", IMAGE_SYMBOL_VALUE
, 1},
10102 {":data", IMAGE_STRING_VALUE
, 0},
10103 {":file", IMAGE_STRING_VALUE
, 0},
10104 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10105 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10106 {":relief", IMAGE_INTEGER_VALUE
, 0},
10107 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10108 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10111 /* Structure describing the image type `jpeg'. */
10113 static struct image_type jpeg_type
=
10123 /* Return non-zero if OBJECT is a valid JPEG image specification. */
10126 jpeg_image_p (object
)
10127 Lisp_Object object
;
10129 struct image_keyword fmt
[JPEG_LAST
];
10131 bcopy (jpeg_format
, fmt
, sizeof fmt
);
10133 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
10134 || (fmt
[JPEG_ASCENT
].count
10135 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
10138 /* Must specify either the :data or :file keyword. */
10139 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
10143 struct my_jpeg_error_mgr
10145 struct jpeg_error_mgr pub
;
10146 jmp_buf setjmp_buffer
;
10150 my_error_exit (cinfo
)
10151 j_common_ptr cinfo
;
10153 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
10154 longjmp (mgr
->setjmp_buffer
, 1);
10158 /* Init source method for JPEG data source manager. Called by
10159 jpeg_read_header() before any data is actually read. See
10160 libjpeg.doc from the JPEG lib distribution. */
10163 our_init_source (cinfo
)
10164 j_decompress_ptr cinfo
;
10169 /* Fill input buffer method for JPEG data source manager. Called
10170 whenever more data is needed. We read the whole image in one step,
10171 so this only adds a fake end of input marker at the end. */
10174 our_fill_input_buffer (cinfo
)
10175 j_decompress_ptr cinfo
;
10177 /* Insert a fake EOI marker. */
10178 struct jpeg_source_mgr
*src
= cinfo
->src
;
10179 static JOCTET buffer
[2];
10181 buffer
[0] = (JOCTET
) 0xFF;
10182 buffer
[1] = (JOCTET
) JPEG_EOI
;
10184 src
->next_input_byte
= buffer
;
10185 src
->bytes_in_buffer
= 2;
10190 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
10191 is the JPEG data source manager. */
10194 our_skip_input_data (cinfo
, num_bytes
)
10195 j_decompress_ptr cinfo
;
10198 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10202 if (num_bytes
> src
->bytes_in_buffer
)
10203 ERREXIT (cinfo
, JERR_INPUT_EOF
);
10205 src
->bytes_in_buffer
-= num_bytes
;
10206 src
->next_input_byte
+= num_bytes
;
10211 /* Method to terminate data source. Called by
10212 jpeg_finish_decompress() after all data has been processed. */
10215 our_term_source (cinfo
)
10216 j_decompress_ptr cinfo
;
10221 /* Set up the JPEG lib for reading an image from DATA which contains
10222 LEN bytes. CINFO is the decompression info structure created for
10223 reading the image. */
10226 jpeg_memory_src (cinfo
, data
, len
)
10227 j_decompress_ptr cinfo
;
10231 struct jpeg_source_mgr
*src
;
10233 if (cinfo
->src
== NULL
)
10235 /* First time for this JPEG object? */
10236 cinfo
->src
= (struct jpeg_source_mgr
*)
10237 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
10238 sizeof (struct jpeg_source_mgr
));
10239 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10240 src
->next_input_byte
= data
;
10243 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10244 src
->init_source
= our_init_source
;
10245 src
->fill_input_buffer
= our_fill_input_buffer
;
10246 src
->skip_input_data
= our_skip_input_data
;
10247 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
10248 src
->term_source
= our_term_source
;
10249 src
->bytes_in_buffer
= len
;
10250 src
->next_input_byte
= data
;
10254 /* Load image IMG for use on frame F. Patterned after example.c
10255 from the JPEG lib. */
10262 struct jpeg_decompress_struct cinfo
;
10263 struct my_jpeg_error_mgr mgr
;
10264 Lisp_Object file
, specified_file
;
10265 Lisp_Object specified_data
;
10268 int row_stride
, x
, y
;
10269 XImage
*ximg
= NULL
;
10271 unsigned long *colors
;
10273 struct gcpro gcpro1
;
10275 /* Open the JPEG file. */
10276 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10277 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10282 if (NILP (specified_data
))
10284 file
= x_find_image_file (specified_file
);
10285 if (!STRINGP (file
))
10287 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10292 fp
= fopen (XSTRING (file
)->data
, "r");
10295 image_error ("Cannot open `%s'", file
, Qnil
);
10301 /* Customize libjpeg's error handling to call my_error_exit when an
10302 error is detected. This function will perform a longjmp. */
10303 mgr
.pub
.error_exit
= my_error_exit
;
10304 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
10306 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
10310 /* Called from my_error_exit. Display a JPEG error. */
10311 char buffer
[JMSG_LENGTH_MAX
];
10312 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
10313 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
10314 build_string (buffer
));
10317 /* Close the input file and destroy the JPEG object. */
10320 jpeg_destroy_decompress (&cinfo
);
10324 /* If we already have an XImage, free that. */
10325 x_destroy_x_image (ximg
);
10327 /* Free pixmap and colors. */
10328 x_clear_image (f
, img
);
10335 /* Create the JPEG decompression object. Let it read from fp.
10336 Read the JPEG image header. */
10337 jpeg_create_decompress (&cinfo
);
10339 if (NILP (specified_data
))
10340 jpeg_stdio_src (&cinfo
, fp
);
10342 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
10343 STRING_BYTES (XSTRING (specified_data
)));
10345 jpeg_read_header (&cinfo
, TRUE
);
10347 /* Customize decompression so that color quantization will be used.
10348 Start decompression. */
10349 cinfo
.quantize_colors
= TRUE
;
10350 jpeg_start_decompress (&cinfo
);
10351 width
= img
->width
= cinfo
.output_width
;
10352 height
= img
->height
= cinfo
.output_height
;
10356 /* Create X image and pixmap. */
10357 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10361 longjmp (mgr
.setjmp_buffer
, 2);
10364 /* Allocate colors. When color quantization is used,
10365 cinfo.actual_number_of_colors has been set with the number of
10366 colors generated, and cinfo.colormap is a two-dimensional array
10367 of color indices in the range 0..cinfo.actual_number_of_colors.
10368 No more than 255 colors will be generated. */
10372 if (cinfo
.out_color_components
> 2)
10373 ir
= 0, ig
= 1, ib
= 2;
10374 else if (cinfo
.out_color_components
> 1)
10375 ir
= 0, ig
= 1, ib
= 0;
10377 ir
= 0, ig
= 0, ib
= 0;
10379 /* Use the color table mechanism because it handles colors that
10380 cannot be allocated nicely. Such colors will be replaced with
10381 a default color, and we don't have to care about which colors
10382 can be freed safely, and which can't. */
10383 init_color_table ();
10384 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
10387 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
10389 /* Multiply RGB values with 255 because X expects RGB values
10390 in the range 0..0xffff. */
10391 int r
= cinfo
.colormap
[ir
][i
] << 8;
10392 int g
= cinfo
.colormap
[ig
][i
] << 8;
10393 int b
= cinfo
.colormap
[ib
][i
] << 8;
10394 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
10397 /* Remember those colors actually allocated. */
10398 img
->colors
= colors_in_color_table (&img
->ncolors
);
10399 free_color_table ();
10403 row_stride
= width
* cinfo
.output_components
;
10404 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
10406 for (y
= 0; y
< height
; ++y
)
10408 jpeg_read_scanlines (&cinfo
, buffer
, 1);
10409 for (x
= 0; x
< cinfo
.output_width
; ++x
)
10410 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
10414 jpeg_finish_decompress (&cinfo
);
10415 jpeg_destroy_decompress (&cinfo
);
10419 /* Put the image into the pixmap. */
10420 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10421 x_destroy_x_image (ximg
);
10427 #endif /* HAVE_JPEG */
10431 /***********************************************************************
10433 ***********************************************************************/
10437 #include <tiffio.h>
10439 static int tiff_image_p
P_ ((Lisp_Object object
));
10440 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
10442 /* The symbol `tiff' identifying images of this type. */
10446 /* Indices of image specification fields in tiff_format, below. */
10448 enum tiff_keyword_index
10457 TIFF_HEURISTIC_MASK
,
10461 /* Vector of image_keyword structures describing the format
10462 of valid user-defined image specifications. */
10464 static struct image_keyword tiff_format
[TIFF_LAST
] =
10466 {":type", IMAGE_SYMBOL_VALUE
, 1},
10467 {":data", IMAGE_STRING_VALUE
, 0},
10468 {":file", IMAGE_STRING_VALUE
, 0},
10469 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10470 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10471 {":relief", IMAGE_INTEGER_VALUE
, 0},
10472 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10473 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10476 /* Structure describing the image type `tiff'. */
10478 static struct image_type tiff_type
=
10488 /* Return non-zero if OBJECT is a valid TIFF image specification. */
10491 tiff_image_p (object
)
10492 Lisp_Object object
;
10494 struct image_keyword fmt
[TIFF_LAST
];
10495 bcopy (tiff_format
, fmt
, sizeof fmt
);
10497 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
10498 || (fmt
[TIFF_ASCENT
].count
10499 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
10502 /* Must specify either the :data or :file keyword. */
10503 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
10507 /* Reading from a memory buffer for TIFF images Based on the PNG
10508 memory source, but we have to provide a lot of extra functions.
10511 We really only need to implement read and seek, but I am not
10512 convinced that the TIFF library is smart enough not to destroy
10513 itself if we only hand it the function pointers we need to
10518 unsigned char *bytes
;
10522 tiff_memory_source
;
10525 tiff_read_from_memory (data
, buf
, size
)
10530 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
10532 if (size
> src
->len
- src
->index
)
10533 return (size_t) -1;
10534 bcopy (src
->bytes
+ src
->index
, buf
, size
);
10535 src
->index
+= size
;
10540 tiff_write_from_memory (data
, buf
, size
)
10545 return (size_t) -1;
10549 tiff_seek_in_memory (data
, off
, whence
)
10554 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
10559 case SEEK_SET
: /* Go from beginning of source. */
10563 case SEEK_END
: /* Go from end of source. */
10564 idx
= src
->len
+ off
;
10567 case SEEK_CUR
: /* Go from current position. */
10568 idx
= src
->index
+ off
;
10571 default: /* Invalid `whence'. */
10575 if (idx
> src
->len
|| idx
< 0)
10583 tiff_close_memory (data
)
10591 tiff_mmap_memory (data
, pbase
, psize
)
10596 /* It is already _IN_ memory. */
10601 tiff_unmap_memory (data
, base
, size
)
10606 /* We don't need to do this. */
10610 tiff_size_of_memory (data
)
10613 return ((tiff_memory_source
*) data
)->len
;
10617 /* Load TIFF image IMG for use on frame F. Value is non-zero if
10625 Lisp_Object file
, specified_file
;
10626 Lisp_Object specified_data
;
10628 int width
, height
, x
, y
;
10632 struct gcpro gcpro1
;
10633 tiff_memory_source memsrc
;
10635 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10636 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10640 if (NILP (specified_data
))
10642 /* Read from a file */
10643 file
= x_find_image_file (specified_file
);
10644 if (!STRINGP (file
))
10646 image_error ("Cannot find image file `%s'", file
, Qnil
);
10651 /* Try to open the image file. */
10652 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
10655 image_error ("Cannot open `%s'", file
, Qnil
);
10662 /* Memory source! */
10663 memsrc
.bytes
= XSTRING (specified_data
)->data
;
10664 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
10667 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
10668 (TIFFReadWriteProc
) tiff_read_from_memory
,
10669 (TIFFReadWriteProc
) tiff_write_from_memory
,
10670 tiff_seek_in_memory
,
10672 tiff_size_of_memory
,
10674 tiff_unmap_memory
);
10678 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
10684 /* Get width and height of the image, and allocate a raster buffer
10685 of width x height 32-bit values. */
10686 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
10687 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
10688 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
10690 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
10694 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
10702 /* Create the X image and pixmap. */
10703 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
10711 /* Initialize the color table. */
10712 init_color_table ();
10714 /* Process the pixel raster. Origin is in the lower-left corner. */
10715 for (y
= 0; y
< height
; ++y
)
10717 uint32
*row
= buf
+ y
* width
;
10719 for (x
= 0; x
< width
; ++x
)
10721 uint32 abgr
= row
[x
];
10722 int r
= TIFFGetR (abgr
) << 8;
10723 int g
= TIFFGetG (abgr
) << 8;
10724 int b
= TIFFGetB (abgr
) << 8;
10725 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
10729 /* Remember the colors allocated for the image. Free the color table. */
10730 img
->colors
= colors_in_color_table (&img
->ncolors
);
10731 free_color_table ();
10733 /* Put the image into the pixmap, then free the X image and its buffer. */
10734 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10735 x_destroy_x_image (ximg
);
10739 img
->width
= width
;
10740 img
->height
= height
;
10746 #endif /* HAVE_TIFF != 0 */
10750 /***********************************************************************
10752 ***********************************************************************/
10756 #include <gif_lib.h>
10758 static int gif_image_p
P_ ((Lisp_Object object
));
10759 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
10761 /* The symbol `gif' identifying images of this type. */
10765 /* Indices of image specification fields in gif_format, below. */
10767 enum gif_keyword_index
10776 GIF_HEURISTIC_MASK
,
10781 /* Vector of image_keyword structures describing the format
10782 of valid user-defined image specifications. */
10784 static struct image_keyword gif_format
[GIF_LAST
] =
10786 {":type", IMAGE_SYMBOL_VALUE
, 1},
10787 {":data", IMAGE_STRING_VALUE
, 0},
10788 {":file", IMAGE_STRING_VALUE
, 0},
10789 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10790 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10791 {":relief", IMAGE_INTEGER_VALUE
, 0},
10792 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10793 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10794 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0}
10797 /* Structure describing the image type `gif'. */
10799 static struct image_type gif_type
=
10808 /* Return non-zero if OBJECT is a valid GIF image specification. */
10811 gif_image_p (object
)
10812 Lisp_Object object
;
10814 struct image_keyword fmt
[GIF_LAST
];
10815 bcopy (gif_format
, fmt
, sizeof fmt
);
10817 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
10818 || (fmt
[GIF_ASCENT
].count
10819 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
10822 /* Must specify either the :data or :file keyword. */
10823 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
10826 /* Reading a GIF image from memory
10827 Based on the PNG memory stuff to a certain extent. */
10831 unsigned char *bytes
;
10837 /* Make the current memory source available to gif_read_from_memory.
10838 It's done this way because not all versions of libungif support
10839 a UserData field in the GifFileType structure. */
10840 static gif_memory_source
*current_gif_memory_src
;
10843 gif_read_from_memory (file
, buf
, len
)
10848 gif_memory_source
*src
= current_gif_memory_src
;
10850 if (len
> src
->len
- src
->index
)
10853 bcopy (src
->bytes
+ src
->index
, buf
, len
);
10859 /* Load GIF image IMG for use on frame F. Value is non-zero if
10867 Lisp_Object file
, specified_file
;
10868 Lisp_Object specified_data
;
10869 int rc
, width
, height
, x
, y
, i
;
10871 ColorMapObject
*gif_color_map
;
10872 unsigned long pixel_colors
[256];
10874 struct gcpro gcpro1
;
10876 int ino
, image_left
, image_top
, image_width
, image_height
;
10877 gif_memory_source memsrc
;
10878 unsigned char *raster
;
10880 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10881 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10884 if (NILP (specified_data
))
10886 file
= x_find_image_file (specified_file
);
10888 if (!STRINGP (file
))
10890 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10895 /* Open the GIF file. */
10896 gif
= DGifOpenFileName (XSTRING (file
)->data
);
10899 image_error ("Cannot open `%s'", file
, Qnil
);
10906 /* Read from memory! */
10907 current_gif_memory_src
= &memsrc
;
10908 memsrc
.bytes
= XSTRING (specified_data
)->data
;
10909 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
10912 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
10915 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
10921 /* Read entire contents. */
10922 rc
= DGifSlurp (gif
);
10923 if (rc
== GIF_ERROR
)
10925 image_error ("Error reading `%s'", img
->spec
, Qnil
);
10926 DGifCloseFile (gif
);
10931 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
10932 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
10933 if (ino
>= gif
->ImageCount
)
10935 image_error ("Invalid image number `%s' in image `%s'",
10937 DGifCloseFile (gif
);
10942 width
= img
->width
= gif
->SWidth
;
10943 height
= img
->height
= gif
->SHeight
;
10947 /* Create the X image and pixmap. */
10948 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
10951 DGifCloseFile (gif
);
10956 /* Allocate colors. */
10957 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
10958 if (!gif_color_map
)
10959 gif_color_map
= gif
->SColorMap
;
10960 init_color_table ();
10961 bzero (pixel_colors
, sizeof pixel_colors
);
10963 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
10965 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
10966 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
10967 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
10968 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
10971 img
->colors
= colors_in_color_table (&img
->ncolors
);
10972 free_color_table ();
10974 /* Clear the part of the screen image that are not covered by
10975 the image from the GIF file. Full animated GIF support
10976 requires more than can be done here (see the gif89 spec,
10977 disposal methods). Let's simply assume that the part
10978 not covered by a sub-image is in the frame's background color. */
10979 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
10980 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
10981 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
10982 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
10984 for (y
= 0; y
< image_top
; ++y
)
10985 for (x
= 0; x
< width
; ++x
)
10986 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
10988 for (y
= image_top
+ image_height
; y
< height
; ++y
)
10989 for (x
= 0; x
< width
; ++x
)
10990 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
10992 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
10994 for (x
= 0; x
< image_left
; ++x
)
10995 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
10996 for (x
= image_left
+ image_width
; x
< width
; ++x
)
10997 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11000 /* Read the GIF image into the X image. We use a local variable
11001 `raster' here because RasterBits below is a char *, and invites
11002 problems with bytes >= 0x80. */
11003 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
11005 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
11007 static int interlace_start
[] = {0, 4, 2, 1};
11008 static int interlace_increment
[] = {8, 8, 4, 2};
11010 int row
= interlace_start
[0];
11014 for (y
= 0; y
< image_height
; y
++)
11016 if (row
>= image_height
)
11018 row
= interlace_start
[++pass
];
11019 while (row
>= image_height
)
11020 row
= interlace_start
[++pass
];
11023 for (x
= 0; x
< image_width
; x
++)
11025 int i
= raster
[(y
* image_width
) + x
];
11026 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
11030 row
+= interlace_increment
[pass
];
11035 for (y
= 0; y
< image_height
; ++y
)
11036 for (x
= 0; x
< image_width
; ++x
)
11038 int i
= raster
[y
* image_width
+ x
];
11039 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
11043 DGifCloseFile (gif
);
11045 /* Put the image into the pixmap, then free the X image and its buffer. */
11046 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11047 x_destroy_x_image (ximg
);
11054 #endif /* HAVE_GIF != 0 */
11058 /***********************************************************************
11060 ***********************************************************************/
11062 #ifdef HAVE_GHOSTSCRIPT
11063 static int gs_image_p
P_ ((Lisp_Object object
));
11064 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
11065 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
11067 /* The symbol `postscript' identifying images of this type. */
11069 Lisp_Object Qpostscript
;
11071 /* Keyword symbols. */
11073 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
11075 /* Indices of image specification fields in gs_format, below. */
11077 enum gs_keyword_index
11093 /* Vector of image_keyword structures describing the format
11094 of valid user-defined image specifications. */
11096 static struct image_keyword gs_format
[GS_LAST
] =
11098 {":type", IMAGE_SYMBOL_VALUE
, 1},
11099 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11100 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11101 {":file", IMAGE_STRING_VALUE
, 1},
11102 {":loader", IMAGE_FUNCTION_VALUE
, 0},
11103 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
11104 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11105 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11106 {":relief", IMAGE_INTEGER_VALUE
, 0},
11107 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11108 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11111 /* Structure describing the image type `ghostscript'. */
11113 static struct image_type gs_type
=
11123 /* Free X resources of Ghostscript image IMG which is used on frame F. */
11126 gs_clear_image (f
, img
)
11130 /* IMG->data.ptr_val may contain a recorded colormap. */
11131 xfree (img
->data
.ptr_val
);
11132 x_clear_image (f
, img
);
11136 /* Return non-zero if OBJECT is a valid Ghostscript image
11140 gs_image_p (object
)
11141 Lisp_Object object
;
11143 struct image_keyword fmt
[GS_LAST
];
11147 bcopy (gs_format
, fmt
, sizeof fmt
);
11149 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
11150 || (fmt
[GS_ASCENT
].count
11151 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
11154 /* Bounding box must be a list or vector containing 4 integers. */
11155 tem
= fmt
[GS_BOUNDING_BOX
].value
;
11158 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
11159 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
11164 else if (VECTORP (tem
))
11166 if (XVECTOR (tem
)->size
!= 4)
11168 for (i
= 0; i
< 4; ++i
)
11169 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
11179 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
11188 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
11189 struct gcpro gcpro1
, gcpro2
;
11191 double in_width
, in_height
;
11192 Lisp_Object pixel_colors
= Qnil
;
11194 /* Compute pixel size of pixmap needed from the given size in the
11195 image specification. Sizes in the specification are in pt. 1 pt
11196 = 1/72 in, xdpi and ydpi are stored in the frame's X display
11198 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
11199 in_width
= XFASTINT (pt_width
) / 72.0;
11200 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
11201 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
11202 in_height
= XFASTINT (pt_height
) / 72.0;
11203 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
11205 /* Create the pixmap. */
11207 xassert (img
->pixmap
== 0);
11208 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11209 img
->width
, img
->height
,
11210 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
11215 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
11219 /* Call the loader to fill the pixmap. It returns a process object
11220 if successful. We do not record_unwind_protect here because
11221 other places in redisplay like calling window scroll functions
11222 don't either. Let the Lisp loader use `unwind-protect' instead. */
11223 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
11225 sprintf (buffer
, "%lu %lu",
11226 (unsigned long) FRAME_W32_WINDOW (f
),
11227 (unsigned long) img
->pixmap
);
11228 window_and_pixmap_id
= build_string (buffer
);
11230 sprintf (buffer
, "%lu %lu",
11231 FRAME_FOREGROUND_PIXEL (f
),
11232 FRAME_BACKGROUND_PIXEL (f
));
11233 pixel_colors
= build_string (buffer
);
11235 XSETFRAME (frame
, f
);
11236 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
11238 loader
= intern ("gs-load-image");
11240 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
11241 make_number (img
->width
),
11242 make_number (img
->height
),
11243 window_and_pixmap_id
,
11246 return PROCESSP (img
->data
.lisp_val
);
11250 /* Kill the Ghostscript process that was started to fill PIXMAP on
11251 frame F. Called from XTread_socket when receiving an event
11252 telling Emacs that Ghostscript has finished drawing. */
11255 x_kill_gs_process (pixmap
, f
)
11259 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
11263 /* Find the image containing PIXMAP. */
11264 for (i
= 0; i
< c
->used
; ++i
)
11265 if (c
->images
[i
]->pixmap
== pixmap
)
11268 /* Kill the GS process. We should have found PIXMAP in the image
11269 cache and its image should contain a process object. */
11270 xassert (i
< c
->used
);
11271 img
= c
->images
[i
];
11272 xassert (PROCESSP (img
->data
.lisp_val
));
11273 Fkill_process (img
->data
.lisp_val
, Qnil
);
11274 img
->data
.lisp_val
= Qnil
;
11276 /* On displays with a mutable colormap, figure out the colors
11277 allocated for the image by looking at the pixels of an XImage for
11279 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
11280 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
11286 /* Try to get an XImage for img->pixmep. */
11287 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
11288 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
11293 /* Initialize the color table. */
11294 init_color_table ();
11296 /* For each pixel of the image, look its color up in the
11297 color table. After having done so, the color table will
11298 contain an entry for each color used by the image. */
11299 for (y
= 0; y
< img
->height
; ++y
)
11300 for (x
= 0; x
< img
->width
; ++x
)
11302 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
11303 lookup_pixel_color (f
, pixel
);
11306 /* Record colors in the image. Free color table and XImage. */
11307 img
->colors
= colors_in_color_table (&img
->ncolors
);
11308 free_color_table ();
11309 XDestroyImage (ximg
);
11311 #if 0 /* This doesn't seem to be the case. If we free the colors
11312 here, we get a BadAccess later in x_clear_image when
11313 freeing the colors. */
11314 /* We have allocated colors once, but Ghostscript has also
11315 allocated colors on behalf of us. So, to get the
11316 reference counts right, free them once. */
11319 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
11320 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
,
11321 img
->colors
, img
->ncolors
, 0);
11326 image_error ("Cannot get X image of `%s'; colors will not be freed",
11333 #endif /* HAVE_GHOSTSCRIPT */
11336 /***********************************************************************
11338 ***********************************************************************/
11340 DEFUN ("x-change-window-property", Fx_change_window_property
,
11341 Sx_change_window_property
, 2, 3, 0,
11342 "Change window property PROP to VALUE on the X window of FRAME.\n\
11343 PROP and VALUE must be strings. FRAME nil or omitted means use the\n\
11344 selected frame. Value is VALUE.")
11345 (prop
, value
, frame
)
11346 Lisp_Object frame
, prop
, value
;
11348 #if 0 /* NTEMACS_TODO : port window properties to W32 */
11349 struct frame
*f
= check_x_frame (frame
);
11352 CHECK_STRING (prop
, 1);
11353 CHECK_STRING (value
, 2);
11356 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11357 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11358 prop_atom
, XA_STRING
, 8, PropModeReplace
,
11359 XSTRING (value
)->data
, XSTRING (value
)->size
);
11361 /* Make sure the property is set when we return. */
11362 XFlush (FRAME_W32_DISPLAY (f
));
11365 #endif /* NTEMACS_TODO */
11371 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
11372 Sx_delete_window_property
, 1, 2, 0,
11373 "Remove window property PROP from X window of FRAME.\n\
11374 FRAME nil or omitted means use the selected frame. Value is PROP.")
11376 Lisp_Object prop
, frame
;
11378 #if 0 /* NTEMACS_TODO : port window properties to W32 */
11380 struct frame
*f
= check_x_frame (frame
);
11383 CHECK_STRING (prop
, 1);
11385 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11386 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
11388 /* Make sure the property is removed when we return. */
11389 XFlush (FRAME_W32_DISPLAY (f
));
11391 #endif /* NTEMACS_TODO */
11397 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
11399 "Value is the value of window property PROP on FRAME.\n\
11400 If FRAME is nil or omitted, use the selected frame. Value is nil\n\
11401 if FRAME hasn't a property with name PROP or if PROP has no string\n\
11404 Lisp_Object prop
, frame
;
11406 #if 0 /* NTEMACS_TODO : port window properties to W32 */
11408 struct frame
*f
= check_x_frame (frame
);
11411 Lisp_Object prop_value
= Qnil
;
11412 char *tmp_data
= NULL
;
11415 unsigned long actual_size
, bytes_remaining
;
11417 CHECK_STRING (prop
, 1);
11419 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11420 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11421 prop_atom
, 0, 0, False
, XA_STRING
,
11422 &actual_type
, &actual_format
, &actual_size
,
11423 &bytes_remaining
, (unsigned char **) &tmp_data
);
11426 int size
= bytes_remaining
;
11431 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11432 prop_atom
, 0, bytes_remaining
,
11434 &actual_type
, &actual_format
,
11435 &actual_size
, &bytes_remaining
,
11436 (unsigned char **) &tmp_data
);
11438 prop_value
= make_string (tmp_data
, size
);
11447 #endif /* NTEMACS_TODO */
11453 /***********************************************************************
11455 ***********************************************************************/
11457 /* The implementation partly follows a patch from
11458 F.Pierresteguy@frcl.bull.fr dated 1994. */
11460 /* Setting inhibit_busy_cursor to 2 inhibits busy-cursor display until
11461 the next X event is read and we enter XTread_socket again. Setting
11462 it to 1 inhibits busy-cursor display for direct commands. */
11464 int inhibit_busy_cursor
;
11466 /* Incremented with each call to x-display-busy-cursor.
11467 Decremented in x-undisplay-busy-cursor. */
11469 static int busy_count
;
11472 DEFUN ("x-show-busy-cursor", Fx_show_busy_cursor
,
11473 Sx_show_busy_cursor
, 0, 0, 0,
11474 "Show a busy cursor, if not already shown.\n\
11475 Each call to this function must be matched by a call to\n\
11476 x-undisplay-busy-cursor to make the busy pointer disappear again.")
11480 if (busy_count
== 1)
11482 Lisp_Object rest
, frame
;
11484 FOR_EACH_FRAME (rest
, frame
)
11485 if (FRAME_X_P (XFRAME (frame
)))
11487 struct frame
*f
= XFRAME (frame
);
11488 #if 0 /* NTEMACS_TODO : busy cursor */
11491 f
->output_data
.w32
->busy_p
= 1;
11493 if (!f
->output_data
.w32
->busy_window
)
11495 unsigned long mask
= CWCursor
;
11496 XSetWindowAttributes attrs
;
11498 attrs
.cursor
= f
->output_data
.w32
->busy_cursor
;
11499 f
->output_data
.w32
->busy_window
11500 = XCreateWindow (FRAME_W32_DISPLAY (f
),
11501 FRAME_OUTER_WINDOW (f
),
11502 0, 0, 32000, 32000, 0, 0,
11503 InputOnly
, CopyFromParent
,
11507 XMapRaised (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->busy_window
);
11517 DEFUN ("x-hide-busy-cursor", Fx_hide_busy_cursor
,
11518 Sx_hide_busy_cursor
, 0, 1, 0,
11519 "Hide a busy-cursor.\n\
11520 A busy-cursor will actually be undisplayed when a matching\n\
11521 `x-undisplay-busy-cursor' is called for each `x-display-busy-cursor'\n\
11522 issued. FORCE non-nil means undisplay the busy-cursor forcibly,\n\
11523 not counting calls.")
11527 Lisp_Object rest
, frame
;
11529 if (busy_count
== 0)
11532 if (!NILP (force
) && busy_count
!= 0)
11536 if (busy_count
!= 0)
11539 FOR_EACH_FRAME (rest
, frame
)
11541 struct frame
*f
= XFRAME (frame
);
11544 /* Watch out for newly created frames. */
11545 && f
->output_data
.w32
->busy_window
)
11547 #if 0 /* NTEMACS_TODO : busy cursor */
11549 XUnmapWindow (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->busy_window
);
11550 /* Sync here because XTread_socket looks at the busy_p flag
11551 that is reset to zero below. */
11552 XSync (FRAME_W32_DISPLAY (f
), False
);
11554 f
->output_data
.w32
->busy_p
= 0;
11564 /***********************************************************************
11566 ***********************************************************************/
11568 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
11571 /* The frame of a currently visible tooltip, or null. */
11573 struct frame
*tip_frame
;
11575 /* If non-nil, a timer started that hides the last tooltip when it
11578 Lisp_Object tip_timer
;
11581 /* Create a frame for a tooltip on the display described by DPYINFO.
11582 PARMS is a list of frame parameters. Value is the frame. */
11585 x_create_tip_frame (dpyinfo
, parms
)
11586 struct w32_display_info
*dpyinfo
;
11589 #if 0 /* NTEMACS_TODO : w32 version */
11591 Lisp_Object frame
, tem
;
11593 long window_prompting
= 0;
11595 int count
= specpdl_ptr
- specpdl
;
11596 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11601 /* Use this general default value to start with until we know if
11602 this frame has a specified name. */
11603 Vx_resource_name
= Vinvocation_name
;
11605 #ifdef MULTI_KBOARD
11606 kb
= dpyinfo
->kboard
;
11608 kb
= &the_only_kboard
;
11611 /* Get the name of the frame to use for resource lookup. */
11612 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
11613 if (!STRINGP (name
)
11614 && !EQ (name
, Qunbound
)
11616 error ("Invalid frame name--not a string or nil");
11617 Vx_resource_name
= name
;
11620 GCPRO3 (parms
, name
, frame
);
11621 tip_frame
= f
= make_frame (1);
11622 XSETFRAME (frame
, f
);
11623 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
11625 f
->output_method
= output_x_window
;
11626 f
->output_data
.w32
=
11627 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
11628 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
11630 f
->output_data
.w32
->icon_bitmap
= -1;
11632 f
->output_data
.w32
->fontset
= -1;
11633 f
->icon_name
= Qnil
;
11635 #ifdef MULTI_KBOARD
11636 FRAME_KBOARD (f
) = kb
;
11638 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
11639 f
->output_data
.w32
->explicit_parent
= 0;
11641 /* Set the name; the functions to which we pass f expect the name to
11643 if (EQ (name
, Qunbound
) || NILP (name
))
11645 f
->name
= build_string (dpyinfo
->x_id_name
);
11646 f
->explicit_name
= 0;
11651 f
->explicit_name
= 1;
11652 /* use the frame's title when getting resources for this frame. */
11653 specbind (Qx_resource_name
, name
);
11656 /* Create fontsets from `global_fontset_alist' before handling fonts. */
11657 for (tem
= Vglobal_fontset_alist
; CONSP (tem
); tem
= XCDR (tem
))
11658 fs_register_fontset (f
, XCAR (tem
));
11660 /* Extract the window parameters from the supplied values
11661 that are needed to determine window geometry. */
11665 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
11668 /* First, try whatever font the caller has specified. */
11669 if (STRINGP (font
))
11671 tem
= Fquery_fontset (font
, Qnil
);
11673 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
11675 font
= x_new_font (f
, XSTRING (font
)->data
);
11678 /* Try out a font which we hope has bold and italic variations. */
11679 if (!STRINGP (font
))
11680 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
11681 if (!STRINGP (font
))
11682 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
11683 if (! STRINGP (font
))
11684 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
11685 if (! STRINGP (font
))
11686 /* This was formerly the first thing tried, but it finds too many fonts
11687 and takes too long. */
11688 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
11689 /* If those didn't work, look for something which will at least work. */
11690 if (! STRINGP (font
))
11691 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
11693 if (! STRINGP (font
))
11694 font
= build_string ("fixed");
11696 x_default_parameter (f
, parms
, Qfont
, font
,
11697 "font", "Font", RES_TYPE_STRING
);
11700 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
11701 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
11703 /* This defaults to 2 in order to match xterm. We recognize either
11704 internalBorderWidth or internalBorder (which is what xterm calls
11706 if (NILP (Fassq (Qinternal_border_width
, parms
)))
11710 value
= w32_get_arg (parms
, Qinternal_border_width
,
11711 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
11712 if (! EQ (value
, Qunbound
))
11713 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
11717 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
11718 "internalBorderWidth", "internalBorderWidth",
11721 /* Also do the stuff which must be set before the window exists. */
11722 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
11723 "foreground", "Foreground", RES_TYPE_STRING
);
11724 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
11725 "background", "Background", RES_TYPE_STRING
);
11726 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
11727 "pointerColor", "Foreground", RES_TYPE_STRING
);
11728 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
11729 "cursorColor", "Foreground", RES_TYPE_STRING
);
11730 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
11731 "borderColor", "BorderColor", RES_TYPE_STRING
);
11733 /* Init faces before x_default_parameter is called for scroll-bar
11734 parameters because that function calls x_set_scroll_bar_width,
11735 which calls change_frame_size, which calls Fset_window_buffer,
11736 which runs hooks, which call Fvertical_motion. At the end, we
11737 end up in init_iterator with a null face cache, which should not
11739 init_frame_faces (f
);
11741 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
11742 window_prompting
= x_figure_window_size (f
, parms
);
11744 if (window_prompting
& XNegative
)
11746 if (window_prompting
& YNegative
)
11747 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
11749 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
11753 if (window_prompting
& YNegative
)
11754 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
11756 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
11759 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
11761 XSetWindowAttributes attrs
;
11762 unsigned long mask
;
11765 mask
= CWBackPixel
| CWOverrideRedirect
| CWSaveUnder
| CWEventMask
;
11766 /* Window managers looks at the override-redirect flag to
11767 determine whether or net to give windows a decoration (Xlib
11769 attrs
.override_redirect
= True
;
11770 attrs
.save_under
= True
;
11771 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
11772 /* Arrange for getting MapNotify and UnmapNotify events. */
11773 attrs
.event_mask
= StructureNotifyMask
;
11775 = FRAME_W32_WINDOW (f
)
11776 = XCreateWindow (FRAME_W32_DISPLAY (f
),
11777 FRAME_W32_DISPLAY_INFO (f
)->root_window
,
11778 /* x, y, width, height */
11782 CopyFromParent
, InputOutput
, CopyFromParent
,
11789 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
11790 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
11791 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
11792 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
11793 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
11794 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
11796 /* Dimensions, especially f->height, must be done via change_frame_size.
11797 Change will not be effected unless different from the current
11800 height
= f
->height
;
11802 SET_FRAME_WIDTH (f
, 0);
11803 change_frame_size (f
, height
, width
, 1, 0, 0);
11809 /* It is now ok to make the frame official even if we get an error
11810 below. And the frame needs to be on Vframe_list or making it
11811 visible won't work. */
11812 Vframe_list
= Fcons (frame
, Vframe_list
);
11814 /* Now that the frame is official, it counts as a reference to
11816 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
11818 return unbind_to (count
, frame
);
11819 #endif /* NTEMACS_TODO */
11824 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 4, 0,
11825 "Show STRING in a \"tooltip\" window on frame FRAME.\n\
11826 A tooltip window is a small X window displaying STRING at\n\
11827 the current mouse position.\n\
11828 FRAME nil or omitted means use the selected frame.\n\
11829 PARMS is an optional list of frame parameters which can be\n\
11830 used to change the tooltip's appearance.\n\
11831 Automatically hide the tooltip after TIMEOUT seconds.\n\
11832 TIMEOUT nil means use the default timeout of 5 seconds.")
11833 (string
, frame
, parms
, timeout
)
11834 Lisp_Object string
, frame
, parms
, timeout
;
11838 Window root
, child
;
11839 Lisp_Object buffer
;
11840 struct buffer
*old_buffer
;
11841 struct text_pos pos
;
11842 int i
, width
, height
;
11843 int root_x
, root_y
, win_x
, win_y
;
11845 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
11846 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
11847 int count
= specpdl_ptr
- specpdl
;
11849 specbind (Qinhibit_redisplay
, Qt
);
11851 GCPRO3 (string
, parms
, frame
, timeout
);
11853 CHECK_STRING (string
, 0);
11854 f
= check_x_frame (frame
);
11855 if (NILP (timeout
))
11856 timeout
= make_number (5);
11858 CHECK_NATNUM (timeout
, 2);
11860 /* Hide a previous tip, if any. */
11863 /* Add default values to frame parameters. */
11864 if (NILP (Fassq (Qname
, parms
)))
11865 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
11866 if (NILP (Fassq (Qinternal_border_width
, parms
)))
11867 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
11868 if (NILP (Fassq (Qborder_width
, parms
)))
11869 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
11870 if (NILP (Fassq (Qborder_color
, parms
)))
11871 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
11872 if (NILP (Fassq (Qbackground_color
, parms
)))
11873 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
11876 /* Create a frame for the tooltip, and record it in the global
11877 variable tip_frame. */
11878 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
);
11879 tip_frame
= f
= XFRAME (frame
);
11881 /* Set up the frame's root window. Currently we use a size of 80
11882 columns x 40 lines. If someone wants to show a larger tip, he
11883 will loose. I don't think this is a realistic case. */
11884 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
11885 w
->left
= w
->top
= make_number (0);
11889 w
->pseudo_window_p
= 1;
11891 /* Display the tooltip text in a temporary buffer. */
11892 buffer
= Fget_buffer_create (build_string (" *tip*"));
11893 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
11894 old_buffer
= current_buffer
;
11895 set_buffer_internal_1 (XBUFFER (buffer
));
11897 Finsert (make_number (1), &string
);
11898 clear_glyph_matrix (w
->desired_matrix
);
11899 clear_glyph_matrix (w
->current_matrix
);
11900 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
11901 try_window (FRAME_ROOT_WINDOW (f
), pos
);
11903 /* Compute width and height of the tooltip. */
11904 width
= height
= 0;
11905 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
11907 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
11908 struct glyph
*last
;
11911 /* Stop at the first empty row at the end. */
11912 if (!row
->enabled_p
|| !row
->displays_text_p
)
11915 /* Let the row go over the full width of the frame. */
11916 row
->full_width_p
= 1;
11918 /* There's a glyph at the end of rows that is use to place
11919 the cursor there. Don't include the width of this glyph. */
11920 if (row
->used
[TEXT_AREA
])
11922 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
11923 row_width
= row
->pixel_width
- last
->pixel_width
;
11926 row_width
= row
->pixel_width
;
11928 height
+= row
->height
;
11929 width
= max (width
, row_width
);
11932 /* Add the frame's internal border to the width and height the X
11933 window should have. */
11934 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
11935 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
11937 /* Move the tooltip window where the mouse pointer is. Resize and
11939 #if 0 /* NTEMACS_TODO : W32 specifics */
11941 XQueryPointer (FRAME_W32_DISPLAY (f
), FRAME_W32_DISPLAY_INFO (f
)->root_window
,
11942 &root
, &child
, &root_x
, &root_y
, &win_x
, &win_y
, &pmask
);
11943 XMoveResizeWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11944 root_x
+ 5, root_y
- height
- 5, width
, height
);
11945 XMapRaised (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
11947 #endif /* NTEMACS_TODO */
11949 /* Draw into the window. */
11950 w
->must_be_updated_p
= 1;
11951 update_single_window (w
, 1);
11953 /* Restore original current buffer. */
11954 set_buffer_internal_1 (old_buffer
);
11955 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
11957 /* Let the tip disappear after timeout seconds. */
11958 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
11959 intern ("x-hide-tip"));
11962 return unbind_to (count
, Qnil
);
11966 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
11967 "Hide the current tooltip window, if there is any.\n\
11968 Value is t is tooltip was open, nil otherwise.")
11971 int count
= specpdl_ptr
- specpdl
;
11974 specbind (Qinhibit_redisplay
, Qt
);
11976 if (!NILP (tip_timer
))
11978 call1 (intern ("cancel-timer"), tip_timer
);
11986 XSETFRAME (frame
, tip_frame
);
11987 Fdelete_frame (frame
, Qt
);
11992 return unbind_to (count
, deleted_p
? Qt
: Qnil
);
11997 /***********************************************************************
11998 File selection dialog
11999 ***********************************************************************/
12001 extern Lisp_Object Qfile_name_history
;
12003 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
12004 "Read file name, prompting with PROMPT in directory DIR.\n\
12005 Use a file selection dialog.\n\
12006 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
12007 specified. Don't let the user enter a file name in the file\n\
12008 selection dialog's entry field, if MUSTMATCH is non-nil.")
12009 (prompt
, dir
, default_filename
, mustmatch
)
12010 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
12012 struct frame
*f
= SELECTED_FRAME ();
12013 Lisp_Object file
= Qnil
;
12014 int count
= specpdl_ptr
- specpdl
;
12015 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
12016 char filename
[MAX_PATH
+ 1];
12017 char init_dir
[MAX_PATH
+ 1];
12018 int use_dialog_p
= 1;
12020 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
12021 CHECK_STRING (prompt
, 0);
12022 CHECK_STRING (dir
, 1);
12024 /* Create the dialog with PROMPT as title, using DIR as initial
12025 directory and using "*" as pattern. */
12026 dir
= Fexpand_file_name (dir
, Qnil
);
12027 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
12028 init_dir
[MAX_PATH
] = '\0';
12029 unixtodos_filename (init_dir
);
12031 if (STRINGP (default_filename
))
12033 char *file_name_only
;
12034 char *full_path_name
= XSTRING (default_filename
)->data
;
12036 unixtodos_filename (full_path_name
);
12038 file_name_only
= strrchr (full_path_name
, '\\');
12039 if (!file_name_only
)
12040 file_name_only
= full_path_name
;
12045 /* If default_file_name is a directory, don't use the open
12046 file dialog, as it does not support selecting
12048 if (!(*file_name_only
))
12052 strncpy (filename
, file_name_only
, MAX_PATH
);
12053 filename
[MAX_PATH
] = '\0';
12056 filename
[0] = '\0';
12060 OPENFILENAME file_details
;
12061 char *filename_file
;
12063 /* Prevent redisplay. */
12064 specbind (Qinhibit_redisplay
, Qt
);
12067 bzero (&file_details
, sizeof (file_details
));
12068 file_details
.lStructSize
= sizeof (file_details
);
12069 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
12070 file_details
.lpstrFile
= filename
;
12071 file_details
.nMaxFile
= sizeof (filename
);
12072 file_details
.lpstrInitialDir
= init_dir
;
12073 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
12074 file_details
.Flags
= OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
;
12076 if (!NILP (mustmatch
))
12077 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
12079 if (GetOpenFileName (&file_details
))
12081 dostounix_filename (filename
);
12082 file
= build_string (filename
);
12088 file
= unbind_to (count
, file
);
12090 /* Open File dialog will not allow folders to be selected, so resort
12091 to minibuffer completing reads for directories. */
12093 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
12094 dir
, mustmatch
, dir
, Qfile_name_history
,
12095 default_filename
, Qnil
);
12099 /* Make "Cancel" equivalent to C-g. */
12101 Fsignal (Qquit
, Qnil
);
12108 /***********************************************************************
12110 ***********************************************************************/
12114 DEFUN ("imagep", Fimagep
, Simagep
, 1, 1, 0,
12115 "Value is non-nil if SPEC is a valid image specification.")
12119 return valid_image_p (spec
) ? Qt
: Qnil
;
12123 DEFUN ("lookup-image", Flookup_image
, Slookup_image
, 1, 1, 0, "")
12129 if (valid_image_p (spec
))
12130 id
= lookup_image (SELECTED_FRAME (), spec
);
12132 debug_print (spec
);
12133 return make_number (id
);
12136 #endif /* GLYPH_DEBUG != 0 */
12140 /***********************************************************************
12141 w32 specialized functions
12142 ***********************************************************************/
12144 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 1, 0,
12145 "This will display the W32 font dialog and return an X font string corresponding to the selection.")
12149 FRAME_PTR f
= check_x_frame (frame
);
12157 bzero (&cf
, sizeof (cf
));
12158 bzero (&lf
, sizeof (lf
));
12160 cf
.lStructSize
= sizeof (cf
);
12161 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
12162 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
;
12163 cf
.lpLogFont
= &lf
;
12165 /* Initialize as much of the font details as we can from the current
12167 hdc
= GetDC (FRAME_W32_WINDOW (f
));
12168 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
12169 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
12170 if (GetTextMetrics (hdc
, &tm
))
12172 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
12173 lf
.lfWeight
= tm
.tmWeight
;
12174 lf
.lfItalic
= tm
.tmItalic
;
12175 lf
.lfUnderline
= tm
.tmUnderlined
;
12176 lf
.lfStrikeOut
= tm
.tmStruckOut
;
12177 lf
.lfCharSet
= tm
.tmCharSet
;
12178 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
12180 SelectObject (hdc
, oldobj
);
12181 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
12183 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100))
12186 return build_string (buf
);
12189 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
, Sw32_send_sys_command
, 1, 2, 0,
12190 "Send frame a Windows WM_SYSCOMMAND message of type COMMAND.\n\
12191 Some useful values for command are 0xf030 to maximise frame (0xf020\n\
12192 to minimize), 0xf120 to restore frame to original size, and 0xf100\n\
12193 to activate the menubar for keyboard access. 0xf140 activates the\n\
12194 screen saver if defined.\n\
12196 If optional parameter FRAME is not specified, use selected frame.")
12198 Lisp_Object command
, frame
;
12201 FRAME_PTR f
= check_x_frame (frame
);
12203 CHECK_NUMBER (command
, 0);
12205 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
12210 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
12211 "Get Windows to perform OPERATION on DOCUMENT.\n\
12212 This is a wrapper around the ShellExecute system function, which\n\
12213 invokes the application registered to handle OPERATION for DOCUMENT.\n\
12214 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be\n\
12215 nil for the default action), and DOCUMENT is typically the name of a\n\
12216 document file or URL, but can also be a program executable to run or\n\
12217 a directory to open in the Windows Explorer.\n\
12219 If DOCUMENT is a program executable, PARAMETERS can be a string\n\
12220 containing command line parameters, but otherwise should be nil.\n\
12222 SHOW-FLAG can be used to control whether the invoked application is hidden\n\
12223 or minimized. If SHOW-FLAG is nil, the application is displayed normally,\n\
12224 otherwise it is an integer representing a ShowWindow flag:\n\
12226 0 - start hidden\n\
12227 1 - start normally\n\
12228 3 - start maximized\n\
12229 6 - start minimized")
12230 (operation
, document
, parameters
, show_flag
)
12231 Lisp_Object operation
, document
, parameters
, show_flag
;
12233 Lisp_Object current_dir
;
12235 CHECK_STRING (document
, 0);
12237 /* Encode filename and current directory. */
12238 current_dir
= ENCODE_FILE (current_buffer
->directory
);
12239 document
= ENCODE_FILE (document
);
12240 if ((int) ShellExecute (NULL
,
12241 (STRINGP (operation
) ?
12242 XSTRING (operation
)->data
: NULL
),
12243 XSTRING (document
)->data
,
12244 (STRINGP (parameters
) ?
12245 XSTRING (parameters
)->data
: NULL
),
12246 XSTRING (current_dir
)->data
,
12247 (INTEGERP (show_flag
) ?
12248 XINT (show_flag
) : SW_SHOWDEFAULT
))
12251 error ("ShellExecute failed");
12254 /* Lookup virtual keycode from string representing the name of a
12255 non-ascii keystroke into the corresponding virtual key, using
12256 lispy_function_keys. */
12258 lookup_vk_code (char *key
)
12262 for (i
= 0; i
< 256; i
++)
12263 if (lispy_function_keys
[i
] != 0
12264 && strcmp (lispy_function_keys
[i
], key
) == 0)
12270 /* Convert a one-element vector style key sequence to a hot key
12273 w32_parse_hot_key (key
)
12276 /* Copied from Fdefine_key and store_in_keymap. */
12277 register Lisp_Object c
;
12279 int lisp_modifiers
;
12281 struct gcpro gcpro1
;
12283 CHECK_VECTOR (key
, 0);
12285 if (XFASTINT (Flength (key
)) != 1)
12290 c
= Faref (key
, make_number (0));
12292 if (CONSP (c
) && lucid_event_type_list_p (c
))
12293 c
= Fevent_convert_list (c
);
12297 if (! INTEGERP (c
) && ! SYMBOLP (c
))
12298 error ("Key definition is invalid");
12300 /* Work out the base key and the modifiers. */
12303 c
= parse_modifiers (c
);
12304 lisp_modifiers
= Fcar (Fcdr (c
));
12308 vk_code
= lookup_vk_code (XSYMBOL (c
)->name
->data
);
12310 else if (INTEGERP (c
))
12312 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
12313 /* Many ascii characters are their own virtual key code. */
12314 vk_code
= XINT (c
) & CHARACTERBITS
;
12317 if (vk_code
< 0 || vk_code
> 255)
12320 if ((lisp_modifiers
& meta_modifier
) != 0
12321 && !NILP (Vw32_alt_is_meta
))
12322 lisp_modifiers
|= alt_modifier
;
12324 /* Convert lisp modifiers to Windows hot-key form. */
12325 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
12326 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
12327 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
12328 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
12330 return HOTKEY (vk_code
, w32_modifiers
);
12333 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
, Sw32_register_hot_key
, 1, 1, 0,
12334 "Register KEY as a hot-key combination.\n\
12335 Certain key combinations like Alt-Tab are reserved for system use on\n\
12336 Windows, and therefore are normally intercepted by the system. However,\n\
12337 most of these key combinations can be received by registering them as\n\
12338 hot-keys, overriding their special meaning.\n\
12340 KEY must be a one element key definition in vector form that would be\n\
12341 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta\n\
12342 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper\n\
12343 is always interpreted as the Windows modifier keys.\n\
12345 The return value is the hotkey-id if registered, otherwise nil.")
12349 key
= w32_parse_hot_key (key
);
12351 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
12353 /* Reuse an empty slot if possible. */
12354 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
12356 /* Safe to add new key to list, even if we have focus. */
12358 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
12362 /* Notify input thread about new hot-key definition, so that it
12363 takes effect without needing to switch focus. */
12364 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
12371 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
, Sw32_unregister_hot_key
, 1, 1, 0,
12372 "Unregister HOTKEY as a hot-key combination.")
12378 if (!INTEGERP (key
))
12379 key
= w32_parse_hot_key (key
);
12381 item
= Fmemq (key
, w32_grabbed_keys
);
12385 /* Notify input thread about hot-key definition being removed, so
12386 that it takes effect without needing focus switch. */
12387 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
12388 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
12391 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
12398 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
, Sw32_registered_hot_keys
, 0, 0, 0,
12399 "Return list of registered hot-key IDs.")
12402 return Fcopy_sequence (w32_grabbed_keys
);
12405 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
, Sw32_reconstruct_hot_key
, 1, 1, 0,
12406 "Convert hot-key ID to a lisp key combination.")
12408 Lisp_Object hotkeyid
;
12410 int vk_code
, w32_modifiers
;
12413 CHECK_NUMBER (hotkeyid
, 0);
12415 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
12416 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
12418 if (lispy_function_keys
[vk_code
])
12419 key
= intern (lispy_function_keys
[vk_code
]);
12421 key
= make_number (vk_code
);
12423 key
= Fcons (key
, Qnil
);
12424 if (w32_modifiers
& MOD_SHIFT
)
12425 key
= Fcons (Qshift
, key
);
12426 if (w32_modifiers
& MOD_CONTROL
)
12427 key
= Fcons (Qctrl
, key
);
12428 if (w32_modifiers
& MOD_ALT
)
12429 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
12430 if (w32_modifiers
& MOD_WIN
)
12431 key
= Fcons (Qhyper
, key
);
12436 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
, Sw32_toggle_lock_key
, 1, 2, 0,
12437 "Toggle the state of the lock key KEY.\n\
12438 KEY can be `capslock', `kp-numlock', or `scroll'.\n\
12439 If the optional parameter NEW-STATE is a number, then the state of KEY\n\
12440 is set to off if the low bit of NEW-STATE is zero, otherwise on.")
12442 Lisp_Object key
, new_state
;
12447 if (EQ (key
, intern ("capslock")))
12448 vk_code
= VK_CAPITAL
;
12449 else if (EQ (key
, intern ("kp-numlock")))
12450 vk_code
= VK_NUMLOCK
;
12451 else if (EQ (key
, intern ("scroll")))
12452 vk_code
= VK_SCROLL
;
12456 if (!dwWindowsThreadId
)
12457 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
12459 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
12460 (WPARAM
) vk_code
, (LPARAM
) new_state
))
12463 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
12464 return make_number (msg
.wParam
);
12471 /* This is zero if not using MS-Windows. */
12474 /* The section below is built by the lisp expression at the top of the file,
12475 just above where these variables are declared. */
12476 /*&&& init symbols here &&&*/
12477 Qauto_raise
= intern ("auto-raise");
12478 staticpro (&Qauto_raise
);
12479 Qauto_lower
= intern ("auto-lower");
12480 staticpro (&Qauto_lower
);
12481 Qbar
= intern ("bar");
12483 Qborder_color
= intern ("border-color");
12484 staticpro (&Qborder_color
);
12485 Qborder_width
= intern ("border-width");
12486 staticpro (&Qborder_width
);
12487 Qbox
= intern ("box");
12489 Qcursor_color
= intern ("cursor-color");
12490 staticpro (&Qcursor_color
);
12491 Qcursor_type
= intern ("cursor-type");
12492 staticpro (&Qcursor_type
);
12493 Qgeometry
= intern ("geometry");
12494 staticpro (&Qgeometry
);
12495 Qicon_left
= intern ("icon-left");
12496 staticpro (&Qicon_left
);
12497 Qicon_top
= intern ("icon-top");
12498 staticpro (&Qicon_top
);
12499 Qicon_type
= intern ("icon-type");
12500 staticpro (&Qicon_type
);
12501 Qicon_name
= intern ("icon-name");
12502 staticpro (&Qicon_name
);
12503 Qinternal_border_width
= intern ("internal-border-width");
12504 staticpro (&Qinternal_border_width
);
12505 Qleft
= intern ("left");
12506 staticpro (&Qleft
);
12507 Qright
= intern ("right");
12508 staticpro (&Qright
);
12509 Qmouse_color
= intern ("mouse-color");
12510 staticpro (&Qmouse_color
);
12511 Qnone
= intern ("none");
12512 staticpro (&Qnone
);
12513 Qparent_id
= intern ("parent-id");
12514 staticpro (&Qparent_id
);
12515 Qscroll_bar_width
= intern ("scroll-bar-width");
12516 staticpro (&Qscroll_bar_width
);
12517 Qsuppress_icon
= intern ("suppress-icon");
12518 staticpro (&Qsuppress_icon
);
12519 Qundefined_color
= intern ("undefined-color");
12520 staticpro (&Qundefined_color
);
12521 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
12522 staticpro (&Qvertical_scroll_bars
);
12523 Qvisibility
= intern ("visibility");
12524 staticpro (&Qvisibility
);
12525 Qwindow_id
= intern ("window-id");
12526 staticpro (&Qwindow_id
);
12527 Qx_frame_parameter
= intern ("x-frame-parameter");
12528 staticpro (&Qx_frame_parameter
);
12529 Qx_resource_name
= intern ("x-resource-name");
12530 staticpro (&Qx_resource_name
);
12531 Quser_position
= intern ("user-position");
12532 staticpro (&Quser_position
);
12533 Quser_size
= intern ("user-size");
12534 staticpro (&Quser_size
);
12535 #if 0 /* Duplicate initialization in xdisp.c */
12536 Qdisplay
= intern ("display");
12537 staticpro (&Qdisplay
);
12539 Qscreen_gamma
= intern ("screen-gamma");
12540 staticpro (&Qscreen_gamma
);
12541 /* This is the end of symbol initialization. */
12543 Qhyper
= intern ("hyper");
12544 staticpro (&Qhyper
);
12545 Qsuper
= intern ("super");
12546 staticpro (&Qsuper
);
12547 Qmeta
= intern ("meta");
12548 staticpro (&Qmeta
);
12549 Qalt
= intern ("alt");
12551 Qctrl
= intern ("ctrl");
12552 staticpro (&Qctrl
);
12553 Qcontrol
= intern ("control");
12554 staticpro (&Qcontrol
);
12555 Qshift
= intern ("shift");
12556 staticpro (&Qshift
);
12558 /* Text property `display' should be nonsticky by default. */
12559 Vtext_property_default_nonsticky
12560 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
12563 Qlaplace
= intern ("laplace");
12564 staticpro (&Qlaplace
);
12566 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
12567 staticpro (&Qface_set_after_frame_default
);
12569 Fput (Qundefined_color
, Qerror_conditions
,
12570 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
12571 Fput (Qundefined_color
, Qerror_message
,
12572 build_string ("Undefined color"));
12574 staticpro (&w32_grabbed_keys
);
12575 w32_grabbed_keys
= Qnil
;
12577 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
12578 "An array of color name mappings for windows.");
12579 Vw32_color_map
= Qnil
;
12581 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
12582 "Non-nil if alt key presses are passed on to Windows.\n\
12583 When non-nil, for example, alt pressed and released and then space will\n\
12584 open the System menu. When nil, Emacs silently swallows alt key events.");
12585 Vw32_pass_alt_to_system
= Qnil
;
12587 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
12588 "Non-nil if the alt key is to be considered the same as the meta key.\n\
12589 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta.");
12590 Vw32_alt_is_meta
= Qt
;
12592 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
12593 "If non-zero, the virtual key code for an alternative quit key.");
12594 XSETINT (Vw32_quit_key
, 0);
12596 DEFVAR_LISP ("w32-pass-lwindow-to-system",
12597 &Vw32_pass_lwindow_to_system
,
12598 "Non-nil if the left \"Windows\" key is passed on to Windows.\n\
12599 When non-nil, the Start menu is opened by tapping the key.");
12600 Vw32_pass_lwindow_to_system
= Qt
;
12602 DEFVAR_LISP ("w32-pass-rwindow-to-system",
12603 &Vw32_pass_rwindow_to_system
,
12604 "Non-nil if the right \"Windows\" key is passed on to Windows.\n\
12605 When non-nil, the Start menu is opened by tapping the key.");
12606 Vw32_pass_rwindow_to_system
= Qt
;
12608 DEFVAR_INT ("w32-phantom-key-code",
12609 &Vw32_phantom_key_code
,
12610 "Virtual key code used to generate \"phantom\" key presses.\n\
12611 Value is a number between 0 and 255.\n\
12613 Phantom key presses are generated in order to stop the system from\n\
12614 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or\n\
12615 `w32-pass-rwindow-to-system' is nil.");
12616 /* Although 255 is technically not a valid key code, it works and
12617 means that this hack won't interfere with any real key code. */
12618 Vw32_phantom_key_code
= 255;
12620 DEFVAR_LISP ("w32-enable-num-lock",
12621 &Vw32_enable_num_lock
,
12622 "Non-nil if Num Lock should act normally.\n\
12623 Set to nil to see Num Lock as the key `kp-numlock'.");
12624 Vw32_enable_num_lock
= Qt
;
12626 DEFVAR_LISP ("w32-enable-caps-lock",
12627 &Vw32_enable_caps_lock
,
12628 "Non-nil if Caps Lock should act normally.\n\
12629 Set to nil to see Caps Lock as the key `capslock'.");
12630 Vw32_enable_caps_lock
= Qt
;
12632 DEFVAR_LISP ("w32-scroll-lock-modifier",
12633 &Vw32_scroll_lock_modifier
,
12634 "Modifier to use for the Scroll Lock on state.\n\
12635 The value can be hyper, super, meta, alt, control or shift for the\n\
12636 respective modifier, or nil to see Scroll Lock as the key `scroll'.\n\
12637 Any other value will cause the key to be ignored.");
12638 Vw32_scroll_lock_modifier
= Qt
;
12640 DEFVAR_LISP ("w32-lwindow-modifier",
12641 &Vw32_lwindow_modifier
,
12642 "Modifier to use for the left \"Windows\" key.\n\
12643 The value can be hyper, super, meta, alt, control or shift for the\n\
12644 respective modifier, or nil to appear as the key `lwindow'.\n\
12645 Any other value will cause the key to be ignored.");
12646 Vw32_lwindow_modifier
= Qnil
;
12648 DEFVAR_LISP ("w32-rwindow-modifier",
12649 &Vw32_rwindow_modifier
,
12650 "Modifier to use for the right \"Windows\" key.\n\
12651 The value can be hyper, super, meta, alt, control or shift for the\n\
12652 respective modifier, or nil to appear as the key `rwindow'.\n\
12653 Any other value will cause the key to be ignored.");
12654 Vw32_rwindow_modifier
= Qnil
;
12656 DEFVAR_LISP ("w32-apps-modifier",
12657 &Vw32_apps_modifier
,
12658 "Modifier to use for the \"Apps\" key.\n\
12659 The value can be hyper, super, meta, alt, control or shift for the\n\
12660 respective modifier, or nil to appear as the key `apps'.\n\
12661 Any other value will cause the key to be ignored.");
12662 Vw32_apps_modifier
= Qnil
;
12664 DEFVAR_LISP ("w32-enable-synthesized_fonts", &Vw32_enable_synthesized_fonts
,
12665 "Non-nil enables selection of artificially italicized and bold fonts.");
12666 Vw32_enable_synthesized_fonts
= Qnil
;
12668 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
12669 "Non-nil enables Windows palette management to map colors exactly.");
12670 Vw32_enable_palette
= Qt
;
12672 DEFVAR_INT ("w32-mouse-button-tolerance",
12673 &Vw32_mouse_button_tolerance
,
12674 "Analogue of double click interval for faking middle mouse events.\n\
12675 The value is the minimum time in milliseconds that must elapse between\n\
12676 left/right button down events before they are considered distinct events.\n\
12677 If both mouse buttons are depressed within this interval, a middle mouse\n\
12678 button down event is generated instead.");
12679 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
12681 DEFVAR_INT ("w32-mouse-move-interval",
12682 &Vw32_mouse_move_interval
,
12683 "Minimum interval between mouse move events.\n\
12684 The value is the minimum time in milliseconds that must elapse between\n\
12685 successive mouse move (or scroll bar drag) events before they are\n\
12686 reported as lisp events.");
12687 XSETINT (Vw32_mouse_move_interval
, 0);
12689 init_x_parm_symbols ();
12691 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
12692 "List of directories to search for bitmap files for w32.");
12693 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
12695 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
12696 "The shape of the pointer when over text.\n\
12697 Changing the value does not affect existing frames\n\
12698 unless you set the mouse color.");
12699 Vx_pointer_shape
= Qnil
;
12701 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
12702 "The name Emacs uses to look up resources; for internal use only.\n\
12703 `x-get-resource' uses this as the first component of the instance name\n\
12704 when requesting resource values.\n\
12705 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
12706 was invoked, or to the value specified with the `-name' or `-rn'\n\
12707 switches, if present.");
12708 Vx_resource_name
= Qnil
;
12710 Vx_nontext_pointer_shape
= Qnil
;
12712 Vx_mode_pointer_shape
= Qnil
;
12714 DEFVAR_LISP ("x-busy-pointer-shape", &Vx_busy_pointer_shape
,
12715 "The shape of the pointer when Emacs is busy.\n\
12716 This variable takes effect when you create a new frame\n\
12717 or when you set the mouse color.");
12718 Vx_busy_pointer_shape
= Qnil
;
12720 DEFVAR_BOOL ("display-busy-cursor", &display_busy_cursor_p
,
12721 "Non-zero means Emacs displays a busy cursor on window systems.");
12722 display_busy_cursor_p
= 1;
12724 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
12725 &Vx_sensitive_text_pointer_shape
,
12726 "The shape of the pointer when over mouse-sensitive text.\n\
12727 This variable takes effect when you create a new frame\n\
12728 or when you set the mouse color.");
12729 Vx_sensitive_text_pointer_shape
= Qnil
;
12731 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
12732 "A string indicating the foreground color of the cursor box.");
12733 Vx_cursor_fore_pixel
= Qnil
;
12735 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
12736 "Non-nil if no window manager is in use.\n\
12737 Emacs doesn't try to figure this out; this is always nil\n\
12738 unless you set it to something else.");
12739 /* We don't have any way to find this out, so set it to nil
12740 and maybe the user would like to set it to t. */
12741 Vx_no_window_manager
= Qnil
;
12743 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
12744 &Vx_pixel_size_width_font_regexp
,
12745 "Regexp matching a font name whose width is the same as `PIXEL_SIZE'.\n\
12747 Since Emacs gets width of a font matching with this regexp from\n\
12748 PIXEL_SIZE field of the name, font finding mechanism gets faster for\n\
12749 such a font. This is especially effective for such large fonts as\n\
12750 Chinese, Japanese, and Korean.");
12751 Vx_pixel_size_width_font_regexp
= Qnil
;
12753 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
12754 "Time after which cached images are removed from the cache.\n\
12755 When an image has not been displayed this many seconds, remove it\n\
12756 from the image cache. Value must be an integer or nil with nil\n\
12757 meaning don't clear the cache.");
12758 Vimage_cache_eviction_delay
= make_number (30 * 60);
12760 DEFVAR_LISP ("image-types", &Vimage_types
,
12761 "List of supported image types.\n\
12762 Each element of the list is a symbol for a supported image type.");
12763 Vimage_types
= Qnil
;
12765 DEFVAR_LISP ("w32-bdf-filename-alist",
12766 &Vw32_bdf_filename_alist
,
12767 "List of bdf fonts and their corresponding filenames.");
12768 Vw32_bdf_filename_alist
= Qnil
;
12770 DEFVAR_BOOL ("w32-strict-fontnames",
12771 &w32_strict_fontnames
,
12772 "Non-nil means only use fonts that are exact matches for those requested.\n\
12773 Default is nil, which allows old fontnames that are not XLFD compliant,\n\
12774 and allows third-party CJK display to work by specifying false charset\n\
12775 fields to trick Emacs into translating to Big5, SJIS etc.\n\
12776 Setting this to t will prevent wrong fonts being selected when\n\
12777 fontsets are automatically created.");
12778 w32_strict_fontnames
= 0;
12780 DEFVAR_BOOL ("w32-strict-painting",
12781 &w32_strict_painting
,
12782 "Non-nil means use strict rules for repainting frames.\n\
12783 Set this to nil to get the old behaviour for repainting; this should\n\
12784 only be necessary if the default setting causes problems.");
12785 w32_strict_painting
= 1;
12787 DEFVAR_LISP ("w32-system-coding-system",
12788 &Vw32_system_coding_system
,
12789 "Coding system used by Windows system functions, such as for font names.");
12790 Vw32_system_coding_system
= Qnil
;
12792 defsubr (&Sx_get_resource
);
12793 #if 0 /* NTEMACS_TODO: Port to W32 */
12794 defsubr (&Sx_change_window_property
);
12795 defsubr (&Sx_delete_window_property
);
12796 defsubr (&Sx_window_property
);
12798 defsubr (&Sxw_display_color_p
);
12799 defsubr (&Sx_display_grayscale_p
);
12800 defsubr (&Sxw_color_defined_p
);
12801 defsubr (&Sxw_color_values
);
12802 defsubr (&Sx_server_max_request_size
);
12803 defsubr (&Sx_server_vendor
);
12804 defsubr (&Sx_server_version
);
12805 defsubr (&Sx_display_pixel_width
);
12806 defsubr (&Sx_display_pixel_height
);
12807 defsubr (&Sx_display_mm_width
);
12808 defsubr (&Sx_display_mm_height
);
12809 defsubr (&Sx_display_screens
);
12810 defsubr (&Sx_display_planes
);
12811 defsubr (&Sx_display_color_cells
);
12812 defsubr (&Sx_display_visual_class
);
12813 defsubr (&Sx_display_backing_store
);
12814 defsubr (&Sx_display_save_under
);
12815 defsubr (&Sx_parse_geometry
);
12816 defsubr (&Sx_create_frame
);
12817 defsubr (&Sx_open_connection
);
12818 defsubr (&Sx_close_connection
);
12819 defsubr (&Sx_display_list
);
12820 defsubr (&Sx_synchronize
);
12822 /* W32 specific functions */
12824 defsubr (&Sw32_focus_frame
);
12825 defsubr (&Sw32_select_font
);
12826 defsubr (&Sw32_define_rgb_color
);
12827 defsubr (&Sw32_default_color_map
);
12828 defsubr (&Sw32_load_color_file
);
12829 defsubr (&Sw32_send_sys_command
);
12830 defsubr (&Sw32_shell_execute
);
12831 defsubr (&Sw32_register_hot_key
);
12832 defsubr (&Sw32_unregister_hot_key
);
12833 defsubr (&Sw32_registered_hot_keys
);
12834 defsubr (&Sw32_reconstruct_hot_key
);
12835 defsubr (&Sw32_toggle_lock_key
);
12836 defsubr (&Sw32_find_bdf_fonts
);
12838 /* Setting callback functions for fontset handler. */
12839 get_font_info_func
= w32_get_font_info
;
12841 #if 0 /* This function pointer doesn't seem to be used anywhere.
12842 And the pointer assigned has the wrong type, anyway. */
12843 list_fonts_func
= w32_list_fonts
;
12846 load_font_func
= w32_load_font
;
12847 find_ccl_program_func
= w32_find_ccl_program
;
12848 query_font_func
= w32_query_font
;
12849 set_frame_fontset_func
= x_set_font
;
12850 check_window_system_func
= check_w32
;
12852 #if 0 /* NTEMACS_TODO Image support for W32 */
12854 Qxbm
= intern ("xbm");
12856 QCtype
= intern (":type");
12857 staticpro (&QCtype
);
12858 QCalgorithm
= intern (":algorithm");
12859 staticpro (&QCalgorithm
);
12860 QCheuristic_mask
= intern (":heuristic-mask");
12861 staticpro (&QCheuristic_mask
);
12862 QCcolor_symbols
= intern (":color-symbols");
12863 staticpro (&QCcolor_symbols
);
12864 QCdata
= intern (":data");
12865 staticpro (&QCdata
);
12866 QCascent
= intern (":ascent");
12867 staticpro (&QCascent
);
12868 QCmargin
= intern (":margin");
12869 staticpro (&QCmargin
);
12870 QCrelief
= intern (":relief");
12871 staticpro (&QCrelief
);
12872 Qpostscript
= intern ("postscript");
12873 staticpro (&Qpostscript
);
12874 QCloader
= intern (":loader");
12875 staticpro (&QCloader
);
12876 QCbounding_box
= intern (":bounding-box");
12877 staticpro (&QCbounding_box
);
12878 QCpt_width
= intern (":pt-width");
12879 staticpro (&QCpt_width
);
12880 QCpt_height
= intern (":pt-height");
12881 staticpro (&QCpt_height
);
12882 QCindex
= intern (":index");
12883 staticpro (&QCindex
);
12884 Qpbm
= intern ("pbm");
12888 Qxpm
= intern ("xpm");
12893 Qjpeg
= intern ("jpeg");
12894 staticpro (&Qjpeg
);
12898 Qtiff
= intern ("tiff");
12899 staticpro (&Qtiff
);
12903 Qgif
= intern ("gif");
12908 Qpng
= intern ("png");
12912 defsubr (&Sclear_image_cache
);
12915 defsubr (&Simagep
);
12916 defsubr (&Slookup_image
);
12918 #endif /* NTEMACS_TODO */
12921 defsubr (&Sx_show_busy_cursor
);
12922 defsubr (&Sx_hide_busy_cursor
);
12924 inhibit_busy_cursor
= 0;
12926 defsubr (&Sx_show_tip
);
12927 defsubr (&Sx_hide_tip
);
12928 staticpro (&tip_timer
);
12931 defsubr (&Sx_file_dialog
);
12938 image_types
= NULL
;
12939 Vimage_types
= Qnil
;
12941 #if 0 /* NTEMACS_TODO : Image support for W32 */
12942 define_image_type (&xbm_type
);
12943 define_image_type (&gs_type
);
12944 define_image_type (&pbm_type
);
12947 define_image_type (&xpm_type
);
12951 define_image_type (&jpeg_type
);
12955 define_image_type (&tiff_type
);
12959 define_image_type (&gif_type
);
12963 define_image_type (&png_type
);
12965 #endif /* NTEMACS_TODO */
12974 button
= MessageBox (NULL
,
12975 "A fatal error has occurred!\n\n"
12976 "Select Abort to exit, Retry to debug, Ignore to continue",
12977 "Emacs Abort Dialog",
12978 MB_ICONEXCLAMATION
| MB_TASKMODAL
12979 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
12994 /* For convenience when debugging. */
12998 return GetLastError ();