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 x_set_menu_bar_lines (f
, value
, oldval
)
2478 Lisp_Object value
, oldval
;
2481 int olines
= FRAME_MENU_BAR_LINES (f
);
2483 /* Right now, menu bars don't work properly in minibuf-only frames;
2484 most of the commands try to apply themselves to the minibuffer
2485 frame itself, and get an error because you can't switch buffers
2486 in or split the minibuffer window. */
2487 if (FRAME_MINIBUF_ONLY_P (f
))
2490 if (INTEGERP (value
))
2491 nlines
= XINT (value
);
2495 FRAME_MENU_BAR_LINES (f
) = 0;
2497 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2500 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2501 free_frame_menubar (f
);
2502 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2504 /* Adjust the frame size so that the client (text) dimensions
2505 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
2507 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2508 do_pending_window_change (0);
2514 /* Set the number of lines used for the tool bar of frame F to VALUE.
2515 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2516 is the old number of tool bar lines. This function changes the
2517 height of all windows on frame F to match the new tool bar height.
2518 The frame's height doesn't change. */
2521 x_set_tool_bar_lines (f
, value
, oldval
)
2523 Lisp_Object value
, oldval
;
2527 /* Use VALUE only if an integer >= 0. */
2528 if (INTEGERP (value
) && XINT (value
) >= 0)
2529 nlines
= XFASTINT (value
);
2533 /* Make sure we redisplay all windows in this frame. */
2534 ++windows_or_buffers_changed
;
2536 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2537 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2538 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2539 do_pending_window_change (0);
2544 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2547 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2548 name; if NAME is a string, set F's name to NAME and set
2549 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2551 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2552 suggesting a new name, which lisp code should override; if
2553 F->explicit_name is set, ignore the new name; otherwise, set it. */
2556 x_set_name (f
, name
, explicit)
2561 /* Make sure that requests from lisp code override requests from
2562 Emacs redisplay code. */
2565 /* If we're switching from explicit to implicit, we had better
2566 update the mode lines and thereby update the title. */
2567 if (f
->explicit_name
&& NILP (name
))
2568 update_mode_lines
= 1;
2570 f
->explicit_name
= ! NILP (name
);
2572 else if (f
->explicit_name
)
2575 /* If NAME is nil, set the name to the w32_id_name. */
2578 /* Check for no change needed in this very common case
2579 before we do any consing. */
2580 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
2581 XSTRING (f
->name
)->data
))
2583 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
2586 CHECK_STRING (name
, 0);
2588 /* Don't change the name if it's already NAME. */
2589 if (! NILP (Fstring_equal (name
, f
->name
)))
2594 /* For setting the frame title, the title parameter should override
2595 the name parameter. */
2596 if (! NILP (f
->title
))
2599 if (FRAME_W32_WINDOW (f
))
2601 if (STRING_MULTIBYTE (name
))
2602 name
= ENCODE_SYSTEM (name
);
2605 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2610 /* This function should be called when the user's lisp code has
2611 specified a name for the frame; the name will override any set by the
2614 x_explicitly_set_name (f
, arg
, oldval
)
2616 Lisp_Object arg
, oldval
;
2618 x_set_name (f
, arg
, 1);
2621 /* This function should be called by Emacs redisplay code to set the
2622 name; names set this way will never override names set by the user's
2625 x_implicitly_set_name (f
, arg
, oldval
)
2627 Lisp_Object arg
, oldval
;
2629 x_set_name (f
, arg
, 0);
2632 /* Change the title of frame F to NAME.
2633 If NAME is nil, use the frame name as the title.
2635 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2636 name; if NAME is a string, set F's name to NAME and set
2637 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2639 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2640 suggesting a new name, which lisp code should override; if
2641 F->explicit_name is set, ignore the new name; otherwise, set it. */
2644 x_set_title (f
, name
, old_name
)
2646 Lisp_Object name
, old_name
;
2648 /* Don't change the title if it's already NAME. */
2649 if (EQ (name
, f
->title
))
2652 update_mode_lines
= 1;
2659 if (FRAME_W32_WINDOW (f
))
2661 if (STRING_MULTIBYTE (name
))
2662 name
= ENCODE_SYSTEM (name
);
2665 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2671 x_set_autoraise (f
, arg
, oldval
)
2673 Lisp_Object arg
, oldval
;
2675 f
->auto_raise
= !EQ (Qnil
, arg
);
2679 x_set_autolower (f
, arg
, oldval
)
2681 Lisp_Object arg
, oldval
;
2683 f
->auto_lower
= !EQ (Qnil
, arg
);
2687 x_set_unsplittable (f
, arg
, oldval
)
2689 Lisp_Object arg
, oldval
;
2691 f
->no_split
= !NILP (arg
);
2695 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2697 Lisp_Object arg
, oldval
;
2699 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2700 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2701 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2702 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2704 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = NILP (arg
) ?
2705 vertical_scroll_bar_none
:
2706 /* Put scroll bars on the right by default, as is conventional
2709 ? vertical_scroll_bar_left
2710 : vertical_scroll_bar_right
;
2712 /* We set this parameter before creating the window for the
2713 frame, so we can get the geometry right from the start.
2714 However, if the window hasn't been created yet, we shouldn't
2715 call x_set_window_size. */
2716 if (FRAME_W32_WINDOW (f
))
2717 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2718 do_pending_window_change (0);
2723 x_set_scroll_bar_width (f
, arg
, oldval
)
2725 Lisp_Object arg
, oldval
;
2727 int wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
2731 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2732 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) +
2734 if (FRAME_W32_WINDOW (f
))
2735 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2736 do_pending_window_change (0);
2738 else if (INTEGERP (arg
) && XINT (arg
) > 0
2739 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2741 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2742 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2744 if (FRAME_W32_WINDOW (f
))
2745 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2746 do_pending_window_change (0);
2748 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2749 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2750 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2753 /* Subroutines of creating an frame. */
2755 /* Make sure that Vx_resource_name is set to a reasonable value.
2756 Fix it up, or set it to `emacs' if it is too hopeless. */
2759 validate_x_resource_name ()
2762 /* Number of valid characters in the resource name. */
2764 /* Number of invalid characters in the resource name. */
2769 if (STRINGP (Vx_resource_name
))
2771 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
2774 len
= STRING_BYTES (XSTRING (Vx_resource_name
));
2776 /* Only letters, digits, - and _ are valid in resource names.
2777 Count the valid characters and count the invalid ones. */
2778 for (i
= 0; i
< len
; i
++)
2781 if (! ((c
>= 'a' && c
<= 'z')
2782 || (c
>= 'A' && c
<= 'Z')
2783 || (c
>= '0' && c
<= '9')
2784 || c
== '-' || c
== '_'))
2791 /* Not a string => completely invalid. */
2792 bad_count
= 5, good_count
= 0;
2794 /* If name is valid already, return. */
2798 /* If name is entirely invalid, or nearly so, use `emacs'. */
2800 || (good_count
== 1 && bad_count
> 0))
2802 Vx_resource_name
= build_string ("emacs");
2806 /* Name is partly valid. Copy it and replace the invalid characters
2807 with underscores. */
2809 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
2811 for (i
= 0; i
< len
; i
++)
2813 int c
= XSTRING (new)->data
[i
];
2814 if (! ((c
>= 'a' && c
<= 'z')
2815 || (c
>= 'A' && c
<= 'Z')
2816 || (c
>= '0' && c
<= '9')
2817 || c
== '-' || c
== '_'))
2818 XSTRING (new)->data
[i
] = '_';
2823 extern char *x_get_string_resource ();
2825 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
2826 "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
2827 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
2828 class, where INSTANCE is the name under which Emacs was invoked, or\n\
2829 the name specified by the `-name' or `-rn' command-line arguments.\n\
2831 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
2832 class, respectively. You must specify both of them or neither.\n\
2833 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
2834 and the class is `Emacs.CLASS.SUBCLASS'.")
2835 (attribute
, class, component
, subclass
)
2836 Lisp_Object attribute
, class, component
, subclass
;
2838 register char *value
;
2842 CHECK_STRING (attribute
, 0);
2843 CHECK_STRING (class, 0);
2845 if (!NILP (component
))
2846 CHECK_STRING (component
, 1);
2847 if (!NILP (subclass
))
2848 CHECK_STRING (subclass
, 2);
2849 if (NILP (component
) != NILP (subclass
))
2850 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
2852 validate_x_resource_name ();
2854 /* Allocate space for the components, the dots which separate them,
2855 and the final '\0'. Make them big enough for the worst case. */
2856 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vx_resource_name
))
2857 + (STRINGP (component
)
2858 ? STRING_BYTES (XSTRING (component
)) : 0)
2859 + STRING_BYTES (XSTRING (attribute
))
2862 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2863 + STRING_BYTES (XSTRING (class))
2864 + (STRINGP (subclass
)
2865 ? STRING_BYTES (XSTRING (subclass
)) : 0)
2868 /* Start with emacs.FRAMENAME for the name (the specific one)
2869 and with `Emacs' for the class key (the general one). */
2870 strcpy (name_key
, XSTRING (Vx_resource_name
)->data
);
2871 strcpy (class_key
, EMACS_CLASS
);
2873 strcat (class_key
, ".");
2874 strcat (class_key
, XSTRING (class)->data
);
2876 if (!NILP (component
))
2878 strcat (class_key
, ".");
2879 strcat (class_key
, XSTRING (subclass
)->data
);
2881 strcat (name_key
, ".");
2882 strcat (name_key
, XSTRING (component
)->data
);
2885 strcat (name_key
, ".");
2886 strcat (name_key
, XSTRING (attribute
)->data
);
2888 value
= x_get_string_resource (Qnil
,
2889 name_key
, class_key
);
2891 if (value
!= (char *) 0)
2892 return build_string (value
);
2897 /* Used when C code wants a resource value. */
2900 x_get_resource_string (attribute
, class)
2901 char *attribute
, *class;
2905 struct frame
*sf
= SELECTED_FRAME ();
2907 /* Allocate space for the components, the dots which separate them,
2908 and the final '\0'. */
2909 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vinvocation_name
))
2910 + strlen (attribute
) + 2);
2911 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2912 + strlen (class) + 2);
2914 sprintf (name_key
, "%s.%s",
2915 XSTRING (Vinvocation_name
)->data
,
2917 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
2919 return x_get_string_resource (sf
, name_key
, class_key
);
2922 /* Types we might convert a resource string into. */
2932 /* Return the value of parameter PARAM.
2934 First search ALIST, then Vdefault_frame_alist, then the X defaults
2935 database, using ATTRIBUTE as the attribute name and CLASS as its class.
2937 Convert the resource to the type specified by desired_type.
2939 If no default is specified, return Qunbound. If you call
2940 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
2941 and don't let it get stored in any Lisp-visible variables! */
2944 w32_get_arg (alist
, param
, attribute
, class, type
)
2945 Lisp_Object alist
, param
;
2948 enum resource_types type
;
2950 register Lisp_Object tem
;
2952 tem
= Fassq (param
, alist
);
2954 tem
= Fassq (param
, Vdefault_frame_alist
);
2960 tem
= Fx_get_resource (build_string (attribute
),
2961 build_string (class),
2969 case RES_TYPE_NUMBER
:
2970 return make_number (atoi (XSTRING (tem
)->data
));
2972 case RES_TYPE_FLOAT
:
2973 return make_float (atof (XSTRING (tem
)->data
));
2975 case RES_TYPE_BOOLEAN
:
2976 tem
= Fdowncase (tem
);
2977 if (!strcmp (XSTRING (tem
)->data
, "on")
2978 || !strcmp (XSTRING (tem
)->data
, "true"))
2983 case RES_TYPE_STRING
:
2986 case RES_TYPE_SYMBOL
:
2987 /* As a special case, we map the values `true' and `on'
2988 to Qt, and `false' and `off' to Qnil. */
2991 lower
= Fdowncase (tem
);
2992 if (!strcmp (XSTRING (lower
)->data
, "on")
2993 || !strcmp (XSTRING (lower
)->data
, "true"))
2995 else if (!strcmp (XSTRING (lower
)->data
, "off")
2996 || !strcmp (XSTRING (lower
)->data
, "false"))
2999 return Fintern (tem
, Qnil
);
3012 /* Record in frame F the specified or default value according to ALIST
3013 of the parameter named PROP (a Lisp symbol).
3014 If no value is specified for PROP, look for an X default for XPROP
3015 on the frame named NAME.
3016 If that is not found either, use the value DEFLT. */
3019 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3026 enum resource_types type
;
3030 tem
= w32_get_arg (alist
, prop
, xprop
, xclass
, type
);
3031 if (EQ (tem
, Qunbound
))
3033 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3037 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3038 "Parse an X-style geometry string STRING.\n\
3039 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
3040 The properties returned may include `top', `left', `height', and `width'.\n\
3041 The value of `left' or `top' may be an integer,\n\
3042 or a list (+ N) meaning N pixels relative to top/left corner,\n\
3043 or a list (- N) meaning -N pixels relative to bottom/right corner.")
3048 unsigned int width
, height
;
3051 CHECK_STRING (string
, 0);
3053 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
3054 &x
, &y
, &width
, &height
);
3057 if (geometry
& XValue
)
3059 Lisp_Object element
;
3061 if (x
>= 0 && (geometry
& XNegative
))
3062 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3063 else if (x
< 0 && ! (geometry
& XNegative
))
3064 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3066 element
= Fcons (Qleft
, make_number (x
));
3067 result
= Fcons (element
, result
);
3070 if (geometry
& YValue
)
3072 Lisp_Object element
;
3074 if (y
>= 0 && (geometry
& YNegative
))
3075 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3076 else if (y
< 0 && ! (geometry
& YNegative
))
3077 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3079 element
= Fcons (Qtop
, make_number (y
));
3080 result
= Fcons (element
, result
);
3083 if (geometry
& WidthValue
)
3084 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3085 if (geometry
& HeightValue
)
3086 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3091 /* Calculate the desired size and position of this window,
3092 and return the flags saying which aspects were specified.
3094 This function does not make the coordinates positive. */
3096 #define DEFAULT_ROWS 40
3097 #define DEFAULT_COLS 80
3100 x_figure_window_size (f
, parms
)
3104 register Lisp_Object tem0
, tem1
, tem2
;
3105 long window_prompting
= 0;
3107 /* Default values if we fall through.
3108 Actually, if that happens we should get
3109 window manager prompting. */
3110 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3111 f
->height
= DEFAULT_ROWS
;
3112 /* Window managers expect that if program-specified
3113 positions are not (0,0), they're intentional, not defaults. */
3114 f
->output_data
.w32
->top_pos
= 0;
3115 f
->output_data
.w32
->left_pos
= 0;
3117 tem0
= w32_get_arg (parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3118 tem1
= w32_get_arg (parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3119 tem2
= w32_get_arg (parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3120 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3122 if (!EQ (tem0
, Qunbound
))
3124 CHECK_NUMBER (tem0
, 0);
3125 f
->height
= XINT (tem0
);
3127 if (!EQ (tem1
, Qunbound
))
3129 CHECK_NUMBER (tem1
, 0);
3130 SET_FRAME_WIDTH (f
, XINT (tem1
));
3132 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3133 window_prompting
|= USSize
;
3135 window_prompting
|= PSize
;
3138 f
->output_data
.w32
->vertical_scroll_bar_extra
3139 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3141 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3142 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3143 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
3144 f
->output_data
.w32
->flags_areas_extra
3145 = FRAME_FLAGS_AREA_WIDTH (f
);
3146 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3147 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3149 tem0
= w32_get_arg (parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3150 tem1
= w32_get_arg (parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3151 tem2
= w32_get_arg (parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3152 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3154 if (EQ (tem0
, Qminus
))
3156 f
->output_data
.w32
->top_pos
= 0;
3157 window_prompting
|= YNegative
;
3159 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3160 && CONSP (XCDR (tem0
))
3161 && INTEGERP (XCAR (XCDR (tem0
))))
3163 f
->output_data
.w32
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3164 window_prompting
|= YNegative
;
3166 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3167 && CONSP (XCDR (tem0
))
3168 && INTEGERP (XCAR (XCDR (tem0
))))
3170 f
->output_data
.w32
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3172 else if (EQ (tem0
, Qunbound
))
3173 f
->output_data
.w32
->top_pos
= 0;
3176 CHECK_NUMBER (tem0
, 0);
3177 f
->output_data
.w32
->top_pos
= XINT (tem0
);
3178 if (f
->output_data
.w32
->top_pos
< 0)
3179 window_prompting
|= YNegative
;
3182 if (EQ (tem1
, Qminus
))
3184 f
->output_data
.w32
->left_pos
= 0;
3185 window_prompting
|= XNegative
;
3187 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3188 && CONSP (XCDR (tem1
))
3189 && INTEGERP (XCAR (XCDR (tem1
))))
3191 f
->output_data
.w32
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3192 window_prompting
|= XNegative
;
3194 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3195 && CONSP (XCDR (tem1
))
3196 && INTEGERP (XCAR (XCDR (tem1
))))
3198 f
->output_data
.w32
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3200 else if (EQ (tem1
, Qunbound
))
3201 f
->output_data
.w32
->left_pos
= 0;
3204 CHECK_NUMBER (tem1
, 0);
3205 f
->output_data
.w32
->left_pos
= XINT (tem1
);
3206 if (f
->output_data
.w32
->left_pos
< 0)
3207 window_prompting
|= XNegative
;
3210 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3211 window_prompting
|= USPosition
;
3213 window_prompting
|= PPosition
;
3216 return window_prompting
;
3221 extern LRESULT CALLBACK
w32_wnd_proc ();
3224 w32_init_class (hinst
)
3229 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3230 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
3232 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
3233 wc
.hInstance
= hinst
;
3234 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
3235 wc
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
3236 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
3237 wc
.lpszMenuName
= NULL
;
3238 wc
.lpszClassName
= EMACS_CLASS
;
3240 return (RegisterClass (&wc
));
3244 w32_createscrollbar (f
, bar
)
3246 struct scroll_bar
* bar
;
3248 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
3249 /* Position and size of scroll bar. */
3250 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3252 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3254 FRAME_W32_WINDOW (f
),
3261 w32_createwindow (f
)
3267 rect
.left
= rect
.top
= 0;
3268 rect
.right
= PIXEL_WIDTH (f
);
3269 rect
.bottom
= PIXEL_HEIGHT (f
);
3271 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3272 FRAME_EXTERNAL_MENU_BAR (f
));
3274 /* Do first time app init */
3278 w32_init_class (hinst
);
3281 FRAME_W32_WINDOW (f
) = hwnd
3282 = CreateWindow (EMACS_CLASS
,
3284 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
3285 f
->output_data
.w32
->left_pos
,
3286 f
->output_data
.w32
->top_pos
,
3287 rect
.right
- rect
.left
,
3288 rect
.bottom
- rect
.top
,
3296 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
3297 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
3298 SetWindowLong (hwnd
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
3299 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
3300 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3302 /* Enable drag-n-drop. */
3303 DragAcceptFiles (hwnd
, TRUE
);
3305 /* Do this to discard the default setting specified by our parent. */
3306 ShowWindow (hwnd
, SW_HIDE
);
3311 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
3318 wmsg
->msg
.hwnd
= hwnd
;
3319 wmsg
->msg
.message
= msg
;
3320 wmsg
->msg
.wParam
= wParam
;
3321 wmsg
->msg
.lParam
= lParam
;
3322 wmsg
->msg
.time
= GetMessageTime ();
3327 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
3328 between left and right keys as advertised. We test for this
3329 support dynamically, and set a flag when the support is absent. If
3330 absent, we keep track of the left and right control and alt keys
3331 ourselves. This is particularly necessary on keyboards that rely
3332 upon the AltGr key, which is represented as having the left control
3333 and right alt keys pressed. For these keyboards, we need to know
3334 when the left alt key has been pressed in addition to the AltGr key
3335 so that we can properly support M-AltGr-key sequences (such as M-@
3336 on Swedish keyboards). */
3338 #define EMACS_LCONTROL 0
3339 #define EMACS_RCONTROL 1
3340 #define EMACS_LMENU 2
3341 #define EMACS_RMENU 3
3343 static int modifiers
[4];
3344 static int modifiers_recorded
;
3345 static int modifier_key_support_tested
;
3348 test_modifier_support (unsigned int wparam
)
3352 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
3354 if (wparam
== VK_CONTROL
)
3364 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
3365 modifiers_recorded
= 1;
3367 modifiers_recorded
= 0;
3368 modifier_key_support_tested
= 1;
3372 record_keydown (unsigned int wparam
, unsigned int lparam
)
3376 if (!modifier_key_support_tested
)
3377 test_modifier_support (wparam
);
3379 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3382 if (wparam
== VK_CONTROL
)
3383 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3385 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3391 record_keyup (unsigned int wparam
, unsigned int lparam
)
3395 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3398 if (wparam
== VK_CONTROL
)
3399 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3401 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3406 /* Emacs can lose focus while a modifier key has been pressed. When
3407 it regains focus, be conservative and clear all modifiers since
3408 we cannot reconstruct the left and right modifier state. */
3414 if (GetFocus () == NULL
)
3415 /* Emacs doesn't have keyboard focus. Do nothing. */
3418 ctrl
= GetAsyncKeyState (VK_CONTROL
);
3419 alt
= GetAsyncKeyState (VK_MENU
);
3421 if (!(ctrl
& 0x08000))
3422 /* Clear any recorded control modifier state. */
3423 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3425 if (!(alt
& 0x08000))
3426 /* Clear any recorded alt modifier state. */
3427 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3429 /* Update the state of all modifier keys, because modifiers used in
3430 hot-key combinations can get stuck on if Emacs loses focus as a
3431 result of a hot-key being pressed. */
3435 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
3437 GetKeyboardState (keystate
);
3438 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
3439 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
3440 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
3441 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
3442 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
3443 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
3444 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
3445 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
3446 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
3447 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
3448 SetKeyboardState (keystate
);
3452 /* Synchronize modifier state with what is reported with the current
3453 keystroke. Even if we cannot distinguish between left and right
3454 modifier keys, we know that, if no modifiers are set, then neither
3455 the left or right modifier should be set. */
3459 if (!modifiers_recorded
)
3462 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
3463 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3465 if (!(GetKeyState (VK_MENU
) & 0x8000))
3466 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3470 modifier_set (int vkey
)
3472 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
3473 return (GetKeyState (vkey
) & 0x1);
3474 if (!modifiers_recorded
)
3475 return (GetKeyState (vkey
) & 0x8000);
3480 return modifiers
[EMACS_LCONTROL
];
3482 return modifiers
[EMACS_RCONTROL
];
3484 return modifiers
[EMACS_LMENU
];
3486 return modifiers
[EMACS_RMENU
];
3488 return (GetKeyState (vkey
) & 0x8000);
3491 /* Convert between the modifier bits W32 uses and the modifier bits
3495 w32_key_to_modifier (int key
)
3497 Lisp_Object key_mapping
;
3502 key_mapping
= Vw32_lwindow_modifier
;
3505 key_mapping
= Vw32_rwindow_modifier
;
3508 key_mapping
= Vw32_apps_modifier
;
3511 key_mapping
= Vw32_scroll_lock_modifier
;
3517 /* NB. This code runs in the input thread, asychronously to the lisp
3518 thread, so we must be careful to ensure access to lisp data is
3519 thread-safe. The following code is safe because the modifier
3520 variable values are updated atomically from lisp and symbols are
3521 not relocated by GC. Also, we don't have to worry about seeing GC
3523 if (EQ (key_mapping
, Qhyper
))
3524 return hyper_modifier
;
3525 if (EQ (key_mapping
, Qsuper
))
3526 return super_modifier
;
3527 if (EQ (key_mapping
, Qmeta
))
3528 return meta_modifier
;
3529 if (EQ (key_mapping
, Qalt
))
3530 return alt_modifier
;
3531 if (EQ (key_mapping
, Qctrl
))
3532 return ctrl_modifier
;
3533 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
3534 return ctrl_modifier
;
3535 if (EQ (key_mapping
, Qshift
))
3536 return shift_modifier
;
3538 /* Don't generate any modifier if not explicitly requested. */
3543 w32_get_modifiers ()
3545 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
3546 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
3547 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
3548 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
3549 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
3550 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
3551 (modifier_set (VK_MENU
) ?
3552 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
3555 /* We map the VK_* modifiers into console modifier constants
3556 so that we can use the same routines to handle both console
3557 and window input. */
3560 construct_console_modifiers ()
3565 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
3566 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
3567 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
3568 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
3569 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
3570 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
3571 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
3572 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
3573 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
3574 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
3575 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
3581 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
3585 /* Convert to emacs modifiers. */
3586 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
3592 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
3594 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
3597 if (virt_key
== VK_RETURN
)
3598 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
3600 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
3601 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
3603 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
3604 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
3606 if (virt_key
== VK_CLEAR
)
3607 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
3612 /* List of special key combinations which w32 would normally capture,
3613 but emacs should grab instead. Not directly visible to lisp, to
3614 simplify synchronization. Each item is an integer encoding a virtual
3615 key code and modifier combination to capture. */
3616 Lisp_Object w32_grabbed_keys
;
3618 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
3619 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
3620 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
3621 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
3623 /* Register hot-keys for reserved key combinations when Emacs has
3624 keyboard focus, since this is the only way Emacs can receive key
3625 combinations like Alt-Tab which are used by the system. */
3628 register_hot_keys (hwnd
)
3631 Lisp_Object keylist
;
3633 /* Use GC_CONSP, since we are called asynchronously. */
3634 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3636 Lisp_Object key
= XCAR (keylist
);
3638 /* Deleted entries get set to nil. */
3639 if (!INTEGERP (key
))
3642 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
3643 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
3648 unregister_hot_keys (hwnd
)
3651 Lisp_Object keylist
;
3653 /* Use GC_CONSP, since we are called asynchronously. */
3654 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3656 Lisp_Object key
= XCAR (keylist
);
3658 if (!INTEGERP (key
))
3661 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
3665 /* Main message dispatch loop. */
3668 w32_msg_pump (deferred_msg
* msg_buf
)
3674 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
3676 while (GetMessage (&msg
, NULL
, 0, 0))
3678 if (msg
.hwnd
== NULL
)
3680 switch (msg
.message
)
3683 /* Produced by complete_deferred_msg; just ignore. */
3685 case WM_EMACS_CREATEWINDOW
:
3686 w32_createwindow ((struct frame
*) msg
.wParam
);
3687 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3690 case WM_EMACS_SETLOCALE
:
3691 SetThreadLocale (msg
.wParam
);
3692 /* Reply is not expected. */
3694 case WM_EMACS_SETKEYBOARDLAYOUT
:
3695 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
3696 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3700 case WM_EMACS_REGISTER_HOT_KEY
:
3701 focus_window
= GetFocus ();
3702 if (focus_window
!= NULL
)
3703 RegisterHotKey (focus_window
,
3704 HOTKEY_ID (msg
.wParam
),
3705 HOTKEY_MODIFIERS (msg
.wParam
),
3706 HOTKEY_VK_CODE (msg
.wParam
));
3707 /* Reply is not expected. */
3709 case WM_EMACS_UNREGISTER_HOT_KEY
:
3710 focus_window
= GetFocus ();
3711 if (focus_window
!= NULL
)
3712 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
3713 /* Mark item as erased. NB: this code must be
3714 thread-safe. The next line is okay because the cons
3715 cell is never made into garbage and is not relocated by
3717 XCAR ((Lisp_Object
) msg
.lParam
) = Qnil
;
3718 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3721 case WM_EMACS_TOGGLE_LOCK_KEY
:
3723 int vk_code
= (int) msg
.wParam
;
3724 int cur_state
= (GetKeyState (vk_code
) & 1);
3725 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
3727 /* NB: This code must be thread-safe. It is safe to
3728 call NILP because symbols are not relocated by GC,
3729 and pointer here is not touched by GC (so the markbit
3730 can't be set). Numbers are safe because they are
3731 immediate values. */
3732 if (NILP (new_state
)
3733 || (NUMBERP (new_state
)
3734 && (XUINT (new_state
)) & 1 != cur_state
))
3736 one_w32_display_info
.faked_key
= vk_code
;
3738 keybd_event ((BYTE
) vk_code
,
3739 (BYTE
) MapVirtualKey (vk_code
, 0),
3740 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3741 keybd_event ((BYTE
) vk_code
,
3742 (BYTE
) MapVirtualKey (vk_code
, 0),
3743 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3744 keybd_event ((BYTE
) vk_code
,
3745 (BYTE
) MapVirtualKey (vk_code
, 0),
3746 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3747 cur_state
= !cur_state
;
3749 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3755 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
3760 DispatchMessage (&msg
);
3763 /* Exit nested loop when our deferred message has completed. */
3764 if (msg_buf
->completed
)
3769 deferred_msg
* deferred_msg_head
;
3771 static deferred_msg
*
3772 find_deferred_msg (HWND hwnd
, UINT msg
)
3774 deferred_msg
* item
;
3776 /* Don't actually need synchronization for read access, since
3777 modification of single pointer is always atomic. */
3778 /* enter_crit (); */
3780 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3781 if (item
->w32msg
.msg
.hwnd
== hwnd
3782 && item
->w32msg
.msg
.message
== msg
)
3785 /* leave_crit (); */
3791 send_deferred_msg (deferred_msg
* msg_buf
,
3797 /* Only input thread can send deferred messages. */
3798 if (GetCurrentThreadId () != dwWindowsThreadId
)
3801 /* It is an error to send a message that is already deferred. */
3802 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3805 /* Enforced synchronization is not needed because this is the only
3806 function that alters deferred_msg_head, and the following critical
3807 section is guaranteed to only be serially reentered (since only the
3808 input thread can call us). */
3810 /* enter_crit (); */
3812 msg_buf
->completed
= 0;
3813 msg_buf
->next
= deferred_msg_head
;
3814 deferred_msg_head
= msg_buf
;
3815 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
3817 /* leave_crit (); */
3819 /* Start a new nested message loop to process other messages until
3820 this one is completed. */
3821 w32_msg_pump (msg_buf
);
3823 deferred_msg_head
= msg_buf
->next
;
3825 return msg_buf
->result
;
3829 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
3831 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
3833 if (msg_buf
== NULL
)
3834 /* Message may have been cancelled, so don't abort(). */
3837 msg_buf
->result
= result
;
3838 msg_buf
->completed
= 1;
3840 /* Ensure input thread is woken so it notices the completion. */
3841 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3845 cancel_all_deferred_msgs ()
3847 deferred_msg
* item
;
3849 /* Don't actually need synchronization for read access, since
3850 modification of single pointer is always atomic. */
3851 /* enter_crit (); */
3853 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3856 item
->completed
= 1;
3859 /* leave_crit (); */
3861 /* Ensure input thread is woken so it notices the completion. */
3862 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3870 deferred_msg dummy_buf
;
3872 /* Ensure our message queue is created */
3874 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
3876 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3879 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
3880 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
3881 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
3883 /* This is the inital message loop which should only exit when the
3884 application quits. */
3885 w32_msg_pump (&dummy_buf
);
3891 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
3901 wmsg
.dwModifiers
= modifiers
;
3903 /* Detect quit_char and set quit-flag directly. Note that we
3904 still need to post a message to ensure the main thread will be
3905 woken up if blocked in sys_select(), but we do NOT want to post
3906 the quit_char message itself (because it will usually be as if
3907 the user had typed quit_char twice). Instead, we post a dummy
3908 message that has no particular effect. */
3911 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
3912 c
= make_ctrl_char (c
) & 0377;
3914 || (wmsg
.dwModifiers
== 0 &&
3915 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
3919 /* The choice of message is somewhat arbitrary, as long as
3920 the main thread handler just ignores it. */
3923 /* Interrupt any blocking system calls. */
3926 /* As a safety precaution, forcibly complete any deferred
3927 messages. This is a kludge, but I don't see any particularly
3928 clean way to handle the situation where a deferred message is
3929 "dropped" in the lisp thread, and will thus never be
3930 completed, eg. by the user trying to activate the menubar
3931 when the lisp thread is busy, and then typing C-g when the
3932 menubar doesn't open promptly (with the result that the
3933 menubar never responds at all because the deferred
3934 WM_INITMENU message is never completed). Another problem
3935 situation is when the lisp thread calls SendMessage (to send
3936 a window manager command) when a message has been deferred;
3937 the lisp thread gets blocked indefinitely waiting for the
3938 deferred message to be completed, which itself is waiting for
3939 the lisp thread to respond.
3941 Note that we don't want to block the input thread waiting for
3942 a reponse from the lisp thread (although that would at least
3943 solve the deadlock problem above), because we want to be able
3944 to receive C-g to interrupt the lisp thread. */
3945 cancel_all_deferred_msgs ();
3949 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
3952 /* Main window procedure */
3955 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
3962 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
3964 int windows_translate
;
3967 /* Note that it is okay to call x_window_to_frame, even though we are
3968 not running in the main lisp thread, because frame deletion
3969 requires the lisp thread to synchronize with this thread. Thus, if
3970 a frame struct is returned, it can be used without concern that the
3971 lisp thread might make it disappear while we are using it.
3973 NB. Walking the frame list in this thread is safe (as long as
3974 writes of Lisp_Object slots are atomic, which they are on Windows).
3975 Although delete-frame can destructively modify the frame list while
3976 we are walking it, a garbage collection cannot occur until after
3977 delete-frame has synchronized with this thread.
3979 It is also safe to use functions that make GDI calls, such as
3980 w32_clear_rect, because these functions must obtain a DC handle
3981 from the frame struct using get_frame_dc which is thread-aware. */
3986 f
= x_window_to_frame (dpyinfo
, hwnd
);
3989 HDC hdc
= get_frame_dc (f
);
3990 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
3991 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
3992 release_frame_dc (f
, hdc
);
3994 #if defined (W32_DEBUG_DISPLAY)
3995 DebPrint (("WM_ERASEBKGND: erasing %d,%d-%d,%d\n",
3996 wmsg
.rect
.left
, wmsg
.rect
.top
, wmsg
.rect
.right
,
3998 #endif /* W32_DEBUG_DISPLAY */
4001 case WM_PALETTECHANGED
:
4002 /* ignore our own changes */
4003 if ((HWND
)wParam
!= hwnd
)
4005 f
= x_window_to_frame (dpyinfo
, hwnd
);
4007 /* get_frame_dc will realize our palette and force all
4008 frames to be redrawn if needed. */
4009 release_frame_dc (f
, get_frame_dc (f
));
4014 PAINTSTRUCT paintStruct
;
4017 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
4018 fails. Apparently this can happen under some
4020 if (!w32_strict_painting
|| GetUpdateRect (hwnd
, &update_rect
, FALSE
))
4023 BeginPaint (hwnd
, &paintStruct
);
4025 if (w32_strict_painting
)
4026 /* The rectangles returned by GetUpdateRect and BeginPaint
4027 do not always match. GetUpdateRect seems to be the
4028 more reliable of the two. */
4029 wmsg
.rect
= update_rect
;
4031 wmsg
.rect
= paintStruct
.rcPaint
;
4033 #if defined (W32_DEBUG_DISPLAY)
4034 DebPrint (("WM_PAINT: painting %d,%d-%d,%d\n", wmsg
.rect
.left
,
4035 wmsg
.rect
.top
, wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4036 DebPrint (("WM_PAINT: update region is %d,%d-%d,%d\n",
4037 update_rect
.left
, update_rect
.top
,
4038 update_rect
.right
, update_rect
.bottom
));
4040 EndPaint (hwnd
, &paintStruct
);
4043 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4048 /* If GetUpdateRect returns 0 (meaning there is no update
4049 region), assume the whole window needs to be repainted. */
4050 GetClientRect(hwnd
, &wmsg
.rect
);
4051 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4055 case WM_INPUTLANGCHANGE
:
4056 /* Inform lisp thread of keyboard layout changes. */
4057 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4059 /* Clear dead keys in the keyboard state; for simplicity only
4060 preserve modifier key states. */
4065 GetKeyboardState (keystate
);
4066 for (i
= 0; i
< 256; i
++)
4083 SetKeyboardState (keystate
);
4088 /* Synchronize hot keys with normal input. */
4089 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
4094 record_keyup (wParam
, lParam
);
4099 /* Ignore keystrokes we fake ourself; see below. */
4100 if (dpyinfo
->faked_key
== wParam
)
4102 dpyinfo
->faked_key
= 0;
4103 /* Make sure TranslateMessage sees them though (as long as
4104 they don't produce WM_CHAR messages). This ensures that
4105 indicator lights are toggled promptly on Windows 9x, for
4107 if (lispy_function_keys
[wParam
] != 0)
4109 windows_translate
= 1;
4115 /* Synchronize modifiers with current keystroke. */
4117 record_keydown (wParam
, lParam
);
4118 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
4120 windows_translate
= 0;
4125 if (NILP (Vw32_pass_lwindow_to_system
))
4127 /* Prevent system from acting on keyup (which opens the
4128 Start menu if no other key was pressed) by simulating a
4129 press of Space which we will ignore. */
4130 if (GetAsyncKeyState (wParam
) & 1)
4132 if (NUMBERP (Vw32_phantom_key_code
))
4133 key
= XUINT (Vw32_phantom_key_code
) & 255;
4136 dpyinfo
->faked_key
= key
;
4137 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4140 if (!NILP (Vw32_lwindow_modifier
))
4144 if (NILP (Vw32_pass_rwindow_to_system
))
4146 if (GetAsyncKeyState (wParam
) & 1)
4148 if (NUMBERP (Vw32_phantom_key_code
))
4149 key
= XUINT (Vw32_phantom_key_code
) & 255;
4152 dpyinfo
->faked_key
= key
;
4153 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4156 if (!NILP (Vw32_rwindow_modifier
))
4160 if (!NILP (Vw32_apps_modifier
))
4164 if (NILP (Vw32_pass_alt_to_system
))
4165 /* Prevent DefWindowProc from activating the menu bar if an
4166 Alt key is pressed and released by itself. */
4168 windows_translate
= 1;
4171 /* Decide whether to treat as modifier or function key. */
4172 if (NILP (Vw32_enable_caps_lock
))
4173 goto disable_lock_key
;
4174 windows_translate
= 1;
4177 /* Decide whether to treat as modifier or function key. */
4178 if (NILP (Vw32_enable_num_lock
))
4179 goto disable_lock_key
;
4180 windows_translate
= 1;
4183 /* Decide whether to treat as modifier or function key. */
4184 if (NILP (Vw32_scroll_lock_modifier
))
4185 goto disable_lock_key
;
4186 windows_translate
= 1;
4189 /* Ensure the appropriate lock key state (and indicator light)
4190 remains in the same state. We do this by faking another
4191 press of the relevant key. Apparently, this really is the
4192 only way to toggle the state of the indicator lights. */
4193 dpyinfo
->faked_key
= wParam
;
4194 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4195 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4196 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4197 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4198 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4199 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4200 /* Ensure indicator lights are updated promptly on Windows 9x
4201 (TranslateMessage apparently does this), after forwarding
4203 post_character_message (hwnd
, msg
, wParam
, lParam
,
4204 w32_get_key_modifiers (wParam
, lParam
));
4205 windows_translate
= 1;
4209 case VK_PROCESSKEY
: /* Generated by IME. */
4210 windows_translate
= 1;
4213 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
4214 which is confusing for purposes of key binding; convert
4215 VK_CANCEL events into VK_PAUSE events. */
4219 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
4220 for purposes of key binding; convert these back into
4221 VK_NUMLOCK events, at least when we want to see NumLock key
4222 presses. (Note that there is never any possibility that
4223 VK_PAUSE with Ctrl really is C-Pause as per above.) */
4224 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
4225 wParam
= VK_NUMLOCK
;
4228 /* If not defined as a function key, change it to a WM_CHAR message. */
4229 if (lispy_function_keys
[wParam
] == 0)
4231 DWORD modifiers
= construct_console_modifiers ();
4233 if (!NILP (Vw32_recognize_altgr
)
4234 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
4236 /* Always let TranslateMessage handle AltGr key chords;
4237 for some reason, ToAscii doesn't always process AltGr
4238 chords correctly. */
4239 windows_translate
= 1;
4241 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
4243 /* Handle key chords including any modifiers other
4244 than shift directly, in order to preserve as much
4245 modifier information as possible. */
4246 if ('A' <= wParam
&& wParam
<= 'Z')
4248 /* Don't translate modified alphabetic keystrokes,
4249 so the user doesn't need to constantly switch
4250 layout to type control or meta keystrokes when
4251 the normal layout translates alphabetic
4252 characters to non-ascii characters. */
4253 if (!modifier_set (VK_SHIFT
))
4254 wParam
+= ('a' - 'A');
4259 /* Try to handle other keystrokes by determining the
4260 base character (ie. translating the base key plus
4264 KEY_EVENT_RECORD key
;
4266 key
.bKeyDown
= TRUE
;
4267 key
.wRepeatCount
= 1;
4268 key
.wVirtualKeyCode
= wParam
;
4269 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
4270 key
.uChar
.AsciiChar
= 0;
4271 key
.dwControlKeyState
= modifiers
;
4273 add
= w32_kbd_patch_key (&key
);
4274 /* 0 means an unrecognised keycode, negative means
4275 dead key. Ignore both. */
4278 /* Forward asciified character sequence. */
4279 post_character_message
4280 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
4281 w32_get_key_modifiers (wParam
, lParam
));
4282 w32_kbd_patch_key (&key
);
4289 /* Let TranslateMessage handle everything else. */
4290 windows_translate
= 1;
4296 if (windows_translate
)
4298 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
4300 windows_msg
.time
= GetMessageTime ();
4301 TranslateMessage (&windows_msg
);
4309 post_character_message (hwnd
, msg
, wParam
, lParam
,
4310 w32_get_key_modifiers (wParam
, lParam
));
4313 /* Simulate middle mouse button events when left and right buttons
4314 are used together, but only if user has two button mouse. */
4315 case WM_LBUTTONDOWN
:
4316 case WM_RBUTTONDOWN
:
4317 if (XINT (Vw32_num_mouse_buttons
) > 2)
4318 goto handle_plain_button
;
4321 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
4322 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
4324 if (button_state
& this)
4327 if (button_state
== 0)
4330 button_state
|= this;
4332 if (button_state
& other
)
4334 if (mouse_button_timer
)
4336 KillTimer (hwnd
, mouse_button_timer
);
4337 mouse_button_timer
= 0;
4339 /* Generate middle mouse event instead. */
4340 msg
= WM_MBUTTONDOWN
;
4341 button_state
|= MMOUSE
;
4343 else if (button_state
& MMOUSE
)
4345 /* Ignore button event if we've already generated a
4346 middle mouse down event. This happens if the
4347 user releases and press one of the two buttons
4348 after we've faked a middle mouse event. */
4353 /* Flush out saved message. */
4354 post_msg (&saved_mouse_button_msg
);
4356 wmsg
.dwModifiers
= w32_get_modifiers ();
4357 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4359 /* Clear message buffer. */
4360 saved_mouse_button_msg
.msg
.hwnd
= 0;
4364 /* Hold onto message for now. */
4365 mouse_button_timer
=
4366 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
4367 XINT (Vw32_mouse_button_tolerance
), NULL
);
4368 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
4369 saved_mouse_button_msg
.msg
.message
= msg
;
4370 saved_mouse_button_msg
.msg
.wParam
= wParam
;
4371 saved_mouse_button_msg
.msg
.lParam
= lParam
;
4372 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
4373 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
4380 if (XINT (Vw32_num_mouse_buttons
) > 2)
4381 goto handle_plain_button
;
4384 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
4385 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
4387 if ((button_state
& this) == 0)
4390 button_state
&= ~this;
4392 if (button_state
& MMOUSE
)
4394 /* Only generate event when second button is released. */
4395 if ((button_state
& other
) == 0)
4398 button_state
&= ~MMOUSE
;
4400 if (button_state
) abort ();
4407 /* Flush out saved message if necessary. */
4408 if (saved_mouse_button_msg
.msg
.hwnd
)
4410 post_msg (&saved_mouse_button_msg
);
4413 wmsg
.dwModifiers
= w32_get_modifiers ();
4414 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4416 /* Always clear message buffer and cancel timer. */
4417 saved_mouse_button_msg
.msg
.hwnd
= 0;
4418 KillTimer (hwnd
, mouse_button_timer
);
4419 mouse_button_timer
= 0;
4421 if (button_state
== 0)
4426 case WM_MBUTTONDOWN
:
4428 handle_plain_button
:
4433 if (parse_button (msg
, &button
, &up
))
4435 if (up
) ReleaseCapture ();
4436 else SetCapture (hwnd
);
4437 button
= (button
== 0) ? LMOUSE
:
4438 ((button
== 1) ? MMOUSE
: RMOUSE
);
4440 button_state
&= ~button
;
4442 button_state
|= button
;
4446 wmsg
.dwModifiers
= w32_get_modifiers ();
4447 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4452 if (XINT (Vw32_mouse_move_interval
) <= 0
4453 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4455 wmsg
.dwModifiers
= w32_get_modifiers ();
4456 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4460 /* Hang onto mouse move and scroll messages for a bit, to avoid
4461 sending such events to Emacs faster than it can process them.
4462 If we get more events before the timer from the first message
4463 expires, we just replace the first message. */
4465 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4467 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4468 XINT (Vw32_mouse_move_interval
), NULL
);
4470 /* Hold onto message for now. */
4471 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4472 saved_mouse_move_msg
.msg
.message
= msg
;
4473 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4474 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4475 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4476 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4481 wmsg
.dwModifiers
= w32_get_modifiers ();
4482 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4486 wmsg
.dwModifiers
= w32_get_modifiers ();
4487 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4491 /* Flush out saved messages if necessary. */
4492 if (wParam
== mouse_button_timer
)
4494 if (saved_mouse_button_msg
.msg
.hwnd
)
4496 post_msg (&saved_mouse_button_msg
);
4497 saved_mouse_button_msg
.msg
.hwnd
= 0;
4499 KillTimer (hwnd
, mouse_button_timer
);
4500 mouse_button_timer
= 0;
4502 else if (wParam
== mouse_move_timer
)
4504 if (saved_mouse_move_msg
.msg
.hwnd
)
4506 post_msg (&saved_mouse_move_msg
);
4507 saved_mouse_move_msg
.msg
.hwnd
= 0;
4509 KillTimer (hwnd
, mouse_move_timer
);
4510 mouse_move_timer
= 0;
4515 /* Windows doesn't send us focus messages when putting up and
4516 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4517 The only indication we get that something happened is receiving
4518 this message afterwards. So this is a good time to reset our
4519 keyboard modifiers' state. */
4526 /* We must ensure menu bar is fully constructed and up to date
4527 before allowing user interaction with it. To achieve this
4528 we send this message to the lisp thread and wait for a
4529 reply (whose value is not actually needed) to indicate that
4530 the menu bar is now ready for use, so we can now return.
4532 To remain responsive in the meantime, we enter a nested message
4533 loop that can process all other messages.
4535 However, we skip all this if the message results from calling
4536 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4537 thread a message because it is blocked on us at this point. We
4538 set menubar_active before calling TrackPopupMenu to indicate
4539 this (there is no possibility of confusion with real menubar
4542 f
= x_window_to_frame (dpyinfo
, hwnd
);
4544 && (f
->output_data
.w32
->menubar_active
4545 /* We can receive this message even in the absence of a
4546 menubar (ie. when the system menu is activated) - in this
4547 case we do NOT want to forward the message, otherwise it
4548 will cause the menubar to suddenly appear when the user
4549 had requested it to be turned off! */
4550 || f
->output_data
.w32
->menubar_widget
== NULL
))
4554 deferred_msg msg_buf
;
4556 /* Detect if message has already been deferred; in this case
4557 we cannot return any sensible value to ignore this. */
4558 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4561 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4564 case WM_EXITMENULOOP
:
4565 f
= x_window_to_frame (dpyinfo
, hwnd
);
4567 /* Indicate that menubar can be modified again. */
4569 f
->output_data
.w32
->menubar_active
= 0;
4573 wmsg
.dwModifiers
= w32_get_modifiers ();
4574 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4577 case WM_MEASUREITEM
:
4578 f
= x_window_to_frame (dpyinfo
, hwnd
);
4581 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4583 if (pMis
->CtlType
== ODT_MENU
)
4585 /* Work out dimensions for popup menu titles. */
4586 char * title
= (char *) pMis
->itemData
;
4587 HDC hdc
= GetDC (hwnd
);
4588 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4589 LOGFONT menu_logfont
;
4593 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4594 menu_logfont
.lfWeight
= FW_BOLD
;
4595 menu_font
= CreateFontIndirect (&menu_logfont
);
4596 old_font
= SelectObject (hdc
, menu_font
);
4598 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4601 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4602 pMis
->itemWidth
= size
.cx
;
4603 if (pMis
->itemHeight
< size
.cy
)
4604 pMis
->itemHeight
= size
.cy
;
4607 pMis
->itemWidth
= 0;
4609 SelectObject (hdc
, old_font
);
4610 DeleteObject (menu_font
);
4611 ReleaseDC (hwnd
, hdc
);
4618 f
= x_window_to_frame (dpyinfo
, hwnd
);
4621 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4623 if (pDis
->CtlType
== ODT_MENU
)
4625 /* Draw popup menu title. */
4626 char * title
= (char *) pDis
->itemData
;
4629 HDC hdc
= pDis
->hDC
;
4630 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4631 LOGFONT menu_logfont
;
4634 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4635 menu_logfont
.lfWeight
= FW_BOLD
;
4636 menu_font
= CreateFontIndirect (&menu_logfont
);
4637 old_font
= SelectObject (hdc
, menu_font
);
4639 /* Always draw title as if not selected. */
4642 + GetSystemMetrics (SM_CXMENUCHECK
),
4644 ETO_OPAQUE
, &pDis
->rcItem
,
4645 title
, strlen (title
), NULL
);
4647 SelectObject (hdc
, old_font
);
4648 DeleteObject (menu_font
);
4656 /* Still not right - can't distinguish between clicks in the
4657 client area of the frame from clicks forwarded from the scroll
4658 bars - may have to hook WM_NCHITTEST to remember the mouse
4659 position and then check if it is in the client area ourselves. */
4660 case WM_MOUSEACTIVATE
:
4661 /* Discard the mouse click that activates a frame, allowing the
4662 user to click anywhere without changing point (or worse!).
4663 Don't eat mouse clicks on scrollbars though!! */
4664 if (LOWORD (lParam
) == HTCLIENT
)
4665 return MA_ACTIVATEANDEAT
;
4669 case WM_ACTIVATEAPP
:
4671 case WM_WINDOWPOSCHANGED
:
4673 /* Inform lisp thread that a frame might have just been obscured
4674 or exposed, so should recheck visibility of all frames. */
4675 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4679 dpyinfo
->faked_key
= 0;
4681 register_hot_keys (hwnd
);
4684 unregister_hot_keys (hwnd
);
4691 wmsg
.dwModifiers
= w32_get_modifiers ();
4692 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4696 wmsg
.dwModifiers
= w32_get_modifiers ();
4697 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4700 case WM_WINDOWPOSCHANGING
:
4703 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
4705 wp
.length
= sizeof (WINDOWPLACEMENT
);
4706 GetWindowPlacement (hwnd
, &wp
);
4708 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
4715 DWORD internal_border
;
4716 DWORD scrollbar_extra
;
4719 wp
.length
= sizeof(wp
);
4720 GetWindowRect (hwnd
, &wr
);
4724 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
4725 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
4726 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
4727 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
4731 memset (&rect
, 0, sizeof (rect
));
4732 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
4733 GetMenu (hwnd
) != NULL
);
4735 /* Force width and height of client area to be exact
4736 multiples of the character cell dimensions. */
4737 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
4738 - 2 * internal_border
- scrollbar_extra
)
4740 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
4741 - 2 * internal_border
)
4746 /* For right/bottom sizing we can just fix the sizes.
4747 However for top/left sizing we will need to fix the X
4748 and Y positions as well. */
4753 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
4754 && (lppos
->flags
& SWP_NOMOVE
) == 0)
4756 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
4763 lppos
->flags
|= SWP_NOMOVE
;
4774 case WM_GETMINMAXINFO
:
4775 /* Hack to correct bug that allows Emacs frames to be resized
4776 below the Minimum Tracking Size. */
4777 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
4780 case WM_EMACS_CREATESCROLLBAR
:
4781 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
4782 (struct scroll_bar
*) lParam
);
4784 case WM_EMACS_SHOWWINDOW
:
4785 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4787 case WM_EMACS_SETFOREGROUND
:
4789 HWND foreground_window
;
4790 DWORD foreground_thread
, retval
;
4792 /* On NT 5.0, and apparently Windows 98, it is necessary to
4793 attach to the thread that currently has focus in order to
4794 pull the focus away from it. */
4795 foreground_window
= GetForegroundWindow ();
4796 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4797 if (!foreground_window
4798 || foreground_thread
== GetCurrentThreadId ()
4799 || !AttachThreadInput (GetCurrentThreadId (),
4800 foreground_thread
, TRUE
))
4801 foreground_thread
= 0;
4803 retval
= SetForegroundWindow ((HWND
) wParam
);
4805 /* Detach from the previous foreground thread. */
4806 if (foreground_thread
)
4807 AttachThreadInput (GetCurrentThreadId (),
4808 foreground_thread
, FALSE
);
4813 case WM_EMACS_SETWINDOWPOS
:
4815 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4816 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4817 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4820 case WM_EMACS_DESTROYWINDOW
:
4821 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4822 return DestroyWindow ((HWND
) wParam
);
4824 case WM_EMACS_TRACKPOPUPMENU
:
4829 pos
= (POINT
*)lParam
;
4830 flags
= TPM_CENTERALIGN
;
4831 if (button_state
& LMOUSE
)
4832 flags
|= TPM_LEFTBUTTON
;
4833 else if (button_state
& RMOUSE
)
4834 flags
|= TPM_RIGHTBUTTON
;
4836 /* Remember we did a SetCapture on the initial mouse down event,
4837 so for safety, we make sure the capture is cancelled now. */
4841 /* Use menubar_active to indicate that WM_INITMENU is from
4842 TrackPopupMenu below, and should be ignored. */
4843 f
= x_window_to_frame (dpyinfo
, hwnd
);
4845 f
->output_data
.w32
->menubar_active
= 1;
4847 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4851 /* Eat any mouse messages during popupmenu */
4852 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4854 /* Get the menu selection, if any */
4855 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4857 retval
= LOWORD (amsg
.wParam
);
4873 /* Check for messages registered at runtime. */
4874 if (msg
== msh_mousewheel
)
4876 wmsg
.dwModifiers
= w32_get_modifiers ();
4877 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4882 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
4886 /* The most common default return code for handled messages is 0. */
4891 my_create_window (f
)
4896 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4898 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4901 /* Create and set up the w32 window for frame F. */
4904 w32_window (f
, window_prompting
, minibuffer_only
)
4906 long window_prompting
;
4907 int minibuffer_only
;
4911 /* Use the resource name as the top-level window name
4912 for looking up resources. Make a non-Lisp copy
4913 for the window manager, so GC relocation won't bother it.
4915 Elsewhere we specify the window name for the window manager. */
4918 char *str
= (char *) XSTRING (Vx_resource_name
)->data
;
4919 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4920 strcpy (f
->namebuf
, str
);
4923 my_create_window (f
);
4925 validate_x_resource_name ();
4927 /* x_set_name normally ignores requests to set the name if the
4928 requested name is the same as the current name. This is the one
4929 place where that assumption isn't correct; f->name is set, but
4930 the server hasn't been told. */
4933 int explicit = f
->explicit_name
;
4935 f
->explicit_name
= 0;
4938 x_set_name (f
, name
, explicit);
4943 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4944 initialize_frame_menubar (f
);
4946 if (FRAME_W32_WINDOW (f
) == 0)
4947 error ("Unable to create window");
4950 /* Handle the icon stuff for this window. Perhaps later we might
4951 want an x_set_icon_position which can be called interactively as
4959 Lisp_Object icon_x
, icon_y
;
4961 /* Set the position of the icon. Note that Windows 95 groups all
4962 icons in the tray. */
4963 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4964 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4965 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4967 CHECK_NUMBER (icon_x
, 0);
4968 CHECK_NUMBER (icon_y
, 0);
4970 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4971 error ("Both left and top icon corners of icon must be specified");
4975 if (! EQ (icon_x
, Qunbound
))
4976 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4979 /* Start up iconic or window? */
4980 x_wm_set_window_state
4981 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
4985 x_text_icon (f
, (char *) XSTRING ((!NILP (f
->icon_name
)
4998 XGCValues gc_values
;
5002 /* Create the GC's of this frame.
5003 Note that many default values are used. */
5006 gc_values
.font
= f
->output_data
.w32
->font
;
5008 /* Cursor has cursor-color background, background-color foreground. */
5009 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
5010 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
5011 f
->output_data
.w32
->cursor_gc
5012 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
5013 (GCFont
| GCForeground
| GCBackground
),
5017 f
->output_data
.w32
->white_relief
.gc
= 0;
5018 f
->output_data
.w32
->black_relief
.gc
= 0;
5024 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
5026 "Make a new window, which is called a \"frame\" in Emacs terms.\n\
5027 Returns an Emacs frame object.\n\
5028 ALIST is an alist of frame parameters.\n\
5029 If the parameters specify that the frame should not have a minibuffer,\n\
5030 and do not specify a specific minibuffer window to use,\n\
5031 then `default-minibuffer-frame' must be a frame whose minibuffer can\n\
5032 be shared by the new frame.\n\
5034 This function is an internal primitive--use `make-frame' instead.")
5039 Lisp_Object frame
, tem
;
5041 int minibuffer_only
= 0;
5042 long window_prompting
= 0;
5044 int count
= specpdl_ptr
- specpdl
;
5045 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5046 Lisp_Object display
;
5047 struct w32_display_info
*dpyinfo
= NULL
;
5053 /* Use this general default value to start with
5054 until we know if this frame has a specified name. */
5055 Vx_resource_name
= Vinvocation_name
;
5057 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
5058 if (EQ (display
, Qunbound
))
5060 dpyinfo
= check_x_display_info (display
);
5062 kb
= dpyinfo
->kboard
;
5064 kb
= &the_only_kboard
;
5067 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5069 && ! EQ (name
, Qunbound
)
5071 error ("Invalid frame name--not a string or nil");
5074 Vx_resource_name
= name
;
5076 /* See if parent window is specified. */
5077 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
5078 if (EQ (parent
, Qunbound
))
5080 if (! NILP (parent
))
5081 CHECK_NUMBER (parent
, 0);
5083 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
5084 /* No need to protect DISPLAY because that's not used after passing
5085 it to make_frame_without_minibuffer. */
5087 GCPRO4 (parms
, parent
, name
, frame
);
5088 tem
= w32_get_arg (parms
, Qminibuffer
, "minibuffer", "Minibuffer",
5090 if (EQ (tem
, Qnone
) || NILP (tem
))
5091 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
5092 else if (EQ (tem
, Qonly
))
5094 f
= make_minibuffer_frame ();
5095 minibuffer_only
= 1;
5097 else if (WINDOWP (tem
))
5098 f
= make_frame_without_minibuffer (tem
, kb
, display
);
5102 XSETFRAME (frame
, f
);
5104 /* Note that Windows does support scroll bars. */
5105 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
5106 /* By default, make scrollbars the system standard width. */
5107 f
->scroll_bar_pixel_width
= GetSystemMetrics (SM_CXVSCROLL
);
5109 f
->output_method
= output_w32
;
5110 f
->output_data
.w32
=
5111 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5112 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5114 FRAME_FONTSET (f
) = -1;
5117 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
5118 if (! STRINGP (f
->icon_name
))
5119 f
->icon_name
= Qnil
;
5121 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
5123 FRAME_KBOARD (f
) = kb
;
5126 /* Specify the parent under which to make this window. */
5130 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
5131 f
->output_data
.w32
->explicit_parent
= 1;
5135 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5136 f
->output_data
.w32
->explicit_parent
= 0;
5139 /* Set the name; the functions to which we pass f expect the name to
5141 if (EQ (name
, Qunbound
) || NILP (name
))
5143 f
->name
= build_string (dpyinfo
->w32_id_name
);
5144 f
->explicit_name
= 0;
5149 f
->explicit_name
= 1;
5150 /* use the frame's title when getting resources for this frame. */
5151 specbind (Qx_resource_name
, name
);
5154 /* Extract the window parameters from the supplied values
5155 that are needed to determine window geometry. */
5159 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
5162 /* First, try whatever font the caller has specified. */
5165 tem
= Fquery_fontset (font
, Qnil
);
5167 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
5169 font
= x_new_font (f
, XSTRING (font
)->data
);
5171 /* Try out a font which we hope has bold and italic variations. */
5172 if (!STRINGP (font
))
5173 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
5174 if (! STRINGP (font
))
5175 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5176 /* If those didn't work, look for something which will at least work. */
5177 if (! STRINGP (font
))
5178 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
5180 if (! STRINGP (font
))
5181 font
= build_string ("Fixedsys");
5183 x_default_parameter (f
, parms
, Qfont
, font
,
5184 "font", "Font", RES_TYPE_STRING
);
5187 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5188 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5189 /* This defaults to 2 in order to match xterm. We recognize either
5190 internalBorderWidth or internalBorder (which is what xterm calls
5192 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5196 value
= w32_get_arg (parms
, Qinternal_border_width
,
5197 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
5198 if (! EQ (value
, Qunbound
))
5199 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5202 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5203 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
5204 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
5205 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qright
,
5206 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5208 /* Also do the stuff which must be set before the window exists. */
5209 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5210 "foreground", "Foreground", RES_TYPE_STRING
);
5211 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5212 "background", "Background", RES_TYPE_STRING
);
5213 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5214 "pointerColor", "Foreground", RES_TYPE_STRING
);
5215 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5216 "cursorColor", "Foreground", RES_TYPE_STRING
);
5217 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5218 "borderColor", "BorderColor", RES_TYPE_STRING
);
5219 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
5220 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5221 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
5222 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
5225 /* Init faces before x_default_parameter is called for scroll-bar
5226 parameters because that function calls x_set_scroll_bar_width,
5227 which calls change_frame_size, which calls Fset_window_buffer,
5228 which runs hooks, which call Fvertical_motion. At the end, we
5229 end up in init_iterator with a null face cache, which should not
5231 init_frame_faces (f
);
5233 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
5234 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
5235 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (0),
5236 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
5237 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
5238 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5239 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
5240 "title", "Title", RES_TYPE_STRING
);
5242 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5243 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5244 window_prompting
= x_figure_window_size (f
, parms
);
5246 if (window_prompting
& XNegative
)
5248 if (window_prompting
& YNegative
)
5249 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
5251 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
5255 if (window_prompting
& YNegative
)
5256 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
5258 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
5261 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
5263 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5264 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5266 /* Create the window. Add the tool-bar height to the initial frame
5267 height so that the user gets a text display area of the size he
5268 specified with -g or via the registry. Later changes of the
5269 tool-bar height don't change the frame size. This is done so that
5270 users can create tall Emacs frames without having to guess how
5271 tall the tool-bar will get. */
5272 f
->height
+= FRAME_TOOL_BAR_LINES (f
);
5273 w32_window (f
, window_prompting
, minibuffer_only
);
5278 /* Now consider the frame official. */
5279 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5280 Vframe_list
= Fcons (frame
, Vframe_list
);
5282 /* We need to do this after creating the window, so that the
5283 icon-creation functions can say whose icon they're describing. */
5284 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
5285 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5287 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5288 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5289 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5290 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5291 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5292 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5293 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
5294 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5296 /* Dimensions, especially f->height, must be done via change_frame_size.
5297 Change will not be effected unless different from the current
5302 SET_FRAME_WIDTH (f
, 0);
5303 change_frame_size (f
, height
, width
, 1, 0, 0);
5305 /* Tell the server what size and position, etc, we want, and how
5306 badly we want them. This should be done after we have the menu
5307 bar so that its size can be taken into account. */
5309 x_wm_set_size_hint (f
, window_prompting
, 0);
5312 /* Make the window appear on the frame and enable display, unless
5313 the caller says not to. However, with explicit parent, Emacs
5314 cannot control visibility, so don't try. */
5315 if (! f
->output_data
.w32
->explicit_parent
)
5317 Lisp_Object visibility
;
5319 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5320 if (EQ (visibility
, Qunbound
))
5323 if (EQ (visibility
, Qicon
))
5324 x_iconify_frame (f
);
5325 else if (! NILP (visibility
))
5326 x_make_frame_visible (f
);
5328 /* Must have been Qnil. */
5332 return unbind_to (count
, frame
);
5335 /* FRAME is used only to get a handle on the X display. We don't pass the
5336 display info directly because we're called from frame.c, which doesn't
5337 know about that structure. */
5339 x_get_focus_frame (frame
)
5340 struct frame
*frame
;
5342 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
5344 if (! dpyinfo
->w32_focus_frame
)
5347 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5351 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
5352 "Give FRAME input focus, raising to foreground if necessary.")
5356 x_focus_on_frame (check_x_frame (frame
));
5361 /* Return the charset portion of a font name. */
5362 char * xlfd_charset_of_font (char * fontname
)
5364 char *charset
, *encoding
;
5366 encoding
= strrchr(fontname
, '-');
5371 charset
= strrchr(fontname
, '-');
5374 if (!charset
|| strcmp(charset
, "-*-*") == 0)
5380 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
5381 int size
, char* filename
);
5382 BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
, char * charset
);
5385 w32_load_system_font (f
,fontname
,size
)
5390 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5391 Lisp_Object font_names
;
5393 /* Get a list of all the fonts that match this name. Once we
5394 have a list of matching fonts, we compare them against the fonts
5395 we already have loaded by comparing names. */
5396 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
5398 if (!NILP (font_names
))
5403 /* First check if any are already loaded, as that is cheaper
5404 than loading another one. */
5405 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5406 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
5407 if (dpyinfo
->font_table
[i
].name
5408 && (!strcmp (dpyinfo
->font_table
[i
].name
,
5409 XSTRING (XCAR (tail
))->data
)
5410 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
5411 XSTRING (XCAR (tail
))->data
)))
5412 return (dpyinfo
->font_table
+ i
);
5414 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
5416 else if (w32_strict_fontnames
)
5418 /* If EnumFontFamiliesEx was available, we got a full list of
5419 fonts back so stop now to avoid the possibility of loading a
5420 random font. If we had to fall back to EnumFontFamilies, the
5421 list is incomplete, so continue whether the font we want was
5423 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5424 FARPROC enum_font_families_ex
5425 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
5426 if (enum_font_families_ex
)
5430 /* Load the font and add it to the table. */
5432 char *full_name
, *encoding
, *charset
;
5434 struct font_info
*fontp
;
5439 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
5442 if (!*lf
.lfFaceName
)
5443 /* If no name was specified for the font, we get a random font
5444 from CreateFontIndirect - this is not particularly
5445 desirable, especially since CreateFontIndirect does not
5446 fill out the missing name in lf, so we never know what we
5450 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
5451 bzero (font
, sizeof (*font
));
5453 /* Set bdf to NULL to indicate that this is a Windows font. */
5458 font
->hfont
= CreateFontIndirect (&lf
);
5460 if (font
->hfont
== NULL
)
5469 hdc
= GetDC (dpyinfo
->root_window
);
5470 oldobj
= SelectObject (hdc
, font
->hfont
);
5471 ok
= GetTextMetrics (hdc
, &font
->tm
);
5472 font
->double_byte_p
= GetFontLanguageInfo(hdc
) & GCP_DBCS
;
5473 SelectObject (hdc
, oldobj
);
5474 ReleaseDC (dpyinfo
->root_window
, hdc
);
5475 /* Fill out details in lf according to the font that was
5477 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
5478 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
5479 lf
.lfWeight
= font
->tm
.tmWeight
;
5480 lf
.lfItalic
= font
->tm
.tmItalic
;
5481 lf
.lfCharSet
= font
->tm
.tmCharSet
;
5482 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
5483 ? VARIABLE_PITCH
: FIXED_PITCH
);
5484 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
5485 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
5487 w32_cache_char_metrics (font
);
5494 w32_unload_font (dpyinfo
, font
);
5498 /* Find a free slot in the font table. */
5499 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
5500 if (dpyinfo
->font_table
[i
].name
== NULL
)
5503 /* If no free slot found, maybe enlarge the font table. */
5504 if (i
== dpyinfo
->n_fonts
5505 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
5508 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
5509 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
5511 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
5514 fontp
= dpyinfo
->font_table
+ i
;
5515 if (i
== dpyinfo
->n_fonts
)
5518 /* Now fill in the slots of *FONTP. */
5521 fontp
->font_idx
= i
;
5522 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
5523 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
5525 charset
= xlfd_charset_of_font (fontname
);
5527 /* Work out the font's full name. */
5528 full_name
= (char *)xmalloc (100);
5529 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
5530 fontp
->full_name
= full_name
;
5533 /* If all else fails - just use the name we used to load it. */
5535 fontp
->full_name
= fontp
->name
;
5538 fontp
->size
= FONT_WIDTH (font
);
5539 fontp
->height
= FONT_HEIGHT (font
);
5541 /* The slot `encoding' specifies how to map a character
5542 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
5543 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
5544 (0:0x20..0x7F, 1:0xA0..0xFF,
5545 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
5546 2:0xA020..0xFF7F). For the moment, we don't know which charset
5547 uses this font. So, we set information in fontp->encoding[1]
5548 which is never used by any charset. If mapping can't be
5549 decided, set FONT_ENCODING_NOT_DECIDED. */
5551 /* SJIS fonts need to be set to type 4, all others seem to work as
5552 type FONT_ENCODING_NOT_DECIDED. */
5553 encoding
= strrchr (fontp
->name
, '-');
5554 if (encoding
&& stricmp (encoding
+1, "sjis") == 0)
5555 fontp
->encoding
[1] = 4;
5557 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
5559 /* The following three values are set to 0 under W32, which is
5560 what they get set to if XGetFontProperty fails under X. */
5561 fontp
->baseline_offset
= 0;
5562 fontp
->relative_compose
= 0;
5563 fontp
->default_ascent
= 0;
5565 /* Set global flag fonts_changed_p to non-zero if the font loaded
5566 has a character with a smaller width than any other character
5567 before, or if the font loaded has a smalle>r height than any
5568 other font loaded before. If this happens, it will make a
5569 glyph matrix reallocation necessary. */
5570 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
5576 /* Load font named FONTNAME of size SIZE for frame F, and return a
5577 pointer to the structure font_info while allocating it dynamically.
5578 If loading fails, return NULL. */
5580 w32_load_font (f
,fontname
,size
)
5585 Lisp_Object bdf_fonts
;
5586 struct font_info
*retval
= NULL
;
5588 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
));
5590 while (!retval
&& CONSP (bdf_fonts
))
5592 char *bdf_name
, *bdf_file
;
5593 Lisp_Object bdf_pair
;
5595 bdf_name
= XSTRING (XCAR (bdf_fonts
))->data
;
5596 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
5597 bdf_file
= XSTRING (XCDR (bdf_pair
))->data
;
5599 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
5601 bdf_fonts
= XCDR (bdf_fonts
);
5607 return w32_load_system_font(f
, fontname
, size
);
5612 w32_unload_font (dpyinfo
, font
)
5613 struct w32_display_info
*dpyinfo
;
5618 if (font
->per_char
) xfree (font
->per_char
);
5619 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
5621 if (font
->hfont
) DeleteObject(font
->hfont
);
5626 /* The font conversion stuff between x and w32 */
5628 /* X font string is as follows (from faces.el)
5632 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
5633 * (weight\? "\\([^-]*\\)") ; 1
5634 * (slant "\\([ior]\\)") ; 2
5635 * (slant\? "\\([^-]?\\)") ; 2
5636 * (swidth "\\([^-]*\\)") ; 3
5637 * (adstyle "[^-]*") ; 4
5638 * (pixelsize "[0-9]+")
5639 * (pointsize "[0-9][0-9]+")
5640 * (resx "[0-9][0-9]+")
5641 * (resy "[0-9][0-9]+")
5642 * (spacing "[cmp?*]")
5643 * (avgwidth "[0-9]+")
5644 * (registry "[^-]+")
5645 * (encoding "[^-]+")
5650 x_to_w32_weight (lpw
)
5653 if (!lpw
) return (FW_DONTCARE
);
5655 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
5656 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
5657 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
5658 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
5659 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
5660 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
5661 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
5662 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
5663 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
5664 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
5671 w32_to_x_weight (fnweight
)
5674 if (fnweight
>= FW_HEAVY
) return "heavy";
5675 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
5676 if (fnweight
>= FW_BOLD
) return "bold";
5677 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
5678 if (fnweight
>= FW_MEDIUM
) return "medium";
5679 if (fnweight
>= FW_NORMAL
) return "normal";
5680 if (fnweight
>= FW_LIGHT
) return "light";
5681 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
5682 if (fnweight
>= FW_THIN
) return "thin";
5688 x_to_w32_charset (lpcs
)
5691 Lisp_Object this_entry
, w32_charset
;
5693 /* Look through w32-charset-info-alist for the character set.
5694 Format of each entry is
5695 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5697 this_entry
= Fassoc (build_string(lpcs
), Vw32_charset_info_alist
);
5699 if (NILP(this_entry
))
5701 /* At startup, we want iso8859-1 fonts to come up properly. */
5702 if (stricmp(lpcs
, "iso8859-1") == 0)
5703 return ANSI_CHARSET
;
5705 return DEFAULT_CHARSET
;
5708 w32_charset
= Fcar (Fcdr (this_entry
));
5710 // Translate Lisp symbol to number.
5711 if (w32_charset
== Qw32_charset_ansi
)
5712 return ANSI_CHARSET
;
5713 if (w32_charset
== Qw32_charset_symbol
)
5714 return SYMBOL_CHARSET
;
5715 if (w32_charset
== Qw32_charset_shiftjis
)
5716 return SHIFTJIS_CHARSET
;
5717 if (w32_charset
== Qw32_charset_hangeul
)
5718 return HANGEUL_CHARSET
;
5719 if (w32_charset
== Qw32_charset_chinesebig5
)
5720 return CHINESEBIG5_CHARSET
;
5721 if (w32_charset
== Qw32_charset_gb2312
)
5722 return GB2312_CHARSET
;
5723 if (w32_charset
== Qw32_charset_oem
)
5725 #ifdef JOHAB_CHARSET
5726 if (w32_charset
== Qw32_charset_johab
)
5727 return JOHAB_CHARSET
;
5728 if (w32_charset
== Qw32_charset_easteurope
)
5729 return EASTEUROPE_CHARSET
;
5730 if (w32_charset
== Qw32_charset_turkish
)
5731 return TURKISH_CHARSET
;
5732 if (w32_charset
== Qw32_charset_baltic
)
5733 return BALTIC_CHARSET
;
5734 if (w32_charset
== Qw32_charset_russian
)
5735 return RUSSIAN_CHARSET
;
5736 if (w32_charset
== Qw32_charset_arabic
)
5737 return ARABIC_CHARSET
;
5738 if (w32_charset
== Qw32_charset_greek
)
5739 return GREEK_CHARSET
;
5740 if (w32_charset
== Qw32_charset_hebrew
)
5741 return HEBREW_CHARSET
;
5742 if (w32_charset
== Qw32_charset_vietnamese
)
5743 return VIETNAMESE_CHARSET
;
5744 if (w32_charset
== Qw32_charset_thai
)
5745 return THAI_CHARSET
;
5746 if (w32_charset
== Qw32_charset_mac
)
5748 #endif /* JOHAB_CHARSET */
5749 #ifdef UNICODE_CHARSET
5750 if (w32_charset
== Qw32_charset_unicode
)
5751 return UNICODE_CHARSET
;
5754 return DEFAULT_CHARSET
;
5759 w32_to_x_charset (fncharset
)
5762 static char buf
[16];
5763 Lisp_Object charset_type
;
5768 /* Handle startup case of w32-charset-info-alist not
5769 being set up yet. */
5770 if (NILP(Vw32_charset_info_alist
))
5772 charset_type
= Qw32_charset_ansi
;
5774 case DEFAULT_CHARSET
:
5775 charset_type
= Qw32_charset_default
;
5777 case SYMBOL_CHARSET
:
5778 charset_type
= Qw32_charset_symbol
;
5780 case SHIFTJIS_CHARSET
:
5781 charset_type
= Qw32_charset_shiftjis
;
5783 case HANGEUL_CHARSET
:
5784 charset_type
= Qw32_charset_hangeul
;
5786 case GB2312_CHARSET
:
5787 charset_type
= Qw32_charset_gb2312
;
5789 case CHINESEBIG5_CHARSET
:
5790 charset_type
= Qw32_charset_chinesebig5
;
5793 charset_type
= Qw32_charset_oem
;
5796 /* More recent versions of Windows (95 and NT4.0) define more
5798 #ifdef EASTEUROPE_CHARSET
5799 case EASTEUROPE_CHARSET
:
5800 charset_type
= Qw32_charset_easteurope
;
5802 case TURKISH_CHARSET
:
5803 charset_type
= Qw32_charset_turkish
;
5805 case BALTIC_CHARSET
:
5806 charset_type
= Qw32_charset_baltic
;
5808 case RUSSIAN_CHARSET
:
5809 charset_type
= Qw32_charset_russian
;
5811 case ARABIC_CHARSET
:
5812 charset_type
= Qw32_charset_arabic
;
5815 charset_type
= Qw32_charset_greek
;
5817 case HEBREW_CHARSET
:
5818 charset_type
= Qw32_charset_hebrew
;
5820 case VIETNAMESE_CHARSET
:
5821 charset_type
= Qw32_charset_vietnamese
;
5824 charset_type
= Qw32_charset_thai
;
5827 charset_type
= Qw32_charset_mac
;
5830 charset_type
= Qw32_charset_johab
;
5834 #ifdef UNICODE_CHARSET
5835 case UNICODE_CHARSET
:
5836 charset_type
= Qw32_charset_unicode
;
5840 /* Encode numerical value of unknown charset. */
5841 sprintf (buf
, "*-#%u", fncharset
);
5847 char * best_match
= NULL
;
5849 /* Look through w32-charset-info-alist for the character set.
5850 Prefer ISO codepages, and prefer lower numbers in the ISO
5851 range. Only return charsets for codepages which are installed.
5853 Format of each entry is
5854 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5856 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5859 Lisp_Object w32_charset
;
5860 Lisp_Object codepage
;
5862 Lisp_Object this_entry
= XCAR (rest
);
5864 /* Skip invalid entries in alist. */
5865 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5866 || !CONSP (XCDR (this_entry
))
5867 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5870 x_charset
= XSTRING (XCAR (this_entry
))->data
;
5871 w32_charset
= XCAR (XCDR (this_entry
));
5872 codepage
= XCDR (XCDR (this_entry
));
5874 /* Look for Same charset and a valid codepage (or non-int
5875 which means ignore). */
5876 if (w32_charset
== charset_type
5877 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
5878 || IsValidCodePage (XINT (codepage
))))
5880 /* If we don't have a match already, then this is the
5883 best_match
= x_charset
;
5884 /* If this is an ISO codepage, and the best so far isn't,
5885 then this is better. */
5886 else if (stricmp (best_match
, "iso") != 0
5887 && stricmp (x_charset
, "iso") == 0)
5888 best_match
= x_charset
;
5889 /* If both are ISO8859 codepages, choose the one with the
5890 lowest number in the encoding field. */
5891 else if (stricmp (best_match
, "iso8859-") == 0
5892 && stricmp (x_charset
, "iso8859-") == 0)
5894 int best_enc
= atoi (best_match
+ 8);
5895 int this_enc
= atoi (x_charset
+ 8);
5896 if (this_enc
> 0 && this_enc
< best_enc
)
5897 best_match
= x_charset
;
5902 /* If no match, encode the numeric value. */
5905 sprintf (buf
, "*-#%u", fncharset
);
5909 strncpy(buf
, best_match
, 15);
5916 /* Get the Windows codepage corresponding to the specified font. The
5917 charset info in the font name is used to look up
5918 w32-charset-to-codepage-alist. */
5920 w32_codepage_for_font (char *fontname
)
5922 Lisp_Object codepage
, entry
;
5923 char *charset_str
, *charset
, *end
;
5925 if (NILP (Vw32_charset_info_alist
))
5928 /* Extract charset part of font string. */
5929 charset
= xlfd_charset_of_font (fontname
);
5934 charset_str
= (char *) alloca (strlen (charset
));
5935 strcpy (charset_str
, charset
);
5937 /* Remove leading "*-". */
5938 if (strncmp ("*-", charset_str
, 2) == 0)
5939 charset
= charset_str
+ 2;
5941 charset
= charset_str
;
5943 /* Stop match at wildcard (including preceding '-'). */
5944 if (end
= strchr (charset
, '*'))
5946 if (end
> charset
&& *(end
-1) == '-')
5951 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5955 codepage
= Fcdr (Fcdr (entry
));
5957 if (NILP (codepage
))
5959 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
5961 else if (INTEGERP (codepage
))
5962 return XINT (codepage
);
5969 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
5970 LOGFONT
* lplogfont
;
5973 char * specific_charset
;
5977 char height_pixels
[8];
5979 char width_pixels
[8];
5980 char *fontname_dash
;
5981 int display_resy
= one_w32_display_info
.resy
;
5982 int display_resx
= one_w32_display_info
.resx
;
5984 struct coding_system coding
;
5986 if (!lpxstr
) abort ();
5991 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
5992 fonttype
= "raster";
5993 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
5994 fonttype
= "outline";
5996 fonttype
= "unknown";
5998 setup_coding_system (Fcheck_coding_system (Vw32_system_coding_system
),
6000 coding
.src_multibyte
= 0;
6001 coding
.dst_multibyte
= 1;
6002 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6003 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
6005 fontname
= alloca(sizeof(*fontname
) * bufsz
);
6006 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
6007 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
6008 *(fontname
+ coding
.produced
) = '\0';
6010 /* Replace dashes with underscores so the dashes are not
6012 fontname_dash
= fontname
;
6013 while (fontname_dash
= strchr (fontname_dash
, '-'))
6014 *fontname_dash
= '_';
6016 if (lplogfont
->lfHeight
)
6018 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
6019 sprintf (height_dpi
, "%u",
6020 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
6024 strcpy (height_pixels
, "*");
6025 strcpy (height_dpi
, "*");
6027 if (lplogfont
->lfWidth
)
6028 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
6030 strcpy (width_pixels
, "*");
6032 _snprintf (lpxstr
, len
- 1,
6033 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
6034 fonttype
, /* foundry */
6035 fontname
, /* family */
6036 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
6037 lplogfont
->lfItalic
?'i':'r', /* slant */
6039 /* add style name */
6040 height_pixels
, /* pixel size */
6041 height_dpi
, /* point size */
6042 display_resx
, /* resx */
6043 display_resy
, /* resy */
6044 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
6045 ? 'p' : 'c', /* spacing */
6046 width_pixels
, /* avg width */
6047 specific_charset
? specific_charset
6048 : w32_to_x_charset (lplogfont
->lfCharSet
)
6049 /* charset registry and encoding */
6052 lpxstr
[len
- 1] = 0; /* just to be sure */
6057 x_to_w32_font (lpxstr
, lplogfont
)
6059 LOGFONT
* lplogfont
;
6061 struct coding_system coding
;
6063 if (!lplogfont
) return (FALSE
);
6065 memset (lplogfont
, 0, sizeof (*lplogfont
));
6067 /* Set default value for each field. */
6069 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
6070 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
6071 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
6073 /* go for maximum quality */
6074 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
6075 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
6076 lplogfont
->lfQuality
= PROOF_QUALITY
;
6079 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
6080 lplogfont
->lfWeight
= FW_DONTCARE
;
6081 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
6086 /* Provide a simple escape mechanism for specifying Windows font names
6087 * directly -- if font spec does not beginning with '-', assume this
6089 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
6095 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
6096 width
[10], resy
[10], remainder
[20];
6098 int dpi
= one_w32_display_info
.resy
;
6100 fields
= sscanf (lpxstr
,
6101 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%19s",
6102 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
6103 if (fields
== EOF
) return (FALSE
);
6105 /* If wildcards cover more than one field, we don't know which
6106 field is which, so don't fill any in. */
6111 if (fields
> 0 && name
[0] != '*')
6117 (Fcheck_coding_system (Vw32_system_coding_system
), &coding
);
6118 coding
.src_multibyte
= 1;
6119 coding
.dst_multibyte
= 1;
6120 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
6121 buf
= (unsigned char *) alloca (bufsize
);
6122 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6123 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
6124 if (coding
.produced
>= LF_FACESIZE
)
6125 coding
.produced
= LF_FACESIZE
- 1;
6126 buf
[coding
.produced
] = 0;
6127 strcpy (lplogfont
->lfFaceName
, buf
);
6131 lplogfont
->lfFaceName
[0] = '\0';
6136 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6140 if (!NILP (Vw32_enable_synthesized_fonts
))
6141 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
6145 if (fields
> 0 && pixels
[0] != '*')
6146 lplogfont
->lfHeight
= atoi (pixels
);
6150 if (fields
> 0 && resy
[0] != '*')
6153 if (tem
> 0) dpi
= tem
;
6156 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
6157 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
6160 lplogfont
->lfPitchAndFamily
=
6161 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
6165 if (fields
> 0 && width
[0] != '*')
6166 lplogfont
->lfWidth
= atoi (width
) / 10;
6170 /* Strip the trailing '-' if present. (it shouldn't be, as it
6171 fails the test against xlfd-tight-regexp in fontset.el). */
6173 int len
= strlen (remainder
);
6174 if (len
> 0 && remainder
[len
-1] == '-')
6175 remainder
[len
-1] = 0;
6177 encoding
= remainder
;
6178 if (strncmp (encoding
, "*-", 2) == 0)
6180 lplogfont
->lfCharSet
= x_to_w32_charset (fields
> 0 ? encoding
: "");
6185 char name
[100], height
[10], width
[10], weight
[20];
6187 fields
= sscanf (lpxstr
,
6188 "%99[^:]:%9[^:]:%9[^:]:%19s",
6189 name
, height
, width
, weight
);
6191 if (fields
== EOF
) return (FALSE
);
6195 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
6196 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
6200 lplogfont
->lfFaceName
[0] = 0;
6206 lplogfont
->lfHeight
= atoi (height
);
6211 lplogfont
->lfWidth
= atoi (width
);
6215 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6218 /* This makes TrueType fonts work better. */
6219 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
6224 /* Strip the pixel height and point height from the given xlfd, and
6225 return the pixel height. If no pixel height is specified, calculate
6226 one from the point height, or if that isn't defined either, return
6227 0 (which usually signifies a scalable font).
6229 int xlfd_strip_height (char *fontname
)
6231 int pixel_height
, point_height
, dpi
, field_number
;
6232 char *read_from
, *write_to
;
6236 pixel_height
= field_number
= 0;
6239 /* Look for height fields. */
6240 for (read_from
= fontname
; *read_from
; read_from
++)
6242 if (*read_from
== '-')
6245 if (field_number
== 7) /* Pixel height. */
6248 write_to
= read_from
;
6250 /* Find end of field. */
6251 for (;*read_from
&& *read_from
!= '-'; read_from
++)
6254 /* Split the fontname at end of field. */
6260 pixel_height
= atoi (write_to
);
6261 /* Blank out field. */
6262 if (read_from
> write_to
)
6267 /* If the pixel height field is at the end (partial xlfd),
6270 return pixel_height
;
6272 /* If we got a pixel height, the point height can be
6273 ignored. Just blank it out and break now. */
6276 /* Find end of point size field. */
6277 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6283 /* Blank out the point size field. */
6284 if (read_from
> write_to
)
6290 return pixel_height
;
6294 /* If the point height is already blank, break now. */
6295 if (*read_from
== '-')
6301 else if (field_number
== 8)
6303 /* If we didn't get a pixel height, try to get the point
6304 height and convert that. */
6306 char *point_size_start
= read_from
++;
6308 /* Find end of field. */
6309 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6318 point_size
= atoi (point_size_start
);
6320 /* Convert to pixel height. */
6321 pixel_height
= point_size
6322 * one_w32_display_info
.height_in
/ 720;
6324 /* Blank out this field and break. */
6332 /* Shift the rest of the font spec into place. */
6333 if (write_to
&& read_from
> write_to
)
6335 for (; *read_from
; read_from
++, write_to
++)
6336 *write_to
= *read_from
;
6340 return pixel_height
;
6343 /* Assume parameter 1 is fully qualified, no wildcards. */
6345 w32_font_match (fontname
, pattern
)
6349 char *regex
= alloca (strlen (pattern
) * 2);
6350 char *font_name_copy
= alloca (strlen (fontname
) + 1);
6353 /* Copy fontname so we can modify it during comparison. */
6354 strcpy (font_name_copy
, fontname
);
6359 /* Turn pattern into a regexp and do a regexp match. */
6360 for (; *pattern
; pattern
++)
6362 if (*pattern
== '?')
6364 else if (*pattern
== '*')
6375 /* Strip out font heights and compare them seperately, since
6376 rounding error can cause mismatches. This also allows a
6377 comparison between a font that declares only a pixel height and a
6378 pattern that declares the point height.
6381 int font_height
, pattern_height
;
6383 font_height
= xlfd_strip_height (font_name_copy
);
6384 pattern_height
= xlfd_strip_height (regex
);
6386 /* Compare now, and don't bother doing expensive regexp matching
6387 if the heights differ. */
6388 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
6392 return (fast_c_string_match_ignore_case (build_string (regex
),
6393 font_name_copy
) >= 0);
6396 /* Callback functions, and a structure holding info they need, for
6397 listing system fonts on W32. We need one set of functions to do the
6398 job properly, but these don't work on NT 3.51 and earlier, so we
6399 have a second set which don't handle character sets properly to
6402 In both cases, there are two passes made. The first pass gets one
6403 font from each family, the second pass lists all the fonts from
6406 typedef struct enumfont_t
6411 XFontStruct
*size_ref
;
6412 Lisp_Object
*pattern
;
6417 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
6419 NEWTEXTMETRIC
* lptm
;
6423 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
6426 /* Check that the character set matches if it was specified */
6427 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6428 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6433 Lisp_Object width
= Qnil
;
6434 char *charset
= NULL
;
6436 /* Truetype fonts do not report their true metrics until loaded */
6437 if (FontType
!= RASTER_FONTTYPE
)
6439 if (!NILP (*(lpef
->pattern
)))
6441 /* Scalable fonts are as big as you want them to be. */
6442 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6443 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6444 width
= make_number (lpef
->logfont
.lfWidth
);
6448 lplf
->elfLogFont
.lfHeight
= 0;
6449 lplf
->elfLogFont
.lfWidth
= 0;
6453 /* Make sure the height used here is the same as everywhere
6454 else (ie character height, not cell height). */
6455 if (lplf
->elfLogFont
.lfHeight
> 0)
6457 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6458 if (FontType
== RASTER_FONTTYPE
)
6459 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6461 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6464 if (!NILP (*(lpef
->pattern
)))
6466 charset
= xlfd_charset_of_font (XSTRING(*(lpef
->pattern
))->data
);
6468 /* Ensure that charset is valid for this font. */
6470 && (x_to_w32_charset (charset
) != lplf
->elfLogFont
.lfCharSet
))
6474 /* TODO: List all relevant charsets if charset not specified. */
6475 if (!w32_to_x_font (&(lplf
->elfLogFont
), buf
, 100, charset
))
6478 if (NILP (*(lpef
->pattern
))
6479 || w32_font_match (buf
, XSTRING (*(lpef
->pattern
))->data
))
6481 *lpef
->tail
= Fcons (Fcons (build_string (buf
), width
), Qnil
);
6482 lpef
->tail
= &(XCDR (*lpef
->tail
));
6491 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6493 NEWTEXTMETRIC
* lptm
;
6497 return EnumFontFamilies (lpef
->hdc
,
6498 lplf
->elfLogFont
.lfFaceName
,
6499 (FONTENUMPROC
) enum_font_cb2
,
6505 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6506 ENUMLOGFONTEX
* lplf
;
6507 NEWTEXTMETRICEX
* lptm
;
6511 /* We are not interested in the extra info we get back from the 'Ex
6512 version - only the fact that we get character set variations
6513 enumerated seperately. */
6514 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6519 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6520 ENUMLOGFONTEX
* lplf
;
6521 NEWTEXTMETRICEX
* lptm
;
6525 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6526 FARPROC enum_font_families_ex
6527 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6528 /* We don't really expect EnumFontFamiliesEx to disappear once we
6529 get here, so don't bother handling it gracefully. */
6530 if (enum_font_families_ex
== NULL
)
6531 error ("gdi32.dll has disappeared!");
6532 return enum_font_families_ex (lpef
->hdc
,
6534 (FONTENUMPROC
) enum_fontex_cb2
,
6538 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6539 and xterm.c in Emacs 20.3) */
6541 Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6543 char *fontname
, *ptnstr
;
6544 Lisp_Object list
, tem
, newlist
= Qnil
;
6547 list
= Vw32_bdf_filename_alist
;
6548 ptnstr
= XSTRING (pattern
)->data
;
6550 for ( ; CONSP (list
); list
= XCDR (list
))
6554 fontname
= XSTRING (XCAR (tem
))->data
;
6555 else if (STRINGP (tem
))
6556 fontname
= XSTRING (tem
)->data
;
6560 if (w32_font_match (fontname
, ptnstr
))
6562 newlist
= Fcons (XCAR (tem
), newlist
);
6564 if (n_fonts
>= max_names
)
6572 Lisp_Object
w32_list_synthesized_fonts (FRAME_PTR f
, Lisp_Object pattern
,
6573 int size
, int max_names
);
6575 /* Return a list of names of available fonts matching PATTERN on frame
6576 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6577 to be listed. Frame F NULL means we have not yet created any
6578 frame, which means we can't get proper size info, as we don't have
6579 a device context to use for GetTextMetrics.
6580 MAXNAMES sets a limit on how many fonts to match. */
6583 w32_list_fonts (FRAME_PTR f
, Lisp_Object pattern
, int size
, int maxnames
)
6585 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6586 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6587 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6590 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6591 if (NILP (patterns
))
6592 patterns
= Fcons (pattern
, Qnil
);
6594 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6599 tpat
= XCAR (patterns
);
6601 if (!STRINGP (tpat
))
6604 /* Avoid expensive EnumFontFamilies functions if we are not
6605 going to be able to output one of these anyway. */
6606 codepage
= w32_codepage_for_font (XSTRING (tpat
)->data
);
6607 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6608 && codepage
!= CP_DEFAULT
&& !IsValidCodePage(codepage
))
6611 /* See if we cached the result for this particular query.
6612 The cache is an alist of the form:
6613 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6615 if (tem
= XCDR (dpyinfo
->name_list_element
),
6616 !NILP (list
= Fassoc (tpat
, tem
)))
6618 list
= Fcdr_safe (list
);
6619 /* We have a cached list. Don't have to get the list again. */
6624 /* At first, put PATTERN in the cache. */
6630 /* Use EnumFontFamiliesEx where it is available, as it knows
6631 about character sets. Fall back to EnumFontFamilies for
6632 older versions of NT that don't support the 'Ex function. */
6633 x_to_w32_font (XSTRING (tpat
)->data
, &ef
.logfont
);
6635 LOGFONT font_match_pattern
;
6636 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6637 FARPROC enum_font_families_ex
6638 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6640 /* We do our own pattern matching so we can handle wildcards. */
6641 font_match_pattern
.lfFaceName
[0] = 0;
6642 font_match_pattern
.lfPitchAndFamily
= 0;
6643 /* We can use the charset, because if it is a wildcard it will
6644 be DEFAULT_CHARSET anyway. */
6645 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6647 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6649 if (enum_font_families_ex
)
6650 enum_font_families_ex (ef
.hdc
,
6651 &font_match_pattern
,
6652 (FONTENUMPROC
) enum_fontex_cb1
,
6655 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6658 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6663 /* Make a list of the fonts we got back.
6664 Store that in the font cache for the display. */
6665 XCDR (dpyinfo
->name_list_element
)
6666 = Fcons (Fcons (tpat
, list
),
6667 XCDR (dpyinfo
->name_list_element
));
6670 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6672 newlist
= second_best
= Qnil
;
6674 /* Make a list of the fonts that have the right width. */
6675 for (; CONSP (list
); list
= XCDR (list
))
6682 if (NILP (XCAR (tem
)))
6686 newlist
= Fcons (XCAR (tem
), newlist
);
6688 if (n_fonts
>= maxnames
)
6693 if (!INTEGERP (XCDR (tem
)))
6695 /* Since we don't yet know the size of the font, we must
6696 load it and try GetTextMetrics. */
6697 W32FontStruct thisinfo
;
6702 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
6706 thisinfo
.bdf
= NULL
;
6707 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6708 if (thisinfo
.hfont
== NULL
)
6711 hdc
= GetDC (dpyinfo
->root_window
);
6712 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6713 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6714 XCDR (tem
) = make_number (FONT_WIDTH (&thisinfo
));
6716 XCDR (tem
) = make_number (0);
6717 SelectObject (hdc
, oldobj
);
6718 ReleaseDC (dpyinfo
->root_window
, hdc
);
6719 DeleteObject(thisinfo
.hfont
);
6722 found_size
= XINT (XCDR (tem
));
6723 if (found_size
== size
)
6725 newlist
= Fcons (XCAR (tem
), newlist
);
6727 if (n_fonts
>= maxnames
)
6730 /* keep track of the closest matching size in case
6731 no exact match is found. */
6732 else if (found_size
> 0)
6734 if (NILP (second_best
))
6737 else if (found_size
< size
)
6739 if (XINT (XCDR (second_best
)) > size
6740 || XINT (XCDR (second_best
)) < found_size
)
6745 if (XINT (XCDR (second_best
)) > size
6746 && XINT (XCDR (second_best
)) >
6753 if (!NILP (newlist
))
6755 else if (!NILP (second_best
))
6757 newlist
= Fcons (XCAR (second_best
), Qnil
);
6762 /* Include any bdf fonts. */
6763 if (n_fonts
< maxnames
)
6765 Lisp_Object combined
[2];
6766 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6767 combined
[1] = newlist
;
6768 newlist
= Fnconc(2, combined
);
6771 /* If we can't find a font that matches, check if Windows would be
6772 able to synthesize it from a different style. */
6773 if (NILP (newlist
) && !NILP (Vw32_enable_synthesized_fonts
))
6774 newlist
= w32_list_synthesized_fonts (f
, pattern
, size
, maxnames
);
6780 w32_list_synthesized_fonts (f
, pattern
, size
, max_names
)
6782 Lisp_Object pattern
;
6787 char *full_pattn
, *new_pattn
, foundary
[50], family
[50], *pattn_part2
;
6788 char style
[20], slant
;
6789 Lisp_Object matches
, match
, tem
, synthed_matches
= Qnil
;
6791 full_pattn
= XSTRING (pattern
)->data
;
6793 pattn_part2
= alloca (XSTRING (pattern
)->size
);
6794 /* Allow some space for wildcard expansion. */
6795 new_pattn
= alloca (XSTRING (pattern
)->size
+ 100);
6797 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%19[^-]-%c-%s",
6798 foundary
, family
, style
, &slant
, pattn_part2
);
6799 if (fields
== EOF
|| fields
< 5)
6802 /* If the style and slant are wildcards already there is no point
6803 checking again (and we don't want to keep recursing). */
6804 if (*style
== '*' && slant
== '*')
6807 sprintf (new_pattn
, "-%s-%s-*-*-%s", foundary
, family
, pattn_part2
);
6809 matches
= w32_list_fonts (f
, build_string (new_pattn
), size
, max_names
);
6811 for ( ; CONSP (matches
); matches
= XCDR (matches
))
6813 tem
= XCAR (matches
);
6817 full_pattn
= XSTRING (tem
)->data
;
6818 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%*[^-]-%*c-%s",
6819 foundary
, family
, pattn_part2
);
6820 if (fields
== EOF
|| fields
< 3)
6823 sprintf (new_pattn
, "-%s-%s-%s-%c-%s", foundary
, family
, style
,
6824 slant
, pattn_part2
);
6826 synthed_matches
= Fcons (build_string (new_pattn
),
6830 return synthed_matches
;
6834 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6836 w32_get_font_info (f
, font_idx
)
6840 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6845 w32_query_font (struct frame
*f
, char *fontname
)
6848 struct font_info
*pfi
;
6850 pfi
= FRAME_W32_FONT_TABLE (f
);
6852 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6854 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
6860 /* Find a CCL program for a font specified by FONTP, and set the member
6861 `encoder' of the structure. */
6864 w32_find_ccl_program (fontp
)
6865 struct font_info
*fontp
;
6867 Lisp_Object list
, elt
;
6869 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6873 && STRINGP (XCAR (elt
))
6874 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6880 struct ccl_program
*ccl
6881 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6883 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6886 fontp
->font_encoder
= ccl
;
6891 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6893 "Return a list of BDF fonts in DIR, suitable for appending to\n\
6894 w32-bdf-filename-alist. Fonts which do not contain an xlfd description\n\
6895 will not be included in the list. DIR may be a list of directories.")
6897 Lisp_Object directory
;
6899 Lisp_Object list
= Qnil
;
6900 struct gcpro gcpro1
, gcpro2
;
6902 if (!CONSP (directory
))
6903 return w32_find_bdf_fonts_in_dir (directory
);
6905 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6907 Lisp_Object pair
[2];
6910 GCPRO2 (directory
, list
);
6911 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6912 list
= Fnconc( 2, pair
);
6918 /* Find BDF files in a specified directory. (use GCPRO when calling,
6919 as this calls lisp to get a directory listing). */
6920 Lisp_Object
w32_find_bdf_fonts_in_dir( Lisp_Object directory
)
6922 Lisp_Object filelist
, list
= Qnil
;
6925 if (!STRINGP(directory
))
6928 filelist
= Fdirectory_files (directory
, Qt
,
6929 build_string (".*\\.[bB][dD][fF]"), Qt
);
6931 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
6933 Lisp_Object filename
= XCAR (filelist
);
6934 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
6935 store_in_alist (&list
, build_string (fontname
), filename
);
6941 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
6942 "Internal function called by `color-defined-p', which see.")
6944 Lisp_Object color
, frame
;
6947 FRAME_PTR f
= check_x_frame (frame
);
6949 CHECK_STRING (color
, 1);
6951 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
6957 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
6958 "Internal function called by `color-values', which see.")
6960 Lisp_Object color
, frame
;
6963 FRAME_PTR f
= check_x_frame (frame
);
6965 CHECK_STRING (color
, 1);
6967 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
6971 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
6972 | GetRValue (foo
.pixel
));
6973 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
6974 | GetGValue (foo
.pixel
));
6975 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
6976 | GetBValue (foo
.pixel
));
6977 return Flist (3, rgb
);
6983 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
6984 "Internal function called by `display-color-p', which see.")
6986 Lisp_Object display
;
6988 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
6990 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
6996 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
6998 "Return t if the X display supports shades of gray.\n\
6999 Note that color displays do support shades of gray.\n\
7000 The optional argument DISPLAY specifies which display to ask about.\n\
7001 DISPLAY should be either a frame or a display name (a string).\n\
7002 If omitted or nil, that stands for the selected frame's display.")
7004 Lisp_Object display
;
7006 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7008 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
7014 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
7016 "Returns the width in pixels of the X display DISPLAY.\n\
7017 The optional argument DISPLAY specifies which display to ask about.\n\
7018 DISPLAY should be either a frame or a display name (a string).\n\
7019 If omitted or nil, that stands for the selected frame's display.")
7021 Lisp_Object display
;
7023 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7025 return make_number (dpyinfo
->width
);
7028 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
7029 Sx_display_pixel_height
, 0, 1, 0,
7030 "Returns the height in pixels of the X display DISPLAY.\n\
7031 The optional argument DISPLAY specifies which display to ask about.\n\
7032 DISPLAY should be either a frame or a display name (a string).\n\
7033 If omitted or nil, that stands for the selected frame's display.")
7035 Lisp_Object display
;
7037 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7039 return make_number (dpyinfo
->height
);
7042 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
7044 "Returns the number of bitplanes of the display DISPLAY.\n\
7045 The optional argument DISPLAY specifies which display to ask about.\n\
7046 DISPLAY should be either a frame or a display name (a string).\n\
7047 If omitted or nil, that stands for the selected frame's display.")
7049 Lisp_Object display
;
7051 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7053 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7056 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
7058 "Returns the number of color cells of the display DISPLAY.\n\
7059 The optional argument DISPLAY specifies which display to ask about.\n\
7060 DISPLAY should be either a frame or a display name (a string).\n\
7061 If omitted or nil, that stands for the selected frame's display.")
7063 Lisp_Object display
;
7065 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7069 hdc
= GetDC (dpyinfo
->root_window
);
7070 if (dpyinfo
->has_palette
)
7071 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
7073 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
7075 ReleaseDC (dpyinfo
->root_window
, hdc
);
7077 return make_number (cap
);
7080 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
7081 Sx_server_max_request_size
,
7083 "Returns the maximum request size of the server of display DISPLAY.\n\
7084 The optional argument DISPLAY specifies which display to ask about.\n\
7085 DISPLAY should be either a frame or a display name (a string).\n\
7086 If omitted or nil, that stands for the selected frame's display.")
7088 Lisp_Object display
;
7090 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7092 return make_number (1);
7095 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
7096 "Returns the vendor ID string of the W32 system (Microsoft).\n\
7097 The optional argument DISPLAY specifies which display to ask about.\n\
7098 DISPLAY should be either a frame or a display name (a string).\n\
7099 If omitted or nil, that stands for the selected frame's display.")
7101 Lisp_Object display
;
7103 return build_string ("Microsoft Corp.");
7106 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
7107 "Returns the version numbers of the server of display DISPLAY.\n\
7108 The value is a list of three integers: the major and minor\n\
7109 version numbers, and the vendor-specific release\n\
7110 number. See also the function `x-server-vendor'.\n\n\
7111 The optional argument DISPLAY specifies which display to ask about.\n\
7112 DISPLAY should be either a frame or a display name (a string).\n\
7113 If omitted or nil, that stands for the selected frame's display.")
7115 Lisp_Object display
;
7117 return Fcons (make_number (w32_major_version
),
7118 Fcons (make_number (w32_minor_version
),
7119 Fcons (make_number (w32_build_number
), Qnil
)));
7122 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
7123 "Returns the number of screens on the server of display DISPLAY.\n\
7124 The optional argument DISPLAY specifies which display to ask about.\n\
7125 DISPLAY should be either a frame or a display name (a string).\n\
7126 If omitted or nil, that stands for the selected frame's display.")
7128 Lisp_Object display
;
7130 return make_number (1);
7133 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
7134 "Returns the height in millimeters of the X display DISPLAY.\n\
7135 The optional argument DISPLAY specifies which display to ask about.\n\
7136 DISPLAY should be either a frame or a display name (a string).\n\
7137 If omitted or nil, that stands for the selected frame's display.")
7139 Lisp_Object display
;
7141 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7145 hdc
= GetDC (dpyinfo
->root_window
);
7147 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
7149 ReleaseDC (dpyinfo
->root_window
, hdc
);
7151 return make_number (cap
);
7154 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
7155 "Returns the width in millimeters of the X 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
);
7167 hdc
= GetDC (dpyinfo
->root_window
);
7169 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
7171 ReleaseDC (dpyinfo
->root_window
, hdc
);
7173 return make_number (cap
);
7176 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
7177 Sx_display_backing_store
, 0, 1, 0,
7178 "Returns an indication of whether display DISPLAY does backing store.\n\
7179 The value may be `always', `when-mapped', or `not-useful'.\n\
7180 The optional argument DISPLAY specifies which display to ask about.\n\
7181 DISPLAY should be either a frame or a display name (a string).\n\
7182 If omitted or nil, that stands for the selected frame's display.")
7184 Lisp_Object display
;
7186 return intern ("not-useful");
7189 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
7190 Sx_display_visual_class
, 0, 1, 0,
7191 "Returns the visual class of the display DISPLAY.\n\
7192 The value is one of the symbols `static-gray', `gray-scale',\n\
7193 `static-color', `pseudo-color', `true-color', or `direct-color'.\n\n\
7194 The optional argument DISPLAY specifies which display to ask about.\n\
7195 DISPLAY should be either a frame or a display name (a string).\n\
7196 If omitted or nil, that stands for the selected frame's display.")
7198 Lisp_Object display
;
7200 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7203 switch (dpyinfo
->visual
->class)
7205 case StaticGray
: return (intern ("static-gray"));
7206 case GrayScale
: return (intern ("gray-scale"));
7207 case StaticColor
: return (intern ("static-color"));
7208 case PseudoColor
: return (intern ("pseudo-color"));
7209 case TrueColor
: return (intern ("true-color"));
7210 case DirectColor
: return (intern ("direct-color"));
7212 error ("Display has an unknown visual class");
7216 error ("Display has an unknown visual class");
7219 DEFUN ("x-display-save-under", Fx_display_save_under
,
7220 Sx_display_save_under
, 0, 1, 0,
7221 "Returns t if the display DISPLAY supports the save-under feature.\n\
7222 The optional argument DISPLAY specifies which display to ask about.\n\
7223 DISPLAY should be either a frame or a display name (a string).\n\
7224 If omitted or nil, that stands for the selected frame's display.")
7226 Lisp_Object display
;
7233 register struct frame
*f
;
7235 return PIXEL_WIDTH (f
);
7240 register struct frame
*f
;
7242 return PIXEL_HEIGHT (f
);
7247 register struct frame
*f
;
7249 return FONT_WIDTH (f
->output_data
.w32
->font
);
7254 register struct frame
*f
;
7256 return f
->output_data
.w32
->line_height
;
7261 register struct frame
*f
;
7263 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
7266 /* Return the display structure for the display named NAME.
7267 Open a new connection if necessary. */
7269 struct w32_display_info
*
7270 x_display_info_for_name (name
)
7274 struct w32_display_info
*dpyinfo
;
7276 CHECK_STRING (name
, 0);
7278 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
7280 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
7283 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
7288 /* Use this general default value to start with. */
7289 Vx_resource_name
= Vinvocation_name
;
7291 validate_x_resource_name ();
7293 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
7294 (char *) XSTRING (Vx_resource_name
)->data
);
7297 error ("Cannot connect to server %s", XSTRING (name
)->data
);
7300 XSETFASTINT (Vwindow_system_version
, 3);
7305 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
7306 1, 3, 0, "Open a connection to a server.\n\
7307 DISPLAY is the name of the display to connect to.\n\
7308 Optional second arg XRM-STRING is a string of resources in xrdb format.\n\
7309 If the optional third arg MUST-SUCCEED is non-nil,\n\
7310 terminate Emacs if we can't open the connection.")
7311 (display
, xrm_string
, must_succeed
)
7312 Lisp_Object display
, xrm_string
, must_succeed
;
7314 unsigned char *xrm_option
;
7315 struct w32_display_info
*dpyinfo
;
7317 CHECK_STRING (display
, 0);
7318 if (! NILP (xrm_string
))
7319 CHECK_STRING (xrm_string
, 1);
7321 if (! EQ (Vwindow_system
, intern ("w32")))
7322 error ("Not using Microsoft Windows");
7324 /* Allow color mapping to be defined externally; first look in user's
7325 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
7327 Lisp_Object color_file
;
7328 struct gcpro gcpro1
;
7330 color_file
= build_string("~/rgb.txt");
7332 GCPRO1 (color_file
);
7334 if (NILP (Ffile_readable_p (color_file
)))
7336 Fexpand_file_name (build_string ("rgb.txt"),
7337 Fsymbol_value (intern ("data-directory")));
7339 Vw32_color_map
= Fw32_load_color_file (color_file
);
7343 if (NILP (Vw32_color_map
))
7344 Vw32_color_map
= Fw32_default_color_map ();
7346 if (! NILP (xrm_string
))
7347 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
7349 xrm_option
= (unsigned char *) 0;
7351 /* Use this general default value to start with. */
7352 /* First remove .exe suffix from invocation-name - it looks ugly. */
7354 char basename
[ MAX_PATH
], *str
;
7356 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
7357 str
= strrchr (basename
, '.');
7359 Vinvocation_name
= build_string (basename
);
7361 Vx_resource_name
= Vinvocation_name
;
7363 validate_x_resource_name ();
7365 /* This is what opens the connection and sets x_current_display.
7366 This also initializes many symbols, such as those used for input. */
7367 dpyinfo
= w32_term_init (display
, xrm_option
,
7368 (char *) XSTRING (Vx_resource_name
)->data
);
7372 if (!NILP (must_succeed
))
7373 fatal ("Cannot connect to server %s.\n",
7374 XSTRING (display
)->data
);
7376 error ("Cannot connect to server %s", XSTRING (display
)->data
);
7381 XSETFASTINT (Vwindow_system_version
, 3);
7385 DEFUN ("x-close-connection", Fx_close_connection
,
7386 Sx_close_connection
, 1, 1, 0,
7387 "Close the connection to DISPLAY's server.\n\
7388 For DISPLAY, specify either a frame or a display name (a string).\n\
7389 If DISPLAY is nil, that stands for the selected frame's display.")
7391 Lisp_Object display
;
7393 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7396 if (dpyinfo
->reference_count
> 0)
7397 error ("Display still has frames on it");
7400 /* Free the fonts in the font table. */
7401 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7402 if (dpyinfo
->font_table
[i
].name
)
7404 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7405 xfree (dpyinfo
->font_table
[i
].full_name
);
7406 xfree (dpyinfo
->font_table
[i
].name
);
7407 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7409 x_destroy_all_bitmaps (dpyinfo
);
7411 x_delete_display (dpyinfo
);
7417 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7418 "Return the list of display names that Emacs has connections to.")
7421 Lisp_Object tail
, result
;
7424 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
7425 result
= Fcons (XCAR (XCAR (tail
)), result
);
7430 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7431 "If ON is non-nil, report errors as soon as the erring request is made.\n\
7432 If ON is nil, allow buffering of requests.\n\
7433 This is a noop on W32 systems.\n\
7434 The optional second argument DISPLAY specifies which display to act on.\n\
7435 DISPLAY should be either a frame or a display name (a string).\n\
7436 If DISPLAY is omitted or nil, that stands for the selected frame's display.")
7438 Lisp_Object display
, on
;
7445 /***********************************************************************
7447 ***********************************************************************/
7449 /* Value is the number of elements of vector VECTOR. */
7451 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
7453 /* List of supported image types. Use define_image_type to add new
7454 types. Use lookup_image_type to find a type for a given symbol. */
7456 static struct image_type
*image_types
;
7458 /* The symbol `image' which is the car of the lists used to represent
7461 extern Lisp_Object Qimage
;
7463 /* The symbol `xbm' which is used as the type symbol for XBM images. */
7469 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
7470 extern Lisp_Object QCdata
;
7471 Lisp_Object QCtype
, QCascent
, QCmargin
, QCrelief
;
7472 Lisp_Object QCalgorithm
, QCcolor_symbols
, QCheuristic_mask
;
7473 Lisp_Object QCindex
;
7475 /* Other symbols. */
7477 Lisp_Object Qlaplace
;
7479 /* Time in seconds after which images should be removed from the cache
7480 if not displayed. */
7482 Lisp_Object Vimage_cache_eviction_delay
;
7484 /* Function prototypes. */
7486 static void define_image_type
P_ ((struct image_type
*type
));
7487 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
7488 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
7489 static void x_laplace
P_ ((struct frame
*, struct image
*));
7490 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
7494 /* Define a new image type from TYPE. This adds a copy of TYPE to
7495 image_types and adds the symbol *TYPE->type to Vimage_types. */
7498 define_image_type (type
)
7499 struct image_type
*type
;
7501 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
7502 The initialized data segment is read-only. */
7503 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
7504 bcopy (type
, p
, sizeof *p
);
7505 p
->next
= image_types
;
7507 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
7511 /* Look up image type SYMBOL, and return a pointer to its image_type
7512 structure. Value is null if SYMBOL is not a known image type. */
7514 static INLINE
struct image_type
*
7515 lookup_image_type (symbol
)
7518 struct image_type
*type
;
7520 for (type
= image_types
; type
; type
= type
->next
)
7521 if (EQ (symbol
, *type
->type
))
7528 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
7529 valid image specification is a list whose car is the symbol
7530 `image', and whose rest is a property list. The property list must
7531 contain a value for key `:type'. That value must be the name of a
7532 supported image type. The rest of the property list depends on the
7536 valid_image_p (object
)
7541 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
7543 Lisp_Object symbol
= Fplist_get (XCDR (object
), QCtype
);
7544 struct image_type
*type
= lookup_image_type (symbol
);
7547 valid_p
= type
->valid_p (object
);
7554 /* Log error message with format string FORMAT and argument ARG.
7555 Signaling an error, e.g. when an image cannot be loaded, is not a
7556 good idea because this would interrupt redisplay, and the error
7557 message display would lead to another redisplay. This function
7558 therefore simply displays a message. */
7561 image_error (format
, arg1
, arg2
)
7563 Lisp_Object arg1
, arg2
;
7565 add_to_log (format
, arg1
, arg2
);
7570 /***********************************************************************
7571 Image specifications
7572 ***********************************************************************/
7574 enum image_value_type
7576 IMAGE_DONT_CHECK_VALUE_TYPE
,
7579 IMAGE_POSITIVE_INTEGER_VALUE
,
7580 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
7582 IMAGE_INTEGER_VALUE
,
7583 IMAGE_FUNCTION_VALUE
,
7588 /* Structure used when parsing image specifications. */
7590 struct image_keyword
7592 /* Name of keyword. */
7595 /* The type of value allowed. */
7596 enum image_value_type type
;
7598 /* Non-zero means key must be present. */
7601 /* Used to recognize duplicate keywords in a property list. */
7604 /* The value that was found. */
7609 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
7611 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
7614 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
7615 has the format (image KEYWORD VALUE ...). One of the keyword/
7616 value pairs must be `:type TYPE'. KEYWORDS is a vector of
7617 image_keywords structures of size NKEYWORDS describing other
7618 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
7621 parse_image_spec (spec
, keywords
, nkeywords
, type
)
7623 struct image_keyword
*keywords
;
7630 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
7633 plist
= XCDR (spec
);
7634 while (CONSP (plist
))
7636 Lisp_Object key
, value
;
7638 /* First element of a pair must be a symbol. */
7640 plist
= XCDR (plist
);
7644 /* There must follow a value. */
7647 value
= XCAR (plist
);
7648 plist
= XCDR (plist
);
7650 /* Find key in KEYWORDS. Error if not found. */
7651 for (i
= 0; i
< nkeywords
; ++i
)
7652 if (strcmp (keywords
[i
].name
, XSYMBOL (key
)->name
->data
) == 0)
7658 /* Record that we recognized the keyword. If a keywords
7659 was found more than once, it's an error. */
7660 keywords
[i
].value
= value
;
7661 ++keywords
[i
].count
;
7663 if (keywords
[i
].count
> 1)
7666 /* Check type of value against allowed type. */
7667 switch (keywords
[i
].type
)
7669 case IMAGE_STRING_VALUE
:
7670 if (!STRINGP (value
))
7674 case IMAGE_SYMBOL_VALUE
:
7675 if (!SYMBOLP (value
))
7679 case IMAGE_POSITIVE_INTEGER_VALUE
:
7680 if (!INTEGERP (value
) || XINT (value
) <= 0)
7684 case IMAGE_ASCENT_VALUE
:
7685 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
7687 else if (INTEGERP (value
)
7688 && XINT (value
) >= 0
7689 && XINT (value
) <= 100)
7693 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
7694 if (!INTEGERP (value
) || XINT (value
) < 0)
7698 case IMAGE_DONT_CHECK_VALUE_TYPE
:
7701 case IMAGE_FUNCTION_VALUE
:
7702 value
= indirect_function (value
);
7704 || COMPILEDP (value
)
7705 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
7709 case IMAGE_NUMBER_VALUE
:
7710 if (!INTEGERP (value
) && !FLOATP (value
))
7714 case IMAGE_INTEGER_VALUE
:
7715 if (!INTEGERP (value
))
7719 case IMAGE_BOOL_VALUE
:
7720 if (!NILP (value
) && !EQ (value
, Qt
))
7729 if (EQ (key
, QCtype
) && !EQ (type
, value
))
7733 /* Check that all mandatory fields are present. */
7734 for (i
= 0; i
< nkeywords
; ++i
)
7735 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
7738 return NILP (plist
);
7742 /* Return the value of KEY in image specification SPEC. Value is nil
7743 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
7744 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
7747 image_spec_value (spec
, key
, found
)
7748 Lisp_Object spec
, key
;
7753 xassert (valid_image_p (spec
));
7755 for (tail
= XCDR (spec
);
7756 CONSP (tail
) && CONSP (XCDR (tail
));
7757 tail
= XCDR (XCDR (tail
)))
7759 if (EQ (XCAR (tail
), key
))
7763 return XCAR (XCDR (tail
));
7775 /***********************************************************************
7776 Image type independent image structures
7777 ***********************************************************************/
7779 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
7780 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
7783 /* Allocate and return a new image structure for image specification
7784 SPEC. SPEC has a hash value of HASH. */
7786 static struct image
*
7787 make_image (spec
, hash
)
7791 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
7793 xassert (valid_image_p (spec
));
7794 bzero (img
, sizeof *img
);
7795 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
7796 xassert (img
->type
!= NULL
);
7798 img
->data
.lisp_val
= Qnil
;
7799 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
7805 /* Free image IMG which was used on frame F, including its resources. */
7814 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7816 /* Remove IMG from the hash table of its cache. */
7818 img
->prev
->next
= img
->next
;
7820 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
7823 img
->next
->prev
= img
->prev
;
7825 c
->images
[img
->id
] = NULL
;
7827 /* Free resources, then free IMG. */
7828 img
->type
->free (f
, img
);
7834 /* Prepare image IMG for display on frame F. Must be called before
7835 drawing an image. */
7838 prepare_image_for_display (f
, img
)
7844 /* We're about to display IMG, so set its timestamp to `now'. */
7846 img
->timestamp
= EMACS_SECS (t
);
7848 /* If IMG doesn't have a pixmap yet, load it now, using the image
7849 type dependent loader function. */
7850 if (img
->pixmap
== 0 && !img
->load_failed_p
)
7851 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
7855 /* Value is the number of pixels for the ascent of image IMG when
7856 drawn in face FACE. */
7859 image_ascent (img
, face
)
7863 int height
= img
->height
+ img
->margin
;
7866 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
7869 ascent
= height
/ 2 - (FONT_DESCENT(face
->font
)
7870 - FONT_BASE(face
->font
)) / 2;
7872 ascent
= height
/ 2;
7875 ascent
= height
* img
->ascent
/ 100.0;
7882 /***********************************************************************
7883 Helper functions for X image types
7884 ***********************************************************************/
7886 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
7887 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
7889 Lisp_Object color_name
,
7890 unsigned long dflt
));
7892 /* Free X resources of image IMG which is used on frame F. */
7895 x_clear_image (f
, img
)
7899 #if 0 /* TODO: W32 image support */
7904 XFreePixmap (NULL
, img
->pixmap
);
7911 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
7913 /* If display has an immutable color map, freeing colors is not
7914 necessary and some servers don't allow it. So don't do it. */
7915 if (class != StaticColor
7916 && class != StaticGray
7917 && class != TrueColor
)
7921 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
7922 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
7927 xfree (img
->colors
);
7935 /* Allocate color COLOR_NAME for image IMG on frame F. If color
7936 cannot be allocated, use DFLT. Add a newly allocated color to
7937 IMG->colors, so that it can be freed again. Value is the pixel
7940 static unsigned long
7941 x_alloc_image_color (f
, img
, color_name
, dflt
)
7944 Lisp_Object color_name
;
7947 #if 0 /* TODO: allocing colors. */
7949 unsigned long result
;
7951 xassert (STRINGP (color_name
));
7953 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
7955 /* This isn't called frequently so we get away with simply
7956 reallocating the color vector to the needed size, here. */
7959 (unsigned long *) xrealloc (img
->colors
,
7960 img
->ncolors
* sizeof *img
->colors
);
7961 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
7962 result
= color
.pixel
;
7973 /***********************************************************************
7975 ***********************************************************************/
7977 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
7980 /* Return a new, initialized image cache that is allocated from the
7981 heap. Call free_image_cache to free an image cache. */
7983 struct image_cache
*
7986 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
7989 bzero (c
, sizeof *c
);
7991 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
7992 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
7993 c
->buckets
= (struct image
**) xmalloc (size
);
7994 bzero (c
->buckets
, size
);
7999 /* Free image cache of frame F. Be aware that X frames share images
8003 free_image_cache (f
)
8006 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8011 /* Cache should not be referenced by any frame when freed. */
8012 xassert (c
->refcount
== 0);
8014 for (i
= 0; i
< c
->used
; ++i
)
8015 free_image (f
, c
->images
[i
]);
8019 FRAME_X_IMAGE_CACHE (f
) = NULL
;
8024 /* Clear image cache of frame F. FORCE_P non-zero means free all
8025 images. FORCE_P zero means clear only images that haven't been
8026 displayed for some time. Should be called from time to time to
8027 reduce the number of loaded images. If image-eviction-seconds is
8028 non-nil, this frees images in the cache which weren't displayed for
8029 at least that many seconds. */
8032 clear_image_cache (f
, force_p
)
8036 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8038 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
8042 int i
, any_freed_p
= 0;
8045 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
8047 for (i
= 0; i
< c
->used
; ++i
)
8049 struct image
*img
= c
->images
[i
];
8052 || (img
->timestamp
> old
)))
8054 free_image (f
, img
);
8059 /* We may be clearing the image cache because, for example,
8060 Emacs was iconified for a longer period of time. In that
8061 case, current matrices may still contain references to
8062 images freed above. So, clear these matrices. */
8065 clear_current_matrices (f
);
8066 ++windows_or_buffers_changed
;
8072 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
8074 "Clear the image cache of FRAME.\n\
8075 FRAME nil or omitted means use the selected frame.\n\
8076 FRAME t means clear the image caches of all frames.")
8084 FOR_EACH_FRAME (tail
, frame
)
8085 if (FRAME_W32_P (XFRAME (frame
)))
8086 clear_image_cache (XFRAME (frame
), 1);
8089 clear_image_cache (check_x_frame (frame
), 1);
8095 /* Return the id of image with Lisp specification SPEC on frame F.
8096 SPEC must be a valid Lisp image specification (see valid_image_p). */
8099 lookup_image (f
, spec
)
8103 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8107 struct gcpro gcpro1
;
8110 /* F must be a window-system frame, and SPEC must be a valid image
8112 xassert (FRAME_WINDOW_P (f
));
8113 xassert (valid_image_p (spec
));
8117 /* Look up SPEC in the hash table of the image cache. */
8118 hash
= sxhash (spec
, 0);
8119 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8121 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
8122 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
8125 /* If not found, create a new image and cache it. */
8128 img
= make_image (spec
, hash
);
8129 cache_image (f
, img
);
8130 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8131 xassert (!interrupt_input_blocked
);
8133 /* If we can't load the image, and we don't have a width and
8134 height, use some arbitrary width and height so that we can
8135 draw a rectangle for it. */
8136 if (img
->load_failed_p
)
8140 value
= image_spec_value (spec
, QCwidth
, NULL
);
8141 img
->width
= (INTEGERP (value
)
8142 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
8143 value
= image_spec_value (spec
, QCheight
, NULL
);
8144 img
->height
= (INTEGERP (value
)
8145 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
8149 /* Handle image type independent image attributes
8150 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF'. */
8151 Lisp_Object ascent
, margin
, relief
, algorithm
, heuristic_mask
;
8154 ascent
= image_spec_value (spec
, QCascent
, NULL
);
8155 if (INTEGERP (ascent
))
8156 img
->ascent
= XFASTINT (ascent
);
8157 else if (EQ (ascent
, Qcenter
))
8158 img
->ascent
= CENTERED_IMAGE_ASCENT
;
8160 margin
= image_spec_value (spec
, QCmargin
, NULL
);
8161 if (INTEGERP (margin
) && XINT (margin
) >= 0)
8162 img
->margin
= XFASTINT (margin
);
8164 relief
= image_spec_value (spec
, QCrelief
, NULL
);
8165 if (INTEGERP (relief
))
8167 img
->relief
= XINT (relief
);
8168 img
->margin
+= abs (img
->relief
);
8171 /* Should we apply a Laplace edge-detection algorithm? */
8172 algorithm
= image_spec_value (spec
, QCalgorithm
, NULL
);
8173 if (img
->pixmap
&& EQ (algorithm
, Qlaplace
))
8176 /* Should we built a mask heuristically? */
8177 heuristic_mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
8178 if (img
->pixmap
&& !img
->mask
&& !NILP (heuristic_mask
))
8179 x_build_heuristic_mask (f
, img
, heuristic_mask
);
8183 /* We're using IMG, so set its timestamp to `now'. */
8184 EMACS_GET_TIME (now
);
8185 img
->timestamp
= EMACS_SECS (now
);
8189 /* Value is the image id. */
8194 /* Cache image IMG in the image cache of frame F. */
8197 cache_image (f
, img
)
8201 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8204 /* Find a free slot in c->images. */
8205 for (i
= 0; i
< c
->used
; ++i
)
8206 if (c
->images
[i
] == NULL
)
8209 /* If no free slot found, maybe enlarge c->images. */
8210 if (i
== c
->used
&& c
->used
== c
->size
)
8213 c
->images
= (struct image
**) xrealloc (c
->images
,
8214 c
->size
* sizeof *c
->images
);
8217 /* Add IMG to c->images, and assign IMG an id. */
8223 /* Add IMG to the cache's hash table. */
8224 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8225 img
->next
= c
->buckets
[i
];
8227 img
->next
->prev
= img
;
8229 c
->buckets
[i
] = img
;
8233 /* Call FN on every image in the image cache of frame F. Used to mark
8234 Lisp Objects in the image cache. */
8237 forall_images_in_image_cache (f
, fn
)
8239 void (*fn
) P_ ((struct image
*img
));
8241 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
8243 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8247 for (i
= 0; i
< c
->used
; ++i
)
8256 /***********************************************************************
8258 ***********************************************************************/
8260 #if 0 /* TODO: W32 specific image code. */
8262 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
8263 XImage
**, Pixmap
*));
8264 static void x_destroy_x_image
P_ ((XImage
*));
8265 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
8268 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
8269 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
8270 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
8271 via xmalloc. Print error messages via image_error if an error
8272 occurs. Value is non-zero if successful. */
8275 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
8277 int width
, height
, depth
;
8281 #if 0 /* TODO: Image support for W32 */
8282 Display
*display
= FRAME_W32_DISPLAY (f
);
8283 Screen
*screen
= FRAME_X_SCREEN (f
);
8284 Window window
= FRAME_W32_WINDOW (f
);
8286 xassert (interrupt_input_blocked
);
8289 depth
= DefaultDepthOfScreen (screen
);
8290 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
8291 depth
, ZPixmap
, 0, NULL
, width
, height
,
8292 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
8295 image_error ("Unable to allocate X image", Qnil
, Qnil
);
8299 /* Allocate image raster. */
8300 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
8302 /* Allocate a pixmap of the same size. */
8303 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
8306 x_destroy_x_image (*ximg
);
8308 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
8316 /* Destroy XImage XIMG. Free XIMG->data. */
8319 x_destroy_x_image (ximg
)
8322 xassert (interrupt_input_blocked
);
8327 XDestroyImage (ximg
);
8332 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
8333 are width and height of both the image and pixmap. */
8336 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
8343 xassert (interrupt_input_blocked
);
8344 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
8345 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
8352 /***********************************************************************
8354 ***********************************************************************/
8356 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
8358 /* Find image file FILE. Look in data-directory, then
8359 x-bitmap-file-path. Value is the full name of the file found, or
8360 nil if not found. */
8363 x_find_image_file (file
)
8366 Lisp_Object file_found
, search_path
;
8367 struct gcpro gcpro1
, gcpro2
;
8371 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
8372 GCPRO2 (file_found
, search_path
);
8374 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
8375 fd
= openp (search_path
, file
, "", &file_found
, 0);
8388 /***********************************************************************
8390 ***********************************************************************/
8392 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
8393 static int xbm_load_image_from_file
P_ ((struct frame
*f
, struct image
*img
,
8395 static int xbm_image_p
P_ ((Lisp_Object object
));
8396 static int xbm_read_bitmap_file_data
P_ ((char *, int *, int *,
8400 /* Indices of image specification fields in xbm_format, below. */
8402 enum xbm_keyword_index
8419 /* Vector of image_keyword structures describing the format
8420 of valid XBM image specifications. */
8422 static struct image_keyword xbm_format
[XBM_LAST
] =
8424 {":type", IMAGE_SYMBOL_VALUE
, 1},
8425 {":file", IMAGE_STRING_VALUE
, 0},
8426 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8427 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8428 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8429 {":foreground", IMAGE_STRING_VALUE
, 0},
8430 {":background", IMAGE_STRING_VALUE
, 0},
8431 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
8432 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8433 {":relief", IMAGE_INTEGER_VALUE
, 0},
8434 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8435 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
8438 /* Structure describing the image type XBM. */
8440 static struct image_type xbm_type
=
8449 /* Tokens returned from xbm_scan. */
8458 /* Return non-zero if OBJECT is a valid XBM-type image specification.
8459 A valid specification is a list starting with the symbol `image'
8460 The rest of the list is a property list which must contain an
8463 If the specification specifies a file to load, it must contain
8464 an entry `:file FILENAME' where FILENAME is a string.
8466 If the specification is for a bitmap loaded from memory it must
8467 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
8468 WIDTH and HEIGHT are integers > 0. DATA may be:
8470 1. a string large enough to hold the bitmap data, i.e. it must
8471 have a size >= (WIDTH + 7) / 8 * HEIGHT
8473 2. a bool-vector of size >= WIDTH * HEIGHT
8475 3. a vector of strings or bool-vectors, one for each line of the
8478 Both the file and data forms may contain the additional entries
8479 `:background COLOR' and `:foreground COLOR'. If not present,
8480 foreground and background of the frame on which the image is
8481 displayed, is used. */
8484 xbm_image_p (object
)
8487 struct image_keyword kw
[XBM_LAST
];
8489 bcopy (xbm_format
, kw
, sizeof kw
);
8490 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
8493 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
8495 if (kw
[XBM_FILE
].count
)
8497 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
8505 /* Entries for `:width', `:height' and `:data' must be present. */
8506 if (!kw
[XBM_WIDTH
].count
8507 || !kw
[XBM_HEIGHT
].count
8508 || !kw
[XBM_DATA
].count
)
8511 data
= kw
[XBM_DATA
].value
;
8512 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
8513 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
8515 /* Check type of data, and width and height against contents of
8521 /* Number of elements of the vector must be >= height. */
8522 if (XVECTOR (data
)->size
< height
)
8525 /* Each string or bool-vector in data must be large enough
8526 for one line of the image. */
8527 for (i
= 0; i
< height
; ++i
)
8529 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
8533 if (XSTRING (elt
)->size
8534 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
8537 else if (BOOL_VECTOR_P (elt
))
8539 if (XBOOL_VECTOR (elt
)->size
< width
)
8546 else if (STRINGP (data
))
8548 if (XSTRING (data
)->size
8549 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
8552 else if (BOOL_VECTOR_P (data
))
8554 if (XBOOL_VECTOR (data
)->size
< width
* height
)
8561 /* Baseline must be a value between 0 and 100 (a percentage). */
8562 if (kw
[XBM_ASCENT
].count
8563 && XFASTINT (kw
[XBM_ASCENT
].value
) > 100)
8570 /* Scan a bitmap file. FP is the stream to read from. Value is
8571 either an enumerator from enum xbm_token, or a character for a
8572 single-character token, or 0 at end of file. If scanning an
8573 identifier, store the lexeme of the identifier in SVAL. If
8574 scanning a number, store its value in *IVAL. */
8577 xbm_scan (fp
, sval
, ival
)
8584 /* Skip white space. */
8585 while ((c
= fgetc (fp
)) != EOF
&& isspace (c
))
8590 else if (isdigit (c
))
8592 int value
= 0, digit
;
8597 if (c
== 'x' || c
== 'X')
8599 while ((c
= fgetc (fp
)) != EOF
)
8603 else if (c
>= 'a' && c
<= 'f')
8604 digit
= c
- 'a' + 10;
8605 else if (c
>= 'A' && c
<= 'F')
8606 digit
= c
- 'A' + 10;
8609 value
= 16 * value
+ digit
;
8612 else if (isdigit (c
))
8615 while ((c
= fgetc (fp
)) != EOF
8617 value
= 8 * value
+ c
- '0';
8623 while ((c
= fgetc (fp
)) != EOF
8625 value
= 10 * value
+ c
- '0';
8633 else if (isalpha (c
) || c
== '_')
8636 while ((c
= fgetc (fp
)) != EOF
8637 && (isalnum (c
) || c
== '_'))
8649 /* Replacement for XReadBitmapFileData which isn't available under old
8650 X versions. FILE is the name of the bitmap file to read. Set
8651 *WIDTH and *HEIGHT to the width and height of the image. Return in
8652 *DATA the bitmap data allocated with xmalloc. Value is non-zero if
8656 xbm_read_bitmap_file_data (file
, width
, height
, data
)
8658 int *width
, *height
;
8659 unsigned char **data
;
8662 char buffer
[BUFSIZ
];
8665 int bytes_per_line
, i
, nbytes
;
8671 LA1 = xbm_scan (fp, buffer, &value)
8673 #define expect(TOKEN) \
8674 if (LA1 != (TOKEN)) \
8679 #define expect_ident(IDENT) \
8680 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
8685 fp
= fopen (file
, "r");
8689 *width
= *height
= -1;
8691 LA1
= xbm_scan (fp
, buffer
, &value
);
8693 /* Parse defines for width, height and hot-spots. */
8697 expect_ident ("define");
8698 expect (XBM_TK_IDENT
);
8700 if (LA1
== XBM_TK_NUMBER
);
8702 char *p
= strrchr (buffer
, '_');
8703 p
= p
? p
+ 1 : buffer
;
8704 if (strcmp (p
, "width") == 0)
8706 else if (strcmp (p
, "height") == 0)
8709 expect (XBM_TK_NUMBER
);
8712 if (*width
< 0 || *height
< 0)
8715 /* Parse bits. Must start with `static'. */
8716 expect_ident ("static");
8717 if (LA1
== XBM_TK_IDENT
)
8719 if (strcmp (buffer
, "unsigned") == 0)
8722 expect_ident ("char");
8724 else if (strcmp (buffer
, "short") == 0)
8728 if (*width
% 16 && *width
% 16 < 9)
8731 else if (strcmp (buffer
, "char") == 0)
8739 expect (XBM_TK_IDENT
);
8745 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
8746 nbytes
= bytes_per_line
* *height
;
8747 p
= *data
= (char *) xmalloc (nbytes
);
8752 for (i
= 0; i
< nbytes
; i
+= 2)
8755 expect (XBM_TK_NUMBER
);
8758 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
8761 if (LA1
== ',' || LA1
== '}')
8769 for (i
= 0; i
< nbytes
; ++i
)
8772 expect (XBM_TK_NUMBER
);
8776 if (LA1
== ',' || LA1
== '}')
8802 /* Load XBM image IMG which will be displayed on frame F from file
8803 SPECIFIED_FILE. Value is non-zero if successful. */
8806 xbm_load_image_from_file (f
, img
, specified_file
)
8809 Lisp_Object specified_file
;
8812 unsigned char *data
;
8815 struct gcpro gcpro1
;
8817 xassert (STRINGP (specified_file
));
8821 file
= x_find_image_file (specified_file
);
8822 if (!STRINGP (file
))
8824 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8829 rc
= xbm_read_bitmap_file_data (XSTRING (file
)->data
, &img
->width
,
8830 &img
->height
, &data
);
8833 int depth
= one_w32_display_info
.n_cbits
;
8834 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
8835 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
8838 xassert (img
->width
> 0 && img
->height
> 0);
8840 /* Get foreground and background colors, maybe allocate colors. */
8841 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
8843 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
8845 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
8847 background
= x_alloc_image_color (f
, img
, value
, background
);
8849 #if 0 /* TODO : Port image display to W32 */
8852 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
8853 FRAME_W32_WINDOW (f
),
8855 img
->width
, img
->height
,
8856 foreground
, background
,
8860 if (img
->pixmap
== 0)
8862 x_clear_image (f
, img
);
8863 image_error ("Unable to create X pixmap for `%s'", file
, Qnil
);
8872 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
8879 /* Fill image IMG which is used on frame F with pixmap data. Value is
8880 non-zero if successful. */
8888 Lisp_Object file_name
;
8890 xassert (xbm_image_p (img
->spec
));
8892 /* If IMG->spec specifies a file name, create a non-file spec from it. */
8893 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
8894 if (STRINGP (file_name
))
8895 success_p
= xbm_load_image_from_file (f
, img
, file_name
);
8898 struct image_keyword fmt
[XBM_LAST
];
8901 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
8902 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
8906 /* Parse the list specification. */
8907 bcopy (xbm_format
, fmt
, sizeof fmt
);
8908 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
8911 /* Get specified width, and height. */
8912 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
8913 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
8914 xassert (img
->width
> 0 && img
->height
> 0);
8918 if (fmt
[XBM_ASCENT
].count
)
8919 img
->ascent
= XFASTINT (fmt
[XBM_ASCENT
].value
);
8921 /* Get foreground and background colors, maybe allocate colors. */
8922 if (fmt
[XBM_FOREGROUND
].count
)
8923 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
8925 if (fmt
[XBM_BACKGROUND
].count
)
8926 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
8929 /* Set bits to the bitmap image data. */
8930 data
= fmt
[XBM_DATA
].value
;
8935 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
8937 p
= bits
= (char *) alloca (nbytes
* img
->height
);
8938 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
8940 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
8942 bcopy (XSTRING (line
)->data
, p
, nbytes
);
8944 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
8947 else if (STRINGP (data
))
8948 bits
= XSTRING (data
)->data
;
8950 bits
= XBOOL_VECTOR (data
)->data
;
8952 #if 0 /* TODO : W32 XPM code */
8953 /* Create the pixmap. */
8954 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
8956 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
8957 FRAME_W32_WINDOW (f
),
8959 img
->width
, img
->height
,
8960 foreground
, background
,
8968 image_error ("Unable to create pixmap for XBM image `%s'",
8970 x_clear_image (f
, img
);
8981 /***********************************************************************
8983 ***********************************************************************/
8987 static int xpm_image_p
P_ ((Lisp_Object object
));
8988 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
8989 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
8991 #include "X11/xpm.h"
8993 /* The symbol `xpm' identifying XPM-format images. */
8997 /* Indices of image specification fields in xpm_format, below. */
8999 enum xpm_keyword_index
9013 /* Vector of image_keyword structures describing the format
9014 of valid XPM image specifications. */
9016 static struct image_keyword xpm_format
[XPM_LAST
] =
9018 {":type", IMAGE_SYMBOL_VALUE
, 1},
9019 {":file", IMAGE_STRING_VALUE
, 0},
9020 {":data", IMAGE_STRING_VALUE
, 0},
9021 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9022 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9023 {":relief", IMAGE_INTEGER_VALUE
, 0},
9024 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9025 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9026 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9029 /* Structure describing the image type XBM. */
9031 static struct image_type xpm_type
=
9041 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
9042 for XPM images. Such a list must consist of conses whose car and
9046 xpm_valid_color_symbols_p (color_symbols
)
9047 Lisp_Object color_symbols
;
9049 while (CONSP (color_symbols
))
9051 Lisp_Object sym
= XCAR (color_symbols
);
9053 || !STRINGP (XCAR (sym
))
9054 || !STRINGP (XCDR (sym
)))
9056 color_symbols
= XCDR (color_symbols
);
9059 return NILP (color_symbols
);
9063 /* Value is non-zero if OBJECT is a valid XPM image specification. */
9066 xpm_image_p (object
)
9069 struct image_keyword fmt
[XPM_LAST
];
9070 bcopy (xpm_format
, fmt
, sizeof fmt
);
9071 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
9072 /* Either `:file' or `:data' must be present. */
9073 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
9074 /* Either no `:color-symbols' or it's a list of conses
9075 whose car and cdr are strings. */
9076 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
9077 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
9078 && (fmt
[XPM_ASCENT
].count
== 0
9079 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
9083 /* Load image IMG which will be displayed on frame F. Value is
9084 non-zero if successful. */
9092 XpmAttributes attrs
;
9093 Lisp_Object specified_file
, color_symbols
;
9095 /* Configure the XPM lib. Use the visual of frame F. Allocate
9096 close colors. Return colors allocated. */
9097 bzero (&attrs
, sizeof attrs
);
9098 attrs
.visual
= FRAME_X_VISUAL (f
);
9099 attrs
.colormap
= FRAME_X_COLORMAP (f
);
9100 attrs
.valuemask
|= XpmVisual
;
9101 attrs
.valuemask
|= XpmColormap
;
9102 attrs
.valuemask
|= XpmReturnAllocPixels
;
9103 #ifdef XpmAllocCloseColors
9104 attrs
.alloc_close_colors
= 1;
9105 attrs
.valuemask
|= XpmAllocCloseColors
;
9107 attrs
.closeness
= 600;
9108 attrs
.valuemask
|= XpmCloseness
;
9111 /* If image specification contains symbolic color definitions, add
9112 these to `attrs'. */
9113 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
9114 if (CONSP (color_symbols
))
9117 XpmColorSymbol
*xpm_syms
;
9120 attrs
.valuemask
|= XpmColorSymbols
;
9122 /* Count number of symbols. */
9123 attrs
.numsymbols
= 0;
9124 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
9127 /* Allocate an XpmColorSymbol array. */
9128 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
9129 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
9130 bzero (xpm_syms
, size
);
9131 attrs
.colorsymbols
= xpm_syms
;
9133 /* Fill the color symbol array. */
9134 for (tail
= color_symbols
, i
= 0;
9136 ++i
, tail
= XCDR (tail
))
9138 Lisp_Object name
= XCAR (XCAR (tail
));
9139 Lisp_Object color
= XCDR (XCAR (tail
));
9140 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
9141 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
9142 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
9143 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
9147 /* Create a pixmap for the image, either from a file, or from a
9148 string buffer containing data in the same format as an XPM file. */
9150 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9151 if (STRINGP (specified_file
))
9153 Lisp_Object file
= x_find_image_file (specified_file
);
9154 if (!STRINGP (file
))
9156 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9161 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
9162 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
9167 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
9168 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
9169 XSTRING (buffer
)->data
,
9170 &img
->pixmap
, &img
->mask
,
9175 if (rc
== XpmSuccess
)
9177 /* Remember allocated colors. */
9178 img
->ncolors
= attrs
.nalloc_pixels
;
9179 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
9180 * sizeof *img
->colors
);
9181 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
9182 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
9184 img
->width
= attrs
.width
;
9185 img
->height
= attrs
.height
;
9186 xassert (img
->width
> 0 && img
->height
> 0);
9188 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
9190 XpmFreeAttributes (&attrs
);
9198 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
9201 case XpmFileInvalid
:
9202 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
9206 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
9209 case XpmColorFailed
:
9210 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
9214 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
9219 return rc
== XpmSuccess
;
9222 #endif /* HAVE_XPM != 0 */
9225 #if 0 /* TODO : Color tables on W32. */
9226 /***********************************************************************
9228 ***********************************************************************/
9230 /* An entry in the color table mapping an RGB color to a pixel color. */
9235 unsigned long pixel
;
9237 /* Next in color table collision list. */
9238 struct ct_color
*next
;
9241 /* The bucket vector size to use. Must be prime. */
9245 /* Value is a hash of the RGB color given by R, G, and B. */
9247 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
9249 /* The color hash table. */
9251 struct ct_color
**ct_table
;
9253 /* Number of entries in the color table. */
9255 int ct_colors_allocated
;
9257 /* Function prototypes. */
9259 static void init_color_table
P_ ((void));
9260 static void free_color_table
P_ ((void));
9261 static unsigned long *colors_in_color_table
P_ ((int *n
));
9262 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
9263 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
9266 /* Initialize the color table. */
9271 int size
= CT_SIZE
* sizeof (*ct_table
);
9272 ct_table
= (struct ct_color
**) xmalloc (size
);
9273 bzero (ct_table
, size
);
9274 ct_colors_allocated
= 0;
9278 /* Free memory associated with the color table. */
9284 struct ct_color
*p
, *next
;
9286 for (i
= 0; i
< CT_SIZE
; ++i
)
9287 for (p
= ct_table
[i
]; p
; p
= next
)
9298 /* Value is a pixel color for RGB color R, G, B on frame F. If an
9299 entry for that color already is in the color table, return the
9300 pixel color of that entry. Otherwise, allocate a new color for R,
9301 G, B, and make an entry in the color table. */
9303 static unsigned long
9304 lookup_rgb_color (f
, r
, g
, b
)
9308 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
9309 int i
= hash
% CT_SIZE
;
9312 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9313 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
9322 color
= PALETTERGB (r
, g
, b
);
9324 ++ct_colors_allocated
;
9326 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9331 p
->next
= ct_table
[i
];
9339 /* Look up pixel color PIXEL which is used on frame F in the color
9340 table. If not already present, allocate it. Value is PIXEL. */
9342 static unsigned long
9343 lookup_pixel_color (f
, pixel
)
9345 unsigned long pixel
;
9347 int i
= pixel
% CT_SIZE
;
9350 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9351 if (p
->pixel
== pixel
)
9362 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9363 color
.pixel
= pixel
;
9364 XQueryColor (NULL
, cmap
, &color
);
9365 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
9370 ++ct_colors_allocated
;
9372 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9377 p
->next
= ct_table
[i
];
9381 return FRAME_FOREGROUND_PIXEL (f
);
9387 /* Value is a vector of all pixel colors contained in the color table,
9388 allocated via xmalloc. Set *N to the number of colors. */
9390 static unsigned long *
9391 colors_in_color_table (n
)
9396 unsigned long *colors
;
9398 if (ct_colors_allocated
== 0)
9405 colors
= (unsigned long *) xmalloc (ct_colors_allocated
9407 *n
= ct_colors_allocated
;
9409 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
9410 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9411 colors
[j
++] = p
->pixel
;
9420 /***********************************************************************
9422 ***********************************************************************/
9424 #if 0 /* TODO : W32 versions of low level algorithms */
9425 static void x_laplace_write_row
P_ ((struct frame
*, long *,
9426 int, XImage
*, int));
9427 static void x_laplace_read_row
P_ ((struct frame
*, Colormap
,
9428 XColor
*, int, XImage
*, int));
9431 /* Fill COLORS with RGB colors from row Y of image XIMG. F is the
9432 frame we operate on, CMAP is the color-map in effect, and WIDTH is
9433 the width of one row in the image. */
9436 x_laplace_read_row (f
, cmap
, colors
, width
, ximg
, y
)
9446 for (x
= 0; x
< width
; ++x
)
9447 colors
[x
].pixel
= XGetPixel (ximg
, x
, y
);
9449 XQueryColors (NULL
, cmap
, colors
, width
);
9453 /* Write row Y of image XIMG. PIXELS is an array of WIDTH longs
9454 containing the pixel colors to write. F is the frame we are
9458 x_laplace_write_row (f
, pixels
, width
, ximg
, y
)
9467 for (x
= 0; x
< width
; ++x
)
9468 XPutPixel (ximg
, x
, y
, pixels
[x
]);
9472 /* Transform image IMG which is used on frame F with a Laplace
9473 edge-detection algorithm. The result is an image that can be used
9474 to draw disabled buttons, for example. */
9481 #if 0 /* TODO : W32 version */
9482 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9483 XImage
*ximg
, *oimg
;
9489 int in_y
, out_y
, rc
;
9494 /* Get the X image IMG->pixmap. */
9495 ximg
= XGetImage (NULL
, img
->pixmap
,
9496 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
9498 /* Allocate 3 input rows, and one output row of colors. */
9499 for (i
= 0; i
< 3; ++i
)
9500 in
[i
] = (XColor
*) alloca (img
->width
* sizeof (XColor
));
9501 out
= (long *) alloca (img
->width
* sizeof (long));
9503 /* Create an X image for output. */
9504 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
9507 /* Fill first two rows. */
9508 x_laplace_read_row (f
, cmap
, in
[0], img
->width
, ximg
, 0);
9509 x_laplace_read_row (f
, cmap
, in
[1], img
->width
, ximg
, 1);
9512 /* Write first row, all zeros. */
9513 init_color_table ();
9514 pixel
= lookup_rgb_color (f
, 0, 0, 0);
9515 for (x
= 0; x
< img
->width
; ++x
)
9517 x_laplace_write_row (f
, out
, img
->width
, oimg
, 0);
9520 for (y
= 2; y
< img
->height
; ++y
)
9523 int rowb
= (y
+ 2) % 3;
9525 x_laplace_read_row (f
, cmap
, in
[rowa
], img
->width
, ximg
, in_y
++);
9527 for (x
= 0; x
< img
->width
- 2; ++x
)
9529 int r
= in
[rowa
][x
].red
+ mv2
- in
[rowb
][x
+ 2].red
;
9530 int g
= in
[rowa
][x
].green
+ mv2
- in
[rowb
][x
+ 2].green
;
9531 int b
= in
[rowa
][x
].blue
+ mv2
- in
[rowb
][x
+ 2].blue
;
9533 out
[x
+ 1] = lookup_rgb_color (f
, r
& 0xffff, g
& 0xffff,
9537 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
++);
9540 /* Write last line, all zeros. */
9541 for (x
= 0; x
< img
->width
; ++x
)
9543 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
);
9545 /* Free the input image, and free resources of IMG. */
9546 XDestroyImage (ximg
);
9547 x_clear_image (f
, img
);
9549 /* Put the output image into pixmap, and destroy it. */
9550 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
9551 x_destroy_x_image (oimg
);
9553 /* Remember new pixmap and colors in IMG. */
9554 img
->pixmap
= pixmap
;
9555 img
->colors
= colors_in_color_table (&img
->ncolors
);
9556 free_color_table ();
9563 /* Build a mask for image IMG which is used on frame F. FILE is the
9564 name of an image file, for error messages. HOW determines how to
9565 determine the background color of IMG. If it is a list '(R G B)',
9566 with R, G, and B being integers >= 0, take that as the color of the
9567 background. Otherwise, determine the background color of IMG
9568 heuristically. Value is non-zero if successful. */
9571 x_build_heuristic_mask (f
, img
, how
)
9576 #if 0 /* TODO : W32 version */
9577 Display
*dpy
= FRAME_W32_DISPLAY (f
);
9578 XImage
*ximg
, *mask_img
;
9579 int x
, y
, rc
, look_at_corners_p
;
9584 /* Create an image and pixmap serving as mask. */
9585 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
9586 &mask_img
, &img
->mask
);
9593 /* Get the X image of IMG->pixmap. */
9594 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
9597 /* Determine the background color of ximg. If HOW is `(R G B)'
9598 take that as color. Otherwise, try to determine the color
9600 look_at_corners_p
= 1;
9608 && NATNUMP (XCAR (how
)))
9610 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
9614 if (i
== 3 && NILP (how
))
9616 char color_name
[30];
9617 XColor exact
, color
;
9620 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
9622 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9623 if (XLookupColor (dpy
, cmap
, color_name
, &exact
, &color
))
9626 look_at_corners_p
= 0;
9631 if (look_at_corners_p
)
9633 unsigned long corners
[4];
9636 /* Get the colors at the corners of ximg. */
9637 corners
[0] = XGetPixel (ximg
, 0, 0);
9638 corners
[1] = XGetPixel (ximg
, img
->width
- 1, 0);
9639 corners
[2] = XGetPixel (ximg
, img
->width
- 1, img
->height
- 1);
9640 corners
[3] = XGetPixel (ximg
, 0, img
->height
- 1);
9642 /* Choose the most frequently found color as background. */
9643 for (i
= best_count
= 0; i
< 4; ++i
)
9647 for (j
= n
= 0; j
< 4; ++j
)
9648 if (corners
[i
] == corners
[j
])
9652 bg
= corners
[i
], best_count
= n
;
9656 /* Set all bits in mask_img to 1 whose color in ximg is different
9657 from the background color bg. */
9658 for (y
= 0; y
< img
->height
; ++y
)
9659 for (x
= 0; x
< img
->width
; ++x
)
9660 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
9662 /* Put mask_img into img->mask. */
9663 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
9664 x_destroy_x_image (mask_img
);
9665 XDestroyImage (ximg
);
9675 /***********************************************************************
9676 PBM (mono, gray, color)
9677 ***********************************************************************/
9680 static int pbm_image_p
P_ ((Lisp_Object object
));
9681 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
9682 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
9684 /* The symbol `pbm' identifying images of this type. */
9688 /* Indices of image specification fields in gs_format, below. */
9690 enum pbm_keyword_index
9703 /* Vector of image_keyword structures describing the format
9704 of valid user-defined image specifications. */
9706 static struct image_keyword pbm_format
[PBM_LAST
] =
9708 {":type", IMAGE_SYMBOL_VALUE
, 1},
9709 {":file", IMAGE_STRING_VALUE
, 0},
9710 {":data", IMAGE_STRING_VALUE
, 0},
9711 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9712 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9713 {":relief", IMAGE_INTEGER_VALUE
, 0},
9714 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9715 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9718 /* Structure describing the image type `pbm'. */
9720 static struct image_type pbm_type
=
9730 /* Return non-zero if OBJECT is a valid PBM image specification. */
9733 pbm_image_p (object
)
9736 struct image_keyword fmt
[PBM_LAST
];
9738 bcopy (pbm_format
, fmt
, sizeof fmt
);
9740 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
9741 || (fmt
[PBM_ASCENT
].count
9742 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
9745 /* Must specify either :data or :file. */
9746 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
9750 /* Scan a decimal number from *S and return it. Advance *S while
9751 reading the number. END is the end of the string. Value is -1 at
9755 pbm_scan_number (s
, end
)
9756 unsigned char **s
, *end
;
9762 /* Skip white-space. */
9763 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
9768 /* Skip comment to end of line. */
9769 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
9772 else if (isdigit (c
))
9774 /* Read decimal number. */
9776 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
9777 val
= 10 * val
+ c
- '0';
9788 /* Read FILE into memory. Value is a pointer to a buffer allocated
9789 with xmalloc holding FILE's contents. Value is null if an error
9790 occured. *SIZE is set to the size of the file. */
9793 pbm_read_file (file
, size
)
9801 if (stat (XSTRING (file
)->data
, &st
) == 0
9802 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
9803 && (buf
= (char *) xmalloc (st
.st_size
),
9804 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
9824 /* Load PBM image IMG for use on frame F. */
9832 int width
, height
, max_color_idx
= 0;
9834 Lisp_Object file
, specified_file
;
9835 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
9836 struct gcpro gcpro1
;
9837 unsigned char *contents
= NULL
;
9838 unsigned char *end
, *p
;
9841 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9845 if (STRINGP (specified_file
))
9847 file
= x_find_image_file (specified_file
);
9848 if (!STRINGP (file
))
9850 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9855 contents
= pbm_read_file (file
, &size
);
9856 if (contents
== NULL
)
9858 image_error ("Error reading `%s'", file
, Qnil
);
9864 end
= contents
+ size
;
9869 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
9870 p
= XSTRING (data
)->data
;
9871 end
= p
+ STRING_BYTES (XSTRING (data
));
9874 /* Check magic number. */
9875 if (end
- p
< 2 || *p
++ != 'P')
9877 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
9887 raw_p
= 0, type
= PBM_MONO
;
9891 raw_p
= 0, type
= PBM_GRAY
;
9895 raw_p
= 0, type
= PBM_COLOR
;
9899 raw_p
= 1, type
= PBM_MONO
;
9903 raw_p
= 1, type
= PBM_GRAY
;
9907 raw_p
= 1, type
= PBM_COLOR
;
9911 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
9915 /* Read width, height, maximum color-component. Characters
9916 starting with `#' up to the end of a line are ignored. */
9917 width
= pbm_scan_number (&p
, end
);
9918 height
= pbm_scan_number (&p
, end
);
9920 if (type
!= PBM_MONO
)
9922 max_color_idx
= pbm_scan_number (&p
, end
);
9923 if (raw_p
&& max_color_idx
> 255)
9924 max_color_idx
= 255;
9929 || (type
!= PBM_MONO
&& max_color_idx
< 0))
9933 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
9934 &ximg
, &img
->pixmap
))
9940 /* Initialize the color hash table. */
9941 init_color_table ();
9943 if (type
== PBM_MONO
)
9947 for (y
= 0; y
< height
; ++y
)
9948 for (x
= 0; x
< width
; ++x
)
9958 g
= pbm_scan_number (&p
, end
);
9960 XPutPixel (ximg
, x
, y
, (g
9961 ? FRAME_FOREGROUND_PIXEL (f
)
9962 : FRAME_BACKGROUND_PIXEL (f
)));
9967 for (y
= 0; y
< height
; ++y
)
9968 for (x
= 0; x
< width
; ++x
)
9972 if (type
== PBM_GRAY
)
9973 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
9982 r
= pbm_scan_number (&p
, end
);
9983 g
= pbm_scan_number (&p
, end
);
9984 b
= pbm_scan_number (&p
, end
);
9987 if (r
< 0 || g
< 0 || b
< 0)
9991 XDestroyImage (ximg
);
9993 image_error ("Invalid pixel value in image `%s'",
9998 /* RGB values are now in the range 0..max_color_idx.
9999 Scale this to the range 0..0xffff supported by X. */
10000 r
= (double) r
* 65535 / max_color_idx
;
10001 g
= (double) g
* 65535 / max_color_idx
;
10002 b
= (double) b
* 65535 / max_color_idx
;
10003 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10007 /* Store in IMG->colors the colors allocated for the image, and
10008 free the color table. */
10009 img
->colors
= colors_in_color_table (&img
->ncolors
);
10010 free_color_table ();
10012 /* Put the image into a pixmap. */
10013 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10014 x_destroy_x_image (ximg
);
10017 img
->width
= width
;
10018 img
->height
= height
;
10024 #endif /* HAVE_PBM */
10027 /***********************************************************************
10029 ***********************************************************************/
10035 /* Function prototypes. */
10037 static int png_image_p
P_ ((Lisp_Object object
));
10038 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
10040 /* The symbol `png' identifying images of this type. */
10044 /* Indices of image specification fields in png_format, below. */
10046 enum png_keyword_index
10055 PNG_HEURISTIC_MASK
,
10059 /* Vector of image_keyword structures describing the format
10060 of valid user-defined image specifications. */
10062 static struct image_keyword png_format
[PNG_LAST
] =
10064 {":type", IMAGE_SYMBOL_VALUE
, 1},
10065 {":data", IMAGE_STRING_VALUE
, 0},
10066 {":file", IMAGE_STRING_VALUE
, 0},
10067 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10068 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10069 {":relief", IMAGE_INTEGER_VALUE
, 0},
10070 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10071 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10074 /* Structure describing the image type `png'. */
10076 static struct image_type png_type
=
10086 /* Return non-zero if OBJECT is a valid PNG image specification. */
10089 png_image_p (object
)
10090 Lisp_Object object
;
10092 struct image_keyword fmt
[PNG_LAST
];
10093 bcopy (png_format
, fmt
, sizeof fmt
);
10095 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
10096 || (fmt
[PNG_ASCENT
].count
10097 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
10100 /* Must specify either the :data or :file keyword. */
10101 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
10105 /* Error and warning handlers installed when the PNG library
10109 my_png_error (png_ptr
, msg
)
10110 png_struct
*png_ptr
;
10113 xassert (png_ptr
!= NULL
);
10114 image_error ("PNG error: %s", build_string (msg
), Qnil
);
10115 longjmp (png_ptr
->jmpbuf
, 1);
10120 my_png_warning (png_ptr
, msg
)
10121 png_struct
*png_ptr
;
10124 xassert (png_ptr
!= NULL
);
10125 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
10128 /* Memory source for PNG decoding. */
10130 struct png_memory_storage
10132 unsigned char *bytes
; /* The data */
10133 size_t len
; /* How big is it? */
10134 int index
; /* Where are we? */
10138 /* Function set as reader function when reading PNG image from memory.
10139 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
10140 bytes from the input to DATA. */
10143 png_read_from_memory (png_ptr
, data
, length
)
10144 png_structp png_ptr
;
10148 struct png_memory_storage
*tbr
10149 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
10151 if (length
> tbr
->len
- tbr
->index
)
10152 png_error (png_ptr
, "Read error");
10154 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
10155 tbr
->index
= tbr
->index
+ length
;
10158 /* Load PNG image IMG for use on frame F. Value is non-zero if
10166 Lisp_Object file
, specified_file
;
10167 Lisp_Object specified_data
;
10169 XImage
*ximg
, *mask_img
= NULL
;
10170 struct gcpro gcpro1
;
10171 png_struct
*png_ptr
= NULL
;
10172 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
10175 png_byte
*pixels
= NULL
;
10176 png_byte
**rows
= NULL
;
10177 png_uint_32 width
, height
;
10178 int bit_depth
, color_type
, interlace_type
;
10180 png_uint_32 row_bytes
;
10183 double screen_gamma
, image_gamma
;
10185 struct png_memory_storage tbr
; /* Data to be read */
10187 /* Find out what file to load. */
10188 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10189 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10193 if (NILP (specified_data
))
10195 file
= x_find_image_file (specified_file
);
10196 if (!STRINGP (file
))
10198 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10203 /* Open the image file. */
10204 fp
= fopen (XSTRING (file
)->data
, "rb");
10207 image_error ("Cannot open image file `%s'", file
, Qnil
);
10213 /* Check PNG signature. */
10214 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
10215 || !png_check_sig (sig
, sizeof sig
))
10217 image_error ("Not a PNG file:` %s'", file
, Qnil
);
10225 /* Read from memory. */
10226 tbr
.bytes
= XSTRING (specified_data
)->data
;
10227 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
10230 /* Check PNG signature. */
10231 if (tbr
.len
< sizeof sig
10232 || !png_check_sig (tbr
.bytes
, sizeof sig
))
10234 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
10239 /* Need to skip past the signature. */
10240 tbr
.bytes
+= sizeof (sig
);
10243 /* Initialize read and info structs for PNG lib. */
10244 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
10245 my_png_error
, my_png_warning
);
10248 if (fp
) fclose (fp
);
10253 info_ptr
= png_create_info_struct (png_ptr
);
10256 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
10257 if (fp
) fclose (fp
);
10262 end_info
= png_create_info_struct (png_ptr
);
10265 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
10266 if (fp
) fclose (fp
);
10271 /* Set error jump-back. We come back here when the PNG library
10272 detects an error. */
10273 if (setjmp (png_ptr
->jmpbuf
))
10277 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10280 if (fp
) fclose (fp
);
10285 /* Read image info. */
10286 if (!NILP (specified_data
))
10287 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
10289 png_init_io (png_ptr
, fp
);
10291 png_set_sig_bytes (png_ptr
, sizeof sig
);
10292 png_read_info (png_ptr
, info_ptr
);
10293 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
10294 &interlace_type
, NULL
, NULL
);
10296 /* If image contains simply transparency data, we prefer to
10297 construct a clipping mask. */
10298 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
10303 /* This function is easier to write if we only have to handle
10304 one data format: RGB or RGBA with 8 bits per channel. Let's
10305 transform other formats into that format. */
10307 /* Strip more than 8 bits per channel. */
10308 if (bit_depth
== 16)
10309 png_set_strip_16 (png_ptr
);
10311 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
10313 png_set_expand (png_ptr
);
10315 /* Convert grayscale images to RGB. */
10316 if (color_type
== PNG_COLOR_TYPE_GRAY
10317 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
10318 png_set_gray_to_rgb (png_ptr
);
10320 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
10321 gamma_str
= getenv ("SCREEN_GAMMA");
10322 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
10324 /* Tell the PNG lib to handle gamma correction for us. */
10326 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
10327 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
10328 /* There is a special chunk in the image specifying the gamma. */
10329 png_set_sRGB (png_ptr
, info_ptr
, intent
);
10332 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
10333 /* Image contains gamma information. */
10334 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
10336 /* Use a default of 0.5 for the image gamma. */
10337 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
10339 /* Handle alpha channel by combining the image with a background
10340 color. Do this only if a real alpha channel is supplied. For
10341 simple transparency, we prefer a clipping mask. */
10342 if (!transparent_p
)
10344 png_color_16
*image_background
;
10346 if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
10347 /* Image contains a background color with which to
10348 combine the image. */
10349 png_set_background (png_ptr
, image_background
,
10350 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
10353 /* Image does not contain a background color with which
10354 to combine the image data via an alpha channel. Use
10355 the frame's background instead. */
10358 png_color_16 frame_background
;
10361 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10362 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
10363 XQueryColor (FRAME_W32_DISPLAY (f
), cmap
, &color
);
10366 bzero (&frame_background
, sizeof frame_background
);
10367 frame_background
.red
= color
.red
;
10368 frame_background
.green
= color
.green
;
10369 frame_background
.blue
= color
.blue
;
10371 png_set_background (png_ptr
, &frame_background
,
10372 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
10376 /* Update info structure. */
10377 png_read_update_info (png_ptr
, info_ptr
);
10379 /* Get number of channels. Valid values are 1 for grayscale images
10380 and images with a palette, 2 for grayscale images with transparency
10381 information (alpha channel), 3 for RGB images, and 4 for RGB
10382 images with alpha channel, i.e. RGBA. If conversions above were
10383 sufficient we should only have 3 or 4 channels here. */
10384 channels
= png_get_channels (png_ptr
, info_ptr
);
10385 xassert (channels
== 3 || channels
== 4);
10387 /* Number of bytes needed for one row of the image. */
10388 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
10390 /* Allocate memory for the image. */
10391 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
10392 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
10393 for (i
= 0; i
< height
; ++i
)
10394 rows
[i
] = pixels
+ i
* row_bytes
;
10396 /* Read the entire image. */
10397 png_read_image (png_ptr
, rows
);
10398 png_read_end (png_ptr
, info_ptr
);
10407 /* Create the X image and pixmap. */
10408 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10415 /* Create an image and pixmap serving as mask if the PNG image
10416 contains an alpha channel. */
10419 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
10420 &mask_img
, &img
->mask
))
10422 x_destroy_x_image (ximg
);
10423 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
10429 /* Fill the X image and mask from PNG data. */
10430 init_color_table ();
10432 for (y
= 0; y
< height
; ++y
)
10434 png_byte
*p
= rows
[y
];
10436 for (x
= 0; x
< width
; ++x
)
10443 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10445 /* An alpha channel, aka mask channel, associates variable
10446 transparency with an image. Where other image formats
10447 support binary transparency---fully transparent or fully
10448 opaque---PNG allows up to 254 levels of partial transparency.
10449 The PNG library implements partial transparency by combining
10450 the image with a specified background color.
10452 I'm not sure how to handle this here nicely: because the
10453 background on which the image is displayed may change, for
10454 real alpha channel support, it would be necessary to create
10455 a new image for each possible background.
10457 What I'm doing now is that a mask is created if we have
10458 boolean transparency information. Otherwise I'm using
10459 the frame's background color to combine the image with. */
10464 XPutPixel (mask_img
, x
, y
, *p
> 0);
10470 /* Remember colors allocated for this image. */
10471 img
->colors
= colors_in_color_table (&img
->ncolors
);
10472 free_color_table ();
10475 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10479 img
->width
= width
;
10480 img
->height
= height
;
10482 /* Put the image into the pixmap, then free the X image and its buffer. */
10483 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10484 x_destroy_x_image (ximg
);
10486 /* Same for the mask. */
10489 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10490 x_destroy_x_image (mask_img
);
10498 #endif /* HAVE_PNG != 0 */
10502 /***********************************************************************
10504 ***********************************************************************/
10508 /* Work around a warning about HAVE_STDLIB_H being redefined in
10510 #ifdef HAVE_STDLIB_H
10511 #define HAVE_STDLIB_H_1
10512 #undef HAVE_STDLIB_H
10513 #endif /* HAVE_STLIB_H */
10515 #include <jpeglib.h>
10516 #include <jerror.h>
10517 #include <setjmp.h>
10519 #ifdef HAVE_STLIB_H_1
10520 #define HAVE_STDLIB_H 1
10523 static int jpeg_image_p
P_ ((Lisp_Object object
));
10524 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
10526 /* The symbol `jpeg' identifying images of this type. */
10530 /* Indices of image specification fields in gs_format, below. */
10532 enum jpeg_keyword_index
10541 JPEG_HEURISTIC_MASK
,
10545 /* Vector of image_keyword structures describing the format
10546 of valid user-defined image specifications. */
10548 static struct image_keyword jpeg_format
[JPEG_LAST
] =
10550 {":type", IMAGE_SYMBOL_VALUE
, 1},
10551 {":data", IMAGE_STRING_VALUE
, 0},
10552 {":file", IMAGE_STRING_VALUE
, 0},
10553 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10554 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10555 {":relief", IMAGE_INTEGER_VALUE
, 0},
10556 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10557 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10560 /* Structure describing the image type `jpeg'. */
10562 static struct image_type jpeg_type
=
10572 /* Return non-zero if OBJECT is a valid JPEG image specification. */
10575 jpeg_image_p (object
)
10576 Lisp_Object object
;
10578 struct image_keyword fmt
[JPEG_LAST
];
10580 bcopy (jpeg_format
, fmt
, sizeof fmt
);
10582 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
10583 || (fmt
[JPEG_ASCENT
].count
10584 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
10587 /* Must specify either the :data or :file keyword. */
10588 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
10592 struct my_jpeg_error_mgr
10594 struct jpeg_error_mgr pub
;
10595 jmp_buf setjmp_buffer
;
10599 my_error_exit (cinfo
)
10600 j_common_ptr cinfo
;
10602 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
10603 longjmp (mgr
->setjmp_buffer
, 1);
10606 /* Init source method for JPEG data source manager. Called by
10607 jpeg_read_header() before any data is actually read. See
10608 libjpeg.doc from the JPEG lib distribution. */
10611 our_init_source (cinfo
)
10612 j_decompress_ptr cinfo
;
10617 /* Fill input buffer method for JPEG data source manager. Called
10618 whenever more data is needed. We read the whole image in one step,
10619 so this only adds a fake end of input marker at the end. */
10622 our_fill_input_buffer (cinfo
)
10623 j_decompress_ptr cinfo
;
10625 /* Insert a fake EOI marker. */
10626 struct jpeg_source_mgr
*src
= cinfo
->src
;
10627 static JOCTET buffer
[2];
10629 buffer
[0] = (JOCTET
) 0xFF;
10630 buffer
[1] = (JOCTET
) JPEG_EOI
;
10632 src
->next_input_byte
= buffer
;
10633 src
->bytes_in_buffer
= 2;
10638 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
10639 is the JPEG data source manager. */
10642 our_skip_input_data (cinfo
, num_bytes
)
10643 j_decompress_ptr cinfo
;
10646 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10650 if (num_bytes
> src
->bytes_in_buffer
)
10651 ERREXIT (cinfo
, JERR_INPUT_EOF
);
10653 src
->bytes_in_buffer
-= num_bytes
;
10654 src
->next_input_byte
+= num_bytes
;
10659 /* Method to terminate data source. Called by
10660 jpeg_finish_decompress() after all data has been processed. */
10663 our_term_source (cinfo
)
10664 j_decompress_ptr cinfo
;
10669 /* Set up the JPEG lib for reading an image from DATA which contains
10670 LEN bytes. CINFO is the decompression info structure created for
10671 reading the image. */
10674 jpeg_memory_src (cinfo
, data
, len
)
10675 j_decompress_ptr cinfo
;
10679 struct jpeg_source_mgr
*src
;
10681 if (cinfo
->src
== NULL
)
10683 /* First time for this JPEG object? */
10684 cinfo
->src
= (struct jpeg_source_mgr
*)
10685 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
10686 sizeof (struct jpeg_source_mgr
));
10687 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10688 src
->next_input_byte
= data
;
10691 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10692 src
->init_source
= our_init_source
;
10693 src
->fill_input_buffer
= our_fill_input_buffer
;
10694 src
->skip_input_data
= our_skip_input_data
;
10695 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
10696 src
->term_source
= our_term_source
;
10697 src
->bytes_in_buffer
= len
;
10698 src
->next_input_byte
= data
;
10702 /* Load image IMG for use on frame F. Patterned after example.c
10703 from the JPEG lib. */
10710 struct jpeg_decompress_struct cinfo
;
10711 struct my_jpeg_error_mgr mgr
;
10712 Lisp_Object file
, specified_file
;
10713 Lisp_Object specified_data
;
10716 int row_stride
, x
, y
;
10717 XImage
*ximg
= NULL
;
10719 unsigned long *colors
;
10721 struct gcpro gcpro1
;
10723 /* Open the JPEG file. */
10724 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10725 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10729 if (NILP (specified_data
))
10731 file
= x_find_image_file (specified_file
);
10732 if (!STRINGP (file
))
10734 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10739 fp
= fopen (XSTRING (file
)->data
, "r");
10742 image_error ("Cannot open `%s'", file
, Qnil
);
10748 /* Customize libjpeg's error handling to call my_error_exit when an
10749 error is detected. This function will perform a longjmp. */
10750 mgr
.pub
.error_exit
= my_error_exit
;
10751 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
10753 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
10757 /* Called from my_error_exit. Display a JPEG error. */
10758 char buffer
[JMSG_LENGTH_MAX
];
10759 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
10760 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
10761 build_string (buffer
));
10764 /* Close the input file and destroy the JPEG object. */
10767 jpeg_destroy_decompress (&cinfo
);
10771 /* If we already have an XImage, free that. */
10772 x_destroy_x_image (ximg
);
10774 /* Free pixmap and colors. */
10775 x_clear_image (f
, img
);
10782 /* Create the JPEG decompression object. Let it read from fp.
10783 Read the JPEG image header. */
10784 jpeg_create_decompress (&cinfo
);
10786 if (NILP (specified_data
))
10787 jpeg_stdio_src (&cinfo
, fp
);
10789 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
10790 STRING_BYTES (XSTRING (specified_data
)));
10792 jpeg_read_header (&cinfo
, TRUE
);
10794 /* Customize decompression so that color quantization will be used.
10795 Start decompression. */
10796 cinfo
.quantize_colors
= TRUE
;
10797 jpeg_start_decompress (&cinfo
);
10798 width
= img
->width
= cinfo
.output_width
;
10799 height
= img
->height
= cinfo
.output_height
;
10803 /* Create X image and pixmap. */
10804 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10808 longjmp (mgr
.setjmp_buffer
, 2);
10811 /* Allocate colors. When color quantization is used,
10812 cinfo.actual_number_of_colors has been set with the number of
10813 colors generated, and cinfo.colormap is a two-dimensional array
10814 of color indices in the range 0..cinfo.actual_number_of_colors.
10815 No more than 255 colors will be generated. */
10819 if (cinfo
.out_color_components
> 2)
10820 ir
= 0, ig
= 1, ib
= 2;
10821 else if (cinfo
.out_color_components
> 1)
10822 ir
= 0, ig
= 1, ib
= 0;
10824 ir
= 0, ig
= 0, ib
= 0;
10826 /* Use the color table mechanism because it handles colors that
10827 cannot be allocated nicely. Such colors will be replaced with
10828 a default color, and we don't have to care about which colors
10829 can be freed safely, and which can't. */
10830 init_color_table ();
10831 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
10834 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
10836 /* Multiply RGB values with 255 because X expects RGB values
10837 in the range 0..0xffff. */
10838 int r
= cinfo
.colormap
[ir
][i
] << 8;
10839 int g
= cinfo
.colormap
[ig
][i
] << 8;
10840 int b
= cinfo
.colormap
[ib
][i
] << 8;
10841 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
10844 /* Remember those colors actually allocated. */
10845 img
->colors
= colors_in_color_table (&img
->ncolors
);
10846 free_color_table ();
10850 row_stride
= width
* cinfo
.output_components
;
10851 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
10853 for (y
= 0; y
< height
; ++y
)
10855 jpeg_read_scanlines (&cinfo
, buffer
, 1);
10856 for (x
= 0; x
< cinfo
.output_width
; ++x
)
10857 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
10861 jpeg_finish_decompress (&cinfo
);
10862 jpeg_destroy_decompress (&cinfo
);
10866 /* Put the image into the pixmap. */
10867 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10868 x_destroy_x_image (ximg
);
10874 #endif /* HAVE_JPEG */
10878 /***********************************************************************
10880 ***********************************************************************/
10884 #include <tiffio.h>
10886 static int tiff_image_p
P_ ((Lisp_Object object
));
10887 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
10889 /* The symbol `tiff' identifying images of this type. */
10893 /* Indices of image specification fields in tiff_format, below. */
10895 enum tiff_keyword_index
10904 TIFF_HEURISTIC_MASK
,
10908 /* Vector of image_keyword structures describing the format
10909 of valid user-defined image specifications. */
10911 static struct image_keyword tiff_format
[TIFF_LAST
] =
10913 {":type", IMAGE_SYMBOL_VALUE
, 1},
10914 {":data", IMAGE_STRING_VALUE
, 0},
10915 {":file", IMAGE_STRING_VALUE
, 0},
10916 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10917 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10918 {":relief", IMAGE_INTEGER_VALUE
, 0},
10919 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10920 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10923 /* Structure describing the image type `tiff'. */
10925 static struct image_type tiff_type
=
10935 /* Return non-zero if OBJECT is a valid TIFF image specification. */
10938 tiff_image_p (object
)
10939 Lisp_Object object
;
10941 struct image_keyword fmt
[TIFF_LAST
];
10942 bcopy (tiff_format
, fmt
, sizeof fmt
);
10944 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
10945 || (fmt
[TIFF_ASCENT
].count
10946 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
10949 /* Must specify either the :data or :file keyword. */
10950 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
10954 /* Reading from a memory buffer for TIFF images Based on the PNG
10955 memory source, but we have to provide a lot of extra functions.
10958 We really only need to implement read and seek, but I am not
10959 convinced that the TIFF library is smart enough not to destroy
10960 itself if we only hand it the function pointers we need to
10965 unsigned char *bytes
;
10969 tiff_memory_source
;
10972 tiff_read_from_memory (data
, buf
, size
)
10977 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
10979 if (size
> src
->len
- src
->index
)
10980 return (size_t) -1;
10981 bcopy (src
->bytes
+ src
->index
, buf
, size
);
10982 src
->index
+= size
;
10987 tiff_write_from_memory (data
, buf
, size
)
10992 return (size_t) -1;
10996 tiff_seek_in_memory (data
, off
, whence
)
11001 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11006 case SEEK_SET
: /* Go from beginning of source. */
11010 case SEEK_END
: /* Go from end of source. */
11011 idx
= src
->len
+ off
;
11014 case SEEK_CUR
: /* Go from current position. */
11015 idx
= src
->index
+ off
;
11018 default: /* Invalid `whence'. */
11022 if (idx
> src
->len
|| idx
< 0)
11030 tiff_close_memory (data
)
11038 tiff_mmap_memory (data
, pbase
, psize
)
11043 /* It is already _IN_ memory. */
11048 tiff_unmap_memory (data
, base
, size
)
11053 /* We don't need to do this. */
11057 tiff_size_of_memory (data
)
11060 return ((tiff_memory_source
*) data
)->len
;
11063 /* Load TIFF image IMG for use on frame F. Value is non-zero if
11071 Lisp_Object file
, specified_file
;
11072 Lisp_Object specified_data
;
11074 int width
, height
, x
, y
;
11078 struct gcpro gcpro1
;
11079 tiff_memory_source memsrc
;
11081 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11082 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11086 if (NILP (specified_data
))
11088 /* Read from a file */
11089 file
= x_find_image_file (specified_file
);
11090 if (!STRINGP (file
))
11092 image_error ("Cannot find image file `%s'", file
, Qnil
);
11097 /* Try to open the image file. */
11098 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
11101 image_error ("Cannot open `%s'", file
, Qnil
);
11108 /* Memory source! */
11109 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11110 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11113 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
11114 (TIFFReadWriteProc
) tiff_read_from_memory
,
11115 (TIFFReadWriteProc
) tiff_write_from_memory
,
11116 tiff_seek_in_memory
,
11118 tiff_size_of_memory
,
11120 tiff_unmap_memory
);
11124 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
11130 /* Get width and height of the image, and allocate a raster buffer
11131 of width x height 32-bit values. */
11132 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
11133 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
11134 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
11136 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
11140 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
11148 /* Create the X image and pixmap. */
11149 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11157 /* Initialize the color table. */
11158 init_color_table ();
11160 /* Process the pixel raster. Origin is in the lower-left corner. */
11161 for (y
= 0; y
< height
; ++y
)
11163 uint32
*row
= buf
+ y
* width
;
11165 for (x
= 0; x
< width
; ++x
)
11167 uint32 abgr
= row
[x
];
11168 int r
= TIFFGetR (abgr
) << 8;
11169 int g
= TIFFGetG (abgr
) << 8;
11170 int b
= TIFFGetB (abgr
) << 8;
11171 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
11175 /* Remember the colors allocated for the image. Free the color table. */
11176 img
->colors
= colors_in_color_table (&img
->ncolors
);
11177 free_color_table ();
11179 /* Put the image into the pixmap, then free the X image and its buffer. */
11180 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11181 x_destroy_x_image (ximg
);
11185 img
->width
= width
;
11186 img
->height
= height
;
11192 #endif /* HAVE_TIFF != 0 */
11196 /***********************************************************************
11198 ***********************************************************************/
11202 #include <gif_lib.h>
11204 static int gif_image_p
P_ ((Lisp_Object object
));
11205 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
11207 /* The symbol `gif' identifying images of this type. */
11211 /* Indices of image specification fields in gif_format, below. */
11213 enum gif_keyword_index
11222 GIF_HEURISTIC_MASK
,
11227 /* Vector of image_keyword structures describing the format
11228 of valid user-defined image specifications. */
11230 static struct image_keyword gif_format
[GIF_LAST
] =
11232 {":type", IMAGE_SYMBOL_VALUE
, 1},
11233 {":data", IMAGE_STRING_VALUE
, 0},
11234 {":file", IMAGE_STRING_VALUE
, 0},
11235 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11236 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11237 {":relief", IMAGE_INTEGER_VALUE
, 0},
11238 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11239 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11240 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0}
11243 /* Structure describing the image type `gif'. */
11245 static struct image_type gif_type
=
11254 /* Return non-zero if OBJECT is a valid GIF image specification. */
11257 gif_image_p (object
)
11258 Lisp_Object object
;
11260 struct image_keyword fmt
[GIF_LAST
];
11261 bcopy (gif_format
, fmt
, sizeof fmt
);
11263 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
11264 || (fmt
[GIF_ASCENT
].count
11265 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
11268 /* Must specify either the :data or :file keyword. */
11269 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
11272 /* Reading a GIF image from memory
11273 Based on the PNG memory stuff to a certain extent. */
11277 unsigned char *bytes
;
11283 /* Make the current memory source available to gif_read_from_memory.
11284 It's done this way because not all versions of libungif support
11285 a UserData field in the GifFileType structure. */
11286 static gif_memory_source
*current_gif_memory_src
;
11289 gif_read_from_memory (file
, buf
, len
)
11294 gif_memory_source
*src
= current_gif_memory_src
;
11296 if (len
> src
->len
- src
->index
)
11299 bcopy (src
->bytes
+ src
->index
, buf
, len
);
11305 /* Load GIF image IMG for use on frame F. Value is non-zero if
11313 Lisp_Object file
, specified_file
;
11314 Lisp_Object specified_data
;
11315 int rc
, width
, height
, x
, y
, i
;
11317 ColorMapObject
*gif_color_map
;
11318 unsigned long pixel_colors
[256];
11320 struct gcpro gcpro1
;
11322 int ino
, image_left
, image_top
, image_width
, image_height
;
11323 gif_memory_source memsrc
;
11324 unsigned char *raster
;
11326 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11327 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11331 if (NILP (specified_data
))
11333 file
= x_find_image_file (specified_file
);
11334 if (!STRINGP (file
))
11336 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11341 /* Open the GIF file. */
11342 gif
= DGifOpenFileName (XSTRING (file
)->data
);
11345 image_error ("Cannot open `%s'", file
, Qnil
);
11352 /* Read from memory! */
11353 current_gif_memory_src
= &memsrc
;
11354 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11355 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11358 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
11361 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
11367 /* Read entire contents. */
11368 rc
= DGifSlurp (gif
);
11369 if (rc
== GIF_ERROR
)
11371 image_error ("Error reading `%s'", img
->spec
, Qnil
);
11372 DGifCloseFile (gif
);
11377 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
11378 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
11379 if (ino
>= gif
->ImageCount
)
11381 image_error ("Invalid image number `%s' in image `%s'",
11383 DGifCloseFile (gif
);
11388 width
= img
->width
= gif
->SWidth
;
11389 height
= img
->height
= gif
->SHeight
;
11393 /* Create the X image and pixmap. */
11394 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11397 DGifCloseFile (gif
);
11402 /* Allocate colors. */
11403 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
11404 if (!gif_color_map
)
11405 gif_color_map
= gif
->SColorMap
;
11406 init_color_table ();
11407 bzero (pixel_colors
, sizeof pixel_colors
);
11409 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
11411 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
11412 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
11413 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
11414 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11417 img
->colors
= colors_in_color_table (&img
->ncolors
);
11418 free_color_table ();
11420 /* Clear the part of the screen image that are not covered by
11421 the image from the GIF file. Full animated GIF support
11422 requires more than can be done here (see the gif89 spec,
11423 disposal methods). Let's simply assume that the part
11424 not covered by a sub-image is in the frame's background color. */
11425 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
11426 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
11427 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
11428 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
11430 for (y
= 0; y
< image_top
; ++y
)
11431 for (x
= 0; x
< width
; ++x
)
11432 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11434 for (y
= image_top
+ image_height
; y
< height
; ++y
)
11435 for (x
= 0; x
< width
; ++x
)
11436 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11438 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
11440 for (x
= 0; x
< image_left
; ++x
)
11441 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11442 for (x
= image_left
+ image_width
; x
< width
; ++x
)
11443 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11446 /* Read the GIF image into the X image. We use a local variable
11447 `raster' here because RasterBits below is a char *, and invites
11448 problems with bytes >= 0x80. */
11449 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
11451 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
11453 static int interlace_start
[] = {0, 4, 2, 1};
11454 static int interlace_increment
[] = {8, 8, 4, 2};
11456 int row
= interlace_start
[0];
11460 for (y
= 0; y
< image_height
; y
++)
11462 if (row
>= image_height
)
11464 row
= interlace_start
[++pass
];
11465 while (row
>= image_height
)
11466 row
= interlace_start
[++pass
];
11469 for (x
= 0; x
< image_width
; x
++)
11471 int i
= raster
[(y
* image_width
) + x
];
11472 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
11476 row
+= interlace_increment
[pass
];
11481 for (y
= 0; y
< image_height
; ++y
)
11482 for (x
= 0; x
< image_width
; ++x
)
11484 int i
= raster
[y
* image_width
+ x
];
11485 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
11489 DGifCloseFile (gif
);
11491 /* Put the image into the pixmap, then free the X image and its buffer. */
11492 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11493 x_destroy_x_image (ximg
);
11500 #endif /* HAVE_GIF != 0 */
11504 /***********************************************************************
11506 ***********************************************************************/
11508 #ifdef HAVE_GHOSTSCRIPT
11509 static int gs_image_p
P_ ((Lisp_Object object
));
11510 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
11511 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
11513 /* The symbol `postscript' identifying images of this type. */
11515 Lisp_Object Qpostscript
;
11517 /* Keyword symbols. */
11519 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
11521 /* Indices of image specification fields in gs_format, below. */
11523 enum gs_keyword_index
11539 /* Vector of image_keyword structures describing the format
11540 of valid user-defined image specifications. */
11542 static struct image_keyword gs_format
[GS_LAST
] =
11544 {":type", IMAGE_SYMBOL_VALUE
, 1},
11545 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11546 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11547 {":file", IMAGE_STRING_VALUE
, 1},
11548 {":loader", IMAGE_FUNCTION_VALUE
, 0},
11549 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
11550 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11551 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11552 {":relief", IMAGE_INTEGER_VALUE
, 0},
11553 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11554 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11557 /* Structure describing the image type `ghostscript'. */
11559 static struct image_type gs_type
=
11569 /* Free X resources of Ghostscript image IMG which is used on frame F. */
11572 gs_clear_image (f
, img
)
11576 /* IMG->data.ptr_val may contain a recorded colormap. */
11577 xfree (img
->data
.ptr_val
);
11578 x_clear_image (f
, img
);
11582 /* Return non-zero if OBJECT is a valid Ghostscript image
11586 gs_image_p (object
)
11587 Lisp_Object object
;
11589 struct image_keyword fmt
[GS_LAST
];
11593 bcopy (gs_format
, fmt
, sizeof fmt
);
11595 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
11596 || (fmt
[GS_ASCENT
].count
11597 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
11600 /* Bounding box must be a list or vector containing 4 integers. */
11601 tem
= fmt
[GS_BOUNDING_BOX
].value
;
11604 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
11605 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
11610 else if (VECTORP (tem
))
11612 if (XVECTOR (tem
)->size
!= 4)
11614 for (i
= 0; i
< 4; ++i
)
11615 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
11625 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
11634 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
11635 struct gcpro gcpro1
, gcpro2
;
11637 double in_width
, in_height
;
11638 Lisp_Object pixel_colors
= Qnil
;
11640 /* Compute pixel size of pixmap needed from the given size in the
11641 image specification. Sizes in the specification are in pt. 1 pt
11642 = 1/72 in, xdpi and ydpi are stored in the frame's X display
11644 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
11645 in_width
= XFASTINT (pt_width
) / 72.0;
11646 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
11647 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
11648 in_height
= XFASTINT (pt_height
) / 72.0;
11649 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
11651 /* Create the pixmap. */
11653 xassert (img
->pixmap
== 0);
11654 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11655 img
->width
, img
->height
,
11656 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
11661 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
11665 /* Call the loader to fill the pixmap. It returns a process object
11666 if successful. We do not record_unwind_protect here because
11667 other places in redisplay like calling window scroll functions
11668 don't either. Let the Lisp loader use `unwind-protect' instead. */
11669 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
11671 sprintf (buffer
, "%lu %lu",
11672 (unsigned long) FRAME_W32_WINDOW (f
),
11673 (unsigned long) img
->pixmap
);
11674 window_and_pixmap_id
= build_string (buffer
);
11676 sprintf (buffer
, "%lu %lu",
11677 FRAME_FOREGROUND_PIXEL (f
),
11678 FRAME_BACKGROUND_PIXEL (f
));
11679 pixel_colors
= build_string (buffer
);
11681 XSETFRAME (frame
, f
);
11682 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
11684 loader
= intern ("gs-load-image");
11686 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
11687 make_number (img
->width
),
11688 make_number (img
->height
),
11689 window_and_pixmap_id
,
11692 return PROCESSP (img
->data
.lisp_val
);
11696 /* Kill the Ghostscript process that was started to fill PIXMAP on
11697 frame F. Called from XTread_socket when receiving an event
11698 telling Emacs that Ghostscript has finished drawing. */
11701 x_kill_gs_process (pixmap
, f
)
11705 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
11709 /* Find the image containing PIXMAP. */
11710 for (i
= 0; i
< c
->used
; ++i
)
11711 if (c
->images
[i
]->pixmap
== pixmap
)
11714 /* Kill the GS process. We should have found PIXMAP in the image
11715 cache and its image should contain a process object. */
11716 xassert (i
< c
->used
);
11717 img
= c
->images
[i
];
11718 xassert (PROCESSP (img
->data
.lisp_val
));
11719 Fkill_process (img
->data
.lisp_val
, Qnil
);
11720 img
->data
.lisp_val
= Qnil
;
11722 /* On displays with a mutable colormap, figure out the colors
11723 allocated for the image by looking at the pixels of an XImage for
11725 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
11726 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
11732 /* Try to get an XImage for img->pixmep. */
11733 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
11734 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
11739 /* Initialize the color table. */
11740 init_color_table ();
11742 /* For each pixel of the image, look its color up in the
11743 color table. After having done so, the color table will
11744 contain an entry for each color used by the image. */
11745 for (y
= 0; y
< img
->height
; ++y
)
11746 for (x
= 0; x
< img
->width
; ++x
)
11748 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
11749 lookup_pixel_color (f
, pixel
);
11752 /* Record colors in the image. Free color table and XImage. */
11753 img
->colors
= colors_in_color_table (&img
->ncolors
);
11754 free_color_table ();
11755 XDestroyImage (ximg
);
11757 #if 0 /* This doesn't seem to be the case. If we free the colors
11758 here, we get a BadAccess later in x_clear_image when
11759 freeing the colors. */
11760 /* We have allocated colors once, but Ghostscript has also
11761 allocated colors on behalf of us. So, to get the
11762 reference counts right, free them once. */
11765 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
11766 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
,
11767 img
->colors
, img
->ncolors
, 0);
11772 image_error ("Cannot get X image of `%s'; colors will not be freed",
11779 #endif /* HAVE_GHOSTSCRIPT */
11782 /***********************************************************************
11784 ***********************************************************************/
11786 DEFUN ("x-change-window-property", Fx_change_window_property
,
11787 Sx_change_window_property
, 2, 3, 0,
11788 "Change window property PROP to VALUE on the X window of FRAME.\n\
11789 PROP and VALUE must be strings. FRAME nil or omitted means use the\n\
11790 selected frame. Value is VALUE.")
11791 (prop
, value
, frame
)
11792 Lisp_Object frame
, prop
, value
;
11794 #if 0 /* TODO : port window properties to W32 */
11795 struct frame
*f
= check_x_frame (frame
);
11798 CHECK_STRING (prop
, 1);
11799 CHECK_STRING (value
, 2);
11802 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11803 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11804 prop_atom
, XA_STRING
, 8, PropModeReplace
,
11805 XSTRING (value
)->data
, XSTRING (value
)->size
);
11807 /* Make sure the property is set when we return. */
11808 XFlush (FRAME_W32_DISPLAY (f
));
11817 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
11818 Sx_delete_window_property
, 1, 2, 0,
11819 "Remove window property PROP from X window of FRAME.\n\
11820 FRAME nil or omitted means use the selected frame. Value is PROP.")
11822 Lisp_Object prop
, frame
;
11824 #if 0 /* TODO : port window properties to W32 */
11826 struct frame
*f
= check_x_frame (frame
);
11829 CHECK_STRING (prop
, 1);
11831 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11832 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
11834 /* Make sure the property is removed when we return. */
11835 XFlush (FRAME_W32_DISPLAY (f
));
11843 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
11845 "Value is the value of window property PROP on FRAME.\n\
11846 If FRAME is nil or omitted, use the selected frame. Value is nil\n\
11847 if FRAME hasn't a property with name PROP or if PROP has no string\n\
11850 Lisp_Object prop
, frame
;
11852 #if 0 /* TODO : port window properties to W32 */
11854 struct frame
*f
= check_x_frame (frame
);
11857 Lisp_Object prop_value
= Qnil
;
11858 char *tmp_data
= NULL
;
11861 unsigned long actual_size
, bytes_remaining
;
11863 CHECK_STRING (prop
, 1);
11865 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11866 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11867 prop_atom
, 0, 0, False
, XA_STRING
,
11868 &actual_type
, &actual_format
, &actual_size
,
11869 &bytes_remaining
, (unsigned char **) &tmp_data
);
11872 int size
= bytes_remaining
;
11877 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11878 prop_atom
, 0, bytes_remaining
,
11880 &actual_type
, &actual_format
,
11881 &actual_size
, &bytes_remaining
,
11882 (unsigned char **) &tmp_data
);
11884 prop_value
= make_string (tmp_data
, size
);
11899 /***********************************************************************
11901 ***********************************************************************/
11903 /* If non-null, an asynchronous timer that, when it expires, displays
11904 a busy cursor on all frames. */
11906 static struct atimer
*busy_cursor_atimer
;
11908 /* Non-zero means a busy cursor is currently shown. */
11910 static int busy_cursor_shown_p
;
11912 /* Number of seconds to wait before displaying a busy cursor. */
11914 static Lisp_Object Vbusy_cursor_delay
;
11916 /* Default number of seconds to wait before displaying a busy
11919 #define DEFAULT_BUSY_CURSOR_DELAY 1
11921 /* Function prototypes. */
11923 static void show_busy_cursor
P_ ((struct atimer
*));
11924 static void hide_busy_cursor
P_ ((void));
11927 /* Cancel a currently active busy-cursor timer, and start a new one. */
11930 start_busy_cursor ()
11932 #if 0 /* TODO: cursor shape changes. */
11934 int secs
, usecs
= 0;
11936 cancel_busy_cursor ();
11938 if (INTEGERP (Vbusy_cursor_delay
)
11939 && XINT (Vbusy_cursor_delay
) > 0)
11940 secs
= XFASTINT (Vbusy_cursor_delay
);
11941 else if (FLOATP (Vbusy_cursor_delay
)
11942 && XFLOAT_DATA (Vbusy_cursor_delay
) > 0)
11945 tem
= Ftruncate (Vbusy_cursor_delay
, Qnil
);
11946 secs
= XFASTINT (tem
);
11947 usecs
= (XFLOAT_DATA (Vbusy_cursor_delay
) - secs
) * 1000000;
11950 secs
= DEFAULT_BUSY_CURSOR_DELAY
;
11952 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
11953 busy_cursor_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
11954 show_busy_cursor
, NULL
);
11959 /* Cancel the busy cursor timer if active, hide a busy cursor if
11963 cancel_busy_cursor ()
11965 if (busy_cursor_atimer
)
11967 cancel_atimer (busy_cursor_atimer
);
11968 busy_cursor_atimer
= NULL
;
11971 if (busy_cursor_shown_p
)
11972 hide_busy_cursor ();
11976 /* Timer function of busy_cursor_atimer. TIMER is equal to
11977 busy_cursor_atimer.
11979 Display a busy cursor on all frames by mapping the frames'
11980 busy_window. Set the busy_p flag in the frames' output_data.x
11981 structure to indicate that a busy cursor is shown on the
11985 show_busy_cursor (timer
)
11986 struct atimer
*timer
;
11988 #if 0 /* TODO: cursor shape changes. */
11989 /* The timer implementation will cancel this timer automatically
11990 after this function has run. Set busy_cursor_atimer to null
11991 so that we know the timer doesn't have to be canceled. */
11992 busy_cursor_atimer
= NULL
;
11994 if (!busy_cursor_shown_p
)
11996 Lisp_Object rest
, frame
;
12000 FOR_EACH_FRAME (rest
, frame
)
12001 if (FRAME_X_P (XFRAME (frame
)))
12003 struct frame
*f
= XFRAME (frame
);
12005 f
->output_data
.w32
->busy_p
= 1;
12007 if (!f
->output_data
.w32
->busy_window
)
12009 unsigned long mask
= CWCursor
;
12010 XSetWindowAttributes attrs
;
12012 attrs
.cursor
= f
->output_data
.w32
->busy_cursor
;
12014 f
->output_data
.w32
->busy_window
12015 = XCreateWindow (FRAME_X_DISPLAY (f
),
12016 FRAME_OUTER_WINDOW (f
),
12017 0, 0, 32000, 32000, 0, 0,
12023 XMapRaised (FRAME_X_DISPLAY (f
), f
->output_data
.w32
->busy_window
);
12024 XFlush (FRAME_X_DISPLAY (f
));
12027 busy_cursor_shown_p
= 1;
12034 /* Hide the busy cursor on all frames, if it is currently shown. */
12037 hide_busy_cursor ()
12039 #if 0 /* TODO: cursor shape changes. */
12040 if (busy_cursor_shown_p
)
12042 Lisp_Object rest
, frame
;
12045 FOR_EACH_FRAME (rest
, frame
)
12047 struct frame
*f
= XFRAME (frame
);
12050 /* Watch out for newly created frames. */
12051 && f
->output_data
.x
->busy_window
)
12053 XUnmapWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->busy_window
);
12054 /* Sync here because XTread_socket looks at the busy_p flag
12055 that is reset to zero below. */
12056 XSync (FRAME_X_DISPLAY (f
), False
);
12057 f
->output_data
.x
->busy_p
= 0;
12061 busy_cursor_shown_p
= 0;
12069 /***********************************************************************
12071 ***********************************************************************/
12073 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
12076 /* The frame of a currently visible tooltip, or null. */
12078 struct frame
*tip_frame
;
12080 /* If non-nil, a timer started that hides the last tooltip when it
12083 Lisp_Object tip_timer
;
12086 /* Create a frame for a tooltip on the display described by DPYINFO.
12087 PARMS is a list of frame parameters. Value is the frame. */
12090 x_create_tip_frame (dpyinfo
, parms
)
12091 struct w32_display_info
*dpyinfo
;
12094 #if 0 /* TODO : w32 version */
12096 Lisp_Object frame
, tem
;
12098 long window_prompting
= 0;
12100 int count
= specpdl_ptr
- specpdl
;
12101 struct gcpro gcpro1
, gcpro2
, gcpro3
;
12106 /* Use this general default value to start with until we know if
12107 this frame has a specified name. */
12108 Vx_resource_name
= Vinvocation_name
;
12110 #ifdef MULTI_KBOARD
12111 kb
= dpyinfo
->kboard
;
12113 kb
= &the_only_kboard
;
12116 /* Get the name of the frame to use for resource lookup. */
12117 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
12118 if (!STRINGP (name
)
12119 && !EQ (name
, Qunbound
)
12121 error ("Invalid frame name--not a string or nil");
12122 Vx_resource_name
= name
;
12125 GCPRO3 (parms
, name
, frame
);
12126 tip_frame
= f
= make_frame (1);
12127 XSETFRAME (frame
, f
);
12128 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
12130 f
->output_method
= output_w32
;
12131 f
->output_data
.w32
=
12132 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
12133 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
12135 f
->output_data
.w32
->icon_bitmap
= -1;
12137 f
->output_data
.w32
->fontset
= -1;
12138 f
->icon_name
= Qnil
;
12140 #ifdef MULTI_KBOARD
12141 FRAME_KBOARD (f
) = kb
;
12143 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12144 f
->output_data
.w32
->explicit_parent
= 0;
12146 /* Set the name; the functions to which we pass f expect the name to
12148 if (EQ (name
, Qunbound
) || NILP (name
))
12150 f
->name
= build_string (dpyinfo
->x_id_name
);
12151 f
->explicit_name
= 0;
12156 f
->explicit_name
= 1;
12157 /* use the frame's title when getting resources for this frame. */
12158 specbind (Qx_resource_name
, name
);
12161 /* Extract the window parameters from the supplied values
12162 that are needed to determine window geometry. */
12166 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
12169 /* First, try whatever font the caller has specified. */
12170 if (STRINGP (font
))
12172 tem
= Fquery_fontset (font
, Qnil
);
12174 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
12176 font
= x_new_font (f
, XSTRING (font
)->data
);
12179 /* Try out a font which we hope has bold and italic variations. */
12180 if (!STRINGP (font
))
12181 font
= x_new_font (f
, "-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
12182 if (!STRINGP (font
))
12183 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12184 if (! STRINGP (font
))
12185 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12186 if (! STRINGP (font
))
12187 /* This was formerly the first thing tried, but it finds too many fonts
12188 and takes too long. */
12189 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
12190 /* If those didn't work, look for something which will at least work. */
12191 if (! STRINGP (font
))
12192 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
12194 if (! STRINGP (font
))
12195 font
= build_string ("fixed");
12197 x_default_parameter (f
, parms
, Qfont
, font
,
12198 "font", "Font", RES_TYPE_STRING
);
12201 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
12202 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
12204 /* This defaults to 2 in order to match xterm. We recognize either
12205 internalBorderWidth or internalBorder (which is what xterm calls
12207 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12211 value
= w32_get_arg (parms
, Qinternal_border_width
,
12212 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
12213 if (! EQ (value
, Qunbound
))
12214 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
12218 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
12219 "internalBorderWidth", "internalBorderWidth",
12222 /* Also do the stuff which must be set before the window exists. */
12223 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
12224 "foreground", "Foreground", RES_TYPE_STRING
);
12225 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
12226 "background", "Background", RES_TYPE_STRING
);
12227 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
12228 "pointerColor", "Foreground", RES_TYPE_STRING
);
12229 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
12230 "cursorColor", "Foreground", RES_TYPE_STRING
);
12231 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
12232 "borderColor", "BorderColor", RES_TYPE_STRING
);
12234 /* Init faces before x_default_parameter is called for scroll-bar
12235 parameters because that function calls x_set_scroll_bar_width,
12236 which calls change_frame_size, which calls Fset_window_buffer,
12237 which runs hooks, which call Fvertical_motion. At the end, we
12238 end up in init_iterator with a null face cache, which should not
12240 init_frame_faces (f
);
12242 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12243 window_prompting
= x_figure_window_size (f
, parms
);
12245 if (window_prompting
& XNegative
)
12247 if (window_prompting
& YNegative
)
12248 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
12250 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
12254 if (window_prompting
& YNegative
)
12255 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
12257 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
12260 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
12262 XSetWindowAttributes attrs
;
12263 unsigned long mask
;
12266 mask
= CWBackPixel
| CWOverrideRedirect
| CWSaveUnder
| CWEventMask
;
12267 /* Window managers looks at the override-redirect flag to
12268 determine whether or net to give windows a decoration (Xlib
12270 attrs
.override_redirect
= True
;
12271 attrs
.save_under
= True
;
12272 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
12273 /* Arrange for getting MapNotify and UnmapNotify events. */
12274 attrs
.event_mask
= StructureNotifyMask
;
12276 = FRAME_W32_WINDOW (f
)
12277 = XCreateWindow (FRAME_W32_DISPLAY (f
),
12278 FRAME_W32_DISPLAY_INFO (f
)->root_window
,
12279 /* x, y, width, height */
12283 CopyFromParent
, InputOutput
, CopyFromParent
,
12290 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
12291 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12292 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
12293 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12294 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
12295 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
12297 /* Dimensions, especially f->height, must be done via change_frame_size.
12298 Change will not be effected unless different from the current
12301 height
= f
->height
;
12303 SET_FRAME_WIDTH (f
, 0);
12304 change_frame_size (f
, height
, width
, 1, 0, 0);
12310 /* It is now ok to make the frame official even if we get an error
12311 below. And the frame needs to be on Vframe_list or making it
12312 visible won't work. */
12313 Vframe_list
= Fcons (frame
, Vframe_list
);
12315 /* Now that the frame is official, it counts as a reference to
12317 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
12319 return unbind_to (count
, frame
);
12324 #ifdef TODO /* Tooltip support not complete. */
12325 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
12326 "Show STRING in a \"tooltip\" window on frame FRAME.\n\
12327 A tooltip window is a small X window displaying a string.\n\
12329 FRAME nil or omitted means use the selected frame.\n\
12331 PARMS is an optional list of frame parameters which can be\n\
12332 used to change the tooltip's appearance.\n\
12334 Automatically hide the tooltip after TIMEOUT seconds.\n\
12335 TIMEOUT nil means use the default timeout of 5 seconds.\n\
12337 If the list of frame parameters PARAMS contains a `left' parameters,\n\
12338 the tooltip is displayed at that x-position. Otherwise it is\n\
12339 displayed at the mouse position, with offset DX added (default is 5 if\n\
12340 DX isn't specified). Likewise for the y-position; if a `top' frame\n\
12341 parameter is specified, it determines the y-position of the tooltip\n\
12342 window, otherwise it is displayed at the mouse position, with offset\n\
12343 DY added (default is -5).")
12344 (string
, frame
, parms
, timeout
, dx
, dy
)
12345 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
12349 Window root
, child
;
12350 Lisp_Object buffer
, top
, left
;
12351 struct buffer
*old_buffer
;
12352 struct text_pos pos
;
12353 int i
, width
, height
;
12354 int root_x
, root_y
, win_x
, win_y
;
12356 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
12357 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
12358 int count
= specpdl_ptr
- specpdl
;
12360 specbind (Qinhibit_redisplay
, Qt
);
12362 GCPRO4 (string
, parms
, frame
, timeout
);
12364 CHECK_STRING (string
, 0);
12365 f
= check_x_frame (frame
);
12366 if (NILP (timeout
))
12367 timeout
= make_number (5);
12369 CHECK_NATNUM (timeout
, 2);
12372 dx
= make_number (5);
12374 CHECK_NUMBER (dx
, 5);
12377 dy
= make_number (-5);
12379 CHECK_NUMBER (dy
, 6);
12381 /* Hide a previous tip, if any. */
12384 /* Add default values to frame parameters. */
12385 if (NILP (Fassq (Qname
, parms
)))
12386 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
12387 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12388 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
12389 if (NILP (Fassq (Qborder_width
, parms
)))
12390 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
12391 if (NILP (Fassq (Qborder_color
, parms
)))
12392 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
12393 if (NILP (Fassq (Qbackground_color
, parms
)))
12394 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
12397 /* Create a frame for the tooltip, and record it in the global
12398 variable tip_frame. */
12399 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
);
12400 tip_frame
= f
= XFRAME (frame
);
12402 /* Set up the frame's root window. Currently we use a size of 80
12403 columns x 40 lines. If someone wants to show a larger tip, he
12404 will loose. I don't think this is a realistic case. */
12405 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
12406 w
->left
= w
->top
= make_number (0);
12410 w
->pseudo_window_p
= 1;
12412 /* Display the tooltip text in a temporary buffer. */
12413 buffer
= Fget_buffer_create (build_string (" *tip*"));
12414 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
12415 old_buffer
= current_buffer
;
12416 set_buffer_internal_1 (XBUFFER (buffer
));
12418 Finsert (make_number (1), &string
);
12419 clear_glyph_matrix (w
->desired_matrix
);
12420 clear_glyph_matrix (w
->current_matrix
);
12421 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
12422 try_window (FRAME_ROOT_WINDOW (f
), pos
);
12424 /* Compute width and height of the tooltip. */
12425 width
= height
= 0;
12426 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
12428 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
12429 struct glyph
*last
;
12432 /* Stop at the first empty row at the end. */
12433 if (!row
->enabled_p
|| !row
->displays_text_p
)
12436 /* Let the row go over the full width of the frame. */
12437 row
->full_width_p
= 1;
12439 /* There's a glyph at the end of rows that is use to place
12440 the cursor there. Don't include the width of this glyph. */
12441 if (row
->used
[TEXT_AREA
])
12443 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
12444 row_width
= row
->pixel_width
- last
->pixel_width
;
12447 row_width
= row
->pixel_width
;
12449 height
+= row
->height
;
12450 width
= max (width
, row_width
);
12453 /* Add the frame's internal border to the width and height the X
12454 window should have. */
12455 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12456 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12458 /* User-specified position? */
12459 left
= Fcdr (Fassq (Qleft
, parms
));
12460 top
= Fcdr (Fassq (Qtop
, parms
));
12462 /* Move the tooltip window where the mouse pointer is. Resize and
12464 #if 0 /* TODO : W32 specifics */
12466 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
12467 &root
, &child
, &root_x
, &root_y
, &win_x
, &win_y
, &pmask
);
12470 root_x
+= XINT (dx
);
12471 root_y
+= XINT (dy
);
12473 if (INTEGERP (left
))
12474 root_x
= XINT (left
);
12475 if (INTEGERP (top
))
12476 root_y
= XINT (top
);
12479 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12480 root_x
, root_y
- height
, width
, height
);
12481 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12485 /* Draw into the window. */
12486 w
->must_be_updated_p
= 1;
12487 update_single_window (w
, 1);
12489 /* Restore original current buffer. */
12490 set_buffer_internal_1 (old_buffer
);
12491 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
12493 /* Let the tip disappear after timeout seconds. */
12494 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
12495 intern ("x-hide-tip"));
12498 return unbind_to (count
, Qnil
);
12502 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
12503 "Hide the current tooltip window, if there is any.\n\
12504 Value is t is tooltip was open, nil otherwise.")
12507 int count
= specpdl_ptr
- specpdl
;
12510 specbind (Qinhibit_redisplay
, Qt
);
12512 if (!NILP (tip_timer
))
12514 call1 (intern ("cancel-timer"), tip_timer
);
12522 XSETFRAME (frame
, tip_frame
);
12523 Fdelete_frame (frame
, Qt
);
12528 return unbind_to (count
, deleted_p
? Qt
: Qnil
);
12534 /***********************************************************************
12535 File selection dialog
12536 ***********************************************************************/
12538 extern Lisp_Object Qfile_name_history
;
12540 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
12541 "Read file name, prompting with PROMPT in directory DIR.\n\
12542 Use a file selection dialog.\n\
12543 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
12544 specified. Don't let the user enter a file name in the file\n\
12545 selection dialog's entry field, if MUSTMATCH is non-nil.")
12546 (prompt
, dir
, default_filename
, mustmatch
)
12547 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
12549 struct frame
*f
= SELECTED_FRAME ();
12550 Lisp_Object file
= Qnil
;
12551 int count
= specpdl_ptr
- specpdl
;
12552 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
12553 char filename
[MAX_PATH
+ 1];
12554 char init_dir
[MAX_PATH
+ 1];
12555 int use_dialog_p
= 1;
12557 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
12558 CHECK_STRING (prompt
, 0);
12559 CHECK_STRING (dir
, 1);
12561 /* Create the dialog with PROMPT as title, using DIR as initial
12562 directory and using "*" as pattern. */
12563 dir
= Fexpand_file_name (dir
, Qnil
);
12564 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
12565 init_dir
[MAX_PATH
] = '\0';
12566 unixtodos_filename (init_dir
);
12568 if (STRINGP (default_filename
))
12570 char *file_name_only
;
12571 char *full_path_name
= XSTRING (default_filename
)->data
;
12573 unixtodos_filename (full_path_name
);
12575 file_name_only
= strrchr (full_path_name
, '\\');
12576 if (!file_name_only
)
12577 file_name_only
= full_path_name
;
12582 /* If default_file_name is a directory, don't use the open
12583 file dialog, as it does not support selecting
12585 if (!(*file_name_only
))
12589 strncpy (filename
, file_name_only
, MAX_PATH
);
12590 filename
[MAX_PATH
] = '\0';
12593 filename
[0] = '\0';
12597 OPENFILENAME file_details
;
12598 char *filename_file
;
12600 /* Prevent redisplay. */
12601 specbind (Qinhibit_redisplay
, Qt
);
12604 bzero (&file_details
, sizeof (file_details
));
12605 file_details
.lStructSize
= sizeof (file_details
);
12606 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
12607 file_details
.lpstrFile
= filename
;
12608 file_details
.nMaxFile
= sizeof (filename
);
12609 file_details
.lpstrInitialDir
= init_dir
;
12610 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
12611 file_details
.Flags
= OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
;
12613 if (!NILP (mustmatch
))
12614 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
12616 if (GetOpenFileName (&file_details
))
12618 dostounix_filename (filename
);
12619 file
= build_string (filename
);
12625 file
= unbind_to (count
, file
);
12627 /* Open File dialog will not allow folders to be selected, so resort
12628 to minibuffer completing reads for directories. */
12630 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
12631 dir
, mustmatch
, dir
, Qfile_name_history
,
12632 default_filename
, Qnil
);
12636 /* Make "Cancel" equivalent to C-g. */
12638 Fsignal (Qquit
, Qnil
);
12640 return unbind_to (count
, file
);
12645 /***********************************************************************
12647 ***********************************************************************/
12651 DEFUN ("imagep", Fimagep
, Simagep
, 1, 1, 0,
12652 "Value is non-nil if SPEC is a valid image specification.")
12656 return valid_image_p (spec
) ? Qt
: Qnil
;
12660 DEFUN ("lookup-image", Flookup_image
, Slookup_image
, 1, 1, 0, "")
12666 if (valid_image_p (spec
))
12667 id
= lookup_image (SELECTED_FRAME (), spec
);
12669 debug_print (spec
);
12670 return make_number (id
);
12673 #endif /* GLYPH_DEBUG != 0 */
12677 /***********************************************************************
12678 w32 specialized functions
12679 ***********************************************************************/
12681 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 1, 0,
12682 "This will display the W32 font dialog and return an X font string corresponding to the selection.")
12686 FRAME_PTR f
= check_x_frame (frame
);
12694 bzero (&cf
, sizeof (cf
));
12695 bzero (&lf
, sizeof (lf
));
12697 cf
.lStructSize
= sizeof (cf
);
12698 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
12699 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
;
12700 cf
.lpLogFont
= &lf
;
12702 /* Initialize as much of the font details as we can from the current
12704 hdc
= GetDC (FRAME_W32_WINDOW (f
));
12705 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
12706 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
12707 if (GetTextMetrics (hdc
, &tm
))
12709 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
12710 lf
.lfWeight
= tm
.tmWeight
;
12711 lf
.lfItalic
= tm
.tmItalic
;
12712 lf
.lfUnderline
= tm
.tmUnderlined
;
12713 lf
.lfStrikeOut
= tm
.tmStruckOut
;
12714 lf
.lfCharSet
= tm
.tmCharSet
;
12715 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
12717 SelectObject (hdc
, oldobj
);
12718 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
12720 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
12723 return build_string (buf
);
12726 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
, Sw32_send_sys_command
, 1, 2, 0,
12727 "Send frame a Windows WM_SYSCOMMAND message of type COMMAND.\n\
12728 Some useful values for command are 0xf030 to maximise frame (0xf020\n\
12729 to minimize), 0xf120 to restore frame to original size, and 0xf100\n\
12730 to activate the menubar for keyboard access. 0xf140 activates the\n\
12731 screen saver if defined.\n\
12733 If optional parameter FRAME is not specified, use selected frame.")
12735 Lisp_Object command
, frame
;
12738 FRAME_PTR f
= check_x_frame (frame
);
12740 CHECK_NUMBER (command
, 0);
12742 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
12747 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
12748 "Get Windows to perform OPERATION on DOCUMENT.\n\
12749 This is a wrapper around the ShellExecute system function, which\n\
12750 invokes the application registered to handle OPERATION for DOCUMENT.\n\
12751 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be\n\
12752 nil for the default action), and DOCUMENT is typically the name of a\n\
12753 document file or URL, but can also be a program executable to run or\n\
12754 a directory to open in the Windows Explorer.\n\
12756 If DOCUMENT is a program executable, PARAMETERS can be a string\n\
12757 containing command line parameters, but otherwise should be nil.\n\
12759 SHOW-FLAG can be used to control whether the invoked application is hidden\n\
12760 or minimized. If SHOW-FLAG is nil, the application is displayed normally,\n\
12761 otherwise it is an integer representing a ShowWindow flag:\n\
12763 0 - start hidden\n\
12764 1 - start normally\n\
12765 3 - start maximized\n\
12766 6 - start minimized")
12767 (operation
, document
, parameters
, show_flag
)
12768 Lisp_Object operation
, document
, parameters
, show_flag
;
12770 Lisp_Object current_dir
;
12772 CHECK_STRING (document
, 0);
12774 /* Encode filename and current directory. */
12775 current_dir
= ENCODE_FILE (current_buffer
->directory
);
12776 document
= ENCODE_FILE (document
);
12777 if ((int) ShellExecute (NULL
,
12778 (STRINGP (operation
) ?
12779 XSTRING (operation
)->data
: NULL
),
12780 XSTRING (document
)->data
,
12781 (STRINGP (parameters
) ?
12782 XSTRING (parameters
)->data
: NULL
),
12783 XSTRING (current_dir
)->data
,
12784 (INTEGERP (show_flag
) ?
12785 XINT (show_flag
) : SW_SHOWDEFAULT
))
12788 error ("ShellExecute failed");
12791 /* Lookup virtual keycode from string representing the name of a
12792 non-ascii keystroke into the corresponding virtual key, using
12793 lispy_function_keys. */
12795 lookup_vk_code (char *key
)
12799 for (i
= 0; i
< 256; i
++)
12800 if (lispy_function_keys
[i
] != 0
12801 && strcmp (lispy_function_keys
[i
], key
) == 0)
12807 /* Convert a one-element vector style key sequence to a hot key
12810 w32_parse_hot_key (key
)
12813 /* Copied from Fdefine_key and store_in_keymap. */
12814 register Lisp_Object c
;
12816 int lisp_modifiers
;
12818 struct gcpro gcpro1
;
12820 CHECK_VECTOR (key
, 0);
12822 if (XFASTINT (Flength (key
)) != 1)
12827 c
= Faref (key
, make_number (0));
12829 if (CONSP (c
) && lucid_event_type_list_p (c
))
12830 c
= Fevent_convert_list (c
);
12834 if (! INTEGERP (c
) && ! SYMBOLP (c
))
12835 error ("Key definition is invalid");
12837 /* Work out the base key and the modifiers. */
12840 c
= parse_modifiers (c
);
12841 lisp_modifiers
= Fcar (Fcdr (c
));
12845 vk_code
= lookup_vk_code (XSYMBOL (c
)->name
->data
);
12847 else if (INTEGERP (c
))
12849 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
12850 /* Many ascii characters are their own virtual key code. */
12851 vk_code
= XINT (c
) & CHARACTERBITS
;
12854 if (vk_code
< 0 || vk_code
> 255)
12857 if ((lisp_modifiers
& meta_modifier
) != 0
12858 && !NILP (Vw32_alt_is_meta
))
12859 lisp_modifiers
|= alt_modifier
;
12861 /* Supply defs missing from mingw32. */
12863 #define MOD_ALT 0x0001
12864 #define MOD_CONTROL 0x0002
12865 #define MOD_SHIFT 0x0004
12866 #define MOD_WIN 0x0008
12869 /* Convert lisp modifiers to Windows hot-key form. */
12870 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
12871 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
12872 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
12873 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
12875 return HOTKEY (vk_code
, w32_modifiers
);
12878 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
, Sw32_register_hot_key
, 1, 1, 0,
12879 "Register KEY as a hot-key combination.\n\
12880 Certain key combinations like Alt-Tab are reserved for system use on\n\
12881 Windows, and therefore are normally intercepted by the system. However,\n\
12882 most of these key combinations can be received by registering them as\n\
12883 hot-keys, overriding their special meaning.\n\
12885 KEY must be a one element key definition in vector form that would be\n\
12886 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta\n\
12887 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper\n\
12888 is always interpreted as the Windows modifier keys.\n\
12890 The return value is the hotkey-id if registered, otherwise nil.")
12894 key
= w32_parse_hot_key (key
);
12896 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
12898 /* Reuse an empty slot if possible. */
12899 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
12901 /* Safe to add new key to list, even if we have focus. */
12903 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
12907 /* Notify input thread about new hot-key definition, so that it
12908 takes effect without needing to switch focus. */
12909 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
12916 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
, Sw32_unregister_hot_key
, 1, 1, 0,
12917 "Unregister HOTKEY as a hot-key combination.")
12923 if (!INTEGERP (key
))
12924 key
= w32_parse_hot_key (key
);
12926 item
= Fmemq (key
, w32_grabbed_keys
);
12930 /* Notify input thread about hot-key definition being removed, so
12931 that it takes effect without needing focus switch. */
12932 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
12933 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
12936 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
12943 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
, Sw32_registered_hot_keys
, 0, 0, 0,
12944 "Return list of registered hot-key IDs.")
12947 return Fcopy_sequence (w32_grabbed_keys
);
12950 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
, Sw32_reconstruct_hot_key
, 1, 1, 0,
12951 "Convert hot-key ID to a lisp key combination.")
12953 Lisp_Object hotkeyid
;
12955 int vk_code
, w32_modifiers
;
12958 CHECK_NUMBER (hotkeyid
, 0);
12960 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
12961 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
12963 if (lispy_function_keys
[vk_code
])
12964 key
= intern (lispy_function_keys
[vk_code
]);
12966 key
= make_number (vk_code
);
12968 key
= Fcons (key
, Qnil
);
12969 if (w32_modifiers
& MOD_SHIFT
)
12970 key
= Fcons (Qshift
, key
);
12971 if (w32_modifiers
& MOD_CONTROL
)
12972 key
= Fcons (Qctrl
, key
);
12973 if (w32_modifiers
& MOD_ALT
)
12974 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
12975 if (w32_modifiers
& MOD_WIN
)
12976 key
= Fcons (Qhyper
, key
);
12981 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
, Sw32_toggle_lock_key
, 1, 2, 0,
12982 "Toggle the state of the lock key KEY.\n\
12983 KEY can be `capslock', `kp-numlock', or `scroll'.\n\
12984 If the optional parameter NEW-STATE is a number, then the state of KEY\n\
12985 is set to off if the low bit of NEW-STATE is zero, otherwise on.")
12987 Lisp_Object key
, new_state
;
12992 if (EQ (key
, intern ("capslock")))
12993 vk_code
= VK_CAPITAL
;
12994 else if (EQ (key
, intern ("kp-numlock")))
12995 vk_code
= VK_NUMLOCK
;
12996 else if (EQ (key
, intern ("scroll")))
12997 vk_code
= VK_SCROLL
;
13001 if (!dwWindowsThreadId
)
13002 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
13004 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
13005 (WPARAM
) vk_code
, (LPARAM
) new_state
))
13008 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13009 return make_number (msg
.wParam
);
13016 /* This is zero if not using MS-Windows. */
13019 /* The section below is built by the lisp expression at the top of the file,
13020 just above where these variables are declared. */
13021 /*&&& init symbols here &&&*/
13022 Qauto_raise
= intern ("auto-raise");
13023 staticpro (&Qauto_raise
);
13024 Qauto_lower
= intern ("auto-lower");
13025 staticpro (&Qauto_lower
);
13026 Qbar
= intern ("bar");
13028 Qborder_color
= intern ("border-color");
13029 staticpro (&Qborder_color
);
13030 Qborder_width
= intern ("border-width");
13031 staticpro (&Qborder_width
);
13032 Qbox
= intern ("box");
13034 Qcursor_color
= intern ("cursor-color");
13035 staticpro (&Qcursor_color
);
13036 Qcursor_type
= intern ("cursor-type");
13037 staticpro (&Qcursor_type
);
13038 Qgeometry
= intern ("geometry");
13039 staticpro (&Qgeometry
);
13040 Qicon_left
= intern ("icon-left");
13041 staticpro (&Qicon_left
);
13042 Qicon_top
= intern ("icon-top");
13043 staticpro (&Qicon_top
);
13044 Qicon_type
= intern ("icon-type");
13045 staticpro (&Qicon_type
);
13046 Qicon_name
= intern ("icon-name");
13047 staticpro (&Qicon_name
);
13048 Qinternal_border_width
= intern ("internal-border-width");
13049 staticpro (&Qinternal_border_width
);
13050 Qleft
= intern ("left");
13051 staticpro (&Qleft
);
13052 Qright
= intern ("right");
13053 staticpro (&Qright
);
13054 Qmouse_color
= intern ("mouse-color");
13055 staticpro (&Qmouse_color
);
13056 Qnone
= intern ("none");
13057 staticpro (&Qnone
);
13058 Qparent_id
= intern ("parent-id");
13059 staticpro (&Qparent_id
);
13060 Qscroll_bar_width
= intern ("scroll-bar-width");
13061 staticpro (&Qscroll_bar_width
);
13062 Qsuppress_icon
= intern ("suppress-icon");
13063 staticpro (&Qsuppress_icon
);
13064 Qundefined_color
= intern ("undefined-color");
13065 staticpro (&Qundefined_color
);
13066 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
13067 staticpro (&Qvertical_scroll_bars
);
13068 Qvisibility
= intern ("visibility");
13069 staticpro (&Qvisibility
);
13070 Qwindow_id
= intern ("window-id");
13071 staticpro (&Qwindow_id
);
13072 Qx_frame_parameter
= intern ("x-frame-parameter");
13073 staticpro (&Qx_frame_parameter
);
13074 Qx_resource_name
= intern ("x-resource-name");
13075 staticpro (&Qx_resource_name
);
13076 Quser_position
= intern ("user-position");
13077 staticpro (&Quser_position
);
13078 Quser_size
= intern ("user-size");
13079 staticpro (&Quser_size
);
13080 Qscreen_gamma
= intern ("screen-gamma");
13081 staticpro (&Qscreen_gamma
);
13082 Qline_spacing
= intern ("line-spacing");
13083 staticpro (&Qline_spacing
);
13084 Qcenter
= intern ("center");
13085 staticpro (&Qcenter
);
13086 /* This is the end of symbol initialization. */
13088 Qhyper
= intern ("hyper");
13089 staticpro (&Qhyper
);
13090 Qsuper
= intern ("super");
13091 staticpro (&Qsuper
);
13092 Qmeta
= intern ("meta");
13093 staticpro (&Qmeta
);
13094 Qalt
= intern ("alt");
13096 Qctrl
= intern ("ctrl");
13097 staticpro (&Qctrl
);
13098 Qcontrol
= intern ("control");
13099 staticpro (&Qcontrol
);
13100 Qshift
= intern ("shift");
13101 staticpro (&Qshift
);
13103 /* Text property `display' should be nonsticky by default. */
13104 Vtext_property_default_nonsticky
13105 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
13108 Qlaplace
= intern ("laplace");
13109 staticpro (&Qlaplace
);
13111 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
13112 staticpro (&Qface_set_after_frame_default
);
13114 Fput (Qundefined_color
, Qerror_conditions
,
13115 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
13116 Fput (Qundefined_color
, Qerror_message
,
13117 build_string ("Undefined color"));
13119 staticpro (&w32_grabbed_keys
);
13120 w32_grabbed_keys
= Qnil
;
13122 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
13123 "An array of color name mappings for windows.");
13124 Vw32_color_map
= Qnil
;
13126 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
13127 "Non-nil if alt key presses are passed on to Windows.\n\
13128 When non-nil, for example, alt pressed and released and then space will\n\
13129 open the System menu. When nil, Emacs silently swallows alt key events.");
13130 Vw32_pass_alt_to_system
= Qnil
;
13132 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
13133 "Non-nil if the alt key is to be considered the same as the meta key.\n\
13134 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta.");
13135 Vw32_alt_is_meta
= Qt
;
13137 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
13138 "If non-zero, the virtual key code for an alternative quit key.");
13139 XSETINT (Vw32_quit_key
, 0);
13141 DEFVAR_LISP ("w32-pass-lwindow-to-system",
13142 &Vw32_pass_lwindow_to_system
,
13143 "Non-nil if the left \"Windows\" key is passed on to Windows.\n\
13144 When non-nil, the Start menu is opened by tapping the key.");
13145 Vw32_pass_lwindow_to_system
= Qt
;
13147 DEFVAR_LISP ("w32-pass-rwindow-to-system",
13148 &Vw32_pass_rwindow_to_system
,
13149 "Non-nil if the right \"Windows\" key is passed on to Windows.\n\
13150 When non-nil, the Start menu is opened by tapping the key.");
13151 Vw32_pass_rwindow_to_system
= Qt
;
13153 DEFVAR_INT ("w32-phantom-key-code",
13154 &Vw32_phantom_key_code
,
13155 "Virtual key code used to generate \"phantom\" key presses.\n\
13156 Value is a number between 0 and 255.\n\
13158 Phantom key presses are generated in order to stop the system from\n\
13159 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or\n\
13160 `w32-pass-rwindow-to-system' is nil.");
13161 /* Although 255 is technically not a valid key code, it works and
13162 means that this hack won't interfere with any real key code. */
13163 Vw32_phantom_key_code
= 255;
13165 DEFVAR_LISP ("w32-enable-num-lock",
13166 &Vw32_enable_num_lock
,
13167 "Non-nil if Num Lock should act normally.\n\
13168 Set to nil to see Num Lock as the key `kp-numlock'.");
13169 Vw32_enable_num_lock
= Qt
;
13171 DEFVAR_LISP ("w32-enable-caps-lock",
13172 &Vw32_enable_caps_lock
,
13173 "Non-nil if Caps Lock should act normally.\n\
13174 Set to nil to see Caps Lock as the key `capslock'.");
13175 Vw32_enable_caps_lock
= Qt
;
13177 DEFVAR_LISP ("w32-scroll-lock-modifier",
13178 &Vw32_scroll_lock_modifier
,
13179 "Modifier to use for the Scroll Lock on state.\n\
13180 The value can be hyper, super, meta, alt, control or shift for the\n\
13181 respective modifier, or nil to see Scroll Lock as the key `scroll'.\n\
13182 Any other value will cause the key to be ignored.");
13183 Vw32_scroll_lock_modifier
= Qt
;
13185 DEFVAR_LISP ("w32-lwindow-modifier",
13186 &Vw32_lwindow_modifier
,
13187 "Modifier to use for the left \"Windows\" key.\n\
13188 The value can be hyper, super, meta, alt, control or shift for the\n\
13189 respective modifier, or nil to appear as the key `lwindow'.\n\
13190 Any other value will cause the key to be ignored.");
13191 Vw32_lwindow_modifier
= Qnil
;
13193 DEFVAR_LISP ("w32-rwindow-modifier",
13194 &Vw32_rwindow_modifier
,
13195 "Modifier to use for the right \"Windows\" key.\n\
13196 The value can be hyper, super, meta, alt, control or shift for the\n\
13197 respective modifier, or nil to appear as the key `rwindow'.\n\
13198 Any other value will cause the key to be ignored.");
13199 Vw32_rwindow_modifier
= Qnil
;
13201 DEFVAR_LISP ("w32-apps-modifier",
13202 &Vw32_apps_modifier
,
13203 "Modifier to use for the \"Apps\" key.\n\
13204 The value can be hyper, super, meta, alt, control or shift for the\n\
13205 respective modifier, or nil to appear as the key `apps'.\n\
13206 Any other value will cause the key to be ignored.");
13207 Vw32_apps_modifier
= Qnil
;
13209 DEFVAR_LISP ("w32-enable-synthesized-fonts", &Vw32_enable_synthesized_fonts
,
13210 "Non-nil enables selection of artificially italicized and bold fonts.");
13211 Vw32_enable_synthesized_fonts
= Qnil
;
13213 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
13214 "Non-nil enables Windows palette management to map colors exactly.");
13215 Vw32_enable_palette
= Qt
;
13217 DEFVAR_INT ("w32-mouse-button-tolerance",
13218 &Vw32_mouse_button_tolerance
,
13219 "Analogue of double click interval for faking middle mouse events.\n\
13220 The value is the minimum time in milliseconds that must elapse between\n\
13221 left/right button down events before they are considered distinct events.\n\
13222 If both mouse buttons are depressed within this interval, a middle mouse\n\
13223 button down event is generated instead.");
13224 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
13226 DEFVAR_INT ("w32-mouse-move-interval",
13227 &Vw32_mouse_move_interval
,
13228 "Minimum interval between mouse move events.\n\
13229 The value is the minimum time in milliseconds that must elapse between\n\
13230 successive mouse move (or scroll bar drag) events before they are\n\
13231 reported as lisp events.");
13232 XSETINT (Vw32_mouse_move_interval
, 0);
13234 init_x_parm_symbols ();
13236 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
13237 "List of directories to search for bitmap files for w32.");
13238 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
13240 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
13241 "The shape of the pointer when over text.\n\
13242 Changing the value does not affect existing frames\n\
13243 unless you set the mouse color.");
13244 Vx_pointer_shape
= Qnil
;
13246 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
13247 "The name Emacs uses to look up resources; for internal use only.\n\
13248 `x-get-resource' uses this as the first component of the instance name\n\
13249 when requesting resource values.\n\
13250 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
13251 was invoked, or to the value specified with the `-name' or `-rn'\n\
13252 switches, if present.");
13253 Vx_resource_name
= Qnil
;
13255 Vx_nontext_pointer_shape
= Qnil
;
13257 Vx_mode_pointer_shape
= Qnil
;
13259 DEFVAR_LISP ("x-busy-pointer-shape", &Vx_busy_pointer_shape
,
13260 "The shape of the pointer when Emacs is busy.\n\
13261 This variable takes effect when you create a new frame\n\
13262 or when you set the mouse color.");
13263 Vx_busy_pointer_shape
= Qnil
;
13265 DEFVAR_BOOL ("display-busy-cursor", &display_busy_cursor_p
,
13266 "Non-zero means Emacs displays a busy cursor on window systems.");
13267 display_busy_cursor_p
= 1;
13269 DEFVAR_LISP ("busy-cursor-delay", &Vbusy_cursor_delay
,
13270 "*Seconds to wait before displaying a busy-cursor.\n\
13271 Value must be an integer or float.");
13272 Vbusy_cursor_delay
= make_number (DEFAULT_BUSY_CURSOR_DELAY
);
13274 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
13275 &Vx_sensitive_text_pointer_shape
,
13276 "The shape of the pointer when over mouse-sensitive text.\n\
13277 This variable takes effect when you create a new frame\n\
13278 or when you set the mouse color.");
13279 Vx_sensitive_text_pointer_shape
= Qnil
;
13281 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
13282 "A string indicating the foreground color of the cursor box.");
13283 Vx_cursor_fore_pixel
= Qnil
;
13285 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
13286 "Non-nil if no window manager is in use.\n\
13287 Emacs doesn't try to figure this out; this is always nil\n\
13288 unless you set it to something else.");
13289 /* We don't have any way to find this out, so set it to nil
13290 and maybe the user would like to set it to t. */
13291 Vx_no_window_manager
= Qnil
;
13293 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
13294 &Vx_pixel_size_width_font_regexp
,
13295 "Regexp matching a font name whose width is the same as `PIXEL_SIZE'.\n\
13297 Since Emacs gets width of a font matching with this regexp from\n\
13298 PIXEL_SIZE field of the name, font finding mechanism gets faster for\n\
13299 such a font. This is especially effective for such large fonts as\n\
13300 Chinese, Japanese, and Korean.");
13301 Vx_pixel_size_width_font_regexp
= Qnil
;
13303 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
13304 "Time after which cached images are removed from the cache.\n\
13305 When an image has not been displayed this many seconds, remove it\n\
13306 from the image cache. Value must be an integer or nil with nil\n\
13307 meaning don't clear the cache.");
13308 Vimage_cache_eviction_delay
= make_number (30 * 60);
13310 DEFVAR_LISP ("w32-bdf-filename-alist",
13311 &Vw32_bdf_filename_alist
,
13312 "List of bdf fonts and their corresponding filenames.");
13313 Vw32_bdf_filename_alist
= Qnil
;
13315 DEFVAR_BOOL ("w32-strict-fontnames",
13316 &w32_strict_fontnames
,
13317 "Non-nil means only use fonts that are exact matches for those requested.\n\
13318 Default is nil, which allows old fontnames that are not XLFD compliant,\n\
13319 and allows third-party CJK display to work by specifying false charset\n\
13320 fields to trick Emacs into translating to Big5, SJIS etc.\n\
13321 Setting this to t will prevent wrong fonts being selected when\n\
13322 fontsets are automatically created.");
13323 w32_strict_fontnames
= 0;
13325 DEFVAR_BOOL ("w32-strict-painting",
13326 &w32_strict_painting
,
13327 "Non-nil means use strict rules for repainting frames.\n\
13328 Set this to nil to get the old behaviour for repainting; this should\n\
13329 only be necessary if the default setting causes problems.");
13330 w32_strict_painting
= 1;
13332 DEFVAR_LISP ("w32-system-coding-system",
13333 &Vw32_system_coding_system
,
13334 "Coding system used by Windows system functions, such as for font names.");
13335 Vw32_system_coding_system
= Qnil
;
13337 DEFVAR_LISP ("w32-charset-info-alist",
13338 &Vw32_charset_info_alist
,
13339 "Alist linking Emacs character sets to Windows fonts\n\
13340 and codepages. Each entry should be of the form:\n\
13342 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))\n\
13344 where CHARSET_NAME is a string used in font names to identify the charset,\n\
13345 WINDOWS_CHARSET is a symbol that can be one of:\n\
13346 w32-charset-ansi, w32-charset-default, w32-charset-symbol,\n\
13347 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,\n\
13348 w32-charset-chinesebig5, "
13349 #ifdef JOHAB_CHARSET
13350 "w32-charset-johab, w32-charset-hebrew,\n\
13351 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,\n\
13352 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,\n\
13353 w32-charset-russian, w32-charset-mac, w32-charset-baltic,\n"
13355 #ifdef UNICODE_CHARSET
13356 "w32-charset-unicode, "
13358 "or w32-charset-oem.\n\
13359 CODEPAGE should be an integer specifying the codepage that should be used\n\
13360 to display the character set, t to do no translation and output as Unicode,\n\
13361 or nil to do no translation and output as 8 bit (or multibyte on far-east\n\
13362 versions of Windows) characters.");
13363 Vw32_charset_info_alist
= Qnil
;
13365 staticpro (&Qw32_charset_ansi
);
13366 Qw32_charset_ansi
= intern ("w32-charset-ansi");
13367 staticpro (&Qw32_charset_symbol
);
13368 Qw32_charset_symbol
= intern ("w32-charset-symbol");
13369 staticpro (&Qw32_charset_shiftjis
);
13370 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
13371 staticpro (&Qw32_charset_hangeul
);
13372 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
13373 staticpro (&Qw32_charset_chinesebig5
);
13374 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
13375 staticpro (&Qw32_charset_gb2312
);
13376 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
13377 staticpro (&Qw32_charset_oem
);
13378 Qw32_charset_oem
= intern ("w32-charset-oem");
13380 #ifdef JOHAB_CHARSET
13382 static int w32_extra_charsets_defined
= 1;
13383 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
, "");
13385 staticpro (&Qw32_charset_johab
);
13386 Qw32_charset_johab
= intern ("w32-charset-johab");
13387 staticpro (&Qw32_charset_easteurope
);
13388 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
13389 staticpro (&Qw32_charset_turkish
);
13390 Qw32_charset_turkish
= intern ("w32-charset-turkish");
13391 staticpro (&Qw32_charset_baltic
);
13392 Qw32_charset_baltic
= intern ("w32-charset-baltic");
13393 staticpro (&Qw32_charset_russian
);
13394 Qw32_charset_russian
= intern ("w32-charset-russian");
13395 staticpro (&Qw32_charset_arabic
);
13396 Qw32_charset_arabic
= intern ("w32-charset-arabic");
13397 staticpro (&Qw32_charset_greek
);
13398 Qw32_charset_greek
= intern ("w32-charset-greek");
13399 staticpro (&Qw32_charset_hebrew
);
13400 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
13401 staticpro (&Qw32_charset_vietnamese
);
13402 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
13403 staticpro (&Qw32_charset_thai
);
13404 Qw32_charset_thai
= intern ("w32-charset-thai");
13405 staticpro (&Qw32_charset_mac
);
13406 Qw32_charset_mac
= intern ("w32-charset-mac");
13410 #ifdef UNICODE_CHARSET
13412 static int w32_unicode_charset_defined
= 1;
13413 DEFVAR_BOOL ("w32-unicode-charset-defined",
13414 &w32_unicode_charset_defined
, "");
13416 staticpro (&Qw32_charset_unicode
);
13417 Qw32_charset_unicode
= intern ("w32-charset-unicode");
13420 defsubr (&Sx_get_resource
);
13421 #if 0 /* TODO: Port to W32 */
13422 defsubr (&Sx_change_window_property
);
13423 defsubr (&Sx_delete_window_property
);
13424 defsubr (&Sx_window_property
);
13426 defsubr (&Sxw_display_color_p
);
13427 defsubr (&Sx_display_grayscale_p
);
13428 defsubr (&Sxw_color_defined_p
);
13429 defsubr (&Sxw_color_values
);
13430 defsubr (&Sx_server_max_request_size
);
13431 defsubr (&Sx_server_vendor
);
13432 defsubr (&Sx_server_version
);
13433 defsubr (&Sx_display_pixel_width
);
13434 defsubr (&Sx_display_pixel_height
);
13435 defsubr (&Sx_display_mm_width
);
13436 defsubr (&Sx_display_mm_height
);
13437 defsubr (&Sx_display_screens
);
13438 defsubr (&Sx_display_planes
);
13439 defsubr (&Sx_display_color_cells
);
13440 defsubr (&Sx_display_visual_class
);
13441 defsubr (&Sx_display_backing_store
);
13442 defsubr (&Sx_display_save_under
);
13443 defsubr (&Sx_parse_geometry
);
13444 defsubr (&Sx_create_frame
);
13445 defsubr (&Sx_open_connection
);
13446 defsubr (&Sx_close_connection
);
13447 defsubr (&Sx_display_list
);
13448 defsubr (&Sx_synchronize
);
13450 /* W32 specific functions */
13452 defsubr (&Sw32_focus_frame
);
13453 defsubr (&Sw32_select_font
);
13454 defsubr (&Sw32_define_rgb_color
);
13455 defsubr (&Sw32_default_color_map
);
13456 defsubr (&Sw32_load_color_file
);
13457 defsubr (&Sw32_send_sys_command
);
13458 defsubr (&Sw32_shell_execute
);
13459 defsubr (&Sw32_register_hot_key
);
13460 defsubr (&Sw32_unregister_hot_key
);
13461 defsubr (&Sw32_registered_hot_keys
);
13462 defsubr (&Sw32_reconstruct_hot_key
);
13463 defsubr (&Sw32_toggle_lock_key
);
13464 defsubr (&Sw32_find_bdf_fonts
);
13466 /* Setting callback functions for fontset handler. */
13467 get_font_info_func
= w32_get_font_info
;
13469 #if 0 /* This function pointer doesn't seem to be used anywhere.
13470 And the pointer assigned has the wrong type, anyway. */
13471 list_fonts_func
= w32_list_fonts
;
13474 load_font_func
= w32_load_font
;
13475 find_ccl_program_func
= w32_find_ccl_program
;
13476 query_font_func
= w32_query_font
;
13477 set_frame_fontset_func
= x_set_font
;
13478 check_window_system_func
= check_w32
;
13480 #if 0 /* TODO Image support for W32 */
13482 Qxbm
= intern ("xbm");
13484 QCtype
= intern (":type");
13485 staticpro (&QCtype
);
13486 QCalgorithm
= intern (":algorithm");
13487 staticpro (&QCalgorithm
);
13488 QCheuristic_mask
= intern (":heuristic-mask");
13489 staticpro (&QCheuristic_mask
);
13490 QCcolor_symbols
= intern (":color-symbols");
13491 staticpro (&QCcolor_symbols
);
13492 QCascent
= intern (":ascent");
13493 staticpro (&QCascent
);
13494 QCmargin
= intern (":margin");
13495 staticpro (&QCmargin
);
13496 QCrelief
= intern (":relief");
13497 staticpro (&QCrelief
);
13498 Qpostscript
= intern ("postscript");
13499 staticpro (&Qpostscript
);
13500 QCloader
= intern (":loader");
13501 staticpro (&QCloader
);
13502 QCbounding_box
= intern (":bounding-box");
13503 staticpro (&QCbounding_box
);
13504 QCpt_width
= intern (":pt-width");
13505 staticpro (&QCpt_width
);
13506 QCpt_height
= intern (":pt-height");
13507 staticpro (&QCpt_height
);
13508 QCindex
= intern (":index");
13509 staticpro (&QCindex
);
13510 Qpbm
= intern ("pbm");
13514 Qxpm
= intern ("xpm");
13519 Qjpeg
= intern ("jpeg");
13520 staticpro (&Qjpeg
);
13524 Qtiff
= intern ("tiff");
13525 staticpro (&Qtiff
);
13529 Qgif
= intern ("gif");
13534 Qpng
= intern ("png");
13538 defsubr (&Sclear_image_cache
);
13541 defsubr (&Simagep
);
13542 defsubr (&Slookup_image
);
13546 busy_cursor_atimer
= NULL
;
13547 busy_cursor_shown_p
= 0;
13548 #ifdef TODO /* Tooltip support not complete. */
13549 defsubr (&Sx_show_tip
);
13550 defsubr (&Sx_hide_tip
);
13552 staticpro (&tip_timer
);
13555 defsubr (&Sx_file_dialog
);
13562 image_types
= NULL
;
13563 Vimage_types
= Qnil
;
13565 #if 0 /* TODO : Image support for W32 */
13566 define_image_type (&xbm_type
);
13567 define_image_type (&gs_type
);
13568 define_image_type (&pbm_type
);
13571 define_image_type (&xpm_type
);
13575 define_image_type (&jpeg_type
);
13579 define_image_type (&tiff_type
);
13583 define_image_type (&gif_type
);
13587 define_image_type (&png_type
);
13598 button
= MessageBox (NULL
,
13599 "A fatal error has occurred!\n\n"
13600 "Select Abort to exit, Retry to debug, Ignore to continue",
13601 "Emacs Abort Dialog",
13602 MB_ICONEXCLAMATION
| MB_TASKMODAL
13603 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
13618 /* For convenience when debugging. */
13622 return GetLastError ();