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 */
33 #include "dispextern.h"
39 #include "intervals.h"
41 #include "blockinput.h"
44 #include "termhooks.h"
49 #include "bitmaps/gray.xbm"
55 #define max(a, b) ((a) > (b) ? (a) : (b))
57 extern void free_frame_menubar ();
58 extern double atof ();
59 extern int w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
);
62 /* A definition of XColor for non-X frames. */
63 #ifndef HAVE_X_WINDOWS
66 unsigned short red
, green
, blue
;
72 extern char *lispy_function_keys
[];
74 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
75 it, and including `bitmaps/gray' more than once is a problem when
76 config.h defines `static' as an empty replacement string. */
78 int gray_bitmap_width
= gray_width
;
79 int gray_bitmap_height
= gray_height
;
80 unsigned char *gray_bitmap_bits
= gray_bits
;
82 /* The colormap for converting color names to RGB values */
83 Lisp_Object Vw32_color_map
;
85 /* Non nil if alt key presses are passed on to Windows. */
86 Lisp_Object Vw32_pass_alt_to_system
;
88 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
90 Lisp_Object Vw32_alt_is_meta
;
92 /* If non-zero, the windows virtual key code for an alternative quit key. */
93 Lisp_Object Vw32_quit_key
;
95 /* Non nil if left window key events are passed on to Windows (this only
96 affects whether "tapping" the key opens the Start menu). */
97 Lisp_Object Vw32_pass_lwindow_to_system
;
99 /* Non nil if right window key events are passed on to Windows (this
100 only affects whether "tapping" the key opens the Start menu). */
101 Lisp_Object Vw32_pass_rwindow_to_system
;
103 /* Virtual key code used to generate "phantom" key presses in order
104 to stop system from acting on Windows key events. */
105 Lisp_Object Vw32_phantom_key_code
;
107 /* Modifier associated with the left "Windows" key, or nil to act as a
109 Lisp_Object Vw32_lwindow_modifier
;
111 /* Modifier associated with the right "Windows" key, or nil to act as a
113 Lisp_Object Vw32_rwindow_modifier
;
115 /* Modifier associated with the "Apps" key, or nil to act as a normal
117 Lisp_Object Vw32_apps_modifier
;
119 /* Value is nil if Num Lock acts as a function key. */
120 Lisp_Object Vw32_enable_num_lock
;
122 /* Value is nil if Caps Lock acts as a function key. */
123 Lisp_Object Vw32_enable_caps_lock
;
125 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
126 Lisp_Object Vw32_scroll_lock_modifier
;
128 /* Switch to control whether we inhibit requests for synthesized bold
129 and italic versions of fonts. */
130 Lisp_Object Vw32_enable_synthesized_fonts
;
132 /* Enable palette management. */
133 Lisp_Object Vw32_enable_palette
;
135 /* Control how close left/right button down events must be to
136 be converted to a middle button down event. */
137 Lisp_Object Vw32_mouse_button_tolerance
;
139 /* Minimum interval between mouse movement (and scroll bar drag)
140 events that are passed on to the event loop. */
141 Lisp_Object Vw32_mouse_move_interval
;
143 /* The name we're using in resource queries. */
144 Lisp_Object Vx_resource_name
;
146 /* Non nil if no window manager is in use. */
147 Lisp_Object Vx_no_window_manager
;
149 /* Non-zero means we're allowed to display a busy cursor. */
151 int display_busy_cursor_p
;
153 /* The background and shape of the mouse pointer, and shape when not
154 over text or in the modeline. */
156 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
157 Lisp_Object Vx_busy_pointer_shape
;
159 /* The shape when over mouse-sensitive text. */
161 Lisp_Object Vx_sensitive_text_pointer_shape
;
163 /* Color of chars displayed in cursor box. */
165 Lisp_Object Vx_cursor_fore_pixel
;
167 /* Nonzero if using Windows. */
169 static int w32_in_use
;
171 /* Search path for bitmap files. */
173 Lisp_Object Vx_bitmap_file_path
;
175 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
177 Lisp_Object Vx_pixel_size_width_font_regexp
;
179 /* Alist of bdf fonts and the files that define them. */
180 Lisp_Object Vw32_bdf_filename_alist
;
182 Lisp_Object Vw32_system_coding_system
;
184 /* A flag to control whether fonts are matched strictly or not. */
185 int w32_strict_fontnames
;
187 /* A flag to control whether we should only repaint if GetUpdateRect
188 indicates there is an update region. */
189 int w32_strict_painting
;
191 /* Associative list linking character set strings to Windows codepages. */
192 Lisp_Object Vw32_charset_info_alist
;
194 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
195 #ifndef VIETNAMESE_CHARSET
196 #define VIETNAMESE_CHARSET 163
200 /* Evaluate this expression to rebuild the section of syms_of_w32fns
201 that initializes and staticpros the symbols declared below. Note
202 that Emacs 18 has a bug that keeps C-x C-e from being able to
203 evaluate this expression.
206 ;; Accumulate a list of the symbols we want to initialize from the
207 ;; declarations at the top of the file.
208 (goto-char (point-min))
209 (search-forward "/\*&&& symbols declared here &&&*\/\n")
211 (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
213 (cons (buffer-substring (match-beginning 1) (match-end 1))
216 (setq symbol-list (nreverse symbol-list))
217 ;; Delete the section of syms_of_... where we initialize the symbols.
218 (search-forward "\n /\*&&& init symbols here &&&*\/\n")
219 (let ((start (point)))
220 (while (looking-at "^ Q")
222 (kill-region start (point)))
223 ;; Write a new symbol initialization section.
225 (insert (format " %s = intern (\"" (car symbol-list)))
226 (let ((start (point)))
227 (insert (substring (car symbol-list) 1))
228 (subst-char-in-region start (point) ?_ ?-))
229 (insert (format "\");\n staticpro (&%s);\n" (car symbol-list)))
230 (setq symbol-list (cdr symbol-list)))))
234 /*&&& symbols declared here &&&*/
235 Lisp_Object Qauto_raise
;
236 Lisp_Object Qauto_lower
;
238 Lisp_Object Qborder_color
;
239 Lisp_Object Qborder_width
;
241 Lisp_Object Qcursor_color
;
242 Lisp_Object Qcursor_type
;
243 Lisp_Object Qgeometry
;
244 Lisp_Object Qicon_left
;
245 Lisp_Object Qicon_top
;
246 Lisp_Object Qicon_type
;
247 Lisp_Object Qicon_name
;
248 Lisp_Object Qinternal_border_width
;
251 Lisp_Object Qmouse_color
;
253 Lisp_Object Qparent_id
;
254 Lisp_Object Qscroll_bar_width
;
255 Lisp_Object Qsuppress_icon
;
256 Lisp_Object Qundefined_color
;
257 Lisp_Object Qvertical_scroll_bars
;
258 Lisp_Object Qvisibility
;
259 Lisp_Object Qwindow_id
;
260 Lisp_Object Qx_frame_parameter
;
261 Lisp_Object Qx_resource_name
;
262 Lisp_Object Quser_position
;
263 Lisp_Object Quser_size
;
264 Lisp_Object Qscreen_gamma
;
265 Lisp_Object Qline_spacing
;
272 Lisp_Object Qcontrol
;
275 Lisp_Object Qw32_charset_ansi
;
276 Lisp_Object Qw32_charset_default
;
277 Lisp_Object Qw32_charset_symbol
;
278 Lisp_Object Qw32_charset_shiftjis
;
279 Lisp_Object Qw32_charset_hangeul
;
280 Lisp_Object Qw32_charset_gb2312
;
281 Lisp_Object Qw32_charset_chinesebig5
;
282 Lisp_Object Qw32_charset_oem
;
284 #ifndef JOHAB_CHARSET
285 #define JOHAB_CHARSET 130
288 Lisp_Object Qw32_charset_easteurope
;
289 Lisp_Object Qw32_charset_turkish
;
290 Lisp_Object Qw32_charset_baltic
;
291 Lisp_Object Qw32_charset_russian
;
292 Lisp_Object Qw32_charset_arabic
;
293 Lisp_Object Qw32_charset_greek
;
294 Lisp_Object Qw32_charset_hebrew
;
295 Lisp_Object Qw32_charset_vietnamese
;
296 Lisp_Object Qw32_charset_thai
;
297 Lisp_Object Qw32_charset_johab
;
298 Lisp_Object Qw32_charset_mac
;
301 #ifdef UNICODE_CHARSET
302 Lisp_Object Qw32_charset_unicode
;
305 extern Lisp_Object Qtop
;
306 extern Lisp_Object Qdisplay
;
307 extern Lisp_Object Qtool_bar_lines
;
309 /* State variables for emulating a three button mouse. */
314 static int button_state
= 0;
315 static W32Msg saved_mouse_button_msg
;
316 static unsigned mouse_button_timer
; /* non-zero when timer is active */
317 static W32Msg saved_mouse_move_msg
;
318 static unsigned mouse_move_timer
;
320 /* W95 mousewheel handler */
321 unsigned int msh_mousewheel
= 0;
323 #define MOUSE_BUTTON_ID 1
324 #define MOUSE_MOVE_ID 2
326 /* The below are defined in frame.c. */
328 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
329 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
, Qbuffer_predicate
, Qtitle
;
330 extern Lisp_Object Qtool_bar_lines
;
332 extern Lisp_Object Vwindow_system_version
;
334 Lisp_Object Qface_set_after_frame_default
;
336 /* From w32term.c. */
337 extern Lisp_Object Vw32_num_mouse_buttons
;
338 extern Lisp_Object Vw32_recognize_altgr
;
341 /* Error if we are not connected to MS-Windows. */
346 error ("MS-Windows not in use or not initialized");
349 /* Nonzero if we can use mouse menus.
350 You should not call this unless HAVE_MENUS is defined. */
358 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
359 and checking validity for W32. */
362 check_x_frame (frame
)
368 frame
= selected_frame
;
369 CHECK_LIVE_FRAME (frame
, 0);
371 if (! FRAME_W32_P (f
))
372 error ("non-w32 frame used");
376 /* Let the user specify an display with a frame.
377 nil stands for the selected frame--or, if that is not a w32 frame,
378 the first display on the list. */
380 static struct w32_display_info
*
381 check_x_display_info (frame
)
386 struct frame
*sf
= XFRAME (selected_frame
);
388 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
389 return FRAME_W32_DISPLAY_INFO (sf
);
391 return &one_w32_display_info
;
393 else if (STRINGP (frame
))
394 return x_display_info_for_name (frame
);
399 CHECK_LIVE_FRAME (frame
, 0);
401 if (! FRAME_W32_P (f
))
402 error ("non-w32 frame used");
403 return FRAME_W32_DISPLAY_INFO (f
);
407 /* Return the Emacs frame-object corresponding to an w32 window.
408 It could be the frame's main window or an icon window. */
410 /* This function can be called during GC, so use GC_xxx type test macros. */
413 x_window_to_frame (dpyinfo
, wdesc
)
414 struct w32_display_info
*dpyinfo
;
417 Lisp_Object tail
, frame
;
420 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
423 if (!GC_FRAMEP (frame
))
426 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
428 if (f
->output_data
.w32
->busy_window
== wdesc
)
431 /* TODO: Check tooltips when supported. */
432 if (FRAME_W32_WINDOW (f
) == wdesc
)
440 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
441 id, which is just an int that this section returns. Bitmaps are
442 reference counted so they can be shared among frames.
444 Bitmap indices are guaranteed to be > 0, so a negative number can
445 be used to indicate no bitmap.
447 If you use x_create_bitmap_from_data, then you must keep track of
448 the bitmaps yourself. That is, creating a bitmap from the same
449 data more than once will not be caught. */
452 /* Functions to access the contents of a bitmap, given an id. */
455 x_bitmap_height (f
, id
)
459 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
463 x_bitmap_width (f
, id
)
467 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
471 x_bitmap_pixmap (f
, id
)
475 return (int) FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
479 /* Allocate a new bitmap record. Returns index of new record. */
482 x_allocate_bitmap_record (f
)
485 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
488 if (dpyinfo
->bitmaps
== NULL
)
490 dpyinfo
->bitmaps_size
= 10;
492 = (struct w32_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
493 dpyinfo
->bitmaps_last
= 1;
497 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
498 return ++dpyinfo
->bitmaps_last
;
500 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
501 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
504 dpyinfo
->bitmaps_size
*= 2;
506 = (struct w32_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
507 dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
508 return ++dpyinfo
->bitmaps_last
;
511 /* Add one reference to the reference count of the bitmap with id ID. */
514 x_reference_bitmap (f
, id
)
518 ++FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
521 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
524 x_create_bitmap_from_data (f
, bits
, width
, height
)
527 unsigned int width
, height
;
529 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
533 bitmap
= CreateBitmap (width
, height
,
534 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_planes
,
535 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_cbits
,
541 id
= x_allocate_bitmap_record (f
);
542 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
543 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
544 dpyinfo
->bitmaps
[id
- 1].hinst
= NULL
;
545 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
546 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
547 dpyinfo
->bitmaps
[id
- 1].height
= height
;
548 dpyinfo
->bitmaps
[id
- 1].width
= width
;
553 /* Create bitmap from file FILE for frame F. */
556 x_create_bitmap_from_file (f
, file
)
561 #if 0 /* TODO : bitmap support */
562 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
563 unsigned int width
, height
;
565 int xhot
, yhot
, result
, id
;
571 /* Look for an existing bitmap with the same name. */
572 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
574 if (dpyinfo
->bitmaps
[id
].refcount
575 && dpyinfo
->bitmaps
[id
].file
576 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) XSTRING (file
)->data
))
578 ++dpyinfo
->bitmaps
[id
].refcount
;
583 /* Search bitmap-file-path for the file, if appropriate. */
584 fd
= openp (Vx_bitmap_file_path
, file
, "", &found
, 0);
589 filename
= (char *) XSTRING (found
)->data
;
591 hinst
= LoadLibraryEx (filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
597 result
= XReadBitmapFile (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
598 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
599 if (result
!= BitmapSuccess
)
602 id
= x_allocate_bitmap_record (f
);
603 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
604 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
605 dpyinfo
->bitmaps
[id
- 1].file
= (char *) xmalloc (XSTRING (file
)->size
+ 1);
606 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
607 dpyinfo
->bitmaps
[id
- 1].height
= height
;
608 dpyinfo
->bitmaps
[id
- 1].width
= width
;
609 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, XSTRING (file
)->data
);
615 /* Remove reference to bitmap with id number ID. */
618 x_destroy_bitmap (f
, id
)
622 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
626 --dpyinfo
->bitmaps
[id
- 1].refcount
;
627 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
630 DeleteObject (dpyinfo
->bitmaps
[id
- 1].pixmap
);
631 if (dpyinfo
->bitmaps
[id
- 1].file
)
633 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
634 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
641 /* Free all the bitmaps for the display specified by DPYINFO. */
644 x_destroy_all_bitmaps (dpyinfo
)
645 struct w32_display_info
*dpyinfo
;
648 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
649 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
651 DeleteObject (dpyinfo
->bitmaps
[i
].pixmap
);
652 if (dpyinfo
->bitmaps
[i
].file
)
653 xfree (dpyinfo
->bitmaps
[i
].file
);
655 dpyinfo
->bitmaps_last
= 0;
658 /* Connect the frame-parameter names for W32 frames
659 to the ways of passing the parameter values to the window system.
661 The name of a parameter, as a Lisp symbol,
662 has an `x-frame-parameter' property which is an integer in Lisp
663 but can be interpreted as an `enum x_frame_parm' in C. */
667 X_PARM_FOREGROUND_COLOR
,
668 X_PARM_BACKGROUND_COLOR
,
675 X_PARM_INTERNAL_BORDER_WIDTH
,
679 X_PARM_VERT_SCROLL_BAR
,
681 X_PARM_MENU_BAR_LINES
685 struct x_frame_parm_table
688 void (*setter
) P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
691 /* TODO: Native Input Method support; see x_create_im. */
692 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
693 static void x_set_line_spacing
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
694 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
695 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
696 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
697 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
698 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
699 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
700 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
701 void x_set_font
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
702 void x_set_border_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
703 void x_set_internal_border_width
P_ ((struct frame
*, Lisp_Object
,
705 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
706 void x_set_autoraise
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
707 void x_set_autolower
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
708 void x_set_vertical_scroll_bars
P_ ((struct frame
*, Lisp_Object
,
710 void x_set_visibility
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
711 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
712 void x_set_scroll_bar_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
713 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
714 void x_set_unsplittable
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
715 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
716 static void x_set_screen_gamma
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
718 static struct x_frame_parm_table x_frame_parms
[] =
720 "auto-raise", x_set_autoraise
,
721 "auto-lower", x_set_autolower
,
722 "background-color", x_set_background_color
,
723 "border-color", x_set_border_color
,
724 "border-width", x_set_border_width
,
725 "cursor-color", x_set_cursor_color
,
726 "cursor-type", x_set_cursor_type
,
728 "foreground-color", x_set_foreground_color
,
729 "icon-name", x_set_icon_name
,
730 "icon-type", x_set_icon_type
,
731 "internal-border-width", x_set_internal_border_width
,
732 "menu-bar-lines", x_set_menu_bar_lines
,
733 "mouse-color", x_set_mouse_color
,
734 "name", x_explicitly_set_name
,
735 "scroll-bar-width", x_set_scroll_bar_width
,
736 "title", x_set_title
,
737 "unsplittable", x_set_unsplittable
,
738 "vertical-scroll-bars", x_set_vertical_scroll_bars
,
739 "visibility", x_set_visibility
,
740 "tool-bar-lines", x_set_tool_bar_lines
,
741 "screen-gamma", x_set_screen_gamma
,
742 "line-spacing", x_set_line_spacing
745 /* Attach the `x-frame-parameter' properties to
746 the Lisp symbol names of parameters relevant to W32. */
749 init_x_parm_symbols ()
753 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
754 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
758 /* Change the parameters of frame F as specified by ALIST.
759 If a parameter is not specially recognized, do nothing;
760 otherwise call the `x_set_...' function for that parameter. */
763 x_set_frame_parameters (f
, alist
)
769 /* If both of these parameters are present, it's more efficient to
770 set them both at once. So we wait until we've looked at the
771 entire list before we set them. */
775 Lisp_Object left
, top
;
777 /* Same with these. */
778 Lisp_Object icon_left
, icon_top
;
780 /* Record in these vectors all the parms specified. */
784 int left_no_change
= 0, top_no_change
= 0;
785 int icon_left_no_change
= 0, icon_top_no_change
= 0;
787 struct gcpro gcpro1
, gcpro2
;
790 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
793 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
794 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
796 /* Extract parm names and values into those vectors. */
799 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
804 parms
[i
] = Fcar (elt
);
805 values
[i
] = Fcdr (elt
);
808 /* TAIL and ALIST are not used again below here. */
811 GCPRO2 (*parms
, *values
);
815 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
816 because their values appear in VALUES and strings are not valid. */
817 top
= left
= Qunbound
;
818 icon_left
= icon_top
= Qunbound
;
820 /* Provide default values for HEIGHT and WIDTH. */
821 if (FRAME_NEW_WIDTH (f
))
822 width
= FRAME_NEW_WIDTH (f
);
824 width
= FRAME_WIDTH (f
);
826 if (FRAME_NEW_HEIGHT (f
))
827 height
= FRAME_NEW_HEIGHT (f
);
829 height
= FRAME_HEIGHT (f
);
831 /* Process foreground_color and background_color before anything else.
832 They are independent of other properties, but other properties (e.g.,
833 cursor_color) are dependent upon them. */
834 for (p
= 0; p
< i
; p
++)
836 Lisp_Object prop
, val
;
840 if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
842 register Lisp_Object param_index
, old_value
;
844 param_index
= Fget (prop
, Qx_frame_parameter
);
845 old_value
= get_frame_param (f
, prop
);
846 store_frame_param (f
, prop
, val
);
847 if (NATNUMP (param_index
)
848 && (XFASTINT (param_index
)
849 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
850 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
854 /* Now process them in reverse of specified order. */
855 for (i
--; i
>= 0; i
--)
857 Lisp_Object prop
, val
;
862 if (EQ (prop
, Qwidth
) && NUMBERP (val
))
863 width
= XFASTINT (val
);
864 else if (EQ (prop
, Qheight
) && NUMBERP (val
))
865 height
= XFASTINT (val
);
866 else if (EQ (prop
, Qtop
))
868 else if (EQ (prop
, Qleft
))
870 else if (EQ (prop
, Qicon_top
))
872 else if (EQ (prop
, Qicon_left
))
874 else if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
875 /* Processed above. */
879 register Lisp_Object param_index
, old_value
;
881 param_index
= Fget (prop
, Qx_frame_parameter
);
882 old_value
= get_frame_param (f
, prop
);
883 store_frame_param (f
, prop
, val
);
884 if (NATNUMP (param_index
)
885 && (XFASTINT (param_index
)
886 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
887 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
891 /* Don't die if just one of these was set. */
892 if (EQ (left
, Qunbound
))
895 if (f
->output_data
.w32
->left_pos
< 0)
896 left
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->left_pos
), Qnil
));
898 XSETINT (left
, f
->output_data
.w32
->left_pos
);
900 if (EQ (top
, Qunbound
))
903 if (f
->output_data
.w32
->top_pos
< 0)
904 top
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->top_pos
), Qnil
));
906 XSETINT (top
, f
->output_data
.w32
->top_pos
);
909 /* If one of the icon positions was not set, preserve or default it. */
910 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
912 icon_left_no_change
= 1;
913 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
914 if (NILP (icon_left
))
915 XSETINT (icon_left
, 0);
917 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
919 icon_top_no_change
= 1;
920 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
922 XSETINT (icon_top
, 0);
925 /* Don't set these parameters unless they've been explicitly
926 specified. The window might be mapped or resized while we're in
927 this function, and we don't want to override that unless the lisp
928 code has asked for it.
930 Don't set these parameters unless they actually differ from the
931 window's current parameters; the window may not actually exist
936 check_frame_size (f
, &height
, &width
);
938 XSETFRAME (frame
, f
);
940 if (width
!= FRAME_WIDTH (f
)
941 || height
!= FRAME_HEIGHT (f
)
942 || FRAME_NEW_HEIGHT (f
) || FRAME_NEW_WIDTH (f
))
943 Fset_frame_size (frame
, make_number (width
), make_number (height
));
945 if ((!NILP (left
) || !NILP (top
))
946 && ! (left_no_change
&& top_no_change
)
947 && ! (NUMBERP (left
) && XINT (left
) == f
->output_data
.w32
->left_pos
948 && NUMBERP (top
) && XINT (top
) == f
->output_data
.w32
->top_pos
))
953 /* Record the signs. */
954 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
955 if (EQ (left
, Qminus
))
956 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
957 else if (INTEGERP (left
))
959 leftpos
= XINT (left
);
961 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
963 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
964 && CONSP (XCDR (left
))
965 && INTEGERP (XCAR (XCDR (left
))))
967 leftpos
= - XINT (XCAR (XCDR (left
)));
968 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
970 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
971 && CONSP (XCDR (left
))
972 && INTEGERP (XCAR (XCDR (left
))))
974 leftpos
= XINT (XCAR (XCDR (left
)));
977 if (EQ (top
, Qminus
))
978 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
979 else if (INTEGERP (top
))
983 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
985 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
986 && CONSP (XCDR (top
))
987 && INTEGERP (XCAR (XCDR (top
))))
989 toppos
= - XINT (XCAR (XCDR (top
)));
990 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
992 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
993 && CONSP (XCDR (top
))
994 && INTEGERP (XCAR (XCDR (top
))))
996 toppos
= XINT (XCAR (XCDR (top
)));
1000 /* Store the numeric value of the position. */
1001 f
->output_data
.w32
->top_pos
= toppos
;
1002 f
->output_data
.w32
->left_pos
= leftpos
;
1004 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
1006 /* Actually set that position, and convert to absolute. */
1007 x_set_offset (f
, leftpos
, toppos
, -1);
1010 if ((!NILP (icon_left
) || !NILP (icon_top
))
1011 && ! (icon_left_no_change
&& icon_top_no_change
))
1012 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
1018 /* Store the screen positions of frame F into XPTR and YPTR.
1019 These are the positions of the containing window manager window,
1020 not Emacs's own window. */
1023 x_real_positions (f
, xptr
, yptr
)
1032 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
1033 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
1039 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
1045 /* Insert a description of internally-recorded parameters of frame X
1046 into the parameter alist *ALISTPTR that is to be given to the user.
1047 Only parameters that are specific to W32
1048 and whose values are not correctly recorded in the frame's
1049 param_alist need to be considered here. */
1052 x_report_frame_params (f
, alistptr
)
1054 Lisp_Object
*alistptr
;
1059 /* Represent negative positions (off the top or left screen edge)
1060 in a way that Fmodify_frame_parameters will understand correctly. */
1061 XSETINT (tem
, f
->output_data
.w32
->left_pos
);
1062 if (f
->output_data
.w32
->left_pos
>= 0)
1063 store_in_alist (alistptr
, Qleft
, tem
);
1065 store_in_alist (alistptr
, Qleft
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1067 XSETINT (tem
, f
->output_data
.w32
->top_pos
);
1068 if (f
->output_data
.w32
->top_pos
>= 0)
1069 store_in_alist (alistptr
, Qtop
, tem
);
1071 store_in_alist (alistptr
, Qtop
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1073 store_in_alist (alistptr
, Qborder_width
,
1074 make_number (f
->output_data
.w32
->border_width
));
1075 store_in_alist (alistptr
, Qinternal_border_width
,
1076 make_number (f
->output_data
.w32
->internal_border_width
));
1077 sprintf (buf
, "%ld", (long) FRAME_W32_WINDOW (f
));
1078 store_in_alist (alistptr
, Qwindow_id
,
1079 build_string (buf
));
1080 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
1081 FRAME_SAMPLE_VISIBILITY (f
);
1082 store_in_alist (alistptr
, Qvisibility
,
1083 (FRAME_VISIBLE_P (f
) ? Qt
1084 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
1085 store_in_alist (alistptr
, Qdisplay
,
1086 XCAR (FRAME_W32_DISPLAY_INFO (f
)->name_list_element
));
1090 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
, Sw32_define_rgb_color
, 4, 4, 0,
1091 "Convert RGB numbers to a windows color reference and associate with NAME (a string).\n\
1092 This adds or updates a named color to w32-color-map, making it available for use.\n\
1093 The original entry's RGB ref is returned, or nil if the entry is new.")
1094 (red
, green
, blue
, name
)
1095 Lisp_Object red
, green
, blue
, name
;
1098 Lisp_Object oldrgb
= Qnil
;
1101 CHECK_NUMBER (red
, 0);
1102 CHECK_NUMBER (green
, 0);
1103 CHECK_NUMBER (blue
, 0);
1104 CHECK_STRING (name
, 0);
1106 XSET (rgb
, Lisp_Int
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
1110 /* replace existing entry in w32-color-map or add new entry. */
1111 entry
= Fassoc (name
, Vw32_color_map
);
1114 entry
= Fcons (name
, rgb
);
1115 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
1119 oldrgb
= Fcdr (entry
);
1120 Fsetcdr (entry
, rgb
);
1128 DEFUN ("w32-load-color-file", Fw32_load_color_file
, Sw32_load_color_file
, 1, 1, 0,
1129 "Create an alist of color entries from an external file (ie. rgb.txt).\n\
1130 Assign this value to w32-color-map to replace the existing color map.\n\
1132 The file should define one named RGB color per line like so:\
1134 where R,G,B are numbers between 0 and 255 and name is an arbitrary string.")
1136 Lisp_Object filename
;
1139 Lisp_Object cmap
= Qnil
;
1140 Lisp_Object abspath
;
1142 CHECK_STRING (filename
, 0);
1143 abspath
= Fexpand_file_name (filename
, Qnil
);
1145 fp
= fopen (XSTRING (filename
)->data
, "rt");
1149 int red
, green
, blue
;
1154 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
1155 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
1157 char *name
= buf
+ num
;
1158 num
= strlen (name
) - 1;
1159 if (name
[num
] == '\n')
1161 cmap
= Fcons (Fcons (build_string (name
),
1162 make_number (RGB (red
, green
, blue
))),
1174 /* The default colors for the w32 color map */
1175 typedef struct colormap_t
1181 colormap_t w32_color_map
[] =
1183 {"snow" , PALETTERGB (255,250,250)},
1184 {"ghost white" , PALETTERGB (248,248,255)},
1185 {"GhostWhite" , PALETTERGB (248,248,255)},
1186 {"white smoke" , PALETTERGB (245,245,245)},
1187 {"WhiteSmoke" , PALETTERGB (245,245,245)},
1188 {"gainsboro" , PALETTERGB (220,220,220)},
1189 {"floral white" , PALETTERGB (255,250,240)},
1190 {"FloralWhite" , PALETTERGB (255,250,240)},
1191 {"old lace" , PALETTERGB (253,245,230)},
1192 {"OldLace" , PALETTERGB (253,245,230)},
1193 {"linen" , PALETTERGB (250,240,230)},
1194 {"antique white" , PALETTERGB (250,235,215)},
1195 {"AntiqueWhite" , PALETTERGB (250,235,215)},
1196 {"papaya whip" , PALETTERGB (255,239,213)},
1197 {"PapayaWhip" , PALETTERGB (255,239,213)},
1198 {"blanched almond" , PALETTERGB (255,235,205)},
1199 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
1200 {"bisque" , PALETTERGB (255,228,196)},
1201 {"peach puff" , PALETTERGB (255,218,185)},
1202 {"PeachPuff" , PALETTERGB (255,218,185)},
1203 {"navajo white" , PALETTERGB (255,222,173)},
1204 {"NavajoWhite" , PALETTERGB (255,222,173)},
1205 {"moccasin" , PALETTERGB (255,228,181)},
1206 {"cornsilk" , PALETTERGB (255,248,220)},
1207 {"ivory" , PALETTERGB (255,255,240)},
1208 {"lemon chiffon" , PALETTERGB (255,250,205)},
1209 {"LemonChiffon" , PALETTERGB (255,250,205)},
1210 {"seashell" , PALETTERGB (255,245,238)},
1211 {"honeydew" , PALETTERGB (240,255,240)},
1212 {"mint cream" , PALETTERGB (245,255,250)},
1213 {"MintCream" , PALETTERGB (245,255,250)},
1214 {"azure" , PALETTERGB (240,255,255)},
1215 {"alice blue" , PALETTERGB (240,248,255)},
1216 {"AliceBlue" , PALETTERGB (240,248,255)},
1217 {"lavender" , PALETTERGB (230,230,250)},
1218 {"lavender blush" , PALETTERGB (255,240,245)},
1219 {"LavenderBlush" , PALETTERGB (255,240,245)},
1220 {"misty rose" , PALETTERGB (255,228,225)},
1221 {"MistyRose" , PALETTERGB (255,228,225)},
1222 {"white" , PALETTERGB (255,255,255)},
1223 {"black" , PALETTERGB ( 0, 0, 0)},
1224 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
1225 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
1226 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
1227 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
1228 {"dim gray" , PALETTERGB (105,105,105)},
1229 {"DimGray" , PALETTERGB (105,105,105)},
1230 {"dim grey" , PALETTERGB (105,105,105)},
1231 {"DimGrey" , PALETTERGB (105,105,105)},
1232 {"slate gray" , PALETTERGB (112,128,144)},
1233 {"SlateGray" , PALETTERGB (112,128,144)},
1234 {"slate grey" , PALETTERGB (112,128,144)},
1235 {"SlateGrey" , PALETTERGB (112,128,144)},
1236 {"light slate gray" , PALETTERGB (119,136,153)},
1237 {"LightSlateGray" , PALETTERGB (119,136,153)},
1238 {"light slate grey" , PALETTERGB (119,136,153)},
1239 {"LightSlateGrey" , PALETTERGB (119,136,153)},
1240 {"gray" , PALETTERGB (190,190,190)},
1241 {"grey" , PALETTERGB (190,190,190)},
1242 {"light grey" , PALETTERGB (211,211,211)},
1243 {"LightGrey" , PALETTERGB (211,211,211)},
1244 {"light gray" , PALETTERGB (211,211,211)},
1245 {"LightGray" , PALETTERGB (211,211,211)},
1246 {"midnight blue" , PALETTERGB ( 25, 25,112)},
1247 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
1248 {"navy" , PALETTERGB ( 0, 0,128)},
1249 {"navy blue" , PALETTERGB ( 0, 0,128)},
1250 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
1251 {"cornflower blue" , PALETTERGB (100,149,237)},
1252 {"CornflowerBlue" , PALETTERGB (100,149,237)},
1253 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
1254 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
1255 {"slate blue" , PALETTERGB (106, 90,205)},
1256 {"SlateBlue" , PALETTERGB (106, 90,205)},
1257 {"medium slate blue" , PALETTERGB (123,104,238)},
1258 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
1259 {"light slate blue" , PALETTERGB (132,112,255)},
1260 {"LightSlateBlue" , PALETTERGB (132,112,255)},
1261 {"medium blue" , PALETTERGB ( 0, 0,205)},
1262 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
1263 {"royal blue" , PALETTERGB ( 65,105,225)},
1264 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
1265 {"blue" , PALETTERGB ( 0, 0,255)},
1266 {"dodger blue" , PALETTERGB ( 30,144,255)},
1267 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
1268 {"deep sky blue" , PALETTERGB ( 0,191,255)},
1269 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
1270 {"sky blue" , PALETTERGB (135,206,235)},
1271 {"SkyBlue" , PALETTERGB (135,206,235)},
1272 {"light sky blue" , PALETTERGB (135,206,250)},
1273 {"LightSkyBlue" , PALETTERGB (135,206,250)},
1274 {"steel blue" , PALETTERGB ( 70,130,180)},
1275 {"SteelBlue" , PALETTERGB ( 70,130,180)},
1276 {"light steel blue" , PALETTERGB (176,196,222)},
1277 {"LightSteelBlue" , PALETTERGB (176,196,222)},
1278 {"light blue" , PALETTERGB (173,216,230)},
1279 {"LightBlue" , PALETTERGB (173,216,230)},
1280 {"powder blue" , PALETTERGB (176,224,230)},
1281 {"PowderBlue" , PALETTERGB (176,224,230)},
1282 {"pale turquoise" , PALETTERGB (175,238,238)},
1283 {"PaleTurquoise" , PALETTERGB (175,238,238)},
1284 {"dark turquoise" , PALETTERGB ( 0,206,209)},
1285 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
1286 {"medium turquoise" , PALETTERGB ( 72,209,204)},
1287 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
1288 {"turquoise" , PALETTERGB ( 64,224,208)},
1289 {"cyan" , PALETTERGB ( 0,255,255)},
1290 {"light cyan" , PALETTERGB (224,255,255)},
1291 {"LightCyan" , PALETTERGB (224,255,255)},
1292 {"cadet blue" , PALETTERGB ( 95,158,160)},
1293 {"CadetBlue" , PALETTERGB ( 95,158,160)},
1294 {"medium aquamarine" , PALETTERGB (102,205,170)},
1295 {"MediumAquamarine" , PALETTERGB (102,205,170)},
1296 {"aquamarine" , PALETTERGB (127,255,212)},
1297 {"dark green" , PALETTERGB ( 0,100, 0)},
1298 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
1299 {"dark olive green" , PALETTERGB ( 85,107, 47)},
1300 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
1301 {"dark sea green" , PALETTERGB (143,188,143)},
1302 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
1303 {"sea green" , PALETTERGB ( 46,139, 87)},
1304 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
1305 {"medium sea green" , PALETTERGB ( 60,179,113)},
1306 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
1307 {"light sea green" , PALETTERGB ( 32,178,170)},
1308 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
1309 {"pale green" , PALETTERGB (152,251,152)},
1310 {"PaleGreen" , PALETTERGB (152,251,152)},
1311 {"spring green" , PALETTERGB ( 0,255,127)},
1312 {"SpringGreen" , PALETTERGB ( 0,255,127)},
1313 {"lawn green" , PALETTERGB (124,252, 0)},
1314 {"LawnGreen" , PALETTERGB (124,252, 0)},
1315 {"green" , PALETTERGB ( 0,255, 0)},
1316 {"chartreuse" , PALETTERGB (127,255, 0)},
1317 {"medium spring green" , PALETTERGB ( 0,250,154)},
1318 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
1319 {"green yellow" , PALETTERGB (173,255, 47)},
1320 {"GreenYellow" , PALETTERGB (173,255, 47)},
1321 {"lime green" , PALETTERGB ( 50,205, 50)},
1322 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
1323 {"yellow green" , PALETTERGB (154,205, 50)},
1324 {"YellowGreen" , PALETTERGB (154,205, 50)},
1325 {"forest green" , PALETTERGB ( 34,139, 34)},
1326 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
1327 {"olive drab" , PALETTERGB (107,142, 35)},
1328 {"OliveDrab" , PALETTERGB (107,142, 35)},
1329 {"dark khaki" , PALETTERGB (189,183,107)},
1330 {"DarkKhaki" , PALETTERGB (189,183,107)},
1331 {"khaki" , PALETTERGB (240,230,140)},
1332 {"pale goldenrod" , PALETTERGB (238,232,170)},
1333 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
1334 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
1335 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
1336 {"light yellow" , PALETTERGB (255,255,224)},
1337 {"LightYellow" , PALETTERGB (255,255,224)},
1338 {"yellow" , PALETTERGB (255,255, 0)},
1339 {"gold" , PALETTERGB (255,215, 0)},
1340 {"light goldenrod" , PALETTERGB (238,221,130)},
1341 {"LightGoldenrod" , PALETTERGB (238,221,130)},
1342 {"goldenrod" , PALETTERGB (218,165, 32)},
1343 {"dark goldenrod" , PALETTERGB (184,134, 11)},
1344 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
1345 {"rosy brown" , PALETTERGB (188,143,143)},
1346 {"RosyBrown" , PALETTERGB (188,143,143)},
1347 {"indian red" , PALETTERGB (205, 92, 92)},
1348 {"IndianRed" , PALETTERGB (205, 92, 92)},
1349 {"saddle brown" , PALETTERGB (139, 69, 19)},
1350 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
1351 {"sienna" , PALETTERGB (160, 82, 45)},
1352 {"peru" , PALETTERGB (205,133, 63)},
1353 {"burlywood" , PALETTERGB (222,184,135)},
1354 {"beige" , PALETTERGB (245,245,220)},
1355 {"wheat" , PALETTERGB (245,222,179)},
1356 {"sandy brown" , PALETTERGB (244,164, 96)},
1357 {"SandyBrown" , PALETTERGB (244,164, 96)},
1358 {"tan" , PALETTERGB (210,180,140)},
1359 {"chocolate" , PALETTERGB (210,105, 30)},
1360 {"firebrick" , PALETTERGB (178,34, 34)},
1361 {"brown" , PALETTERGB (165,42, 42)},
1362 {"dark salmon" , PALETTERGB (233,150,122)},
1363 {"DarkSalmon" , PALETTERGB (233,150,122)},
1364 {"salmon" , PALETTERGB (250,128,114)},
1365 {"light salmon" , PALETTERGB (255,160,122)},
1366 {"LightSalmon" , PALETTERGB (255,160,122)},
1367 {"orange" , PALETTERGB (255,165, 0)},
1368 {"dark orange" , PALETTERGB (255,140, 0)},
1369 {"DarkOrange" , PALETTERGB (255,140, 0)},
1370 {"coral" , PALETTERGB (255,127, 80)},
1371 {"light coral" , PALETTERGB (240,128,128)},
1372 {"LightCoral" , PALETTERGB (240,128,128)},
1373 {"tomato" , PALETTERGB (255, 99, 71)},
1374 {"orange red" , PALETTERGB (255, 69, 0)},
1375 {"OrangeRed" , PALETTERGB (255, 69, 0)},
1376 {"red" , PALETTERGB (255, 0, 0)},
1377 {"hot pink" , PALETTERGB (255,105,180)},
1378 {"HotPink" , PALETTERGB (255,105,180)},
1379 {"deep pink" , PALETTERGB (255, 20,147)},
1380 {"DeepPink" , PALETTERGB (255, 20,147)},
1381 {"pink" , PALETTERGB (255,192,203)},
1382 {"light pink" , PALETTERGB (255,182,193)},
1383 {"LightPink" , PALETTERGB (255,182,193)},
1384 {"pale violet red" , PALETTERGB (219,112,147)},
1385 {"PaleVioletRed" , PALETTERGB (219,112,147)},
1386 {"maroon" , PALETTERGB (176, 48, 96)},
1387 {"medium violet red" , PALETTERGB (199, 21,133)},
1388 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
1389 {"violet red" , PALETTERGB (208, 32,144)},
1390 {"VioletRed" , PALETTERGB (208, 32,144)},
1391 {"magenta" , PALETTERGB (255, 0,255)},
1392 {"violet" , PALETTERGB (238,130,238)},
1393 {"plum" , PALETTERGB (221,160,221)},
1394 {"orchid" , PALETTERGB (218,112,214)},
1395 {"medium orchid" , PALETTERGB (186, 85,211)},
1396 {"MediumOrchid" , PALETTERGB (186, 85,211)},
1397 {"dark orchid" , PALETTERGB (153, 50,204)},
1398 {"DarkOrchid" , PALETTERGB (153, 50,204)},
1399 {"dark violet" , PALETTERGB (148, 0,211)},
1400 {"DarkViolet" , PALETTERGB (148, 0,211)},
1401 {"blue violet" , PALETTERGB (138, 43,226)},
1402 {"BlueViolet" , PALETTERGB (138, 43,226)},
1403 {"purple" , PALETTERGB (160, 32,240)},
1404 {"medium purple" , PALETTERGB (147,112,219)},
1405 {"MediumPurple" , PALETTERGB (147,112,219)},
1406 {"thistle" , PALETTERGB (216,191,216)},
1407 {"gray0" , PALETTERGB ( 0, 0, 0)},
1408 {"grey0" , PALETTERGB ( 0, 0, 0)},
1409 {"dark grey" , PALETTERGB (169,169,169)},
1410 {"DarkGrey" , PALETTERGB (169,169,169)},
1411 {"dark gray" , PALETTERGB (169,169,169)},
1412 {"DarkGray" , PALETTERGB (169,169,169)},
1413 {"dark blue" , PALETTERGB ( 0, 0,139)},
1414 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
1415 {"dark cyan" , PALETTERGB ( 0,139,139)},
1416 {"DarkCyan" , PALETTERGB ( 0,139,139)},
1417 {"dark magenta" , PALETTERGB (139, 0,139)},
1418 {"DarkMagenta" , PALETTERGB (139, 0,139)},
1419 {"dark red" , PALETTERGB (139, 0, 0)},
1420 {"DarkRed" , PALETTERGB (139, 0, 0)},
1421 {"light green" , PALETTERGB (144,238,144)},
1422 {"LightGreen" , PALETTERGB (144,238,144)},
1425 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
1426 0, 0, 0, "Return the default color map.")
1430 colormap_t
*pc
= w32_color_map
;
1437 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
1439 cmap
= Fcons (Fcons (build_string (pc
->name
),
1440 make_number (pc
->colorref
)),
1449 w32_to_x_color (rgb
)
1454 CHECK_NUMBER (rgb
, 0);
1458 color
= Frassq (rgb
, Vw32_color_map
);
1463 return (Fcar (color
));
1469 w32_color_map_lookup (colorname
)
1472 Lisp_Object tail
, ret
= Qnil
;
1476 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
1478 register Lisp_Object elt
, tem
;
1481 if (!CONSP (elt
)) continue;
1485 if (lstrcmpi (XSTRING (tem
)->data
, colorname
) == 0)
1487 ret
= XUINT (Fcdr (elt
));
1501 x_to_w32_color (colorname
)
1504 register Lisp_Object tail
, ret
= Qnil
;
1508 if (colorname
[0] == '#')
1510 /* Could be an old-style RGB Device specification. */
1513 color
= colorname
+ 1;
1515 size
= strlen(color
);
1516 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
1524 for (i
= 0; i
< 3; i
++)
1528 unsigned long value
;
1530 /* The check for 'x' in the following conditional takes into
1531 account the fact that strtol allows a "0x" in front of
1532 our numbers, and we don't. */
1533 if (!isxdigit(color
[0]) || color
[1] == 'x')
1537 value
= strtoul(color
, &end
, 16);
1539 if (errno
== ERANGE
|| end
- color
!= size
)
1544 value
= value
* 0x10;
1555 colorval
|= (value
<< pos
);
1566 else if (strnicmp(colorname
, "rgb:", 4) == 0)
1574 color
= colorname
+ 4;
1575 for (i
= 0; i
< 3; i
++)
1578 unsigned long value
;
1580 /* The check for 'x' in the following conditional takes into
1581 account the fact that strtol allows a "0x" in front of
1582 our numbers, and we don't. */
1583 if (!isxdigit(color
[0]) || color
[1] == 'x')
1585 value
= strtoul(color
, &end
, 16);
1586 if (errno
== ERANGE
)
1588 switch (end
- color
)
1591 value
= value
* 0x10 + value
;
1604 if (value
== ULONG_MAX
)
1606 colorval
|= (value
<< pos
);
1620 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1622 /* This is an RGB Intensity specification. */
1629 color
= colorname
+ 5;
1630 for (i
= 0; i
< 3; i
++)
1636 value
= strtod(color
, &end
);
1637 if (errno
== ERANGE
)
1639 if (value
< 0.0 || value
> 1.0)
1641 val
= (UINT
)(0x100 * value
);
1642 /* We used 0x100 instead of 0xFF to give an continuous
1643 range between 0.0 and 1.0 inclusive. The next statement
1644 fixes the 1.0 case. */
1647 colorval
|= (val
<< pos
);
1661 /* I am not going to attempt to handle any of the CIE color schemes
1662 or TekHVC, since I don't know the algorithms for conversion to
1665 /* If we fail to lookup the color name in w32_color_map, then check the
1666 colorname to see if it can be crudely approximated: If the X color
1667 ends in a number (e.g., "darkseagreen2"), strip the number and
1668 return the result of looking up the base color name. */
1669 ret
= w32_color_map_lookup (colorname
);
1672 int len
= strlen (colorname
);
1674 if (isdigit (colorname
[len
- 1]))
1676 char *ptr
, *approx
= alloca (len
);
1678 strcpy (approx
, colorname
);
1679 ptr
= &approx
[len
- 1];
1680 while (ptr
> approx
&& isdigit (*ptr
))
1683 ret
= w32_color_map_lookup (approx
);
1693 w32_regenerate_palette (FRAME_PTR f
)
1695 struct w32_palette_entry
* list
;
1696 LOGPALETTE
* log_palette
;
1697 HPALETTE new_palette
;
1700 /* don't bother trying to create palette if not supported */
1701 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1704 log_palette
= (LOGPALETTE
*)
1705 alloca (sizeof (LOGPALETTE
) +
1706 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1707 log_palette
->palVersion
= 0x300;
1708 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1710 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1712 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1713 i
++, list
= list
->next
)
1714 log_palette
->palPalEntry
[i
] = list
->entry
;
1716 new_palette
= CreatePalette (log_palette
);
1720 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1721 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1722 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1724 /* Realize display palette and garbage all frames. */
1725 release_frame_dc (f
, get_frame_dc (f
));
1730 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1731 #define SET_W32_COLOR(pe, color) \
1734 pe.peRed = GetRValue (color); \
1735 pe.peGreen = GetGValue (color); \
1736 pe.peBlue = GetBValue (color); \
1741 /* Keep these around in case we ever want to track color usage. */
1743 w32_map_color (FRAME_PTR f
, COLORREF color
)
1745 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1747 if (NILP (Vw32_enable_palette
))
1750 /* check if color is already mapped */
1753 if (W32_COLOR (list
->entry
) == color
)
1761 /* not already mapped, so add to list and recreate Windows palette */
1762 list
= (struct w32_palette_entry
*)
1763 xmalloc (sizeof (struct w32_palette_entry
));
1764 SET_W32_COLOR (list
->entry
, color
);
1766 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1767 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1768 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1770 /* set flag that palette must be regenerated */
1771 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1775 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1777 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1778 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1780 if (NILP (Vw32_enable_palette
))
1783 /* check if color is already mapped */
1786 if (W32_COLOR (list
->entry
) == color
)
1788 if (--list
->refcount
== 0)
1792 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1802 /* set flag that palette must be regenerated */
1803 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1808 /* Gamma-correct COLOR on frame F. */
1811 gamma_correct (f
, color
)
1817 *color
= PALETTERGB (
1818 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1819 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1820 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1825 /* Decide if color named COLOR is valid for the display associated with
1826 the selected frame; if so, return the rgb values in COLOR_DEF.
1827 If ALLOC is nonzero, allocate a new colormap cell. */
1830 w32_defined_color (f
, color
, color_def
, alloc
)
1836 register Lisp_Object tem
;
1837 COLORREF w32_color_ref
;
1839 tem
= x_to_w32_color (color
);
1845 /* Apply gamma correction. */
1846 w32_color_ref
= XUINT (tem
);
1847 gamma_correct (f
, &w32_color_ref
);
1848 XSETINT (tem
, w32_color_ref
);
1851 /* Map this color to the palette if it is enabled. */
1852 if (!NILP (Vw32_enable_palette
))
1854 struct w32_palette_entry
* entry
=
1855 one_w32_display_info
.color_list
;
1856 struct w32_palette_entry
** prev
=
1857 &one_w32_display_info
.color_list
;
1859 /* check if color is already mapped */
1862 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1864 prev
= &entry
->next
;
1865 entry
= entry
->next
;
1868 if (entry
== NULL
&& alloc
)
1870 /* not already mapped, so add to list */
1871 entry
= (struct w32_palette_entry
*)
1872 xmalloc (sizeof (struct w32_palette_entry
));
1873 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1876 one_w32_display_info
.num_colors
++;
1878 /* set flag that palette must be regenerated */
1879 one_w32_display_info
.regen_palette
= TRUE
;
1882 /* Ensure COLORREF value is snapped to nearest color in (default)
1883 palette by simulating the PALETTERGB macro. This works whether
1884 or not the display device has a palette. */
1885 w32_color_ref
= XUINT (tem
) | 0x2000000;
1887 color_def
->pixel
= w32_color_ref
;
1888 color_def
->red
= GetRValue (w32_color_ref
);
1889 color_def
->green
= GetGValue (w32_color_ref
);
1890 color_def
->blue
= GetBValue (w32_color_ref
);
1900 /* Given a string ARG naming a color, compute a pixel value from it
1901 suitable for screen F.
1902 If F is not a color screen, return DEF (default) regardless of what
1906 x_decode_color (f
, arg
, def
)
1913 CHECK_STRING (arg
, 0);
1915 if (strcmp (XSTRING (arg
)->data
, "black") == 0)
1916 return BLACK_PIX_DEFAULT (f
);
1917 else if (strcmp (XSTRING (arg
)->data
, "white") == 0)
1918 return WHITE_PIX_DEFAULT (f
);
1920 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1923 /* w32_defined_color is responsible for coping with failures
1924 by looking for a near-miss. */
1925 if (w32_defined_color (f
, XSTRING (arg
)->data
, &cdef
, 1))
1928 /* defined_color failed; return an ultimate default. */
1932 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
1933 the previous value of that parameter, NEW_VALUE is the new value. */
1936 x_set_line_spacing (f
, new_value
, old_value
)
1938 Lisp_Object new_value
, old_value
;
1940 if (NILP (new_value
))
1941 f
->extra_line_spacing
= 0;
1942 else if (NATNUMP (new_value
))
1943 f
->extra_line_spacing
= XFASTINT (new_value
);
1945 Fsignal (Qerror
, Fcons (build_string ("Invalid line-spacing"),
1946 Fcons (new_value
, Qnil
)));
1947 if (FRAME_VISIBLE_P (f
))
1952 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
1953 the previous value of that parameter, NEW_VALUE is the new value. */
1956 x_set_screen_gamma (f
, new_value
, old_value
)
1958 Lisp_Object new_value
, old_value
;
1960 if (NILP (new_value
))
1962 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
1963 /* The value 0.4545 is the normal viewing gamma. */
1964 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
1966 Fsignal (Qerror
, Fcons (build_string ("Invalid screen-gamma"),
1967 Fcons (new_value
, Qnil
)));
1969 clear_face_cache (0);
1973 /* Functions called only from `x_set_frame_param'
1974 to set individual parameters.
1976 If FRAME_W32_WINDOW (f) is 0,
1977 the frame is being created and its window does not exist yet.
1978 In that case, just record the parameter's new value
1979 in the standard place; do not attempt to change the window. */
1982 x_set_foreground_color (f
, arg
, oldval
)
1984 Lisp_Object arg
, oldval
;
1986 FRAME_FOREGROUND_PIXEL (f
)
1987 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1989 if (FRAME_W32_WINDOW (f
) != 0)
1991 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1992 if (FRAME_VISIBLE_P (f
))
1998 x_set_background_color (f
, arg
, oldval
)
2000 Lisp_Object arg
, oldval
;
2002 FRAME_BACKGROUND_PIXEL (f
)
2003 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
2005 if (FRAME_W32_WINDOW (f
) != 0)
2007 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
2008 FRAME_BACKGROUND_PIXEL (f
));
2010 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
2012 if (FRAME_VISIBLE_P (f
))
2018 x_set_mouse_color (f
, arg
, oldval
)
2020 Lisp_Object arg
, oldval
;
2022 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
2026 if (!EQ (Qnil
, arg
))
2027 f
->output_data
.w32
->mouse_pixel
2028 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2029 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
2031 /* Don't let pointers be invisible. */
2032 if (mask_color
== f
->output_data
.w32
->mouse_pixel
2033 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
2034 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
2036 #if 0 /* TODO : cursor changes */
2039 /* It's not okay to crash if the user selects a screwy cursor. */
2040 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
2042 if (!EQ (Qnil
, Vx_pointer_shape
))
2044 CHECK_NUMBER (Vx_pointer_shape
, 0);
2045 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
2048 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2049 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
2051 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
2053 CHECK_NUMBER (Vx_nontext_pointer_shape
, 0);
2054 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2055 XINT (Vx_nontext_pointer_shape
));
2058 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
2059 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2061 if (!EQ (Qnil
, Vx_busy_pointer_shape
))
2063 CHECK_NUMBER (Vx_busy_pointer_shape
, 0);
2064 busy_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2065 XINT (Vx_busy_pointer_shape
));
2068 busy_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
2069 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
2071 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2072 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
2074 CHECK_NUMBER (Vx_mode_pointer_shape
, 0);
2075 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2076 XINT (Vx_mode_pointer_shape
));
2079 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2080 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
2082 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
2084 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
, 0);
2086 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2087 XINT (Vx_sensitive_text_pointer_shape
));
2090 cross_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
2092 /* Check and report errors with the above calls. */
2093 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
2094 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
2097 XColor fore_color
, back_color
;
2099 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
2100 back_color
.pixel
= mask_color
;
2101 XQueryColor (FRAME_W32_DISPLAY (f
),
2102 DefaultColormap (FRAME_W32_DISPLAY (f
),
2103 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2105 XQueryColor (FRAME_W32_DISPLAY (f
),
2106 DefaultColormap (FRAME_W32_DISPLAY (f
),
2107 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2109 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
2110 &fore_color
, &back_color
);
2111 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
2112 &fore_color
, &back_color
);
2113 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
2114 &fore_color
, &back_color
);
2115 XRecolorCursor (FRAME_W32_DISPLAY (f
), cross_cursor
,
2116 &fore_color
, &back_color
);
2117 XRecolorCursor (FRAME_W32_DISPLAY (f
), busy_cursor
,
2118 &fore_color
, &back_color
);
2121 if (FRAME_W32_WINDOW (f
) != 0)
2122 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
2124 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
2125 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
2126 f
->output_data
.w32
->text_cursor
= cursor
;
2128 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
2129 && f
->output_data
.w32
->nontext_cursor
!= 0)
2130 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
2131 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
2133 if (busy_cursor
!= f
->output_data
.w32
->busy_cursor
2134 && f
->output_data
.w32
->busy_cursor
!= 0)
2135 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->busy_cursor
);
2136 f
->output_data
.w32
->busy_cursor
= busy_cursor
;
2138 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
2139 && f
->output_data
.w32
->modeline_cursor
!= 0)
2140 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
2141 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
2143 if (cross_cursor
!= f
->output_data
.w32
->cross_cursor
2144 && f
->output_data
.w32
->cross_cursor
!= 0)
2145 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->cross_cursor
);
2146 f
->output_data
.w32
->cross_cursor
= cross_cursor
;
2148 XFlush (FRAME_W32_DISPLAY (f
));
2151 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
2155 /* Defined in w32term.c. */
2156 void x_update_cursor (struct frame
*f
, int on_p
);
2159 x_set_cursor_color (f
, arg
, oldval
)
2161 Lisp_Object arg
, oldval
;
2163 unsigned long fore_pixel
, pixel
;
2165 if (!NILP (Vx_cursor_fore_pixel
))
2166 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
2167 WHITE_PIX_DEFAULT (f
));
2169 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2171 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2173 /* Make sure that the cursor color differs from the background color. */
2174 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
2176 pixel
= f
->output_data
.w32
->mouse_pixel
;
2177 if (pixel
== fore_pixel
)
2178 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2181 FRAME_FOREGROUND_PIXEL (f
) = fore_pixel
;
2182 f
->output_data
.w32
->cursor_pixel
= pixel
;
2184 if (FRAME_W32_WINDOW (f
) != 0)
2186 if (FRAME_VISIBLE_P (f
))
2188 x_update_cursor (f
, 0);
2189 x_update_cursor (f
, 1);
2193 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
2196 /* Set the border-color of frame F to pixel value PIX.
2197 Note that this does not fully take effect if done before
2200 x_set_border_pixel (f
, pix
)
2204 f
->output_data
.w32
->border_pixel
= pix
;
2206 if (FRAME_W32_WINDOW (f
) != 0 && f
->output_data
.w32
->border_width
> 0)
2208 if (FRAME_VISIBLE_P (f
))
2213 /* Set the border-color of frame F to value described by ARG.
2214 ARG can be a string naming a color.
2215 The border-color is used for the border that is drawn by the server.
2216 Note that this does not fully take effect if done before
2217 F has a window; it must be redone when the window is created. */
2220 x_set_border_color (f
, arg
, oldval
)
2222 Lisp_Object arg
, oldval
;
2226 CHECK_STRING (arg
, 0);
2227 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2228 x_set_border_pixel (f
, pix
);
2229 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
2232 /* Value is the internal representation of the specified cursor type
2233 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
2234 of the bar cursor. */
2236 enum text_cursor_kinds
2237 x_specified_cursor_type (arg
, width
)
2241 enum text_cursor_kinds type
;
2248 else if (CONSP (arg
)
2249 && EQ (XCAR (arg
), Qbar
)
2250 && INTEGERP (XCDR (arg
))
2251 && XINT (XCDR (arg
)) >= 0)
2254 *width
= XINT (XCDR (arg
));
2256 else if (NILP (arg
))
2259 /* Treat anything unknown as "box cursor".
2260 It was bad to signal an error; people have trouble fixing
2261 .Xdefaults with Emacs, when it has something bad in it. */
2262 type
= FILLED_BOX_CURSOR
;
2268 x_set_cursor_type (f
, arg
, oldval
)
2270 Lisp_Object arg
, oldval
;
2274 FRAME_DESIRED_CURSOR (f
) = x_specified_cursor_type (arg
, &width
);
2275 f
->output_data
.w32
->cursor_width
= width
;
2277 /* Make sure the cursor gets redrawn. This is overkill, but how
2278 often do people change cursor types? */
2279 update_mode_lines
++;
2283 x_set_icon_type (f
, arg
, oldval
)
2285 Lisp_Object arg
, oldval
;
2289 if (NILP (arg
) && NILP (oldval
))
2292 if (STRINGP (arg
) && STRINGP (oldval
)
2293 && EQ (Fstring_equal (oldval
, arg
), Qt
))
2296 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
2301 result
= x_bitmap_icon (f
, arg
);
2305 error ("No icon window available");
2311 /* Return non-nil if frame F wants a bitmap icon. */
2319 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
2327 x_set_icon_name (f
, arg
, oldval
)
2329 Lisp_Object arg
, oldval
;
2335 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
2338 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
2344 if (f
->output_data
.w32
->icon_bitmap
!= 0)
2349 result
= x_text_icon (f
,
2350 (char *) XSTRING ((!NILP (f
->icon_name
)
2359 error ("No icon window available");
2362 /* If the window was unmapped (and its icon was mapped),
2363 the new icon is not mapped, so map the window in its stead. */
2364 if (FRAME_VISIBLE_P (f
))
2366 #ifdef USE_X_TOOLKIT
2367 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
2369 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
2372 XFlush (FRAME_W32_DISPLAY (f
));
2377 extern Lisp_Object
x_new_font ();
2378 extern Lisp_Object
x_new_fontset();
2381 x_set_font (f
, arg
, oldval
)
2383 Lisp_Object arg
, oldval
;
2386 Lisp_Object fontset_name
;
2389 CHECK_STRING (arg
, 1);
2391 fontset_name
= Fquery_fontset (arg
, Qnil
);
2394 result
= (STRINGP (fontset_name
)
2395 ? x_new_fontset (f
, XSTRING (fontset_name
)->data
)
2396 : x_new_font (f
, XSTRING (arg
)->data
));
2399 if (EQ (result
, Qnil
))
2400 error ("Font `%s' is not defined", XSTRING (arg
)->data
);
2401 else if (EQ (result
, Qt
))
2402 error ("The characters of the given font have varying widths");
2403 else if (STRINGP (result
))
2405 store_frame_param (f
, Qfont
, result
);
2406 recompute_basic_faces (f
);
2411 do_pending_window_change (0);
2413 /* Don't call `face-set-after-frame-default' when faces haven't been
2414 initialized yet. This is the case when called from
2415 Fx_create_frame. In that case, the X widget or window doesn't
2416 exist either, and we can end up in x_report_frame_params with a
2417 null widget which gives a segfault. */
2418 if (FRAME_FACE_CACHE (f
))
2420 XSETFRAME (frame
, f
);
2421 call1 (Qface_set_after_frame_default
, frame
);
2426 x_set_border_width (f
, arg
, oldval
)
2428 Lisp_Object arg
, oldval
;
2430 CHECK_NUMBER (arg
, 0);
2432 if (XINT (arg
) == f
->output_data
.w32
->border_width
)
2435 if (FRAME_W32_WINDOW (f
) != 0)
2436 error ("Cannot change the border width of a window");
2438 f
->output_data
.w32
->border_width
= XINT (arg
);
2442 x_set_internal_border_width (f
, arg
, oldval
)
2444 Lisp_Object arg
, oldval
;
2446 int old
= f
->output_data
.w32
->internal_border_width
;
2448 CHECK_NUMBER (arg
, 0);
2449 f
->output_data
.w32
->internal_border_width
= XINT (arg
);
2450 if (f
->output_data
.w32
->internal_border_width
< 0)
2451 f
->output_data
.w32
->internal_border_width
= 0;
2453 if (f
->output_data
.w32
->internal_border_width
== old
)
2456 if (FRAME_W32_WINDOW (f
) != 0)
2458 x_set_window_size (f
, 0, f
->width
, f
->height
);
2459 SET_FRAME_GARBAGED (f
);
2460 do_pending_window_change (0);
2465 x_set_visibility (f
, value
, oldval
)
2467 Lisp_Object value
, oldval
;
2470 XSETFRAME (frame
, f
);
2473 Fmake_frame_invisible (frame
, Qt
);
2474 else if (EQ (value
, Qicon
))
2475 Ficonify_frame (frame
);
2477 Fmake_frame_visible (frame
);
2481 /* Change window heights in windows rooted in WINDOW by N lines. */
2484 x_change_window_heights (window
, n
)
2488 struct window
*w
= XWINDOW (window
);
2490 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
2491 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
2493 if (INTEGERP (w
->orig_top
))
2494 XSETFASTINT (w
->orig_top
, XFASTINT (w
->orig_top
) + n
);
2495 if (INTEGERP (w
->orig_height
))
2496 XSETFASTINT (w
->orig_height
, XFASTINT (w
->orig_height
) - n
);
2498 /* Handle just the top child in a vertical split. */
2499 if (!NILP (w
->vchild
))
2500 x_change_window_heights (w
->vchild
, n
);
2502 /* Adjust all children in a horizontal split. */
2503 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2505 w
= XWINDOW (window
);
2506 x_change_window_heights (window
, n
);
2511 x_set_menu_bar_lines (f
, value
, oldval
)
2513 Lisp_Object value
, oldval
;
2516 int olines
= FRAME_MENU_BAR_LINES (f
);
2518 /* Right now, menu bars don't work properly in minibuf-only frames;
2519 most of the commands try to apply themselves to the minibuffer
2520 frame itself, and get an error because you can't switch buffers
2521 in or split the minibuffer window. */
2522 if (FRAME_MINIBUF_ONLY_P (f
))
2525 if (INTEGERP (value
))
2526 nlines
= XINT (value
);
2530 FRAME_MENU_BAR_LINES (f
) = 0;
2532 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2535 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2536 free_frame_menubar (f
);
2537 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2539 /* Adjust the frame size so that the client (text) dimensions
2540 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
2542 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2543 do_pending_window_change (0);
2549 /* Set the number of lines used for the tool bar of frame F to VALUE.
2550 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2551 is the old number of tool bar lines. This function changes the
2552 height of all windows on frame F to match the new tool bar height.
2553 The frame's height doesn't change. */
2556 x_set_tool_bar_lines (f
, value
, oldval
)
2558 Lisp_Object value
, oldval
;
2560 int delta
, nlines
, root_height
;
2561 Lisp_Object root_window
;
2563 /* Use VALUE only if an integer >= 0. */
2564 if (INTEGERP (value
) && XINT (value
) >= 0)
2565 nlines
= XFASTINT (value
);
2569 /* Make sure we redisplay all windows in this frame. */
2570 ++windows_or_buffers_changed
;
2572 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2574 /* Don't resize the tool-bar to more than we have room for. */
2575 root_window
= FRAME_ROOT_WINDOW (f
);
2576 root_height
= XINT (XWINDOW (root_window
)->height
);
2577 if (root_height
- delta
< 1)
2579 delta
= root_height
- 1;
2580 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
2583 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2584 x_change_window_heights (root_window
, delta
);
2587 /* We also have to make sure that the internal border at the top of
2588 the frame, below the menu bar or tool bar, is redrawn when the
2589 tool bar disappears. This is so because the internal border is
2590 below the tool bar if one is displayed, but is below the menu bar
2591 if there isn't a tool bar. The tool bar draws into the area
2592 below the menu bar. */
2593 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
2597 clear_current_matrices (f
);
2598 updating_frame
= NULL
;
2601 /* If the tool bar gets smaller, the internal border below it
2602 has to be cleared. It was formerly part of the display
2603 of the larger tool bar, and updating windows won't clear it. */
2606 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2607 int width
= PIXEL_WIDTH (f
);
2608 int y
= nlines
* CANON_Y_UNIT (f
);
2612 HDC hdc
= get_frame_dc (f
);
2613 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
2614 release_frame_dc (f
, hdc
);
2621 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2624 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2625 name; if NAME is a string, set F's name to NAME and set
2626 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2628 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2629 suggesting a new name, which lisp code should override; if
2630 F->explicit_name is set, ignore the new name; otherwise, set it. */
2633 x_set_name (f
, name
, explicit)
2638 /* Make sure that requests from lisp code override requests from
2639 Emacs redisplay code. */
2642 /* If we're switching from explicit to implicit, we had better
2643 update the mode lines and thereby update the title. */
2644 if (f
->explicit_name
&& NILP (name
))
2645 update_mode_lines
= 1;
2647 f
->explicit_name
= ! NILP (name
);
2649 else if (f
->explicit_name
)
2652 /* If NAME is nil, set the name to the w32_id_name. */
2655 /* Check for no change needed in this very common case
2656 before we do any consing. */
2657 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
2658 XSTRING (f
->name
)->data
))
2660 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
2663 CHECK_STRING (name
, 0);
2665 /* Don't change the name if it's already NAME. */
2666 if (! NILP (Fstring_equal (name
, f
->name
)))
2671 /* For setting the frame title, the title parameter should override
2672 the name parameter. */
2673 if (! NILP (f
->title
))
2676 if (FRAME_W32_WINDOW (f
))
2678 if (STRING_MULTIBYTE (name
))
2679 name
= ENCODE_SYSTEM (name
);
2682 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2687 /* This function should be called when the user's lisp code has
2688 specified a name for the frame; the name will override any set by the
2691 x_explicitly_set_name (f
, arg
, oldval
)
2693 Lisp_Object arg
, oldval
;
2695 x_set_name (f
, arg
, 1);
2698 /* This function should be called by Emacs redisplay code to set the
2699 name; names set this way will never override names set by the user's
2702 x_implicitly_set_name (f
, arg
, oldval
)
2704 Lisp_Object arg
, oldval
;
2706 x_set_name (f
, arg
, 0);
2709 /* Change the title of frame F to NAME.
2710 If NAME is nil, use the frame name as the title.
2712 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2713 name; if NAME is a string, set F's name to NAME and set
2714 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2716 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2717 suggesting a new name, which lisp code should override; if
2718 F->explicit_name is set, ignore the new name; otherwise, set it. */
2721 x_set_title (f
, name
, old_name
)
2723 Lisp_Object name
, old_name
;
2725 /* Don't change the title if it's already NAME. */
2726 if (EQ (name
, f
->title
))
2729 update_mode_lines
= 1;
2736 if (FRAME_W32_WINDOW (f
))
2738 if (STRING_MULTIBYTE (name
))
2739 name
= ENCODE_SYSTEM (name
);
2742 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2748 x_set_autoraise (f
, arg
, oldval
)
2750 Lisp_Object arg
, oldval
;
2752 f
->auto_raise
= !EQ (Qnil
, arg
);
2756 x_set_autolower (f
, arg
, oldval
)
2758 Lisp_Object arg
, oldval
;
2760 f
->auto_lower
= !EQ (Qnil
, arg
);
2764 x_set_unsplittable (f
, arg
, oldval
)
2766 Lisp_Object arg
, oldval
;
2768 f
->no_split
= !NILP (arg
);
2772 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2774 Lisp_Object arg
, oldval
;
2776 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2777 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2778 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2779 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2781 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = NILP (arg
) ?
2782 vertical_scroll_bar_none
:
2783 /* Put scroll bars on the right by default, as is conventional
2786 ? vertical_scroll_bar_left
2787 : vertical_scroll_bar_right
;
2789 /* We set this parameter before creating the window for the
2790 frame, so we can get the geometry right from the start.
2791 However, if the window hasn't been created yet, we shouldn't
2792 call x_set_window_size. */
2793 if (FRAME_W32_WINDOW (f
))
2794 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2795 do_pending_window_change (0);
2800 x_set_scroll_bar_width (f
, arg
, oldval
)
2802 Lisp_Object arg
, oldval
;
2804 int wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
2808 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2809 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) +
2811 if (FRAME_W32_WINDOW (f
))
2812 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2813 do_pending_window_change (0);
2815 else if (INTEGERP (arg
) && XINT (arg
) > 0
2816 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2818 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2819 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2821 if (FRAME_W32_WINDOW (f
))
2822 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2823 do_pending_window_change (0);
2825 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2826 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2827 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2830 /* Subroutines of creating an frame. */
2832 /* Make sure that Vx_resource_name is set to a reasonable value.
2833 Fix it up, or set it to `emacs' if it is too hopeless. */
2836 validate_x_resource_name ()
2839 /* Number of valid characters in the resource name. */
2841 /* Number of invalid characters in the resource name. */
2846 if (STRINGP (Vx_resource_name
))
2848 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
2851 len
= STRING_BYTES (XSTRING (Vx_resource_name
));
2853 /* Only letters, digits, - and _ are valid in resource names.
2854 Count the valid characters and count the invalid ones. */
2855 for (i
= 0; i
< len
; i
++)
2858 if (! ((c
>= 'a' && c
<= 'z')
2859 || (c
>= 'A' && c
<= 'Z')
2860 || (c
>= '0' && c
<= '9')
2861 || c
== '-' || c
== '_'))
2868 /* Not a string => completely invalid. */
2869 bad_count
= 5, good_count
= 0;
2871 /* If name is valid already, return. */
2875 /* If name is entirely invalid, or nearly so, use `emacs'. */
2877 || (good_count
== 1 && bad_count
> 0))
2879 Vx_resource_name
= build_string ("emacs");
2883 /* Name is partly valid. Copy it and replace the invalid characters
2884 with underscores. */
2886 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
2888 for (i
= 0; i
< len
; i
++)
2890 int c
= XSTRING (new)->data
[i
];
2891 if (! ((c
>= 'a' && c
<= 'z')
2892 || (c
>= 'A' && c
<= 'Z')
2893 || (c
>= '0' && c
<= '9')
2894 || c
== '-' || c
== '_'))
2895 XSTRING (new)->data
[i
] = '_';
2900 extern char *x_get_string_resource ();
2902 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
2903 "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
2904 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
2905 class, where INSTANCE is the name under which Emacs was invoked, or\n\
2906 the name specified by the `-name' or `-rn' command-line arguments.\n\
2908 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
2909 class, respectively. You must specify both of them or neither.\n\
2910 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
2911 and the class is `Emacs.CLASS.SUBCLASS'.")
2912 (attribute
, class, component
, subclass
)
2913 Lisp_Object attribute
, class, component
, subclass
;
2915 register char *value
;
2919 CHECK_STRING (attribute
, 0);
2920 CHECK_STRING (class, 0);
2922 if (!NILP (component
))
2923 CHECK_STRING (component
, 1);
2924 if (!NILP (subclass
))
2925 CHECK_STRING (subclass
, 2);
2926 if (NILP (component
) != NILP (subclass
))
2927 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
2929 validate_x_resource_name ();
2931 /* Allocate space for the components, the dots which separate them,
2932 and the final '\0'. Make them big enough for the worst case. */
2933 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vx_resource_name
))
2934 + (STRINGP (component
)
2935 ? STRING_BYTES (XSTRING (component
)) : 0)
2936 + STRING_BYTES (XSTRING (attribute
))
2939 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2940 + STRING_BYTES (XSTRING (class))
2941 + (STRINGP (subclass
)
2942 ? STRING_BYTES (XSTRING (subclass
)) : 0)
2945 /* Start with emacs.FRAMENAME for the name (the specific one)
2946 and with `Emacs' for the class key (the general one). */
2947 strcpy (name_key
, XSTRING (Vx_resource_name
)->data
);
2948 strcpy (class_key
, EMACS_CLASS
);
2950 strcat (class_key
, ".");
2951 strcat (class_key
, XSTRING (class)->data
);
2953 if (!NILP (component
))
2955 strcat (class_key
, ".");
2956 strcat (class_key
, XSTRING (subclass
)->data
);
2958 strcat (name_key
, ".");
2959 strcat (name_key
, XSTRING (component
)->data
);
2962 strcat (name_key
, ".");
2963 strcat (name_key
, XSTRING (attribute
)->data
);
2965 value
= x_get_string_resource (Qnil
,
2966 name_key
, class_key
);
2968 if (value
!= (char *) 0)
2969 return build_string (value
);
2974 /* Used when C code wants a resource value. */
2977 x_get_resource_string (attribute
, class)
2978 char *attribute
, *class;
2982 struct frame
*sf
= SELECTED_FRAME ();
2984 /* Allocate space for the components, the dots which separate them,
2985 and the final '\0'. */
2986 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vinvocation_name
))
2987 + strlen (attribute
) + 2);
2988 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2989 + strlen (class) + 2);
2991 sprintf (name_key
, "%s.%s",
2992 XSTRING (Vinvocation_name
)->data
,
2994 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
2996 return x_get_string_resource (sf
, name_key
, class_key
);
2999 /* Types we might convert a resource string into. */
3009 /* Return the value of parameter PARAM.
3011 First search ALIST, then Vdefault_frame_alist, then the X defaults
3012 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3014 Convert the resource to the type specified by desired_type.
3016 If no default is specified, return Qunbound. If you call
3017 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
3018 and don't let it get stored in any Lisp-visible variables! */
3021 w32_get_arg (alist
, param
, attribute
, class, type
)
3022 Lisp_Object alist
, param
;
3025 enum resource_types type
;
3027 register Lisp_Object tem
;
3029 tem
= Fassq (param
, alist
);
3031 tem
= Fassq (param
, Vdefault_frame_alist
);
3037 tem
= Fx_get_resource (build_string (attribute
),
3038 build_string (class),
3046 case RES_TYPE_NUMBER
:
3047 return make_number (atoi (XSTRING (tem
)->data
));
3049 case RES_TYPE_FLOAT
:
3050 return make_float (atof (XSTRING (tem
)->data
));
3052 case RES_TYPE_BOOLEAN
:
3053 tem
= Fdowncase (tem
);
3054 if (!strcmp (XSTRING (tem
)->data
, "on")
3055 || !strcmp (XSTRING (tem
)->data
, "true"))
3060 case RES_TYPE_STRING
:
3063 case RES_TYPE_SYMBOL
:
3064 /* As a special case, we map the values `true' and `on'
3065 to Qt, and `false' and `off' to Qnil. */
3068 lower
= Fdowncase (tem
);
3069 if (!strcmp (XSTRING (lower
)->data
, "on")
3070 || !strcmp (XSTRING (lower
)->data
, "true"))
3072 else if (!strcmp (XSTRING (lower
)->data
, "off")
3073 || !strcmp (XSTRING (lower
)->data
, "false"))
3076 return Fintern (tem
, Qnil
);
3089 /* Record in frame F the specified or default value according to ALIST
3090 of the parameter named PROP (a Lisp symbol).
3091 If no value is specified for PROP, look for an X default for XPROP
3092 on the frame named NAME.
3093 If that is not found either, use the value DEFLT. */
3096 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3103 enum resource_types type
;
3107 tem
= w32_get_arg (alist
, prop
, xprop
, xclass
, type
);
3108 if (EQ (tem
, Qunbound
))
3110 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3114 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3115 "Parse an X-style geometry string STRING.\n\
3116 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
3117 The properties returned may include `top', `left', `height', and `width'.\n\
3118 The value of `left' or `top' may be an integer,\n\
3119 or a list (+ N) meaning N pixels relative to top/left corner,\n\
3120 or a list (- N) meaning -N pixels relative to bottom/right corner.")
3125 unsigned int width
, height
;
3128 CHECK_STRING (string
, 0);
3130 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
3131 &x
, &y
, &width
, &height
);
3134 if (geometry
& XValue
)
3136 Lisp_Object element
;
3138 if (x
>= 0 && (geometry
& XNegative
))
3139 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3140 else if (x
< 0 && ! (geometry
& XNegative
))
3141 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3143 element
= Fcons (Qleft
, make_number (x
));
3144 result
= Fcons (element
, result
);
3147 if (geometry
& YValue
)
3149 Lisp_Object element
;
3151 if (y
>= 0 && (geometry
& YNegative
))
3152 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3153 else if (y
< 0 && ! (geometry
& YNegative
))
3154 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3156 element
= Fcons (Qtop
, make_number (y
));
3157 result
= Fcons (element
, result
);
3160 if (geometry
& WidthValue
)
3161 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3162 if (geometry
& HeightValue
)
3163 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3168 /* Calculate the desired size and position of this window,
3169 and return the flags saying which aspects were specified.
3171 This function does not make the coordinates positive. */
3173 #define DEFAULT_ROWS 40
3174 #define DEFAULT_COLS 80
3177 x_figure_window_size (f
, parms
)
3181 register Lisp_Object tem0
, tem1
, tem2
;
3182 long window_prompting
= 0;
3184 /* Default values if we fall through.
3185 Actually, if that happens we should get
3186 window manager prompting. */
3187 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3188 f
->height
= DEFAULT_ROWS
;
3189 /* Window managers expect that if program-specified
3190 positions are not (0,0), they're intentional, not defaults. */
3191 f
->output_data
.w32
->top_pos
= 0;
3192 f
->output_data
.w32
->left_pos
= 0;
3194 tem0
= w32_get_arg (parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3195 tem1
= w32_get_arg (parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3196 tem2
= w32_get_arg (parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3197 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3199 if (!EQ (tem0
, Qunbound
))
3201 CHECK_NUMBER (tem0
, 0);
3202 f
->height
= XINT (tem0
);
3204 if (!EQ (tem1
, Qunbound
))
3206 CHECK_NUMBER (tem1
, 0);
3207 SET_FRAME_WIDTH (f
, XINT (tem1
));
3209 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3210 window_prompting
|= USSize
;
3212 window_prompting
|= PSize
;
3215 f
->output_data
.w32
->vertical_scroll_bar_extra
3216 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3218 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3219 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3220 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
3221 f
->output_data
.w32
->flags_areas_extra
3222 = FRAME_FLAGS_AREA_WIDTH (f
);
3223 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3224 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3226 tem0
= w32_get_arg (parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3227 tem1
= w32_get_arg (parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3228 tem2
= w32_get_arg (parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3229 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3231 if (EQ (tem0
, Qminus
))
3233 f
->output_data
.w32
->top_pos
= 0;
3234 window_prompting
|= YNegative
;
3236 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3237 && CONSP (XCDR (tem0
))
3238 && INTEGERP (XCAR (XCDR (tem0
))))
3240 f
->output_data
.w32
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3241 window_prompting
|= YNegative
;
3243 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3244 && CONSP (XCDR (tem0
))
3245 && INTEGERP (XCAR (XCDR (tem0
))))
3247 f
->output_data
.w32
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3249 else if (EQ (tem0
, Qunbound
))
3250 f
->output_data
.w32
->top_pos
= 0;
3253 CHECK_NUMBER (tem0
, 0);
3254 f
->output_data
.w32
->top_pos
= XINT (tem0
);
3255 if (f
->output_data
.w32
->top_pos
< 0)
3256 window_prompting
|= YNegative
;
3259 if (EQ (tem1
, Qminus
))
3261 f
->output_data
.w32
->left_pos
= 0;
3262 window_prompting
|= XNegative
;
3264 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3265 && CONSP (XCDR (tem1
))
3266 && INTEGERP (XCAR (XCDR (tem1
))))
3268 f
->output_data
.w32
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3269 window_prompting
|= XNegative
;
3271 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3272 && CONSP (XCDR (tem1
))
3273 && INTEGERP (XCAR (XCDR (tem1
))))
3275 f
->output_data
.w32
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3277 else if (EQ (tem1
, Qunbound
))
3278 f
->output_data
.w32
->left_pos
= 0;
3281 CHECK_NUMBER (tem1
, 0);
3282 f
->output_data
.w32
->left_pos
= XINT (tem1
);
3283 if (f
->output_data
.w32
->left_pos
< 0)
3284 window_prompting
|= XNegative
;
3287 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3288 window_prompting
|= USPosition
;
3290 window_prompting
|= PPosition
;
3293 return window_prompting
;
3298 extern LRESULT CALLBACK
w32_wnd_proc ();
3301 w32_init_class (hinst
)
3306 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3307 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
3309 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
3310 wc
.hInstance
= hinst
;
3311 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
3312 wc
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
3313 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
3314 wc
.lpszMenuName
= NULL
;
3315 wc
.lpszClassName
= EMACS_CLASS
;
3317 return (RegisterClass (&wc
));
3321 w32_createscrollbar (f
, bar
)
3323 struct scroll_bar
* bar
;
3325 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
3326 /* Position and size of scroll bar. */
3327 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3329 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3331 FRAME_W32_WINDOW (f
),
3338 w32_createwindow (f
)
3344 rect
.left
= rect
.top
= 0;
3345 rect
.right
= PIXEL_WIDTH (f
);
3346 rect
.bottom
= PIXEL_HEIGHT (f
);
3348 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3349 FRAME_EXTERNAL_MENU_BAR (f
));
3351 /* Do first time app init */
3355 w32_init_class (hinst
);
3358 FRAME_W32_WINDOW (f
) = hwnd
3359 = CreateWindow (EMACS_CLASS
,
3361 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
3362 f
->output_data
.w32
->left_pos
,
3363 f
->output_data
.w32
->top_pos
,
3364 rect
.right
- rect
.left
,
3365 rect
.bottom
- rect
.top
,
3373 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
3374 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
3375 SetWindowLong (hwnd
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
3376 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
3377 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3379 /* Enable drag-n-drop. */
3380 DragAcceptFiles (hwnd
, TRUE
);
3382 /* Do this to discard the default setting specified by our parent. */
3383 ShowWindow (hwnd
, SW_HIDE
);
3388 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
3395 wmsg
->msg
.hwnd
= hwnd
;
3396 wmsg
->msg
.message
= msg
;
3397 wmsg
->msg
.wParam
= wParam
;
3398 wmsg
->msg
.lParam
= lParam
;
3399 wmsg
->msg
.time
= GetMessageTime ();
3404 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
3405 between left and right keys as advertised. We test for this
3406 support dynamically, and set a flag when the support is absent. If
3407 absent, we keep track of the left and right control and alt keys
3408 ourselves. This is particularly necessary on keyboards that rely
3409 upon the AltGr key, which is represented as having the left control
3410 and right alt keys pressed. For these keyboards, we need to know
3411 when the left alt key has been pressed in addition to the AltGr key
3412 so that we can properly support M-AltGr-key sequences (such as M-@
3413 on Swedish keyboards). */
3415 #define EMACS_LCONTROL 0
3416 #define EMACS_RCONTROL 1
3417 #define EMACS_LMENU 2
3418 #define EMACS_RMENU 3
3420 static int modifiers
[4];
3421 static int modifiers_recorded
;
3422 static int modifier_key_support_tested
;
3425 test_modifier_support (unsigned int wparam
)
3429 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
3431 if (wparam
== VK_CONTROL
)
3441 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
3442 modifiers_recorded
= 1;
3444 modifiers_recorded
= 0;
3445 modifier_key_support_tested
= 1;
3449 record_keydown (unsigned int wparam
, unsigned int lparam
)
3453 if (!modifier_key_support_tested
)
3454 test_modifier_support (wparam
);
3456 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3459 if (wparam
== VK_CONTROL
)
3460 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3462 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3468 record_keyup (unsigned int wparam
, unsigned int lparam
)
3472 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3475 if (wparam
== VK_CONTROL
)
3476 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3478 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3483 /* Emacs can lose focus while a modifier key has been pressed. When
3484 it regains focus, be conservative and clear all modifiers since
3485 we cannot reconstruct the left and right modifier state. */
3491 if (GetFocus () == NULL
)
3492 /* Emacs doesn't have keyboard focus. Do nothing. */
3495 ctrl
= GetAsyncKeyState (VK_CONTROL
);
3496 alt
= GetAsyncKeyState (VK_MENU
);
3498 if (!(ctrl
& 0x08000))
3499 /* Clear any recorded control modifier state. */
3500 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3502 if (!(alt
& 0x08000))
3503 /* Clear any recorded alt modifier state. */
3504 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3506 /* Update the state of all modifier keys, because modifiers used in
3507 hot-key combinations can get stuck on if Emacs loses focus as a
3508 result of a hot-key being pressed. */
3512 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
3514 GetKeyboardState (keystate
);
3515 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
3516 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
3517 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
3518 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
3519 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
3520 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
3521 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
3522 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
3523 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
3524 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
3525 SetKeyboardState (keystate
);
3529 /* Synchronize modifier state with what is reported with the current
3530 keystroke. Even if we cannot distinguish between left and right
3531 modifier keys, we know that, if no modifiers are set, then neither
3532 the left or right modifier should be set. */
3536 if (!modifiers_recorded
)
3539 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
3540 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3542 if (!(GetKeyState (VK_MENU
) & 0x8000))
3543 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3547 modifier_set (int vkey
)
3549 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
3550 return (GetKeyState (vkey
) & 0x1);
3551 if (!modifiers_recorded
)
3552 return (GetKeyState (vkey
) & 0x8000);
3557 return modifiers
[EMACS_LCONTROL
];
3559 return modifiers
[EMACS_RCONTROL
];
3561 return modifiers
[EMACS_LMENU
];
3563 return modifiers
[EMACS_RMENU
];
3565 return (GetKeyState (vkey
) & 0x8000);
3568 /* Convert between the modifier bits W32 uses and the modifier bits
3572 w32_key_to_modifier (int key
)
3574 Lisp_Object key_mapping
;
3579 key_mapping
= Vw32_lwindow_modifier
;
3582 key_mapping
= Vw32_rwindow_modifier
;
3585 key_mapping
= Vw32_apps_modifier
;
3588 key_mapping
= Vw32_scroll_lock_modifier
;
3594 /* NB. This code runs in the input thread, asychronously to the lisp
3595 thread, so we must be careful to ensure access to lisp data is
3596 thread-safe. The following code is safe because the modifier
3597 variable values are updated atomically from lisp and symbols are
3598 not relocated by GC. Also, we don't have to worry about seeing GC
3600 if (EQ (key_mapping
, Qhyper
))
3601 return hyper_modifier
;
3602 if (EQ (key_mapping
, Qsuper
))
3603 return super_modifier
;
3604 if (EQ (key_mapping
, Qmeta
))
3605 return meta_modifier
;
3606 if (EQ (key_mapping
, Qalt
))
3607 return alt_modifier
;
3608 if (EQ (key_mapping
, Qctrl
))
3609 return ctrl_modifier
;
3610 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
3611 return ctrl_modifier
;
3612 if (EQ (key_mapping
, Qshift
))
3613 return shift_modifier
;
3615 /* Don't generate any modifier if not explicitly requested. */
3620 w32_get_modifiers ()
3622 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
3623 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
3624 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
3625 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
3626 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
3627 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
3628 (modifier_set (VK_MENU
) ?
3629 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
3632 /* We map the VK_* modifiers into console modifier constants
3633 so that we can use the same routines to handle both console
3634 and window input. */
3637 construct_console_modifiers ()
3642 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
3643 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
3644 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
3645 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
3646 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
3647 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
3648 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
3649 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
3650 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
3651 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
3652 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
3658 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
3662 /* Convert to emacs modifiers. */
3663 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
3669 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
3671 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
3674 if (virt_key
== VK_RETURN
)
3675 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
3677 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
3678 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
3680 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
3681 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
3683 if (virt_key
== VK_CLEAR
)
3684 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
3689 /* List of special key combinations which w32 would normally capture,
3690 but emacs should grab instead. Not directly visible to lisp, to
3691 simplify synchronization. Each item is an integer encoding a virtual
3692 key code and modifier combination to capture. */
3693 Lisp_Object w32_grabbed_keys
;
3695 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
3696 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
3697 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
3698 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
3700 /* Register hot-keys for reserved key combinations when Emacs has
3701 keyboard focus, since this is the only way Emacs can receive key
3702 combinations like Alt-Tab which are used by the system. */
3705 register_hot_keys (hwnd
)
3708 Lisp_Object keylist
;
3710 /* Use GC_CONSP, since we are called asynchronously. */
3711 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3713 Lisp_Object key
= XCAR (keylist
);
3715 /* Deleted entries get set to nil. */
3716 if (!INTEGERP (key
))
3719 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
3720 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
3725 unregister_hot_keys (hwnd
)
3728 Lisp_Object keylist
;
3730 /* Use GC_CONSP, since we are called asynchronously. */
3731 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3733 Lisp_Object key
= XCAR (keylist
);
3735 if (!INTEGERP (key
))
3738 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
3742 /* Main message dispatch loop. */
3745 w32_msg_pump (deferred_msg
* msg_buf
)
3751 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
3753 while (GetMessage (&msg
, NULL
, 0, 0))
3755 if (msg
.hwnd
== NULL
)
3757 switch (msg
.message
)
3760 /* Produced by complete_deferred_msg; just ignore. */
3762 case WM_EMACS_CREATEWINDOW
:
3763 w32_createwindow ((struct frame
*) msg
.wParam
);
3764 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3767 case WM_EMACS_SETLOCALE
:
3768 SetThreadLocale (msg
.wParam
);
3769 /* Reply is not expected. */
3771 case WM_EMACS_SETKEYBOARDLAYOUT
:
3772 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
3773 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3777 case WM_EMACS_REGISTER_HOT_KEY
:
3778 focus_window
= GetFocus ();
3779 if (focus_window
!= NULL
)
3780 RegisterHotKey (focus_window
,
3781 HOTKEY_ID (msg
.wParam
),
3782 HOTKEY_MODIFIERS (msg
.wParam
),
3783 HOTKEY_VK_CODE (msg
.wParam
));
3784 /* Reply is not expected. */
3786 case WM_EMACS_UNREGISTER_HOT_KEY
:
3787 focus_window
= GetFocus ();
3788 if (focus_window
!= NULL
)
3789 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
3790 /* Mark item as erased. NB: this code must be
3791 thread-safe. The next line is okay because the cons
3792 cell is never made into garbage and is not relocated by
3794 XCAR ((Lisp_Object
) msg
.lParam
) = Qnil
;
3795 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3798 case WM_EMACS_TOGGLE_LOCK_KEY
:
3800 int vk_code
= (int) msg
.wParam
;
3801 int cur_state
= (GetKeyState (vk_code
) & 1);
3802 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
3804 /* NB: This code must be thread-safe. It is safe to
3805 call NILP because symbols are not relocated by GC,
3806 and pointer here is not touched by GC (so the markbit
3807 can't be set). Numbers are safe because they are
3808 immediate values. */
3809 if (NILP (new_state
)
3810 || (NUMBERP (new_state
)
3811 && (XUINT (new_state
)) & 1 != cur_state
))
3813 one_w32_display_info
.faked_key
= vk_code
;
3815 keybd_event ((BYTE
) vk_code
,
3816 (BYTE
) MapVirtualKey (vk_code
, 0),
3817 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3818 keybd_event ((BYTE
) vk_code
,
3819 (BYTE
) MapVirtualKey (vk_code
, 0),
3820 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3821 keybd_event ((BYTE
) vk_code
,
3822 (BYTE
) MapVirtualKey (vk_code
, 0),
3823 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3824 cur_state
= !cur_state
;
3826 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3832 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
3837 DispatchMessage (&msg
);
3840 /* Exit nested loop when our deferred message has completed. */
3841 if (msg_buf
->completed
)
3846 deferred_msg
* deferred_msg_head
;
3848 static deferred_msg
*
3849 find_deferred_msg (HWND hwnd
, UINT msg
)
3851 deferred_msg
* item
;
3853 /* Don't actually need synchronization for read access, since
3854 modification of single pointer is always atomic. */
3855 /* enter_crit (); */
3857 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3858 if (item
->w32msg
.msg
.hwnd
== hwnd
3859 && item
->w32msg
.msg
.message
== msg
)
3862 /* leave_crit (); */
3868 send_deferred_msg (deferred_msg
* msg_buf
,
3874 /* Only input thread can send deferred messages. */
3875 if (GetCurrentThreadId () != dwWindowsThreadId
)
3878 /* It is an error to send a message that is already deferred. */
3879 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3882 /* Enforced synchronization is not needed because this is the only
3883 function that alters deferred_msg_head, and the following critical
3884 section is guaranteed to only be serially reentered (since only the
3885 input thread can call us). */
3887 /* enter_crit (); */
3889 msg_buf
->completed
= 0;
3890 msg_buf
->next
= deferred_msg_head
;
3891 deferred_msg_head
= msg_buf
;
3892 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
3894 /* leave_crit (); */
3896 /* Start a new nested message loop to process other messages until
3897 this one is completed. */
3898 w32_msg_pump (msg_buf
);
3900 deferred_msg_head
= msg_buf
->next
;
3902 return msg_buf
->result
;
3906 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
3908 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
3910 if (msg_buf
== NULL
)
3911 /* Message may have been cancelled, so don't abort(). */
3914 msg_buf
->result
= result
;
3915 msg_buf
->completed
= 1;
3917 /* Ensure input thread is woken so it notices the completion. */
3918 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3922 cancel_all_deferred_msgs ()
3924 deferred_msg
* item
;
3926 /* Don't actually need synchronization for read access, since
3927 modification of single pointer is always atomic. */
3928 /* enter_crit (); */
3930 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3933 item
->completed
= 1;
3936 /* leave_crit (); */
3938 /* Ensure input thread is woken so it notices the completion. */
3939 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3947 deferred_msg dummy_buf
;
3949 /* Ensure our message queue is created */
3951 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
3953 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3956 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
3957 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
3958 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
3960 /* This is the inital message loop which should only exit when the
3961 application quits. */
3962 w32_msg_pump (&dummy_buf
);
3968 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
3978 wmsg
.dwModifiers
= modifiers
;
3980 /* Detect quit_char and set quit-flag directly. Note that we
3981 still need to post a message to ensure the main thread will be
3982 woken up if blocked in sys_select(), but we do NOT want to post
3983 the quit_char message itself (because it will usually be as if
3984 the user had typed quit_char twice). Instead, we post a dummy
3985 message that has no particular effect. */
3988 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
3989 c
= make_ctrl_char (c
) & 0377;
3991 || (wmsg
.dwModifiers
== 0 &&
3992 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
3996 /* The choice of message is somewhat arbitrary, as long as
3997 the main thread handler just ignores it. */
4000 /* Interrupt any blocking system calls. */
4003 /* As a safety precaution, forcibly complete any deferred
4004 messages. This is a kludge, but I don't see any particularly
4005 clean way to handle the situation where a deferred message is
4006 "dropped" in the lisp thread, and will thus never be
4007 completed, eg. by the user trying to activate the menubar
4008 when the lisp thread is busy, and then typing C-g when the
4009 menubar doesn't open promptly (with the result that the
4010 menubar never responds at all because the deferred
4011 WM_INITMENU message is never completed). Another problem
4012 situation is when the lisp thread calls SendMessage (to send
4013 a window manager command) when a message has been deferred;
4014 the lisp thread gets blocked indefinitely waiting for the
4015 deferred message to be completed, which itself is waiting for
4016 the lisp thread to respond.
4018 Note that we don't want to block the input thread waiting for
4019 a reponse from the lisp thread (although that would at least
4020 solve the deadlock problem above), because we want to be able
4021 to receive C-g to interrupt the lisp thread. */
4022 cancel_all_deferred_msgs ();
4026 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4029 /* Main window procedure */
4032 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
4039 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4041 int windows_translate
;
4044 /* Note that it is okay to call x_window_to_frame, even though we are
4045 not running in the main lisp thread, because frame deletion
4046 requires the lisp thread to synchronize with this thread. Thus, if
4047 a frame struct is returned, it can be used without concern that the
4048 lisp thread might make it disappear while we are using it.
4050 NB. Walking the frame list in this thread is safe (as long as
4051 writes of Lisp_Object slots are atomic, which they are on Windows).
4052 Although delete-frame can destructively modify the frame list while
4053 we are walking it, a garbage collection cannot occur until after
4054 delete-frame has synchronized with this thread.
4056 It is also safe to use functions that make GDI calls, such as
4057 w32_clear_rect, because these functions must obtain a DC handle
4058 from the frame struct using get_frame_dc which is thread-aware. */
4063 f
= x_window_to_frame (dpyinfo
, hwnd
);
4066 HDC hdc
= get_frame_dc (f
);
4067 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
4068 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
4069 release_frame_dc (f
, hdc
);
4071 #if defined (W32_DEBUG_DISPLAY)
4072 DebPrint (("WM_ERASEBKGND: erasing %d,%d-%d,%d\n",
4073 wmsg
.rect
.left
, wmsg
.rect
.top
, wmsg
.rect
.right
,
4075 #endif /* W32_DEBUG_DISPLAY */
4078 case WM_PALETTECHANGED
:
4079 /* ignore our own changes */
4080 if ((HWND
)wParam
!= hwnd
)
4082 f
= x_window_to_frame (dpyinfo
, hwnd
);
4084 /* get_frame_dc will realize our palette and force all
4085 frames to be redrawn if needed. */
4086 release_frame_dc (f
, get_frame_dc (f
));
4091 PAINTSTRUCT paintStruct
;
4094 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
4095 fails. Apparently this can happen under some
4097 if (!w32_strict_painting
|| GetUpdateRect (hwnd
, &update_rect
, FALSE
))
4100 BeginPaint (hwnd
, &paintStruct
);
4102 if (w32_strict_painting
)
4103 /* The rectangles returned by GetUpdateRect and BeginPaint
4104 do not always match. GetUpdateRect seems to be the
4105 more reliable of the two. */
4106 wmsg
.rect
= update_rect
;
4108 wmsg
.rect
= paintStruct
.rcPaint
;
4110 #if defined (W32_DEBUG_DISPLAY)
4111 DebPrint (("WM_PAINT: painting %d,%d-%d,%d\n", wmsg
.rect
.left
,
4112 wmsg
.rect
.top
, wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4113 DebPrint (("WM_PAINT: update region is %d,%d-%d,%d\n",
4114 update_rect
.left
, update_rect
.top
,
4115 update_rect
.right
, update_rect
.bottom
));
4117 EndPaint (hwnd
, &paintStruct
);
4120 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4125 /* If GetUpdateRect returns 0 (meaning there is no update
4126 region), assume the whole window needs to be repainted. */
4127 GetClientRect(hwnd
, &wmsg
.rect
);
4128 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4132 case WM_INPUTLANGCHANGE
:
4133 /* Inform lisp thread of keyboard layout changes. */
4134 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4136 /* Clear dead keys in the keyboard state; for simplicity only
4137 preserve modifier key states. */
4142 GetKeyboardState (keystate
);
4143 for (i
= 0; i
< 256; i
++)
4160 SetKeyboardState (keystate
);
4165 /* Synchronize hot keys with normal input. */
4166 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
4171 record_keyup (wParam
, lParam
);
4176 /* Ignore keystrokes we fake ourself; see below. */
4177 if (dpyinfo
->faked_key
== wParam
)
4179 dpyinfo
->faked_key
= 0;
4180 /* Make sure TranslateMessage sees them though (as long as
4181 they don't produce WM_CHAR messages). This ensures that
4182 indicator lights are toggled promptly on Windows 9x, for
4184 if (lispy_function_keys
[wParam
] != 0)
4186 windows_translate
= 1;
4192 /* Synchronize modifiers with current keystroke. */
4194 record_keydown (wParam
, lParam
);
4195 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
4197 windows_translate
= 0;
4202 if (NILP (Vw32_pass_lwindow_to_system
))
4204 /* Prevent system from acting on keyup (which opens the
4205 Start menu if no other key was pressed) by simulating a
4206 press of Space which we will ignore. */
4207 if (GetAsyncKeyState (wParam
) & 1)
4209 if (NUMBERP (Vw32_phantom_key_code
))
4210 key
= XUINT (Vw32_phantom_key_code
) & 255;
4213 dpyinfo
->faked_key
= key
;
4214 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4217 if (!NILP (Vw32_lwindow_modifier
))
4221 if (NILP (Vw32_pass_rwindow_to_system
))
4223 if (GetAsyncKeyState (wParam
) & 1)
4225 if (NUMBERP (Vw32_phantom_key_code
))
4226 key
= XUINT (Vw32_phantom_key_code
) & 255;
4229 dpyinfo
->faked_key
= key
;
4230 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4233 if (!NILP (Vw32_rwindow_modifier
))
4237 if (!NILP (Vw32_apps_modifier
))
4241 if (NILP (Vw32_pass_alt_to_system
))
4242 /* Prevent DefWindowProc from activating the menu bar if an
4243 Alt key is pressed and released by itself. */
4245 windows_translate
= 1;
4248 /* Decide whether to treat as modifier or function key. */
4249 if (NILP (Vw32_enable_caps_lock
))
4250 goto disable_lock_key
;
4251 windows_translate
= 1;
4254 /* Decide whether to treat as modifier or function key. */
4255 if (NILP (Vw32_enable_num_lock
))
4256 goto disable_lock_key
;
4257 windows_translate
= 1;
4260 /* Decide whether to treat as modifier or function key. */
4261 if (NILP (Vw32_scroll_lock_modifier
))
4262 goto disable_lock_key
;
4263 windows_translate
= 1;
4266 /* Ensure the appropriate lock key state (and indicator light)
4267 remains in the same state. We do this by faking another
4268 press of the relevant key. Apparently, this really is the
4269 only way to toggle the state of the indicator lights. */
4270 dpyinfo
->faked_key
= wParam
;
4271 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4272 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4273 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4274 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4275 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4276 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4277 /* Ensure indicator lights are updated promptly on Windows 9x
4278 (TranslateMessage apparently does this), after forwarding
4280 post_character_message (hwnd
, msg
, wParam
, lParam
,
4281 w32_get_key_modifiers (wParam
, lParam
));
4282 windows_translate
= 1;
4286 case VK_PROCESSKEY
: /* Generated by IME. */
4287 windows_translate
= 1;
4290 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
4291 which is confusing for purposes of key binding; convert
4292 VK_CANCEL events into VK_PAUSE events. */
4296 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
4297 for purposes of key binding; convert these back into
4298 VK_NUMLOCK events, at least when we want to see NumLock key
4299 presses. (Note that there is never any possibility that
4300 VK_PAUSE with Ctrl really is C-Pause as per above.) */
4301 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
4302 wParam
= VK_NUMLOCK
;
4305 /* If not defined as a function key, change it to a WM_CHAR message. */
4306 if (lispy_function_keys
[wParam
] == 0)
4308 DWORD modifiers
= construct_console_modifiers ();
4310 if (!NILP (Vw32_recognize_altgr
)
4311 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
4313 /* Always let TranslateMessage handle AltGr key chords;
4314 for some reason, ToAscii doesn't always process AltGr
4315 chords correctly. */
4316 windows_translate
= 1;
4318 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
4320 /* Handle key chords including any modifiers other
4321 than shift directly, in order to preserve as much
4322 modifier information as possible. */
4323 if ('A' <= wParam
&& wParam
<= 'Z')
4325 /* Don't translate modified alphabetic keystrokes,
4326 so the user doesn't need to constantly switch
4327 layout to type control or meta keystrokes when
4328 the normal layout translates alphabetic
4329 characters to non-ascii characters. */
4330 if (!modifier_set (VK_SHIFT
))
4331 wParam
+= ('a' - 'A');
4336 /* Try to handle other keystrokes by determining the
4337 base character (ie. translating the base key plus
4341 KEY_EVENT_RECORD key
;
4343 key
.bKeyDown
= TRUE
;
4344 key
.wRepeatCount
= 1;
4345 key
.wVirtualKeyCode
= wParam
;
4346 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
4347 key
.uChar
.AsciiChar
= 0;
4348 key
.dwControlKeyState
= modifiers
;
4350 add
= w32_kbd_patch_key (&key
);
4351 /* 0 means an unrecognised keycode, negative means
4352 dead key. Ignore both. */
4355 /* Forward asciified character sequence. */
4356 post_character_message
4357 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
4358 w32_get_key_modifiers (wParam
, lParam
));
4359 w32_kbd_patch_key (&key
);
4366 /* Let TranslateMessage handle everything else. */
4367 windows_translate
= 1;
4373 if (windows_translate
)
4375 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
4377 windows_msg
.time
= GetMessageTime ();
4378 TranslateMessage (&windows_msg
);
4386 post_character_message (hwnd
, msg
, wParam
, lParam
,
4387 w32_get_key_modifiers (wParam
, lParam
));
4390 /* Simulate middle mouse button events when left and right buttons
4391 are used together, but only if user has two button mouse. */
4392 case WM_LBUTTONDOWN
:
4393 case WM_RBUTTONDOWN
:
4394 if (XINT (Vw32_num_mouse_buttons
) > 2)
4395 goto handle_plain_button
;
4398 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
4399 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
4401 if (button_state
& this)
4404 if (button_state
== 0)
4407 button_state
|= this;
4409 if (button_state
& other
)
4411 if (mouse_button_timer
)
4413 KillTimer (hwnd
, mouse_button_timer
);
4414 mouse_button_timer
= 0;
4416 /* Generate middle mouse event instead. */
4417 msg
= WM_MBUTTONDOWN
;
4418 button_state
|= MMOUSE
;
4420 else if (button_state
& MMOUSE
)
4422 /* Ignore button event if we've already generated a
4423 middle mouse down event. This happens if the
4424 user releases and press one of the two buttons
4425 after we've faked a middle mouse event. */
4430 /* Flush out saved message. */
4431 post_msg (&saved_mouse_button_msg
);
4433 wmsg
.dwModifiers
= w32_get_modifiers ();
4434 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4436 /* Clear message buffer. */
4437 saved_mouse_button_msg
.msg
.hwnd
= 0;
4441 /* Hold onto message for now. */
4442 mouse_button_timer
=
4443 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
4444 XINT (Vw32_mouse_button_tolerance
), NULL
);
4445 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
4446 saved_mouse_button_msg
.msg
.message
= msg
;
4447 saved_mouse_button_msg
.msg
.wParam
= wParam
;
4448 saved_mouse_button_msg
.msg
.lParam
= lParam
;
4449 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
4450 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
4457 if (XINT (Vw32_num_mouse_buttons
) > 2)
4458 goto handle_plain_button
;
4461 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
4462 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
4464 if ((button_state
& this) == 0)
4467 button_state
&= ~this;
4469 if (button_state
& MMOUSE
)
4471 /* Only generate event when second button is released. */
4472 if ((button_state
& other
) == 0)
4475 button_state
&= ~MMOUSE
;
4477 if (button_state
) abort ();
4484 /* Flush out saved message if necessary. */
4485 if (saved_mouse_button_msg
.msg
.hwnd
)
4487 post_msg (&saved_mouse_button_msg
);
4490 wmsg
.dwModifiers
= w32_get_modifiers ();
4491 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4493 /* Always clear message buffer and cancel timer. */
4494 saved_mouse_button_msg
.msg
.hwnd
= 0;
4495 KillTimer (hwnd
, mouse_button_timer
);
4496 mouse_button_timer
= 0;
4498 if (button_state
== 0)
4503 case WM_MBUTTONDOWN
:
4505 handle_plain_button
:
4510 if (parse_button (msg
, &button
, &up
))
4512 if (up
) ReleaseCapture ();
4513 else SetCapture (hwnd
);
4514 button
= (button
== 0) ? LMOUSE
:
4515 ((button
== 1) ? MMOUSE
: RMOUSE
);
4517 button_state
&= ~button
;
4519 button_state
|= button
;
4523 wmsg
.dwModifiers
= w32_get_modifiers ();
4524 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4529 if (XINT (Vw32_mouse_move_interval
) <= 0
4530 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4532 wmsg
.dwModifiers
= w32_get_modifiers ();
4533 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4537 /* Hang onto mouse move and scroll messages for a bit, to avoid
4538 sending such events to Emacs faster than it can process them.
4539 If we get more events before the timer from the first message
4540 expires, we just replace the first message. */
4542 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4544 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4545 XINT (Vw32_mouse_move_interval
), NULL
);
4547 /* Hold onto message for now. */
4548 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4549 saved_mouse_move_msg
.msg
.message
= msg
;
4550 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4551 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4552 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4553 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4558 wmsg
.dwModifiers
= w32_get_modifiers ();
4559 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4563 wmsg
.dwModifiers
= w32_get_modifiers ();
4564 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4568 /* Flush out saved messages if necessary. */
4569 if (wParam
== mouse_button_timer
)
4571 if (saved_mouse_button_msg
.msg
.hwnd
)
4573 post_msg (&saved_mouse_button_msg
);
4574 saved_mouse_button_msg
.msg
.hwnd
= 0;
4576 KillTimer (hwnd
, mouse_button_timer
);
4577 mouse_button_timer
= 0;
4579 else if (wParam
== mouse_move_timer
)
4581 if (saved_mouse_move_msg
.msg
.hwnd
)
4583 post_msg (&saved_mouse_move_msg
);
4584 saved_mouse_move_msg
.msg
.hwnd
= 0;
4586 KillTimer (hwnd
, mouse_move_timer
);
4587 mouse_move_timer
= 0;
4592 /* Windows doesn't send us focus messages when putting up and
4593 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4594 The only indication we get that something happened is receiving
4595 this message afterwards. So this is a good time to reset our
4596 keyboard modifiers' state. */
4603 /* We must ensure menu bar is fully constructed and up to date
4604 before allowing user interaction with it. To achieve this
4605 we send this message to the lisp thread and wait for a
4606 reply (whose value is not actually needed) to indicate that
4607 the menu bar is now ready for use, so we can now return.
4609 To remain responsive in the meantime, we enter a nested message
4610 loop that can process all other messages.
4612 However, we skip all this if the message results from calling
4613 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4614 thread a message because it is blocked on us at this point. We
4615 set menubar_active before calling TrackPopupMenu to indicate
4616 this (there is no possibility of confusion with real menubar
4619 f
= x_window_to_frame (dpyinfo
, hwnd
);
4621 && (f
->output_data
.w32
->menubar_active
4622 /* We can receive this message even in the absence of a
4623 menubar (ie. when the system menu is activated) - in this
4624 case we do NOT want to forward the message, otherwise it
4625 will cause the menubar to suddenly appear when the user
4626 had requested it to be turned off! */
4627 || f
->output_data
.w32
->menubar_widget
== NULL
))
4631 deferred_msg msg_buf
;
4633 /* Detect if message has already been deferred; in this case
4634 we cannot return any sensible value to ignore this. */
4635 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4638 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4641 case WM_EXITMENULOOP
:
4642 f
= x_window_to_frame (dpyinfo
, hwnd
);
4644 /* Indicate that menubar can be modified again. */
4646 f
->output_data
.w32
->menubar_active
= 0;
4650 wmsg
.dwModifiers
= w32_get_modifiers ();
4651 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4654 case WM_MEASUREITEM
:
4655 f
= x_window_to_frame (dpyinfo
, hwnd
);
4658 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4660 if (pMis
->CtlType
== ODT_MENU
)
4662 /* Work out dimensions for popup menu titles. */
4663 char * title
= (char *) pMis
->itemData
;
4664 HDC hdc
= GetDC (hwnd
);
4665 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4666 LOGFONT menu_logfont
;
4670 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4671 menu_logfont
.lfWeight
= FW_BOLD
;
4672 menu_font
= CreateFontIndirect (&menu_logfont
);
4673 old_font
= SelectObject (hdc
, menu_font
);
4675 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4678 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4679 pMis
->itemWidth
= size
.cx
;
4680 if (pMis
->itemHeight
< size
.cy
)
4681 pMis
->itemHeight
= size
.cy
;
4684 pMis
->itemWidth
= 0;
4686 SelectObject (hdc
, old_font
);
4687 DeleteObject (menu_font
);
4688 ReleaseDC (hwnd
, hdc
);
4695 f
= x_window_to_frame (dpyinfo
, hwnd
);
4698 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4700 if (pDis
->CtlType
== ODT_MENU
)
4702 /* Draw popup menu title. */
4703 char * title
= (char *) pDis
->itemData
;
4706 HDC hdc
= pDis
->hDC
;
4707 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4708 LOGFONT menu_logfont
;
4711 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4712 menu_logfont
.lfWeight
= FW_BOLD
;
4713 menu_font
= CreateFontIndirect (&menu_logfont
);
4714 old_font
= SelectObject (hdc
, menu_font
);
4716 /* Always draw title as if not selected. */
4719 + GetSystemMetrics (SM_CXMENUCHECK
),
4721 ETO_OPAQUE
, &pDis
->rcItem
,
4722 title
, strlen (title
), NULL
);
4724 SelectObject (hdc
, old_font
);
4725 DeleteObject (menu_font
);
4733 /* Still not right - can't distinguish between clicks in the
4734 client area of the frame from clicks forwarded from the scroll
4735 bars - may have to hook WM_NCHITTEST to remember the mouse
4736 position and then check if it is in the client area ourselves. */
4737 case WM_MOUSEACTIVATE
:
4738 /* Discard the mouse click that activates a frame, allowing the
4739 user to click anywhere without changing point (or worse!).
4740 Don't eat mouse clicks on scrollbars though!! */
4741 if (LOWORD (lParam
) == HTCLIENT
)
4742 return MA_ACTIVATEANDEAT
;
4746 case WM_ACTIVATEAPP
:
4748 case WM_WINDOWPOSCHANGED
:
4750 /* Inform lisp thread that a frame might have just been obscured
4751 or exposed, so should recheck visibility of all frames. */
4752 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4756 dpyinfo
->faked_key
= 0;
4758 register_hot_keys (hwnd
);
4761 unregister_hot_keys (hwnd
);
4768 wmsg
.dwModifiers
= w32_get_modifiers ();
4769 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4773 wmsg
.dwModifiers
= w32_get_modifiers ();
4774 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4777 case WM_WINDOWPOSCHANGING
:
4780 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
4782 wp
.length
= sizeof (WINDOWPLACEMENT
);
4783 GetWindowPlacement (hwnd
, &wp
);
4785 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
4792 DWORD internal_border
;
4793 DWORD scrollbar_extra
;
4796 wp
.length
= sizeof(wp
);
4797 GetWindowRect (hwnd
, &wr
);
4801 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
4802 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
4803 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
4804 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
4808 memset (&rect
, 0, sizeof (rect
));
4809 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
4810 GetMenu (hwnd
) != NULL
);
4812 /* Force width and height of client area to be exact
4813 multiples of the character cell dimensions. */
4814 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
4815 - 2 * internal_border
- scrollbar_extra
)
4817 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
4818 - 2 * internal_border
)
4823 /* For right/bottom sizing we can just fix the sizes.
4824 However for top/left sizing we will need to fix the X
4825 and Y positions as well. */
4830 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
4831 && (lppos
->flags
& SWP_NOMOVE
) == 0)
4833 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
4840 lppos
->flags
|= SWP_NOMOVE
;
4851 case WM_GETMINMAXINFO
:
4852 /* Hack to correct bug that allows Emacs frames to be resized
4853 below the Minimum Tracking Size. */
4854 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
4857 case WM_EMACS_CREATESCROLLBAR
:
4858 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
4859 (struct scroll_bar
*) lParam
);
4861 case WM_EMACS_SHOWWINDOW
:
4862 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4864 case WM_EMACS_SETFOREGROUND
:
4866 HWND foreground_window
;
4867 DWORD foreground_thread
, retval
;
4869 /* On NT 5.0, and apparently Windows 98, it is necessary to
4870 attach to the thread that currently has focus in order to
4871 pull the focus away from it. */
4872 foreground_window
= GetForegroundWindow ();
4873 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4874 if (!foreground_window
4875 || foreground_thread
== GetCurrentThreadId ()
4876 || !AttachThreadInput (GetCurrentThreadId (),
4877 foreground_thread
, TRUE
))
4878 foreground_thread
= 0;
4880 retval
= SetForegroundWindow ((HWND
) wParam
);
4882 /* Detach from the previous foreground thread. */
4883 if (foreground_thread
)
4884 AttachThreadInput (GetCurrentThreadId (),
4885 foreground_thread
, FALSE
);
4890 case WM_EMACS_SETWINDOWPOS
:
4892 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4893 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4894 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4897 case WM_EMACS_DESTROYWINDOW
:
4898 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4899 return DestroyWindow ((HWND
) wParam
);
4901 case WM_EMACS_TRACKPOPUPMENU
:
4906 pos
= (POINT
*)lParam
;
4907 flags
= TPM_CENTERALIGN
;
4908 if (button_state
& LMOUSE
)
4909 flags
|= TPM_LEFTBUTTON
;
4910 else if (button_state
& RMOUSE
)
4911 flags
|= TPM_RIGHTBUTTON
;
4913 /* Remember we did a SetCapture on the initial mouse down event,
4914 so for safety, we make sure the capture is cancelled now. */
4918 /* Use menubar_active to indicate that WM_INITMENU is from
4919 TrackPopupMenu below, and should be ignored. */
4920 f
= x_window_to_frame (dpyinfo
, hwnd
);
4922 f
->output_data
.w32
->menubar_active
= 1;
4924 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4928 /* Eat any mouse messages during popupmenu */
4929 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4931 /* Get the menu selection, if any */
4932 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4934 retval
= LOWORD (amsg
.wParam
);
4950 /* Check for messages registered at runtime. */
4951 if (msg
== msh_mousewheel
)
4953 wmsg
.dwModifiers
= w32_get_modifiers ();
4954 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4959 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
4963 /* The most common default return code for handled messages is 0. */
4968 my_create_window (f
)
4973 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4975 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4978 /* Create and set up the w32 window for frame F. */
4981 w32_window (f
, window_prompting
, minibuffer_only
)
4983 long window_prompting
;
4984 int minibuffer_only
;
4988 /* Use the resource name as the top-level window name
4989 for looking up resources. Make a non-Lisp copy
4990 for the window manager, so GC relocation won't bother it.
4992 Elsewhere we specify the window name for the window manager. */
4995 char *str
= (char *) XSTRING (Vx_resource_name
)->data
;
4996 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4997 strcpy (f
->namebuf
, str
);
5000 my_create_window (f
);
5002 validate_x_resource_name ();
5004 /* x_set_name normally ignores requests to set the name if the
5005 requested name is the same as the current name. This is the one
5006 place where that assumption isn't correct; f->name is set, but
5007 the server hasn't been told. */
5010 int explicit = f
->explicit_name
;
5012 f
->explicit_name
= 0;
5015 x_set_name (f
, name
, explicit);
5020 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
5021 initialize_frame_menubar (f
);
5023 if (FRAME_W32_WINDOW (f
) == 0)
5024 error ("Unable to create window");
5027 /* Handle the icon stuff for this window. Perhaps later we might
5028 want an x_set_icon_position which can be called interactively as
5036 Lisp_Object icon_x
, icon_y
;
5038 /* Set the position of the icon. Note that Windows 95 groups all
5039 icons in the tray. */
5040 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
5041 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
5042 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
5044 CHECK_NUMBER (icon_x
, 0);
5045 CHECK_NUMBER (icon_y
, 0);
5047 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
5048 error ("Both left and top icon corners of icon must be specified");
5052 if (! EQ (icon_x
, Qunbound
))
5053 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
5056 /* Start up iconic or window? */
5057 x_wm_set_window_state
5058 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
5062 x_text_icon (f
, (char *) XSTRING ((!NILP (f
->icon_name
)
5075 XGCValues gc_values
;
5079 /* Create the GC's of this frame.
5080 Note that many default values are used. */
5083 gc_values
.font
= f
->output_data
.w32
->font
;
5085 /* Cursor has cursor-color background, background-color foreground. */
5086 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
5087 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
5088 f
->output_data
.w32
->cursor_gc
5089 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
5090 (GCFont
| GCForeground
| GCBackground
),
5094 f
->output_data
.w32
->white_relief
.gc
= 0;
5095 f
->output_data
.w32
->black_relief
.gc
= 0;
5101 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
5103 "Make a new window, which is called a \"frame\" in Emacs terms.\n\
5104 Returns an Emacs frame object.\n\
5105 ALIST is an alist of frame parameters.\n\
5106 If the parameters specify that the frame should not have a minibuffer,\n\
5107 and do not specify a specific minibuffer window to use,\n\
5108 then `default-minibuffer-frame' must be a frame whose minibuffer can\n\
5109 be shared by the new frame.\n\
5111 This function is an internal primitive--use `make-frame' instead.")
5116 Lisp_Object frame
, tem
;
5118 int minibuffer_only
= 0;
5119 long window_prompting
= 0;
5121 int count
= specpdl_ptr
- specpdl
;
5122 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5123 Lisp_Object display
;
5124 struct w32_display_info
*dpyinfo
= NULL
;
5130 /* Use this general default value to start with
5131 until we know if this frame has a specified name. */
5132 Vx_resource_name
= Vinvocation_name
;
5134 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
5135 if (EQ (display
, Qunbound
))
5137 dpyinfo
= check_x_display_info (display
);
5139 kb
= dpyinfo
->kboard
;
5141 kb
= &the_only_kboard
;
5144 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5146 && ! EQ (name
, Qunbound
)
5148 error ("Invalid frame name--not a string or nil");
5151 Vx_resource_name
= name
;
5153 /* See if parent window is specified. */
5154 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
5155 if (EQ (parent
, Qunbound
))
5157 if (! NILP (parent
))
5158 CHECK_NUMBER (parent
, 0);
5160 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
5161 /* No need to protect DISPLAY because that's not used after passing
5162 it to make_frame_without_minibuffer. */
5164 GCPRO4 (parms
, parent
, name
, frame
);
5165 tem
= w32_get_arg (parms
, Qminibuffer
, "minibuffer", "Minibuffer",
5167 if (EQ (tem
, Qnone
) || NILP (tem
))
5168 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
5169 else if (EQ (tem
, Qonly
))
5171 f
= make_minibuffer_frame ();
5172 minibuffer_only
= 1;
5174 else if (WINDOWP (tem
))
5175 f
= make_frame_without_minibuffer (tem
, kb
, display
);
5179 XSETFRAME (frame
, f
);
5181 /* Note that Windows does support scroll bars. */
5182 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
5183 /* By default, make scrollbars the system standard width. */
5184 f
->scroll_bar_pixel_width
= GetSystemMetrics (SM_CXVSCROLL
);
5186 f
->output_method
= output_w32
;
5187 f
->output_data
.w32
=
5188 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5189 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5191 FRAME_FONTSET (f
) = -1;
5194 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
5195 if (! STRINGP (f
->icon_name
))
5196 f
->icon_name
= Qnil
;
5198 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
5200 FRAME_KBOARD (f
) = kb
;
5203 /* Specify the parent under which to make this window. */
5207 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
5208 f
->output_data
.w32
->explicit_parent
= 1;
5212 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5213 f
->output_data
.w32
->explicit_parent
= 0;
5216 /* Set the name; the functions to which we pass f expect the name to
5218 if (EQ (name
, Qunbound
) || NILP (name
))
5220 f
->name
= build_string (dpyinfo
->w32_id_name
);
5221 f
->explicit_name
= 0;
5226 f
->explicit_name
= 1;
5227 /* use the frame's title when getting resources for this frame. */
5228 specbind (Qx_resource_name
, name
);
5231 /* Extract the window parameters from the supplied values
5232 that are needed to determine window geometry. */
5236 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
5239 /* First, try whatever font the caller has specified. */
5242 tem
= Fquery_fontset (font
, Qnil
);
5244 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
5246 font
= x_new_font (f
, XSTRING (font
)->data
);
5248 /* Try out a font which we hope has bold and italic variations. */
5249 if (!STRINGP (font
))
5250 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
5251 if (! STRINGP (font
))
5252 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5253 /* If those didn't work, look for something which will at least work. */
5254 if (! STRINGP (font
))
5255 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
5257 if (! STRINGP (font
))
5258 font
= build_string ("Fixedsys");
5260 x_default_parameter (f
, parms
, Qfont
, font
,
5261 "font", "Font", RES_TYPE_STRING
);
5264 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5265 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5266 /* This defaults to 2 in order to match xterm. We recognize either
5267 internalBorderWidth or internalBorder (which is what xterm calls
5269 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5273 value
= w32_get_arg (parms
, Qinternal_border_width
,
5274 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
5275 if (! EQ (value
, Qunbound
))
5276 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5279 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5280 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
5281 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
5282 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qright
,
5283 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5285 /* Also do the stuff which must be set before the window exists. */
5286 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5287 "foreground", "Foreground", RES_TYPE_STRING
);
5288 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5289 "background", "Background", RES_TYPE_STRING
);
5290 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5291 "pointerColor", "Foreground", RES_TYPE_STRING
);
5292 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5293 "cursorColor", "Foreground", RES_TYPE_STRING
);
5294 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5295 "borderColor", "BorderColor", RES_TYPE_STRING
);
5296 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
5297 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5298 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
5299 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
5302 /* Init faces before x_default_parameter is called for scroll-bar
5303 parameters because that function calls x_set_scroll_bar_width,
5304 which calls change_frame_size, which calls Fset_window_buffer,
5305 which runs hooks, which call Fvertical_motion. At the end, we
5306 end up in init_iterator with a null face cache, which should not
5308 init_frame_faces (f
);
5310 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
5311 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
5312 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (0),
5313 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
5314 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
5315 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5316 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
5317 "title", "Title", RES_TYPE_STRING
);
5319 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5320 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5321 window_prompting
= x_figure_window_size (f
, parms
);
5323 if (window_prompting
& XNegative
)
5325 if (window_prompting
& YNegative
)
5326 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
5328 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
5332 if (window_prompting
& YNegative
)
5333 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
5335 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
5338 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
5340 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5341 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5343 /* Create the window. Add the tool-bar height to the initial frame
5344 height so that the user gets a text display area of the size he
5345 specified with -g or via the registry. Later changes of the
5346 tool-bar height don't change the frame size. This is done so that
5347 users can create tall Emacs frames without having to guess how
5348 tall the tool-bar will get. */
5349 f
->height
+= FRAME_TOOL_BAR_LINES (f
);
5350 w32_window (f
, window_prompting
, minibuffer_only
);
5355 /* Now consider the frame official. */
5356 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5357 Vframe_list
= Fcons (frame
, Vframe_list
);
5359 /* We need to do this after creating the window, so that the
5360 icon-creation functions can say whose icon they're describing. */
5361 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
5362 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5364 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5365 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5366 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5367 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5368 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5369 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5370 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
5371 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5373 /* Dimensions, especially f->height, must be done via change_frame_size.
5374 Change will not be effected unless different from the current
5379 SET_FRAME_WIDTH (f
, 0);
5380 change_frame_size (f
, height
, width
, 1, 0, 0);
5382 /* Tell the server what size and position, etc, we want, and how
5383 badly we want them. This should be done after we have the menu
5384 bar so that its size can be taken into account. */
5386 x_wm_set_size_hint (f
, window_prompting
, 0);
5389 /* Make the window appear on the frame and enable display, unless
5390 the caller says not to. However, with explicit parent, Emacs
5391 cannot control visibility, so don't try. */
5392 if (! f
->output_data
.w32
->explicit_parent
)
5394 Lisp_Object visibility
;
5396 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5397 if (EQ (visibility
, Qunbound
))
5400 if (EQ (visibility
, Qicon
))
5401 x_iconify_frame (f
);
5402 else if (! NILP (visibility
))
5403 x_make_frame_visible (f
);
5405 /* Must have been Qnil. */
5409 return unbind_to (count
, frame
);
5412 /* FRAME is used only to get a handle on the X display. We don't pass the
5413 display info directly because we're called from frame.c, which doesn't
5414 know about that structure. */
5416 x_get_focus_frame (frame
)
5417 struct frame
*frame
;
5419 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
5421 if (! dpyinfo
->w32_focus_frame
)
5424 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5428 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
5429 "Give FRAME input focus, raising to foreground if necessary.")
5433 x_focus_on_frame (check_x_frame (frame
));
5438 /* Return the charset portion of a font name. */
5439 char * xlfd_charset_of_font (char * fontname
)
5441 char *charset
, *encoding
;
5443 encoding
= strrchr(fontname
, '-');
5448 charset
= strrchr(fontname
, '-');
5451 if (!charset
|| strcmp(charset
, "-*-*") == 0)
5457 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
5458 int size
, char* filename
);
5459 BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
, char * charset
);
5462 w32_load_system_font (f
,fontname
,size
)
5467 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5468 Lisp_Object font_names
;
5470 /* Get a list of all the fonts that match this name. Once we
5471 have a list of matching fonts, we compare them against the fonts
5472 we already have loaded by comparing names. */
5473 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
5475 if (!NILP (font_names
))
5480 /* First check if any are already loaded, as that is cheaper
5481 than loading another one. */
5482 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5483 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
5484 if (dpyinfo
->font_table
[i
].name
5485 && (!strcmp (dpyinfo
->font_table
[i
].name
,
5486 XSTRING (XCAR (tail
))->data
)
5487 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
5488 XSTRING (XCAR (tail
))->data
)))
5489 return (dpyinfo
->font_table
+ i
);
5491 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
5493 else if (w32_strict_fontnames
)
5495 /* If EnumFontFamiliesEx was available, we got a full list of
5496 fonts back so stop now to avoid the possibility of loading a
5497 random font. If we had to fall back to EnumFontFamilies, the
5498 list is incomplete, so continue whether the font we want was
5500 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5501 FARPROC enum_font_families_ex
5502 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
5503 if (enum_font_families_ex
)
5507 /* Load the font and add it to the table. */
5509 char *full_name
, *encoding
, *charset
;
5511 struct font_info
*fontp
;
5516 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
5519 if (!*lf
.lfFaceName
)
5520 /* If no name was specified for the font, we get a random font
5521 from CreateFontIndirect - this is not particularly
5522 desirable, especially since CreateFontIndirect does not
5523 fill out the missing name in lf, so we never know what we
5527 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
5528 bzero (font
, sizeof (*font
));
5530 /* Set bdf to NULL to indicate that this is a Windows font. */
5535 font
->hfont
= CreateFontIndirect (&lf
);
5537 if (font
->hfont
== NULL
)
5545 int codepage
= w32_codepage_for_font (fontname
);
5547 hdc
= GetDC (dpyinfo
->root_window
);
5548 oldobj
= SelectObject (hdc
, font
->hfont
);
5550 ok
= GetTextMetrics (hdc
, &font
->tm
);
5551 if (codepage
== CP_UNICODE
)
5552 font
->double_byte_p
= 1;
5554 font
->double_byte_p
= GetFontLanguageInfo(hdc
) & GCP_DBCS
;
5556 SelectObject (hdc
, oldobj
);
5557 ReleaseDC (dpyinfo
->root_window
, hdc
);
5558 /* Fill out details in lf according to the font that was
5560 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
5561 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
5562 lf
.lfWeight
= font
->tm
.tmWeight
;
5563 lf
.lfItalic
= font
->tm
.tmItalic
;
5564 lf
.lfCharSet
= font
->tm
.tmCharSet
;
5565 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
5566 ? VARIABLE_PITCH
: FIXED_PITCH
);
5567 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
5568 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
5570 w32_cache_char_metrics (font
);
5577 w32_unload_font (dpyinfo
, font
);
5581 /* Find a free slot in the font table. */
5582 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
5583 if (dpyinfo
->font_table
[i
].name
== NULL
)
5586 /* If no free slot found, maybe enlarge the font table. */
5587 if (i
== dpyinfo
->n_fonts
5588 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
5591 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
5592 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
5594 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
5597 fontp
= dpyinfo
->font_table
+ i
;
5598 if (i
== dpyinfo
->n_fonts
)
5601 /* Now fill in the slots of *FONTP. */
5604 fontp
->font_idx
= i
;
5605 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
5606 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
5608 charset
= xlfd_charset_of_font (fontname
);
5610 /* Work out the font's full name. */
5611 full_name
= (char *)xmalloc (100);
5612 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
5613 fontp
->full_name
= full_name
;
5616 /* If all else fails - just use the name we used to load it. */
5618 fontp
->full_name
= fontp
->name
;
5621 fontp
->size
= FONT_WIDTH (font
);
5622 fontp
->height
= FONT_HEIGHT (font
);
5624 /* The slot `encoding' specifies how to map a character
5625 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
5626 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
5627 (0:0x20..0x7F, 1:0xA0..0xFF,
5628 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
5629 2:0xA020..0xFF7F). For the moment, we don't know which charset
5630 uses this font. So, we set information in fontp->encoding[1]
5631 which is never used by any charset. If mapping can't be
5632 decided, set FONT_ENCODING_NOT_DECIDED. */
5634 /* SJIS fonts need to be set to type 4, all others seem to work as
5635 type FONT_ENCODING_NOT_DECIDED. */
5636 encoding
= strrchr (fontp
->name
, '-');
5637 if (encoding
&& stricmp (encoding
+1, "sjis") == 0)
5638 fontp
->encoding
[1] = 4;
5640 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
5642 /* The following three values are set to 0 under W32, which is
5643 what they get set to if XGetFontProperty fails under X. */
5644 fontp
->baseline_offset
= 0;
5645 fontp
->relative_compose
= 0;
5646 fontp
->default_ascent
= 0;
5648 /* Set global flag fonts_changed_p to non-zero if the font loaded
5649 has a character with a smaller width than any other character
5650 before, or if the font loaded has a smalle>r height than any
5651 other font loaded before. If this happens, it will make a
5652 glyph matrix reallocation necessary. */
5653 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
5659 /* Load font named FONTNAME of size SIZE for frame F, and return a
5660 pointer to the structure font_info while allocating it dynamically.
5661 If loading fails, return NULL. */
5663 w32_load_font (f
,fontname
,size
)
5668 Lisp_Object bdf_fonts
;
5669 struct font_info
*retval
= NULL
;
5671 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
));
5673 while (!retval
&& CONSP (bdf_fonts
))
5675 char *bdf_name
, *bdf_file
;
5676 Lisp_Object bdf_pair
;
5678 bdf_name
= XSTRING (XCAR (bdf_fonts
))->data
;
5679 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
5680 bdf_file
= XSTRING (XCDR (bdf_pair
))->data
;
5682 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
5684 bdf_fonts
= XCDR (bdf_fonts
);
5690 return w32_load_system_font(f
, fontname
, size
);
5695 w32_unload_font (dpyinfo
, font
)
5696 struct w32_display_info
*dpyinfo
;
5701 if (font
->per_char
) xfree (font
->per_char
);
5702 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
5704 if (font
->hfont
) DeleteObject(font
->hfont
);
5709 /* The font conversion stuff between x and w32 */
5711 /* X font string is as follows (from faces.el)
5715 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
5716 * (weight\? "\\([^-]*\\)") ; 1
5717 * (slant "\\([ior]\\)") ; 2
5718 * (slant\? "\\([^-]?\\)") ; 2
5719 * (swidth "\\([^-]*\\)") ; 3
5720 * (adstyle "[^-]*") ; 4
5721 * (pixelsize "[0-9]+")
5722 * (pointsize "[0-9][0-9]+")
5723 * (resx "[0-9][0-9]+")
5724 * (resy "[0-9][0-9]+")
5725 * (spacing "[cmp?*]")
5726 * (avgwidth "[0-9]+")
5727 * (registry "[^-]+")
5728 * (encoding "[^-]+")
5733 x_to_w32_weight (lpw
)
5736 if (!lpw
) return (FW_DONTCARE
);
5738 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
5739 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
5740 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
5741 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
5742 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
5743 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
5744 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
5745 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
5746 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
5747 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
5754 w32_to_x_weight (fnweight
)
5757 if (fnweight
>= FW_HEAVY
) return "heavy";
5758 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
5759 if (fnweight
>= FW_BOLD
) return "bold";
5760 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
5761 if (fnweight
>= FW_MEDIUM
) return "medium";
5762 if (fnweight
>= FW_NORMAL
) return "normal";
5763 if (fnweight
>= FW_LIGHT
) return "light";
5764 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
5765 if (fnweight
>= FW_THIN
) return "thin";
5771 x_to_w32_charset (lpcs
)
5774 Lisp_Object this_entry
, w32_charset
;
5776 /* Look through w32-charset-info-alist for the character set.
5777 Format of each entry is
5778 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5780 this_entry
= Fassoc (build_string(lpcs
), Vw32_charset_info_alist
);
5782 if (NILP(this_entry
))
5784 /* At startup, we want iso8859-1 fonts to come up properly. */
5785 if (stricmp(lpcs
, "iso8859-1") == 0)
5786 return ANSI_CHARSET
;
5788 return DEFAULT_CHARSET
;
5791 w32_charset
= Fcar (Fcdr (this_entry
));
5793 // Translate Lisp symbol to number.
5794 if (w32_charset
== Qw32_charset_ansi
)
5795 return ANSI_CHARSET
;
5796 if (w32_charset
== Qw32_charset_symbol
)
5797 return SYMBOL_CHARSET
;
5798 if (w32_charset
== Qw32_charset_shiftjis
)
5799 return SHIFTJIS_CHARSET
;
5800 if (w32_charset
== Qw32_charset_hangeul
)
5801 return HANGEUL_CHARSET
;
5802 if (w32_charset
== Qw32_charset_chinesebig5
)
5803 return CHINESEBIG5_CHARSET
;
5804 if (w32_charset
== Qw32_charset_gb2312
)
5805 return GB2312_CHARSET
;
5806 if (w32_charset
== Qw32_charset_oem
)
5808 #ifdef JOHAB_CHARSET
5809 if (w32_charset
== Qw32_charset_johab
)
5810 return JOHAB_CHARSET
;
5811 if (w32_charset
== Qw32_charset_easteurope
)
5812 return EASTEUROPE_CHARSET
;
5813 if (w32_charset
== Qw32_charset_turkish
)
5814 return TURKISH_CHARSET
;
5815 if (w32_charset
== Qw32_charset_baltic
)
5816 return BALTIC_CHARSET
;
5817 if (w32_charset
== Qw32_charset_russian
)
5818 return RUSSIAN_CHARSET
;
5819 if (w32_charset
== Qw32_charset_arabic
)
5820 return ARABIC_CHARSET
;
5821 if (w32_charset
== Qw32_charset_greek
)
5822 return GREEK_CHARSET
;
5823 if (w32_charset
== Qw32_charset_hebrew
)
5824 return HEBREW_CHARSET
;
5825 if (w32_charset
== Qw32_charset_vietnamese
)
5826 return VIETNAMESE_CHARSET
;
5827 if (w32_charset
== Qw32_charset_thai
)
5828 return THAI_CHARSET
;
5829 if (w32_charset
== Qw32_charset_mac
)
5831 #endif /* JOHAB_CHARSET */
5832 #ifdef UNICODE_CHARSET
5833 if (w32_charset
== Qw32_charset_unicode
)
5834 return UNICODE_CHARSET
;
5837 return DEFAULT_CHARSET
;
5842 w32_to_x_charset (fncharset
)
5845 static char buf
[16];
5846 Lisp_Object charset_type
;
5851 /* Handle startup case of w32-charset-info-alist not
5852 being set up yet. */
5853 if (NILP(Vw32_charset_info_alist
))
5855 charset_type
= Qw32_charset_ansi
;
5857 case DEFAULT_CHARSET
:
5858 charset_type
= Qw32_charset_default
;
5860 case SYMBOL_CHARSET
:
5861 charset_type
= Qw32_charset_symbol
;
5863 case SHIFTJIS_CHARSET
:
5864 charset_type
= Qw32_charset_shiftjis
;
5866 case HANGEUL_CHARSET
:
5867 charset_type
= Qw32_charset_hangeul
;
5869 case GB2312_CHARSET
:
5870 charset_type
= Qw32_charset_gb2312
;
5872 case CHINESEBIG5_CHARSET
:
5873 charset_type
= Qw32_charset_chinesebig5
;
5876 charset_type
= Qw32_charset_oem
;
5879 /* More recent versions of Windows (95 and NT4.0) define more
5881 #ifdef EASTEUROPE_CHARSET
5882 case EASTEUROPE_CHARSET
:
5883 charset_type
= Qw32_charset_easteurope
;
5885 case TURKISH_CHARSET
:
5886 charset_type
= Qw32_charset_turkish
;
5888 case BALTIC_CHARSET
:
5889 charset_type
= Qw32_charset_baltic
;
5891 case RUSSIAN_CHARSET
:
5892 charset_type
= Qw32_charset_russian
;
5894 case ARABIC_CHARSET
:
5895 charset_type
= Qw32_charset_arabic
;
5898 charset_type
= Qw32_charset_greek
;
5900 case HEBREW_CHARSET
:
5901 charset_type
= Qw32_charset_hebrew
;
5903 case VIETNAMESE_CHARSET
:
5904 charset_type
= Qw32_charset_vietnamese
;
5907 charset_type
= Qw32_charset_thai
;
5910 charset_type
= Qw32_charset_mac
;
5913 charset_type
= Qw32_charset_johab
;
5917 #ifdef UNICODE_CHARSET
5918 case UNICODE_CHARSET
:
5919 charset_type
= Qw32_charset_unicode
;
5923 /* Encode numerical value of unknown charset. */
5924 sprintf (buf
, "*-#%u", fncharset
);
5930 char * best_match
= NULL
;
5932 /* Look through w32-charset-info-alist for the character set.
5933 Prefer ISO codepages, and prefer lower numbers in the ISO
5934 range. Only return charsets for codepages which are installed.
5936 Format of each entry is
5937 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5939 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5942 Lisp_Object w32_charset
;
5943 Lisp_Object codepage
;
5945 Lisp_Object this_entry
= XCAR (rest
);
5947 /* Skip invalid entries in alist. */
5948 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5949 || !CONSP (XCDR (this_entry
))
5950 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5953 x_charset
= XSTRING (XCAR (this_entry
))->data
;
5954 w32_charset
= XCAR (XCDR (this_entry
));
5955 codepage
= XCDR (XCDR (this_entry
));
5957 /* Look for Same charset and a valid codepage (or non-int
5958 which means ignore). */
5959 if (w32_charset
== charset_type
5960 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
5961 || IsValidCodePage (XINT (codepage
))))
5963 /* If we don't have a match already, then this is the
5966 best_match
= x_charset
;
5967 /* If this is an ISO codepage, and the best so far isn't,
5968 then this is better. */
5969 else if (stricmp (best_match
, "iso") != 0
5970 && stricmp (x_charset
, "iso") == 0)
5971 best_match
= x_charset
;
5972 /* If both are ISO8859 codepages, choose the one with the
5973 lowest number in the encoding field. */
5974 else if (stricmp (best_match
, "iso8859-") == 0
5975 && stricmp (x_charset
, "iso8859-") == 0)
5977 int best_enc
= atoi (best_match
+ 8);
5978 int this_enc
= atoi (x_charset
+ 8);
5979 if (this_enc
> 0 && this_enc
< best_enc
)
5980 best_match
= x_charset
;
5985 /* If no match, encode the numeric value. */
5988 sprintf (buf
, "*-#%u", fncharset
);
5992 strncpy(buf
, best_match
, 15);
5999 /* Get the Windows codepage corresponding to the specified font. The
6000 charset info in the font name is used to look up
6001 w32-charset-to-codepage-alist. */
6003 w32_codepage_for_font (char *fontname
)
6005 Lisp_Object codepage
, entry
;
6006 char *charset_str
, *charset
, *end
;
6008 if (NILP (Vw32_charset_info_alist
))
6011 /* Extract charset part of font string. */
6012 charset
= xlfd_charset_of_font (fontname
);
6017 charset_str
= (char *) alloca (strlen (charset
));
6018 strcpy (charset_str
, charset
);
6020 /* Remove leading "*-". */
6021 if (strncmp ("*-", charset_str
, 2) == 0)
6022 charset
= charset_str
+ 2;
6024 charset
= charset_str
;
6026 /* Stop match at wildcard (including preceding '-'). */
6027 if (end
= strchr (charset
, '*'))
6029 if (end
> charset
&& *(end
-1) == '-')
6034 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6038 codepage
= Fcdr (Fcdr (entry
));
6040 if (NILP (codepage
))
6042 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
6044 else if (INTEGERP (codepage
))
6045 return XINT (codepage
);
6052 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
6053 LOGFONT
* lplogfont
;
6056 char * specific_charset
;
6060 char height_pixels
[8];
6062 char width_pixels
[8];
6063 char *fontname_dash
;
6064 int display_resy
= one_w32_display_info
.resy
;
6065 int display_resx
= one_w32_display_info
.resx
;
6067 struct coding_system coding
;
6069 if (!lpxstr
) abort ();
6074 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
6075 fonttype
= "raster";
6076 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
6077 fonttype
= "outline";
6079 fonttype
= "unknown";
6081 setup_coding_system (Fcheck_coding_system (Vw32_system_coding_system
),
6083 coding
.src_multibyte
= 0;
6084 coding
.dst_multibyte
= 1;
6085 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6086 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
6088 fontname
= alloca(sizeof(*fontname
) * bufsz
);
6089 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
6090 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
6091 *(fontname
+ coding
.produced
) = '\0';
6093 /* Replace dashes with underscores so the dashes are not
6095 fontname_dash
= fontname
;
6096 while (fontname_dash
= strchr (fontname_dash
, '-'))
6097 *fontname_dash
= '_';
6099 if (lplogfont
->lfHeight
)
6101 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
6102 sprintf (height_dpi
, "%u",
6103 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
6107 strcpy (height_pixels
, "*");
6108 strcpy (height_dpi
, "*");
6110 if (lplogfont
->lfWidth
)
6111 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
6113 strcpy (width_pixels
, "*");
6115 _snprintf (lpxstr
, len
- 1,
6116 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
6117 fonttype
, /* foundry */
6118 fontname
, /* family */
6119 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
6120 lplogfont
->lfItalic
?'i':'r', /* slant */
6122 /* add style name */
6123 height_pixels
, /* pixel size */
6124 height_dpi
, /* point size */
6125 display_resx
, /* resx */
6126 display_resy
, /* resy */
6127 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
6128 ? 'p' : 'c', /* spacing */
6129 width_pixels
, /* avg width */
6130 specific_charset
? specific_charset
6131 : w32_to_x_charset (lplogfont
->lfCharSet
)
6132 /* charset registry and encoding */
6135 lpxstr
[len
- 1] = 0; /* just to be sure */
6140 x_to_w32_font (lpxstr
, lplogfont
)
6142 LOGFONT
* lplogfont
;
6144 struct coding_system coding
;
6146 if (!lplogfont
) return (FALSE
);
6148 memset (lplogfont
, 0, sizeof (*lplogfont
));
6150 /* Set default value for each field. */
6152 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
6153 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
6154 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
6156 /* go for maximum quality */
6157 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
6158 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
6159 lplogfont
->lfQuality
= PROOF_QUALITY
;
6162 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
6163 lplogfont
->lfWeight
= FW_DONTCARE
;
6164 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
6169 /* Provide a simple escape mechanism for specifying Windows font names
6170 * directly -- if font spec does not beginning with '-', assume this
6172 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
6178 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
6179 width
[10], resy
[10], remainder
[20];
6181 int dpi
= one_w32_display_info
.resy
;
6183 fields
= sscanf (lpxstr
,
6184 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%19s",
6185 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
6186 if (fields
== EOF
) return (FALSE
);
6188 /* If wildcards cover more than one field, we don't know which
6189 field is which, so don't fill any in. */
6194 if (fields
> 0 && name
[0] != '*')
6200 (Fcheck_coding_system (Vw32_system_coding_system
), &coding
);
6201 coding
.src_multibyte
= 1;
6202 coding
.dst_multibyte
= 1;
6203 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
6204 buf
= (unsigned char *) alloca (bufsize
);
6205 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6206 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
6207 if (coding
.produced
>= LF_FACESIZE
)
6208 coding
.produced
= LF_FACESIZE
- 1;
6209 buf
[coding
.produced
] = 0;
6210 strcpy (lplogfont
->lfFaceName
, buf
);
6214 lplogfont
->lfFaceName
[0] = '\0';
6219 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6223 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
6227 if (fields
> 0 && pixels
[0] != '*')
6228 lplogfont
->lfHeight
= atoi (pixels
);
6232 if (fields
> 0 && resy
[0] != '*')
6235 if (tem
> 0) dpi
= tem
;
6238 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
6239 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
6242 lplogfont
->lfPitchAndFamily
=
6243 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
6247 if (fields
> 0 && width
[0] != '*')
6248 lplogfont
->lfWidth
= atoi (width
) / 10;
6252 /* Strip the trailing '-' if present. (it shouldn't be, as it
6253 fails the test against xlfd-tight-regexp in fontset.el). */
6255 int len
= strlen (remainder
);
6256 if (len
> 0 && remainder
[len
-1] == '-')
6257 remainder
[len
-1] = 0;
6259 encoding
= remainder
;
6260 if (strncmp (encoding
, "*-", 2) == 0)
6262 lplogfont
->lfCharSet
= x_to_w32_charset (fields
> 0 ? encoding
: "");
6267 char name
[100], height
[10], width
[10], weight
[20];
6269 fields
= sscanf (lpxstr
,
6270 "%99[^:]:%9[^:]:%9[^:]:%19s",
6271 name
, height
, width
, weight
);
6273 if (fields
== EOF
) return (FALSE
);
6277 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
6278 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
6282 lplogfont
->lfFaceName
[0] = 0;
6288 lplogfont
->lfHeight
= atoi (height
);
6293 lplogfont
->lfWidth
= atoi (width
);
6297 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6300 /* This makes TrueType fonts work better. */
6301 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
6306 /* Strip the pixel height and point height from the given xlfd, and
6307 return the pixel height. If no pixel height is specified, calculate
6308 one from the point height, or if that isn't defined either, return
6309 0 (which usually signifies a scalable font).
6311 int xlfd_strip_height (char *fontname
)
6313 int pixel_height
, point_height
, dpi
, field_number
;
6314 char *read_from
, *write_to
;
6318 pixel_height
= field_number
= 0;
6321 /* Look for height fields. */
6322 for (read_from
= fontname
; *read_from
; read_from
++)
6324 if (*read_from
== '-')
6327 if (field_number
== 7) /* Pixel height. */
6330 write_to
= read_from
;
6332 /* Find end of field. */
6333 for (;*read_from
&& *read_from
!= '-'; read_from
++)
6336 /* Split the fontname at end of field. */
6342 pixel_height
= atoi (write_to
);
6343 /* Blank out field. */
6344 if (read_from
> write_to
)
6349 /* If the pixel height field is at the end (partial xlfd),
6352 return pixel_height
;
6354 /* If we got a pixel height, the point height can be
6355 ignored. Just blank it out and break now. */
6358 /* Find end of point size field. */
6359 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6365 /* Blank out the point size field. */
6366 if (read_from
> write_to
)
6372 return pixel_height
;
6376 /* If the point height is already blank, break now. */
6377 if (*read_from
== '-')
6383 else if (field_number
== 8)
6385 /* If we didn't get a pixel height, try to get the point
6386 height and convert that. */
6388 char *point_size_start
= read_from
++;
6390 /* Find end of field. */
6391 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6400 point_size
= atoi (point_size_start
);
6402 /* Convert to pixel height. */
6403 pixel_height
= point_size
6404 * one_w32_display_info
.height_in
/ 720;
6406 /* Blank out this field and break. */
6414 /* Shift the rest of the font spec into place. */
6415 if (write_to
&& read_from
> write_to
)
6417 for (; *read_from
; read_from
++, write_to
++)
6418 *write_to
= *read_from
;
6422 return pixel_height
;
6425 /* Assume parameter 1 is fully qualified, no wildcards. */
6427 w32_font_match (fontname
, pattern
)
6431 char *regex
= alloca (strlen (pattern
) * 2);
6432 char *font_name_copy
= alloca (strlen (fontname
) + 1);
6435 /* Copy fontname so we can modify it during comparison. */
6436 strcpy (font_name_copy
, fontname
);
6441 /* Turn pattern into a regexp and do a regexp match. */
6442 for (; *pattern
; pattern
++)
6444 if (*pattern
== '?')
6446 else if (*pattern
== '*')
6457 /* Strip out font heights and compare them seperately, since
6458 rounding error can cause mismatches. This also allows a
6459 comparison between a font that declares only a pixel height and a
6460 pattern that declares the point height.
6463 int font_height
, pattern_height
;
6465 font_height
= xlfd_strip_height (font_name_copy
);
6466 pattern_height
= xlfd_strip_height (regex
);
6468 /* Compare now, and don't bother doing expensive regexp matching
6469 if the heights differ. */
6470 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
6474 return (fast_c_string_match_ignore_case (build_string (regex
),
6475 font_name_copy
) >= 0);
6478 /* Callback functions, and a structure holding info they need, for
6479 listing system fonts on W32. We need one set of functions to do the
6480 job properly, but these don't work on NT 3.51 and earlier, so we
6481 have a second set which don't handle character sets properly to
6484 In both cases, there are two passes made. The first pass gets one
6485 font from each family, the second pass lists all the fonts from
6488 typedef struct enumfont_t
6493 XFontStruct
*size_ref
;
6494 Lisp_Object
*pattern
;
6499 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
6501 NEWTEXTMETRIC
* lptm
;
6505 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
6508 /* Check that the character set matches if it was specified */
6509 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6510 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6515 Lisp_Object width
= Qnil
;
6516 char *charset
= NULL
;
6518 /* Truetype fonts do not report their true metrics until loaded */
6519 if (FontType
!= RASTER_FONTTYPE
)
6521 if (!NILP (*(lpef
->pattern
)))
6523 /* Scalable fonts are as big as you want them to be. */
6524 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6525 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6526 width
= make_number (lpef
->logfont
.lfWidth
);
6530 lplf
->elfLogFont
.lfHeight
= 0;
6531 lplf
->elfLogFont
.lfWidth
= 0;
6535 /* Make sure the height used here is the same as everywhere
6536 else (ie character height, not cell height). */
6537 if (lplf
->elfLogFont
.lfHeight
> 0)
6539 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6540 if (FontType
== RASTER_FONTTYPE
)
6541 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6543 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6546 if (!NILP (*(lpef
->pattern
)))
6548 charset
= xlfd_charset_of_font (XSTRING(*(lpef
->pattern
))->data
);
6550 /* Ensure that charset is valid for this font. */
6552 && (x_to_w32_charset (charset
) != lplf
->elfLogFont
.lfCharSet
))
6556 /* TODO: List all relevant charsets if charset not specified. */
6557 if (!w32_to_x_font (&(lplf
->elfLogFont
), buf
, 100, charset
))
6560 if (NILP (*(lpef
->pattern
))
6561 || w32_font_match (buf
, XSTRING (*(lpef
->pattern
))->data
))
6563 *lpef
->tail
= Fcons (Fcons (build_string (buf
), width
), Qnil
);
6564 lpef
->tail
= &(XCDR (*lpef
->tail
));
6573 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6575 NEWTEXTMETRIC
* lptm
;
6579 return EnumFontFamilies (lpef
->hdc
,
6580 lplf
->elfLogFont
.lfFaceName
,
6581 (FONTENUMPROC
) enum_font_cb2
,
6587 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6588 ENUMLOGFONTEX
* lplf
;
6589 NEWTEXTMETRICEX
* lptm
;
6593 /* We are not interested in the extra info we get back from the 'Ex
6594 version - only the fact that we get character set variations
6595 enumerated seperately. */
6596 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6601 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6602 ENUMLOGFONTEX
* lplf
;
6603 NEWTEXTMETRICEX
* lptm
;
6607 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6608 FARPROC enum_font_families_ex
6609 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6610 /* We don't really expect EnumFontFamiliesEx to disappear once we
6611 get here, so don't bother handling it gracefully. */
6612 if (enum_font_families_ex
== NULL
)
6613 error ("gdi32.dll has disappeared!");
6614 return enum_font_families_ex (lpef
->hdc
,
6616 (FONTENUMPROC
) enum_fontex_cb2
,
6620 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6621 and xterm.c in Emacs 20.3) */
6623 Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6625 char *fontname
, *ptnstr
;
6626 Lisp_Object list
, tem
, newlist
= Qnil
;
6629 list
= Vw32_bdf_filename_alist
;
6630 ptnstr
= XSTRING (pattern
)->data
;
6632 for ( ; CONSP (list
); list
= XCDR (list
))
6636 fontname
= XSTRING (XCAR (tem
))->data
;
6637 else if (STRINGP (tem
))
6638 fontname
= XSTRING (tem
)->data
;
6642 if (w32_font_match (fontname
, ptnstr
))
6644 newlist
= Fcons (XCAR (tem
), newlist
);
6646 if (n_fonts
>= max_names
)
6654 Lisp_Object
w32_list_synthesized_fonts (FRAME_PTR f
, Lisp_Object pattern
,
6655 int size
, int max_names
);
6657 /* Return a list of names of available fonts matching PATTERN on frame
6658 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6659 to be listed. Frame F NULL means we have not yet created any
6660 frame, which means we can't get proper size info, as we don't have
6661 a device context to use for GetTextMetrics.
6662 MAXNAMES sets a limit on how many fonts to match. */
6665 w32_list_fonts (FRAME_PTR f
, Lisp_Object pattern
, int size
, int maxnames
)
6667 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6668 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6669 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6672 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6673 if (NILP (patterns
))
6674 patterns
= Fcons (pattern
, Qnil
);
6676 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6681 tpat
= XCAR (patterns
);
6683 if (!STRINGP (tpat
))
6686 /* Avoid expensive EnumFontFamilies functions if we are not
6687 going to be able to output one of these anyway. */
6688 codepage
= w32_codepage_for_font (XSTRING (tpat
)->data
);
6689 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6690 && codepage
!= CP_DEFAULT
&& !IsValidCodePage(codepage
))
6693 /* See if we cached the result for this particular query.
6694 The cache is an alist of the form:
6695 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6697 if (tem
= XCDR (dpyinfo
->name_list_element
),
6698 !NILP (list
= Fassoc (tpat
, tem
)))
6700 list
= Fcdr_safe (list
);
6701 /* We have a cached list. Don't have to get the list again. */
6706 /* At first, put PATTERN in the cache. */
6712 /* Use EnumFontFamiliesEx where it is available, as it knows
6713 about character sets. Fall back to EnumFontFamilies for
6714 older versions of NT that don't support the 'Ex function. */
6715 x_to_w32_font (XSTRING (tpat
)->data
, &ef
.logfont
);
6717 LOGFONT font_match_pattern
;
6718 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6719 FARPROC enum_font_families_ex
6720 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6722 /* We do our own pattern matching so we can handle wildcards. */
6723 font_match_pattern
.lfFaceName
[0] = 0;
6724 font_match_pattern
.lfPitchAndFamily
= 0;
6725 /* We can use the charset, because if it is a wildcard it will
6726 be DEFAULT_CHARSET anyway. */
6727 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6729 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6731 if (enum_font_families_ex
)
6732 enum_font_families_ex (ef
.hdc
,
6733 &font_match_pattern
,
6734 (FONTENUMPROC
) enum_fontex_cb1
,
6737 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6740 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6745 /* Make a list of the fonts we got back.
6746 Store that in the font cache for the display. */
6747 XCDR (dpyinfo
->name_list_element
)
6748 = Fcons (Fcons (tpat
, list
),
6749 XCDR (dpyinfo
->name_list_element
));
6752 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6754 newlist
= second_best
= Qnil
;
6756 /* Make a list of the fonts that have the right width. */
6757 for (; CONSP (list
); list
= XCDR (list
))
6764 if (NILP (XCAR (tem
)))
6768 newlist
= Fcons (XCAR (tem
), newlist
);
6770 if (n_fonts
>= maxnames
)
6775 if (!INTEGERP (XCDR (tem
)))
6777 /* Since we don't yet know the size of the font, we must
6778 load it and try GetTextMetrics. */
6779 W32FontStruct thisinfo
;
6784 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
6788 thisinfo
.bdf
= NULL
;
6789 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6790 if (thisinfo
.hfont
== NULL
)
6793 hdc
= GetDC (dpyinfo
->root_window
);
6794 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6795 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6796 XCDR (tem
) = make_number (FONT_WIDTH (&thisinfo
));
6798 XCDR (tem
) = make_number (0);
6799 SelectObject (hdc
, oldobj
);
6800 ReleaseDC (dpyinfo
->root_window
, hdc
);
6801 DeleteObject(thisinfo
.hfont
);
6804 found_size
= XINT (XCDR (tem
));
6805 if (found_size
== size
)
6807 newlist
= Fcons (XCAR (tem
), newlist
);
6809 if (n_fonts
>= maxnames
)
6812 /* keep track of the closest matching size in case
6813 no exact match is found. */
6814 else if (found_size
> 0)
6816 if (NILP (second_best
))
6819 else if (found_size
< size
)
6821 if (XINT (XCDR (second_best
)) > size
6822 || XINT (XCDR (second_best
)) < found_size
)
6827 if (XINT (XCDR (second_best
)) > size
6828 && XINT (XCDR (second_best
)) >
6835 if (!NILP (newlist
))
6837 else if (!NILP (second_best
))
6839 newlist
= Fcons (XCAR (second_best
), Qnil
);
6844 /* Include any bdf fonts. */
6845 if (n_fonts
< maxnames
)
6847 Lisp_Object combined
[2];
6848 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6849 combined
[1] = newlist
;
6850 newlist
= Fnconc(2, combined
);
6853 /* If we can't find a font that matches, check if Windows would be
6854 able to synthesize it from a different style. */
6855 if (NILP (newlist
) && !NILP (Vw32_enable_synthesized_fonts
))
6856 newlist
= w32_list_synthesized_fonts (f
, pattern
, size
, maxnames
);
6862 w32_list_synthesized_fonts (f
, pattern
, size
, max_names
)
6864 Lisp_Object pattern
;
6869 char *full_pattn
, *new_pattn
, foundary
[50], family
[50], *pattn_part2
;
6870 char style
[20], slant
;
6871 Lisp_Object matches
, match
, tem
, synthed_matches
= Qnil
;
6873 full_pattn
= XSTRING (pattern
)->data
;
6875 pattn_part2
= alloca (XSTRING (pattern
)->size
);
6876 /* Allow some space for wildcard expansion. */
6877 new_pattn
= alloca (XSTRING (pattern
)->size
+ 100);
6879 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%19[^-]-%c-%s",
6880 foundary
, family
, style
, &slant
, pattn_part2
);
6881 if (fields
== EOF
|| fields
< 5)
6884 /* If the style and slant are wildcards already there is no point
6885 checking again (and we don't want to keep recursing). */
6886 if (*style
== '*' && slant
== '*')
6889 sprintf (new_pattn
, "-%s-%s-*-*-%s", foundary
, family
, pattn_part2
);
6891 matches
= w32_list_fonts (f
, build_string (new_pattn
), size
, max_names
);
6893 for ( ; CONSP (matches
); matches
= XCDR (matches
))
6895 tem
= XCAR (matches
);
6899 full_pattn
= XSTRING (tem
)->data
;
6900 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%*[^-]-%*c-%s",
6901 foundary
, family
, pattn_part2
);
6902 if (fields
== EOF
|| fields
< 3)
6905 sprintf (new_pattn
, "-%s-%s-%s-%c-%s", foundary
, family
, style
,
6906 slant
, pattn_part2
);
6908 synthed_matches
= Fcons (build_string (new_pattn
),
6912 return synthed_matches
;
6916 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6918 w32_get_font_info (f
, font_idx
)
6922 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6927 w32_query_font (struct frame
*f
, char *fontname
)
6930 struct font_info
*pfi
;
6932 pfi
= FRAME_W32_FONT_TABLE (f
);
6934 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6936 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
6942 /* Find a CCL program for a font specified by FONTP, and set the member
6943 `encoder' of the structure. */
6946 w32_find_ccl_program (fontp
)
6947 struct font_info
*fontp
;
6949 Lisp_Object list
, elt
;
6951 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6955 && STRINGP (XCAR (elt
))
6956 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6962 struct ccl_program
*ccl
6963 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6965 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6968 fontp
->font_encoder
= ccl
;
6973 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6975 "Return a list of BDF fonts in DIR, suitable for appending to\n\
6976 w32-bdf-filename-alist. Fonts which do not contain an xlfd description\n\
6977 will not be included in the list. DIR may be a list of directories.")
6979 Lisp_Object directory
;
6981 Lisp_Object list
= Qnil
;
6982 struct gcpro gcpro1
, gcpro2
;
6984 if (!CONSP (directory
))
6985 return w32_find_bdf_fonts_in_dir (directory
);
6987 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6989 Lisp_Object pair
[2];
6992 GCPRO2 (directory
, list
);
6993 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6994 list
= Fnconc( 2, pair
);
7000 /* Find BDF files in a specified directory. (use GCPRO when calling,
7001 as this calls lisp to get a directory listing). */
7002 Lisp_Object
w32_find_bdf_fonts_in_dir( Lisp_Object directory
)
7004 Lisp_Object filelist
, list
= Qnil
;
7007 if (!STRINGP(directory
))
7010 filelist
= Fdirectory_files (directory
, Qt
,
7011 build_string (".*\\.[bB][dD][fF]"), Qt
);
7013 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
7015 Lisp_Object filename
= XCAR (filelist
);
7016 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
7017 store_in_alist (&list
, build_string (fontname
), filename
);
7023 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
7024 "Internal function called by `color-defined-p', which see.")
7026 Lisp_Object color
, frame
;
7029 FRAME_PTR f
= check_x_frame (frame
);
7031 CHECK_STRING (color
, 1);
7033 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7039 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
7040 "Internal function called by `color-values', which see.")
7042 Lisp_Object color
, frame
;
7045 FRAME_PTR f
= check_x_frame (frame
);
7047 CHECK_STRING (color
, 1);
7049 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7053 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
7054 | GetRValue (foo
.pixel
));
7055 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
7056 | GetGValue (foo
.pixel
));
7057 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
7058 | GetBValue (foo
.pixel
));
7059 return Flist (3, rgb
);
7065 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
7066 "Internal function called by `display-color-p', which see.")
7068 Lisp_Object display
;
7070 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7072 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
7078 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
7080 "Return t if the X display supports shades of gray.\n\
7081 Note that color displays do support shades of gray.\n\
7082 The optional argument DISPLAY specifies which display to ask about.\n\
7083 DISPLAY should be either a frame or a display name (a string).\n\
7084 If omitted or nil, that stands for the selected frame's display.")
7086 Lisp_Object display
;
7088 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7090 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
7096 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
7098 "Returns the width in pixels of the X display DISPLAY.\n\
7099 The optional argument DISPLAY specifies which display to ask about.\n\
7100 DISPLAY should be either a frame or a display name (a string).\n\
7101 If omitted or nil, that stands for the selected frame's display.")
7103 Lisp_Object display
;
7105 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7107 return make_number (dpyinfo
->width
);
7110 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
7111 Sx_display_pixel_height
, 0, 1, 0,
7112 "Returns the height in pixels of the X display DISPLAY.\n\
7113 The optional argument DISPLAY specifies which display to ask about.\n\
7114 DISPLAY should be either a frame or a display name (a string).\n\
7115 If omitted or nil, that stands for the selected frame's display.")
7117 Lisp_Object display
;
7119 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7121 return make_number (dpyinfo
->height
);
7124 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
7126 "Returns the number of bitplanes of the display DISPLAY.\n\
7127 The optional argument DISPLAY specifies which display to ask about.\n\
7128 DISPLAY should be either a frame or a display name (a string).\n\
7129 If omitted or nil, that stands for the selected frame's display.")
7131 Lisp_Object display
;
7133 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7135 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7138 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
7140 "Returns the number of color cells of the display DISPLAY.\n\
7141 The optional argument DISPLAY specifies which display to ask about.\n\
7142 DISPLAY should be either a frame or a display name (a string).\n\
7143 If omitted or nil, that stands for the selected frame's display.")
7145 Lisp_Object display
;
7147 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7151 hdc
= GetDC (dpyinfo
->root_window
);
7152 if (dpyinfo
->has_palette
)
7153 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
7155 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
7157 ReleaseDC (dpyinfo
->root_window
, hdc
);
7159 return make_number (cap
);
7162 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
7163 Sx_server_max_request_size
,
7165 "Returns the maximum request size of the server of display DISPLAY.\n\
7166 The optional argument DISPLAY specifies which display to ask about.\n\
7167 DISPLAY should be either a frame or a display name (a string).\n\
7168 If omitted or nil, that stands for the selected frame's display.")
7170 Lisp_Object display
;
7172 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7174 return make_number (1);
7177 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
7178 "Returns the vendor ID string of the W32 system (Microsoft).\n\
7179 The optional argument DISPLAY specifies which display to ask about.\n\
7180 DISPLAY should be either a frame or a display name (a string).\n\
7181 If omitted or nil, that stands for the selected frame's display.")
7183 Lisp_Object display
;
7185 return build_string ("Microsoft Corp.");
7188 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
7189 "Returns the version numbers of the server of display DISPLAY.\n\
7190 The value is a list of three integers: the major and minor\n\
7191 version numbers, and the vendor-specific release\n\
7192 number. See also the function `x-server-vendor'.\n\n\
7193 The optional argument DISPLAY specifies which display to ask about.\n\
7194 DISPLAY should be either a frame or a display name (a string).\n\
7195 If omitted or nil, that stands for the selected frame's display.")
7197 Lisp_Object display
;
7199 return Fcons (make_number (w32_major_version
),
7200 Fcons (make_number (w32_minor_version
),
7201 Fcons (make_number (w32_build_number
), Qnil
)));
7204 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
7205 "Returns the number of screens on the server of display DISPLAY.\n\
7206 The optional argument DISPLAY specifies which display to ask about.\n\
7207 DISPLAY should be either a frame or a display name (a string).\n\
7208 If omitted or nil, that stands for the selected frame's display.")
7210 Lisp_Object display
;
7212 return make_number (1);
7215 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
7216 "Returns the height in millimeters of the X display DISPLAY.\n\
7217 The optional argument DISPLAY specifies which display to ask about.\n\
7218 DISPLAY should be either a frame or a display name (a string).\n\
7219 If omitted or nil, that stands for the selected frame's display.")
7221 Lisp_Object display
;
7223 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7227 hdc
= GetDC (dpyinfo
->root_window
);
7229 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
7231 ReleaseDC (dpyinfo
->root_window
, hdc
);
7233 return make_number (cap
);
7236 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
7237 "Returns the width in millimeters of the X display DISPLAY.\n\
7238 The optional argument DISPLAY specifies which display to ask about.\n\
7239 DISPLAY should be either a frame or a display name (a string).\n\
7240 If omitted or nil, that stands for the selected frame's display.")
7242 Lisp_Object display
;
7244 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7249 hdc
= GetDC (dpyinfo
->root_window
);
7251 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
7253 ReleaseDC (dpyinfo
->root_window
, hdc
);
7255 return make_number (cap
);
7258 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
7259 Sx_display_backing_store
, 0, 1, 0,
7260 "Returns an indication of whether display DISPLAY does backing store.\n\
7261 The value may be `always', `when-mapped', or `not-useful'.\n\
7262 The optional argument DISPLAY specifies which display to ask about.\n\
7263 DISPLAY should be either a frame or a display name (a string).\n\
7264 If omitted or nil, that stands for the selected frame's display.")
7266 Lisp_Object display
;
7268 return intern ("not-useful");
7271 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
7272 Sx_display_visual_class
, 0, 1, 0,
7273 "Returns the visual class of the display DISPLAY.\n\
7274 The value is one of the symbols `static-gray', `gray-scale',\n\
7275 `static-color', `pseudo-color', `true-color', or `direct-color'.\n\n\
7276 The optional argument DISPLAY specifies which display to ask about.\n\
7277 DISPLAY should be either a frame or a display name (a string).\n\
7278 If omitted or nil, that stands for the selected frame's display.")
7280 Lisp_Object display
;
7282 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7285 switch (dpyinfo
->visual
->class)
7287 case StaticGray
: return (intern ("static-gray"));
7288 case GrayScale
: return (intern ("gray-scale"));
7289 case StaticColor
: return (intern ("static-color"));
7290 case PseudoColor
: return (intern ("pseudo-color"));
7291 case TrueColor
: return (intern ("true-color"));
7292 case DirectColor
: return (intern ("direct-color"));
7294 error ("Display has an unknown visual class");
7298 error ("Display has an unknown visual class");
7301 DEFUN ("x-display-save-under", Fx_display_save_under
,
7302 Sx_display_save_under
, 0, 1, 0,
7303 "Returns t if the display DISPLAY supports the save-under feature.\n\
7304 The optional argument DISPLAY specifies which display to ask about.\n\
7305 DISPLAY should be either a frame or a display name (a string).\n\
7306 If omitted or nil, that stands for the selected frame's display.")
7308 Lisp_Object display
;
7315 register struct frame
*f
;
7317 return PIXEL_WIDTH (f
);
7322 register struct frame
*f
;
7324 return PIXEL_HEIGHT (f
);
7329 register struct frame
*f
;
7331 return FONT_WIDTH (f
->output_data
.w32
->font
);
7336 register struct frame
*f
;
7338 return f
->output_data
.w32
->line_height
;
7343 register struct frame
*f
;
7345 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
7348 /* Return the display structure for the display named NAME.
7349 Open a new connection if necessary. */
7351 struct w32_display_info
*
7352 x_display_info_for_name (name
)
7356 struct w32_display_info
*dpyinfo
;
7358 CHECK_STRING (name
, 0);
7360 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
7362 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
7365 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
7370 /* Use this general default value to start with. */
7371 Vx_resource_name
= Vinvocation_name
;
7373 validate_x_resource_name ();
7375 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
7376 (char *) XSTRING (Vx_resource_name
)->data
);
7379 error ("Cannot connect to server %s", XSTRING (name
)->data
);
7382 XSETFASTINT (Vwindow_system_version
, 3);
7387 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
7388 1, 3, 0, "Open a connection to a server.\n\
7389 DISPLAY is the name of the display to connect to.\n\
7390 Optional second arg XRM-STRING is a string of resources in xrdb format.\n\
7391 If the optional third arg MUST-SUCCEED is non-nil,\n\
7392 terminate Emacs if we can't open the connection.")
7393 (display
, xrm_string
, must_succeed
)
7394 Lisp_Object display
, xrm_string
, must_succeed
;
7396 unsigned char *xrm_option
;
7397 struct w32_display_info
*dpyinfo
;
7399 CHECK_STRING (display
, 0);
7400 if (! NILP (xrm_string
))
7401 CHECK_STRING (xrm_string
, 1);
7403 if (! EQ (Vwindow_system
, intern ("w32")))
7404 error ("Not using Microsoft Windows");
7406 /* Allow color mapping to be defined externally; first look in user's
7407 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
7409 Lisp_Object color_file
;
7410 struct gcpro gcpro1
;
7412 color_file
= build_string("~/rgb.txt");
7414 GCPRO1 (color_file
);
7416 if (NILP (Ffile_readable_p (color_file
)))
7418 Fexpand_file_name (build_string ("rgb.txt"),
7419 Fsymbol_value (intern ("data-directory")));
7421 Vw32_color_map
= Fw32_load_color_file (color_file
);
7425 if (NILP (Vw32_color_map
))
7426 Vw32_color_map
= Fw32_default_color_map ();
7428 if (! NILP (xrm_string
))
7429 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
7431 xrm_option
= (unsigned char *) 0;
7433 /* Use this general default value to start with. */
7434 /* First remove .exe suffix from invocation-name - it looks ugly. */
7436 char basename
[ MAX_PATH
], *str
;
7438 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
7439 str
= strrchr (basename
, '.');
7441 Vinvocation_name
= build_string (basename
);
7443 Vx_resource_name
= Vinvocation_name
;
7445 validate_x_resource_name ();
7447 /* This is what opens the connection and sets x_current_display.
7448 This also initializes many symbols, such as those used for input. */
7449 dpyinfo
= w32_term_init (display
, xrm_option
,
7450 (char *) XSTRING (Vx_resource_name
)->data
);
7454 if (!NILP (must_succeed
))
7455 fatal ("Cannot connect to server %s.\n",
7456 XSTRING (display
)->data
);
7458 error ("Cannot connect to server %s", XSTRING (display
)->data
);
7463 XSETFASTINT (Vwindow_system_version
, 3);
7467 DEFUN ("x-close-connection", Fx_close_connection
,
7468 Sx_close_connection
, 1, 1, 0,
7469 "Close the connection to DISPLAY's server.\n\
7470 For DISPLAY, specify either a frame or a display name (a string).\n\
7471 If DISPLAY is nil, that stands for the selected frame's display.")
7473 Lisp_Object display
;
7475 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7478 if (dpyinfo
->reference_count
> 0)
7479 error ("Display still has frames on it");
7482 /* Free the fonts in the font table. */
7483 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7484 if (dpyinfo
->font_table
[i
].name
)
7486 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7487 xfree (dpyinfo
->font_table
[i
].full_name
);
7488 xfree (dpyinfo
->font_table
[i
].name
);
7489 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7491 x_destroy_all_bitmaps (dpyinfo
);
7493 x_delete_display (dpyinfo
);
7499 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7500 "Return the list of display names that Emacs has connections to.")
7503 Lisp_Object tail
, result
;
7506 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
7507 result
= Fcons (XCAR (XCAR (tail
)), result
);
7512 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7513 "If ON is non-nil, report errors as soon as the erring request is made.\n\
7514 If ON is nil, allow buffering of requests.\n\
7515 This is a noop on W32 systems.\n\
7516 The optional second argument DISPLAY specifies which display to act on.\n\
7517 DISPLAY should be either a frame or a display name (a string).\n\
7518 If DISPLAY is omitted or nil, that stands for the selected frame's display.")
7520 Lisp_Object display
, on
;
7527 /***********************************************************************
7529 ***********************************************************************/
7531 /* Value is the number of elements of vector VECTOR. */
7533 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
7535 /* List of supported image types. Use define_image_type to add new
7536 types. Use lookup_image_type to find a type for a given symbol. */
7538 static struct image_type
*image_types
;
7540 /* The symbol `image' which is the car of the lists used to represent
7543 extern Lisp_Object Qimage
;
7545 /* The symbol `xbm' which is used as the type symbol for XBM images. */
7551 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
7552 extern Lisp_Object QCdata
;
7553 Lisp_Object QCtype
, QCascent
, QCmargin
, QCrelief
;
7554 Lisp_Object QCalgorithm
, QCcolor_symbols
, QCheuristic_mask
;
7555 Lisp_Object QCindex
;
7557 /* Other symbols. */
7559 Lisp_Object Qlaplace
;
7561 /* Time in seconds after which images should be removed from the cache
7562 if not displayed. */
7564 Lisp_Object Vimage_cache_eviction_delay
;
7566 /* Function prototypes. */
7568 static void define_image_type
P_ ((struct image_type
*type
));
7569 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
7570 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
7571 static void x_laplace
P_ ((struct frame
*, struct image
*));
7572 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
7576 /* Define a new image type from TYPE. This adds a copy of TYPE to
7577 image_types and adds the symbol *TYPE->type to Vimage_types. */
7580 define_image_type (type
)
7581 struct image_type
*type
;
7583 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
7584 The initialized data segment is read-only. */
7585 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
7586 bcopy (type
, p
, sizeof *p
);
7587 p
->next
= image_types
;
7589 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
7593 /* Look up image type SYMBOL, and return a pointer to its image_type
7594 structure. Value is null if SYMBOL is not a known image type. */
7596 static INLINE
struct image_type
*
7597 lookup_image_type (symbol
)
7600 struct image_type
*type
;
7602 for (type
= image_types
; type
; type
= type
->next
)
7603 if (EQ (symbol
, *type
->type
))
7610 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
7611 valid image specification is a list whose car is the symbol
7612 `image', and whose rest is a property list. The property list must
7613 contain a value for key `:type'. That value must be the name of a
7614 supported image type. The rest of the property list depends on the
7618 valid_image_p (object
)
7623 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
7625 Lisp_Object symbol
= Fplist_get (XCDR (object
), QCtype
);
7626 struct image_type
*type
= lookup_image_type (symbol
);
7629 valid_p
= type
->valid_p (object
);
7636 /* Log error message with format string FORMAT and argument ARG.
7637 Signaling an error, e.g. when an image cannot be loaded, is not a
7638 good idea because this would interrupt redisplay, and the error
7639 message display would lead to another redisplay. This function
7640 therefore simply displays a message. */
7643 image_error (format
, arg1
, arg2
)
7645 Lisp_Object arg1
, arg2
;
7647 add_to_log (format
, arg1
, arg2
);
7652 /***********************************************************************
7653 Image specifications
7654 ***********************************************************************/
7656 enum image_value_type
7658 IMAGE_DONT_CHECK_VALUE_TYPE
,
7661 IMAGE_POSITIVE_INTEGER_VALUE
,
7662 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
7664 IMAGE_INTEGER_VALUE
,
7665 IMAGE_FUNCTION_VALUE
,
7670 /* Structure used when parsing image specifications. */
7672 struct image_keyword
7674 /* Name of keyword. */
7677 /* The type of value allowed. */
7678 enum image_value_type type
;
7680 /* Non-zero means key must be present. */
7683 /* Used to recognize duplicate keywords in a property list. */
7686 /* The value that was found. */
7691 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
7693 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
7696 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
7697 has the format (image KEYWORD VALUE ...). One of the keyword/
7698 value pairs must be `:type TYPE'. KEYWORDS is a vector of
7699 image_keywords structures of size NKEYWORDS describing other
7700 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
7703 parse_image_spec (spec
, keywords
, nkeywords
, type
)
7705 struct image_keyword
*keywords
;
7712 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
7715 plist
= XCDR (spec
);
7716 while (CONSP (plist
))
7718 Lisp_Object key
, value
;
7720 /* First element of a pair must be a symbol. */
7722 plist
= XCDR (plist
);
7726 /* There must follow a value. */
7729 value
= XCAR (plist
);
7730 plist
= XCDR (plist
);
7732 /* Find key in KEYWORDS. Error if not found. */
7733 for (i
= 0; i
< nkeywords
; ++i
)
7734 if (strcmp (keywords
[i
].name
, XSYMBOL (key
)->name
->data
) == 0)
7740 /* Record that we recognized the keyword. If a keywords
7741 was found more than once, it's an error. */
7742 keywords
[i
].value
= value
;
7743 ++keywords
[i
].count
;
7745 if (keywords
[i
].count
> 1)
7748 /* Check type of value against allowed type. */
7749 switch (keywords
[i
].type
)
7751 case IMAGE_STRING_VALUE
:
7752 if (!STRINGP (value
))
7756 case IMAGE_SYMBOL_VALUE
:
7757 if (!SYMBOLP (value
))
7761 case IMAGE_POSITIVE_INTEGER_VALUE
:
7762 if (!INTEGERP (value
) || XINT (value
) <= 0)
7766 case IMAGE_ASCENT_VALUE
:
7767 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
7769 else if (INTEGERP (value
)
7770 && XINT (value
) >= 0
7771 && XINT (value
) <= 100)
7775 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
7776 if (!INTEGERP (value
) || XINT (value
) < 0)
7780 case IMAGE_DONT_CHECK_VALUE_TYPE
:
7783 case IMAGE_FUNCTION_VALUE
:
7784 value
= indirect_function (value
);
7786 || COMPILEDP (value
)
7787 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
7791 case IMAGE_NUMBER_VALUE
:
7792 if (!INTEGERP (value
) && !FLOATP (value
))
7796 case IMAGE_INTEGER_VALUE
:
7797 if (!INTEGERP (value
))
7801 case IMAGE_BOOL_VALUE
:
7802 if (!NILP (value
) && !EQ (value
, Qt
))
7811 if (EQ (key
, QCtype
) && !EQ (type
, value
))
7815 /* Check that all mandatory fields are present. */
7816 for (i
= 0; i
< nkeywords
; ++i
)
7817 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
7820 return NILP (plist
);
7824 /* Return the value of KEY in image specification SPEC. Value is nil
7825 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
7826 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
7829 image_spec_value (spec
, key
, found
)
7830 Lisp_Object spec
, key
;
7835 xassert (valid_image_p (spec
));
7837 for (tail
= XCDR (spec
);
7838 CONSP (tail
) && CONSP (XCDR (tail
));
7839 tail
= XCDR (XCDR (tail
)))
7841 if (EQ (XCAR (tail
), key
))
7845 return XCAR (XCDR (tail
));
7857 /***********************************************************************
7858 Image type independent image structures
7859 ***********************************************************************/
7861 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
7862 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
7865 /* Allocate and return a new image structure for image specification
7866 SPEC. SPEC has a hash value of HASH. */
7868 static struct image
*
7869 make_image (spec
, hash
)
7873 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
7875 xassert (valid_image_p (spec
));
7876 bzero (img
, sizeof *img
);
7877 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
7878 xassert (img
->type
!= NULL
);
7880 img
->data
.lisp_val
= Qnil
;
7881 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
7887 /* Free image IMG which was used on frame F, including its resources. */
7896 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7898 /* Remove IMG from the hash table of its cache. */
7900 img
->prev
->next
= img
->next
;
7902 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
7905 img
->next
->prev
= img
->prev
;
7907 c
->images
[img
->id
] = NULL
;
7909 /* Free resources, then free IMG. */
7910 img
->type
->free (f
, img
);
7916 /* Prepare image IMG for display on frame F. Must be called before
7917 drawing an image. */
7920 prepare_image_for_display (f
, img
)
7926 /* We're about to display IMG, so set its timestamp to `now'. */
7928 img
->timestamp
= EMACS_SECS (t
);
7930 /* If IMG doesn't have a pixmap yet, load it now, using the image
7931 type dependent loader function. */
7932 if (img
->pixmap
== 0 && !img
->load_failed_p
)
7933 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
7937 /* Value is the number of pixels for the ascent of image IMG when
7938 drawn in face FACE. */
7941 image_ascent (img
, face
)
7945 int height
= img
->height
+ img
->margin
;
7948 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
7951 ascent
= height
/ 2 - (FONT_DESCENT(face
->font
)
7952 - FONT_BASE(face
->font
)) / 2;
7954 ascent
= height
/ 2;
7957 ascent
= height
* img
->ascent
/ 100.0;
7964 /***********************************************************************
7965 Helper functions for X image types
7966 ***********************************************************************/
7968 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
7969 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
7971 Lisp_Object color_name
,
7972 unsigned long dflt
));
7974 /* Free X resources of image IMG which is used on frame F. */
7977 x_clear_image (f
, img
)
7981 #if 0 /* TODO: W32 image support */
7986 XFreePixmap (NULL
, img
->pixmap
);
7993 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
7995 /* If display has an immutable color map, freeing colors is not
7996 necessary and some servers don't allow it. So don't do it. */
7997 if (class != StaticColor
7998 && class != StaticGray
7999 && class != TrueColor
)
8003 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
8004 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
8009 xfree (img
->colors
);
8017 /* Allocate color COLOR_NAME for image IMG on frame F. If color
8018 cannot be allocated, use DFLT. Add a newly allocated color to
8019 IMG->colors, so that it can be freed again. Value is the pixel
8022 static unsigned long
8023 x_alloc_image_color (f
, img
, color_name
, dflt
)
8026 Lisp_Object color_name
;
8029 #if 0 /* TODO: allocing colors. */
8031 unsigned long result
;
8033 xassert (STRINGP (color_name
));
8035 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
8037 /* This isn't called frequently so we get away with simply
8038 reallocating the color vector to the needed size, here. */
8041 (unsigned long *) xrealloc (img
->colors
,
8042 img
->ncolors
* sizeof *img
->colors
);
8043 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
8044 result
= color
.pixel
;
8055 /***********************************************************************
8057 ***********************************************************************/
8059 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
8062 /* Return a new, initialized image cache that is allocated from the
8063 heap. Call free_image_cache to free an image cache. */
8065 struct image_cache
*
8068 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
8071 bzero (c
, sizeof *c
);
8073 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
8074 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
8075 c
->buckets
= (struct image
**) xmalloc (size
);
8076 bzero (c
->buckets
, size
);
8081 /* Free image cache of frame F. Be aware that X frames share images
8085 free_image_cache (f
)
8088 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8093 /* Cache should not be referenced by any frame when freed. */
8094 xassert (c
->refcount
== 0);
8096 for (i
= 0; i
< c
->used
; ++i
)
8097 free_image (f
, c
->images
[i
]);
8101 FRAME_X_IMAGE_CACHE (f
) = NULL
;
8106 /* Clear image cache of frame F. FORCE_P non-zero means free all
8107 images. FORCE_P zero means clear only images that haven't been
8108 displayed for some time. Should be called from time to time to
8109 reduce the number of loaded images. If image-eviction-seconds is
8110 non-nil, this frees images in the cache which weren't displayed for
8111 at least that many seconds. */
8114 clear_image_cache (f
, force_p
)
8118 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8120 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
8124 int i
, any_freed_p
= 0;
8127 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
8129 for (i
= 0; i
< c
->used
; ++i
)
8131 struct image
*img
= c
->images
[i
];
8134 || (img
->timestamp
> old
)))
8136 free_image (f
, img
);
8141 /* We may be clearing the image cache because, for example,
8142 Emacs was iconified for a longer period of time. In that
8143 case, current matrices may still contain references to
8144 images freed above. So, clear these matrices. */
8147 clear_current_matrices (f
);
8148 ++windows_or_buffers_changed
;
8154 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
8156 "Clear the image cache of FRAME.\n\
8157 FRAME nil or omitted means use the selected frame.\n\
8158 FRAME t means clear the image caches of all frames.")
8166 FOR_EACH_FRAME (tail
, frame
)
8167 if (FRAME_W32_P (XFRAME (frame
)))
8168 clear_image_cache (XFRAME (frame
), 1);
8171 clear_image_cache (check_x_frame (frame
), 1);
8177 /* Return the id of image with Lisp specification SPEC on frame F.
8178 SPEC must be a valid Lisp image specification (see valid_image_p). */
8181 lookup_image (f
, spec
)
8185 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8189 struct gcpro gcpro1
;
8192 /* F must be a window-system frame, and SPEC must be a valid image
8194 xassert (FRAME_WINDOW_P (f
));
8195 xassert (valid_image_p (spec
));
8199 /* Look up SPEC in the hash table of the image cache. */
8200 hash
= sxhash (spec
, 0);
8201 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8203 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
8204 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
8207 /* If not found, create a new image and cache it. */
8210 img
= make_image (spec
, hash
);
8211 cache_image (f
, img
);
8212 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8213 xassert (!interrupt_input_blocked
);
8215 /* If we can't load the image, and we don't have a width and
8216 height, use some arbitrary width and height so that we can
8217 draw a rectangle for it. */
8218 if (img
->load_failed_p
)
8222 value
= image_spec_value (spec
, QCwidth
, NULL
);
8223 img
->width
= (INTEGERP (value
)
8224 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
8225 value
= image_spec_value (spec
, QCheight
, NULL
);
8226 img
->height
= (INTEGERP (value
)
8227 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
8231 /* Handle image type independent image attributes
8232 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF'. */
8233 Lisp_Object ascent
, margin
, relief
, algorithm
, heuristic_mask
;
8236 ascent
= image_spec_value (spec
, QCascent
, NULL
);
8237 if (INTEGERP (ascent
))
8238 img
->ascent
= XFASTINT (ascent
);
8239 else if (EQ (ascent
, Qcenter
))
8240 img
->ascent
= CENTERED_IMAGE_ASCENT
;
8242 margin
= image_spec_value (spec
, QCmargin
, NULL
);
8243 if (INTEGERP (margin
) && XINT (margin
) >= 0)
8244 img
->margin
= XFASTINT (margin
);
8246 relief
= image_spec_value (spec
, QCrelief
, NULL
);
8247 if (INTEGERP (relief
))
8249 img
->relief
= XINT (relief
);
8250 img
->margin
+= abs (img
->relief
);
8253 /* Should we apply a Laplace edge-detection algorithm? */
8254 algorithm
= image_spec_value (spec
, QCalgorithm
, NULL
);
8255 if (img
->pixmap
&& EQ (algorithm
, Qlaplace
))
8258 /* Should we built a mask heuristically? */
8259 heuristic_mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
8260 if (img
->pixmap
&& !img
->mask
&& !NILP (heuristic_mask
))
8261 x_build_heuristic_mask (f
, img
, heuristic_mask
);
8265 /* We're using IMG, so set its timestamp to `now'. */
8266 EMACS_GET_TIME (now
);
8267 img
->timestamp
= EMACS_SECS (now
);
8271 /* Value is the image id. */
8276 /* Cache image IMG in the image cache of frame F. */
8279 cache_image (f
, img
)
8283 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8286 /* Find a free slot in c->images. */
8287 for (i
= 0; i
< c
->used
; ++i
)
8288 if (c
->images
[i
] == NULL
)
8291 /* If no free slot found, maybe enlarge c->images. */
8292 if (i
== c
->used
&& c
->used
== c
->size
)
8295 c
->images
= (struct image
**) xrealloc (c
->images
,
8296 c
->size
* sizeof *c
->images
);
8299 /* Add IMG to c->images, and assign IMG an id. */
8305 /* Add IMG to the cache's hash table. */
8306 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8307 img
->next
= c
->buckets
[i
];
8309 img
->next
->prev
= img
;
8311 c
->buckets
[i
] = img
;
8315 /* Call FN on every image in the image cache of frame F. Used to mark
8316 Lisp Objects in the image cache. */
8319 forall_images_in_image_cache (f
, fn
)
8321 void (*fn
) P_ ((struct image
*img
));
8323 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
8325 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8329 for (i
= 0; i
< c
->used
; ++i
)
8338 /***********************************************************************
8340 ***********************************************************************/
8342 #if 0 /* TODO: W32 specific image code. */
8344 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
8345 XImage
**, Pixmap
*));
8346 static void x_destroy_x_image
P_ ((XImage
*));
8347 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
8350 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
8351 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
8352 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
8353 via xmalloc. Print error messages via image_error if an error
8354 occurs. Value is non-zero if successful. */
8357 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
8359 int width
, height
, depth
;
8363 #if 0 /* TODO: Image support for W32 */
8364 Display
*display
= FRAME_W32_DISPLAY (f
);
8365 Screen
*screen
= FRAME_X_SCREEN (f
);
8366 Window window
= FRAME_W32_WINDOW (f
);
8368 xassert (interrupt_input_blocked
);
8371 depth
= DefaultDepthOfScreen (screen
);
8372 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
8373 depth
, ZPixmap
, 0, NULL
, width
, height
,
8374 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
8377 image_error ("Unable to allocate X image", Qnil
, Qnil
);
8381 /* Allocate image raster. */
8382 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
8384 /* Allocate a pixmap of the same size. */
8385 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
8388 x_destroy_x_image (*ximg
);
8390 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
8398 /* Destroy XImage XIMG. Free XIMG->data. */
8401 x_destroy_x_image (ximg
)
8404 xassert (interrupt_input_blocked
);
8409 XDestroyImage (ximg
);
8414 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
8415 are width and height of both the image and pixmap. */
8418 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
8425 xassert (interrupt_input_blocked
);
8426 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
8427 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
8434 /***********************************************************************
8436 ***********************************************************************/
8438 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
8440 /* Find image file FILE. Look in data-directory, then
8441 x-bitmap-file-path. Value is the full name of the file found, or
8442 nil if not found. */
8445 x_find_image_file (file
)
8448 Lisp_Object file_found
, search_path
;
8449 struct gcpro gcpro1
, gcpro2
;
8453 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
8454 GCPRO2 (file_found
, search_path
);
8456 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
8457 fd
= openp (search_path
, file
, "", &file_found
, 0);
8470 /***********************************************************************
8472 ***********************************************************************/
8474 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
8475 static int xbm_load_image_from_file
P_ ((struct frame
*f
, struct image
*img
,
8477 static int xbm_image_p
P_ ((Lisp_Object object
));
8478 static int xbm_read_bitmap_file_data
P_ ((char *, int *, int *,
8482 /* Indices of image specification fields in xbm_format, below. */
8484 enum xbm_keyword_index
8501 /* Vector of image_keyword structures describing the format
8502 of valid XBM image specifications. */
8504 static struct image_keyword xbm_format
[XBM_LAST
] =
8506 {":type", IMAGE_SYMBOL_VALUE
, 1},
8507 {":file", IMAGE_STRING_VALUE
, 0},
8508 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8509 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8510 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8511 {":foreground", IMAGE_STRING_VALUE
, 0},
8512 {":background", IMAGE_STRING_VALUE
, 0},
8513 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
8514 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8515 {":relief", IMAGE_INTEGER_VALUE
, 0},
8516 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8517 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
8520 /* Structure describing the image type XBM. */
8522 static struct image_type xbm_type
=
8531 /* Tokens returned from xbm_scan. */
8540 /* Return non-zero if OBJECT is a valid XBM-type image specification.
8541 A valid specification is a list starting with the symbol `image'
8542 The rest of the list is a property list which must contain an
8545 If the specification specifies a file to load, it must contain
8546 an entry `:file FILENAME' where FILENAME is a string.
8548 If the specification is for a bitmap loaded from memory it must
8549 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
8550 WIDTH and HEIGHT are integers > 0. DATA may be:
8552 1. a string large enough to hold the bitmap data, i.e. it must
8553 have a size >= (WIDTH + 7) / 8 * HEIGHT
8555 2. a bool-vector of size >= WIDTH * HEIGHT
8557 3. a vector of strings or bool-vectors, one for each line of the
8560 Both the file and data forms may contain the additional entries
8561 `:background COLOR' and `:foreground COLOR'. If not present,
8562 foreground and background of the frame on which the image is
8563 displayed, is used. */
8566 xbm_image_p (object
)
8569 struct image_keyword kw
[XBM_LAST
];
8571 bcopy (xbm_format
, kw
, sizeof kw
);
8572 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
8575 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
8577 if (kw
[XBM_FILE
].count
)
8579 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
8587 /* Entries for `:width', `:height' and `:data' must be present. */
8588 if (!kw
[XBM_WIDTH
].count
8589 || !kw
[XBM_HEIGHT
].count
8590 || !kw
[XBM_DATA
].count
)
8593 data
= kw
[XBM_DATA
].value
;
8594 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
8595 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
8597 /* Check type of data, and width and height against contents of
8603 /* Number of elements of the vector must be >= height. */
8604 if (XVECTOR (data
)->size
< height
)
8607 /* Each string or bool-vector in data must be large enough
8608 for one line of the image. */
8609 for (i
= 0; i
< height
; ++i
)
8611 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
8615 if (XSTRING (elt
)->size
8616 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
8619 else if (BOOL_VECTOR_P (elt
))
8621 if (XBOOL_VECTOR (elt
)->size
< width
)
8628 else if (STRINGP (data
))
8630 if (XSTRING (data
)->size
8631 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
8634 else if (BOOL_VECTOR_P (data
))
8636 if (XBOOL_VECTOR (data
)->size
< width
* height
)
8643 /* Baseline must be a value between 0 and 100 (a percentage). */
8644 if (kw
[XBM_ASCENT
].count
8645 && XFASTINT (kw
[XBM_ASCENT
].value
) > 100)
8652 /* Scan a bitmap file. FP is the stream to read from. Value is
8653 either an enumerator from enum xbm_token, or a character for a
8654 single-character token, or 0 at end of file. If scanning an
8655 identifier, store the lexeme of the identifier in SVAL. If
8656 scanning a number, store its value in *IVAL. */
8659 xbm_scan (fp
, sval
, ival
)
8666 /* Skip white space. */
8667 while ((c
= fgetc (fp
)) != EOF
&& isspace (c
))
8672 else if (isdigit (c
))
8674 int value
= 0, digit
;
8679 if (c
== 'x' || c
== 'X')
8681 while ((c
= fgetc (fp
)) != EOF
)
8685 else if (c
>= 'a' && c
<= 'f')
8686 digit
= c
- 'a' + 10;
8687 else if (c
>= 'A' && c
<= 'F')
8688 digit
= c
- 'A' + 10;
8691 value
= 16 * value
+ digit
;
8694 else if (isdigit (c
))
8697 while ((c
= fgetc (fp
)) != EOF
8699 value
= 8 * value
+ c
- '0';
8705 while ((c
= fgetc (fp
)) != EOF
8707 value
= 10 * value
+ c
- '0';
8715 else if (isalpha (c
) || c
== '_')
8718 while ((c
= fgetc (fp
)) != EOF
8719 && (isalnum (c
) || c
== '_'))
8731 /* Replacement for XReadBitmapFileData which isn't available under old
8732 X versions. FILE is the name of the bitmap file to read. Set
8733 *WIDTH and *HEIGHT to the width and height of the image. Return in
8734 *DATA the bitmap data allocated with xmalloc. Value is non-zero if
8738 xbm_read_bitmap_file_data (file
, width
, height
, data
)
8740 int *width
, *height
;
8741 unsigned char **data
;
8744 char buffer
[BUFSIZ
];
8747 int bytes_per_line
, i
, nbytes
;
8753 LA1 = xbm_scan (fp, buffer, &value)
8755 #define expect(TOKEN) \
8756 if (LA1 != (TOKEN)) \
8761 #define expect_ident(IDENT) \
8762 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
8767 fp
= fopen (file
, "r");
8771 *width
= *height
= -1;
8773 LA1
= xbm_scan (fp
, buffer
, &value
);
8775 /* Parse defines for width, height and hot-spots. */
8779 expect_ident ("define");
8780 expect (XBM_TK_IDENT
);
8782 if (LA1
== XBM_TK_NUMBER
);
8784 char *p
= strrchr (buffer
, '_');
8785 p
= p
? p
+ 1 : buffer
;
8786 if (strcmp (p
, "width") == 0)
8788 else if (strcmp (p
, "height") == 0)
8791 expect (XBM_TK_NUMBER
);
8794 if (*width
< 0 || *height
< 0)
8797 /* Parse bits. Must start with `static'. */
8798 expect_ident ("static");
8799 if (LA1
== XBM_TK_IDENT
)
8801 if (strcmp (buffer
, "unsigned") == 0)
8804 expect_ident ("char");
8806 else if (strcmp (buffer
, "short") == 0)
8810 if (*width
% 16 && *width
% 16 < 9)
8813 else if (strcmp (buffer
, "char") == 0)
8821 expect (XBM_TK_IDENT
);
8827 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
8828 nbytes
= bytes_per_line
* *height
;
8829 p
= *data
= (char *) xmalloc (nbytes
);
8834 for (i
= 0; i
< nbytes
; i
+= 2)
8837 expect (XBM_TK_NUMBER
);
8840 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
8843 if (LA1
== ',' || LA1
== '}')
8851 for (i
= 0; i
< nbytes
; ++i
)
8854 expect (XBM_TK_NUMBER
);
8858 if (LA1
== ',' || LA1
== '}')
8884 /* Load XBM image IMG which will be displayed on frame F from file
8885 SPECIFIED_FILE. Value is non-zero if successful. */
8888 xbm_load_image_from_file (f
, img
, specified_file
)
8891 Lisp_Object specified_file
;
8894 unsigned char *data
;
8897 struct gcpro gcpro1
;
8899 xassert (STRINGP (specified_file
));
8903 file
= x_find_image_file (specified_file
);
8904 if (!STRINGP (file
))
8906 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8911 rc
= xbm_read_bitmap_file_data (XSTRING (file
)->data
, &img
->width
,
8912 &img
->height
, &data
);
8915 int depth
= one_w32_display_info
.n_cbits
;
8916 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
8917 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
8920 xassert (img
->width
> 0 && img
->height
> 0);
8922 /* Get foreground and background colors, maybe allocate colors. */
8923 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
8925 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
8927 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
8929 background
= x_alloc_image_color (f
, img
, value
, background
);
8931 #if 0 /* TODO : Port image display to W32 */
8934 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
8935 FRAME_W32_WINDOW (f
),
8937 img
->width
, img
->height
,
8938 foreground
, background
,
8942 if (img
->pixmap
== 0)
8944 x_clear_image (f
, img
);
8945 image_error ("Unable to create X pixmap for `%s'", file
, Qnil
);
8954 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
8961 /* Fill image IMG which is used on frame F with pixmap data. Value is
8962 non-zero if successful. */
8970 Lisp_Object file_name
;
8972 xassert (xbm_image_p (img
->spec
));
8974 /* If IMG->spec specifies a file name, create a non-file spec from it. */
8975 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
8976 if (STRINGP (file_name
))
8977 success_p
= xbm_load_image_from_file (f
, img
, file_name
);
8980 struct image_keyword fmt
[XBM_LAST
];
8983 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
8984 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
8988 /* Parse the list specification. */
8989 bcopy (xbm_format
, fmt
, sizeof fmt
);
8990 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
8993 /* Get specified width, and height. */
8994 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
8995 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
8996 xassert (img
->width
> 0 && img
->height
> 0);
9000 if (fmt
[XBM_ASCENT
].count
)
9001 img
->ascent
= XFASTINT (fmt
[XBM_ASCENT
].value
);
9003 /* Get foreground and background colors, maybe allocate colors. */
9004 if (fmt
[XBM_FOREGROUND
].count
)
9005 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
9007 if (fmt
[XBM_BACKGROUND
].count
)
9008 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
9011 /* Set bits to the bitmap image data. */
9012 data
= fmt
[XBM_DATA
].value
;
9017 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
9019 p
= bits
= (char *) alloca (nbytes
* img
->height
);
9020 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
9022 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
9024 bcopy (XSTRING (line
)->data
, p
, nbytes
);
9026 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
9029 else if (STRINGP (data
))
9030 bits
= XSTRING (data
)->data
;
9032 bits
= XBOOL_VECTOR (data
)->data
;
9034 #if 0 /* TODO : W32 XPM code */
9035 /* Create the pixmap. */
9036 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
9038 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
9039 FRAME_W32_WINDOW (f
),
9041 img
->width
, img
->height
,
9042 foreground
, background
,
9050 image_error ("Unable to create pixmap for XBM image `%s'",
9052 x_clear_image (f
, img
);
9063 /***********************************************************************
9065 ***********************************************************************/
9069 static int xpm_image_p
P_ ((Lisp_Object object
));
9070 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
9071 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
9073 #include "X11/xpm.h"
9075 /* The symbol `xpm' identifying XPM-format images. */
9079 /* Indices of image specification fields in xpm_format, below. */
9081 enum xpm_keyword_index
9095 /* Vector of image_keyword structures describing the format
9096 of valid XPM image specifications. */
9098 static struct image_keyword xpm_format
[XPM_LAST
] =
9100 {":type", IMAGE_SYMBOL_VALUE
, 1},
9101 {":file", IMAGE_STRING_VALUE
, 0},
9102 {":data", IMAGE_STRING_VALUE
, 0},
9103 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9104 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9105 {":relief", IMAGE_INTEGER_VALUE
, 0},
9106 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9107 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9108 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9111 /* Structure describing the image type XBM. */
9113 static struct image_type xpm_type
=
9123 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
9124 for XPM images. Such a list must consist of conses whose car and
9128 xpm_valid_color_symbols_p (color_symbols
)
9129 Lisp_Object color_symbols
;
9131 while (CONSP (color_symbols
))
9133 Lisp_Object sym
= XCAR (color_symbols
);
9135 || !STRINGP (XCAR (sym
))
9136 || !STRINGP (XCDR (sym
)))
9138 color_symbols
= XCDR (color_symbols
);
9141 return NILP (color_symbols
);
9145 /* Value is non-zero if OBJECT is a valid XPM image specification. */
9148 xpm_image_p (object
)
9151 struct image_keyword fmt
[XPM_LAST
];
9152 bcopy (xpm_format
, fmt
, sizeof fmt
);
9153 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
9154 /* Either `:file' or `:data' must be present. */
9155 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
9156 /* Either no `:color-symbols' or it's a list of conses
9157 whose car and cdr are strings. */
9158 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
9159 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
9160 && (fmt
[XPM_ASCENT
].count
== 0
9161 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
9165 /* Load image IMG which will be displayed on frame F. Value is
9166 non-zero if successful. */
9174 XpmAttributes attrs
;
9175 Lisp_Object specified_file
, color_symbols
;
9177 /* Configure the XPM lib. Use the visual of frame F. Allocate
9178 close colors. Return colors allocated. */
9179 bzero (&attrs
, sizeof attrs
);
9180 attrs
.visual
= FRAME_X_VISUAL (f
);
9181 attrs
.colormap
= FRAME_X_COLORMAP (f
);
9182 attrs
.valuemask
|= XpmVisual
;
9183 attrs
.valuemask
|= XpmColormap
;
9184 attrs
.valuemask
|= XpmReturnAllocPixels
;
9185 #ifdef XpmAllocCloseColors
9186 attrs
.alloc_close_colors
= 1;
9187 attrs
.valuemask
|= XpmAllocCloseColors
;
9189 attrs
.closeness
= 600;
9190 attrs
.valuemask
|= XpmCloseness
;
9193 /* If image specification contains symbolic color definitions, add
9194 these to `attrs'. */
9195 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
9196 if (CONSP (color_symbols
))
9199 XpmColorSymbol
*xpm_syms
;
9202 attrs
.valuemask
|= XpmColorSymbols
;
9204 /* Count number of symbols. */
9205 attrs
.numsymbols
= 0;
9206 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
9209 /* Allocate an XpmColorSymbol array. */
9210 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
9211 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
9212 bzero (xpm_syms
, size
);
9213 attrs
.colorsymbols
= xpm_syms
;
9215 /* Fill the color symbol array. */
9216 for (tail
= color_symbols
, i
= 0;
9218 ++i
, tail
= XCDR (tail
))
9220 Lisp_Object name
= XCAR (XCAR (tail
));
9221 Lisp_Object color
= XCDR (XCAR (tail
));
9222 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
9223 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
9224 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
9225 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
9229 /* Create a pixmap for the image, either from a file, or from a
9230 string buffer containing data in the same format as an XPM file. */
9232 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9233 if (STRINGP (specified_file
))
9235 Lisp_Object file
= x_find_image_file (specified_file
);
9236 if (!STRINGP (file
))
9238 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9243 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
9244 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
9249 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
9250 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
9251 XSTRING (buffer
)->data
,
9252 &img
->pixmap
, &img
->mask
,
9257 if (rc
== XpmSuccess
)
9259 /* Remember allocated colors. */
9260 img
->ncolors
= attrs
.nalloc_pixels
;
9261 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
9262 * sizeof *img
->colors
);
9263 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
9264 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
9266 img
->width
= attrs
.width
;
9267 img
->height
= attrs
.height
;
9268 xassert (img
->width
> 0 && img
->height
> 0);
9270 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
9272 XpmFreeAttributes (&attrs
);
9280 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
9283 case XpmFileInvalid
:
9284 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
9288 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
9291 case XpmColorFailed
:
9292 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
9296 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
9301 return rc
== XpmSuccess
;
9304 #endif /* HAVE_XPM != 0 */
9307 #if 0 /* TODO : Color tables on W32. */
9308 /***********************************************************************
9310 ***********************************************************************/
9312 /* An entry in the color table mapping an RGB color to a pixel color. */
9317 unsigned long pixel
;
9319 /* Next in color table collision list. */
9320 struct ct_color
*next
;
9323 /* The bucket vector size to use. Must be prime. */
9327 /* Value is a hash of the RGB color given by R, G, and B. */
9329 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
9331 /* The color hash table. */
9333 struct ct_color
**ct_table
;
9335 /* Number of entries in the color table. */
9337 int ct_colors_allocated
;
9339 /* Function prototypes. */
9341 static void init_color_table
P_ ((void));
9342 static void free_color_table
P_ ((void));
9343 static unsigned long *colors_in_color_table
P_ ((int *n
));
9344 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
9345 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
9348 /* Initialize the color table. */
9353 int size
= CT_SIZE
* sizeof (*ct_table
);
9354 ct_table
= (struct ct_color
**) xmalloc (size
);
9355 bzero (ct_table
, size
);
9356 ct_colors_allocated
= 0;
9360 /* Free memory associated with the color table. */
9366 struct ct_color
*p
, *next
;
9368 for (i
= 0; i
< CT_SIZE
; ++i
)
9369 for (p
= ct_table
[i
]; p
; p
= next
)
9380 /* Value is a pixel color for RGB color R, G, B on frame F. If an
9381 entry for that color already is in the color table, return the
9382 pixel color of that entry. Otherwise, allocate a new color for R,
9383 G, B, and make an entry in the color table. */
9385 static unsigned long
9386 lookup_rgb_color (f
, r
, g
, b
)
9390 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
9391 int i
= hash
% CT_SIZE
;
9394 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9395 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
9404 color
= PALETTERGB (r
, g
, b
);
9406 ++ct_colors_allocated
;
9408 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9413 p
->next
= ct_table
[i
];
9421 /* Look up pixel color PIXEL which is used on frame F in the color
9422 table. If not already present, allocate it. Value is PIXEL. */
9424 static unsigned long
9425 lookup_pixel_color (f
, pixel
)
9427 unsigned long pixel
;
9429 int i
= pixel
% CT_SIZE
;
9432 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9433 if (p
->pixel
== pixel
)
9444 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9445 color
.pixel
= pixel
;
9446 XQueryColor (NULL
, cmap
, &color
);
9447 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
9452 ++ct_colors_allocated
;
9454 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9459 p
->next
= ct_table
[i
];
9463 return FRAME_FOREGROUND_PIXEL (f
);
9469 /* Value is a vector of all pixel colors contained in the color table,
9470 allocated via xmalloc. Set *N to the number of colors. */
9472 static unsigned long *
9473 colors_in_color_table (n
)
9478 unsigned long *colors
;
9480 if (ct_colors_allocated
== 0)
9487 colors
= (unsigned long *) xmalloc (ct_colors_allocated
9489 *n
= ct_colors_allocated
;
9491 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
9492 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9493 colors
[j
++] = p
->pixel
;
9502 /***********************************************************************
9504 ***********************************************************************/
9506 #if 0 /* TODO : W32 versions of low level algorithms */
9507 static void x_laplace_write_row
P_ ((struct frame
*, long *,
9508 int, XImage
*, int));
9509 static void x_laplace_read_row
P_ ((struct frame
*, Colormap
,
9510 XColor
*, int, XImage
*, int));
9513 /* Fill COLORS with RGB colors from row Y of image XIMG. F is the
9514 frame we operate on, CMAP is the color-map in effect, and WIDTH is
9515 the width of one row in the image. */
9518 x_laplace_read_row (f
, cmap
, colors
, width
, ximg
, y
)
9528 for (x
= 0; x
< width
; ++x
)
9529 colors
[x
].pixel
= XGetPixel (ximg
, x
, y
);
9531 XQueryColors (NULL
, cmap
, colors
, width
);
9535 /* Write row Y of image XIMG. PIXELS is an array of WIDTH longs
9536 containing the pixel colors to write. F is the frame we are
9540 x_laplace_write_row (f
, pixels
, width
, ximg
, y
)
9549 for (x
= 0; x
< width
; ++x
)
9550 XPutPixel (ximg
, x
, y
, pixels
[x
]);
9554 /* Transform image IMG which is used on frame F with a Laplace
9555 edge-detection algorithm. The result is an image that can be used
9556 to draw disabled buttons, for example. */
9563 #if 0 /* TODO : W32 version */
9564 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9565 XImage
*ximg
, *oimg
;
9571 int in_y
, out_y
, rc
;
9576 /* Get the X image IMG->pixmap. */
9577 ximg
= XGetImage (NULL
, img
->pixmap
,
9578 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
9580 /* Allocate 3 input rows, and one output row of colors. */
9581 for (i
= 0; i
< 3; ++i
)
9582 in
[i
] = (XColor
*) alloca (img
->width
* sizeof (XColor
));
9583 out
= (long *) alloca (img
->width
* sizeof (long));
9585 /* Create an X image for output. */
9586 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
9589 /* Fill first two rows. */
9590 x_laplace_read_row (f
, cmap
, in
[0], img
->width
, ximg
, 0);
9591 x_laplace_read_row (f
, cmap
, in
[1], img
->width
, ximg
, 1);
9594 /* Write first row, all zeros. */
9595 init_color_table ();
9596 pixel
= lookup_rgb_color (f
, 0, 0, 0);
9597 for (x
= 0; x
< img
->width
; ++x
)
9599 x_laplace_write_row (f
, out
, img
->width
, oimg
, 0);
9602 for (y
= 2; y
< img
->height
; ++y
)
9605 int rowb
= (y
+ 2) % 3;
9607 x_laplace_read_row (f
, cmap
, in
[rowa
], img
->width
, ximg
, in_y
++);
9609 for (x
= 0; x
< img
->width
- 2; ++x
)
9611 int r
= in
[rowa
][x
].red
+ mv2
- in
[rowb
][x
+ 2].red
;
9612 int g
= in
[rowa
][x
].green
+ mv2
- in
[rowb
][x
+ 2].green
;
9613 int b
= in
[rowa
][x
].blue
+ mv2
- in
[rowb
][x
+ 2].blue
;
9615 out
[x
+ 1] = lookup_rgb_color (f
, r
& 0xffff, g
& 0xffff,
9619 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
++);
9622 /* Write last line, all zeros. */
9623 for (x
= 0; x
< img
->width
; ++x
)
9625 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
);
9627 /* Free the input image, and free resources of IMG. */
9628 XDestroyImage (ximg
);
9629 x_clear_image (f
, img
);
9631 /* Put the output image into pixmap, and destroy it. */
9632 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
9633 x_destroy_x_image (oimg
);
9635 /* Remember new pixmap and colors in IMG. */
9636 img
->pixmap
= pixmap
;
9637 img
->colors
= colors_in_color_table (&img
->ncolors
);
9638 free_color_table ();
9645 /* Build a mask for image IMG which is used on frame F. FILE is the
9646 name of an image file, for error messages. HOW determines how to
9647 determine the background color of IMG. If it is a list '(R G B)',
9648 with R, G, and B being integers >= 0, take that as the color of the
9649 background. Otherwise, determine the background color of IMG
9650 heuristically. Value is non-zero if successful. */
9653 x_build_heuristic_mask (f
, img
, how
)
9658 #if 0 /* TODO : W32 version */
9659 Display
*dpy
= FRAME_W32_DISPLAY (f
);
9660 XImage
*ximg
, *mask_img
;
9661 int x
, y
, rc
, look_at_corners_p
;
9666 /* Create an image and pixmap serving as mask. */
9667 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
9668 &mask_img
, &img
->mask
);
9675 /* Get the X image of IMG->pixmap. */
9676 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
9679 /* Determine the background color of ximg. If HOW is `(R G B)'
9680 take that as color. Otherwise, try to determine the color
9682 look_at_corners_p
= 1;
9690 && NATNUMP (XCAR (how
)))
9692 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
9696 if (i
== 3 && NILP (how
))
9698 char color_name
[30];
9699 XColor exact
, color
;
9702 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
9704 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9705 if (XLookupColor (dpy
, cmap
, color_name
, &exact
, &color
))
9708 look_at_corners_p
= 0;
9713 if (look_at_corners_p
)
9715 unsigned long corners
[4];
9718 /* Get the colors at the corners of ximg. */
9719 corners
[0] = XGetPixel (ximg
, 0, 0);
9720 corners
[1] = XGetPixel (ximg
, img
->width
- 1, 0);
9721 corners
[2] = XGetPixel (ximg
, img
->width
- 1, img
->height
- 1);
9722 corners
[3] = XGetPixel (ximg
, 0, img
->height
- 1);
9724 /* Choose the most frequently found color as background. */
9725 for (i
= best_count
= 0; i
< 4; ++i
)
9729 for (j
= n
= 0; j
< 4; ++j
)
9730 if (corners
[i
] == corners
[j
])
9734 bg
= corners
[i
], best_count
= n
;
9738 /* Set all bits in mask_img to 1 whose color in ximg is different
9739 from the background color bg. */
9740 for (y
= 0; y
< img
->height
; ++y
)
9741 for (x
= 0; x
< img
->width
; ++x
)
9742 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
9744 /* Put mask_img into img->mask. */
9745 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
9746 x_destroy_x_image (mask_img
);
9747 XDestroyImage (ximg
);
9757 /***********************************************************************
9758 PBM (mono, gray, color)
9759 ***********************************************************************/
9762 static int pbm_image_p
P_ ((Lisp_Object object
));
9763 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
9764 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
9766 /* The symbol `pbm' identifying images of this type. */
9770 /* Indices of image specification fields in gs_format, below. */
9772 enum pbm_keyword_index
9785 /* Vector of image_keyword structures describing the format
9786 of valid user-defined image specifications. */
9788 static struct image_keyword pbm_format
[PBM_LAST
] =
9790 {":type", IMAGE_SYMBOL_VALUE
, 1},
9791 {":file", IMAGE_STRING_VALUE
, 0},
9792 {":data", IMAGE_STRING_VALUE
, 0},
9793 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9794 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9795 {":relief", IMAGE_INTEGER_VALUE
, 0},
9796 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9797 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9800 /* Structure describing the image type `pbm'. */
9802 static struct image_type pbm_type
=
9812 /* Return non-zero if OBJECT is a valid PBM image specification. */
9815 pbm_image_p (object
)
9818 struct image_keyword fmt
[PBM_LAST
];
9820 bcopy (pbm_format
, fmt
, sizeof fmt
);
9822 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
9823 || (fmt
[PBM_ASCENT
].count
9824 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
9827 /* Must specify either :data or :file. */
9828 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
9832 /* Scan a decimal number from *S and return it. Advance *S while
9833 reading the number. END is the end of the string. Value is -1 at
9837 pbm_scan_number (s
, end
)
9838 unsigned char **s
, *end
;
9844 /* Skip white-space. */
9845 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
9850 /* Skip comment to end of line. */
9851 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
9854 else if (isdigit (c
))
9856 /* Read decimal number. */
9858 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
9859 val
= 10 * val
+ c
- '0';
9870 /* Read FILE into memory. Value is a pointer to a buffer allocated
9871 with xmalloc holding FILE's contents. Value is null if an error
9872 occured. *SIZE is set to the size of the file. */
9875 pbm_read_file (file
, size
)
9883 if (stat (XSTRING (file
)->data
, &st
) == 0
9884 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
9885 && (buf
= (char *) xmalloc (st
.st_size
),
9886 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
9906 /* Load PBM image IMG for use on frame F. */
9914 int width
, height
, max_color_idx
= 0;
9916 Lisp_Object file
, specified_file
;
9917 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
9918 struct gcpro gcpro1
;
9919 unsigned char *contents
= NULL
;
9920 unsigned char *end
, *p
;
9923 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9927 if (STRINGP (specified_file
))
9929 file
= x_find_image_file (specified_file
);
9930 if (!STRINGP (file
))
9932 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9937 contents
= pbm_read_file (file
, &size
);
9938 if (contents
== NULL
)
9940 image_error ("Error reading `%s'", file
, Qnil
);
9946 end
= contents
+ size
;
9951 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
9952 p
= XSTRING (data
)->data
;
9953 end
= p
+ STRING_BYTES (XSTRING (data
));
9956 /* Check magic number. */
9957 if (end
- p
< 2 || *p
++ != 'P')
9959 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
9969 raw_p
= 0, type
= PBM_MONO
;
9973 raw_p
= 0, type
= PBM_GRAY
;
9977 raw_p
= 0, type
= PBM_COLOR
;
9981 raw_p
= 1, type
= PBM_MONO
;
9985 raw_p
= 1, type
= PBM_GRAY
;
9989 raw_p
= 1, type
= PBM_COLOR
;
9993 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
9997 /* Read width, height, maximum color-component. Characters
9998 starting with `#' up to the end of a line are ignored. */
9999 width
= pbm_scan_number (&p
, end
);
10000 height
= pbm_scan_number (&p
, end
);
10002 if (type
!= PBM_MONO
)
10004 max_color_idx
= pbm_scan_number (&p
, end
);
10005 if (raw_p
&& max_color_idx
> 255)
10006 max_color_idx
= 255;
10011 || (type
!= PBM_MONO
&& max_color_idx
< 0))
10015 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
10016 &ximg
, &img
->pixmap
))
10022 /* Initialize the color hash table. */
10023 init_color_table ();
10025 if (type
== PBM_MONO
)
10029 for (y
= 0; y
< height
; ++y
)
10030 for (x
= 0; x
< width
; ++x
)
10040 g
= pbm_scan_number (&p
, end
);
10042 XPutPixel (ximg
, x
, y
, (g
10043 ? FRAME_FOREGROUND_PIXEL (f
)
10044 : FRAME_BACKGROUND_PIXEL (f
)));
10049 for (y
= 0; y
< height
; ++y
)
10050 for (x
= 0; x
< width
; ++x
)
10054 if (type
== PBM_GRAY
)
10055 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
10064 r
= pbm_scan_number (&p
, end
);
10065 g
= pbm_scan_number (&p
, end
);
10066 b
= pbm_scan_number (&p
, end
);
10069 if (r
< 0 || g
< 0 || b
< 0)
10071 xfree (ximg
->data
);
10073 XDestroyImage (ximg
);
10075 image_error ("Invalid pixel value in image `%s'",
10080 /* RGB values are now in the range 0..max_color_idx.
10081 Scale this to the range 0..0xffff supported by X. */
10082 r
= (double) r
* 65535 / max_color_idx
;
10083 g
= (double) g
* 65535 / max_color_idx
;
10084 b
= (double) b
* 65535 / max_color_idx
;
10085 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10089 /* Store in IMG->colors the colors allocated for the image, and
10090 free the color table. */
10091 img
->colors
= colors_in_color_table (&img
->ncolors
);
10092 free_color_table ();
10094 /* Put the image into a pixmap. */
10095 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10096 x_destroy_x_image (ximg
);
10099 img
->width
= width
;
10100 img
->height
= height
;
10106 #endif /* HAVE_PBM */
10109 /***********************************************************************
10111 ***********************************************************************/
10117 /* Function prototypes. */
10119 static int png_image_p
P_ ((Lisp_Object object
));
10120 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
10122 /* The symbol `png' identifying images of this type. */
10126 /* Indices of image specification fields in png_format, below. */
10128 enum png_keyword_index
10137 PNG_HEURISTIC_MASK
,
10141 /* Vector of image_keyword structures describing the format
10142 of valid user-defined image specifications. */
10144 static struct image_keyword png_format
[PNG_LAST
] =
10146 {":type", IMAGE_SYMBOL_VALUE
, 1},
10147 {":data", IMAGE_STRING_VALUE
, 0},
10148 {":file", IMAGE_STRING_VALUE
, 0},
10149 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10150 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10151 {":relief", IMAGE_INTEGER_VALUE
, 0},
10152 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10153 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10156 /* Structure describing the image type `png'. */
10158 static struct image_type png_type
=
10168 /* Return non-zero if OBJECT is a valid PNG image specification. */
10171 png_image_p (object
)
10172 Lisp_Object object
;
10174 struct image_keyword fmt
[PNG_LAST
];
10175 bcopy (png_format
, fmt
, sizeof fmt
);
10177 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
10178 || (fmt
[PNG_ASCENT
].count
10179 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
10182 /* Must specify either the :data or :file keyword. */
10183 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
10187 /* Error and warning handlers installed when the PNG library
10191 my_png_error (png_ptr
, msg
)
10192 png_struct
*png_ptr
;
10195 xassert (png_ptr
!= NULL
);
10196 image_error ("PNG error: %s", build_string (msg
), Qnil
);
10197 longjmp (png_ptr
->jmpbuf
, 1);
10202 my_png_warning (png_ptr
, msg
)
10203 png_struct
*png_ptr
;
10206 xassert (png_ptr
!= NULL
);
10207 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
10210 /* Memory source for PNG decoding. */
10212 struct png_memory_storage
10214 unsigned char *bytes
; /* The data */
10215 size_t len
; /* How big is it? */
10216 int index
; /* Where are we? */
10220 /* Function set as reader function when reading PNG image from memory.
10221 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
10222 bytes from the input to DATA. */
10225 png_read_from_memory (png_ptr
, data
, length
)
10226 png_structp png_ptr
;
10230 struct png_memory_storage
*tbr
10231 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
10233 if (length
> tbr
->len
- tbr
->index
)
10234 png_error (png_ptr
, "Read error");
10236 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
10237 tbr
->index
= tbr
->index
+ length
;
10240 /* Load PNG image IMG for use on frame F. Value is non-zero if
10248 Lisp_Object file
, specified_file
;
10249 Lisp_Object specified_data
;
10251 XImage
*ximg
, *mask_img
= NULL
;
10252 struct gcpro gcpro1
;
10253 png_struct
*png_ptr
= NULL
;
10254 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
10257 png_byte
*pixels
= NULL
;
10258 png_byte
**rows
= NULL
;
10259 png_uint_32 width
, height
;
10260 int bit_depth
, color_type
, interlace_type
;
10262 png_uint_32 row_bytes
;
10265 double screen_gamma
, image_gamma
;
10267 struct png_memory_storage tbr
; /* Data to be read */
10269 /* Find out what file to load. */
10270 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10271 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10275 if (NILP (specified_data
))
10277 file
= x_find_image_file (specified_file
);
10278 if (!STRINGP (file
))
10280 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10285 /* Open the image file. */
10286 fp
= fopen (XSTRING (file
)->data
, "rb");
10289 image_error ("Cannot open image file `%s'", file
, Qnil
);
10295 /* Check PNG signature. */
10296 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
10297 || !png_check_sig (sig
, sizeof sig
))
10299 image_error ("Not a PNG file:` %s'", file
, Qnil
);
10307 /* Read from memory. */
10308 tbr
.bytes
= XSTRING (specified_data
)->data
;
10309 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
10312 /* Check PNG signature. */
10313 if (tbr
.len
< sizeof sig
10314 || !png_check_sig (tbr
.bytes
, sizeof sig
))
10316 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
10321 /* Need to skip past the signature. */
10322 tbr
.bytes
+= sizeof (sig
);
10325 /* Initialize read and info structs for PNG lib. */
10326 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
10327 my_png_error
, my_png_warning
);
10330 if (fp
) fclose (fp
);
10335 info_ptr
= png_create_info_struct (png_ptr
);
10338 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
10339 if (fp
) fclose (fp
);
10344 end_info
= png_create_info_struct (png_ptr
);
10347 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
10348 if (fp
) fclose (fp
);
10353 /* Set error jump-back. We come back here when the PNG library
10354 detects an error. */
10355 if (setjmp (png_ptr
->jmpbuf
))
10359 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10362 if (fp
) fclose (fp
);
10367 /* Read image info. */
10368 if (!NILP (specified_data
))
10369 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
10371 png_init_io (png_ptr
, fp
);
10373 png_set_sig_bytes (png_ptr
, sizeof sig
);
10374 png_read_info (png_ptr
, info_ptr
);
10375 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
10376 &interlace_type
, NULL
, NULL
);
10378 /* If image contains simply transparency data, we prefer to
10379 construct a clipping mask. */
10380 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
10385 /* This function is easier to write if we only have to handle
10386 one data format: RGB or RGBA with 8 bits per channel. Let's
10387 transform other formats into that format. */
10389 /* Strip more than 8 bits per channel. */
10390 if (bit_depth
== 16)
10391 png_set_strip_16 (png_ptr
);
10393 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
10395 png_set_expand (png_ptr
);
10397 /* Convert grayscale images to RGB. */
10398 if (color_type
== PNG_COLOR_TYPE_GRAY
10399 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
10400 png_set_gray_to_rgb (png_ptr
);
10402 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
10403 gamma_str
= getenv ("SCREEN_GAMMA");
10404 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
10406 /* Tell the PNG lib to handle gamma correction for us. */
10408 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
10409 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
10410 /* There is a special chunk in the image specifying the gamma. */
10411 png_set_sRGB (png_ptr
, info_ptr
, intent
);
10414 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
10415 /* Image contains gamma information. */
10416 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
10418 /* Use a default of 0.5 for the image gamma. */
10419 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
10421 /* Handle alpha channel by combining the image with a background
10422 color. Do this only if a real alpha channel is supplied. For
10423 simple transparency, we prefer a clipping mask. */
10424 if (!transparent_p
)
10426 png_color_16
*image_background
;
10428 if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
10429 /* Image contains a background color with which to
10430 combine the image. */
10431 png_set_background (png_ptr
, image_background
,
10432 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
10435 /* Image does not contain a background color with which
10436 to combine the image data via an alpha channel. Use
10437 the frame's background instead. */
10440 png_color_16 frame_background
;
10443 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10444 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
10445 XQueryColor (FRAME_W32_DISPLAY (f
), cmap
, &color
);
10448 bzero (&frame_background
, sizeof frame_background
);
10449 frame_background
.red
= color
.red
;
10450 frame_background
.green
= color
.green
;
10451 frame_background
.blue
= color
.blue
;
10453 png_set_background (png_ptr
, &frame_background
,
10454 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
10458 /* Update info structure. */
10459 png_read_update_info (png_ptr
, info_ptr
);
10461 /* Get number of channels. Valid values are 1 for grayscale images
10462 and images with a palette, 2 for grayscale images with transparency
10463 information (alpha channel), 3 for RGB images, and 4 for RGB
10464 images with alpha channel, i.e. RGBA. If conversions above were
10465 sufficient we should only have 3 or 4 channels here. */
10466 channels
= png_get_channels (png_ptr
, info_ptr
);
10467 xassert (channels
== 3 || channels
== 4);
10469 /* Number of bytes needed for one row of the image. */
10470 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
10472 /* Allocate memory for the image. */
10473 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
10474 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
10475 for (i
= 0; i
< height
; ++i
)
10476 rows
[i
] = pixels
+ i
* row_bytes
;
10478 /* Read the entire image. */
10479 png_read_image (png_ptr
, rows
);
10480 png_read_end (png_ptr
, info_ptr
);
10489 /* Create the X image and pixmap. */
10490 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10497 /* Create an image and pixmap serving as mask if the PNG image
10498 contains an alpha channel. */
10501 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
10502 &mask_img
, &img
->mask
))
10504 x_destroy_x_image (ximg
);
10505 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
10511 /* Fill the X image and mask from PNG data. */
10512 init_color_table ();
10514 for (y
= 0; y
< height
; ++y
)
10516 png_byte
*p
= rows
[y
];
10518 for (x
= 0; x
< width
; ++x
)
10525 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10527 /* An alpha channel, aka mask channel, associates variable
10528 transparency with an image. Where other image formats
10529 support binary transparency---fully transparent or fully
10530 opaque---PNG allows up to 254 levels of partial transparency.
10531 The PNG library implements partial transparency by combining
10532 the image with a specified background color.
10534 I'm not sure how to handle this here nicely: because the
10535 background on which the image is displayed may change, for
10536 real alpha channel support, it would be necessary to create
10537 a new image for each possible background.
10539 What I'm doing now is that a mask is created if we have
10540 boolean transparency information. Otherwise I'm using
10541 the frame's background color to combine the image with. */
10546 XPutPixel (mask_img
, x
, y
, *p
> 0);
10552 /* Remember colors allocated for this image. */
10553 img
->colors
= colors_in_color_table (&img
->ncolors
);
10554 free_color_table ();
10557 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10561 img
->width
= width
;
10562 img
->height
= height
;
10564 /* Put the image into the pixmap, then free the X image and its buffer. */
10565 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10566 x_destroy_x_image (ximg
);
10568 /* Same for the mask. */
10571 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10572 x_destroy_x_image (mask_img
);
10580 #endif /* HAVE_PNG != 0 */
10584 /***********************************************************************
10586 ***********************************************************************/
10590 /* Work around a warning about HAVE_STDLIB_H being redefined in
10592 #ifdef HAVE_STDLIB_H
10593 #define HAVE_STDLIB_H_1
10594 #undef HAVE_STDLIB_H
10595 #endif /* HAVE_STLIB_H */
10597 #include <jpeglib.h>
10598 #include <jerror.h>
10599 #include <setjmp.h>
10601 #ifdef HAVE_STLIB_H_1
10602 #define HAVE_STDLIB_H 1
10605 static int jpeg_image_p
P_ ((Lisp_Object object
));
10606 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
10608 /* The symbol `jpeg' identifying images of this type. */
10612 /* Indices of image specification fields in gs_format, below. */
10614 enum jpeg_keyword_index
10623 JPEG_HEURISTIC_MASK
,
10627 /* Vector of image_keyword structures describing the format
10628 of valid user-defined image specifications. */
10630 static struct image_keyword jpeg_format
[JPEG_LAST
] =
10632 {":type", IMAGE_SYMBOL_VALUE
, 1},
10633 {":data", IMAGE_STRING_VALUE
, 0},
10634 {":file", IMAGE_STRING_VALUE
, 0},
10635 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10636 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10637 {":relief", IMAGE_INTEGER_VALUE
, 0},
10638 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10639 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10642 /* Structure describing the image type `jpeg'. */
10644 static struct image_type jpeg_type
=
10654 /* Return non-zero if OBJECT is a valid JPEG image specification. */
10657 jpeg_image_p (object
)
10658 Lisp_Object object
;
10660 struct image_keyword fmt
[JPEG_LAST
];
10662 bcopy (jpeg_format
, fmt
, sizeof fmt
);
10664 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
10665 || (fmt
[JPEG_ASCENT
].count
10666 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
10669 /* Must specify either the :data or :file keyword. */
10670 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
10674 struct my_jpeg_error_mgr
10676 struct jpeg_error_mgr pub
;
10677 jmp_buf setjmp_buffer
;
10681 my_error_exit (cinfo
)
10682 j_common_ptr cinfo
;
10684 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
10685 longjmp (mgr
->setjmp_buffer
, 1);
10688 /* Init source method for JPEG data source manager. Called by
10689 jpeg_read_header() before any data is actually read. See
10690 libjpeg.doc from the JPEG lib distribution. */
10693 our_init_source (cinfo
)
10694 j_decompress_ptr cinfo
;
10699 /* Fill input buffer method for JPEG data source manager. Called
10700 whenever more data is needed. We read the whole image in one step,
10701 so this only adds a fake end of input marker at the end. */
10704 our_fill_input_buffer (cinfo
)
10705 j_decompress_ptr cinfo
;
10707 /* Insert a fake EOI marker. */
10708 struct jpeg_source_mgr
*src
= cinfo
->src
;
10709 static JOCTET buffer
[2];
10711 buffer
[0] = (JOCTET
) 0xFF;
10712 buffer
[1] = (JOCTET
) JPEG_EOI
;
10714 src
->next_input_byte
= buffer
;
10715 src
->bytes_in_buffer
= 2;
10720 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
10721 is the JPEG data source manager. */
10724 our_skip_input_data (cinfo
, num_bytes
)
10725 j_decompress_ptr cinfo
;
10728 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10732 if (num_bytes
> src
->bytes_in_buffer
)
10733 ERREXIT (cinfo
, JERR_INPUT_EOF
);
10735 src
->bytes_in_buffer
-= num_bytes
;
10736 src
->next_input_byte
+= num_bytes
;
10741 /* Method to terminate data source. Called by
10742 jpeg_finish_decompress() after all data has been processed. */
10745 our_term_source (cinfo
)
10746 j_decompress_ptr cinfo
;
10751 /* Set up the JPEG lib for reading an image from DATA which contains
10752 LEN bytes. CINFO is the decompression info structure created for
10753 reading the image. */
10756 jpeg_memory_src (cinfo
, data
, len
)
10757 j_decompress_ptr cinfo
;
10761 struct jpeg_source_mgr
*src
;
10763 if (cinfo
->src
== NULL
)
10765 /* First time for this JPEG object? */
10766 cinfo
->src
= (struct jpeg_source_mgr
*)
10767 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
10768 sizeof (struct jpeg_source_mgr
));
10769 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10770 src
->next_input_byte
= data
;
10773 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10774 src
->init_source
= our_init_source
;
10775 src
->fill_input_buffer
= our_fill_input_buffer
;
10776 src
->skip_input_data
= our_skip_input_data
;
10777 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
10778 src
->term_source
= our_term_source
;
10779 src
->bytes_in_buffer
= len
;
10780 src
->next_input_byte
= data
;
10784 /* Load image IMG for use on frame F. Patterned after example.c
10785 from the JPEG lib. */
10792 struct jpeg_decompress_struct cinfo
;
10793 struct my_jpeg_error_mgr mgr
;
10794 Lisp_Object file
, specified_file
;
10795 Lisp_Object specified_data
;
10798 int row_stride
, x
, y
;
10799 XImage
*ximg
= NULL
;
10801 unsigned long *colors
;
10803 struct gcpro gcpro1
;
10805 /* Open the JPEG file. */
10806 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10807 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10811 if (NILP (specified_data
))
10813 file
= x_find_image_file (specified_file
);
10814 if (!STRINGP (file
))
10816 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10821 fp
= fopen (XSTRING (file
)->data
, "r");
10824 image_error ("Cannot open `%s'", file
, Qnil
);
10830 /* Customize libjpeg's error handling to call my_error_exit when an
10831 error is detected. This function will perform a longjmp. */
10832 mgr
.pub
.error_exit
= my_error_exit
;
10833 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
10835 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
10839 /* Called from my_error_exit. Display a JPEG error. */
10840 char buffer
[JMSG_LENGTH_MAX
];
10841 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
10842 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
10843 build_string (buffer
));
10846 /* Close the input file and destroy the JPEG object. */
10849 jpeg_destroy_decompress (&cinfo
);
10853 /* If we already have an XImage, free that. */
10854 x_destroy_x_image (ximg
);
10856 /* Free pixmap and colors. */
10857 x_clear_image (f
, img
);
10864 /* Create the JPEG decompression object. Let it read from fp.
10865 Read the JPEG image header. */
10866 jpeg_create_decompress (&cinfo
);
10868 if (NILP (specified_data
))
10869 jpeg_stdio_src (&cinfo
, fp
);
10871 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
10872 STRING_BYTES (XSTRING (specified_data
)));
10874 jpeg_read_header (&cinfo
, TRUE
);
10876 /* Customize decompression so that color quantization will be used.
10877 Start decompression. */
10878 cinfo
.quantize_colors
= TRUE
;
10879 jpeg_start_decompress (&cinfo
);
10880 width
= img
->width
= cinfo
.output_width
;
10881 height
= img
->height
= cinfo
.output_height
;
10885 /* Create X image and pixmap. */
10886 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10890 longjmp (mgr
.setjmp_buffer
, 2);
10893 /* Allocate colors. When color quantization is used,
10894 cinfo.actual_number_of_colors has been set with the number of
10895 colors generated, and cinfo.colormap is a two-dimensional array
10896 of color indices in the range 0..cinfo.actual_number_of_colors.
10897 No more than 255 colors will be generated. */
10901 if (cinfo
.out_color_components
> 2)
10902 ir
= 0, ig
= 1, ib
= 2;
10903 else if (cinfo
.out_color_components
> 1)
10904 ir
= 0, ig
= 1, ib
= 0;
10906 ir
= 0, ig
= 0, ib
= 0;
10908 /* Use the color table mechanism because it handles colors that
10909 cannot be allocated nicely. Such colors will be replaced with
10910 a default color, and we don't have to care about which colors
10911 can be freed safely, and which can't. */
10912 init_color_table ();
10913 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
10916 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
10918 /* Multiply RGB values with 255 because X expects RGB values
10919 in the range 0..0xffff. */
10920 int r
= cinfo
.colormap
[ir
][i
] << 8;
10921 int g
= cinfo
.colormap
[ig
][i
] << 8;
10922 int b
= cinfo
.colormap
[ib
][i
] << 8;
10923 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
10926 /* Remember those colors actually allocated. */
10927 img
->colors
= colors_in_color_table (&img
->ncolors
);
10928 free_color_table ();
10932 row_stride
= width
* cinfo
.output_components
;
10933 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
10935 for (y
= 0; y
< height
; ++y
)
10937 jpeg_read_scanlines (&cinfo
, buffer
, 1);
10938 for (x
= 0; x
< cinfo
.output_width
; ++x
)
10939 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
10943 jpeg_finish_decompress (&cinfo
);
10944 jpeg_destroy_decompress (&cinfo
);
10948 /* Put the image into the pixmap. */
10949 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10950 x_destroy_x_image (ximg
);
10956 #endif /* HAVE_JPEG */
10960 /***********************************************************************
10962 ***********************************************************************/
10966 #include <tiffio.h>
10968 static int tiff_image_p
P_ ((Lisp_Object object
));
10969 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
10971 /* The symbol `tiff' identifying images of this type. */
10975 /* Indices of image specification fields in tiff_format, below. */
10977 enum tiff_keyword_index
10986 TIFF_HEURISTIC_MASK
,
10990 /* Vector of image_keyword structures describing the format
10991 of valid user-defined image specifications. */
10993 static struct image_keyword tiff_format
[TIFF_LAST
] =
10995 {":type", IMAGE_SYMBOL_VALUE
, 1},
10996 {":data", IMAGE_STRING_VALUE
, 0},
10997 {":file", IMAGE_STRING_VALUE
, 0},
10998 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10999 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11000 {":relief", IMAGE_INTEGER_VALUE
, 0},
11001 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11002 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11005 /* Structure describing the image type `tiff'. */
11007 static struct image_type tiff_type
=
11017 /* Return non-zero if OBJECT is a valid TIFF image specification. */
11020 tiff_image_p (object
)
11021 Lisp_Object object
;
11023 struct image_keyword fmt
[TIFF_LAST
];
11024 bcopy (tiff_format
, fmt
, sizeof fmt
);
11026 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
11027 || (fmt
[TIFF_ASCENT
].count
11028 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
11031 /* Must specify either the :data or :file keyword. */
11032 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
11036 /* Reading from a memory buffer for TIFF images Based on the PNG
11037 memory source, but we have to provide a lot of extra functions.
11040 We really only need to implement read and seek, but I am not
11041 convinced that the TIFF library is smart enough not to destroy
11042 itself if we only hand it the function pointers we need to
11047 unsigned char *bytes
;
11051 tiff_memory_source
;
11054 tiff_read_from_memory (data
, buf
, size
)
11059 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11061 if (size
> src
->len
- src
->index
)
11062 return (size_t) -1;
11063 bcopy (src
->bytes
+ src
->index
, buf
, size
);
11064 src
->index
+= size
;
11069 tiff_write_from_memory (data
, buf
, size
)
11074 return (size_t) -1;
11078 tiff_seek_in_memory (data
, off
, whence
)
11083 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11088 case SEEK_SET
: /* Go from beginning of source. */
11092 case SEEK_END
: /* Go from end of source. */
11093 idx
= src
->len
+ off
;
11096 case SEEK_CUR
: /* Go from current position. */
11097 idx
= src
->index
+ off
;
11100 default: /* Invalid `whence'. */
11104 if (idx
> src
->len
|| idx
< 0)
11112 tiff_close_memory (data
)
11120 tiff_mmap_memory (data
, pbase
, psize
)
11125 /* It is already _IN_ memory. */
11130 tiff_unmap_memory (data
, base
, size
)
11135 /* We don't need to do this. */
11139 tiff_size_of_memory (data
)
11142 return ((tiff_memory_source
*) data
)->len
;
11145 /* Load TIFF image IMG for use on frame F. Value is non-zero if
11153 Lisp_Object file
, specified_file
;
11154 Lisp_Object specified_data
;
11156 int width
, height
, x
, y
;
11160 struct gcpro gcpro1
;
11161 tiff_memory_source memsrc
;
11163 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11164 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11168 if (NILP (specified_data
))
11170 /* Read from a file */
11171 file
= x_find_image_file (specified_file
);
11172 if (!STRINGP (file
))
11174 image_error ("Cannot find image file `%s'", file
, Qnil
);
11179 /* Try to open the image file. */
11180 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
11183 image_error ("Cannot open `%s'", file
, Qnil
);
11190 /* Memory source! */
11191 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11192 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11195 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
11196 (TIFFReadWriteProc
) tiff_read_from_memory
,
11197 (TIFFReadWriteProc
) tiff_write_from_memory
,
11198 tiff_seek_in_memory
,
11200 tiff_size_of_memory
,
11202 tiff_unmap_memory
);
11206 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
11212 /* Get width and height of the image, and allocate a raster buffer
11213 of width x height 32-bit values. */
11214 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
11215 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
11216 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
11218 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
11222 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
11230 /* Create the X image and pixmap. */
11231 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11239 /* Initialize the color table. */
11240 init_color_table ();
11242 /* Process the pixel raster. Origin is in the lower-left corner. */
11243 for (y
= 0; y
< height
; ++y
)
11245 uint32
*row
= buf
+ y
* width
;
11247 for (x
= 0; x
< width
; ++x
)
11249 uint32 abgr
= row
[x
];
11250 int r
= TIFFGetR (abgr
) << 8;
11251 int g
= TIFFGetG (abgr
) << 8;
11252 int b
= TIFFGetB (abgr
) << 8;
11253 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
11257 /* Remember the colors allocated for the image. Free the color table. */
11258 img
->colors
= colors_in_color_table (&img
->ncolors
);
11259 free_color_table ();
11261 /* Put the image into the pixmap, then free the X image and its buffer. */
11262 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11263 x_destroy_x_image (ximg
);
11267 img
->width
= width
;
11268 img
->height
= height
;
11274 #endif /* HAVE_TIFF != 0 */
11278 /***********************************************************************
11280 ***********************************************************************/
11284 #include <gif_lib.h>
11286 static int gif_image_p
P_ ((Lisp_Object object
));
11287 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
11289 /* The symbol `gif' identifying images of this type. */
11293 /* Indices of image specification fields in gif_format, below. */
11295 enum gif_keyword_index
11304 GIF_HEURISTIC_MASK
,
11309 /* Vector of image_keyword structures describing the format
11310 of valid user-defined image specifications. */
11312 static struct image_keyword gif_format
[GIF_LAST
] =
11314 {":type", IMAGE_SYMBOL_VALUE
, 1},
11315 {":data", IMAGE_STRING_VALUE
, 0},
11316 {":file", IMAGE_STRING_VALUE
, 0},
11317 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11318 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11319 {":relief", IMAGE_INTEGER_VALUE
, 0},
11320 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11321 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11322 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0}
11325 /* Structure describing the image type `gif'. */
11327 static struct image_type gif_type
=
11336 /* Return non-zero if OBJECT is a valid GIF image specification. */
11339 gif_image_p (object
)
11340 Lisp_Object object
;
11342 struct image_keyword fmt
[GIF_LAST
];
11343 bcopy (gif_format
, fmt
, sizeof fmt
);
11345 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
11346 || (fmt
[GIF_ASCENT
].count
11347 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
11350 /* Must specify either the :data or :file keyword. */
11351 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
11354 /* Reading a GIF image from memory
11355 Based on the PNG memory stuff to a certain extent. */
11359 unsigned char *bytes
;
11365 /* Make the current memory source available to gif_read_from_memory.
11366 It's done this way because not all versions of libungif support
11367 a UserData field in the GifFileType structure. */
11368 static gif_memory_source
*current_gif_memory_src
;
11371 gif_read_from_memory (file
, buf
, len
)
11376 gif_memory_source
*src
= current_gif_memory_src
;
11378 if (len
> src
->len
- src
->index
)
11381 bcopy (src
->bytes
+ src
->index
, buf
, len
);
11387 /* Load GIF image IMG for use on frame F. Value is non-zero if
11395 Lisp_Object file
, specified_file
;
11396 Lisp_Object specified_data
;
11397 int rc
, width
, height
, x
, y
, i
;
11399 ColorMapObject
*gif_color_map
;
11400 unsigned long pixel_colors
[256];
11402 struct gcpro gcpro1
;
11404 int ino
, image_left
, image_top
, image_width
, image_height
;
11405 gif_memory_source memsrc
;
11406 unsigned char *raster
;
11408 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11409 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11413 if (NILP (specified_data
))
11415 file
= x_find_image_file (specified_file
);
11416 if (!STRINGP (file
))
11418 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11423 /* Open the GIF file. */
11424 gif
= DGifOpenFileName (XSTRING (file
)->data
);
11427 image_error ("Cannot open `%s'", file
, Qnil
);
11434 /* Read from memory! */
11435 current_gif_memory_src
= &memsrc
;
11436 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11437 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11440 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
11443 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
11449 /* Read entire contents. */
11450 rc
= DGifSlurp (gif
);
11451 if (rc
== GIF_ERROR
)
11453 image_error ("Error reading `%s'", img
->spec
, Qnil
);
11454 DGifCloseFile (gif
);
11459 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
11460 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
11461 if (ino
>= gif
->ImageCount
)
11463 image_error ("Invalid image number `%s' in image `%s'",
11465 DGifCloseFile (gif
);
11470 width
= img
->width
= gif
->SWidth
;
11471 height
= img
->height
= gif
->SHeight
;
11475 /* Create the X image and pixmap. */
11476 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11479 DGifCloseFile (gif
);
11484 /* Allocate colors. */
11485 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
11486 if (!gif_color_map
)
11487 gif_color_map
= gif
->SColorMap
;
11488 init_color_table ();
11489 bzero (pixel_colors
, sizeof pixel_colors
);
11491 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
11493 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
11494 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
11495 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
11496 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11499 img
->colors
= colors_in_color_table (&img
->ncolors
);
11500 free_color_table ();
11502 /* Clear the part of the screen image that are not covered by
11503 the image from the GIF file. Full animated GIF support
11504 requires more than can be done here (see the gif89 spec,
11505 disposal methods). Let's simply assume that the part
11506 not covered by a sub-image is in the frame's background color. */
11507 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
11508 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
11509 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
11510 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
11512 for (y
= 0; y
< image_top
; ++y
)
11513 for (x
= 0; x
< width
; ++x
)
11514 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11516 for (y
= image_top
+ image_height
; y
< height
; ++y
)
11517 for (x
= 0; x
< width
; ++x
)
11518 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11520 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
11522 for (x
= 0; x
< image_left
; ++x
)
11523 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11524 for (x
= image_left
+ image_width
; x
< width
; ++x
)
11525 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11528 /* Read the GIF image into the X image. We use a local variable
11529 `raster' here because RasterBits below is a char *, and invites
11530 problems with bytes >= 0x80. */
11531 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
11533 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
11535 static int interlace_start
[] = {0, 4, 2, 1};
11536 static int interlace_increment
[] = {8, 8, 4, 2};
11538 int row
= interlace_start
[0];
11542 for (y
= 0; y
< image_height
; y
++)
11544 if (row
>= image_height
)
11546 row
= interlace_start
[++pass
];
11547 while (row
>= image_height
)
11548 row
= interlace_start
[++pass
];
11551 for (x
= 0; x
< image_width
; x
++)
11553 int i
= raster
[(y
* image_width
) + x
];
11554 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
11558 row
+= interlace_increment
[pass
];
11563 for (y
= 0; y
< image_height
; ++y
)
11564 for (x
= 0; x
< image_width
; ++x
)
11566 int i
= raster
[y
* image_width
+ x
];
11567 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
11571 DGifCloseFile (gif
);
11573 /* Put the image into the pixmap, then free the X image and its buffer. */
11574 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11575 x_destroy_x_image (ximg
);
11582 #endif /* HAVE_GIF != 0 */
11586 /***********************************************************************
11588 ***********************************************************************/
11590 #ifdef HAVE_GHOSTSCRIPT
11591 static int gs_image_p
P_ ((Lisp_Object object
));
11592 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
11593 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
11595 /* The symbol `postscript' identifying images of this type. */
11597 Lisp_Object Qpostscript
;
11599 /* Keyword symbols. */
11601 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
11603 /* Indices of image specification fields in gs_format, below. */
11605 enum gs_keyword_index
11621 /* Vector of image_keyword structures describing the format
11622 of valid user-defined image specifications. */
11624 static struct image_keyword gs_format
[GS_LAST
] =
11626 {":type", IMAGE_SYMBOL_VALUE
, 1},
11627 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11628 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11629 {":file", IMAGE_STRING_VALUE
, 1},
11630 {":loader", IMAGE_FUNCTION_VALUE
, 0},
11631 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
11632 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11633 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11634 {":relief", IMAGE_INTEGER_VALUE
, 0},
11635 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11636 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11639 /* Structure describing the image type `ghostscript'. */
11641 static struct image_type gs_type
=
11651 /* Free X resources of Ghostscript image IMG which is used on frame F. */
11654 gs_clear_image (f
, img
)
11658 /* IMG->data.ptr_val may contain a recorded colormap. */
11659 xfree (img
->data
.ptr_val
);
11660 x_clear_image (f
, img
);
11664 /* Return non-zero if OBJECT is a valid Ghostscript image
11668 gs_image_p (object
)
11669 Lisp_Object object
;
11671 struct image_keyword fmt
[GS_LAST
];
11675 bcopy (gs_format
, fmt
, sizeof fmt
);
11677 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
11678 || (fmt
[GS_ASCENT
].count
11679 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
11682 /* Bounding box must be a list or vector containing 4 integers. */
11683 tem
= fmt
[GS_BOUNDING_BOX
].value
;
11686 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
11687 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
11692 else if (VECTORP (tem
))
11694 if (XVECTOR (tem
)->size
!= 4)
11696 for (i
= 0; i
< 4; ++i
)
11697 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
11707 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
11716 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
11717 struct gcpro gcpro1
, gcpro2
;
11719 double in_width
, in_height
;
11720 Lisp_Object pixel_colors
= Qnil
;
11722 /* Compute pixel size of pixmap needed from the given size in the
11723 image specification. Sizes in the specification are in pt. 1 pt
11724 = 1/72 in, xdpi and ydpi are stored in the frame's X display
11726 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
11727 in_width
= XFASTINT (pt_width
) / 72.0;
11728 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
11729 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
11730 in_height
= XFASTINT (pt_height
) / 72.0;
11731 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
11733 /* Create the pixmap. */
11735 xassert (img
->pixmap
== 0);
11736 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11737 img
->width
, img
->height
,
11738 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
11743 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
11747 /* Call the loader to fill the pixmap. It returns a process object
11748 if successful. We do not record_unwind_protect here because
11749 other places in redisplay like calling window scroll functions
11750 don't either. Let the Lisp loader use `unwind-protect' instead. */
11751 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
11753 sprintf (buffer
, "%lu %lu",
11754 (unsigned long) FRAME_W32_WINDOW (f
),
11755 (unsigned long) img
->pixmap
);
11756 window_and_pixmap_id
= build_string (buffer
);
11758 sprintf (buffer
, "%lu %lu",
11759 FRAME_FOREGROUND_PIXEL (f
),
11760 FRAME_BACKGROUND_PIXEL (f
));
11761 pixel_colors
= build_string (buffer
);
11763 XSETFRAME (frame
, f
);
11764 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
11766 loader
= intern ("gs-load-image");
11768 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
11769 make_number (img
->width
),
11770 make_number (img
->height
),
11771 window_and_pixmap_id
,
11774 return PROCESSP (img
->data
.lisp_val
);
11778 /* Kill the Ghostscript process that was started to fill PIXMAP on
11779 frame F. Called from XTread_socket when receiving an event
11780 telling Emacs that Ghostscript has finished drawing. */
11783 x_kill_gs_process (pixmap
, f
)
11787 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
11791 /* Find the image containing PIXMAP. */
11792 for (i
= 0; i
< c
->used
; ++i
)
11793 if (c
->images
[i
]->pixmap
== pixmap
)
11796 /* Kill the GS process. We should have found PIXMAP in the image
11797 cache and its image should contain a process object. */
11798 xassert (i
< c
->used
);
11799 img
= c
->images
[i
];
11800 xassert (PROCESSP (img
->data
.lisp_val
));
11801 Fkill_process (img
->data
.lisp_val
, Qnil
);
11802 img
->data
.lisp_val
= Qnil
;
11804 /* On displays with a mutable colormap, figure out the colors
11805 allocated for the image by looking at the pixels of an XImage for
11807 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
11808 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
11814 /* Try to get an XImage for img->pixmep. */
11815 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
11816 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
11821 /* Initialize the color table. */
11822 init_color_table ();
11824 /* For each pixel of the image, look its color up in the
11825 color table. After having done so, the color table will
11826 contain an entry for each color used by the image. */
11827 for (y
= 0; y
< img
->height
; ++y
)
11828 for (x
= 0; x
< img
->width
; ++x
)
11830 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
11831 lookup_pixel_color (f
, pixel
);
11834 /* Record colors in the image. Free color table and XImage. */
11835 img
->colors
= colors_in_color_table (&img
->ncolors
);
11836 free_color_table ();
11837 XDestroyImage (ximg
);
11839 #if 0 /* This doesn't seem to be the case. If we free the colors
11840 here, we get a BadAccess later in x_clear_image when
11841 freeing the colors. */
11842 /* We have allocated colors once, but Ghostscript has also
11843 allocated colors on behalf of us. So, to get the
11844 reference counts right, free them once. */
11847 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
11848 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
,
11849 img
->colors
, img
->ncolors
, 0);
11854 image_error ("Cannot get X image of `%s'; colors will not be freed",
11861 #endif /* HAVE_GHOSTSCRIPT */
11864 /***********************************************************************
11866 ***********************************************************************/
11868 DEFUN ("x-change-window-property", Fx_change_window_property
,
11869 Sx_change_window_property
, 2, 3, 0,
11870 "Change window property PROP to VALUE on the X window of FRAME.\n\
11871 PROP and VALUE must be strings. FRAME nil or omitted means use the\n\
11872 selected frame. Value is VALUE.")
11873 (prop
, value
, frame
)
11874 Lisp_Object frame
, prop
, value
;
11876 #if 0 /* TODO : port window properties to W32 */
11877 struct frame
*f
= check_x_frame (frame
);
11880 CHECK_STRING (prop
, 1);
11881 CHECK_STRING (value
, 2);
11884 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11885 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11886 prop_atom
, XA_STRING
, 8, PropModeReplace
,
11887 XSTRING (value
)->data
, XSTRING (value
)->size
);
11889 /* Make sure the property is set when we return. */
11890 XFlush (FRAME_W32_DISPLAY (f
));
11899 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
11900 Sx_delete_window_property
, 1, 2, 0,
11901 "Remove window property PROP from X window of FRAME.\n\
11902 FRAME nil or omitted means use the selected frame. Value is PROP.")
11904 Lisp_Object prop
, frame
;
11906 #if 0 /* TODO : port window properties to W32 */
11908 struct frame
*f
= check_x_frame (frame
);
11911 CHECK_STRING (prop
, 1);
11913 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11914 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
11916 /* Make sure the property is removed when we return. */
11917 XFlush (FRAME_W32_DISPLAY (f
));
11925 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
11927 "Value is the value of window property PROP on FRAME.\n\
11928 If FRAME is nil or omitted, use the selected frame. Value is nil\n\
11929 if FRAME hasn't a property with name PROP or if PROP has no string\n\
11932 Lisp_Object prop
, frame
;
11934 #if 0 /* TODO : port window properties to W32 */
11936 struct frame
*f
= check_x_frame (frame
);
11939 Lisp_Object prop_value
= Qnil
;
11940 char *tmp_data
= NULL
;
11943 unsigned long actual_size
, bytes_remaining
;
11945 CHECK_STRING (prop
, 1);
11947 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11948 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11949 prop_atom
, 0, 0, False
, XA_STRING
,
11950 &actual_type
, &actual_format
, &actual_size
,
11951 &bytes_remaining
, (unsigned char **) &tmp_data
);
11954 int size
= bytes_remaining
;
11959 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11960 prop_atom
, 0, bytes_remaining
,
11962 &actual_type
, &actual_format
,
11963 &actual_size
, &bytes_remaining
,
11964 (unsigned char **) &tmp_data
);
11966 prop_value
= make_string (tmp_data
, size
);
11981 /***********************************************************************
11983 ***********************************************************************/
11985 /* If non-null, an asynchronous timer that, when it expires, displays
11986 a busy cursor on all frames. */
11988 static struct atimer
*busy_cursor_atimer
;
11990 /* Non-zero means a busy cursor is currently shown. */
11992 static int busy_cursor_shown_p
;
11994 /* Number of seconds to wait before displaying a busy cursor. */
11996 static Lisp_Object Vbusy_cursor_delay
;
11998 /* Default number of seconds to wait before displaying a busy
12001 #define DEFAULT_BUSY_CURSOR_DELAY 1
12003 /* Function prototypes. */
12005 static void show_busy_cursor
P_ ((struct atimer
*));
12006 static void hide_busy_cursor
P_ ((void));
12009 /* Cancel a currently active busy-cursor timer, and start a new one. */
12012 start_busy_cursor ()
12014 #if 0 /* TODO: cursor shape changes. */
12016 int secs
, usecs
= 0;
12018 cancel_busy_cursor ();
12020 if (INTEGERP (Vbusy_cursor_delay
)
12021 && XINT (Vbusy_cursor_delay
) > 0)
12022 secs
= XFASTINT (Vbusy_cursor_delay
);
12023 else if (FLOATP (Vbusy_cursor_delay
)
12024 && XFLOAT_DATA (Vbusy_cursor_delay
) > 0)
12027 tem
= Ftruncate (Vbusy_cursor_delay
, Qnil
);
12028 secs
= XFASTINT (tem
);
12029 usecs
= (XFLOAT_DATA (Vbusy_cursor_delay
) - secs
) * 1000000;
12032 secs
= DEFAULT_BUSY_CURSOR_DELAY
;
12034 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
12035 busy_cursor_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
12036 show_busy_cursor
, NULL
);
12041 /* Cancel the busy cursor timer if active, hide a busy cursor if
12045 cancel_busy_cursor ()
12047 if (busy_cursor_atimer
)
12049 cancel_atimer (busy_cursor_atimer
);
12050 busy_cursor_atimer
= NULL
;
12053 if (busy_cursor_shown_p
)
12054 hide_busy_cursor ();
12058 /* Timer function of busy_cursor_atimer. TIMER is equal to
12059 busy_cursor_atimer.
12061 Display a busy cursor on all frames by mapping the frames'
12062 busy_window. Set the busy_p flag in the frames' output_data.x
12063 structure to indicate that a busy cursor is shown on the
12067 show_busy_cursor (timer
)
12068 struct atimer
*timer
;
12070 #if 0 /* TODO: cursor shape changes. */
12071 /* The timer implementation will cancel this timer automatically
12072 after this function has run. Set busy_cursor_atimer to null
12073 so that we know the timer doesn't have to be canceled. */
12074 busy_cursor_atimer
= NULL
;
12076 if (!busy_cursor_shown_p
)
12078 Lisp_Object rest
, frame
;
12082 FOR_EACH_FRAME (rest
, frame
)
12083 if (FRAME_X_P (XFRAME (frame
)))
12085 struct frame
*f
= XFRAME (frame
);
12087 f
->output_data
.w32
->busy_p
= 1;
12089 if (!f
->output_data
.w32
->busy_window
)
12091 unsigned long mask
= CWCursor
;
12092 XSetWindowAttributes attrs
;
12094 attrs
.cursor
= f
->output_data
.w32
->busy_cursor
;
12096 f
->output_data
.w32
->busy_window
12097 = XCreateWindow (FRAME_X_DISPLAY (f
),
12098 FRAME_OUTER_WINDOW (f
),
12099 0, 0, 32000, 32000, 0, 0,
12105 XMapRaised (FRAME_X_DISPLAY (f
), f
->output_data
.w32
->busy_window
);
12106 XFlush (FRAME_X_DISPLAY (f
));
12109 busy_cursor_shown_p
= 1;
12116 /* Hide the busy cursor on all frames, if it is currently shown. */
12119 hide_busy_cursor ()
12121 #if 0 /* TODO: cursor shape changes. */
12122 if (busy_cursor_shown_p
)
12124 Lisp_Object rest
, frame
;
12127 FOR_EACH_FRAME (rest
, frame
)
12129 struct frame
*f
= XFRAME (frame
);
12132 /* Watch out for newly created frames. */
12133 && f
->output_data
.x
->busy_window
)
12135 XUnmapWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->busy_window
);
12136 /* Sync here because XTread_socket looks at the busy_p flag
12137 that is reset to zero below. */
12138 XSync (FRAME_X_DISPLAY (f
), False
);
12139 f
->output_data
.x
->busy_p
= 0;
12143 busy_cursor_shown_p
= 0;
12151 /***********************************************************************
12153 ***********************************************************************/
12155 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
12158 /* The frame of a currently visible tooltip, or null. */
12160 struct frame
*tip_frame
;
12162 /* If non-nil, a timer started that hides the last tooltip when it
12165 Lisp_Object tip_timer
;
12168 /* Create a frame for a tooltip on the display described by DPYINFO.
12169 PARMS is a list of frame parameters. Value is the frame. */
12172 x_create_tip_frame (dpyinfo
, parms
)
12173 struct w32_display_info
*dpyinfo
;
12176 #if 0 /* TODO : w32 version */
12178 Lisp_Object frame
, tem
;
12180 long window_prompting
= 0;
12182 int count
= specpdl_ptr
- specpdl
;
12183 struct gcpro gcpro1
, gcpro2
, gcpro3
;
12188 /* Use this general default value to start with until we know if
12189 this frame has a specified name. */
12190 Vx_resource_name
= Vinvocation_name
;
12192 #ifdef MULTI_KBOARD
12193 kb
= dpyinfo
->kboard
;
12195 kb
= &the_only_kboard
;
12198 /* Get the name of the frame to use for resource lookup. */
12199 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
12200 if (!STRINGP (name
)
12201 && !EQ (name
, Qunbound
)
12203 error ("Invalid frame name--not a string or nil");
12204 Vx_resource_name
= name
;
12207 GCPRO3 (parms
, name
, frame
);
12208 tip_frame
= f
= make_frame (1);
12209 XSETFRAME (frame
, f
);
12210 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
12212 f
->output_method
= output_w32
;
12213 f
->output_data
.w32
=
12214 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
12215 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
12217 f
->output_data
.w32
->icon_bitmap
= -1;
12219 f
->output_data
.w32
->fontset
= -1;
12220 f
->icon_name
= Qnil
;
12222 #ifdef MULTI_KBOARD
12223 FRAME_KBOARD (f
) = kb
;
12225 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12226 f
->output_data
.w32
->explicit_parent
= 0;
12228 /* Set the name; the functions to which we pass f expect the name to
12230 if (EQ (name
, Qunbound
) || NILP (name
))
12232 f
->name
= build_string (dpyinfo
->x_id_name
);
12233 f
->explicit_name
= 0;
12238 f
->explicit_name
= 1;
12239 /* use the frame's title when getting resources for this frame. */
12240 specbind (Qx_resource_name
, name
);
12243 /* Extract the window parameters from the supplied values
12244 that are needed to determine window geometry. */
12248 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
12251 /* First, try whatever font the caller has specified. */
12252 if (STRINGP (font
))
12254 tem
= Fquery_fontset (font
, Qnil
);
12256 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
12258 font
= x_new_font (f
, XSTRING (font
)->data
);
12261 /* Try out a font which we hope has bold and italic variations. */
12262 if (!STRINGP (font
))
12263 font
= x_new_font (f
, "-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
12264 if (!STRINGP (font
))
12265 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12266 if (! STRINGP (font
))
12267 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12268 if (! STRINGP (font
))
12269 /* This was formerly the first thing tried, but it finds too many fonts
12270 and takes too long. */
12271 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
12272 /* If those didn't work, look for something which will at least work. */
12273 if (! STRINGP (font
))
12274 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
12276 if (! STRINGP (font
))
12277 font
= build_string ("fixed");
12279 x_default_parameter (f
, parms
, Qfont
, font
,
12280 "font", "Font", RES_TYPE_STRING
);
12283 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
12284 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
12286 /* This defaults to 2 in order to match xterm. We recognize either
12287 internalBorderWidth or internalBorder (which is what xterm calls
12289 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12293 value
= w32_get_arg (parms
, Qinternal_border_width
,
12294 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
12295 if (! EQ (value
, Qunbound
))
12296 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
12300 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
12301 "internalBorderWidth", "internalBorderWidth",
12304 /* Also do the stuff which must be set before the window exists. */
12305 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
12306 "foreground", "Foreground", RES_TYPE_STRING
);
12307 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
12308 "background", "Background", RES_TYPE_STRING
);
12309 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
12310 "pointerColor", "Foreground", RES_TYPE_STRING
);
12311 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
12312 "cursorColor", "Foreground", RES_TYPE_STRING
);
12313 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
12314 "borderColor", "BorderColor", RES_TYPE_STRING
);
12316 /* Init faces before x_default_parameter is called for scroll-bar
12317 parameters because that function calls x_set_scroll_bar_width,
12318 which calls change_frame_size, which calls Fset_window_buffer,
12319 which runs hooks, which call Fvertical_motion. At the end, we
12320 end up in init_iterator with a null face cache, which should not
12322 init_frame_faces (f
);
12324 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12325 window_prompting
= x_figure_window_size (f
, parms
);
12327 if (window_prompting
& XNegative
)
12329 if (window_prompting
& YNegative
)
12330 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
12332 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
12336 if (window_prompting
& YNegative
)
12337 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
12339 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
12342 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
12344 XSetWindowAttributes attrs
;
12345 unsigned long mask
;
12348 mask
= CWBackPixel
| CWOverrideRedirect
| CWSaveUnder
| CWEventMask
;
12349 /* Window managers looks at the override-redirect flag to
12350 determine whether or net to give windows a decoration (Xlib
12352 attrs
.override_redirect
= True
;
12353 attrs
.save_under
= True
;
12354 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
12355 /* Arrange for getting MapNotify and UnmapNotify events. */
12356 attrs
.event_mask
= StructureNotifyMask
;
12358 = FRAME_W32_WINDOW (f
)
12359 = XCreateWindow (FRAME_W32_DISPLAY (f
),
12360 FRAME_W32_DISPLAY_INFO (f
)->root_window
,
12361 /* x, y, width, height */
12365 CopyFromParent
, InputOutput
, CopyFromParent
,
12372 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
12373 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12374 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
12375 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12376 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
12377 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
12379 /* Dimensions, especially f->height, must be done via change_frame_size.
12380 Change will not be effected unless different from the current
12383 height
= f
->height
;
12385 SET_FRAME_WIDTH (f
, 0);
12386 change_frame_size (f
, height
, width
, 1, 0, 0);
12392 /* It is now ok to make the frame official even if we get an error
12393 below. And the frame needs to be on Vframe_list or making it
12394 visible won't work. */
12395 Vframe_list
= Fcons (frame
, Vframe_list
);
12397 /* Now that the frame is official, it counts as a reference to
12399 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
12401 return unbind_to (count
, frame
);
12406 #ifdef TODO /* Tooltip support not complete. */
12407 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
12408 "Show STRING in a \"tooltip\" window on frame FRAME.\n\
12409 A tooltip window is a small X window displaying a string.\n\
12411 FRAME nil or omitted means use the selected frame.\n\
12413 PARMS is an optional list of frame parameters which can be\n\
12414 used to change the tooltip's appearance.\n\
12416 Automatically hide the tooltip after TIMEOUT seconds.\n\
12417 TIMEOUT nil means use the default timeout of 5 seconds.\n\
12419 If the list of frame parameters PARAMS contains a `left' parameters,\n\
12420 the tooltip is displayed at that x-position. Otherwise it is\n\
12421 displayed at the mouse position, with offset DX added (default is 5 if\n\
12422 DX isn't specified). Likewise for the y-position; if a `top' frame\n\
12423 parameter is specified, it determines the y-position of the tooltip\n\
12424 window, otherwise it is displayed at the mouse position, with offset\n\
12425 DY added (default is -5).")
12426 (string
, frame
, parms
, timeout
, dx
, dy
)
12427 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
12431 Window root
, child
;
12432 Lisp_Object buffer
, top
, left
;
12433 struct buffer
*old_buffer
;
12434 struct text_pos pos
;
12435 int i
, width
, height
;
12436 int root_x
, root_y
, win_x
, win_y
;
12438 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
12439 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
12440 int count
= specpdl_ptr
- specpdl
;
12442 specbind (Qinhibit_redisplay
, Qt
);
12444 GCPRO4 (string
, parms
, frame
, timeout
);
12446 CHECK_STRING (string
, 0);
12447 f
= check_x_frame (frame
);
12448 if (NILP (timeout
))
12449 timeout
= make_number (5);
12451 CHECK_NATNUM (timeout
, 2);
12454 dx
= make_number (5);
12456 CHECK_NUMBER (dx
, 5);
12459 dy
= make_number (-5);
12461 CHECK_NUMBER (dy
, 6);
12463 /* Hide a previous tip, if any. */
12466 /* Add default values to frame parameters. */
12467 if (NILP (Fassq (Qname
, parms
)))
12468 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
12469 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12470 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
12471 if (NILP (Fassq (Qborder_width
, parms
)))
12472 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
12473 if (NILP (Fassq (Qborder_color
, parms
)))
12474 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
12475 if (NILP (Fassq (Qbackground_color
, parms
)))
12476 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
12479 /* Create a frame for the tooltip, and record it in the global
12480 variable tip_frame. */
12481 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
);
12482 tip_frame
= f
= XFRAME (frame
);
12484 /* Set up the frame's root window. Currently we use a size of 80
12485 columns x 40 lines. If someone wants to show a larger tip, he
12486 will loose. I don't think this is a realistic case. */
12487 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
12488 w
->left
= w
->top
= make_number (0);
12492 w
->pseudo_window_p
= 1;
12494 /* Display the tooltip text in a temporary buffer. */
12495 buffer
= Fget_buffer_create (build_string (" *tip*"));
12496 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
12497 old_buffer
= current_buffer
;
12498 set_buffer_internal_1 (XBUFFER (buffer
));
12500 Finsert (make_number (1), &string
);
12501 clear_glyph_matrix (w
->desired_matrix
);
12502 clear_glyph_matrix (w
->current_matrix
);
12503 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
12504 try_window (FRAME_ROOT_WINDOW (f
), pos
);
12506 /* Compute width and height of the tooltip. */
12507 width
= height
= 0;
12508 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
12510 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
12511 struct glyph
*last
;
12514 /* Stop at the first empty row at the end. */
12515 if (!row
->enabled_p
|| !row
->displays_text_p
)
12518 /* Let the row go over the full width of the frame. */
12519 row
->full_width_p
= 1;
12521 /* There's a glyph at the end of rows that is use to place
12522 the cursor there. Don't include the width of this glyph. */
12523 if (row
->used
[TEXT_AREA
])
12525 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
12526 row_width
= row
->pixel_width
- last
->pixel_width
;
12529 row_width
= row
->pixel_width
;
12531 height
+= row
->height
;
12532 width
= max (width
, row_width
);
12535 /* Add the frame's internal border to the width and height the X
12536 window should have. */
12537 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12538 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12540 /* User-specified position? */
12541 left
= Fcdr (Fassq (Qleft
, parms
));
12542 top
= Fcdr (Fassq (Qtop
, parms
));
12544 /* Move the tooltip window where the mouse pointer is. Resize and
12546 #if 0 /* TODO : W32 specifics */
12548 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
12549 &root
, &child
, &root_x
, &root_y
, &win_x
, &win_y
, &pmask
);
12552 root_x
+= XINT (dx
);
12553 root_y
+= XINT (dy
);
12555 if (INTEGERP (left
))
12556 root_x
= XINT (left
);
12557 if (INTEGERP (top
))
12558 root_y
= XINT (top
);
12561 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12562 root_x
, root_y
- height
, width
, height
);
12563 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12567 /* Draw into the window. */
12568 w
->must_be_updated_p
= 1;
12569 update_single_window (w
, 1);
12571 /* Restore original current buffer. */
12572 set_buffer_internal_1 (old_buffer
);
12573 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
12575 /* Let the tip disappear after timeout seconds. */
12576 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
12577 intern ("x-hide-tip"));
12580 return unbind_to (count
, Qnil
);
12584 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
12585 "Hide the current tooltip window, if there is any.\n\
12586 Value is t is tooltip was open, nil otherwise.")
12589 int count
= specpdl_ptr
- specpdl
;
12592 specbind (Qinhibit_redisplay
, Qt
);
12594 if (!NILP (tip_timer
))
12596 call1 (intern ("cancel-timer"), tip_timer
);
12604 XSETFRAME (frame
, tip_frame
);
12605 Fdelete_frame (frame
, Qt
);
12610 return unbind_to (count
, deleted_p
? Qt
: Qnil
);
12616 /***********************************************************************
12617 File selection dialog
12618 ***********************************************************************/
12620 extern Lisp_Object Qfile_name_history
;
12622 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
12623 "Read file name, prompting with PROMPT in directory DIR.\n\
12624 Use a file selection dialog.\n\
12625 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
12626 specified. Don't let the user enter a file name in the file\n\
12627 selection dialog's entry field, if MUSTMATCH is non-nil.")
12628 (prompt
, dir
, default_filename
, mustmatch
)
12629 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
12631 struct frame
*f
= SELECTED_FRAME ();
12632 Lisp_Object file
= Qnil
;
12633 int count
= specpdl_ptr
- specpdl
;
12634 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
12635 char filename
[MAX_PATH
+ 1];
12636 char init_dir
[MAX_PATH
+ 1];
12637 int use_dialog_p
= 1;
12639 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
12640 CHECK_STRING (prompt
, 0);
12641 CHECK_STRING (dir
, 1);
12643 /* Create the dialog with PROMPT as title, using DIR as initial
12644 directory and using "*" as pattern. */
12645 dir
= Fexpand_file_name (dir
, Qnil
);
12646 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
12647 init_dir
[MAX_PATH
] = '\0';
12648 unixtodos_filename (init_dir
);
12650 if (STRINGP (default_filename
))
12652 char *file_name_only
;
12653 char *full_path_name
= XSTRING (default_filename
)->data
;
12655 unixtodos_filename (full_path_name
);
12657 file_name_only
= strrchr (full_path_name
, '\\');
12658 if (!file_name_only
)
12659 file_name_only
= full_path_name
;
12664 /* If default_file_name is a directory, don't use the open
12665 file dialog, as it does not support selecting
12667 if (!(*file_name_only
))
12671 strncpy (filename
, file_name_only
, MAX_PATH
);
12672 filename
[MAX_PATH
] = '\0';
12675 filename
[0] = '\0';
12679 OPENFILENAME file_details
;
12680 char *filename_file
;
12682 /* Prevent redisplay. */
12683 specbind (Qinhibit_redisplay
, Qt
);
12686 bzero (&file_details
, sizeof (file_details
));
12687 file_details
.lStructSize
= sizeof (file_details
);
12688 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
12689 file_details
.lpstrFile
= filename
;
12690 file_details
.nMaxFile
= sizeof (filename
);
12691 file_details
.lpstrInitialDir
= init_dir
;
12692 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
12693 file_details
.Flags
= OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
;
12695 if (!NILP (mustmatch
))
12696 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
12698 if (GetOpenFileName (&file_details
))
12700 dostounix_filename (filename
);
12701 file
= build_string (filename
);
12707 file
= unbind_to (count
, file
);
12709 /* Open File dialog will not allow folders to be selected, so resort
12710 to minibuffer completing reads for directories. */
12712 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
12713 dir
, mustmatch
, dir
, Qfile_name_history
,
12714 default_filename
, Qnil
);
12718 /* Make "Cancel" equivalent to C-g. */
12720 Fsignal (Qquit
, Qnil
);
12722 return unbind_to (count
, file
);
12727 /***********************************************************************
12729 ***********************************************************************/
12733 DEFUN ("imagep", Fimagep
, Simagep
, 1, 1, 0,
12734 "Value is non-nil if SPEC is a valid image specification.")
12738 return valid_image_p (spec
) ? Qt
: Qnil
;
12742 DEFUN ("lookup-image", Flookup_image
, Slookup_image
, 1, 1, 0, "")
12748 if (valid_image_p (spec
))
12749 id
= lookup_image (SELECTED_FRAME (), spec
);
12751 debug_print (spec
);
12752 return make_number (id
);
12755 #endif /* GLYPH_DEBUG != 0 */
12759 /***********************************************************************
12760 w32 specialized functions
12761 ***********************************************************************/
12763 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 1, 0,
12764 "This will display the W32 font dialog and return an X font string corresponding to the selection.")
12768 FRAME_PTR f
= check_x_frame (frame
);
12776 bzero (&cf
, sizeof (cf
));
12777 bzero (&lf
, sizeof (lf
));
12779 cf
.lStructSize
= sizeof (cf
);
12780 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
12781 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
;
12782 cf
.lpLogFont
= &lf
;
12784 /* Initialize as much of the font details as we can from the current
12786 hdc
= GetDC (FRAME_W32_WINDOW (f
));
12787 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
12788 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
12789 if (GetTextMetrics (hdc
, &tm
))
12791 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
12792 lf
.lfWeight
= tm
.tmWeight
;
12793 lf
.lfItalic
= tm
.tmItalic
;
12794 lf
.lfUnderline
= tm
.tmUnderlined
;
12795 lf
.lfStrikeOut
= tm
.tmStruckOut
;
12796 lf
.lfCharSet
= tm
.tmCharSet
;
12797 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
12799 SelectObject (hdc
, oldobj
);
12800 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
12802 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
12805 return build_string (buf
);
12808 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
, Sw32_send_sys_command
, 1, 2, 0,
12809 "Send frame a Windows WM_SYSCOMMAND message of type COMMAND.\n\
12810 Some useful values for command are 0xf030 to maximise frame (0xf020\n\
12811 to minimize), 0xf120 to restore frame to original size, and 0xf100\n\
12812 to activate the menubar for keyboard access. 0xf140 activates the\n\
12813 screen saver if defined.\n\
12815 If optional parameter FRAME is not specified, use selected frame.")
12817 Lisp_Object command
, frame
;
12820 FRAME_PTR f
= check_x_frame (frame
);
12822 CHECK_NUMBER (command
, 0);
12824 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
12829 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
12830 "Get Windows to perform OPERATION on DOCUMENT.\n\
12831 This is a wrapper around the ShellExecute system function, which\n\
12832 invokes the application registered to handle OPERATION for DOCUMENT.\n\
12833 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be\n\
12834 nil for the default action), and DOCUMENT is typically the name of a\n\
12835 document file or URL, but can also be a program executable to run or\n\
12836 a directory to open in the Windows Explorer.\n\
12838 If DOCUMENT is a program executable, PARAMETERS can be a string\n\
12839 containing command line parameters, but otherwise should be nil.\n\
12841 SHOW-FLAG can be used to control whether the invoked application is hidden\n\
12842 or minimized. If SHOW-FLAG is nil, the application is displayed normally,\n\
12843 otherwise it is an integer representing a ShowWindow flag:\n\
12845 0 - start hidden\n\
12846 1 - start normally\n\
12847 3 - start maximized\n\
12848 6 - start minimized")
12849 (operation
, document
, parameters
, show_flag
)
12850 Lisp_Object operation
, document
, parameters
, show_flag
;
12852 Lisp_Object current_dir
;
12854 CHECK_STRING (document
, 0);
12856 /* Encode filename and current directory. */
12857 current_dir
= ENCODE_FILE (current_buffer
->directory
);
12858 document
= ENCODE_FILE (document
);
12859 if ((int) ShellExecute (NULL
,
12860 (STRINGP (operation
) ?
12861 XSTRING (operation
)->data
: NULL
),
12862 XSTRING (document
)->data
,
12863 (STRINGP (parameters
) ?
12864 XSTRING (parameters
)->data
: NULL
),
12865 XSTRING (current_dir
)->data
,
12866 (INTEGERP (show_flag
) ?
12867 XINT (show_flag
) : SW_SHOWDEFAULT
))
12870 error ("ShellExecute failed");
12873 /* Lookup virtual keycode from string representing the name of a
12874 non-ascii keystroke into the corresponding virtual key, using
12875 lispy_function_keys. */
12877 lookup_vk_code (char *key
)
12881 for (i
= 0; i
< 256; i
++)
12882 if (lispy_function_keys
[i
] != 0
12883 && strcmp (lispy_function_keys
[i
], key
) == 0)
12889 /* Convert a one-element vector style key sequence to a hot key
12892 w32_parse_hot_key (key
)
12895 /* Copied from Fdefine_key and store_in_keymap. */
12896 register Lisp_Object c
;
12898 int lisp_modifiers
;
12900 struct gcpro gcpro1
;
12902 CHECK_VECTOR (key
, 0);
12904 if (XFASTINT (Flength (key
)) != 1)
12909 c
= Faref (key
, make_number (0));
12911 if (CONSP (c
) && lucid_event_type_list_p (c
))
12912 c
= Fevent_convert_list (c
);
12916 if (! INTEGERP (c
) && ! SYMBOLP (c
))
12917 error ("Key definition is invalid");
12919 /* Work out the base key and the modifiers. */
12922 c
= parse_modifiers (c
);
12923 lisp_modifiers
= Fcar (Fcdr (c
));
12927 vk_code
= lookup_vk_code (XSYMBOL (c
)->name
->data
);
12929 else if (INTEGERP (c
))
12931 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
12932 /* Many ascii characters are their own virtual key code. */
12933 vk_code
= XINT (c
) & CHARACTERBITS
;
12936 if (vk_code
< 0 || vk_code
> 255)
12939 if ((lisp_modifiers
& meta_modifier
) != 0
12940 && !NILP (Vw32_alt_is_meta
))
12941 lisp_modifiers
|= alt_modifier
;
12943 /* Supply defs missing from mingw32. */
12945 #define MOD_ALT 0x0001
12946 #define MOD_CONTROL 0x0002
12947 #define MOD_SHIFT 0x0004
12948 #define MOD_WIN 0x0008
12951 /* Convert lisp modifiers to Windows hot-key form. */
12952 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
12953 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
12954 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
12955 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
12957 return HOTKEY (vk_code
, w32_modifiers
);
12960 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
, Sw32_register_hot_key
, 1, 1, 0,
12961 "Register KEY as a hot-key combination.\n\
12962 Certain key combinations like Alt-Tab are reserved for system use on\n\
12963 Windows, and therefore are normally intercepted by the system. However,\n\
12964 most of these key combinations can be received by registering them as\n\
12965 hot-keys, overriding their special meaning.\n\
12967 KEY must be a one element key definition in vector form that would be\n\
12968 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta\n\
12969 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper\n\
12970 is always interpreted as the Windows modifier keys.\n\
12972 The return value is the hotkey-id if registered, otherwise nil.")
12976 key
= w32_parse_hot_key (key
);
12978 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
12980 /* Reuse an empty slot if possible. */
12981 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
12983 /* Safe to add new key to list, even if we have focus. */
12985 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
12989 /* Notify input thread about new hot-key definition, so that it
12990 takes effect without needing to switch focus. */
12991 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
12998 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
, Sw32_unregister_hot_key
, 1, 1, 0,
12999 "Unregister HOTKEY as a hot-key combination.")
13005 if (!INTEGERP (key
))
13006 key
= w32_parse_hot_key (key
);
13008 item
= Fmemq (key
, w32_grabbed_keys
);
13012 /* Notify input thread about hot-key definition being removed, so
13013 that it takes effect without needing focus switch. */
13014 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
13015 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
13018 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13025 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
, Sw32_registered_hot_keys
, 0, 0, 0,
13026 "Return list of registered hot-key IDs.")
13029 return Fcopy_sequence (w32_grabbed_keys
);
13032 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
, Sw32_reconstruct_hot_key
, 1, 1, 0,
13033 "Convert hot-key ID to a lisp key combination.")
13035 Lisp_Object hotkeyid
;
13037 int vk_code
, w32_modifiers
;
13040 CHECK_NUMBER (hotkeyid
, 0);
13042 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
13043 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
13045 if (lispy_function_keys
[vk_code
])
13046 key
= intern (lispy_function_keys
[vk_code
]);
13048 key
= make_number (vk_code
);
13050 key
= Fcons (key
, Qnil
);
13051 if (w32_modifiers
& MOD_SHIFT
)
13052 key
= Fcons (Qshift
, key
);
13053 if (w32_modifiers
& MOD_CONTROL
)
13054 key
= Fcons (Qctrl
, key
);
13055 if (w32_modifiers
& MOD_ALT
)
13056 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
13057 if (w32_modifiers
& MOD_WIN
)
13058 key
= Fcons (Qhyper
, key
);
13063 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
, Sw32_toggle_lock_key
, 1, 2, 0,
13064 "Toggle the state of the lock key KEY.\n\
13065 KEY can be `capslock', `kp-numlock', or `scroll'.\n\
13066 If the optional parameter NEW-STATE is a number, then the state of KEY\n\
13067 is set to off if the low bit of NEW-STATE is zero, otherwise on.")
13069 Lisp_Object key
, new_state
;
13074 if (EQ (key
, intern ("capslock")))
13075 vk_code
= VK_CAPITAL
;
13076 else if (EQ (key
, intern ("kp-numlock")))
13077 vk_code
= VK_NUMLOCK
;
13078 else if (EQ (key
, intern ("scroll")))
13079 vk_code
= VK_SCROLL
;
13083 if (!dwWindowsThreadId
)
13084 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
13086 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
13087 (WPARAM
) vk_code
, (LPARAM
) new_state
))
13090 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13091 return make_number (msg
.wParam
);
13098 /* This is zero if not using MS-Windows. */
13101 /* The section below is built by the lisp expression at the top of the file,
13102 just above where these variables are declared. */
13103 /*&&& init symbols here &&&*/
13104 Qauto_raise
= intern ("auto-raise");
13105 staticpro (&Qauto_raise
);
13106 Qauto_lower
= intern ("auto-lower");
13107 staticpro (&Qauto_lower
);
13108 Qbar
= intern ("bar");
13110 Qborder_color
= intern ("border-color");
13111 staticpro (&Qborder_color
);
13112 Qborder_width
= intern ("border-width");
13113 staticpro (&Qborder_width
);
13114 Qbox
= intern ("box");
13116 Qcursor_color
= intern ("cursor-color");
13117 staticpro (&Qcursor_color
);
13118 Qcursor_type
= intern ("cursor-type");
13119 staticpro (&Qcursor_type
);
13120 Qgeometry
= intern ("geometry");
13121 staticpro (&Qgeometry
);
13122 Qicon_left
= intern ("icon-left");
13123 staticpro (&Qicon_left
);
13124 Qicon_top
= intern ("icon-top");
13125 staticpro (&Qicon_top
);
13126 Qicon_type
= intern ("icon-type");
13127 staticpro (&Qicon_type
);
13128 Qicon_name
= intern ("icon-name");
13129 staticpro (&Qicon_name
);
13130 Qinternal_border_width
= intern ("internal-border-width");
13131 staticpro (&Qinternal_border_width
);
13132 Qleft
= intern ("left");
13133 staticpro (&Qleft
);
13134 Qright
= intern ("right");
13135 staticpro (&Qright
);
13136 Qmouse_color
= intern ("mouse-color");
13137 staticpro (&Qmouse_color
);
13138 Qnone
= intern ("none");
13139 staticpro (&Qnone
);
13140 Qparent_id
= intern ("parent-id");
13141 staticpro (&Qparent_id
);
13142 Qscroll_bar_width
= intern ("scroll-bar-width");
13143 staticpro (&Qscroll_bar_width
);
13144 Qsuppress_icon
= intern ("suppress-icon");
13145 staticpro (&Qsuppress_icon
);
13146 Qundefined_color
= intern ("undefined-color");
13147 staticpro (&Qundefined_color
);
13148 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
13149 staticpro (&Qvertical_scroll_bars
);
13150 Qvisibility
= intern ("visibility");
13151 staticpro (&Qvisibility
);
13152 Qwindow_id
= intern ("window-id");
13153 staticpro (&Qwindow_id
);
13154 Qx_frame_parameter
= intern ("x-frame-parameter");
13155 staticpro (&Qx_frame_parameter
);
13156 Qx_resource_name
= intern ("x-resource-name");
13157 staticpro (&Qx_resource_name
);
13158 Quser_position
= intern ("user-position");
13159 staticpro (&Quser_position
);
13160 Quser_size
= intern ("user-size");
13161 staticpro (&Quser_size
);
13162 Qscreen_gamma
= intern ("screen-gamma");
13163 staticpro (&Qscreen_gamma
);
13164 Qline_spacing
= intern ("line-spacing");
13165 staticpro (&Qline_spacing
);
13166 Qcenter
= intern ("center");
13167 staticpro (&Qcenter
);
13168 /* This is the end of symbol initialization. */
13170 Qhyper
= intern ("hyper");
13171 staticpro (&Qhyper
);
13172 Qsuper
= intern ("super");
13173 staticpro (&Qsuper
);
13174 Qmeta
= intern ("meta");
13175 staticpro (&Qmeta
);
13176 Qalt
= intern ("alt");
13178 Qctrl
= intern ("ctrl");
13179 staticpro (&Qctrl
);
13180 Qcontrol
= intern ("control");
13181 staticpro (&Qcontrol
);
13182 Qshift
= intern ("shift");
13183 staticpro (&Qshift
);
13185 /* Text property `display' should be nonsticky by default. */
13186 Vtext_property_default_nonsticky
13187 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
13190 Qlaplace
= intern ("laplace");
13191 staticpro (&Qlaplace
);
13193 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
13194 staticpro (&Qface_set_after_frame_default
);
13196 Fput (Qundefined_color
, Qerror_conditions
,
13197 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
13198 Fput (Qundefined_color
, Qerror_message
,
13199 build_string ("Undefined color"));
13201 staticpro (&w32_grabbed_keys
);
13202 w32_grabbed_keys
= Qnil
;
13204 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
13205 "An array of color name mappings for windows.");
13206 Vw32_color_map
= Qnil
;
13208 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
13209 "Non-nil if alt key presses are passed on to Windows.\n\
13210 When non-nil, for example, alt pressed and released and then space will\n\
13211 open the System menu. When nil, Emacs silently swallows alt key events.");
13212 Vw32_pass_alt_to_system
= Qnil
;
13214 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
13215 "Non-nil if the alt key is to be considered the same as the meta key.\n\
13216 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta.");
13217 Vw32_alt_is_meta
= Qt
;
13219 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
13220 "If non-zero, the virtual key code for an alternative quit key.");
13221 XSETINT (Vw32_quit_key
, 0);
13223 DEFVAR_LISP ("w32-pass-lwindow-to-system",
13224 &Vw32_pass_lwindow_to_system
,
13225 "Non-nil if the left \"Windows\" key is passed on to Windows.\n\
13226 When non-nil, the Start menu is opened by tapping the key.");
13227 Vw32_pass_lwindow_to_system
= Qt
;
13229 DEFVAR_LISP ("w32-pass-rwindow-to-system",
13230 &Vw32_pass_rwindow_to_system
,
13231 "Non-nil if the right \"Windows\" key is passed on to Windows.\n\
13232 When non-nil, the Start menu is opened by tapping the key.");
13233 Vw32_pass_rwindow_to_system
= Qt
;
13235 DEFVAR_INT ("w32-phantom-key-code",
13236 &Vw32_phantom_key_code
,
13237 "Virtual key code used to generate \"phantom\" key presses.\n\
13238 Value is a number between 0 and 255.\n\
13240 Phantom key presses are generated in order to stop the system from\n\
13241 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or\n\
13242 `w32-pass-rwindow-to-system' is nil.");
13243 /* Although 255 is technically not a valid key code, it works and
13244 means that this hack won't interfere with any real key code. */
13245 Vw32_phantom_key_code
= 255;
13247 DEFVAR_LISP ("w32-enable-num-lock",
13248 &Vw32_enable_num_lock
,
13249 "Non-nil if Num Lock should act normally.\n\
13250 Set to nil to see Num Lock as the key `kp-numlock'.");
13251 Vw32_enable_num_lock
= Qt
;
13253 DEFVAR_LISP ("w32-enable-caps-lock",
13254 &Vw32_enable_caps_lock
,
13255 "Non-nil if Caps Lock should act normally.\n\
13256 Set to nil to see Caps Lock as the key `capslock'.");
13257 Vw32_enable_caps_lock
= Qt
;
13259 DEFVAR_LISP ("w32-scroll-lock-modifier",
13260 &Vw32_scroll_lock_modifier
,
13261 "Modifier to use for the Scroll Lock on state.\n\
13262 The value can be hyper, super, meta, alt, control or shift for the\n\
13263 respective modifier, or nil to see Scroll Lock as the key `scroll'.\n\
13264 Any other value will cause the key to be ignored.");
13265 Vw32_scroll_lock_modifier
= Qt
;
13267 DEFVAR_LISP ("w32-lwindow-modifier",
13268 &Vw32_lwindow_modifier
,
13269 "Modifier to use for the left \"Windows\" key.\n\
13270 The value can be hyper, super, meta, alt, control or shift for the\n\
13271 respective modifier, or nil to appear as the key `lwindow'.\n\
13272 Any other value will cause the key to be ignored.");
13273 Vw32_lwindow_modifier
= Qnil
;
13275 DEFVAR_LISP ("w32-rwindow-modifier",
13276 &Vw32_rwindow_modifier
,
13277 "Modifier to use for the right \"Windows\" key.\n\
13278 The value can be hyper, super, meta, alt, control or shift for the\n\
13279 respective modifier, or nil to appear as the key `rwindow'.\n\
13280 Any other value will cause the key to be ignored.");
13281 Vw32_rwindow_modifier
= Qnil
;
13283 DEFVAR_LISP ("w32-apps-modifier",
13284 &Vw32_apps_modifier
,
13285 "Modifier to use for the \"Apps\" key.\n\
13286 The value can be hyper, super, meta, alt, control or shift for the\n\
13287 respective modifier, or nil to appear as the key `apps'.\n\
13288 Any other value will cause the key to be ignored.");
13289 Vw32_apps_modifier
= Qnil
;
13291 DEFVAR_LISP ("w32-enable-synthesized-fonts", &Vw32_enable_synthesized_fonts
,
13292 "Non-nil enables selection of artificially italicized and bold fonts.");
13293 Vw32_enable_synthesized_fonts
= Qnil
;
13295 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
13296 "Non-nil enables Windows palette management to map colors exactly.");
13297 Vw32_enable_palette
= Qt
;
13299 DEFVAR_INT ("w32-mouse-button-tolerance",
13300 &Vw32_mouse_button_tolerance
,
13301 "Analogue of double click interval for faking middle mouse events.\n\
13302 The value is the minimum time in milliseconds that must elapse between\n\
13303 left/right button down events before they are considered distinct events.\n\
13304 If both mouse buttons are depressed within this interval, a middle mouse\n\
13305 button down event is generated instead.");
13306 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
13308 DEFVAR_INT ("w32-mouse-move-interval",
13309 &Vw32_mouse_move_interval
,
13310 "Minimum interval between mouse move events.\n\
13311 The value is the minimum time in milliseconds that must elapse between\n\
13312 successive mouse move (or scroll bar drag) events before they are\n\
13313 reported as lisp events.");
13314 XSETINT (Vw32_mouse_move_interval
, 0);
13316 init_x_parm_symbols ();
13318 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
13319 "List of directories to search for bitmap files for w32.");
13320 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
13322 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
13323 "The shape of the pointer when over text.\n\
13324 Changing the value does not affect existing frames\n\
13325 unless you set the mouse color.");
13326 Vx_pointer_shape
= Qnil
;
13328 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
13329 "The name Emacs uses to look up resources; for internal use only.\n\
13330 `x-get-resource' uses this as the first component of the instance name\n\
13331 when requesting resource values.\n\
13332 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
13333 was invoked, or to the value specified with the `-name' or `-rn'\n\
13334 switches, if present.");
13335 Vx_resource_name
= Qnil
;
13337 Vx_nontext_pointer_shape
= Qnil
;
13339 Vx_mode_pointer_shape
= Qnil
;
13341 DEFVAR_LISP ("x-busy-pointer-shape", &Vx_busy_pointer_shape
,
13342 "The shape of the pointer when Emacs is busy.\n\
13343 This variable takes effect when you create a new frame\n\
13344 or when you set the mouse color.");
13345 Vx_busy_pointer_shape
= Qnil
;
13347 DEFVAR_BOOL ("display-busy-cursor", &display_busy_cursor_p
,
13348 "Non-zero means Emacs displays a busy cursor on window systems.");
13349 display_busy_cursor_p
= 1;
13351 DEFVAR_LISP ("busy-cursor-delay", &Vbusy_cursor_delay
,
13352 "*Seconds to wait before displaying a busy-cursor.\n\
13353 Value must be an integer or float.");
13354 Vbusy_cursor_delay
= make_number (DEFAULT_BUSY_CURSOR_DELAY
);
13356 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
13357 &Vx_sensitive_text_pointer_shape
,
13358 "The shape of the pointer when over mouse-sensitive text.\n\
13359 This variable takes effect when you create a new frame\n\
13360 or when you set the mouse color.");
13361 Vx_sensitive_text_pointer_shape
= Qnil
;
13363 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
13364 "A string indicating the foreground color of the cursor box.");
13365 Vx_cursor_fore_pixel
= Qnil
;
13367 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
13368 "Non-nil if no window manager is in use.\n\
13369 Emacs doesn't try to figure this out; this is always nil\n\
13370 unless you set it to something else.");
13371 /* We don't have any way to find this out, so set it to nil
13372 and maybe the user would like to set it to t. */
13373 Vx_no_window_manager
= Qnil
;
13375 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
13376 &Vx_pixel_size_width_font_regexp
,
13377 "Regexp matching a font name whose width is the same as `PIXEL_SIZE'.\n\
13379 Since Emacs gets width of a font matching with this regexp from\n\
13380 PIXEL_SIZE field of the name, font finding mechanism gets faster for\n\
13381 such a font. This is especially effective for such large fonts as\n\
13382 Chinese, Japanese, and Korean.");
13383 Vx_pixel_size_width_font_regexp
= Qnil
;
13385 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
13386 "Time after which cached images are removed from the cache.\n\
13387 When an image has not been displayed this many seconds, remove it\n\
13388 from the image cache. Value must be an integer or nil with nil\n\
13389 meaning don't clear the cache.");
13390 Vimage_cache_eviction_delay
= make_number (30 * 60);
13392 DEFVAR_LISP ("w32-bdf-filename-alist",
13393 &Vw32_bdf_filename_alist
,
13394 "List of bdf fonts and their corresponding filenames.");
13395 Vw32_bdf_filename_alist
= Qnil
;
13397 DEFVAR_BOOL ("w32-strict-fontnames",
13398 &w32_strict_fontnames
,
13399 "Non-nil means only use fonts that are exact matches for those requested.\n\
13400 Default is nil, which allows old fontnames that are not XLFD compliant,\n\
13401 and allows third-party CJK display to work by specifying false charset\n\
13402 fields to trick Emacs into translating to Big5, SJIS etc.\n\
13403 Setting this to t will prevent wrong fonts being selected when\n\
13404 fontsets are automatically created.");
13405 w32_strict_fontnames
= 0;
13407 DEFVAR_BOOL ("w32-strict-painting",
13408 &w32_strict_painting
,
13409 "Non-nil means use strict rules for repainting frames.\n\
13410 Set this to nil to get the old behaviour for repainting; this should\n\
13411 only be necessary if the default setting causes problems.");
13412 w32_strict_painting
= 1;
13414 DEFVAR_LISP ("w32-system-coding-system",
13415 &Vw32_system_coding_system
,
13416 "Coding system used by Windows system functions, such as for font names.");
13417 Vw32_system_coding_system
= Qnil
;
13419 DEFVAR_LISP ("w32-charset-info-alist",
13420 &Vw32_charset_info_alist
,
13421 "Alist linking Emacs character sets to Windows fonts\n\
13422 and codepages. Each entry should be of the form:\n\
13424 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))\n\
13426 where CHARSET_NAME is a string used in font names to identify the charset,\n\
13427 WINDOWS_CHARSET is a symbol that can be one of:\n\
13428 w32-charset-ansi, w32-charset-default, w32-charset-symbol,\n\
13429 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,\n\
13430 w32-charset-chinesebig5, "
13431 #ifdef JOHAB_CHARSET
13432 "w32-charset-johab, w32-charset-hebrew,\n\
13433 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,\n\
13434 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,\n\
13435 w32-charset-russian, w32-charset-mac, w32-charset-baltic,\n"
13437 #ifdef UNICODE_CHARSET
13438 "w32-charset-unicode, "
13440 "or w32-charset-oem.\n\
13441 CODEPAGE should be an integer specifying the codepage that should be used\n\
13442 to display the character set, t to do no translation and output as Unicode,\n\
13443 or nil to do no translation and output as 8 bit (or multibyte on far-east\n\
13444 versions of Windows) characters.");
13445 Vw32_charset_info_alist
= Qnil
;
13447 staticpro (&Qw32_charset_ansi
);
13448 Qw32_charset_ansi
= intern ("w32-charset-ansi");
13449 staticpro (&Qw32_charset_symbol
);
13450 Qw32_charset_symbol
= intern ("w32-charset-symbol");
13451 staticpro (&Qw32_charset_shiftjis
);
13452 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
13453 staticpro (&Qw32_charset_hangeul
);
13454 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
13455 staticpro (&Qw32_charset_chinesebig5
);
13456 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
13457 staticpro (&Qw32_charset_gb2312
);
13458 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
13459 staticpro (&Qw32_charset_oem
);
13460 Qw32_charset_oem
= intern ("w32-charset-oem");
13462 #ifdef JOHAB_CHARSET
13464 static int w32_extra_charsets_defined
= 1;
13465 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
, "");
13467 staticpro (&Qw32_charset_johab
);
13468 Qw32_charset_johab
= intern ("w32-charset-johab");
13469 staticpro (&Qw32_charset_easteurope
);
13470 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
13471 staticpro (&Qw32_charset_turkish
);
13472 Qw32_charset_turkish
= intern ("w32-charset-turkish");
13473 staticpro (&Qw32_charset_baltic
);
13474 Qw32_charset_baltic
= intern ("w32-charset-baltic");
13475 staticpro (&Qw32_charset_russian
);
13476 Qw32_charset_russian
= intern ("w32-charset-russian");
13477 staticpro (&Qw32_charset_arabic
);
13478 Qw32_charset_arabic
= intern ("w32-charset-arabic");
13479 staticpro (&Qw32_charset_greek
);
13480 Qw32_charset_greek
= intern ("w32-charset-greek");
13481 staticpro (&Qw32_charset_hebrew
);
13482 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
13483 staticpro (&Qw32_charset_vietnamese
);
13484 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
13485 staticpro (&Qw32_charset_thai
);
13486 Qw32_charset_thai
= intern ("w32-charset-thai");
13487 staticpro (&Qw32_charset_mac
);
13488 Qw32_charset_mac
= intern ("w32-charset-mac");
13492 #ifdef UNICODE_CHARSET
13494 static int w32_unicode_charset_defined
= 1;
13495 DEFVAR_BOOL ("w32-unicode-charset-defined",
13496 &w32_unicode_charset_defined
, "");
13498 staticpro (&Qw32_charset_unicode
);
13499 Qw32_charset_unicode
= intern ("w32-charset-unicode");
13502 defsubr (&Sx_get_resource
);
13503 #if 0 /* TODO: Port to W32 */
13504 defsubr (&Sx_change_window_property
);
13505 defsubr (&Sx_delete_window_property
);
13506 defsubr (&Sx_window_property
);
13508 defsubr (&Sxw_display_color_p
);
13509 defsubr (&Sx_display_grayscale_p
);
13510 defsubr (&Sxw_color_defined_p
);
13511 defsubr (&Sxw_color_values
);
13512 defsubr (&Sx_server_max_request_size
);
13513 defsubr (&Sx_server_vendor
);
13514 defsubr (&Sx_server_version
);
13515 defsubr (&Sx_display_pixel_width
);
13516 defsubr (&Sx_display_pixel_height
);
13517 defsubr (&Sx_display_mm_width
);
13518 defsubr (&Sx_display_mm_height
);
13519 defsubr (&Sx_display_screens
);
13520 defsubr (&Sx_display_planes
);
13521 defsubr (&Sx_display_color_cells
);
13522 defsubr (&Sx_display_visual_class
);
13523 defsubr (&Sx_display_backing_store
);
13524 defsubr (&Sx_display_save_under
);
13525 defsubr (&Sx_parse_geometry
);
13526 defsubr (&Sx_create_frame
);
13527 defsubr (&Sx_open_connection
);
13528 defsubr (&Sx_close_connection
);
13529 defsubr (&Sx_display_list
);
13530 defsubr (&Sx_synchronize
);
13532 /* W32 specific functions */
13534 defsubr (&Sw32_focus_frame
);
13535 defsubr (&Sw32_select_font
);
13536 defsubr (&Sw32_define_rgb_color
);
13537 defsubr (&Sw32_default_color_map
);
13538 defsubr (&Sw32_load_color_file
);
13539 defsubr (&Sw32_send_sys_command
);
13540 defsubr (&Sw32_shell_execute
);
13541 defsubr (&Sw32_register_hot_key
);
13542 defsubr (&Sw32_unregister_hot_key
);
13543 defsubr (&Sw32_registered_hot_keys
);
13544 defsubr (&Sw32_reconstruct_hot_key
);
13545 defsubr (&Sw32_toggle_lock_key
);
13546 defsubr (&Sw32_find_bdf_fonts
);
13548 /* Setting callback functions for fontset handler. */
13549 get_font_info_func
= w32_get_font_info
;
13551 #if 0 /* This function pointer doesn't seem to be used anywhere.
13552 And the pointer assigned has the wrong type, anyway. */
13553 list_fonts_func
= w32_list_fonts
;
13556 load_font_func
= w32_load_font
;
13557 find_ccl_program_func
= w32_find_ccl_program
;
13558 query_font_func
= w32_query_font
;
13559 set_frame_fontset_func
= x_set_font
;
13560 check_window_system_func
= check_w32
;
13562 #if 0 /* TODO Image support for W32 */
13564 Qxbm
= intern ("xbm");
13566 QCtype
= intern (":type");
13567 staticpro (&QCtype
);
13568 QCalgorithm
= intern (":algorithm");
13569 staticpro (&QCalgorithm
);
13570 QCheuristic_mask
= intern (":heuristic-mask");
13571 staticpro (&QCheuristic_mask
);
13572 QCcolor_symbols
= intern (":color-symbols");
13573 staticpro (&QCcolor_symbols
);
13574 QCascent
= intern (":ascent");
13575 staticpro (&QCascent
);
13576 QCmargin
= intern (":margin");
13577 staticpro (&QCmargin
);
13578 QCrelief
= intern (":relief");
13579 staticpro (&QCrelief
);
13580 Qpostscript
= intern ("postscript");
13581 staticpro (&Qpostscript
);
13582 QCloader
= intern (":loader");
13583 staticpro (&QCloader
);
13584 QCbounding_box
= intern (":bounding-box");
13585 staticpro (&QCbounding_box
);
13586 QCpt_width
= intern (":pt-width");
13587 staticpro (&QCpt_width
);
13588 QCpt_height
= intern (":pt-height");
13589 staticpro (&QCpt_height
);
13590 QCindex
= intern (":index");
13591 staticpro (&QCindex
);
13592 Qpbm
= intern ("pbm");
13596 Qxpm
= intern ("xpm");
13601 Qjpeg
= intern ("jpeg");
13602 staticpro (&Qjpeg
);
13606 Qtiff
= intern ("tiff");
13607 staticpro (&Qtiff
);
13611 Qgif
= intern ("gif");
13616 Qpng
= intern ("png");
13620 defsubr (&Sclear_image_cache
);
13623 defsubr (&Simagep
);
13624 defsubr (&Slookup_image
);
13628 busy_cursor_atimer
= NULL
;
13629 busy_cursor_shown_p
= 0;
13630 #ifdef TODO /* Tooltip support not complete. */
13631 defsubr (&Sx_show_tip
);
13632 defsubr (&Sx_hide_tip
);
13634 staticpro (&tip_timer
);
13637 defsubr (&Sx_file_dialog
);
13644 image_types
= NULL
;
13645 Vimage_types
= Qnil
;
13647 #if 0 /* TODO : Image support for W32 */
13648 define_image_type (&xbm_type
);
13649 define_image_type (&gs_type
);
13650 define_image_type (&pbm_type
);
13653 define_image_type (&xpm_type
);
13657 define_image_type (&jpeg_type
);
13661 define_image_type (&tiff_type
);
13665 define_image_type (&gif_type
);
13669 define_image_type (&png_type
);
13680 button
= MessageBox (NULL
,
13681 "A fatal error has occurred!\n\n"
13682 "Select Abort to exit, Retry to debug, Ignore to continue",
13683 "Emacs Abort Dialog",
13684 MB_ICONEXCLAMATION
| MB_TASKMODAL
13685 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
13700 /* For convenience when debugging. */
13704 return GetLastError ();