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
;
2023 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
2027 if (!EQ (Qnil
, arg
))
2028 f
->output_data
.w32
->mouse_pixel
2029 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2030 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
2032 /* Don't let pointers be invisible. */
2033 if (mask_color
== f
->output_data
.w32
->mouse_pixel
2034 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
2035 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
2037 #if 0 /* TODO : cursor changes */
2040 /* It's not okay to crash if the user selects a screwy cursor. */
2041 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
2043 if (!EQ (Qnil
, Vx_pointer_shape
))
2045 CHECK_NUMBER (Vx_pointer_shape
, 0);
2046 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
2049 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2050 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
2052 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
2054 CHECK_NUMBER (Vx_nontext_pointer_shape
, 0);
2055 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2056 XINT (Vx_nontext_pointer_shape
));
2059 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
2060 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2062 if (!EQ (Qnil
, Vx_busy_pointer_shape
))
2064 CHECK_NUMBER (Vx_busy_pointer_shape
, 0);
2065 busy_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2066 XINT (Vx_busy_pointer_shape
));
2069 busy_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
2070 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
2072 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2073 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
2075 CHECK_NUMBER (Vx_mode_pointer_shape
, 0);
2076 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2077 XINT (Vx_mode_pointer_shape
));
2080 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2081 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
2083 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
2085 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
, 0);
2087 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2088 XINT (Vx_sensitive_text_pointer_shape
));
2091 cross_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
2093 /* Check and report errors with the above calls. */
2094 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
2095 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
2098 XColor fore_color
, back_color
;
2100 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
2101 back_color
.pixel
= mask_color
;
2102 XQueryColor (FRAME_W32_DISPLAY (f
),
2103 DefaultColormap (FRAME_W32_DISPLAY (f
),
2104 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2106 XQueryColor (FRAME_W32_DISPLAY (f
),
2107 DefaultColormap (FRAME_W32_DISPLAY (f
),
2108 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2110 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
2111 &fore_color
, &back_color
);
2112 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
2113 &fore_color
, &back_color
);
2114 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
2115 &fore_color
, &back_color
);
2116 XRecolorCursor (FRAME_W32_DISPLAY (f
), cross_cursor
,
2117 &fore_color
, &back_color
);
2118 XRecolorCursor (FRAME_W32_DISPLAY (f
), busy_cursor
,
2119 &fore_color
, &back_color
);
2122 if (FRAME_W32_WINDOW (f
) != 0)
2123 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
2125 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
2126 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
2127 f
->output_data
.w32
->text_cursor
= cursor
;
2129 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
2130 && f
->output_data
.w32
->nontext_cursor
!= 0)
2131 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
2132 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
2134 if (busy_cursor
!= f
->output_data
.w32
->busy_cursor
2135 && f
->output_data
.w32
->busy_cursor
!= 0)
2136 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->busy_cursor
);
2137 f
->output_data
.w32
->busy_cursor
= busy_cursor
;
2139 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
2140 && f
->output_data
.w32
->modeline_cursor
!= 0)
2141 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
2142 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
2144 if (cross_cursor
!= f
->output_data
.w32
->cross_cursor
2145 && f
->output_data
.w32
->cross_cursor
!= 0)
2146 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->cross_cursor
);
2147 f
->output_data
.w32
->cross_cursor
= cross_cursor
;
2149 XFlush (FRAME_W32_DISPLAY (f
));
2152 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
2157 x_set_cursor_color (f
, arg
, oldval
)
2159 Lisp_Object arg
, oldval
;
2161 unsigned long fore_pixel
;
2163 if (!NILP (Vx_cursor_fore_pixel
))
2164 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
2165 WHITE_PIX_DEFAULT (f
));
2167 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2168 f
->output_data
.w32
->cursor_pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2170 /* Make sure that the cursor color differs from the background color. */
2171 if (f
->output_data
.w32
->cursor_pixel
== FRAME_BACKGROUND_PIXEL (f
))
2173 f
->output_data
.w32
->cursor_pixel
= f
->output_data
.w32
->mouse_pixel
;
2174 if (f
->output_data
.w32
->cursor_pixel
== fore_pixel
)
2175 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2177 FRAME_FOREGROUND_PIXEL (f
) = fore_pixel
;
2179 if (FRAME_W32_WINDOW (f
) != 0)
2181 if (FRAME_VISIBLE_P (f
))
2183 x_display_cursor (f
, 0);
2184 x_display_cursor (f
, 1);
2188 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
2191 /* Set the border-color of frame F to pixel value PIX.
2192 Note that this does not fully take effect if done before
2195 x_set_border_pixel (f
, pix
)
2199 f
->output_data
.w32
->border_pixel
= pix
;
2201 if (FRAME_W32_WINDOW (f
) != 0 && f
->output_data
.w32
->border_width
> 0)
2203 if (FRAME_VISIBLE_P (f
))
2208 /* Set the border-color of frame F to value described by ARG.
2209 ARG can be a string naming a color.
2210 The border-color is used for the border that is drawn by the server.
2211 Note that this does not fully take effect if done before
2212 F has a window; it must be redone when the window is created. */
2215 x_set_border_color (f
, arg
, oldval
)
2217 Lisp_Object arg
, oldval
;
2221 CHECK_STRING (arg
, 0);
2222 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2223 x_set_border_pixel (f
, pix
);
2224 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
2227 /* Value is the internal representation of the specified cursor type
2228 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
2229 of the bar cursor. */
2231 enum text_cursor_kinds
2232 x_specified_cursor_type (arg
, width
)
2236 enum text_cursor_kinds type
;
2243 else if (CONSP (arg
)
2244 && EQ (XCAR (arg
), Qbar
)
2245 && INTEGERP (XCDR (arg
))
2246 && XINT (XCDR (arg
)) >= 0)
2249 *width
= XINT (XCDR (arg
));
2251 else if (NILP (arg
))
2254 /* Treat anything unknown as "box cursor".
2255 It was bad to signal an error; people have trouble fixing
2256 .Xdefaults with Emacs, when it has something bad in it. */
2257 type
= FILLED_BOX_CURSOR
;
2263 x_set_cursor_type (f
, arg
, oldval
)
2265 Lisp_Object arg
, oldval
;
2269 FRAME_DESIRED_CURSOR (f
) = x_specified_cursor_type (arg
, &width
);
2270 f
->output_data
.w32
->cursor_width
= width
;
2272 /* Make sure the cursor gets redrawn. This is overkill, but how
2273 often do people change cursor types? */
2274 update_mode_lines
++;
2278 x_set_icon_type (f
, arg
, oldval
)
2280 Lisp_Object arg
, oldval
;
2284 if (NILP (arg
) && NILP (oldval
))
2287 if (STRINGP (arg
) && STRINGP (oldval
)
2288 && EQ (Fstring_equal (oldval
, arg
), Qt
))
2291 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
2296 result
= x_bitmap_icon (f
, arg
);
2300 error ("No icon window available");
2306 /* Return non-nil if frame F wants a bitmap icon. */
2314 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
2322 x_set_icon_name (f
, arg
, oldval
)
2324 Lisp_Object arg
, oldval
;
2330 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
2333 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
2339 if (f
->output_data
.w32
->icon_bitmap
!= 0)
2344 result
= x_text_icon (f
,
2345 (char *) XSTRING ((!NILP (f
->icon_name
)
2354 error ("No icon window available");
2357 /* If the window was unmapped (and its icon was mapped),
2358 the new icon is not mapped, so map the window in its stead. */
2359 if (FRAME_VISIBLE_P (f
))
2361 #ifdef USE_X_TOOLKIT
2362 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
2364 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
2367 XFlush (FRAME_W32_DISPLAY (f
));
2372 extern Lisp_Object
x_new_font ();
2373 extern Lisp_Object
x_new_fontset();
2376 x_set_font (f
, arg
, oldval
)
2378 Lisp_Object arg
, oldval
;
2381 Lisp_Object fontset_name
;
2384 CHECK_STRING (arg
, 1);
2386 fontset_name
= Fquery_fontset (arg
, Qnil
);
2389 result
= (STRINGP (fontset_name
)
2390 ? x_new_fontset (f
, XSTRING (fontset_name
)->data
)
2391 : x_new_font (f
, XSTRING (arg
)->data
));
2394 if (EQ (result
, Qnil
))
2395 error ("Font `%s' is not defined", XSTRING (arg
)->data
);
2396 else if (EQ (result
, Qt
))
2397 error ("The characters of the given font have varying widths");
2398 else if (STRINGP (result
))
2400 store_frame_param (f
, Qfont
, result
);
2401 recompute_basic_faces (f
);
2406 do_pending_window_change (0);
2408 /* Don't call `face-set-after-frame-default' when faces haven't been
2409 initialized yet. This is the case when called from
2410 Fx_create_frame. In that case, the X widget or window doesn't
2411 exist either, and we can end up in x_report_frame_params with a
2412 null widget which gives a segfault. */
2413 if (FRAME_FACE_CACHE (f
))
2415 XSETFRAME (frame
, f
);
2416 call1 (Qface_set_after_frame_default
, frame
);
2421 x_set_border_width (f
, arg
, oldval
)
2423 Lisp_Object arg
, oldval
;
2425 CHECK_NUMBER (arg
, 0);
2427 if (XINT (arg
) == f
->output_data
.w32
->border_width
)
2430 if (FRAME_W32_WINDOW (f
) != 0)
2431 error ("Cannot change the border width of a window");
2433 f
->output_data
.w32
->border_width
= XINT (arg
);
2437 x_set_internal_border_width (f
, arg
, oldval
)
2439 Lisp_Object arg
, oldval
;
2441 int old
= f
->output_data
.w32
->internal_border_width
;
2443 CHECK_NUMBER (arg
, 0);
2444 f
->output_data
.w32
->internal_border_width
= XINT (arg
);
2445 if (f
->output_data
.w32
->internal_border_width
< 0)
2446 f
->output_data
.w32
->internal_border_width
= 0;
2448 if (f
->output_data
.w32
->internal_border_width
== old
)
2451 if (FRAME_W32_WINDOW (f
) != 0)
2453 x_set_window_size (f
, 0, f
->width
, f
->height
);
2454 SET_FRAME_GARBAGED (f
);
2455 do_pending_window_change (0);
2460 x_set_visibility (f
, value
, oldval
)
2462 Lisp_Object value
, oldval
;
2465 XSETFRAME (frame
, f
);
2468 Fmake_frame_invisible (frame
, Qt
);
2469 else if (EQ (value
, Qicon
))
2470 Ficonify_frame (frame
);
2472 Fmake_frame_visible (frame
);
2476 /* Change window heights in windows rooted in WINDOW by N lines. */
2479 x_change_window_heights (window
, n
)
2483 struct window
*w
= XWINDOW (window
);
2485 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
2486 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
2488 if (INTEGERP (w
->orig_top
))
2489 XSETFASTINT (w
->orig_top
, XFASTINT (w
->orig_top
) + n
);
2490 if (INTEGERP (w
->orig_height
))
2491 XSETFASTINT (w
->orig_height
, XFASTINT (w
->orig_height
) - n
);
2493 /* Handle just the top child in a vertical split. */
2494 if (!NILP (w
->vchild
))
2495 x_change_window_heights (w
->vchild
, n
);
2497 /* Adjust all children in a horizontal split. */
2498 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2500 w
= XWINDOW (window
);
2501 x_change_window_heights (window
, n
);
2506 x_set_menu_bar_lines (f
, value
, oldval
)
2508 Lisp_Object value
, oldval
;
2511 int olines
= FRAME_MENU_BAR_LINES (f
);
2513 /* Right now, menu bars don't work properly in minibuf-only frames;
2514 most of the commands try to apply themselves to the minibuffer
2515 frame itself, and get an error because you can't switch buffers
2516 in or split the minibuffer window. */
2517 if (FRAME_MINIBUF_ONLY_P (f
))
2520 if (INTEGERP (value
))
2521 nlines
= XINT (value
);
2525 FRAME_MENU_BAR_LINES (f
) = 0;
2527 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2530 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2531 free_frame_menubar (f
);
2532 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2534 /* Adjust the frame size so that the client (text) dimensions
2535 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
2537 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2538 do_pending_window_change (0);
2544 /* Set the number of lines used for the tool bar of frame F to VALUE.
2545 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2546 is the old number of tool bar lines. This function changes the
2547 height of all windows on frame F to match the new tool bar height.
2548 The frame's height doesn't change. */
2551 x_set_tool_bar_lines (f
, value
, oldval
)
2553 Lisp_Object value
, oldval
;
2555 int delta
, nlines
, root_height
;
2556 Lisp_Object root_window
;
2558 /* Use VALUE only if an integer >= 0. */
2559 if (INTEGERP (value
) && XINT (value
) >= 0)
2560 nlines
= XFASTINT (value
);
2564 /* Make sure we redisplay all windows in this frame. */
2565 ++windows_or_buffers_changed
;
2567 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2569 /* Don't resize the tool-bar to more than we have room for. */
2570 root_window
= FRAME_ROOT_WINDOW (f
);
2571 root_height
= XINT (XWINDOW (root_window
)->height
);
2572 if (root_height
- delta
< 1)
2574 delta
= root_height
- 1;
2575 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
2578 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2579 x_change_window_heights (root_window
, delta
);
2582 /* We also have to make sure that the internal border at the top of
2583 the frame, below the menu bar or tool bar, is redrawn when the
2584 tool bar disappears. This is so because the internal border is
2585 below the tool bar if one is displayed, but is below the menu bar
2586 if there isn't a tool bar. The tool bar draws into the area
2587 below the menu bar. */
2588 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
2592 clear_current_matrices (f
);
2593 updating_frame
= NULL
;
2596 /* If the tool bar gets smaller, the internal border below it
2597 has to be cleared. It was formerly part of the display
2598 of the larger tool bar, and updating windows won't clear it. */
2601 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2602 int width
= PIXEL_WIDTH (f
);
2603 int y
= nlines
* CANON_Y_UNIT (f
);
2607 HDC hdc
= get_frame_dc (f
);
2608 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
2609 release_frame_dc (f
, hdc
);
2616 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2619 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2620 name; if NAME is a string, set F's name to NAME and set
2621 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2623 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2624 suggesting a new name, which lisp code should override; if
2625 F->explicit_name is set, ignore the new name; otherwise, set it. */
2628 x_set_name (f
, name
, explicit)
2633 /* Make sure that requests from lisp code override requests from
2634 Emacs redisplay code. */
2637 /* If we're switching from explicit to implicit, we had better
2638 update the mode lines and thereby update the title. */
2639 if (f
->explicit_name
&& NILP (name
))
2640 update_mode_lines
= 1;
2642 f
->explicit_name
= ! NILP (name
);
2644 else if (f
->explicit_name
)
2647 /* If NAME is nil, set the name to the w32_id_name. */
2650 /* Check for no change needed in this very common case
2651 before we do any consing. */
2652 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
2653 XSTRING (f
->name
)->data
))
2655 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
2658 CHECK_STRING (name
, 0);
2660 /* Don't change the name if it's already NAME. */
2661 if (! NILP (Fstring_equal (name
, f
->name
)))
2666 /* For setting the frame title, the title parameter should override
2667 the name parameter. */
2668 if (! NILP (f
->title
))
2671 if (FRAME_W32_WINDOW (f
))
2673 if (STRING_MULTIBYTE (name
))
2674 name
= ENCODE_SYSTEM (name
);
2677 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2682 /* This function should be called when the user's lisp code has
2683 specified a name for the frame; the name will override any set by the
2686 x_explicitly_set_name (f
, arg
, oldval
)
2688 Lisp_Object arg
, oldval
;
2690 x_set_name (f
, arg
, 1);
2693 /* This function should be called by Emacs redisplay code to set the
2694 name; names set this way will never override names set by the user's
2697 x_implicitly_set_name (f
, arg
, oldval
)
2699 Lisp_Object arg
, oldval
;
2701 x_set_name (f
, arg
, 0);
2704 /* Change the title of frame F to NAME.
2705 If NAME is nil, use the frame name as the title.
2707 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2708 name; if NAME is a string, set F's name to NAME and set
2709 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2711 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2712 suggesting a new name, which lisp code should override; if
2713 F->explicit_name is set, ignore the new name; otherwise, set it. */
2716 x_set_title (f
, name
, old_name
)
2718 Lisp_Object name
, old_name
;
2720 /* Don't change the title if it's already NAME. */
2721 if (EQ (name
, f
->title
))
2724 update_mode_lines
= 1;
2731 if (FRAME_W32_WINDOW (f
))
2733 if (STRING_MULTIBYTE (name
))
2734 name
= ENCODE_SYSTEM (name
);
2737 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2743 x_set_autoraise (f
, arg
, oldval
)
2745 Lisp_Object arg
, oldval
;
2747 f
->auto_raise
= !EQ (Qnil
, arg
);
2751 x_set_autolower (f
, arg
, oldval
)
2753 Lisp_Object arg
, oldval
;
2755 f
->auto_lower
= !EQ (Qnil
, arg
);
2759 x_set_unsplittable (f
, arg
, oldval
)
2761 Lisp_Object arg
, oldval
;
2763 f
->no_split
= !NILP (arg
);
2767 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2769 Lisp_Object arg
, oldval
;
2771 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2772 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2773 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2774 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2776 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = NILP (arg
) ?
2777 vertical_scroll_bar_none
:
2778 /* Put scroll bars on the right by default, as is conventional
2781 ? vertical_scroll_bar_left
2782 : vertical_scroll_bar_right
;
2784 /* We set this parameter before creating the window for the
2785 frame, so we can get the geometry right from the start.
2786 However, if the window hasn't been created yet, we shouldn't
2787 call x_set_window_size. */
2788 if (FRAME_W32_WINDOW (f
))
2789 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2790 do_pending_window_change (0);
2795 x_set_scroll_bar_width (f
, arg
, oldval
)
2797 Lisp_Object arg
, oldval
;
2799 int wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
2803 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2804 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) +
2806 if (FRAME_W32_WINDOW (f
))
2807 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2808 do_pending_window_change (0);
2810 else if (INTEGERP (arg
) && XINT (arg
) > 0
2811 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2813 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2814 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2816 if (FRAME_W32_WINDOW (f
))
2817 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2818 do_pending_window_change (0);
2820 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2821 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2822 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2825 /* Subroutines of creating an frame. */
2827 /* Make sure that Vx_resource_name is set to a reasonable value.
2828 Fix it up, or set it to `emacs' if it is too hopeless. */
2831 validate_x_resource_name ()
2834 /* Number of valid characters in the resource name. */
2836 /* Number of invalid characters in the resource name. */
2841 if (STRINGP (Vx_resource_name
))
2843 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
2846 len
= STRING_BYTES (XSTRING (Vx_resource_name
));
2848 /* Only letters, digits, - and _ are valid in resource names.
2849 Count the valid characters and count the invalid ones. */
2850 for (i
= 0; i
< len
; i
++)
2853 if (! ((c
>= 'a' && c
<= 'z')
2854 || (c
>= 'A' && c
<= 'Z')
2855 || (c
>= '0' && c
<= '9')
2856 || c
== '-' || c
== '_'))
2863 /* Not a string => completely invalid. */
2864 bad_count
= 5, good_count
= 0;
2866 /* If name is valid already, return. */
2870 /* If name is entirely invalid, or nearly so, use `emacs'. */
2872 || (good_count
== 1 && bad_count
> 0))
2874 Vx_resource_name
= build_string ("emacs");
2878 /* Name is partly valid. Copy it and replace the invalid characters
2879 with underscores. */
2881 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
2883 for (i
= 0; i
< len
; i
++)
2885 int c
= XSTRING (new)->data
[i
];
2886 if (! ((c
>= 'a' && c
<= 'z')
2887 || (c
>= 'A' && c
<= 'Z')
2888 || (c
>= '0' && c
<= '9')
2889 || c
== '-' || c
== '_'))
2890 XSTRING (new)->data
[i
] = '_';
2895 extern char *x_get_string_resource ();
2897 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
2898 "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
2899 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
2900 class, where INSTANCE is the name under which Emacs was invoked, or\n\
2901 the name specified by the `-name' or `-rn' command-line arguments.\n\
2903 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
2904 class, respectively. You must specify both of them or neither.\n\
2905 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
2906 and the class is `Emacs.CLASS.SUBCLASS'.")
2907 (attribute
, class, component
, subclass
)
2908 Lisp_Object attribute
, class, component
, subclass
;
2910 register char *value
;
2914 CHECK_STRING (attribute
, 0);
2915 CHECK_STRING (class, 0);
2917 if (!NILP (component
))
2918 CHECK_STRING (component
, 1);
2919 if (!NILP (subclass
))
2920 CHECK_STRING (subclass
, 2);
2921 if (NILP (component
) != NILP (subclass
))
2922 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
2924 validate_x_resource_name ();
2926 /* Allocate space for the components, the dots which separate them,
2927 and the final '\0'. Make them big enough for the worst case. */
2928 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vx_resource_name
))
2929 + (STRINGP (component
)
2930 ? STRING_BYTES (XSTRING (component
)) : 0)
2931 + STRING_BYTES (XSTRING (attribute
))
2934 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2935 + STRING_BYTES (XSTRING (class))
2936 + (STRINGP (subclass
)
2937 ? STRING_BYTES (XSTRING (subclass
)) : 0)
2940 /* Start with emacs.FRAMENAME for the name (the specific one)
2941 and with `Emacs' for the class key (the general one). */
2942 strcpy (name_key
, XSTRING (Vx_resource_name
)->data
);
2943 strcpy (class_key
, EMACS_CLASS
);
2945 strcat (class_key
, ".");
2946 strcat (class_key
, XSTRING (class)->data
);
2948 if (!NILP (component
))
2950 strcat (class_key
, ".");
2951 strcat (class_key
, XSTRING (subclass
)->data
);
2953 strcat (name_key
, ".");
2954 strcat (name_key
, XSTRING (component
)->data
);
2957 strcat (name_key
, ".");
2958 strcat (name_key
, XSTRING (attribute
)->data
);
2960 value
= x_get_string_resource (Qnil
,
2961 name_key
, class_key
);
2963 if (value
!= (char *) 0)
2964 return build_string (value
);
2969 /* Used when C code wants a resource value. */
2972 x_get_resource_string (attribute
, class)
2973 char *attribute
, *class;
2977 struct frame
*sf
= SELECTED_FRAME ();
2979 /* Allocate space for the components, the dots which separate them,
2980 and the final '\0'. */
2981 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vinvocation_name
))
2982 + strlen (attribute
) + 2);
2983 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2984 + strlen (class) + 2);
2986 sprintf (name_key
, "%s.%s",
2987 XSTRING (Vinvocation_name
)->data
,
2989 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
2991 return x_get_string_resource (sf
, name_key
, class_key
);
2994 /* Types we might convert a resource string into. */
3004 /* Return the value of parameter PARAM.
3006 First search ALIST, then Vdefault_frame_alist, then the X defaults
3007 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3009 Convert the resource to the type specified by desired_type.
3011 If no default is specified, return Qunbound. If you call
3012 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
3013 and don't let it get stored in any Lisp-visible variables! */
3016 w32_get_arg (alist
, param
, attribute
, class, type
)
3017 Lisp_Object alist
, param
;
3020 enum resource_types type
;
3022 register Lisp_Object tem
;
3024 tem
= Fassq (param
, alist
);
3026 tem
= Fassq (param
, Vdefault_frame_alist
);
3032 tem
= Fx_get_resource (build_string (attribute
),
3033 build_string (class),
3041 case RES_TYPE_NUMBER
:
3042 return make_number (atoi (XSTRING (tem
)->data
));
3044 case RES_TYPE_FLOAT
:
3045 return make_float (atof (XSTRING (tem
)->data
));
3047 case RES_TYPE_BOOLEAN
:
3048 tem
= Fdowncase (tem
);
3049 if (!strcmp (XSTRING (tem
)->data
, "on")
3050 || !strcmp (XSTRING (tem
)->data
, "true"))
3055 case RES_TYPE_STRING
:
3058 case RES_TYPE_SYMBOL
:
3059 /* As a special case, we map the values `true' and `on'
3060 to Qt, and `false' and `off' to Qnil. */
3063 lower
= Fdowncase (tem
);
3064 if (!strcmp (XSTRING (lower
)->data
, "on")
3065 || !strcmp (XSTRING (lower
)->data
, "true"))
3067 else if (!strcmp (XSTRING (lower
)->data
, "off")
3068 || !strcmp (XSTRING (lower
)->data
, "false"))
3071 return Fintern (tem
, Qnil
);
3084 /* Record in frame F the specified or default value according to ALIST
3085 of the parameter named PROP (a Lisp symbol).
3086 If no value is specified for PROP, look for an X default for XPROP
3087 on the frame named NAME.
3088 If that is not found either, use the value DEFLT. */
3091 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3098 enum resource_types type
;
3102 tem
= w32_get_arg (alist
, prop
, xprop
, xclass
, type
);
3103 if (EQ (tem
, Qunbound
))
3105 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3109 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3110 "Parse an X-style geometry string STRING.\n\
3111 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
3112 The properties returned may include `top', `left', `height', and `width'.\n\
3113 The value of `left' or `top' may be an integer,\n\
3114 or a list (+ N) meaning N pixels relative to top/left corner,\n\
3115 or a list (- N) meaning -N pixels relative to bottom/right corner.")
3120 unsigned int width
, height
;
3123 CHECK_STRING (string
, 0);
3125 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
3126 &x
, &y
, &width
, &height
);
3129 if (geometry
& XValue
)
3131 Lisp_Object element
;
3133 if (x
>= 0 && (geometry
& XNegative
))
3134 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3135 else if (x
< 0 && ! (geometry
& XNegative
))
3136 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3138 element
= Fcons (Qleft
, make_number (x
));
3139 result
= Fcons (element
, result
);
3142 if (geometry
& YValue
)
3144 Lisp_Object element
;
3146 if (y
>= 0 && (geometry
& YNegative
))
3147 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3148 else if (y
< 0 && ! (geometry
& YNegative
))
3149 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3151 element
= Fcons (Qtop
, make_number (y
));
3152 result
= Fcons (element
, result
);
3155 if (geometry
& WidthValue
)
3156 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3157 if (geometry
& HeightValue
)
3158 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3163 /* Calculate the desired size and position of this window,
3164 and return the flags saying which aspects were specified.
3166 This function does not make the coordinates positive. */
3168 #define DEFAULT_ROWS 40
3169 #define DEFAULT_COLS 80
3172 x_figure_window_size (f
, parms
)
3176 register Lisp_Object tem0
, tem1
, tem2
;
3177 long window_prompting
= 0;
3179 /* Default values if we fall through.
3180 Actually, if that happens we should get
3181 window manager prompting. */
3182 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3183 f
->height
= DEFAULT_ROWS
;
3184 /* Window managers expect that if program-specified
3185 positions are not (0,0), they're intentional, not defaults. */
3186 f
->output_data
.w32
->top_pos
= 0;
3187 f
->output_data
.w32
->left_pos
= 0;
3189 tem0
= w32_get_arg (parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3190 tem1
= w32_get_arg (parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3191 tem2
= w32_get_arg (parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3192 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3194 if (!EQ (tem0
, Qunbound
))
3196 CHECK_NUMBER (tem0
, 0);
3197 f
->height
= XINT (tem0
);
3199 if (!EQ (tem1
, Qunbound
))
3201 CHECK_NUMBER (tem1
, 0);
3202 SET_FRAME_WIDTH (f
, XINT (tem1
));
3204 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3205 window_prompting
|= USSize
;
3207 window_prompting
|= PSize
;
3210 f
->output_data
.w32
->vertical_scroll_bar_extra
3211 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3213 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3214 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3215 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
3216 f
->output_data
.w32
->flags_areas_extra
3217 = FRAME_FLAGS_AREA_WIDTH (f
);
3218 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3219 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3221 tem0
= w32_get_arg (parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3222 tem1
= w32_get_arg (parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3223 tem2
= w32_get_arg (parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3224 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3226 if (EQ (tem0
, Qminus
))
3228 f
->output_data
.w32
->top_pos
= 0;
3229 window_prompting
|= YNegative
;
3231 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3232 && CONSP (XCDR (tem0
))
3233 && INTEGERP (XCAR (XCDR (tem0
))))
3235 f
->output_data
.w32
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3236 window_prompting
|= YNegative
;
3238 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3239 && CONSP (XCDR (tem0
))
3240 && INTEGERP (XCAR (XCDR (tem0
))))
3242 f
->output_data
.w32
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3244 else if (EQ (tem0
, Qunbound
))
3245 f
->output_data
.w32
->top_pos
= 0;
3248 CHECK_NUMBER (tem0
, 0);
3249 f
->output_data
.w32
->top_pos
= XINT (tem0
);
3250 if (f
->output_data
.w32
->top_pos
< 0)
3251 window_prompting
|= YNegative
;
3254 if (EQ (tem1
, Qminus
))
3256 f
->output_data
.w32
->left_pos
= 0;
3257 window_prompting
|= XNegative
;
3259 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3260 && CONSP (XCDR (tem1
))
3261 && INTEGERP (XCAR (XCDR (tem1
))))
3263 f
->output_data
.w32
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3264 window_prompting
|= XNegative
;
3266 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3267 && CONSP (XCDR (tem1
))
3268 && INTEGERP (XCAR (XCDR (tem1
))))
3270 f
->output_data
.w32
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3272 else if (EQ (tem1
, Qunbound
))
3273 f
->output_data
.w32
->left_pos
= 0;
3276 CHECK_NUMBER (tem1
, 0);
3277 f
->output_data
.w32
->left_pos
= XINT (tem1
);
3278 if (f
->output_data
.w32
->left_pos
< 0)
3279 window_prompting
|= XNegative
;
3282 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3283 window_prompting
|= USPosition
;
3285 window_prompting
|= PPosition
;
3288 return window_prompting
;
3293 extern LRESULT CALLBACK
w32_wnd_proc ();
3296 w32_init_class (hinst
)
3301 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3302 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
3304 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
3305 wc
.hInstance
= hinst
;
3306 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
3307 wc
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
3308 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
3309 wc
.lpszMenuName
= NULL
;
3310 wc
.lpszClassName
= EMACS_CLASS
;
3312 return (RegisterClass (&wc
));
3316 w32_createscrollbar (f
, bar
)
3318 struct scroll_bar
* bar
;
3320 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
3321 /* Position and size of scroll bar. */
3322 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3324 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3326 FRAME_W32_WINDOW (f
),
3333 w32_createwindow (f
)
3339 rect
.left
= rect
.top
= 0;
3340 rect
.right
= PIXEL_WIDTH (f
);
3341 rect
.bottom
= PIXEL_HEIGHT (f
);
3343 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3344 FRAME_EXTERNAL_MENU_BAR (f
));
3346 /* Do first time app init */
3350 w32_init_class (hinst
);
3353 FRAME_W32_WINDOW (f
) = hwnd
3354 = CreateWindow (EMACS_CLASS
,
3356 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
3357 f
->output_data
.w32
->left_pos
,
3358 f
->output_data
.w32
->top_pos
,
3359 rect
.right
- rect
.left
,
3360 rect
.bottom
- rect
.top
,
3368 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
3369 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
3370 SetWindowLong (hwnd
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
3371 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
3372 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3374 /* Enable drag-n-drop. */
3375 DragAcceptFiles (hwnd
, TRUE
);
3377 /* Do this to discard the default setting specified by our parent. */
3378 ShowWindow (hwnd
, SW_HIDE
);
3383 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
3390 wmsg
->msg
.hwnd
= hwnd
;
3391 wmsg
->msg
.message
= msg
;
3392 wmsg
->msg
.wParam
= wParam
;
3393 wmsg
->msg
.lParam
= lParam
;
3394 wmsg
->msg
.time
= GetMessageTime ();
3399 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
3400 between left and right keys as advertised. We test for this
3401 support dynamically, and set a flag when the support is absent. If
3402 absent, we keep track of the left and right control and alt keys
3403 ourselves. This is particularly necessary on keyboards that rely
3404 upon the AltGr key, which is represented as having the left control
3405 and right alt keys pressed. For these keyboards, we need to know
3406 when the left alt key has been pressed in addition to the AltGr key
3407 so that we can properly support M-AltGr-key sequences (such as M-@
3408 on Swedish keyboards). */
3410 #define EMACS_LCONTROL 0
3411 #define EMACS_RCONTROL 1
3412 #define EMACS_LMENU 2
3413 #define EMACS_RMENU 3
3415 static int modifiers
[4];
3416 static int modifiers_recorded
;
3417 static int modifier_key_support_tested
;
3420 test_modifier_support (unsigned int wparam
)
3424 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
3426 if (wparam
== VK_CONTROL
)
3436 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
3437 modifiers_recorded
= 1;
3439 modifiers_recorded
= 0;
3440 modifier_key_support_tested
= 1;
3444 record_keydown (unsigned int wparam
, unsigned int lparam
)
3448 if (!modifier_key_support_tested
)
3449 test_modifier_support (wparam
);
3451 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3454 if (wparam
== VK_CONTROL
)
3455 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3457 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3463 record_keyup (unsigned int wparam
, unsigned int lparam
)
3467 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3470 if (wparam
== VK_CONTROL
)
3471 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3473 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3478 /* Emacs can lose focus while a modifier key has been pressed. When
3479 it regains focus, be conservative and clear all modifiers since
3480 we cannot reconstruct the left and right modifier state. */
3486 if (GetFocus () == NULL
)
3487 /* Emacs doesn't have keyboard focus. Do nothing. */
3490 ctrl
= GetAsyncKeyState (VK_CONTROL
);
3491 alt
= GetAsyncKeyState (VK_MENU
);
3493 if (!(ctrl
& 0x08000))
3494 /* Clear any recorded control modifier state. */
3495 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3497 if (!(alt
& 0x08000))
3498 /* Clear any recorded alt modifier state. */
3499 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3501 /* Update the state of all modifier keys, because modifiers used in
3502 hot-key combinations can get stuck on if Emacs loses focus as a
3503 result of a hot-key being pressed. */
3507 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
3509 GetKeyboardState (keystate
);
3510 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
3511 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
3512 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
3513 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
3514 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
3515 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
3516 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
3517 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
3518 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
3519 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
3520 SetKeyboardState (keystate
);
3524 /* Synchronize modifier state with what is reported with the current
3525 keystroke. Even if we cannot distinguish between left and right
3526 modifier keys, we know that, if no modifiers are set, then neither
3527 the left or right modifier should be set. */
3531 if (!modifiers_recorded
)
3534 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
3535 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3537 if (!(GetKeyState (VK_MENU
) & 0x8000))
3538 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3542 modifier_set (int vkey
)
3544 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
3545 return (GetKeyState (vkey
) & 0x1);
3546 if (!modifiers_recorded
)
3547 return (GetKeyState (vkey
) & 0x8000);
3552 return modifiers
[EMACS_LCONTROL
];
3554 return modifiers
[EMACS_RCONTROL
];
3556 return modifiers
[EMACS_LMENU
];
3558 return modifiers
[EMACS_RMENU
];
3560 return (GetKeyState (vkey
) & 0x8000);
3563 /* Convert between the modifier bits W32 uses and the modifier bits
3567 w32_key_to_modifier (int key
)
3569 Lisp_Object key_mapping
;
3574 key_mapping
= Vw32_lwindow_modifier
;
3577 key_mapping
= Vw32_rwindow_modifier
;
3580 key_mapping
= Vw32_apps_modifier
;
3583 key_mapping
= Vw32_scroll_lock_modifier
;
3589 /* NB. This code runs in the input thread, asychronously to the lisp
3590 thread, so we must be careful to ensure access to lisp data is
3591 thread-safe. The following code is safe because the modifier
3592 variable values are updated atomically from lisp and symbols are
3593 not relocated by GC. Also, we don't have to worry about seeing GC
3595 if (EQ (key_mapping
, Qhyper
))
3596 return hyper_modifier
;
3597 if (EQ (key_mapping
, Qsuper
))
3598 return super_modifier
;
3599 if (EQ (key_mapping
, Qmeta
))
3600 return meta_modifier
;
3601 if (EQ (key_mapping
, Qalt
))
3602 return alt_modifier
;
3603 if (EQ (key_mapping
, Qctrl
))
3604 return ctrl_modifier
;
3605 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
3606 return ctrl_modifier
;
3607 if (EQ (key_mapping
, Qshift
))
3608 return shift_modifier
;
3610 /* Don't generate any modifier if not explicitly requested. */
3615 w32_get_modifiers ()
3617 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
3618 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
3619 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
3620 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
3621 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
3622 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
3623 (modifier_set (VK_MENU
) ?
3624 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
3627 /* We map the VK_* modifiers into console modifier constants
3628 so that we can use the same routines to handle both console
3629 and window input. */
3632 construct_console_modifiers ()
3637 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
3638 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
3639 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
3640 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
3641 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
3642 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
3643 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
3644 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
3645 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
3646 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
3647 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
3653 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
3657 /* Convert to emacs modifiers. */
3658 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
3664 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
3666 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
3669 if (virt_key
== VK_RETURN
)
3670 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
3672 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
3673 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
3675 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
3676 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
3678 if (virt_key
== VK_CLEAR
)
3679 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
3684 /* List of special key combinations which w32 would normally capture,
3685 but emacs should grab instead. Not directly visible to lisp, to
3686 simplify synchronization. Each item is an integer encoding a virtual
3687 key code and modifier combination to capture. */
3688 Lisp_Object w32_grabbed_keys
;
3690 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
3691 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
3692 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
3693 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
3695 /* Register hot-keys for reserved key combinations when Emacs has
3696 keyboard focus, since this is the only way Emacs can receive key
3697 combinations like Alt-Tab which are used by the system. */
3700 register_hot_keys (hwnd
)
3703 Lisp_Object keylist
;
3705 /* Use GC_CONSP, since we are called asynchronously. */
3706 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3708 Lisp_Object key
= XCAR (keylist
);
3710 /* Deleted entries get set to nil. */
3711 if (!INTEGERP (key
))
3714 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
3715 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
3720 unregister_hot_keys (hwnd
)
3723 Lisp_Object keylist
;
3725 /* Use GC_CONSP, since we are called asynchronously. */
3726 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3728 Lisp_Object key
= XCAR (keylist
);
3730 if (!INTEGERP (key
))
3733 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
3737 /* Main message dispatch loop. */
3740 w32_msg_pump (deferred_msg
* msg_buf
)
3746 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
3748 while (GetMessage (&msg
, NULL
, 0, 0))
3750 if (msg
.hwnd
== NULL
)
3752 switch (msg
.message
)
3755 /* Produced by complete_deferred_msg; just ignore. */
3757 case WM_EMACS_CREATEWINDOW
:
3758 w32_createwindow ((struct frame
*) msg
.wParam
);
3759 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3762 case WM_EMACS_SETLOCALE
:
3763 SetThreadLocale (msg
.wParam
);
3764 /* Reply is not expected. */
3766 case WM_EMACS_SETKEYBOARDLAYOUT
:
3767 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
3768 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3772 case WM_EMACS_REGISTER_HOT_KEY
:
3773 focus_window
= GetFocus ();
3774 if (focus_window
!= NULL
)
3775 RegisterHotKey (focus_window
,
3776 HOTKEY_ID (msg
.wParam
),
3777 HOTKEY_MODIFIERS (msg
.wParam
),
3778 HOTKEY_VK_CODE (msg
.wParam
));
3779 /* Reply is not expected. */
3781 case WM_EMACS_UNREGISTER_HOT_KEY
:
3782 focus_window
= GetFocus ();
3783 if (focus_window
!= NULL
)
3784 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
3785 /* Mark item as erased. NB: this code must be
3786 thread-safe. The next line is okay because the cons
3787 cell is never made into garbage and is not relocated by
3789 XCAR ((Lisp_Object
) msg
.lParam
) = Qnil
;
3790 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3793 case WM_EMACS_TOGGLE_LOCK_KEY
:
3795 int vk_code
= (int) msg
.wParam
;
3796 int cur_state
= (GetKeyState (vk_code
) & 1);
3797 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
3799 /* NB: This code must be thread-safe. It is safe to
3800 call NILP because symbols are not relocated by GC,
3801 and pointer here is not touched by GC (so the markbit
3802 can't be set). Numbers are safe because they are
3803 immediate values. */
3804 if (NILP (new_state
)
3805 || (NUMBERP (new_state
)
3806 && (XUINT (new_state
)) & 1 != cur_state
))
3808 one_w32_display_info
.faked_key
= vk_code
;
3810 keybd_event ((BYTE
) vk_code
,
3811 (BYTE
) MapVirtualKey (vk_code
, 0),
3812 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3813 keybd_event ((BYTE
) vk_code
,
3814 (BYTE
) MapVirtualKey (vk_code
, 0),
3815 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3816 keybd_event ((BYTE
) vk_code
,
3817 (BYTE
) MapVirtualKey (vk_code
, 0),
3818 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3819 cur_state
= !cur_state
;
3821 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3827 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
3832 DispatchMessage (&msg
);
3835 /* Exit nested loop when our deferred message has completed. */
3836 if (msg_buf
->completed
)
3841 deferred_msg
* deferred_msg_head
;
3843 static deferred_msg
*
3844 find_deferred_msg (HWND hwnd
, UINT msg
)
3846 deferred_msg
* item
;
3848 /* Don't actually need synchronization for read access, since
3849 modification of single pointer is always atomic. */
3850 /* enter_crit (); */
3852 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3853 if (item
->w32msg
.msg
.hwnd
== hwnd
3854 && item
->w32msg
.msg
.message
== msg
)
3857 /* leave_crit (); */
3863 send_deferred_msg (deferred_msg
* msg_buf
,
3869 /* Only input thread can send deferred messages. */
3870 if (GetCurrentThreadId () != dwWindowsThreadId
)
3873 /* It is an error to send a message that is already deferred. */
3874 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3877 /* Enforced synchronization is not needed because this is the only
3878 function that alters deferred_msg_head, and the following critical
3879 section is guaranteed to only be serially reentered (since only the
3880 input thread can call us). */
3882 /* enter_crit (); */
3884 msg_buf
->completed
= 0;
3885 msg_buf
->next
= deferred_msg_head
;
3886 deferred_msg_head
= msg_buf
;
3887 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
3889 /* leave_crit (); */
3891 /* Start a new nested message loop to process other messages until
3892 this one is completed. */
3893 w32_msg_pump (msg_buf
);
3895 deferred_msg_head
= msg_buf
->next
;
3897 return msg_buf
->result
;
3901 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
3903 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
3905 if (msg_buf
== NULL
)
3906 /* Message may have been cancelled, so don't abort(). */
3909 msg_buf
->result
= result
;
3910 msg_buf
->completed
= 1;
3912 /* Ensure input thread is woken so it notices the completion. */
3913 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3917 cancel_all_deferred_msgs ()
3919 deferred_msg
* item
;
3921 /* Don't actually need synchronization for read access, since
3922 modification of single pointer is always atomic. */
3923 /* enter_crit (); */
3925 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3928 item
->completed
= 1;
3931 /* leave_crit (); */
3933 /* Ensure input thread is woken so it notices the completion. */
3934 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3942 deferred_msg dummy_buf
;
3944 /* Ensure our message queue is created */
3946 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
3948 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3951 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
3952 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
3953 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
3955 /* This is the inital message loop which should only exit when the
3956 application quits. */
3957 w32_msg_pump (&dummy_buf
);
3963 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
3973 wmsg
.dwModifiers
= modifiers
;
3975 /* Detect quit_char and set quit-flag directly. Note that we
3976 still need to post a message to ensure the main thread will be
3977 woken up if blocked in sys_select(), but we do NOT want to post
3978 the quit_char message itself (because it will usually be as if
3979 the user had typed quit_char twice). Instead, we post a dummy
3980 message that has no particular effect. */
3983 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
3984 c
= make_ctrl_char (c
) & 0377;
3986 || (wmsg
.dwModifiers
== 0 &&
3987 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
3991 /* The choice of message is somewhat arbitrary, as long as
3992 the main thread handler just ignores it. */
3995 /* Interrupt any blocking system calls. */
3998 /* As a safety precaution, forcibly complete any deferred
3999 messages. This is a kludge, but I don't see any particularly
4000 clean way to handle the situation where a deferred message is
4001 "dropped" in the lisp thread, and will thus never be
4002 completed, eg. by the user trying to activate the menubar
4003 when the lisp thread is busy, and then typing C-g when the
4004 menubar doesn't open promptly (with the result that the
4005 menubar never responds at all because the deferred
4006 WM_INITMENU message is never completed). Another problem
4007 situation is when the lisp thread calls SendMessage (to send
4008 a window manager command) when a message has been deferred;
4009 the lisp thread gets blocked indefinitely waiting for the
4010 deferred message to be completed, which itself is waiting for
4011 the lisp thread to respond.
4013 Note that we don't want to block the input thread waiting for
4014 a reponse from the lisp thread (although that would at least
4015 solve the deadlock problem above), because we want to be able
4016 to receive C-g to interrupt the lisp thread. */
4017 cancel_all_deferred_msgs ();
4021 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4024 /* Main window procedure */
4027 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
4034 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4036 int windows_translate
;
4039 /* Note that it is okay to call x_window_to_frame, even though we are
4040 not running in the main lisp thread, because frame deletion
4041 requires the lisp thread to synchronize with this thread. Thus, if
4042 a frame struct is returned, it can be used without concern that the
4043 lisp thread might make it disappear while we are using it.
4045 NB. Walking the frame list in this thread is safe (as long as
4046 writes of Lisp_Object slots are atomic, which they are on Windows).
4047 Although delete-frame can destructively modify the frame list while
4048 we are walking it, a garbage collection cannot occur until after
4049 delete-frame has synchronized with this thread.
4051 It is also safe to use functions that make GDI calls, such as
4052 w32_clear_rect, because these functions must obtain a DC handle
4053 from the frame struct using get_frame_dc which is thread-aware. */
4058 f
= x_window_to_frame (dpyinfo
, hwnd
);
4061 HDC hdc
= get_frame_dc (f
);
4062 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
4063 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
4064 release_frame_dc (f
, hdc
);
4066 #if defined (W32_DEBUG_DISPLAY)
4067 DebPrint (("WM_ERASEBKGND: erasing %d,%d-%d,%d\n",
4068 wmsg
.rect
.left
, wmsg
.rect
.top
, wmsg
.rect
.right
,
4070 #endif /* W32_DEBUG_DISPLAY */
4073 case WM_PALETTECHANGED
:
4074 /* ignore our own changes */
4075 if ((HWND
)wParam
!= hwnd
)
4077 f
= x_window_to_frame (dpyinfo
, hwnd
);
4079 /* get_frame_dc will realize our palette and force all
4080 frames to be redrawn if needed. */
4081 release_frame_dc (f
, get_frame_dc (f
));
4086 PAINTSTRUCT paintStruct
;
4089 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
4090 fails. Apparently this can happen under some
4092 if (!w32_strict_painting
|| GetUpdateRect (hwnd
, &update_rect
, FALSE
))
4095 BeginPaint (hwnd
, &paintStruct
);
4097 if (w32_strict_painting
)
4098 /* The rectangles returned by GetUpdateRect and BeginPaint
4099 do not always match. GetUpdateRect seems to be the
4100 more reliable of the two. */
4101 wmsg
.rect
= update_rect
;
4103 wmsg
.rect
= paintStruct
.rcPaint
;
4105 #if defined (W32_DEBUG_DISPLAY)
4106 DebPrint (("WM_PAINT: painting %d,%d-%d,%d\n", wmsg
.rect
.left
,
4107 wmsg
.rect
.top
, wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4108 DebPrint (("WM_PAINT: update region is %d,%d-%d,%d\n",
4109 update_rect
.left
, update_rect
.top
,
4110 update_rect
.right
, update_rect
.bottom
));
4112 EndPaint (hwnd
, &paintStruct
);
4115 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4120 /* If GetUpdateRect returns 0 (meaning there is no update
4121 region), assume the whole window needs to be repainted. */
4122 GetClientRect(hwnd
, &wmsg
.rect
);
4123 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4127 case WM_INPUTLANGCHANGE
:
4128 /* Inform lisp thread of keyboard layout changes. */
4129 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4131 /* Clear dead keys in the keyboard state; for simplicity only
4132 preserve modifier key states. */
4137 GetKeyboardState (keystate
);
4138 for (i
= 0; i
< 256; i
++)
4155 SetKeyboardState (keystate
);
4160 /* Synchronize hot keys with normal input. */
4161 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
4166 record_keyup (wParam
, lParam
);
4171 /* Ignore keystrokes we fake ourself; see below. */
4172 if (dpyinfo
->faked_key
== wParam
)
4174 dpyinfo
->faked_key
= 0;
4175 /* Make sure TranslateMessage sees them though (as long as
4176 they don't produce WM_CHAR messages). This ensures that
4177 indicator lights are toggled promptly on Windows 9x, for
4179 if (lispy_function_keys
[wParam
] != 0)
4181 windows_translate
= 1;
4187 /* Synchronize modifiers with current keystroke. */
4189 record_keydown (wParam
, lParam
);
4190 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
4192 windows_translate
= 0;
4197 if (NILP (Vw32_pass_lwindow_to_system
))
4199 /* Prevent system from acting on keyup (which opens the
4200 Start menu if no other key was pressed) by simulating a
4201 press of Space which we will ignore. */
4202 if (GetAsyncKeyState (wParam
) & 1)
4204 if (NUMBERP (Vw32_phantom_key_code
))
4205 key
= XUINT (Vw32_phantom_key_code
) & 255;
4208 dpyinfo
->faked_key
= key
;
4209 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4212 if (!NILP (Vw32_lwindow_modifier
))
4216 if (NILP (Vw32_pass_rwindow_to_system
))
4218 if (GetAsyncKeyState (wParam
) & 1)
4220 if (NUMBERP (Vw32_phantom_key_code
))
4221 key
= XUINT (Vw32_phantom_key_code
) & 255;
4224 dpyinfo
->faked_key
= key
;
4225 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4228 if (!NILP (Vw32_rwindow_modifier
))
4232 if (!NILP (Vw32_apps_modifier
))
4236 if (NILP (Vw32_pass_alt_to_system
))
4237 /* Prevent DefWindowProc from activating the menu bar if an
4238 Alt key is pressed and released by itself. */
4240 windows_translate
= 1;
4243 /* Decide whether to treat as modifier or function key. */
4244 if (NILP (Vw32_enable_caps_lock
))
4245 goto disable_lock_key
;
4246 windows_translate
= 1;
4249 /* Decide whether to treat as modifier or function key. */
4250 if (NILP (Vw32_enable_num_lock
))
4251 goto disable_lock_key
;
4252 windows_translate
= 1;
4255 /* Decide whether to treat as modifier or function key. */
4256 if (NILP (Vw32_scroll_lock_modifier
))
4257 goto disable_lock_key
;
4258 windows_translate
= 1;
4261 /* Ensure the appropriate lock key state (and indicator light)
4262 remains in the same state. We do this by faking another
4263 press of the relevant key. Apparently, this really is the
4264 only way to toggle the state of the indicator lights. */
4265 dpyinfo
->faked_key
= wParam
;
4266 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4267 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4268 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4269 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4270 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4271 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4272 /* Ensure indicator lights are updated promptly on Windows 9x
4273 (TranslateMessage apparently does this), after forwarding
4275 post_character_message (hwnd
, msg
, wParam
, lParam
,
4276 w32_get_key_modifiers (wParam
, lParam
));
4277 windows_translate
= 1;
4281 case VK_PROCESSKEY
: /* Generated by IME. */
4282 windows_translate
= 1;
4285 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
4286 which is confusing for purposes of key binding; convert
4287 VK_CANCEL events into VK_PAUSE events. */
4291 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
4292 for purposes of key binding; convert these back into
4293 VK_NUMLOCK events, at least when we want to see NumLock key
4294 presses. (Note that there is never any possibility that
4295 VK_PAUSE with Ctrl really is C-Pause as per above.) */
4296 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
4297 wParam
= VK_NUMLOCK
;
4300 /* If not defined as a function key, change it to a WM_CHAR message. */
4301 if (lispy_function_keys
[wParam
] == 0)
4303 DWORD modifiers
= construct_console_modifiers ();
4305 if (!NILP (Vw32_recognize_altgr
)
4306 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
4308 /* Always let TranslateMessage handle AltGr key chords;
4309 for some reason, ToAscii doesn't always process AltGr
4310 chords correctly. */
4311 windows_translate
= 1;
4313 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
4315 /* Handle key chords including any modifiers other
4316 than shift directly, in order to preserve as much
4317 modifier information as possible. */
4318 if ('A' <= wParam
&& wParam
<= 'Z')
4320 /* Don't translate modified alphabetic keystrokes,
4321 so the user doesn't need to constantly switch
4322 layout to type control or meta keystrokes when
4323 the normal layout translates alphabetic
4324 characters to non-ascii characters. */
4325 if (!modifier_set (VK_SHIFT
))
4326 wParam
+= ('a' - 'A');
4331 /* Try to handle other keystrokes by determining the
4332 base character (ie. translating the base key plus
4336 KEY_EVENT_RECORD key
;
4338 key
.bKeyDown
= TRUE
;
4339 key
.wRepeatCount
= 1;
4340 key
.wVirtualKeyCode
= wParam
;
4341 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
4342 key
.uChar
.AsciiChar
= 0;
4343 key
.dwControlKeyState
= modifiers
;
4345 add
= w32_kbd_patch_key (&key
);
4346 /* 0 means an unrecognised keycode, negative means
4347 dead key. Ignore both. */
4350 /* Forward asciified character sequence. */
4351 post_character_message
4352 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
4353 w32_get_key_modifiers (wParam
, lParam
));
4354 w32_kbd_patch_key (&key
);
4361 /* Let TranslateMessage handle everything else. */
4362 windows_translate
= 1;
4368 if (windows_translate
)
4370 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
4372 windows_msg
.time
= GetMessageTime ();
4373 TranslateMessage (&windows_msg
);
4381 post_character_message (hwnd
, msg
, wParam
, lParam
,
4382 w32_get_key_modifiers (wParam
, lParam
));
4385 /* Simulate middle mouse button events when left and right buttons
4386 are used together, but only if user has two button mouse. */
4387 case WM_LBUTTONDOWN
:
4388 case WM_RBUTTONDOWN
:
4389 if (XINT (Vw32_num_mouse_buttons
) > 2)
4390 goto handle_plain_button
;
4393 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
4394 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
4396 if (button_state
& this)
4399 if (button_state
== 0)
4402 button_state
|= this;
4404 if (button_state
& other
)
4406 if (mouse_button_timer
)
4408 KillTimer (hwnd
, mouse_button_timer
);
4409 mouse_button_timer
= 0;
4411 /* Generate middle mouse event instead. */
4412 msg
= WM_MBUTTONDOWN
;
4413 button_state
|= MMOUSE
;
4415 else if (button_state
& MMOUSE
)
4417 /* Ignore button event if we've already generated a
4418 middle mouse down event. This happens if the
4419 user releases and press one of the two buttons
4420 after we've faked a middle mouse event. */
4425 /* Flush out saved message. */
4426 post_msg (&saved_mouse_button_msg
);
4428 wmsg
.dwModifiers
= w32_get_modifiers ();
4429 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4431 /* Clear message buffer. */
4432 saved_mouse_button_msg
.msg
.hwnd
= 0;
4436 /* Hold onto message for now. */
4437 mouse_button_timer
=
4438 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
4439 XINT (Vw32_mouse_button_tolerance
), NULL
);
4440 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
4441 saved_mouse_button_msg
.msg
.message
= msg
;
4442 saved_mouse_button_msg
.msg
.wParam
= wParam
;
4443 saved_mouse_button_msg
.msg
.lParam
= lParam
;
4444 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
4445 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
4452 if (XINT (Vw32_num_mouse_buttons
) > 2)
4453 goto handle_plain_button
;
4456 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
4457 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
4459 if ((button_state
& this) == 0)
4462 button_state
&= ~this;
4464 if (button_state
& MMOUSE
)
4466 /* Only generate event when second button is released. */
4467 if ((button_state
& other
) == 0)
4470 button_state
&= ~MMOUSE
;
4472 if (button_state
) abort ();
4479 /* Flush out saved message if necessary. */
4480 if (saved_mouse_button_msg
.msg
.hwnd
)
4482 post_msg (&saved_mouse_button_msg
);
4485 wmsg
.dwModifiers
= w32_get_modifiers ();
4486 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4488 /* Always clear message buffer and cancel timer. */
4489 saved_mouse_button_msg
.msg
.hwnd
= 0;
4490 KillTimer (hwnd
, mouse_button_timer
);
4491 mouse_button_timer
= 0;
4493 if (button_state
== 0)
4498 case WM_MBUTTONDOWN
:
4500 handle_plain_button
:
4505 if (parse_button (msg
, &button
, &up
))
4507 if (up
) ReleaseCapture ();
4508 else SetCapture (hwnd
);
4509 button
= (button
== 0) ? LMOUSE
:
4510 ((button
== 1) ? MMOUSE
: RMOUSE
);
4512 button_state
&= ~button
;
4514 button_state
|= button
;
4518 wmsg
.dwModifiers
= w32_get_modifiers ();
4519 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4524 if (XINT (Vw32_mouse_move_interval
) <= 0
4525 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4527 wmsg
.dwModifiers
= w32_get_modifiers ();
4528 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4532 /* Hang onto mouse move and scroll messages for a bit, to avoid
4533 sending such events to Emacs faster than it can process them.
4534 If we get more events before the timer from the first message
4535 expires, we just replace the first message. */
4537 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4539 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4540 XINT (Vw32_mouse_move_interval
), NULL
);
4542 /* Hold onto message for now. */
4543 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4544 saved_mouse_move_msg
.msg
.message
= msg
;
4545 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4546 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4547 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4548 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4553 wmsg
.dwModifiers
= w32_get_modifiers ();
4554 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4558 wmsg
.dwModifiers
= w32_get_modifiers ();
4559 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4563 /* Flush out saved messages if necessary. */
4564 if (wParam
== mouse_button_timer
)
4566 if (saved_mouse_button_msg
.msg
.hwnd
)
4568 post_msg (&saved_mouse_button_msg
);
4569 saved_mouse_button_msg
.msg
.hwnd
= 0;
4571 KillTimer (hwnd
, mouse_button_timer
);
4572 mouse_button_timer
= 0;
4574 else if (wParam
== mouse_move_timer
)
4576 if (saved_mouse_move_msg
.msg
.hwnd
)
4578 post_msg (&saved_mouse_move_msg
);
4579 saved_mouse_move_msg
.msg
.hwnd
= 0;
4581 KillTimer (hwnd
, mouse_move_timer
);
4582 mouse_move_timer
= 0;
4587 /* Windows doesn't send us focus messages when putting up and
4588 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4589 The only indication we get that something happened is receiving
4590 this message afterwards. So this is a good time to reset our
4591 keyboard modifiers' state. */
4598 /* We must ensure menu bar is fully constructed and up to date
4599 before allowing user interaction with it. To achieve this
4600 we send this message to the lisp thread and wait for a
4601 reply (whose value is not actually needed) to indicate that
4602 the menu bar is now ready for use, so we can now return.
4604 To remain responsive in the meantime, we enter a nested message
4605 loop that can process all other messages.
4607 However, we skip all this if the message results from calling
4608 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4609 thread a message because it is blocked on us at this point. We
4610 set menubar_active before calling TrackPopupMenu to indicate
4611 this (there is no possibility of confusion with real menubar
4614 f
= x_window_to_frame (dpyinfo
, hwnd
);
4616 && (f
->output_data
.w32
->menubar_active
4617 /* We can receive this message even in the absence of a
4618 menubar (ie. when the system menu is activated) - in this
4619 case we do NOT want to forward the message, otherwise it
4620 will cause the menubar to suddenly appear when the user
4621 had requested it to be turned off! */
4622 || f
->output_data
.w32
->menubar_widget
== NULL
))
4626 deferred_msg msg_buf
;
4628 /* Detect if message has already been deferred; in this case
4629 we cannot return any sensible value to ignore this. */
4630 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4633 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4636 case WM_EXITMENULOOP
:
4637 f
= x_window_to_frame (dpyinfo
, hwnd
);
4639 /* Indicate that menubar can be modified again. */
4641 f
->output_data
.w32
->menubar_active
= 0;
4645 wmsg
.dwModifiers
= w32_get_modifiers ();
4646 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4649 case WM_MEASUREITEM
:
4650 f
= x_window_to_frame (dpyinfo
, hwnd
);
4653 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4655 if (pMis
->CtlType
== ODT_MENU
)
4657 /* Work out dimensions for popup menu titles. */
4658 char * title
= (char *) pMis
->itemData
;
4659 HDC hdc
= GetDC (hwnd
);
4660 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4661 LOGFONT menu_logfont
;
4665 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4666 menu_logfont
.lfWeight
= FW_BOLD
;
4667 menu_font
= CreateFontIndirect (&menu_logfont
);
4668 old_font
= SelectObject (hdc
, menu_font
);
4670 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4673 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4674 pMis
->itemWidth
= size
.cx
;
4675 if (pMis
->itemHeight
< size
.cy
)
4676 pMis
->itemHeight
= size
.cy
;
4679 pMis
->itemWidth
= 0;
4681 SelectObject (hdc
, old_font
);
4682 DeleteObject (menu_font
);
4683 ReleaseDC (hwnd
, hdc
);
4690 f
= x_window_to_frame (dpyinfo
, hwnd
);
4693 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4695 if (pDis
->CtlType
== ODT_MENU
)
4697 /* Draw popup menu title. */
4698 char * title
= (char *) pDis
->itemData
;
4701 HDC hdc
= pDis
->hDC
;
4702 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4703 LOGFONT menu_logfont
;
4706 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4707 menu_logfont
.lfWeight
= FW_BOLD
;
4708 menu_font
= CreateFontIndirect (&menu_logfont
);
4709 old_font
= SelectObject (hdc
, menu_font
);
4711 /* Always draw title as if not selected. */
4714 + GetSystemMetrics (SM_CXMENUCHECK
),
4716 ETO_OPAQUE
, &pDis
->rcItem
,
4717 title
, strlen (title
), NULL
);
4719 SelectObject (hdc
, old_font
);
4720 DeleteObject (menu_font
);
4728 /* Still not right - can't distinguish between clicks in the
4729 client area of the frame from clicks forwarded from the scroll
4730 bars - may have to hook WM_NCHITTEST to remember the mouse
4731 position and then check if it is in the client area ourselves. */
4732 case WM_MOUSEACTIVATE
:
4733 /* Discard the mouse click that activates a frame, allowing the
4734 user to click anywhere without changing point (or worse!).
4735 Don't eat mouse clicks on scrollbars though!! */
4736 if (LOWORD (lParam
) == HTCLIENT
)
4737 return MA_ACTIVATEANDEAT
;
4741 case WM_ACTIVATEAPP
:
4743 case WM_WINDOWPOSCHANGED
:
4745 /* Inform lisp thread that a frame might have just been obscured
4746 or exposed, so should recheck visibility of all frames. */
4747 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4751 dpyinfo
->faked_key
= 0;
4753 register_hot_keys (hwnd
);
4756 unregister_hot_keys (hwnd
);
4763 wmsg
.dwModifiers
= w32_get_modifiers ();
4764 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4768 wmsg
.dwModifiers
= w32_get_modifiers ();
4769 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4772 case WM_WINDOWPOSCHANGING
:
4775 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
4777 wp
.length
= sizeof (WINDOWPLACEMENT
);
4778 GetWindowPlacement (hwnd
, &wp
);
4780 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
4787 DWORD internal_border
;
4788 DWORD scrollbar_extra
;
4791 wp
.length
= sizeof(wp
);
4792 GetWindowRect (hwnd
, &wr
);
4796 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
4797 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
4798 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
4799 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
4803 memset (&rect
, 0, sizeof (rect
));
4804 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
4805 GetMenu (hwnd
) != NULL
);
4807 /* Force width and height of client area to be exact
4808 multiples of the character cell dimensions. */
4809 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
4810 - 2 * internal_border
- scrollbar_extra
)
4812 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
4813 - 2 * internal_border
)
4818 /* For right/bottom sizing we can just fix the sizes.
4819 However for top/left sizing we will need to fix the X
4820 and Y positions as well. */
4825 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
4826 && (lppos
->flags
& SWP_NOMOVE
) == 0)
4828 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
4835 lppos
->flags
|= SWP_NOMOVE
;
4846 case WM_GETMINMAXINFO
:
4847 /* Hack to correct bug that allows Emacs frames to be resized
4848 below the Minimum Tracking Size. */
4849 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
4852 case WM_EMACS_CREATESCROLLBAR
:
4853 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
4854 (struct scroll_bar
*) lParam
);
4856 case WM_EMACS_SHOWWINDOW
:
4857 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4859 case WM_EMACS_SETFOREGROUND
:
4861 HWND foreground_window
;
4862 DWORD foreground_thread
, retval
;
4864 /* On NT 5.0, and apparently Windows 98, it is necessary to
4865 attach to the thread that currently has focus in order to
4866 pull the focus away from it. */
4867 foreground_window
= GetForegroundWindow ();
4868 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4869 if (!foreground_window
4870 || foreground_thread
== GetCurrentThreadId ()
4871 || !AttachThreadInput (GetCurrentThreadId (),
4872 foreground_thread
, TRUE
))
4873 foreground_thread
= 0;
4875 retval
= SetForegroundWindow ((HWND
) wParam
);
4877 /* Detach from the previous foreground thread. */
4878 if (foreground_thread
)
4879 AttachThreadInput (GetCurrentThreadId (),
4880 foreground_thread
, FALSE
);
4885 case WM_EMACS_SETWINDOWPOS
:
4887 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4888 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4889 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4892 case WM_EMACS_DESTROYWINDOW
:
4893 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4894 return DestroyWindow ((HWND
) wParam
);
4896 case WM_EMACS_TRACKPOPUPMENU
:
4901 pos
= (POINT
*)lParam
;
4902 flags
= TPM_CENTERALIGN
;
4903 if (button_state
& LMOUSE
)
4904 flags
|= TPM_LEFTBUTTON
;
4905 else if (button_state
& RMOUSE
)
4906 flags
|= TPM_RIGHTBUTTON
;
4908 /* Remember we did a SetCapture on the initial mouse down event,
4909 so for safety, we make sure the capture is cancelled now. */
4913 /* Use menubar_active to indicate that WM_INITMENU is from
4914 TrackPopupMenu below, and should be ignored. */
4915 f
= x_window_to_frame (dpyinfo
, hwnd
);
4917 f
->output_data
.w32
->menubar_active
= 1;
4919 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4923 /* Eat any mouse messages during popupmenu */
4924 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4926 /* Get the menu selection, if any */
4927 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4929 retval
= LOWORD (amsg
.wParam
);
4945 /* Check for messages registered at runtime. */
4946 if (msg
== msh_mousewheel
)
4948 wmsg
.dwModifiers
= w32_get_modifiers ();
4949 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4954 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
4958 /* The most common default return code for handled messages is 0. */
4963 my_create_window (f
)
4968 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4970 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4973 /* Create and set up the w32 window for frame F. */
4976 w32_window (f
, window_prompting
, minibuffer_only
)
4978 long window_prompting
;
4979 int minibuffer_only
;
4983 /* Use the resource name as the top-level window name
4984 for looking up resources. Make a non-Lisp copy
4985 for the window manager, so GC relocation won't bother it.
4987 Elsewhere we specify the window name for the window manager. */
4990 char *str
= (char *) XSTRING (Vx_resource_name
)->data
;
4991 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4992 strcpy (f
->namebuf
, str
);
4995 my_create_window (f
);
4997 validate_x_resource_name ();
4999 /* x_set_name normally ignores requests to set the name if the
5000 requested name is the same as the current name. This is the one
5001 place where that assumption isn't correct; f->name is set, but
5002 the server hasn't been told. */
5005 int explicit = f
->explicit_name
;
5007 f
->explicit_name
= 0;
5010 x_set_name (f
, name
, explicit);
5015 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
5016 initialize_frame_menubar (f
);
5018 if (FRAME_W32_WINDOW (f
) == 0)
5019 error ("Unable to create window");
5022 /* Handle the icon stuff for this window. Perhaps later we might
5023 want an x_set_icon_position which can be called interactively as
5031 Lisp_Object icon_x
, icon_y
;
5033 /* Set the position of the icon. Note that Windows 95 groups all
5034 icons in the tray. */
5035 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
5036 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
5037 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
5039 CHECK_NUMBER (icon_x
, 0);
5040 CHECK_NUMBER (icon_y
, 0);
5042 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
5043 error ("Both left and top icon corners of icon must be specified");
5047 if (! EQ (icon_x
, Qunbound
))
5048 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
5051 /* Start up iconic or window? */
5052 x_wm_set_window_state
5053 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
5057 x_text_icon (f
, (char *) XSTRING ((!NILP (f
->icon_name
)
5070 XGCValues gc_values
;
5074 /* Create the GC's of this frame.
5075 Note that many default values are used. */
5078 gc_values
.font
= f
->output_data
.w32
->font
;
5080 /* Cursor has cursor-color background, background-color foreground. */
5081 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
5082 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
5083 f
->output_data
.w32
->cursor_gc
5084 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
5085 (GCFont
| GCForeground
| GCBackground
),
5089 f
->output_data
.w32
->white_relief
.gc
= 0;
5090 f
->output_data
.w32
->black_relief
.gc
= 0;
5096 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
5098 "Make a new window, which is called a \"frame\" in Emacs terms.\n\
5099 Returns an Emacs frame object.\n\
5100 ALIST is an alist of frame parameters.\n\
5101 If the parameters specify that the frame should not have a minibuffer,\n\
5102 and do not specify a specific minibuffer window to use,\n\
5103 then `default-minibuffer-frame' must be a frame whose minibuffer can\n\
5104 be shared by the new frame.\n\
5106 This function is an internal primitive--use `make-frame' instead.")
5111 Lisp_Object frame
, tem
;
5113 int minibuffer_only
= 0;
5114 long window_prompting
= 0;
5116 int count
= specpdl_ptr
- specpdl
;
5117 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5118 Lisp_Object display
;
5119 struct w32_display_info
*dpyinfo
= NULL
;
5125 /* Use this general default value to start with
5126 until we know if this frame has a specified name. */
5127 Vx_resource_name
= Vinvocation_name
;
5129 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
5130 if (EQ (display
, Qunbound
))
5132 dpyinfo
= check_x_display_info (display
);
5134 kb
= dpyinfo
->kboard
;
5136 kb
= &the_only_kboard
;
5139 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5141 && ! EQ (name
, Qunbound
)
5143 error ("Invalid frame name--not a string or nil");
5146 Vx_resource_name
= name
;
5148 /* See if parent window is specified. */
5149 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
5150 if (EQ (parent
, Qunbound
))
5152 if (! NILP (parent
))
5153 CHECK_NUMBER (parent
, 0);
5155 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
5156 /* No need to protect DISPLAY because that's not used after passing
5157 it to make_frame_without_minibuffer. */
5159 GCPRO4 (parms
, parent
, name
, frame
);
5160 tem
= w32_get_arg (parms
, Qminibuffer
, "minibuffer", "Minibuffer",
5162 if (EQ (tem
, Qnone
) || NILP (tem
))
5163 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
5164 else if (EQ (tem
, Qonly
))
5166 f
= make_minibuffer_frame ();
5167 minibuffer_only
= 1;
5169 else if (WINDOWP (tem
))
5170 f
= make_frame_without_minibuffer (tem
, kb
, display
);
5174 XSETFRAME (frame
, f
);
5176 /* Note that Windows does support scroll bars. */
5177 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
5178 /* By default, make scrollbars the system standard width. */
5179 f
->scroll_bar_pixel_width
= GetSystemMetrics (SM_CXVSCROLL
);
5181 f
->output_method
= output_w32
;
5182 f
->output_data
.w32
=
5183 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5184 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5186 FRAME_FONTSET (f
) = -1;
5189 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
5190 if (! STRINGP (f
->icon_name
))
5191 f
->icon_name
= Qnil
;
5193 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
5195 FRAME_KBOARD (f
) = kb
;
5198 /* Specify the parent under which to make this window. */
5202 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
5203 f
->output_data
.w32
->explicit_parent
= 1;
5207 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5208 f
->output_data
.w32
->explicit_parent
= 0;
5211 /* Set the name; the functions to which we pass f expect the name to
5213 if (EQ (name
, Qunbound
) || NILP (name
))
5215 f
->name
= build_string (dpyinfo
->w32_id_name
);
5216 f
->explicit_name
= 0;
5221 f
->explicit_name
= 1;
5222 /* use the frame's title when getting resources for this frame. */
5223 specbind (Qx_resource_name
, name
);
5226 /* Extract the window parameters from the supplied values
5227 that are needed to determine window geometry. */
5231 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
5234 /* First, try whatever font the caller has specified. */
5237 tem
= Fquery_fontset (font
, Qnil
);
5239 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
5241 font
= x_new_font (f
, XSTRING (font
)->data
);
5243 /* Try out a font which we hope has bold and italic variations. */
5244 if (!STRINGP (font
))
5245 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
5246 if (! STRINGP (font
))
5247 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5248 /* If those didn't work, look for something which will at least work. */
5249 if (! STRINGP (font
))
5250 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
5252 if (! STRINGP (font
))
5253 font
= build_string ("Fixedsys");
5255 x_default_parameter (f
, parms
, Qfont
, font
,
5256 "font", "Font", RES_TYPE_STRING
);
5259 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5260 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5261 /* This defaults to 2 in order to match xterm. We recognize either
5262 internalBorderWidth or internalBorder (which is what xterm calls
5264 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5268 value
= w32_get_arg (parms
, Qinternal_border_width
,
5269 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
5270 if (! EQ (value
, Qunbound
))
5271 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5274 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5275 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
5276 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
5277 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qright
,
5278 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5280 /* Also do the stuff which must be set before the window exists. */
5281 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5282 "foreground", "Foreground", RES_TYPE_STRING
);
5283 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5284 "background", "Background", RES_TYPE_STRING
);
5285 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5286 "pointerColor", "Foreground", RES_TYPE_STRING
);
5287 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5288 "cursorColor", "Foreground", RES_TYPE_STRING
);
5289 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5290 "borderColor", "BorderColor", RES_TYPE_STRING
);
5291 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
5292 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5293 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
5294 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
5297 /* Init faces before x_default_parameter is called for scroll-bar
5298 parameters because that function calls x_set_scroll_bar_width,
5299 which calls change_frame_size, which calls Fset_window_buffer,
5300 which runs hooks, which call Fvertical_motion. At the end, we
5301 end up in init_iterator with a null face cache, which should not
5303 init_frame_faces (f
);
5305 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
5306 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
5307 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (0),
5308 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
5309 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
5310 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5311 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
5312 "title", "Title", RES_TYPE_STRING
);
5314 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5315 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5316 window_prompting
= x_figure_window_size (f
, parms
);
5318 if (window_prompting
& XNegative
)
5320 if (window_prompting
& YNegative
)
5321 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
5323 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
5327 if (window_prompting
& YNegative
)
5328 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
5330 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
5333 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
5335 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5336 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5338 /* Create the window. Add the tool-bar height to the initial frame
5339 height so that the user gets a text display area of the size he
5340 specified with -g or via the registry. Later changes of the
5341 tool-bar height don't change the frame size. This is done so that
5342 users can create tall Emacs frames without having to guess how
5343 tall the tool-bar will get. */
5344 f
->height
+= FRAME_TOOL_BAR_LINES (f
);
5345 w32_window (f
, window_prompting
, minibuffer_only
);
5350 /* Now consider the frame official. */
5351 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5352 Vframe_list
= Fcons (frame
, Vframe_list
);
5354 /* We need to do this after creating the window, so that the
5355 icon-creation functions can say whose icon they're describing. */
5356 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
5357 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5359 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5360 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5361 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5362 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5363 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5364 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5365 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
5366 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5368 /* Dimensions, especially f->height, must be done via change_frame_size.
5369 Change will not be effected unless different from the current
5374 SET_FRAME_WIDTH (f
, 0);
5375 change_frame_size (f
, height
, width
, 1, 0, 0);
5377 /* Tell the server what size and position, etc, we want, and how
5378 badly we want them. This should be done after we have the menu
5379 bar so that its size can be taken into account. */
5381 x_wm_set_size_hint (f
, window_prompting
, 0);
5384 /* Make the window appear on the frame and enable display, unless
5385 the caller says not to. However, with explicit parent, Emacs
5386 cannot control visibility, so don't try. */
5387 if (! f
->output_data
.w32
->explicit_parent
)
5389 Lisp_Object visibility
;
5391 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5392 if (EQ (visibility
, Qunbound
))
5395 if (EQ (visibility
, Qicon
))
5396 x_iconify_frame (f
);
5397 else if (! NILP (visibility
))
5398 x_make_frame_visible (f
);
5400 /* Must have been Qnil. */
5404 return unbind_to (count
, frame
);
5407 /* FRAME is used only to get a handle on the X display. We don't pass the
5408 display info directly because we're called from frame.c, which doesn't
5409 know about that structure. */
5411 x_get_focus_frame (frame
)
5412 struct frame
*frame
;
5414 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
5416 if (! dpyinfo
->w32_focus_frame
)
5419 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5423 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
5424 "Give FRAME input focus, raising to foreground if necessary.")
5428 x_focus_on_frame (check_x_frame (frame
));
5433 /* Return the charset portion of a font name. */
5434 char * xlfd_charset_of_font (char * fontname
)
5436 char *charset
, *encoding
;
5438 encoding
= strrchr(fontname
, '-');
5443 charset
= strrchr(fontname
, '-');
5446 if (!charset
|| strcmp(charset
, "-*-*") == 0)
5452 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
5453 int size
, char* filename
);
5454 BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
, char * charset
);
5457 w32_load_system_font (f
,fontname
,size
)
5462 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5463 Lisp_Object font_names
;
5465 /* Get a list of all the fonts that match this name. Once we
5466 have a list of matching fonts, we compare them against the fonts
5467 we already have loaded by comparing names. */
5468 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
5470 if (!NILP (font_names
))
5475 /* First check if any are already loaded, as that is cheaper
5476 than loading another one. */
5477 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5478 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
5479 if (dpyinfo
->font_table
[i
].name
5480 && (!strcmp (dpyinfo
->font_table
[i
].name
,
5481 XSTRING (XCAR (tail
))->data
)
5482 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
5483 XSTRING (XCAR (tail
))->data
)))
5484 return (dpyinfo
->font_table
+ i
);
5486 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
5488 else if (w32_strict_fontnames
)
5490 /* If EnumFontFamiliesEx was available, we got a full list of
5491 fonts back so stop now to avoid the possibility of loading a
5492 random font. If we had to fall back to EnumFontFamilies, the
5493 list is incomplete, so continue whether the font we want was
5495 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5496 FARPROC enum_font_families_ex
5497 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
5498 if (enum_font_families_ex
)
5502 /* Load the font and add it to the table. */
5504 char *full_name
, *encoding
, *charset
;
5506 struct font_info
*fontp
;
5511 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
5514 if (!*lf
.lfFaceName
)
5515 /* If no name was specified for the font, we get a random font
5516 from CreateFontIndirect - this is not particularly
5517 desirable, especially since CreateFontIndirect does not
5518 fill out the missing name in lf, so we never know what we
5522 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
5523 bzero (font
, sizeof (*font
));
5525 /* Set bdf to NULL to indicate that this is a Windows font. */
5530 font
->hfont
= CreateFontIndirect (&lf
);
5532 if (font
->hfont
== NULL
)
5541 hdc
= GetDC (dpyinfo
->root_window
);
5542 oldobj
= SelectObject (hdc
, font
->hfont
);
5543 ok
= GetTextMetrics (hdc
, &font
->tm
);
5544 font
->double_byte_p
= GetFontLanguageInfo(hdc
) & GCP_DBCS
;
5545 SelectObject (hdc
, oldobj
);
5546 ReleaseDC (dpyinfo
->root_window
, hdc
);
5547 /* Fill out details in lf according to the font that was
5549 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
5550 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
5551 lf
.lfWeight
= font
->tm
.tmWeight
;
5552 lf
.lfItalic
= font
->tm
.tmItalic
;
5553 lf
.lfCharSet
= font
->tm
.tmCharSet
;
5554 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
5555 ? VARIABLE_PITCH
: FIXED_PITCH
);
5556 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
5557 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
5559 w32_cache_char_metrics (font
);
5566 w32_unload_font (dpyinfo
, font
);
5570 /* Find a free slot in the font table. */
5571 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
5572 if (dpyinfo
->font_table
[i
].name
== NULL
)
5575 /* If no free slot found, maybe enlarge the font table. */
5576 if (i
== dpyinfo
->n_fonts
5577 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
5580 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
5581 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
5583 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
5586 fontp
= dpyinfo
->font_table
+ i
;
5587 if (i
== dpyinfo
->n_fonts
)
5590 /* Now fill in the slots of *FONTP. */
5593 fontp
->font_idx
= i
;
5594 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
5595 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
5597 charset
= xlfd_charset_of_font (fontname
);
5599 /* Work out the font's full name. */
5600 full_name
= (char *)xmalloc (100);
5601 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
5602 fontp
->full_name
= full_name
;
5605 /* If all else fails - just use the name we used to load it. */
5607 fontp
->full_name
= fontp
->name
;
5610 fontp
->size
= FONT_WIDTH (font
);
5611 fontp
->height
= FONT_HEIGHT (font
);
5613 /* The slot `encoding' specifies how to map a character
5614 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
5615 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
5616 (0:0x20..0x7F, 1:0xA0..0xFF,
5617 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
5618 2:0xA020..0xFF7F). For the moment, we don't know which charset
5619 uses this font. So, we set information in fontp->encoding[1]
5620 which is never used by any charset. If mapping can't be
5621 decided, set FONT_ENCODING_NOT_DECIDED. */
5623 /* SJIS fonts need to be set to type 4, all others seem to work as
5624 type FONT_ENCODING_NOT_DECIDED. */
5625 encoding
= strrchr (fontp
->name
, '-');
5626 if (encoding
&& stricmp (encoding
+1, "sjis") == 0)
5627 fontp
->encoding
[1] = 4;
5629 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
5631 /* The following three values are set to 0 under W32, which is
5632 what they get set to if XGetFontProperty fails under X. */
5633 fontp
->baseline_offset
= 0;
5634 fontp
->relative_compose
= 0;
5635 fontp
->default_ascent
= 0;
5637 /* Set global flag fonts_changed_p to non-zero if the font loaded
5638 has a character with a smaller width than any other character
5639 before, or if the font loaded has a smalle>r height than any
5640 other font loaded before. If this happens, it will make a
5641 glyph matrix reallocation necessary. */
5642 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
5648 /* Load font named FONTNAME of size SIZE for frame F, and return a
5649 pointer to the structure font_info while allocating it dynamically.
5650 If loading fails, return NULL. */
5652 w32_load_font (f
,fontname
,size
)
5657 Lisp_Object bdf_fonts
;
5658 struct font_info
*retval
= NULL
;
5660 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
));
5662 while (!retval
&& CONSP (bdf_fonts
))
5664 char *bdf_name
, *bdf_file
;
5665 Lisp_Object bdf_pair
;
5667 bdf_name
= XSTRING (XCAR (bdf_fonts
))->data
;
5668 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
5669 bdf_file
= XSTRING (XCDR (bdf_pair
))->data
;
5671 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
5673 bdf_fonts
= XCDR (bdf_fonts
);
5679 return w32_load_system_font(f
, fontname
, size
);
5684 w32_unload_font (dpyinfo
, font
)
5685 struct w32_display_info
*dpyinfo
;
5690 if (font
->per_char
) xfree (font
->per_char
);
5691 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
5693 if (font
->hfont
) DeleteObject(font
->hfont
);
5698 /* The font conversion stuff between x and w32 */
5700 /* X font string is as follows (from faces.el)
5704 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
5705 * (weight\? "\\([^-]*\\)") ; 1
5706 * (slant "\\([ior]\\)") ; 2
5707 * (slant\? "\\([^-]?\\)") ; 2
5708 * (swidth "\\([^-]*\\)") ; 3
5709 * (adstyle "[^-]*") ; 4
5710 * (pixelsize "[0-9]+")
5711 * (pointsize "[0-9][0-9]+")
5712 * (resx "[0-9][0-9]+")
5713 * (resy "[0-9][0-9]+")
5714 * (spacing "[cmp?*]")
5715 * (avgwidth "[0-9]+")
5716 * (registry "[^-]+")
5717 * (encoding "[^-]+")
5722 x_to_w32_weight (lpw
)
5725 if (!lpw
) return (FW_DONTCARE
);
5727 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
5728 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
5729 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
5730 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
5731 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
5732 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
5733 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
5734 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
5735 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
5736 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
5743 w32_to_x_weight (fnweight
)
5746 if (fnweight
>= FW_HEAVY
) return "heavy";
5747 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
5748 if (fnweight
>= FW_BOLD
) return "bold";
5749 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
5750 if (fnweight
>= FW_MEDIUM
) return "medium";
5751 if (fnweight
>= FW_NORMAL
) return "normal";
5752 if (fnweight
>= FW_LIGHT
) return "light";
5753 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
5754 if (fnweight
>= FW_THIN
) return "thin";
5760 x_to_w32_charset (lpcs
)
5763 Lisp_Object this_entry
, w32_charset
;
5765 /* Look through w32-charset-info-alist for the character set.
5766 Format of each entry is
5767 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5769 this_entry
= Fassoc (build_string(lpcs
), Vw32_charset_info_alist
);
5771 if (NILP(this_entry
))
5773 /* At startup, we want iso8859-1 fonts to come up properly. */
5774 if (stricmp(lpcs
, "iso8859-1") == 0)
5775 return ANSI_CHARSET
;
5777 return DEFAULT_CHARSET
;
5780 w32_charset
= Fcar (Fcdr (this_entry
));
5782 // Translate Lisp symbol to number.
5783 if (w32_charset
== Qw32_charset_ansi
)
5784 return ANSI_CHARSET
;
5785 if (w32_charset
== Qw32_charset_symbol
)
5786 return SYMBOL_CHARSET
;
5787 if (w32_charset
== Qw32_charset_shiftjis
)
5788 return SHIFTJIS_CHARSET
;
5789 if (w32_charset
== Qw32_charset_hangeul
)
5790 return HANGEUL_CHARSET
;
5791 if (w32_charset
== Qw32_charset_chinesebig5
)
5792 return CHINESEBIG5_CHARSET
;
5793 if (w32_charset
== Qw32_charset_gb2312
)
5794 return GB2312_CHARSET
;
5795 if (w32_charset
== Qw32_charset_oem
)
5797 #ifdef JOHAB_CHARSET
5798 if (w32_charset
== Qw32_charset_johab
)
5799 return JOHAB_CHARSET
;
5800 if (w32_charset
== Qw32_charset_easteurope
)
5801 return EASTEUROPE_CHARSET
;
5802 if (w32_charset
== Qw32_charset_turkish
)
5803 return TURKISH_CHARSET
;
5804 if (w32_charset
== Qw32_charset_baltic
)
5805 return BALTIC_CHARSET
;
5806 if (w32_charset
== Qw32_charset_russian
)
5807 return RUSSIAN_CHARSET
;
5808 if (w32_charset
== Qw32_charset_arabic
)
5809 return ARABIC_CHARSET
;
5810 if (w32_charset
== Qw32_charset_greek
)
5811 return GREEK_CHARSET
;
5812 if (w32_charset
== Qw32_charset_hebrew
)
5813 return HEBREW_CHARSET
;
5814 if (w32_charset
== Qw32_charset_vietnamese
)
5815 return VIETNAMESE_CHARSET
;
5816 if (w32_charset
== Qw32_charset_thai
)
5817 return THAI_CHARSET
;
5818 if (w32_charset
== Qw32_charset_mac
)
5820 #endif /* JOHAB_CHARSET */
5821 #ifdef UNICODE_CHARSET
5822 if (w32_charset
== Qw32_charset_unicode
)
5823 return UNICODE_CHARSET
;
5826 return DEFAULT_CHARSET
;
5831 w32_to_x_charset (fncharset
)
5834 static char buf
[16];
5835 Lisp_Object charset_type
;
5840 /* Handle startup case of w32-charset-info-alist not
5841 being set up yet. */
5842 if (NILP(Vw32_charset_info_alist
))
5844 charset_type
= Qw32_charset_ansi
;
5846 case DEFAULT_CHARSET
:
5847 charset_type
= Qw32_charset_default
;
5849 case SYMBOL_CHARSET
:
5850 charset_type
= Qw32_charset_symbol
;
5852 case SHIFTJIS_CHARSET
:
5853 charset_type
= Qw32_charset_shiftjis
;
5855 case HANGEUL_CHARSET
:
5856 charset_type
= Qw32_charset_hangeul
;
5858 case GB2312_CHARSET
:
5859 charset_type
= Qw32_charset_gb2312
;
5861 case CHINESEBIG5_CHARSET
:
5862 charset_type
= Qw32_charset_chinesebig5
;
5865 charset_type
= Qw32_charset_oem
;
5868 /* More recent versions of Windows (95 and NT4.0) define more
5870 #ifdef EASTEUROPE_CHARSET
5871 case EASTEUROPE_CHARSET
:
5872 charset_type
= Qw32_charset_easteurope
;
5874 case TURKISH_CHARSET
:
5875 charset_type
= Qw32_charset_turkish
;
5877 case BALTIC_CHARSET
:
5878 charset_type
= Qw32_charset_baltic
;
5880 case RUSSIAN_CHARSET
:
5881 charset_type
= Qw32_charset_russian
;
5883 case ARABIC_CHARSET
:
5884 charset_type
= Qw32_charset_arabic
;
5887 charset_type
= Qw32_charset_greek
;
5889 case HEBREW_CHARSET
:
5890 charset_type
= Qw32_charset_hebrew
;
5892 case VIETNAMESE_CHARSET
:
5893 charset_type
= Qw32_charset_vietnamese
;
5896 charset_type
= Qw32_charset_thai
;
5899 charset_type
= Qw32_charset_mac
;
5902 charset_type
= Qw32_charset_johab
;
5906 #ifdef UNICODE_CHARSET
5907 case UNICODE_CHARSET
:
5908 charset_type
= Qw32_charset_unicode
;
5912 /* Encode numerical value of unknown charset. */
5913 sprintf (buf
, "*-#%u", fncharset
);
5919 char * best_match
= NULL
;
5921 /* Look through w32-charset-info-alist for the character set.
5922 Prefer ISO codepages, and prefer lower numbers in the ISO
5923 range. Only return charsets for codepages which are installed.
5925 Format of each entry is
5926 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5928 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5931 Lisp_Object w32_charset
;
5932 Lisp_Object codepage
;
5934 Lisp_Object this_entry
= XCAR (rest
);
5936 /* Skip invalid entries in alist. */
5937 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5938 || !CONSP (XCDR (this_entry
))
5939 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5942 x_charset
= XSTRING (XCAR (this_entry
))->data
;
5943 w32_charset
= XCAR (XCDR (this_entry
));
5944 codepage
= XCDR (XCDR (this_entry
));
5946 /* Look for Same charset and a valid codepage (or non-int
5947 which means ignore). */
5948 if (w32_charset
== charset_type
5949 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
5950 || IsValidCodePage (XINT (codepage
))))
5952 /* If we don't have a match already, then this is the
5955 best_match
= x_charset
;
5956 /* If this is an ISO codepage, and the best so far isn't,
5957 then this is better. */
5958 else if (stricmp (best_match
, "iso") != 0
5959 && stricmp (x_charset
, "iso") == 0)
5960 best_match
= x_charset
;
5961 /* If both are ISO8859 codepages, choose the one with the
5962 lowest number in the encoding field. */
5963 else if (stricmp (best_match
, "iso8859-") == 0
5964 && stricmp (x_charset
, "iso8859-") == 0)
5966 int best_enc
= atoi (best_match
+ 8);
5967 int this_enc
= atoi (x_charset
+ 8);
5968 if (this_enc
> 0 && this_enc
< best_enc
)
5969 best_match
= x_charset
;
5974 /* If no match, encode the numeric value. */
5977 sprintf (buf
, "*-#%u", fncharset
);
5981 strncpy(buf
, best_match
, 15);
5988 /* Get the Windows codepage corresponding to the specified font. The
5989 charset info in the font name is used to look up
5990 w32-charset-to-codepage-alist. */
5992 w32_codepage_for_font (char *fontname
)
5994 Lisp_Object codepage
, entry
;
5995 char *charset_str
, *charset
, *end
;
5997 if (NILP (Vw32_charset_info_alist
))
6000 /* Extract charset part of font string. */
6001 charset
= xlfd_charset_of_font (fontname
);
6006 charset_str
= (char *) alloca (strlen (charset
));
6007 strcpy (charset_str
, charset
);
6009 /* Remove leading "*-". */
6010 if (strncmp ("*-", charset_str
, 2) == 0)
6011 charset
= charset_str
+ 2;
6013 charset
= charset_str
;
6015 /* Stop match at wildcard (including preceding '-'). */
6016 if (end
= strchr (charset
, '*'))
6018 if (end
> charset
&& *(end
-1) == '-')
6023 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6027 codepage
= Fcdr (Fcdr (entry
));
6029 if (NILP (codepage
))
6031 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
6033 else if (INTEGERP (codepage
))
6034 return XINT (codepage
);
6041 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
6042 LOGFONT
* lplogfont
;
6045 char * specific_charset
;
6049 char height_pixels
[8];
6051 char width_pixels
[8];
6052 char *fontname_dash
;
6053 int display_resy
= one_w32_display_info
.resy
;
6054 int display_resx
= one_w32_display_info
.resx
;
6056 struct coding_system coding
;
6058 if (!lpxstr
) abort ();
6063 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
6064 fonttype
= "raster";
6065 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
6066 fonttype
= "outline";
6068 fonttype
= "unknown";
6070 setup_coding_system (Fcheck_coding_system (Vw32_system_coding_system
),
6072 coding
.src_multibyte
= 0;
6073 coding
.dst_multibyte
= 1;
6074 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6075 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
6077 fontname
= alloca(sizeof(*fontname
) * bufsz
);
6078 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
6079 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
6080 *(fontname
+ coding
.produced
) = '\0';
6082 /* Replace dashes with underscores so the dashes are not
6084 fontname_dash
= fontname
;
6085 while (fontname_dash
= strchr (fontname_dash
, '-'))
6086 *fontname_dash
= '_';
6088 if (lplogfont
->lfHeight
)
6090 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
6091 sprintf (height_dpi
, "%u",
6092 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
6096 strcpy (height_pixels
, "*");
6097 strcpy (height_dpi
, "*");
6099 if (lplogfont
->lfWidth
)
6100 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
6102 strcpy (width_pixels
, "*");
6104 _snprintf (lpxstr
, len
- 1,
6105 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
6106 fonttype
, /* foundry */
6107 fontname
, /* family */
6108 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
6109 lplogfont
->lfItalic
?'i':'r', /* slant */
6111 /* add style name */
6112 height_pixels
, /* pixel size */
6113 height_dpi
, /* point size */
6114 display_resx
, /* resx */
6115 display_resy
, /* resy */
6116 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
6117 ? 'p' : 'c', /* spacing */
6118 width_pixels
, /* avg width */
6119 specific_charset
? specific_charset
6120 : w32_to_x_charset (lplogfont
->lfCharSet
)
6121 /* charset registry and encoding */
6124 lpxstr
[len
- 1] = 0; /* just to be sure */
6129 x_to_w32_font (lpxstr
, lplogfont
)
6131 LOGFONT
* lplogfont
;
6133 struct coding_system coding
;
6135 if (!lplogfont
) return (FALSE
);
6137 memset (lplogfont
, 0, sizeof (*lplogfont
));
6139 /* Set default value for each field. */
6141 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
6142 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
6143 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
6145 /* go for maximum quality */
6146 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
6147 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
6148 lplogfont
->lfQuality
= PROOF_QUALITY
;
6151 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
6152 lplogfont
->lfWeight
= FW_DONTCARE
;
6153 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
6158 /* Provide a simple escape mechanism for specifying Windows font names
6159 * directly -- if font spec does not beginning with '-', assume this
6161 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
6167 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
6168 width
[10], resy
[10], remainder
[20];
6170 int dpi
= one_w32_display_info
.resy
;
6172 fields
= sscanf (lpxstr
,
6173 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%19s",
6174 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
6175 if (fields
== EOF
) return (FALSE
);
6177 /* If wildcards cover more than one field, we don't know which
6178 field is which, so don't fill any in. */
6183 if (fields
> 0 && name
[0] != '*')
6189 (Fcheck_coding_system (Vw32_system_coding_system
), &coding
);
6190 coding
.src_multibyte
= 1;
6191 coding
.dst_multibyte
= 1;
6192 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
6193 buf
= (unsigned char *) alloca (bufsize
);
6194 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6195 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
6196 if (coding
.produced
>= LF_FACESIZE
)
6197 coding
.produced
= LF_FACESIZE
- 1;
6198 buf
[coding
.produced
] = 0;
6199 strcpy (lplogfont
->lfFaceName
, buf
);
6203 lplogfont
->lfFaceName
[0] = '\0';
6208 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6212 if (!NILP (Vw32_enable_synthesized_fonts
))
6213 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
6217 if (fields
> 0 && pixels
[0] != '*')
6218 lplogfont
->lfHeight
= atoi (pixels
);
6222 if (fields
> 0 && resy
[0] != '*')
6225 if (tem
> 0) dpi
= tem
;
6228 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
6229 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
6232 lplogfont
->lfPitchAndFamily
=
6233 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
6237 if (fields
> 0 && width
[0] != '*')
6238 lplogfont
->lfWidth
= atoi (width
) / 10;
6242 /* Strip the trailing '-' if present. (it shouldn't be, as it
6243 fails the test against xlfd-tight-regexp in fontset.el). */
6245 int len
= strlen (remainder
);
6246 if (len
> 0 && remainder
[len
-1] == '-')
6247 remainder
[len
-1] = 0;
6249 encoding
= remainder
;
6250 if (strncmp (encoding
, "*-", 2) == 0)
6252 lplogfont
->lfCharSet
= x_to_w32_charset (fields
> 0 ? encoding
: "");
6257 char name
[100], height
[10], width
[10], weight
[20];
6259 fields
= sscanf (lpxstr
,
6260 "%99[^:]:%9[^:]:%9[^:]:%19s",
6261 name
, height
, width
, weight
);
6263 if (fields
== EOF
) return (FALSE
);
6267 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
6268 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
6272 lplogfont
->lfFaceName
[0] = 0;
6278 lplogfont
->lfHeight
= atoi (height
);
6283 lplogfont
->lfWidth
= atoi (width
);
6287 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6290 /* This makes TrueType fonts work better. */
6291 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
6296 /* Strip the pixel height and point height from the given xlfd, and
6297 return the pixel height. If no pixel height is specified, calculate
6298 one from the point height, or if that isn't defined either, return
6299 0 (which usually signifies a scalable font).
6301 int xlfd_strip_height (char *fontname
)
6303 int pixel_height
, point_height
, dpi
, field_number
;
6304 char *read_from
, *write_to
;
6308 pixel_height
= field_number
= 0;
6311 /* Look for height fields. */
6312 for (read_from
= fontname
; *read_from
; read_from
++)
6314 if (*read_from
== '-')
6317 if (field_number
== 7) /* Pixel height. */
6320 write_to
= read_from
;
6322 /* Find end of field. */
6323 for (;*read_from
&& *read_from
!= '-'; read_from
++)
6326 /* Split the fontname at end of field. */
6332 pixel_height
= atoi (write_to
);
6333 /* Blank out field. */
6334 if (read_from
> write_to
)
6339 /* If the pixel height field is at the end (partial xlfd),
6342 return pixel_height
;
6344 /* If we got a pixel height, the point height can be
6345 ignored. Just blank it out and break now. */
6348 /* Find end of point size field. */
6349 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6355 /* Blank out the point size field. */
6356 if (read_from
> write_to
)
6362 return pixel_height
;
6366 /* If the point height is already blank, break now. */
6367 if (*read_from
== '-')
6373 else if (field_number
== 8)
6375 /* If we didn't get a pixel height, try to get the point
6376 height and convert that. */
6378 char *point_size_start
= read_from
++;
6380 /* Find end of field. */
6381 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6390 point_size
= atoi (point_size_start
);
6392 /* Convert to pixel height. */
6393 pixel_height
= point_size
6394 * one_w32_display_info
.height_in
/ 720;
6396 /* Blank out this field and break. */
6404 /* Shift the rest of the font spec into place. */
6405 if (write_to
&& read_from
> write_to
)
6407 for (; *read_from
; read_from
++, write_to
++)
6408 *write_to
= *read_from
;
6412 return pixel_height
;
6415 /* Assume parameter 1 is fully qualified, no wildcards. */
6417 w32_font_match (fontname
, pattern
)
6421 char *regex
= alloca (strlen (pattern
) * 2);
6422 char *font_name_copy
= alloca (strlen (fontname
) + 1);
6425 /* Copy fontname so we can modify it during comparison. */
6426 strcpy (font_name_copy
, fontname
);
6431 /* Turn pattern into a regexp and do a regexp match. */
6432 for (; *pattern
; pattern
++)
6434 if (*pattern
== '?')
6436 else if (*pattern
== '*')
6447 /* Strip out font heights and compare them seperately, since
6448 rounding error can cause mismatches. This also allows a
6449 comparison between a font that declares only a pixel height and a
6450 pattern that declares the point height.
6453 int font_height
, pattern_height
;
6455 font_height
= xlfd_strip_height (font_name_copy
);
6456 pattern_height
= xlfd_strip_height (regex
);
6458 /* Compare now, and don't bother doing expensive regexp matching
6459 if the heights differ. */
6460 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
6464 return (fast_c_string_match_ignore_case (build_string (regex
),
6465 font_name_copy
) >= 0);
6468 /* Callback functions, and a structure holding info they need, for
6469 listing system fonts on W32. We need one set of functions to do the
6470 job properly, but these don't work on NT 3.51 and earlier, so we
6471 have a second set which don't handle character sets properly to
6474 In both cases, there are two passes made. The first pass gets one
6475 font from each family, the second pass lists all the fonts from
6478 typedef struct enumfont_t
6483 XFontStruct
*size_ref
;
6484 Lisp_Object
*pattern
;
6489 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
6491 NEWTEXTMETRIC
* lptm
;
6495 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
6498 /* Check that the character set matches if it was specified */
6499 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6500 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6505 Lisp_Object width
= Qnil
;
6506 char *charset
= NULL
;
6508 /* Truetype fonts do not report their true metrics until loaded */
6509 if (FontType
!= RASTER_FONTTYPE
)
6511 if (!NILP (*(lpef
->pattern
)))
6513 /* Scalable fonts are as big as you want them to be. */
6514 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6515 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6516 width
= make_number (lpef
->logfont
.lfWidth
);
6520 lplf
->elfLogFont
.lfHeight
= 0;
6521 lplf
->elfLogFont
.lfWidth
= 0;
6525 /* Make sure the height used here is the same as everywhere
6526 else (ie character height, not cell height). */
6527 if (lplf
->elfLogFont
.lfHeight
> 0)
6529 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6530 if (FontType
== RASTER_FONTTYPE
)
6531 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6533 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6536 if (!NILP (*(lpef
->pattern
)))
6538 charset
= xlfd_charset_of_font (XSTRING(*(lpef
->pattern
))->data
);
6540 /* Ensure that charset is valid for this font. */
6542 && (x_to_w32_charset (charset
) != lplf
->elfLogFont
.lfCharSet
))
6546 /* TODO: List all relevant charsets if charset not specified. */
6547 if (!w32_to_x_font (&(lplf
->elfLogFont
), buf
, 100, charset
))
6550 if (NILP (*(lpef
->pattern
))
6551 || w32_font_match (buf
, XSTRING (*(lpef
->pattern
))->data
))
6553 *lpef
->tail
= Fcons (Fcons (build_string (buf
), width
), Qnil
);
6554 lpef
->tail
= &(XCDR (*lpef
->tail
));
6563 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6565 NEWTEXTMETRIC
* lptm
;
6569 return EnumFontFamilies (lpef
->hdc
,
6570 lplf
->elfLogFont
.lfFaceName
,
6571 (FONTENUMPROC
) enum_font_cb2
,
6577 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6578 ENUMLOGFONTEX
* lplf
;
6579 NEWTEXTMETRICEX
* lptm
;
6583 /* We are not interested in the extra info we get back from the 'Ex
6584 version - only the fact that we get character set variations
6585 enumerated seperately. */
6586 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6591 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6592 ENUMLOGFONTEX
* lplf
;
6593 NEWTEXTMETRICEX
* lptm
;
6597 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6598 FARPROC enum_font_families_ex
6599 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6600 /* We don't really expect EnumFontFamiliesEx to disappear once we
6601 get here, so don't bother handling it gracefully. */
6602 if (enum_font_families_ex
== NULL
)
6603 error ("gdi32.dll has disappeared!");
6604 return enum_font_families_ex (lpef
->hdc
,
6606 (FONTENUMPROC
) enum_fontex_cb2
,
6610 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6611 and xterm.c in Emacs 20.3) */
6613 Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6615 char *fontname
, *ptnstr
;
6616 Lisp_Object list
, tem
, newlist
= Qnil
;
6619 list
= Vw32_bdf_filename_alist
;
6620 ptnstr
= XSTRING (pattern
)->data
;
6622 for ( ; CONSP (list
); list
= XCDR (list
))
6626 fontname
= XSTRING (XCAR (tem
))->data
;
6627 else if (STRINGP (tem
))
6628 fontname
= XSTRING (tem
)->data
;
6632 if (w32_font_match (fontname
, ptnstr
))
6634 newlist
= Fcons (XCAR (tem
), newlist
);
6636 if (n_fonts
>= max_names
)
6644 Lisp_Object
w32_list_synthesized_fonts (FRAME_PTR f
, Lisp_Object pattern
,
6645 int size
, int max_names
);
6647 /* Return a list of names of available fonts matching PATTERN on frame
6648 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6649 to be listed. Frame F NULL means we have not yet created any
6650 frame, which means we can't get proper size info, as we don't have
6651 a device context to use for GetTextMetrics.
6652 MAXNAMES sets a limit on how many fonts to match. */
6655 w32_list_fonts (FRAME_PTR f
, Lisp_Object pattern
, int size
, int maxnames
)
6657 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6658 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6659 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6662 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6663 if (NILP (patterns
))
6664 patterns
= Fcons (pattern
, Qnil
);
6666 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6671 tpat
= XCAR (patterns
);
6673 if (!STRINGP (tpat
))
6676 /* Avoid expensive EnumFontFamilies functions if we are not
6677 going to be able to output one of these anyway. */
6678 codepage
= w32_codepage_for_font (XSTRING (tpat
)->data
);
6679 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6680 && codepage
!= CP_DEFAULT
&& !IsValidCodePage(codepage
))
6683 /* See if we cached the result for this particular query.
6684 The cache is an alist of the form:
6685 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6687 if (tem
= XCDR (dpyinfo
->name_list_element
),
6688 !NILP (list
= Fassoc (tpat
, tem
)))
6690 list
= Fcdr_safe (list
);
6691 /* We have a cached list. Don't have to get the list again. */
6696 /* At first, put PATTERN in the cache. */
6702 /* Use EnumFontFamiliesEx where it is available, as it knows
6703 about character sets. Fall back to EnumFontFamilies for
6704 older versions of NT that don't support the 'Ex function. */
6705 x_to_w32_font (XSTRING (tpat
)->data
, &ef
.logfont
);
6707 LOGFONT font_match_pattern
;
6708 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6709 FARPROC enum_font_families_ex
6710 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6712 /* We do our own pattern matching so we can handle wildcards. */
6713 font_match_pattern
.lfFaceName
[0] = 0;
6714 font_match_pattern
.lfPitchAndFamily
= 0;
6715 /* We can use the charset, because if it is a wildcard it will
6716 be DEFAULT_CHARSET anyway. */
6717 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6719 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6721 if (enum_font_families_ex
)
6722 enum_font_families_ex (ef
.hdc
,
6723 &font_match_pattern
,
6724 (FONTENUMPROC
) enum_fontex_cb1
,
6727 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6730 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6735 /* Make a list of the fonts we got back.
6736 Store that in the font cache for the display. */
6737 XCDR (dpyinfo
->name_list_element
)
6738 = Fcons (Fcons (tpat
, list
),
6739 XCDR (dpyinfo
->name_list_element
));
6742 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6744 newlist
= second_best
= Qnil
;
6746 /* Make a list of the fonts that have the right width. */
6747 for (; CONSP (list
); list
= XCDR (list
))
6754 if (NILP (XCAR (tem
)))
6758 newlist
= Fcons (XCAR (tem
), newlist
);
6760 if (n_fonts
>= maxnames
)
6765 if (!INTEGERP (XCDR (tem
)))
6767 /* Since we don't yet know the size of the font, we must
6768 load it and try GetTextMetrics. */
6769 W32FontStruct thisinfo
;
6774 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
6778 thisinfo
.bdf
= NULL
;
6779 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6780 if (thisinfo
.hfont
== NULL
)
6783 hdc
= GetDC (dpyinfo
->root_window
);
6784 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6785 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6786 XCDR (tem
) = make_number (FONT_WIDTH (&thisinfo
));
6788 XCDR (tem
) = make_number (0);
6789 SelectObject (hdc
, oldobj
);
6790 ReleaseDC (dpyinfo
->root_window
, hdc
);
6791 DeleteObject(thisinfo
.hfont
);
6794 found_size
= XINT (XCDR (tem
));
6795 if (found_size
== size
)
6797 newlist
= Fcons (XCAR (tem
), newlist
);
6799 if (n_fonts
>= maxnames
)
6802 /* keep track of the closest matching size in case
6803 no exact match is found. */
6804 else if (found_size
> 0)
6806 if (NILP (second_best
))
6809 else if (found_size
< size
)
6811 if (XINT (XCDR (second_best
)) > size
6812 || XINT (XCDR (second_best
)) < found_size
)
6817 if (XINT (XCDR (second_best
)) > size
6818 && XINT (XCDR (second_best
)) >
6825 if (!NILP (newlist
))
6827 else if (!NILP (second_best
))
6829 newlist
= Fcons (XCAR (second_best
), Qnil
);
6834 /* Include any bdf fonts. */
6835 if (n_fonts
< maxnames
)
6837 Lisp_Object combined
[2];
6838 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6839 combined
[1] = newlist
;
6840 newlist
= Fnconc(2, combined
);
6843 /* If we can't find a font that matches, check if Windows would be
6844 able to synthesize it from a different style. */
6845 if (NILP (newlist
) && !NILP (Vw32_enable_synthesized_fonts
))
6846 newlist
= w32_list_synthesized_fonts (f
, pattern
, size
, maxnames
);
6852 w32_list_synthesized_fonts (f
, pattern
, size
, max_names
)
6854 Lisp_Object pattern
;
6859 char *full_pattn
, *new_pattn
, foundary
[50], family
[50], *pattn_part2
;
6860 char style
[20], slant
;
6861 Lisp_Object matches
, match
, tem
, synthed_matches
= Qnil
;
6863 full_pattn
= XSTRING (pattern
)->data
;
6865 pattn_part2
= alloca (XSTRING (pattern
)->size
);
6866 /* Allow some space for wildcard expansion. */
6867 new_pattn
= alloca (XSTRING (pattern
)->size
+ 100);
6869 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%19[^-]-%c-%s",
6870 foundary
, family
, style
, &slant
, pattn_part2
);
6871 if (fields
== EOF
|| fields
< 5)
6874 /* If the style and slant are wildcards already there is no point
6875 checking again (and we don't want to keep recursing). */
6876 if (*style
== '*' && slant
== '*')
6879 sprintf (new_pattn
, "-%s-%s-*-*-%s", foundary
, family
, pattn_part2
);
6881 matches
= w32_list_fonts (f
, build_string (new_pattn
), size
, max_names
);
6883 for ( ; CONSP (matches
); matches
= XCDR (matches
))
6885 tem
= XCAR (matches
);
6889 full_pattn
= XSTRING (tem
)->data
;
6890 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%*[^-]-%*c-%s",
6891 foundary
, family
, pattn_part2
);
6892 if (fields
== EOF
|| fields
< 3)
6895 sprintf (new_pattn
, "-%s-%s-%s-%c-%s", foundary
, family
, style
,
6896 slant
, pattn_part2
);
6898 synthed_matches
= Fcons (build_string (new_pattn
),
6902 return synthed_matches
;
6906 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6908 w32_get_font_info (f
, font_idx
)
6912 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6917 w32_query_font (struct frame
*f
, char *fontname
)
6920 struct font_info
*pfi
;
6922 pfi
= FRAME_W32_FONT_TABLE (f
);
6924 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6926 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
6932 /* Find a CCL program for a font specified by FONTP, and set the member
6933 `encoder' of the structure. */
6936 w32_find_ccl_program (fontp
)
6937 struct font_info
*fontp
;
6939 Lisp_Object list
, elt
;
6941 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6945 && STRINGP (XCAR (elt
))
6946 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6952 struct ccl_program
*ccl
6953 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6955 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6958 fontp
->font_encoder
= ccl
;
6963 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6965 "Return a list of BDF fonts in DIR, suitable for appending to\n\
6966 w32-bdf-filename-alist. Fonts which do not contain an xlfd description\n\
6967 will not be included in the list. DIR may be a list of directories.")
6969 Lisp_Object directory
;
6971 Lisp_Object list
= Qnil
;
6972 struct gcpro gcpro1
, gcpro2
;
6974 if (!CONSP (directory
))
6975 return w32_find_bdf_fonts_in_dir (directory
);
6977 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6979 Lisp_Object pair
[2];
6982 GCPRO2 (directory
, list
);
6983 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6984 list
= Fnconc( 2, pair
);
6990 /* Find BDF files in a specified directory. (use GCPRO when calling,
6991 as this calls lisp to get a directory listing). */
6992 Lisp_Object
w32_find_bdf_fonts_in_dir( Lisp_Object directory
)
6994 Lisp_Object filelist
, list
= Qnil
;
6997 if (!STRINGP(directory
))
7000 filelist
= Fdirectory_files (directory
, Qt
,
7001 build_string (".*\\.[bB][dD][fF]"), Qt
);
7003 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
7005 Lisp_Object filename
= XCAR (filelist
);
7006 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
7007 store_in_alist (&list
, build_string (fontname
), filename
);
7013 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
7014 "Internal function called by `color-defined-p', which see.")
7016 Lisp_Object color
, frame
;
7019 FRAME_PTR f
= check_x_frame (frame
);
7021 CHECK_STRING (color
, 1);
7023 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7029 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
7030 "Internal function called by `color-values', which see.")
7032 Lisp_Object color
, frame
;
7035 FRAME_PTR f
= check_x_frame (frame
);
7037 CHECK_STRING (color
, 1);
7039 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7043 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
7044 | GetRValue (foo
.pixel
));
7045 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
7046 | GetGValue (foo
.pixel
));
7047 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
7048 | GetBValue (foo
.pixel
));
7049 return Flist (3, rgb
);
7055 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
7056 "Internal function called by `display-color-p', which see.")
7058 Lisp_Object display
;
7060 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7062 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
7068 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
7070 "Return t if the X display supports shades of gray.\n\
7071 Note that color displays do support shades of gray.\n\
7072 The optional argument DISPLAY specifies which display to ask about.\n\
7073 DISPLAY should be either a frame or a display name (a string).\n\
7074 If omitted or nil, that stands for the selected frame's display.")
7076 Lisp_Object display
;
7078 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7080 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
7086 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
7088 "Returns the width in pixels of the X display DISPLAY.\n\
7089 The optional argument DISPLAY specifies which display to ask about.\n\
7090 DISPLAY should be either a frame or a display name (a string).\n\
7091 If omitted or nil, that stands for the selected frame's display.")
7093 Lisp_Object display
;
7095 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7097 return make_number (dpyinfo
->width
);
7100 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
7101 Sx_display_pixel_height
, 0, 1, 0,
7102 "Returns the height in pixels of the X display DISPLAY.\n\
7103 The optional argument DISPLAY specifies which display to ask about.\n\
7104 DISPLAY should be either a frame or a display name (a string).\n\
7105 If omitted or nil, that stands for the selected frame's display.")
7107 Lisp_Object display
;
7109 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7111 return make_number (dpyinfo
->height
);
7114 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
7116 "Returns the number of bitplanes of the display DISPLAY.\n\
7117 The optional argument DISPLAY specifies which display to ask about.\n\
7118 DISPLAY should be either a frame or a display name (a string).\n\
7119 If omitted or nil, that stands for the selected frame's display.")
7121 Lisp_Object display
;
7123 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7125 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7128 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
7130 "Returns the number of color cells of the display DISPLAY.\n\
7131 The optional argument DISPLAY specifies which display to ask about.\n\
7132 DISPLAY should be either a frame or a display name (a string).\n\
7133 If omitted or nil, that stands for the selected frame's display.")
7135 Lisp_Object display
;
7137 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7141 hdc
= GetDC (dpyinfo
->root_window
);
7142 if (dpyinfo
->has_palette
)
7143 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
7145 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
7147 ReleaseDC (dpyinfo
->root_window
, hdc
);
7149 return make_number (cap
);
7152 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
7153 Sx_server_max_request_size
,
7155 "Returns the maximum request size of the server of display DISPLAY.\n\
7156 The optional argument DISPLAY specifies which display to ask about.\n\
7157 DISPLAY should be either a frame or a display name (a string).\n\
7158 If omitted or nil, that stands for the selected frame's display.")
7160 Lisp_Object display
;
7162 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7164 return make_number (1);
7167 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
7168 "Returns the vendor ID string of the W32 system (Microsoft).\n\
7169 The optional argument DISPLAY specifies which display to ask about.\n\
7170 DISPLAY should be either a frame or a display name (a string).\n\
7171 If omitted or nil, that stands for the selected frame's display.")
7173 Lisp_Object display
;
7175 return build_string ("Microsoft Corp.");
7178 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
7179 "Returns the version numbers of the server of display DISPLAY.\n\
7180 The value is a list of three integers: the major and minor\n\
7181 version numbers, and the vendor-specific release\n\
7182 number. See also the function `x-server-vendor'.\n\n\
7183 The optional argument DISPLAY specifies which display to ask about.\n\
7184 DISPLAY should be either a frame or a display name (a string).\n\
7185 If omitted or nil, that stands for the selected frame's display.")
7187 Lisp_Object display
;
7189 return Fcons (make_number (w32_major_version
),
7190 Fcons (make_number (w32_minor_version
),
7191 Fcons (make_number (w32_build_number
), Qnil
)));
7194 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
7195 "Returns the number of screens on the server of display DISPLAY.\n\
7196 The optional argument DISPLAY specifies which display to ask about.\n\
7197 DISPLAY should be either a frame or a display name (a string).\n\
7198 If omitted or nil, that stands for the selected frame's display.")
7200 Lisp_Object display
;
7202 return make_number (1);
7205 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
7206 "Returns the height in millimeters of the X display DISPLAY.\n\
7207 The optional argument DISPLAY specifies which display to ask about.\n\
7208 DISPLAY should be either a frame or a display name (a string).\n\
7209 If omitted or nil, that stands for the selected frame's display.")
7211 Lisp_Object display
;
7213 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7217 hdc
= GetDC (dpyinfo
->root_window
);
7219 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
7221 ReleaseDC (dpyinfo
->root_window
, hdc
);
7223 return make_number (cap
);
7226 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
7227 "Returns the width in millimeters of the X display DISPLAY.\n\
7228 The optional argument DISPLAY specifies which display to ask about.\n\
7229 DISPLAY should be either a frame or a display name (a string).\n\
7230 If omitted or nil, that stands for the selected frame's display.")
7232 Lisp_Object display
;
7234 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7239 hdc
= GetDC (dpyinfo
->root_window
);
7241 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
7243 ReleaseDC (dpyinfo
->root_window
, hdc
);
7245 return make_number (cap
);
7248 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
7249 Sx_display_backing_store
, 0, 1, 0,
7250 "Returns an indication of whether display DISPLAY does backing store.\n\
7251 The value may be `always', `when-mapped', or `not-useful'.\n\
7252 The optional argument DISPLAY specifies which display to ask about.\n\
7253 DISPLAY should be either a frame or a display name (a string).\n\
7254 If omitted or nil, that stands for the selected frame's display.")
7256 Lisp_Object display
;
7258 return intern ("not-useful");
7261 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
7262 Sx_display_visual_class
, 0, 1, 0,
7263 "Returns the visual class of the display DISPLAY.\n\
7264 The value is one of the symbols `static-gray', `gray-scale',\n\
7265 `static-color', `pseudo-color', `true-color', or `direct-color'.\n\n\
7266 The optional argument DISPLAY specifies which display to ask about.\n\
7267 DISPLAY should be either a frame or a display name (a string).\n\
7268 If omitted or nil, that stands for the selected frame's display.")
7270 Lisp_Object display
;
7272 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7275 switch (dpyinfo
->visual
->class)
7277 case StaticGray
: return (intern ("static-gray"));
7278 case GrayScale
: return (intern ("gray-scale"));
7279 case StaticColor
: return (intern ("static-color"));
7280 case PseudoColor
: return (intern ("pseudo-color"));
7281 case TrueColor
: return (intern ("true-color"));
7282 case DirectColor
: return (intern ("direct-color"));
7284 error ("Display has an unknown visual class");
7288 error ("Display has an unknown visual class");
7291 DEFUN ("x-display-save-under", Fx_display_save_under
,
7292 Sx_display_save_under
, 0, 1, 0,
7293 "Returns t if the display DISPLAY supports the save-under feature.\n\
7294 The optional argument DISPLAY specifies which display to ask about.\n\
7295 DISPLAY should be either a frame or a display name (a string).\n\
7296 If omitted or nil, that stands for the selected frame's display.")
7298 Lisp_Object display
;
7305 register struct frame
*f
;
7307 return PIXEL_WIDTH (f
);
7312 register struct frame
*f
;
7314 return PIXEL_HEIGHT (f
);
7319 register struct frame
*f
;
7321 return FONT_WIDTH (f
->output_data
.w32
->font
);
7326 register struct frame
*f
;
7328 return f
->output_data
.w32
->line_height
;
7333 register struct frame
*f
;
7335 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
7338 /* Return the display structure for the display named NAME.
7339 Open a new connection if necessary. */
7341 struct w32_display_info
*
7342 x_display_info_for_name (name
)
7346 struct w32_display_info
*dpyinfo
;
7348 CHECK_STRING (name
, 0);
7350 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
7352 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
7355 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
7360 /* Use this general default value to start with. */
7361 Vx_resource_name
= Vinvocation_name
;
7363 validate_x_resource_name ();
7365 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
7366 (char *) XSTRING (Vx_resource_name
)->data
);
7369 error ("Cannot connect to server %s", XSTRING (name
)->data
);
7372 XSETFASTINT (Vwindow_system_version
, 3);
7377 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
7378 1, 3, 0, "Open a connection to a server.\n\
7379 DISPLAY is the name of the display to connect to.\n\
7380 Optional second arg XRM-STRING is a string of resources in xrdb format.\n\
7381 If the optional third arg MUST-SUCCEED is non-nil,\n\
7382 terminate Emacs if we can't open the connection.")
7383 (display
, xrm_string
, must_succeed
)
7384 Lisp_Object display
, xrm_string
, must_succeed
;
7386 unsigned char *xrm_option
;
7387 struct w32_display_info
*dpyinfo
;
7389 CHECK_STRING (display
, 0);
7390 if (! NILP (xrm_string
))
7391 CHECK_STRING (xrm_string
, 1);
7393 if (! EQ (Vwindow_system
, intern ("w32")))
7394 error ("Not using Microsoft Windows");
7396 /* Allow color mapping to be defined externally; first look in user's
7397 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
7399 Lisp_Object color_file
;
7400 struct gcpro gcpro1
;
7402 color_file
= build_string("~/rgb.txt");
7404 GCPRO1 (color_file
);
7406 if (NILP (Ffile_readable_p (color_file
)))
7408 Fexpand_file_name (build_string ("rgb.txt"),
7409 Fsymbol_value (intern ("data-directory")));
7411 Vw32_color_map
= Fw32_load_color_file (color_file
);
7415 if (NILP (Vw32_color_map
))
7416 Vw32_color_map
= Fw32_default_color_map ();
7418 if (! NILP (xrm_string
))
7419 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
7421 xrm_option
= (unsigned char *) 0;
7423 /* Use this general default value to start with. */
7424 /* First remove .exe suffix from invocation-name - it looks ugly. */
7426 char basename
[ MAX_PATH
], *str
;
7428 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
7429 str
= strrchr (basename
, '.');
7431 Vinvocation_name
= build_string (basename
);
7433 Vx_resource_name
= Vinvocation_name
;
7435 validate_x_resource_name ();
7437 /* This is what opens the connection and sets x_current_display.
7438 This also initializes many symbols, such as those used for input. */
7439 dpyinfo
= w32_term_init (display
, xrm_option
,
7440 (char *) XSTRING (Vx_resource_name
)->data
);
7444 if (!NILP (must_succeed
))
7445 fatal ("Cannot connect to server %s.\n",
7446 XSTRING (display
)->data
);
7448 error ("Cannot connect to server %s", XSTRING (display
)->data
);
7453 XSETFASTINT (Vwindow_system_version
, 3);
7457 DEFUN ("x-close-connection", Fx_close_connection
,
7458 Sx_close_connection
, 1, 1, 0,
7459 "Close the connection to DISPLAY's server.\n\
7460 For DISPLAY, specify either a frame or a display name (a string).\n\
7461 If DISPLAY is nil, that stands for the selected frame's display.")
7463 Lisp_Object display
;
7465 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7468 if (dpyinfo
->reference_count
> 0)
7469 error ("Display still has frames on it");
7472 /* Free the fonts in the font table. */
7473 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7474 if (dpyinfo
->font_table
[i
].name
)
7476 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7477 xfree (dpyinfo
->font_table
[i
].full_name
);
7478 xfree (dpyinfo
->font_table
[i
].name
);
7479 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7481 x_destroy_all_bitmaps (dpyinfo
);
7483 x_delete_display (dpyinfo
);
7489 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7490 "Return the list of display names that Emacs has connections to.")
7493 Lisp_Object tail
, result
;
7496 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
7497 result
= Fcons (XCAR (XCAR (tail
)), result
);
7502 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7503 "If ON is non-nil, report errors as soon as the erring request is made.\n\
7504 If ON is nil, allow buffering of requests.\n\
7505 This is a noop on W32 systems.\n\
7506 The optional second argument DISPLAY specifies which display to act on.\n\
7507 DISPLAY should be either a frame or a display name (a string).\n\
7508 If DISPLAY is omitted or nil, that stands for the selected frame's display.")
7510 Lisp_Object display
, on
;
7517 /***********************************************************************
7519 ***********************************************************************/
7521 /* Value is the number of elements of vector VECTOR. */
7523 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
7525 /* List of supported image types. Use define_image_type to add new
7526 types. Use lookup_image_type to find a type for a given symbol. */
7528 static struct image_type
*image_types
;
7530 /* The symbol `image' which is the car of the lists used to represent
7533 extern Lisp_Object Qimage
;
7535 /* The symbol `xbm' which is used as the type symbol for XBM images. */
7541 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
7542 extern Lisp_Object QCdata
;
7543 Lisp_Object QCtype
, QCascent
, QCmargin
, QCrelief
;
7544 Lisp_Object QCalgorithm
, QCcolor_symbols
, QCheuristic_mask
;
7545 Lisp_Object QCindex
;
7547 /* Other symbols. */
7549 Lisp_Object Qlaplace
;
7551 /* Time in seconds after which images should be removed from the cache
7552 if not displayed. */
7554 Lisp_Object Vimage_cache_eviction_delay
;
7556 /* Function prototypes. */
7558 static void define_image_type
P_ ((struct image_type
*type
));
7559 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
7560 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
7561 static void x_laplace
P_ ((struct frame
*, struct image
*));
7562 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
7566 /* Define a new image type from TYPE. This adds a copy of TYPE to
7567 image_types and adds the symbol *TYPE->type to Vimage_types. */
7570 define_image_type (type
)
7571 struct image_type
*type
;
7573 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
7574 The initialized data segment is read-only. */
7575 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
7576 bcopy (type
, p
, sizeof *p
);
7577 p
->next
= image_types
;
7579 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
7583 /* Look up image type SYMBOL, and return a pointer to its image_type
7584 structure. Value is null if SYMBOL is not a known image type. */
7586 static INLINE
struct image_type
*
7587 lookup_image_type (symbol
)
7590 struct image_type
*type
;
7592 for (type
= image_types
; type
; type
= type
->next
)
7593 if (EQ (symbol
, *type
->type
))
7600 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
7601 valid image specification is a list whose car is the symbol
7602 `image', and whose rest is a property list. The property list must
7603 contain a value for key `:type'. That value must be the name of a
7604 supported image type. The rest of the property list depends on the
7608 valid_image_p (object
)
7613 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
7615 Lisp_Object symbol
= Fplist_get (XCDR (object
), QCtype
);
7616 struct image_type
*type
= lookup_image_type (symbol
);
7619 valid_p
= type
->valid_p (object
);
7626 /* Log error message with format string FORMAT and argument ARG.
7627 Signaling an error, e.g. when an image cannot be loaded, is not a
7628 good idea because this would interrupt redisplay, and the error
7629 message display would lead to another redisplay. This function
7630 therefore simply displays a message. */
7633 image_error (format
, arg1
, arg2
)
7635 Lisp_Object arg1
, arg2
;
7637 add_to_log (format
, arg1
, arg2
);
7642 /***********************************************************************
7643 Image specifications
7644 ***********************************************************************/
7646 enum image_value_type
7648 IMAGE_DONT_CHECK_VALUE_TYPE
,
7651 IMAGE_POSITIVE_INTEGER_VALUE
,
7652 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
7654 IMAGE_INTEGER_VALUE
,
7655 IMAGE_FUNCTION_VALUE
,
7660 /* Structure used when parsing image specifications. */
7662 struct image_keyword
7664 /* Name of keyword. */
7667 /* The type of value allowed. */
7668 enum image_value_type type
;
7670 /* Non-zero means key must be present. */
7673 /* Used to recognize duplicate keywords in a property list. */
7676 /* The value that was found. */
7681 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
7683 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
7686 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
7687 has the format (image KEYWORD VALUE ...). One of the keyword/
7688 value pairs must be `:type TYPE'. KEYWORDS is a vector of
7689 image_keywords structures of size NKEYWORDS describing other
7690 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
7693 parse_image_spec (spec
, keywords
, nkeywords
, type
)
7695 struct image_keyword
*keywords
;
7702 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
7705 plist
= XCDR (spec
);
7706 while (CONSP (plist
))
7708 Lisp_Object key
, value
;
7710 /* First element of a pair must be a symbol. */
7712 plist
= XCDR (plist
);
7716 /* There must follow a value. */
7719 value
= XCAR (plist
);
7720 plist
= XCDR (plist
);
7722 /* Find key in KEYWORDS. Error if not found. */
7723 for (i
= 0; i
< nkeywords
; ++i
)
7724 if (strcmp (keywords
[i
].name
, XSYMBOL (key
)->name
->data
) == 0)
7730 /* Record that we recognized the keyword. If a keywords
7731 was found more than once, it's an error. */
7732 keywords
[i
].value
= value
;
7733 ++keywords
[i
].count
;
7735 if (keywords
[i
].count
> 1)
7738 /* Check type of value against allowed type. */
7739 switch (keywords
[i
].type
)
7741 case IMAGE_STRING_VALUE
:
7742 if (!STRINGP (value
))
7746 case IMAGE_SYMBOL_VALUE
:
7747 if (!SYMBOLP (value
))
7751 case IMAGE_POSITIVE_INTEGER_VALUE
:
7752 if (!INTEGERP (value
) || XINT (value
) <= 0)
7756 case IMAGE_ASCENT_VALUE
:
7757 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
7759 else if (INTEGERP (value
)
7760 && XINT (value
) >= 0
7761 && XINT (value
) <= 100)
7765 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
7766 if (!INTEGERP (value
) || XINT (value
) < 0)
7770 case IMAGE_DONT_CHECK_VALUE_TYPE
:
7773 case IMAGE_FUNCTION_VALUE
:
7774 value
= indirect_function (value
);
7776 || COMPILEDP (value
)
7777 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
7781 case IMAGE_NUMBER_VALUE
:
7782 if (!INTEGERP (value
) && !FLOATP (value
))
7786 case IMAGE_INTEGER_VALUE
:
7787 if (!INTEGERP (value
))
7791 case IMAGE_BOOL_VALUE
:
7792 if (!NILP (value
) && !EQ (value
, Qt
))
7801 if (EQ (key
, QCtype
) && !EQ (type
, value
))
7805 /* Check that all mandatory fields are present. */
7806 for (i
= 0; i
< nkeywords
; ++i
)
7807 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
7810 return NILP (plist
);
7814 /* Return the value of KEY in image specification SPEC. Value is nil
7815 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
7816 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
7819 image_spec_value (spec
, key
, found
)
7820 Lisp_Object spec
, key
;
7825 xassert (valid_image_p (spec
));
7827 for (tail
= XCDR (spec
);
7828 CONSP (tail
) && CONSP (XCDR (tail
));
7829 tail
= XCDR (XCDR (tail
)))
7831 if (EQ (XCAR (tail
), key
))
7835 return XCAR (XCDR (tail
));
7847 /***********************************************************************
7848 Image type independent image structures
7849 ***********************************************************************/
7851 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
7852 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
7855 /* Allocate and return a new image structure for image specification
7856 SPEC. SPEC has a hash value of HASH. */
7858 static struct image
*
7859 make_image (spec
, hash
)
7863 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
7865 xassert (valid_image_p (spec
));
7866 bzero (img
, sizeof *img
);
7867 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
7868 xassert (img
->type
!= NULL
);
7870 img
->data
.lisp_val
= Qnil
;
7871 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
7877 /* Free image IMG which was used on frame F, including its resources. */
7886 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7888 /* Remove IMG from the hash table of its cache. */
7890 img
->prev
->next
= img
->next
;
7892 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
7895 img
->next
->prev
= img
->prev
;
7897 c
->images
[img
->id
] = NULL
;
7899 /* Free resources, then free IMG. */
7900 img
->type
->free (f
, img
);
7906 /* Prepare image IMG for display on frame F. Must be called before
7907 drawing an image. */
7910 prepare_image_for_display (f
, img
)
7916 /* We're about to display IMG, so set its timestamp to `now'. */
7918 img
->timestamp
= EMACS_SECS (t
);
7920 /* If IMG doesn't have a pixmap yet, load it now, using the image
7921 type dependent loader function. */
7922 if (img
->pixmap
== 0 && !img
->load_failed_p
)
7923 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
7927 /* Value is the number of pixels for the ascent of image IMG when
7928 drawn in face FACE. */
7931 image_ascent (img
, face
)
7935 int height
= img
->height
+ img
->margin
;
7938 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
7941 ascent
= height
/ 2 - (FONT_DESCENT(face
->font
)
7942 - FONT_BASE(face
->font
)) / 2;
7944 ascent
= height
/ 2;
7947 ascent
= height
* img
->ascent
/ 100.0;
7954 /***********************************************************************
7955 Helper functions for X image types
7956 ***********************************************************************/
7958 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
7959 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
7961 Lisp_Object color_name
,
7962 unsigned long dflt
));
7964 /* Free X resources of image IMG which is used on frame F. */
7967 x_clear_image (f
, img
)
7971 #if 0 /* TODO: W32 image support */
7976 XFreePixmap (NULL
, img
->pixmap
);
7983 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
7985 /* If display has an immutable color map, freeing colors is not
7986 necessary and some servers don't allow it. So don't do it. */
7987 if (class != StaticColor
7988 && class != StaticGray
7989 && class != TrueColor
)
7993 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
7994 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
7999 xfree (img
->colors
);
8007 /* Allocate color COLOR_NAME for image IMG on frame F. If color
8008 cannot be allocated, use DFLT. Add a newly allocated color to
8009 IMG->colors, so that it can be freed again. Value is the pixel
8012 static unsigned long
8013 x_alloc_image_color (f
, img
, color_name
, dflt
)
8016 Lisp_Object color_name
;
8019 #if 0 /* TODO: allocing colors. */
8021 unsigned long result
;
8023 xassert (STRINGP (color_name
));
8025 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
8027 /* This isn't called frequently so we get away with simply
8028 reallocating the color vector to the needed size, here. */
8031 (unsigned long *) xrealloc (img
->colors
,
8032 img
->ncolors
* sizeof *img
->colors
);
8033 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
8034 result
= color
.pixel
;
8045 /***********************************************************************
8047 ***********************************************************************/
8049 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
8052 /* Return a new, initialized image cache that is allocated from the
8053 heap. Call free_image_cache to free an image cache. */
8055 struct image_cache
*
8058 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
8061 bzero (c
, sizeof *c
);
8063 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
8064 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
8065 c
->buckets
= (struct image
**) xmalloc (size
);
8066 bzero (c
->buckets
, size
);
8071 /* Free image cache of frame F. Be aware that X frames share images
8075 free_image_cache (f
)
8078 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8083 /* Cache should not be referenced by any frame when freed. */
8084 xassert (c
->refcount
== 0);
8086 for (i
= 0; i
< c
->used
; ++i
)
8087 free_image (f
, c
->images
[i
]);
8091 FRAME_X_IMAGE_CACHE (f
) = NULL
;
8096 /* Clear image cache of frame F. FORCE_P non-zero means free all
8097 images. FORCE_P zero means clear only images that haven't been
8098 displayed for some time. Should be called from time to time to
8099 reduce the number of loaded images. If image-eviction-seconds is
8100 non-nil, this frees images in the cache which weren't displayed for
8101 at least that many seconds. */
8104 clear_image_cache (f
, force_p
)
8108 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8110 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
8114 int i
, any_freed_p
= 0;
8117 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
8119 for (i
= 0; i
< c
->used
; ++i
)
8121 struct image
*img
= c
->images
[i
];
8124 || (img
->timestamp
> old
)))
8126 free_image (f
, img
);
8131 /* We may be clearing the image cache because, for example,
8132 Emacs was iconified for a longer period of time. In that
8133 case, current matrices may still contain references to
8134 images freed above. So, clear these matrices. */
8137 clear_current_matrices (f
);
8138 ++windows_or_buffers_changed
;
8144 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
8146 "Clear the image cache of FRAME.\n\
8147 FRAME nil or omitted means use the selected frame.\n\
8148 FRAME t means clear the image caches of all frames.")
8156 FOR_EACH_FRAME (tail
, frame
)
8157 if (FRAME_W32_P (XFRAME (frame
)))
8158 clear_image_cache (XFRAME (frame
), 1);
8161 clear_image_cache (check_x_frame (frame
), 1);
8167 /* Return the id of image with Lisp specification SPEC on frame F.
8168 SPEC must be a valid Lisp image specification (see valid_image_p). */
8171 lookup_image (f
, spec
)
8175 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8179 struct gcpro gcpro1
;
8182 /* F must be a window-system frame, and SPEC must be a valid image
8184 xassert (FRAME_WINDOW_P (f
));
8185 xassert (valid_image_p (spec
));
8189 /* Look up SPEC in the hash table of the image cache. */
8190 hash
= sxhash (spec
, 0);
8191 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8193 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
8194 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
8197 /* If not found, create a new image and cache it. */
8200 img
= make_image (spec
, hash
);
8201 cache_image (f
, img
);
8202 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8203 xassert (!interrupt_input_blocked
);
8205 /* If we can't load the image, and we don't have a width and
8206 height, use some arbitrary width and height so that we can
8207 draw a rectangle for it. */
8208 if (img
->load_failed_p
)
8212 value
= image_spec_value (spec
, QCwidth
, NULL
);
8213 img
->width
= (INTEGERP (value
)
8214 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
8215 value
= image_spec_value (spec
, QCheight
, NULL
);
8216 img
->height
= (INTEGERP (value
)
8217 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
8221 /* Handle image type independent image attributes
8222 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF'. */
8223 Lisp_Object ascent
, margin
, relief
, algorithm
, heuristic_mask
;
8226 ascent
= image_spec_value (spec
, QCascent
, NULL
);
8227 if (INTEGERP (ascent
))
8228 img
->ascent
= XFASTINT (ascent
);
8229 else if (EQ (ascent
, Qcenter
))
8230 img
->ascent
= CENTERED_IMAGE_ASCENT
;
8232 margin
= image_spec_value (spec
, QCmargin
, NULL
);
8233 if (INTEGERP (margin
) && XINT (margin
) >= 0)
8234 img
->margin
= XFASTINT (margin
);
8236 relief
= image_spec_value (spec
, QCrelief
, NULL
);
8237 if (INTEGERP (relief
))
8239 img
->relief
= XINT (relief
);
8240 img
->margin
+= abs (img
->relief
);
8243 /* Should we apply a Laplace edge-detection algorithm? */
8244 algorithm
= image_spec_value (spec
, QCalgorithm
, NULL
);
8245 if (img
->pixmap
&& EQ (algorithm
, Qlaplace
))
8248 /* Should we built a mask heuristically? */
8249 heuristic_mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
8250 if (img
->pixmap
&& !img
->mask
&& !NILP (heuristic_mask
))
8251 x_build_heuristic_mask (f
, img
, heuristic_mask
);
8255 /* We're using IMG, so set its timestamp to `now'. */
8256 EMACS_GET_TIME (now
);
8257 img
->timestamp
= EMACS_SECS (now
);
8261 /* Value is the image id. */
8266 /* Cache image IMG in the image cache of frame F. */
8269 cache_image (f
, img
)
8273 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8276 /* Find a free slot in c->images. */
8277 for (i
= 0; i
< c
->used
; ++i
)
8278 if (c
->images
[i
] == NULL
)
8281 /* If no free slot found, maybe enlarge c->images. */
8282 if (i
== c
->used
&& c
->used
== c
->size
)
8285 c
->images
= (struct image
**) xrealloc (c
->images
,
8286 c
->size
* sizeof *c
->images
);
8289 /* Add IMG to c->images, and assign IMG an id. */
8295 /* Add IMG to the cache's hash table. */
8296 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8297 img
->next
= c
->buckets
[i
];
8299 img
->next
->prev
= img
;
8301 c
->buckets
[i
] = img
;
8305 /* Call FN on every image in the image cache of frame F. Used to mark
8306 Lisp Objects in the image cache. */
8309 forall_images_in_image_cache (f
, fn
)
8311 void (*fn
) P_ ((struct image
*img
));
8313 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
8315 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8319 for (i
= 0; i
< c
->used
; ++i
)
8328 /***********************************************************************
8330 ***********************************************************************/
8332 #if 0 /* TODO: W32 specific image code. */
8334 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
8335 XImage
**, Pixmap
*));
8336 static void x_destroy_x_image
P_ ((XImage
*));
8337 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
8340 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
8341 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
8342 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
8343 via xmalloc. Print error messages via image_error if an error
8344 occurs. Value is non-zero if successful. */
8347 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
8349 int width
, height
, depth
;
8353 #if 0 /* TODO: Image support for W32 */
8354 Display
*display
= FRAME_W32_DISPLAY (f
);
8355 Screen
*screen
= FRAME_X_SCREEN (f
);
8356 Window window
= FRAME_W32_WINDOW (f
);
8358 xassert (interrupt_input_blocked
);
8361 depth
= DefaultDepthOfScreen (screen
);
8362 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
8363 depth
, ZPixmap
, 0, NULL
, width
, height
,
8364 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
8367 image_error ("Unable to allocate X image", Qnil
, Qnil
);
8371 /* Allocate image raster. */
8372 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
8374 /* Allocate a pixmap of the same size. */
8375 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
8378 x_destroy_x_image (*ximg
);
8380 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
8388 /* Destroy XImage XIMG. Free XIMG->data. */
8391 x_destroy_x_image (ximg
)
8394 xassert (interrupt_input_blocked
);
8399 XDestroyImage (ximg
);
8404 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
8405 are width and height of both the image and pixmap. */
8408 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
8415 xassert (interrupt_input_blocked
);
8416 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
8417 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
8424 /***********************************************************************
8426 ***********************************************************************/
8428 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
8430 /* Find image file FILE. Look in data-directory, then
8431 x-bitmap-file-path. Value is the full name of the file found, or
8432 nil if not found. */
8435 x_find_image_file (file
)
8438 Lisp_Object file_found
, search_path
;
8439 struct gcpro gcpro1
, gcpro2
;
8443 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
8444 GCPRO2 (file_found
, search_path
);
8446 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
8447 fd
= openp (search_path
, file
, "", &file_found
, 0);
8460 /***********************************************************************
8462 ***********************************************************************/
8464 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
8465 static int xbm_load_image_from_file
P_ ((struct frame
*f
, struct image
*img
,
8467 static int xbm_image_p
P_ ((Lisp_Object object
));
8468 static int xbm_read_bitmap_file_data
P_ ((char *, int *, int *,
8472 /* Indices of image specification fields in xbm_format, below. */
8474 enum xbm_keyword_index
8491 /* Vector of image_keyword structures describing the format
8492 of valid XBM image specifications. */
8494 static struct image_keyword xbm_format
[XBM_LAST
] =
8496 {":type", IMAGE_SYMBOL_VALUE
, 1},
8497 {":file", IMAGE_STRING_VALUE
, 0},
8498 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8499 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8500 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8501 {":foreground", IMAGE_STRING_VALUE
, 0},
8502 {":background", IMAGE_STRING_VALUE
, 0},
8503 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
8504 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8505 {":relief", IMAGE_INTEGER_VALUE
, 0},
8506 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8507 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
8510 /* Structure describing the image type XBM. */
8512 static struct image_type xbm_type
=
8521 /* Tokens returned from xbm_scan. */
8530 /* Return non-zero if OBJECT is a valid XBM-type image specification.
8531 A valid specification is a list starting with the symbol `image'
8532 The rest of the list is a property list which must contain an
8535 If the specification specifies a file to load, it must contain
8536 an entry `:file FILENAME' where FILENAME is a string.
8538 If the specification is for a bitmap loaded from memory it must
8539 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
8540 WIDTH and HEIGHT are integers > 0. DATA may be:
8542 1. a string large enough to hold the bitmap data, i.e. it must
8543 have a size >= (WIDTH + 7) / 8 * HEIGHT
8545 2. a bool-vector of size >= WIDTH * HEIGHT
8547 3. a vector of strings or bool-vectors, one for each line of the
8550 Both the file and data forms may contain the additional entries
8551 `:background COLOR' and `:foreground COLOR'. If not present,
8552 foreground and background of the frame on which the image is
8553 displayed, is used. */
8556 xbm_image_p (object
)
8559 struct image_keyword kw
[XBM_LAST
];
8561 bcopy (xbm_format
, kw
, sizeof kw
);
8562 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
8565 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
8567 if (kw
[XBM_FILE
].count
)
8569 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
8577 /* Entries for `:width', `:height' and `:data' must be present. */
8578 if (!kw
[XBM_WIDTH
].count
8579 || !kw
[XBM_HEIGHT
].count
8580 || !kw
[XBM_DATA
].count
)
8583 data
= kw
[XBM_DATA
].value
;
8584 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
8585 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
8587 /* Check type of data, and width and height against contents of
8593 /* Number of elements of the vector must be >= height. */
8594 if (XVECTOR (data
)->size
< height
)
8597 /* Each string or bool-vector in data must be large enough
8598 for one line of the image. */
8599 for (i
= 0; i
< height
; ++i
)
8601 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
8605 if (XSTRING (elt
)->size
8606 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
8609 else if (BOOL_VECTOR_P (elt
))
8611 if (XBOOL_VECTOR (elt
)->size
< width
)
8618 else if (STRINGP (data
))
8620 if (XSTRING (data
)->size
8621 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
8624 else if (BOOL_VECTOR_P (data
))
8626 if (XBOOL_VECTOR (data
)->size
< width
* height
)
8633 /* Baseline must be a value between 0 and 100 (a percentage). */
8634 if (kw
[XBM_ASCENT
].count
8635 && XFASTINT (kw
[XBM_ASCENT
].value
) > 100)
8642 /* Scan a bitmap file. FP is the stream to read from. Value is
8643 either an enumerator from enum xbm_token, or a character for a
8644 single-character token, or 0 at end of file. If scanning an
8645 identifier, store the lexeme of the identifier in SVAL. If
8646 scanning a number, store its value in *IVAL. */
8649 xbm_scan (fp
, sval
, ival
)
8656 /* Skip white space. */
8657 while ((c
= fgetc (fp
)) != EOF
&& isspace (c
))
8662 else if (isdigit (c
))
8664 int value
= 0, digit
;
8669 if (c
== 'x' || c
== 'X')
8671 while ((c
= fgetc (fp
)) != EOF
)
8675 else if (c
>= 'a' && c
<= 'f')
8676 digit
= c
- 'a' + 10;
8677 else if (c
>= 'A' && c
<= 'F')
8678 digit
= c
- 'A' + 10;
8681 value
= 16 * value
+ digit
;
8684 else if (isdigit (c
))
8687 while ((c
= fgetc (fp
)) != EOF
8689 value
= 8 * value
+ c
- '0';
8695 while ((c
= fgetc (fp
)) != EOF
8697 value
= 10 * value
+ c
- '0';
8705 else if (isalpha (c
) || c
== '_')
8708 while ((c
= fgetc (fp
)) != EOF
8709 && (isalnum (c
) || c
== '_'))
8721 /* Replacement for XReadBitmapFileData which isn't available under old
8722 X versions. FILE is the name of the bitmap file to read. Set
8723 *WIDTH and *HEIGHT to the width and height of the image. Return in
8724 *DATA the bitmap data allocated with xmalloc. Value is non-zero if
8728 xbm_read_bitmap_file_data (file
, width
, height
, data
)
8730 int *width
, *height
;
8731 unsigned char **data
;
8734 char buffer
[BUFSIZ
];
8737 int bytes_per_line
, i
, nbytes
;
8743 LA1 = xbm_scan (fp, buffer, &value)
8745 #define expect(TOKEN) \
8746 if (LA1 != (TOKEN)) \
8751 #define expect_ident(IDENT) \
8752 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
8757 fp
= fopen (file
, "r");
8761 *width
= *height
= -1;
8763 LA1
= xbm_scan (fp
, buffer
, &value
);
8765 /* Parse defines for width, height and hot-spots. */
8769 expect_ident ("define");
8770 expect (XBM_TK_IDENT
);
8772 if (LA1
== XBM_TK_NUMBER
);
8774 char *p
= strrchr (buffer
, '_');
8775 p
= p
? p
+ 1 : buffer
;
8776 if (strcmp (p
, "width") == 0)
8778 else if (strcmp (p
, "height") == 0)
8781 expect (XBM_TK_NUMBER
);
8784 if (*width
< 0 || *height
< 0)
8787 /* Parse bits. Must start with `static'. */
8788 expect_ident ("static");
8789 if (LA1
== XBM_TK_IDENT
)
8791 if (strcmp (buffer
, "unsigned") == 0)
8794 expect_ident ("char");
8796 else if (strcmp (buffer
, "short") == 0)
8800 if (*width
% 16 && *width
% 16 < 9)
8803 else if (strcmp (buffer
, "char") == 0)
8811 expect (XBM_TK_IDENT
);
8817 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
8818 nbytes
= bytes_per_line
* *height
;
8819 p
= *data
= (char *) xmalloc (nbytes
);
8824 for (i
= 0; i
< nbytes
; i
+= 2)
8827 expect (XBM_TK_NUMBER
);
8830 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
8833 if (LA1
== ',' || LA1
== '}')
8841 for (i
= 0; i
< nbytes
; ++i
)
8844 expect (XBM_TK_NUMBER
);
8848 if (LA1
== ',' || LA1
== '}')
8874 /* Load XBM image IMG which will be displayed on frame F from file
8875 SPECIFIED_FILE. Value is non-zero if successful. */
8878 xbm_load_image_from_file (f
, img
, specified_file
)
8881 Lisp_Object specified_file
;
8884 unsigned char *data
;
8887 struct gcpro gcpro1
;
8889 xassert (STRINGP (specified_file
));
8893 file
= x_find_image_file (specified_file
);
8894 if (!STRINGP (file
))
8896 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8901 rc
= xbm_read_bitmap_file_data (XSTRING (file
)->data
, &img
->width
,
8902 &img
->height
, &data
);
8905 int depth
= one_w32_display_info
.n_cbits
;
8906 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
8907 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
8910 xassert (img
->width
> 0 && img
->height
> 0);
8912 /* Get foreground and background colors, maybe allocate colors. */
8913 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
8915 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
8917 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
8919 background
= x_alloc_image_color (f
, img
, value
, background
);
8921 #if 0 /* TODO : Port image display to W32 */
8924 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
8925 FRAME_W32_WINDOW (f
),
8927 img
->width
, img
->height
,
8928 foreground
, background
,
8932 if (img
->pixmap
== 0)
8934 x_clear_image (f
, img
);
8935 image_error ("Unable to create X pixmap for `%s'", file
, Qnil
);
8944 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
8951 /* Fill image IMG which is used on frame F with pixmap data. Value is
8952 non-zero if successful. */
8960 Lisp_Object file_name
;
8962 xassert (xbm_image_p (img
->spec
));
8964 /* If IMG->spec specifies a file name, create a non-file spec from it. */
8965 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
8966 if (STRINGP (file_name
))
8967 success_p
= xbm_load_image_from_file (f
, img
, file_name
);
8970 struct image_keyword fmt
[XBM_LAST
];
8973 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
8974 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
8978 /* Parse the list specification. */
8979 bcopy (xbm_format
, fmt
, sizeof fmt
);
8980 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
8983 /* Get specified width, and height. */
8984 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
8985 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
8986 xassert (img
->width
> 0 && img
->height
> 0);
8990 if (fmt
[XBM_ASCENT
].count
)
8991 img
->ascent
= XFASTINT (fmt
[XBM_ASCENT
].value
);
8993 /* Get foreground and background colors, maybe allocate colors. */
8994 if (fmt
[XBM_FOREGROUND
].count
)
8995 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
8997 if (fmt
[XBM_BACKGROUND
].count
)
8998 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
9001 /* Set bits to the bitmap image data. */
9002 data
= fmt
[XBM_DATA
].value
;
9007 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
9009 p
= bits
= (char *) alloca (nbytes
* img
->height
);
9010 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
9012 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
9014 bcopy (XSTRING (line
)->data
, p
, nbytes
);
9016 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
9019 else if (STRINGP (data
))
9020 bits
= XSTRING (data
)->data
;
9022 bits
= XBOOL_VECTOR (data
)->data
;
9024 #if 0 /* TODO : W32 XPM code */
9025 /* Create the pixmap. */
9026 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
9028 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
9029 FRAME_W32_WINDOW (f
),
9031 img
->width
, img
->height
,
9032 foreground
, background
,
9040 image_error ("Unable to create pixmap for XBM image `%s'",
9042 x_clear_image (f
, img
);
9053 /***********************************************************************
9055 ***********************************************************************/
9059 static int xpm_image_p
P_ ((Lisp_Object object
));
9060 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
9061 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
9063 #include "X11/xpm.h"
9065 /* The symbol `xpm' identifying XPM-format images. */
9069 /* Indices of image specification fields in xpm_format, below. */
9071 enum xpm_keyword_index
9085 /* Vector of image_keyword structures describing the format
9086 of valid XPM image specifications. */
9088 static struct image_keyword xpm_format
[XPM_LAST
] =
9090 {":type", IMAGE_SYMBOL_VALUE
, 1},
9091 {":file", IMAGE_STRING_VALUE
, 0},
9092 {":data", IMAGE_STRING_VALUE
, 0},
9093 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9094 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9095 {":relief", IMAGE_INTEGER_VALUE
, 0},
9096 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9097 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9098 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9101 /* Structure describing the image type XBM. */
9103 static struct image_type xpm_type
=
9113 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
9114 for XPM images. Such a list must consist of conses whose car and
9118 xpm_valid_color_symbols_p (color_symbols
)
9119 Lisp_Object color_symbols
;
9121 while (CONSP (color_symbols
))
9123 Lisp_Object sym
= XCAR (color_symbols
);
9125 || !STRINGP (XCAR (sym
))
9126 || !STRINGP (XCDR (sym
)))
9128 color_symbols
= XCDR (color_symbols
);
9131 return NILP (color_symbols
);
9135 /* Value is non-zero if OBJECT is a valid XPM image specification. */
9138 xpm_image_p (object
)
9141 struct image_keyword fmt
[XPM_LAST
];
9142 bcopy (xpm_format
, fmt
, sizeof fmt
);
9143 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
9144 /* Either `:file' or `:data' must be present. */
9145 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
9146 /* Either no `:color-symbols' or it's a list of conses
9147 whose car and cdr are strings. */
9148 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
9149 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
9150 && (fmt
[XPM_ASCENT
].count
== 0
9151 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
9155 /* Load image IMG which will be displayed on frame F. Value is
9156 non-zero if successful. */
9164 XpmAttributes attrs
;
9165 Lisp_Object specified_file
, color_symbols
;
9167 /* Configure the XPM lib. Use the visual of frame F. Allocate
9168 close colors. Return colors allocated. */
9169 bzero (&attrs
, sizeof attrs
);
9170 attrs
.visual
= FRAME_X_VISUAL (f
);
9171 attrs
.colormap
= FRAME_X_COLORMAP (f
);
9172 attrs
.valuemask
|= XpmVisual
;
9173 attrs
.valuemask
|= XpmColormap
;
9174 attrs
.valuemask
|= XpmReturnAllocPixels
;
9175 #ifdef XpmAllocCloseColors
9176 attrs
.alloc_close_colors
= 1;
9177 attrs
.valuemask
|= XpmAllocCloseColors
;
9179 attrs
.closeness
= 600;
9180 attrs
.valuemask
|= XpmCloseness
;
9183 /* If image specification contains symbolic color definitions, add
9184 these to `attrs'. */
9185 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
9186 if (CONSP (color_symbols
))
9189 XpmColorSymbol
*xpm_syms
;
9192 attrs
.valuemask
|= XpmColorSymbols
;
9194 /* Count number of symbols. */
9195 attrs
.numsymbols
= 0;
9196 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
9199 /* Allocate an XpmColorSymbol array. */
9200 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
9201 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
9202 bzero (xpm_syms
, size
);
9203 attrs
.colorsymbols
= xpm_syms
;
9205 /* Fill the color symbol array. */
9206 for (tail
= color_symbols
, i
= 0;
9208 ++i
, tail
= XCDR (tail
))
9210 Lisp_Object name
= XCAR (XCAR (tail
));
9211 Lisp_Object color
= XCDR (XCAR (tail
));
9212 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
9213 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
9214 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
9215 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
9219 /* Create a pixmap for the image, either from a file, or from a
9220 string buffer containing data in the same format as an XPM file. */
9222 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9223 if (STRINGP (specified_file
))
9225 Lisp_Object file
= x_find_image_file (specified_file
);
9226 if (!STRINGP (file
))
9228 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9233 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
9234 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
9239 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
9240 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
9241 XSTRING (buffer
)->data
,
9242 &img
->pixmap
, &img
->mask
,
9247 if (rc
== XpmSuccess
)
9249 /* Remember allocated colors. */
9250 img
->ncolors
= attrs
.nalloc_pixels
;
9251 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
9252 * sizeof *img
->colors
);
9253 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
9254 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
9256 img
->width
= attrs
.width
;
9257 img
->height
= attrs
.height
;
9258 xassert (img
->width
> 0 && img
->height
> 0);
9260 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
9262 XpmFreeAttributes (&attrs
);
9270 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
9273 case XpmFileInvalid
:
9274 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
9278 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
9281 case XpmColorFailed
:
9282 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
9286 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
9291 return rc
== XpmSuccess
;
9294 #endif /* HAVE_XPM != 0 */
9297 #if 0 /* TODO : Color tables on W32. */
9298 /***********************************************************************
9300 ***********************************************************************/
9302 /* An entry in the color table mapping an RGB color to a pixel color. */
9307 unsigned long pixel
;
9309 /* Next in color table collision list. */
9310 struct ct_color
*next
;
9313 /* The bucket vector size to use. Must be prime. */
9317 /* Value is a hash of the RGB color given by R, G, and B. */
9319 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
9321 /* The color hash table. */
9323 struct ct_color
**ct_table
;
9325 /* Number of entries in the color table. */
9327 int ct_colors_allocated
;
9329 /* Function prototypes. */
9331 static void init_color_table
P_ ((void));
9332 static void free_color_table
P_ ((void));
9333 static unsigned long *colors_in_color_table
P_ ((int *n
));
9334 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
9335 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
9338 /* Initialize the color table. */
9343 int size
= CT_SIZE
* sizeof (*ct_table
);
9344 ct_table
= (struct ct_color
**) xmalloc (size
);
9345 bzero (ct_table
, size
);
9346 ct_colors_allocated
= 0;
9350 /* Free memory associated with the color table. */
9356 struct ct_color
*p
, *next
;
9358 for (i
= 0; i
< CT_SIZE
; ++i
)
9359 for (p
= ct_table
[i
]; p
; p
= next
)
9370 /* Value is a pixel color for RGB color R, G, B on frame F. If an
9371 entry for that color already is in the color table, return the
9372 pixel color of that entry. Otherwise, allocate a new color for R,
9373 G, B, and make an entry in the color table. */
9375 static unsigned long
9376 lookup_rgb_color (f
, r
, g
, b
)
9380 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
9381 int i
= hash
% CT_SIZE
;
9384 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9385 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
9394 color
= PALETTERGB (r
, g
, b
);
9396 ++ct_colors_allocated
;
9398 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9403 p
->next
= ct_table
[i
];
9411 /* Look up pixel color PIXEL which is used on frame F in the color
9412 table. If not already present, allocate it. Value is PIXEL. */
9414 static unsigned long
9415 lookup_pixel_color (f
, pixel
)
9417 unsigned long pixel
;
9419 int i
= pixel
% CT_SIZE
;
9422 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9423 if (p
->pixel
== pixel
)
9434 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9435 color
.pixel
= pixel
;
9436 XQueryColor (NULL
, cmap
, &color
);
9437 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
9442 ++ct_colors_allocated
;
9444 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9449 p
->next
= ct_table
[i
];
9453 return FRAME_FOREGROUND_PIXEL (f
);
9459 /* Value is a vector of all pixel colors contained in the color table,
9460 allocated via xmalloc. Set *N to the number of colors. */
9462 static unsigned long *
9463 colors_in_color_table (n
)
9468 unsigned long *colors
;
9470 if (ct_colors_allocated
== 0)
9477 colors
= (unsigned long *) xmalloc (ct_colors_allocated
9479 *n
= ct_colors_allocated
;
9481 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
9482 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9483 colors
[j
++] = p
->pixel
;
9492 /***********************************************************************
9494 ***********************************************************************/
9496 #if 0 /* TODO : W32 versions of low level algorithms */
9497 static void x_laplace_write_row
P_ ((struct frame
*, long *,
9498 int, XImage
*, int));
9499 static void x_laplace_read_row
P_ ((struct frame
*, Colormap
,
9500 XColor
*, int, XImage
*, int));
9503 /* Fill COLORS with RGB colors from row Y of image XIMG. F is the
9504 frame we operate on, CMAP is the color-map in effect, and WIDTH is
9505 the width of one row in the image. */
9508 x_laplace_read_row (f
, cmap
, colors
, width
, ximg
, y
)
9518 for (x
= 0; x
< width
; ++x
)
9519 colors
[x
].pixel
= XGetPixel (ximg
, x
, y
);
9521 XQueryColors (NULL
, cmap
, colors
, width
);
9525 /* Write row Y of image XIMG. PIXELS is an array of WIDTH longs
9526 containing the pixel colors to write. F is the frame we are
9530 x_laplace_write_row (f
, pixels
, width
, ximg
, y
)
9539 for (x
= 0; x
< width
; ++x
)
9540 XPutPixel (ximg
, x
, y
, pixels
[x
]);
9544 /* Transform image IMG which is used on frame F with a Laplace
9545 edge-detection algorithm. The result is an image that can be used
9546 to draw disabled buttons, for example. */
9553 #if 0 /* TODO : W32 version */
9554 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9555 XImage
*ximg
, *oimg
;
9561 int in_y
, out_y
, rc
;
9566 /* Get the X image IMG->pixmap. */
9567 ximg
= XGetImage (NULL
, img
->pixmap
,
9568 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
9570 /* Allocate 3 input rows, and one output row of colors. */
9571 for (i
= 0; i
< 3; ++i
)
9572 in
[i
] = (XColor
*) alloca (img
->width
* sizeof (XColor
));
9573 out
= (long *) alloca (img
->width
* sizeof (long));
9575 /* Create an X image for output. */
9576 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
9579 /* Fill first two rows. */
9580 x_laplace_read_row (f
, cmap
, in
[0], img
->width
, ximg
, 0);
9581 x_laplace_read_row (f
, cmap
, in
[1], img
->width
, ximg
, 1);
9584 /* Write first row, all zeros. */
9585 init_color_table ();
9586 pixel
= lookup_rgb_color (f
, 0, 0, 0);
9587 for (x
= 0; x
< img
->width
; ++x
)
9589 x_laplace_write_row (f
, out
, img
->width
, oimg
, 0);
9592 for (y
= 2; y
< img
->height
; ++y
)
9595 int rowb
= (y
+ 2) % 3;
9597 x_laplace_read_row (f
, cmap
, in
[rowa
], img
->width
, ximg
, in_y
++);
9599 for (x
= 0; x
< img
->width
- 2; ++x
)
9601 int r
= in
[rowa
][x
].red
+ mv2
- in
[rowb
][x
+ 2].red
;
9602 int g
= in
[rowa
][x
].green
+ mv2
- in
[rowb
][x
+ 2].green
;
9603 int b
= in
[rowa
][x
].blue
+ mv2
- in
[rowb
][x
+ 2].blue
;
9605 out
[x
+ 1] = lookup_rgb_color (f
, r
& 0xffff, g
& 0xffff,
9609 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
++);
9612 /* Write last line, all zeros. */
9613 for (x
= 0; x
< img
->width
; ++x
)
9615 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
);
9617 /* Free the input image, and free resources of IMG. */
9618 XDestroyImage (ximg
);
9619 x_clear_image (f
, img
);
9621 /* Put the output image into pixmap, and destroy it. */
9622 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
9623 x_destroy_x_image (oimg
);
9625 /* Remember new pixmap and colors in IMG. */
9626 img
->pixmap
= pixmap
;
9627 img
->colors
= colors_in_color_table (&img
->ncolors
);
9628 free_color_table ();
9635 /* Build a mask for image IMG which is used on frame F. FILE is the
9636 name of an image file, for error messages. HOW determines how to
9637 determine the background color of IMG. If it is a list '(R G B)',
9638 with R, G, and B being integers >= 0, take that as the color of the
9639 background. Otherwise, determine the background color of IMG
9640 heuristically. Value is non-zero if successful. */
9643 x_build_heuristic_mask (f
, img
, how
)
9648 #if 0 /* TODO : W32 version */
9649 Display
*dpy
= FRAME_W32_DISPLAY (f
);
9650 XImage
*ximg
, *mask_img
;
9651 int x
, y
, rc
, look_at_corners_p
;
9656 /* Create an image and pixmap serving as mask. */
9657 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
9658 &mask_img
, &img
->mask
);
9665 /* Get the X image of IMG->pixmap. */
9666 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
9669 /* Determine the background color of ximg. If HOW is `(R G B)'
9670 take that as color. Otherwise, try to determine the color
9672 look_at_corners_p
= 1;
9680 && NATNUMP (XCAR (how
)))
9682 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
9686 if (i
== 3 && NILP (how
))
9688 char color_name
[30];
9689 XColor exact
, color
;
9692 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
9694 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9695 if (XLookupColor (dpy
, cmap
, color_name
, &exact
, &color
))
9698 look_at_corners_p
= 0;
9703 if (look_at_corners_p
)
9705 unsigned long corners
[4];
9708 /* Get the colors at the corners of ximg. */
9709 corners
[0] = XGetPixel (ximg
, 0, 0);
9710 corners
[1] = XGetPixel (ximg
, img
->width
- 1, 0);
9711 corners
[2] = XGetPixel (ximg
, img
->width
- 1, img
->height
- 1);
9712 corners
[3] = XGetPixel (ximg
, 0, img
->height
- 1);
9714 /* Choose the most frequently found color as background. */
9715 for (i
= best_count
= 0; i
< 4; ++i
)
9719 for (j
= n
= 0; j
< 4; ++j
)
9720 if (corners
[i
] == corners
[j
])
9724 bg
= corners
[i
], best_count
= n
;
9728 /* Set all bits in mask_img to 1 whose color in ximg is different
9729 from the background color bg. */
9730 for (y
= 0; y
< img
->height
; ++y
)
9731 for (x
= 0; x
< img
->width
; ++x
)
9732 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
9734 /* Put mask_img into img->mask. */
9735 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
9736 x_destroy_x_image (mask_img
);
9737 XDestroyImage (ximg
);
9747 /***********************************************************************
9748 PBM (mono, gray, color)
9749 ***********************************************************************/
9752 static int pbm_image_p
P_ ((Lisp_Object object
));
9753 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
9754 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
9756 /* The symbol `pbm' identifying images of this type. */
9760 /* Indices of image specification fields in gs_format, below. */
9762 enum pbm_keyword_index
9775 /* Vector of image_keyword structures describing the format
9776 of valid user-defined image specifications. */
9778 static struct image_keyword pbm_format
[PBM_LAST
] =
9780 {":type", IMAGE_SYMBOL_VALUE
, 1},
9781 {":file", IMAGE_STRING_VALUE
, 0},
9782 {":data", IMAGE_STRING_VALUE
, 0},
9783 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9784 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9785 {":relief", IMAGE_INTEGER_VALUE
, 0},
9786 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9787 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9790 /* Structure describing the image type `pbm'. */
9792 static struct image_type pbm_type
=
9802 /* Return non-zero if OBJECT is a valid PBM image specification. */
9805 pbm_image_p (object
)
9808 struct image_keyword fmt
[PBM_LAST
];
9810 bcopy (pbm_format
, fmt
, sizeof fmt
);
9812 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
9813 || (fmt
[PBM_ASCENT
].count
9814 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
9817 /* Must specify either :data or :file. */
9818 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
9822 /* Scan a decimal number from *S and return it. Advance *S while
9823 reading the number. END is the end of the string. Value is -1 at
9827 pbm_scan_number (s
, end
)
9828 unsigned char **s
, *end
;
9834 /* Skip white-space. */
9835 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
9840 /* Skip comment to end of line. */
9841 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
9844 else if (isdigit (c
))
9846 /* Read decimal number. */
9848 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
9849 val
= 10 * val
+ c
- '0';
9860 /* Read FILE into memory. Value is a pointer to a buffer allocated
9861 with xmalloc holding FILE's contents. Value is null if an error
9862 occured. *SIZE is set to the size of the file. */
9865 pbm_read_file (file
, size
)
9873 if (stat (XSTRING (file
)->data
, &st
) == 0
9874 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
9875 && (buf
= (char *) xmalloc (st
.st_size
),
9876 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
9896 /* Load PBM image IMG for use on frame F. */
9904 int width
, height
, max_color_idx
= 0;
9906 Lisp_Object file
, specified_file
;
9907 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
9908 struct gcpro gcpro1
;
9909 unsigned char *contents
= NULL
;
9910 unsigned char *end
, *p
;
9913 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9917 if (STRINGP (specified_file
))
9919 file
= x_find_image_file (specified_file
);
9920 if (!STRINGP (file
))
9922 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9927 contents
= pbm_read_file (file
, &size
);
9928 if (contents
== NULL
)
9930 image_error ("Error reading `%s'", file
, Qnil
);
9936 end
= contents
+ size
;
9941 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
9942 p
= XSTRING (data
)->data
;
9943 end
= p
+ STRING_BYTES (XSTRING (data
));
9946 /* Check magic number. */
9947 if (end
- p
< 2 || *p
++ != 'P')
9949 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
9959 raw_p
= 0, type
= PBM_MONO
;
9963 raw_p
= 0, type
= PBM_GRAY
;
9967 raw_p
= 0, type
= PBM_COLOR
;
9971 raw_p
= 1, type
= PBM_MONO
;
9975 raw_p
= 1, type
= PBM_GRAY
;
9979 raw_p
= 1, type
= PBM_COLOR
;
9983 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
9987 /* Read width, height, maximum color-component. Characters
9988 starting with `#' up to the end of a line are ignored. */
9989 width
= pbm_scan_number (&p
, end
);
9990 height
= pbm_scan_number (&p
, end
);
9992 if (type
!= PBM_MONO
)
9994 max_color_idx
= pbm_scan_number (&p
, end
);
9995 if (raw_p
&& max_color_idx
> 255)
9996 max_color_idx
= 255;
10001 || (type
!= PBM_MONO
&& max_color_idx
< 0))
10005 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
10006 &ximg
, &img
->pixmap
))
10012 /* Initialize the color hash table. */
10013 init_color_table ();
10015 if (type
== PBM_MONO
)
10019 for (y
= 0; y
< height
; ++y
)
10020 for (x
= 0; x
< width
; ++x
)
10030 g
= pbm_scan_number (&p
, end
);
10032 XPutPixel (ximg
, x
, y
, (g
10033 ? FRAME_FOREGROUND_PIXEL (f
)
10034 : FRAME_BACKGROUND_PIXEL (f
)));
10039 for (y
= 0; y
< height
; ++y
)
10040 for (x
= 0; x
< width
; ++x
)
10044 if (type
== PBM_GRAY
)
10045 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
10054 r
= pbm_scan_number (&p
, end
);
10055 g
= pbm_scan_number (&p
, end
);
10056 b
= pbm_scan_number (&p
, end
);
10059 if (r
< 0 || g
< 0 || b
< 0)
10061 xfree (ximg
->data
);
10063 XDestroyImage (ximg
);
10065 image_error ("Invalid pixel value in image `%s'",
10070 /* RGB values are now in the range 0..max_color_idx.
10071 Scale this to the range 0..0xffff supported by X. */
10072 r
= (double) r
* 65535 / max_color_idx
;
10073 g
= (double) g
* 65535 / max_color_idx
;
10074 b
= (double) b
* 65535 / max_color_idx
;
10075 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10079 /* Store in IMG->colors the colors allocated for the image, and
10080 free the color table. */
10081 img
->colors
= colors_in_color_table (&img
->ncolors
);
10082 free_color_table ();
10084 /* Put the image into a pixmap. */
10085 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10086 x_destroy_x_image (ximg
);
10089 img
->width
= width
;
10090 img
->height
= height
;
10096 #endif /* HAVE_PBM */
10099 /***********************************************************************
10101 ***********************************************************************/
10107 /* Function prototypes. */
10109 static int png_image_p
P_ ((Lisp_Object object
));
10110 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
10112 /* The symbol `png' identifying images of this type. */
10116 /* Indices of image specification fields in png_format, below. */
10118 enum png_keyword_index
10127 PNG_HEURISTIC_MASK
,
10131 /* Vector of image_keyword structures describing the format
10132 of valid user-defined image specifications. */
10134 static struct image_keyword png_format
[PNG_LAST
] =
10136 {":type", IMAGE_SYMBOL_VALUE
, 1},
10137 {":data", IMAGE_STRING_VALUE
, 0},
10138 {":file", IMAGE_STRING_VALUE
, 0},
10139 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10140 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10141 {":relief", IMAGE_INTEGER_VALUE
, 0},
10142 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10143 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10146 /* Structure describing the image type `png'. */
10148 static struct image_type png_type
=
10158 /* Return non-zero if OBJECT is a valid PNG image specification. */
10161 png_image_p (object
)
10162 Lisp_Object object
;
10164 struct image_keyword fmt
[PNG_LAST
];
10165 bcopy (png_format
, fmt
, sizeof fmt
);
10167 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
10168 || (fmt
[PNG_ASCENT
].count
10169 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
10172 /* Must specify either the :data or :file keyword. */
10173 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
10177 /* Error and warning handlers installed when the PNG library
10181 my_png_error (png_ptr
, msg
)
10182 png_struct
*png_ptr
;
10185 xassert (png_ptr
!= NULL
);
10186 image_error ("PNG error: %s", build_string (msg
), Qnil
);
10187 longjmp (png_ptr
->jmpbuf
, 1);
10192 my_png_warning (png_ptr
, msg
)
10193 png_struct
*png_ptr
;
10196 xassert (png_ptr
!= NULL
);
10197 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
10200 /* Memory source for PNG decoding. */
10202 struct png_memory_storage
10204 unsigned char *bytes
; /* The data */
10205 size_t len
; /* How big is it? */
10206 int index
; /* Where are we? */
10210 /* Function set as reader function when reading PNG image from memory.
10211 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
10212 bytes from the input to DATA. */
10215 png_read_from_memory (png_ptr
, data
, length
)
10216 png_structp png_ptr
;
10220 struct png_memory_storage
*tbr
10221 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
10223 if (length
> tbr
->len
- tbr
->index
)
10224 png_error (png_ptr
, "Read error");
10226 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
10227 tbr
->index
= tbr
->index
+ length
;
10230 /* Load PNG image IMG for use on frame F. Value is non-zero if
10238 Lisp_Object file
, specified_file
;
10239 Lisp_Object specified_data
;
10241 XImage
*ximg
, *mask_img
= NULL
;
10242 struct gcpro gcpro1
;
10243 png_struct
*png_ptr
= NULL
;
10244 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
10247 png_byte
*pixels
= NULL
;
10248 png_byte
**rows
= NULL
;
10249 png_uint_32 width
, height
;
10250 int bit_depth
, color_type
, interlace_type
;
10252 png_uint_32 row_bytes
;
10255 double screen_gamma
, image_gamma
;
10257 struct png_memory_storage tbr
; /* Data to be read */
10259 /* Find out what file to load. */
10260 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10261 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10265 if (NILP (specified_data
))
10267 file
= x_find_image_file (specified_file
);
10268 if (!STRINGP (file
))
10270 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10275 /* Open the image file. */
10276 fp
= fopen (XSTRING (file
)->data
, "rb");
10279 image_error ("Cannot open image file `%s'", file
, Qnil
);
10285 /* Check PNG signature. */
10286 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
10287 || !png_check_sig (sig
, sizeof sig
))
10289 image_error ("Not a PNG file:` %s'", file
, Qnil
);
10297 /* Read from memory. */
10298 tbr
.bytes
= XSTRING (specified_data
)->data
;
10299 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
10302 /* Check PNG signature. */
10303 if (tbr
.len
< sizeof sig
10304 || !png_check_sig (tbr
.bytes
, sizeof sig
))
10306 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
10311 /* Need to skip past the signature. */
10312 tbr
.bytes
+= sizeof (sig
);
10315 /* Initialize read and info structs for PNG lib. */
10316 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
10317 my_png_error
, my_png_warning
);
10320 if (fp
) fclose (fp
);
10325 info_ptr
= png_create_info_struct (png_ptr
);
10328 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
10329 if (fp
) fclose (fp
);
10334 end_info
= png_create_info_struct (png_ptr
);
10337 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
10338 if (fp
) fclose (fp
);
10343 /* Set error jump-back. We come back here when the PNG library
10344 detects an error. */
10345 if (setjmp (png_ptr
->jmpbuf
))
10349 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10352 if (fp
) fclose (fp
);
10357 /* Read image info. */
10358 if (!NILP (specified_data
))
10359 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
10361 png_init_io (png_ptr
, fp
);
10363 png_set_sig_bytes (png_ptr
, sizeof sig
);
10364 png_read_info (png_ptr
, info_ptr
);
10365 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
10366 &interlace_type
, NULL
, NULL
);
10368 /* If image contains simply transparency data, we prefer to
10369 construct a clipping mask. */
10370 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
10375 /* This function is easier to write if we only have to handle
10376 one data format: RGB or RGBA with 8 bits per channel. Let's
10377 transform other formats into that format. */
10379 /* Strip more than 8 bits per channel. */
10380 if (bit_depth
== 16)
10381 png_set_strip_16 (png_ptr
);
10383 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
10385 png_set_expand (png_ptr
);
10387 /* Convert grayscale images to RGB. */
10388 if (color_type
== PNG_COLOR_TYPE_GRAY
10389 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
10390 png_set_gray_to_rgb (png_ptr
);
10392 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
10393 gamma_str
= getenv ("SCREEN_GAMMA");
10394 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
10396 /* Tell the PNG lib to handle gamma correction for us. */
10398 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
10399 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
10400 /* There is a special chunk in the image specifying the gamma. */
10401 png_set_sRGB (png_ptr
, info_ptr
, intent
);
10404 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
10405 /* Image contains gamma information. */
10406 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
10408 /* Use a default of 0.5 for the image gamma. */
10409 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
10411 /* Handle alpha channel by combining the image with a background
10412 color. Do this only if a real alpha channel is supplied. For
10413 simple transparency, we prefer a clipping mask. */
10414 if (!transparent_p
)
10416 png_color_16
*image_background
;
10418 if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
10419 /* Image contains a background color with which to
10420 combine the image. */
10421 png_set_background (png_ptr
, image_background
,
10422 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
10425 /* Image does not contain a background color with which
10426 to combine the image data via an alpha channel. Use
10427 the frame's background instead. */
10430 png_color_16 frame_background
;
10433 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10434 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
10435 XQueryColor (FRAME_W32_DISPLAY (f
), cmap
, &color
);
10438 bzero (&frame_background
, sizeof frame_background
);
10439 frame_background
.red
= color
.red
;
10440 frame_background
.green
= color
.green
;
10441 frame_background
.blue
= color
.blue
;
10443 png_set_background (png_ptr
, &frame_background
,
10444 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
10448 /* Update info structure. */
10449 png_read_update_info (png_ptr
, info_ptr
);
10451 /* Get number of channels. Valid values are 1 for grayscale images
10452 and images with a palette, 2 for grayscale images with transparency
10453 information (alpha channel), 3 for RGB images, and 4 for RGB
10454 images with alpha channel, i.e. RGBA. If conversions above were
10455 sufficient we should only have 3 or 4 channels here. */
10456 channels
= png_get_channels (png_ptr
, info_ptr
);
10457 xassert (channels
== 3 || channels
== 4);
10459 /* Number of bytes needed for one row of the image. */
10460 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
10462 /* Allocate memory for the image. */
10463 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
10464 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
10465 for (i
= 0; i
< height
; ++i
)
10466 rows
[i
] = pixels
+ i
* row_bytes
;
10468 /* Read the entire image. */
10469 png_read_image (png_ptr
, rows
);
10470 png_read_end (png_ptr
, info_ptr
);
10479 /* Create the X image and pixmap. */
10480 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10487 /* Create an image and pixmap serving as mask if the PNG image
10488 contains an alpha channel. */
10491 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
10492 &mask_img
, &img
->mask
))
10494 x_destroy_x_image (ximg
);
10495 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
10501 /* Fill the X image and mask from PNG data. */
10502 init_color_table ();
10504 for (y
= 0; y
< height
; ++y
)
10506 png_byte
*p
= rows
[y
];
10508 for (x
= 0; x
< width
; ++x
)
10515 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10517 /* An alpha channel, aka mask channel, associates variable
10518 transparency with an image. Where other image formats
10519 support binary transparency---fully transparent or fully
10520 opaque---PNG allows up to 254 levels of partial transparency.
10521 The PNG library implements partial transparency by combining
10522 the image with a specified background color.
10524 I'm not sure how to handle this here nicely: because the
10525 background on which the image is displayed may change, for
10526 real alpha channel support, it would be necessary to create
10527 a new image for each possible background.
10529 What I'm doing now is that a mask is created if we have
10530 boolean transparency information. Otherwise I'm using
10531 the frame's background color to combine the image with. */
10536 XPutPixel (mask_img
, x
, y
, *p
> 0);
10542 /* Remember colors allocated for this image. */
10543 img
->colors
= colors_in_color_table (&img
->ncolors
);
10544 free_color_table ();
10547 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10551 img
->width
= width
;
10552 img
->height
= height
;
10554 /* Put the image into the pixmap, then free the X image and its buffer. */
10555 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10556 x_destroy_x_image (ximg
);
10558 /* Same for the mask. */
10561 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10562 x_destroy_x_image (mask_img
);
10570 #endif /* HAVE_PNG != 0 */
10574 /***********************************************************************
10576 ***********************************************************************/
10580 /* Work around a warning about HAVE_STDLIB_H being redefined in
10582 #ifdef HAVE_STDLIB_H
10583 #define HAVE_STDLIB_H_1
10584 #undef HAVE_STDLIB_H
10585 #endif /* HAVE_STLIB_H */
10587 #include <jpeglib.h>
10588 #include <jerror.h>
10589 #include <setjmp.h>
10591 #ifdef HAVE_STLIB_H_1
10592 #define HAVE_STDLIB_H 1
10595 static int jpeg_image_p
P_ ((Lisp_Object object
));
10596 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
10598 /* The symbol `jpeg' identifying images of this type. */
10602 /* Indices of image specification fields in gs_format, below. */
10604 enum jpeg_keyword_index
10613 JPEG_HEURISTIC_MASK
,
10617 /* Vector of image_keyword structures describing the format
10618 of valid user-defined image specifications. */
10620 static struct image_keyword jpeg_format
[JPEG_LAST
] =
10622 {":type", IMAGE_SYMBOL_VALUE
, 1},
10623 {":data", IMAGE_STRING_VALUE
, 0},
10624 {":file", IMAGE_STRING_VALUE
, 0},
10625 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10626 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10627 {":relief", IMAGE_INTEGER_VALUE
, 0},
10628 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10629 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10632 /* Structure describing the image type `jpeg'. */
10634 static struct image_type jpeg_type
=
10644 /* Return non-zero if OBJECT is a valid JPEG image specification. */
10647 jpeg_image_p (object
)
10648 Lisp_Object object
;
10650 struct image_keyword fmt
[JPEG_LAST
];
10652 bcopy (jpeg_format
, fmt
, sizeof fmt
);
10654 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
10655 || (fmt
[JPEG_ASCENT
].count
10656 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
10659 /* Must specify either the :data or :file keyword. */
10660 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
10664 struct my_jpeg_error_mgr
10666 struct jpeg_error_mgr pub
;
10667 jmp_buf setjmp_buffer
;
10671 my_error_exit (cinfo
)
10672 j_common_ptr cinfo
;
10674 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
10675 longjmp (mgr
->setjmp_buffer
, 1);
10678 /* Init source method for JPEG data source manager. Called by
10679 jpeg_read_header() before any data is actually read. See
10680 libjpeg.doc from the JPEG lib distribution. */
10683 our_init_source (cinfo
)
10684 j_decompress_ptr cinfo
;
10689 /* Fill input buffer method for JPEG data source manager. Called
10690 whenever more data is needed. We read the whole image in one step,
10691 so this only adds a fake end of input marker at the end. */
10694 our_fill_input_buffer (cinfo
)
10695 j_decompress_ptr cinfo
;
10697 /* Insert a fake EOI marker. */
10698 struct jpeg_source_mgr
*src
= cinfo
->src
;
10699 static JOCTET buffer
[2];
10701 buffer
[0] = (JOCTET
) 0xFF;
10702 buffer
[1] = (JOCTET
) JPEG_EOI
;
10704 src
->next_input_byte
= buffer
;
10705 src
->bytes_in_buffer
= 2;
10710 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
10711 is the JPEG data source manager. */
10714 our_skip_input_data (cinfo
, num_bytes
)
10715 j_decompress_ptr cinfo
;
10718 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10722 if (num_bytes
> src
->bytes_in_buffer
)
10723 ERREXIT (cinfo
, JERR_INPUT_EOF
);
10725 src
->bytes_in_buffer
-= num_bytes
;
10726 src
->next_input_byte
+= num_bytes
;
10731 /* Method to terminate data source. Called by
10732 jpeg_finish_decompress() after all data has been processed. */
10735 our_term_source (cinfo
)
10736 j_decompress_ptr cinfo
;
10741 /* Set up the JPEG lib for reading an image from DATA which contains
10742 LEN bytes. CINFO is the decompression info structure created for
10743 reading the image. */
10746 jpeg_memory_src (cinfo
, data
, len
)
10747 j_decompress_ptr cinfo
;
10751 struct jpeg_source_mgr
*src
;
10753 if (cinfo
->src
== NULL
)
10755 /* First time for this JPEG object? */
10756 cinfo
->src
= (struct jpeg_source_mgr
*)
10757 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
10758 sizeof (struct jpeg_source_mgr
));
10759 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10760 src
->next_input_byte
= data
;
10763 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10764 src
->init_source
= our_init_source
;
10765 src
->fill_input_buffer
= our_fill_input_buffer
;
10766 src
->skip_input_data
= our_skip_input_data
;
10767 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
10768 src
->term_source
= our_term_source
;
10769 src
->bytes_in_buffer
= len
;
10770 src
->next_input_byte
= data
;
10774 /* Load image IMG for use on frame F. Patterned after example.c
10775 from the JPEG lib. */
10782 struct jpeg_decompress_struct cinfo
;
10783 struct my_jpeg_error_mgr mgr
;
10784 Lisp_Object file
, specified_file
;
10785 Lisp_Object specified_data
;
10788 int row_stride
, x
, y
;
10789 XImage
*ximg
= NULL
;
10791 unsigned long *colors
;
10793 struct gcpro gcpro1
;
10795 /* Open the JPEG file. */
10796 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10797 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10801 if (NILP (specified_data
))
10803 file
= x_find_image_file (specified_file
);
10804 if (!STRINGP (file
))
10806 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10811 fp
= fopen (XSTRING (file
)->data
, "r");
10814 image_error ("Cannot open `%s'", file
, Qnil
);
10820 /* Customize libjpeg's error handling to call my_error_exit when an
10821 error is detected. This function will perform a longjmp. */
10822 mgr
.pub
.error_exit
= my_error_exit
;
10823 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
10825 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
10829 /* Called from my_error_exit. Display a JPEG error. */
10830 char buffer
[JMSG_LENGTH_MAX
];
10831 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
10832 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
10833 build_string (buffer
));
10836 /* Close the input file and destroy the JPEG object. */
10839 jpeg_destroy_decompress (&cinfo
);
10843 /* If we already have an XImage, free that. */
10844 x_destroy_x_image (ximg
);
10846 /* Free pixmap and colors. */
10847 x_clear_image (f
, img
);
10854 /* Create the JPEG decompression object. Let it read from fp.
10855 Read the JPEG image header. */
10856 jpeg_create_decompress (&cinfo
);
10858 if (NILP (specified_data
))
10859 jpeg_stdio_src (&cinfo
, fp
);
10861 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
10862 STRING_BYTES (XSTRING (specified_data
)));
10864 jpeg_read_header (&cinfo
, TRUE
);
10866 /* Customize decompression so that color quantization will be used.
10867 Start decompression. */
10868 cinfo
.quantize_colors
= TRUE
;
10869 jpeg_start_decompress (&cinfo
);
10870 width
= img
->width
= cinfo
.output_width
;
10871 height
= img
->height
= cinfo
.output_height
;
10875 /* Create X image and pixmap. */
10876 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10880 longjmp (mgr
.setjmp_buffer
, 2);
10883 /* Allocate colors. When color quantization is used,
10884 cinfo.actual_number_of_colors has been set with the number of
10885 colors generated, and cinfo.colormap is a two-dimensional array
10886 of color indices in the range 0..cinfo.actual_number_of_colors.
10887 No more than 255 colors will be generated. */
10891 if (cinfo
.out_color_components
> 2)
10892 ir
= 0, ig
= 1, ib
= 2;
10893 else if (cinfo
.out_color_components
> 1)
10894 ir
= 0, ig
= 1, ib
= 0;
10896 ir
= 0, ig
= 0, ib
= 0;
10898 /* Use the color table mechanism because it handles colors that
10899 cannot be allocated nicely. Such colors will be replaced with
10900 a default color, and we don't have to care about which colors
10901 can be freed safely, and which can't. */
10902 init_color_table ();
10903 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
10906 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
10908 /* Multiply RGB values with 255 because X expects RGB values
10909 in the range 0..0xffff. */
10910 int r
= cinfo
.colormap
[ir
][i
] << 8;
10911 int g
= cinfo
.colormap
[ig
][i
] << 8;
10912 int b
= cinfo
.colormap
[ib
][i
] << 8;
10913 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
10916 /* Remember those colors actually allocated. */
10917 img
->colors
= colors_in_color_table (&img
->ncolors
);
10918 free_color_table ();
10922 row_stride
= width
* cinfo
.output_components
;
10923 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
10925 for (y
= 0; y
< height
; ++y
)
10927 jpeg_read_scanlines (&cinfo
, buffer
, 1);
10928 for (x
= 0; x
< cinfo
.output_width
; ++x
)
10929 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
10933 jpeg_finish_decompress (&cinfo
);
10934 jpeg_destroy_decompress (&cinfo
);
10938 /* Put the image into the pixmap. */
10939 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10940 x_destroy_x_image (ximg
);
10946 #endif /* HAVE_JPEG */
10950 /***********************************************************************
10952 ***********************************************************************/
10956 #include <tiffio.h>
10958 static int tiff_image_p
P_ ((Lisp_Object object
));
10959 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
10961 /* The symbol `tiff' identifying images of this type. */
10965 /* Indices of image specification fields in tiff_format, below. */
10967 enum tiff_keyword_index
10976 TIFF_HEURISTIC_MASK
,
10980 /* Vector of image_keyword structures describing the format
10981 of valid user-defined image specifications. */
10983 static struct image_keyword tiff_format
[TIFF_LAST
] =
10985 {":type", IMAGE_SYMBOL_VALUE
, 1},
10986 {":data", IMAGE_STRING_VALUE
, 0},
10987 {":file", IMAGE_STRING_VALUE
, 0},
10988 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10989 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10990 {":relief", IMAGE_INTEGER_VALUE
, 0},
10991 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10992 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10995 /* Structure describing the image type `tiff'. */
10997 static struct image_type tiff_type
=
11007 /* Return non-zero if OBJECT is a valid TIFF image specification. */
11010 tiff_image_p (object
)
11011 Lisp_Object object
;
11013 struct image_keyword fmt
[TIFF_LAST
];
11014 bcopy (tiff_format
, fmt
, sizeof fmt
);
11016 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
11017 || (fmt
[TIFF_ASCENT
].count
11018 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
11021 /* Must specify either the :data or :file keyword. */
11022 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
11026 /* Reading from a memory buffer for TIFF images Based on the PNG
11027 memory source, but we have to provide a lot of extra functions.
11030 We really only need to implement read and seek, but I am not
11031 convinced that the TIFF library is smart enough not to destroy
11032 itself if we only hand it the function pointers we need to
11037 unsigned char *bytes
;
11041 tiff_memory_source
;
11044 tiff_read_from_memory (data
, buf
, size
)
11049 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11051 if (size
> src
->len
- src
->index
)
11052 return (size_t) -1;
11053 bcopy (src
->bytes
+ src
->index
, buf
, size
);
11054 src
->index
+= size
;
11059 tiff_write_from_memory (data
, buf
, size
)
11064 return (size_t) -1;
11068 tiff_seek_in_memory (data
, off
, whence
)
11073 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11078 case SEEK_SET
: /* Go from beginning of source. */
11082 case SEEK_END
: /* Go from end of source. */
11083 idx
= src
->len
+ off
;
11086 case SEEK_CUR
: /* Go from current position. */
11087 idx
= src
->index
+ off
;
11090 default: /* Invalid `whence'. */
11094 if (idx
> src
->len
|| idx
< 0)
11102 tiff_close_memory (data
)
11110 tiff_mmap_memory (data
, pbase
, psize
)
11115 /* It is already _IN_ memory. */
11120 tiff_unmap_memory (data
, base
, size
)
11125 /* We don't need to do this. */
11129 tiff_size_of_memory (data
)
11132 return ((tiff_memory_source
*) data
)->len
;
11135 /* Load TIFF image IMG for use on frame F. Value is non-zero if
11143 Lisp_Object file
, specified_file
;
11144 Lisp_Object specified_data
;
11146 int width
, height
, x
, y
;
11150 struct gcpro gcpro1
;
11151 tiff_memory_source memsrc
;
11153 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11154 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11158 if (NILP (specified_data
))
11160 /* Read from a file */
11161 file
= x_find_image_file (specified_file
);
11162 if (!STRINGP (file
))
11164 image_error ("Cannot find image file `%s'", file
, Qnil
);
11169 /* Try to open the image file. */
11170 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
11173 image_error ("Cannot open `%s'", file
, Qnil
);
11180 /* Memory source! */
11181 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11182 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11185 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
11186 (TIFFReadWriteProc
) tiff_read_from_memory
,
11187 (TIFFReadWriteProc
) tiff_write_from_memory
,
11188 tiff_seek_in_memory
,
11190 tiff_size_of_memory
,
11192 tiff_unmap_memory
);
11196 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
11202 /* Get width and height of the image, and allocate a raster buffer
11203 of width x height 32-bit values. */
11204 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
11205 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
11206 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
11208 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
11212 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
11220 /* Create the X image and pixmap. */
11221 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11229 /* Initialize the color table. */
11230 init_color_table ();
11232 /* Process the pixel raster. Origin is in the lower-left corner. */
11233 for (y
= 0; y
< height
; ++y
)
11235 uint32
*row
= buf
+ y
* width
;
11237 for (x
= 0; x
< width
; ++x
)
11239 uint32 abgr
= row
[x
];
11240 int r
= TIFFGetR (abgr
) << 8;
11241 int g
= TIFFGetG (abgr
) << 8;
11242 int b
= TIFFGetB (abgr
) << 8;
11243 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
11247 /* Remember the colors allocated for the image. Free the color table. */
11248 img
->colors
= colors_in_color_table (&img
->ncolors
);
11249 free_color_table ();
11251 /* Put the image into the pixmap, then free the X image and its buffer. */
11252 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11253 x_destroy_x_image (ximg
);
11257 img
->width
= width
;
11258 img
->height
= height
;
11264 #endif /* HAVE_TIFF != 0 */
11268 /***********************************************************************
11270 ***********************************************************************/
11274 #include <gif_lib.h>
11276 static int gif_image_p
P_ ((Lisp_Object object
));
11277 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
11279 /* The symbol `gif' identifying images of this type. */
11283 /* Indices of image specification fields in gif_format, below. */
11285 enum gif_keyword_index
11294 GIF_HEURISTIC_MASK
,
11299 /* Vector of image_keyword structures describing the format
11300 of valid user-defined image specifications. */
11302 static struct image_keyword gif_format
[GIF_LAST
] =
11304 {":type", IMAGE_SYMBOL_VALUE
, 1},
11305 {":data", IMAGE_STRING_VALUE
, 0},
11306 {":file", IMAGE_STRING_VALUE
, 0},
11307 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11308 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11309 {":relief", IMAGE_INTEGER_VALUE
, 0},
11310 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11311 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11312 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0}
11315 /* Structure describing the image type `gif'. */
11317 static struct image_type gif_type
=
11326 /* Return non-zero if OBJECT is a valid GIF image specification. */
11329 gif_image_p (object
)
11330 Lisp_Object object
;
11332 struct image_keyword fmt
[GIF_LAST
];
11333 bcopy (gif_format
, fmt
, sizeof fmt
);
11335 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
11336 || (fmt
[GIF_ASCENT
].count
11337 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
11340 /* Must specify either the :data or :file keyword. */
11341 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
11344 /* Reading a GIF image from memory
11345 Based on the PNG memory stuff to a certain extent. */
11349 unsigned char *bytes
;
11355 /* Make the current memory source available to gif_read_from_memory.
11356 It's done this way because not all versions of libungif support
11357 a UserData field in the GifFileType structure. */
11358 static gif_memory_source
*current_gif_memory_src
;
11361 gif_read_from_memory (file
, buf
, len
)
11366 gif_memory_source
*src
= current_gif_memory_src
;
11368 if (len
> src
->len
- src
->index
)
11371 bcopy (src
->bytes
+ src
->index
, buf
, len
);
11377 /* Load GIF image IMG for use on frame F. Value is non-zero if
11385 Lisp_Object file
, specified_file
;
11386 Lisp_Object specified_data
;
11387 int rc
, width
, height
, x
, y
, i
;
11389 ColorMapObject
*gif_color_map
;
11390 unsigned long pixel_colors
[256];
11392 struct gcpro gcpro1
;
11394 int ino
, image_left
, image_top
, image_width
, image_height
;
11395 gif_memory_source memsrc
;
11396 unsigned char *raster
;
11398 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11399 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11403 if (NILP (specified_data
))
11405 file
= x_find_image_file (specified_file
);
11406 if (!STRINGP (file
))
11408 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11413 /* Open the GIF file. */
11414 gif
= DGifOpenFileName (XSTRING (file
)->data
);
11417 image_error ("Cannot open `%s'", file
, Qnil
);
11424 /* Read from memory! */
11425 current_gif_memory_src
= &memsrc
;
11426 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11427 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11430 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
11433 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
11439 /* Read entire contents. */
11440 rc
= DGifSlurp (gif
);
11441 if (rc
== GIF_ERROR
)
11443 image_error ("Error reading `%s'", img
->spec
, Qnil
);
11444 DGifCloseFile (gif
);
11449 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
11450 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
11451 if (ino
>= gif
->ImageCount
)
11453 image_error ("Invalid image number `%s' in image `%s'",
11455 DGifCloseFile (gif
);
11460 width
= img
->width
= gif
->SWidth
;
11461 height
= img
->height
= gif
->SHeight
;
11465 /* Create the X image and pixmap. */
11466 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11469 DGifCloseFile (gif
);
11474 /* Allocate colors. */
11475 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
11476 if (!gif_color_map
)
11477 gif_color_map
= gif
->SColorMap
;
11478 init_color_table ();
11479 bzero (pixel_colors
, sizeof pixel_colors
);
11481 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
11483 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
11484 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
11485 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
11486 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11489 img
->colors
= colors_in_color_table (&img
->ncolors
);
11490 free_color_table ();
11492 /* Clear the part of the screen image that are not covered by
11493 the image from the GIF file. Full animated GIF support
11494 requires more than can be done here (see the gif89 spec,
11495 disposal methods). Let's simply assume that the part
11496 not covered by a sub-image is in the frame's background color. */
11497 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
11498 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
11499 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
11500 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
11502 for (y
= 0; y
< image_top
; ++y
)
11503 for (x
= 0; x
< width
; ++x
)
11504 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11506 for (y
= image_top
+ image_height
; y
< height
; ++y
)
11507 for (x
= 0; x
< width
; ++x
)
11508 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11510 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
11512 for (x
= 0; x
< image_left
; ++x
)
11513 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11514 for (x
= image_left
+ image_width
; x
< width
; ++x
)
11515 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11518 /* Read the GIF image into the X image. We use a local variable
11519 `raster' here because RasterBits below is a char *, and invites
11520 problems with bytes >= 0x80. */
11521 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
11523 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
11525 static int interlace_start
[] = {0, 4, 2, 1};
11526 static int interlace_increment
[] = {8, 8, 4, 2};
11528 int row
= interlace_start
[0];
11532 for (y
= 0; y
< image_height
; y
++)
11534 if (row
>= image_height
)
11536 row
= interlace_start
[++pass
];
11537 while (row
>= image_height
)
11538 row
= interlace_start
[++pass
];
11541 for (x
= 0; x
< image_width
; x
++)
11543 int i
= raster
[(y
* image_width
) + x
];
11544 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
11548 row
+= interlace_increment
[pass
];
11553 for (y
= 0; y
< image_height
; ++y
)
11554 for (x
= 0; x
< image_width
; ++x
)
11556 int i
= raster
[y
* image_width
+ x
];
11557 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
11561 DGifCloseFile (gif
);
11563 /* Put the image into the pixmap, then free the X image and its buffer. */
11564 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11565 x_destroy_x_image (ximg
);
11572 #endif /* HAVE_GIF != 0 */
11576 /***********************************************************************
11578 ***********************************************************************/
11580 #ifdef HAVE_GHOSTSCRIPT
11581 static int gs_image_p
P_ ((Lisp_Object object
));
11582 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
11583 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
11585 /* The symbol `postscript' identifying images of this type. */
11587 Lisp_Object Qpostscript
;
11589 /* Keyword symbols. */
11591 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
11593 /* Indices of image specification fields in gs_format, below. */
11595 enum gs_keyword_index
11611 /* Vector of image_keyword structures describing the format
11612 of valid user-defined image specifications. */
11614 static struct image_keyword gs_format
[GS_LAST
] =
11616 {":type", IMAGE_SYMBOL_VALUE
, 1},
11617 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11618 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11619 {":file", IMAGE_STRING_VALUE
, 1},
11620 {":loader", IMAGE_FUNCTION_VALUE
, 0},
11621 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
11622 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11623 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11624 {":relief", IMAGE_INTEGER_VALUE
, 0},
11625 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11626 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11629 /* Structure describing the image type `ghostscript'. */
11631 static struct image_type gs_type
=
11641 /* Free X resources of Ghostscript image IMG which is used on frame F. */
11644 gs_clear_image (f
, img
)
11648 /* IMG->data.ptr_val may contain a recorded colormap. */
11649 xfree (img
->data
.ptr_val
);
11650 x_clear_image (f
, img
);
11654 /* Return non-zero if OBJECT is a valid Ghostscript image
11658 gs_image_p (object
)
11659 Lisp_Object object
;
11661 struct image_keyword fmt
[GS_LAST
];
11665 bcopy (gs_format
, fmt
, sizeof fmt
);
11667 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
11668 || (fmt
[GS_ASCENT
].count
11669 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
11672 /* Bounding box must be a list or vector containing 4 integers. */
11673 tem
= fmt
[GS_BOUNDING_BOX
].value
;
11676 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
11677 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
11682 else if (VECTORP (tem
))
11684 if (XVECTOR (tem
)->size
!= 4)
11686 for (i
= 0; i
< 4; ++i
)
11687 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
11697 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
11706 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
11707 struct gcpro gcpro1
, gcpro2
;
11709 double in_width
, in_height
;
11710 Lisp_Object pixel_colors
= Qnil
;
11712 /* Compute pixel size of pixmap needed from the given size in the
11713 image specification. Sizes in the specification are in pt. 1 pt
11714 = 1/72 in, xdpi and ydpi are stored in the frame's X display
11716 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
11717 in_width
= XFASTINT (pt_width
) / 72.0;
11718 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
11719 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
11720 in_height
= XFASTINT (pt_height
) / 72.0;
11721 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
11723 /* Create the pixmap. */
11725 xassert (img
->pixmap
== 0);
11726 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11727 img
->width
, img
->height
,
11728 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
11733 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
11737 /* Call the loader to fill the pixmap. It returns a process object
11738 if successful. We do not record_unwind_protect here because
11739 other places in redisplay like calling window scroll functions
11740 don't either. Let the Lisp loader use `unwind-protect' instead. */
11741 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
11743 sprintf (buffer
, "%lu %lu",
11744 (unsigned long) FRAME_W32_WINDOW (f
),
11745 (unsigned long) img
->pixmap
);
11746 window_and_pixmap_id
= build_string (buffer
);
11748 sprintf (buffer
, "%lu %lu",
11749 FRAME_FOREGROUND_PIXEL (f
),
11750 FRAME_BACKGROUND_PIXEL (f
));
11751 pixel_colors
= build_string (buffer
);
11753 XSETFRAME (frame
, f
);
11754 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
11756 loader
= intern ("gs-load-image");
11758 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
11759 make_number (img
->width
),
11760 make_number (img
->height
),
11761 window_and_pixmap_id
,
11764 return PROCESSP (img
->data
.lisp_val
);
11768 /* Kill the Ghostscript process that was started to fill PIXMAP on
11769 frame F. Called from XTread_socket when receiving an event
11770 telling Emacs that Ghostscript has finished drawing. */
11773 x_kill_gs_process (pixmap
, f
)
11777 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
11781 /* Find the image containing PIXMAP. */
11782 for (i
= 0; i
< c
->used
; ++i
)
11783 if (c
->images
[i
]->pixmap
== pixmap
)
11786 /* Kill the GS process. We should have found PIXMAP in the image
11787 cache and its image should contain a process object. */
11788 xassert (i
< c
->used
);
11789 img
= c
->images
[i
];
11790 xassert (PROCESSP (img
->data
.lisp_val
));
11791 Fkill_process (img
->data
.lisp_val
, Qnil
);
11792 img
->data
.lisp_val
= Qnil
;
11794 /* On displays with a mutable colormap, figure out the colors
11795 allocated for the image by looking at the pixels of an XImage for
11797 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
11798 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
11804 /* Try to get an XImage for img->pixmep. */
11805 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
11806 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
11811 /* Initialize the color table. */
11812 init_color_table ();
11814 /* For each pixel of the image, look its color up in the
11815 color table. After having done so, the color table will
11816 contain an entry for each color used by the image. */
11817 for (y
= 0; y
< img
->height
; ++y
)
11818 for (x
= 0; x
< img
->width
; ++x
)
11820 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
11821 lookup_pixel_color (f
, pixel
);
11824 /* Record colors in the image. Free color table and XImage. */
11825 img
->colors
= colors_in_color_table (&img
->ncolors
);
11826 free_color_table ();
11827 XDestroyImage (ximg
);
11829 #if 0 /* This doesn't seem to be the case. If we free the colors
11830 here, we get a BadAccess later in x_clear_image when
11831 freeing the colors. */
11832 /* We have allocated colors once, but Ghostscript has also
11833 allocated colors on behalf of us. So, to get the
11834 reference counts right, free them once. */
11837 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
11838 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
,
11839 img
->colors
, img
->ncolors
, 0);
11844 image_error ("Cannot get X image of `%s'; colors will not be freed",
11851 #endif /* HAVE_GHOSTSCRIPT */
11854 /***********************************************************************
11856 ***********************************************************************/
11858 DEFUN ("x-change-window-property", Fx_change_window_property
,
11859 Sx_change_window_property
, 2, 3, 0,
11860 "Change window property PROP to VALUE on the X window of FRAME.\n\
11861 PROP and VALUE must be strings. FRAME nil or omitted means use the\n\
11862 selected frame. Value is VALUE.")
11863 (prop
, value
, frame
)
11864 Lisp_Object frame
, prop
, value
;
11866 #if 0 /* TODO : port window properties to W32 */
11867 struct frame
*f
= check_x_frame (frame
);
11870 CHECK_STRING (prop
, 1);
11871 CHECK_STRING (value
, 2);
11874 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11875 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11876 prop_atom
, XA_STRING
, 8, PropModeReplace
,
11877 XSTRING (value
)->data
, XSTRING (value
)->size
);
11879 /* Make sure the property is set when we return. */
11880 XFlush (FRAME_W32_DISPLAY (f
));
11889 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
11890 Sx_delete_window_property
, 1, 2, 0,
11891 "Remove window property PROP from X window of FRAME.\n\
11892 FRAME nil or omitted means use the selected frame. Value is PROP.")
11894 Lisp_Object prop
, frame
;
11896 #if 0 /* TODO : port window properties to W32 */
11898 struct frame
*f
= check_x_frame (frame
);
11901 CHECK_STRING (prop
, 1);
11903 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11904 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
11906 /* Make sure the property is removed when we return. */
11907 XFlush (FRAME_W32_DISPLAY (f
));
11915 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
11917 "Value is the value of window property PROP on FRAME.\n\
11918 If FRAME is nil or omitted, use the selected frame. Value is nil\n\
11919 if FRAME hasn't a property with name PROP or if PROP has no string\n\
11922 Lisp_Object prop
, frame
;
11924 #if 0 /* TODO : port window properties to W32 */
11926 struct frame
*f
= check_x_frame (frame
);
11929 Lisp_Object prop_value
= Qnil
;
11930 char *tmp_data
= NULL
;
11933 unsigned long actual_size
, bytes_remaining
;
11935 CHECK_STRING (prop
, 1);
11937 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11938 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11939 prop_atom
, 0, 0, False
, XA_STRING
,
11940 &actual_type
, &actual_format
, &actual_size
,
11941 &bytes_remaining
, (unsigned char **) &tmp_data
);
11944 int size
= bytes_remaining
;
11949 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11950 prop_atom
, 0, bytes_remaining
,
11952 &actual_type
, &actual_format
,
11953 &actual_size
, &bytes_remaining
,
11954 (unsigned char **) &tmp_data
);
11956 prop_value
= make_string (tmp_data
, size
);
11971 /***********************************************************************
11973 ***********************************************************************/
11975 /* If non-null, an asynchronous timer that, when it expires, displays
11976 a busy cursor on all frames. */
11978 static struct atimer
*busy_cursor_atimer
;
11980 /* Non-zero means a busy cursor is currently shown. */
11982 static int busy_cursor_shown_p
;
11984 /* Number of seconds to wait before displaying a busy cursor. */
11986 static Lisp_Object Vbusy_cursor_delay
;
11988 /* Default number of seconds to wait before displaying a busy
11991 #define DEFAULT_BUSY_CURSOR_DELAY 1
11993 /* Function prototypes. */
11995 static void show_busy_cursor
P_ ((struct atimer
*));
11996 static void hide_busy_cursor
P_ ((void));
11999 /* Cancel a currently active busy-cursor timer, and start a new one. */
12002 start_busy_cursor ()
12004 #if 0 /* TODO: cursor shape changes. */
12006 int secs
, usecs
= 0;
12008 cancel_busy_cursor ();
12010 if (INTEGERP (Vbusy_cursor_delay
)
12011 && XINT (Vbusy_cursor_delay
) > 0)
12012 secs
= XFASTINT (Vbusy_cursor_delay
);
12013 else if (FLOATP (Vbusy_cursor_delay
)
12014 && XFLOAT_DATA (Vbusy_cursor_delay
) > 0)
12017 tem
= Ftruncate (Vbusy_cursor_delay
, Qnil
);
12018 secs
= XFASTINT (tem
);
12019 usecs
= (XFLOAT_DATA (Vbusy_cursor_delay
) - secs
) * 1000000;
12022 secs
= DEFAULT_BUSY_CURSOR_DELAY
;
12024 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
12025 busy_cursor_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
12026 show_busy_cursor
, NULL
);
12031 /* Cancel the busy cursor timer if active, hide a busy cursor if
12035 cancel_busy_cursor ()
12037 if (busy_cursor_atimer
)
12039 cancel_atimer (busy_cursor_atimer
);
12040 busy_cursor_atimer
= NULL
;
12043 if (busy_cursor_shown_p
)
12044 hide_busy_cursor ();
12048 /* Timer function of busy_cursor_atimer. TIMER is equal to
12049 busy_cursor_atimer.
12051 Display a busy cursor on all frames by mapping the frames'
12052 busy_window. Set the busy_p flag in the frames' output_data.x
12053 structure to indicate that a busy cursor is shown on the
12057 show_busy_cursor (timer
)
12058 struct atimer
*timer
;
12060 #if 0 /* TODO: cursor shape changes. */
12061 /* The timer implementation will cancel this timer automatically
12062 after this function has run. Set busy_cursor_atimer to null
12063 so that we know the timer doesn't have to be canceled. */
12064 busy_cursor_atimer
= NULL
;
12066 if (!busy_cursor_shown_p
)
12068 Lisp_Object rest
, frame
;
12072 FOR_EACH_FRAME (rest
, frame
)
12073 if (FRAME_X_P (XFRAME (frame
)))
12075 struct frame
*f
= XFRAME (frame
);
12077 f
->output_data
.w32
->busy_p
= 1;
12079 if (!f
->output_data
.w32
->busy_window
)
12081 unsigned long mask
= CWCursor
;
12082 XSetWindowAttributes attrs
;
12084 attrs
.cursor
= f
->output_data
.w32
->busy_cursor
;
12086 f
->output_data
.w32
->busy_window
12087 = XCreateWindow (FRAME_X_DISPLAY (f
),
12088 FRAME_OUTER_WINDOW (f
),
12089 0, 0, 32000, 32000, 0, 0,
12095 XMapRaised (FRAME_X_DISPLAY (f
), f
->output_data
.w32
->busy_window
);
12096 XFlush (FRAME_X_DISPLAY (f
));
12099 busy_cursor_shown_p
= 1;
12106 /* Hide the busy cursor on all frames, if it is currently shown. */
12109 hide_busy_cursor ()
12111 #if 0 /* TODO: cursor shape changes. */
12112 if (busy_cursor_shown_p
)
12114 Lisp_Object rest
, frame
;
12117 FOR_EACH_FRAME (rest
, frame
)
12119 struct frame
*f
= XFRAME (frame
);
12122 /* Watch out for newly created frames. */
12123 && f
->output_data
.x
->busy_window
)
12125 XUnmapWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->busy_window
);
12126 /* Sync here because XTread_socket looks at the busy_p flag
12127 that is reset to zero below. */
12128 XSync (FRAME_X_DISPLAY (f
), False
);
12129 f
->output_data
.x
->busy_p
= 0;
12133 busy_cursor_shown_p
= 0;
12141 /***********************************************************************
12143 ***********************************************************************/
12145 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
12148 /* The frame of a currently visible tooltip, or null. */
12150 struct frame
*tip_frame
;
12152 /* If non-nil, a timer started that hides the last tooltip when it
12155 Lisp_Object tip_timer
;
12158 /* Create a frame for a tooltip on the display described by DPYINFO.
12159 PARMS is a list of frame parameters. Value is the frame. */
12162 x_create_tip_frame (dpyinfo
, parms
)
12163 struct w32_display_info
*dpyinfo
;
12166 #if 0 /* TODO : w32 version */
12168 Lisp_Object frame
, tem
;
12170 long window_prompting
= 0;
12172 int count
= specpdl_ptr
- specpdl
;
12173 struct gcpro gcpro1
, gcpro2
, gcpro3
;
12178 /* Use this general default value to start with until we know if
12179 this frame has a specified name. */
12180 Vx_resource_name
= Vinvocation_name
;
12182 #ifdef MULTI_KBOARD
12183 kb
= dpyinfo
->kboard
;
12185 kb
= &the_only_kboard
;
12188 /* Get the name of the frame to use for resource lookup. */
12189 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
12190 if (!STRINGP (name
)
12191 && !EQ (name
, Qunbound
)
12193 error ("Invalid frame name--not a string or nil");
12194 Vx_resource_name
= name
;
12197 GCPRO3 (parms
, name
, frame
);
12198 tip_frame
= f
= make_frame (1);
12199 XSETFRAME (frame
, f
);
12200 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
12202 f
->output_method
= output_w32
;
12203 f
->output_data
.w32
=
12204 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
12205 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
12207 f
->output_data
.w32
->icon_bitmap
= -1;
12209 f
->output_data
.w32
->fontset
= -1;
12210 f
->icon_name
= Qnil
;
12212 #ifdef MULTI_KBOARD
12213 FRAME_KBOARD (f
) = kb
;
12215 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12216 f
->output_data
.w32
->explicit_parent
= 0;
12218 /* Set the name; the functions to which we pass f expect the name to
12220 if (EQ (name
, Qunbound
) || NILP (name
))
12222 f
->name
= build_string (dpyinfo
->x_id_name
);
12223 f
->explicit_name
= 0;
12228 f
->explicit_name
= 1;
12229 /* use the frame's title when getting resources for this frame. */
12230 specbind (Qx_resource_name
, name
);
12233 /* Extract the window parameters from the supplied values
12234 that are needed to determine window geometry. */
12238 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
12241 /* First, try whatever font the caller has specified. */
12242 if (STRINGP (font
))
12244 tem
= Fquery_fontset (font
, Qnil
);
12246 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
12248 font
= x_new_font (f
, XSTRING (font
)->data
);
12251 /* Try out a font which we hope has bold and italic variations. */
12252 if (!STRINGP (font
))
12253 font
= x_new_font (f
, "-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
12254 if (!STRINGP (font
))
12255 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12256 if (! STRINGP (font
))
12257 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12258 if (! STRINGP (font
))
12259 /* This was formerly the first thing tried, but it finds too many fonts
12260 and takes too long. */
12261 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
12262 /* If those didn't work, look for something which will at least work. */
12263 if (! STRINGP (font
))
12264 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
12266 if (! STRINGP (font
))
12267 font
= build_string ("fixed");
12269 x_default_parameter (f
, parms
, Qfont
, font
,
12270 "font", "Font", RES_TYPE_STRING
);
12273 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
12274 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
12276 /* This defaults to 2 in order to match xterm. We recognize either
12277 internalBorderWidth or internalBorder (which is what xterm calls
12279 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12283 value
= w32_get_arg (parms
, Qinternal_border_width
,
12284 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
12285 if (! EQ (value
, Qunbound
))
12286 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
12290 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
12291 "internalBorderWidth", "internalBorderWidth",
12294 /* Also do the stuff which must be set before the window exists. */
12295 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
12296 "foreground", "Foreground", RES_TYPE_STRING
);
12297 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
12298 "background", "Background", RES_TYPE_STRING
);
12299 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
12300 "pointerColor", "Foreground", RES_TYPE_STRING
);
12301 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
12302 "cursorColor", "Foreground", RES_TYPE_STRING
);
12303 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
12304 "borderColor", "BorderColor", RES_TYPE_STRING
);
12306 /* Init faces before x_default_parameter is called for scroll-bar
12307 parameters because that function calls x_set_scroll_bar_width,
12308 which calls change_frame_size, which calls Fset_window_buffer,
12309 which runs hooks, which call Fvertical_motion. At the end, we
12310 end up in init_iterator with a null face cache, which should not
12312 init_frame_faces (f
);
12314 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12315 window_prompting
= x_figure_window_size (f
, parms
);
12317 if (window_prompting
& XNegative
)
12319 if (window_prompting
& YNegative
)
12320 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
12322 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
12326 if (window_prompting
& YNegative
)
12327 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
12329 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
12332 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
12334 XSetWindowAttributes attrs
;
12335 unsigned long mask
;
12338 mask
= CWBackPixel
| CWOverrideRedirect
| CWSaveUnder
| CWEventMask
;
12339 /* Window managers looks at the override-redirect flag to
12340 determine whether or net to give windows a decoration (Xlib
12342 attrs
.override_redirect
= True
;
12343 attrs
.save_under
= True
;
12344 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
12345 /* Arrange for getting MapNotify and UnmapNotify events. */
12346 attrs
.event_mask
= StructureNotifyMask
;
12348 = FRAME_W32_WINDOW (f
)
12349 = XCreateWindow (FRAME_W32_DISPLAY (f
),
12350 FRAME_W32_DISPLAY_INFO (f
)->root_window
,
12351 /* x, y, width, height */
12355 CopyFromParent
, InputOutput
, CopyFromParent
,
12362 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
12363 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12364 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
12365 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12366 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
12367 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
12369 /* Dimensions, especially f->height, must be done via change_frame_size.
12370 Change will not be effected unless different from the current
12373 height
= f
->height
;
12375 SET_FRAME_WIDTH (f
, 0);
12376 change_frame_size (f
, height
, width
, 1, 0, 0);
12382 /* It is now ok to make the frame official even if we get an error
12383 below. And the frame needs to be on Vframe_list or making it
12384 visible won't work. */
12385 Vframe_list
= Fcons (frame
, Vframe_list
);
12387 /* Now that the frame is official, it counts as a reference to
12389 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
12391 return unbind_to (count
, frame
);
12396 #ifdef TODO /* Tooltip support not complete. */
12397 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
12398 "Show STRING in a \"tooltip\" window on frame FRAME.\n\
12399 A tooltip window is a small X window displaying a string.\n\
12401 FRAME nil or omitted means use the selected frame.\n\
12403 PARMS is an optional list of frame parameters which can be\n\
12404 used to change the tooltip's appearance.\n\
12406 Automatically hide the tooltip after TIMEOUT seconds.\n\
12407 TIMEOUT nil means use the default timeout of 5 seconds.\n\
12409 If the list of frame parameters PARAMS contains a `left' parameters,\n\
12410 the tooltip is displayed at that x-position. Otherwise it is\n\
12411 displayed at the mouse position, with offset DX added (default is 5 if\n\
12412 DX isn't specified). Likewise for the y-position; if a `top' frame\n\
12413 parameter is specified, it determines the y-position of the tooltip\n\
12414 window, otherwise it is displayed at the mouse position, with offset\n\
12415 DY added (default is -5).")
12416 (string
, frame
, parms
, timeout
, dx
, dy
)
12417 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
12421 Window root
, child
;
12422 Lisp_Object buffer
, top
, left
;
12423 struct buffer
*old_buffer
;
12424 struct text_pos pos
;
12425 int i
, width
, height
;
12426 int root_x
, root_y
, win_x
, win_y
;
12428 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
12429 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
12430 int count
= specpdl_ptr
- specpdl
;
12432 specbind (Qinhibit_redisplay
, Qt
);
12434 GCPRO4 (string
, parms
, frame
, timeout
);
12436 CHECK_STRING (string
, 0);
12437 f
= check_x_frame (frame
);
12438 if (NILP (timeout
))
12439 timeout
= make_number (5);
12441 CHECK_NATNUM (timeout
, 2);
12444 dx
= make_number (5);
12446 CHECK_NUMBER (dx
, 5);
12449 dy
= make_number (-5);
12451 CHECK_NUMBER (dy
, 6);
12453 /* Hide a previous tip, if any. */
12456 /* Add default values to frame parameters. */
12457 if (NILP (Fassq (Qname
, parms
)))
12458 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
12459 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12460 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
12461 if (NILP (Fassq (Qborder_width
, parms
)))
12462 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
12463 if (NILP (Fassq (Qborder_color
, parms
)))
12464 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
12465 if (NILP (Fassq (Qbackground_color
, parms
)))
12466 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
12469 /* Create a frame for the tooltip, and record it in the global
12470 variable tip_frame. */
12471 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
);
12472 tip_frame
= f
= XFRAME (frame
);
12474 /* Set up the frame's root window. Currently we use a size of 80
12475 columns x 40 lines. If someone wants to show a larger tip, he
12476 will loose. I don't think this is a realistic case. */
12477 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
12478 w
->left
= w
->top
= make_number (0);
12482 w
->pseudo_window_p
= 1;
12484 /* Display the tooltip text in a temporary buffer. */
12485 buffer
= Fget_buffer_create (build_string (" *tip*"));
12486 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
12487 old_buffer
= current_buffer
;
12488 set_buffer_internal_1 (XBUFFER (buffer
));
12490 Finsert (make_number (1), &string
);
12491 clear_glyph_matrix (w
->desired_matrix
);
12492 clear_glyph_matrix (w
->current_matrix
);
12493 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
12494 try_window (FRAME_ROOT_WINDOW (f
), pos
);
12496 /* Compute width and height of the tooltip. */
12497 width
= height
= 0;
12498 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
12500 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
12501 struct glyph
*last
;
12504 /* Stop at the first empty row at the end. */
12505 if (!row
->enabled_p
|| !row
->displays_text_p
)
12508 /* Let the row go over the full width of the frame. */
12509 row
->full_width_p
= 1;
12511 /* There's a glyph at the end of rows that is use to place
12512 the cursor there. Don't include the width of this glyph. */
12513 if (row
->used
[TEXT_AREA
])
12515 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
12516 row_width
= row
->pixel_width
- last
->pixel_width
;
12519 row_width
= row
->pixel_width
;
12521 height
+= row
->height
;
12522 width
= max (width
, row_width
);
12525 /* Add the frame's internal border to the width and height the X
12526 window should have. */
12527 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12528 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12530 /* User-specified position? */
12531 left
= Fcdr (Fassq (Qleft
, parms
));
12532 top
= Fcdr (Fassq (Qtop
, parms
));
12534 /* Move the tooltip window where the mouse pointer is. Resize and
12536 #if 0 /* TODO : W32 specifics */
12538 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
12539 &root
, &child
, &root_x
, &root_y
, &win_x
, &win_y
, &pmask
);
12542 root_x
+= XINT (dx
);
12543 root_y
+= XINT (dy
);
12545 if (INTEGERP (left
))
12546 root_x
= XINT (left
);
12547 if (INTEGERP (top
))
12548 root_y
= XINT (top
);
12551 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12552 root_x
, root_y
- height
, width
, height
);
12553 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12557 /* Draw into the window. */
12558 w
->must_be_updated_p
= 1;
12559 update_single_window (w
, 1);
12561 /* Restore original current buffer. */
12562 set_buffer_internal_1 (old_buffer
);
12563 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
12565 /* Let the tip disappear after timeout seconds. */
12566 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
12567 intern ("x-hide-tip"));
12570 return unbind_to (count
, Qnil
);
12574 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
12575 "Hide the current tooltip window, if there is any.\n\
12576 Value is t is tooltip was open, nil otherwise.")
12579 int count
= specpdl_ptr
- specpdl
;
12582 specbind (Qinhibit_redisplay
, Qt
);
12584 if (!NILP (tip_timer
))
12586 call1 (intern ("cancel-timer"), tip_timer
);
12594 XSETFRAME (frame
, tip_frame
);
12595 Fdelete_frame (frame
, Qt
);
12600 return unbind_to (count
, deleted_p
? Qt
: Qnil
);
12606 /***********************************************************************
12607 File selection dialog
12608 ***********************************************************************/
12610 extern Lisp_Object Qfile_name_history
;
12612 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
12613 "Read file name, prompting with PROMPT in directory DIR.\n\
12614 Use a file selection dialog.\n\
12615 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
12616 specified. Don't let the user enter a file name in the file\n\
12617 selection dialog's entry field, if MUSTMATCH is non-nil.")
12618 (prompt
, dir
, default_filename
, mustmatch
)
12619 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
12621 struct frame
*f
= SELECTED_FRAME ();
12622 Lisp_Object file
= Qnil
;
12623 int count
= specpdl_ptr
- specpdl
;
12624 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
12625 char filename
[MAX_PATH
+ 1];
12626 char init_dir
[MAX_PATH
+ 1];
12627 int use_dialog_p
= 1;
12629 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
12630 CHECK_STRING (prompt
, 0);
12631 CHECK_STRING (dir
, 1);
12633 /* Create the dialog with PROMPT as title, using DIR as initial
12634 directory and using "*" as pattern. */
12635 dir
= Fexpand_file_name (dir
, Qnil
);
12636 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
12637 init_dir
[MAX_PATH
] = '\0';
12638 unixtodos_filename (init_dir
);
12640 if (STRINGP (default_filename
))
12642 char *file_name_only
;
12643 char *full_path_name
= XSTRING (default_filename
)->data
;
12645 unixtodos_filename (full_path_name
);
12647 file_name_only
= strrchr (full_path_name
, '\\');
12648 if (!file_name_only
)
12649 file_name_only
= full_path_name
;
12654 /* If default_file_name is a directory, don't use the open
12655 file dialog, as it does not support selecting
12657 if (!(*file_name_only
))
12661 strncpy (filename
, file_name_only
, MAX_PATH
);
12662 filename
[MAX_PATH
] = '\0';
12665 filename
[0] = '\0';
12669 OPENFILENAME file_details
;
12670 char *filename_file
;
12672 /* Prevent redisplay. */
12673 specbind (Qinhibit_redisplay
, Qt
);
12676 bzero (&file_details
, sizeof (file_details
));
12677 file_details
.lStructSize
= sizeof (file_details
);
12678 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
12679 file_details
.lpstrFile
= filename
;
12680 file_details
.nMaxFile
= sizeof (filename
);
12681 file_details
.lpstrInitialDir
= init_dir
;
12682 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
12683 file_details
.Flags
= OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
;
12685 if (!NILP (mustmatch
))
12686 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
12688 if (GetOpenFileName (&file_details
))
12690 dostounix_filename (filename
);
12691 file
= build_string (filename
);
12697 file
= unbind_to (count
, file
);
12699 /* Open File dialog will not allow folders to be selected, so resort
12700 to minibuffer completing reads for directories. */
12702 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
12703 dir
, mustmatch
, dir
, Qfile_name_history
,
12704 default_filename
, Qnil
);
12708 /* Make "Cancel" equivalent to C-g. */
12710 Fsignal (Qquit
, Qnil
);
12712 return unbind_to (count
, file
);
12717 /***********************************************************************
12719 ***********************************************************************/
12723 DEFUN ("imagep", Fimagep
, Simagep
, 1, 1, 0,
12724 "Value is non-nil if SPEC is a valid image specification.")
12728 return valid_image_p (spec
) ? Qt
: Qnil
;
12732 DEFUN ("lookup-image", Flookup_image
, Slookup_image
, 1, 1, 0, "")
12738 if (valid_image_p (spec
))
12739 id
= lookup_image (SELECTED_FRAME (), spec
);
12741 debug_print (spec
);
12742 return make_number (id
);
12745 #endif /* GLYPH_DEBUG != 0 */
12749 /***********************************************************************
12750 w32 specialized functions
12751 ***********************************************************************/
12753 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 1, 0,
12754 "This will display the W32 font dialog and return an X font string corresponding to the selection.")
12758 FRAME_PTR f
= check_x_frame (frame
);
12766 bzero (&cf
, sizeof (cf
));
12767 bzero (&lf
, sizeof (lf
));
12769 cf
.lStructSize
= sizeof (cf
);
12770 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
12771 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
;
12772 cf
.lpLogFont
= &lf
;
12774 /* Initialize as much of the font details as we can from the current
12776 hdc
= GetDC (FRAME_W32_WINDOW (f
));
12777 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
12778 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
12779 if (GetTextMetrics (hdc
, &tm
))
12781 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
12782 lf
.lfWeight
= tm
.tmWeight
;
12783 lf
.lfItalic
= tm
.tmItalic
;
12784 lf
.lfUnderline
= tm
.tmUnderlined
;
12785 lf
.lfStrikeOut
= tm
.tmStruckOut
;
12786 lf
.lfCharSet
= tm
.tmCharSet
;
12787 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
12789 SelectObject (hdc
, oldobj
);
12790 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
12792 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
12795 return build_string (buf
);
12798 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
, Sw32_send_sys_command
, 1, 2, 0,
12799 "Send frame a Windows WM_SYSCOMMAND message of type COMMAND.\n\
12800 Some useful values for command are 0xf030 to maximise frame (0xf020\n\
12801 to minimize), 0xf120 to restore frame to original size, and 0xf100\n\
12802 to activate the menubar for keyboard access. 0xf140 activates the\n\
12803 screen saver if defined.\n\
12805 If optional parameter FRAME is not specified, use selected frame.")
12807 Lisp_Object command
, frame
;
12810 FRAME_PTR f
= check_x_frame (frame
);
12812 CHECK_NUMBER (command
, 0);
12814 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
12819 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
12820 "Get Windows to perform OPERATION on DOCUMENT.\n\
12821 This is a wrapper around the ShellExecute system function, which\n\
12822 invokes the application registered to handle OPERATION for DOCUMENT.\n\
12823 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be\n\
12824 nil for the default action), and DOCUMENT is typically the name of a\n\
12825 document file or URL, but can also be a program executable to run or\n\
12826 a directory to open in the Windows Explorer.\n\
12828 If DOCUMENT is a program executable, PARAMETERS can be a string\n\
12829 containing command line parameters, but otherwise should be nil.\n\
12831 SHOW-FLAG can be used to control whether the invoked application is hidden\n\
12832 or minimized. If SHOW-FLAG is nil, the application is displayed normally,\n\
12833 otherwise it is an integer representing a ShowWindow flag:\n\
12835 0 - start hidden\n\
12836 1 - start normally\n\
12837 3 - start maximized\n\
12838 6 - start minimized")
12839 (operation
, document
, parameters
, show_flag
)
12840 Lisp_Object operation
, document
, parameters
, show_flag
;
12842 Lisp_Object current_dir
;
12844 CHECK_STRING (document
, 0);
12846 /* Encode filename and current directory. */
12847 current_dir
= ENCODE_FILE (current_buffer
->directory
);
12848 document
= ENCODE_FILE (document
);
12849 if ((int) ShellExecute (NULL
,
12850 (STRINGP (operation
) ?
12851 XSTRING (operation
)->data
: NULL
),
12852 XSTRING (document
)->data
,
12853 (STRINGP (parameters
) ?
12854 XSTRING (parameters
)->data
: NULL
),
12855 XSTRING (current_dir
)->data
,
12856 (INTEGERP (show_flag
) ?
12857 XINT (show_flag
) : SW_SHOWDEFAULT
))
12860 error ("ShellExecute failed");
12863 /* Lookup virtual keycode from string representing the name of a
12864 non-ascii keystroke into the corresponding virtual key, using
12865 lispy_function_keys. */
12867 lookup_vk_code (char *key
)
12871 for (i
= 0; i
< 256; i
++)
12872 if (lispy_function_keys
[i
] != 0
12873 && strcmp (lispy_function_keys
[i
], key
) == 0)
12879 /* Convert a one-element vector style key sequence to a hot key
12882 w32_parse_hot_key (key
)
12885 /* Copied from Fdefine_key and store_in_keymap. */
12886 register Lisp_Object c
;
12888 int lisp_modifiers
;
12890 struct gcpro gcpro1
;
12892 CHECK_VECTOR (key
, 0);
12894 if (XFASTINT (Flength (key
)) != 1)
12899 c
= Faref (key
, make_number (0));
12901 if (CONSP (c
) && lucid_event_type_list_p (c
))
12902 c
= Fevent_convert_list (c
);
12906 if (! INTEGERP (c
) && ! SYMBOLP (c
))
12907 error ("Key definition is invalid");
12909 /* Work out the base key and the modifiers. */
12912 c
= parse_modifiers (c
);
12913 lisp_modifiers
= Fcar (Fcdr (c
));
12917 vk_code
= lookup_vk_code (XSYMBOL (c
)->name
->data
);
12919 else if (INTEGERP (c
))
12921 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
12922 /* Many ascii characters are their own virtual key code. */
12923 vk_code
= XINT (c
) & CHARACTERBITS
;
12926 if (vk_code
< 0 || vk_code
> 255)
12929 if ((lisp_modifiers
& meta_modifier
) != 0
12930 && !NILP (Vw32_alt_is_meta
))
12931 lisp_modifiers
|= alt_modifier
;
12933 /* Supply defs missing from mingw32. */
12935 #define MOD_ALT 0x0001
12936 #define MOD_CONTROL 0x0002
12937 #define MOD_SHIFT 0x0004
12938 #define MOD_WIN 0x0008
12941 /* Convert lisp modifiers to Windows hot-key form. */
12942 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
12943 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
12944 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
12945 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
12947 return HOTKEY (vk_code
, w32_modifiers
);
12950 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
, Sw32_register_hot_key
, 1, 1, 0,
12951 "Register KEY as a hot-key combination.\n\
12952 Certain key combinations like Alt-Tab are reserved for system use on\n\
12953 Windows, and therefore are normally intercepted by the system. However,\n\
12954 most of these key combinations can be received by registering them as\n\
12955 hot-keys, overriding their special meaning.\n\
12957 KEY must be a one element key definition in vector form that would be\n\
12958 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta\n\
12959 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper\n\
12960 is always interpreted as the Windows modifier keys.\n\
12962 The return value is the hotkey-id if registered, otherwise nil.")
12966 key
= w32_parse_hot_key (key
);
12968 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
12970 /* Reuse an empty slot if possible. */
12971 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
12973 /* Safe to add new key to list, even if we have focus. */
12975 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
12979 /* Notify input thread about new hot-key definition, so that it
12980 takes effect without needing to switch focus. */
12981 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
12988 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
, Sw32_unregister_hot_key
, 1, 1, 0,
12989 "Unregister HOTKEY as a hot-key combination.")
12995 if (!INTEGERP (key
))
12996 key
= w32_parse_hot_key (key
);
12998 item
= Fmemq (key
, w32_grabbed_keys
);
13002 /* Notify input thread about hot-key definition being removed, so
13003 that it takes effect without needing focus switch. */
13004 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
13005 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
13008 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13015 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
, Sw32_registered_hot_keys
, 0, 0, 0,
13016 "Return list of registered hot-key IDs.")
13019 return Fcopy_sequence (w32_grabbed_keys
);
13022 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
, Sw32_reconstruct_hot_key
, 1, 1, 0,
13023 "Convert hot-key ID to a lisp key combination.")
13025 Lisp_Object hotkeyid
;
13027 int vk_code
, w32_modifiers
;
13030 CHECK_NUMBER (hotkeyid
, 0);
13032 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
13033 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
13035 if (lispy_function_keys
[vk_code
])
13036 key
= intern (lispy_function_keys
[vk_code
]);
13038 key
= make_number (vk_code
);
13040 key
= Fcons (key
, Qnil
);
13041 if (w32_modifiers
& MOD_SHIFT
)
13042 key
= Fcons (Qshift
, key
);
13043 if (w32_modifiers
& MOD_CONTROL
)
13044 key
= Fcons (Qctrl
, key
);
13045 if (w32_modifiers
& MOD_ALT
)
13046 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
13047 if (w32_modifiers
& MOD_WIN
)
13048 key
= Fcons (Qhyper
, key
);
13053 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
, Sw32_toggle_lock_key
, 1, 2, 0,
13054 "Toggle the state of the lock key KEY.\n\
13055 KEY can be `capslock', `kp-numlock', or `scroll'.\n\
13056 If the optional parameter NEW-STATE is a number, then the state of KEY\n\
13057 is set to off if the low bit of NEW-STATE is zero, otherwise on.")
13059 Lisp_Object key
, new_state
;
13064 if (EQ (key
, intern ("capslock")))
13065 vk_code
= VK_CAPITAL
;
13066 else if (EQ (key
, intern ("kp-numlock")))
13067 vk_code
= VK_NUMLOCK
;
13068 else if (EQ (key
, intern ("scroll")))
13069 vk_code
= VK_SCROLL
;
13073 if (!dwWindowsThreadId
)
13074 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
13076 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
13077 (WPARAM
) vk_code
, (LPARAM
) new_state
))
13080 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13081 return make_number (msg
.wParam
);
13088 /* This is zero if not using MS-Windows. */
13091 /* The section below is built by the lisp expression at the top of the file,
13092 just above where these variables are declared. */
13093 /*&&& init symbols here &&&*/
13094 Qauto_raise
= intern ("auto-raise");
13095 staticpro (&Qauto_raise
);
13096 Qauto_lower
= intern ("auto-lower");
13097 staticpro (&Qauto_lower
);
13098 Qbar
= intern ("bar");
13100 Qborder_color
= intern ("border-color");
13101 staticpro (&Qborder_color
);
13102 Qborder_width
= intern ("border-width");
13103 staticpro (&Qborder_width
);
13104 Qbox
= intern ("box");
13106 Qcursor_color
= intern ("cursor-color");
13107 staticpro (&Qcursor_color
);
13108 Qcursor_type
= intern ("cursor-type");
13109 staticpro (&Qcursor_type
);
13110 Qgeometry
= intern ("geometry");
13111 staticpro (&Qgeometry
);
13112 Qicon_left
= intern ("icon-left");
13113 staticpro (&Qicon_left
);
13114 Qicon_top
= intern ("icon-top");
13115 staticpro (&Qicon_top
);
13116 Qicon_type
= intern ("icon-type");
13117 staticpro (&Qicon_type
);
13118 Qicon_name
= intern ("icon-name");
13119 staticpro (&Qicon_name
);
13120 Qinternal_border_width
= intern ("internal-border-width");
13121 staticpro (&Qinternal_border_width
);
13122 Qleft
= intern ("left");
13123 staticpro (&Qleft
);
13124 Qright
= intern ("right");
13125 staticpro (&Qright
);
13126 Qmouse_color
= intern ("mouse-color");
13127 staticpro (&Qmouse_color
);
13128 Qnone
= intern ("none");
13129 staticpro (&Qnone
);
13130 Qparent_id
= intern ("parent-id");
13131 staticpro (&Qparent_id
);
13132 Qscroll_bar_width
= intern ("scroll-bar-width");
13133 staticpro (&Qscroll_bar_width
);
13134 Qsuppress_icon
= intern ("suppress-icon");
13135 staticpro (&Qsuppress_icon
);
13136 Qundefined_color
= intern ("undefined-color");
13137 staticpro (&Qundefined_color
);
13138 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
13139 staticpro (&Qvertical_scroll_bars
);
13140 Qvisibility
= intern ("visibility");
13141 staticpro (&Qvisibility
);
13142 Qwindow_id
= intern ("window-id");
13143 staticpro (&Qwindow_id
);
13144 Qx_frame_parameter
= intern ("x-frame-parameter");
13145 staticpro (&Qx_frame_parameter
);
13146 Qx_resource_name
= intern ("x-resource-name");
13147 staticpro (&Qx_resource_name
);
13148 Quser_position
= intern ("user-position");
13149 staticpro (&Quser_position
);
13150 Quser_size
= intern ("user-size");
13151 staticpro (&Quser_size
);
13152 Qscreen_gamma
= intern ("screen-gamma");
13153 staticpro (&Qscreen_gamma
);
13154 Qline_spacing
= intern ("line-spacing");
13155 staticpro (&Qline_spacing
);
13156 Qcenter
= intern ("center");
13157 staticpro (&Qcenter
);
13158 /* This is the end of symbol initialization. */
13160 Qhyper
= intern ("hyper");
13161 staticpro (&Qhyper
);
13162 Qsuper
= intern ("super");
13163 staticpro (&Qsuper
);
13164 Qmeta
= intern ("meta");
13165 staticpro (&Qmeta
);
13166 Qalt
= intern ("alt");
13168 Qctrl
= intern ("ctrl");
13169 staticpro (&Qctrl
);
13170 Qcontrol
= intern ("control");
13171 staticpro (&Qcontrol
);
13172 Qshift
= intern ("shift");
13173 staticpro (&Qshift
);
13175 /* Text property `display' should be nonsticky by default. */
13176 Vtext_property_default_nonsticky
13177 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
13180 Qlaplace
= intern ("laplace");
13181 staticpro (&Qlaplace
);
13183 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
13184 staticpro (&Qface_set_after_frame_default
);
13186 Fput (Qundefined_color
, Qerror_conditions
,
13187 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
13188 Fput (Qundefined_color
, Qerror_message
,
13189 build_string ("Undefined color"));
13191 staticpro (&w32_grabbed_keys
);
13192 w32_grabbed_keys
= Qnil
;
13194 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
13195 "An array of color name mappings for windows.");
13196 Vw32_color_map
= Qnil
;
13198 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
13199 "Non-nil if alt key presses are passed on to Windows.\n\
13200 When non-nil, for example, alt pressed and released and then space will\n\
13201 open the System menu. When nil, Emacs silently swallows alt key events.");
13202 Vw32_pass_alt_to_system
= Qnil
;
13204 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
13205 "Non-nil if the alt key is to be considered the same as the meta key.\n\
13206 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta.");
13207 Vw32_alt_is_meta
= Qt
;
13209 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
13210 "If non-zero, the virtual key code for an alternative quit key.");
13211 XSETINT (Vw32_quit_key
, 0);
13213 DEFVAR_LISP ("w32-pass-lwindow-to-system",
13214 &Vw32_pass_lwindow_to_system
,
13215 "Non-nil if the left \"Windows\" key is passed on to Windows.\n\
13216 When non-nil, the Start menu is opened by tapping the key.");
13217 Vw32_pass_lwindow_to_system
= Qt
;
13219 DEFVAR_LISP ("w32-pass-rwindow-to-system",
13220 &Vw32_pass_rwindow_to_system
,
13221 "Non-nil if the right \"Windows\" key is passed on to Windows.\n\
13222 When non-nil, the Start menu is opened by tapping the key.");
13223 Vw32_pass_rwindow_to_system
= Qt
;
13225 DEFVAR_INT ("w32-phantom-key-code",
13226 &Vw32_phantom_key_code
,
13227 "Virtual key code used to generate \"phantom\" key presses.\n\
13228 Value is a number between 0 and 255.\n\
13230 Phantom key presses are generated in order to stop the system from\n\
13231 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or\n\
13232 `w32-pass-rwindow-to-system' is nil.");
13233 /* Although 255 is technically not a valid key code, it works and
13234 means that this hack won't interfere with any real key code. */
13235 Vw32_phantom_key_code
= 255;
13237 DEFVAR_LISP ("w32-enable-num-lock",
13238 &Vw32_enable_num_lock
,
13239 "Non-nil if Num Lock should act normally.\n\
13240 Set to nil to see Num Lock as the key `kp-numlock'.");
13241 Vw32_enable_num_lock
= Qt
;
13243 DEFVAR_LISP ("w32-enable-caps-lock",
13244 &Vw32_enable_caps_lock
,
13245 "Non-nil if Caps Lock should act normally.\n\
13246 Set to nil to see Caps Lock as the key `capslock'.");
13247 Vw32_enable_caps_lock
= Qt
;
13249 DEFVAR_LISP ("w32-scroll-lock-modifier",
13250 &Vw32_scroll_lock_modifier
,
13251 "Modifier to use for the Scroll Lock on state.\n\
13252 The value can be hyper, super, meta, alt, control or shift for the\n\
13253 respective modifier, or nil to see Scroll Lock as the key `scroll'.\n\
13254 Any other value will cause the key to be ignored.");
13255 Vw32_scroll_lock_modifier
= Qt
;
13257 DEFVAR_LISP ("w32-lwindow-modifier",
13258 &Vw32_lwindow_modifier
,
13259 "Modifier to use for the left \"Windows\" key.\n\
13260 The value can be hyper, super, meta, alt, control or shift for the\n\
13261 respective modifier, or nil to appear as the key `lwindow'.\n\
13262 Any other value will cause the key to be ignored.");
13263 Vw32_lwindow_modifier
= Qnil
;
13265 DEFVAR_LISP ("w32-rwindow-modifier",
13266 &Vw32_rwindow_modifier
,
13267 "Modifier to use for the right \"Windows\" key.\n\
13268 The value can be hyper, super, meta, alt, control or shift for the\n\
13269 respective modifier, or nil to appear as the key `rwindow'.\n\
13270 Any other value will cause the key to be ignored.");
13271 Vw32_rwindow_modifier
= Qnil
;
13273 DEFVAR_LISP ("w32-apps-modifier",
13274 &Vw32_apps_modifier
,
13275 "Modifier to use for the \"Apps\" key.\n\
13276 The value can be hyper, super, meta, alt, control or shift for the\n\
13277 respective modifier, or nil to appear as the key `apps'.\n\
13278 Any other value will cause the key to be ignored.");
13279 Vw32_apps_modifier
= Qnil
;
13281 DEFVAR_LISP ("w32-enable-synthesized-fonts", &Vw32_enable_synthesized_fonts
,
13282 "Non-nil enables selection of artificially italicized and bold fonts.");
13283 Vw32_enable_synthesized_fonts
= Qnil
;
13285 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
13286 "Non-nil enables Windows palette management to map colors exactly.");
13287 Vw32_enable_palette
= Qt
;
13289 DEFVAR_INT ("w32-mouse-button-tolerance",
13290 &Vw32_mouse_button_tolerance
,
13291 "Analogue of double click interval for faking middle mouse events.\n\
13292 The value is the minimum time in milliseconds that must elapse between\n\
13293 left/right button down events before they are considered distinct events.\n\
13294 If both mouse buttons are depressed within this interval, a middle mouse\n\
13295 button down event is generated instead.");
13296 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
13298 DEFVAR_INT ("w32-mouse-move-interval",
13299 &Vw32_mouse_move_interval
,
13300 "Minimum interval between mouse move events.\n\
13301 The value is the minimum time in milliseconds that must elapse between\n\
13302 successive mouse move (or scroll bar drag) events before they are\n\
13303 reported as lisp events.");
13304 XSETINT (Vw32_mouse_move_interval
, 0);
13306 init_x_parm_symbols ();
13308 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
13309 "List of directories to search for bitmap files for w32.");
13310 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
13312 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
13313 "The shape of the pointer when over text.\n\
13314 Changing the value does not affect existing frames\n\
13315 unless you set the mouse color.");
13316 Vx_pointer_shape
= Qnil
;
13318 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
13319 "The name Emacs uses to look up resources; for internal use only.\n\
13320 `x-get-resource' uses this as the first component of the instance name\n\
13321 when requesting resource values.\n\
13322 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
13323 was invoked, or to the value specified with the `-name' or `-rn'\n\
13324 switches, if present.");
13325 Vx_resource_name
= Qnil
;
13327 Vx_nontext_pointer_shape
= Qnil
;
13329 Vx_mode_pointer_shape
= Qnil
;
13331 DEFVAR_LISP ("x-busy-pointer-shape", &Vx_busy_pointer_shape
,
13332 "The shape of the pointer when Emacs is busy.\n\
13333 This variable takes effect when you create a new frame\n\
13334 or when you set the mouse color.");
13335 Vx_busy_pointer_shape
= Qnil
;
13337 DEFVAR_BOOL ("display-busy-cursor", &display_busy_cursor_p
,
13338 "Non-zero means Emacs displays a busy cursor on window systems.");
13339 display_busy_cursor_p
= 1;
13341 DEFVAR_LISP ("busy-cursor-delay", &Vbusy_cursor_delay
,
13342 "*Seconds to wait before displaying a busy-cursor.\n\
13343 Value must be an integer or float.");
13344 Vbusy_cursor_delay
= make_number (DEFAULT_BUSY_CURSOR_DELAY
);
13346 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
13347 &Vx_sensitive_text_pointer_shape
,
13348 "The shape of the pointer when over mouse-sensitive text.\n\
13349 This variable takes effect when you create a new frame\n\
13350 or when you set the mouse color.");
13351 Vx_sensitive_text_pointer_shape
= Qnil
;
13353 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
13354 "A string indicating the foreground color of the cursor box.");
13355 Vx_cursor_fore_pixel
= Qnil
;
13357 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
13358 "Non-nil if no window manager is in use.\n\
13359 Emacs doesn't try to figure this out; this is always nil\n\
13360 unless you set it to something else.");
13361 /* We don't have any way to find this out, so set it to nil
13362 and maybe the user would like to set it to t. */
13363 Vx_no_window_manager
= Qnil
;
13365 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
13366 &Vx_pixel_size_width_font_regexp
,
13367 "Regexp matching a font name whose width is the same as `PIXEL_SIZE'.\n\
13369 Since Emacs gets width of a font matching with this regexp from\n\
13370 PIXEL_SIZE field of the name, font finding mechanism gets faster for\n\
13371 such a font. This is especially effective for such large fonts as\n\
13372 Chinese, Japanese, and Korean.");
13373 Vx_pixel_size_width_font_regexp
= Qnil
;
13375 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
13376 "Time after which cached images are removed from the cache.\n\
13377 When an image has not been displayed this many seconds, remove it\n\
13378 from the image cache. Value must be an integer or nil with nil\n\
13379 meaning don't clear the cache.");
13380 Vimage_cache_eviction_delay
= make_number (30 * 60);
13382 DEFVAR_LISP ("w32-bdf-filename-alist",
13383 &Vw32_bdf_filename_alist
,
13384 "List of bdf fonts and their corresponding filenames.");
13385 Vw32_bdf_filename_alist
= Qnil
;
13387 DEFVAR_BOOL ("w32-strict-fontnames",
13388 &w32_strict_fontnames
,
13389 "Non-nil means only use fonts that are exact matches for those requested.\n\
13390 Default is nil, which allows old fontnames that are not XLFD compliant,\n\
13391 and allows third-party CJK display to work by specifying false charset\n\
13392 fields to trick Emacs into translating to Big5, SJIS etc.\n\
13393 Setting this to t will prevent wrong fonts being selected when\n\
13394 fontsets are automatically created.");
13395 w32_strict_fontnames
= 0;
13397 DEFVAR_BOOL ("w32-strict-painting",
13398 &w32_strict_painting
,
13399 "Non-nil means use strict rules for repainting frames.\n\
13400 Set this to nil to get the old behaviour for repainting; this should\n\
13401 only be necessary if the default setting causes problems.");
13402 w32_strict_painting
= 1;
13404 DEFVAR_LISP ("w32-system-coding-system",
13405 &Vw32_system_coding_system
,
13406 "Coding system used by Windows system functions, such as for font names.");
13407 Vw32_system_coding_system
= Qnil
;
13409 DEFVAR_LISP ("w32-charset-info-alist",
13410 &Vw32_charset_info_alist
,
13411 "Alist linking Emacs character sets to Windows fonts\n\
13412 and codepages. Each entry should be of the form:\n\
13414 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))\n\
13416 where CHARSET_NAME is a string used in font names to identify the charset,\n\
13417 WINDOWS_CHARSET is a symbol that can be one of:\n\
13418 w32-charset-ansi, w32-charset-default, w32-charset-symbol,\n\
13419 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,\n\
13420 w32-charset-chinesebig5, "
13421 #ifdef JOHAB_CHARSET
13422 "w32-charset-johab, w32-charset-hebrew,\n\
13423 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,\n\
13424 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,\n\
13425 w32-charset-russian, w32-charset-mac, w32-charset-baltic,\n"
13427 #ifdef UNICODE_CHARSET
13428 "w32-charset-unicode, "
13430 "or w32-charset-oem.\n\
13431 CODEPAGE should be an integer specifying the codepage that should be used\n\
13432 to display the character set, t to do no translation and output as Unicode,\n\
13433 or nil to do no translation and output as 8 bit (or multibyte on far-east\n\
13434 versions of Windows) characters.");
13435 Vw32_charset_info_alist
= Qnil
;
13437 staticpro (&Qw32_charset_ansi
);
13438 Qw32_charset_ansi
= intern ("w32-charset-ansi");
13439 staticpro (&Qw32_charset_symbol
);
13440 Qw32_charset_symbol
= intern ("w32-charset-symbol");
13441 staticpro (&Qw32_charset_shiftjis
);
13442 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
13443 staticpro (&Qw32_charset_hangeul
);
13444 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
13445 staticpro (&Qw32_charset_chinesebig5
);
13446 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
13447 staticpro (&Qw32_charset_gb2312
);
13448 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
13449 staticpro (&Qw32_charset_oem
);
13450 Qw32_charset_oem
= intern ("w32-charset-oem");
13452 #ifdef JOHAB_CHARSET
13454 static int w32_extra_charsets_defined
= 1;
13455 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
, "");
13457 staticpro (&Qw32_charset_johab
);
13458 Qw32_charset_johab
= intern ("w32-charset-johab");
13459 staticpro (&Qw32_charset_easteurope
);
13460 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
13461 staticpro (&Qw32_charset_turkish
);
13462 Qw32_charset_turkish
= intern ("w32-charset-turkish");
13463 staticpro (&Qw32_charset_baltic
);
13464 Qw32_charset_baltic
= intern ("w32-charset-baltic");
13465 staticpro (&Qw32_charset_russian
);
13466 Qw32_charset_russian
= intern ("w32-charset-russian");
13467 staticpro (&Qw32_charset_arabic
);
13468 Qw32_charset_arabic
= intern ("w32-charset-arabic");
13469 staticpro (&Qw32_charset_greek
);
13470 Qw32_charset_greek
= intern ("w32-charset-greek");
13471 staticpro (&Qw32_charset_hebrew
);
13472 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
13473 staticpro (&Qw32_charset_vietnamese
);
13474 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
13475 staticpro (&Qw32_charset_thai
);
13476 Qw32_charset_thai
= intern ("w32-charset-thai");
13477 staticpro (&Qw32_charset_mac
);
13478 Qw32_charset_mac
= intern ("w32-charset-mac");
13482 #ifdef UNICODE_CHARSET
13484 static int w32_unicode_charset_defined
= 1;
13485 DEFVAR_BOOL ("w32-unicode-charset-defined",
13486 &w32_unicode_charset_defined
, "");
13488 staticpro (&Qw32_charset_unicode
);
13489 Qw32_charset_unicode
= intern ("w32-charset-unicode");
13492 defsubr (&Sx_get_resource
);
13493 #if 0 /* TODO: Port to W32 */
13494 defsubr (&Sx_change_window_property
);
13495 defsubr (&Sx_delete_window_property
);
13496 defsubr (&Sx_window_property
);
13498 defsubr (&Sxw_display_color_p
);
13499 defsubr (&Sx_display_grayscale_p
);
13500 defsubr (&Sxw_color_defined_p
);
13501 defsubr (&Sxw_color_values
);
13502 defsubr (&Sx_server_max_request_size
);
13503 defsubr (&Sx_server_vendor
);
13504 defsubr (&Sx_server_version
);
13505 defsubr (&Sx_display_pixel_width
);
13506 defsubr (&Sx_display_pixel_height
);
13507 defsubr (&Sx_display_mm_width
);
13508 defsubr (&Sx_display_mm_height
);
13509 defsubr (&Sx_display_screens
);
13510 defsubr (&Sx_display_planes
);
13511 defsubr (&Sx_display_color_cells
);
13512 defsubr (&Sx_display_visual_class
);
13513 defsubr (&Sx_display_backing_store
);
13514 defsubr (&Sx_display_save_under
);
13515 defsubr (&Sx_parse_geometry
);
13516 defsubr (&Sx_create_frame
);
13517 defsubr (&Sx_open_connection
);
13518 defsubr (&Sx_close_connection
);
13519 defsubr (&Sx_display_list
);
13520 defsubr (&Sx_synchronize
);
13522 /* W32 specific functions */
13524 defsubr (&Sw32_focus_frame
);
13525 defsubr (&Sw32_select_font
);
13526 defsubr (&Sw32_define_rgb_color
);
13527 defsubr (&Sw32_default_color_map
);
13528 defsubr (&Sw32_load_color_file
);
13529 defsubr (&Sw32_send_sys_command
);
13530 defsubr (&Sw32_shell_execute
);
13531 defsubr (&Sw32_register_hot_key
);
13532 defsubr (&Sw32_unregister_hot_key
);
13533 defsubr (&Sw32_registered_hot_keys
);
13534 defsubr (&Sw32_reconstruct_hot_key
);
13535 defsubr (&Sw32_toggle_lock_key
);
13536 defsubr (&Sw32_find_bdf_fonts
);
13538 /* Setting callback functions for fontset handler. */
13539 get_font_info_func
= w32_get_font_info
;
13541 #if 0 /* This function pointer doesn't seem to be used anywhere.
13542 And the pointer assigned has the wrong type, anyway. */
13543 list_fonts_func
= w32_list_fonts
;
13546 load_font_func
= w32_load_font
;
13547 find_ccl_program_func
= w32_find_ccl_program
;
13548 query_font_func
= w32_query_font
;
13549 set_frame_fontset_func
= x_set_font
;
13550 check_window_system_func
= check_w32
;
13552 #if 0 /* TODO Image support for W32 */
13554 Qxbm
= intern ("xbm");
13556 QCtype
= intern (":type");
13557 staticpro (&QCtype
);
13558 QCalgorithm
= intern (":algorithm");
13559 staticpro (&QCalgorithm
);
13560 QCheuristic_mask
= intern (":heuristic-mask");
13561 staticpro (&QCheuristic_mask
);
13562 QCcolor_symbols
= intern (":color-symbols");
13563 staticpro (&QCcolor_symbols
);
13564 QCascent
= intern (":ascent");
13565 staticpro (&QCascent
);
13566 QCmargin
= intern (":margin");
13567 staticpro (&QCmargin
);
13568 QCrelief
= intern (":relief");
13569 staticpro (&QCrelief
);
13570 Qpostscript
= intern ("postscript");
13571 staticpro (&Qpostscript
);
13572 QCloader
= intern (":loader");
13573 staticpro (&QCloader
);
13574 QCbounding_box
= intern (":bounding-box");
13575 staticpro (&QCbounding_box
);
13576 QCpt_width
= intern (":pt-width");
13577 staticpro (&QCpt_width
);
13578 QCpt_height
= intern (":pt-height");
13579 staticpro (&QCpt_height
);
13580 QCindex
= intern (":index");
13581 staticpro (&QCindex
);
13582 Qpbm
= intern ("pbm");
13586 Qxpm
= intern ("xpm");
13591 Qjpeg
= intern ("jpeg");
13592 staticpro (&Qjpeg
);
13596 Qtiff
= intern ("tiff");
13597 staticpro (&Qtiff
);
13601 Qgif
= intern ("gif");
13606 Qpng
= intern ("png");
13610 defsubr (&Sclear_image_cache
);
13613 defsubr (&Simagep
);
13614 defsubr (&Slookup_image
);
13618 busy_cursor_atimer
= NULL
;
13619 busy_cursor_shown_p
= 0;
13620 #ifdef TODO /* Tooltip support not complete. */
13621 defsubr (&Sx_show_tip
);
13622 defsubr (&Sx_hide_tip
);
13624 staticpro (&tip_timer
);
13627 defsubr (&Sx_file_dialog
);
13634 image_types
= NULL
;
13635 Vimage_types
= Qnil
;
13637 #if 0 /* TODO : Image support for W32 */
13638 define_image_type (&xbm_type
);
13639 define_image_type (&gs_type
);
13640 define_image_type (&pbm_type
);
13643 define_image_type (&xpm_type
);
13647 define_image_type (&jpeg_type
);
13651 define_image_type (&tiff_type
);
13655 define_image_type (&gif_type
);
13659 define_image_type (&png_type
);
13670 button
= MessageBox (NULL
,
13671 "A fatal error has occurred!\n\n"
13672 "Select Abort to exit, Retry to debug, Ignore to continue",
13673 "Emacs Abort Dialog",
13674 MB_ICONEXCLAMATION
| MB_TASKMODAL
13675 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
13690 /* For convenience when debugging. */
13694 return GetLastError ();