1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 92, 93, 94, 95, 1996, 1997, 1998, 1999
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Added by Kevin Gallo */
33 #include "dispextern.h"
39 #include "intervals.h"
41 #include "blockinput.h"
44 #include "termhooks.h"
49 #include "bitmaps/gray.xbm"
55 #define max(a, b) ((a) > (b) ? (a) : (b))
57 extern void free_frame_menubar ();
58 extern double atof ();
59 extern int w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
);
62 /* A definition of XColor for non-X frames. */
63 #ifndef HAVE_X_WINDOWS
66 unsigned short red
, green
, blue
;
72 extern char *lispy_function_keys
[];
74 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
75 it, and including `bitmaps/gray' more than once is a problem when
76 config.h defines `static' as an empty replacement string. */
78 int gray_bitmap_width
= gray_width
;
79 int gray_bitmap_height
= gray_height
;
80 unsigned char *gray_bitmap_bits
= gray_bits
;
82 /* The colormap for converting color names to RGB values */
83 Lisp_Object Vw32_color_map
;
85 /* Non nil if alt key presses are passed on to Windows. */
86 Lisp_Object Vw32_pass_alt_to_system
;
88 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
90 Lisp_Object Vw32_alt_is_meta
;
92 /* If non-zero, the windows virtual key code for an alternative quit key. */
93 Lisp_Object Vw32_quit_key
;
95 /* Non nil if left window key events are passed on to Windows (this only
96 affects whether "tapping" the key opens the Start menu). */
97 Lisp_Object Vw32_pass_lwindow_to_system
;
99 /* Non nil if right window key events are passed on to Windows (this
100 only affects whether "tapping" the key opens the Start menu). */
101 Lisp_Object Vw32_pass_rwindow_to_system
;
103 /* Virtual key code used to generate "phantom" key presses in order
104 to stop system from acting on Windows key events. */
105 Lisp_Object Vw32_phantom_key_code
;
107 /* Modifier associated with the left "Windows" key, or nil to act as a
109 Lisp_Object Vw32_lwindow_modifier
;
111 /* Modifier associated with the right "Windows" key, or nil to act as a
113 Lisp_Object Vw32_rwindow_modifier
;
115 /* Modifier associated with the "Apps" key, or nil to act as a normal
117 Lisp_Object Vw32_apps_modifier
;
119 /* Value is nil if Num Lock acts as a function key. */
120 Lisp_Object Vw32_enable_num_lock
;
122 /* Value is nil if Caps Lock acts as a function key. */
123 Lisp_Object Vw32_enable_caps_lock
;
125 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
126 Lisp_Object Vw32_scroll_lock_modifier
;
128 /* Switch to control whether we inhibit requests for synthesized bold
129 and italic versions of fonts. */
130 Lisp_Object Vw32_enable_synthesized_fonts
;
132 /* Enable palette management. */
133 Lisp_Object Vw32_enable_palette
;
135 /* Control how close left/right button down events must be to
136 be converted to a middle button down event. */
137 Lisp_Object Vw32_mouse_button_tolerance
;
139 /* Minimum interval between mouse movement (and scroll bar drag)
140 events that are passed on to the event loop. */
141 Lisp_Object Vw32_mouse_move_interval
;
143 /* The name we're using in resource queries. */
144 Lisp_Object Vx_resource_name
;
146 /* Non nil if no window manager is in use. */
147 Lisp_Object Vx_no_window_manager
;
149 /* Non-zero means we're allowed to display a busy cursor. */
151 int display_busy_cursor_p
;
153 /* The background and shape of the mouse pointer, and shape when not
154 over text or in the modeline. */
156 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
157 Lisp_Object Vx_busy_pointer_shape
;
159 /* The shape when over mouse-sensitive text. */
161 Lisp_Object Vx_sensitive_text_pointer_shape
;
163 /* Color of chars displayed in cursor box. */
165 Lisp_Object Vx_cursor_fore_pixel
;
167 /* Nonzero if using Windows. */
169 static int w32_in_use
;
171 /* Search path for bitmap files. */
173 Lisp_Object Vx_bitmap_file_path
;
175 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
177 Lisp_Object Vx_pixel_size_width_font_regexp
;
179 /* Alist of bdf fonts and the files that define them. */
180 Lisp_Object Vw32_bdf_filename_alist
;
182 Lisp_Object Vw32_system_coding_system
;
184 /* A flag to control whether fonts are matched strictly or not. */
185 int w32_strict_fontnames
;
187 /* A flag to control whether we should only repaint if GetUpdateRect
188 indicates there is an update region. */
189 int w32_strict_painting
;
191 /* Associative list linking character set strings to Windows codepages. */
192 Lisp_Object Vw32_charset_info_alist
;
194 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
195 #ifndef VIETNAMESE_CHARSET
196 #define VIETNAMESE_CHARSET 163
200 /* Evaluate this expression to rebuild the section of syms_of_w32fns
201 that initializes and staticpros the symbols declared below. Note
202 that Emacs 18 has a bug that keeps C-x C-e from being able to
203 evaluate this expression.
206 ;; Accumulate a list of the symbols we want to initialize from the
207 ;; declarations at the top of the file.
208 (goto-char (point-min))
209 (search-forward "/\*&&& symbols declared here &&&*\/\n")
211 (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
213 (cons (buffer-substring (match-beginning 1) (match-end 1))
216 (setq symbol-list (nreverse symbol-list))
217 ;; Delete the section of syms_of_... where we initialize the symbols.
218 (search-forward "\n /\*&&& init symbols here &&&*\/\n")
219 (let ((start (point)))
220 (while (looking-at "^ Q")
222 (kill-region start (point)))
223 ;; Write a new symbol initialization section.
225 (insert (format " %s = intern (\"" (car symbol-list)))
226 (let ((start (point)))
227 (insert (substring (car symbol-list) 1))
228 (subst-char-in-region start (point) ?_ ?-))
229 (insert (format "\");\n staticpro (&%s);\n" (car symbol-list)))
230 (setq symbol-list (cdr symbol-list)))))
234 /*&&& symbols declared here &&&*/
235 Lisp_Object Qauto_raise
;
236 Lisp_Object Qauto_lower
;
238 Lisp_Object Qborder_color
;
239 Lisp_Object Qborder_width
;
241 Lisp_Object Qcursor_color
;
242 Lisp_Object Qcursor_type
;
243 Lisp_Object Qgeometry
;
244 Lisp_Object Qicon_left
;
245 Lisp_Object Qicon_top
;
246 Lisp_Object Qicon_type
;
247 Lisp_Object Qicon_name
;
248 Lisp_Object Qinternal_border_width
;
251 Lisp_Object Qmouse_color
;
253 Lisp_Object Qparent_id
;
254 Lisp_Object Qscroll_bar_width
;
255 Lisp_Object Qsuppress_icon
;
256 Lisp_Object Qundefined_color
;
257 Lisp_Object Qvertical_scroll_bars
;
258 Lisp_Object Qvisibility
;
259 Lisp_Object Qwindow_id
;
260 Lisp_Object Qx_frame_parameter
;
261 Lisp_Object Qx_resource_name
;
262 Lisp_Object Quser_position
;
263 Lisp_Object Quser_size
;
264 Lisp_Object Qscreen_gamma
;
265 Lisp_Object Qline_spacing
;
272 Lisp_Object Qcontrol
;
275 Lisp_Object Qw32_charset_ansi
;
276 Lisp_Object Qw32_charset_default
;
277 Lisp_Object Qw32_charset_symbol
;
278 Lisp_Object Qw32_charset_shiftjis
;
279 Lisp_Object Qw32_charset_hangeul
;
280 Lisp_Object Qw32_charset_gb2312
;
281 Lisp_Object Qw32_charset_chinesebig5
;
282 Lisp_Object Qw32_charset_oem
;
284 #ifndef JOHAB_CHARSET
285 #define JOHAB_CHARSET 130
288 Lisp_Object Qw32_charset_easteurope
;
289 Lisp_Object Qw32_charset_turkish
;
290 Lisp_Object Qw32_charset_baltic
;
291 Lisp_Object Qw32_charset_russian
;
292 Lisp_Object Qw32_charset_arabic
;
293 Lisp_Object Qw32_charset_greek
;
294 Lisp_Object Qw32_charset_hebrew
;
295 Lisp_Object Qw32_charset_vietnamese
;
296 Lisp_Object Qw32_charset_thai
;
297 Lisp_Object Qw32_charset_johab
;
298 Lisp_Object Qw32_charset_mac
;
301 #ifdef UNICODE_CHARSET
302 Lisp_Object Qw32_charset_unicode
;
305 extern Lisp_Object Qtop
;
306 extern Lisp_Object Qdisplay
;
307 extern Lisp_Object Qtool_bar_lines
;
309 /* State variables for emulating a three button mouse. */
314 static int button_state
= 0;
315 static W32Msg saved_mouse_button_msg
;
316 static unsigned mouse_button_timer
; /* non-zero when timer is active */
317 static W32Msg saved_mouse_move_msg
;
318 static unsigned mouse_move_timer
;
320 /* W95 mousewheel handler */
321 unsigned int msh_mousewheel
= 0;
323 #define MOUSE_BUTTON_ID 1
324 #define MOUSE_MOVE_ID 2
326 /* The below are defined in frame.c. */
328 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
329 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
, Qbuffer_predicate
, Qtitle
;
330 extern Lisp_Object Qtool_bar_lines
;
332 extern Lisp_Object Vwindow_system_version
;
334 Lisp_Object Qface_set_after_frame_default
;
336 /* From w32term.c. */
337 extern Lisp_Object Vw32_num_mouse_buttons
;
338 extern Lisp_Object Vw32_recognize_altgr
;
341 /* Error if we are not connected to MS-Windows. */
346 error ("MS-Windows not in use or not initialized");
349 /* Nonzero if we can use mouse menus.
350 You should not call this unless HAVE_MENUS is defined. */
358 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
359 and checking validity for W32. */
362 check_x_frame (frame
)
368 frame
= selected_frame
;
369 CHECK_LIVE_FRAME (frame
, 0);
371 if (! FRAME_W32_P (f
))
372 error ("non-w32 frame used");
376 /* Let the user specify an display with a frame.
377 nil stands for the selected frame--or, if that is not a w32 frame,
378 the first display on the list. */
380 static struct w32_display_info
*
381 check_x_display_info (frame
)
386 struct frame
*sf
= XFRAME (selected_frame
);
388 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
389 return FRAME_W32_DISPLAY_INFO (sf
);
391 return &one_w32_display_info
;
393 else if (STRINGP (frame
))
394 return x_display_info_for_name (frame
);
399 CHECK_LIVE_FRAME (frame
, 0);
401 if (! FRAME_W32_P (f
))
402 error ("non-w32 frame used");
403 return FRAME_W32_DISPLAY_INFO (f
);
407 /* Return the Emacs frame-object corresponding to an w32 window.
408 It could be the frame's main window or an icon window. */
410 /* This function can be called during GC, so use GC_xxx type test macros. */
413 x_window_to_frame (dpyinfo
, wdesc
)
414 struct w32_display_info
*dpyinfo
;
417 Lisp_Object tail
, frame
;
420 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
423 if (!GC_FRAMEP (frame
))
426 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
428 if (f
->output_data
.w32
->busy_window
== wdesc
)
431 /* TODO: Check tooltips when supported. */
432 if (FRAME_W32_WINDOW (f
) == wdesc
)
440 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
441 id, which is just an int that this section returns. Bitmaps are
442 reference counted so they can be shared among frames.
444 Bitmap indices are guaranteed to be > 0, so a negative number can
445 be used to indicate no bitmap.
447 If you use x_create_bitmap_from_data, then you must keep track of
448 the bitmaps yourself. That is, creating a bitmap from the same
449 data more than once will not be caught. */
452 /* Functions to access the contents of a bitmap, given an id. */
455 x_bitmap_height (f
, id
)
459 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
463 x_bitmap_width (f
, id
)
467 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
471 x_bitmap_pixmap (f
, id
)
475 return (int) FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
479 /* Allocate a new bitmap record. Returns index of new record. */
482 x_allocate_bitmap_record (f
)
485 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
488 if (dpyinfo
->bitmaps
== NULL
)
490 dpyinfo
->bitmaps_size
= 10;
492 = (struct w32_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
493 dpyinfo
->bitmaps_last
= 1;
497 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
498 return ++dpyinfo
->bitmaps_last
;
500 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
501 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
504 dpyinfo
->bitmaps_size
*= 2;
506 = (struct w32_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
507 dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
508 return ++dpyinfo
->bitmaps_last
;
511 /* Add one reference to the reference count of the bitmap with id ID. */
514 x_reference_bitmap (f
, id
)
518 ++FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
521 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
524 x_create_bitmap_from_data (f
, bits
, width
, height
)
527 unsigned int width
, height
;
529 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
533 bitmap
= CreateBitmap (width
, height
,
534 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_planes
,
535 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_cbits
,
541 id
= x_allocate_bitmap_record (f
);
542 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
543 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
544 dpyinfo
->bitmaps
[id
- 1].hinst
= NULL
;
545 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
546 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
547 dpyinfo
->bitmaps
[id
- 1].height
= height
;
548 dpyinfo
->bitmaps
[id
- 1].width
= width
;
553 /* Create bitmap from file FILE for frame F. */
556 x_create_bitmap_from_file (f
, file
)
561 #if 0 /* TODO : bitmap support */
562 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
563 unsigned int width
, height
;
565 int xhot
, yhot
, result
, id
;
571 /* Look for an existing bitmap with the same name. */
572 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
574 if (dpyinfo
->bitmaps
[id
].refcount
575 && dpyinfo
->bitmaps
[id
].file
576 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) XSTRING (file
)->data
))
578 ++dpyinfo
->bitmaps
[id
].refcount
;
583 /* Search bitmap-file-path for the file, if appropriate. */
584 fd
= openp (Vx_bitmap_file_path
, file
, "", &found
, 0);
589 filename
= (char *) XSTRING (found
)->data
;
591 hinst
= LoadLibraryEx (filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
597 result
= XReadBitmapFile (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
598 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
599 if (result
!= BitmapSuccess
)
602 id
= x_allocate_bitmap_record (f
);
603 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
604 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
605 dpyinfo
->bitmaps
[id
- 1].file
= (char *) xmalloc (XSTRING (file
)->size
+ 1);
606 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
607 dpyinfo
->bitmaps
[id
- 1].height
= height
;
608 dpyinfo
->bitmaps
[id
- 1].width
= width
;
609 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, XSTRING (file
)->data
);
615 /* Remove reference to bitmap with id number ID. */
618 x_destroy_bitmap (f
, id
)
622 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
626 --dpyinfo
->bitmaps
[id
- 1].refcount
;
627 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
630 DeleteObject (dpyinfo
->bitmaps
[id
- 1].pixmap
);
631 if (dpyinfo
->bitmaps
[id
- 1].file
)
633 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
634 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
641 /* Free all the bitmaps for the display specified by DPYINFO. */
644 x_destroy_all_bitmaps (dpyinfo
)
645 struct w32_display_info
*dpyinfo
;
648 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
649 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
651 DeleteObject (dpyinfo
->bitmaps
[i
].pixmap
);
652 if (dpyinfo
->bitmaps
[i
].file
)
653 xfree (dpyinfo
->bitmaps
[i
].file
);
655 dpyinfo
->bitmaps_last
= 0;
658 /* Connect the frame-parameter names for W32 frames
659 to the ways of passing the parameter values to the window system.
661 The name of a parameter, as a Lisp symbol,
662 has an `x-frame-parameter' property which is an integer in Lisp
663 but can be interpreted as an `enum x_frame_parm' in C. */
667 X_PARM_FOREGROUND_COLOR
,
668 X_PARM_BACKGROUND_COLOR
,
675 X_PARM_INTERNAL_BORDER_WIDTH
,
679 X_PARM_VERT_SCROLL_BAR
,
681 X_PARM_MENU_BAR_LINES
685 struct x_frame_parm_table
688 void (*setter
) P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
691 /* TODO: Native Input Method support; see x_create_im. */
692 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
693 static void x_set_line_spacing
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
694 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
695 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
696 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
697 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
698 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
699 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
700 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
701 void x_set_font
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
702 void x_set_border_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
703 void x_set_internal_border_width
P_ ((struct frame
*, Lisp_Object
,
705 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
706 void x_set_autoraise
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
707 void x_set_autolower
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
708 void x_set_vertical_scroll_bars
P_ ((struct frame
*, Lisp_Object
,
710 void x_set_visibility
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
711 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
712 void x_set_scroll_bar_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
713 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
714 void x_set_unsplittable
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
715 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
716 static void x_set_screen_gamma
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
718 static struct x_frame_parm_table x_frame_parms
[] =
720 "auto-raise", x_set_autoraise
,
721 "auto-lower", x_set_autolower
,
722 "background-color", x_set_background_color
,
723 "border-color", x_set_border_color
,
724 "border-width", x_set_border_width
,
725 "cursor-color", x_set_cursor_color
,
726 "cursor-type", x_set_cursor_type
,
728 "foreground-color", x_set_foreground_color
,
729 "icon-name", x_set_icon_name
,
730 "icon-type", x_set_icon_type
,
731 "internal-border-width", x_set_internal_border_width
,
732 "menu-bar-lines", x_set_menu_bar_lines
,
733 "mouse-color", x_set_mouse_color
,
734 "name", x_explicitly_set_name
,
735 "scroll-bar-width", x_set_scroll_bar_width
,
736 "title", x_set_title
,
737 "unsplittable", x_set_unsplittable
,
738 "vertical-scroll-bars", x_set_vertical_scroll_bars
,
739 "visibility", x_set_visibility
,
740 "tool-bar-lines", x_set_tool_bar_lines
,
741 "screen-gamma", x_set_screen_gamma
,
742 "line-spacing", x_set_line_spacing
745 /* Attach the `x-frame-parameter' properties to
746 the Lisp symbol names of parameters relevant to W32. */
749 init_x_parm_symbols ()
753 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
754 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
758 /* Change the parameters of frame F as specified by ALIST.
759 If a parameter is not specially recognized, do nothing;
760 otherwise call the `x_set_...' function for that parameter. */
763 x_set_frame_parameters (f
, alist
)
769 /* If both of these parameters are present, it's more efficient to
770 set them both at once. So we wait until we've looked at the
771 entire list before we set them. */
775 Lisp_Object left
, top
;
777 /* Same with these. */
778 Lisp_Object icon_left
, icon_top
;
780 /* Record in these vectors all the parms specified. */
784 int left_no_change
= 0, top_no_change
= 0;
785 int icon_left_no_change
= 0, icon_top_no_change
= 0;
787 struct gcpro gcpro1
, gcpro2
;
790 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
793 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
794 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
796 /* Extract parm names and values into those vectors. */
799 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
804 parms
[i
] = Fcar (elt
);
805 values
[i
] = Fcdr (elt
);
808 /* TAIL and ALIST are not used again below here. */
811 GCPRO2 (*parms
, *values
);
815 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
816 because their values appear in VALUES and strings are not valid. */
817 top
= left
= Qunbound
;
818 icon_left
= icon_top
= Qunbound
;
820 /* Provide default values for HEIGHT and WIDTH. */
821 if (FRAME_NEW_WIDTH (f
))
822 width
= FRAME_NEW_WIDTH (f
);
824 width
= FRAME_WIDTH (f
);
826 if (FRAME_NEW_HEIGHT (f
))
827 height
= FRAME_NEW_HEIGHT (f
);
829 height
= FRAME_HEIGHT (f
);
831 /* Process foreground_color and background_color before anything else.
832 They are independent of other properties, but other properties (e.g.,
833 cursor_color) are dependent upon them. */
834 for (p
= 0; p
< i
; p
++)
836 Lisp_Object prop
, val
;
840 if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
842 register Lisp_Object param_index
, old_value
;
844 param_index
= Fget (prop
, Qx_frame_parameter
);
845 old_value
= get_frame_param (f
, prop
);
846 store_frame_param (f
, prop
, val
);
847 if (NATNUMP (param_index
)
848 && (XFASTINT (param_index
)
849 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
850 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
854 /* Now process them in reverse of specified order. */
855 for (i
--; i
>= 0; i
--)
857 Lisp_Object prop
, val
;
862 if (EQ (prop
, Qwidth
) && NUMBERP (val
))
863 width
= XFASTINT (val
);
864 else if (EQ (prop
, Qheight
) && NUMBERP (val
))
865 height
= XFASTINT (val
);
866 else if (EQ (prop
, Qtop
))
868 else if (EQ (prop
, Qleft
))
870 else if (EQ (prop
, Qicon_top
))
872 else if (EQ (prop
, Qicon_left
))
874 else if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
875 /* Processed above. */
879 register Lisp_Object param_index
, old_value
;
881 param_index
= Fget (prop
, Qx_frame_parameter
);
882 old_value
= get_frame_param (f
, prop
);
883 store_frame_param (f
, prop
, val
);
884 if (NATNUMP (param_index
)
885 && (XFASTINT (param_index
)
886 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
887 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
891 /* Don't die if just one of these was set. */
892 if (EQ (left
, Qunbound
))
895 if (f
->output_data
.w32
->left_pos
< 0)
896 left
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->left_pos
), Qnil
));
898 XSETINT (left
, f
->output_data
.w32
->left_pos
);
900 if (EQ (top
, Qunbound
))
903 if (f
->output_data
.w32
->top_pos
< 0)
904 top
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->top_pos
), Qnil
));
906 XSETINT (top
, f
->output_data
.w32
->top_pos
);
909 /* If one of the icon positions was not set, preserve or default it. */
910 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
912 icon_left_no_change
= 1;
913 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
914 if (NILP (icon_left
))
915 XSETINT (icon_left
, 0);
917 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
919 icon_top_no_change
= 1;
920 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
922 XSETINT (icon_top
, 0);
925 /* Don't set these parameters unless they've been explicitly
926 specified. The window might be mapped or resized while we're in
927 this function, and we don't want to override that unless the lisp
928 code has asked for it.
930 Don't set these parameters unless they actually differ from the
931 window's current parameters; the window may not actually exist
936 check_frame_size (f
, &height
, &width
);
938 XSETFRAME (frame
, f
);
940 if (width
!= FRAME_WIDTH (f
)
941 || height
!= FRAME_HEIGHT (f
)
942 || FRAME_NEW_HEIGHT (f
) || FRAME_NEW_WIDTH (f
))
943 Fset_frame_size (frame
, make_number (width
), make_number (height
));
945 if ((!NILP (left
) || !NILP (top
))
946 && ! (left_no_change
&& top_no_change
)
947 && ! (NUMBERP (left
) && XINT (left
) == f
->output_data
.w32
->left_pos
948 && NUMBERP (top
) && XINT (top
) == f
->output_data
.w32
->top_pos
))
953 /* Record the signs. */
954 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
955 if (EQ (left
, Qminus
))
956 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
957 else if (INTEGERP (left
))
959 leftpos
= XINT (left
);
961 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
963 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
964 && CONSP (XCDR (left
))
965 && INTEGERP (XCAR (XCDR (left
))))
967 leftpos
= - XINT (XCAR (XCDR (left
)));
968 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
970 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
971 && CONSP (XCDR (left
))
972 && INTEGERP (XCAR (XCDR (left
))))
974 leftpos
= XINT (XCAR (XCDR (left
)));
977 if (EQ (top
, Qminus
))
978 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
979 else if (INTEGERP (top
))
983 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
985 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
986 && CONSP (XCDR (top
))
987 && INTEGERP (XCAR (XCDR (top
))))
989 toppos
= - XINT (XCAR (XCDR (top
)));
990 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
992 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
993 && CONSP (XCDR (top
))
994 && INTEGERP (XCAR (XCDR (top
))))
996 toppos
= XINT (XCAR (XCDR (top
)));
1000 /* Store the numeric value of the position. */
1001 f
->output_data
.w32
->top_pos
= toppos
;
1002 f
->output_data
.w32
->left_pos
= leftpos
;
1004 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
1006 /* Actually set that position, and convert to absolute. */
1007 x_set_offset (f
, leftpos
, toppos
, -1);
1010 if ((!NILP (icon_left
) || !NILP (icon_top
))
1011 && ! (icon_left_no_change
&& icon_top_no_change
))
1012 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
1018 /* Store the screen positions of frame F into XPTR and YPTR.
1019 These are the positions of the containing window manager window,
1020 not Emacs's own window. */
1023 x_real_positions (f
, xptr
, yptr
)
1032 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
1033 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
1039 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
1045 /* Insert a description of internally-recorded parameters of frame X
1046 into the parameter alist *ALISTPTR that is to be given to the user.
1047 Only parameters that are specific to W32
1048 and whose values are not correctly recorded in the frame's
1049 param_alist need to be considered here. */
1052 x_report_frame_params (f
, alistptr
)
1054 Lisp_Object
*alistptr
;
1059 /* Represent negative positions (off the top or left screen edge)
1060 in a way that Fmodify_frame_parameters will understand correctly. */
1061 XSETINT (tem
, f
->output_data
.w32
->left_pos
);
1062 if (f
->output_data
.w32
->left_pos
>= 0)
1063 store_in_alist (alistptr
, Qleft
, tem
);
1065 store_in_alist (alistptr
, Qleft
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1067 XSETINT (tem
, f
->output_data
.w32
->top_pos
);
1068 if (f
->output_data
.w32
->top_pos
>= 0)
1069 store_in_alist (alistptr
, Qtop
, tem
);
1071 store_in_alist (alistptr
, Qtop
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1073 store_in_alist (alistptr
, Qborder_width
,
1074 make_number (f
->output_data
.w32
->border_width
));
1075 store_in_alist (alistptr
, Qinternal_border_width
,
1076 make_number (f
->output_data
.w32
->internal_border_width
));
1077 sprintf (buf
, "%ld", (long) FRAME_W32_WINDOW (f
));
1078 store_in_alist (alistptr
, Qwindow_id
,
1079 build_string (buf
));
1080 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
1081 FRAME_SAMPLE_VISIBILITY (f
);
1082 store_in_alist (alistptr
, Qvisibility
,
1083 (FRAME_VISIBLE_P (f
) ? Qt
1084 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
1085 store_in_alist (alistptr
, Qdisplay
,
1086 XCAR (FRAME_W32_DISPLAY_INFO (f
)->name_list_element
));
1090 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
, Sw32_define_rgb_color
, 4, 4, 0,
1091 "Convert RGB numbers to a windows color reference and associate with NAME (a string).\n\
1092 This adds or updates a named color to w32-color-map, making it available for use.\n\
1093 The original entry's RGB ref is returned, or nil if the entry is new.")
1094 (red
, green
, blue
, name
)
1095 Lisp_Object red
, green
, blue
, name
;
1098 Lisp_Object oldrgb
= Qnil
;
1101 CHECK_NUMBER (red
, 0);
1102 CHECK_NUMBER (green
, 0);
1103 CHECK_NUMBER (blue
, 0);
1104 CHECK_STRING (name
, 0);
1106 XSET (rgb
, Lisp_Int
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
1110 /* replace existing entry in w32-color-map or add new entry. */
1111 entry
= Fassoc (name
, Vw32_color_map
);
1114 entry
= Fcons (name
, rgb
);
1115 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
1119 oldrgb
= Fcdr (entry
);
1120 Fsetcdr (entry
, rgb
);
1128 DEFUN ("w32-load-color-file", Fw32_load_color_file
, Sw32_load_color_file
, 1, 1, 0,
1129 "Create an alist of color entries from an external file (ie. rgb.txt).\n\
1130 Assign this value to w32-color-map to replace the existing color map.\n\
1132 The file should define one named RGB color per line like so:\
1134 where R,G,B are numbers between 0 and 255 and name is an arbitrary string.")
1136 Lisp_Object filename
;
1139 Lisp_Object cmap
= Qnil
;
1140 Lisp_Object abspath
;
1142 CHECK_STRING (filename
, 0);
1143 abspath
= Fexpand_file_name (filename
, Qnil
);
1145 fp
= fopen (XSTRING (filename
)->data
, "rt");
1149 int red
, green
, blue
;
1154 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
1155 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
1157 char *name
= buf
+ num
;
1158 num
= strlen (name
) - 1;
1159 if (name
[num
] == '\n')
1161 cmap
= Fcons (Fcons (build_string (name
),
1162 make_number (RGB (red
, green
, blue
))),
1174 /* The default colors for the w32 color map */
1175 typedef struct colormap_t
1181 colormap_t w32_color_map
[] =
1183 {"snow" , PALETTERGB (255,250,250)},
1184 {"ghost white" , PALETTERGB (248,248,255)},
1185 {"GhostWhite" , PALETTERGB (248,248,255)},
1186 {"white smoke" , PALETTERGB (245,245,245)},
1187 {"WhiteSmoke" , PALETTERGB (245,245,245)},
1188 {"gainsboro" , PALETTERGB (220,220,220)},
1189 {"floral white" , PALETTERGB (255,250,240)},
1190 {"FloralWhite" , PALETTERGB (255,250,240)},
1191 {"old lace" , PALETTERGB (253,245,230)},
1192 {"OldLace" , PALETTERGB (253,245,230)},
1193 {"linen" , PALETTERGB (250,240,230)},
1194 {"antique white" , PALETTERGB (250,235,215)},
1195 {"AntiqueWhite" , PALETTERGB (250,235,215)},
1196 {"papaya whip" , PALETTERGB (255,239,213)},
1197 {"PapayaWhip" , PALETTERGB (255,239,213)},
1198 {"blanched almond" , PALETTERGB (255,235,205)},
1199 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
1200 {"bisque" , PALETTERGB (255,228,196)},
1201 {"peach puff" , PALETTERGB (255,218,185)},
1202 {"PeachPuff" , PALETTERGB (255,218,185)},
1203 {"navajo white" , PALETTERGB (255,222,173)},
1204 {"NavajoWhite" , PALETTERGB (255,222,173)},
1205 {"moccasin" , PALETTERGB (255,228,181)},
1206 {"cornsilk" , PALETTERGB (255,248,220)},
1207 {"ivory" , PALETTERGB (255,255,240)},
1208 {"lemon chiffon" , PALETTERGB (255,250,205)},
1209 {"LemonChiffon" , PALETTERGB (255,250,205)},
1210 {"seashell" , PALETTERGB (255,245,238)},
1211 {"honeydew" , PALETTERGB (240,255,240)},
1212 {"mint cream" , PALETTERGB (245,255,250)},
1213 {"MintCream" , PALETTERGB (245,255,250)},
1214 {"azure" , PALETTERGB (240,255,255)},
1215 {"alice blue" , PALETTERGB (240,248,255)},
1216 {"AliceBlue" , PALETTERGB (240,248,255)},
1217 {"lavender" , PALETTERGB (230,230,250)},
1218 {"lavender blush" , PALETTERGB (255,240,245)},
1219 {"LavenderBlush" , PALETTERGB (255,240,245)},
1220 {"misty rose" , PALETTERGB (255,228,225)},
1221 {"MistyRose" , PALETTERGB (255,228,225)},
1222 {"white" , PALETTERGB (255,255,255)},
1223 {"black" , PALETTERGB ( 0, 0, 0)},
1224 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
1225 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
1226 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
1227 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
1228 {"dim gray" , PALETTERGB (105,105,105)},
1229 {"DimGray" , PALETTERGB (105,105,105)},
1230 {"dim grey" , PALETTERGB (105,105,105)},
1231 {"DimGrey" , PALETTERGB (105,105,105)},
1232 {"slate gray" , PALETTERGB (112,128,144)},
1233 {"SlateGray" , PALETTERGB (112,128,144)},
1234 {"slate grey" , PALETTERGB (112,128,144)},
1235 {"SlateGrey" , PALETTERGB (112,128,144)},
1236 {"light slate gray" , PALETTERGB (119,136,153)},
1237 {"LightSlateGray" , PALETTERGB (119,136,153)},
1238 {"light slate grey" , PALETTERGB (119,136,153)},
1239 {"LightSlateGrey" , PALETTERGB (119,136,153)},
1240 {"gray" , PALETTERGB (190,190,190)},
1241 {"grey" , PALETTERGB (190,190,190)},
1242 {"light grey" , PALETTERGB (211,211,211)},
1243 {"LightGrey" , PALETTERGB (211,211,211)},
1244 {"light gray" , PALETTERGB (211,211,211)},
1245 {"LightGray" , PALETTERGB (211,211,211)},
1246 {"midnight blue" , PALETTERGB ( 25, 25,112)},
1247 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
1248 {"navy" , PALETTERGB ( 0, 0,128)},
1249 {"navy blue" , PALETTERGB ( 0, 0,128)},
1250 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
1251 {"cornflower blue" , PALETTERGB (100,149,237)},
1252 {"CornflowerBlue" , PALETTERGB (100,149,237)},
1253 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
1254 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
1255 {"slate blue" , PALETTERGB (106, 90,205)},
1256 {"SlateBlue" , PALETTERGB (106, 90,205)},
1257 {"medium slate blue" , PALETTERGB (123,104,238)},
1258 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
1259 {"light slate blue" , PALETTERGB (132,112,255)},
1260 {"LightSlateBlue" , PALETTERGB (132,112,255)},
1261 {"medium blue" , PALETTERGB ( 0, 0,205)},
1262 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
1263 {"royal blue" , PALETTERGB ( 65,105,225)},
1264 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
1265 {"blue" , PALETTERGB ( 0, 0,255)},
1266 {"dodger blue" , PALETTERGB ( 30,144,255)},
1267 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
1268 {"deep sky blue" , PALETTERGB ( 0,191,255)},
1269 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
1270 {"sky blue" , PALETTERGB (135,206,235)},
1271 {"SkyBlue" , PALETTERGB (135,206,235)},
1272 {"light sky blue" , PALETTERGB (135,206,250)},
1273 {"LightSkyBlue" , PALETTERGB (135,206,250)},
1274 {"steel blue" , PALETTERGB ( 70,130,180)},
1275 {"SteelBlue" , PALETTERGB ( 70,130,180)},
1276 {"light steel blue" , PALETTERGB (176,196,222)},
1277 {"LightSteelBlue" , PALETTERGB (176,196,222)},
1278 {"light blue" , PALETTERGB (173,216,230)},
1279 {"LightBlue" , PALETTERGB (173,216,230)},
1280 {"powder blue" , PALETTERGB (176,224,230)},
1281 {"PowderBlue" , PALETTERGB (176,224,230)},
1282 {"pale turquoise" , PALETTERGB (175,238,238)},
1283 {"PaleTurquoise" , PALETTERGB (175,238,238)},
1284 {"dark turquoise" , PALETTERGB ( 0,206,209)},
1285 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
1286 {"medium turquoise" , PALETTERGB ( 72,209,204)},
1287 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
1288 {"turquoise" , PALETTERGB ( 64,224,208)},
1289 {"cyan" , PALETTERGB ( 0,255,255)},
1290 {"light cyan" , PALETTERGB (224,255,255)},
1291 {"LightCyan" , PALETTERGB (224,255,255)},
1292 {"cadet blue" , PALETTERGB ( 95,158,160)},
1293 {"CadetBlue" , PALETTERGB ( 95,158,160)},
1294 {"medium aquamarine" , PALETTERGB (102,205,170)},
1295 {"MediumAquamarine" , PALETTERGB (102,205,170)},
1296 {"aquamarine" , PALETTERGB (127,255,212)},
1297 {"dark green" , PALETTERGB ( 0,100, 0)},
1298 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
1299 {"dark olive green" , PALETTERGB ( 85,107, 47)},
1300 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
1301 {"dark sea green" , PALETTERGB (143,188,143)},
1302 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
1303 {"sea green" , PALETTERGB ( 46,139, 87)},
1304 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
1305 {"medium sea green" , PALETTERGB ( 60,179,113)},
1306 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
1307 {"light sea green" , PALETTERGB ( 32,178,170)},
1308 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
1309 {"pale green" , PALETTERGB (152,251,152)},
1310 {"PaleGreen" , PALETTERGB (152,251,152)},
1311 {"spring green" , PALETTERGB ( 0,255,127)},
1312 {"SpringGreen" , PALETTERGB ( 0,255,127)},
1313 {"lawn green" , PALETTERGB (124,252, 0)},
1314 {"LawnGreen" , PALETTERGB (124,252, 0)},
1315 {"green" , PALETTERGB ( 0,255, 0)},
1316 {"chartreuse" , PALETTERGB (127,255, 0)},
1317 {"medium spring green" , PALETTERGB ( 0,250,154)},
1318 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
1319 {"green yellow" , PALETTERGB (173,255, 47)},
1320 {"GreenYellow" , PALETTERGB (173,255, 47)},
1321 {"lime green" , PALETTERGB ( 50,205, 50)},
1322 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
1323 {"yellow green" , PALETTERGB (154,205, 50)},
1324 {"YellowGreen" , PALETTERGB (154,205, 50)},
1325 {"forest green" , PALETTERGB ( 34,139, 34)},
1326 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
1327 {"olive drab" , PALETTERGB (107,142, 35)},
1328 {"OliveDrab" , PALETTERGB (107,142, 35)},
1329 {"dark khaki" , PALETTERGB (189,183,107)},
1330 {"DarkKhaki" , PALETTERGB (189,183,107)},
1331 {"khaki" , PALETTERGB (240,230,140)},
1332 {"pale goldenrod" , PALETTERGB (238,232,170)},
1333 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
1334 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
1335 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
1336 {"light yellow" , PALETTERGB (255,255,224)},
1337 {"LightYellow" , PALETTERGB (255,255,224)},
1338 {"yellow" , PALETTERGB (255,255, 0)},
1339 {"gold" , PALETTERGB (255,215, 0)},
1340 {"light goldenrod" , PALETTERGB (238,221,130)},
1341 {"LightGoldenrod" , PALETTERGB (238,221,130)},
1342 {"goldenrod" , PALETTERGB (218,165, 32)},
1343 {"dark goldenrod" , PALETTERGB (184,134, 11)},
1344 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
1345 {"rosy brown" , PALETTERGB (188,143,143)},
1346 {"RosyBrown" , PALETTERGB (188,143,143)},
1347 {"indian red" , PALETTERGB (205, 92, 92)},
1348 {"IndianRed" , PALETTERGB (205, 92, 92)},
1349 {"saddle brown" , PALETTERGB (139, 69, 19)},
1350 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
1351 {"sienna" , PALETTERGB (160, 82, 45)},
1352 {"peru" , PALETTERGB (205,133, 63)},
1353 {"burlywood" , PALETTERGB (222,184,135)},
1354 {"beige" , PALETTERGB (245,245,220)},
1355 {"wheat" , PALETTERGB (245,222,179)},
1356 {"sandy brown" , PALETTERGB (244,164, 96)},
1357 {"SandyBrown" , PALETTERGB (244,164, 96)},
1358 {"tan" , PALETTERGB (210,180,140)},
1359 {"chocolate" , PALETTERGB (210,105, 30)},
1360 {"firebrick" , PALETTERGB (178,34, 34)},
1361 {"brown" , PALETTERGB (165,42, 42)},
1362 {"dark salmon" , PALETTERGB (233,150,122)},
1363 {"DarkSalmon" , PALETTERGB (233,150,122)},
1364 {"salmon" , PALETTERGB (250,128,114)},
1365 {"light salmon" , PALETTERGB (255,160,122)},
1366 {"LightSalmon" , PALETTERGB (255,160,122)},
1367 {"orange" , PALETTERGB (255,165, 0)},
1368 {"dark orange" , PALETTERGB (255,140, 0)},
1369 {"DarkOrange" , PALETTERGB (255,140, 0)},
1370 {"coral" , PALETTERGB (255,127, 80)},
1371 {"light coral" , PALETTERGB (240,128,128)},
1372 {"LightCoral" , PALETTERGB (240,128,128)},
1373 {"tomato" , PALETTERGB (255, 99, 71)},
1374 {"orange red" , PALETTERGB (255, 69, 0)},
1375 {"OrangeRed" , PALETTERGB (255, 69, 0)},
1376 {"red" , PALETTERGB (255, 0, 0)},
1377 {"hot pink" , PALETTERGB (255,105,180)},
1378 {"HotPink" , PALETTERGB (255,105,180)},
1379 {"deep pink" , PALETTERGB (255, 20,147)},
1380 {"DeepPink" , PALETTERGB (255, 20,147)},
1381 {"pink" , PALETTERGB (255,192,203)},
1382 {"light pink" , PALETTERGB (255,182,193)},
1383 {"LightPink" , PALETTERGB (255,182,193)},
1384 {"pale violet red" , PALETTERGB (219,112,147)},
1385 {"PaleVioletRed" , PALETTERGB (219,112,147)},
1386 {"maroon" , PALETTERGB (176, 48, 96)},
1387 {"medium violet red" , PALETTERGB (199, 21,133)},
1388 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
1389 {"violet red" , PALETTERGB (208, 32,144)},
1390 {"VioletRed" , PALETTERGB (208, 32,144)},
1391 {"magenta" , PALETTERGB (255, 0,255)},
1392 {"violet" , PALETTERGB (238,130,238)},
1393 {"plum" , PALETTERGB (221,160,221)},
1394 {"orchid" , PALETTERGB (218,112,214)},
1395 {"medium orchid" , PALETTERGB (186, 85,211)},
1396 {"MediumOrchid" , PALETTERGB (186, 85,211)},
1397 {"dark orchid" , PALETTERGB (153, 50,204)},
1398 {"DarkOrchid" , PALETTERGB (153, 50,204)},
1399 {"dark violet" , PALETTERGB (148, 0,211)},
1400 {"DarkViolet" , PALETTERGB (148, 0,211)},
1401 {"blue violet" , PALETTERGB (138, 43,226)},
1402 {"BlueViolet" , PALETTERGB (138, 43,226)},
1403 {"purple" , PALETTERGB (160, 32,240)},
1404 {"medium purple" , PALETTERGB (147,112,219)},
1405 {"MediumPurple" , PALETTERGB (147,112,219)},
1406 {"thistle" , PALETTERGB (216,191,216)},
1407 {"gray0" , PALETTERGB ( 0, 0, 0)},
1408 {"grey0" , PALETTERGB ( 0, 0, 0)},
1409 {"dark grey" , PALETTERGB (169,169,169)},
1410 {"DarkGrey" , PALETTERGB (169,169,169)},
1411 {"dark gray" , PALETTERGB (169,169,169)},
1412 {"DarkGray" , PALETTERGB (169,169,169)},
1413 {"dark blue" , PALETTERGB ( 0, 0,139)},
1414 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
1415 {"dark cyan" , PALETTERGB ( 0,139,139)},
1416 {"DarkCyan" , PALETTERGB ( 0,139,139)},
1417 {"dark magenta" , PALETTERGB (139, 0,139)},
1418 {"DarkMagenta" , PALETTERGB (139, 0,139)},
1419 {"dark red" , PALETTERGB (139, 0, 0)},
1420 {"DarkRed" , PALETTERGB (139, 0, 0)},
1421 {"light green" , PALETTERGB (144,238,144)},
1422 {"LightGreen" , PALETTERGB (144,238,144)},
1425 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
1426 0, 0, 0, "Return the default color map.")
1430 colormap_t
*pc
= w32_color_map
;
1437 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
1439 cmap
= Fcons (Fcons (build_string (pc
->name
),
1440 make_number (pc
->colorref
)),
1449 w32_to_x_color (rgb
)
1454 CHECK_NUMBER (rgb
, 0);
1458 color
= Frassq (rgb
, Vw32_color_map
);
1463 return (Fcar (color
));
1469 w32_color_map_lookup (colorname
)
1472 Lisp_Object tail
, ret
= Qnil
;
1476 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
1478 register Lisp_Object elt
, tem
;
1481 if (!CONSP (elt
)) continue;
1485 if (lstrcmpi (XSTRING (tem
)->data
, colorname
) == 0)
1487 ret
= XUINT (Fcdr (elt
));
1501 x_to_w32_color (colorname
)
1504 register Lisp_Object tail
, ret
= Qnil
;
1508 if (colorname
[0] == '#')
1510 /* Could be an old-style RGB Device specification. */
1513 color
= colorname
+ 1;
1515 size
= strlen(color
);
1516 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
1524 for (i
= 0; i
< 3; i
++)
1528 unsigned long value
;
1530 /* The check for 'x' in the following conditional takes into
1531 account the fact that strtol allows a "0x" in front of
1532 our numbers, and we don't. */
1533 if (!isxdigit(color
[0]) || color
[1] == 'x')
1537 value
= strtoul(color
, &end
, 16);
1539 if (errno
== ERANGE
|| end
- color
!= size
)
1544 value
= value
* 0x10;
1555 colorval
|= (value
<< pos
);
1566 else if (strnicmp(colorname
, "rgb:", 4) == 0)
1574 color
= colorname
+ 4;
1575 for (i
= 0; i
< 3; i
++)
1578 unsigned long value
;
1580 /* The check for 'x' in the following conditional takes into
1581 account the fact that strtol allows a "0x" in front of
1582 our numbers, and we don't. */
1583 if (!isxdigit(color
[0]) || color
[1] == 'x')
1585 value
= strtoul(color
, &end
, 16);
1586 if (errno
== ERANGE
)
1588 switch (end
- color
)
1591 value
= value
* 0x10 + value
;
1604 if (value
== ULONG_MAX
)
1606 colorval
|= (value
<< pos
);
1620 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1622 /* This is an RGB Intensity specification. */
1629 color
= colorname
+ 5;
1630 for (i
= 0; i
< 3; i
++)
1636 value
= strtod(color
, &end
);
1637 if (errno
== ERANGE
)
1639 if (value
< 0.0 || value
> 1.0)
1641 val
= (UINT
)(0x100 * value
);
1642 /* We used 0x100 instead of 0xFF to give an continuous
1643 range between 0.0 and 1.0 inclusive. The next statement
1644 fixes the 1.0 case. */
1647 colorval
|= (val
<< pos
);
1661 /* I am not going to attempt to handle any of the CIE color schemes
1662 or TekHVC, since I don't know the algorithms for conversion to
1665 /* If we fail to lookup the color name in w32_color_map, then check the
1666 colorname to see if it can be crudely approximated: If the X color
1667 ends in a number (e.g., "darkseagreen2"), strip the number and
1668 return the result of looking up the base color name. */
1669 ret
= w32_color_map_lookup (colorname
);
1672 int len
= strlen (colorname
);
1674 if (isdigit (colorname
[len
- 1]))
1676 char *ptr
, *approx
= alloca (len
);
1678 strcpy (approx
, colorname
);
1679 ptr
= &approx
[len
- 1];
1680 while (ptr
> approx
&& isdigit (*ptr
))
1683 ret
= w32_color_map_lookup (approx
);
1693 w32_regenerate_palette (FRAME_PTR f
)
1695 struct w32_palette_entry
* list
;
1696 LOGPALETTE
* log_palette
;
1697 HPALETTE new_palette
;
1700 /* don't bother trying to create palette if not supported */
1701 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1704 log_palette
= (LOGPALETTE
*)
1705 alloca (sizeof (LOGPALETTE
) +
1706 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1707 log_palette
->palVersion
= 0x300;
1708 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1710 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1712 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1713 i
++, list
= list
->next
)
1714 log_palette
->palPalEntry
[i
] = list
->entry
;
1716 new_palette
= CreatePalette (log_palette
);
1720 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1721 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1722 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1724 /* Realize display palette and garbage all frames. */
1725 release_frame_dc (f
, get_frame_dc (f
));
1730 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1731 #define SET_W32_COLOR(pe, color) \
1734 pe.peRed = GetRValue (color); \
1735 pe.peGreen = GetGValue (color); \
1736 pe.peBlue = GetBValue (color); \
1741 /* Keep these around in case we ever want to track color usage. */
1743 w32_map_color (FRAME_PTR f
, COLORREF color
)
1745 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1747 if (NILP (Vw32_enable_palette
))
1750 /* check if color is already mapped */
1753 if (W32_COLOR (list
->entry
) == color
)
1761 /* not already mapped, so add to list and recreate Windows palette */
1762 list
= (struct w32_palette_entry
*)
1763 xmalloc (sizeof (struct w32_palette_entry
));
1764 SET_W32_COLOR (list
->entry
, color
);
1766 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1767 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1768 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1770 /* set flag that palette must be regenerated */
1771 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1775 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1777 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1778 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1780 if (NILP (Vw32_enable_palette
))
1783 /* check if color is already mapped */
1786 if (W32_COLOR (list
->entry
) == color
)
1788 if (--list
->refcount
== 0)
1792 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1802 /* set flag that palette must be regenerated */
1803 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1808 /* Gamma-correct COLOR on frame F. */
1811 gamma_correct (f
, color
)
1817 *color
= PALETTERGB (
1818 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1819 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1820 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1825 /* Decide if color named COLOR is valid for the display associated with
1826 the selected frame; if so, return the rgb values in COLOR_DEF.
1827 If ALLOC is nonzero, allocate a new colormap cell. */
1830 w32_defined_color (f
, color
, color_def
, alloc
)
1836 register Lisp_Object tem
;
1837 COLORREF w32_color_ref
;
1839 tem
= x_to_w32_color (color
);
1845 /* Apply gamma correction. */
1846 w32_color_ref
= XUINT (tem
);
1847 gamma_correct (f
, &w32_color_ref
);
1848 XSETINT (tem
, w32_color_ref
);
1851 /* Map this color to the palette if it is enabled. */
1852 if (!NILP (Vw32_enable_palette
))
1854 struct w32_palette_entry
* entry
=
1855 one_w32_display_info
.color_list
;
1856 struct w32_palette_entry
** prev
=
1857 &one_w32_display_info
.color_list
;
1859 /* check if color is already mapped */
1862 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1864 prev
= &entry
->next
;
1865 entry
= entry
->next
;
1868 if (entry
== NULL
&& alloc
)
1870 /* not already mapped, so add to list */
1871 entry
= (struct w32_palette_entry
*)
1872 xmalloc (sizeof (struct w32_palette_entry
));
1873 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1876 one_w32_display_info
.num_colors
++;
1878 /* set flag that palette must be regenerated */
1879 one_w32_display_info
.regen_palette
= TRUE
;
1882 /* Ensure COLORREF value is snapped to nearest color in (default)
1883 palette by simulating the PALETTERGB macro. This works whether
1884 or not the display device has a palette. */
1885 w32_color_ref
= XUINT (tem
) | 0x2000000;
1887 color_def
->pixel
= w32_color_ref
;
1888 color_def
->red
= GetRValue (w32_color_ref
);
1889 color_def
->green
= GetGValue (w32_color_ref
);
1890 color_def
->blue
= GetBValue (w32_color_ref
);
1900 /* Given a string ARG naming a color, compute a pixel value from it
1901 suitable for screen F.
1902 If F is not a color screen, return DEF (default) regardless of what
1906 x_decode_color (f
, arg
, def
)
1913 CHECK_STRING (arg
, 0);
1915 if (strcmp (XSTRING (arg
)->data
, "black") == 0)
1916 return BLACK_PIX_DEFAULT (f
);
1917 else if (strcmp (XSTRING (arg
)->data
, "white") == 0)
1918 return WHITE_PIX_DEFAULT (f
);
1920 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1923 /* w32_defined_color is responsible for coping with failures
1924 by looking for a near-miss. */
1925 if (w32_defined_color (f
, XSTRING (arg
)->data
, &cdef
, 1))
1928 /* defined_color failed; return an ultimate default. */
1932 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
1933 the previous value of that parameter, NEW_VALUE is the new value. */
1936 x_set_line_spacing (f
, new_value
, old_value
)
1938 Lisp_Object new_value
, old_value
;
1940 if (NILP (new_value
))
1941 f
->extra_line_spacing
= 0;
1942 else if (NATNUMP (new_value
))
1943 f
->extra_line_spacing
= XFASTINT (new_value
);
1945 Fsignal (Qerror
, Fcons (build_string ("Invalid line-spacing"),
1946 Fcons (new_value
, Qnil
)));
1947 if (FRAME_VISIBLE_P (f
))
1952 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
1953 the previous value of that parameter, NEW_VALUE is the new value. */
1956 x_set_screen_gamma (f
, new_value
, old_value
)
1958 Lisp_Object new_value
, old_value
;
1960 if (NILP (new_value
))
1962 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
1963 /* The value 0.4545 is the normal viewing gamma. */
1964 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
1966 Fsignal (Qerror
, Fcons (build_string ("Invalid screen-gamma"),
1967 Fcons (new_value
, Qnil
)));
1969 clear_face_cache (0);
1973 /* Functions called only from `x_set_frame_param'
1974 to set individual parameters.
1976 If FRAME_W32_WINDOW (f) is 0,
1977 the frame is being created and its window does not exist yet.
1978 In that case, just record the parameter's new value
1979 in the standard place; do not attempt to change the window. */
1982 x_set_foreground_color (f
, arg
, oldval
)
1984 Lisp_Object arg
, oldval
;
1986 FRAME_FOREGROUND_PIXEL (f
)
1987 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1989 if (FRAME_W32_WINDOW (f
) != 0)
1991 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1992 if (FRAME_VISIBLE_P (f
))
1998 x_set_background_color (f
, arg
, oldval
)
2000 Lisp_Object arg
, oldval
;
2002 FRAME_BACKGROUND_PIXEL (f
)
2003 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
2005 if (FRAME_W32_WINDOW (f
) != 0)
2007 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
2008 FRAME_BACKGROUND_PIXEL (f
));
2010 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
2012 if (FRAME_VISIBLE_P (f
))
2018 x_set_mouse_color (f
, arg
, oldval
)
2020 Lisp_Object arg
, oldval
;
2023 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
2027 if (!EQ (Qnil
, arg
))
2028 f
->output_data
.w32
->mouse_pixel
2029 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2030 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
2032 /* Don't let pointers be invisible. */
2033 if (mask_color
== f
->output_data
.w32
->mouse_pixel
2034 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
2035 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
2037 #if 0 /* TODO : cursor changes */
2040 /* It's not okay to crash if the user selects a screwy cursor. */
2041 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
2043 if (!EQ (Qnil
, Vx_pointer_shape
))
2045 CHECK_NUMBER (Vx_pointer_shape
, 0);
2046 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
2049 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2050 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
2052 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
2054 CHECK_NUMBER (Vx_nontext_pointer_shape
, 0);
2055 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2056 XINT (Vx_nontext_pointer_shape
));
2059 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
2060 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2062 if (!EQ (Qnil
, Vx_busy_pointer_shape
))
2064 CHECK_NUMBER (Vx_busy_pointer_shape
, 0);
2065 busy_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2066 XINT (Vx_busy_pointer_shape
));
2069 busy_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
2070 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
2072 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2073 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
2075 CHECK_NUMBER (Vx_mode_pointer_shape
, 0);
2076 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2077 XINT (Vx_mode_pointer_shape
));
2080 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2081 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
2083 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
2085 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
, 0);
2087 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2088 XINT (Vx_sensitive_text_pointer_shape
));
2091 cross_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
2093 /* Check and report errors with the above calls. */
2094 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
2095 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
2098 XColor fore_color
, back_color
;
2100 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
2101 back_color
.pixel
= mask_color
;
2102 XQueryColor (FRAME_W32_DISPLAY (f
),
2103 DefaultColormap (FRAME_W32_DISPLAY (f
),
2104 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2106 XQueryColor (FRAME_W32_DISPLAY (f
),
2107 DefaultColormap (FRAME_W32_DISPLAY (f
),
2108 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2110 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
2111 &fore_color
, &back_color
);
2112 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
2113 &fore_color
, &back_color
);
2114 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
2115 &fore_color
, &back_color
);
2116 XRecolorCursor (FRAME_W32_DISPLAY (f
), cross_cursor
,
2117 &fore_color
, &back_color
);
2118 XRecolorCursor (FRAME_W32_DISPLAY (f
), busy_cursor
,
2119 &fore_color
, &back_color
);
2122 if (FRAME_W32_WINDOW (f
) != 0)
2123 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
2125 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
2126 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
2127 f
->output_data
.w32
->text_cursor
= cursor
;
2129 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
2130 && f
->output_data
.w32
->nontext_cursor
!= 0)
2131 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
2132 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
2134 if (busy_cursor
!= f
->output_data
.w32
->busy_cursor
2135 && f
->output_data
.w32
->busy_cursor
!= 0)
2136 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->busy_cursor
);
2137 f
->output_data
.w32
->busy_cursor
= busy_cursor
;
2139 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
2140 && f
->output_data
.w32
->modeline_cursor
!= 0)
2141 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
2142 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
2144 if (cross_cursor
!= f
->output_data
.w32
->cross_cursor
2145 && f
->output_data
.w32
->cross_cursor
!= 0)
2146 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->cross_cursor
);
2147 f
->output_data
.w32
->cross_cursor
= cross_cursor
;
2149 XFlush (FRAME_W32_DISPLAY (f
));
2152 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
2157 x_set_cursor_color (f
, arg
, oldval
)
2159 Lisp_Object arg
, oldval
;
2161 unsigned long fore_pixel
;
2163 if (!NILP (Vx_cursor_fore_pixel
))
2164 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
2165 WHITE_PIX_DEFAULT (f
));
2167 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2168 f
->output_data
.w32
->cursor_pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2170 /* Make sure that the cursor color differs from the background color. */
2171 if (f
->output_data
.w32
->cursor_pixel
== FRAME_BACKGROUND_PIXEL (f
))
2173 f
->output_data
.w32
->cursor_pixel
= f
->output_data
.w32
->mouse_pixel
;
2174 if (f
->output_data
.w32
->cursor_pixel
== fore_pixel
)
2175 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2177 FRAME_FOREGROUND_PIXEL (f
) = fore_pixel
;
2179 if (FRAME_W32_WINDOW (f
) != 0)
2181 if (FRAME_VISIBLE_P (f
))
2183 x_display_cursor (f
, 0);
2184 x_display_cursor (f
, 1);
2188 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
2191 /* Set the border-color of frame F to pixel value PIX.
2192 Note that this does not fully take effect if done before
2195 x_set_border_pixel (f
, pix
)
2199 f
->output_data
.w32
->border_pixel
= pix
;
2201 if (FRAME_W32_WINDOW (f
) != 0 && f
->output_data
.w32
->border_width
> 0)
2203 if (FRAME_VISIBLE_P (f
))
2208 /* Set the border-color of frame F to value described by ARG.
2209 ARG can be a string naming a color.
2210 The border-color is used for the border that is drawn by the server.
2211 Note that this does not fully take effect if done before
2212 F has a window; it must be redone when the window is created. */
2215 x_set_border_color (f
, arg
, oldval
)
2217 Lisp_Object arg
, oldval
;
2221 CHECK_STRING (arg
, 0);
2222 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2223 x_set_border_pixel (f
, pix
);
2224 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
2227 /* Value is the internal representation of the specified cursor type
2228 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
2229 of the bar cursor. */
2231 enum text_cursor_kinds
2232 x_specified_cursor_type (arg
, width
)
2236 enum text_cursor_kinds type
;
2243 else if (CONSP (arg
)
2244 && EQ (XCAR (arg
), Qbar
)
2245 && INTEGERP (XCDR (arg
))
2246 && XINT (XCDR (arg
)) >= 0)
2249 *width
= XINT (XCDR (arg
));
2251 else if (NILP (arg
))
2254 /* Treat anything unknown as "box cursor".
2255 It was bad to signal an error; people have trouble fixing
2256 .Xdefaults with Emacs, when it has something bad in it. */
2257 type
= FILLED_BOX_CURSOR
;
2263 x_set_cursor_type (f
, arg
, oldval
)
2265 Lisp_Object arg
, oldval
;
2269 FRAME_DESIRED_CURSOR (f
) = x_specified_cursor_type (arg
, &width
);
2270 f
->output_data
.w32
->cursor_width
= width
;
2272 /* Make sure the cursor gets redrawn. This is overkill, but how
2273 often do people change cursor types? */
2274 update_mode_lines
++;
2278 x_set_icon_type (f
, arg
, oldval
)
2280 Lisp_Object arg
, oldval
;
2284 if (NILP (arg
) && NILP (oldval
))
2287 if (STRINGP (arg
) && STRINGP (oldval
)
2288 && EQ (Fstring_equal (oldval
, arg
), Qt
))
2291 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
2296 result
= x_bitmap_icon (f
, arg
);
2300 error ("No icon window available");
2306 /* Return non-nil if frame F wants a bitmap icon. */
2314 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
2322 x_set_icon_name (f
, arg
, oldval
)
2324 Lisp_Object arg
, oldval
;
2330 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
2333 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
2339 if (f
->output_data
.w32
->icon_bitmap
!= 0)
2344 result
= x_text_icon (f
,
2345 (char *) XSTRING ((!NILP (f
->icon_name
)
2354 error ("No icon window available");
2357 /* If the window was unmapped (and its icon was mapped),
2358 the new icon is not mapped, so map the window in its stead. */
2359 if (FRAME_VISIBLE_P (f
))
2361 #ifdef USE_X_TOOLKIT
2362 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
2364 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
2367 XFlush (FRAME_W32_DISPLAY (f
));
2372 extern Lisp_Object
x_new_font ();
2373 extern Lisp_Object
x_new_fontset();
2376 x_set_font (f
, arg
, oldval
)
2378 Lisp_Object arg
, oldval
;
2381 Lisp_Object fontset_name
;
2384 CHECK_STRING (arg
, 1);
2386 fontset_name
= Fquery_fontset (arg
, Qnil
);
2389 result
= (STRINGP (fontset_name
)
2390 ? x_new_fontset (f
, XSTRING (fontset_name
)->data
)
2391 : x_new_font (f
, XSTRING (arg
)->data
));
2394 if (EQ (result
, Qnil
))
2395 error ("Font `%s' is not defined", XSTRING (arg
)->data
);
2396 else if (EQ (result
, Qt
))
2397 error ("The characters of the given font have varying widths");
2398 else if (STRINGP (result
))
2400 store_frame_param (f
, Qfont
, result
);
2401 recompute_basic_faces (f
);
2406 do_pending_window_change (0);
2408 /* Don't call `face-set-after-frame-default' when faces haven't been
2409 initialized yet. This is the case when called from
2410 Fx_create_frame. In that case, the X widget or window doesn't
2411 exist either, and we can end up in x_report_frame_params with a
2412 null widget which gives a segfault. */
2413 if (FRAME_FACE_CACHE (f
))
2415 XSETFRAME (frame
, f
);
2416 call1 (Qface_set_after_frame_default
, frame
);
2421 x_set_border_width (f
, arg
, oldval
)
2423 Lisp_Object arg
, oldval
;
2425 CHECK_NUMBER (arg
, 0);
2427 if (XINT (arg
) == f
->output_data
.w32
->border_width
)
2430 if (FRAME_W32_WINDOW (f
) != 0)
2431 error ("Cannot change the border width of a window");
2433 f
->output_data
.w32
->border_width
= XINT (arg
);
2437 x_set_internal_border_width (f
, arg
, oldval
)
2439 Lisp_Object arg
, oldval
;
2441 int old
= f
->output_data
.w32
->internal_border_width
;
2443 CHECK_NUMBER (arg
, 0);
2444 f
->output_data
.w32
->internal_border_width
= XINT (arg
);
2445 if (f
->output_data
.w32
->internal_border_width
< 0)
2446 f
->output_data
.w32
->internal_border_width
= 0;
2448 if (f
->output_data
.w32
->internal_border_width
== old
)
2451 if (FRAME_W32_WINDOW (f
) != 0)
2453 x_set_window_size (f
, 0, f
->width
, f
->height
);
2454 SET_FRAME_GARBAGED (f
);
2455 do_pending_window_change (0);
2460 x_set_visibility (f
, value
, oldval
)
2462 Lisp_Object value
, oldval
;
2465 XSETFRAME (frame
, f
);
2468 Fmake_frame_invisible (frame
, Qt
);
2469 else if (EQ (value
, Qicon
))
2470 Ficonify_frame (frame
);
2472 Fmake_frame_visible (frame
);
2476 /* Change window heights in windows rooted in WINDOW by N lines. */
2479 x_change_window_heights (window
, n
)
2483 struct window
*w
= XWINDOW (window
);
2485 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
2486 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
2488 if (INTEGERP (w
->orig_top
))
2489 XSETFASTINT (w
->orig_top
, XFASTINT (w
->orig_top
) + n
);
2490 if (INTEGERP (w
->orig_height
))
2491 XSETFASTINT (w
->orig_height
, XFASTINT (w
->orig_height
) - n
);
2493 /* Handle just the top child in a vertical split. */
2494 if (!NILP (w
->vchild
))
2495 x_change_window_heights (w
->vchild
, n
);
2497 /* Adjust all children in a horizontal split. */
2498 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2500 w
= XWINDOW (window
);
2501 x_change_window_heights (window
, n
);
2506 x_set_menu_bar_lines (f
, value
, oldval
)
2508 Lisp_Object value
, oldval
;
2511 int olines
= FRAME_MENU_BAR_LINES (f
);
2513 /* Right now, menu bars don't work properly in minibuf-only frames;
2514 most of the commands try to apply themselves to the minibuffer
2515 frame itself, and get an error because you can't switch buffers
2516 in or split the minibuffer window. */
2517 if (FRAME_MINIBUF_ONLY_P (f
))
2520 if (INTEGERP (value
))
2521 nlines
= XINT (value
);
2525 FRAME_MENU_BAR_LINES (f
) = 0;
2527 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2530 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2531 free_frame_menubar (f
);
2532 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2534 /* Adjust the frame size so that the client (text) dimensions
2535 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
2537 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2538 do_pending_window_change (0);
2544 /* Set the number of lines used for the tool bar of frame F to VALUE.
2545 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2546 is the old number of tool bar lines. This function changes the
2547 height of all windows on frame F to match the new tool bar height.
2548 The frame's height doesn't change. */
2551 x_set_tool_bar_lines (f
, value
, oldval
)
2553 Lisp_Object value
, oldval
;
2555 int delta
, nlines
, root_height
;
2556 Lisp_Object root_window
;
2558 /* Use VALUE only if an integer >= 0. */
2559 if (INTEGERP (value
) && XINT (value
) >= 0)
2560 nlines
= XFASTINT (value
);
2564 /* Make sure we redisplay all windows in this frame. */
2565 ++windows_or_buffers_changed
;
2567 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2569 /* Don't resize the tool-bar to more than we have room for. */
2570 root_window
= FRAME_ROOT_WINDOW (f
);
2571 root_height
= XINT (XWINDOW (root_window
)->height
);
2572 if (root_height
- delta
< 1)
2574 delta
= root_height
- 1;
2575 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
2578 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2579 x_change_window_heights (root_window
, delta
);
2582 /* We also have to make sure that the internal border at the top of
2583 the frame, below the menu bar or tool bar, is redrawn when the
2584 tool bar disappears. This is so because the internal border is
2585 below the tool bar if one is displayed, but is below the menu bar
2586 if there isn't a tool bar. The tool bar draws into the area
2587 below the menu bar. */
2588 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
2592 clear_current_matrices (f
);
2593 updating_frame
= NULL
;
2596 /* If the tool bar gets smaller, the internal border below it
2597 has to be cleared. It was formerly part of the display
2598 of the larger tool bar, and updating windows won't clear it. */
2601 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2602 int width
= PIXEL_WIDTH (f
);
2603 int y
= nlines
* CANON_Y_UNIT (f
);
2607 HDC hdc
= get_frame_dc (f
);
2608 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
2609 release_frame_dc (f
, hdc
);
2616 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2619 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2620 name; if NAME is a string, set F's name to NAME and set
2621 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2623 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2624 suggesting a new name, which lisp code should override; if
2625 F->explicit_name is set, ignore the new name; otherwise, set it. */
2628 x_set_name (f
, name
, explicit)
2633 /* Make sure that requests from lisp code override requests from
2634 Emacs redisplay code. */
2637 /* If we're switching from explicit to implicit, we had better
2638 update the mode lines and thereby update the title. */
2639 if (f
->explicit_name
&& NILP (name
))
2640 update_mode_lines
= 1;
2642 f
->explicit_name
= ! NILP (name
);
2644 else if (f
->explicit_name
)
2647 /* If NAME is nil, set the name to the w32_id_name. */
2650 /* Check for no change needed in this very common case
2651 before we do any consing. */
2652 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
2653 XSTRING (f
->name
)->data
))
2655 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
2658 CHECK_STRING (name
, 0);
2660 /* Don't change the name if it's already NAME. */
2661 if (! NILP (Fstring_equal (name
, f
->name
)))
2666 /* For setting the frame title, the title parameter should override
2667 the name parameter. */
2668 if (! NILP (f
->title
))
2671 if (FRAME_W32_WINDOW (f
))
2673 if (STRING_MULTIBYTE (name
))
2674 name
= ENCODE_SYSTEM (name
);
2677 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2682 /* This function should be called when the user's lisp code has
2683 specified a name for the frame; the name will override any set by the
2686 x_explicitly_set_name (f
, arg
, oldval
)
2688 Lisp_Object arg
, oldval
;
2690 x_set_name (f
, arg
, 1);
2693 /* This function should be called by Emacs redisplay code to set the
2694 name; names set this way will never override names set by the user's
2697 x_implicitly_set_name (f
, arg
, oldval
)
2699 Lisp_Object arg
, oldval
;
2701 x_set_name (f
, arg
, 0);
2704 /* Change the title of frame F to NAME.
2705 If NAME is nil, use the frame name as the title.
2707 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2708 name; if NAME is a string, set F's name to NAME and set
2709 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2711 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2712 suggesting a new name, which lisp code should override; if
2713 F->explicit_name is set, ignore the new name; otherwise, set it. */
2716 x_set_title (f
, name
, old_name
)
2718 Lisp_Object name
, old_name
;
2720 /* Don't change the title if it's already NAME. */
2721 if (EQ (name
, f
->title
))
2724 update_mode_lines
= 1;
2731 if (FRAME_W32_WINDOW (f
))
2733 if (STRING_MULTIBYTE (name
))
2734 name
= ENCODE_SYSTEM (name
);
2737 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2743 x_set_autoraise (f
, arg
, oldval
)
2745 Lisp_Object arg
, oldval
;
2747 f
->auto_raise
= !EQ (Qnil
, arg
);
2751 x_set_autolower (f
, arg
, oldval
)
2753 Lisp_Object arg
, oldval
;
2755 f
->auto_lower
= !EQ (Qnil
, arg
);
2759 x_set_unsplittable (f
, arg
, oldval
)
2761 Lisp_Object arg
, oldval
;
2763 f
->no_split
= !NILP (arg
);
2767 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2769 Lisp_Object arg
, oldval
;
2771 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2772 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2773 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2774 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2776 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = NILP (arg
) ?
2777 vertical_scroll_bar_none
:
2778 /* Put scroll bars on the right by default, as is conventional
2781 ? vertical_scroll_bar_left
2782 : vertical_scroll_bar_right
;
2784 /* We set this parameter before creating the window for the
2785 frame, so we can get the geometry right from the start.
2786 However, if the window hasn't been created yet, we shouldn't
2787 call x_set_window_size. */
2788 if (FRAME_W32_WINDOW (f
))
2789 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2790 do_pending_window_change (0);
2795 x_set_scroll_bar_width (f
, arg
, oldval
)
2797 Lisp_Object arg
, oldval
;
2799 int wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
2803 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2804 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) +
2806 if (FRAME_W32_WINDOW (f
))
2807 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2808 do_pending_window_change (0);
2810 else if (INTEGERP (arg
) && XINT (arg
) > 0
2811 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2813 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2814 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2816 if (FRAME_W32_WINDOW (f
))
2817 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2818 do_pending_window_change (0);
2820 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2821 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2822 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2825 /* Subroutines of creating an frame. */
2827 /* Make sure that Vx_resource_name is set to a reasonable value.
2828 Fix it up, or set it to `emacs' if it is too hopeless. */
2831 validate_x_resource_name ()
2834 /* Number of valid characters in the resource name. */
2836 /* Number of invalid characters in the resource name. */
2841 if (STRINGP (Vx_resource_name
))
2843 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
2846 len
= STRING_BYTES (XSTRING (Vx_resource_name
));
2848 /* Only letters, digits, - and _ are valid in resource names.
2849 Count the valid characters and count the invalid ones. */
2850 for (i
= 0; i
< len
; i
++)
2853 if (! ((c
>= 'a' && c
<= 'z')
2854 || (c
>= 'A' && c
<= 'Z')
2855 || (c
>= '0' && c
<= '9')
2856 || c
== '-' || c
== '_'))
2863 /* Not a string => completely invalid. */
2864 bad_count
= 5, good_count
= 0;
2866 /* If name is valid already, return. */
2870 /* If name is entirely invalid, or nearly so, use `emacs'. */
2872 || (good_count
== 1 && bad_count
> 0))
2874 Vx_resource_name
= build_string ("emacs");
2878 /* Name is partly valid. Copy it and replace the invalid characters
2879 with underscores. */
2881 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
2883 for (i
= 0; i
< len
; i
++)
2885 int c
= XSTRING (new)->data
[i
];
2886 if (! ((c
>= 'a' && c
<= 'z')
2887 || (c
>= 'A' && c
<= 'Z')
2888 || (c
>= '0' && c
<= '9')
2889 || c
== '-' || c
== '_'))
2890 XSTRING (new)->data
[i
] = '_';
2895 extern char *x_get_string_resource ();
2897 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
2898 "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
2899 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
2900 class, where INSTANCE is the name under which Emacs was invoked, or\n\
2901 the name specified by the `-name' or `-rn' command-line arguments.\n\
2903 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
2904 class, respectively. You must specify both of them or neither.\n\
2905 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
2906 and the class is `Emacs.CLASS.SUBCLASS'.")
2907 (attribute
, class, component
, subclass
)
2908 Lisp_Object attribute
, class, component
, subclass
;
2910 register char *value
;
2914 CHECK_STRING (attribute
, 0);
2915 CHECK_STRING (class, 0);
2917 if (!NILP (component
))
2918 CHECK_STRING (component
, 1);
2919 if (!NILP (subclass
))
2920 CHECK_STRING (subclass
, 2);
2921 if (NILP (component
) != NILP (subclass
))
2922 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
2924 validate_x_resource_name ();
2926 /* Allocate space for the components, the dots which separate them,
2927 and the final '\0'. Make them big enough for the worst case. */
2928 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vx_resource_name
))
2929 + (STRINGP (component
)
2930 ? STRING_BYTES (XSTRING (component
)) : 0)
2931 + STRING_BYTES (XSTRING (attribute
))
2934 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2935 + STRING_BYTES (XSTRING (class))
2936 + (STRINGP (subclass
)
2937 ? STRING_BYTES (XSTRING (subclass
)) : 0)
2940 /* Start with emacs.FRAMENAME for the name (the specific one)
2941 and with `Emacs' for the class key (the general one). */
2942 strcpy (name_key
, XSTRING (Vx_resource_name
)->data
);
2943 strcpy (class_key
, EMACS_CLASS
);
2945 strcat (class_key
, ".");
2946 strcat (class_key
, XSTRING (class)->data
);
2948 if (!NILP (component
))
2950 strcat (class_key
, ".");
2951 strcat (class_key
, XSTRING (subclass
)->data
);
2953 strcat (name_key
, ".");
2954 strcat (name_key
, XSTRING (component
)->data
);
2957 strcat (name_key
, ".");
2958 strcat (name_key
, XSTRING (attribute
)->data
);
2960 value
= x_get_string_resource (Qnil
,
2961 name_key
, class_key
);
2963 if (value
!= (char *) 0)
2964 return build_string (value
);
2969 /* Used when C code wants a resource value. */
2972 x_get_resource_string (attribute
, class)
2973 char *attribute
, *class;
2977 struct frame
*sf
= SELECTED_FRAME ();
2979 /* Allocate space for the components, the dots which separate them,
2980 and the final '\0'. */
2981 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vinvocation_name
))
2982 + strlen (attribute
) + 2);
2983 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2984 + strlen (class) + 2);
2986 sprintf (name_key
, "%s.%s",
2987 XSTRING (Vinvocation_name
)->data
,
2989 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
2991 return x_get_string_resource (sf
, name_key
, class_key
);
2994 /* Types we might convert a resource string into. */
3004 /* Return the value of parameter PARAM.
3006 First search ALIST, then Vdefault_frame_alist, then the X defaults
3007 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3009 Convert the resource to the type specified by desired_type.
3011 If no default is specified, return Qunbound. If you call
3012 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
3013 and don't let it get stored in any Lisp-visible variables! */
3016 w32_get_arg (alist
, param
, attribute
, class, type
)
3017 Lisp_Object alist
, param
;
3020 enum resource_types type
;
3022 register Lisp_Object tem
;
3024 tem
= Fassq (param
, alist
);
3026 tem
= Fassq (param
, Vdefault_frame_alist
);
3032 tem
= Fx_get_resource (build_string (attribute
),
3033 build_string (class),
3041 case RES_TYPE_NUMBER
:
3042 return make_number (atoi (XSTRING (tem
)->data
));
3044 case RES_TYPE_FLOAT
:
3045 return make_float (atof (XSTRING (tem
)->data
));
3047 case RES_TYPE_BOOLEAN
:
3048 tem
= Fdowncase (tem
);
3049 if (!strcmp (XSTRING (tem
)->data
, "on")
3050 || !strcmp (XSTRING (tem
)->data
, "true"))
3055 case RES_TYPE_STRING
:
3058 case RES_TYPE_SYMBOL
:
3059 /* As a special case, we map the values `true' and `on'
3060 to Qt, and `false' and `off' to Qnil. */
3063 lower
= Fdowncase (tem
);
3064 if (!strcmp (XSTRING (lower
)->data
, "on")
3065 || !strcmp (XSTRING (lower
)->data
, "true"))
3067 else if (!strcmp (XSTRING (lower
)->data
, "off")
3068 || !strcmp (XSTRING (lower
)->data
, "false"))
3071 return Fintern (tem
, Qnil
);
3084 /* Record in frame F the specified or default value according to ALIST
3085 of the parameter named PROP (a Lisp symbol).
3086 If no value is specified for PROP, look for an X default for XPROP
3087 on the frame named NAME.
3088 If that is not found either, use the value DEFLT. */
3091 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3098 enum resource_types type
;
3102 tem
= w32_get_arg (alist
, prop
, xprop
, xclass
, type
);
3103 if (EQ (tem
, Qunbound
))
3105 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3109 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3110 "Parse an X-style geometry string STRING.\n\
3111 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
3112 The properties returned may include `top', `left', `height', and `width'.\n\
3113 The value of `left' or `top' may be an integer,\n\
3114 or a list (+ N) meaning N pixels relative to top/left corner,\n\
3115 or a list (- N) meaning -N pixels relative to bottom/right corner.")
3120 unsigned int width
, height
;
3123 CHECK_STRING (string
, 0);
3125 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
3126 &x
, &y
, &width
, &height
);
3129 if (geometry
& XValue
)
3131 Lisp_Object element
;
3133 if (x
>= 0 && (geometry
& XNegative
))
3134 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3135 else if (x
< 0 && ! (geometry
& XNegative
))
3136 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3138 element
= Fcons (Qleft
, make_number (x
));
3139 result
= Fcons (element
, result
);
3142 if (geometry
& YValue
)
3144 Lisp_Object element
;
3146 if (y
>= 0 && (geometry
& YNegative
))
3147 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3148 else if (y
< 0 && ! (geometry
& YNegative
))
3149 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3151 element
= Fcons (Qtop
, make_number (y
));
3152 result
= Fcons (element
, result
);
3155 if (geometry
& WidthValue
)
3156 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3157 if (geometry
& HeightValue
)
3158 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3163 /* Calculate the desired size and position of this window,
3164 and return the flags saying which aspects were specified.
3166 This function does not make the coordinates positive. */
3168 #define DEFAULT_ROWS 40
3169 #define DEFAULT_COLS 80
3172 x_figure_window_size (f
, parms
)
3176 register Lisp_Object tem0
, tem1
, tem2
;
3177 long window_prompting
= 0;
3179 /* Default values if we fall through.
3180 Actually, if that happens we should get
3181 window manager prompting. */
3182 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3183 f
->height
= DEFAULT_ROWS
;
3184 /* Window managers expect that if program-specified
3185 positions are not (0,0), they're intentional, not defaults. */
3186 f
->output_data
.w32
->top_pos
= 0;
3187 f
->output_data
.w32
->left_pos
= 0;
3189 tem0
= w32_get_arg (parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3190 tem1
= w32_get_arg (parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3191 tem2
= w32_get_arg (parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3192 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3194 if (!EQ (tem0
, Qunbound
))
3196 CHECK_NUMBER (tem0
, 0);
3197 f
->height
= XINT (tem0
);
3199 if (!EQ (tem1
, Qunbound
))
3201 CHECK_NUMBER (tem1
, 0);
3202 SET_FRAME_WIDTH (f
, XINT (tem1
));
3204 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3205 window_prompting
|= USSize
;
3207 window_prompting
|= PSize
;
3210 f
->output_data
.w32
->vertical_scroll_bar_extra
3211 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3213 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3214 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3215 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
3216 f
->output_data
.w32
->flags_areas_extra
3217 = FRAME_FLAGS_AREA_WIDTH (f
);
3218 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3219 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3221 tem0
= w32_get_arg (parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3222 tem1
= w32_get_arg (parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3223 tem2
= w32_get_arg (parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3224 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3226 if (EQ (tem0
, Qminus
))
3228 f
->output_data
.w32
->top_pos
= 0;
3229 window_prompting
|= YNegative
;
3231 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3232 && CONSP (XCDR (tem0
))
3233 && INTEGERP (XCAR (XCDR (tem0
))))
3235 f
->output_data
.w32
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3236 window_prompting
|= YNegative
;
3238 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3239 && CONSP (XCDR (tem0
))
3240 && INTEGERP (XCAR (XCDR (tem0
))))
3242 f
->output_data
.w32
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3244 else if (EQ (tem0
, Qunbound
))
3245 f
->output_data
.w32
->top_pos
= 0;
3248 CHECK_NUMBER (tem0
, 0);
3249 f
->output_data
.w32
->top_pos
= XINT (tem0
);
3250 if (f
->output_data
.w32
->top_pos
< 0)
3251 window_prompting
|= YNegative
;
3254 if (EQ (tem1
, Qminus
))
3256 f
->output_data
.w32
->left_pos
= 0;
3257 window_prompting
|= XNegative
;
3259 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3260 && CONSP (XCDR (tem1
))
3261 && INTEGERP (XCAR (XCDR (tem1
))))
3263 f
->output_data
.w32
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3264 window_prompting
|= XNegative
;
3266 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3267 && CONSP (XCDR (tem1
))
3268 && INTEGERP (XCAR (XCDR (tem1
))))
3270 f
->output_data
.w32
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3272 else if (EQ (tem1
, Qunbound
))
3273 f
->output_data
.w32
->left_pos
= 0;
3276 CHECK_NUMBER (tem1
, 0);
3277 f
->output_data
.w32
->left_pos
= XINT (tem1
);
3278 if (f
->output_data
.w32
->left_pos
< 0)
3279 window_prompting
|= XNegative
;
3282 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3283 window_prompting
|= USPosition
;
3285 window_prompting
|= PPosition
;
3288 return window_prompting
;
3293 extern LRESULT CALLBACK
w32_wnd_proc ();
3296 w32_init_class (hinst
)
3301 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3302 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
3304 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
3305 wc
.hInstance
= hinst
;
3306 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
3307 wc
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
3308 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
3309 wc
.lpszMenuName
= NULL
;
3310 wc
.lpszClassName
= EMACS_CLASS
;
3312 return (RegisterClass (&wc
));
3316 w32_createscrollbar (f
, bar
)
3318 struct scroll_bar
* bar
;
3320 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
3321 /* Position and size of scroll bar. */
3322 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3324 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3326 FRAME_W32_WINDOW (f
),
3333 w32_createwindow (f
)
3339 rect
.left
= rect
.top
= 0;
3340 rect
.right
= PIXEL_WIDTH (f
);
3341 rect
.bottom
= PIXEL_HEIGHT (f
);
3343 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3344 FRAME_EXTERNAL_MENU_BAR (f
));
3346 /* Do first time app init */
3350 w32_init_class (hinst
);
3353 FRAME_W32_WINDOW (f
) = hwnd
3354 = CreateWindow (EMACS_CLASS
,
3356 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
3357 f
->output_data
.w32
->left_pos
,
3358 f
->output_data
.w32
->top_pos
,
3359 rect
.right
- rect
.left
,
3360 rect
.bottom
- rect
.top
,
3368 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
3369 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
3370 SetWindowLong (hwnd
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
3371 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
3372 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3374 /* Enable drag-n-drop. */
3375 DragAcceptFiles (hwnd
, TRUE
);
3377 /* Do this to discard the default setting specified by our parent. */
3378 ShowWindow (hwnd
, SW_HIDE
);
3383 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
3390 wmsg
->msg
.hwnd
= hwnd
;
3391 wmsg
->msg
.message
= msg
;
3392 wmsg
->msg
.wParam
= wParam
;
3393 wmsg
->msg
.lParam
= lParam
;
3394 wmsg
->msg
.time
= GetMessageTime ();
3399 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
3400 between left and right keys as advertised. We test for this
3401 support dynamically, and set a flag when the support is absent. If
3402 absent, we keep track of the left and right control and alt keys
3403 ourselves. This is particularly necessary on keyboards that rely
3404 upon the AltGr key, which is represented as having the left control
3405 and right alt keys pressed. For these keyboards, we need to know
3406 when the left alt key has been pressed in addition to the AltGr key
3407 so that we can properly support M-AltGr-key sequences (such as M-@
3408 on Swedish keyboards). */
3410 #define EMACS_LCONTROL 0
3411 #define EMACS_RCONTROL 1
3412 #define EMACS_LMENU 2
3413 #define EMACS_RMENU 3
3415 static int modifiers
[4];
3416 static int modifiers_recorded
;
3417 static int modifier_key_support_tested
;
3420 test_modifier_support (unsigned int wparam
)
3424 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
3426 if (wparam
== VK_CONTROL
)
3436 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
3437 modifiers_recorded
= 1;
3439 modifiers_recorded
= 0;
3440 modifier_key_support_tested
= 1;
3444 record_keydown (unsigned int wparam
, unsigned int lparam
)
3448 if (!modifier_key_support_tested
)
3449 test_modifier_support (wparam
);
3451 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3454 if (wparam
== VK_CONTROL
)
3455 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3457 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3463 record_keyup (unsigned int wparam
, unsigned int lparam
)
3467 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3470 if (wparam
== VK_CONTROL
)
3471 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3473 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3478 /* Emacs can lose focus while a modifier key has been pressed. When
3479 it regains focus, be conservative and clear all modifiers since
3480 we cannot reconstruct the left and right modifier state. */
3486 if (GetFocus () == NULL
)
3487 /* Emacs doesn't have keyboard focus. Do nothing. */
3490 ctrl
= GetAsyncKeyState (VK_CONTROL
);
3491 alt
= GetAsyncKeyState (VK_MENU
);
3493 if (!(ctrl
& 0x08000))
3494 /* Clear any recorded control modifier state. */
3495 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3497 if (!(alt
& 0x08000))
3498 /* Clear any recorded alt modifier state. */
3499 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3501 /* Update the state of all modifier keys, because modifiers used in
3502 hot-key combinations can get stuck on if Emacs loses focus as a
3503 result of a hot-key being pressed. */
3507 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
3509 GetKeyboardState (keystate
);
3510 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
3511 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
3512 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
3513 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
3514 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
3515 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
3516 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
3517 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
3518 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
3519 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
3520 SetKeyboardState (keystate
);
3524 /* Synchronize modifier state with what is reported with the current
3525 keystroke. Even if we cannot distinguish between left and right
3526 modifier keys, we know that, if no modifiers are set, then neither
3527 the left or right modifier should be set. */
3531 if (!modifiers_recorded
)
3534 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
3535 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3537 if (!(GetKeyState (VK_MENU
) & 0x8000))
3538 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3542 modifier_set (int vkey
)
3544 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
3545 return (GetKeyState (vkey
) & 0x1);
3546 if (!modifiers_recorded
)
3547 return (GetKeyState (vkey
) & 0x8000);
3552 return modifiers
[EMACS_LCONTROL
];
3554 return modifiers
[EMACS_RCONTROL
];
3556 return modifiers
[EMACS_LMENU
];
3558 return modifiers
[EMACS_RMENU
];
3560 return (GetKeyState (vkey
) & 0x8000);
3563 /* Convert between the modifier bits W32 uses and the modifier bits
3567 w32_key_to_modifier (int key
)
3569 Lisp_Object key_mapping
;
3574 key_mapping
= Vw32_lwindow_modifier
;
3577 key_mapping
= Vw32_rwindow_modifier
;
3580 key_mapping
= Vw32_apps_modifier
;
3583 key_mapping
= Vw32_scroll_lock_modifier
;
3589 /* NB. This code runs in the input thread, asychronously to the lisp
3590 thread, so we must be careful to ensure access to lisp data is
3591 thread-safe. The following code is safe because the modifier
3592 variable values are updated atomically from lisp and symbols are
3593 not relocated by GC. Also, we don't have to worry about seeing GC
3595 if (EQ (key_mapping
, Qhyper
))
3596 return hyper_modifier
;
3597 if (EQ (key_mapping
, Qsuper
))
3598 return super_modifier
;
3599 if (EQ (key_mapping
, Qmeta
))
3600 return meta_modifier
;
3601 if (EQ (key_mapping
, Qalt
))
3602 return alt_modifier
;
3603 if (EQ (key_mapping
, Qctrl
))
3604 return ctrl_modifier
;
3605 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
3606 return ctrl_modifier
;
3607 if (EQ (key_mapping
, Qshift
))
3608 return shift_modifier
;
3610 /* Don't generate any modifier if not explicitly requested. */
3615 w32_get_modifiers ()
3617 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
3618 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
3619 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
3620 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
3621 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
3622 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
3623 (modifier_set (VK_MENU
) ?
3624 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
3627 /* We map the VK_* modifiers into console modifier constants
3628 so that we can use the same routines to handle both console
3629 and window input. */
3632 construct_console_modifiers ()
3637 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
3638 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
3639 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
3640 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
3641 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
3642 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
3643 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
3644 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
3645 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
3646 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
3647 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
3653 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
3657 /* Convert to emacs modifiers. */
3658 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
3664 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
3666 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
3669 if (virt_key
== VK_RETURN
)
3670 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
3672 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
3673 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
3675 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
3676 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
3678 if (virt_key
== VK_CLEAR
)
3679 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
3684 /* List of special key combinations which w32 would normally capture,
3685 but emacs should grab instead. Not directly visible to lisp, to
3686 simplify synchronization. Each item is an integer encoding a virtual
3687 key code and modifier combination to capture. */
3688 Lisp_Object w32_grabbed_keys
;
3690 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
3691 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
3692 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
3693 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
3695 /* Register hot-keys for reserved key combinations when Emacs has
3696 keyboard focus, since this is the only way Emacs can receive key
3697 combinations like Alt-Tab which are used by the system. */
3700 register_hot_keys (hwnd
)
3703 Lisp_Object keylist
;
3705 /* Use GC_CONSP, since we are called asynchronously. */
3706 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3708 Lisp_Object key
= XCAR (keylist
);
3710 /* Deleted entries get set to nil. */
3711 if (!INTEGERP (key
))
3714 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
3715 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
3720 unregister_hot_keys (hwnd
)
3723 Lisp_Object keylist
;
3725 /* Use GC_CONSP, since we are called asynchronously. */
3726 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3728 Lisp_Object key
= XCAR (keylist
);
3730 if (!INTEGERP (key
))
3733 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
3737 /* Main message dispatch loop. */
3740 w32_msg_pump (deferred_msg
* msg_buf
)
3746 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
3748 while (GetMessage (&msg
, NULL
, 0, 0))
3750 if (msg
.hwnd
== NULL
)
3752 switch (msg
.message
)
3755 /* Produced by complete_deferred_msg; just ignore. */
3757 case WM_EMACS_CREATEWINDOW
:
3758 w32_createwindow ((struct frame
*) msg
.wParam
);
3759 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3762 case WM_EMACS_SETLOCALE
:
3763 SetThreadLocale (msg
.wParam
);
3764 /* Reply is not expected. */
3766 case WM_EMACS_SETKEYBOARDLAYOUT
:
3767 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
3768 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3772 case WM_EMACS_REGISTER_HOT_KEY
:
3773 focus_window
= GetFocus ();
3774 if (focus_window
!= NULL
)
3775 RegisterHotKey (focus_window
,
3776 HOTKEY_ID (msg
.wParam
),
3777 HOTKEY_MODIFIERS (msg
.wParam
),
3778 HOTKEY_VK_CODE (msg
.wParam
));
3779 /* Reply is not expected. */
3781 case WM_EMACS_UNREGISTER_HOT_KEY
:
3782 focus_window
= GetFocus ();
3783 if (focus_window
!= NULL
)
3784 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
3785 /* Mark item as erased. NB: this code must be
3786 thread-safe. The next line is okay because the cons
3787 cell is never made into garbage and is not relocated by
3789 XCAR ((Lisp_Object
) msg
.lParam
) = Qnil
;
3790 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3793 case WM_EMACS_TOGGLE_LOCK_KEY
:
3795 int vk_code
= (int) msg
.wParam
;
3796 int cur_state
= (GetKeyState (vk_code
) & 1);
3797 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
3799 /* NB: This code must be thread-safe. It is safe to
3800 call NILP because symbols are not relocated by GC,
3801 and pointer here is not touched by GC (so the markbit
3802 can't be set). Numbers are safe because they are
3803 immediate values. */
3804 if (NILP (new_state
)
3805 || (NUMBERP (new_state
)
3806 && (XUINT (new_state
)) & 1 != cur_state
))
3808 one_w32_display_info
.faked_key
= vk_code
;
3810 keybd_event ((BYTE
) vk_code
,
3811 (BYTE
) MapVirtualKey (vk_code
, 0),
3812 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3813 keybd_event ((BYTE
) vk_code
,
3814 (BYTE
) MapVirtualKey (vk_code
, 0),
3815 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3816 keybd_event ((BYTE
) vk_code
,
3817 (BYTE
) MapVirtualKey (vk_code
, 0),
3818 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3819 cur_state
= !cur_state
;
3821 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3827 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
3832 DispatchMessage (&msg
);
3835 /* Exit nested loop when our deferred message has completed. */
3836 if (msg_buf
->completed
)
3841 deferred_msg
* deferred_msg_head
;
3843 static deferred_msg
*
3844 find_deferred_msg (HWND hwnd
, UINT msg
)
3846 deferred_msg
* item
;
3848 /* Don't actually need synchronization for read access, since
3849 modification of single pointer is always atomic. */
3850 /* enter_crit (); */
3852 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3853 if (item
->w32msg
.msg
.hwnd
== hwnd
3854 && item
->w32msg
.msg
.message
== msg
)
3857 /* leave_crit (); */
3863 send_deferred_msg (deferred_msg
* msg_buf
,
3869 /* Only input thread can send deferred messages. */
3870 if (GetCurrentThreadId () != dwWindowsThreadId
)
3873 /* It is an error to send a message that is already deferred. */
3874 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3877 /* Enforced synchronization is not needed because this is the only
3878 function that alters deferred_msg_head, and the following critical
3879 section is guaranteed to only be serially reentered (since only the
3880 input thread can call us). */
3882 /* enter_crit (); */
3884 msg_buf
->completed
= 0;
3885 msg_buf
->next
= deferred_msg_head
;
3886 deferred_msg_head
= msg_buf
;
3887 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
3889 /* leave_crit (); */
3891 /* Start a new nested message loop to process other messages until
3892 this one is completed. */
3893 w32_msg_pump (msg_buf
);
3895 deferred_msg_head
= msg_buf
->next
;
3897 return msg_buf
->result
;
3901 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
3903 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
3905 if (msg_buf
== NULL
)
3906 /* Message may have been cancelled, so don't abort(). */
3909 msg_buf
->result
= result
;
3910 msg_buf
->completed
= 1;
3912 /* Ensure input thread is woken so it notices the completion. */
3913 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3917 cancel_all_deferred_msgs ()
3919 deferred_msg
* item
;
3921 /* Don't actually need synchronization for read access, since
3922 modification of single pointer is always atomic. */
3923 /* enter_crit (); */
3925 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3928 item
->completed
= 1;
3931 /* leave_crit (); */
3933 /* Ensure input thread is woken so it notices the completion. */
3934 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3942 deferred_msg dummy_buf
;
3944 /* Ensure our message queue is created */
3946 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
3948 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3951 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
3952 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
3953 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
3955 /* This is the inital message loop which should only exit when the
3956 application quits. */
3957 w32_msg_pump (&dummy_buf
);
3963 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
3973 wmsg
.dwModifiers
= modifiers
;
3975 /* Detect quit_char and set quit-flag directly. Note that we
3976 still need to post a message to ensure the main thread will be
3977 woken up if blocked in sys_select(), but we do NOT want to post
3978 the quit_char message itself (because it will usually be as if
3979 the user had typed quit_char twice). Instead, we post a dummy
3980 message that has no particular effect. */
3983 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
3984 c
= make_ctrl_char (c
) & 0377;
3986 || (wmsg
.dwModifiers
== 0 &&
3987 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
3991 /* The choice of message is somewhat arbitrary, as long as
3992 the main thread handler just ignores it. */
3995 /* Interrupt any blocking system calls. */
3998 /* As a safety precaution, forcibly complete any deferred
3999 messages. This is a kludge, but I don't see any particularly
4000 clean way to handle the situation where a deferred message is
4001 "dropped" in the lisp thread, and will thus never be
4002 completed, eg. by the user trying to activate the menubar
4003 when the lisp thread is busy, and then typing C-g when the
4004 menubar doesn't open promptly (with the result that the
4005 menubar never responds at all because the deferred
4006 WM_INITMENU message is never completed). Another problem
4007 situation is when the lisp thread calls SendMessage (to send
4008 a window manager command) when a message has been deferred;
4009 the lisp thread gets blocked indefinitely waiting for the
4010 deferred message to be completed, which itself is waiting for
4011 the lisp thread to respond.
4013 Note that we don't want to block the input thread waiting for
4014 a reponse from the lisp thread (although that would at least
4015 solve the deadlock problem above), because we want to be able
4016 to receive C-g to interrupt the lisp thread. */
4017 cancel_all_deferred_msgs ();
4021 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4024 /* Main window procedure */
4027 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
4034 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4036 int windows_translate
;
4039 /* Note that it is okay to call x_window_to_frame, even though we are
4040 not running in the main lisp thread, because frame deletion
4041 requires the lisp thread to synchronize with this thread. Thus, if
4042 a frame struct is returned, it can be used without concern that the
4043 lisp thread might make it disappear while we are using it.
4045 NB. Walking the frame list in this thread is safe (as long as
4046 writes of Lisp_Object slots are atomic, which they are on Windows).
4047 Although delete-frame can destructively modify the frame list while
4048 we are walking it, a garbage collection cannot occur until after
4049 delete-frame has synchronized with this thread.
4051 It is also safe to use functions that make GDI calls, such as
4052 w32_clear_rect, because these functions must obtain a DC handle
4053 from the frame struct using get_frame_dc which is thread-aware. */
4058 f
= x_window_to_frame (dpyinfo
, hwnd
);
4061 HDC hdc
= get_frame_dc (f
);
4062 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
4063 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
4064 release_frame_dc (f
, hdc
);
4066 #if defined (W32_DEBUG_DISPLAY)
4067 DebPrint (("WM_ERASEBKGND: erasing %d,%d-%d,%d\n",
4068 wmsg
.rect
.left
, wmsg
.rect
.top
, wmsg
.rect
.right
,
4070 #endif /* W32_DEBUG_DISPLAY */
4073 case WM_PALETTECHANGED
:
4074 /* ignore our own changes */
4075 if ((HWND
)wParam
!= hwnd
)
4077 f
= x_window_to_frame (dpyinfo
, hwnd
);
4079 /* get_frame_dc will realize our palette and force all
4080 frames to be redrawn if needed. */
4081 release_frame_dc (f
, get_frame_dc (f
));
4086 PAINTSTRUCT paintStruct
;
4089 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
4090 fails. Apparently this can happen under some
4092 if (!w32_strict_painting
|| GetUpdateRect (hwnd
, &update_rect
, FALSE
))
4095 BeginPaint (hwnd
, &paintStruct
);
4097 if (w32_strict_painting
)
4098 /* The rectangles returned by GetUpdateRect and BeginPaint
4099 do not always match. GetUpdateRect seems to be the
4100 more reliable of the two. */
4101 wmsg
.rect
= update_rect
;
4103 wmsg
.rect
= paintStruct
.rcPaint
;
4105 #if defined (W32_DEBUG_DISPLAY)
4106 DebPrint (("WM_PAINT: painting %d,%d-%d,%d\n", wmsg
.rect
.left
,
4107 wmsg
.rect
.top
, wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4108 DebPrint (("WM_PAINT: update region is %d,%d-%d,%d\n",
4109 update_rect
.left
, update_rect
.top
,
4110 update_rect
.right
, update_rect
.bottom
));
4112 EndPaint (hwnd
, &paintStruct
);
4115 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4120 /* If GetUpdateRect returns 0 (meaning there is no update
4121 region), assume the whole window needs to be repainted. */
4122 GetClientRect(hwnd
, &wmsg
.rect
);
4123 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4127 case WM_INPUTLANGCHANGE
:
4128 /* Inform lisp thread of keyboard layout changes. */
4129 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4131 /* Clear dead keys in the keyboard state; for simplicity only
4132 preserve modifier key states. */
4137 GetKeyboardState (keystate
);
4138 for (i
= 0; i
< 256; i
++)
4155 SetKeyboardState (keystate
);
4160 /* Synchronize hot keys with normal input. */
4161 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
4166 record_keyup (wParam
, lParam
);
4171 /* Ignore keystrokes we fake ourself; see below. */
4172 if (dpyinfo
->faked_key
== wParam
)
4174 dpyinfo
->faked_key
= 0;
4175 /* Make sure TranslateMessage sees them though (as long as
4176 they don't produce WM_CHAR messages). This ensures that
4177 indicator lights are toggled promptly on Windows 9x, for
4179 if (lispy_function_keys
[wParam
] != 0)
4181 windows_translate
= 1;
4187 /* Synchronize modifiers with current keystroke. */
4189 record_keydown (wParam
, lParam
);
4190 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
4192 windows_translate
= 0;
4197 if (NILP (Vw32_pass_lwindow_to_system
))
4199 /* Prevent system from acting on keyup (which opens the
4200 Start menu if no other key was pressed) by simulating a
4201 press of Space which we will ignore. */
4202 if (GetAsyncKeyState (wParam
) & 1)
4204 if (NUMBERP (Vw32_phantom_key_code
))
4205 key
= XUINT (Vw32_phantom_key_code
) & 255;
4208 dpyinfo
->faked_key
= key
;
4209 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4212 if (!NILP (Vw32_lwindow_modifier
))
4216 if (NILP (Vw32_pass_rwindow_to_system
))
4218 if (GetAsyncKeyState (wParam
) & 1)
4220 if (NUMBERP (Vw32_phantom_key_code
))
4221 key
= XUINT (Vw32_phantom_key_code
) & 255;
4224 dpyinfo
->faked_key
= key
;
4225 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4228 if (!NILP (Vw32_rwindow_modifier
))
4232 if (!NILP (Vw32_apps_modifier
))
4236 if (NILP (Vw32_pass_alt_to_system
))
4237 /* Prevent DefWindowProc from activating the menu bar if an
4238 Alt key is pressed and released by itself. */
4240 windows_translate
= 1;
4243 /* Decide whether to treat as modifier or function key. */
4244 if (NILP (Vw32_enable_caps_lock
))
4245 goto disable_lock_key
;
4246 windows_translate
= 1;
4249 /* Decide whether to treat as modifier or function key. */
4250 if (NILP (Vw32_enable_num_lock
))
4251 goto disable_lock_key
;
4252 windows_translate
= 1;
4255 /* Decide whether to treat as modifier or function key. */
4256 if (NILP (Vw32_scroll_lock_modifier
))
4257 goto disable_lock_key
;
4258 windows_translate
= 1;
4261 /* Ensure the appropriate lock key state (and indicator light)
4262 remains in the same state. We do this by faking another
4263 press of the relevant key. Apparently, this really is the
4264 only way to toggle the state of the indicator lights. */
4265 dpyinfo
->faked_key
= wParam
;
4266 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4267 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4268 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4269 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4270 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4271 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4272 /* Ensure indicator lights are updated promptly on Windows 9x
4273 (TranslateMessage apparently does this), after forwarding
4275 post_character_message (hwnd
, msg
, wParam
, lParam
,
4276 w32_get_key_modifiers (wParam
, lParam
));
4277 windows_translate
= 1;
4281 case VK_PROCESSKEY
: /* Generated by IME. */
4282 windows_translate
= 1;
4285 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
4286 which is confusing for purposes of key binding; convert
4287 VK_CANCEL events into VK_PAUSE events. */
4291 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
4292 for purposes of key binding; convert these back into
4293 VK_NUMLOCK events, at least when we want to see NumLock key
4294 presses. (Note that there is never any possibility that
4295 VK_PAUSE with Ctrl really is C-Pause as per above.) */
4296 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
4297 wParam
= VK_NUMLOCK
;
4300 /* If not defined as a function key, change it to a WM_CHAR message. */
4301 if (lispy_function_keys
[wParam
] == 0)
4303 DWORD modifiers
= construct_console_modifiers ();
4305 if (!NILP (Vw32_recognize_altgr
)
4306 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
4308 /* Always let TranslateMessage handle AltGr key chords;
4309 for some reason, ToAscii doesn't always process AltGr
4310 chords correctly. */
4311 windows_translate
= 1;
4313 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
4315 /* Handle key chords including any modifiers other
4316 than shift directly, in order to preserve as much
4317 modifier information as possible. */
4318 if ('A' <= wParam
&& wParam
<= 'Z')
4320 /* Don't translate modified alphabetic keystrokes,
4321 so the user doesn't need to constantly switch
4322 layout to type control or meta keystrokes when
4323 the normal layout translates alphabetic
4324 characters to non-ascii characters. */
4325 if (!modifier_set (VK_SHIFT
))
4326 wParam
+= ('a' - 'A');
4331 /* Try to handle other keystrokes by determining the
4332 base character (ie. translating the base key plus
4336 KEY_EVENT_RECORD key
;
4338 key
.bKeyDown
= TRUE
;
4339 key
.wRepeatCount
= 1;
4340 key
.wVirtualKeyCode
= wParam
;
4341 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
4342 key
.uChar
.AsciiChar
= 0;
4343 key
.dwControlKeyState
= modifiers
;
4345 add
= w32_kbd_patch_key (&key
);
4346 /* 0 means an unrecognised keycode, negative means
4347 dead key. Ignore both. */
4350 /* Forward asciified character sequence. */
4351 post_character_message
4352 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
4353 w32_get_key_modifiers (wParam
, lParam
));
4354 w32_kbd_patch_key (&key
);
4361 /* Let TranslateMessage handle everything else. */
4362 windows_translate
= 1;
4368 if (windows_translate
)
4370 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
4372 windows_msg
.time
= GetMessageTime ();
4373 TranslateMessage (&windows_msg
);
4381 post_character_message (hwnd
, msg
, wParam
, lParam
,
4382 w32_get_key_modifiers (wParam
, lParam
));
4385 /* Simulate middle mouse button events when left and right buttons
4386 are used together, but only if user has two button mouse. */
4387 case WM_LBUTTONDOWN
:
4388 case WM_RBUTTONDOWN
:
4389 if (XINT (Vw32_num_mouse_buttons
) > 2)
4390 goto handle_plain_button
;
4393 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
4394 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
4396 if (button_state
& this)
4399 if (button_state
== 0)
4402 button_state
|= this;
4404 if (button_state
& other
)
4406 if (mouse_button_timer
)
4408 KillTimer (hwnd
, mouse_button_timer
);
4409 mouse_button_timer
= 0;
4411 /* Generate middle mouse event instead. */
4412 msg
= WM_MBUTTONDOWN
;
4413 button_state
|= MMOUSE
;
4415 else if (button_state
& MMOUSE
)
4417 /* Ignore button event if we've already generated a
4418 middle mouse down event. This happens if the
4419 user releases and press one of the two buttons
4420 after we've faked a middle mouse event. */
4425 /* Flush out saved message. */
4426 post_msg (&saved_mouse_button_msg
);
4428 wmsg
.dwModifiers
= w32_get_modifiers ();
4429 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4431 /* Clear message buffer. */
4432 saved_mouse_button_msg
.msg
.hwnd
= 0;
4436 /* Hold onto message for now. */
4437 mouse_button_timer
=
4438 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
4439 XINT (Vw32_mouse_button_tolerance
), NULL
);
4440 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
4441 saved_mouse_button_msg
.msg
.message
= msg
;
4442 saved_mouse_button_msg
.msg
.wParam
= wParam
;
4443 saved_mouse_button_msg
.msg
.lParam
= lParam
;
4444 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
4445 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
4452 if (XINT (Vw32_num_mouse_buttons
) > 2)
4453 goto handle_plain_button
;
4456 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
4457 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
4459 if ((button_state
& this) == 0)
4462 button_state
&= ~this;
4464 if (button_state
& MMOUSE
)
4466 /* Only generate event when second button is released. */
4467 if ((button_state
& other
) == 0)
4470 button_state
&= ~MMOUSE
;
4472 if (button_state
) abort ();
4479 /* Flush out saved message if necessary. */
4480 if (saved_mouse_button_msg
.msg
.hwnd
)
4482 post_msg (&saved_mouse_button_msg
);
4485 wmsg
.dwModifiers
= w32_get_modifiers ();
4486 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4488 /* Always clear message buffer and cancel timer. */
4489 saved_mouse_button_msg
.msg
.hwnd
= 0;
4490 KillTimer (hwnd
, mouse_button_timer
);
4491 mouse_button_timer
= 0;
4493 if (button_state
== 0)
4498 case WM_MBUTTONDOWN
:
4500 handle_plain_button
:
4505 if (parse_button (msg
, &button
, &up
))
4507 if (up
) ReleaseCapture ();
4508 else SetCapture (hwnd
);
4509 button
= (button
== 0) ? LMOUSE
:
4510 ((button
== 1) ? MMOUSE
: RMOUSE
);
4512 button_state
&= ~button
;
4514 button_state
|= button
;
4518 wmsg
.dwModifiers
= w32_get_modifiers ();
4519 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4524 if (XINT (Vw32_mouse_move_interval
) <= 0
4525 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4527 wmsg
.dwModifiers
= w32_get_modifiers ();
4528 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4532 /* Hang onto mouse move and scroll messages for a bit, to avoid
4533 sending such events to Emacs faster than it can process them.
4534 If we get more events before the timer from the first message
4535 expires, we just replace the first message. */
4537 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4539 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4540 XINT (Vw32_mouse_move_interval
), NULL
);
4542 /* Hold onto message for now. */
4543 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4544 saved_mouse_move_msg
.msg
.message
= msg
;
4545 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4546 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4547 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4548 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4553 wmsg
.dwModifiers
= w32_get_modifiers ();
4554 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4558 wmsg
.dwModifiers
= w32_get_modifiers ();
4559 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4563 /* Flush out saved messages if necessary. */
4564 if (wParam
== mouse_button_timer
)
4566 if (saved_mouse_button_msg
.msg
.hwnd
)
4568 post_msg (&saved_mouse_button_msg
);
4569 saved_mouse_button_msg
.msg
.hwnd
= 0;
4571 KillTimer (hwnd
, mouse_button_timer
);
4572 mouse_button_timer
= 0;
4574 else if (wParam
== mouse_move_timer
)
4576 if (saved_mouse_move_msg
.msg
.hwnd
)
4578 post_msg (&saved_mouse_move_msg
);
4579 saved_mouse_move_msg
.msg
.hwnd
= 0;
4581 KillTimer (hwnd
, mouse_move_timer
);
4582 mouse_move_timer
= 0;
4587 /* Windows doesn't send us focus messages when putting up and
4588 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4589 The only indication we get that something happened is receiving
4590 this message afterwards. So this is a good time to reset our
4591 keyboard modifiers' state. */
4598 /* We must ensure menu bar is fully constructed and up to date
4599 before allowing user interaction with it. To achieve this
4600 we send this message to the lisp thread and wait for a
4601 reply (whose value is not actually needed) to indicate that
4602 the menu bar is now ready for use, so we can now return.
4604 To remain responsive in the meantime, we enter a nested message
4605 loop that can process all other messages.
4607 However, we skip all this if the message results from calling
4608 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4609 thread a message because it is blocked on us at this point. We
4610 set menubar_active before calling TrackPopupMenu to indicate
4611 this (there is no possibility of confusion with real menubar
4614 f
= x_window_to_frame (dpyinfo
, hwnd
);
4616 && (f
->output_data
.w32
->menubar_active
4617 /* We can receive this message even in the absence of a
4618 menubar (ie. when the system menu is activated) - in this
4619 case we do NOT want to forward the message, otherwise it
4620 will cause the menubar to suddenly appear when the user
4621 had requested it to be turned off! */
4622 || f
->output_data
.w32
->menubar_widget
== NULL
))
4626 deferred_msg msg_buf
;
4628 /* Detect if message has already been deferred; in this case
4629 we cannot return any sensible value to ignore this. */
4630 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4633 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4636 case WM_EXITMENULOOP
:
4637 f
= x_window_to_frame (dpyinfo
, hwnd
);
4639 /* Indicate that menubar can be modified again. */
4641 f
->output_data
.w32
->menubar_active
= 0;
4645 wmsg
.dwModifiers
= w32_get_modifiers ();
4646 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4649 case WM_MEASUREITEM
:
4650 f
= x_window_to_frame (dpyinfo
, hwnd
);
4653 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4655 if (pMis
->CtlType
== ODT_MENU
)
4657 /* Work out dimensions for popup menu titles. */
4658 char * title
= (char *) pMis
->itemData
;
4659 HDC hdc
= GetDC (hwnd
);
4660 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4661 LOGFONT menu_logfont
;
4665 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4666 menu_logfont
.lfWeight
= FW_BOLD
;
4667 menu_font
= CreateFontIndirect (&menu_logfont
);
4668 old_font
= SelectObject (hdc
, menu_font
);
4670 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4673 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4674 pMis
->itemWidth
= size
.cx
;
4675 if (pMis
->itemHeight
< size
.cy
)
4676 pMis
->itemHeight
= size
.cy
;
4679 pMis
->itemWidth
= 0;
4681 SelectObject (hdc
, old_font
);
4682 DeleteObject (menu_font
);
4683 ReleaseDC (hwnd
, hdc
);
4690 f
= x_window_to_frame (dpyinfo
, hwnd
);
4693 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4695 if (pDis
->CtlType
== ODT_MENU
)
4697 /* Draw popup menu title. */
4698 char * title
= (char *) pDis
->itemData
;
4701 HDC hdc
= pDis
->hDC
;
4702 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4703 LOGFONT menu_logfont
;
4706 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4707 menu_logfont
.lfWeight
= FW_BOLD
;
4708 menu_font
= CreateFontIndirect (&menu_logfont
);
4709 old_font
= SelectObject (hdc
, menu_font
);
4711 /* Always draw title as if not selected. */
4714 + GetSystemMetrics (SM_CXMENUCHECK
),
4716 ETO_OPAQUE
, &pDis
->rcItem
,
4717 title
, strlen (title
), NULL
);
4719 SelectObject (hdc
, old_font
);
4720 DeleteObject (menu_font
);
4728 /* Still not right - can't distinguish between clicks in the
4729 client area of the frame from clicks forwarded from the scroll
4730 bars - may have to hook WM_NCHITTEST to remember the mouse
4731 position and then check if it is in the client area ourselves. */
4732 case WM_MOUSEACTIVATE
:
4733 /* Discard the mouse click that activates a frame, allowing the
4734 user to click anywhere without changing point (or worse!).
4735 Don't eat mouse clicks on scrollbars though!! */
4736 if (LOWORD (lParam
) == HTCLIENT
)
4737 return MA_ACTIVATEANDEAT
;
4741 case WM_ACTIVATEAPP
:
4743 case WM_WINDOWPOSCHANGED
:
4745 /* Inform lisp thread that a frame might have just been obscured
4746 or exposed, so should recheck visibility of all frames. */
4747 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4751 dpyinfo
->faked_key
= 0;
4753 register_hot_keys (hwnd
);
4756 unregister_hot_keys (hwnd
);
4763 wmsg
.dwModifiers
= w32_get_modifiers ();
4764 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4768 wmsg
.dwModifiers
= w32_get_modifiers ();
4769 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4772 case WM_WINDOWPOSCHANGING
:
4775 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
4777 wp
.length
= sizeof (WINDOWPLACEMENT
);
4778 GetWindowPlacement (hwnd
, &wp
);
4780 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
4787 DWORD internal_border
;
4788 DWORD scrollbar_extra
;
4791 wp
.length
= sizeof(wp
);
4792 GetWindowRect (hwnd
, &wr
);
4796 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
4797 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
4798 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
4799 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
4803 memset (&rect
, 0, sizeof (rect
));
4804 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
4805 GetMenu (hwnd
) != NULL
);
4807 /* Force width and height of client area to be exact
4808 multiples of the character cell dimensions. */
4809 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
4810 - 2 * internal_border
- scrollbar_extra
)
4812 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
4813 - 2 * internal_border
)
4818 /* For right/bottom sizing we can just fix the sizes.
4819 However for top/left sizing we will need to fix the X
4820 and Y positions as well. */
4825 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
4826 && (lppos
->flags
& SWP_NOMOVE
) == 0)
4828 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
4835 lppos
->flags
|= SWP_NOMOVE
;
4846 case WM_GETMINMAXINFO
:
4847 /* Hack to correct bug that allows Emacs frames to be resized
4848 below the Minimum Tracking Size. */
4849 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
4852 case WM_EMACS_CREATESCROLLBAR
:
4853 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
4854 (struct scroll_bar
*) lParam
);
4856 case WM_EMACS_SHOWWINDOW
:
4857 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4859 case WM_EMACS_SETFOREGROUND
:
4861 HWND foreground_window
;
4862 DWORD foreground_thread
, retval
;
4864 /* On NT 5.0, and apparently Windows 98, it is necessary to
4865 attach to the thread that currently has focus in order to
4866 pull the focus away from it. */
4867 foreground_window
= GetForegroundWindow ();
4868 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4869 if (!foreground_window
4870 || foreground_thread
== GetCurrentThreadId ()
4871 || !AttachThreadInput (GetCurrentThreadId (),
4872 foreground_thread
, TRUE
))
4873 foreground_thread
= 0;
4875 retval
= SetForegroundWindow ((HWND
) wParam
);
4877 /* Detach from the previous foreground thread. */
4878 if (foreground_thread
)
4879 AttachThreadInput (GetCurrentThreadId (),
4880 foreground_thread
, FALSE
);
4885 case WM_EMACS_SETWINDOWPOS
:
4887 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4888 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4889 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4892 case WM_EMACS_DESTROYWINDOW
:
4893 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4894 return DestroyWindow ((HWND
) wParam
);
4896 case WM_EMACS_TRACKPOPUPMENU
:
4901 pos
= (POINT
*)lParam
;
4902 flags
= TPM_CENTERALIGN
;
4903 if (button_state
& LMOUSE
)
4904 flags
|= TPM_LEFTBUTTON
;
4905 else if (button_state
& RMOUSE
)
4906 flags
|= TPM_RIGHTBUTTON
;
4908 /* Remember we did a SetCapture on the initial mouse down event,
4909 so for safety, we make sure the capture is cancelled now. */
4913 /* Use menubar_active to indicate that WM_INITMENU is from
4914 TrackPopupMenu below, and should be ignored. */
4915 f
= x_window_to_frame (dpyinfo
, hwnd
);
4917 f
->output_data
.w32
->menubar_active
= 1;
4919 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4923 /* Eat any mouse messages during popupmenu */
4924 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4926 /* Get the menu selection, if any */
4927 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4929 retval
= LOWORD (amsg
.wParam
);
4945 /* Check for messages registered at runtime. */
4946 if (msg
== msh_mousewheel
)
4948 wmsg
.dwModifiers
= w32_get_modifiers ();
4949 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4954 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
4958 /* The most common default return code for handled messages is 0. */
4963 my_create_window (f
)
4968 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4970 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4973 /* Create and set up the w32 window for frame F. */
4976 w32_window (f
, window_prompting
, minibuffer_only
)
4978 long window_prompting
;
4979 int minibuffer_only
;
4983 /* Use the resource name as the top-level window name
4984 for looking up resources. Make a non-Lisp copy
4985 for the window manager, so GC relocation won't bother it.
4987 Elsewhere we specify the window name for the window manager. */
4990 char *str
= (char *) XSTRING (Vx_resource_name
)->data
;
4991 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
4992 strcpy (f
->namebuf
, str
);
4995 my_create_window (f
);
4997 validate_x_resource_name ();
4999 /* x_set_name normally ignores requests to set the name if the
5000 requested name is the same as the current name. This is the one
5001 place where that assumption isn't correct; f->name is set, but
5002 the server hasn't been told. */
5005 int explicit = f
->explicit_name
;
5007 f
->explicit_name
= 0;
5010 x_set_name (f
, name
, explicit);
5015 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
5016 initialize_frame_menubar (f
);
5018 if (FRAME_W32_WINDOW (f
) == 0)
5019 error ("Unable to create window");
5022 /* Handle the icon stuff for this window. Perhaps later we might
5023 want an x_set_icon_position which can be called interactively as
5031 Lisp_Object icon_x
, icon_y
;
5033 /* Set the position of the icon. Note that Windows 95 groups all
5034 icons in the tray. */
5035 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
5036 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
5037 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
5039 CHECK_NUMBER (icon_x
, 0);
5040 CHECK_NUMBER (icon_y
, 0);
5042 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
5043 error ("Both left and top icon corners of icon must be specified");
5047 if (! EQ (icon_x
, Qunbound
))
5048 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
5051 /* Start up iconic or window? */
5052 x_wm_set_window_state
5053 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
5057 x_text_icon (f
, (char *) XSTRING ((!NILP (f
->icon_name
)
5070 XGCValues gc_values
;
5074 /* Create the GC's of this frame.
5075 Note that many default values are used. */
5078 gc_values
.font
= f
->output_data
.w32
->font
;
5080 /* Cursor has cursor-color background, background-color foreground. */
5081 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
5082 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
5083 f
->output_data
.w32
->cursor_gc
5084 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
5085 (GCFont
| GCForeground
| GCBackground
),
5089 f
->output_data
.w32
->white_relief
.gc
= 0;
5090 f
->output_data
.w32
->black_relief
.gc
= 0;
5096 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
5098 "Make a new window, which is called a \"frame\" in Emacs terms.\n\
5099 Returns an Emacs frame object.\n\
5100 ALIST is an alist of frame parameters.\n\
5101 If the parameters specify that the frame should not have a minibuffer,\n\
5102 and do not specify a specific minibuffer window to use,\n\
5103 then `default-minibuffer-frame' must be a frame whose minibuffer can\n\
5104 be shared by the new frame.\n\
5106 This function is an internal primitive--use `make-frame' instead.")
5111 Lisp_Object frame
, tem
;
5113 int minibuffer_only
= 0;
5114 long window_prompting
= 0;
5116 int count
= specpdl_ptr
- specpdl
;
5117 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5118 Lisp_Object display
;
5119 struct w32_display_info
*dpyinfo
= NULL
;
5125 /* Use this general default value to start with
5126 until we know if this frame has a specified name. */
5127 Vx_resource_name
= Vinvocation_name
;
5129 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
5130 if (EQ (display
, Qunbound
))
5132 dpyinfo
= check_x_display_info (display
);
5134 kb
= dpyinfo
->kboard
;
5136 kb
= &the_only_kboard
;
5139 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5141 && ! EQ (name
, Qunbound
)
5143 error ("Invalid frame name--not a string or nil");
5146 Vx_resource_name
= name
;
5148 /* See if parent window is specified. */
5149 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
5150 if (EQ (parent
, Qunbound
))
5152 if (! NILP (parent
))
5153 CHECK_NUMBER (parent
, 0);
5155 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
5156 /* No need to protect DISPLAY because that's not used after passing
5157 it to make_frame_without_minibuffer. */
5159 GCPRO4 (parms
, parent
, name
, frame
);
5160 tem
= w32_get_arg (parms
, Qminibuffer
, "minibuffer", "Minibuffer",
5162 if (EQ (tem
, Qnone
) || NILP (tem
))
5163 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
5164 else if (EQ (tem
, Qonly
))
5166 f
= make_minibuffer_frame ();
5167 minibuffer_only
= 1;
5169 else if (WINDOWP (tem
))
5170 f
= make_frame_without_minibuffer (tem
, kb
, display
);
5174 XSETFRAME (frame
, f
);
5176 /* Note that Windows does support scroll bars. */
5177 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
5178 /* By default, make scrollbars the system standard width. */
5179 f
->scroll_bar_pixel_width
= GetSystemMetrics (SM_CXVSCROLL
);
5181 f
->output_method
= output_w32
;
5182 f
->output_data
.w32
=
5183 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5184 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5186 FRAME_FONTSET (f
) = -1;
5189 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
5190 if (! STRINGP (f
->icon_name
))
5191 f
->icon_name
= Qnil
;
5193 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
5195 FRAME_KBOARD (f
) = kb
;
5198 /* Specify the parent under which to make this window. */
5202 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
5203 f
->output_data
.w32
->explicit_parent
= 1;
5207 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5208 f
->output_data
.w32
->explicit_parent
= 0;
5211 /* Set the name; the functions to which we pass f expect the name to
5213 if (EQ (name
, Qunbound
) || NILP (name
))
5215 f
->name
= build_string (dpyinfo
->w32_id_name
);
5216 f
->explicit_name
= 0;
5221 f
->explicit_name
= 1;
5222 /* use the frame's title when getting resources for this frame. */
5223 specbind (Qx_resource_name
, name
);
5226 /* Extract the window parameters from the supplied values
5227 that are needed to determine window geometry. */
5231 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
5234 /* First, try whatever font the caller has specified. */
5237 tem
= Fquery_fontset (font
, Qnil
);
5239 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
5241 font
= x_new_font (f
, XSTRING (font
)->data
);
5243 /* Try out a font which we hope has bold and italic variations. */
5244 if (!STRINGP (font
))
5245 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
5246 if (! STRINGP (font
))
5247 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5248 /* If those didn't work, look for something which will at least work. */
5249 if (! STRINGP (font
))
5250 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
5252 if (! STRINGP (font
))
5253 font
= build_string ("Fixedsys");
5255 x_default_parameter (f
, parms
, Qfont
, font
,
5256 "font", "Font", RES_TYPE_STRING
);
5259 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5260 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5261 /* This defaults to 2 in order to match xterm. We recognize either
5262 internalBorderWidth or internalBorder (which is what xterm calls
5264 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5268 value
= w32_get_arg (parms
, Qinternal_border_width
,
5269 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
5270 if (! EQ (value
, Qunbound
))
5271 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5274 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5275 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
5276 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
5277 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qright
,
5278 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5280 /* Also do the stuff which must be set before the window exists. */
5281 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5282 "foreground", "Foreground", RES_TYPE_STRING
);
5283 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5284 "background", "Background", RES_TYPE_STRING
);
5285 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5286 "pointerColor", "Foreground", RES_TYPE_STRING
);
5287 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5288 "cursorColor", "Foreground", RES_TYPE_STRING
);
5289 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5290 "borderColor", "BorderColor", RES_TYPE_STRING
);
5291 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
5292 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5293 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
5294 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
5297 /* Init faces before x_default_parameter is called for scroll-bar
5298 parameters because that function calls x_set_scroll_bar_width,
5299 which calls change_frame_size, which calls Fset_window_buffer,
5300 which runs hooks, which call Fvertical_motion. At the end, we
5301 end up in init_iterator with a null face cache, which should not
5303 init_frame_faces (f
);
5305 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
5306 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
5307 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (0),
5308 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
5309 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
5310 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5311 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
5312 "title", "Title", RES_TYPE_STRING
);
5314 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5315 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5316 window_prompting
= x_figure_window_size (f
, parms
);
5318 if (window_prompting
& XNegative
)
5320 if (window_prompting
& YNegative
)
5321 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
5323 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
5327 if (window_prompting
& YNegative
)
5328 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
5330 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
5333 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
5335 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5336 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5338 /* Create the window. Add the tool-bar height to the initial frame
5339 height so that the user gets a text display area of the size he
5340 specified with -g or via the registry. Later changes of the
5341 tool-bar height don't change the frame size. This is done so that
5342 users can create tall Emacs frames without having to guess how
5343 tall the tool-bar will get. */
5344 f
->height
+= FRAME_TOOL_BAR_LINES (f
);
5345 w32_window (f
, window_prompting
, minibuffer_only
);
5350 /* Now consider the frame official. */
5351 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5352 Vframe_list
= Fcons (frame
, Vframe_list
);
5354 /* We need to do this after creating the window, so that the
5355 icon-creation functions can say whose icon they're describing. */
5356 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
5357 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5359 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5360 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5361 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5362 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5363 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5364 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5365 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
5366 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5368 /* Dimensions, especially f->height, must be done via change_frame_size.
5369 Change will not be effected unless different from the current
5374 SET_FRAME_WIDTH (f
, 0);
5375 change_frame_size (f
, height
, width
, 1, 0, 0);
5377 /* Tell the server what size and position, etc, we want, and how
5378 badly we want them. This should be done after we have the menu
5379 bar so that its size can be taken into account. */
5381 x_wm_set_size_hint (f
, window_prompting
, 0);
5384 /* Make the window appear on the frame and enable display, unless
5385 the caller says not to. However, with explicit parent, Emacs
5386 cannot control visibility, so don't try. */
5387 if (! f
->output_data
.w32
->explicit_parent
)
5389 Lisp_Object visibility
;
5391 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5392 if (EQ (visibility
, Qunbound
))
5395 if (EQ (visibility
, Qicon
))
5396 x_iconify_frame (f
);
5397 else if (! NILP (visibility
))
5398 x_make_frame_visible (f
);
5400 /* Must have been Qnil. */
5404 return unbind_to (count
, frame
);
5407 /* FRAME is used only to get a handle on the X display. We don't pass the
5408 display info directly because we're called from frame.c, which doesn't
5409 know about that structure. */
5411 x_get_focus_frame (frame
)
5412 struct frame
*frame
;
5414 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
5416 if (! dpyinfo
->w32_focus_frame
)
5419 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5423 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
5424 "Give FRAME input focus, raising to foreground if necessary.")
5428 x_focus_on_frame (check_x_frame (frame
));
5433 /* Return the charset portion of a font name. */
5434 char * xlfd_charset_of_font (char * fontname
)
5436 char *charset
, *encoding
;
5438 encoding
= strrchr(fontname
, '-');
5443 charset
= strrchr(fontname
, '-');
5446 if (!charset
|| strcmp(charset
, "-*-*") == 0)
5452 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
5453 int size
, char* filename
);
5454 BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
, char * charset
);
5457 w32_load_system_font (f
,fontname
,size
)
5462 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5463 Lisp_Object font_names
;
5465 /* Get a list of all the fonts that match this name. Once we
5466 have a list of matching fonts, we compare them against the fonts
5467 we already have loaded by comparing names. */
5468 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
5470 if (!NILP (font_names
))
5475 /* First check if any are already loaded, as that is cheaper
5476 than loading another one. */
5477 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5478 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
5479 if (dpyinfo
->font_table
[i
].name
5480 && (!strcmp (dpyinfo
->font_table
[i
].name
,
5481 XSTRING (XCAR (tail
))->data
)
5482 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
5483 XSTRING (XCAR (tail
))->data
)))
5484 return (dpyinfo
->font_table
+ i
);
5486 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
5488 else if (w32_strict_fontnames
)
5490 /* If EnumFontFamiliesEx was available, we got a full list of
5491 fonts back so stop now to avoid the possibility of loading a
5492 random font. If we had to fall back to EnumFontFamilies, the
5493 list is incomplete, so continue whether the font we want was
5495 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5496 FARPROC enum_font_families_ex
5497 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
5498 if (enum_font_families_ex
)
5502 /* Load the font and add it to the table. */
5504 char *full_name
, *encoding
, *charset
;
5506 struct font_info
*fontp
;
5511 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
5514 if (!*lf
.lfFaceName
)
5515 /* If no name was specified for the font, we get a random font
5516 from CreateFontIndirect - this is not particularly
5517 desirable, especially since CreateFontIndirect does not
5518 fill out the missing name in lf, so we never know what we
5522 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
5523 bzero (font
, sizeof (*font
));
5525 /* Set bdf to NULL to indicate that this is a Windows font. */
5530 font
->hfont
= CreateFontIndirect (&lf
);
5532 if (font
->hfont
== NULL
)
5540 int codepage
= w32_codepage_for_font (fontname
);
5542 hdc
= GetDC (dpyinfo
->root_window
);
5543 oldobj
= SelectObject (hdc
, font
->hfont
);
5545 ok
= GetTextMetrics (hdc
, &font
->tm
);
5546 if (codepage
== CP_UNICODE
)
5547 font
->double_byte_p
= 1;
5549 font
->double_byte_p
= GetFontLanguageInfo(hdc
) & GCP_DBCS
;
5551 SelectObject (hdc
, oldobj
);
5552 ReleaseDC (dpyinfo
->root_window
, hdc
);
5553 /* Fill out details in lf according to the font that was
5555 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
5556 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
5557 lf
.lfWeight
= font
->tm
.tmWeight
;
5558 lf
.lfItalic
= font
->tm
.tmItalic
;
5559 lf
.lfCharSet
= font
->tm
.tmCharSet
;
5560 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
5561 ? VARIABLE_PITCH
: FIXED_PITCH
);
5562 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
5563 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
5565 w32_cache_char_metrics (font
);
5572 w32_unload_font (dpyinfo
, font
);
5576 /* Find a free slot in the font table. */
5577 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
5578 if (dpyinfo
->font_table
[i
].name
== NULL
)
5581 /* If no free slot found, maybe enlarge the font table. */
5582 if (i
== dpyinfo
->n_fonts
5583 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
5586 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
5587 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
5589 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
5592 fontp
= dpyinfo
->font_table
+ i
;
5593 if (i
== dpyinfo
->n_fonts
)
5596 /* Now fill in the slots of *FONTP. */
5599 fontp
->font_idx
= i
;
5600 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
5601 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
5603 charset
= xlfd_charset_of_font (fontname
);
5605 /* Work out the font's full name. */
5606 full_name
= (char *)xmalloc (100);
5607 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
5608 fontp
->full_name
= full_name
;
5611 /* If all else fails - just use the name we used to load it. */
5613 fontp
->full_name
= fontp
->name
;
5616 fontp
->size
= FONT_WIDTH (font
);
5617 fontp
->height
= FONT_HEIGHT (font
);
5619 /* The slot `encoding' specifies how to map a character
5620 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
5621 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
5622 (0:0x20..0x7F, 1:0xA0..0xFF,
5623 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
5624 2:0xA020..0xFF7F). For the moment, we don't know which charset
5625 uses this font. So, we set information in fontp->encoding[1]
5626 which is never used by any charset. If mapping can't be
5627 decided, set FONT_ENCODING_NOT_DECIDED. */
5629 /* SJIS fonts need to be set to type 4, all others seem to work as
5630 type FONT_ENCODING_NOT_DECIDED. */
5631 encoding
= strrchr (fontp
->name
, '-');
5632 if (encoding
&& stricmp (encoding
+1, "sjis") == 0)
5633 fontp
->encoding
[1] = 4;
5635 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
5637 /* The following three values are set to 0 under W32, which is
5638 what they get set to if XGetFontProperty fails under X. */
5639 fontp
->baseline_offset
= 0;
5640 fontp
->relative_compose
= 0;
5641 fontp
->default_ascent
= 0;
5643 /* Set global flag fonts_changed_p to non-zero if the font loaded
5644 has a character with a smaller width than any other character
5645 before, or if the font loaded has a smalle>r height than any
5646 other font loaded before. If this happens, it will make a
5647 glyph matrix reallocation necessary. */
5648 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
5654 /* Load font named FONTNAME of size SIZE for frame F, and return a
5655 pointer to the structure font_info while allocating it dynamically.
5656 If loading fails, return NULL. */
5658 w32_load_font (f
,fontname
,size
)
5663 Lisp_Object bdf_fonts
;
5664 struct font_info
*retval
= NULL
;
5666 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
));
5668 while (!retval
&& CONSP (bdf_fonts
))
5670 char *bdf_name
, *bdf_file
;
5671 Lisp_Object bdf_pair
;
5673 bdf_name
= XSTRING (XCAR (bdf_fonts
))->data
;
5674 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
5675 bdf_file
= XSTRING (XCDR (bdf_pair
))->data
;
5677 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
5679 bdf_fonts
= XCDR (bdf_fonts
);
5685 return w32_load_system_font(f
, fontname
, size
);
5690 w32_unload_font (dpyinfo
, font
)
5691 struct w32_display_info
*dpyinfo
;
5696 if (font
->per_char
) xfree (font
->per_char
);
5697 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
5699 if (font
->hfont
) DeleteObject(font
->hfont
);
5704 /* The font conversion stuff between x and w32 */
5706 /* X font string is as follows (from faces.el)
5710 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
5711 * (weight\? "\\([^-]*\\)") ; 1
5712 * (slant "\\([ior]\\)") ; 2
5713 * (slant\? "\\([^-]?\\)") ; 2
5714 * (swidth "\\([^-]*\\)") ; 3
5715 * (adstyle "[^-]*") ; 4
5716 * (pixelsize "[0-9]+")
5717 * (pointsize "[0-9][0-9]+")
5718 * (resx "[0-9][0-9]+")
5719 * (resy "[0-9][0-9]+")
5720 * (spacing "[cmp?*]")
5721 * (avgwidth "[0-9]+")
5722 * (registry "[^-]+")
5723 * (encoding "[^-]+")
5728 x_to_w32_weight (lpw
)
5731 if (!lpw
) return (FW_DONTCARE
);
5733 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
5734 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
5735 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
5736 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
5737 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
5738 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
5739 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
5740 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
5741 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
5742 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
5749 w32_to_x_weight (fnweight
)
5752 if (fnweight
>= FW_HEAVY
) return "heavy";
5753 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
5754 if (fnweight
>= FW_BOLD
) return "bold";
5755 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
5756 if (fnweight
>= FW_MEDIUM
) return "medium";
5757 if (fnweight
>= FW_NORMAL
) return "normal";
5758 if (fnweight
>= FW_LIGHT
) return "light";
5759 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
5760 if (fnweight
>= FW_THIN
) return "thin";
5766 x_to_w32_charset (lpcs
)
5769 Lisp_Object this_entry
, w32_charset
;
5771 /* Look through w32-charset-info-alist for the character set.
5772 Format of each entry is
5773 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5775 this_entry
= Fassoc (build_string(lpcs
), Vw32_charset_info_alist
);
5777 if (NILP(this_entry
))
5779 /* At startup, we want iso8859-1 fonts to come up properly. */
5780 if (stricmp(lpcs
, "iso8859-1") == 0)
5781 return ANSI_CHARSET
;
5783 return DEFAULT_CHARSET
;
5786 w32_charset
= Fcar (Fcdr (this_entry
));
5788 // Translate Lisp symbol to number.
5789 if (w32_charset
== Qw32_charset_ansi
)
5790 return ANSI_CHARSET
;
5791 if (w32_charset
== Qw32_charset_symbol
)
5792 return SYMBOL_CHARSET
;
5793 if (w32_charset
== Qw32_charset_shiftjis
)
5794 return SHIFTJIS_CHARSET
;
5795 if (w32_charset
== Qw32_charset_hangeul
)
5796 return HANGEUL_CHARSET
;
5797 if (w32_charset
== Qw32_charset_chinesebig5
)
5798 return CHINESEBIG5_CHARSET
;
5799 if (w32_charset
== Qw32_charset_gb2312
)
5800 return GB2312_CHARSET
;
5801 if (w32_charset
== Qw32_charset_oem
)
5803 #ifdef JOHAB_CHARSET
5804 if (w32_charset
== Qw32_charset_johab
)
5805 return JOHAB_CHARSET
;
5806 if (w32_charset
== Qw32_charset_easteurope
)
5807 return EASTEUROPE_CHARSET
;
5808 if (w32_charset
== Qw32_charset_turkish
)
5809 return TURKISH_CHARSET
;
5810 if (w32_charset
== Qw32_charset_baltic
)
5811 return BALTIC_CHARSET
;
5812 if (w32_charset
== Qw32_charset_russian
)
5813 return RUSSIAN_CHARSET
;
5814 if (w32_charset
== Qw32_charset_arabic
)
5815 return ARABIC_CHARSET
;
5816 if (w32_charset
== Qw32_charset_greek
)
5817 return GREEK_CHARSET
;
5818 if (w32_charset
== Qw32_charset_hebrew
)
5819 return HEBREW_CHARSET
;
5820 if (w32_charset
== Qw32_charset_vietnamese
)
5821 return VIETNAMESE_CHARSET
;
5822 if (w32_charset
== Qw32_charset_thai
)
5823 return THAI_CHARSET
;
5824 if (w32_charset
== Qw32_charset_mac
)
5826 #endif /* JOHAB_CHARSET */
5827 #ifdef UNICODE_CHARSET
5828 if (w32_charset
== Qw32_charset_unicode
)
5829 return UNICODE_CHARSET
;
5832 return DEFAULT_CHARSET
;
5837 w32_to_x_charset (fncharset
)
5840 static char buf
[16];
5841 Lisp_Object charset_type
;
5846 /* Handle startup case of w32-charset-info-alist not
5847 being set up yet. */
5848 if (NILP(Vw32_charset_info_alist
))
5850 charset_type
= Qw32_charset_ansi
;
5852 case DEFAULT_CHARSET
:
5853 charset_type
= Qw32_charset_default
;
5855 case SYMBOL_CHARSET
:
5856 charset_type
= Qw32_charset_symbol
;
5858 case SHIFTJIS_CHARSET
:
5859 charset_type
= Qw32_charset_shiftjis
;
5861 case HANGEUL_CHARSET
:
5862 charset_type
= Qw32_charset_hangeul
;
5864 case GB2312_CHARSET
:
5865 charset_type
= Qw32_charset_gb2312
;
5867 case CHINESEBIG5_CHARSET
:
5868 charset_type
= Qw32_charset_chinesebig5
;
5871 charset_type
= Qw32_charset_oem
;
5874 /* More recent versions of Windows (95 and NT4.0) define more
5876 #ifdef EASTEUROPE_CHARSET
5877 case EASTEUROPE_CHARSET
:
5878 charset_type
= Qw32_charset_easteurope
;
5880 case TURKISH_CHARSET
:
5881 charset_type
= Qw32_charset_turkish
;
5883 case BALTIC_CHARSET
:
5884 charset_type
= Qw32_charset_baltic
;
5886 case RUSSIAN_CHARSET
:
5887 charset_type
= Qw32_charset_russian
;
5889 case ARABIC_CHARSET
:
5890 charset_type
= Qw32_charset_arabic
;
5893 charset_type
= Qw32_charset_greek
;
5895 case HEBREW_CHARSET
:
5896 charset_type
= Qw32_charset_hebrew
;
5898 case VIETNAMESE_CHARSET
:
5899 charset_type
= Qw32_charset_vietnamese
;
5902 charset_type
= Qw32_charset_thai
;
5905 charset_type
= Qw32_charset_mac
;
5908 charset_type
= Qw32_charset_johab
;
5912 #ifdef UNICODE_CHARSET
5913 case UNICODE_CHARSET
:
5914 charset_type
= Qw32_charset_unicode
;
5918 /* Encode numerical value of unknown charset. */
5919 sprintf (buf
, "*-#%u", fncharset
);
5925 char * best_match
= NULL
;
5927 /* Look through w32-charset-info-alist for the character set.
5928 Prefer ISO codepages, and prefer lower numbers in the ISO
5929 range. Only return charsets for codepages which are installed.
5931 Format of each entry is
5932 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5934 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5937 Lisp_Object w32_charset
;
5938 Lisp_Object codepage
;
5940 Lisp_Object this_entry
= XCAR (rest
);
5942 /* Skip invalid entries in alist. */
5943 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
5944 || !CONSP (XCDR (this_entry
))
5945 || !SYMBOLP (XCAR (XCDR (this_entry
))))
5948 x_charset
= XSTRING (XCAR (this_entry
))->data
;
5949 w32_charset
= XCAR (XCDR (this_entry
));
5950 codepage
= XCDR (XCDR (this_entry
));
5952 /* Look for Same charset and a valid codepage (or non-int
5953 which means ignore). */
5954 if (w32_charset
== charset_type
5955 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
5956 || IsValidCodePage (XINT (codepage
))))
5958 /* If we don't have a match already, then this is the
5961 best_match
= x_charset
;
5962 /* If this is an ISO codepage, and the best so far isn't,
5963 then this is better. */
5964 else if (stricmp (best_match
, "iso") != 0
5965 && stricmp (x_charset
, "iso") == 0)
5966 best_match
= x_charset
;
5967 /* If both are ISO8859 codepages, choose the one with the
5968 lowest number in the encoding field. */
5969 else if (stricmp (best_match
, "iso8859-") == 0
5970 && stricmp (x_charset
, "iso8859-") == 0)
5972 int best_enc
= atoi (best_match
+ 8);
5973 int this_enc
= atoi (x_charset
+ 8);
5974 if (this_enc
> 0 && this_enc
< best_enc
)
5975 best_match
= x_charset
;
5980 /* If no match, encode the numeric value. */
5983 sprintf (buf
, "*-#%u", fncharset
);
5987 strncpy(buf
, best_match
, 15);
5994 /* Get the Windows codepage corresponding to the specified font. The
5995 charset info in the font name is used to look up
5996 w32-charset-to-codepage-alist. */
5998 w32_codepage_for_font (char *fontname
)
6000 Lisp_Object codepage
, entry
;
6001 char *charset_str
, *charset
, *end
;
6003 if (NILP (Vw32_charset_info_alist
))
6006 /* Extract charset part of font string. */
6007 charset
= xlfd_charset_of_font (fontname
);
6012 charset_str
= (char *) alloca (strlen (charset
));
6013 strcpy (charset_str
, charset
);
6015 /* Remove leading "*-". */
6016 if (strncmp ("*-", charset_str
, 2) == 0)
6017 charset
= charset_str
+ 2;
6019 charset
= charset_str
;
6021 /* Stop match at wildcard (including preceding '-'). */
6022 if (end
= strchr (charset
, '*'))
6024 if (end
> charset
&& *(end
-1) == '-')
6029 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6033 codepage
= Fcdr (Fcdr (entry
));
6035 if (NILP (codepage
))
6037 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
6039 else if (INTEGERP (codepage
))
6040 return XINT (codepage
);
6047 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
6048 LOGFONT
* lplogfont
;
6051 char * specific_charset
;
6055 char height_pixels
[8];
6057 char width_pixels
[8];
6058 char *fontname_dash
;
6059 int display_resy
= one_w32_display_info
.resy
;
6060 int display_resx
= one_w32_display_info
.resx
;
6062 struct coding_system coding
;
6064 if (!lpxstr
) abort ();
6069 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
6070 fonttype
= "raster";
6071 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
6072 fonttype
= "outline";
6074 fonttype
= "unknown";
6076 setup_coding_system (Fcheck_coding_system (Vw32_system_coding_system
),
6078 coding
.src_multibyte
= 0;
6079 coding
.dst_multibyte
= 1;
6080 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6081 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
6083 fontname
= alloca(sizeof(*fontname
) * bufsz
);
6084 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
6085 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
6086 *(fontname
+ coding
.produced
) = '\0';
6088 /* Replace dashes with underscores so the dashes are not
6090 fontname_dash
= fontname
;
6091 while (fontname_dash
= strchr (fontname_dash
, '-'))
6092 *fontname_dash
= '_';
6094 if (lplogfont
->lfHeight
)
6096 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
6097 sprintf (height_dpi
, "%u",
6098 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
6102 strcpy (height_pixels
, "*");
6103 strcpy (height_dpi
, "*");
6105 if (lplogfont
->lfWidth
)
6106 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
6108 strcpy (width_pixels
, "*");
6110 _snprintf (lpxstr
, len
- 1,
6111 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
6112 fonttype
, /* foundry */
6113 fontname
, /* family */
6114 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
6115 lplogfont
->lfItalic
?'i':'r', /* slant */
6117 /* add style name */
6118 height_pixels
, /* pixel size */
6119 height_dpi
, /* point size */
6120 display_resx
, /* resx */
6121 display_resy
, /* resy */
6122 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
6123 ? 'p' : 'c', /* spacing */
6124 width_pixels
, /* avg width */
6125 specific_charset
? specific_charset
6126 : w32_to_x_charset (lplogfont
->lfCharSet
)
6127 /* charset registry and encoding */
6130 lpxstr
[len
- 1] = 0; /* just to be sure */
6135 x_to_w32_font (lpxstr
, lplogfont
)
6137 LOGFONT
* lplogfont
;
6139 struct coding_system coding
;
6141 if (!lplogfont
) return (FALSE
);
6143 memset (lplogfont
, 0, sizeof (*lplogfont
));
6145 /* Set default value for each field. */
6147 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
6148 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
6149 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
6151 /* go for maximum quality */
6152 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
6153 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
6154 lplogfont
->lfQuality
= PROOF_QUALITY
;
6157 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
6158 lplogfont
->lfWeight
= FW_DONTCARE
;
6159 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
6164 /* Provide a simple escape mechanism for specifying Windows font names
6165 * directly -- if font spec does not beginning with '-', assume this
6167 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
6173 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
6174 width
[10], resy
[10], remainder
[20];
6176 int dpi
= one_w32_display_info
.resy
;
6178 fields
= sscanf (lpxstr
,
6179 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%19s",
6180 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
6181 if (fields
== EOF
) return (FALSE
);
6183 /* If wildcards cover more than one field, we don't know which
6184 field is which, so don't fill any in. */
6189 if (fields
> 0 && name
[0] != '*')
6195 (Fcheck_coding_system (Vw32_system_coding_system
), &coding
);
6196 coding
.src_multibyte
= 1;
6197 coding
.dst_multibyte
= 1;
6198 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
6199 buf
= (unsigned char *) alloca (bufsize
);
6200 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6201 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
6202 if (coding
.produced
>= LF_FACESIZE
)
6203 coding
.produced
= LF_FACESIZE
- 1;
6204 buf
[coding
.produced
] = 0;
6205 strcpy (lplogfont
->lfFaceName
, buf
);
6209 lplogfont
->lfFaceName
[0] = '\0';
6214 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6218 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
6222 if (fields
> 0 && pixels
[0] != '*')
6223 lplogfont
->lfHeight
= atoi (pixels
);
6227 if (fields
> 0 && resy
[0] != '*')
6230 if (tem
> 0) dpi
= tem
;
6233 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
6234 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
6237 lplogfont
->lfPitchAndFamily
=
6238 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
6242 if (fields
> 0 && width
[0] != '*')
6243 lplogfont
->lfWidth
= atoi (width
) / 10;
6247 /* Strip the trailing '-' if present. (it shouldn't be, as it
6248 fails the test against xlfd-tight-regexp in fontset.el). */
6250 int len
= strlen (remainder
);
6251 if (len
> 0 && remainder
[len
-1] == '-')
6252 remainder
[len
-1] = 0;
6254 encoding
= remainder
;
6255 if (strncmp (encoding
, "*-", 2) == 0)
6257 lplogfont
->lfCharSet
= x_to_w32_charset (fields
> 0 ? encoding
: "");
6262 char name
[100], height
[10], width
[10], weight
[20];
6264 fields
= sscanf (lpxstr
,
6265 "%99[^:]:%9[^:]:%9[^:]:%19s",
6266 name
, height
, width
, weight
);
6268 if (fields
== EOF
) return (FALSE
);
6272 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
6273 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
6277 lplogfont
->lfFaceName
[0] = 0;
6283 lplogfont
->lfHeight
= atoi (height
);
6288 lplogfont
->lfWidth
= atoi (width
);
6292 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6295 /* This makes TrueType fonts work better. */
6296 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
6301 /* Strip the pixel height and point height from the given xlfd, and
6302 return the pixel height. If no pixel height is specified, calculate
6303 one from the point height, or if that isn't defined either, return
6304 0 (which usually signifies a scalable font).
6306 int xlfd_strip_height (char *fontname
)
6308 int pixel_height
, point_height
, dpi
, field_number
;
6309 char *read_from
, *write_to
;
6313 pixel_height
= field_number
= 0;
6316 /* Look for height fields. */
6317 for (read_from
= fontname
; *read_from
; read_from
++)
6319 if (*read_from
== '-')
6322 if (field_number
== 7) /* Pixel height. */
6325 write_to
= read_from
;
6327 /* Find end of field. */
6328 for (;*read_from
&& *read_from
!= '-'; read_from
++)
6331 /* Split the fontname at end of field. */
6337 pixel_height
= atoi (write_to
);
6338 /* Blank out field. */
6339 if (read_from
> write_to
)
6344 /* If the pixel height field is at the end (partial xlfd),
6347 return pixel_height
;
6349 /* If we got a pixel height, the point height can be
6350 ignored. Just blank it out and break now. */
6353 /* Find end of point size field. */
6354 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6360 /* Blank out the point size field. */
6361 if (read_from
> write_to
)
6367 return pixel_height
;
6371 /* If the point height is already blank, break now. */
6372 if (*read_from
== '-')
6378 else if (field_number
== 8)
6380 /* If we didn't get a pixel height, try to get the point
6381 height and convert that. */
6383 char *point_size_start
= read_from
++;
6385 /* Find end of field. */
6386 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6395 point_size
= atoi (point_size_start
);
6397 /* Convert to pixel height. */
6398 pixel_height
= point_size
6399 * one_w32_display_info
.height_in
/ 720;
6401 /* Blank out this field and break. */
6409 /* Shift the rest of the font spec into place. */
6410 if (write_to
&& read_from
> write_to
)
6412 for (; *read_from
; read_from
++, write_to
++)
6413 *write_to
= *read_from
;
6417 return pixel_height
;
6420 /* Assume parameter 1 is fully qualified, no wildcards. */
6422 w32_font_match (fontname
, pattern
)
6426 char *regex
= alloca (strlen (pattern
) * 2);
6427 char *font_name_copy
= alloca (strlen (fontname
) + 1);
6430 /* Copy fontname so we can modify it during comparison. */
6431 strcpy (font_name_copy
, fontname
);
6436 /* Turn pattern into a regexp and do a regexp match. */
6437 for (; *pattern
; pattern
++)
6439 if (*pattern
== '?')
6441 else if (*pattern
== '*')
6452 /* Strip out font heights and compare them seperately, since
6453 rounding error can cause mismatches. This also allows a
6454 comparison between a font that declares only a pixel height and a
6455 pattern that declares the point height.
6458 int font_height
, pattern_height
;
6460 font_height
= xlfd_strip_height (font_name_copy
);
6461 pattern_height
= xlfd_strip_height (regex
);
6463 /* Compare now, and don't bother doing expensive regexp matching
6464 if the heights differ. */
6465 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
6469 return (fast_c_string_match_ignore_case (build_string (regex
),
6470 font_name_copy
) >= 0);
6473 /* Callback functions, and a structure holding info they need, for
6474 listing system fonts on W32. We need one set of functions to do the
6475 job properly, but these don't work on NT 3.51 and earlier, so we
6476 have a second set which don't handle character sets properly to
6479 In both cases, there are two passes made. The first pass gets one
6480 font from each family, the second pass lists all the fonts from
6483 typedef struct enumfont_t
6488 XFontStruct
*size_ref
;
6489 Lisp_Object
*pattern
;
6494 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
6496 NEWTEXTMETRIC
* lptm
;
6500 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
6503 /* Check that the character set matches if it was specified */
6504 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6505 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6510 Lisp_Object width
= Qnil
;
6511 char *charset
= NULL
;
6513 /* Truetype fonts do not report their true metrics until loaded */
6514 if (FontType
!= RASTER_FONTTYPE
)
6516 if (!NILP (*(lpef
->pattern
)))
6518 /* Scalable fonts are as big as you want them to be. */
6519 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6520 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6521 width
= make_number (lpef
->logfont
.lfWidth
);
6525 lplf
->elfLogFont
.lfHeight
= 0;
6526 lplf
->elfLogFont
.lfWidth
= 0;
6530 /* Make sure the height used here is the same as everywhere
6531 else (ie character height, not cell height). */
6532 if (lplf
->elfLogFont
.lfHeight
> 0)
6534 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6535 if (FontType
== RASTER_FONTTYPE
)
6536 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6538 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6541 if (!NILP (*(lpef
->pattern
)))
6543 charset
= xlfd_charset_of_font (XSTRING(*(lpef
->pattern
))->data
);
6545 /* Ensure that charset is valid for this font. */
6547 && (x_to_w32_charset (charset
) != lplf
->elfLogFont
.lfCharSet
))
6551 /* TODO: List all relevant charsets if charset not specified. */
6552 if (!w32_to_x_font (&(lplf
->elfLogFont
), buf
, 100, charset
))
6555 if (NILP (*(lpef
->pattern
))
6556 || w32_font_match (buf
, XSTRING (*(lpef
->pattern
))->data
))
6558 *lpef
->tail
= Fcons (Fcons (build_string (buf
), width
), Qnil
);
6559 lpef
->tail
= &(XCDR (*lpef
->tail
));
6568 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6570 NEWTEXTMETRIC
* lptm
;
6574 return EnumFontFamilies (lpef
->hdc
,
6575 lplf
->elfLogFont
.lfFaceName
,
6576 (FONTENUMPROC
) enum_font_cb2
,
6582 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6583 ENUMLOGFONTEX
* lplf
;
6584 NEWTEXTMETRICEX
* lptm
;
6588 /* We are not interested in the extra info we get back from the 'Ex
6589 version - only the fact that we get character set variations
6590 enumerated seperately. */
6591 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6596 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6597 ENUMLOGFONTEX
* lplf
;
6598 NEWTEXTMETRICEX
* lptm
;
6602 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6603 FARPROC enum_font_families_ex
6604 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6605 /* We don't really expect EnumFontFamiliesEx to disappear once we
6606 get here, so don't bother handling it gracefully. */
6607 if (enum_font_families_ex
== NULL
)
6608 error ("gdi32.dll has disappeared!");
6609 return enum_font_families_ex (lpef
->hdc
,
6611 (FONTENUMPROC
) enum_fontex_cb2
,
6615 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6616 and xterm.c in Emacs 20.3) */
6618 Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6620 char *fontname
, *ptnstr
;
6621 Lisp_Object list
, tem
, newlist
= Qnil
;
6624 list
= Vw32_bdf_filename_alist
;
6625 ptnstr
= XSTRING (pattern
)->data
;
6627 for ( ; CONSP (list
); list
= XCDR (list
))
6631 fontname
= XSTRING (XCAR (tem
))->data
;
6632 else if (STRINGP (tem
))
6633 fontname
= XSTRING (tem
)->data
;
6637 if (w32_font_match (fontname
, ptnstr
))
6639 newlist
= Fcons (XCAR (tem
), newlist
);
6641 if (n_fonts
>= max_names
)
6649 Lisp_Object
w32_list_synthesized_fonts (FRAME_PTR f
, Lisp_Object pattern
,
6650 int size
, int max_names
);
6652 /* Return a list of names of available fonts matching PATTERN on frame
6653 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6654 to be listed. Frame F NULL means we have not yet created any
6655 frame, which means we can't get proper size info, as we don't have
6656 a device context to use for GetTextMetrics.
6657 MAXNAMES sets a limit on how many fonts to match. */
6660 w32_list_fonts (FRAME_PTR f
, Lisp_Object pattern
, int size
, int maxnames
)
6662 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6663 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6664 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6667 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6668 if (NILP (patterns
))
6669 patterns
= Fcons (pattern
, Qnil
);
6671 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6676 tpat
= XCAR (patterns
);
6678 if (!STRINGP (tpat
))
6681 /* Avoid expensive EnumFontFamilies functions if we are not
6682 going to be able to output one of these anyway. */
6683 codepage
= w32_codepage_for_font (XSTRING (tpat
)->data
);
6684 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6685 && codepage
!= CP_DEFAULT
&& !IsValidCodePage(codepage
))
6688 /* See if we cached the result for this particular query.
6689 The cache is an alist of the form:
6690 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6692 if (tem
= XCDR (dpyinfo
->name_list_element
),
6693 !NILP (list
= Fassoc (tpat
, tem
)))
6695 list
= Fcdr_safe (list
);
6696 /* We have a cached list. Don't have to get the list again. */
6701 /* At first, put PATTERN in the cache. */
6707 /* Use EnumFontFamiliesEx where it is available, as it knows
6708 about character sets. Fall back to EnumFontFamilies for
6709 older versions of NT that don't support the 'Ex function. */
6710 x_to_w32_font (XSTRING (tpat
)->data
, &ef
.logfont
);
6712 LOGFONT font_match_pattern
;
6713 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6714 FARPROC enum_font_families_ex
6715 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6717 /* We do our own pattern matching so we can handle wildcards. */
6718 font_match_pattern
.lfFaceName
[0] = 0;
6719 font_match_pattern
.lfPitchAndFamily
= 0;
6720 /* We can use the charset, because if it is a wildcard it will
6721 be DEFAULT_CHARSET anyway. */
6722 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6724 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6726 if (enum_font_families_ex
)
6727 enum_font_families_ex (ef
.hdc
,
6728 &font_match_pattern
,
6729 (FONTENUMPROC
) enum_fontex_cb1
,
6732 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6735 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6740 /* Make a list of the fonts we got back.
6741 Store that in the font cache for the display. */
6742 XCDR (dpyinfo
->name_list_element
)
6743 = Fcons (Fcons (tpat
, list
),
6744 XCDR (dpyinfo
->name_list_element
));
6747 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6749 newlist
= second_best
= Qnil
;
6751 /* Make a list of the fonts that have the right width. */
6752 for (; CONSP (list
); list
= XCDR (list
))
6759 if (NILP (XCAR (tem
)))
6763 newlist
= Fcons (XCAR (tem
), newlist
);
6765 if (n_fonts
>= maxnames
)
6770 if (!INTEGERP (XCDR (tem
)))
6772 /* Since we don't yet know the size of the font, we must
6773 load it and try GetTextMetrics. */
6774 W32FontStruct thisinfo
;
6779 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
6783 thisinfo
.bdf
= NULL
;
6784 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6785 if (thisinfo
.hfont
== NULL
)
6788 hdc
= GetDC (dpyinfo
->root_window
);
6789 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6790 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6791 XCDR (tem
) = make_number (FONT_WIDTH (&thisinfo
));
6793 XCDR (tem
) = make_number (0);
6794 SelectObject (hdc
, oldobj
);
6795 ReleaseDC (dpyinfo
->root_window
, hdc
);
6796 DeleteObject(thisinfo
.hfont
);
6799 found_size
= XINT (XCDR (tem
));
6800 if (found_size
== size
)
6802 newlist
= Fcons (XCAR (tem
), newlist
);
6804 if (n_fonts
>= maxnames
)
6807 /* keep track of the closest matching size in case
6808 no exact match is found. */
6809 else if (found_size
> 0)
6811 if (NILP (second_best
))
6814 else if (found_size
< size
)
6816 if (XINT (XCDR (second_best
)) > size
6817 || XINT (XCDR (second_best
)) < found_size
)
6822 if (XINT (XCDR (second_best
)) > size
6823 && XINT (XCDR (second_best
)) >
6830 if (!NILP (newlist
))
6832 else if (!NILP (second_best
))
6834 newlist
= Fcons (XCAR (second_best
), Qnil
);
6839 /* Include any bdf fonts. */
6840 if (n_fonts
< maxnames
)
6842 Lisp_Object combined
[2];
6843 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6844 combined
[1] = newlist
;
6845 newlist
= Fnconc(2, combined
);
6848 /* If we can't find a font that matches, check if Windows would be
6849 able to synthesize it from a different style. */
6850 if (NILP (newlist
) && !NILP (Vw32_enable_synthesized_fonts
))
6851 newlist
= w32_list_synthesized_fonts (f
, pattern
, size
, maxnames
);
6857 w32_list_synthesized_fonts (f
, pattern
, size
, max_names
)
6859 Lisp_Object pattern
;
6864 char *full_pattn
, *new_pattn
, foundary
[50], family
[50], *pattn_part2
;
6865 char style
[20], slant
;
6866 Lisp_Object matches
, match
, tem
, synthed_matches
= Qnil
;
6868 full_pattn
= XSTRING (pattern
)->data
;
6870 pattn_part2
= alloca (XSTRING (pattern
)->size
);
6871 /* Allow some space for wildcard expansion. */
6872 new_pattn
= alloca (XSTRING (pattern
)->size
+ 100);
6874 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%19[^-]-%c-%s",
6875 foundary
, family
, style
, &slant
, pattn_part2
);
6876 if (fields
== EOF
|| fields
< 5)
6879 /* If the style and slant are wildcards already there is no point
6880 checking again (and we don't want to keep recursing). */
6881 if (*style
== '*' && slant
== '*')
6884 sprintf (new_pattn
, "-%s-%s-*-*-%s", foundary
, family
, pattn_part2
);
6886 matches
= w32_list_fonts (f
, build_string (new_pattn
), size
, max_names
);
6888 for ( ; CONSP (matches
); matches
= XCDR (matches
))
6890 tem
= XCAR (matches
);
6894 full_pattn
= XSTRING (tem
)->data
;
6895 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%*[^-]-%*c-%s",
6896 foundary
, family
, pattn_part2
);
6897 if (fields
== EOF
|| fields
< 3)
6900 sprintf (new_pattn
, "-%s-%s-%s-%c-%s", foundary
, family
, style
,
6901 slant
, pattn_part2
);
6903 synthed_matches
= Fcons (build_string (new_pattn
),
6907 return synthed_matches
;
6911 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6913 w32_get_font_info (f
, font_idx
)
6917 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6922 w32_query_font (struct frame
*f
, char *fontname
)
6925 struct font_info
*pfi
;
6927 pfi
= FRAME_W32_FONT_TABLE (f
);
6929 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6931 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
6937 /* Find a CCL program for a font specified by FONTP, and set the member
6938 `encoder' of the structure. */
6941 w32_find_ccl_program (fontp
)
6942 struct font_info
*fontp
;
6944 Lisp_Object list
, elt
;
6946 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
6950 && STRINGP (XCAR (elt
))
6951 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
6957 struct ccl_program
*ccl
6958 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6960 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
6963 fontp
->font_encoder
= ccl
;
6968 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
6970 "Return a list of BDF fonts in DIR, suitable for appending to\n\
6971 w32-bdf-filename-alist. Fonts which do not contain an xlfd description\n\
6972 will not be included in the list. DIR may be a list of directories.")
6974 Lisp_Object directory
;
6976 Lisp_Object list
= Qnil
;
6977 struct gcpro gcpro1
, gcpro2
;
6979 if (!CONSP (directory
))
6980 return w32_find_bdf_fonts_in_dir (directory
);
6982 for ( ; CONSP (directory
); directory
= XCDR (directory
))
6984 Lisp_Object pair
[2];
6987 GCPRO2 (directory
, list
);
6988 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
6989 list
= Fnconc( 2, pair
);
6995 /* Find BDF files in a specified directory. (use GCPRO when calling,
6996 as this calls lisp to get a directory listing). */
6997 Lisp_Object
w32_find_bdf_fonts_in_dir( Lisp_Object directory
)
6999 Lisp_Object filelist
, list
= Qnil
;
7002 if (!STRINGP(directory
))
7005 filelist
= Fdirectory_files (directory
, Qt
,
7006 build_string (".*\\.[bB][dD][fF]"), Qt
);
7008 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
7010 Lisp_Object filename
= XCAR (filelist
);
7011 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
7012 store_in_alist (&list
, build_string (fontname
), filename
);
7018 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
7019 "Internal function called by `color-defined-p', which see.")
7021 Lisp_Object color
, frame
;
7024 FRAME_PTR f
= check_x_frame (frame
);
7026 CHECK_STRING (color
, 1);
7028 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7034 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
7035 "Internal function called by `color-values', which see.")
7037 Lisp_Object color
, frame
;
7040 FRAME_PTR f
= check_x_frame (frame
);
7042 CHECK_STRING (color
, 1);
7044 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7048 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
7049 | GetRValue (foo
.pixel
));
7050 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
7051 | GetGValue (foo
.pixel
));
7052 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
7053 | GetBValue (foo
.pixel
));
7054 return Flist (3, rgb
);
7060 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
7061 "Internal function called by `display-color-p', which see.")
7063 Lisp_Object display
;
7065 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7067 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
7073 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
7075 "Return t if the X display supports shades of gray.\n\
7076 Note that color displays do support shades of gray.\n\
7077 The optional argument DISPLAY specifies which display to ask about.\n\
7078 DISPLAY should be either a frame or a display name (a string).\n\
7079 If omitted or nil, that stands for the selected frame's display.")
7081 Lisp_Object display
;
7083 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7085 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
7091 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
7093 "Returns the width in pixels of the X display DISPLAY.\n\
7094 The optional argument DISPLAY specifies which display to ask about.\n\
7095 DISPLAY should be either a frame or a display name (a string).\n\
7096 If omitted or nil, that stands for the selected frame's display.")
7098 Lisp_Object display
;
7100 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7102 return make_number (dpyinfo
->width
);
7105 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
7106 Sx_display_pixel_height
, 0, 1, 0,
7107 "Returns the height in pixels of the X display DISPLAY.\n\
7108 The optional argument DISPLAY specifies which display to ask about.\n\
7109 DISPLAY should be either a frame or a display name (a string).\n\
7110 If omitted or nil, that stands for the selected frame's display.")
7112 Lisp_Object display
;
7114 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7116 return make_number (dpyinfo
->height
);
7119 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
7121 "Returns the number of bitplanes of the display DISPLAY.\n\
7122 The optional argument DISPLAY specifies which display to ask about.\n\
7123 DISPLAY should be either a frame or a display name (a string).\n\
7124 If omitted or nil, that stands for the selected frame's display.")
7126 Lisp_Object display
;
7128 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7130 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7133 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
7135 "Returns the number of color cells of the display DISPLAY.\n\
7136 The optional argument DISPLAY specifies which display to ask about.\n\
7137 DISPLAY should be either a frame or a display name (a string).\n\
7138 If omitted or nil, that stands for the selected frame's display.")
7140 Lisp_Object display
;
7142 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7146 hdc
= GetDC (dpyinfo
->root_window
);
7147 if (dpyinfo
->has_palette
)
7148 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
7150 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
7152 ReleaseDC (dpyinfo
->root_window
, hdc
);
7154 return make_number (cap
);
7157 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
7158 Sx_server_max_request_size
,
7160 "Returns the maximum request size of the server of display DISPLAY.\n\
7161 The optional argument DISPLAY specifies which display to ask about.\n\
7162 DISPLAY should be either a frame or a display name (a string).\n\
7163 If omitted or nil, that stands for the selected frame's display.")
7165 Lisp_Object display
;
7167 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7169 return make_number (1);
7172 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
7173 "Returns the vendor ID string of the W32 system (Microsoft).\n\
7174 The optional argument DISPLAY specifies which display to ask about.\n\
7175 DISPLAY should be either a frame or a display name (a string).\n\
7176 If omitted or nil, that stands for the selected frame's display.")
7178 Lisp_Object display
;
7180 return build_string ("Microsoft Corp.");
7183 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
7184 "Returns the version numbers of the server of display DISPLAY.\n\
7185 The value is a list of three integers: the major and minor\n\
7186 version numbers, and the vendor-specific release\n\
7187 number. See also the function `x-server-vendor'.\n\n\
7188 The optional argument DISPLAY specifies which display to ask about.\n\
7189 DISPLAY should be either a frame or a display name (a string).\n\
7190 If omitted or nil, that stands for the selected frame's display.")
7192 Lisp_Object display
;
7194 return Fcons (make_number (w32_major_version
),
7195 Fcons (make_number (w32_minor_version
),
7196 Fcons (make_number (w32_build_number
), Qnil
)));
7199 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
7200 "Returns the number of screens on the server of display DISPLAY.\n\
7201 The optional argument DISPLAY specifies which display to ask about.\n\
7202 DISPLAY should be either a frame or a display name (a string).\n\
7203 If omitted or nil, that stands for the selected frame's display.")
7205 Lisp_Object display
;
7207 return make_number (1);
7210 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
7211 "Returns the height in millimeters of the X display DISPLAY.\n\
7212 The optional argument DISPLAY specifies which display to ask about.\n\
7213 DISPLAY should be either a frame or a display name (a string).\n\
7214 If omitted or nil, that stands for the selected frame's display.")
7216 Lisp_Object display
;
7218 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7222 hdc
= GetDC (dpyinfo
->root_window
);
7224 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
7226 ReleaseDC (dpyinfo
->root_window
, hdc
);
7228 return make_number (cap
);
7231 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
7232 "Returns the width in millimeters of the X display DISPLAY.\n\
7233 The optional argument DISPLAY specifies which display to ask about.\n\
7234 DISPLAY should be either a frame or a display name (a string).\n\
7235 If omitted or nil, that stands for the selected frame's display.")
7237 Lisp_Object display
;
7239 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7244 hdc
= GetDC (dpyinfo
->root_window
);
7246 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
7248 ReleaseDC (dpyinfo
->root_window
, hdc
);
7250 return make_number (cap
);
7253 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
7254 Sx_display_backing_store
, 0, 1, 0,
7255 "Returns an indication of whether display DISPLAY does backing store.\n\
7256 The value may be `always', `when-mapped', or `not-useful'.\n\
7257 The optional argument DISPLAY specifies which display to ask about.\n\
7258 DISPLAY should be either a frame or a display name (a string).\n\
7259 If omitted or nil, that stands for the selected frame's display.")
7261 Lisp_Object display
;
7263 return intern ("not-useful");
7266 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
7267 Sx_display_visual_class
, 0, 1, 0,
7268 "Returns the visual class of the display DISPLAY.\n\
7269 The value is one of the symbols `static-gray', `gray-scale',\n\
7270 `static-color', `pseudo-color', `true-color', or `direct-color'.\n\n\
7271 The optional argument DISPLAY specifies which display to ask about.\n\
7272 DISPLAY should be either a frame or a display name (a string).\n\
7273 If omitted or nil, that stands for the selected frame's display.")
7275 Lisp_Object display
;
7277 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7280 switch (dpyinfo
->visual
->class)
7282 case StaticGray
: return (intern ("static-gray"));
7283 case GrayScale
: return (intern ("gray-scale"));
7284 case StaticColor
: return (intern ("static-color"));
7285 case PseudoColor
: return (intern ("pseudo-color"));
7286 case TrueColor
: return (intern ("true-color"));
7287 case DirectColor
: return (intern ("direct-color"));
7289 error ("Display has an unknown visual class");
7293 error ("Display has an unknown visual class");
7296 DEFUN ("x-display-save-under", Fx_display_save_under
,
7297 Sx_display_save_under
, 0, 1, 0,
7298 "Returns t if the display DISPLAY supports the save-under feature.\n\
7299 The optional argument DISPLAY specifies which display to ask about.\n\
7300 DISPLAY should be either a frame or a display name (a string).\n\
7301 If omitted or nil, that stands for the selected frame's display.")
7303 Lisp_Object display
;
7310 register struct frame
*f
;
7312 return PIXEL_WIDTH (f
);
7317 register struct frame
*f
;
7319 return PIXEL_HEIGHT (f
);
7324 register struct frame
*f
;
7326 return FONT_WIDTH (f
->output_data
.w32
->font
);
7331 register struct frame
*f
;
7333 return f
->output_data
.w32
->line_height
;
7338 register struct frame
*f
;
7340 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
7343 /* Return the display structure for the display named NAME.
7344 Open a new connection if necessary. */
7346 struct w32_display_info
*
7347 x_display_info_for_name (name
)
7351 struct w32_display_info
*dpyinfo
;
7353 CHECK_STRING (name
, 0);
7355 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
7357 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
7360 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
7365 /* Use this general default value to start with. */
7366 Vx_resource_name
= Vinvocation_name
;
7368 validate_x_resource_name ();
7370 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
7371 (char *) XSTRING (Vx_resource_name
)->data
);
7374 error ("Cannot connect to server %s", XSTRING (name
)->data
);
7377 XSETFASTINT (Vwindow_system_version
, 3);
7382 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
7383 1, 3, 0, "Open a connection to a server.\n\
7384 DISPLAY is the name of the display to connect to.\n\
7385 Optional second arg XRM-STRING is a string of resources in xrdb format.\n\
7386 If the optional third arg MUST-SUCCEED is non-nil,\n\
7387 terminate Emacs if we can't open the connection.")
7388 (display
, xrm_string
, must_succeed
)
7389 Lisp_Object display
, xrm_string
, must_succeed
;
7391 unsigned char *xrm_option
;
7392 struct w32_display_info
*dpyinfo
;
7394 CHECK_STRING (display
, 0);
7395 if (! NILP (xrm_string
))
7396 CHECK_STRING (xrm_string
, 1);
7398 if (! EQ (Vwindow_system
, intern ("w32")))
7399 error ("Not using Microsoft Windows");
7401 /* Allow color mapping to be defined externally; first look in user's
7402 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
7404 Lisp_Object color_file
;
7405 struct gcpro gcpro1
;
7407 color_file
= build_string("~/rgb.txt");
7409 GCPRO1 (color_file
);
7411 if (NILP (Ffile_readable_p (color_file
)))
7413 Fexpand_file_name (build_string ("rgb.txt"),
7414 Fsymbol_value (intern ("data-directory")));
7416 Vw32_color_map
= Fw32_load_color_file (color_file
);
7420 if (NILP (Vw32_color_map
))
7421 Vw32_color_map
= Fw32_default_color_map ();
7423 if (! NILP (xrm_string
))
7424 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
7426 xrm_option
= (unsigned char *) 0;
7428 /* Use this general default value to start with. */
7429 /* First remove .exe suffix from invocation-name - it looks ugly. */
7431 char basename
[ MAX_PATH
], *str
;
7433 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
7434 str
= strrchr (basename
, '.');
7436 Vinvocation_name
= build_string (basename
);
7438 Vx_resource_name
= Vinvocation_name
;
7440 validate_x_resource_name ();
7442 /* This is what opens the connection and sets x_current_display.
7443 This also initializes many symbols, such as those used for input. */
7444 dpyinfo
= w32_term_init (display
, xrm_option
,
7445 (char *) XSTRING (Vx_resource_name
)->data
);
7449 if (!NILP (must_succeed
))
7450 fatal ("Cannot connect to server %s.\n",
7451 XSTRING (display
)->data
);
7453 error ("Cannot connect to server %s", XSTRING (display
)->data
);
7458 XSETFASTINT (Vwindow_system_version
, 3);
7462 DEFUN ("x-close-connection", Fx_close_connection
,
7463 Sx_close_connection
, 1, 1, 0,
7464 "Close the connection to DISPLAY's server.\n\
7465 For DISPLAY, specify either a frame or a display name (a string).\n\
7466 If DISPLAY is nil, that stands for the selected frame's display.")
7468 Lisp_Object display
;
7470 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7473 if (dpyinfo
->reference_count
> 0)
7474 error ("Display still has frames on it");
7477 /* Free the fonts in the font table. */
7478 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7479 if (dpyinfo
->font_table
[i
].name
)
7481 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7482 xfree (dpyinfo
->font_table
[i
].full_name
);
7483 xfree (dpyinfo
->font_table
[i
].name
);
7484 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7486 x_destroy_all_bitmaps (dpyinfo
);
7488 x_delete_display (dpyinfo
);
7494 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7495 "Return the list of display names that Emacs has connections to.")
7498 Lisp_Object tail
, result
;
7501 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
7502 result
= Fcons (XCAR (XCAR (tail
)), result
);
7507 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7508 "If ON is non-nil, report errors as soon as the erring request is made.\n\
7509 If ON is nil, allow buffering of requests.\n\
7510 This is a noop on W32 systems.\n\
7511 The optional second argument DISPLAY specifies which display to act on.\n\
7512 DISPLAY should be either a frame or a display name (a string).\n\
7513 If DISPLAY is omitted or nil, that stands for the selected frame's display.")
7515 Lisp_Object display
, on
;
7522 /***********************************************************************
7524 ***********************************************************************/
7526 /* Value is the number of elements of vector VECTOR. */
7528 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
7530 /* List of supported image types. Use define_image_type to add new
7531 types. Use lookup_image_type to find a type for a given symbol. */
7533 static struct image_type
*image_types
;
7535 /* The symbol `image' which is the car of the lists used to represent
7538 extern Lisp_Object Qimage
;
7540 /* The symbol `xbm' which is used as the type symbol for XBM images. */
7546 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
7547 extern Lisp_Object QCdata
;
7548 Lisp_Object QCtype
, QCascent
, QCmargin
, QCrelief
;
7549 Lisp_Object QCalgorithm
, QCcolor_symbols
, QCheuristic_mask
;
7550 Lisp_Object QCindex
;
7552 /* Other symbols. */
7554 Lisp_Object Qlaplace
;
7556 /* Time in seconds after which images should be removed from the cache
7557 if not displayed. */
7559 Lisp_Object Vimage_cache_eviction_delay
;
7561 /* Function prototypes. */
7563 static void define_image_type
P_ ((struct image_type
*type
));
7564 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
7565 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
7566 static void x_laplace
P_ ((struct frame
*, struct image
*));
7567 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
7571 /* Define a new image type from TYPE. This adds a copy of TYPE to
7572 image_types and adds the symbol *TYPE->type to Vimage_types. */
7575 define_image_type (type
)
7576 struct image_type
*type
;
7578 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
7579 The initialized data segment is read-only. */
7580 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
7581 bcopy (type
, p
, sizeof *p
);
7582 p
->next
= image_types
;
7584 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
7588 /* Look up image type SYMBOL, and return a pointer to its image_type
7589 structure. Value is null if SYMBOL is not a known image type. */
7591 static INLINE
struct image_type
*
7592 lookup_image_type (symbol
)
7595 struct image_type
*type
;
7597 for (type
= image_types
; type
; type
= type
->next
)
7598 if (EQ (symbol
, *type
->type
))
7605 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
7606 valid image specification is a list whose car is the symbol
7607 `image', and whose rest is a property list. The property list must
7608 contain a value for key `:type'. That value must be the name of a
7609 supported image type. The rest of the property list depends on the
7613 valid_image_p (object
)
7618 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
7620 Lisp_Object symbol
= Fplist_get (XCDR (object
), QCtype
);
7621 struct image_type
*type
= lookup_image_type (symbol
);
7624 valid_p
= type
->valid_p (object
);
7631 /* Log error message with format string FORMAT and argument ARG.
7632 Signaling an error, e.g. when an image cannot be loaded, is not a
7633 good idea because this would interrupt redisplay, and the error
7634 message display would lead to another redisplay. This function
7635 therefore simply displays a message. */
7638 image_error (format
, arg1
, arg2
)
7640 Lisp_Object arg1
, arg2
;
7642 add_to_log (format
, arg1
, arg2
);
7647 /***********************************************************************
7648 Image specifications
7649 ***********************************************************************/
7651 enum image_value_type
7653 IMAGE_DONT_CHECK_VALUE_TYPE
,
7656 IMAGE_POSITIVE_INTEGER_VALUE
,
7657 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
7659 IMAGE_INTEGER_VALUE
,
7660 IMAGE_FUNCTION_VALUE
,
7665 /* Structure used when parsing image specifications. */
7667 struct image_keyword
7669 /* Name of keyword. */
7672 /* The type of value allowed. */
7673 enum image_value_type type
;
7675 /* Non-zero means key must be present. */
7678 /* Used to recognize duplicate keywords in a property list. */
7681 /* The value that was found. */
7686 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
7688 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
7691 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
7692 has the format (image KEYWORD VALUE ...). One of the keyword/
7693 value pairs must be `:type TYPE'. KEYWORDS is a vector of
7694 image_keywords structures of size NKEYWORDS describing other
7695 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
7698 parse_image_spec (spec
, keywords
, nkeywords
, type
)
7700 struct image_keyword
*keywords
;
7707 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
7710 plist
= XCDR (spec
);
7711 while (CONSP (plist
))
7713 Lisp_Object key
, value
;
7715 /* First element of a pair must be a symbol. */
7717 plist
= XCDR (plist
);
7721 /* There must follow a value. */
7724 value
= XCAR (plist
);
7725 plist
= XCDR (plist
);
7727 /* Find key in KEYWORDS. Error if not found. */
7728 for (i
= 0; i
< nkeywords
; ++i
)
7729 if (strcmp (keywords
[i
].name
, XSYMBOL (key
)->name
->data
) == 0)
7735 /* Record that we recognized the keyword. If a keywords
7736 was found more than once, it's an error. */
7737 keywords
[i
].value
= value
;
7738 ++keywords
[i
].count
;
7740 if (keywords
[i
].count
> 1)
7743 /* Check type of value against allowed type. */
7744 switch (keywords
[i
].type
)
7746 case IMAGE_STRING_VALUE
:
7747 if (!STRINGP (value
))
7751 case IMAGE_SYMBOL_VALUE
:
7752 if (!SYMBOLP (value
))
7756 case IMAGE_POSITIVE_INTEGER_VALUE
:
7757 if (!INTEGERP (value
) || XINT (value
) <= 0)
7761 case IMAGE_ASCENT_VALUE
:
7762 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
7764 else if (INTEGERP (value
)
7765 && XINT (value
) >= 0
7766 && XINT (value
) <= 100)
7770 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
7771 if (!INTEGERP (value
) || XINT (value
) < 0)
7775 case IMAGE_DONT_CHECK_VALUE_TYPE
:
7778 case IMAGE_FUNCTION_VALUE
:
7779 value
= indirect_function (value
);
7781 || COMPILEDP (value
)
7782 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
7786 case IMAGE_NUMBER_VALUE
:
7787 if (!INTEGERP (value
) && !FLOATP (value
))
7791 case IMAGE_INTEGER_VALUE
:
7792 if (!INTEGERP (value
))
7796 case IMAGE_BOOL_VALUE
:
7797 if (!NILP (value
) && !EQ (value
, Qt
))
7806 if (EQ (key
, QCtype
) && !EQ (type
, value
))
7810 /* Check that all mandatory fields are present. */
7811 for (i
= 0; i
< nkeywords
; ++i
)
7812 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
7815 return NILP (plist
);
7819 /* Return the value of KEY in image specification SPEC. Value is nil
7820 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
7821 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
7824 image_spec_value (spec
, key
, found
)
7825 Lisp_Object spec
, key
;
7830 xassert (valid_image_p (spec
));
7832 for (tail
= XCDR (spec
);
7833 CONSP (tail
) && CONSP (XCDR (tail
));
7834 tail
= XCDR (XCDR (tail
)))
7836 if (EQ (XCAR (tail
), key
))
7840 return XCAR (XCDR (tail
));
7852 /***********************************************************************
7853 Image type independent image structures
7854 ***********************************************************************/
7856 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
7857 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
7860 /* Allocate and return a new image structure for image specification
7861 SPEC. SPEC has a hash value of HASH. */
7863 static struct image
*
7864 make_image (spec
, hash
)
7868 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
7870 xassert (valid_image_p (spec
));
7871 bzero (img
, sizeof *img
);
7872 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
7873 xassert (img
->type
!= NULL
);
7875 img
->data
.lisp_val
= Qnil
;
7876 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
7882 /* Free image IMG which was used on frame F, including its resources. */
7891 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7893 /* Remove IMG from the hash table of its cache. */
7895 img
->prev
->next
= img
->next
;
7897 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
7900 img
->next
->prev
= img
->prev
;
7902 c
->images
[img
->id
] = NULL
;
7904 /* Free resources, then free IMG. */
7905 img
->type
->free (f
, img
);
7911 /* Prepare image IMG for display on frame F. Must be called before
7912 drawing an image. */
7915 prepare_image_for_display (f
, img
)
7921 /* We're about to display IMG, so set its timestamp to `now'. */
7923 img
->timestamp
= EMACS_SECS (t
);
7925 /* If IMG doesn't have a pixmap yet, load it now, using the image
7926 type dependent loader function. */
7927 if (img
->pixmap
== 0 && !img
->load_failed_p
)
7928 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
7932 /* Value is the number of pixels for the ascent of image IMG when
7933 drawn in face FACE. */
7936 image_ascent (img
, face
)
7940 int height
= img
->height
+ img
->margin
;
7943 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
7946 ascent
= height
/ 2 - (FONT_DESCENT(face
->font
)
7947 - FONT_BASE(face
->font
)) / 2;
7949 ascent
= height
/ 2;
7952 ascent
= height
* img
->ascent
/ 100.0;
7959 /***********************************************************************
7960 Helper functions for X image types
7961 ***********************************************************************/
7963 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
7964 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
7966 Lisp_Object color_name
,
7967 unsigned long dflt
));
7969 /* Free X resources of image IMG which is used on frame F. */
7972 x_clear_image (f
, img
)
7976 #if 0 /* TODO: W32 image support */
7981 XFreePixmap (NULL
, img
->pixmap
);
7988 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
7990 /* If display has an immutable color map, freeing colors is not
7991 necessary and some servers don't allow it. So don't do it. */
7992 if (class != StaticColor
7993 && class != StaticGray
7994 && class != TrueColor
)
7998 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
7999 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
8004 xfree (img
->colors
);
8012 /* Allocate color COLOR_NAME for image IMG on frame F. If color
8013 cannot be allocated, use DFLT. Add a newly allocated color to
8014 IMG->colors, so that it can be freed again. Value is the pixel
8017 static unsigned long
8018 x_alloc_image_color (f
, img
, color_name
, dflt
)
8021 Lisp_Object color_name
;
8024 #if 0 /* TODO: allocing colors. */
8026 unsigned long result
;
8028 xassert (STRINGP (color_name
));
8030 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
8032 /* This isn't called frequently so we get away with simply
8033 reallocating the color vector to the needed size, here. */
8036 (unsigned long *) xrealloc (img
->colors
,
8037 img
->ncolors
* sizeof *img
->colors
);
8038 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
8039 result
= color
.pixel
;
8050 /***********************************************************************
8052 ***********************************************************************/
8054 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
8057 /* Return a new, initialized image cache that is allocated from the
8058 heap. Call free_image_cache to free an image cache. */
8060 struct image_cache
*
8063 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
8066 bzero (c
, sizeof *c
);
8068 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
8069 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
8070 c
->buckets
= (struct image
**) xmalloc (size
);
8071 bzero (c
->buckets
, size
);
8076 /* Free image cache of frame F. Be aware that X frames share images
8080 free_image_cache (f
)
8083 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8088 /* Cache should not be referenced by any frame when freed. */
8089 xassert (c
->refcount
== 0);
8091 for (i
= 0; i
< c
->used
; ++i
)
8092 free_image (f
, c
->images
[i
]);
8096 FRAME_X_IMAGE_CACHE (f
) = NULL
;
8101 /* Clear image cache of frame F. FORCE_P non-zero means free all
8102 images. FORCE_P zero means clear only images that haven't been
8103 displayed for some time. Should be called from time to time to
8104 reduce the number of loaded images. If image-eviction-seconds is
8105 non-nil, this frees images in the cache which weren't displayed for
8106 at least that many seconds. */
8109 clear_image_cache (f
, force_p
)
8113 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8115 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
8119 int i
, any_freed_p
= 0;
8122 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
8124 for (i
= 0; i
< c
->used
; ++i
)
8126 struct image
*img
= c
->images
[i
];
8129 || (img
->timestamp
> old
)))
8131 free_image (f
, img
);
8136 /* We may be clearing the image cache because, for example,
8137 Emacs was iconified for a longer period of time. In that
8138 case, current matrices may still contain references to
8139 images freed above. So, clear these matrices. */
8142 clear_current_matrices (f
);
8143 ++windows_or_buffers_changed
;
8149 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
8151 "Clear the image cache of FRAME.\n\
8152 FRAME nil or omitted means use the selected frame.\n\
8153 FRAME t means clear the image caches of all frames.")
8161 FOR_EACH_FRAME (tail
, frame
)
8162 if (FRAME_W32_P (XFRAME (frame
)))
8163 clear_image_cache (XFRAME (frame
), 1);
8166 clear_image_cache (check_x_frame (frame
), 1);
8172 /* Return the id of image with Lisp specification SPEC on frame F.
8173 SPEC must be a valid Lisp image specification (see valid_image_p). */
8176 lookup_image (f
, spec
)
8180 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8184 struct gcpro gcpro1
;
8187 /* F must be a window-system frame, and SPEC must be a valid image
8189 xassert (FRAME_WINDOW_P (f
));
8190 xassert (valid_image_p (spec
));
8194 /* Look up SPEC in the hash table of the image cache. */
8195 hash
= sxhash (spec
, 0);
8196 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8198 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
8199 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
8202 /* If not found, create a new image and cache it. */
8205 img
= make_image (spec
, hash
);
8206 cache_image (f
, img
);
8207 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8208 xassert (!interrupt_input_blocked
);
8210 /* If we can't load the image, and we don't have a width and
8211 height, use some arbitrary width and height so that we can
8212 draw a rectangle for it. */
8213 if (img
->load_failed_p
)
8217 value
= image_spec_value (spec
, QCwidth
, NULL
);
8218 img
->width
= (INTEGERP (value
)
8219 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
8220 value
= image_spec_value (spec
, QCheight
, NULL
);
8221 img
->height
= (INTEGERP (value
)
8222 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
8226 /* Handle image type independent image attributes
8227 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF'. */
8228 Lisp_Object ascent
, margin
, relief
, algorithm
, heuristic_mask
;
8231 ascent
= image_spec_value (spec
, QCascent
, NULL
);
8232 if (INTEGERP (ascent
))
8233 img
->ascent
= XFASTINT (ascent
);
8234 else if (EQ (ascent
, Qcenter
))
8235 img
->ascent
= CENTERED_IMAGE_ASCENT
;
8237 margin
= image_spec_value (spec
, QCmargin
, NULL
);
8238 if (INTEGERP (margin
) && XINT (margin
) >= 0)
8239 img
->margin
= XFASTINT (margin
);
8241 relief
= image_spec_value (spec
, QCrelief
, NULL
);
8242 if (INTEGERP (relief
))
8244 img
->relief
= XINT (relief
);
8245 img
->margin
+= abs (img
->relief
);
8248 /* Should we apply a Laplace edge-detection algorithm? */
8249 algorithm
= image_spec_value (spec
, QCalgorithm
, NULL
);
8250 if (img
->pixmap
&& EQ (algorithm
, Qlaplace
))
8253 /* Should we built a mask heuristically? */
8254 heuristic_mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
8255 if (img
->pixmap
&& !img
->mask
&& !NILP (heuristic_mask
))
8256 x_build_heuristic_mask (f
, img
, heuristic_mask
);
8260 /* We're using IMG, so set its timestamp to `now'. */
8261 EMACS_GET_TIME (now
);
8262 img
->timestamp
= EMACS_SECS (now
);
8266 /* Value is the image id. */
8271 /* Cache image IMG in the image cache of frame F. */
8274 cache_image (f
, img
)
8278 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8281 /* Find a free slot in c->images. */
8282 for (i
= 0; i
< c
->used
; ++i
)
8283 if (c
->images
[i
] == NULL
)
8286 /* If no free slot found, maybe enlarge c->images. */
8287 if (i
== c
->used
&& c
->used
== c
->size
)
8290 c
->images
= (struct image
**) xrealloc (c
->images
,
8291 c
->size
* sizeof *c
->images
);
8294 /* Add IMG to c->images, and assign IMG an id. */
8300 /* Add IMG to the cache's hash table. */
8301 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8302 img
->next
= c
->buckets
[i
];
8304 img
->next
->prev
= img
;
8306 c
->buckets
[i
] = img
;
8310 /* Call FN on every image in the image cache of frame F. Used to mark
8311 Lisp Objects in the image cache. */
8314 forall_images_in_image_cache (f
, fn
)
8316 void (*fn
) P_ ((struct image
*img
));
8318 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
8320 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8324 for (i
= 0; i
< c
->used
; ++i
)
8333 /***********************************************************************
8335 ***********************************************************************/
8337 #if 0 /* TODO: W32 specific image code. */
8339 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
8340 XImage
**, Pixmap
*));
8341 static void x_destroy_x_image
P_ ((XImage
*));
8342 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
8345 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
8346 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
8347 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
8348 via xmalloc. Print error messages via image_error if an error
8349 occurs. Value is non-zero if successful. */
8352 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
8354 int width
, height
, depth
;
8358 #if 0 /* TODO: Image support for W32 */
8359 Display
*display
= FRAME_W32_DISPLAY (f
);
8360 Screen
*screen
= FRAME_X_SCREEN (f
);
8361 Window window
= FRAME_W32_WINDOW (f
);
8363 xassert (interrupt_input_blocked
);
8366 depth
= DefaultDepthOfScreen (screen
);
8367 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
8368 depth
, ZPixmap
, 0, NULL
, width
, height
,
8369 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
8372 image_error ("Unable to allocate X image", Qnil
, Qnil
);
8376 /* Allocate image raster. */
8377 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
8379 /* Allocate a pixmap of the same size. */
8380 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
8383 x_destroy_x_image (*ximg
);
8385 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
8393 /* Destroy XImage XIMG. Free XIMG->data. */
8396 x_destroy_x_image (ximg
)
8399 xassert (interrupt_input_blocked
);
8404 XDestroyImage (ximg
);
8409 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
8410 are width and height of both the image and pixmap. */
8413 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
8420 xassert (interrupt_input_blocked
);
8421 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
8422 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
8429 /***********************************************************************
8431 ***********************************************************************/
8433 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
8435 /* Find image file FILE. Look in data-directory, then
8436 x-bitmap-file-path. Value is the full name of the file found, or
8437 nil if not found. */
8440 x_find_image_file (file
)
8443 Lisp_Object file_found
, search_path
;
8444 struct gcpro gcpro1
, gcpro2
;
8448 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
8449 GCPRO2 (file_found
, search_path
);
8451 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
8452 fd
= openp (search_path
, file
, "", &file_found
, 0);
8465 /***********************************************************************
8467 ***********************************************************************/
8469 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
8470 static int xbm_load_image_from_file
P_ ((struct frame
*f
, struct image
*img
,
8472 static int xbm_image_p
P_ ((Lisp_Object object
));
8473 static int xbm_read_bitmap_file_data
P_ ((char *, int *, int *,
8477 /* Indices of image specification fields in xbm_format, below. */
8479 enum xbm_keyword_index
8496 /* Vector of image_keyword structures describing the format
8497 of valid XBM image specifications. */
8499 static struct image_keyword xbm_format
[XBM_LAST
] =
8501 {":type", IMAGE_SYMBOL_VALUE
, 1},
8502 {":file", IMAGE_STRING_VALUE
, 0},
8503 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8504 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8505 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8506 {":foreground", IMAGE_STRING_VALUE
, 0},
8507 {":background", IMAGE_STRING_VALUE
, 0},
8508 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
8509 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8510 {":relief", IMAGE_INTEGER_VALUE
, 0},
8511 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8512 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
8515 /* Structure describing the image type XBM. */
8517 static struct image_type xbm_type
=
8526 /* Tokens returned from xbm_scan. */
8535 /* Return non-zero if OBJECT is a valid XBM-type image specification.
8536 A valid specification is a list starting with the symbol `image'
8537 The rest of the list is a property list which must contain an
8540 If the specification specifies a file to load, it must contain
8541 an entry `:file FILENAME' where FILENAME is a string.
8543 If the specification is for a bitmap loaded from memory it must
8544 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
8545 WIDTH and HEIGHT are integers > 0. DATA may be:
8547 1. a string large enough to hold the bitmap data, i.e. it must
8548 have a size >= (WIDTH + 7) / 8 * HEIGHT
8550 2. a bool-vector of size >= WIDTH * HEIGHT
8552 3. a vector of strings or bool-vectors, one for each line of the
8555 Both the file and data forms may contain the additional entries
8556 `:background COLOR' and `:foreground COLOR'. If not present,
8557 foreground and background of the frame on which the image is
8558 displayed, is used. */
8561 xbm_image_p (object
)
8564 struct image_keyword kw
[XBM_LAST
];
8566 bcopy (xbm_format
, kw
, sizeof kw
);
8567 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
8570 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
8572 if (kw
[XBM_FILE
].count
)
8574 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
8582 /* Entries for `:width', `:height' and `:data' must be present. */
8583 if (!kw
[XBM_WIDTH
].count
8584 || !kw
[XBM_HEIGHT
].count
8585 || !kw
[XBM_DATA
].count
)
8588 data
= kw
[XBM_DATA
].value
;
8589 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
8590 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
8592 /* Check type of data, and width and height against contents of
8598 /* Number of elements of the vector must be >= height. */
8599 if (XVECTOR (data
)->size
< height
)
8602 /* Each string or bool-vector in data must be large enough
8603 for one line of the image. */
8604 for (i
= 0; i
< height
; ++i
)
8606 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
8610 if (XSTRING (elt
)->size
8611 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
8614 else if (BOOL_VECTOR_P (elt
))
8616 if (XBOOL_VECTOR (elt
)->size
< width
)
8623 else if (STRINGP (data
))
8625 if (XSTRING (data
)->size
8626 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
8629 else if (BOOL_VECTOR_P (data
))
8631 if (XBOOL_VECTOR (data
)->size
< width
* height
)
8638 /* Baseline must be a value between 0 and 100 (a percentage). */
8639 if (kw
[XBM_ASCENT
].count
8640 && XFASTINT (kw
[XBM_ASCENT
].value
) > 100)
8647 /* Scan a bitmap file. FP is the stream to read from. Value is
8648 either an enumerator from enum xbm_token, or a character for a
8649 single-character token, or 0 at end of file. If scanning an
8650 identifier, store the lexeme of the identifier in SVAL. If
8651 scanning a number, store its value in *IVAL. */
8654 xbm_scan (fp
, sval
, ival
)
8661 /* Skip white space. */
8662 while ((c
= fgetc (fp
)) != EOF
&& isspace (c
))
8667 else if (isdigit (c
))
8669 int value
= 0, digit
;
8674 if (c
== 'x' || c
== 'X')
8676 while ((c
= fgetc (fp
)) != EOF
)
8680 else if (c
>= 'a' && c
<= 'f')
8681 digit
= c
- 'a' + 10;
8682 else if (c
>= 'A' && c
<= 'F')
8683 digit
= c
- 'A' + 10;
8686 value
= 16 * value
+ digit
;
8689 else if (isdigit (c
))
8692 while ((c
= fgetc (fp
)) != EOF
8694 value
= 8 * value
+ c
- '0';
8700 while ((c
= fgetc (fp
)) != EOF
8702 value
= 10 * value
+ c
- '0';
8710 else if (isalpha (c
) || c
== '_')
8713 while ((c
= fgetc (fp
)) != EOF
8714 && (isalnum (c
) || c
== '_'))
8726 /* Replacement for XReadBitmapFileData which isn't available under old
8727 X versions. FILE is the name of the bitmap file to read. Set
8728 *WIDTH and *HEIGHT to the width and height of the image. Return in
8729 *DATA the bitmap data allocated with xmalloc. Value is non-zero if
8733 xbm_read_bitmap_file_data (file
, width
, height
, data
)
8735 int *width
, *height
;
8736 unsigned char **data
;
8739 char buffer
[BUFSIZ
];
8742 int bytes_per_line
, i
, nbytes
;
8748 LA1 = xbm_scan (fp, buffer, &value)
8750 #define expect(TOKEN) \
8751 if (LA1 != (TOKEN)) \
8756 #define expect_ident(IDENT) \
8757 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
8762 fp
= fopen (file
, "r");
8766 *width
= *height
= -1;
8768 LA1
= xbm_scan (fp
, buffer
, &value
);
8770 /* Parse defines for width, height and hot-spots. */
8774 expect_ident ("define");
8775 expect (XBM_TK_IDENT
);
8777 if (LA1
== XBM_TK_NUMBER
);
8779 char *p
= strrchr (buffer
, '_');
8780 p
= p
? p
+ 1 : buffer
;
8781 if (strcmp (p
, "width") == 0)
8783 else if (strcmp (p
, "height") == 0)
8786 expect (XBM_TK_NUMBER
);
8789 if (*width
< 0 || *height
< 0)
8792 /* Parse bits. Must start with `static'. */
8793 expect_ident ("static");
8794 if (LA1
== XBM_TK_IDENT
)
8796 if (strcmp (buffer
, "unsigned") == 0)
8799 expect_ident ("char");
8801 else if (strcmp (buffer
, "short") == 0)
8805 if (*width
% 16 && *width
% 16 < 9)
8808 else if (strcmp (buffer
, "char") == 0)
8816 expect (XBM_TK_IDENT
);
8822 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
8823 nbytes
= bytes_per_line
* *height
;
8824 p
= *data
= (char *) xmalloc (nbytes
);
8829 for (i
= 0; i
< nbytes
; i
+= 2)
8832 expect (XBM_TK_NUMBER
);
8835 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
8838 if (LA1
== ',' || LA1
== '}')
8846 for (i
= 0; i
< nbytes
; ++i
)
8849 expect (XBM_TK_NUMBER
);
8853 if (LA1
== ',' || LA1
== '}')
8879 /* Load XBM image IMG which will be displayed on frame F from file
8880 SPECIFIED_FILE. Value is non-zero if successful. */
8883 xbm_load_image_from_file (f
, img
, specified_file
)
8886 Lisp_Object specified_file
;
8889 unsigned char *data
;
8892 struct gcpro gcpro1
;
8894 xassert (STRINGP (specified_file
));
8898 file
= x_find_image_file (specified_file
);
8899 if (!STRINGP (file
))
8901 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8906 rc
= xbm_read_bitmap_file_data (XSTRING (file
)->data
, &img
->width
,
8907 &img
->height
, &data
);
8910 int depth
= one_w32_display_info
.n_cbits
;
8911 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
8912 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
8915 xassert (img
->width
> 0 && img
->height
> 0);
8917 /* Get foreground and background colors, maybe allocate colors. */
8918 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
8920 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
8922 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
8924 background
= x_alloc_image_color (f
, img
, value
, background
);
8926 #if 0 /* TODO : Port image display to W32 */
8929 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
8930 FRAME_W32_WINDOW (f
),
8932 img
->width
, img
->height
,
8933 foreground
, background
,
8937 if (img
->pixmap
== 0)
8939 x_clear_image (f
, img
);
8940 image_error ("Unable to create X pixmap for `%s'", file
, Qnil
);
8949 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
8956 /* Fill image IMG which is used on frame F with pixmap data. Value is
8957 non-zero if successful. */
8965 Lisp_Object file_name
;
8967 xassert (xbm_image_p (img
->spec
));
8969 /* If IMG->spec specifies a file name, create a non-file spec from it. */
8970 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
8971 if (STRINGP (file_name
))
8972 success_p
= xbm_load_image_from_file (f
, img
, file_name
);
8975 struct image_keyword fmt
[XBM_LAST
];
8978 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
8979 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
8983 /* Parse the list specification. */
8984 bcopy (xbm_format
, fmt
, sizeof fmt
);
8985 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
8988 /* Get specified width, and height. */
8989 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
8990 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
8991 xassert (img
->width
> 0 && img
->height
> 0);
8995 if (fmt
[XBM_ASCENT
].count
)
8996 img
->ascent
= XFASTINT (fmt
[XBM_ASCENT
].value
);
8998 /* Get foreground and background colors, maybe allocate colors. */
8999 if (fmt
[XBM_FOREGROUND
].count
)
9000 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
9002 if (fmt
[XBM_BACKGROUND
].count
)
9003 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
9006 /* Set bits to the bitmap image data. */
9007 data
= fmt
[XBM_DATA
].value
;
9012 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
9014 p
= bits
= (char *) alloca (nbytes
* img
->height
);
9015 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
9017 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
9019 bcopy (XSTRING (line
)->data
, p
, nbytes
);
9021 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
9024 else if (STRINGP (data
))
9025 bits
= XSTRING (data
)->data
;
9027 bits
= XBOOL_VECTOR (data
)->data
;
9029 #if 0 /* TODO : W32 XPM code */
9030 /* Create the pixmap. */
9031 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
9033 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
9034 FRAME_W32_WINDOW (f
),
9036 img
->width
, img
->height
,
9037 foreground
, background
,
9045 image_error ("Unable to create pixmap for XBM image `%s'",
9047 x_clear_image (f
, img
);
9058 /***********************************************************************
9060 ***********************************************************************/
9064 static int xpm_image_p
P_ ((Lisp_Object object
));
9065 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
9066 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
9068 #include "X11/xpm.h"
9070 /* The symbol `xpm' identifying XPM-format images. */
9074 /* Indices of image specification fields in xpm_format, below. */
9076 enum xpm_keyword_index
9090 /* Vector of image_keyword structures describing the format
9091 of valid XPM image specifications. */
9093 static struct image_keyword xpm_format
[XPM_LAST
] =
9095 {":type", IMAGE_SYMBOL_VALUE
, 1},
9096 {":file", IMAGE_STRING_VALUE
, 0},
9097 {":data", IMAGE_STRING_VALUE
, 0},
9098 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9099 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9100 {":relief", IMAGE_INTEGER_VALUE
, 0},
9101 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9102 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9103 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9106 /* Structure describing the image type XBM. */
9108 static struct image_type xpm_type
=
9118 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
9119 for XPM images. Such a list must consist of conses whose car and
9123 xpm_valid_color_symbols_p (color_symbols
)
9124 Lisp_Object color_symbols
;
9126 while (CONSP (color_symbols
))
9128 Lisp_Object sym
= XCAR (color_symbols
);
9130 || !STRINGP (XCAR (sym
))
9131 || !STRINGP (XCDR (sym
)))
9133 color_symbols
= XCDR (color_symbols
);
9136 return NILP (color_symbols
);
9140 /* Value is non-zero if OBJECT is a valid XPM image specification. */
9143 xpm_image_p (object
)
9146 struct image_keyword fmt
[XPM_LAST
];
9147 bcopy (xpm_format
, fmt
, sizeof fmt
);
9148 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
9149 /* Either `:file' or `:data' must be present. */
9150 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
9151 /* Either no `:color-symbols' or it's a list of conses
9152 whose car and cdr are strings. */
9153 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
9154 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
9155 && (fmt
[XPM_ASCENT
].count
== 0
9156 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
9160 /* Load image IMG which will be displayed on frame F. Value is
9161 non-zero if successful. */
9169 XpmAttributes attrs
;
9170 Lisp_Object specified_file
, color_symbols
;
9172 /* Configure the XPM lib. Use the visual of frame F. Allocate
9173 close colors. Return colors allocated. */
9174 bzero (&attrs
, sizeof attrs
);
9175 attrs
.visual
= FRAME_X_VISUAL (f
);
9176 attrs
.colormap
= FRAME_X_COLORMAP (f
);
9177 attrs
.valuemask
|= XpmVisual
;
9178 attrs
.valuemask
|= XpmColormap
;
9179 attrs
.valuemask
|= XpmReturnAllocPixels
;
9180 #ifdef XpmAllocCloseColors
9181 attrs
.alloc_close_colors
= 1;
9182 attrs
.valuemask
|= XpmAllocCloseColors
;
9184 attrs
.closeness
= 600;
9185 attrs
.valuemask
|= XpmCloseness
;
9188 /* If image specification contains symbolic color definitions, add
9189 these to `attrs'. */
9190 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
9191 if (CONSP (color_symbols
))
9194 XpmColorSymbol
*xpm_syms
;
9197 attrs
.valuemask
|= XpmColorSymbols
;
9199 /* Count number of symbols. */
9200 attrs
.numsymbols
= 0;
9201 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
9204 /* Allocate an XpmColorSymbol array. */
9205 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
9206 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
9207 bzero (xpm_syms
, size
);
9208 attrs
.colorsymbols
= xpm_syms
;
9210 /* Fill the color symbol array. */
9211 for (tail
= color_symbols
, i
= 0;
9213 ++i
, tail
= XCDR (tail
))
9215 Lisp_Object name
= XCAR (XCAR (tail
));
9216 Lisp_Object color
= XCDR (XCAR (tail
));
9217 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
9218 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
9219 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
9220 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
9224 /* Create a pixmap for the image, either from a file, or from a
9225 string buffer containing data in the same format as an XPM file. */
9227 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9228 if (STRINGP (specified_file
))
9230 Lisp_Object file
= x_find_image_file (specified_file
);
9231 if (!STRINGP (file
))
9233 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9238 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
9239 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
9244 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
9245 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
9246 XSTRING (buffer
)->data
,
9247 &img
->pixmap
, &img
->mask
,
9252 if (rc
== XpmSuccess
)
9254 /* Remember allocated colors. */
9255 img
->ncolors
= attrs
.nalloc_pixels
;
9256 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
9257 * sizeof *img
->colors
);
9258 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
9259 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
9261 img
->width
= attrs
.width
;
9262 img
->height
= attrs
.height
;
9263 xassert (img
->width
> 0 && img
->height
> 0);
9265 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
9267 XpmFreeAttributes (&attrs
);
9275 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
9278 case XpmFileInvalid
:
9279 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
9283 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
9286 case XpmColorFailed
:
9287 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
9291 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
9296 return rc
== XpmSuccess
;
9299 #endif /* HAVE_XPM != 0 */
9302 #if 0 /* TODO : Color tables on W32. */
9303 /***********************************************************************
9305 ***********************************************************************/
9307 /* An entry in the color table mapping an RGB color to a pixel color. */
9312 unsigned long pixel
;
9314 /* Next in color table collision list. */
9315 struct ct_color
*next
;
9318 /* The bucket vector size to use. Must be prime. */
9322 /* Value is a hash of the RGB color given by R, G, and B. */
9324 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
9326 /* The color hash table. */
9328 struct ct_color
**ct_table
;
9330 /* Number of entries in the color table. */
9332 int ct_colors_allocated
;
9334 /* Function prototypes. */
9336 static void init_color_table
P_ ((void));
9337 static void free_color_table
P_ ((void));
9338 static unsigned long *colors_in_color_table
P_ ((int *n
));
9339 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
9340 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
9343 /* Initialize the color table. */
9348 int size
= CT_SIZE
* sizeof (*ct_table
);
9349 ct_table
= (struct ct_color
**) xmalloc (size
);
9350 bzero (ct_table
, size
);
9351 ct_colors_allocated
= 0;
9355 /* Free memory associated with the color table. */
9361 struct ct_color
*p
, *next
;
9363 for (i
= 0; i
< CT_SIZE
; ++i
)
9364 for (p
= ct_table
[i
]; p
; p
= next
)
9375 /* Value is a pixel color for RGB color R, G, B on frame F. If an
9376 entry for that color already is in the color table, return the
9377 pixel color of that entry. Otherwise, allocate a new color for R,
9378 G, B, and make an entry in the color table. */
9380 static unsigned long
9381 lookup_rgb_color (f
, r
, g
, b
)
9385 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
9386 int i
= hash
% CT_SIZE
;
9389 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9390 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
9399 color
= PALETTERGB (r
, g
, b
);
9401 ++ct_colors_allocated
;
9403 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9408 p
->next
= ct_table
[i
];
9416 /* Look up pixel color PIXEL which is used on frame F in the color
9417 table. If not already present, allocate it. Value is PIXEL. */
9419 static unsigned long
9420 lookup_pixel_color (f
, pixel
)
9422 unsigned long pixel
;
9424 int i
= pixel
% CT_SIZE
;
9427 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9428 if (p
->pixel
== pixel
)
9439 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9440 color
.pixel
= pixel
;
9441 XQueryColor (NULL
, cmap
, &color
);
9442 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
9447 ++ct_colors_allocated
;
9449 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9454 p
->next
= ct_table
[i
];
9458 return FRAME_FOREGROUND_PIXEL (f
);
9464 /* Value is a vector of all pixel colors contained in the color table,
9465 allocated via xmalloc. Set *N to the number of colors. */
9467 static unsigned long *
9468 colors_in_color_table (n
)
9473 unsigned long *colors
;
9475 if (ct_colors_allocated
== 0)
9482 colors
= (unsigned long *) xmalloc (ct_colors_allocated
9484 *n
= ct_colors_allocated
;
9486 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
9487 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9488 colors
[j
++] = p
->pixel
;
9497 /***********************************************************************
9499 ***********************************************************************/
9501 #if 0 /* TODO : W32 versions of low level algorithms */
9502 static void x_laplace_write_row
P_ ((struct frame
*, long *,
9503 int, XImage
*, int));
9504 static void x_laplace_read_row
P_ ((struct frame
*, Colormap
,
9505 XColor
*, int, XImage
*, int));
9508 /* Fill COLORS with RGB colors from row Y of image XIMG. F is the
9509 frame we operate on, CMAP is the color-map in effect, and WIDTH is
9510 the width of one row in the image. */
9513 x_laplace_read_row (f
, cmap
, colors
, width
, ximg
, y
)
9523 for (x
= 0; x
< width
; ++x
)
9524 colors
[x
].pixel
= XGetPixel (ximg
, x
, y
);
9526 XQueryColors (NULL
, cmap
, colors
, width
);
9530 /* Write row Y of image XIMG. PIXELS is an array of WIDTH longs
9531 containing the pixel colors to write. F is the frame we are
9535 x_laplace_write_row (f
, pixels
, width
, ximg
, y
)
9544 for (x
= 0; x
< width
; ++x
)
9545 XPutPixel (ximg
, x
, y
, pixels
[x
]);
9549 /* Transform image IMG which is used on frame F with a Laplace
9550 edge-detection algorithm. The result is an image that can be used
9551 to draw disabled buttons, for example. */
9558 #if 0 /* TODO : W32 version */
9559 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9560 XImage
*ximg
, *oimg
;
9566 int in_y
, out_y
, rc
;
9571 /* Get the X image IMG->pixmap. */
9572 ximg
= XGetImage (NULL
, img
->pixmap
,
9573 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
9575 /* Allocate 3 input rows, and one output row of colors. */
9576 for (i
= 0; i
< 3; ++i
)
9577 in
[i
] = (XColor
*) alloca (img
->width
* sizeof (XColor
));
9578 out
= (long *) alloca (img
->width
* sizeof (long));
9580 /* Create an X image for output. */
9581 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
9584 /* Fill first two rows. */
9585 x_laplace_read_row (f
, cmap
, in
[0], img
->width
, ximg
, 0);
9586 x_laplace_read_row (f
, cmap
, in
[1], img
->width
, ximg
, 1);
9589 /* Write first row, all zeros. */
9590 init_color_table ();
9591 pixel
= lookup_rgb_color (f
, 0, 0, 0);
9592 for (x
= 0; x
< img
->width
; ++x
)
9594 x_laplace_write_row (f
, out
, img
->width
, oimg
, 0);
9597 for (y
= 2; y
< img
->height
; ++y
)
9600 int rowb
= (y
+ 2) % 3;
9602 x_laplace_read_row (f
, cmap
, in
[rowa
], img
->width
, ximg
, in_y
++);
9604 for (x
= 0; x
< img
->width
- 2; ++x
)
9606 int r
= in
[rowa
][x
].red
+ mv2
- in
[rowb
][x
+ 2].red
;
9607 int g
= in
[rowa
][x
].green
+ mv2
- in
[rowb
][x
+ 2].green
;
9608 int b
= in
[rowa
][x
].blue
+ mv2
- in
[rowb
][x
+ 2].blue
;
9610 out
[x
+ 1] = lookup_rgb_color (f
, r
& 0xffff, g
& 0xffff,
9614 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
++);
9617 /* Write last line, all zeros. */
9618 for (x
= 0; x
< img
->width
; ++x
)
9620 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
);
9622 /* Free the input image, and free resources of IMG. */
9623 XDestroyImage (ximg
);
9624 x_clear_image (f
, img
);
9626 /* Put the output image into pixmap, and destroy it. */
9627 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
9628 x_destroy_x_image (oimg
);
9630 /* Remember new pixmap and colors in IMG. */
9631 img
->pixmap
= pixmap
;
9632 img
->colors
= colors_in_color_table (&img
->ncolors
);
9633 free_color_table ();
9640 /* Build a mask for image IMG which is used on frame F. FILE is the
9641 name of an image file, for error messages. HOW determines how to
9642 determine the background color of IMG. If it is a list '(R G B)',
9643 with R, G, and B being integers >= 0, take that as the color of the
9644 background. Otherwise, determine the background color of IMG
9645 heuristically. Value is non-zero if successful. */
9648 x_build_heuristic_mask (f
, img
, how
)
9653 #if 0 /* TODO : W32 version */
9654 Display
*dpy
= FRAME_W32_DISPLAY (f
);
9655 XImage
*ximg
, *mask_img
;
9656 int x
, y
, rc
, look_at_corners_p
;
9661 /* Create an image and pixmap serving as mask. */
9662 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
9663 &mask_img
, &img
->mask
);
9670 /* Get the X image of IMG->pixmap. */
9671 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
9674 /* Determine the background color of ximg. If HOW is `(R G B)'
9675 take that as color. Otherwise, try to determine the color
9677 look_at_corners_p
= 1;
9685 && NATNUMP (XCAR (how
)))
9687 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
9691 if (i
== 3 && NILP (how
))
9693 char color_name
[30];
9694 XColor exact
, color
;
9697 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
9699 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9700 if (XLookupColor (dpy
, cmap
, color_name
, &exact
, &color
))
9703 look_at_corners_p
= 0;
9708 if (look_at_corners_p
)
9710 unsigned long corners
[4];
9713 /* Get the colors at the corners of ximg. */
9714 corners
[0] = XGetPixel (ximg
, 0, 0);
9715 corners
[1] = XGetPixel (ximg
, img
->width
- 1, 0);
9716 corners
[2] = XGetPixel (ximg
, img
->width
- 1, img
->height
- 1);
9717 corners
[3] = XGetPixel (ximg
, 0, img
->height
- 1);
9719 /* Choose the most frequently found color as background. */
9720 for (i
= best_count
= 0; i
< 4; ++i
)
9724 for (j
= n
= 0; j
< 4; ++j
)
9725 if (corners
[i
] == corners
[j
])
9729 bg
= corners
[i
], best_count
= n
;
9733 /* Set all bits in mask_img to 1 whose color in ximg is different
9734 from the background color bg. */
9735 for (y
= 0; y
< img
->height
; ++y
)
9736 for (x
= 0; x
< img
->width
; ++x
)
9737 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
9739 /* Put mask_img into img->mask. */
9740 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
9741 x_destroy_x_image (mask_img
);
9742 XDestroyImage (ximg
);
9752 /***********************************************************************
9753 PBM (mono, gray, color)
9754 ***********************************************************************/
9757 static int pbm_image_p
P_ ((Lisp_Object object
));
9758 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
9759 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
9761 /* The symbol `pbm' identifying images of this type. */
9765 /* Indices of image specification fields in gs_format, below. */
9767 enum pbm_keyword_index
9780 /* Vector of image_keyword structures describing the format
9781 of valid user-defined image specifications. */
9783 static struct image_keyword pbm_format
[PBM_LAST
] =
9785 {":type", IMAGE_SYMBOL_VALUE
, 1},
9786 {":file", IMAGE_STRING_VALUE
, 0},
9787 {":data", IMAGE_STRING_VALUE
, 0},
9788 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9789 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9790 {":relief", IMAGE_INTEGER_VALUE
, 0},
9791 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9792 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9795 /* Structure describing the image type `pbm'. */
9797 static struct image_type pbm_type
=
9807 /* Return non-zero if OBJECT is a valid PBM image specification. */
9810 pbm_image_p (object
)
9813 struct image_keyword fmt
[PBM_LAST
];
9815 bcopy (pbm_format
, fmt
, sizeof fmt
);
9817 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
9818 || (fmt
[PBM_ASCENT
].count
9819 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
9822 /* Must specify either :data or :file. */
9823 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
9827 /* Scan a decimal number from *S and return it. Advance *S while
9828 reading the number. END is the end of the string. Value is -1 at
9832 pbm_scan_number (s
, end
)
9833 unsigned char **s
, *end
;
9839 /* Skip white-space. */
9840 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
9845 /* Skip comment to end of line. */
9846 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
9849 else if (isdigit (c
))
9851 /* Read decimal number. */
9853 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
9854 val
= 10 * val
+ c
- '0';
9865 /* Read FILE into memory. Value is a pointer to a buffer allocated
9866 with xmalloc holding FILE's contents. Value is null if an error
9867 occured. *SIZE is set to the size of the file. */
9870 pbm_read_file (file
, size
)
9878 if (stat (XSTRING (file
)->data
, &st
) == 0
9879 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
9880 && (buf
= (char *) xmalloc (st
.st_size
),
9881 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
9901 /* Load PBM image IMG for use on frame F. */
9909 int width
, height
, max_color_idx
= 0;
9911 Lisp_Object file
, specified_file
;
9912 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
9913 struct gcpro gcpro1
;
9914 unsigned char *contents
= NULL
;
9915 unsigned char *end
, *p
;
9918 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9922 if (STRINGP (specified_file
))
9924 file
= x_find_image_file (specified_file
);
9925 if (!STRINGP (file
))
9927 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9932 contents
= pbm_read_file (file
, &size
);
9933 if (contents
== NULL
)
9935 image_error ("Error reading `%s'", file
, Qnil
);
9941 end
= contents
+ size
;
9946 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
9947 p
= XSTRING (data
)->data
;
9948 end
= p
+ STRING_BYTES (XSTRING (data
));
9951 /* Check magic number. */
9952 if (end
- p
< 2 || *p
++ != 'P')
9954 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
9964 raw_p
= 0, type
= PBM_MONO
;
9968 raw_p
= 0, type
= PBM_GRAY
;
9972 raw_p
= 0, type
= PBM_COLOR
;
9976 raw_p
= 1, type
= PBM_MONO
;
9980 raw_p
= 1, type
= PBM_GRAY
;
9984 raw_p
= 1, type
= PBM_COLOR
;
9988 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
9992 /* Read width, height, maximum color-component. Characters
9993 starting with `#' up to the end of a line are ignored. */
9994 width
= pbm_scan_number (&p
, end
);
9995 height
= pbm_scan_number (&p
, end
);
9997 if (type
!= PBM_MONO
)
9999 max_color_idx
= pbm_scan_number (&p
, end
);
10000 if (raw_p
&& max_color_idx
> 255)
10001 max_color_idx
= 255;
10006 || (type
!= PBM_MONO
&& max_color_idx
< 0))
10010 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
10011 &ximg
, &img
->pixmap
))
10017 /* Initialize the color hash table. */
10018 init_color_table ();
10020 if (type
== PBM_MONO
)
10024 for (y
= 0; y
< height
; ++y
)
10025 for (x
= 0; x
< width
; ++x
)
10035 g
= pbm_scan_number (&p
, end
);
10037 XPutPixel (ximg
, x
, y
, (g
10038 ? FRAME_FOREGROUND_PIXEL (f
)
10039 : FRAME_BACKGROUND_PIXEL (f
)));
10044 for (y
= 0; y
< height
; ++y
)
10045 for (x
= 0; x
< width
; ++x
)
10049 if (type
== PBM_GRAY
)
10050 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
10059 r
= pbm_scan_number (&p
, end
);
10060 g
= pbm_scan_number (&p
, end
);
10061 b
= pbm_scan_number (&p
, end
);
10064 if (r
< 0 || g
< 0 || b
< 0)
10066 xfree (ximg
->data
);
10068 XDestroyImage (ximg
);
10070 image_error ("Invalid pixel value in image `%s'",
10075 /* RGB values are now in the range 0..max_color_idx.
10076 Scale this to the range 0..0xffff supported by X. */
10077 r
= (double) r
* 65535 / max_color_idx
;
10078 g
= (double) g
* 65535 / max_color_idx
;
10079 b
= (double) b
* 65535 / max_color_idx
;
10080 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10084 /* Store in IMG->colors the colors allocated for the image, and
10085 free the color table. */
10086 img
->colors
= colors_in_color_table (&img
->ncolors
);
10087 free_color_table ();
10089 /* Put the image into a pixmap. */
10090 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10091 x_destroy_x_image (ximg
);
10094 img
->width
= width
;
10095 img
->height
= height
;
10101 #endif /* HAVE_PBM */
10104 /***********************************************************************
10106 ***********************************************************************/
10112 /* Function prototypes. */
10114 static int png_image_p
P_ ((Lisp_Object object
));
10115 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
10117 /* The symbol `png' identifying images of this type. */
10121 /* Indices of image specification fields in png_format, below. */
10123 enum png_keyword_index
10132 PNG_HEURISTIC_MASK
,
10136 /* Vector of image_keyword structures describing the format
10137 of valid user-defined image specifications. */
10139 static struct image_keyword png_format
[PNG_LAST
] =
10141 {":type", IMAGE_SYMBOL_VALUE
, 1},
10142 {":data", IMAGE_STRING_VALUE
, 0},
10143 {":file", IMAGE_STRING_VALUE
, 0},
10144 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10145 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10146 {":relief", IMAGE_INTEGER_VALUE
, 0},
10147 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10148 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10151 /* Structure describing the image type `png'. */
10153 static struct image_type png_type
=
10163 /* Return non-zero if OBJECT is a valid PNG image specification. */
10166 png_image_p (object
)
10167 Lisp_Object object
;
10169 struct image_keyword fmt
[PNG_LAST
];
10170 bcopy (png_format
, fmt
, sizeof fmt
);
10172 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
10173 || (fmt
[PNG_ASCENT
].count
10174 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
10177 /* Must specify either the :data or :file keyword. */
10178 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
10182 /* Error and warning handlers installed when the PNG library
10186 my_png_error (png_ptr
, msg
)
10187 png_struct
*png_ptr
;
10190 xassert (png_ptr
!= NULL
);
10191 image_error ("PNG error: %s", build_string (msg
), Qnil
);
10192 longjmp (png_ptr
->jmpbuf
, 1);
10197 my_png_warning (png_ptr
, msg
)
10198 png_struct
*png_ptr
;
10201 xassert (png_ptr
!= NULL
);
10202 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
10205 /* Memory source for PNG decoding. */
10207 struct png_memory_storage
10209 unsigned char *bytes
; /* The data */
10210 size_t len
; /* How big is it? */
10211 int index
; /* Where are we? */
10215 /* Function set as reader function when reading PNG image from memory.
10216 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
10217 bytes from the input to DATA. */
10220 png_read_from_memory (png_ptr
, data
, length
)
10221 png_structp png_ptr
;
10225 struct png_memory_storage
*tbr
10226 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
10228 if (length
> tbr
->len
- tbr
->index
)
10229 png_error (png_ptr
, "Read error");
10231 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
10232 tbr
->index
= tbr
->index
+ length
;
10235 /* Load PNG image IMG for use on frame F. Value is non-zero if
10243 Lisp_Object file
, specified_file
;
10244 Lisp_Object specified_data
;
10246 XImage
*ximg
, *mask_img
= NULL
;
10247 struct gcpro gcpro1
;
10248 png_struct
*png_ptr
= NULL
;
10249 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
10252 png_byte
*pixels
= NULL
;
10253 png_byte
**rows
= NULL
;
10254 png_uint_32 width
, height
;
10255 int bit_depth
, color_type
, interlace_type
;
10257 png_uint_32 row_bytes
;
10260 double screen_gamma
, image_gamma
;
10262 struct png_memory_storage tbr
; /* Data to be read */
10264 /* Find out what file to load. */
10265 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10266 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10270 if (NILP (specified_data
))
10272 file
= x_find_image_file (specified_file
);
10273 if (!STRINGP (file
))
10275 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10280 /* Open the image file. */
10281 fp
= fopen (XSTRING (file
)->data
, "rb");
10284 image_error ("Cannot open image file `%s'", file
, Qnil
);
10290 /* Check PNG signature. */
10291 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
10292 || !png_check_sig (sig
, sizeof sig
))
10294 image_error ("Not a PNG file:` %s'", file
, Qnil
);
10302 /* Read from memory. */
10303 tbr
.bytes
= XSTRING (specified_data
)->data
;
10304 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
10307 /* Check PNG signature. */
10308 if (tbr
.len
< sizeof sig
10309 || !png_check_sig (tbr
.bytes
, sizeof sig
))
10311 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
10316 /* Need to skip past the signature. */
10317 tbr
.bytes
+= sizeof (sig
);
10320 /* Initialize read and info structs for PNG lib. */
10321 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
10322 my_png_error
, my_png_warning
);
10325 if (fp
) fclose (fp
);
10330 info_ptr
= png_create_info_struct (png_ptr
);
10333 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
10334 if (fp
) fclose (fp
);
10339 end_info
= png_create_info_struct (png_ptr
);
10342 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
10343 if (fp
) fclose (fp
);
10348 /* Set error jump-back. We come back here when the PNG library
10349 detects an error. */
10350 if (setjmp (png_ptr
->jmpbuf
))
10354 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10357 if (fp
) fclose (fp
);
10362 /* Read image info. */
10363 if (!NILP (specified_data
))
10364 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
10366 png_init_io (png_ptr
, fp
);
10368 png_set_sig_bytes (png_ptr
, sizeof sig
);
10369 png_read_info (png_ptr
, info_ptr
);
10370 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
10371 &interlace_type
, NULL
, NULL
);
10373 /* If image contains simply transparency data, we prefer to
10374 construct a clipping mask. */
10375 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
10380 /* This function is easier to write if we only have to handle
10381 one data format: RGB or RGBA with 8 bits per channel. Let's
10382 transform other formats into that format. */
10384 /* Strip more than 8 bits per channel. */
10385 if (bit_depth
== 16)
10386 png_set_strip_16 (png_ptr
);
10388 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
10390 png_set_expand (png_ptr
);
10392 /* Convert grayscale images to RGB. */
10393 if (color_type
== PNG_COLOR_TYPE_GRAY
10394 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
10395 png_set_gray_to_rgb (png_ptr
);
10397 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
10398 gamma_str
= getenv ("SCREEN_GAMMA");
10399 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
10401 /* Tell the PNG lib to handle gamma correction for us. */
10403 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
10404 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
10405 /* There is a special chunk in the image specifying the gamma. */
10406 png_set_sRGB (png_ptr
, info_ptr
, intent
);
10409 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
10410 /* Image contains gamma information. */
10411 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
10413 /* Use a default of 0.5 for the image gamma. */
10414 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
10416 /* Handle alpha channel by combining the image with a background
10417 color. Do this only if a real alpha channel is supplied. For
10418 simple transparency, we prefer a clipping mask. */
10419 if (!transparent_p
)
10421 png_color_16
*image_background
;
10423 if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
10424 /* Image contains a background color with which to
10425 combine the image. */
10426 png_set_background (png_ptr
, image_background
,
10427 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
10430 /* Image does not contain a background color with which
10431 to combine the image data via an alpha channel. Use
10432 the frame's background instead. */
10435 png_color_16 frame_background
;
10438 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10439 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
10440 XQueryColor (FRAME_W32_DISPLAY (f
), cmap
, &color
);
10443 bzero (&frame_background
, sizeof frame_background
);
10444 frame_background
.red
= color
.red
;
10445 frame_background
.green
= color
.green
;
10446 frame_background
.blue
= color
.blue
;
10448 png_set_background (png_ptr
, &frame_background
,
10449 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
10453 /* Update info structure. */
10454 png_read_update_info (png_ptr
, info_ptr
);
10456 /* Get number of channels. Valid values are 1 for grayscale images
10457 and images with a palette, 2 for grayscale images with transparency
10458 information (alpha channel), 3 for RGB images, and 4 for RGB
10459 images with alpha channel, i.e. RGBA. If conversions above were
10460 sufficient we should only have 3 or 4 channels here. */
10461 channels
= png_get_channels (png_ptr
, info_ptr
);
10462 xassert (channels
== 3 || channels
== 4);
10464 /* Number of bytes needed for one row of the image. */
10465 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
10467 /* Allocate memory for the image. */
10468 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
10469 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
10470 for (i
= 0; i
< height
; ++i
)
10471 rows
[i
] = pixels
+ i
* row_bytes
;
10473 /* Read the entire image. */
10474 png_read_image (png_ptr
, rows
);
10475 png_read_end (png_ptr
, info_ptr
);
10484 /* Create the X image and pixmap. */
10485 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10492 /* Create an image and pixmap serving as mask if the PNG image
10493 contains an alpha channel. */
10496 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
10497 &mask_img
, &img
->mask
))
10499 x_destroy_x_image (ximg
);
10500 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
10506 /* Fill the X image and mask from PNG data. */
10507 init_color_table ();
10509 for (y
= 0; y
< height
; ++y
)
10511 png_byte
*p
= rows
[y
];
10513 for (x
= 0; x
< width
; ++x
)
10520 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10522 /* An alpha channel, aka mask channel, associates variable
10523 transparency with an image. Where other image formats
10524 support binary transparency---fully transparent or fully
10525 opaque---PNG allows up to 254 levels of partial transparency.
10526 The PNG library implements partial transparency by combining
10527 the image with a specified background color.
10529 I'm not sure how to handle this here nicely: because the
10530 background on which the image is displayed may change, for
10531 real alpha channel support, it would be necessary to create
10532 a new image for each possible background.
10534 What I'm doing now is that a mask is created if we have
10535 boolean transparency information. Otherwise I'm using
10536 the frame's background color to combine the image with. */
10541 XPutPixel (mask_img
, x
, y
, *p
> 0);
10547 /* Remember colors allocated for this image. */
10548 img
->colors
= colors_in_color_table (&img
->ncolors
);
10549 free_color_table ();
10552 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10556 img
->width
= width
;
10557 img
->height
= height
;
10559 /* Put the image into the pixmap, then free the X image and its buffer. */
10560 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10561 x_destroy_x_image (ximg
);
10563 /* Same for the mask. */
10566 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10567 x_destroy_x_image (mask_img
);
10575 #endif /* HAVE_PNG != 0 */
10579 /***********************************************************************
10581 ***********************************************************************/
10585 /* Work around a warning about HAVE_STDLIB_H being redefined in
10587 #ifdef HAVE_STDLIB_H
10588 #define HAVE_STDLIB_H_1
10589 #undef HAVE_STDLIB_H
10590 #endif /* HAVE_STLIB_H */
10592 #include <jpeglib.h>
10593 #include <jerror.h>
10594 #include <setjmp.h>
10596 #ifdef HAVE_STLIB_H_1
10597 #define HAVE_STDLIB_H 1
10600 static int jpeg_image_p
P_ ((Lisp_Object object
));
10601 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
10603 /* The symbol `jpeg' identifying images of this type. */
10607 /* Indices of image specification fields in gs_format, below. */
10609 enum jpeg_keyword_index
10618 JPEG_HEURISTIC_MASK
,
10622 /* Vector of image_keyword structures describing the format
10623 of valid user-defined image specifications. */
10625 static struct image_keyword jpeg_format
[JPEG_LAST
] =
10627 {":type", IMAGE_SYMBOL_VALUE
, 1},
10628 {":data", IMAGE_STRING_VALUE
, 0},
10629 {":file", IMAGE_STRING_VALUE
, 0},
10630 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10631 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10632 {":relief", IMAGE_INTEGER_VALUE
, 0},
10633 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10634 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10637 /* Structure describing the image type `jpeg'. */
10639 static struct image_type jpeg_type
=
10649 /* Return non-zero if OBJECT is a valid JPEG image specification. */
10652 jpeg_image_p (object
)
10653 Lisp_Object object
;
10655 struct image_keyword fmt
[JPEG_LAST
];
10657 bcopy (jpeg_format
, fmt
, sizeof fmt
);
10659 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
10660 || (fmt
[JPEG_ASCENT
].count
10661 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
10664 /* Must specify either the :data or :file keyword. */
10665 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
10669 struct my_jpeg_error_mgr
10671 struct jpeg_error_mgr pub
;
10672 jmp_buf setjmp_buffer
;
10676 my_error_exit (cinfo
)
10677 j_common_ptr cinfo
;
10679 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
10680 longjmp (mgr
->setjmp_buffer
, 1);
10683 /* Init source method for JPEG data source manager. Called by
10684 jpeg_read_header() before any data is actually read. See
10685 libjpeg.doc from the JPEG lib distribution. */
10688 our_init_source (cinfo
)
10689 j_decompress_ptr cinfo
;
10694 /* Fill input buffer method for JPEG data source manager. Called
10695 whenever more data is needed. We read the whole image in one step,
10696 so this only adds a fake end of input marker at the end. */
10699 our_fill_input_buffer (cinfo
)
10700 j_decompress_ptr cinfo
;
10702 /* Insert a fake EOI marker. */
10703 struct jpeg_source_mgr
*src
= cinfo
->src
;
10704 static JOCTET buffer
[2];
10706 buffer
[0] = (JOCTET
) 0xFF;
10707 buffer
[1] = (JOCTET
) JPEG_EOI
;
10709 src
->next_input_byte
= buffer
;
10710 src
->bytes_in_buffer
= 2;
10715 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
10716 is the JPEG data source manager. */
10719 our_skip_input_data (cinfo
, num_bytes
)
10720 j_decompress_ptr cinfo
;
10723 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10727 if (num_bytes
> src
->bytes_in_buffer
)
10728 ERREXIT (cinfo
, JERR_INPUT_EOF
);
10730 src
->bytes_in_buffer
-= num_bytes
;
10731 src
->next_input_byte
+= num_bytes
;
10736 /* Method to terminate data source. Called by
10737 jpeg_finish_decompress() after all data has been processed. */
10740 our_term_source (cinfo
)
10741 j_decompress_ptr cinfo
;
10746 /* Set up the JPEG lib for reading an image from DATA which contains
10747 LEN bytes. CINFO is the decompression info structure created for
10748 reading the image. */
10751 jpeg_memory_src (cinfo
, data
, len
)
10752 j_decompress_ptr cinfo
;
10756 struct jpeg_source_mgr
*src
;
10758 if (cinfo
->src
== NULL
)
10760 /* First time for this JPEG object? */
10761 cinfo
->src
= (struct jpeg_source_mgr
*)
10762 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
10763 sizeof (struct jpeg_source_mgr
));
10764 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10765 src
->next_input_byte
= data
;
10768 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10769 src
->init_source
= our_init_source
;
10770 src
->fill_input_buffer
= our_fill_input_buffer
;
10771 src
->skip_input_data
= our_skip_input_data
;
10772 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
10773 src
->term_source
= our_term_source
;
10774 src
->bytes_in_buffer
= len
;
10775 src
->next_input_byte
= data
;
10779 /* Load image IMG for use on frame F. Patterned after example.c
10780 from the JPEG lib. */
10787 struct jpeg_decompress_struct cinfo
;
10788 struct my_jpeg_error_mgr mgr
;
10789 Lisp_Object file
, specified_file
;
10790 Lisp_Object specified_data
;
10793 int row_stride
, x
, y
;
10794 XImage
*ximg
= NULL
;
10796 unsigned long *colors
;
10798 struct gcpro gcpro1
;
10800 /* Open the JPEG file. */
10801 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10802 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10806 if (NILP (specified_data
))
10808 file
= x_find_image_file (specified_file
);
10809 if (!STRINGP (file
))
10811 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10816 fp
= fopen (XSTRING (file
)->data
, "r");
10819 image_error ("Cannot open `%s'", file
, Qnil
);
10825 /* Customize libjpeg's error handling to call my_error_exit when an
10826 error is detected. This function will perform a longjmp. */
10827 mgr
.pub
.error_exit
= my_error_exit
;
10828 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
10830 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
10834 /* Called from my_error_exit. Display a JPEG error. */
10835 char buffer
[JMSG_LENGTH_MAX
];
10836 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
10837 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
10838 build_string (buffer
));
10841 /* Close the input file and destroy the JPEG object. */
10844 jpeg_destroy_decompress (&cinfo
);
10848 /* If we already have an XImage, free that. */
10849 x_destroy_x_image (ximg
);
10851 /* Free pixmap and colors. */
10852 x_clear_image (f
, img
);
10859 /* Create the JPEG decompression object. Let it read from fp.
10860 Read the JPEG image header. */
10861 jpeg_create_decompress (&cinfo
);
10863 if (NILP (specified_data
))
10864 jpeg_stdio_src (&cinfo
, fp
);
10866 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
10867 STRING_BYTES (XSTRING (specified_data
)));
10869 jpeg_read_header (&cinfo
, TRUE
);
10871 /* Customize decompression so that color quantization will be used.
10872 Start decompression. */
10873 cinfo
.quantize_colors
= TRUE
;
10874 jpeg_start_decompress (&cinfo
);
10875 width
= img
->width
= cinfo
.output_width
;
10876 height
= img
->height
= cinfo
.output_height
;
10880 /* Create X image and pixmap. */
10881 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10885 longjmp (mgr
.setjmp_buffer
, 2);
10888 /* Allocate colors. When color quantization is used,
10889 cinfo.actual_number_of_colors has been set with the number of
10890 colors generated, and cinfo.colormap is a two-dimensional array
10891 of color indices in the range 0..cinfo.actual_number_of_colors.
10892 No more than 255 colors will be generated. */
10896 if (cinfo
.out_color_components
> 2)
10897 ir
= 0, ig
= 1, ib
= 2;
10898 else if (cinfo
.out_color_components
> 1)
10899 ir
= 0, ig
= 1, ib
= 0;
10901 ir
= 0, ig
= 0, ib
= 0;
10903 /* Use the color table mechanism because it handles colors that
10904 cannot be allocated nicely. Such colors will be replaced with
10905 a default color, and we don't have to care about which colors
10906 can be freed safely, and which can't. */
10907 init_color_table ();
10908 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
10911 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
10913 /* Multiply RGB values with 255 because X expects RGB values
10914 in the range 0..0xffff. */
10915 int r
= cinfo
.colormap
[ir
][i
] << 8;
10916 int g
= cinfo
.colormap
[ig
][i
] << 8;
10917 int b
= cinfo
.colormap
[ib
][i
] << 8;
10918 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
10921 /* Remember those colors actually allocated. */
10922 img
->colors
= colors_in_color_table (&img
->ncolors
);
10923 free_color_table ();
10927 row_stride
= width
* cinfo
.output_components
;
10928 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
10930 for (y
= 0; y
< height
; ++y
)
10932 jpeg_read_scanlines (&cinfo
, buffer
, 1);
10933 for (x
= 0; x
< cinfo
.output_width
; ++x
)
10934 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
10938 jpeg_finish_decompress (&cinfo
);
10939 jpeg_destroy_decompress (&cinfo
);
10943 /* Put the image into the pixmap. */
10944 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10945 x_destroy_x_image (ximg
);
10951 #endif /* HAVE_JPEG */
10955 /***********************************************************************
10957 ***********************************************************************/
10961 #include <tiffio.h>
10963 static int tiff_image_p
P_ ((Lisp_Object object
));
10964 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
10966 /* The symbol `tiff' identifying images of this type. */
10970 /* Indices of image specification fields in tiff_format, below. */
10972 enum tiff_keyword_index
10981 TIFF_HEURISTIC_MASK
,
10985 /* Vector of image_keyword structures describing the format
10986 of valid user-defined image specifications. */
10988 static struct image_keyword tiff_format
[TIFF_LAST
] =
10990 {":type", IMAGE_SYMBOL_VALUE
, 1},
10991 {":data", IMAGE_STRING_VALUE
, 0},
10992 {":file", IMAGE_STRING_VALUE
, 0},
10993 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10994 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10995 {":relief", IMAGE_INTEGER_VALUE
, 0},
10996 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10997 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11000 /* Structure describing the image type `tiff'. */
11002 static struct image_type tiff_type
=
11012 /* Return non-zero if OBJECT is a valid TIFF image specification. */
11015 tiff_image_p (object
)
11016 Lisp_Object object
;
11018 struct image_keyword fmt
[TIFF_LAST
];
11019 bcopy (tiff_format
, fmt
, sizeof fmt
);
11021 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
11022 || (fmt
[TIFF_ASCENT
].count
11023 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
11026 /* Must specify either the :data or :file keyword. */
11027 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
11031 /* Reading from a memory buffer for TIFF images Based on the PNG
11032 memory source, but we have to provide a lot of extra functions.
11035 We really only need to implement read and seek, but I am not
11036 convinced that the TIFF library is smart enough not to destroy
11037 itself if we only hand it the function pointers we need to
11042 unsigned char *bytes
;
11046 tiff_memory_source
;
11049 tiff_read_from_memory (data
, buf
, size
)
11054 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11056 if (size
> src
->len
- src
->index
)
11057 return (size_t) -1;
11058 bcopy (src
->bytes
+ src
->index
, buf
, size
);
11059 src
->index
+= size
;
11064 tiff_write_from_memory (data
, buf
, size
)
11069 return (size_t) -1;
11073 tiff_seek_in_memory (data
, off
, whence
)
11078 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11083 case SEEK_SET
: /* Go from beginning of source. */
11087 case SEEK_END
: /* Go from end of source. */
11088 idx
= src
->len
+ off
;
11091 case SEEK_CUR
: /* Go from current position. */
11092 idx
= src
->index
+ off
;
11095 default: /* Invalid `whence'. */
11099 if (idx
> src
->len
|| idx
< 0)
11107 tiff_close_memory (data
)
11115 tiff_mmap_memory (data
, pbase
, psize
)
11120 /* It is already _IN_ memory. */
11125 tiff_unmap_memory (data
, base
, size
)
11130 /* We don't need to do this. */
11134 tiff_size_of_memory (data
)
11137 return ((tiff_memory_source
*) data
)->len
;
11140 /* Load TIFF image IMG for use on frame F. Value is non-zero if
11148 Lisp_Object file
, specified_file
;
11149 Lisp_Object specified_data
;
11151 int width
, height
, x
, y
;
11155 struct gcpro gcpro1
;
11156 tiff_memory_source memsrc
;
11158 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11159 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11163 if (NILP (specified_data
))
11165 /* Read from a file */
11166 file
= x_find_image_file (specified_file
);
11167 if (!STRINGP (file
))
11169 image_error ("Cannot find image file `%s'", file
, Qnil
);
11174 /* Try to open the image file. */
11175 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
11178 image_error ("Cannot open `%s'", file
, Qnil
);
11185 /* Memory source! */
11186 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11187 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11190 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
11191 (TIFFReadWriteProc
) tiff_read_from_memory
,
11192 (TIFFReadWriteProc
) tiff_write_from_memory
,
11193 tiff_seek_in_memory
,
11195 tiff_size_of_memory
,
11197 tiff_unmap_memory
);
11201 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
11207 /* Get width and height of the image, and allocate a raster buffer
11208 of width x height 32-bit values. */
11209 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
11210 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
11211 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
11213 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
11217 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
11225 /* Create the X image and pixmap. */
11226 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11234 /* Initialize the color table. */
11235 init_color_table ();
11237 /* Process the pixel raster. Origin is in the lower-left corner. */
11238 for (y
= 0; y
< height
; ++y
)
11240 uint32
*row
= buf
+ y
* width
;
11242 for (x
= 0; x
< width
; ++x
)
11244 uint32 abgr
= row
[x
];
11245 int r
= TIFFGetR (abgr
) << 8;
11246 int g
= TIFFGetG (abgr
) << 8;
11247 int b
= TIFFGetB (abgr
) << 8;
11248 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
11252 /* Remember the colors allocated for the image. Free the color table. */
11253 img
->colors
= colors_in_color_table (&img
->ncolors
);
11254 free_color_table ();
11256 /* Put the image into the pixmap, then free the X image and its buffer. */
11257 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11258 x_destroy_x_image (ximg
);
11262 img
->width
= width
;
11263 img
->height
= height
;
11269 #endif /* HAVE_TIFF != 0 */
11273 /***********************************************************************
11275 ***********************************************************************/
11279 #include <gif_lib.h>
11281 static int gif_image_p
P_ ((Lisp_Object object
));
11282 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
11284 /* The symbol `gif' identifying images of this type. */
11288 /* Indices of image specification fields in gif_format, below. */
11290 enum gif_keyword_index
11299 GIF_HEURISTIC_MASK
,
11304 /* Vector of image_keyword structures describing the format
11305 of valid user-defined image specifications. */
11307 static struct image_keyword gif_format
[GIF_LAST
] =
11309 {":type", IMAGE_SYMBOL_VALUE
, 1},
11310 {":data", IMAGE_STRING_VALUE
, 0},
11311 {":file", IMAGE_STRING_VALUE
, 0},
11312 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11313 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11314 {":relief", IMAGE_INTEGER_VALUE
, 0},
11315 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11316 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11317 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0}
11320 /* Structure describing the image type `gif'. */
11322 static struct image_type gif_type
=
11331 /* Return non-zero if OBJECT is a valid GIF image specification. */
11334 gif_image_p (object
)
11335 Lisp_Object object
;
11337 struct image_keyword fmt
[GIF_LAST
];
11338 bcopy (gif_format
, fmt
, sizeof fmt
);
11340 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
11341 || (fmt
[GIF_ASCENT
].count
11342 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
11345 /* Must specify either the :data or :file keyword. */
11346 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
11349 /* Reading a GIF image from memory
11350 Based on the PNG memory stuff to a certain extent. */
11354 unsigned char *bytes
;
11360 /* Make the current memory source available to gif_read_from_memory.
11361 It's done this way because not all versions of libungif support
11362 a UserData field in the GifFileType structure. */
11363 static gif_memory_source
*current_gif_memory_src
;
11366 gif_read_from_memory (file
, buf
, len
)
11371 gif_memory_source
*src
= current_gif_memory_src
;
11373 if (len
> src
->len
- src
->index
)
11376 bcopy (src
->bytes
+ src
->index
, buf
, len
);
11382 /* Load GIF image IMG for use on frame F. Value is non-zero if
11390 Lisp_Object file
, specified_file
;
11391 Lisp_Object specified_data
;
11392 int rc
, width
, height
, x
, y
, i
;
11394 ColorMapObject
*gif_color_map
;
11395 unsigned long pixel_colors
[256];
11397 struct gcpro gcpro1
;
11399 int ino
, image_left
, image_top
, image_width
, image_height
;
11400 gif_memory_source memsrc
;
11401 unsigned char *raster
;
11403 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11404 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11408 if (NILP (specified_data
))
11410 file
= x_find_image_file (specified_file
);
11411 if (!STRINGP (file
))
11413 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11418 /* Open the GIF file. */
11419 gif
= DGifOpenFileName (XSTRING (file
)->data
);
11422 image_error ("Cannot open `%s'", file
, Qnil
);
11429 /* Read from memory! */
11430 current_gif_memory_src
= &memsrc
;
11431 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11432 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11435 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
11438 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
11444 /* Read entire contents. */
11445 rc
= DGifSlurp (gif
);
11446 if (rc
== GIF_ERROR
)
11448 image_error ("Error reading `%s'", img
->spec
, Qnil
);
11449 DGifCloseFile (gif
);
11454 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
11455 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
11456 if (ino
>= gif
->ImageCount
)
11458 image_error ("Invalid image number `%s' in image `%s'",
11460 DGifCloseFile (gif
);
11465 width
= img
->width
= gif
->SWidth
;
11466 height
= img
->height
= gif
->SHeight
;
11470 /* Create the X image and pixmap. */
11471 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11474 DGifCloseFile (gif
);
11479 /* Allocate colors. */
11480 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
11481 if (!gif_color_map
)
11482 gif_color_map
= gif
->SColorMap
;
11483 init_color_table ();
11484 bzero (pixel_colors
, sizeof pixel_colors
);
11486 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
11488 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
11489 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
11490 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
11491 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11494 img
->colors
= colors_in_color_table (&img
->ncolors
);
11495 free_color_table ();
11497 /* Clear the part of the screen image that are not covered by
11498 the image from the GIF file. Full animated GIF support
11499 requires more than can be done here (see the gif89 spec,
11500 disposal methods). Let's simply assume that the part
11501 not covered by a sub-image is in the frame's background color. */
11502 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
11503 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
11504 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
11505 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
11507 for (y
= 0; y
< image_top
; ++y
)
11508 for (x
= 0; x
< width
; ++x
)
11509 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11511 for (y
= image_top
+ image_height
; y
< height
; ++y
)
11512 for (x
= 0; x
< width
; ++x
)
11513 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11515 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
11517 for (x
= 0; x
< image_left
; ++x
)
11518 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11519 for (x
= image_left
+ image_width
; x
< width
; ++x
)
11520 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11523 /* Read the GIF image into the X image. We use a local variable
11524 `raster' here because RasterBits below is a char *, and invites
11525 problems with bytes >= 0x80. */
11526 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
11528 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
11530 static int interlace_start
[] = {0, 4, 2, 1};
11531 static int interlace_increment
[] = {8, 8, 4, 2};
11533 int row
= interlace_start
[0];
11537 for (y
= 0; y
< image_height
; y
++)
11539 if (row
>= image_height
)
11541 row
= interlace_start
[++pass
];
11542 while (row
>= image_height
)
11543 row
= interlace_start
[++pass
];
11546 for (x
= 0; x
< image_width
; x
++)
11548 int i
= raster
[(y
* image_width
) + x
];
11549 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
11553 row
+= interlace_increment
[pass
];
11558 for (y
= 0; y
< image_height
; ++y
)
11559 for (x
= 0; x
< image_width
; ++x
)
11561 int i
= raster
[y
* image_width
+ x
];
11562 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
11566 DGifCloseFile (gif
);
11568 /* Put the image into the pixmap, then free the X image and its buffer. */
11569 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11570 x_destroy_x_image (ximg
);
11577 #endif /* HAVE_GIF != 0 */
11581 /***********************************************************************
11583 ***********************************************************************/
11585 #ifdef HAVE_GHOSTSCRIPT
11586 static int gs_image_p
P_ ((Lisp_Object object
));
11587 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
11588 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
11590 /* The symbol `postscript' identifying images of this type. */
11592 Lisp_Object Qpostscript
;
11594 /* Keyword symbols. */
11596 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
11598 /* Indices of image specification fields in gs_format, below. */
11600 enum gs_keyword_index
11616 /* Vector of image_keyword structures describing the format
11617 of valid user-defined image specifications. */
11619 static struct image_keyword gs_format
[GS_LAST
] =
11621 {":type", IMAGE_SYMBOL_VALUE
, 1},
11622 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11623 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11624 {":file", IMAGE_STRING_VALUE
, 1},
11625 {":loader", IMAGE_FUNCTION_VALUE
, 0},
11626 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
11627 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11628 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11629 {":relief", IMAGE_INTEGER_VALUE
, 0},
11630 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11631 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11634 /* Structure describing the image type `ghostscript'. */
11636 static struct image_type gs_type
=
11646 /* Free X resources of Ghostscript image IMG which is used on frame F. */
11649 gs_clear_image (f
, img
)
11653 /* IMG->data.ptr_val may contain a recorded colormap. */
11654 xfree (img
->data
.ptr_val
);
11655 x_clear_image (f
, img
);
11659 /* Return non-zero if OBJECT is a valid Ghostscript image
11663 gs_image_p (object
)
11664 Lisp_Object object
;
11666 struct image_keyword fmt
[GS_LAST
];
11670 bcopy (gs_format
, fmt
, sizeof fmt
);
11672 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
11673 || (fmt
[GS_ASCENT
].count
11674 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
11677 /* Bounding box must be a list or vector containing 4 integers. */
11678 tem
= fmt
[GS_BOUNDING_BOX
].value
;
11681 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
11682 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
11687 else if (VECTORP (tem
))
11689 if (XVECTOR (tem
)->size
!= 4)
11691 for (i
= 0; i
< 4; ++i
)
11692 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
11702 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
11711 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
11712 struct gcpro gcpro1
, gcpro2
;
11714 double in_width
, in_height
;
11715 Lisp_Object pixel_colors
= Qnil
;
11717 /* Compute pixel size of pixmap needed from the given size in the
11718 image specification. Sizes in the specification are in pt. 1 pt
11719 = 1/72 in, xdpi and ydpi are stored in the frame's X display
11721 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
11722 in_width
= XFASTINT (pt_width
) / 72.0;
11723 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
11724 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
11725 in_height
= XFASTINT (pt_height
) / 72.0;
11726 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
11728 /* Create the pixmap. */
11730 xassert (img
->pixmap
== 0);
11731 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11732 img
->width
, img
->height
,
11733 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
11738 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
11742 /* Call the loader to fill the pixmap. It returns a process object
11743 if successful. We do not record_unwind_protect here because
11744 other places in redisplay like calling window scroll functions
11745 don't either. Let the Lisp loader use `unwind-protect' instead. */
11746 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
11748 sprintf (buffer
, "%lu %lu",
11749 (unsigned long) FRAME_W32_WINDOW (f
),
11750 (unsigned long) img
->pixmap
);
11751 window_and_pixmap_id
= build_string (buffer
);
11753 sprintf (buffer
, "%lu %lu",
11754 FRAME_FOREGROUND_PIXEL (f
),
11755 FRAME_BACKGROUND_PIXEL (f
));
11756 pixel_colors
= build_string (buffer
);
11758 XSETFRAME (frame
, f
);
11759 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
11761 loader
= intern ("gs-load-image");
11763 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
11764 make_number (img
->width
),
11765 make_number (img
->height
),
11766 window_and_pixmap_id
,
11769 return PROCESSP (img
->data
.lisp_val
);
11773 /* Kill the Ghostscript process that was started to fill PIXMAP on
11774 frame F. Called from XTread_socket when receiving an event
11775 telling Emacs that Ghostscript has finished drawing. */
11778 x_kill_gs_process (pixmap
, f
)
11782 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
11786 /* Find the image containing PIXMAP. */
11787 for (i
= 0; i
< c
->used
; ++i
)
11788 if (c
->images
[i
]->pixmap
== pixmap
)
11791 /* Kill the GS process. We should have found PIXMAP in the image
11792 cache and its image should contain a process object. */
11793 xassert (i
< c
->used
);
11794 img
= c
->images
[i
];
11795 xassert (PROCESSP (img
->data
.lisp_val
));
11796 Fkill_process (img
->data
.lisp_val
, Qnil
);
11797 img
->data
.lisp_val
= Qnil
;
11799 /* On displays with a mutable colormap, figure out the colors
11800 allocated for the image by looking at the pixels of an XImage for
11802 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
11803 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
11809 /* Try to get an XImage for img->pixmep. */
11810 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
11811 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
11816 /* Initialize the color table. */
11817 init_color_table ();
11819 /* For each pixel of the image, look its color up in the
11820 color table. After having done so, the color table will
11821 contain an entry for each color used by the image. */
11822 for (y
= 0; y
< img
->height
; ++y
)
11823 for (x
= 0; x
< img
->width
; ++x
)
11825 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
11826 lookup_pixel_color (f
, pixel
);
11829 /* Record colors in the image. Free color table and XImage. */
11830 img
->colors
= colors_in_color_table (&img
->ncolors
);
11831 free_color_table ();
11832 XDestroyImage (ximg
);
11834 #if 0 /* This doesn't seem to be the case. If we free the colors
11835 here, we get a BadAccess later in x_clear_image when
11836 freeing the colors. */
11837 /* We have allocated colors once, but Ghostscript has also
11838 allocated colors on behalf of us. So, to get the
11839 reference counts right, free them once. */
11842 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
11843 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
,
11844 img
->colors
, img
->ncolors
, 0);
11849 image_error ("Cannot get X image of `%s'; colors will not be freed",
11856 #endif /* HAVE_GHOSTSCRIPT */
11859 /***********************************************************************
11861 ***********************************************************************/
11863 DEFUN ("x-change-window-property", Fx_change_window_property
,
11864 Sx_change_window_property
, 2, 3, 0,
11865 "Change window property PROP to VALUE on the X window of FRAME.\n\
11866 PROP and VALUE must be strings. FRAME nil or omitted means use the\n\
11867 selected frame. Value is VALUE.")
11868 (prop
, value
, frame
)
11869 Lisp_Object frame
, prop
, value
;
11871 #if 0 /* TODO : port window properties to W32 */
11872 struct frame
*f
= check_x_frame (frame
);
11875 CHECK_STRING (prop
, 1);
11876 CHECK_STRING (value
, 2);
11879 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11880 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11881 prop_atom
, XA_STRING
, 8, PropModeReplace
,
11882 XSTRING (value
)->data
, XSTRING (value
)->size
);
11884 /* Make sure the property is set when we return. */
11885 XFlush (FRAME_W32_DISPLAY (f
));
11894 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
11895 Sx_delete_window_property
, 1, 2, 0,
11896 "Remove window property PROP from X window of FRAME.\n\
11897 FRAME nil or omitted means use the selected frame. Value is PROP.")
11899 Lisp_Object prop
, frame
;
11901 #if 0 /* TODO : port window properties to W32 */
11903 struct frame
*f
= check_x_frame (frame
);
11906 CHECK_STRING (prop
, 1);
11908 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11909 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
11911 /* Make sure the property is removed when we return. */
11912 XFlush (FRAME_W32_DISPLAY (f
));
11920 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
11922 "Value is the value of window property PROP on FRAME.\n\
11923 If FRAME is nil or omitted, use the selected frame. Value is nil\n\
11924 if FRAME hasn't a property with name PROP or if PROP has no string\n\
11927 Lisp_Object prop
, frame
;
11929 #if 0 /* TODO : port window properties to W32 */
11931 struct frame
*f
= check_x_frame (frame
);
11934 Lisp_Object prop_value
= Qnil
;
11935 char *tmp_data
= NULL
;
11938 unsigned long actual_size
, bytes_remaining
;
11940 CHECK_STRING (prop
, 1);
11942 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11943 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11944 prop_atom
, 0, 0, False
, XA_STRING
,
11945 &actual_type
, &actual_format
, &actual_size
,
11946 &bytes_remaining
, (unsigned char **) &tmp_data
);
11949 int size
= bytes_remaining
;
11954 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11955 prop_atom
, 0, bytes_remaining
,
11957 &actual_type
, &actual_format
,
11958 &actual_size
, &bytes_remaining
,
11959 (unsigned char **) &tmp_data
);
11961 prop_value
= make_string (tmp_data
, size
);
11976 /***********************************************************************
11978 ***********************************************************************/
11980 /* If non-null, an asynchronous timer that, when it expires, displays
11981 a busy cursor on all frames. */
11983 static struct atimer
*busy_cursor_atimer
;
11985 /* Non-zero means a busy cursor is currently shown. */
11987 static int busy_cursor_shown_p
;
11989 /* Number of seconds to wait before displaying a busy cursor. */
11991 static Lisp_Object Vbusy_cursor_delay
;
11993 /* Default number of seconds to wait before displaying a busy
11996 #define DEFAULT_BUSY_CURSOR_DELAY 1
11998 /* Function prototypes. */
12000 static void show_busy_cursor
P_ ((struct atimer
*));
12001 static void hide_busy_cursor
P_ ((void));
12004 /* Cancel a currently active busy-cursor timer, and start a new one. */
12007 start_busy_cursor ()
12009 #if 0 /* TODO: cursor shape changes. */
12011 int secs
, usecs
= 0;
12013 cancel_busy_cursor ();
12015 if (INTEGERP (Vbusy_cursor_delay
)
12016 && XINT (Vbusy_cursor_delay
) > 0)
12017 secs
= XFASTINT (Vbusy_cursor_delay
);
12018 else if (FLOATP (Vbusy_cursor_delay
)
12019 && XFLOAT_DATA (Vbusy_cursor_delay
) > 0)
12022 tem
= Ftruncate (Vbusy_cursor_delay
, Qnil
);
12023 secs
= XFASTINT (tem
);
12024 usecs
= (XFLOAT_DATA (Vbusy_cursor_delay
) - secs
) * 1000000;
12027 secs
= DEFAULT_BUSY_CURSOR_DELAY
;
12029 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
12030 busy_cursor_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
12031 show_busy_cursor
, NULL
);
12036 /* Cancel the busy cursor timer if active, hide a busy cursor if
12040 cancel_busy_cursor ()
12042 if (busy_cursor_atimer
)
12044 cancel_atimer (busy_cursor_atimer
);
12045 busy_cursor_atimer
= NULL
;
12048 if (busy_cursor_shown_p
)
12049 hide_busy_cursor ();
12053 /* Timer function of busy_cursor_atimer. TIMER is equal to
12054 busy_cursor_atimer.
12056 Display a busy cursor on all frames by mapping the frames'
12057 busy_window. Set the busy_p flag in the frames' output_data.x
12058 structure to indicate that a busy cursor is shown on the
12062 show_busy_cursor (timer
)
12063 struct atimer
*timer
;
12065 #if 0 /* TODO: cursor shape changes. */
12066 /* The timer implementation will cancel this timer automatically
12067 after this function has run. Set busy_cursor_atimer to null
12068 so that we know the timer doesn't have to be canceled. */
12069 busy_cursor_atimer
= NULL
;
12071 if (!busy_cursor_shown_p
)
12073 Lisp_Object rest
, frame
;
12077 FOR_EACH_FRAME (rest
, frame
)
12078 if (FRAME_X_P (XFRAME (frame
)))
12080 struct frame
*f
= XFRAME (frame
);
12082 f
->output_data
.w32
->busy_p
= 1;
12084 if (!f
->output_data
.w32
->busy_window
)
12086 unsigned long mask
= CWCursor
;
12087 XSetWindowAttributes attrs
;
12089 attrs
.cursor
= f
->output_data
.w32
->busy_cursor
;
12091 f
->output_data
.w32
->busy_window
12092 = XCreateWindow (FRAME_X_DISPLAY (f
),
12093 FRAME_OUTER_WINDOW (f
),
12094 0, 0, 32000, 32000, 0, 0,
12100 XMapRaised (FRAME_X_DISPLAY (f
), f
->output_data
.w32
->busy_window
);
12101 XFlush (FRAME_X_DISPLAY (f
));
12104 busy_cursor_shown_p
= 1;
12111 /* Hide the busy cursor on all frames, if it is currently shown. */
12114 hide_busy_cursor ()
12116 #if 0 /* TODO: cursor shape changes. */
12117 if (busy_cursor_shown_p
)
12119 Lisp_Object rest
, frame
;
12122 FOR_EACH_FRAME (rest
, frame
)
12124 struct frame
*f
= XFRAME (frame
);
12127 /* Watch out for newly created frames. */
12128 && f
->output_data
.x
->busy_window
)
12130 XUnmapWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->busy_window
);
12131 /* Sync here because XTread_socket looks at the busy_p flag
12132 that is reset to zero below. */
12133 XSync (FRAME_X_DISPLAY (f
), False
);
12134 f
->output_data
.x
->busy_p
= 0;
12138 busy_cursor_shown_p
= 0;
12146 /***********************************************************************
12148 ***********************************************************************/
12150 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
12153 /* The frame of a currently visible tooltip, or null. */
12155 struct frame
*tip_frame
;
12157 /* If non-nil, a timer started that hides the last tooltip when it
12160 Lisp_Object tip_timer
;
12163 /* Create a frame for a tooltip on the display described by DPYINFO.
12164 PARMS is a list of frame parameters. Value is the frame. */
12167 x_create_tip_frame (dpyinfo
, parms
)
12168 struct w32_display_info
*dpyinfo
;
12171 #if 0 /* TODO : w32 version */
12173 Lisp_Object frame
, tem
;
12175 long window_prompting
= 0;
12177 int count
= specpdl_ptr
- specpdl
;
12178 struct gcpro gcpro1
, gcpro2
, gcpro3
;
12183 /* Use this general default value to start with until we know if
12184 this frame has a specified name. */
12185 Vx_resource_name
= Vinvocation_name
;
12187 #ifdef MULTI_KBOARD
12188 kb
= dpyinfo
->kboard
;
12190 kb
= &the_only_kboard
;
12193 /* Get the name of the frame to use for resource lookup. */
12194 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
12195 if (!STRINGP (name
)
12196 && !EQ (name
, Qunbound
)
12198 error ("Invalid frame name--not a string or nil");
12199 Vx_resource_name
= name
;
12202 GCPRO3 (parms
, name
, frame
);
12203 tip_frame
= f
= make_frame (1);
12204 XSETFRAME (frame
, f
);
12205 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
12207 f
->output_method
= output_w32
;
12208 f
->output_data
.w32
=
12209 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
12210 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
12212 f
->output_data
.w32
->icon_bitmap
= -1;
12214 f
->output_data
.w32
->fontset
= -1;
12215 f
->icon_name
= Qnil
;
12217 #ifdef MULTI_KBOARD
12218 FRAME_KBOARD (f
) = kb
;
12220 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12221 f
->output_data
.w32
->explicit_parent
= 0;
12223 /* Set the name; the functions to which we pass f expect the name to
12225 if (EQ (name
, Qunbound
) || NILP (name
))
12227 f
->name
= build_string (dpyinfo
->x_id_name
);
12228 f
->explicit_name
= 0;
12233 f
->explicit_name
= 1;
12234 /* use the frame's title when getting resources for this frame. */
12235 specbind (Qx_resource_name
, name
);
12238 /* Extract the window parameters from the supplied values
12239 that are needed to determine window geometry. */
12243 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
12246 /* First, try whatever font the caller has specified. */
12247 if (STRINGP (font
))
12249 tem
= Fquery_fontset (font
, Qnil
);
12251 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
12253 font
= x_new_font (f
, XSTRING (font
)->data
);
12256 /* Try out a font which we hope has bold and italic variations. */
12257 if (!STRINGP (font
))
12258 font
= x_new_font (f
, "-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
12259 if (!STRINGP (font
))
12260 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12261 if (! STRINGP (font
))
12262 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12263 if (! STRINGP (font
))
12264 /* This was formerly the first thing tried, but it finds too many fonts
12265 and takes too long. */
12266 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
12267 /* If those didn't work, look for something which will at least work. */
12268 if (! STRINGP (font
))
12269 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
12271 if (! STRINGP (font
))
12272 font
= build_string ("fixed");
12274 x_default_parameter (f
, parms
, Qfont
, font
,
12275 "font", "Font", RES_TYPE_STRING
);
12278 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
12279 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
12281 /* This defaults to 2 in order to match xterm. We recognize either
12282 internalBorderWidth or internalBorder (which is what xterm calls
12284 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12288 value
= w32_get_arg (parms
, Qinternal_border_width
,
12289 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
12290 if (! EQ (value
, Qunbound
))
12291 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
12295 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
12296 "internalBorderWidth", "internalBorderWidth",
12299 /* Also do the stuff which must be set before the window exists. */
12300 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
12301 "foreground", "Foreground", RES_TYPE_STRING
);
12302 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
12303 "background", "Background", RES_TYPE_STRING
);
12304 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
12305 "pointerColor", "Foreground", RES_TYPE_STRING
);
12306 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
12307 "cursorColor", "Foreground", RES_TYPE_STRING
);
12308 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
12309 "borderColor", "BorderColor", RES_TYPE_STRING
);
12311 /* Init faces before x_default_parameter is called for scroll-bar
12312 parameters because that function calls x_set_scroll_bar_width,
12313 which calls change_frame_size, which calls Fset_window_buffer,
12314 which runs hooks, which call Fvertical_motion. At the end, we
12315 end up in init_iterator with a null face cache, which should not
12317 init_frame_faces (f
);
12319 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12320 window_prompting
= x_figure_window_size (f
, parms
);
12322 if (window_prompting
& XNegative
)
12324 if (window_prompting
& YNegative
)
12325 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
12327 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
12331 if (window_prompting
& YNegative
)
12332 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
12334 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
12337 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
12339 XSetWindowAttributes attrs
;
12340 unsigned long mask
;
12343 mask
= CWBackPixel
| CWOverrideRedirect
| CWSaveUnder
| CWEventMask
;
12344 /* Window managers looks at the override-redirect flag to
12345 determine whether or net to give windows a decoration (Xlib
12347 attrs
.override_redirect
= True
;
12348 attrs
.save_under
= True
;
12349 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
12350 /* Arrange for getting MapNotify and UnmapNotify events. */
12351 attrs
.event_mask
= StructureNotifyMask
;
12353 = FRAME_W32_WINDOW (f
)
12354 = XCreateWindow (FRAME_W32_DISPLAY (f
),
12355 FRAME_W32_DISPLAY_INFO (f
)->root_window
,
12356 /* x, y, width, height */
12360 CopyFromParent
, InputOutput
, CopyFromParent
,
12367 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
12368 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12369 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
12370 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12371 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
12372 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
12374 /* Dimensions, especially f->height, must be done via change_frame_size.
12375 Change will not be effected unless different from the current
12378 height
= f
->height
;
12380 SET_FRAME_WIDTH (f
, 0);
12381 change_frame_size (f
, height
, width
, 1, 0, 0);
12387 /* It is now ok to make the frame official even if we get an error
12388 below. And the frame needs to be on Vframe_list or making it
12389 visible won't work. */
12390 Vframe_list
= Fcons (frame
, Vframe_list
);
12392 /* Now that the frame is official, it counts as a reference to
12394 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
12396 return unbind_to (count
, frame
);
12401 #ifdef TODO /* Tooltip support not complete. */
12402 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
12403 "Show STRING in a \"tooltip\" window on frame FRAME.\n\
12404 A tooltip window is a small X window displaying a string.\n\
12406 FRAME nil or omitted means use the selected frame.\n\
12408 PARMS is an optional list of frame parameters which can be\n\
12409 used to change the tooltip's appearance.\n\
12411 Automatically hide the tooltip after TIMEOUT seconds.\n\
12412 TIMEOUT nil means use the default timeout of 5 seconds.\n\
12414 If the list of frame parameters PARAMS contains a `left' parameters,\n\
12415 the tooltip is displayed at that x-position. Otherwise it is\n\
12416 displayed at the mouse position, with offset DX added (default is 5 if\n\
12417 DX isn't specified). Likewise for the y-position; if a `top' frame\n\
12418 parameter is specified, it determines the y-position of the tooltip\n\
12419 window, otherwise it is displayed at the mouse position, with offset\n\
12420 DY added (default is -5).")
12421 (string
, frame
, parms
, timeout
, dx
, dy
)
12422 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
12426 Window root
, child
;
12427 Lisp_Object buffer
, top
, left
;
12428 struct buffer
*old_buffer
;
12429 struct text_pos pos
;
12430 int i
, width
, height
;
12431 int root_x
, root_y
, win_x
, win_y
;
12433 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
12434 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
12435 int count
= specpdl_ptr
- specpdl
;
12437 specbind (Qinhibit_redisplay
, Qt
);
12439 GCPRO4 (string
, parms
, frame
, timeout
);
12441 CHECK_STRING (string
, 0);
12442 f
= check_x_frame (frame
);
12443 if (NILP (timeout
))
12444 timeout
= make_number (5);
12446 CHECK_NATNUM (timeout
, 2);
12449 dx
= make_number (5);
12451 CHECK_NUMBER (dx
, 5);
12454 dy
= make_number (-5);
12456 CHECK_NUMBER (dy
, 6);
12458 /* Hide a previous tip, if any. */
12461 /* Add default values to frame parameters. */
12462 if (NILP (Fassq (Qname
, parms
)))
12463 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
12464 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12465 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
12466 if (NILP (Fassq (Qborder_width
, parms
)))
12467 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
12468 if (NILP (Fassq (Qborder_color
, parms
)))
12469 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
12470 if (NILP (Fassq (Qbackground_color
, parms
)))
12471 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
12474 /* Create a frame for the tooltip, and record it in the global
12475 variable tip_frame. */
12476 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
);
12477 tip_frame
= f
= XFRAME (frame
);
12479 /* Set up the frame's root window. Currently we use a size of 80
12480 columns x 40 lines. If someone wants to show a larger tip, he
12481 will loose. I don't think this is a realistic case. */
12482 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
12483 w
->left
= w
->top
= make_number (0);
12487 w
->pseudo_window_p
= 1;
12489 /* Display the tooltip text in a temporary buffer. */
12490 buffer
= Fget_buffer_create (build_string (" *tip*"));
12491 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
12492 old_buffer
= current_buffer
;
12493 set_buffer_internal_1 (XBUFFER (buffer
));
12495 Finsert (make_number (1), &string
);
12496 clear_glyph_matrix (w
->desired_matrix
);
12497 clear_glyph_matrix (w
->current_matrix
);
12498 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
12499 try_window (FRAME_ROOT_WINDOW (f
), pos
);
12501 /* Compute width and height of the tooltip. */
12502 width
= height
= 0;
12503 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
12505 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
12506 struct glyph
*last
;
12509 /* Stop at the first empty row at the end. */
12510 if (!row
->enabled_p
|| !row
->displays_text_p
)
12513 /* Let the row go over the full width of the frame. */
12514 row
->full_width_p
= 1;
12516 /* There's a glyph at the end of rows that is use to place
12517 the cursor there. Don't include the width of this glyph. */
12518 if (row
->used
[TEXT_AREA
])
12520 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
12521 row_width
= row
->pixel_width
- last
->pixel_width
;
12524 row_width
= row
->pixel_width
;
12526 height
+= row
->height
;
12527 width
= max (width
, row_width
);
12530 /* Add the frame's internal border to the width and height the X
12531 window should have. */
12532 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12533 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12535 /* User-specified position? */
12536 left
= Fcdr (Fassq (Qleft
, parms
));
12537 top
= Fcdr (Fassq (Qtop
, parms
));
12539 /* Move the tooltip window where the mouse pointer is. Resize and
12541 #if 0 /* TODO : W32 specifics */
12543 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
12544 &root
, &child
, &root_x
, &root_y
, &win_x
, &win_y
, &pmask
);
12547 root_x
+= XINT (dx
);
12548 root_y
+= XINT (dy
);
12550 if (INTEGERP (left
))
12551 root_x
= XINT (left
);
12552 if (INTEGERP (top
))
12553 root_y
= XINT (top
);
12556 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12557 root_x
, root_y
- height
, width
, height
);
12558 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12562 /* Draw into the window. */
12563 w
->must_be_updated_p
= 1;
12564 update_single_window (w
, 1);
12566 /* Restore original current buffer. */
12567 set_buffer_internal_1 (old_buffer
);
12568 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
12570 /* Let the tip disappear after timeout seconds. */
12571 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
12572 intern ("x-hide-tip"));
12575 return unbind_to (count
, Qnil
);
12579 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
12580 "Hide the current tooltip window, if there is any.\n\
12581 Value is t is tooltip was open, nil otherwise.")
12584 int count
= specpdl_ptr
- specpdl
;
12587 specbind (Qinhibit_redisplay
, Qt
);
12589 if (!NILP (tip_timer
))
12591 call1 (intern ("cancel-timer"), tip_timer
);
12599 XSETFRAME (frame
, tip_frame
);
12600 Fdelete_frame (frame
, Qt
);
12605 return unbind_to (count
, deleted_p
? Qt
: Qnil
);
12611 /***********************************************************************
12612 File selection dialog
12613 ***********************************************************************/
12615 extern Lisp_Object Qfile_name_history
;
12617 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
12618 "Read file name, prompting with PROMPT in directory DIR.\n\
12619 Use a file selection dialog.\n\
12620 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
12621 specified. Don't let the user enter a file name in the file\n\
12622 selection dialog's entry field, if MUSTMATCH is non-nil.")
12623 (prompt
, dir
, default_filename
, mustmatch
)
12624 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
12626 struct frame
*f
= SELECTED_FRAME ();
12627 Lisp_Object file
= Qnil
;
12628 int count
= specpdl_ptr
- specpdl
;
12629 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
12630 char filename
[MAX_PATH
+ 1];
12631 char init_dir
[MAX_PATH
+ 1];
12632 int use_dialog_p
= 1;
12634 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
12635 CHECK_STRING (prompt
, 0);
12636 CHECK_STRING (dir
, 1);
12638 /* Create the dialog with PROMPT as title, using DIR as initial
12639 directory and using "*" as pattern. */
12640 dir
= Fexpand_file_name (dir
, Qnil
);
12641 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
12642 init_dir
[MAX_PATH
] = '\0';
12643 unixtodos_filename (init_dir
);
12645 if (STRINGP (default_filename
))
12647 char *file_name_only
;
12648 char *full_path_name
= XSTRING (default_filename
)->data
;
12650 unixtodos_filename (full_path_name
);
12652 file_name_only
= strrchr (full_path_name
, '\\');
12653 if (!file_name_only
)
12654 file_name_only
= full_path_name
;
12659 /* If default_file_name is a directory, don't use the open
12660 file dialog, as it does not support selecting
12662 if (!(*file_name_only
))
12666 strncpy (filename
, file_name_only
, MAX_PATH
);
12667 filename
[MAX_PATH
] = '\0';
12670 filename
[0] = '\0';
12674 OPENFILENAME file_details
;
12675 char *filename_file
;
12677 /* Prevent redisplay. */
12678 specbind (Qinhibit_redisplay
, Qt
);
12681 bzero (&file_details
, sizeof (file_details
));
12682 file_details
.lStructSize
= sizeof (file_details
);
12683 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
12684 file_details
.lpstrFile
= filename
;
12685 file_details
.nMaxFile
= sizeof (filename
);
12686 file_details
.lpstrInitialDir
= init_dir
;
12687 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
12688 file_details
.Flags
= OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
;
12690 if (!NILP (mustmatch
))
12691 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
12693 if (GetOpenFileName (&file_details
))
12695 dostounix_filename (filename
);
12696 file
= build_string (filename
);
12702 file
= unbind_to (count
, file
);
12704 /* Open File dialog will not allow folders to be selected, so resort
12705 to minibuffer completing reads for directories. */
12707 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
12708 dir
, mustmatch
, dir
, Qfile_name_history
,
12709 default_filename
, Qnil
);
12713 /* Make "Cancel" equivalent to C-g. */
12715 Fsignal (Qquit
, Qnil
);
12717 return unbind_to (count
, file
);
12722 /***********************************************************************
12724 ***********************************************************************/
12728 DEFUN ("imagep", Fimagep
, Simagep
, 1, 1, 0,
12729 "Value is non-nil if SPEC is a valid image specification.")
12733 return valid_image_p (spec
) ? Qt
: Qnil
;
12737 DEFUN ("lookup-image", Flookup_image
, Slookup_image
, 1, 1, 0, "")
12743 if (valid_image_p (spec
))
12744 id
= lookup_image (SELECTED_FRAME (), spec
);
12746 debug_print (spec
);
12747 return make_number (id
);
12750 #endif /* GLYPH_DEBUG != 0 */
12754 /***********************************************************************
12755 w32 specialized functions
12756 ***********************************************************************/
12758 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 1, 0,
12759 "This will display the W32 font dialog and return an X font string corresponding to the selection.")
12763 FRAME_PTR f
= check_x_frame (frame
);
12771 bzero (&cf
, sizeof (cf
));
12772 bzero (&lf
, sizeof (lf
));
12774 cf
.lStructSize
= sizeof (cf
);
12775 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
12776 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
;
12777 cf
.lpLogFont
= &lf
;
12779 /* Initialize as much of the font details as we can from the current
12781 hdc
= GetDC (FRAME_W32_WINDOW (f
));
12782 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
12783 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
12784 if (GetTextMetrics (hdc
, &tm
))
12786 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
12787 lf
.lfWeight
= tm
.tmWeight
;
12788 lf
.lfItalic
= tm
.tmItalic
;
12789 lf
.lfUnderline
= tm
.tmUnderlined
;
12790 lf
.lfStrikeOut
= tm
.tmStruckOut
;
12791 lf
.lfCharSet
= tm
.tmCharSet
;
12792 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
12794 SelectObject (hdc
, oldobj
);
12795 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
12797 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
12800 return build_string (buf
);
12803 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
, Sw32_send_sys_command
, 1, 2, 0,
12804 "Send frame a Windows WM_SYSCOMMAND message of type COMMAND.\n\
12805 Some useful values for command are 0xf030 to maximise frame (0xf020\n\
12806 to minimize), 0xf120 to restore frame to original size, and 0xf100\n\
12807 to activate the menubar for keyboard access. 0xf140 activates the\n\
12808 screen saver if defined.\n\
12810 If optional parameter FRAME is not specified, use selected frame.")
12812 Lisp_Object command
, frame
;
12815 FRAME_PTR f
= check_x_frame (frame
);
12817 CHECK_NUMBER (command
, 0);
12819 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
12824 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
12825 "Get Windows to perform OPERATION on DOCUMENT.\n\
12826 This is a wrapper around the ShellExecute system function, which\n\
12827 invokes the application registered to handle OPERATION for DOCUMENT.\n\
12828 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be\n\
12829 nil for the default action), and DOCUMENT is typically the name of a\n\
12830 document file or URL, but can also be a program executable to run or\n\
12831 a directory to open in the Windows Explorer.\n\
12833 If DOCUMENT is a program executable, PARAMETERS can be a string\n\
12834 containing command line parameters, but otherwise should be nil.\n\
12836 SHOW-FLAG can be used to control whether the invoked application is hidden\n\
12837 or minimized. If SHOW-FLAG is nil, the application is displayed normally,\n\
12838 otherwise it is an integer representing a ShowWindow flag:\n\
12840 0 - start hidden\n\
12841 1 - start normally\n\
12842 3 - start maximized\n\
12843 6 - start minimized")
12844 (operation
, document
, parameters
, show_flag
)
12845 Lisp_Object operation
, document
, parameters
, show_flag
;
12847 Lisp_Object current_dir
;
12849 CHECK_STRING (document
, 0);
12851 /* Encode filename and current directory. */
12852 current_dir
= ENCODE_FILE (current_buffer
->directory
);
12853 document
= ENCODE_FILE (document
);
12854 if ((int) ShellExecute (NULL
,
12855 (STRINGP (operation
) ?
12856 XSTRING (operation
)->data
: NULL
),
12857 XSTRING (document
)->data
,
12858 (STRINGP (parameters
) ?
12859 XSTRING (parameters
)->data
: NULL
),
12860 XSTRING (current_dir
)->data
,
12861 (INTEGERP (show_flag
) ?
12862 XINT (show_flag
) : SW_SHOWDEFAULT
))
12865 error ("ShellExecute failed");
12868 /* Lookup virtual keycode from string representing the name of a
12869 non-ascii keystroke into the corresponding virtual key, using
12870 lispy_function_keys. */
12872 lookup_vk_code (char *key
)
12876 for (i
= 0; i
< 256; i
++)
12877 if (lispy_function_keys
[i
] != 0
12878 && strcmp (lispy_function_keys
[i
], key
) == 0)
12884 /* Convert a one-element vector style key sequence to a hot key
12887 w32_parse_hot_key (key
)
12890 /* Copied from Fdefine_key and store_in_keymap. */
12891 register Lisp_Object c
;
12893 int lisp_modifiers
;
12895 struct gcpro gcpro1
;
12897 CHECK_VECTOR (key
, 0);
12899 if (XFASTINT (Flength (key
)) != 1)
12904 c
= Faref (key
, make_number (0));
12906 if (CONSP (c
) && lucid_event_type_list_p (c
))
12907 c
= Fevent_convert_list (c
);
12911 if (! INTEGERP (c
) && ! SYMBOLP (c
))
12912 error ("Key definition is invalid");
12914 /* Work out the base key and the modifiers. */
12917 c
= parse_modifiers (c
);
12918 lisp_modifiers
= Fcar (Fcdr (c
));
12922 vk_code
= lookup_vk_code (XSYMBOL (c
)->name
->data
);
12924 else if (INTEGERP (c
))
12926 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
12927 /* Many ascii characters are their own virtual key code. */
12928 vk_code
= XINT (c
) & CHARACTERBITS
;
12931 if (vk_code
< 0 || vk_code
> 255)
12934 if ((lisp_modifiers
& meta_modifier
) != 0
12935 && !NILP (Vw32_alt_is_meta
))
12936 lisp_modifiers
|= alt_modifier
;
12938 /* Supply defs missing from mingw32. */
12940 #define MOD_ALT 0x0001
12941 #define MOD_CONTROL 0x0002
12942 #define MOD_SHIFT 0x0004
12943 #define MOD_WIN 0x0008
12946 /* Convert lisp modifiers to Windows hot-key form. */
12947 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
12948 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
12949 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
12950 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
12952 return HOTKEY (vk_code
, w32_modifiers
);
12955 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
, Sw32_register_hot_key
, 1, 1, 0,
12956 "Register KEY as a hot-key combination.\n\
12957 Certain key combinations like Alt-Tab are reserved for system use on\n\
12958 Windows, and therefore are normally intercepted by the system. However,\n\
12959 most of these key combinations can be received by registering them as\n\
12960 hot-keys, overriding their special meaning.\n\
12962 KEY must be a one element key definition in vector form that would be\n\
12963 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta\n\
12964 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper\n\
12965 is always interpreted as the Windows modifier keys.\n\
12967 The return value is the hotkey-id if registered, otherwise nil.")
12971 key
= w32_parse_hot_key (key
);
12973 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
12975 /* Reuse an empty slot if possible. */
12976 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
12978 /* Safe to add new key to list, even if we have focus. */
12980 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
12984 /* Notify input thread about new hot-key definition, so that it
12985 takes effect without needing to switch focus. */
12986 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
12993 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
, Sw32_unregister_hot_key
, 1, 1, 0,
12994 "Unregister HOTKEY as a hot-key combination.")
13000 if (!INTEGERP (key
))
13001 key
= w32_parse_hot_key (key
);
13003 item
= Fmemq (key
, w32_grabbed_keys
);
13007 /* Notify input thread about hot-key definition being removed, so
13008 that it takes effect without needing focus switch. */
13009 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
13010 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
13013 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13020 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
, Sw32_registered_hot_keys
, 0, 0, 0,
13021 "Return list of registered hot-key IDs.")
13024 return Fcopy_sequence (w32_grabbed_keys
);
13027 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
, Sw32_reconstruct_hot_key
, 1, 1, 0,
13028 "Convert hot-key ID to a lisp key combination.")
13030 Lisp_Object hotkeyid
;
13032 int vk_code
, w32_modifiers
;
13035 CHECK_NUMBER (hotkeyid
, 0);
13037 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
13038 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
13040 if (lispy_function_keys
[vk_code
])
13041 key
= intern (lispy_function_keys
[vk_code
]);
13043 key
= make_number (vk_code
);
13045 key
= Fcons (key
, Qnil
);
13046 if (w32_modifiers
& MOD_SHIFT
)
13047 key
= Fcons (Qshift
, key
);
13048 if (w32_modifiers
& MOD_CONTROL
)
13049 key
= Fcons (Qctrl
, key
);
13050 if (w32_modifiers
& MOD_ALT
)
13051 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
13052 if (w32_modifiers
& MOD_WIN
)
13053 key
= Fcons (Qhyper
, key
);
13058 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
, Sw32_toggle_lock_key
, 1, 2, 0,
13059 "Toggle the state of the lock key KEY.\n\
13060 KEY can be `capslock', `kp-numlock', or `scroll'.\n\
13061 If the optional parameter NEW-STATE is a number, then the state of KEY\n\
13062 is set to off if the low bit of NEW-STATE is zero, otherwise on.")
13064 Lisp_Object key
, new_state
;
13069 if (EQ (key
, intern ("capslock")))
13070 vk_code
= VK_CAPITAL
;
13071 else if (EQ (key
, intern ("kp-numlock")))
13072 vk_code
= VK_NUMLOCK
;
13073 else if (EQ (key
, intern ("scroll")))
13074 vk_code
= VK_SCROLL
;
13078 if (!dwWindowsThreadId
)
13079 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
13081 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
13082 (WPARAM
) vk_code
, (LPARAM
) new_state
))
13085 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13086 return make_number (msg
.wParam
);
13093 /* This is zero if not using MS-Windows. */
13096 /* The section below is built by the lisp expression at the top of the file,
13097 just above where these variables are declared. */
13098 /*&&& init symbols here &&&*/
13099 Qauto_raise
= intern ("auto-raise");
13100 staticpro (&Qauto_raise
);
13101 Qauto_lower
= intern ("auto-lower");
13102 staticpro (&Qauto_lower
);
13103 Qbar
= intern ("bar");
13105 Qborder_color
= intern ("border-color");
13106 staticpro (&Qborder_color
);
13107 Qborder_width
= intern ("border-width");
13108 staticpro (&Qborder_width
);
13109 Qbox
= intern ("box");
13111 Qcursor_color
= intern ("cursor-color");
13112 staticpro (&Qcursor_color
);
13113 Qcursor_type
= intern ("cursor-type");
13114 staticpro (&Qcursor_type
);
13115 Qgeometry
= intern ("geometry");
13116 staticpro (&Qgeometry
);
13117 Qicon_left
= intern ("icon-left");
13118 staticpro (&Qicon_left
);
13119 Qicon_top
= intern ("icon-top");
13120 staticpro (&Qicon_top
);
13121 Qicon_type
= intern ("icon-type");
13122 staticpro (&Qicon_type
);
13123 Qicon_name
= intern ("icon-name");
13124 staticpro (&Qicon_name
);
13125 Qinternal_border_width
= intern ("internal-border-width");
13126 staticpro (&Qinternal_border_width
);
13127 Qleft
= intern ("left");
13128 staticpro (&Qleft
);
13129 Qright
= intern ("right");
13130 staticpro (&Qright
);
13131 Qmouse_color
= intern ("mouse-color");
13132 staticpro (&Qmouse_color
);
13133 Qnone
= intern ("none");
13134 staticpro (&Qnone
);
13135 Qparent_id
= intern ("parent-id");
13136 staticpro (&Qparent_id
);
13137 Qscroll_bar_width
= intern ("scroll-bar-width");
13138 staticpro (&Qscroll_bar_width
);
13139 Qsuppress_icon
= intern ("suppress-icon");
13140 staticpro (&Qsuppress_icon
);
13141 Qundefined_color
= intern ("undefined-color");
13142 staticpro (&Qundefined_color
);
13143 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
13144 staticpro (&Qvertical_scroll_bars
);
13145 Qvisibility
= intern ("visibility");
13146 staticpro (&Qvisibility
);
13147 Qwindow_id
= intern ("window-id");
13148 staticpro (&Qwindow_id
);
13149 Qx_frame_parameter
= intern ("x-frame-parameter");
13150 staticpro (&Qx_frame_parameter
);
13151 Qx_resource_name
= intern ("x-resource-name");
13152 staticpro (&Qx_resource_name
);
13153 Quser_position
= intern ("user-position");
13154 staticpro (&Quser_position
);
13155 Quser_size
= intern ("user-size");
13156 staticpro (&Quser_size
);
13157 Qscreen_gamma
= intern ("screen-gamma");
13158 staticpro (&Qscreen_gamma
);
13159 Qline_spacing
= intern ("line-spacing");
13160 staticpro (&Qline_spacing
);
13161 Qcenter
= intern ("center");
13162 staticpro (&Qcenter
);
13163 /* This is the end of symbol initialization. */
13165 Qhyper
= intern ("hyper");
13166 staticpro (&Qhyper
);
13167 Qsuper
= intern ("super");
13168 staticpro (&Qsuper
);
13169 Qmeta
= intern ("meta");
13170 staticpro (&Qmeta
);
13171 Qalt
= intern ("alt");
13173 Qctrl
= intern ("ctrl");
13174 staticpro (&Qctrl
);
13175 Qcontrol
= intern ("control");
13176 staticpro (&Qcontrol
);
13177 Qshift
= intern ("shift");
13178 staticpro (&Qshift
);
13180 /* Text property `display' should be nonsticky by default. */
13181 Vtext_property_default_nonsticky
13182 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
13185 Qlaplace
= intern ("laplace");
13186 staticpro (&Qlaplace
);
13188 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
13189 staticpro (&Qface_set_after_frame_default
);
13191 Fput (Qundefined_color
, Qerror_conditions
,
13192 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
13193 Fput (Qundefined_color
, Qerror_message
,
13194 build_string ("Undefined color"));
13196 staticpro (&w32_grabbed_keys
);
13197 w32_grabbed_keys
= Qnil
;
13199 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
13200 "An array of color name mappings for windows.");
13201 Vw32_color_map
= Qnil
;
13203 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
13204 "Non-nil if alt key presses are passed on to Windows.\n\
13205 When non-nil, for example, alt pressed and released and then space will\n\
13206 open the System menu. When nil, Emacs silently swallows alt key events.");
13207 Vw32_pass_alt_to_system
= Qnil
;
13209 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
13210 "Non-nil if the alt key is to be considered the same as the meta key.\n\
13211 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta.");
13212 Vw32_alt_is_meta
= Qt
;
13214 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
13215 "If non-zero, the virtual key code for an alternative quit key.");
13216 XSETINT (Vw32_quit_key
, 0);
13218 DEFVAR_LISP ("w32-pass-lwindow-to-system",
13219 &Vw32_pass_lwindow_to_system
,
13220 "Non-nil if the left \"Windows\" key is passed on to Windows.\n\
13221 When non-nil, the Start menu is opened by tapping the key.");
13222 Vw32_pass_lwindow_to_system
= Qt
;
13224 DEFVAR_LISP ("w32-pass-rwindow-to-system",
13225 &Vw32_pass_rwindow_to_system
,
13226 "Non-nil if the right \"Windows\" key is passed on to Windows.\n\
13227 When non-nil, the Start menu is opened by tapping the key.");
13228 Vw32_pass_rwindow_to_system
= Qt
;
13230 DEFVAR_INT ("w32-phantom-key-code",
13231 &Vw32_phantom_key_code
,
13232 "Virtual key code used to generate \"phantom\" key presses.\n\
13233 Value is a number between 0 and 255.\n\
13235 Phantom key presses are generated in order to stop the system from\n\
13236 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or\n\
13237 `w32-pass-rwindow-to-system' is nil.");
13238 /* Although 255 is technically not a valid key code, it works and
13239 means that this hack won't interfere with any real key code. */
13240 Vw32_phantom_key_code
= 255;
13242 DEFVAR_LISP ("w32-enable-num-lock",
13243 &Vw32_enable_num_lock
,
13244 "Non-nil if Num Lock should act normally.\n\
13245 Set to nil to see Num Lock as the key `kp-numlock'.");
13246 Vw32_enable_num_lock
= Qt
;
13248 DEFVAR_LISP ("w32-enable-caps-lock",
13249 &Vw32_enable_caps_lock
,
13250 "Non-nil if Caps Lock should act normally.\n\
13251 Set to nil to see Caps Lock as the key `capslock'.");
13252 Vw32_enable_caps_lock
= Qt
;
13254 DEFVAR_LISP ("w32-scroll-lock-modifier",
13255 &Vw32_scroll_lock_modifier
,
13256 "Modifier to use for the Scroll Lock on state.\n\
13257 The value can be hyper, super, meta, alt, control or shift for the\n\
13258 respective modifier, or nil to see Scroll Lock as the key `scroll'.\n\
13259 Any other value will cause the key to be ignored.");
13260 Vw32_scroll_lock_modifier
= Qt
;
13262 DEFVAR_LISP ("w32-lwindow-modifier",
13263 &Vw32_lwindow_modifier
,
13264 "Modifier to use for the left \"Windows\" key.\n\
13265 The value can be hyper, super, meta, alt, control or shift for the\n\
13266 respective modifier, or nil to appear as the key `lwindow'.\n\
13267 Any other value will cause the key to be ignored.");
13268 Vw32_lwindow_modifier
= Qnil
;
13270 DEFVAR_LISP ("w32-rwindow-modifier",
13271 &Vw32_rwindow_modifier
,
13272 "Modifier to use for the right \"Windows\" key.\n\
13273 The value can be hyper, super, meta, alt, control or shift for the\n\
13274 respective modifier, or nil to appear as the key `rwindow'.\n\
13275 Any other value will cause the key to be ignored.");
13276 Vw32_rwindow_modifier
= Qnil
;
13278 DEFVAR_LISP ("w32-apps-modifier",
13279 &Vw32_apps_modifier
,
13280 "Modifier to use for the \"Apps\" key.\n\
13281 The value can be hyper, super, meta, alt, control or shift for the\n\
13282 respective modifier, or nil to appear as the key `apps'.\n\
13283 Any other value will cause the key to be ignored.");
13284 Vw32_apps_modifier
= Qnil
;
13286 DEFVAR_LISP ("w32-enable-synthesized-fonts", &Vw32_enable_synthesized_fonts
,
13287 "Non-nil enables selection of artificially italicized and bold fonts.");
13288 Vw32_enable_synthesized_fonts
= Qnil
;
13290 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
13291 "Non-nil enables Windows palette management to map colors exactly.");
13292 Vw32_enable_palette
= Qt
;
13294 DEFVAR_INT ("w32-mouse-button-tolerance",
13295 &Vw32_mouse_button_tolerance
,
13296 "Analogue of double click interval for faking middle mouse events.\n\
13297 The value is the minimum time in milliseconds that must elapse between\n\
13298 left/right button down events before they are considered distinct events.\n\
13299 If both mouse buttons are depressed within this interval, a middle mouse\n\
13300 button down event is generated instead.");
13301 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
13303 DEFVAR_INT ("w32-mouse-move-interval",
13304 &Vw32_mouse_move_interval
,
13305 "Minimum interval between mouse move events.\n\
13306 The value is the minimum time in milliseconds that must elapse between\n\
13307 successive mouse move (or scroll bar drag) events before they are\n\
13308 reported as lisp events.");
13309 XSETINT (Vw32_mouse_move_interval
, 0);
13311 init_x_parm_symbols ();
13313 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
13314 "List of directories to search for bitmap files for w32.");
13315 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
13317 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
13318 "The shape of the pointer when over text.\n\
13319 Changing the value does not affect existing frames\n\
13320 unless you set the mouse color.");
13321 Vx_pointer_shape
= Qnil
;
13323 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
13324 "The name Emacs uses to look up resources; for internal use only.\n\
13325 `x-get-resource' uses this as the first component of the instance name\n\
13326 when requesting resource values.\n\
13327 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
13328 was invoked, or to the value specified with the `-name' or `-rn'\n\
13329 switches, if present.");
13330 Vx_resource_name
= Qnil
;
13332 Vx_nontext_pointer_shape
= Qnil
;
13334 Vx_mode_pointer_shape
= Qnil
;
13336 DEFVAR_LISP ("x-busy-pointer-shape", &Vx_busy_pointer_shape
,
13337 "The shape of the pointer when Emacs is busy.\n\
13338 This variable takes effect when you create a new frame\n\
13339 or when you set the mouse color.");
13340 Vx_busy_pointer_shape
= Qnil
;
13342 DEFVAR_BOOL ("display-busy-cursor", &display_busy_cursor_p
,
13343 "Non-zero means Emacs displays a busy cursor on window systems.");
13344 display_busy_cursor_p
= 1;
13346 DEFVAR_LISP ("busy-cursor-delay", &Vbusy_cursor_delay
,
13347 "*Seconds to wait before displaying a busy-cursor.\n\
13348 Value must be an integer or float.");
13349 Vbusy_cursor_delay
= make_number (DEFAULT_BUSY_CURSOR_DELAY
);
13351 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
13352 &Vx_sensitive_text_pointer_shape
,
13353 "The shape of the pointer when over mouse-sensitive text.\n\
13354 This variable takes effect when you create a new frame\n\
13355 or when you set the mouse color.");
13356 Vx_sensitive_text_pointer_shape
= Qnil
;
13358 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
13359 "A string indicating the foreground color of the cursor box.");
13360 Vx_cursor_fore_pixel
= Qnil
;
13362 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
13363 "Non-nil if no window manager is in use.\n\
13364 Emacs doesn't try to figure this out; this is always nil\n\
13365 unless you set it to something else.");
13366 /* We don't have any way to find this out, so set it to nil
13367 and maybe the user would like to set it to t. */
13368 Vx_no_window_manager
= Qnil
;
13370 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
13371 &Vx_pixel_size_width_font_regexp
,
13372 "Regexp matching a font name whose width is the same as `PIXEL_SIZE'.\n\
13374 Since Emacs gets width of a font matching with this regexp from\n\
13375 PIXEL_SIZE field of the name, font finding mechanism gets faster for\n\
13376 such a font. This is especially effective for such large fonts as\n\
13377 Chinese, Japanese, and Korean.");
13378 Vx_pixel_size_width_font_regexp
= Qnil
;
13380 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
13381 "Time after which cached images are removed from the cache.\n\
13382 When an image has not been displayed this many seconds, remove it\n\
13383 from the image cache. Value must be an integer or nil with nil\n\
13384 meaning don't clear the cache.");
13385 Vimage_cache_eviction_delay
= make_number (30 * 60);
13387 DEFVAR_LISP ("w32-bdf-filename-alist",
13388 &Vw32_bdf_filename_alist
,
13389 "List of bdf fonts and their corresponding filenames.");
13390 Vw32_bdf_filename_alist
= Qnil
;
13392 DEFVAR_BOOL ("w32-strict-fontnames",
13393 &w32_strict_fontnames
,
13394 "Non-nil means only use fonts that are exact matches for those requested.\n\
13395 Default is nil, which allows old fontnames that are not XLFD compliant,\n\
13396 and allows third-party CJK display to work by specifying false charset\n\
13397 fields to trick Emacs into translating to Big5, SJIS etc.\n\
13398 Setting this to t will prevent wrong fonts being selected when\n\
13399 fontsets are automatically created.");
13400 w32_strict_fontnames
= 0;
13402 DEFVAR_BOOL ("w32-strict-painting",
13403 &w32_strict_painting
,
13404 "Non-nil means use strict rules for repainting frames.\n\
13405 Set this to nil to get the old behaviour for repainting; this should\n\
13406 only be necessary if the default setting causes problems.");
13407 w32_strict_painting
= 1;
13409 DEFVAR_LISP ("w32-system-coding-system",
13410 &Vw32_system_coding_system
,
13411 "Coding system used by Windows system functions, such as for font names.");
13412 Vw32_system_coding_system
= Qnil
;
13414 DEFVAR_LISP ("w32-charset-info-alist",
13415 &Vw32_charset_info_alist
,
13416 "Alist linking Emacs character sets to Windows fonts\n\
13417 and codepages. Each entry should be of the form:\n\
13419 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))\n\
13421 where CHARSET_NAME is a string used in font names to identify the charset,\n\
13422 WINDOWS_CHARSET is a symbol that can be one of:\n\
13423 w32-charset-ansi, w32-charset-default, w32-charset-symbol,\n\
13424 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,\n\
13425 w32-charset-chinesebig5, "
13426 #ifdef JOHAB_CHARSET
13427 "w32-charset-johab, w32-charset-hebrew,\n\
13428 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,\n\
13429 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,\n\
13430 w32-charset-russian, w32-charset-mac, w32-charset-baltic,\n"
13432 #ifdef UNICODE_CHARSET
13433 "w32-charset-unicode, "
13435 "or w32-charset-oem.\n\
13436 CODEPAGE should be an integer specifying the codepage that should be used\n\
13437 to display the character set, t to do no translation and output as Unicode,\n\
13438 or nil to do no translation and output as 8 bit (or multibyte on far-east\n\
13439 versions of Windows) characters.");
13440 Vw32_charset_info_alist
= Qnil
;
13442 staticpro (&Qw32_charset_ansi
);
13443 Qw32_charset_ansi
= intern ("w32-charset-ansi");
13444 staticpro (&Qw32_charset_symbol
);
13445 Qw32_charset_symbol
= intern ("w32-charset-symbol");
13446 staticpro (&Qw32_charset_shiftjis
);
13447 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
13448 staticpro (&Qw32_charset_hangeul
);
13449 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
13450 staticpro (&Qw32_charset_chinesebig5
);
13451 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
13452 staticpro (&Qw32_charset_gb2312
);
13453 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
13454 staticpro (&Qw32_charset_oem
);
13455 Qw32_charset_oem
= intern ("w32-charset-oem");
13457 #ifdef JOHAB_CHARSET
13459 static int w32_extra_charsets_defined
= 1;
13460 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
, "");
13462 staticpro (&Qw32_charset_johab
);
13463 Qw32_charset_johab
= intern ("w32-charset-johab");
13464 staticpro (&Qw32_charset_easteurope
);
13465 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
13466 staticpro (&Qw32_charset_turkish
);
13467 Qw32_charset_turkish
= intern ("w32-charset-turkish");
13468 staticpro (&Qw32_charset_baltic
);
13469 Qw32_charset_baltic
= intern ("w32-charset-baltic");
13470 staticpro (&Qw32_charset_russian
);
13471 Qw32_charset_russian
= intern ("w32-charset-russian");
13472 staticpro (&Qw32_charset_arabic
);
13473 Qw32_charset_arabic
= intern ("w32-charset-arabic");
13474 staticpro (&Qw32_charset_greek
);
13475 Qw32_charset_greek
= intern ("w32-charset-greek");
13476 staticpro (&Qw32_charset_hebrew
);
13477 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
13478 staticpro (&Qw32_charset_vietnamese
);
13479 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
13480 staticpro (&Qw32_charset_thai
);
13481 Qw32_charset_thai
= intern ("w32-charset-thai");
13482 staticpro (&Qw32_charset_mac
);
13483 Qw32_charset_mac
= intern ("w32-charset-mac");
13487 #ifdef UNICODE_CHARSET
13489 static int w32_unicode_charset_defined
= 1;
13490 DEFVAR_BOOL ("w32-unicode-charset-defined",
13491 &w32_unicode_charset_defined
, "");
13493 staticpro (&Qw32_charset_unicode
);
13494 Qw32_charset_unicode
= intern ("w32-charset-unicode");
13497 defsubr (&Sx_get_resource
);
13498 #if 0 /* TODO: Port to W32 */
13499 defsubr (&Sx_change_window_property
);
13500 defsubr (&Sx_delete_window_property
);
13501 defsubr (&Sx_window_property
);
13503 defsubr (&Sxw_display_color_p
);
13504 defsubr (&Sx_display_grayscale_p
);
13505 defsubr (&Sxw_color_defined_p
);
13506 defsubr (&Sxw_color_values
);
13507 defsubr (&Sx_server_max_request_size
);
13508 defsubr (&Sx_server_vendor
);
13509 defsubr (&Sx_server_version
);
13510 defsubr (&Sx_display_pixel_width
);
13511 defsubr (&Sx_display_pixel_height
);
13512 defsubr (&Sx_display_mm_width
);
13513 defsubr (&Sx_display_mm_height
);
13514 defsubr (&Sx_display_screens
);
13515 defsubr (&Sx_display_planes
);
13516 defsubr (&Sx_display_color_cells
);
13517 defsubr (&Sx_display_visual_class
);
13518 defsubr (&Sx_display_backing_store
);
13519 defsubr (&Sx_display_save_under
);
13520 defsubr (&Sx_parse_geometry
);
13521 defsubr (&Sx_create_frame
);
13522 defsubr (&Sx_open_connection
);
13523 defsubr (&Sx_close_connection
);
13524 defsubr (&Sx_display_list
);
13525 defsubr (&Sx_synchronize
);
13527 /* W32 specific functions */
13529 defsubr (&Sw32_focus_frame
);
13530 defsubr (&Sw32_select_font
);
13531 defsubr (&Sw32_define_rgb_color
);
13532 defsubr (&Sw32_default_color_map
);
13533 defsubr (&Sw32_load_color_file
);
13534 defsubr (&Sw32_send_sys_command
);
13535 defsubr (&Sw32_shell_execute
);
13536 defsubr (&Sw32_register_hot_key
);
13537 defsubr (&Sw32_unregister_hot_key
);
13538 defsubr (&Sw32_registered_hot_keys
);
13539 defsubr (&Sw32_reconstruct_hot_key
);
13540 defsubr (&Sw32_toggle_lock_key
);
13541 defsubr (&Sw32_find_bdf_fonts
);
13543 /* Setting callback functions for fontset handler. */
13544 get_font_info_func
= w32_get_font_info
;
13546 #if 0 /* This function pointer doesn't seem to be used anywhere.
13547 And the pointer assigned has the wrong type, anyway. */
13548 list_fonts_func
= w32_list_fonts
;
13551 load_font_func
= w32_load_font
;
13552 find_ccl_program_func
= w32_find_ccl_program
;
13553 query_font_func
= w32_query_font
;
13554 set_frame_fontset_func
= x_set_font
;
13555 check_window_system_func
= check_w32
;
13557 #if 0 /* TODO Image support for W32 */
13559 Qxbm
= intern ("xbm");
13561 QCtype
= intern (":type");
13562 staticpro (&QCtype
);
13563 QCalgorithm
= intern (":algorithm");
13564 staticpro (&QCalgorithm
);
13565 QCheuristic_mask
= intern (":heuristic-mask");
13566 staticpro (&QCheuristic_mask
);
13567 QCcolor_symbols
= intern (":color-symbols");
13568 staticpro (&QCcolor_symbols
);
13569 QCascent
= intern (":ascent");
13570 staticpro (&QCascent
);
13571 QCmargin
= intern (":margin");
13572 staticpro (&QCmargin
);
13573 QCrelief
= intern (":relief");
13574 staticpro (&QCrelief
);
13575 Qpostscript
= intern ("postscript");
13576 staticpro (&Qpostscript
);
13577 QCloader
= intern (":loader");
13578 staticpro (&QCloader
);
13579 QCbounding_box
= intern (":bounding-box");
13580 staticpro (&QCbounding_box
);
13581 QCpt_width
= intern (":pt-width");
13582 staticpro (&QCpt_width
);
13583 QCpt_height
= intern (":pt-height");
13584 staticpro (&QCpt_height
);
13585 QCindex
= intern (":index");
13586 staticpro (&QCindex
);
13587 Qpbm
= intern ("pbm");
13591 Qxpm
= intern ("xpm");
13596 Qjpeg
= intern ("jpeg");
13597 staticpro (&Qjpeg
);
13601 Qtiff
= intern ("tiff");
13602 staticpro (&Qtiff
);
13606 Qgif
= intern ("gif");
13611 Qpng
= intern ("png");
13615 defsubr (&Sclear_image_cache
);
13618 defsubr (&Simagep
);
13619 defsubr (&Slookup_image
);
13623 busy_cursor_atimer
= NULL
;
13624 busy_cursor_shown_p
= 0;
13625 #ifdef TODO /* Tooltip support not complete. */
13626 defsubr (&Sx_show_tip
);
13627 defsubr (&Sx_hide_tip
);
13629 staticpro (&tip_timer
);
13632 defsubr (&Sx_file_dialog
);
13639 image_types
= NULL
;
13640 Vimage_types
= Qnil
;
13642 #if 0 /* TODO : Image support for W32 */
13643 define_image_type (&xbm_type
);
13644 define_image_type (&gs_type
);
13645 define_image_type (&pbm_type
);
13648 define_image_type (&xpm_type
);
13652 define_image_type (&jpeg_type
);
13656 define_image_type (&tiff_type
);
13660 define_image_type (&gif_type
);
13664 define_image_type (&png_type
);
13675 button
= MessageBox (NULL
,
13676 "A fatal error has occurred!\n\n"
13677 "Select Abort to exit, Retry to debug, Ignore to continue",
13678 "Emacs Abort Dialog",
13679 MB_ICONEXCLAMATION
| MB_TASKMODAL
13680 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
13695 /* For convenience when debugging. */
13699 return GetLastError ();