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
, Vx_window_horizontal_drag_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
;
337 int image_cache_refcount
, dpyinfo_refcount
;
341 /* From w32term.c. */
342 extern Lisp_Object Vw32_num_mouse_buttons
;
343 extern Lisp_Object Vw32_recognize_altgr
;
346 /* Error if we are not connected to MS-Windows. */
351 error ("MS-Windows not in use or not initialized");
354 /* Nonzero if we can use mouse menus.
355 You should not call this unless HAVE_MENUS is defined. */
363 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
364 and checking validity for W32. */
367 check_x_frame (frame
)
373 frame
= selected_frame
;
374 CHECK_LIVE_FRAME (frame
, 0);
376 if (! FRAME_W32_P (f
))
377 error ("non-w32 frame used");
381 /* Let the user specify an display with a frame.
382 nil stands for the selected frame--or, if that is not a w32 frame,
383 the first display on the list. */
385 static struct w32_display_info
*
386 check_x_display_info (frame
)
391 struct frame
*sf
= XFRAME (selected_frame
);
393 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
394 return FRAME_W32_DISPLAY_INFO (sf
);
396 return &one_w32_display_info
;
398 else if (STRINGP (frame
))
399 return x_display_info_for_name (frame
);
404 CHECK_LIVE_FRAME (frame
, 0);
406 if (! FRAME_W32_P (f
))
407 error ("non-w32 frame used");
408 return FRAME_W32_DISPLAY_INFO (f
);
412 /* Return the Emacs frame-object corresponding to an w32 window.
413 It could be the frame's main window or an icon window. */
415 /* This function can be called during GC, so use GC_xxx type test macros. */
418 x_window_to_frame (dpyinfo
, wdesc
)
419 struct w32_display_info
*dpyinfo
;
422 Lisp_Object tail
, frame
;
425 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
428 if (!GC_FRAMEP (frame
))
431 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
433 if (f
->output_data
.w32
->busy_window
== wdesc
)
436 /* TODO: Check tooltips when supported. */
437 if (FRAME_W32_WINDOW (f
) == wdesc
)
445 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
446 id, which is just an int that this section returns. Bitmaps are
447 reference counted so they can be shared among frames.
449 Bitmap indices are guaranteed to be > 0, so a negative number can
450 be used to indicate no bitmap.
452 If you use x_create_bitmap_from_data, then you must keep track of
453 the bitmaps yourself. That is, creating a bitmap from the same
454 data more than once will not be caught. */
457 /* Functions to access the contents of a bitmap, given an id. */
460 x_bitmap_height (f
, id
)
464 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
468 x_bitmap_width (f
, id
)
472 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
476 x_bitmap_pixmap (f
, id
)
480 return (int) FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
484 /* Allocate a new bitmap record. Returns index of new record. */
487 x_allocate_bitmap_record (f
)
490 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
493 if (dpyinfo
->bitmaps
== NULL
)
495 dpyinfo
->bitmaps_size
= 10;
497 = (struct w32_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
498 dpyinfo
->bitmaps_last
= 1;
502 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
503 return ++dpyinfo
->bitmaps_last
;
505 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
506 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
509 dpyinfo
->bitmaps_size
*= 2;
511 = (struct w32_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
512 dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
513 return ++dpyinfo
->bitmaps_last
;
516 /* Add one reference to the reference count of the bitmap with id ID. */
519 x_reference_bitmap (f
, id
)
523 ++FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
526 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
529 x_create_bitmap_from_data (f
, bits
, width
, height
)
532 unsigned int width
, height
;
534 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
538 bitmap
= CreateBitmap (width
, height
,
539 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_planes
,
540 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_cbits
,
546 id
= x_allocate_bitmap_record (f
);
547 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
548 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
549 dpyinfo
->bitmaps
[id
- 1].hinst
= NULL
;
550 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
551 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
552 dpyinfo
->bitmaps
[id
- 1].height
= height
;
553 dpyinfo
->bitmaps
[id
- 1].width
= width
;
558 /* Create bitmap from file FILE for frame F. */
561 x_create_bitmap_from_file (f
, file
)
566 #if 0 /* TODO : bitmap support */
567 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
568 unsigned int width
, height
;
570 int xhot
, yhot
, result
, id
;
576 /* Look for an existing bitmap with the same name. */
577 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
579 if (dpyinfo
->bitmaps
[id
].refcount
580 && dpyinfo
->bitmaps
[id
].file
581 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) XSTRING (file
)->data
))
583 ++dpyinfo
->bitmaps
[id
].refcount
;
588 /* Search bitmap-file-path for the file, if appropriate. */
589 fd
= openp (Vx_bitmap_file_path
, file
, "", &found
, 0);
594 filename
= (char *) XSTRING (found
)->data
;
596 hinst
= LoadLibraryEx (filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
602 result
= XReadBitmapFile (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
603 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
604 if (result
!= BitmapSuccess
)
607 id
= x_allocate_bitmap_record (f
);
608 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
609 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
610 dpyinfo
->bitmaps
[id
- 1].file
= (char *) xmalloc (XSTRING (file
)->size
+ 1);
611 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
612 dpyinfo
->bitmaps
[id
- 1].height
= height
;
613 dpyinfo
->bitmaps
[id
- 1].width
= width
;
614 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, XSTRING (file
)->data
);
620 /* Remove reference to bitmap with id number ID. */
623 x_destroy_bitmap (f
, id
)
627 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
631 --dpyinfo
->bitmaps
[id
- 1].refcount
;
632 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
635 DeleteObject (dpyinfo
->bitmaps
[id
- 1].pixmap
);
636 if (dpyinfo
->bitmaps
[id
- 1].file
)
638 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
639 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
646 /* Free all the bitmaps for the display specified by DPYINFO. */
649 x_destroy_all_bitmaps (dpyinfo
)
650 struct w32_display_info
*dpyinfo
;
653 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
654 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
656 DeleteObject (dpyinfo
->bitmaps
[i
].pixmap
);
657 if (dpyinfo
->bitmaps
[i
].file
)
658 xfree (dpyinfo
->bitmaps
[i
].file
);
660 dpyinfo
->bitmaps_last
= 0;
663 /* Connect the frame-parameter names for W32 frames
664 to the ways of passing the parameter values to the window system.
666 The name of a parameter, as a Lisp symbol,
667 has an `x-frame-parameter' property which is an integer in Lisp
668 but can be interpreted as an `enum x_frame_parm' in C. */
672 X_PARM_FOREGROUND_COLOR
,
673 X_PARM_BACKGROUND_COLOR
,
680 X_PARM_INTERNAL_BORDER_WIDTH
,
684 X_PARM_VERT_SCROLL_BAR
,
686 X_PARM_MENU_BAR_LINES
690 struct x_frame_parm_table
693 void (*setter
) P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
696 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
697 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
698 static void x_change_window_heights
P_ ((Lisp_Object
, int));
699 /* TODO: Native Input Method support; see x_create_im. */
700 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
701 static void x_set_line_spacing
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
702 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
703 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
704 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
705 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
706 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
707 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
708 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
709 void x_set_font
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
710 void x_set_border_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
711 void x_set_internal_border_width
P_ ((struct frame
*, Lisp_Object
,
713 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
714 void x_set_autoraise
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
715 void x_set_autolower
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
716 void x_set_vertical_scroll_bars
P_ ((struct frame
*, Lisp_Object
,
718 void x_set_visibility
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
719 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
720 void x_set_scroll_bar_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
721 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
722 void x_set_unsplittable
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
723 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
724 static void x_set_screen_gamma
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
726 static struct x_frame_parm_table x_frame_parms
[] =
728 "auto-raise", x_set_autoraise
,
729 "auto-lower", x_set_autolower
,
730 "background-color", x_set_background_color
,
731 "border-color", x_set_border_color
,
732 "border-width", x_set_border_width
,
733 "cursor-color", x_set_cursor_color
,
734 "cursor-type", x_set_cursor_type
,
736 "foreground-color", x_set_foreground_color
,
737 "icon-name", x_set_icon_name
,
738 "icon-type", x_set_icon_type
,
739 "internal-border-width", x_set_internal_border_width
,
740 "menu-bar-lines", x_set_menu_bar_lines
,
741 "mouse-color", x_set_mouse_color
,
742 "name", x_explicitly_set_name
,
743 "scroll-bar-width", x_set_scroll_bar_width
,
744 "title", x_set_title
,
745 "unsplittable", x_set_unsplittable
,
746 "vertical-scroll-bars", x_set_vertical_scroll_bars
,
747 "visibility", x_set_visibility
,
748 "tool-bar-lines", x_set_tool_bar_lines
,
749 "screen-gamma", x_set_screen_gamma
,
750 "line-spacing", x_set_line_spacing
753 /* Attach the `x-frame-parameter' properties to
754 the Lisp symbol names of parameters relevant to W32. */
757 init_x_parm_symbols ()
761 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
762 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
766 /* Change the parameters of frame F as specified by ALIST.
767 If a parameter is not specially recognized, do nothing;
768 otherwise call the `x_set_...' function for that parameter. */
771 x_set_frame_parameters (f
, alist
)
777 /* If both of these parameters are present, it's more efficient to
778 set them both at once. So we wait until we've looked at the
779 entire list before we set them. */
783 Lisp_Object left
, top
;
785 /* Same with these. */
786 Lisp_Object icon_left
, icon_top
;
788 /* Record in these vectors all the parms specified. */
792 int left_no_change
= 0, top_no_change
= 0;
793 int icon_left_no_change
= 0, icon_top_no_change
= 0;
795 struct gcpro gcpro1
, gcpro2
;
798 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
801 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
802 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
804 /* Extract parm names and values into those vectors. */
807 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
812 parms
[i
] = Fcar (elt
);
813 values
[i
] = Fcdr (elt
);
816 /* TAIL and ALIST are not used again below here. */
819 GCPRO2 (*parms
, *values
);
823 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
824 because their values appear in VALUES and strings are not valid. */
825 top
= left
= Qunbound
;
826 icon_left
= icon_top
= Qunbound
;
828 /* Provide default values for HEIGHT and WIDTH. */
829 if (FRAME_NEW_WIDTH (f
))
830 width
= FRAME_NEW_WIDTH (f
);
832 width
= FRAME_WIDTH (f
);
834 if (FRAME_NEW_HEIGHT (f
))
835 height
= FRAME_NEW_HEIGHT (f
);
837 height
= FRAME_HEIGHT (f
);
839 /* Process foreground_color and background_color before anything else.
840 They are independent of other properties, but other properties (e.g.,
841 cursor_color) are dependent upon them. */
842 for (p
= 0; p
< i
; p
++)
844 Lisp_Object prop
, val
;
848 if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
850 register Lisp_Object param_index
, old_value
;
852 param_index
= Fget (prop
, Qx_frame_parameter
);
853 old_value
= get_frame_param (f
, prop
);
854 store_frame_param (f
, prop
, val
);
855 if (NATNUMP (param_index
)
856 && (XFASTINT (param_index
)
857 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
858 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
862 /* Now process them in reverse of specified order. */
863 for (i
--; i
>= 0; i
--)
865 Lisp_Object prop
, val
;
870 if (EQ (prop
, Qwidth
) && NUMBERP (val
))
871 width
= XFASTINT (val
);
872 else if (EQ (prop
, Qheight
) && NUMBERP (val
))
873 height
= XFASTINT (val
);
874 else if (EQ (prop
, Qtop
))
876 else if (EQ (prop
, Qleft
))
878 else if (EQ (prop
, Qicon_top
))
880 else if (EQ (prop
, Qicon_left
))
882 else if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
883 /* Processed above. */
887 register Lisp_Object param_index
, old_value
;
889 param_index
= Fget (prop
, Qx_frame_parameter
);
890 old_value
= get_frame_param (f
, prop
);
891 store_frame_param (f
, prop
, val
);
892 if (NATNUMP (param_index
)
893 && (XFASTINT (param_index
)
894 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
895 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
899 /* Don't die if just one of these was set. */
900 if (EQ (left
, Qunbound
))
903 if (f
->output_data
.w32
->left_pos
< 0)
904 left
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->left_pos
), Qnil
));
906 XSETINT (left
, f
->output_data
.w32
->left_pos
);
908 if (EQ (top
, Qunbound
))
911 if (f
->output_data
.w32
->top_pos
< 0)
912 top
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->top_pos
), Qnil
));
914 XSETINT (top
, f
->output_data
.w32
->top_pos
);
917 /* If one of the icon positions was not set, preserve or default it. */
918 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
920 icon_left_no_change
= 1;
921 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
922 if (NILP (icon_left
))
923 XSETINT (icon_left
, 0);
925 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
927 icon_top_no_change
= 1;
928 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
930 XSETINT (icon_top
, 0);
933 /* Don't set these parameters unless they've been explicitly
934 specified. The window might be mapped or resized while we're in
935 this function, and we don't want to override that unless the lisp
936 code has asked for it.
938 Don't set these parameters unless they actually differ from the
939 window's current parameters; the window may not actually exist
944 check_frame_size (f
, &height
, &width
);
946 XSETFRAME (frame
, f
);
948 if (width
!= FRAME_WIDTH (f
)
949 || height
!= FRAME_HEIGHT (f
)
950 || FRAME_NEW_HEIGHT (f
) || FRAME_NEW_WIDTH (f
))
951 Fset_frame_size (frame
, make_number (width
), make_number (height
));
953 if ((!NILP (left
) || !NILP (top
))
954 && ! (left_no_change
&& top_no_change
)
955 && ! (NUMBERP (left
) && XINT (left
) == f
->output_data
.w32
->left_pos
956 && NUMBERP (top
) && XINT (top
) == f
->output_data
.w32
->top_pos
))
961 /* Record the signs. */
962 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
963 if (EQ (left
, Qminus
))
964 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
965 else if (INTEGERP (left
))
967 leftpos
= XINT (left
);
969 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
971 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
972 && CONSP (XCDR (left
))
973 && INTEGERP (XCAR (XCDR (left
))))
975 leftpos
= - XINT (XCAR (XCDR (left
)));
976 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
978 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
979 && CONSP (XCDR (left
))
980 && INTEGERP (XCAR (XCDR (left
))))
982 leftpos
= XINT (XCAR (XCDR (left
)));
985 if (EQ (top
, Qminus
))
986 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
987 else if (INTEGERP (top
))
991 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
993 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
994 && CONSP (XCDR (top
))
995 && INTEGERP (XCAR (XCDR (top
))))
997 toppos
= - XINT (XCAR (XCDR (top
)));
998 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
1000 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
1001 && CONSP (XCDR (top
))
1002 && INTEGERP (XCAR (XCDR (top
))))
1004 toppos
= XINT (XCAR (XCDR (top
)));
1008 /* Store the numeric value of the position. */
1009 f
->output_data
.w32
->top_pos
= toppos
;
1010 f
->output_data
.w32
->left_pos
= leftpos
;
1012 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
1014 /* Actually set that position, and convert to absolute. */
1015 x_set_offset (f
, leftpos
, toppos
, -1);
1018 if ((!NILP (icon_left
) || !NILP (icon_top
))
1019 && ! (icon_left_no_change
&& icon_top_no_change
))
1020 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
1026 /* Store the screen positions of frame F into XPTR and YPTR.
1027 These are the positions of the containing window manager window,
1028 not Emacs's own window. */
1031 x_real_positions (f
, xptr
, yptr
)
1040 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
1041 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
1047 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
1053 /* Insert a description of internally-recorded parameters of frame X
1054 into the parameter alist *ALISTPTR that is to be given to the user.
1055 Only parameters that are specific to W32
1056 and whose values are not correctly recorded in the frame's
1057 param_alist need to be considered here. */
1060 x_report_frame_params (f
, alistptr
)
1062 Lisp_Object
*alistptr
;
1067 /* Represent negative positions (off the top or left screen edge)
1068 in a way that Fmodify_frame_parameters will understand correctly. */
1069 XSETINT (tem
, f
->output_data
.w32
->left_pos
);
1070 if (f
->output_data
.w32
->left_pos
>= 0)
1071 store_in_alist (alistptr
, Qleft
, tem
);
1073 store_in_alist (alistptr
, Qleft
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1075 XSETINT (tem
, f
->output_data
.w32
->top_pos
);
1076 if (f
->output_data
.w32
->top_pos
>= 0)
1077 store_in_alist (alistptr
, Qtop
, tem
);
1079 store_in_alist (alistptr
, Qtop
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1081 store_in_alist (alistptr
, Qborder_width
,
1082 make_number (f
->output_data
.w32
->border_width
));
1083 store_in_alist (alistptr
, Qinternal_border_width
,
1084 make_number (f
->output_data
.w32
->internal_border_width
));
1085 sprintf (buf
, "%ld", (long) FRAME_W32_WINDOW (f
));
1086 store_in_alist (alistptr
, Qwindow_id
,
1087 build_string (buf
));
1088 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
1089 FRAME_SAMPLE_VISIBILITY (f
);
1090 store_in_alist (alistptr
, Qvisibility
,
1091 (FRAME_VISIBLE_P (f
) ? Qt
1092 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
1093 store_in_alist (alistptr
, Qdisplay
,
1094 XCAR (FRAME_W32_DISPLAY_INFO (f
)->name_list_element
));
1098 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
, Sw32_define_rgb_color
, 4, 4, 0,
1099 "Convert RGB numbers to a windows color reference and associate with NAME (a string).\n\
1100 This adds or updates a named color to w32-color-map, making it available for use.\n\
1101 The original entry's RGB ref is returned, or nil if the entry is new.")
1102 (red
, green
, blue
, name
)
1103 Lisp_Object red
, green
, blue
, name
;
1106 Lisp_Object oldrgb
= Qnil
;
1109 CHECK_NUMBER (red
, 0);
1110 CHECK_NUMBER (green
, 0);
1111 CHECK_NUMBER (blue
, 0);
1112 CHECK_STRING (name
, 0);
1114 XSET (rgb
, Lisp_Int
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
1118 /* replace existing entry in w32-color-map or add new entry. */
1119 entry
= Fassoc (name
, Vw32_color_map
);
1122 entry
= Fcons (name
, rgb
);
1123 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
1127 oldrgb
= Fcdr (entry
);
1128 Fsetcdr (entry
, rgb
);
1136 DEFUN ("w32-load-color-file", Fw32_load_color_file
, Sw32_load_color_file
, 1, 1, 0,
1137 "Create an alist of color entries from an external file (ie. rgb.txt).\n\
1138 Assign this value to w32-color-map to replace the existing color map.\n\
1140 The file should define one named RGB color per line like so:\
1142 where R,G,B are numbers between 0 and 255 and name is an arbitrary string.")
1144 Lisp_Object filename
;
1147 Lisp_Object cmap
= Qnil
;
1148 Lisp_Object abspath
;
1150 CHECK_STRING (filename
, 0);
1151 abspath
= Fexpand_file_name (filename
, Qnil
);
1153 fp
= fopen (XSTRING (filename
)->data
, "rt");
1157 int red
, green
, blue
;
1162 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
1163 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
1165 char *name
= buf
+ num
;
1166 num
= strlen (name
) - 1;
1167 if (name
[num
] == '\n')
1169 cmap
= Fcons (Fcons (build_string (name
),
1170 make_number (RGB (red
, green
, blue
))),
1182 /* The default colors for the w32 color map */
1183 typedef struct colormap_t
1189 colormap_t w32_color_map
[] =
1191 {"snow" , PALETTERGB (255,250,250)},
1192 {"ghost white" , PALETTERGB (248,248,255)},
1193 {"GhostWhite" , PALETTERGB (248,248,255)},
1194 {"white smoke" , PALETTERGB (245,245,245)},
1195 {"WhiteSmoke" , PALETTERGB (245,245,245)},
1196 {"gainsboro" , PALETTERGB (220,220,220)},
1197 {"floral white" , PALETTERGB (255,250,240)},
1198 {"FloralWhite" , PALETTERGB (255,250,240)},
1199 {"old lace" , PALETTERGB (253,245,230)},
1200 {"OldLace" , PALETTERGB (253,245,230)},
1201 {"linen" , PALETTERGB (250,240,230)},
1202 {"antique white" , PALETTERGB (250,235,215)},
1203 {"AntiqueWhite" , PALETTERGB (250,235,215)},
1204 {"papaya whip" , PALETTERGB (255,239,213)},
1205 {"PapayaWhip" , PALETTERGB (255,239,213)},
1206 {"blanched almond" , PALETTERGB (255,235,205)},
1207 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
1208 {"bisque" , PALETTERGB (255,228,196)},
1209 {"peach puff" , PALETTERGB (255,218,185)},
1210 {"PeachPuff" , PALETTERGB (255,218,185)},
1211 {"navajo white" , PALETTERGB (255,222,173)},
1212 {"NavajoWhite" , PALETTERGB (255,222,173)},
1213 {"moccasin" , PALETTERGB (255,228,181)},
1214 {"cornsilk" , PALETTERGB (255,248,220)},
1215 {"ivory" , PALETTERGB (255,255,240)},
1216 {"lemon chiffon" , PALETTERGB (255,250,205)},
1217 {"LemonChiffon" , PALETTERGB (255,250,205)},
1218 {"seashell" , PALETTERGB (255,245,238)},
1219 {"honeydew" , PALETTERGB (240,255,240)},
1220 {"mint cream" , PALETTERGB (245,255,250)},
1221 {"MintCream" , PALETTERGB (245,255,250)},
1222 {"azure" , PALETTERGB (240,255,255)},
1223 {"alice blue" , PALETTERGB (240,248,255)},
1224 {"AliceBlue" , PALETTERGB (240,248,255)},
1225 {"lavender" , PALETTERGB (230,230,250)},
1226 {"lavender blush" , PALETTERGB (255,240,245)},
1227 {"LavenderBlush" , PALETTERGB (255,240,245)},
1228 {"misty rose" , PALETTERGB (255,228,225)},
1229 {"MistyRose" , PALETTERGB (255,228,225)},
1230 {"white" , PALETTERGB (255,255,255)},
1231 {"black" , PALETTERGB ( 0, 0, 0)},
1232 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
1233 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
1234 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
1235 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
1236 {"dim gray" , PALETTERGB (105,105,105)},
1237 {"DimGray" , PALETTERGB (105,105,105)},
1238 {"dim grey" , PALETTERGB (105,105,105)},
1239 {"DimGrey" , PALETTERGB (105,105,105)},
1240 {"slate gray" , PALETTERGB (112,128,144)},
1241 {"SlateGray" , PALETTERGB (112,128,144)},
1242 {"slate grey" , PALETTERGB (112,128,144)},
1243 {"SlateGrey" , PALETTERGB (112,128,144)},
1244 {"light slate gray" , PALETTERGB (119,136,153)},
1245 {"LightSlateGray" , PALETTERGB (119,136,153)},
1246 {"light slate grey" , PALETTERGB (119,136,153)},
1247 {"LightSlateGrey" , PALETTERGB (119,136,153)},
1248 {"gray" , PALETTERGB (190,190,190)},
1249 {"grey" , PALETTERGB (190,190,190)},
1250 {"light grey" , PALETTERGB (211,211,211)},
1251 {"LightGrey" , PALETTERGB (211,211,211)},
1252 {"light gray" , PALETTERGB (211,211,211)},
1253 {"LightGray" , PALETTERGB (211,211,211)},
1254 {"midnight blue" , PALETTERGB ( 25, 25,112)},
1255 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
1256 {"navy" , PALETTERGB ( 0, 0,128)},
1257 {"navy blue" , PALETTERGB ( 0, 0,128)},
1258 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
1259 {"cornflower blue" , PALETTERGB (100,149,237)},
1260 {"CornflowerBlue" , PALETTERGB (100,149,237)},
1261 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
1262 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
1263 {"slate blue" , PALETTERGB (106, 90,205)},
1264 {"SlateBlue" , PALETTERGB (106, 90,205)},
1265 {"medium slate blue" , PALETTERGB (123,104,238)},
1266 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
1267 {"light slate blue" , PALETTERGB (132,112,255)},
1268 {"LightSlateBlue" , PALETTERGB (132,112,255)},
1269 {"medium blue" , PALETTERGB ( 0, 0,205)},
1270 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
1271 {"royal blue" , PALETTERGB ( 65,105,225)},
1272 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
1273 {"blue" , PALETTERGB ( 0, 0,255)},
1274 {"dodger blue" , PALETTERGB ( 30,144,255)},
1275 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
1276 {"deep sky blue" , PALETTERGB ( 0,191,255)},
1277 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
1278 {"sky blue" , PALETTERGB (135,206,235)},
1279 {"SkyBlue" , PALETTERGB (135,206,235)},
1280 {"light sky blue" , PALETTERGB (135,206,250)},
1281 {"LightSkyBlue" , PALETTERGB (135,206,250)},
1282 {"steel blue" , PALETTERGB ( 70,130,180)},
1283 {"SteelBlue" , PALETTERGB ( 70,130,180)},
1284 {"light steel blue" , PALETTERGB (176,196,222)},
1285 {"LightSteelBlue" , PALETTERGB (176,196,222)},
1286 {"light blue" , PALETTERGB (173,216,230)},
1287 {"LightBlue" , PALETTERGB (173,216,230)},
1288 {"powder blue" , PALETTERGB (176,224,230)},
1289 {"PowderBlue" , PALETTERGB (176,224,230)},
1290 {"pale turquoise" , PALETTERGB (175,238,238)},
1291 {"PaleTurquoise" , PALETTERGB (175,238,238)},
1292 {"dark turquoise" , PALETTERGB ( 0,206,209)},
1293 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
1294 {"medium turquoise" , PALETTERGB ( 72,209,204)},
1295 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
1296 {"turquoise" , PALETTERGB ( 64,224,208)},
1297 {"cyan" , PALETTERGB ( 0,255,255)},
1298 {"light cyan" , PALETTERGB (224,255,255)},
1299 {"LightCyan" , PALETTERGB (224,255,255)},
1300 {"cadet blue" , PALETTERGB ( 95,158,160)},
1301 {"CadetBlue" , PALETTERGB ( 95,158,160)},
1302 {"medium aquamarine" , PALETTERGB (102,205,170)},
1303 {"MediumAquamarine" , PALETTERGB (102,205,170)},
1304 {"aquamarine" , PALETTERGB (127,255,212)},
1305 {"dark green" , PALETTERGB ( 0,100, 0)},
1306 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
1307 {"dark olive green" , PALETTERGB ( 85,107, 47)},
1308 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
1309 {"dark sea green" , PALETTERGB (143,188,143)},
1310 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
1311 {"sea green" , PALETTERGB ( 46,139, 87)},
1312 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
1313 {"medium sea green" , PALETTERGB ( 60,179,113)},
1314 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
1315 {"light sea green" , PALETTERGB ( 32,178,170)},
1316 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
1317 {"pale green" , PALETTERGB (152,251,152)},
1318 {"PaleGreen" , PALETTERGB (152,251,152)},
1319 {"spring green" , PALETTERGB ( 0,255,127)},
1320 {"SpringGreen" , PALETTERGB ( 0,255,127)},
1321 {"lawn green" , PALETTERGB (124,252, 0)},
1322 {"LawnGreen" , PALETTERGB (124,252, 0)},
1323 {"green" , PALETTERGB ( 0,255, 0)},
1324 {"chartreuse" , PALETTERGB (127,255, 0)},
1325 {"medium spring green" , PALETTERGB ( 0,250,154)},
1326 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
1327 {"green yellow" , PALETTERGB (173,255, 47)},
1328 {"GreenYellow" , PALETTERGB (173,255, 47)},
1329 {"lime green" , PALETTERGB ( 50,205, 50)},
1330 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
1331 {"yellow green" , PALETTERGB (154,205, 50)},
1332 {"YellowGreen" , PALETTERGB (154,205, 50)},
1333 {"forest green" , PALETTERGB ( 34,139, 34)},
1334 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
1335 {"olive drab" , PALETTERGB (107,142, 35)},
1336 {"OliveDrab" , PALETTERGB (107,142, 35)},
1337 {"dark khaki" , PALETTERGB (189,183,107)},
1338 {"DarkKhaki" , PALETTERGB (189,183,107)},
1339 {"khaki" , PALETTERGB (240,230,140)},
1340 {"pale goldenrod" , PALETTERGB (238,232,170)},
1341 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
1342 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
1343 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
1344 {"light yellow" , PALETTERGB (255,255,224)},
1345 {"LightYellow" , PALETTERGB (255,255,224)},
1346 {"yellow" , PALETTERGB (255,255, 0)},
1347 {"gold" , PALETTERGB (255,215, 0)},
1348 {"light goldenrod" , PALETTERGB (238,221,130)},
1349 {"LightGoldenrod" , PALETTERGB (238,221,130)},
1350 {"goldenrod" , PALETTERGB (218,165, 32)},
1351 {"dark goldenrod" , PALETTERGB (184,134, 11)},
1352 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
1353 {"rosy brown" , PALETTERGB (188,143,143)},
1354 {"RosyBrown" , PALETTERGB (188,143,143)},
1355 {"indian red" , PALETTERGB (205, 92, 92)},
1356 {"IndianRed" , PALETTERGB (205, 92, 92)},
1357 {"saddle brown" , PALETTERGB (139, 69, 19)},
1358 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
1359 {"sienna" , PALETTERGB (160, 82, 45)},
1360 {"peru" , PALETTERGB (205,133, 63)},
1361 {"burlywood" , PALETTERGB (222,184,135)},
1362 {"beige" , PALETTERGB (245,245,220)},
1363 {"wheat" , PALETTERGB (245,222,179)},
1364 {"sandy brown" , PALETTERGB (244,164, 96)},
1365 {"SandyBrown" , PALETTERGB (244,164, 96)},
1366 {"tan" , PALETTERGB (210,180,140)},
1367 {"chocolate" , PALETTERGB (210,105, 30)},
1368 {"firebrick" , PALETTERGB (178,34, 34)},
1369 {"brown" , PALETTERGB (165,42, 42)},
1370 {"dark salmon" , PALETTERGB (233,150,122)},
1371 {"DarkSalmon" , PALETTERGB (233,150,122)},
1372 {"salmon" , PALETTERGB (250,128,114)},
1373 {"light salmon" , PALETTERGB (255,160,122)},
1374 {"LightSalmon" , PALETTERGB (255,160,122)},
1375 {"orange" , PALETTERGB (255,165, 0)},
1376 {"dark orange" , PALETTERGB (255,140, 0)},
1377 {"DarkOrange" , PALETTERGB (255,140, 0)},
1378 {"coral" , PALETTERGB (255,127, 80)},
1379 {"light coral" , PALETTERGB (240,128,128)},
1380 {"LightCoral" , PALETTERGB (240,128,128)},
1381 {"tomato" , PALETTERGB (255, 99, 71)},
1382 {"orange red" , PALETTERGB (255, 69, 0)},
1383 {"OrangeRed" , PALETTERGB (255, 69, 0)},
1384 {"red" , PALETTERGB (255, 0, 0)},
1385 {"hot pink" , PALETTERGB (255,105,180)},
1386 {"HotPink" , PALETTERGB (255,105,180)},
1387 {"deep pink" , PALETTERGB (255, 20,147)},
1388 {"DeepPink" , PALETTERGB (255, 20,147)},
1389 {"pink" , PALETTERGB (255,192,203)},
1390 {"light pink" , PALETTERGB (255,182,193)},
1391 {"LightPink" , PALETTERGB (255,182,193)},
1392 {"pale violet red" , PALETTERGB (219,112,147)},
1393 {"PaleVioletRed" , PALETTERGB (219,112,147)},
1394 {"maroon" , PALETTERGB (176, 48, 96)},
1395 {"medium violet red" , PALETTERGB (199, 21,133)},
1396 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
1397 {"violet red" , PALETTERGB (208, 32,144)},
1398 {"VioletRed" , PALETTERGB (208, 32,144)},
1399 {"magenta" , PALETTERGB (255, 0,255)},
1400 {"violet" , PALETTERGB (238,130,238)},
1401 {"plum" , PALETTERGB (221,160,221)},
1402 {"orchid" , PALETTERGB (218,112,214)},
1403 {"medium orchid" , PALETTERGB (186, 85,211)},
1404 {"MediumOrchid" , PALETTERGB (186, 85,211)},
1405 {"dark orchid" , PALETTERGB (153, 50,204)},
1406 {"DarkOrchid" , PALETTERGB (153, 50,204)},
1407 {"dark violet" , PALETTERGB (148, 0,211)},
1408 {"DarkViolet" , PALETTERGB (148, 0,211)},
1409 {"blue violet" , PALETTERGB (138, 43,226)},
1410 {"BlueViolet" , PALETTERGB (138, 43,226)},
1411 {"purple" , PALETTERGB (160, 32,240)},
1412 {"medium purple" , PALETTERGB (147,112,219)},
1413 {"MediumPurple" , PALETTERGB (147,112,219)},
1414 {"thistle" , PALETTERGB (216,191,216)},
1415 {"gray0" , PALETTERGB ( 0, 0, 0)},
1416 {"grey0" , PALETTERGB ( 0, 0, 0)},
1417 {"dark grey" , PALETTERGB (169,169,169)},
1418 {"DarkGrey" , PALETTERGB (169,169,169)},
1419 {"dark gray" , PALETTERGB (169,169,169)},
1420 {"DarkGray" , PALETTERGB (169,169,169)},
1421 {"dark blue" , PALETTERGB ( 0, 0,139)},
1422 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
1423 {"dark cyan" , PALETTERGB ( 0,139,139)},
1424 {"DarkCyan" , PALETTERGB ( 0,139,139)},
1425 {"dark magenta" , PALETTERGB (139, 0,139)},
1426 {"DarkMagenta" , PALETTERGB (139, 0,139)},
1427 {"dark red" , PALETTERGB (139, 0, 0)},
1428 {"DarkRed" , PALETTERGB (139, 0, 0)},
1429 {"light green" , PALETTERGB (144,238,144)},
1430 {"LightGreen" , PALETTERGB (144,238,144)},
1433 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
1434 0, 0, 0, "Return the default color map.")
1438 colormap_t
*pc
= w32_color_map
;
1445 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
1447 cmap
= Fcons (Fcons (build_string (pc
->name
),
1448 make_number (pc
->colorref
)),
1457 w32_to_x_color (rgb
)
1462 CHECK_NUMBER (rgb
, 0);
1466 color
= Frassq (rgb
, Vw32_color_map
);
1471 return (Fcar (color
));
1477 w32_color_map_lookup (colorname
)
1480 Lisp_Object tail
, ret
= Qnil
;
1484 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
1486 register Lisp_Object elt
, tem
;
1489 if (!CONSP (elt
)) continue;
1493 if (lstrcmpi (XSTRING (tem
)->data
, colorname
) == 0)
1495 ret
= XUINT (Fcdr (elt
));
1509 x_to_w32_color (colorname
)
1512 register Lisp_Object tail
, ret
= Qnil
;
1516 if (colorname
[0] == '#')
1518 /* Could be an old-style RGB Device specification. */
1521 color
= colorname
+ 1;
1523 size
= strlen(color
);
1524 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
1532 for (i
= 0; i
< 3; i
++)
1536 unsigned long value
;
1538 /* The check for 'x' in the following conditional takes into
1539 account the fact that strtol allows a "0x" in front of
1540 our numbers, and we don't. */
1541 if (!isxdigit(color
[0]) || color
[1] == 'x')
1545 value
= strtoul(color
, &end
, 16);
1547 if (errno
== ERANGE
|| end
- color
!= size
)
1552 value
= value
* 0x10;
1563 colorval
|= (value
<< pos
);
1574 else if (strnicmp(colorname
, "rgb:", 4) == 0)
1582 color
= colorname
+ 4;
1583 for (i
= 0; i
< 3; i
++)
1586 unsigned long value
;
1588 /* The check for 'x' in the following conditional takes into
1589 account the fact that strtol allows a "0x" in front of
1590 our numbers, and we don't. */
1591 if (!isxdigit(color
[0]) || color
[1] == 'x')
1593 value
= strtoul(color
, &end
, 16);
1594 if (errno
== ERANGE
)
1596 switch (end
- color
)
1599 value
= value
* 0x10 + value
;
1612 if (value
== ULONG_MAX
)
1614 colorval
|= (value
<< pos
);
1628 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1630 /* This is an RGB Intensity specification. */
1637 color
= colorname
+ 5;
1638 for (i
= 0; i
< 3; i
++)
1644 value
= strtod(color
, &end
);
1645 if (errno
== ERANGE
)
1647 if (value
< 0.0 || value
> 1.0)
1649 val
= (UINT
)(0x100 * value
);
1650 /* We used 0x100 instead of 0xFF to give an continuous
1651 range between 0.0 and 1.0 inclusive. The next statement
1652 fixes the 1.0 case. */
1655 colorval
|= (val
<< pos
);
1669 /* I am not going to attempt to handle any of the CIE color schemes
1670 or TekHVC, since I don't know the algorithms for conversion to
1673 /* If we fail to lookup the color name in w32_color_map, then check the
1674 colorname to see if it can be crudely approximated: If the X color
1675 ends in a number (e.g., "darkseagreen2"), strip the number and
1676 return the result of looking up the base color name. */
1677 ret
= w32_color_map_lookup (colorname
);
1680 int len
= strlen (colorname
);
1682 if (isdigit (colorname
[len
- 1]))
1684 char *ptr
, *approx
= alloca (len
);
1686 strcpy (approx
, colorname
);
1687 ptr
= &approx
[len
- 1];
1688 while (ptr
> approx
&& isdigit (*ptr
))
1691 ret
= w32_color_map_lookup (approx
);
1701 w32_regenerate_palette (FRAME_PTR f
)
1703 struct w32_palette_entry
* list
;
1704 LOGPALETTE
* log_palette
;
1705 HPALETTE new_palette
;
1708 /* don't bother trying to create palette if not supported */
1709 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1712 log_palette
= (LOGPALETTE
*)
1713 alloca (sizeof (LOGPALETTE
) +
1714 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1715 log_palette
->palVersion
= 0x300;
1716 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1718 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1720 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1721 i
++, list
= list
->next
)
1722 log_palette
->palPalEntry
[i
] = list
->entry
;
1724 new_palette
= CreatePalette (log_palette
);
1728 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1729 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1730 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1732 /* Realize display palette and garbage all frames. */
1733 release_frame_dc (f
, get_frame_dc (f
));
1738 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1739 #define SET_W32_COLOR(pe, color) \
1742 pe.peRed = GetRValue (color); \
1743 pe.peGreen = GetGValue (color); \
1744 pe.peBlue = GetBValue (color); \
1749 /* Keep these around in case we ever want to track color usage. */
1751 w32_map_color (FRAME_PTR f
, COLORREF color
)
1753 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1755 if (NILP (Vw32_enable_palette
))
1758 /* check if color is already mapped */
1761 if (W32_COLOR (list
->entry
) == color
)
1769 /* not already mapped, so add to list and recreate Windows palette */
1770 list
= (struct w32_palette_entry
*)
1771 xmalloc (sizeof (struct w32_palette_entry
));
1772 SET_W32_COLOR (list
->entry
, color
);
1774 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1775 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1776 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1778 /* set flag that palette must be regenerated */
1779 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1783 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1785 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1786 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1788 if (NILP (Vw32_enable_palette
))
1791 /* check if color is already mapped */
1794 if (W32_COLOR (list
->entry
) == color
)
1796 if (--list
->refcount
== 0)
1800 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1810 /* set flag that palette must be regenerated */
1811 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1816 /* Gamma-correct COLOR on frame F. */
1819 gamma_correct (f
, color
)
1825 *color
= PALETTERGB (
1826 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1827 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1828 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1833 /* Decide if color named COLOR is valid for the display associated with
1834 the selected frame; if so, return the rgb values in COLOR_DEF.
1835 If ALLOC is nonzero, allocate a new colormap cell. */
1838 w32_defined_color (f
, color
, color_def
, alloc
)
1844 register Lisp_Object tem
;
1845 COLORREF w32_color_ref
;
1847 tem
= x_to_w32_color (color
);
1853 /* Apply gamma correction. */
1854 w32_color_ref
= XUINT (tem
);
1855 gamma_correct (f
, &w32_color_ref
);
1856 XSETINT (tem
, w32_color_ref
);
1859 /* Map this color to the palette if it is enabled. */
1860 if (!NILP (Vw32_enable_palette
))
1862 struct w32_palette_entry
* entry
=
1863 one_w32_display_info
.color_list
;
1864 struct w32_palette_entry
** prev
=
1865 &one_w32_display_info
.color_list
;
1867 /* check if color is already mapped */
1870 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1872 prev
= &entry
->next
;
1873 entry
= entry
->next
;
1876 if (entry
== NULL
&& alloc
)
1878 /* not already mapped, so add to list */
1879 entry
= (struct w32_palette_entry
*)
1880 xmalloc (sizeof (struct w32_palette_entry
));
1881 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1884 one_w32_display_info
.num_colors
++;
1886 /* set flag that palette must be regenerated */
1887 one_w32_display_info
.regen_palette
= TRUE
;
1890 /* Ensure COLORREF value is snapped to nearest color in (default)
1891 palette by simulating the PALETTERGB macro. This works whether
1892 or not the display device has a palette. */
1893 w32_color_ref
= XUINT (tem
) | 0x2000000;
1895 color_def
->pixel
= w32_color_ref
;
1896 color_def
->red
= GetRValue (w32_color_ref
);
1897 color_def
->green
= GetGValue (w32_color_ref
);
1898 color_def
->blue
= GetBValue (w32_color_ref
);
1908 /* Given a string ARG naming a color, compute a pixel value from it
1909 suitable for screen F.
1910 If F is not a color screen, return DEF (default) regardless of what
1914 x_decode_color (f
, arg
, def
)
1921 CHECK_STRING (arg
, 0);
1923 if (strcmp (XSTRING (arg
)->data
, "black") == 0)
1924 return BLACK_PIX_DEFAULT (f
);
1925 else if (strcmp (XSTRING (arg
)->data
, "white") == 0)
1926 return WHITE_PIX_DEFAULT (f
);
1928 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1931 /* w32_defined_color is responsible for coping with failures
1932 by looking for a near-miss. */
1933 if (w32_defined_color (f
, XSTRING (arg
)->data
, &cdef
, 1))
1936 /* defined_color failed; return an ultimate default. */
1940 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
1941 the previous value of that parameter, NEW_VALUE is the new value. */
1944 x_set_line_spacing (f
, new_value
, old_value
)
1946 Lisp_Object new_value
, old_value
;
1948 if (NILP (new_value
))
1949 f
->extra_line_spacing
= 0;
1950 else if (NATNUMP (new_value
))
1951 f
->extra_line_spacing
= XFASTINT (new_value
);
1953 Fsignal (Qerror
, Fcons (build_string ("Invalid line-spacing"),
1954 Fcons (new_value
, Qnil
)));
1955 if (FRAME_VISIBLE_P (f
))
1960 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
1961 the previous value of that parameter, NEW_VALUE is the new value. */
1964 x_set_screen_gamma (f
, new_value
, old_value
)
1966 Lisp_Object new_value
, old_value
;
1968 if (NILP (new_value
))
1970 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
1971 /* The value 0.4545 is the normal viewing gamma. */
1972 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
1974 Fsignal (Qerror
, Fcons (build_string ("Invalid screen-gamma"),
1975 Fcons (new_value
, Qnil
)));
1977 clear_face_cache (0);
1981 /* Functions called only from `x_set_frame_param'
1982 to set individual parameters.
1984 If FRAME_W32_WINDOW (f) is 0,
1985 the frame is being created and its window does not exist yet.
1986 In that case, just record the parameter's new value
1987 in the standard place; do not attempt to change the window. */
1990 x_set_foreground_color (f
, arg
, oldval
)
1992 Lisp_Object arg
, oldval
;
1994 FRAME_FOREGROUND_PIXEL (f
)
1995 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1997 if (FRAME_W32_WINDOW (f
) != 0)
1999 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
2000 if (FRAME_VISIBLE_P (f
))
2006 x_set_background_color (f
, arg
, oldval
)
2008 Lisp_Object arg
, oldval
;
2010 FRAME_BACKGROUND_PIXEL (f
)
2011 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
2013 if (FRAME_W32_WINDOW (f
) != 0)
2015 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
2016 FRAME_BACKGROUND_PIXEL (f
));
2018 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
2020 if (FRAME_VISIBLE_P (f
))
2026 x_set_mouse_color (f
, arg
, oldval
)
2028 Lisp_Object arg
, oldval
;
2030 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
2034 if (!EQ (Qnil
, arg
))
2035 f
->output_data
.w32
->mouse_pixel
2036 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2037 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
2039 /* Don't let pointers be invisible. */
2040 if (mask_color
== f
->output_data
.w32
->mouse_pixel
2041 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
2042 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
2044 #if 0 /* TODO : cursor changes */
2047 /* It's not okay to crash if the user selects a screwy cursor. */
2048 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
2050 if (!EQ (Qnil
, Vx_pointer_shape
))
2052 CHECK_NUMBER (Vx_pointer_shape
, 0);
2053 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
2056 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2057 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
2059 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
2061 CHECK_NUMBER (Vx_nontext_pointer_shape
, 0);
2062 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2063 XINT (Vx_nontext_pointer_shape
));
2066 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
2067 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2069 if (!EQ (Qnil
, Vx_busy_pointer_shape
))
2071 CHECK_NUMBER (Vx_busy_pointer_shape
, 0);
2072 busy_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2073 XINT (Vx_busy_pointer_shape
));
2076 busy_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
2077 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
2079 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2080 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
2082 CHECK_NUMBER (Vx_mode_pointer_shape
, 0);
2083 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2084 XINT (Vx_mode_pointer_shape
));
2087 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2088 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
2090 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
2092 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
, 0);
2094 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2095 XINT (Vx_sensitive_text_pointer_shape
));
2098 cross_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
2100 if (!NILP (Vx_window_horizontal_drag_shape
))
2102 CHECK_NUMBER (Vx_window_horizontal_drag_shape
, 0);
2103 horizontal_drag_cursor
2104 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
2105 XINT (Vx_window_horizontal_drag_shape
));
2108 horizontal_drag_cursor
2109 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
2111 /* Check and report errors with the above calls. */
2112 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
2113 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
2116 XColor fore_color
, back_color
;
2118 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
2119 back_color
.pixel
= mask_color
;
2120 XQueryColor (FRAME_W32_DISPLAY (f
),
2121 DefaultColormap (FRAME_W32_DISPLAY (f
),
2122 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2124 XQueryColor (FRAME_W32_DISPLAY (f
),
2125 DefaultColormap (FRAME_W32_DISPLAY (f
),
2126 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2128 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
2129 &fore_color
, &back_color
);
2130 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
2131 &fore_color
, &back_color
);
2132 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
2133 &fore_color
, &back_color
);
2134 XRecolorCursor (FRAME_W32_DISPLAY (f
), cross_cursor
,
2135 &fore_color
, &back_color
);
2136 XRecolorCursor (FRAME_W32_DISPLAY (f
), busy_cursor
,
2137 &fore_color
, &back_color
);
2140 if (FRAME_W32_WINDOW (f
) != 0)
2141 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
2143 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
2144 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
2145 f
->output_data
.w32
->text_cursor
= cursor
;
2147 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
2148 && f
->output_data
.w32
->nontext_cursor
!= 0)
2149 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
2150 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
2152 if (busy_cursor
!= f
->output_data
.w32
->busy_cursor
2153 && f
->output_data
.w32
->busy_cursor
!= 0)
2154 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->busy_cursor
);
2155 f
->output_data
.w32
->busy_cursor
= busy_cursor
;
2157 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
2158 && f
->output_data
.w32
->modeline_cursor
!= 0)
2159 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
2160 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
2162 if (cross_cursor
!= f
->output_data
.w32
->cross_cursor
2163 && f
->output_data
.w32
->cross_cursor
!= 0)
2164 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->cross_cursor
);
2165 f
->output_data
.w32
->cross_cursor
= cross_cursor
;
2167 XFlush (FRAME_W32_DISPLAY (f
));
2170 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
2174 /* Defined in w32term.c. */
2175 void x_update_cursor (struct frame
*f
, int on_p
);
2178 x_set_cursor_color (f
, arg
, oldval
)
2180 Lisp_Object arg
, oldval
;
2182 unsigned long fore_pixel
, pixel
;
2184 if (!NILP (Vx_cursor_fore_pixel
))
2185 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
2186 WHITE_PIX_DEFAULT (f
));
2188 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2190 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2192 /* Make sure that the cursor color differs from the background color. */
2193 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
2195 pixel
= f
->output_data
.w32
->mouse_pixel
;
2196 if (pixel
== fore_pixel
)
2197 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2200 FRAME_FOREGROUND_PIXEL (f
) = fore_pixel
;
2201 f
->output_data
.w32
->cursor_pixel
= pixel
;
2203 if (FRAME_W32_WINDOW (f
) != 0)
2205 if (FRAME_VISIBLE_P (f
))
2207 x_update_cursor (f
, 0);
2208 x_update_cursor (f
, 1);
2212 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
2215 /* Set the border-color of frame F to pixel value PIX.
2216 Note that this does not fully take effect if done before
2219 x_set_border_pixel (f
, pix
)
2223 f
->output_data
.w32
->border_pixel
= pix
;
2225 if (FRAME_W32_WINDOW (f
) != 0 && f
->output_data
.w32
->border_width
> 0)
2227 if (FRAME_VISIBLE_P (f
))
2232 /* Set the border-color of frame F to value described by ARG.
2233 ARG can be a string naming a color.
2234 The border-color is used for the border that is drawn by the server.
2235 Note that this does not fully take effect if done before
2236 F has a window; it must be redone when the window is created. */
2239 x_set_border_color (f
, arg
, oldval
)
2241 Lisp_Object arg
, oldval
;
2245 CHECK_STRING (arg
, 0);
2246 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2247 x_set_border_pixel (f
, pix
);
2248 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
2251 /* Value is the internal representation of the specified cursor type
2252 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
2253 of the bar cursor. */
2255 enum text_cursor_kinds
2256 x_specified_cursor_type (arg
, width
)
2260 enum text_cursor_kinds type
;
2267 else if (CONSP (arg
)
2268 && EQ (XCAR (arg
), Qbar
)
2269 && INTEGERP (XCDR (arg
))
2270 && XINT (XCDR (arg
)) >= 0)
2273 *width
= XINT (XCDR (arg
));
2275 else if (NILP (arg
))
2278 /* Treat anything unknown as "box cursor".
2279 It was bad to signal an error; people have trouble fixing
2280 .Xdefaults with Emacs, when it has something bad in it. */
2281 type
= FILLED_BOX_CURSOR
;
2287 x_set_cursor_type (f
, arg
, oldval
)
2289 Lisp_Object arg
, oldval
;
2293 FRAME_DESIRED_CURSOR (f
) = x_specified_cursor_type (arg
, &width
);
2294 f
->output_data
.w32
->cursor_width
= width
;
2296 /* Make sure the cursor gets redrawn. This is overkill, but how
2297 often do people change cursor types? */
2298 update_mode_lines
++;
2302 x_set_icon_type (f
, arg
, oldval
)
2304 Lisp_Object arg
, oldval
;
2308 if (NILP (arg
) && NILP (oldval
))
2311 if (STRINGP (arg
) && STRINGP (oldval
)
2312 && EQ (Fstring_equal (oldval
, arg
), Qt
))
2315 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
2320 result
= x_bitmap_icon (f
, arg
);
2324 error ("No icon window available");
2330 /* Return non-nil if frame F wants a bitmap icon. */
2338 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
2346 x_set_icon_name (f
, arg
, oldval
)
2348 Lisp_Object arg
, oldval
;
2354 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
2357 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
2363 if (f
->output_data
.w32
->icon_bitmap
!= 0)
2368 result
= x_text_icon (f
,
2369 (char *) XSTRING ((!NILP (f
->icon_name
)
2378 error ("No icon window available");
2381 /* If the window was unmapped (and its icon was mapped),
2382 the new icon is not mapped, so map the window in its stead. */
2383 if (FRAME_VISIBLE_P (f
))
2385 #ifdef USE_X_TOOLKIT
2386 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
2388 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
2391 XFlush (FRAME_W32_DISPLAY (f
));
2396 extern Lisp_Object
x_new_font ();
2397 extern Lisp_Object
x_new_fontset();
2400 x_set_font (f
, arg
, oldval
)
2402 Lisp_Object arg
, oldval
;
2405 Lisp_Object fontset_name
;
2408 CHECK_STRING (arg
, 1);
2410 fontset_name
= Fquery_fontset (arg
, Qnil
);
2413 result
= (STRINGP (fontset_name
)
2414 ? x_new_fontset (f
, XSTRING (fontset_name
)->data
)
2415 : x_new_font (f
, XSTRING (arg
)->data
));
2418 if (EQ (result
, Qnil
))
2419 error ("Font `%s' is not defined", XSTRING (arg
)->data
);
2420 else if (EQ (result
, Qt
))
2421 error ("The characters of the given font have varying widths");
2422 else if (STRINGP (result
))
2424 store_frame_param (f
, Qfont
, result
);
2425 recompute_basic_faces (f
);
2430 do_pending_window_change (0);
2432 /* Don't call `face-set-after-frame-default' when faces haven't been
2433 initialized yet. This is the case when called from
2434 Fx_create_frame. In that case, the X widget or window doesn't
2435 exist either, and we can end up in x_report_frame_params with a
2436 null widget which gives a segfault. */
2437 if (FRAME_FACE_CACHE (f
))
2439 XSETFRAME (frame
, f
);
2440 call1 (Qface_set_after_frame_default
, frame
);
2445 x_set_border_width (f
, arg
, oldval
)
2447 Lisp_Object arg
, oldval
;
2449 CHECK_NUMBER (arg
, 0);
2451 if (XINT (arg
) == f
->output_data
.w32
->border_width
)
2454 if (FRAME_W32_WINDOW (f
) != 0)
2455 error ("Cannot change the border width of a window");
2457 f
->output_data
.w32
->border_width
= XINT (arg
);
2461 x_set_internal_border_width (f
, arg
, oldval
)
2463 Lisp_Object arg
, oldval
;
2465 int old
= f
->output_data
.w32
->internal_border_width
;
2467 CHECK_NUMBER (arg
, 0);
2468 f
->output_data
.w32
->internal_border_width
= XINT (arg
);
2469 if (f
->output_data
.w32
->internal_border_width
< 0)
2470 f
->output_data
.w32
->internal_border_width
= 0;
2472 if (f
->output_data
.w32
->internal_border_width
== old
)
2475 if (FRAME_W32_WINDOW (f
) != 0)
2477 x_set_window_size (f
, 0, f
->width
, f
->height
);
2478 SET_FRAME_GARBAGED (f
);
2479 do_pending_window_change (0);
2484 x_set_visibility (f
, value
, oldval
)
2486 Lisp_Object value
, oldval
;
2489 XSETFRAME (frame
, f
);
2492 Fmake_frame_invisible (frame
, Qt
);
2493 else if (EQ (value
, Qicon
))
2494 Ficonify_frame (frame
);
2496 Fmake_frame_visible (frame
);
2500 /* Change window heights in windows rooted in WINDOW by N lines. */
2503 x_change_window_heights (window
, n
)
2507 struct window
*w
= XWINDOW (window
);
2509 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
2510 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
2512 if (INTEGERP (w
->orig_top
))
2513 XSETFASTINT (w
->orig_top
, XFASTINT (w
->orig_top
) + n
);
2514 if (INTEGERP (w
->orig_height
))
2515 XSETFASTINT (w
->orig_height
, XFASTINT (w
->orig_height
) - n
);
2517 /* Handle just the top child in a vertical split. */
2518 if (!NILP (w
->vchild
))
2519 x_change_window_heights (w
->vchild
, n
);
2521 /* Adjust all children in a horizontal split. */
2522 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2524 w
= XWINDOW (window
);
2525 x_change_window_heights (window
, n
);
2530 x_set_menu_bar_lines (f
, value
, oldval
)
2532 Lisp_Object value
, oldval
;
2535 int olines
= FRAME_MENU_BAR_LINES (f
);
2537 /* Right now, menu bars don't work properly in minibuf-only frames;
2538 most of the commands try to apply themselves to the minibuffer
2539 frame itself, and get an error because you can't switch buffers
2540 in or split the minibuffer window. */
2541 if (FRAME_MINIBUF_ONLY_P (f
))
2544 if (INTEGERP (value
))
2545 nlines
= XINT (value
);
2549 FRAME_MENU_BAR_LINES (f
) = 0;
2551 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2554 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2555 free_frame_menubar (f
);
2556 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2558 /* Adjust the frame size so that the client (text) dimensions
2559 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
2561 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2562 do_pending_window_change (0);
2568 /* Set the number of lines used for the tool bar of frame F to VALUE.
2569 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2570 is the old number of tool bar lines. This function changes the
2571 height of all windows on frame F to match the new tool bar height.
2572 The frame's height doesn't change. */
2575 x_set_tool_bar_lines (f
, value
, oldval
)
2577 Lisp_Object value
, oldval
;
2579 int delta
, nlines
, root_height
;
2580 Lisp_Object root_window
;
2582 /* Use VALUE only if an integer >= 0. */
2583 if (INTEGERP (value
) && XINT (value
) >= 0)
2584 nlines
= XFASTINT (value
);
2588 /* Make sure we redisplay all windows in this frame. */
2589 ++windows_or_buffers_changed
;
2591 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2593 /* Don't resize the tool-bar to more than we have room for. */
2594 root_window
= FRAME_ROOT_WINDOW (f
);
2595 root_height
= XINT (XWINDOW (root_window
)->height
);
2596 if (root_height
- delta
< 1)
2598 delta
= root_height
- 1;
2599 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
2602 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2603 x_change_window_heights (root_window
, delta
);
2606 /* We also have to make sure that the internal border at the top of
2607 the frame, below the menu bar or tool bar, is redrawn when the
2608 tool bar disappears. This is so because the internal border is
2609 below the tool bar if one is displayed, but is below the menu bar
2610 if there isn't a tool bar. The tool bar draws into the area
2611 below the menu bar. */
2612 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
2616 clear_current_matrices (f
);
2617 updating_frame
= NULL
;
2620 /* If the tool bar gets smaller, the internal border below it
2621 has to be cleared. It was formerly part of the display
2622 of the larger tool bar, and updating windows won't clear it. */
2625 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2626 int width
= PIXEL_WIDTH (f
);
2627 int y
= nlines
* CANON_Y_UNIT (f
);
2631 HDC hdc
= get_frame_dc (f
);
2632 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
2633 release_frame_dc (f
, hdc
);
2640 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2643 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2644 name; if NAME is a string, set F's name to NAME and set
2645 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2647 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2648 suggesting a new name, which lisp code should override; if
2649 F->explicit_name is set, ignore the new name; otherwise, set it. */
2652 x_set_name (f
, name
, explicit)
2657 /* Make sure that requests from lisp code override requests from
2658 Emacs redisplay code. */
2661 /* If we're switching from explicit to implicit, we had better
2662 update the mode lines and thereby update the title. */
2663 if (f
->explicit_name
&& NILP (name
))
2664 update_mode_lines
= 1;
2666 f
->explicit_name
= ! NILP (name
);
2668 else if (f
->explicit_name
)
2671 /* If NAME is nil, set the name to the w32_id_name. */
2674 /* Check for no change needed in this very common case
2675 before we do any consing. */
2676 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
2677 XSTRING (f
->name
)->data
))
2679 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
2682 CHECK_STRING (name
, 0);
2684 /* Don't change the name if it's already NAME. */
2685 if (! NILP (Fstring_equal (name
, f
->name
)))
2690 /* For setting the frame title, the title parameter should override
2691 the name parameter. */
2692 if (! NILP (f
->title
))
2695 if (FRAME_W32_WINDOW (f
))
2697 if (STRING_MULTIBYTE (name
))
2698 name
= ENCODE_SYSTEM (name
);
2701 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2706 /* This function should be called when the user's lisp code has
2707 specified a name for the frame; the name will override any set by the
2710 x_explicitly_set_name (f
, arg
, oldval
)
2712 Lisp_Object arg
, oldval
;
2714 x_set_name (f
, arg
, 1);
2717 /* This function should be called by Emacs redisplay code to set the
2718 name; names set this way will never override names set by the user's
2721 x_implicitly_set_name (f
, arg
, oldval
)
2723 Lisp_Object arg
, oldval
;
2725 x_set_name (f
, arg
, 0);
2728 /* Change the title of frame F to NAME.
2729 If NAME is nil, use the frame name as the title.
2731 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2732 name; if NAME is a string, set F's name to NAME and set
2733 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2735 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2736 suggesting a new name, which lisp code should override; if
2737 F->explicit_name is set, ignore the new name; otherwise, set it. */
2740 x_set_title (f
, name
, old_name
)
2742 Lisp_Object name
, old_name
;
2744 /* Don't change the title if it's already NAME. */
2745 if (EQ (name
, f
->title
))
2748 update_mode_lines
= 1;
2755 if (FRAME_W32_WINDOW (f
))
2757 if (STRING_MULTIBYTE (name
))
2758 name
= ENCODE_SYSTEM (name
);
2761 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2767 x_set_autoraise (f
, arg
, oldval
)
2769 Lisp_Object arg
, oldval
;
2771 f
->auto_raise
= !EQ (Qnil
, arg
);
2775 x_set_autolower (f
, arg
, oldval
)
2777 Lisp_Object arg
, oldval
;
2779 f
->auto_lower
= !EQ (Qnil
, arg
);
2783 x_set_unsplittable (f
, arg
, oldval
)
2785 Lisp_Object arg
, oldval
;
2787 f
->no_split
= !NILP (arg
);
2791 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2793 Lisp_Object arg
, oldval
;
2795 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2796 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2797 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2798 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2800 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = NILP (arg
) ?
2801 vertical_scroll_bar_none
:
2802 /* Put scroll bars on the right by default, as is conventional
2805 ? vertical_scroll_bar_left
2806 : vertical_scroll_bar_right
;
2808 /* We set this parameter before creating the window for the
2809 frame, so we can get the geometry right from the start.
2810 However, if the window hasn't been created yet, we shouldn't
2811 call x_set_window_size. */
2812 if (FRAME_W32_WINDOW (f
))
2813 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2814 do_pending_window_change (0);
2819 x_set_scroll_bar_width (f
, arg
, oldval
)
2821 Lisp_Object arg
, oldval
;
2823 int wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
2827 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2828 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) +
2830 if (FRAME_W32_WINDOW (f
))
2831 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2832 do_pending_window_change (0);
2834 else if (INTEGERP (arg
) && XINT (arg
) > 0
2835 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2837 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2838 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2840 if (FRAME_W32_WINDOW (f
))
2841 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2842 do_pending_window_change (0);
2844 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2845 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2846 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2849 /* Subroutines of creating an frame. */
2851 /* Make sure that Vx_resource_name is set to a reasonable value.
2852 Fix it up, or set it to `emacs' if it is too hopeless. */
2855 validate_x_resource_name ()
2858 /* Number of valid characters in the resource name. */
2860 /* Number of invalid characters in the resource name. */
2865 if (STRINGP (Vx_resource_name
))
2867 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
2870 len
= STRING_BYTES (XSTRING (Vx_resource_name
));
2872 /* Only letters, digits, - and _ are valid in resource names.
2873 Count the valid characters and count the invalid ones. */
2874 for (i
= 0; i
< len
; i
++)
2877 if (! ((c
>= 'a' && c
<= 'z')
2878 || (c
>= 'A' && c
<= 'Z')
2879 || (c
>= '0' && c
<= '9')
2880 || c
== '-' || c
== '_'))
2887 /* Not a string => completely invalid. */
2888 bad_count
= 5, good_count
= 0;
2890 /* If name is valid already, return. */
2894 /* If name is entirely invalid, or nearly so, use `emacs'. */
2896 || (good_count
== 1 && bad_count
> 0))
2898 Vx_resource_name
= build_string ("emacs");
2902 /* Name is partly valid. Copy it and replace the invalid characters
2903 with underscores. */
2905 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
2907 for (i
= 0; i
< len
; i
++)
2909 int c
= XSTRING (new)->data
[i
];
2910 if (! ((c
>= 'a' && c
<= 'z')
2911 || (c
>= 'A' && c
<= 'Z')
2912 || (c
>= '0' && c
<= '9')
2913 || c
== '-' || c
== '_'))
2914 XSTRING (new)->data
[i
] = '_';
2919 extern char *x_get_string_resource ();
2921 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
2922 "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
2923 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
2924 class, where INSTANCE is the name under which Emacs was invoked, or\n\
2925 the name specified by the `-name' or `-rn' command-line arguments.\n\
2927 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
2928 class, respectively. You must specify both of them or neither.\n\
2929 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
2930 and the class is `Emacs.CLASS.SUBCLASS'.")
2931 (attribute
, class, component
, subclass
)
2932 Lisp_Object attribute
, class, component
, subclass
;
2934 register char *value
;
2938 CHECK_STRING (attribute
, 0);
2939 CHECK_STRING (class, 0);
2941 if (!NILP (component
))
2942 CHECK_STRING (component
, 1);
2943 if (!NILP (subclass
))
2944 CHECK_STRING (subclass
, 2);
2945 if (NILP (component
) != NILP (subclass
))
2946 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
2948 validate_x_resource_name ();
2950 /* Allocate space for the components, the dots which separate them,
2951 and the final '\0'. Make them big enough for the worst case. */
2952 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vx_resource_name
))
2953 + (STRINGP (component
)
2954 ? STRING_BYTES (XSTRING (component
)) : 0)
2955 + STRING_BYTES (XSTRING (attribute
))
2958 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2959 + STRING_BYTES (XSTRING (class))
2960 + (STRINGP (subclass
)
2961 ? STRING_BYTES (XSTRING (subclass
)) : 0)
2964 /* Start with emacs.FRAMENAME for the name (the specific one)
2965 and with `Emacs' for the class key (the general one). */
2966 strcpy (name_key
, XSTRING (Vx_resource_name
)->data
);
2967 strcpy (class_key
, EMACS_CLASS
);
2969 strcat (class_key
, ".");
2970 strcat (class_key
, XSTRING (class)->data
);
2972 if (!NILP (component
))
2974 strcat (class_key
, ".");
2975 strcat (class_key
, XSTRING (subclass
)->data
);
2977 strcat (name_key
, ".");
2978 strcat (name_key
, XSTRING (component
)->data
);
2981 strcat (name_key
, ".");
2982 strcat (name_key
, XSTRING (attribute
)->data
);
2984 value
= x_get_string_resource (Qnil
,
2985 name_key
, class_key
);
2987 if (value
!= (char *) 0)
2988 return build_string (value
);
2993 /* Used when C code wants a resource value. */
2996 x_get_resource_string (attribute
, class)
2997 char *attribute
, *class;
3001 struct frame
*sf
= SELECTED_FRAME ();
3003 /* Allocate space for the components, the dots which separate them,
3004 and the final '\0'. */
3005 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vinvocation_name
))
3006 + strlen (attribute
) + 2);
3007 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
3008 + strlen (class) + 2);
3010 sprintf (name_key
, "%s.%s",
3011 XSTRING (Vinvocation_name
)->data
,
3013 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
3015 return x_get_string_resource (sf
, name_key
, class_key
);
3018 /* Types we might convert a resource string into. */
3028 /* Return the value of parameter PARAM.
3030 First search ALIST, then Vdefault_frame_alist, then the X defaults
3031 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3033 Convert the resource to the type specified by desired_type.
3035 If no default is specified, return Qunbound. If you call
3036 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
3037 and don't let it get stored in any Lisp-visible variables! */
3040 w32_get_arg (alist
, param
, attribute
, class, type
)
3041 Lisp_Object alist
, param
;
3044 enum resource_types type
;
3046 register Lisp_Object tem
;
3048 tem
= Fassq (param
, alist
);
3050 tem
= Fassq (param
, Vdefault_frame_alist
);
3056 tem
= Fx_get_resource (build_string (attribute
),
3057 build_string (class),
3065 case RES_TYPE_NUMBER
:
3066 return make_number (atoi (XSTRING (tem
)->data
));
3068 case RES_TYPE_FLOAT
:
3069 return make_float (atof (XSTRING (tem
)->data
));
3071 case RES_TYPE_BOOLEAN
:
3072 tem
= Fdowncase (tem
);
3073 if (!strcmp (XSTRING (tem
)->data
, "on")
3074 || !strcmp (XSTRING (tem
)->data
, "true"))
3079 case RES_TYPE_STRING
:
3082 case RES_TYPE_SYMBOL
:
3083 /* As a special case, we map the values `true' and `on'
3084 to Qt, and `false' and `off' to Qnil. */
3087 lower
= Fdowncase (tem
);
3088 if (!strcmp (XSTRING (lower
)->data
, "on")
3089 || !strcmp (XSTRING (lower
)->data
, "true"))
3091 else if (!strcmp (XSTRING (lower
)->data
, "off")
3092 || !strcmp (XSTRING (lower
)->data
, "false"))
3095 return Fintern (tem
, Qnil
);
3108 /* Record in frame F the specified or default value according to ALIST
3109 of the parameter named PROP (a Lisp symbol).
3110 If no value is specified for PROP, look for an X default for XPROP
3111 on the frame named NAME.
3112 If that is not found either, use the value DEFLT. */
3115 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3122 enum resource_types type
;
3126 tem
= w32_get_arg (alist
, prop
, xprop
, xclass
, type
);
3127 if (EQ (tem
, Qunbound
))
3129 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3133 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3134 "Parse an X-style geometry string STRING.\n\
3135 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
3136 The properties returned may include `top', `left', `height', and `width'.\n\
3137 The value of `left' or `top' may be an integer,\n\
3138 or a list (+ N) meaning N pixels relative to top/left corner,\n\
3139 or a list (- N) meaning -N pixels relative to bottom/right corner.")
3144 unsigned int width
, height
;
3147 CHECK_STRING (string
, 0);
3149 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
3150 &x
, &y
, &width
, &height
);
3153 if (geometry
& XValue
)
3155 Lisp_Object element
;
3157 if (x
>= 0 && (geometry
& XNegative
))
3158 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3159 else if (x
< 0 && ! (geometry
& XNegative
))
3160 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3162 element
= Fcons (Qleft
, make_number (x
));
3163 result
= Fcons (element
, result
);
3166 if (geometry
& YValue
)
3168 Lisp_Object element
;
3170 if (y
>= 0 && (geometry
& YNegative
))
3171 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3172 else if (y
< 0 && ! (geometry
& YNegative
))
3173 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3175 element
= Fcons (Qtop
, make_number (y
));
3176 result
= Fcons (element
, result
);
3179 if (geometry
& WidthValue
)
3180 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3181 if (geometry
& HeightValue
)
3182 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3187 /* Calculate the desired size and position of this window,
3188 and return the flags saying which aspects were specified.
3190 This function does not make the coordinates positive. */
3192 #define DEFAULT_ROWS 40
3193 #define DEFAULT_COLS 80
3196 x_figure_window_size (f
, parms
)
3200 register Lisp_Object tem0
, tem1
, tem2
;
3201 long window_prompting
= 0;
3203 /* Default values if we fall through.
3204 Actually, if that happens we should get
3205 window manager prompting. */
3206 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3207 f
->height
= DEFAULT_ROWS
;
3208 /* Window managers expect that if program-specified
3209 positions are not (0,0), they're intentional, not defaults. */
3210 f
->output_data
.w32
->top_pos
= 0;
3211 f
->output_data
.w32
->left_pos
= 0;
3213 tem0
= w32_get_arg (parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3214 tem1
= w32_get_arg (parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3215 tem2
= w32_get_arg (parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3216 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3218 if (!EQ (tem0
, Qunbound
))
3220 CHECK_NUMBER (tem0
, 0);
3221 f
->height
= XINT (tem0
);
3223 if (!EQ (tem1
, Qunbound
))
3225 CHECK_NUMBER (tem1
, 0);
3226 SET_FRAME_WIDTH (f
, XINT (tem1
));
3228 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3229 window_prompting
|= USSize
;
3231 window_prompting
|= PSize
;
3234 f
->output_data
.w32
->vertical_scroll_bar_extra
3235 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3237 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3238 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3239 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
3240 f
->output_data
.w32
->flags_areas_extra
3241 = FRAME_FLAGS_AREA_WIDTH (f
);
3242 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3243 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3245 tem0
= w32_get_arg (parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3246 tem1
= w32_get_arg (parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3247 tem2
= w32_get_arg (parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3248 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3250 if (EQ (tem0
, Qminus
))
3252 f
->output_data
.w32
->top_pos
= 0;
3253 window_prompting
|= YNegative
;
3255 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3256 && CONSP (XCDR (tem0
))
3257 && INTEGERP (XCAR (XCDR (tem0
))))
3259 f
->output_data
.w32
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3260 window_prompting
|= YNegative
;
3262 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3263 && CONSP (XCDR (tem0
))
3264 && INTEGERP (XCAR (XCDR (tem0
))))
3266 f
->output_data
.w32
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3268 else if (EQ (tem0
, Qunbound
))
3269 f
->output_data
.w32
->top_pos
= 0;
3272 CHECK_NUMBER (tem0
, 0);
3273 f
->output_data
.w32
->top_pos
= XINT (tem0
);
3274 if (f
->output_data
.w32
->top_pos
< 0)
3275 window_prompting
|= YNegative
;
3278 if (EQ (tem1
, Qminus
))
3280 f
->output_data
.w32
->left_pos
= 0;
3281 window_prompting
|= XNegative
;
3283 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3284 && CONSP (XCDR (tem1
))
3285 && INTEGERP (XCAR (XCDR (tem1
))))
3287 f
->output_data
.w32
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3288 window_prompting
|= XNegative
;
3290 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3291 && CONSP (XCDR (tem1
))
3292 && INTEGERP (XCAR (XCDR (tem1
))))
3294 f
->output_data
.w32
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3296 else if (EQ (tem1
, Qunbound
))
3297 f
->output_data
.w32
->left_pos
= 0;
3300 CHECK_NUMBER (tem1
, 0);
3301 f
->output_data
.w32
->left_pos
= XINT (tem1
);
3302 if (f
->output_data
.w32
->left_pos
< 0)
3303 window_prompting
|= XNegative
;
3306 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3307 window_prompting
|= USPosition
;
3309 window_prompting
|= PPosition
;
3312 return window_prompting
;
3317 extern LRESULT CALLBACK
w32_wnd_proc ();
3320 w32_init_class (hinst
)
3325 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3326 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
3328 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
3329 wc
.hInstance
= hinst
;
3330 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
3331 wc
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
3332 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
3333 wc
.lpszMenuName
= NULL
;
3334 wc
.lpszClassName
= EMACS_CLASS
;
3336 return (RegisterClass (&wc
));
3340 w32_createscrollbar (f
, bar
)
3342 struct scroll_bar
* bar
;
3344 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
3345 /* Position and size of scroll bar. */
3346 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3348 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3350 FRAME_W32_WINDOW (f
),
3357 w32_createwindow (f
)
3363 rect
.left
= rect
.top
= 0;
3364 rect
.right
= PIXEL_WIDTH (f
);
3365 rect
.bottom
= PIXEL_HEIGHT (f
);
3367 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3368 FRAME_EXTERNAL_MENU_BAR (f
));
3370 /* Do first time app init */
3374 w32_init_class (hinst
);
3377 FRAME_W32_WINDOW (f
) = hwnd
3378 = CreateWindow (EMACS_CLASS
,
3380 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
3381 f
->output_data
.w32
->left_pos
,
3382 f
->output_data
.w32
->top_pos
,
3383 rect
.right
- rect
.left
,
3384 rect
.bottom
- rect
.top
,
3392 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
3393 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
3394 SetWindowLong (hwnd
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
3395 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
3396 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3398 /* Enable drag-n-drop. */
3399 DragAcceptFiles (hwnd
, TRUE
);
3401 /* Do this to discard the default setting specified by our parent. */
3402 ShowWindow (hwnd
, SW_HIDE
);
3407 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
3414 wmsg
->msg
.hwnd
= hwnd
;
3415 wmsg
->msg
.message
= msg
;
3416 wmsg
->msg
.wParam
= wParam
;
3417 wmsg
->msg
.lParam
= lParam
;
3418 wmsg
->msg
.time
= GetMessageTime ();
3423 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
3424 between left and right keys as advertised. We test for this
3425 support dynamically, and set a flag when the support is absent. If
3426 absent, we keep track of the left and right control and alt keys
3427 ourselves. This is particularly necessary on keyboards that rely
3428 upon the AltGr key, which is represented as having the left control
3429 and right alt keys pressed. For these keyboards, we need to know
3430 when the left alt key has been pressed in addition to the AltGr key
3431 so that we can properly support M-AltGr-key sequences (such as M-@
3432 on Swedish keyboards). */
3434 #define EMACS_LCONTROL 0
3435 #define EMACS_RCONTROL 1
3436 #define EMACS_LMENU 2
3437 #define EMACS_RMENU 3
3439 static int modifiers
[4];
3440 static int modifiers_recorded
;
3441 static int modifier_key_support_tested
;
3444 test_modifier_support (unsigned int wparam
)
3448 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
3450 if (wparam
== VK_CONTROL
)
3460 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
3461 modifiers_recorded
= 1;
3463 modifiers_recorded
= 0;
3464 modifier_key_support_tested
= 1;
3468 record_keydown (unsigned int wparam
, unsigned int lparam
)
3472 if (!modifier_key_support_tested
)
3473 test_modifier_support (wparam
);
3475 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3478 if (wparam
== VK_CONTROL
)
3479 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3481 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3487 record_keyup (unsigned int wparam
, unsigned int lparam
)
3491 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3494 if (wparam
== VK_CONTROL
)
3495 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3497 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3502 /* Emacs can lose focus while a modifier key has been pressed. When
3503 it regains focus, be conservative and clear all modifiers since
3504 we cannot reconstruct the left and right modifier state. */
3510 if (GetFocus () == NULL
)
3511 /* Emacs doesn't have keyboard focus. Do nothing. */
3514 ctrl
= GetAsyncKeyState (VK_CONTROL
);
3515 alt
= GetAsyncKeyState (VK_MENU
);
3517 if (!(ctrl
& 0x08000))
3518 /* Clear any recorded control modifier state. */
3519 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3521 if (!(alt
& 0x08000))
3522 /* Clear any recorded alt modifier state. */
3523 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3525 /* Update the state of all modifier keys, because modifiers used in
3526 hot-key combinations can get stuck on if Emacs loses focus as a
3527 result of a hot-key being pressed. */
3531 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
3533 GetKeyboardState (keystate
);
3534 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
3535 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
3536 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
3537 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
3538 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
3539 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
3540 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
3541 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
3542 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
3543 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
3544 SetKeyboardState (keystate
);
3548 /* Synchronize modifier state with what is reported with the current
3549 keystroke. Even if we cannot distinguish between left and right
3550 modifier keys, we know that, if no modifiers are set, then neither
3551 the left or right modifier should be set. */
3555 if (!modifiers_recorded
)
3558 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
3559 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3561 if (!(GetKeyState (VK_MENU
) & 0x8000))
3562 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3566 modifier_set (int vkey
)
3568 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
3569 return (GetKeyState (vkey
) & 0x1);
3570 if (!modifiers_recorded
)
3571 return (GetKeyState (vkey
) & 0x8000);
3576 return modifiers
[EMACS_LCONTROL
];
3578 return modifiers
[EMACS_RCONTROL
];
3580 return modifiers
[EMACS_LMENU
];
3582 return modifiers
[EMACS_RMENU
];
3584 return (GetKeyState (vkey
) & 0x8000);
3587 /* Convert between the modifier bits W32 uses and the modifier bits
3591 w32_key_to_modifier (int key
)
3593 Lisp_Object key_mapping
;
3598 key_mapping
= Vw32_lwindow_modifier
;
3601 key_mapping
= Vw32_rwindow_modifier
;
3604 key_mapping
= Vw32_apps_modifier
;
3607 key_mapping
= Vw32_scroll_lock_modifier
;
3613 /* NB. This code runs in the input thread, asychronously to the lisp
3614 thread, so we must be careful to ensure access to lisp data is
3615 thread-safe. The following code is safe because the modifier
3616 variable values are updated atomically from lisp and symbols are
3617 not relocated by GC. Also, we don't have to worry about seeing GC
3619 if (EQ (key_mapping
, Qhyper
))
3620 return hyper_modifier
;
3621 if (EQ (key_mapping
, Qsuper
))
3622 return super_modifier
;
3623 if (EQ (key_mapping
, Qmeta
))
3624 return meta_modifier
;
3625 if (EQ (key_mapping
, Qalt
))
3626 return alt_modifier
;
3627 if (EQ (key_mapping
, Qctrl
))
3628 return ctrl_modifier
;
3629 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
3630 return ctrl_modifier
;
3631 if (EQ (key_mapping
, Qshift
))
3632 return shift_modifier
;
3634 /* Don't generate any modifier if not explicitly requested. */
3639 w32_get_modifiers ()
3641 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
3642 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
3643 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
3644 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
3645 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
3646 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
3647 (modifier_set (VK_MENU
) ?
3648 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
3651 /* We map the VK_* modifiers into console modifier constants
3652 so that we can use the same routines to handle both console
3653 and window input. */
3656 construct_console_modifiers ()
3661 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
3662 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
3663 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
3664 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
3665 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
3666 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
3667 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
3668 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
3669 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
3670 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
3671 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
3677 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
3681 /* Convert to emacs modifiers. */
3682 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
3688 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
3690 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
3693 if (virt_key
== VK_RETURN
)
3694 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
3696 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
3697 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
3699 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
3700 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
3702 if (virt_key
== VK_CLEAR
)
3703 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
3708 /* List of special key combinations which w32 would normally capture,
3709 but emacs should grab instead. Not directly visible to lisp, to
3710 simplify synchronization. Each item is an integer encoding a virtual
3711 key code and modifier combination to capture. */
3712 Lisp_Object w32_grabbed_keys
;
3714 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
3715 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
3716 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
3717 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
3719 /* Register hot-keys for reserved key combinations when Emacs has
3720 keyboard focus, since this is the only way Emacs can receive key
3721 combinations like Alt-Tab which are used by the system. */
3724 register_hot_keys (hwnd
)
3727 Lisp_Object keylist
;
3729 /* Use GC_CONSP, since we are called asynchronously. */
3730 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3732 Lisp_Object key
= XCAR (keylist
);
3734 /* Deleted entries get set to nil. */
3735 if (!INTEGERP (key
))
3738 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
3739 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
3744 unregister_hot_keys (hwnd
)
3747 Lisp_Object keylist
;
3749 /* Use GC_CONSP, since we are called asynchronously. */
3750 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3752 Lisp_Object key
= XCAR (keylist
);
3754 if (!INTEGERP (key
))
3757 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
3761 /* Main message dispatch loop. */
3764 w32_msg_pump (deferred_msg
* msg_buf
)
3770 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
3772 while (GetMessage (&msg
, NULL
, 0, 0))
3774 if (msg
.hwnd
== NULL
)
3776 switch (msg
.message
)
3779 /* Produced by complete_deferred_msg; just ignore. */
3781 case WM_EMACS_CREATEWINDOW
:
3782 w32_createwindow ((struct frame
*) msg
.wParam
);
3783 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3786 case WM_EMACS_SETLOCALE
:
3787 SetThreadLocale (msg
.wParam
);
3788 /* Reply is not expected. */
3790 case WM_EMACS_SETKEYBOARDLAYOUT
:
3791 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
3792 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3796 case WM_EMACS_REGISTER_HOT_KEY
:
3797 focus_window
= GetFocus ();
3798 if (focus_window
!= NULL
)
3799 RegisterHotKey (focus_window
,
3800 HOTKEY_ID (msg
.wParam
),
3801 HOTKEY_MODIFIERS (msg
.wParam
),
3802 HOTKEY_VK_CODE (msg
.wParam
));
3803 /* Reply is not expected. */
3805 case WM_EMACS_UNREGISTER_HOT_KEY
:
3806 focus_window
= GetFocus ();
3807 if (focus_window
!= NULL
)
3808 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
3809 /* Mark item as erased. NB: this code must be
3810 thread-safe. The next line is okay because the cons
3811 cell is never made into garbage and is not relocated by
3813 XCAR ((Lisp_Object
) msg
.lParam
) = Qnil
;
3814 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3817 case WM_EMACS_TOGGLE_LOCK_KEY
:
3819 int vk_code
= (int) msg
.wParam
;
3820 int cur_state
= (GetKeyState (vk_code
) & 1);
3821 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
3823 /* NB: This code must be thread-safe. It is safe to
3824 call NILP because symbols are not relocated by GC,
3825 and pointer here is not touched by GC (so the markbit
3826 can't be set). Numbers are safe because they are
3827 immediate values. */
3828 if (NILP (new_state
)
3829 || (NUMBERP (new_state
)
3830 && (XUINT (new_state
)) & 1 != cur_state
))
3832 one_w32_display_info
.faked_key
= vk_code
;
3834 keybd_event ((BYTE
) vk_code
,
3835 (BYTE
) MapVirtualKey (vk_code
, 0),
3836 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3837 keybd_event ((BYTE
) vk_code
,
3838 (BYTE
) MapVirtualKey (vk_code
, 0),
3839 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3840 keybd_event ((BYTE
) vk_code
,
3841 (BYTE
) MapVirtualKey (vk_code
, 0),
3842 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3843 cur_state
= !cur_state
;
3845 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3851 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
3856 DispatchMessage (&msg
);
3859 /* Exit nested loop when our deferred message has completed. */
3860 if (msg_buf
->completed
)
3865 deferred_msg
* deferred_msg_head
;
3867 static deferred_msg
*
3868 find_deferred_msg (HWND hwnd
, UINT msg
)
3870 deferred_msg
* item
;
3872 /* Don't actually need synchronization for read access, since
3873 modification of single pointer is always atomic. */
3874 /* enter_crit (); */
3876 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3877 if (item
->w32msg
.msg
.hwnd
== hwnd
3878 && item
->w32msg
.msg
.message
== msg
)
3881 /* leave_crit (); */
3887 send_deferred_msg (deferred_msg
* msg_buf
,
3893 /* Only input thread can send deferred messages. */
3894 if (GetCurrentThreadId () != dwWindowsThreadId
)
3897 /* It is an error to send a message that is already deferred. */
3898 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3901 /* Enforced synchronization is not needed because this is the only
3902 function that alters deferred_msg_head, and the following critical
3903 section is guaranteed to only be serially reentered (since only the
3904 input thread can call us). */
3906 /* enter_crit (); */
3908 msg_buf
->completed
= 0;
3909 msg_buf
->next
= deferred_msg_head
;
3910 deferred_msg_head
= msg_buf
;
3911 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
3913 /* leave_crit (); */
3915 /* Start a new nested message loop to process other messages until
3916 this one is completed. */
3917 w32_msg_pump (msg_buf
);
3919 deferred_msg_head
= msg_buf
->next
;
3921 return msg_buf
->result
;
3925 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
3927 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
3929 if (msg_buf
== NULL
)
3930 /* Message may have been cancelled, so don't abort(). */
3933 msg_buf
->result
= result
;
3934 msg_buf
->completed
= 1;
3936 /* Ensure input thread is woken so it notices the completion. */
3937 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3941 cancel_all_deferred_msgs ()
3943 deferred_msg
* item
;
3945 /* Don't actually need synchronization for read access, since
3946 modification of single pointer is always atomic. */
3947 /* enter_crit (); */
3949 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3952 item
->completed
= 1;
3955 /* leave_crit (); */
3957 /* Ensure input thread is woken so it notices the completion. */
3958 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3966 deferred_msg dummy_buf
;
3968 /* Ensure our message queue is created */
3970 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
3972 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3975 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
3976 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
3977 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
3979 /* This is the inital message loop which should only exit when the
3980 application quits. */
3981 w32_msg_pump (&dummy_buf
);
3987 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
3997 wmsg
.dwModifiers
= modifiers
;
3999 /* Detect quit_char and set quit-flag directly. Note that we
4000 still need to post a message to ensure the main thread will be
4001 woken up if blocked in sys_select(), but we do NOT want to post
4002 the quit_char message itself (because it will usually be as if
4003 the user had typed quit_char twice). Instead, we post a dummy
4004 message that has no particular effect. */
4007 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
4008 c
= make_ctrl_char (c
) & 0377;
4010 || (wmsg
.dwModifiers
== 0 &&
4011 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
4015 /* The choice of message is somewhat arbitrary, as long as
4016 the main thread handler just ignores it. */
4019 /* Interrupt any blocking system calls. */
4022 /* As a safety precaution, forcibly complete any deferred
4023 messages. This is a kludge, but I don't see any particularly
4024 clean way to handle the situation where a deferred message is
4025 "dropped" in the lisp thread, and will thus never be
4026 completed, eg. by the user trying to activate the menubar
4027 when the lisp thread is busy, and then typing C-g when the
4028 menubar doesn't open promptly (with the result that the
4029 menubar never responds at all because the deferred
4030 WM_INITMENU message is never completed). Another problem
4031 situation is when the lisp thread calls SendMessage (to send
4032 a window manager command) when a message has been deferred;
4033 the lisp thread gets blocked indefinitely waiting for the
4034 deferred message to be completed, which itself is waiting for
4035 the lisp thread to respond.
4037 Note that we don't want to block the input thread waiting for
4038 a reponse from the lisp thread (although that would at least
4039 solve the deadlock problem above), because we want to be able
4040 to receive C-g to interrupt the lisp thread. */
4041 cancel_all_deferred_msgs ();
4045 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4048 /* Main window procedure */
4051 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
4058 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4060 int windows_translate
;
4063 /* Note that it is okay to call x_window_to_frame, even though we are
4064 not running in the main lisp thread, because frame deletion
4065 requires the lisp thread to synchronize with this thread. Thus, if
4066 a frame struct is returned, it can be used without concern that the
4067 lisp thread might make it disappear while we are using it.
4069 NB. Walking the frame list in this thread is safe (as long as
4070 writes of Lisp_Object slots are atomic, which they are on Windows).
4071 Although delete-frame can destructively modify the frame list while
4072 we are walking it, a garbage collection cannot occur until after
4073 delete-frame has synchronized with this thread.
4075 It is also safe to use functions that make GDI calls, such as
4076 w32_clear_rect, because these functions must obtain a DC handle
4077 from the frame struct using get_frame_dc which is thread-aware. */
4082 f
= x_window_to_frame (dpyinfo
, hwnd
);
4085 HDC hdc
= get_frame_dc (f
);
4086 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
4087 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
4088 release_frame_dc (f
, hdc
);
4090 #if defined (W32_DEBUG_DISPLAY)
4091 DebPrint (("WM_ERASEBKGND: erasing %d,%d-%d,%d\n",
4092 wmsg
.rect
.left
, wmsg
.rect
.top
, wmsg
.rect
.right
,
4094 #endif /* W32_DEBUG_DISPLAY */
4097 case WM_PALETTECHANGED
:
4098 /* ignore our own changes */
4099 if ((HWND
)wParam
!= hwnd
)
4101 f
= x_window_to_frame (dpyinfo
, hwnd
);
4103 /* get_frame_dc will realize our palette and force all
4104 frames to be redrawn if needed. */
4105 release_frame_dc (f
, get_frame_dc (f
));
4110 PAINTSTRUCT paintStruct
;
4113 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
4114 fails. Apparently this can happen under some
4116 if (!w32_strict_painting
|| GetUpdateRect (hwnd
, &update_rect
, FALSE
))
4119 BeginPaint (hwnd
, &paintStruct
);
4121 if (w32_strict_painting
)
4122 /* The rectangles returned by GetUpdateRect and BeginPaint
4123 do not always match. GetUpdateRect seems to be the
4124 more reliable of the two. */
4125 wmsg
.rect
= update_rect
;
4127 wmsg
.rect
= paintStruct
.rcPaint
;
4129 #if defined (W32_DEBUG_DISPLAY)
4130 DebPrint (("WM_PAINT: painting %d,%d-%d,%d\n", wmsg
.rect
.left
,
4131 wmsg
.rect
.top
, wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4132 DebPrint (("WM_PAINT: update region is %d,%d-%d,%d\n",
4133 update_rect
.left
, update_rect
.top
,
4134 update_rect
.right
, update_rect
.bottom
));
4136 EndPaint (hwnd
, &paintStruct
);
4139 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4144 /* If GetUpdateRect returns 0 (meaning there is no update
4145 region), assume the whole window needs to be repainted. */
4146 GetClientRect(hwnd
, &wmsg
.rect
);
4147 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4151 case WM_INPUTLANGCHANGE
:
4152 /* Inform lisp thread of keyboard layout changes. */
4153 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4155 /* Clear dead keys in the keyboard state; for simplicity only
4156 preserve modifier key states. */
4161 GetKeyboardState (keystate
);
4162 for (i
= 0; i
< 256; i
++)
4179 SetKeyboardState (keystate
);
4184 /* Synchronize hot keys with normal input. */
4185 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
4190 record_keyup (wParam
, lParam
);
4195 /* Ignore keystrokes we fake ourself; see below. */
4196 if (dpyinfo
->faked_key
== wParam
)
4198 dpyinfo
->faked_key
= 0;
4199 /* Make sure TranslateMessage sees them though (as long as
4200 they don't produce WM_CHAR messages). This ensures that
4201 indicator lights are toggled promptly on Windows 9x, for
4203 if (lispy_function_keys
[wParam
] != 0)
4205 windows_translate
= 1;
4211 /* Synchronize modifiers with current keystroke. */
4213 record_keydown (wParam
, lParam
);
4214 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
4216 windows_translate
= 0;
4221 if (NILP (Vw32_pass_lwindow_to_system
))
4223 /* Prevent system from acting on keyup (which opens the
4224 Start menu if no other key was pressed) by simulating a
4225 press of Space which we will ignore. */
4226 if (GetAsyncKeyState (wParam
) & 1)
4228 if (NUMBERP (Vw32_phantom_key_code
))
4229 key
= XUINT (Vw32_phantom_key_code
) & 255;
4232 dpyinfo
->faked_key
= key
;
4233 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4236 if (!NILP (Vw32_lwindow_modifier
))
4240 if (NILP (Vw32_pass_rwindow_to_system
))
4242 if (GetAsyncKeyState (wParam
) & 1)
4244 if (NUMBERP (Vw32_phantom_key_code
))
4245 key
= XUINT (Vw32_phantom_key_code
) & 255;
4248 dpyinfo
->faked_key
= key
;
4249 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4252 if (!NILP (Vw32_rwindow_modifier
))
4256 if (!NILP (Vw32_apps_modifier
))
4260 if (NILP (Vw32_pass_alt_to_system
))
4261 /* Prevent DefWindowProc from activating the menu bar if an
4262 Alt key is pressed and released by itself. */
4264 windows_translate
= 1;
4267 /* Decide whether to treat as modifier or function key. */
4268 if (NILP (Vw32_enable_caps_lock
))
4269 goto disable_lock_key
;
4270 windows_translate
= 1;
4273 /* Decide whether to treat as modifier or function key. */
4274 if (NILP (Vw32_enable_num_lock
))
4275 goto disable_lock_key
;
4276 windows_translate
= 1;
4279 /* Decide whether to treat as modifier or function key. */
4280 if (NILP (Vw32_scroll_lock_modifier
))
4281 goto disable_lock_key
;
4282 windows_translate
= 1;
4285 /* Ensure the appropriate lock key state (and indicator light)
4286 remains in the same state. We do this by faking another
4287 press of the relevant key. Apparently, this really is the
4288 only way to toggle the state of the indicator lights. */
4289 dpyinfo
->faked_key
= wParam
;
4290 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4291 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4292 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4293 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4294 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4295 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4296 /* Ensure indicator lights are updated promptly on Windows 9x
4297 (TranslateMessage apparently does this), after forwarding
4299 post_character_message (hwnd
, msg
, wParam
, lParam
,
4300 w32_get_key_modifiers (wParam
, lParam
));
4301 windows_translate
= 1;
4305 case VK_PROCESSKEY
: /* Generated by IME. */
4306 windows_translate
= 1;
4309 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
4310 which is confusing for purposes of key binding; convert
4311 VK_CANCEL events into VK_PAUSE events. */
4315 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
4316 for purposes of key binding; convert these back into
4317 VK_NUMLOCK events, at least when we want to see NumLock key
4318 presses. (Note that there is never any possibility that
4319 VK_PAUSE with Ctrl really is C-Pause as per above.) */
4320 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
4321 wParam
= VK_NUMLOCK
;
4324 /* If not defined as a function key, change it to a WM_CHAR message. */
4325 if (lispy_function_keys
[wParam
] == 0)
4327 DWORD modifiers
= construct_console_modifiers ();
4329 if (!NILP (Vw32_recognize_altgr
)
4330 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
4332 /* Always let TranslateMessage handle AltGr key chords;
4333 for some reason, ToAscii doesn't always process AltGr
4334 chords correctly. */
4335 windows_translate
= 1;
4337 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
4339 /* Handle key chords including any modifiers other
4340 than shift directly, in order to preserve as much
4341 modifier information as possible. */
4342 if ('A' <= wParam
&& wParam
<= 'Z')
4344 /* Don't translate modified alphabetic keystrokes,
4345 so the user doesn't need to constantly switch
4346 layout to type control or meta keystrokes when
4347 the normal layout translates alphabetic
4348 characters to non-ascii characters. */
4349 if (!modifier_set (VK_SHIFT
))
4350 wParam
+= ('a' - 'A');
4355 /* Try to handle other keystrokes by determining the
4356 base character (ie. translating the base key plus
4360 KEY_EVENT_RECORD key
;
4362 key
.bKeyDown
= TRUE
;
4363 key
.wRepeatCount
= 1;
4364 key
.wVirtualKeyCode
= wParam
;
4365 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
4366 key
.uChar
.AsciiChar
= 0;
4367 key
.dwControlKeyState
= modifiers
;
4369 add
= w32_kbd_patch_key (&key
);
4370 /* 0 means an unrecognised keycode, negative means
4371 dead key. Ignore both. */
4374 /* Forward asciified character sequence. */
4375 post_character_message
4376 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
4377 w32_get_key_modifiers (wParam
, lParam
));
4378 w32_kbd_patch_key (&key
);
4385 /* Let TranslateMessage handle everything else. */
4386 windows_translate
= 1;
4392 if (windows_translate
)
4394 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
4396 windows_msg
.time
= GetMessageTime ();
4397 TranslateMessage (&windows_msg
);
4405 post_character_message (hwnd
, msg
, wParam
, lParam
,
4406 w32_get_key_modifiers (wParam
, lParam
));
4409 /* Simulate middle mouse button events when left and right buttons
4410 are used together, but only if user has two button mouse. */
4411 case WM_LBUTTONDOWN
:
4412 case WM_RBUTTONDOWN
:
4413 if (XINT (Vw32_num_mouse_buttons
) > 2)
4414 goto handle_plain_button
;
4417 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
4418 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
4420 if (button_state
& this)
4423 if (button_state
== 0)
4426 button_state
|= this;
4428 if (button_state
& other
)
4430 if (mouse_button_timer
)
4432 KillTimer (hwnd
, mouse_button_timer
);
4433 mouse_button_timer
= 0;
4435 /* Generate middle mouse event instead. */
4436 msg
= WM_MBUTTONDOWN
;
4437 button_state
|= MMOUSE
;
4439 else if (button_state
& MMOUSE
)
4441 /* Ignore button event if we've already generated a
4442 middle mouse down event. This happens if the
4443 user releases and press one of the two buttons
4444 after we've faked a middle mouse event. */
4449 /* Flush out saved message. */
4450 post_msg (&saved_mouse_button_msg
);
4452 wmsg
.dwModifiers
= w32_get_modifiers ();
4453 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4455 /* Clear message buffer. */
4456 saved_mouse_button_msg
.msg
.hwnd
= 0;
4460 /* Hold onto message for now. */
4461 mouse_button_timer
=
4462 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
4463 XINT (Vw32_mouse_button_tolerance
), NULL
);
4464 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
4465 saved_mouse_button_msg
.msg
.message
= msg
;
4466 saved_mouse_button_msg
.msg
.wParam
= wParam
;
4467 saved_mouse_button_msg
.msg
.lParam
= lParam
;
4468 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
4469 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
4476 if (XINT (Vw32_num_mouse_buttons
) > 2)
4477 goto handle_plain_button
;
4480 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
4481 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
4483 if ((button_state
& this) == 0)
4486 button_state
&= ~this;
4488 if (button_state
& MMOUSE
)
4490 /* Only generate event when second button is released. */
4491 if ((button_state
& other
) == 0)
4494 button_state
&= ~MMOUSE
;
4496 if (button_state
) abort ();
4503 /* Flush out saved message if necessary. */
4504 if (saved_mouse_button_msg
.msg
.hwnd
)
4506 post_msg (&saved_mouse_button_msg
);
4509 wmsg
.dwModifiers
= w32_get_modifiers ();
4510 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4512 /* Always clear message buffer and cancel timer. */
4513 saved_mouse_button_msg
.msg
.hwnd
= 0;
4514 KillTimer (hwnd
, mouse_button_timer
);
4515 mouse_button_timer
= 0;
4517 if (button_state
== 0)
4522 case WM_MBUTTONDOWN
:
4524 handle_plain_button
:
4529 if (parse_button (msg
, &button
, &up
))
4531 if (up
) ReleaseCapture ();
4532 else SetCapture (hwnd
);
4533 button
= (button
== 0) ? LMOUSE
:
4534 ((button
== 1) ? MMOUSE
: RMOUSE
);
4536 button_state
&= ~button
;
4538 button_state
|= button
;
4542 wmsg
.dwModifiers
= w32_get_modifiers ();
4543 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4548 if (XINT (Vw32_mouse_move_interval
) <= 0
4549 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4551 wmsg
.dwModifiers
= w32_get_modifiers ();
4552 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4556 /* Hang onto mouse move and scroll messages for a bit, to avoid
4557 sending such events to Emacs faster than it can process them.
4558 If we get more events before the timer from the first message
4559 expires, we just replace the first message. */
4561 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4563 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4564 XINT (Vw32_mouse_move_interval
), NULL
);
4566 /* Hold onto message for now. */
4567 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4568 saved_mouse_move_msg
.msg
.message
= msg
;
4569 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4570 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4571 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4572 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4577 wmsg
.dwModifiers
= w32_get_modifiers ();
4578 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4582 wmsg
.dwModifiers
= w32_get_modifiers ();
4583 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4587 /* Flush out saved messages if necessary. */
4588 if (wParam
== mouse_button_timer
)
4590 if (saved_mouse_button_msg
.msg
.hwnd
)
4592 post_msg (&saved_mouse_button_msg
);
4593 saved_mouse_button_msg
.msg
.hwnd
= 0;
4595 KillTimer (hwnd
, mouse_button_timer
);
4596 mouse_button_timer
= 0;
4598 else if (wParam
== mouse_move_timer
)
4600 if (saved_mouse_move_msg
.msg
.hwnd
)
4602 post_msg (&saved_mouse_move_msg
);
4603 saved_mouse_move_msg
.msg
.hwnd
= 0;
4605 KillTimer (hwnd
, mouse_move_timer
);
4606 mouse_move_timer
= 0;
4611 /* Windows doesn't send us focus messages when putting up and
4612 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4613 The only indication we get that something happened is receiving
4614 this message afterwards. So this is a good time to reset our
4615 keyboard modifiers' state. */
4622 /* We must ensure menu bar is fully constructed and up to date
4623 before allowing user interaction with it. To achieve this
4624 we send this message to the lisp thread and wait for a
4625 reply (whose value is not actually needed) to indicate that
4626 the menu bar is now ready for use, so we can now return.
4628 To remain responsive in the meantime, we enter a nested message
4629 loop that can process all other messages.
4631 However, we skip all this if the message results from calling
4632 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4633 thread a message because it is blocked on us at this point. We
4634 set menubar_active before calling TrackPopupMenu to indicate
4635 this (there is no possibility of confusion with real menubar
4638 f
= x_window_to_frame (dpyinfo
, hwnd
);
4640 && (f
->output_data
.w32
->menubar_active
4641 /* We can receive this message even in the absence of a
4642 menubar (ie. when the system menu is activated) - in this
4643 case we do NOT want to forward the message, otherwise it
4644 will cause the menubar to suddenly appear when the user
4645 had requested it to be turned off! */
4646 || f
->output_data
.w32
->menubar_widget
== NULL
))
4650 deferred_msg msg_buf
;
4652 /* Detect if message has already been deferred; in this case
4653 we cannot return any sensible value to ignore this. */
4654 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4657 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4660 case WM_EXITMENULOOP
:
4661 f
= x_window_to_frame (dpyinfo
, hwnd
);
4663 /* Indicate that menubar can be modified again. */
4665 f
->output_data
.w32
->menubar_active
= 0;
4669 wmsg
.dwModifiers
= w32_get_modifiers ();
4670 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4673 case WM_MEASUREITEM
:
4674 f
= x_window_to_frame (dpyinfo
, hwnd
);
4677 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4679 if (pMis
->CtlType
== ODT_MENU
)
4681 /* Work out dimensions for popup menu titles. */
4682 char * title
= (char *) pMis
->itemData
;
4683 HDC hdc
= GetDC (hwnd
);
4684 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4685 LOGFONT menu_logfont
;
4689 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4690 menu_logfont
.lfWeight
= FW_BOLD
;
4691 menu_font
= CreateFontIndirect (&menu_logfont
);
4692 old_font
= SelectObject (hdc
, menu_font
);
4694 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4697 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4698 pMis
->itemWidth
= size
.cx
;
4699 if (pMis
->itemHeight
< size
.cy
)
4700 pMis
->itemHeight
= size
.cy
;
4703 pMis
->itemWidth
= 0;
4705 SelectObject (hdc
, old_font
);
4706 DeleteObject (menu_font
);
4707 ReleaseDC (hwnd
, hdc
);
4714 f
= x_window_to_frame (dpyinfo
, hwnd
);
4717 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4719 if (pDis
->CtlType
== ODT_MENU
)
4721 /* Draw popup menu title. */
4722 char * title
= (char *) pDis
->itemData
;
4725 HDC hdc
= pDis
->hDC
;
4726 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4727 LOGFONT menu_logfont
;
4730 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4731 menu_logfont
.lfWeight
= FW_BOLD
;
4732 menu_font
= CreateFontIndirect (&menu_logfont
);
4733 old_font
= SelectObject (hdc
, menu_font
);
4735 /* Always draw title as if not selected. */
4738 + GetSystemMetrics (SM_CXMENUCHECK
),
4740 ETO_OPAQUE
, &pDis
->rcItem
,
4741 title
, strlen (title
), NULL
);
4743 SelectObject (hdc
, old_font
);
4744 DeleteObject (menu_font
);
4752 /* Still not right - can't distinguish between clicks in the
4753 client area of the frame from clicks forwarded from the scroll
4754 bars - may have to hook WM_NCHITTEST to remember the mouse
4755 position and then check if it is in the client area ourselves. */
4756 case WM_MOUSEACTIVATE
:
4757 /* Discard the mouse click that activates a frame, allowing the
4758 user to click anywhere without changing point (or worse!).
4759 Don't eat mouse clicks on scrollbars though!! */
4760 if (LOWORD (lParam
) == HTCLIENT
)
4761 return MA_ACTIVATEANDEAT
;
4765 case WM_ACTIVATEAPP
:
4767 case WM_WINDOWPOSCHANGED
:
4769 /* Inform lisp thread that a frame might have just been obscured
4770 or exposed, so should recheck visibility of all frames. */
4771 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4775 dpyinfo
->faked_key
= 0;
4777 register_hot_keys (hwnd
);
4780 unregister_hot_keys (hwnd
);
4787 wmsg
.dwModifiers
= w32_get_modifiers ();
4788 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4792 wmsg
.dwModifiers
= w32_get_modifiers ();
4793 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4796 case WM_WINDOWPOSCHANGING
:
4799 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
4801 wp
.length
= sizeof (WINDOWPLACEMENT
);
4802 GetWindowPlacement (hwnd
, &wp
);
4804 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
4811 DWORD internal_border
;
4812 DWORD scrollbar_extra
;
4815 wp
.length
= sizeof(wp
);
4816 GetWindowRect (hwnd
, &wr
);
4820 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
4821 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
4822 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
4823 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
4827 memset (&rect
, 0, sizeof (rect
));
4828 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
4829 GetMenu (hwnd
) != NULL
);
4831 /* Force width and height of client area to be exact
4832 multiples of the character cell dimensions. */
4833 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
4834 - 2 * internal_border
- scrollbar_extra
)
4836 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
4837 - 2 * internal_border
)
4842 /* For right/bottom sizing we can just fix the sizes.
4843 However for top/left sizing we will need to fix the X
4844 and Y positions as well. */
4849 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
4850 && (lppos
->flags
& SWP_NOMOVE
) == 0)
4852 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
4859 lppos
->flags
|= SWP_NOMOVE
;
4870 case WM_GETMINMAXINFO
:
4871 /* Hack to correct bug that allows Emacs frames to be resized
4872 below the Minimum Tracking Size. */
4873 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
4876 case WM_EMACS_CREATESCROLLBAR
:
4877 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
4878 (struct scroll_bar
*) lParam
);
4880 case WM_EMACS_SHOWWINDOW
:
4881 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4883 case WM_EMACS_SETFOREGROUND
:
4885 HWND foreground_window
;
4886 DWORD foreground_thread
, retval
;
4888 /* On NT 5.0, and apparently Windows 98, it is necessary to
4889 attach to the thread that currently has focus in order to
4890 pull the focus away from it. */
4891 foreground_window
= GetForegroundWindow ();
4892 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4893 if (!foreground_window
4894 || foreground_thread
== GetCurrentThreadId ()
4895 || !AttachThreadInput (GetCurrentThreadId (),
4896 foreground_thread
, TRUE
))
4897 foreground_thread
= 0;
4899 retval
= SetForegroundWindow ((HWND
) wParam
);
4901 /* Detach from the previous foreground thread. */
4902 if (foreground_thread
)
4903 AttachThreadInput (GetCurrentThreadId (),
4904 foreground_thread
, FALSE
);
4909 case WM_EMACS_SETWINDOWPOS
:
4911 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4912 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4913 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4916 case WM_EMACS_DESTROYWINDOW
:
4917 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4918 return DestroyWindow ((HWND
) wParam
);
4920 case WM_EMACS_TRACKPOPUPMENU
:
4925 pos
= (POINT
*)lParam
;
4926 flags
= TPM_CENTERALIGN
;
4927 if (button_state
& LMOUSE
)
4928 flags
|= TPM_LEFTBUTTON
;
4929 else if (button_state
& RMOUSE
)
4930 flags
|= TPM_RIGHTBUTTON
;
4932 /* Remember we did a SetCapture on the initial mouse down event,
4933 so for safety, we make sure the capture is cancelled now. */
4937 /* Use menubar_active to indicate that WM_INITMENU is from
4938 TrackPopupMenu below, and should be ignored. */
4939 f
= x_window_to_frame (dpyinfo
, hwnd
);
4941 f
->output_data
.w32
->menubar_active
= 1;
4943 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4947 /* Eat any mouse messages during popupmenu */
4948 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4950 /* Get the menu selection, if any */
4951 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4953 retval
= LOWORD (amsg
.wParam
);
4969 /* Check for messages registered at runtime. */
4970 if (msg
== msh_mousewheel
)
4972 wmsg
.dwModifiers
= w32_get_modifiers ();
4973 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4978 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
4982 /* The most common default return code for handled messages is 0. */
4987 my_create_window (f
)
4992 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4994 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
4997 /* Create and set up the w32 window for frame F. */
5000 w32_window (f
, window_prompting
, minibuffer_only
)
5002 long window_prompting
;
5003 int minibuffer_only
;
5007 /* Use the resource name as the top-level window name
5008 for looking up resources. Make a non-Lisp copy
5009 for the window manager, so GC relocation won't bother it.
5011 Elsewhere we specify the window name for the window manager. */
5014 char *str
= (char *) XSTRING (Vx_resource_name
)->data
;
5015 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
5016 strcpy (f
->namebuf
, str
);
5019 my_create_window (f
);
5021 validate_x_resource_name ();
5023 /* x_set_name normally ignores requests to set the name if the
5024 requested name is the same as the current name. This is the one
5025 place where that assumption isn't correct; f->name is set, but
5026 the server hasn't been told. */
5029 int explicit = f
->explicit_name
;
5031 f
->explicit_name
= 0;
5034 x_set_name (f
, name
, explicit);
5039 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
5040 initialize_frame_menubar (f
);
5042 if (FRAME_W32_WINDOW (f
) == 0)
5043 error ("Unable to create window");
5046 /* Handle the icon stuff for this window. Perhaps later we might
5047 want an x_set_icon_position which can be called interactively as
5055 Lisp_Object icon_x
, icon_y
;
5057 /* Set the position of the icon. Note that Windows 95 groups all
5058 icons in the tray. */
5059 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
5060 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
5061 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
5063 CHECK_NUMBER (icon_x
, 0);
5064 CHECK_NUMBER (icon_y
, 0);
5066 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
5067 error ("Both left and top icon corners of icon must be specified");
5071 if (! EQ (icon_x
, Qunbound
))
5072 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
5075 /* Start up iconic or window? */
5076 x_wm_set_window_state
5077 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
5081 x_text_icon (f
, (char *) XSTRING ((!NILP (f
->icon_name
)
5094 XGCValues gc_values
;
5098 /* Create the GC's of this frame.
5099 Note that many default values are used. */
5102 gc_values
.font
= f
->output_data
.w32
->font
;
5104 /* Cursor has cursor-color background, background-color foreground. */
5105 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
5106 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
5107 f
->output_data
.w32
->cursor_gc
5108 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
5109 (GCFont
| GCForeground
| GCBackground
),
5113 f
->output_data
.w32
->white_relief
.gc
= 0;
5114 f
->output_data
.w32
->black_relief
.gc
= 0;
5120 /* Handler for signals raised during x_create_frame and
5121 x_create_top_frame. FRAME is the frame which is partially
5125 unwind_create_frame (frame
)
5128 struct frame
*f
= XFRAME (frame
);
5130 /* If frame is ``official'', nothing to do. */
5131 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
5134 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5137 x_free_frame_resources (f
);
5139 /* Check that reference counts are indeed correct. */
5140 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
5141 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
5150 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
5152 "Make a new window, which is called a \"frame\" in Emacs terms.\n\
5153 Returns an Emacs frame object.\n\
5154 ALIST is an alist of frame parameters.\n\
5155 If the parameters specify that the frame should not have a minibuffer,\n\
5156 and do not specify a specific minibuffer window to use,\n\
5157 then `default-minibuffer-frame' must be a frame whose minibuffer can\n\
5158 be shared by the new frame.\n\
5160 This function is an internal primitive--use `make-frame' instead.")
5165 Lisp_Object frame
, tem
;
5167 int minibuffer_only
= 0;
5168 long window_prompting
= 0;
5170 int count
= specpdl_ptr
- specpdl
;
5171 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5172 Lisp_Object display
;
5173 struct w32_display_info
*dpyinfo
= NULL
;
5179 /* Use this general default value to start with
5180 until we know if this frame has a specified name. */
5181 Vx_resource_name
= Vinvocation_name
;
5183 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
5184 if (EQ (display
, Qunbound
))
5186 dpyinfo
= check_x_display_info (display
);
5188 kb
= dpyinfo
->kboard
;
5190 kb
= &the_only_kboard
;
5193 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5195 && ! EQ (name
, Qunbound
)
5197 error ("Invalid frame name--not a string or nil");
5200 Vx_resource_name
= name
;
5202 /* See if parent window is specified. */
5203 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
5204 if (EQ (parent
, Qunbound
))
5206 if (! NILP (parent
))
5207 CHECK_NUMBER (parent
, 0);
5209 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
5210 /* No need to protect DISPLAY because that's not used after passing
5211 it to make_frame_without_minibuffer. */
5213 GCPRO4 (parms
, parent
, name
, frame
);
5214 tem
= w32_get_arg (parms
, Qminibuffer
, "minibuffer", "Minibuffer",
5216 if (EQ (tem
, Qnone
) || NILP (tem
))
5217 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
5218 else if (EQ (tem
, Qonly
))
5220 f
= make_minibuffer_frame ();
5221 minibuffer_only
= 1;
5223 else if (WINDOWP (tem
))
5224 f
= make_frame_without_minibuffer (tem
, kb
, display
);
5228 XSETFRAME (frame
, f
);
5230 /* Note that Windows does support scroll bars. */
5231 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
5232 /* By default, make scrollbars the system standard width. */
5233 f
->scroll_bar_pixel_width
= GetSystemMetrics (SM_CXVSCROLL
);
5235 f
->output_method
= output_w32
;
5236 f
->output_data
.w32
=
5237 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5238 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5239 FRAME_FONTSET (f
) = -1;
5240 record_unwind_protect (unwind_create_frame
, frame
);
5243 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
5244 if (! STRINGP (f
->icon_name
))
5245 f
->icon_name
= Qnil
;
5247 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
5249 FRAME_KBOARD (f
) = kb
;
5252 /* Specify the parent under which to make this window. */
5256 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
5257 f
->output_data
.w32
->explicit_parent
= 1;
5261 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5262 f
->output_data
.w32
->explicit_parent
= 0;
5265 /* Set the name; the functions to which we pass f expect the name to
5267 if (EQ (name
, Qunbound
) || NILP (name
))
5269 f
->name
= build_string (dpyinfo
->w32_id_name
);
5270 f
->explicit_name
= 0;
5275 f
->explicit_name
= 1;
5276 /* use the frame's title when getting resources for this frame. */
5277 specbind (Qx_resource_name
, name
);
5280 /* Extract the window parameters from the supplied values
5281 that are needed to determine window geometry. */
5285 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
5288 /* First, try whatever font the caller has specified. */
5291 tem
= Fquery_fontset (font
, Qnil
);
5293 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
5295 font
= x_new_font (f
, XSTRING (font
)->data
);
5297 /* Try out a font which we hope has bold and italic variations. */
5298 if (!STRINGP (font
))
5299 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
5300 if (! STRINGP (font
))
5301 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5302 /* If those didn't work, look for something which will at least work. */
5303 if (! STRINGP (font
))
5304 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
5306 if (! STRINGP (font
))
5307 font
= build_string ("Fixedsys");
5309 x_default_parameter (f
, parms
, Qfont
, font
,
5310 "font", "Font", RES_TYPE_STRING
);
5313 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5314 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5315 /* This defaults to 2 in order to match xterm. We recognize either
5316 internalBorderWidth or internalBorder (which is what xterm calls
5318 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5322 value
= w32_get_arg (parms
, Qinternal_border_width
,
5323 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
5324 if (! EQ (value
, Qunbound
))
5325 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5328 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5329 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
5330 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
5331 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qright
,
5332 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5334 /* Also do the stuff which must be set before the window exists. */
5335 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5336 "foreground", "Foreground", RES_TYPE_STRING
);
5337 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5338 "background", "Background", RES_TYPE_STRING
);
5339 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5340 "pointerColor", "Foreground", RES_TYPE_STRING
);
5341 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5342 "cursorColor", "Foreground", RES_TYPE_STRING
);
5343 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5344 "borderColor", "BorderColor", RES_TYPE_STRING
);
5345 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
5346 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5347 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
5348 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
5351 /* Init faces before x_default_parameter is called for scroll-bar
5352 parameters because that function calls x_set_scroll_bar_width,
5353 which calls change_frame_size, which calls Fset_window_buffer,
5354 which runs hooks, which call Fvertical_motion. At the end, we
5355 end up in init_iterator with a null face cache, which should not
5357 init_frame_faces (f
);
5359 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
5360 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
5361 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (0),
5362 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
5363 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
5364 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5365 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
5366 "title", "Title", RES_TYPE_STRING
);
5368 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5369 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5370 window_prompting
= x_figure_window_size (f
, parms
);
5372 if (window_prompting
& XNegative
)
5374 if (window_prompting
& YNegative
)
5375 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
5377 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
5381 if (window_prompting
& YNegative
)
5382 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
5384 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
5387 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
5389 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5390 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5392 /* Create the window. Add the tool-bar height to the initial frame
5393 height so that the user gets a text display area of the size he
5394 specified with -g or via the registry. Later changes of the
5395 tool-bar height don't change the frame size. This is done so that
5396 users can create tall Emacs frames without having to guess how
5397 tall the tool-bar will get. */
5398 f
->height
+= FRAME_TOOL_BAR_LINES (f
);
5399 w32_window (f
, window_prompting
, minibuffer_only
);
5404 /* Now consider the frame official. */
5405 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5406 Vframe_list
= Fcons (frame
, Vframe_list
);
5408 /* We need to do this after creating the window, so that the
5409 icon-creation functions can say whose icon they're describing. */
5410 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
5411 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5413 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5414 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5415 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5416 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5417 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5418 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5419 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
5420 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5422 /* Dimensions, especially f->height, must be done via change_frame_size.
5423 Change will not be effected unless different from the current
5428 SET_FRAME_WIDTH (f
, 0);
5429 change_frame_size (f
, height
, width
, 1, 0, 0);
5431 /* Tell the server what size and position, etc, we want, and how
5432 badly we want them. This should be done after we have the menu
5433 bar so that its size can be taken into account. */
5435 x_wm_set_size_hint (f
, window_prompting
, 0);
5438 /* Set up faces after all frame parameters are known. This call
5439 also merges in face attributes specified for new frames. If we
5440 don't do this, the `menu' face for instance won't have the right
5441 colors, and the menu bar won't appear in the specified colors for
5443 call1 (Qface_set_after_frame_default
, frame
);
5445 /* Make the window appear on the frame and enable display, unless
5446 the caller says not to. However, with explicit parent, Emacs
5447 cannot control visibility, so don't try. */
5448 if (! f
->output_data
.w32
->explicit_parent
)
5450 Lisp_Object visibility
;
5452 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5453 if (EQ (visibility
, Qunbound
))
5456 if (EQ (visibility
, Qicon
))
5457 x_iconify_frame (f
);
5458 else if (! NILP (visibility
))
5459 x_make_frame_visible (f
);
5461 /* Must have been Qnil. */
5465 return unbind_to (count
, frame
);
5468 /* FRAME is used only to get a handle on the X display. We don't pass the
5469 display info directly because we're called from frame.c, which doesn't
5470 know about that structure. */
5472 x_get_focus_frame (frame
)
5473 struct frame
*frame
;
5475 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
5477 if (! dpyinfo
->w32_focus_frame
)
5480 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5484 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
5485 "Give FRAME input focus, raising to foreground if necessary.")
5489 x_focus_on_frame (check_x_frame (frame
));
5494 /* Return the charset portion of a font name. */
5495 char * xlfd_charset_of_font (char * fontname
)
5497 char *charset
, *encoding
;
5499 encoding
= strrchr(fontname
, '-');
5500 if (!encoding
|| encoding
== fontname
)
5503 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
5504 if (*charset
== '-')
5507 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
5513 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
5514 int size
, char* filename
);
5515 BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
, char * charset
);
5518 w32_load_system_font (f
,fontname
,size
)
5523 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5524 Lisp_Object font_names
;
5526 /* Get a list of all the fonts that match this name. Once we
5527 have a list of matching fonts, we compare them against the fonts
5528 we already have loaded by comparing names. */
5529 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
5531 if (!NILP (font_names
))
5536 /* First check if any are already loaded, as that is cheaper
5537 than loading another one. */
5538 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5539 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
5540 if (dpyinfo
->font_table
[i
].name
5541 && (!strcmp (dpyinfo
->font_table
[i
].name
,
5542 XSTRING (XCAR (tail
))->data
)
5543 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
5544 XSTRING (XCAR (tail
))->data
)))
5545 return (dpyinfo
->font_table
+ i
);
5547 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
5549 else if (w32_strict_fontnames
)
5551 /* If EnumFontFamiliesEx was available, we got a full list of
5552 fonts back so stop now to avoid the possibility of loading a
5553 random font. If we had to fall back to EnumFontFamilies, the
5554 list is incomplete, so continue whether the font we want was
5556 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5557 FARPROC enum_font_families_ex
5558 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
5559 if (enum_font_families_ex
)
5563 /* Load the font and add it to the table. */
5565 char *full_name
, *encoding
, *charset
;
5567 struct font_info
*fontp
;
5572 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
5575 if (!*lf
.lfFaceName
)
5576 /* If no name was specified for the font, we get a random font
5577 from CreateFontIndirect - this is not particularly
5578 desirable, especially since CreateFontIndirect does not
5579 fill out the missing name in lf, so we never know what we
5583 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
5584 bzero (font
, sizeof (*font
));
5586 /* Set bdf to NULL to indicate that this is a Windows font. */
5591 font
->hfont
= CreateFontIndirect (&lf
);
5593 if (font
->hfont
== NULL
)
5601 int codepage
= w32_codepage_for_font (fontname
);
5603 hdc
= GetDC (dpyinfo
->root_window
);
5604 oldobj
= SelectObject (hdc
, font
->hfont
);
5606 ok
= GetTextMetrics (hdc
, &font
->tm
);
5607 if (codepage
== CP_UNICODE
)
5608 font
->double_byte_p
= 1;
5610 font
->double_byte_p
= GetFontLanguageInfo(hdc
) & GCP_DBCS
;
5612 SelectObject (hdc
, oldobj
);
5613 ReleaseDC (dpyinfo
->root_window
, hdc
);
5614 /* Fill out details in lf according to the font that was
5616 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
5617 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
5618 lf
.lfWeight
= font
->tm
.tmWeight
;
5619 lf
.lfItalic
= font
->tm
.tmItalic
;
5620 lf
.lfCharSet
= font
->tm
.tmCharSet
;
5621 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
5622 ? VARIABLE_PITCH
: FIXED_PITCH
);
5623 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
5624 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
5626 w32_cache_char_metrics (font
);
5633 w32_unload_font (dpyinfo
, font
);
5637 /* Find a free slot in the font table. */
5638 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
5639 if (dpyinfo
->font_table
[i
].name
== NULL
)
5642 /* If no free slot found, maybe enlarge the font table. */
5643 if (i
== dpyinfo
->n_fonts
5644 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
5647 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
5648 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
5650 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
5653 fontp
= dpyinfo
->font_table
+ i
;
5654 if (i
== dpyinfo
->n_fonts
)
5657 /* Now fill in the slots of *FONTP. */
5660 fontp
->font_idx
= i
;
5661 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
5662 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
5664 charset
= xlfd_charset_of_font (fontname
);
5666 /* Work out the font's full name. */
5667 full_name
= (char *)xmalloc (100);
5668 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
5669 fontp
->full_name
= full_name
;
5672 /* If all else fails - just use the name we used to load it. */
5674 fontp
->full_name
= fontp
->name
;
5677 fontp
->size
= FONT_WIDTH (font
);
5678 fontp
->height
= FONT_HEIGHT (font
);
5680 /* The slot `encoding' specifies how to map a character
5681 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
5682 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
5683 (0:0x20..0x7F, 1:0xA0..0xFF,
5684 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
5685 2:0xA020..0xFF7F). For the moment, we don't know which charset
5686 uses this font. So, we set information in fontp->encoding[1]
5687 which is never used by any charset. If mapping can't be
5688 decided, set FONT_ENCODING_NOT_DECIDED. */
5690 /* SJIS fonts need to be set to type 4, all others seem to work as
5691 type FONT_ENCODING_NOT_DECIDED. */
5692 encoding
= strrchr (fontp
->name
, '-');
5693 if (encoding
&& stricmp (encoding
+1, "sjis") == 0)
5694 fontp
->encoding
[1] = 4;
5696 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
5698 /* The following three values are set to 0 under W32, which is
5699 what they get set to if XGetFontProperty fails under X. */
5700 fontp
->baseline_offset
= 0;
5701 fontp
->relative_compose
= 0;
5702 fontp
->default_ascent
= 0;
5704 /* Set global flag fonts_changed_p to non-zero if the font loaded
5705 has a character with a smaller width than any other character
5706 before, or if the font loaded has a smalle>r height than any
5707 other font loaded before. If this happens, it will make a
5708 glyph matrix reallocation necessary. */
5709 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
5715 /* Load font named FONTNAME of size SIZE for frame F, and return a
5716 pointer to the structure font_info while allocating it dynamically.
5717 If loading fails, return NULL. */
5719 w32_load_font (f
,fontname
,size
)
5724 Lisp_Object bdf_fonts
;
5725 struct font_info
*retval
= NULL
;
5727 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
));
5729 while (!retval
&& CONSP (bdf_fonts
))
5731 char *bdf_name
, *bdf_file
;
5732 Lisp_Object bdf_pair
;
5734 bdf_name
= XSTRING (XCAR (bdf_fonts
))->data
;
5735 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
5736 bdf_file
= XSTRING (XCDR (bdf_pair
))->data
;
5738 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
5740 bdf_fonts
= XCDR (bdf_fonts
);
5746 return w32_load_system_font(f
, fontname
, size
);
5751 w32_unload_font (dpyinfo
, font
)
5752 struct w32_display_info
*dpyinfo
;
5757 if (font
->per_char
) xfree (font
->per_char
);
5758 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
5760 if (font
->hfont
) DeleteObject(font
->hfont
);
5765 /* The font conversion stuff between x and w32 */
5767 /* X font string is as follows (from faces.el)
5771 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
5772 * (weight\? "\\([^-]*\\)") ; 1
5773 * (slant "\\([ior]\\)") ; 2
5774 * (slant\? "\\([^-]?\\)") ; 2
5775 * (swidth "\\([^-]*\\)") ; 3
5776 * (adstyle "[^-]*") ; 4
5777 * (pixelsize "[0-9]+")
5778 * (pointsize "[0-9][0-9]+")
5779 * (resx "[0-9][0-9]+")
5780 * (resy "[0-9][0-9]+")
5781 * (spacing "[cmp?*]")
5782 * (avgwidth "[0-9]+")
5783 * (registry "[^-]+")
5784 * (encoding "[^-]+")
5789 x_to_w32_weight (lpw
)
5792 if (!lpw
) return (FW_DONTCARE
);
5794 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
5795 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
5796 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
5797 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
5798 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
5799 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
5800 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
5801 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
5802 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
5803 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
5810 w32_to_x_weight (fnweight
)
5813 if (fnweight
>= FW_HEAVY
) return "heavy";
5814 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
5815 if (fnweight
>= FW_BOLD
) return "bold";
5816 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
5817 if (fnweight
>= FW_MEDIUM
) return "medium";
5818 if (fnweight
>= FW_NORMAL
) return "normal";
5819 if (fnweight
>= FW_LIGHT
) return "light";
5820 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
5821 if (fnweight
>= FW_THIN
) return "thin";
5827 x_to_w32_charset (lpcs
)
5830 Lisp_Object this_entry
, w32_charset
;
5832 /* Look through w32-charset-info-alist for the character set.
5833 Format of each entry is
5834 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5836 this_entry
= Fassoc (build_string(lpcs
), Vw32_charset_info_alist
);
5838 if (NILP(this_entry
))
5840 /* At startup, we want iso8859-1 fonts to come up properly. */
5841 if (stricmp(lpcs
, "iso8859-1") == 0)
5842 return ANSI_CHARSET
;
5844 return DEFAULT_CHARSET
;
5847 w32_charset
= Fcar (Fcdr (this_entry
));
5849 // Translate Lisp symbol to number.
5850 if (w32_charset
== Qw32_charset_ansi
)
5851 return ANSI_CHARSET
;
5852 if (w32_charset
== Qw32_charset_symbol
)
5853 return SYMBOL_CHARSET
;
5854 if (w32_charset
== Qw32_charset_shiftjis
)
5855 return SHIFTJIS_CHARSET
;
5856 if (w32_charset
== Qw32_charset_hangeul
)
5857 return HANGEUL_CHARSET
;
5858 if (w32_charset
== Qw32_charset_chinesebig5
)
5859 return CHINESEBIG5_CHARSET
;
5860 if (w32_charset
== Qw32_charset_gb2312
)
5861 return GB2312_CHARSET
;
5862 if (w32_charset
== Qw32_charset_oem
)
5864 #ifdef JOHAB_CHARSET
5865 if (w32_charset
== Qw32_charset_johab
)
5866 return JOHAB_CHARSET
;
5867 if (w32_charset
== Qw32_charset_easteurope
)
5868 return EASTEUROPE_CHARSET
;
5869 if (w32_charset
== Qw32_charset_turkish
)
5870 return TURKISH_CHARSET
;
5871 if (w32_charset
== Qw32_charset_baltic
)
5872 return BALTIC_CHARSET
;
5873 if (w32_charset
== Qw32_charset_russian
)
5874 return RUSSIAN_CHARSET
;
5875 if (w32_charset
== Qw32_charset_arabic
)
5876 return ARABIC_CHARSET
;
5877 if (w32_charset
== Qw32_charset_greek
)
5878 return GREEK_CHARSET
;
5879 if (w32_charset
== Qw32_charset_hebrew
)
5880 return HEBREW_CHARSET
;
5881 if (w32_charset
== Qw32_charset_vietnamese
)
5882 return VIETNAMESE_CHARSET
;
5883 if (w32_charset
== Qw32_charset_thai
)
5884 return THAI_CHARSET
;
5885 if (w32_charset
== Qw32_charset_mac
)
5887 #endif /* JOHAB_CHARSET */
5888 #ifdef UNICODE_CHARSET
5889 if (w32_charset
== Qw32_charset_unicode
)
5890 return UNICODE_CHARSET
;
5893 return DEFAULT_CHARSET
;
5898 w32_to_x_charset (fncharset
)
5901 static char buf
[16];
5902 Lisp_Object charset_type
;
5907 /* Handle startup case of w32-charset-info-alist not
5908 being set up yet. */
5909 if (NILP(Vw32_charset_info_alist
))
5911 charset_type
= Qw32_charset_ansi
;
5913 case DEFAULT_CHARSET
:
5914 charset_type
= Qw32_charset_default
;
5916 case SYMBOL_CHARSET
:
5917 charset_type
= Qw32_charset_symbol
;
5919 case SHIFTJIS_CHARSET
:
5920 charset_type
= Qw32_charset_shiftjis
;
5922 case HANGEUL_CHARSET
:
5923 charset_type
= Qw32_charset_hangeul
;
5925 case GB2312_CHARSET
:
5926 charset_type
= Qw32_charset_gb2312
;
5928 case CHINESEBIG5_CHARSET
:
5929 charset_type
= Qw32_charset_chinesebig5
;
5932 charset_type
= Qw32_charset_oem
;
5935 /* More recent versions of Windows (95 and NT4.0) define more
5937 #ifdef EASTEUROPE_CHARSET
5938 case EASTEUROPE_CHARSET
:
5939 charset_type
= Qw32_charset_easteurope
;
5941 case TURKISH_CHARSET
:
5942 charset_type
= Qw32_charset_turkish
;
5944 case BALTIC_CHARSET
:
5945 charset_type
= Qw32_charset_baltic
;
5947 case RUSSIAN_CHARSET
:
5948 charset_type
= Qw32_charset_russian
;
5950 case ARABIC_CHARSET
:
5951 charset_type
= Qw32_charset_arabic
;
5954 charset_type
= Qw32_charset_greek
;
5956 case HEBREW_CHARSET
:
5957 charset_type
= Qw32_charset_hebrew
;
5959 case VIETNAMESE_CHARSET
:
5960 charset_type
= Qw32_charset_vietnamese
;
5963 charset_type
= Qw32_charset_thai
;
5966 charset_type
= Qw32_charset_mac
;
5969 charset_type
= Qw32_charset_johab
;
5973 #ifdef UNICODE_CHARSET
5974 case UNICODE_CHARSET
:
5975 charset_type
= Qw32_charset_unicode
;
5979 /* Encode numerical value of unknown charset. */
5980 sprintf (buf
, "*-#%u", fncharset
);
5986 char * best_match
= NULL
;
5988 /* Look through w32-charset-info-alist for the character set.
5989 Prefer ISO codepages, and prefer lower numbers in the ISO
5990 range. Only return charsets for codepages which are installed.
5992 Format of each entry is
5993 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5995 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
5998 Lisp_Object w32_charset
;
5999 Lisp_Object codepage
;
6001 Lisp_Object this_entry
= XCAR (rest
);
6003 /* Skip invalid entries in alist. */
6004 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
6005 || !CONSP (XCDR (this_entry
))
6006 || !SYMBOLP (XCAR (XCDR (this_entry
))))
6009 x_charset
= XSTRING (XCAR (this_entry
))->data
;
6010 w32_charset
= XCAR (XCDR (this_entry
));
6011 codepage
= XCDR (XCDR (this_entry
));
6013 /* Look for Same charset and a valid codepage (or non-int
6014 which means ignore). */
6015 if (w32_charset
== charset_type
6016 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
6017 || IsValidCodePage (XINT (codepage
))))
6019 /* If we don't have a match already, then this is the
6022 best_match
= x_charset
;
6023 /* If this is an ISO codepage, and the best so far isn't,
6024 then this is better. */
6025 else if (stricmp (best_match
, "iso") != 0
6026 && stricmp (x_charset
, "iso") == 0)
6027 best_match
= x_charset
;
6028 /* If both are ISO8859 codepages, choose the one with the
6029 lowest number in the encoding field. */
6030 else if (stricmp (best_match
, "iso8859-") == 0
6031 && stricmp (x_charset
, "iso8859-") == 0)
6033 int best_enc
= atoi (best_match
+ 8);
6034 int this_enc
= atoi (x_charset
+ 8);
6035 if (this_enc
> 0 && this_enc
< best_enc
)
6036 best_match
= x_charset
;
6041 /* If no match, encode the numeric value. */
6044 sprintf (buf
, "*-#%u", fncharset
);
6048 strncpy(buf
, best_match
, 15);
6055 /* Get the Windows codepage corresponding to the specified font. The
6056 charset info in the font name is used to look up
6057 w32-charset-to-codepage-alist. */
6059 w32_codepage_for_font (char *fontname
)
6061 Lisp_Object codepage
, entry
;
6062 char *charset_str
, *charset
, *end
;
6064 if (NILP (Vw32_charset_info_alist
))
6067 /* Extract charset part of font string. */
6068 charset
= xlfd_charset_of_font (fontname
);
6073 charset_str
= (char *) alloca (strlen (charset
));
6074 strcpy (charset_str
, charset
);
6076 /* Remove leading "*-". */
6077 if (strncmp ("*-", charset_str
, 2) == 0)
6078 charset
= charset_str
+ 2;
6080 charset
= charset_str
;
6082 /* Stop match at wildcard (including preceding '-'). */
6083 if (end
= strchr (charset
, '*'))
6085 if (end
> charset
&& *(end
-1) == '-')
6090 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6094 codepage
= Fcdr (Fcdr (entry
));
6096 if (NILP (codepage
))
6098 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
6100 else if (INTEGERP (codepage
))
6101 return XINT (codepage
);
6108 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
6109 LOGFONT
* lplogfont
;
6112 char * specific_charset
;
6116 char height_pixels
[8];
6118 char width_pixels
[8];
6119 char *fontname_dash
;
6120 int display_resy
= one_w32_display_info
.resy
;
6121 int display_resx
= one_w32_display_info
.resx
;
6123 struct coding_system coding
;
6125 if (!lpxstr
) abort ();
6130 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
6131 fonttype
= "raster";
6132 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
6133 fonttype
= "outline";
6135 fonttype
= "unknown";
6137 setup_coding_system (Fcheck_coding_system (Vw32_system_coding_system
),
6139 coding
.src_multibyte
= 0;
6140 coding
.dst_multibyte
= 1;
6141 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6142 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
6144 fontname
= alloca(sizeof(*fontname
) * bufsz
);
6145 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
6146 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
6147 *(fontname
+ coding
.produced
) = '\0';
6149 /* Replace dashes with underscores so the dashes are not
6151 fontname_dash
= fontname
;
6152 while (fontname_dash
= strchr (fontname_dash
, '-'))
6153 *fontname_dash
= '_';
6155 if (lplogfont
->lfHeight
)
6157 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
6158 sprintf (height_dpi
, "%u",
6159 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
6163 strcpy (height_pixels
, "*");
6164 strcpy (height_dpi
, "*");
6166 if (lplogfont
->lfWidth
)
6167 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
6169 strcpy (width_pixels
, "*");
6171 _snprintf (lpxstr
, len
- 1,
6172 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
6173 fonttype
, /* foundry */
6174 fontname
, /* family */
6175 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
6176 lplogfont
->lfItalic
?'i':'r', /* slant */
6178 /* add style name */
6179 height_pixels
, /* pixel size */
6180 height_dpi
, /* point size */
6181 display_resx
, /* resx */
6182 display_resy
, /* resy */
6183 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
6184 ? 'p' : 'c', /* spacing */
6185 width_pixels
, /* avg width */
6186 specific_charset
? specific_charset
6187 : w32_to_x_charset (lplogfont
->lfCharSet
)
6188 /* charset registry and encoding */
6191 lpxstr
[len
- 1] = 0; /* just to be sure */
6196 x_to_w32_font (lpxstr
, lplogfont
)
6198 LOGFONT
* lplogfont
;
6200 struct coding_system coding
;
6202 if (!lplogfont
) return (FALSE
);
6204 memset (lplogfont
, 0, sizeof (*lplogfont
));
6206 /* Set default value for each field. */
6208 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
6209 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
6210 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
6212 /* go for maximum quality */
6213 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
6214 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
6215 lplogfont
->lfQuality
= PROOF_QUALITY
;
6218 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
6219 lplogfont
->lfWeight
= FW_DONTCARE
;
6220 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
6225 /* Provide a simple escape mechanism for specifying Windows font names
6226 * directly -- if font spec does not beginning with '-', assume this
6228 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
6234 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
6235 width
[10], resy
[10], remainder
[20];
6237 int dpi
= one_w32_display_info
.resy
;
6239 fields
= sscanf (lpxstr
,
6240 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%19s",
6241 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
6242 if (fields
== EOF
) return (FALSE
);
6244 /* If wildcards cover more than one field, we don't know which
6245 field is which, so don't fill any in. */
6250 if (fields
> 0 && name
[0] != '*')
6256 (Fcheck_coding_system (Vw32_system_coding_system
), &coding
);
6257 coding
.src_multibyte
= 1;
6258 coding
.dst_multibyte
= 1;
6259 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
6260 buf
= (unsigned char *) alloca (bufsize
);
6261 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6262 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
6263 if (coding
.produced
>= LF_FACESIZE
)
6264 coding
.produced
= LF_FACESIZE
- 1;
6265 buf
[coding
.produced
] = 0;
6266 strcpy (lplogfont
->lfFaceName
, buf
);
6270 lplogfont
->lfFaceName
[0] = '\0';
6275 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6279 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
6283 if (fields
> 0 && pixels
[0] != '*')
6284 lplogfont
->lfHeight
= atoi (pixels
);
6288 if (fields
> 0 && resy
[0] != '*')
6291 if (tem
> 0) dpi
= tem
;
6294 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
6295 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
6298 lplogfont
->lfPitchAndFamily
=
6299 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
6303 if (fields
> 0 && width
[0] != '*')
6304 lplogfont
->lfWidth
= atoi (width
) / 10;
6308 /* Strip the trailing '-' if present. (it shouldn't be, as it
6309 fails the test against xlfd-tight-regexp in fontset.el). */
6311 int len
= strlen (remainder
);
6312 if (len
> 0 && remainder
[len
-1] == '-')
6313 remainder
[len
-1] = 0;
6315 encoding
= remainder
;
6316 if (strncmp (encoding
, "*-", 2) == 0)
6318 lplogfont
->lfCharSet
= x_to_w32_charset (fields
> 0 ? encoding
: "");
6323 char name
[100], height
[10], width
[10], weight
[20];
6325 fields
= sscanf (lpxstr
,
6326 "%99[^:]:%9[^:]:%9[^:]:%19s",
6327 name
, height
, width
, weight
);
6329 if (fields
== EOF
) return (FALSE
);
6333 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
6334 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
6338 lplogfont
->lfFaceName
[0] = 0;
6344 lplogfont
->lfHeight
= atoi (height
);
6349 lplogfont
->lfWidth
= atoi (width
);
6353 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6356 /* This makes TrueType fonts work better. */
6357 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
6362 /* Strip the pixel height and point height from the given xlfd, and
6363 return the pixel height. If no pixel height is specified, calculate
6364 one from the point height, or if that isn't defined either, return
6365 0 (which usually signifies a scalable font).
6367 int xlfd_strip_height (char *fontname
)
6369 int pixel_height
, point_height
, dpi
, field_number
;
6370 char *read_from
, *write_to
;
6374 pixel_height
= field_number
= 0;
6377 /* Look for height fields. */
6378 for (read_from
= fontname
; *read_from
; read_from
++)
6380 if (*read_from
== '-')
6383 if (field_number
== 7) /* Pixel height. */
6386 write_to
= read_from
;
6388 /* Find end of field. */
6389 for (;*read_from
&& *read_from
!= '-'; read_from
++)
6392 /* Split the fontname at end of field. */
6398 pixel_height
= atoi (write_to
);
6399 /* Blank out field. */
6400 if (read_from
> write_to
)
6405 /* If the pixel height field is at the end (partial xlfd),
6408 return pixel_height
;
6410 /* If we got a pixel height, the point height can be
6411 ignored. Just blank it out and break now. */
6414 /* Find end of point size field. */
6415 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6421 /* Blank out the point size field. */
6422 if (read_from
> write_to
)
6428 return pixel_height
;
6432 /* If the point height is already blank, break now. */
6433 if (*read_from
== '-')
6439 else if (field_number
== 8)
6441 /* If we didn't get a pixel height, try to get the point
6442 height and convert that. */
6444 char *point_size_start
= read_from
++;
6446 /* Find end of field. */
6447 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6456 point_size
= atoi (point_size_start
);
6458 /* Convert to pixel height. */
6459 pixel_height
= point_size
6460 * one_w32_display_info
.height_in
/ 720;
6462 /* Blank out this field and break. */
6470 /* Shift the rest of the font spec into place. */
6471 if (write_to
&& read_from
> write_to
)
6473 for (; *read_from
; read_from
++, write_to
++)
6474 *write_to
= *read_from
;
6478 return pixel_height
;
6481 /* Assume parameter 1 is fully qualified, no wildcards. */
6483 w32_font_match (fontname
, pattern
)
6487 char *regex
= alloca (strlen (pattern
) * 2);
6488 char *font_name_copy
= alloca (strlen (fontname
) + 1);
6491 /* Copy fontname so we can modify it during comparison. */
6492 strcpy (font_name_copy
, fontname
);
6497 /* Turn pattern into a regexp and do a regexp match. */
6498 for (; *pattern
; pattern
++)
6500 if (*pattern
== '?')
6502 else if (*pattern
== '*')
6513 /* Strip out font heights and compare them seperately, since
6514 rounding error can cause mismatches. This also allows a
6515 comparison between a font that declares only a pixel height and a
6516 pattern that declares the point height.
6519 int font_height
, pattern_height
;
6521 font_height
= xlfd_strip_height (font_name_copy
);
6522 pattern_height
= xlfd_strip_height (regex
);
6524 /* Compare now, and don't bother doing expensive regexp matching
6525 if the heights differ. */
6526 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
6530 return (fast_c_string_match_ignore_case (build_string (regex
),
6531 font_name_copy
) >= 0);
6534 /* Callback functions, and a structure holding info they need, for
6535 listing system fonts on W32. We need one set of functions to do the
6536 job properly, but these don't work on NT 3.51 and earlier, so we
6537 have a second set which don't handle character sets properly to
6540 In both cases, there are two passes made. The first pass gets one
6541 font from each family, the second pass lists all the fonts from
6544 typedef struct enumfont_t
6549 XFontStruct
*size_ref
;
6550 Lisp_Object
*pattern
;
6555 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
6557 NEWTEXTMETRIC
* lptm
;
6561 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
6564 /* Check that the character set matches if it was specified */
6565 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6566 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6571 Lisp_Object width
= Qnil
;
6572 char *charset
= NULL
;
6574 /* Truetype fonts do not report their true metrics until loaded */
6575 if (FontType
!= RASTER_FONTTYPE
)
6577 if (!NILP (*(lpef
->pattern
)))
6579 /* Scalable fonts are as big as you want them to be. */
6580 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6581 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6582 width
= make_number (lpef
->logfont
.lfWidth
);
6586 lplf
->elfLogFont
.lfHeight
= 0;
6587 lplf
->elfLogFont
.lfWidth
= 0;
6591 /* Make sure the height used here is the same as everywhere
6592 else (ie character height, not cell height). */
6593 if (lplf
->elfLogFont
.lfHeight
> 0)
6595 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6596 if (FontType
== RASTER_FONTTYPE
)
6597 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6599 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6602 if (!NILP (*(lpef
->pattern
)))
6604 charset
= xlfd_charset_of_font (XSTRING(*(lpef
->pattern
))->data
);
6606 /* Ensure that charset is valid for this font. */
6608 && (x_to_w32_charset (charset
) != lplf
->elfLogFont
.lfCharSet
))
6612 /* TODO: List all relevant charsets if charset not specified. */
6613 if (!w32_to_x_font (&(lplf
->elfLogFont
), buf
, 100, charset
))
6616 if (NILP (*(lpef
->pattern
))
6617 || w32_font_match (buf
, XSTRING (*(lpef
->pattern
))->data
))
6619 *lpef
->tail
= Fcons (Fcons (build_string (buf
), width
), Qnil
);
6620 lpef
->tail
= &(XCDR (*lpef
->tail
));
6629 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6631 NEWTEXTMETRIC
* lptm
;
6635 return EnumFontFamilies (lpef
->hdc
,
6636 lplf
->elfLogFont
.lfFaceName
,
6637 (FONTENUMPROC
) enum_font_cb2
,
6643 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6644 ENUMLOGFONTEX
* lplf
;
6645 NEWTEXTMETRICEX
* lptm
;
6649 /* We are not interested in the extra info we get back from the 'Ex
6650 version - only the fact that we get character set variations
6651 enumerated seperately. */
6652 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6657 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6658 ENUMLOGFONTEX
* lplf
;
6659 NEWTEXTMETRICEX
* lptm
;
6663 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6664 FARPROC enum_font_families_ex
6665 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6666 /* We don't really expect EnumFontFamiliesEx to disappear once we
6667 get here, so don't bother handling it gracefully. */
6668 if (enum_font_families_ex
== NULL
)
6669 error ("gdi32.dll has disappeared!");
6670 return enum_font_families_ex (lpef
->hdc
,
6672 (FONTENUMPROC
) enum_fontex_cb2
,
6676 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6677 and xterm.c in Emacs 20.3) */
6679 Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6681 char *fontname
, *ptnstr
;
6682 Lisp_Object list
, tem
, newlist
= Qnil
;
6685 list
= Vw32_bdf_filename_alist
;
6686 ptnstr
= XSTRING (pattern
)->data
;
6688 for ( ; CONSP (list
); list
= XCDR (list
))
6692 fontname
= XSTRING (XCAR (tem
))->data
;
6693 else if (STRINGP (tem
))
6694 fontname
= XSTRING (tem
)->data
;
6698 if (w32_font_match (fontname
, ptnstr
))
6700 newlist
= Fcons (XCAR (tem
), newlist
);
6702 if (n_fonts
>= max_names
)
6710 Lisp_Object
w32_list_synthesized_fonts (FRAME_PTR f
, Lisp_Object pattern
,
6711 int size
, int max_names
);
6713 /* Return a list of names of available fonts matching PATTERN on frame
6714 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6715 to be listed. Frame F NULL means we have not yet created any
6716 frame, which means we can't get proper size info, as we don't have
6717 a device context to use for GetTextMetrics.
6718 MAXNAMES sets a limit on how many fonts to match. */
6721 w32_list_fonts (FRAME_PTR f
, Lisp_Object pattern
, int size
, int maxnames
)
6723 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
6724 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
6725 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
6728 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6729 if (NILP (patterns
))
6730 patterns
= Fcons (pattern
, Qnil
);
6732 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6737 tpat
= XCAR (patterns
);
6739 if (!STRINGP (tpat
))
6742 /* Avoid expensive EnumFontFamilies functions if we are not
6743 going to be able to output one of these anyway. */
6744 codepage
= w32_codepage_for_font (XSTRING (tpat
)->data
);
6745 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
6746 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
6747 && !IsValidCodePage(codepage
))
6750 /* See if we cached the result for this particular query.
6751 The cache is an alist of the form:
6752 ((PATTERN (FONTNAME . WIDTH) ...) ...)
6754 if (tem
= XCDR (dpyinfo
->name_list_element
),
6755 !NILP (list
= Fassoc (tpat
, tem
)))
6757 list
= Fcdr_safe (list
);
6758 /* We have a cached list. Don't have to get the list again. */
6763 /* At first, put PATTERN in the cache. */
6769 /* Use EnumFontFamiliesEx where it is available, as it knows
6770 about character sets. Fall back to EnumFontFamilies for
6771 older versions of NT that don't support the 'Ex function. */
6772 x_to_w32_font (XSTRING (tpat
)->data
, &ef
.logfont
);
6774 LOGFONT font_match_pattern
;
6775 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6776 FARPROC enum_font_families_ex
6777 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6779 /* We do our own pattern matching so we can handle wildcards. */
6780 font_match_pattern
.lfFaceName
[0] = 0;
6781 font_match_pattern
.lfPitchAndFamily
= 0;
6782 /* We can use the charset, because if it is a wildcard it will
6783 be DEFAULT_CHARSET anyway. */
6784 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
6786 ef
.hdc
= GetDC (dpyinfo
->root_window
);
6788 if (enum_font_families_ex
)
6789 enum_font_families_ex (ef
.hdc
,
6790 &font_match_pattern
,
6791 (FONTENUMPROC
) enum_fontex_cb1
,
6794 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
6797 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
6802 /* Make a list of the fonts we got back.
6803 Store that in the font cache for the display. */
6804 XCDR (dpyinfo
->name_list_element
)
6805 = Fcons (Fcons (tpat
, list
),
6806 XCDR (dpyinfo
->name_list_element
));
6809 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6811 newlist
= second_best
= Qnil
;
6813 /* Make a list of the fonts that have the right width. */
6814 for (; CONSP (list
); list
= XCDR (list
))
6821 if (NILP (XCAR (tem
)))
6825 newlist
= Fcons (XCAR (tem
), newlist
);
6827 if (n_fonts
>= maxnames
)
6832 if (!INTEGERP (XCDR (tem
)))
6834 /* Since we don't yet know the size of the font, we must
6835 load it and try GetTextMetrics. */
6836 W32FontStruct thisinfo
;
6841 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
6845 thisinfo
.bdf
= NULL
;
6846 thisinfo
.hfont
= CreateFontIndirect (&lf
);
6847 if (thisinfo
.hfont
== NULL
)
6850 hdc
= GetDC (dpyinfo
->root_window
);
6851 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
6852 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
6853 XCDR (tem
) = make_number (FONT_WIDTH (&thisinfo
));
6855 XCDR (tem
) = make_number (0);
6856 SelectObject (hdc
, oldobj
);
6857 ReleaseDC (dpyinfo
->root_window
, hdc
);
6858 DeleteObject(thisinfo
.hfont
);
6861 found_size
= XINT (XCDR (tem
));
6862 if (found_size
== size
)
6864 newlist
= Fcons (XCAR (tem
), newlist
);
6866 if (n_fonts
>= maxnames
)
6869 /* keep track of the closest matching size in case
6870 no exact match is found. */
6871 else if (found_size
> 0)
6873 if (NILP (second_best
))
6876 else if (found_size
< size
)
6878 if (XINT (XCDR (second_best
)) > size
6879 || XINT (XCDR (second_best
)) < found_size
)
6884 if (XINT (XCDR (second_best
)) > size
6885 && XINT (XCDR (second_best
)) >
6892 if (!NILP (newlist
))
6894 else if (!NILP (second_best
))
6896 newlist
= Fcons (XCAR (second_best
), Qnil
);
6901 /* Include any bdf fonts. */
6902 if (n_fonts
< maxnames
)
6904 Lisp_Object combined
[2];
6905 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
6906 combined
[1] = newlist
;
6907 newlist
= Fnconc(2, combined
);
6910 /* If we can't find a font that matches, check if Windows would be
6911 able to synthesize it from a different style. */
6912 if (NILP (newlist
) && !NILP (Vw32_enable_synthesized_fonts
))
6913 newlist
= w32_list_synthesized_fonts (f
, pattern
, size
, maxnames
);
6919 w32_list_synthesized_fonts (f
, pattern
, size
, max_names
)
6921 Lisp_Object pattern
;
6926 char *full_pattn
, *new_pattn
, foundary
[50], family
[50], *pattn_part2
;
6927 char style
[20], slant
;
6928 Lisp_Object matches
, match
, tem
, synthed_matches
= Qnil
;
6930 full_pattn
= XSTRING (pattern
)->data
;
6932 pattn_part2
= alloca (XSTRING (pattern
)->size
);
6933 /* Allow some space for wildcard expansion. */
6934 new_pattn
= alloca (XSTRING (pattern
)->size
+ 100);
6936 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%19[^-]-%c-%s",
6937 foundary
, family
, style
, &slant
, pattn_part2
);
6938 if (fields
== EOF
|| fields
< 5)
6941 /* If the style and slant are wildcards already there is no point
6942 checking again (and we don't want to keep recursing). */
6943 if (*style
== '*' && slant
== '*')
6946 sprintf (new_pattn
, "-%s-%s-*-*-%s", foundary
, family
, pattn_part2
);
6948 matches
= w32_list_fonts (f
, build_string (new_pattn
), size
, max_names
);
6950 for ( ; CONSP (matches
); matches
= XCDR (matches
))
6952 tem
= XCAR (matches
);
6956 full_pattn
= XSTRING (tem
)->data
;
6957 fields
= sscanf (full_pattn
, "-%49[^-]-%49[^-]-%*[^-]-%*c-%s",
6958 foundary
, family
, pattn_part2
);
6959 if (fields
== EOF
|| fields
< 3)
6962 sprintf (new_pattn
, "-%s-%s-%s-%c-%s", foundary
, family
, style
,
6963 slant
, pattn_part2
);
6965 synthed_matches
= Fcons (build_string (new_pattn
),
6969 return synthed_matches
;
6973 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6975 w32_get_font_info (f
, font_idx
)
6979 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
6984 w32_query_font (struct frame
*f
, char *fontname
)
6987 struct font_info
*pfi
;
6989 pfi
= FRAME_W32_FONT_TABLE (f
);
6991 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
6993 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
6999 /* Find a CCL program for a font specified by FONTP, and set the member
7000 `encoder' of the structure. */
7003 w32_find_ccl_program (fontp
)
7004 struct font_info
*fontp
;
7006 Lisp_Object list
, elt
;
7008 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
7012 && STRINGP (XCAR (elt
))
7013 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
7019 struct ccl_program
*ccl
7020 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
7022 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
7025 fontp
->font_encoder
= ccl
;
7030 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
7032 "Return a list of BDF fonts in DIR, suitable for appending to\n\
7033 w32-bdf-filename-alist. Fonts which do not contain an xlfd description\n\
7034 will not be included in the list. DIR may be a list of directories.")
7036 Lisp_Object directory
;
7038 Lisp_Object list
= Qnil
;
7039 struct gcpro gcpro1
, gcpro2
;
7041 if (!CONSP (directory
))
7042 return w32_find_bdf_fonts_in_dir (directory
);
7044 for ( ; CONSP (directory
); directory
= XCDR (directory
))
7046 Lisp_Object pair
[2];
7049 GCPRO2 (directory
, list
);
7050 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
7051 list
= Fnconc( 2, pair
);
7057 /* Find BDF files in a specified directory. (use GCPRO when calling,
7058 as this calls lisp to get a directory listing). */
7059 Lisp_Object
w32_find_bdf_fonts_in_dir( Lisp_Object directory
)
7061 Lisp_Object filelist
, list
= Qnil
;
7064 if (!STRINGP(directory
))
7067 filelist
= Fdirectory_files (directory
, Qt
,
7068 build_string (".*\\.[bB][dD][fF]"), Qt
);
7070 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
7072 Lisp_Object filename
= XCAR (filelist
);
7073 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
7074 store_in_alist (&list
, build_string (fontname
), filename
);
7080 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
7081 "Internal function called by `color-defined-p', which see.")
7083 Lisp_Object color
, frame
;
7086 FRAME_PTR f
= check_x_frame (frame
);
7088 CHECK_STRING (color
, 1);
7090 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7096 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
7097 "Internal function called by `color-values', which see.")
7099 Lisp_Object color
, frame
;
7102 FRAME_PTR f
= check_x_frame (frame
);
7104 CHECK_STRING (color
, 1);
7106 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7110 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
7111 | GetRValue (foo
.pixel
));
7112 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
7113 | GetGValue (foo
.pixel
));
7114 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
7115 | GetBValue (foo
.pixel
));
7116 return Flist (3, rgb
);
7122 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
7123 "Internal function called by `display-color-p', which see.")
7125 Lisp_Object display
;
7127 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7129 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
7135 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
7137 "Return t if the X display supports shades of gray.\n\
7138 Note that color displays do support shades of gray.\n\
7139 The optional argument DISPLAY specifies which display to ask about.\n\
7140 DISPLAY should be either a frame or a display name (a string).\n\
7141 If omitted or nil, that stands for the selected frame's display.")
7143 Lisp_Object display
;
7145 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7147 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
7153 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
7155 "Returns the width in pixels of the X display DISPLAY.\n\
7156 The optional argument DISPLAY specifies which display to ask about.\n\
7157 DISPLAY should be either a frame or a display name (a string).\n\
7158 If omitted or nil, that stands for the selected frame's display.")
7160 Lisp_Object display
;
7162 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7164 return make_number (dpyinfo
->width
);
7167 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
7168 Sx_display_pixel_height
, 0, 1, 0,
7169 "Returns the height in pixels of the X display DISPLAY.\n\
7170 The optional argument DISPLAY specifies which display to ask about.\n\
7171 DISPLAY should be either a frame or a display name (a string).\n\
7172 If omitted or nil, that stands for the selected frame's display.")
7174 Lisp_Object display
;
7176 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7178 return make_number (dpyinfo
->height
);
7181 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
7183 "Returns the number of bitplanes of the display DISPLAY.\n\
7184 The optional argument DISPLAY specifies which display to ask about.\n\
7185 DISPLAY should be either a frame or a display name (a string).\n\
7186 If omitted or nil, that stands for the selected frame's display.")
7188 Lisp_Object display
;
7190 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7192 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7195 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
7197 "Returns the number of color cells of the display DISPLAY.\n\
7198 The optional argument DISPLAY specifies which display to ask about.\n\
7199 DISPLAY should be either a frame or a display name (a string).\n\
7200 If omitted or nil, that stands for the selected frame's display.")
7202 Lisp_Object display
;
7204 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7208 hdc
= GetDC (dpyinfo
->root_window
);
7209 if (dpyinfo
->has_palette
)
7210 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
7212 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
7214 ReleaseDC (dpyinfo
->root_window
, hdc
);
7216 return make_number (cap
);
7219 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
7220 Sx_server_max_request_size
,
7222 "Returns the maximum request size of the server of display DISPLAY.\n\
7223 The optional argument DISPLAY specifies which display to ask about.\n\
7224 DISPLAY should be either a frame or a display name (a string).\n\
7225 If omitted or nil, that stands for the selected frame's display.")
7227 Lisp_Object display
;
7229 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7231 return make_number (1);
7234 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
7235 "Returns the vendor ID string of the W32 system (Microsoft).\n\
7236 The optional argument DISPLAY specifies which display to ask about.\n\
7237 DISPLAY should be either a frame or a display name (a string).\n\
7238 If omitted or nil, that stands for the selected frame's display.")
7240 Lisp_Object display
;
7242 return build_string ("Microsoft Corp.");
7245 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
7246 "Returns the version numbers of the server of display DISPLAY.\n\
7247 The value is a list of three integers: the major and minor\n\
7248 version numbers, and the vendor-specific release\n\
7249 number. See also the function `x-server-vendor'.\n\n\
7250 The optional argument DISPLAY specifies which display to ask about.\n\
7251 DISPLAY should be either a frame or a display name (a string).\n\
7252 If omitted or nil, that stands for the selected frame's display.")
7254 Lisp_Object display
;
7256 return Fcons (make_number (w32_major_version
),
7257 Fcons (make_number (w32_minor_version
),
7258 Fcons (make_number (w32_build_number
), Qnil
)));
7261 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
7262 "Returns the number of screens on the server of display DISPLAY.\n\
7263 The optional argument DISPLAY specifies which display to ask about.\n\
7264 DISPLAY should be either a frame or a display name (a string).\n\
7265 If omitted or nil, that stands for the selected frame's display.")
7267 Lisp_Object display
;
7269 return make_number (1);
7272 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
7273 "Returns the height in millimeters of the X display DISPLAY.\n\
7274 The optional argument DISPLAY specifies which display to ask about.\n\
7275 DISPLAY should be either a frame or a display name (a string).\n\
7276 If omitted or nil, that stands for the selected frame's display.")
7278 Lisp_Object display
;
7280 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7284 hdc
= GetDC (dpyinfo
->root_window
);
7286 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
7288 ReleaseDC (dpyinfo
->root_window
, hdc
);
7290 return make_number (cap
);
7293 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
7294 "Returns the width in millimeters of the X display DISPLAY.\n\
7295 The optional argument DISPLAY specifies which display to ask about.\n\
7296 DISPLAY should be either a frame or a display name (a string).\n\
7297 If omitted or nil, that stands for the selected frame's display.")
7299 Lisp_Object display
;
7301 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7306 hdc
= GetDC (dpyinfo
->root_window
);
7308 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
7310 ReleaseDC (dpyinfo
->root_window
, hdc
);
7312 return make_number (cap
);
7315 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
7316 Sx_display_backing_store
, 0, 1, 0,
7317 "Returns an indication of whether display DISPLAY does backing store.\n\
7318 The value may be `always', `when-mapped', or `not-useful'.\n\
7319 The optional argument DISPLAY specifies which display to ask about.\n\
7320 DISPLAY should be either a frame or a display name (a string).\n\
7321 If omitted or nil, that stands for the selected frame's display.")
7323 Lisp_Object display
;
7325 return intern ("not-useful");
7328 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
7329 Sx_display_visual_class
, 0, 1, 0,
7330 "Returns the visual class of the display DISPLAY.\n\
7331 The value is one of the symbols `static-gray', `gray-scale',\n\
7332 `static-color', `pseudo-color', `true-color', or `direct-color'.\n\n\
7333 The optional argument DISPLAY specifies which display to ask about.\n\
7334 DISPLAY should be either a frame or a display name (a string).\n\
7335 If omitted or nil, that stands for the selected frame's display.")
7337 Lisp_Object display
;
7339 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7342 switch (dpyinfo
->visual
->class)
7344 case StaticGray
: return (intern ("static-gray"));
7345 case GrayScale
: return (intern ("gray-scale"));
7346 case StaticColor
: return (intern ("static-color"));
7347 case PseudoColor
: return (intern ("pseudo-color"));
7348 case TrueColor
: return (intern ("true-color"));
7349 case DirectColor
: return (intern ("direct-color"));
7351 error ("Display has an unknown visual class");
7355 error ("Display has an unknown visual class");
7358 DEFUN ("x-display-save-under", Fx_display_save_under
,
7359 Sx_display_save_under
, 0, 1, 0,
7360 "Returns t if the display DISPLAY supports the save-under feature.\n\
7361 The optional argument DISPLAY specifies which display to ask about.\n\
7362 DISPLAY should be either a frame or a display name (a string).\n\
7363 If omitted or nil, that stands for the selected frame's display.")
7365 Lisp_Object display
;
7372 register struct frame
*f
;
7374 return PIXEL_WIDTH (f
);
7379 register struct frame
*f
;
7381 return PIXEL_HEIGHT (f
);
7386 register struct frame
*f
;
7388 return FONT_WIDTH (f
->output_data
.w32
->font
);
7393 register struct frame
*f
;
7395 return f
->output_data
.w32
->line_height
;
7400 register struct frame
*f
;
7402 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
7405 /* Return the display structure for the display named NAME.
7406 Open a new connection if necessary. */
7408 struct w32_display_info
*
7409 x_display_info_for_name (name
)
7413 struct w32_display_info
*dpyinfo
;
7415 CHECK_STRING (name
, 0);
7417 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
7419 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
7422 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
7427 /* Use this general default value to start with. */
7428 Vx_resource_name
= Vinvocation_name
;
7430 validate_x_resource_name ();
7432 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
7433 (char *) XSTRING (Vx_resource_name
)->data
);
7436 error ("Cannot connect to server %s", XSTRING (name
)->data
);
7439 XSETFASTINT (Vwindow_system_version
, 3);
7444 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
7445 1, 3, 0, "Open a connection to a server.\n\
7446 DISPLAY is the name of the display to connect to.\n\
7447 Optional second arg XRM-STRING is a string of resources in xrdb format.\n\
7448 If the optional third arg MUST-SUCCEED is non-nil,\n\
7449 terminate Emacs if we can't open the connection.")
7450 (display
, xrm_string
, must_succeed
)
7451 Lisp_Object display
, xrm_string
, must_succeed
;
7453 unsigned char *xrm_option
;
7454 struct w32_display_info
*dpyinfo
;
7456 CHECK_STRING (display
, 0);
7457 if (! NILP (xrm_string
))
7458 CHECK_STRING (xrm_string
, 1);
7460 if (! EQ (Vwindow_system
, intern ("w32")))
7461 error ("Not using Microsoft Windows");
7463 /* Allow color mapping to be defined externally; first look in user's
7464 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
7466 Lisp_Object color_file
;
7467 struct gcpro gcpro1
;
7469 color_file
= build_string("~/rgb.txt");
7471 GCPRO1 (color_file
);
7473 if (NILP (Ffile_readable_p (color_file
)))
7475 Fexpand_file_name (build_string ("rgb.txt"),
7476 Fsymbol_value (intern ("data-directory")));
7478 Vw32_color_map
= Fw32_load_color_file (color_file
);
7482 if (NILP (Vw32_color_map
))
7483 Vw32_color_map
= Fw32_default_color_map ();
7485 if (! NILP (xrm_string
))
7486 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
7488 xrm_option
= (unsigned char *) 0;
7490 /* Use this general default value to start with. */
7491 /* First remove .exe suffix from invocation-name - it looks ugly. */
7493 char basename
[ MAX_PATH
], *str
;
7495 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
7496 str
= strrchr (basename
, '.');
7498 Vinvocation_name
= build_string (basename
);
7500 Vx_resource_name
= Vinvocation_name
;
7502 validate_x_resource_name ();
7504 /* This is what opens the connection and sets x_current_display.
7505 This also initializes many symbols, such as those used for input. */
7506 dpyinfo
= w32_term_init (display
, xrm_option
,
7507 (char *) XSTRING (Vx_resource_name
)->data
);
7511 if (!NILP (must_succeed
))
7512 fatal ("Cannot connect to server %s.\n",
7513 XSTRING (display
)->data
);
7515 error ("Cannot connect to server %s", XSTRING (display
)->data
);
7520 XSETFASTINT (Vwindow_system_version
, 3);
7524 DEFUN ("x-close-connection", Fx_close_connection
,
7525 Sx_close_connection
, 1, 1, 0,
7526 "Close the connection to DISPLAY's server.\n\
7527 For DISPLAY, specify either a frame or a display name (a string).\n\
7528 If DISPLAY is nil, that stands for the selected frame's display.")
7530 Lisp_Object display
;
7532 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7535 if (dpyinfo
->reference_count
> 0)
7536 error ("Display still has frames on it");
7539 /* Free the fonts in the font table. */
7540 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7541 if (dpyinfo
->font_table
[i
].name
)
7543 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7544 xfree (dpyinfo
->font_table
[i
].full_name
);
7545 xfree (dpyinfo
->font_table
[i
].name
);
7546 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7548 x_destroy_all_bitmaps (dpyinfo
);
7550 x_delete_display (dpyinfo
);
7556 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7557 "Return the list of display names that Emacs has connections to.")
7560 Lisp_Object tail
, result
;
7563 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
7564 result
= Fcons (XCAR (XCAR (tail
)), result
);
7569 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7570 "If ON is non-nil, report errors as soon as the erring request is made.\n\
7571 If ON is nil, allow buffering of requests.\n\
7572 This is a noop on W32 systems.\n\
7573 The optional second argument DISPLAY specifies which display to act on.\n\
7574 DISPLAY should be either a frame or a display name (a string).\n\
7575 If DISPLAY is omitted or nil, that stands for the selected frame's display.")
7577 Lisp_Object display
, on
;
7584 /***********************************************************************
7586 ***********************************************************************/
7588 /* Value is the number of elements of vector VECTOR. */
7590 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
7592 /* List of supported image types. Use define_image_type to add new
7593 types. Use lookup_image_type to find a type for a given symbol. */
7595 static struct image_type
*image_types
;
7597 /* The symbol `image' which is the car of the lists used to represent
7600 extern Lisp_Object Qimage
;
7602 /* The symbol `xbm' which is used as the type symbol for XBM images. */
7608 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
7609 extern Lisp_Object QCdata
;
7610 Lisp_Object QCtype
, QCascent
, QCmargin
, QCrelief
;
7611 Lisp_Object QCalgorithm
, QCcolor_symbols
, QCheuristic_mask
;
7612 Lisp_Object QCindex
;
7614 /* Other symbols. */
7616 Lisp_Object Qlaplace
;
7618 /* Time in seconds after which images should be removed from the cache
7619 if not displayed. */
7621 Lisp_Object Vimage_cache_eviction_delay
;
7623 /* Function prototypes. */
7625 static void define_image_type
P_ ((struct image_type
*type
));
7626 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
7627 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
7628 static void x_laplace
P_ ((struct frame
*, struct image
*));
7629 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
7633 /* Define a new image type from TYPE. This adds a copy of TYPE to
7634 image_types and adds the symbol *TYPE->type to Vimage_types. */
7637 define_image_type (type
)
7638 struct image_type
*type
;
7640 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
7641 The initialized data segment is read-only. */
7642 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
7643 bcopy (type
, p
, sizeof *p
);
7644 p
->next
= image_types
;
7646 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
7650 /* Look up image type SYMBOL, and return a pointer to its image_type
7651 structure. Value is null if SYMBOL is not a known image type. */
7653 static INLINE
struct image_type
*
7654 lookup_image_type (symbol
)
7657 struct image_type
*type
;
7659 for (type
= image_types
; type
; type
= type
->next
)
7660 if (EQ (symbol
, *type
->type
))
7667 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
7668 valid image specification is a list whose car is the symbol
7669 `image', and whose rest is a property list. The property list must
7670 contain a value for key `:type'. That value must be the name of a
7671 supported image type. The rest of the property list depends on the
7675 valid_image_p (object
)
7680 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
7682 Lisp_Object symbol
= Fplist_get (XCDR (object
), QCtype
);
7683 struct image_type
*type
= lookup_image_type (symbol
);
7686 valid_p
= type
->valid_p (object
);
7693 /* Log error message with format string FORMAT and argument ARG.
7694 Signaling an error, e.g. when an image cannot be loaded, is not a
7695 good idea because this would interrupt redisplay, and the error
7696 message display would lead to another redisplay. This function
7697 therefore simply displays a message. */
7700 image_error (format
, arg1
, arg2
)
7702 Lisp_Object arg1
, arg2
;
7704 add_to_log (format
, arg1
, arg2
);
7709 /***********************************************************************
7710 Image specifications
7711 ***********************************************************************/
7713 enum image_value_type
7715 IMAGE_DONT_CHECK_VALUE_TYPE
,
7718 IMAGE_POSITIVE_INTEGER_VALUE
,
7719 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
7721 IMAGE_INTEGER_VALUE
,
7722 IMAGE_FUNCTION_VALUE
,
7727 /* Structure used when parsing image specifications. */
7729 struct image_keyword
7731 /* Name of keyword. */
7734 /* The type of value allowed. */
7735 enum image_value_type type
;
7737 /* Non-zero means key must be present. */
7740 /* Used to recognize duplicate keywords in a property list. */
7743 /* The value that was found. */
7748 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
7750 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
7753 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
7754 has the format (image KEYWORD VALUE ...). One of the keyword/
7755 value pairs must be `:type TYPE'. KEYWORDS is a vector of
7756 image_keywords structures of size NKEYWORDS describing other
7757 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
7760 parse_image_spec (spec
, keywords
, nkeywords
, type
)
7762 struct image_keyword
*keywords
;
7769 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
7772 plist
= XCDR (spec
);
7773 while (CONSP (plist
))
7775 Lisp_Object key
, value
;
7777 /* First element of a pair must be a symbol. */
7779 plist
= XCDR (plist
);
7783 /* There must follow a value. */
7786 value
= XCAR (plist
);
7787 plist
= XCDR (plist
);
7789 /* Find key in KEYWORDS. Error if not found. */
7790 for (i
= 0; i
< nkeywords
; ++i
)
7791 if (strcmp (keywords
[i
].name
, XSYMBOL (key
)->name
->data
) == 0)
7797 /* Record that we recognized the keyword. If a keywords
7798 was found more than once, it's an error. */
7799 keywords
[i
].value
= value
;
7800 ++keywords
[i
].count
;
7802 if (keywords
[i
].count
> 1)
7805 /* Check type of value against allowed type. */
7806 switch (keywords
[i
].type
)
7808 case IMAGE_STRING_VALUE
:
7809 if (!STRINGP (value
))
7813 case IMAGE_SYMBOL_VALUE
:
7814 if (!SYMBOLP (value
))
7818 case IMAGE_POSITIVE_INTEGER_VALUE
:
7819 if (!INTEGERP (value
) || XINT (value
) <= 0)
7823 case IMAGE_ASCENT_VALUE
:
7824 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
7826 else if (INTEGERP (value
)
7827 && XINT (value
) >= 0
7828 && XINT (value
) <= 100)
7832 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
7833 if (!INTEGERP (value
) || XINT (value
) < 0)
7837 case IMAGE_DONT_CHECK_VALUE_TYPE
:
7840 case IMAGE_FUNCTION_VALUE
:
7841 value
= indirect_function (value
);
7843 || COMPILEDP (value
)
7844 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
7848 case IMAGE_NUMBER_VALUE
:
7849 if (!INTEGERP (value
) && !FLOATP (value
))
7853 case IMAGE_INTEGER_VALUE
:
7854 if (!INTEGERP (value
))
7858 case IMAGE_BOOL_VALUE
:
7859 if (!NILP (value
) && !EQ (value
, Qt
))
7868 if (EQ (key
, QCtype
) && !EQ (type
, value
))
7872 /* Check that all mandatory fields are present. */
7873 for (i
= 0; i
< nkeywords
; ++i
)
7874 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
7877 return NILP (plist
);
7881 /* Return the value of KEY in image specification SPEC. Value is nil
7882 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
7883 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
7886 image_spec_value (spec
, key
, found
)
7887 Lisp_Object spec
, key
;
7892 xassert (valid_image_p (spec
));
7894 for (tail
= XCDR (spec
);
7895 CONSP (tail
) && CONSP (XCDR (tail
));
7896 tail
= XCDR (XCDR (tail
)))
7898 if (EQ (XCAR (tail
), key
))
7902 return XCAR (XCDR (tail
));
7914 /***********************************************************************
7915 Image type independent image structures
7916 ***********************************************************************/
7918 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
7919 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
7922 /* Allocate and return a new image structure for image specification
7923 SPEC. SPEC has a hash value of HASH. */
7925 static struct image
*
7926 make_image (spec
, hash
)
7930 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
7932 xassert (valid_image_p (spec
));
7933 bzero (img
, sizeof *img
);
7934 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
7935 xassert (img
->type
!= NULL
);
7937 img
->data
.lisp_val
= Qnil
;
7938 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
7944 /* Free image IMG which was used on frame F, including its resources. */
7953 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
7955 /* Remove IMG from the hash table of its cache. */
7957 img
->prev
->next
= img
->next
;
7959 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
7962 img
->next
->prev
= img
->prev
;
7964 c
->images
[img
->id
] = NULL
;
7966 /* Free resources, then free IMG. */
7967 img
->type
->free (f
, img
);
7973 /* Prepare image IMG for display on frame F. Must be called before
7974 drawing an image. */
7977 prepare_image_for_display (f
, img
)
7983 /* We're about to display IMG, so set its timestamp to `now'. */
7985 img
->timestamp
= EMACS_SECS (t
);
7987 /* If IMG doesn't have a pixmap yet, load it now, using the image
7988 type dependent loader function. */
7989 if (img
->pixmap
== 0 && !img
->load_failed_p
)
7990 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
7994 /* Value is the number of pixels for the ascent of image IMG when
7995 drawn in face FACE. */
7998 image_ascent (img
, face
)
8002 int height
= img
->height
+ img
->margin
;
8005 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
8008 ascent
= height
/ 2 - (FONT_DESCENT(face
->font
)
8009 - FONT_BASE(face
->font
)) / 2;
8011 ascent
= height
/ 2;
8014 ascent
= height
* img
->ascent
/ 100.0;
8021 /***********************************************************************
8022 Helper functions for X image types
8023 ***********************************************************************/
8025 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
8026 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
8028 Lisp_Object color_name
,
8029 unsigned long dflt
));
8031 /* Free X resources of image IMG which is used on frame F. */
8034 x_clear_image (f
, img
)
8038 #if 0 /* TODO: W32 image support */
8043 XFreePixmap (NULL
, img
->pixmap
);
8050 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
8052 /* If display has an immutable color map, freeing colors is not
8053 necessary and some servers don't allow it. So don't do it. */
8054 if (class != StaticColor
8055 && class != StaticGray
8056 && class != TrueColor
)
8060 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
8061 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
8066 xfree (img
->colors
);
8074 /* Allocate color COLOR_NAME for image IMG on frame F. If color
8075 cannot be allocated, use DFLT. Add a newly allocated color to
8076 IMG->colors, so that it can be freed again. Value is the pixel
8079 static unsigned long
8080 x_alloc_image_color (f
, img
, color_name
, dflt
)
8083 Lisp_Object color_name
;
8086 #if 0 /* TODO: allocing colors. */
8088 unsigned long result
;
8090 xassert (STRINGP (color_name
));
8092 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
8094 /* This isn't called frequently so we get away with simply
8095 reallocating the color vector to the needed size, here. */
8098 (unsigned long *) xrealloc (img
->colors
,
8099 img
->ncolors
* sizeof *img
->colors
);
8100 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
8101 result
= color
.pixel
;
8112 /***********************************************************************
8114 ***********************************************************************/
8116 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
8119 /* Return a new, initialized image cache that is allocated from the
8120 heap. Call free_image_cache to free an image cache. */
8122 struct image_cache
*
8125 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
8128 bzero (c
, sizeof *c
);
8130 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
8131 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
8132 c
->buckets
= (struct image
**) xmalloc (size
);
8133 bzero (c
->buckets
, size
);
8138 /* Free image cache of frame F. Be aware that X frames share images
8142 free_image_cache (f
)
8145 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8150 /* Cache should not be referenced by any frame when freed. */
8151 xassert (c
->refcount
== 0);
8153 for (i
= 0; i
< c
->used
; ++i
)
8154 free_image (f
, c
->images
[i
]);
8158 FRAME_X_IMAGE_CACHE (f
) = NULL
;
8163 /* Clear image cache of frame F. FORCE_P non-zero means free all
8164 images. FORCE_P zero means clear only images that haven't been
8165 displayed for some time. Should be called from time to time to
8166 reduce the number of loaded images. If image-eviction-seconds is
8167 non-nil, this frees images in the cache which weren't displayed for
8168 at least that many seconds. */
8171 clear_image_cache (f
, force_p
)
8175 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8177 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
8181 int i
, any_freed_p
= 0;
8184 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
8186 for (i
= 0; i
< c
->used
; ++i
)
8188 struct image
*img
= c
->images
[i
];
8191 || (img
->timestamp
> old
)))
8193 free_image (f
, img
);
8198 /* We may be clearing the image cache because, for example,
8199 Emacs was iconified for a longer period of time. In that
8200 case, current matrices may still contain references to
8201 images freed above. So, clear these matrices. */
8204 clear_current_matrices (f
);
8205 ++windows_or_buffers_changed
;
8211 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
8213 "Clear the image cache of FRAME.\n\
8214 FRAME nil or omitted means use the selected frame.\n\
8215 FRAME t means clear the image caches of all frames.")
8223 FOR_EACH_FRAME (tail
, frame
)
8224 if (FRAME_W32_P (XFRAME (frame
)))
8225 clear_image_cache (XFRAME (frame
), 1);
8228 clear_image_cache (check_x_frame (frame
), 1);
8234 /* Return the id of image with Lisp specification SPEC on frame F.
8235 SPEC must be a valid Lisp image specification (see valid_image_p). */
8238 lookup_image (f
, spec
)
8242 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8246 struct gcpro gcpro1
;
8249 /* F must be a window-system frame, and SPEC must be a valid image
8251 xassert (FRAME_WINDOW_P (f
));
8252 xassert (valid_image_p (spec
));
8256 /* Look up SPEC in the hash table of the image cache. */
8257 hash
= sxhash (spec
, 0);
8258 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8260 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
8261 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
8264 /* If not found, create a new image and cache it. */
8267 img
= make_image (spec
, hash
);
8268 cache_image (f
, img
);
8269 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8270 xassert (!interrupt_input_blocked
);
8272 /* If we can't load the image, and we don't have a width and
8273 height, use some arbitrary width and height so that we can
8274 draw a rectangle for it. */
8275 if (img
->load_failed_p
)
8279 value
= image_spec_value (spec
, QCwidth
, NULL
);
8280 img
->width
= (INTEGERP (value
)
8281 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
8282 value
= image_spec_value (spec
, QCheight
, NULL
);
8283 img
->height
= (INTEGERP (value
)
8284 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
8288 /* Handle image type independent image attributes
8289 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF'. */
8290 Lisp_Object ascent
, margin
, relief
, algorithm
, heuristic_mask
;
8293 ascent
= image_spec_value (spec
, QCascent
, NULL
);
8294 if (INTEGERP (ascent
))
8295 img
->ascent
= XFASTINT (ascent
);
8296 else if (EQ (ascent
, Qcenter
))
8297 img
->ascent
= CENTERED_IMAGE_ASCENT
;
8299 margin
= image_spec_value (spec
, QCmargin
, NULL
);
8300 if (INTEGERP (margin
) && XINT (margin
) >= 0)
8301 img
->margin
= XFASTINT (margin
);
8303 relief
= image_spec_value (spec
, QCrelief
, NULL
);
8304 if (INTEGERP (relief
))
8306 img
->relief
= XINT (relief
);
8307 img
->margin
+= abs (img
->relief
);
8310 /* Should we apply a Laplace edge-detection algorithm? */
8311 algorithm
= image_spec_value (spec
, QCalgorithm
, NULL
);
8312 if (img
->pixmap
&& EQ (algorithm
, Qlaplace
))
8315 /* Should we built a mask heuristically? */
8316 heuristic_mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
8317 if (img
->pixmap
&& !img
->mask
&& !NILP (heuristic_mask
))
8318 x_build_heuristic_mask (f
, img
, heuristic_mask
);
8322 /* We're using IMG, so set its timestamp to `now'. */
8323 EMACS_GET_TIME (now
);
8324 img
->timestamp
= EMACS_SECS (now
);
8328 /* Value is the image id. */
8333 /* Cache image IMG in the image cache of frame F. */
8336 cache_image (f
, img
)
8340 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8343 /* Find a free slot in c->images. */
8344 for (i
= 0; i
< c
->used
; ++i
)
8345 if (c
->images
[i
] == NULL
)
8348 /* If no free slot found, maybe enlarge c->images. */
8349 if (i
== c
->used
&& c
->used
== c
->size
)
8352 c
->images
= (struct image
**) xrealloc (c
->images
,
8353 c
->size
* sizeof *c
->images
);
8356 /* Add IMG to c->images, and assign IMG an id. */
8362 /* Add IMG to the cache's hash table. */
8363 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8364 img
->next
= c
->buckets
[i
];
8366 img
->next
->prev
= img
;
8368 c
->buckets
[i
] = img
;
8372 /* Call FN on every image in the image cache of frame F. Used to mark
8373 Lisp Objects in the image cache. */
8376 forall_images_in_image_cache (f
, fn
)
8378 void (*fn
) P_ ((struct image
*img
));
8380 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
8382 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8386 for (i
= 0; i
< c
->used
; ++i
)
8395 /***********************************************************************
8397 ***********************************************************************/
8399 #if 0 /* TODO: W32 specific image code. */
8401 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
8402 XImage
**, Pixmap
*));
8403 static void x_destroy_x_image
P_ ((XImage
*));
8404 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
8407 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
8408 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
8409 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
8410 via xmalloc. Print error messages via image_error if an error
8411 occurs. Value is non-zero if successful. */
8414 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
8416 int width
, height
, depth
;
8420 #if 0 /* TODO: Image support for W32 */
8421 Display
*display
= FRAME_W32_DISPLAY (f
);
8422 Screen
*screen
= FRAME_X_SCREEN (f
);
8423 Window window
= FRAME_W32_WINDOW (f
);
8425 xassert (interrupt_input_blocked
);
8428 depth
= DefaultDepthOfScreen (screen
);
8429 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
8430 depth
, ZPixmap
, 0, NULL
, width
, height
,
8431 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
8434 image_error ("Unable to allocate X image", Qnil
, Qnil
);
8438 /* Allocate image raster. */
8439 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
8441 /* Allocate a pixmap of the same size. */
8442 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
8445 x_destroy_x_image (*ximg
);
8447 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
8455 /* Destroy XImage XIMG. Free XIMG->data. */
8458 x_destroy_x_image (ximg
)
8461 xassert (interrupt_input_blocked
);
8466 XDestroyImage (ximg
);
8471 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
8472 are width and height of both the image and pixmap. */
8475 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
8482 xassert (interrupt_input_blocked
);
8483 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
8484 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
8491 /***********************************************************************
8493 ***********************************************************************/
8495 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
8497 /* Find image file FILE. Look in data-directory, then
8498 x-bitmap-file-path. Value is the full name of the file found, or
8499 nil if not found. */
8502 x_find_image_file (file
)
8505 Lisp_Object file_found
, search_path
;
8506 struct gcpro gcpro1
, gcpro2
;
8510 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
8511 GCPRO2 (file_found
, search_path
);
8513 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
8514 fd
= openp (search_path
, file
, "", &file_found
, 0);
8527 /***********************************************************************
8529 ***********************************************************************/
8531 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
8532 static int xbm_load_image_from_file
P_ ((struct frame
*f
, struct image
*img
,
8534 static int xbm_image_p
P_ ((Lisp_Object object
));
8535 static int xbm_read_bitmap_file_data
P_ ((char *, int *, int *,
8539 /* Indices of image specification fields in xbm_format, below. */
8541 enum xbm_keyword_index
8558 /* Vector of image_keyword structures describing the format
8559 of valid XBM image specifications. */
8561 static struct image_keyword xbm_format
[XBM_LAST
] =
8563 {":type", IMAGE_SYMBOL_VALUE
, 1},
8564 {":file", IMAGE_STRING_VALUE
, 0},
8565 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8566 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8567 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8568 {":foreground", IMAGE_STRING_VALUE
, 0},
8569 {":background", IMAGE_STRING_VALUE
, 0},
8570 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
8571 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8572 {":relief", IMAGE_INTEGER_VALUE
, 0},
8573 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8574 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
8577 /* Structure describing the image type XBM. */
8579 static struct image_type xbm_type
=
8588 /* Tokens returned from xbm_scan. */
8597 /* Return non-zero if OBJECT is a valid XBM-type image specification.
8598 A valid specification is a list starting with the symbol `image'
8599 The rest of the list is a property list which must contain an
8602 If the specification specifies a file to load, it must contain
8603 an entry `:file FILENAME' where FILENAME is a string.
8605 If the specification is for a bitmap loaded from memory it must
8606 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
8607 WIDTH and HEIGHT are integers > 0. DATA may be:
8609 1. a string large enough to hold the bitmap data, i.e. it must
8610 have a size >= (WIDTH + 7) / 8 * HEIGHT
8612 2. a bool-vector of size >= WIDTH * HEIGHT
8614 3. a vector of strings or bool-vectors, one for each line of the
8617 Both the file and data forms may contain the additional entries
8618 `:background COLOR' and `:foreground COLOR'. If not present,
8619 foreground and background of the frame on which the image is
8620 displayed, is used. */
8623 xbm_image_p (object
)
8626 struct image_keyword kw
[XBM_LAST
];
8628 bcopy (xbm_format
, kw
, sizeof kw
);
8629 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
8632 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
8634 if (kw
[XBM_FILE
].count
)
8636 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
8644 /* Entries for `:width', `:height' and `:data' must be present. */
8645 if (!kw
[XBM_WIDTH
].count
8646 || !kw
[XBM_HEIGHT
].count
8647 || !kw
[XBM_DATA
].count
)
8650 data
= kw
[XBM_DATA
].value
;
8651 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
8652 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
8654 /* Check type of data, and width and height against contents of
8660 /* Number of elements of the vector must be >= height. */
8661 if (XVECTOR (data
)->size
< height
)
8664 /* Each string or bool-vector in data must be large enough
8665 for one line of the image. */
8666 for (i
= 0; i
< height
; ++i
)
8668 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
8672 if (XSTRING (elt
)->size
8673 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
8676 else if (BOOL_VECTOR_P (elt
))
8678 if (XBOOL_VECTOR (elt
)->size
< width
)
8685 else if (STRINGP (data
))
8687 if (XSTRING (data
)->size
8688 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
8691 else if (BOOL_VECTOR_P (data
))
8693 if (XBOOL_VECTOR (data
)->size
< width
* height
)
8700 /* Baseline must be a value between 0 and 100 (a percentage). */
8701 if (kw
[XBM_ASCENT
].count
8702 && XFASTINT (kw
[XBM_ASCENT
].value
) > 100)
8709 /* Scan a bitmap file. FP is the stream to read from. Value is
8710 either an enumerator from enum xbm_token, or a character for a
8711 single-character token, or 0 at end of file. If scanning an
8712 identifier, store the lexeme of the identifier in SVAL. If
8713 scanning a number, store its value in *IVAL. */
8716 xbm_scan (fp
, sval
, ival
)
8723 /* Skip white space. */
8724 while ((c
= fgetc (fp
)) != EOF
&& isspace (c
))
8729 else if (isdigit (c
))
8731 int value
= 0, digit
;
8736 if (c
== 'x' || c
== 'X')
8738 while ((c
= fgetc (fp
)) != EOF
)
8742 else if (c
>= 'a' && c
<= 'f')
8743 digit
= c
- 'a' + 10;
8744 else if (c
>= 'A' && c
<= 'F')
8745 digit
= c
- 'A' + 10;
8748 value
= 16 * value
+ digit
;
8751 else if (isdigit (c
))
8754 while ((c
= fgetc (fp
)) != EOF
8756 value
= 8 * value
+ c
- '0';
8762 while ((c
= fgetc (fp
)) != EOF
8764 value
= 10 * value
+ c
- '0';
8772 else if (isalpha (c
) || c
== '_')
8775 while ((c
= fgetc (fp
)) != EOF
8776 && (isalnum (c
) || c
== '_'))
8788 /* Replacement for XReadBitmapFileData which isn't available under old
8789 X versions. FILE is the name of the bitmap file to read. Set
8790 *WIDTH and *HEIGHT to the width and height of the image. Return in
8791 *DATA the bitmap data allocated with xmalloc. Value is non-zero if
8795 xbm_read_bitmap_file_data (file
, width
, height
, data
)
8797 int *width
, *height
;
8798 unsigned char **data
;
8801 char buffer
[BUFSIZ
];
8804 int bytes_per_line
, i
, nbytes
;
8810 LA1 = xbm_scan (fp, buffer, &value)
8812 #define expect(TOKEN) \
8813 if (LA1 != (TOKEN)) \
8818 #define expect_ident(IDENT) \
8819 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
8824 fp
= fopen (file
, "r");
8828 *width
= *height
= -1;
8830 LA1
= xbm_scan (fp
, buffer
, &value
);
8832 /* Parse defines for width, height and hot-spots. */
8836 expect_ident ("define");
8837 expect (XBM_TK_IDENT
);
8839 if (LA1
== XBM_TK_NUMBER
);
8841 char *p
= strrchr (buffer
, '_');
8842 p
= p
? p
+ 1 : buffer
;
8843 if (strcmp (p
, "width") == 0)
8845 else if (strcmp (p
, "height") == 0)
8848 expect (XBM_TK_NUMBER
);
8851 if (*width
< 0 || *height
< 0)
8854 /* Parse bits. Must start with `static'. */
8855 expect_ident ("static");
8856 if (LA1
== XBM_TK_IDENT
)
8858 if (strcmp (buffer
, "unsigned") == 0)
8861 expect_ident ("char");
8863 else if (strcmp (buffer
, "short") == 0)
8867 if (*width
% 16 && *width
% 16 < 9)
8870 else if (strcmp (buffer
, "char") == 0)
8878 expect (XBM_TK_IDENT
);
8884 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
8885 nbytes
= bytes_per_line
* *height
;
8886 p
= *data
= (char *) xmalloc (nbytes
);
8891 for (i
= 0; i
< nbytes
; i
+= 2)
8894 expect (XBM_TK_NUMBER
);
8897 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
8900 if (LA1
== ',' || LA1
== '}')
8908 for (i
= 0; i
< nbytes
; ++i
)
8911 expect (XBM_TK_NUMBER
);
8915 if (LA1
== ',' || LA1
== '}')
8941 /* Load XBM image IMG which will be displayed on frame F from file
8942 SPECIFIED_FILE. Value is non-zero if successful. */
8945 xbm_load_image_from_file (f
, img
, specified_file
)
8948 Lisp_Object specified_file
;
8951 unsigned char *data
;
8954 struct gcpro gcpro1
;
8956 xassert (STRINGP (specified_file
));
8960 file
= x_find_image_file (specified_file
);
8961 if (!STRINGP (file
))
8963 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8968 rc
= xbm_read_bitmap_file_data (XSTRING (file
)->data
, &img
->width
,
8969 &img
->height
, &data
);
8972 int depth
= one_w32_display_info
.n_cbits
;
8973 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
8974 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
8977 xassert (img
->width
> 0 && img
->height
> 0);
8979 /* Get foreground and background colors, maybe allocate colors. */
8980 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
8982 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
8984 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
8986 background
= x_alloc_image_color (f
, img
, value
, background
);
8988 #if 0 /* TODO : Port image display to W32 */
8991 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
8992 FRAME_W32_WINDOW (f
),
8994 img
->width
, img
->height
,
8995 foreground
, background
,
8999 if (img
->pixmap
== 0)
9001 x_clear_image (f
, img
);
9002 image_error ("Unable to create X pixmap for `%s'", file
, Qnil
);
9011 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
9018 /* Fill image IMG which is used on frame F with pixmap data. Value is
9019 non-zero if successful. */
9027 Lisp_Object file_name
;
9029 xassert (xbm_image_p (img
->spec
));
9031 /* If IMG->spec specifies a file name, create a non-file spec from it. */
9032 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
9033 if (STRINGP (file_name
))
9034 success_p
= xbm_load_image_from_file (f
, img
, file_name
);
9037 struct image_keyword fmt
[XBM_LAST
];
9040 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
9041 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
9045 /* Parse the list specification. */
9046 bcopy (xbm_format
, fmt
, sizeof fmt
);
9047 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
9050 /* Get specified width, and height. */
9051 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
9052 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
9053 xassert (img
->width
> 0 && img
->height
> 0);
9057 if (fmt
[XBM_ASCENT
].count
)
9058 img
->ascent
= XFASTINT (fmt
[XBM_ASCENT
].value
);
9060 /* Get foreground and background colors, maybe allocate colors. */
9061 if (fmt
[XBM_FOREGROUND
].count
)
9062 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
9064 if (fmt
[XBM_BACKGROUND
].count
)
9065 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
9068 /* Set bits to the bitmap image data. */
9069 data
= fmt
[XBM_DATA
].value
;
9074 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
9076 p
= bits
= (char *) alloca (nbytes
* img
->height
);
9077 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
9079 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
9081 bcopy (XSTRING (line
)->data
, p
, nbytes
);
9083 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
9086 else if (STRINGP (data
))
9087 bits
= XSTRING (data
)->data
;
9089 bits
= XBOOL_VECTOR (data
)->data
;
9091 #if 0 /* TODO : W32 XPM code */
9092 /* Create the pixmap. */
9093 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
9095 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
9096 FRAME_W32_WINDOW (f
),
9098 img
->width
, img
->height
,
9099 foreground
, background
,
9107 image_error ("Unable to create pixmap for XBM image `%s'",
9109 x_clear_image (f
, img
);
9120 /***********************************************************************
9122 ***********************************************************************/
9126 static int xpm_image_p
P_ ((Lisp_Object object
));
9127 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
9128 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
9130 #include "X11/xpm.h"
9132 /* The symbol `xpm' identifying XPM-format images. */
9136 /* Indices of image specification fields in xpm_format, below. */
9138 enum xpm_keyword_index
9152 /* Vector of image_keyword structures describing the format
9153 of valid XPM image specifications. */
9155 static struct image_keyword xpm_format
[XPM_LAST
] =
9157 {":type", IMAGE_SYMBOL_VALUE
, 1},
9158 {":file", IMAGE_STRING_VALUE
, 0},
9159 {":data", IMAGE_STRING_VALUE
, 0},
9160 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9161 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9162 {":relief", IMAGE_INTEGER_VALUE
, 0},
9163 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9164 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9165 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9168 /* Structure describing the image type XBM. */
9170 static struct image_type xpm_type
=
9180 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
9181 for XPM images. Such a list must consist of conses whose car and
9185 xpm_valid_color_symbols_p (color_symbols
)
9186 Lisp_Object color_symbols
;
9188 while (CONSP (color_symbols
))
9190 Lisp_Object sym
= XCAR (color_symbols
);
9192 || !STRINGP (XCAR (sym
))
9193 || !STRINGP (XCDR (sym
)))
9195 color_symbols
= XCDR (color_symbols
);
9198 return NILP (color_symbols
);
9202 /* Value is non-zero if OBJECT is a valid XPM image specification. */
9205 xpm_image_p (object
)
9208 struct image_keyword fmt
[XPM_LAST
];
9209 bcopy (xpm_format
, fmt
, sizeof fmt
);
9210 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
9211 /* Either `:file' or `:data' must be present. */
9212 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
9213 /* Either no `:color-symbols' or it's a list of conses
9214 whose car and cdr are strings. */
9215 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
9216 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
9217 && (fmt
[XPM_ASCENT
].count
== 0
9218 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
9222 /* Load image IMG which will be displayed on frame F. Value is
9223 non-zero if successful. */
9231 XpmAttributes attrs
;
9232 Lisp_Object specified_file
, color_symbols
;
9234 /* Configure the XPM lib. Use the visual of frame F. Allocate
9235 close colors. Return colors allocated. */
9236 bzero (&attrs
, sizeof attrs
);
9237 attrs
.visual
= FRAME_X_VISUAL (f
);
9238 attrs
.colormap
= FRAME_X_COLORMAP (f
);
9239 attrs
.valuemask
|= XpmVisual
;
9240 attrs
.valuemask
|= XpmColormap
;
9241 attrs
.valuemask
|= XpmReturnAllocPixels
;
9242 #ifdef XpmAllocCloseColors
9243 attrs
.alloc_close_colors
= 1;
9244 attrs
.valuemask
|= XpmAllocCloseColors
;
9246 attrs
.closeness
= 600;
9247 attrs
.valuemask
|= XpmCloseness
;
9250 /* If image specification contains symbolic color definitions, add
9251 these to `attrs'. */
9252 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
9253 if (CONSP (color_symbols
))
9256 XpmColorSymbol
*xpm_syms
;
9259 attrs
.valuemask
|= XpmColorSymbols
;
9261 /* Count number of symbols. */
9262 attrs
.numsymbols
= 0;
9263 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
9266 /* Allocate an XpmColorSymbol array. */
9267 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
9268 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
9269 bzero (xpm_syms
, size
);
9270 attrs
.colorsymbols
= xpm_syms
;
9272 /* Fill the color symbol array. */
9273 for (tail
= color_symbols
, i
= 0;
9275 ++i
, tail
= XCDR (tail
))
9277 Lisp_Object name
= XCAR (XCAR (tail
));
9278 Lisp_Object color
= XCDR (XCAR (tail
));
9279 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
9280 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
9281 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
9282 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
9286 /* Create a pixmap for the image, either from a file, or from a
9287 string buffer containing data in the same format as an XPM file. */
9289 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9290 if (STRINGP (specified_file
))
9292 Lisp_Object file
= x_find_image_file (specified_file
);
9293 if (!STRINGP (file
))
9295 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9300 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
9301 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
9306 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
9307 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
9308 XSTRING (buffer
)->data
,
9309 &img
->pixmap
, &img
->mask
,
9314 if (rc
== XpmSuccess
)
9316 /* Remember allocated colors. */
9317 img
->ncolors
= attrs
.nalloc_pixels
;
9318 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
9319 * sizeof *img
->colors
);
9320 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
9321 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
9323 img
->width
= attrs
.width
;
9324 img
->height
= attrs
.height
;
9325 xassert (img
->width
> 0 && img
->height
> 0);
9327 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
9329 XpmFreeAttributes (&attrs
);
9337 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
9340 case XpmFileInvalid
:
9341 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
9345 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
9348 case XpmColorFailed
:
9349 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
9353 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
9358 return rc
== XpmSuccess
;
9361 #endif /* HAVE_XPM != 0 */
9364 #if 0 /* TODO : Color tables on W32. */
9365 /***********************************************************************
9367 ***********************************************************************/
9369 /* An entry in the color table mapping an RGB color to a pixel color. */
9374 unsigned long pixel
;
9376 /* Next in color table collision list. */
9377 struct ct_color
*next
;
9380 /* The bucket vector size to use. Must be prime. */
9384 /* Value is a hash of the RGB color given by R, G, and B. */
9386 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
9388 /* The color hash table. */
9390 struct ct_color
**ct_table
;
9392 /* Number of entries in the color table. */
9394 int ct_colors_allocated
;
9396 /* Function prototypes. */
9398 static void init_color_table
P_ ((void));
9399 static void free_color_table
P_ ((void));
9400 static unsigned long *colors_in_color_table
P_ ((int *n
));
9401 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
9402 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
9405 /* Initialize the color table. */
9410 int size
= CT_SIZE
* sizeof (*ct_table
);
9411 ct_table
= (struct ct_color
**) xmalloc (size
);
9412 bzero (ct_table
, size
);
9413 ct_colors_allocated
= 0;
9417 /* Free memory associated with the color table. */
9423 struct ct_color
*p
, *next
;
9425 for (i
= 0; i
< CT_SIZE
; ++i
)
9426 for (p
= ct_table
[i
]; p
; p
= next
)
9437 /* Value is a pixel color for RGB color R, G, B on frame F. If an
9438 entry for that color already is in the color table, return the
9439 pixel color of that entry. Otherwise, allocate a new color for R,
9440 G, B, and make an entry in the color table. */
9442 static unsigned long
9443 lookup_rgb_color (f
, r
, g
, b
)
9447 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
9448 int i
= hash
% CT_SIZE
;
9451 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9452 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
9461 color
= PALETTERGB (r
, g
, b
);
9463 ++ct_colors_allocated
;
9465 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9470 p
->next
= ct_table
[i
];
9478 /* Look up pixel color PIXEL which is used on frame F in the color
9479 table. If not already present, allocate it. Value is PIXEL. */
9481 static unsigned long
9482 lookup_pixel_color (f
, pixel
)
9484 unsigned long pixel
;
9486 int i
= pixel
% CT_SIZE
;
9489 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9490 if (p
->pixel
== pixel
)
9501 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9502 color
.pixel
= pixel
;
9503 XQueryColor (NULL
, cmap
, &color
);
9504 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
9509 ++ct_colors_allocated
;
9511 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9516 p
->next
= ct_table
[i
];
9520 return FRAME_FOREGROUND_PIXEL (f
);
9526 /* Value is a vector of all pixel colors contained in the color table,
9527 allocated via xmalloc. Set *N to the number of colors. */
9529 static unsigned long *
9530 colors_in_color_table (n
)
9535 unsigned long *colors
;
9537 if (ct_colors_allocated
== 0)
9544 colors
= (unsigned long *) xmalloc (ct_colors_allocated
9546 *n
= ct_colors_allocated
;
9548 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
9549 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9550 colors
[j
++] = p
->pixel
;
9559 /***********************************************************************
9561 ***********************************************************************/
9563 #if 0 /* TODO : W32 versions of low level algorithms */
9564 static void x_laplace_write_row
P_ ((struct frame
*, long *,
9565 int, XImage
*, int));
9566 static void x_laplace_read_row
P_ ((struct frame
*, Colormap
,
9567 XColor
*, int, XImage
*, int));
9570 /* Fill COLORS with RGB colors from row Y of image XIMG. F is the
9571 frame we operate on, CMAP is the color-map in effect, and WIDTH is
9572 the width of one row in the image. */
9575 x_laplace_read_row (f
, cmap
, colors
, width
, ximg
, y
)
9585 for (x
= 0; x
< width
; ++x
)
9586 colors
[x
].pixel
= XGetPixel (ximg
, x
, y
);
9588 XQueryColors (NULL
, cmap
, colors
, width
);
9592 /* Write row Y of image XIMG. PIXELS is an array of WIDTH longs
9593 containing the pixel colors to write. F is the frame we are
9597 x_laplace_write_row (f
, pixels
, width
, ximg
, y
)
9606 for (x
= 0; x
< width
; ++x
)
9607 XPutPixel (ximg
, x
, y
, pixels
[x
]);
9611 /* Transform image IMG which is used on frame F with a Laplace
9612 edge-detection algorithm. The result is an image that can be used
9613 to draw disabled buttons, for example. */
9620 #if 0 /* TODO : W32 version */
9621 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9622 XImage
*ximg
, *oimg
;
9628 int in_y
, out_y
, rc
;
9633 /* Get the X image IMG->pixmap. */
9634 ximg
= XGetImage (NULL
, img
->pixmap
,
9635 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
9637 /* Allocate 3 input rows, and one output row of colors. */
9638 for (i
= 0; i
< 3; ++i
)
9639 in
[i
] = (XColor
*) alloca (img
->width
* sizeof (XColor
));
9640 out
= (long *) alloca (img
->width
* sizeof (long));
9642 /* Create an X image for output. */
9643 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
9646 /* Fill first two rows. */
9647 x_laplace_read_row (f
, cmap
, in
[0], img
->width
, ximg
, 0);
9648 x_laplace_read_row (f
, cmap
, in
[1], img
->width
, ximg
, 1);
9651 /* Write first row, all zeros. */
9652 init_color_table ();
9653 pixel
= lookup_rgb_color (f
, 0, 0, 0);
9654 for (x
= 0; x
< img
->width
; ++x
)
9656 x_laplace_write_row (f
, out
, img
->width
, oimg
, 0);
9659 for (y
= 2; y
< img
->height
; ++y
)
9662 int rowb
= (y
+ 2) % 3;
9664 x_laplace_read_row (f
, cmap
, in
[rowa
], img
->width
, ximg
, in_y
++);
9666 for (x
= 0; x
< img
->width
- 2; ++x
)
9668 int r
= in
[rowa
][x
].red
+ mv2
- in
[rowb
][x
+ 2].red
;
9669 int g
= in
[rowa
][x
].green
+ mv2
- in
[rowb
][x
+ 2].green
;
9670 int b
= in
[rowa
][x
].blue
+ mv2
- in
[rowb
][x
+ 2].blue
;
9672 out
[x
+ 1] = lookup_rgb_color (f
, r
& 0xffff, g
& 0xffff,
9676 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
++);
9679 /* Write last line, all zeros. */
9680 for (x
= 0; x
< img
->width
; ++x
)
9682 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
);
9684 /* Free the input image, and free resources of IMG. */
9685 XDestroyImage (ximg
);
9686 x_clear_image (f
, img
);
9688 /* Put the output image into pixmap, and destroy it. */
9689 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
9690 x_destroy_x_image (oimg
);
9692 /* Remember new pixmap and colors in IMG. */
9693 img
->pixmap
= pixmap
;
9694 img
->colors
= colors_in_color_table (&img
->ncolors
);
9695 free_color_table ();
9702 /* Build a mask for image IMG which is used on frame F. FILE is the
9703 name of an image file, for error messages. HOW determines how to
9704 determine the background color of IMG. If it is a list '(R G B)',
9705 with R, G, and B being integers >= 0, take that as the color of the
9706 background. Otherwise, determine the background color of IMG
9707 heuristically. Value is non-zero if successful. */
9710 x_build_heuristic_mask (f
, img
, how
)
9715 #if 0 /* TODO : W32 version */
9716 Display
*dpy
= FRAME_W32_DISPLAY (f
);
9717 XImage
*ximg
, *mask_img
;
9718 int x
, y
, rc
, look_at_corners_p
;
9723 /* Create an image and pixmap serving as mask. */
9724 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
9725 &mask_img
, &img
->mask
);
9732 /* Get the X image of IMG->pixmap. */
9733 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
9736 /* Determine the background color of ximg. If HOW is `(R G B)'
9737 take that as color. Otherwise, try to determine the color
9739 look_at_corners_p
= 1;
9747 && NATNUMP (XCAR (how
)))
9749 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
9753 if (i
== 3 && NILP (how
))
9755 char color_name
[30];
9756 XColor exact
, color
;
9759 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
9761 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9762 if (XLookupColor (dpy
, cmap
, color_name
, &exact
, &color
))
9765 look_at_corners_p
= 0;
9770 if (look_at_corners_p
)
9772 unsigned long corners
[4];
9775 /* Get the colors at the corners of ximg. */
9776 corners
[0] = XGetPixel (ximg
, 0, 0);
9777 corners
[1] = XGetPixel (ximg
, img
->width
- 1, 0);
9778 corners
[2] = XGetPixel (ximg
, img
->width
- 1, img
->height
- 1);
9779 corners
[3] = XGetPixel (ximg
, 0, img
->height
- 1);
9781 /* Choose the most frequently found color as background. */
9782 for (i
= best_count
= 0; i
< 4; ++i
)
9786 for (j
= n
= 0; j
< 4; ++j
)
9787 if (corners
[i
] == corners
[j
])
9791 bg
= corners
[i
], best_count
= n
;
9795 /* Set all bits in mask_img to 1 whose color in ximg is different
9796 from the background color bg. */
9797 for (y
= 0; y
< img
->height
; ++y
)
9798 for (x
= 0; x
< img
->width
; ++x
)
9799 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
9801 /* Put mask_img into img->mask. */
9802 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
9803 x_destroy_x_image (mask_img
);
9804 XDestroyImage (ximg
);
9814 /***********************************************************************
9815 PBM (mono, gray, color)
9816 ***********************************************************************/
9819 static int pbm_image_p
P_ ((Lisp_Object object
));
9820 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
9821 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
9823 /* The symbol `pbm' identifying images of this type. */
9827 /* Indices of image specification fields in gs_format, below. */
9829 enum pbm_keyword_index
9842 /* Vector of image_keyword structures describing the format
9843 of valid user-defined image specifications. */
9845 static struct image_keyword pbm_format
[PBM_LAST
] =
9847 {":type", IMAGE_SYMBOL_VALUE
, 1},
9848 {":file", IMAGE_STRING_VALUE
, 0},
9849 {":data", IMAGE_STRING_VALUE
, 0},
9850 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9851 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9852 {":relief", IMAGE_INTEGER_VALUE
, 0},
9853 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9854 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9857 /* Structure describing the image type `pbm'. */
9859 static struct image_type pbm_type
=
9869 /* Return non-zero if OBJECT is a valid PBM image specification. */
9872 pbm_image_p (object
)
9875 struct image_keyword fmt
[PBM_LAST
];
9877 bcopy (pbm_format
, fmt
, sizeof fmt
);
9879 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
9880 || (fmt
[PBM_ASCENT
].count
9881 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
9884 /* Must specify either :data or :file. */
9885 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
9889 /* Scan a decimal number from *S and return it. Advance *S while
9890 reading the number. END is the end of the string. Value is -1 at
9894 pbm_scan_number (s
, end
)
9895 unsigned char **s
, *end
;
9901 /* Skip white-space. */
9902 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
9907 /* Skip comment to end of line. */
9908 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
9911 else if (isdigit (c
))
9913 /* Read decimal number. */
9915 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
9916 val
= 10 * val
+ c
- '0';
9927 /* Read FILE into memory. Value is a pointer to a buffer allocated
9928 with xmalloc holding FILE's contents. Value is null if an error
9929 occured. *SIZE is set to the size of the file. */
9932 pbm_read_file (file
, size
)
9940 if (stat (XSTRING (file
)->data
, &st
) == 0
9941 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
9942 && (buf
= (char *) xmalloc (st
.st_size
),
9943 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
9963 /* Load PBM image IMG for use on frame F. */
9971 int width
, height
, max_color_idx
= 0;
9973 Lisp_Object file
, specified_file
;
9974 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
9975 struct gcpro gcpro1
;
9976 unsigned char *contents
= NULL
;
9977 unsigned char *end
, *p
;
9980 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9984 if (STRINGP (specified_file
))
9986 file
= x_find_image_file (specified_file
);
9987 if (!STRINGP (file
))
9989 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9994 contents
= pbm_read_file (file
, &size
);
9995 if (contents
== NULL
)
9997 image_error ("Error reading `%s'", file
, Qnil
);
10003 end
= contents
+ size
;
10008 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10009 p
= XSTRING (data
)->data
;
10010 end
= p
+ STRING_BYTES (XSTRING (data
));
10013 /* Check magic number. */
10014 if (end
- p
< 2 || *p
++ != 'P')
10016 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
10026 raw_p
= 0, type
= PBM_MONO
;
10030 raw_p
= 0, type
= PBM_GRAY
;
10034 raw_p
= 0, type
= PBM_COLOR
;
10038 raw_p
= 1, type
= PBM_MONO
;
10042 raw_p
= 1, type
= PBM_GRAY
;
10046 raw_p
= 1, type
= PBM_COLOR
;
10050 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
10054 /* Read width, height, maximum color-component. Characters
10055 starting with `#' up to the end of a line are ignored. */
10056 width
= pbm_scan_number (&p
, end
);
10057 height
= pbm_scan_number (&p
, end
);
10059 if (type
!= PBM_MONO
)
10061 max_color_idx
= pbm_scan_number (&p
, end
);
10062 if (raw_p
&& max_color_idx
> 255)
10063 max_color_idx
= 255;
10068 || (type
!= PBM_MONO
&& max_color_idx
< 0))
10072 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
10073 &ximg
, &img
->pixmap
))
10079 /* Initialize the color hash table. */
10080 init_color_table ();
10082 if (type
== PBM_MONO
)
10086 for (y
= 0; y
< height
; ++y
)
10087 for (x
= 0; x
< width
; ++x
)
10097 g
= pbm_scan_number (&p
, end
);
10099 XPutPixel (ximg
, x
, y
, (g
10100 ? FRAME_FOREGROUND_PIXEL (f
)
10101 : FRAME_BACKGROUND_PIXEL (f
)));
10106 for (y
= 0; y
< height
; ++y
)
10107 for (x
= 0; x
< width
; ++x
)
10111 if (type
== PBM_GRAY
)
10112 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
10121 r
= pbm_scan_number (&p
, end
);
10122 g
= pbm_scan_number (&p
, end
);
10123 b
= pbm_scan_number (&p
, end
);
10126 if (r
< 0 || g
< 0 || b
< 0)
10128 xfree (ximg
->data
);
10130 XDestroyImage (ximg
);
10132 image_error ("Invalid pixel value in image `%s'",
10137 /* RGB values are now in the range 0..max_color_idx.
10138 Scale this to the range 0..0xffff supported by X. */
10139 r
= (double) r
* 65535 / max_color_idx
;
10140 g
= (double) g
* 65535 / max_color_idx
;
10141 b
= (double) b
* 65535 / max_color_idx
;
10142 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10146 /* Store in IMG->colors the colors allocated for the image, and
10147 free the color table. */
10148 img
->colors
= colors_in_color_table (&img
->ncolors
);
10149 free_color_table ();
10151 /* Put the image into a pixmap. */
10152 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10153 x_destroy_x_image (ximg
);
10156 img
->width
= width
;
10157 img
->height
= height
;
10163 #endif /* HAVE_PBM */
10166 /***********************************************************************
10168 ***********************************************************************/
10174 /* Function prototypes. */
10176 static int png_image_p
P_ ((Lisp_Object object
));
10177 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
10179 /* The symbol `png' identifying images of this type. */
10183 /* Indices of image specification fields in png_format, below. */
10185 enum png_keyword_index
10194 PNG_HEURISTIC_MASK
,
10198 /* Vector of image_keyword structures describing the format
10199 of valid user-defined image specifications. */
10201 static struct image_keyword png_format
[PNG_LAST
] =
10203 {":type", IMAGE_SYMBOL_VALUE
, 1},
10204 {":data", IMAGE_STRING_VALUE
, 0},
10205 {":file", IMAGE_STRING_VALUE
, 0},
10206 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10207 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10208 {":relief", IMAGE_INTEGER_VALUE
, 0},
10209 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10210 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10213 /* Structure describing the image type `png'. */
10215 static struct image_type png_type
=
10225 /* Return non-zero if OBJECT is a valid PNG image specification. */
10228 png_image_p (object
)
10229 Lisp_Object object
;
10231 struct image_keyword fmt
[PNG_LAST
];
10232 bcopy (png_format
, fmt
, sizeof fmt
);
10234 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
10235 || (fmt
[PNG_ASCENT
].count
10236 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
10239 /* Must specify either the :data or :file keyword. */
10240 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
10244 /* Error and warning handlers installed when the PNG library
10248 my_png_error (png_ptr
, msg
)
10249 png_struct
*png_ptr
;
10252 xassert (png_ptr
!= NULL
);
10253 image_error ("PNG error: %s", build_string (msg
), Qnil
);
10254 longjmp (png_ptr
->jmpbuf
, 1);
10259 my_png_warning (png_ptr
, msg
)
10260 png_struct
*png_ptr
;
10263 xassert (png_ptr
!= NULL
);
10264 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
10267 /* Memory source for PNG decoding. */
10269 struct png_memory_storage
10271 unsigned char *bytes
; /* The data */
10272 size_t len
; /* How big is it? */
10273 int index
; /* Where are we? */
10277 /* Function set as reader function when reading PNG image from memory.
10278 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
10279 bytes from the input to DATA. */
10282 png_read_from_memory (png_ptr
, data
, length
)
10283 png_structp png_ptr
;
10287 struct png_memory_storage
*tbr
10288 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
10290 if (length
> tbr
->len
- tbr
->index
)
10291 png_error (png_ptr
, "Read error");
10293 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
10294 tbr
->index
= tbr
->index
+ length
;
10297 /* Load PNG image IMG for use on frame F. Value is non-zero if
10305 Lisp_Object file
, specified_file
;
10306 Lisp_Object specified_data
;
10308 XImage
*ximg
, *mask_img
= NULL
;
10309 struct gcpro gcpro1
;
10310 png_struct
*png_ptr
= NULL
;
10311 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
10314 png_byte
*pixels
= NULL
;
10315 png_byte
**rows
= NULL
;
10316 png_uint_32 width
, height
;
10317 int bit_depth
, color_type
, interlace_type
;
10319 png_uint_32 row_bytes
;
10322 double screen_gamma
, image_gamma
;
10324 struct png_memory_storage tbr
; /* Data to be read */
10326 /* Find out what file to load. */
10327 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10328 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10332 if (NILP (specified_data
))
10334 file
= x_find_image_file (specified_file
);
10335 if (!STRINGP (file
))
10337 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10342 /* Open the image file. */
10343 fp
= fopen (XSTRING (file
)->data
, "rb");
10346 image_error ("Cannot open image file `%s'", file
, Qnil
);
10352 /* Check PNG signature. */
10353 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
10354 || !png_check_sig (sig
, sizeof sig
))
10356 image_error ("Not a PNG file:` %s'", file
, Qnil
);
10364 /* Read from memory. */
10365 tbr
.bytes
= XSTRING (specified_data
)->data
;
10366 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
10369 /* Check PNG signature. */
10370 if (tbr
.len
< sizeof sig
10371 || !png_check_sig (tbr
.bytes
, sizeof sig
))
10373 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
10378 /* Need to skip past the signature. */
10379 tbr
.bytes
+= sizeof (sig
);
10382 /* Initialize read and info structs for PNG lib. */
10383 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
10384 my_png_error
, my_png_warning
);
10387 if (fp
) fclose (fp
);
10392 info_ptr
= png_create_info_struct (png_ptr
);
10395 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
10396 if (fp
) fclose (fp
);
10401 end_info
= png_create_info_struct (png_ptr
);
10404 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
10405 if (fp
) fclose (fp
);
10410 /* Set error jump-back. We come back here when the PNG library
10411 detects an error. */
10412 if (setjmp (png_ptr
->jmpbuf
))
10416 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10419 if (fp
) fclose (fp
);
10424 /* Read image info. */
10425 if (!NILP (specified_data
))
10426 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
10428 png_init_io (png_ptr
, fp
);
10430 png_set_sig_bytes (png_ptr
, sizeof sig
);
10431 png_read_info (png_ptr
, info_ptr
);
10432 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
10433 &interlace_type
, NULL
, NULL
);
10435 /* If image contains simply transparency data, we prefer to
10436 construct a clipping mask. */
10437 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
10442 /* This function is easier to write if we only have to handle
10443 one data format: RGB or RGBA with 8 bits per channel. Let's
10444 transform other formats into that format. */
10446 /* Strip more than 8 bits per channel. */
10447 if (bit_depth
== 16)
10448 png_set_strip_16 (png_ptr
);
10450 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
10452 png_set_expand (png_ptr
);
10454 /* Convert grayscale images to RGB. */
10455 if (color_type
== PNG_COLOR_TYPE_GRAY
10456 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
10457 png_set_gray_to_rgb (png_ptr
);
10459 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
10460 gamma_str
= getenv ("SCREEN_GAMMA");
10461 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
10463 /* Tell the PNG lib to handle gamma correction for us. */
10465 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
10466 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
10467 /* There is a special chunk in the image specifying the gamma. */
10468 png_set_sRGB (png_ptr
, info_ptr
, intent
);
10471 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
10472 /* Image contains gamma information. */
10473 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
10475 /* Use a default of 0.5 for the image gamma. */
10476 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
10478 /* Handle alpha channel by combining the image with a background
10479 color. Do this only if a real alpha channel is supplied. For
10480 simple transparency, we prefer a clipping mask. */
10481 if (!transparent_p
)
10483 png_color_16
*image_background
;
10485 if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
10486 /* Image contains a background color with which to
10487 combine the image. */
10488 png_set_background (png_ptr
, image_background
,
10489 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
10492 /* Image does not contain a background color with which
10493 to combine the image data via an alpha channel. Use
10494 the frame's background instead. */
10497 png_color_16 frame_background
;
10500 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10501 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
10502 XQueryColor (FRAME_W32_DISPLAY (f
), cmap
, &color
);
10505 bzero (&frame_background
, sizeof frame_background
);
10506 frame_background
.red
= color
.red
;
10507 frame_background
.green
= color
.green
;
10508 frame_background
.blue
= color
.blue
;
10510 png_set_background (png_ptr
, &frame_background
,
10511 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
10515 /* Update info structure. */
10516 png_read_update_info (png_ptr
, info_ptr
);
10518 /* Get number of channels. Valid values are 1 for grayscale images
10519 and images with a palette, 2 for grayscale images with transparency
10520 information (alpha channel), 3 for RGB images, and 4 for RGB
10521 images with alpha channel, i.e. RGBA. If conversions above were
10522 sufficient we should only have 3 or 4 channels here. */
10523 channels
= png_get_channels (png_ptr
, info_ptr
);
10524 xassert (channels
== 3 || channels
== 4);
10526 /* Number of bytes needed for one row of the image. */
10527 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
10529 /* Allocate memory for the image. */
10530 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
10531 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
10532 for (i
= 0; i
< height
; ++i
)
10533 rows
[i
] = pixels
+ i
* row_bytes
;
10535 /* Read the entire image. */
10536 png_read_image (png_ptr
, rows
);
10537 png_read_end (png_ptr
, info_ptr
);
10546 /* Create the X image and pixmap. */
10547 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10554 /* Create an image and pixmap serving as mask if the PNG image
10555 contains an alpha channel. */
10558 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
10559 &mask_img
, &img
->mask
))
10561 x_destroy_x_image (ximg
);
10562 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
10568 /* Fill the X image and mask from PNG data. */
10569 init_color_table ();
10571 for (y
= 0; y
< height
; ++y
)
10573 png_byte
*p
= rows
[y
];
10575 for (x
= 0; x
< width
; ++x
)
10582 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10584 /* An alpha channel, aka mask channel, associates variable
10585 transparency with an image. Where other image formats
10586 support binary transparency---fully transparent or fully
10587 opaque---PNG allows up to 254 levels of partial transparency.
10588 The PNG library implements partial transparency by combining
10589 the image with a specified background color.
10591 I'm not sure how to handle this here nicely: because the
10592 background on which the image is displayed may change, for
10593 real alpha channel support, it would be necessary to create
10594 a new image for each possible background.
10596 What I'm doing now is that a mask is created if we have
10597 boolean transparency information. Otherwise I'm using
10598 the frame's background color to combine the image with. */
10603 XPutPixel (mask_img
, x
, y
, *p
> 0);
10609 /* Remember colors allocated for this image. */
10610 img
->colors
= colors_in_color_table (&img
->ncolors
);
10611 free_color_table ();
10614 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10618 img
->width
= width
;
10619 img
->height
= height
;
10621 /* Put the image into the pixmap, then free the X image and its buffer. */
10622 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10623 x_destroy_x_image (ximg
);
10625 /* Same for the mask. */
10628 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10629 x_destroy_x_image (mask_img
);
10637 #endif /* HAVE_PNG != 0 */
10641 /***********************************************************************
10643 ***********************************************************************/
10647 /* Work around a warning about HAVE_STDLIB_H being redefined in
10649 #ifdef HAVE_STDLIB_H
10650 #define HAVE_STDLIB_H_1
10651 #undef HAVE_STDLIB_H
10652 #endif /* HAVE_STLIB_H */
10654 #include <jpeglib.h>
10655 #include <jerror.h>
10656 #include <setjmp.h>
10658 #ifdef HAVE_STLIB_H_1
10659 #define HAVE_STDLIB_H 1
10662 static int jpeg_image_p
P_ ((Lisp_Object object
));
10663 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
10665 /* The symbol `jpeg' identifying images of this type. */
10669 /* Indices of image specification fields in gs_format, below. */
10671 enum jpeg_keyword_index
10680 JPEG_HEURISTIC_MASK
,
10684 /* Vector of image_keyword structures describing the format
10685 of valid user-defined image specifications. */
10687 static struct image_keyword jpeg_format
[JPEG_LAST
] =
10689 {":type", IMAGE_SYMBOL_VALUE
, 1},
10690 {":data", IMAGE_STRING_VALUE
, 0},
10691 {":file", IMAGE_STRING_VALUE
, 0},
10692 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10693 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
10694 {":relief", IMAGE_INTEGER_VALUE
, 0},
10695 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10696 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10699 /* Structure describing the image type `jpeg'. */
10701 static struct image_type jpeg_type
=
10711 /* Return non-zero if OBJECT is a valid JPEG image specification. */
10714 jpeg_image_p (object
)
10715 Lisp_Object object
;
10717 struct image_keyword fmt
[JPEG_LAST
];
10719 bcopy (jpeg_format
, fmt
, sizeof fmt
);
10721 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
10722 || (fmt
[JPEG_ASCENT
].count
10723 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
10726 /* Must specify either the :data or :file keyword. */
10727 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
10731 struct my_jpeg_error_mgr
10733 struct jpeg_error_mgr pub
;
10734 jmp_buf setjmp_buffer
;
10738 my_error_exit (cinfo
)
10739 j_common_ptr cinfo
;
10741 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
10742 longjmp (mgr
->setjmp_buffer
, 1);
10745 /* Init source method for JPEG data source manager. Called by
10746 jpeg_read_header() before any data is actually read. See
10747 libjpeg.doc from the JPEG lib distribution. */
10750 our_init_source (cinfo
)
10751 j_decompress_ptr cinfo
;
10756 /* Fill input buffer method for JPEG data source manager. Called
10757 whenever more data is needed. We read the whole image in one step,
10758 so this only adds a fake end of input marker at the end. */
10761 our_fill_input_buffer (cinfo
)
10762 j_decompress_ptr cinfo
;
10764 /* Insert a fake EOI marker. */
10765 struct jpeg_source_mgr
*src
= cinfo
->src
;
10766 static JOCTET buffer
[2];
10768 buffer
[0] = (JOCTET
) 0xFF;
10769 buffer
[1] = (JOCTET
) JPEG_EOI
;
10771 src
->next_input_byte
= buffer
;
10772 src
->bytes_in_buffer
= 2;
10777 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
10778 is the JPEG data source manager. */
10781 our_skip_input_data (cinfo
, num_bytes
)
10782 j_decompress_ptr cinfo
;
10785 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10789 if (num_bytes
> src
->bytes_in_buffer
)
10790 ERREXIT (cinfo
, JERR_INPUT_EOF
);
10792 src
->bytes_in_buffer
-= num_bytes
;
10793 src
->next_input_byte
+= num_bytes
;
10798 /* Method to terminate data source. Called by
10799 jpeg_finish_decompress() after all data has been processed. */
10802 our_term_source (cinfo
)
10803 j_decompress_ptr cinfo
;
10808 /* Set up the JPEG lib for reading an image from DATA which contains
10809 LEN bytes. CINFO is the decompression info structure created for
10810 reading the image. */
10813 jpeg_memory_src (cinfo
, data
, len
)
10814 j_decompress_ptr cinfo
;
10818 struct jpeg_source_mgr
*src
;
10820 if (cinfo
->src
== NULL
)
10822 /* First time for this JPEG object? */
10823 cinfo
->src
= (struct jpeg_source_mgr
*)
10824 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
10825 sizeof (struct jpeg_source_mgr
));
10826 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10827 src
->next_input_byte
= data
;
10830 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
10831 src
->init_source
= our_init_source
;
10832 src
->fill_input_buffer
= our_fill_input_buffer
;
10833 src
->skip_input_data
= our_skip_input_data
;
10834 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
10835 src
->term_source
= our_term_source
;
10836 src
->bytes_in_buffer
= len
;
10837 src
->next_input_byte
= data
;
10841 /* Load image IMG for use on frame F. Patterned after example.c
10842 from the JPEG lib. */
10849 struct jpeg_decompress_struct cinfo
;
10850 struct my_jpeg_error_mgr mgr
;
10851 Lisp_Object file
, specified_file
;
10852 Lisp_Object specified_data
;
10855 int row_stride
, x
, y
;
10856 XImage
*ximg
= NULL
;
10858 unsigned long *colors
;
10860 struct gcpro gcpro1
;
10862 /* Open the JPEG file. */
10863 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10864 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10868 if (NILP (specified_data
))
10870 file
= x_find_image_file (specified_file
);
10871 if (!STRINGP (file
))
10873 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10878 fp
= fopen (XSTRING (file
)->data
, "r");
10881 image_error ("Cannot open `%s'", file
, Qnil
);
10887 /* Customize libjpeg's error handling to call my_error_exit when an
10888 error is detected. This function will perform a longjmp. */
10889 mgr
.pub
.error_exit
= my_error_exit
;
10890 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
10892 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
10896 /* Called from my_error_exit. Display a JPEG error. */
10897 char buffer
[JMSG_LENGTH_MAX
];
10898 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
10899 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
10900 build_string (buffer
));
10903 /* Close the input file and destroy the JPEG object. */
10906 jpeg_destroy_decompress (&cinfo
);
10910 /* If we already have an XImage, free that. */
10911 x_destroy_x_image (ximg
);
10913 /* Free pixmap and colors. */
10914 x_clear_image (f
, img
);
10921 /* Create the JPEG decompression object. Let it read from fp.
10922 Read the JPEG image header. */
10923 jpeg_create_decompress (&cinfo
);
10925 if (NILP (specified_data
))
10926 jpeg_stdio_src (&cinfo
, fp
);
10928 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
10929 STRING_BYTES (XSTRING (specified_data
)));
10931 jpeg_read_header (&cinfo
, TRUE
);
10933 /* Customize decompression so that color quantization will be used.
10934 Start decompression. */
10935 cinfo
.quantize_colors
= TRUE
;
10936 jpeg_start_decompress (&cinfo
);
10937 width
= img
->width
= cinfo
.output_width
;
10938 height
= img
->height
= cinfo
.output_height
;
10942 /* Create X image and pixmap. */
10943 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10947 longjmp (mgr
.setjmp_buffer
, 2);
10950 /* Allocate colors. When color quantization is used,
10951 cinfo.actual_number_of_colors has been set with the number of
10952 colors generated, and cinfo.colormap is a two-dimensional array
10953 of color indices in the range 0..cinfo.actual_number_of_colors.
10954 No more than 255 colors will be generated. */
10958 if (cinfo
.out_color_components
> 2)
10959 ir
= 0, ig
= 1, ib
= 2;
10960 else if (cinfo
.out_color_components
> 1)
10961 ir
= 0, ig
= 1, ib
= 0;
10963 ir
= 0, ig
= 0, ib
= 0;
10965 /* Use the color table mechanism because it handles colors that
10966 cannot be allocated nicely. Such colors will be replaced with
10967 a default color, and we don't have to care about which colors
10968 can be freed safely, and which can't. */
10969 init_color_table ();
10970 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
10973 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
10975 /* Multiply RGB values with 255 because X expects RGB values
10976 in the range 0..0xffff. */
10977 int r
= cinfo
.colormap
[ir
][i
] << 8;
10978 int g
= cinfo
.colormap
[ig
][i
] << 8;
10979 int b
= cinfo
.colormap
[ib
][i
] << 8;
10980 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
10983 /* Remember those colors actually allocated. */
10984 img
->colors
= colors_in_color_table (&img
->ncolors
);
10985 free_color_table ();
10989 row_stride
= width
* cinfo
.output_components
;
10990 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
10992 for (y
= 0; y
< height
; ++y
)
10994 jpeg_read_scanlines (&cinfo
, buffer
, 1);
10995 for (x
= 0; x
< cinfo
.output_width
; ++x
)
10996 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
11000 jpeg_finish_decompress (&cinfo
);
11001 jpeg_destroy_decompress (&cinfo
);
11005 /* Put the image into the pixmap. */
11006 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11007 x_destroy_x_image (ximg
);
11013 #endif /* HAVE_JPEG */
11017 /***********************************************************************
11019 ***********************************************************************/
11023 #include <tiffio.h>
11025 static int tiff_image_p
P_ ((Lisp_Object object
));
11026 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
11028 /* The symbol `tiff' identifying images of this type. */
11032 /* Indices of image specification fields in tiff_format, below. */
11034 enum tiff_keyword_index
11043 TIFF_HEURISTIC_MASK
,
11047 /* Vector of image_keyword structures describing the format
11048 of valid user-defined image specifications. */
11050 static struct image_keyword tiff_format
[TIFF_LAST
] =
11052 {":type", IMAGE_SYMBOL_VALUE
, 1},
11053 {":data", IMAGE_STRING_VALUE
, 0},
11054 {":file", IMAGE_STRING_VALUE
, 0},
11055 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11056 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11057 {":relief", IMAGE_INTEGER_VALUE
, 0},
11058 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11059 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11062 /* Structure describing the image type `tiff'. */
11064 static struct image_type tiff_type
=
11074 /* Return non-zero if OBJECT is a valid TIFF image specification. */
11077 tiff_image_p (object
)
11078 Lisp_Object object
;
11080 struct image_keyword fmt
[TIFF_LAST
];
11081 bcopy (tiff_format
, fmt
, sizeof fmt
);
11083 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
11084 || (fmt
[TIFF_ASCENT
].count
11085 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
11088 /* Must specify either the :data or :file keyword. */
11089 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
11093 /* Reading from a memory buffer for TIFF images Based on the PNG
11094 memory source, but we have to provide a lot of extra functions.
11097 We really only need to implement read and seek, but I am not
11098 convinced that the TIFF library is smart enough not to destroy
11099 itself if we only hand it the function pointers we need to
11104 unsigned char *bytes
;
11108 tiff_memory_source
;
11111 tiff_read_from_memory (data
, buf
, size
)
11116 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11118 if (size
> src
->len
- src
->index
)
11119 return (size_t) -1;
11120 bcopy (src
->bytes
+ src
->index
, buf
, size
);
11121 src
->index
+= size
;
11126 tiff_write_from_memory (data
, buf
, size
)
11131 return (size_t) -1;
11135 tiff_seek_in_memory (data
, off
, whence
)
11140 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11145 case SEEK_SET
: /* Go from beginning of source. */
11149 case SEEK_END
: /* Go from end of source. */
11150 idx
= src
->len
+ off
;
11153 case SEEK_CUR
: /* Go from current position. */
11154 idx
= src
->index
+ off
;
11157 default: /* Invalid `whence'. */
11161 if (idx
> src
->len
|| idx
< 0)
11169 tiff_close_memory (data
)
11177 tiff_mmap_memory (data
, pbase
, psize
)
11182 /* It is already _IN_ memory. */
11187 tiff_unmap_memory (data
, base
, size
)
11192 /* We don't need to do this. */
11196 tiff_size_of_memory (data
)
11199 return ((tiff_memory_source
*) data
)->len
;
11202 /* Load TIFF image IMG for use on frame F. Value is non-zero if
11210 Lisp_Object file
, specified_file
;
11211 Lisp_Object specified_data
;
11213 int width
, height
, x
, y
;
11217 struct gcpro gcpro1
;
11218 tiff_memory_source memsrc
;
11220 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11221 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11225 if (NILP (specified_data
))
11227 /* Read from a file */
11228 file
= x_find_image_file (specified_file
);
11229 if (!STRINGP (file
))
11231 image_error ("Cannot find image file `%s'", file
, Qnil
);
11236 /* Try to open the image file. */
11237 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
11240 image_error ("Cannot open `%s'", file
, Qnil
);
11247 /* Memory source! */
11248 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11249 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11252 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
11253 (TIFFReadWriteProc
) tiff_read_from_memory
,
11254 (TIFFReadWriteProc
) tiff_write_from_memory
,
11255 tiff_seek_in_memory
,
11257 tiff_size_of_memory
,
11259 tiff_unmap_memory
);
11263 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
11269 /* Get width and height of the image, and allocate a raster buffer
11270 of width x height 32-bit values. */
11271 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
11272 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
11273 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
11275 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
11279 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
11287 /* Create the X image and pixmap. */
11288 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11296 /* Initialize the color table. */
11297 init_color_table ();
11299 /* Process the pixel raster. Origin is in the lower-left corner. */
11300 for (y
= 0; y
< height
; ++y
)
11302 uint32
*row
= buf
+ y
* width
;
11304 for (x
= 0; x
< width
; ++x
)
11306 uint32 abgr
= row
[x
];
11307 int r
= TIFFGetR (abgr
) << 8;
11308 int g
= TIFFGetG (abgr
) << 8;
11309 int b
= TIFFGetB (abgr
) << 8;
11310 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
11314 /* Remember the colors allocated for the image. Free the color table. */
11315 img
->colors
= colors_in_color_table (&img
->ncolors
);
11316 free_color_table ();
11318 /* Put the image into the pixmap, then free the X image and its buffer. */
11319 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11320 x_destroy_x_image (ximg
);
11324 img
->width
= width
;
11325 img
->height
= height
;
11331 #endif /* HAVE_TIFF != 0 */
11335 /***********************************************************************
11337 ***********************************************************************/
11341 #include <gif_lib.h>
11343 static int gif_image_p
P_ ((Lisp_Object object
));
11344 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
11346 /* The symbol `gif' identifying images of this type. */
11350 /* Indices of image specification fields in gif_format, below. */
11352 enum gif_keyword_index
11361 GIF_HEURISTIC_MASK
,
11366 /* Vector of image_keyword structures describing the format
11367 of valid user-defined image specifications. */
11369 static struct image_keyword gif_format
[GIF_LAST
] =
11371 {":type", IMAGE_SYMBOL_VALUE
, 1},
11372 {":data", IMAGE_STRING_VALUE
, 0},
11373 {":file", IMAGE_STRING_VALUE
, 0},
11374 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11375 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11376 {":relief", IMAGE_INTEGER_VALUE
, 0},
11377 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11378 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11379 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0}
11382 /* Structure describing the image type `gif'. */
11384 static struct image_type gif_type
=
11393 /* Return non-zero if OBJECT is a valid GIF image specification. */
11396 gif_image_p (object
)
11397 Lisp_Object object
;
11399 struct image_keyword fmt
[GIF_LAST
];
11400 bcopy (gif_format
, fmt
, sizeof fmt
);
11402 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
11403 || (fmt
[GIF_ASCENT
].count
11404 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
11407 /* Must specify either the :data or :file keyword. */
11408 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
11411 /* Reading a GIF image from memory
11412 Based on the PNG memory stuff to a certain extent. */
11416 unsigned char *bytes
;
11422 /* Make the current memory source available to gif_read_from_memory.
11423 It's done this way because not all versions of libungif support
11424 a UserData field in the GifFileType structure. */
11425 static gif_memory_source
*current_gif_memory_src
;
11428 gif_read_from_memory (file
, buf
, len
)
11433 gif_memory_source
*src
= current_gif_memory_src
;
11435 if (len
> src
->len
- src
->index
)
11438 bcopy (src
->bytes
+ src
->index
, buf
, len
);
11444 /* Load GIF image IMG for use on frame F. Value is non-zero if
11452 Lisp_Object file
, specified_file
;
11453 Lisp_Object specified_data
;
11454 int rc
, width
, height
, x
, y
, i
;
11456 ColorMapObject
*gif_color_map
;
11457 unsigned long pixel_colors
[256];
11459 struct gcpro gcpro1
;
11461 int ino
, image_left
, image_top
, image_width
, image_height
;
11462 gif_memory_source memsrc
;
11463 unsigned char *raster
;
11465 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11466 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11470 if (NILP (specified_data
))
11472 file
= x_find_image_file (specified_file
);
11473 if (!STRINGP (file
))
11475 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11480 /* Open the GIF file. */
11481 gif
= DGifOpenFileName (XSTRING (file
)->data
);
11484 image_error ("Cannot open `%s'", file
, Qnil
);
11491 /* Read from memory! */
11492 current_gif_memory_src
= &memsrc
;
11493 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11494 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11497 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
11500 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
11506 /* Read entire contents. */
11507 rc
= DGifSlurp (gif
);
11508 if (rc
== GIF_ERROR
)
11510 image_error ("Error reading `%s'", img
->spec
, Qnil
);
11511 DGifCloseFile (gif
);
11516 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
11517 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
11518 if (ino
>= gif
->ImageCount
)
11520 image_error ("Invalid image number `%s' in image `%s'",
11522 DGifCloseFile (gif
);
11527 width
= img
->width
= gif
->SWidth
;
11528 height
= img
->height
= gif
->SHeight
;
11532 /* Create the X image and pixmap. */
11533 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11536 DGifCloseFile (gif
);
11541 /* Allocate colors. */
11542 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
11543 if (!gif_color_map
)
11544 gif_color_map
= gif
->SColorMap
;
11545 init_color_table ();
11546 bzero (pixel_colors
, sizeof pixel_colors
);
11548 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
11550 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
11551 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
11552 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
11553 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11556 img
->colors
= colors_in_color_table (&img
->ncolors
);
11557 free_color_table ();
11559 /* Clear the part of the screen image that are not covered by
11560 the image from the GIF file. Full animated GIF support
11561 requires more than can be done here (see the gif89 spec,
11562 disposal methods). Let's simply assume that the part
11563 not covered by a sub-image is in the frame's background color. */
11564 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
11565 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
11566 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
11567 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
11569 for (y
= 0; y
< image_top
; ++y
)
11570 for (x
= 0; x
< width
; ++x
)
11571 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11573 for (y
= image_top
+ image_height
; y
< height
; ++y
)
11574 for (x
= 0; x
< width
; ++x
)
11575 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11577 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
11579 for (x
= 0; x
< image_left
; ++x
)
11580 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11581 for (x
= image_left
+ image_width
; x
< width
; ++x
)
11582 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11585 /* Read the GIF image into the X image. We use a local variable
11586 `raster' here because RasterBits below is a char *, and invites
11587 problems with bytes >= 0x80. */
11588 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
11590 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
11592 static int interlace_start
[] = {0, 4, 2, 1};
11593 static int interlace_increment
[] = {8, 8, 4, 2};
11595 int row
= interlace_start
[0];
11599 for (y
= 0; y
< image_height
; y
++)
11601 if (row
>= image_height
)
11603 row
= interlace_start
[++pass
];
11604 while (row
>= image_height
)
11605 row
= interlace_start
[++pass
];
11608 for (x
= 0; x
< image_width
; x
++)
11610 int i
= raster
[(y
* image_width
) + x
];
11611 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
11615 row
+= interlace_increment
[pass
];
11620 for (y
= 0; y
< image_height
; ++y
)
11621 for (x
= 0; x
< image_width
; ++x
)
11623 int i
= raster
[y
* image_width
+ x
];
11624 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
11628 DGifCloseFile (gif
);
11630 /* Put the image into the pixmap, then free the X image and its buffer. */
11631 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11632 x_destroy_x_image (ximg
);
11639 #endif /* HAVE_GIF != 0 */
11643 /***********************************************************************
11645 ***********************************************************************/
11647 #ifdef HAVE_GHOSTSCRIPT
11648 static int gs_image_p
P_ ((Lisp_Object object
));
11649 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
11650 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
11652 /* The symbol `postscript' identifying images of this type. */
11654 Lisp_Object Qpostscript
;
11656 /* Keyword symbols. */
11658 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
11660 /* Indices of image specification fields in gs_format, below. */
11662 enum gs_keyword_index
11678 /* Vector of image_keyword structures describing the format
11679 of valid user-defined image specifications. */
11681 static struct image_keyword gs_format
[GS_LAST
] =
11683 {":type", IMAGE_SYMBOL_VALUE
, 1},
11684 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11685 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
11686 {":file", IMAGE_STRING_VALUE
, 1},
11687 {":loader", IMAGE_FUNCTION_VALUE
, 0},
11688 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
11689 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11690 {":margin", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
11691 {":relief", IMAGE_INTEGER_VALUE
, 0},
11692 {":algorithm", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11693 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11696 /* Structure describing the image type `ghostscript'. */
11698 static struct image_type gs_type
=
11708 /* Free X resources of Ghostscript image IMG which is used on frame F. */
11711 gs_clear_image (f
, img
)
11715 /* IMG->data.ptr_val may contain a recorded colormap. */
11716 xfree (img
->data
.ptr_val
);
11717 x_clear_image (f
, img
);
11721 /* Return non-zero if OBJECT is a valid Ghostscript image
11725 gs_image_p (object
)
11726 Lisp_Object object
;
11728 struct image_keyword fmt
[GS_LAST
];
11732 bcopy (gs_format
, fmt
, sizeof fmt
);
11734 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
11735 || (fmt
[GS_ASCENT
].count
11736 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
11739 /* Bounding box must be a list or vector containing 4 integers. */
11740 tem
= fmt
[GS_BOUNDING_BOX
].value
;
11743 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
11744 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
11749 else if (VECTORP (tem
))
11751 if (XVECTOR (tem
)->size
!= 4)
11753 for (i
= 0; i
< 4; ++i
)
11754 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
11764 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
11773 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
11774 struct gcpro gcpro1
, gcpro2
;
11776 double in_width
, in_height
;
11777 Lisp_Object pixel_colors
= Qnil
;
11779 /* Compute pixel size of pixmap needed from the given size in the
11780 image specification. Sizes in the specification are in pt. 1 pt
11781 = 1/72 in, xdpi and ydpi are stored in the frame's X display
11783 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
11784 in_width
= XFASTINT (pt_width
) / 72.0;
11785 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
11786 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
11787 in_height
= XFASTINT (pt_height
) / 72.0;
11788 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
11790 /* Create the pixmap. */
11792 xassert (img
->pixmap
== 0);
11793 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11794 img
->width
, img
->height
,
11795 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
11800 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
11804 /* Call the loader to fill the pixmap. It returns a process object
11805 if successful. We do not record_unwind_protect here because
11806 other places in redisplay like calling window scroll functions
11807 don't either. Let the Lisp loader use `unwind-protect' instead. */
11808 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
11810 sprintf (buffer
, "%lu %lu",
11811 (unsigned long) FRAME_W32_WINDOW (f
),
11812 (unsigned long) img
->pixmap
);
11813 window_and_pixmap_id
= build_string (buffer
);
11815 sprintf (buffer
, "%lu %lu",
11816 FRAME_FOREGROUND_PIXEL (f
),
11817 FRAME_BACKGROUND_PIXEL (f
));
11818 pixel_colors
= build_string (buffer
);
11820 XSETFRAME (frame
, f
);
11821 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
11823 loader
= intern ("gs-load-image");
11825 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
11826 make_number (img
->width
),
11827 make_number (img
->height
),
11828 window_and_pixmap_id
,
11831 return PROCESSP (img
->data
.lisp_val
);
11835 /* Kill the Ghostscript process that was started to fill PIXMAP on
11836 frame F. Called from XTread_socket when receiving an event
11837 telling Emacs that Ghostscript has finished drawing. */
11840 x_kill_gs_process (pixmap
, f
)
11844 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
11848 /* Find the image containing PIXMAP. */
11849 for (i
= 0; i
< c
->used
; ++i
)
11850 if (c
->images
[i
]->pixmap
== pixmap
)
11853 /* Kill the GS process. We should have found PIXMAP in the image
11854 cache and its image should contain a process object. */
11855 xassert (i
< c
->used
);
11856 img
= c
->images
[i
];
11857 xassert (PROCESSP (img
->data
.lisp_val
));
11858 Fkill_process (img
->data
.lisp_val
, Qnil
);
11859 img
->data
.lisp_val
= Qnil
;
11861 /* On displays with a mutable colormap, figure out the colors
11862 allocated for the image by looking at the pixels of an XImage for
11864 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
11865 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
11871 /* Try to get an XImage for img->pixmep. */
11872 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
11873 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
11878 /* Initialize the color table. */
11879 init_color_table ();
11881 /* For each pixel of the image, look its color up in the
11882 color table. After having done so, the color table will
11883 contain an entry for each color used by the image. */
11884 for (y
= 0; y
< img
->height
; ++y
)
11885 for (x
= 0; x
< img
->width
; ++x
)
11887 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
11888 lookup_pixel_color (f
, pixel
);
11891 /* Record colors in the image. Free color table and XImage. */
11892 img
->colors
= colors_in_color_table (&img
->ncolors
);
11893 free_color_table ();
11894 XDestroyImage (ximg
);
11896 #if 0 /* This doesn't seem to be the case. If we free the colors
11897 here, we get a BadAccess later in x_clear_image when
11898 freeing the colors. */
11899 /* We have allocated colors once, but Ghostscript has also
11900 allocated colors on behalf of us. So, to get the
11901 reference counts right, free them once. */
11904 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
11905 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
,
11906 img
->colors
, img
->ncolors
, 0);
11911 image_error ("Cannot get X image of `%s'; colors will not be freed",
11918 #endif /* HAVE_GHOSTSCRIPT */
11921 /***********************************************************************
11923 ***********************************************************************/
11925 DEFUN ("x-change-window-property", Fx_change_window_property
,
11926 Sx_change_window_property
, 2, 3, 0,
11927 "Change window property PROP to VALUE on the X window of FRAME.\n\
11928 PROP and VALUE must be strings. FRAME nil or omitted means use the\n\
11929 selected frame. Value is VALUE.")
11930 (prop
, value
, frame
)
11931 Lisp_Object frame
, prop
, value
;
11933 #if 0 /* TODO : port window properties to W32 */
11934 struct frame
*f
= check_x_frame (frame
);
11937 CHECK_STRING (prop
, 1);
11938 CHECK_STRING (value
, 2);
11941 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11942 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
11943 prop_atom
, XA_STRING
, 8, PropModeReplace
,
11944 XSTRING (value
)->data
, XSTRING (value
)->size
);
11946 /* Make sure the property is set when we return. */
11947 XFlush (FRAME_W32_DISPLAY (f
));
11956 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
11957 Sx_delete_window_property
, 1, 2, 0,
11958 "Remove window property PROP from X window of FRAME.\n\
11959 FRAME nil or omitted means use the selected frame. Value is PROP.")
11961 Lisp_Object prop
, frame
;
11963 #if 0 /* TODO : port window properties to W32 */
11965 struct frame
*f
= check_x_frame (frame
);
11968 CHECK_STRING (prop
, 1);
11970 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
11971 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
11973 /* Make sure the property is removed when we return. */
11974 XFlush (FRAME_W32_DISPLAY (f
));
11982 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
11984 "Value is the value of window property PROP on FRAME.\n\
11985 If FRAME is nil or omitted, use the selected frame. Value is nil\n\
11986 if FRAME hasn't a property with name PROP or if PROP has no string\n\
11989 Lisp_Object prop
, frame
;
11991 #if 0 /* TODO : port window properties to W32 */
11993 struct frame
*f
= check_x_frame (frame
);
11996 Lisp_Object prop_value
= Qnil
;
11997 char *tmp_data
= NULL
;
12000 unsigned long actual_size
, bytes_remaining
;
12002 CHECK_STRING (prop
, 1);
12004 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12005 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12006 prop_atom
, 0, 0, False
, XA_STRING
,
12007 &actual_type
, &actual_format
, &actual_size
,
12008 &bytes_remaining
, (unsigned char **) &tmp_data
);
12011 int size
= bytes_remaining
;
12016 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12017 prop_atom
, 0, bytes_remaining
,
12019 &actual_type
, &actual_format
,
12020 &actual_size
, &bytes_remaining
,
12021 (unsigned char **) &tmp_data
);
12023 prop_value
= make_string (tmp_data
, size
);
12038 /***********************************************************************
12040 ***********************************************************************/
12042 /* If non-null, an asynchronous timer that, when it expires, displays
12043 a busy cursor on all frames. */
12045 static struct atimer
*busy_cursor_atimer
;
12047 /* Non-zero means a busy cursor is currently shown. */
12049 static int busy_cursor_shown_p
;
12051 /* Number of seconds to wait before displaying a busy cursor. */
12053 static Lisp_Object Vbusy_cursor_delay
;
12055 /* Default number of seconds to wait before displaying a busy
12058 #define DEFAULT_BUSY_CURSOR_DELAY 1
12060 /* Function prototypes. */
12062 static void show_busy_cursor
P_ ((struct atimer
*));
12063 static void hide_busy_cursor
P_ ((void));
12066 /* Cancel a currently active busy-cursor timer, and start a new one. */
12069 start_busy_cursor ()
12071 #if 0 /* TODO: cursor shape changes. */
12073 int secs
, usecs
= 0;
12075 cancel_busy_cursor ();
12077 if (INTEGERP (Vbusy_cursor_delay
)
12078 && XINT (Vbusy_cursor_delay
) > 0)
12079 secs
= XFASTINT (Vbusy_cursor_delay
);
12080 else if (FLOATP (Vbusy_cursor_delay
)
12081 && XFLOAT_DATA (Vbusy_cursor_delay
) > 0)
12084 tem
= Ftruncate (Vbusy_cursor_delay
, Qnil
);
12085 secs
= XFASTINT (tem
);
12086 usecs
= (XFLOAT_DATA (Vbusy_cursor_delay
) - secs
) * 1000000;
12089 secs
= DEFAULT_BUSY_CURSOR_DELAY
;
12091 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
12092 busy_cursor_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
12093 show_busy_cursor
, NULL
);
12098 /* Cancel the busy cursor timer if active, hide a busy cursor if
12102 cancel_busy_cursor ()
12104 if (busy_cursor_atimer
)
12106 cancel_atimer (busy_cursor_atimer
);
12107 busy_cursor_atimer
= NULL
;
12110 if (busy_cursor_shown_p
)
12111 hide_busy_cursor ();
12115 /* Timer function of busy_cursor_atimer. TIMER is equal to
12116 busy_cursor_atimer.
12118 Display a busy cursor on all frames by mapping the frames'
12119 busy_window. Set the busy_p flag in the frames' output_data.x
12120 structure to indicate that a busy cursor is shown on the
12124 show_busy_cursor (timer
)
12125 struct atimer
*timer
;
12127 #if 0 /* TODO: cursor shape changes. */
12128 /* The timer implementation will cancel this timer automatically
12129 after this function has run. Set busy_cursor_atimer to null
12130 so that we know the timer doesn't have to be canceled. */
12131 busy_cursor_atimer
= NULL
;
12133 if (!busy_cursor_shown_p
)
12135 Lisp_Object rest
, frame
;
12139 FOR_EACH_FRAME (rest
, frame
)
12140 if (FRAME_X_P (XFRAME (frame
)))
12142 struct frame
*f
= XFRAME (frame
);
12144 f
->output_data
.w32
->busy_p
= 1;
12146 if (!f
->output_data
.w32
->busy_window
)
12148 unsigned long mask
= CWCursor
;
12149 XSetWindowAttributes attrs
;
12151 attrs
.cursor
= f
->output_data
.w32
->busy_cursor
;
12153 f
->output_data
.w32
->busy_window
12154 = XCreateWindow (FRAME_X_DISPLAY (f
),
12155 FRAME_OUTER_WINDOW (f
),
12156 0, 0, 32000, 32000, 0, 0,
12162 XMapRaised (FRAME_X_DISPLAY (f
), f
->output_data
.w32
->busy_window
);
12163 XFlush (FRAME_X_DISPLAY (f
));
12166 busy_cursor_shown_p
= 1;
12173 /* Hide the busy cursor on all frames, if it is currently shown. */
12176 hide_busy_cursor ()
12178 #if 0 /* TODO: cursor shape changes. */
12179 if (busy_cursor_shown_p
)
12181 Lisp_Object rest
, frame
;
12184 FOR_EACH_FRAME (rest
, frame
)
12186 struct frame
*f
= XFRAME (frame
);
12189 /* Watch out for newly created frames. */
12190 && f
->output_data
.x
->busy_window
)
12192 XUnmapWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->busy_window
);
12193 /* Sync here because XTread_socket looks at the busy_p flag
12194 that is reset to zero below. */
12195 XSync (FRAME_X_DISPLAY (f
), False
);
12196 f
->output_data
.x
->busy_p
= 0;
12200 busy_cursor_shown_p
= 0;
12208 /***********************************************************************
12210 ***********************************************************************/
12212 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
12215 /* The frame of a currently visible tooltip, or null. */
12217 Lisp_Object tip_frame
;
12219 /* If non-nil, a timer started that hides the last tooltip when it
12222 Lisp_Object tip_timer
;
12226 unwind_create_tip_frame (frame
)
12229 Lisp_Object deleted
;
12231 deleted
= unwind_create_frame (frame
);
12232 if (EQ (deleted
, Qt
))
12242 /* Create a frame for a tooltip on the display described by DPYINFO.
12243 PARMS is a list of frame parameters. Value is the frame.
12245 Note that functions called here, esp. x_default_parameter can
12246 signal errors, for instance when a specified color name is
12247 undefined. We have to make sure that we're in a consistent state
12248 when this happens. */
12251 x_create_tip_frame (dpyinfo
, parms
)
12252 struct w32_display_info
*dpyinfo
;
12255 #if 0 /* TODO : w32 version */
12257 Lisp_Object frame
, tem
;
12259 long window_prompting
= 0;
12261 int count
= specpdl_ptr
- specpdl
;
12262 struct gcpro gcpro1
, gcpro2
, gcpro3
;
12267 /* Use this general default value to start with until we know if
12268 this frame has a specified name. */
12269 Vx_resource_name
= Vinvocation_name
;
12271 #ifdef MULTI_KBOARD
12272 kb
= dpyinfo
->kboard
;
12274 kb
= &the_only_kboard
;
12277 /* Get the name of the frame to use for resource lookup. */
12278 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
12279 if (!STRINGP (name
)
12280 && !EQ (name
, Qunbound
)
12282 error ("Invalid frame name--not a string or nil");
12283 Vx_resource_name
= name
;
12286 GCPRO3 (parms
, name
, frame
);
12287 f
= make_frame (1);
12288 XSETFRAME (frame
, f
);
12289 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
12290 record_unwind_protect (unwind_create_tip_frame
, frame
);
12292 f
->output_method
= output_w32
;
12293 f
->output_data
.w32
=
12294 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
12295 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
12297 f
->output_data
.w32
->icon_bitmap
= -1;
12299 f
->output_data
.w32
->fontset
= -1;
12300 f
->icon_name
= Qnil
;
12303 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
12304 dpyinfo_refcount
= dpyinfo
->reference_count
;
12305 #endif /* GLYPH_DEBUG */
12306 #ifdef MULTI_KBOARD
12307 FRAME_KBOARD (f
) = kb
;
12309 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12310 f
->output_data
.w32
->explicit_parent
= 0;
12312 /* Set the name; the functions to which we pass f expect the name to
12314 if (EQ (name
, Qunbound
) || NILP (name
))
12316 f
->name
= build_string (dpyinfo
->x_id_name
);
12317 f
->explicit_name
= 0;
12322 f
->explicit_name
= 1;
12323 /* use the frame's title when getting resources for this frame. */
12324 specbind (Qx_resource_name
, name
);
12327 /* Extract the window parameters from the supplied values
12328 that are needed to determine window geometry. */
12332 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
12335 /* First, try whatever font the caller has specified. */
12336 if (STRINGP (font
))
12338 tem
= Fquery_fontset (font
, Qnil
);
12340 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
12342 font
= x_new_font (f
, XSTRING (font
)->data
);
12345 /* Try out a font which we hope has bold and italic variations. */
12346 if (!STRINGP (font
))
12347 font
= x_new_font (f
, "-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
12348 if (!STRINGP (font
))
12349 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12350 if (! STRINGP (font
))
12351 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12352 if (! STRINGP (font
))
12353 /* This was formerly the first thing tried, but it finds too many fonts
12354 and takes too long. */
12355 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
12356 /* If those didn't work, look for something which will at least work. */
12357 if (! STRINGP (font
))
12358 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
12360 if (! STRINGP (font
))
12361 font
= build_string ("fixed");
12363 x_default_parameter (f
, parms
, Qfont
, font
,
12364 "font", "Font", RES_TYPE_STRING
);
12367 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
12368 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
12370 /* This defaults to 2 in order to match xterm. We recognize either
12371 internalBorderWidth or internalBorder (which is what xterm calls
12373 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12377 value
= w32_get_arg (parms
, Qinternal_border_width
,
12378 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
12379 if (! EQ (value
, Qunbound
))
12380 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
12384 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
12385 "internalBorderWidth", "internalBorderWidth",
12388 /* Also do the stuff which must be set before the window exists. */
12389 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
12390 "foreground", "Foreground", RES_TYPE_STRING
);
12391 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
12392 "background", "Background", RES_TYPE_STRING
);
12393 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
12394 "pointerColor", "Foreground", RES_TYPE_STRING
);
12395 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
12396 "cursorColor", "Foreground", RES_TYPE_STRING
);
12397 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
12398 "borderColor", "BorderColor", RES_TYPE_STRING
);
12400 /* Init faces before x_default_parameter is called for scroll-bar
12401 parameters because that function calls x_set_scroll_bar_width,
12402 which calls change_frame_size, which calls Fset_window_buffer,
12403 which runs hooks, which call Fvertical_motion. At the end, we
12404 end up in init_iterator with a null face cache, which should not
12406 init_frame_faces (f
);
12408 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12409 window_prompting
= x_figure_window_size (f
, parms
);
12411 if (window_prompting
& XNegative
)
12413 if (window_prompting
& YNegative
)
12414 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
12416 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
12420 if (window_prompting
& YNegative
)
12421 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
12423 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
12426 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
12428 XSetWindowAttributes attrs
;
12429 unsigned long mask
;
12432 mask
= CWBackPixel
| CWOverrideRedirect
| CWSaveUnder
| CWEventMask
;
12433 /* Window managers looks at the override-redirect flag to
12434 determine whether or net to give windows a decoration (Xlib
12436 attrs
.override_redirect
= True
;
12437 attrs
.save_under
= True
;
12438 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
12439 /* Arrange for getting MapNotify and UnmapNotify events. */
12440 attrs
.event_mask
= StructureNotifyMask
;
12442 = FRAME_W32_WINDOW (f
)
12443 = XCreateWindow (FRAME_W32_DISPLAY (f
),
12444 FRAME_W32_DISPLAY_INFO (f
)->root_window
,
12445 /* x, y, width, height */
12449 CopyFromParent
, InputOutput
, CopyFromParent
,
12456 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
12457 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12458 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
12459 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12460 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
12461 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
12463 /* Dimensions, especially f->height, must be done via change_frame_size.
12464 Change will not be effected unless different from the current
12467 height
= f
->height
;
12469 SET_FRAME_WIDTH (f
, 0);
12470 change_frame_size (f
, height
, width
, 1, 0, 0);
12476 /* It is now ok to make the frame official even if we get an error
12477 below. And the frame needs to be on Vframe_list or making it
12478 visible won't work. */
12479 Vframe_list
= Fcons (frame
, Vframe_list
);
12482 /* Now that the frame is official, it counts as a reference to
12484 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
12486 return unbind_to (count
, frame
);
12491 #ifdef TODO /* Tooltip support not complete. */
12492 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
12493 "Show STRING in a \"tooltip\" window on frame FRAME.\n\
12494 A tooltip window is a small X window displaying a string.\n\
12496 FRAME nil or omitted means use the selected frame.\n\
12498 PARMS is an optional list of frame parameters which can be\n\
12499 used to change the tooltip's appearance.\n\
12501 Automatically hide the tooltip after TIMEOUT seconds.\n\
12502 TIMEOUT nil means use the default timeout of 5 seconds.\n\
12504 If the list of frame parameters PARAMS contains a `left' parameters,\n\
12505 the tooltip is displayed at that x-position. Otherwise it is\n\
12506 displayed at the mouse position, with offset DX added (default is 5 if\n\
12507 DX isn't specified). Likewise for the y-position; if a `top' frame\n\
12508 parameter is specified, it determines the y-position of the tooltip\n\
12509 window, otherwise it is displayed at the mouse position, with offset\n\
12510 DY added (default is -5).")
12511 (string
, frame
, parms
, timeout
, dx
, dy
)
12512 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
12516 Window root
, child
;
12517 Lisp_Object buffer
, top
, left
;
12518 struct buffer
*old_buffer
;
12519 struct text_pos pos
;
12520 int i
, width
, height
;
12521 int root_x
, root_y
, win_x
, win_y
;
12523 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
12524 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
12525 int count
= specpdl_ptr
- specpdl
;
12527 specbind (Qinhibit_redisplay
, Qt
);
12529 GCPRO4 (string
, parms
, frame
, timeout
);
12531 CHECK_STRING (string
, 0);
12532 f
= check_x_frame (frame
);
12533 if (NILP (timeout
))
12534 timeout
= make_number (5);
12536 CHECK_NATNUM (timeout
, 2);
12539 dx
= make_number (5);
12541 CHECK_NUMBER (dx
, 5);
12544 dy
= make_number (-5);
12546 CHECK_NUMBER (dy
, 6);
12548 /* Hide a previous tip, if any. */
12551 /* Add default values to frame parameters. */
12552 if (NILP (Fassq (Qname
, parms
)))
12553 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
12554 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12555 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
12556 if (NILP (Fassq (Qborder_width
, parms
)))
12557 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
12558 if (NILP (Fassq (Qborder_color
, parms
)))
12559 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
12560 if (NILP (Fassq (Qbackground_color
, parms
)))
12561 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
12564 /* Create a frame for the tooltip, and record it in the global
12565 variable tip_frame. */
12566 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
);
12567 f
= XFRAME (frame
);
12569 /* Set up the frame's root window. Currently we use a size of 80
12570 columns x 40 lines. If someone wants to show a larger tip, he
12571 will loose. I don't think this is a realistic case. */
12572 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
12573 w
->left
= w
->top
= make_number (0);
12577 w
->pseudo_window_p
= 1;
12579 /* Display the tooltip text in a temporary buffer. */
12580 buffer
= Fget_buffer_create (build_string (" *tip*"));
12581 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
12582 old_buffer
= current_buffer
;
12583 set_buffer_internal_1 (XBUFFER (buffer
));
12585 Finsert (make_number (1), &string
);
12586 clear_glyph_matrix (w
->desired_matrix
);
12587 clear_glyph_matrix (w
->current_matrix
);
12588 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
12589 try_window (FRAME_ROOT_WINDOW (f
), pos
);
12591 /* Compute width and height of the tooltip. */
12592 width
= height
= 0;
12593 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
12595 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
12596 struct glyph
*last
;
12599 /* Stop at the first empty row at the end. */
12600 if (!row
->enabled_p
|| !row
->displays_text_p
)
12603 /* Let the row go over the full width of the frame. */
12604 row
->full_width_p
= 1;
12606 /* There's a glyph at the end of rows that is use to place
12607 the cursor there. Don't include the width of this glyph. */
12608 if (row
->used
[TEXT_AREA
])
12610 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
12611 row_width
= row
->pixel_width
- last
->pixel_width
;
12614 row_width
= row
->pixel_width
;
12616 height
+= row
->height
;
12617 width
= max (width
, row_width
);
12620 /* Add the frame's internal border to the width and height the X
12621 window should have. */
12622 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12623 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12625 /* User-specified position? */
12626 left
= Fcdr (Fassq (Qleft
, parms
));
12627 top
= Fcdr (Fassq (Qtop
, parms
));
12629 /* Move the tooltip window where the mouse pointer is. Resize and
12631 #if 0 /* TODO : W32 specifics */
12633 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
12634 &root
, &child
, &root_x
, &root_y
, &win_x
, &win_y
, &pmask
);
12637 root_x
+= XINT (dx
);
12638 root_y
+= XINT (dy
);
12640 if (INTEGERP (left
))
12641 root_x
= XINT (left
);
12642 if (INTEGERP (top
))
12643 root_y
= XINT (top
);
12646 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12647 root_x
, root_y
- height
, width
, height
);
12648 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12652 /* Draw into the window. */
12653 w
->must_be_updated_p
= 1;
12654 update_single_window (w
, 1);
12656 /* Restore original current buffer. */
12657 set_buffer_internal_1 (old_buffer
);
12658 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
12660 /* Let the tip disappear after timeout seconds. */
12661 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
12662 intern ("x-hide-tip"));
12665 return unbind_to (count
, Qnil
);
12669 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
12670 "Hide the current tooltip window, if there is any.\n\
12671 Value is t is tooltip was open, nil otherwise.")
12675 Lisp_Object deleted
, frame
, timer
;
12676 struct gcpro gcpro1
, gcpro2
;
12678 /* Return quickly if nothing to do. */
12679 if (NILP (tip_timer
) && NILP (tip_frame
))
12684 GCPRO2 (frame
, timer
);
12685 tip_frame
= tip_timer
= deleted
= Qnil
;
12687 count
= BINDING_STACK_SIZE ();
12688 specbind (Qinhibit_redisplay
, Qt
);
12689 specbind (Qinhibit_quit
, Qt
);
12692 call1 (intern ("cancel-timer"), timer
);
12694 if (FRAMEP (frame
))
12696 Fdelete_frame (frame
, Qnil
);
12701 return unbind_to (count
, deleted
);
12707 /***********************************************************************
12708 File selection dialog
12709 ***********************************************************************/
12711 extern Lisp_Object Qfile_name_history
;
12713 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
12714 "Read file name, prompting with PROMPT in directory DIR.\n\
12715 Use a file selection dialog.\n\
12716 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
12717 specified. Don't let the user enter a file name in the file\n\
12718 selection dialog's entry field, if MUSTMATCH is non-nil.")
12719 (prompt
, dir
, default_filename
, mustmatch
)
12720 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
12722 struct frame
*f
= SELECTED_FRAME ();
12723 Lisp_Object file
= Qnil
;
12724 int count
= specpdl_ptr
- specpdl
;
12725 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
12726 char filename
[MAX_PATH
+ 1];
12727 char init_dir
[MAX_PATH
+ 1];
12728 int use_dialog_p
= 1;
12730 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
12731 CHECK_STRING (prompt
, 0);
12732 CHECK_STRING (dir
, 1);
12734 /* Create the dialog with PROMPT as title, using DIR as initial
12735 directory and using "*" as pattern. */
12736 dir
= Fexpand_file_name (dir
, Qnil
);
12737 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
12738 init_dir
[MAX_PATH
] = '\0';
12739 unixtodos_filename (init_dir
);
12741 if (STRINGP (default_filename
))
12743 char *file_name_only
;
12744 char *full_path_name
= XSTRING (default_filename
)->data
;
12746 unixtodos_filename (full_path_name
);
12748 file_name_only
= strrchr (full_path_name
, '\\');
12749 if (!file_name_only
)
12750 file_name_only
= full_path_name
;
12755 /* If default_file_name is a directory, don't use the open
12756 file dialog, as it does not support selecting
12758 if (!(*file_name_only
))
12762 strncpy (filename
, file_name_only
, MAX_PATH
);
12763 filename
[MAX_PATH
] = '\0';
12766 filename
[0] = '\0';
12770 OPENFILENAME file_details
;
12771 char *filename_file
;
12773 /* Prevent redisplay. */
12774 specbind (Qinhibit_redisplay
, Qt
);
12777 bzero (&file_details
, sizeof (file_details
));
12778 file_details
.lStructSize
= sizeof (file_details
);
12779 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
12780 file_details
.lpstrFile
= filename
;
12781 file_details
.nMaxFile
= sizeof (filename
);
12782 file_details
.lpstrInitialDir
= init_dir
;
12783 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
12784 file_details
.Flags
= OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
;
12786 if (!NILP (mustmatch
))
12787 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
12789 if (GetOpenFileName (&file_details
))
12791 dostounix_filename (filename
);
12792 file
= build_string (filename
);
12798 file
= unbind_to (count
, file
);
12800 /* Open File dialog will not allow folders to be selected, so resort
12801 to minibuffer completing reads for directories. */
12803 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
12804 dir
, mustmatch
, dir
, Qfile_name_history
,
12805 default_filename
, Qnil
);
12809 /* Make "Cancel" equivalent to C-g. */
12811 Fsignal (Qquit
, Qnil
);
12813 return unbind_to (count
, file
);
12818 /***********************************************************************
12820 ***********************************************************************/
12824 DEFUN ("imagep", Fimagep
, Simagep
, 1, 1, 0,
12825 "Value is non-nil if SPEC is a valid image specification.")
12829 return valid_image_p (spec
) ? Qt
: Qnil
;
12833 DEFUN ("lookup-image", Flookup_image
, Slookup_image
, 1, 1, 0, "")
12839 if (valid_image_p (spec
))
12840 id
= lookup_image (SELECTED_FRAME (), spec
);
12842 debug_print (spec
);
12843 return make_number (id
);
12846 #endif /* GLYPH_DEBUG != 0 */
12850 /***********************************************************************
12851 w32 specialized functions
12852 ***********************************************************************/
12854 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 1, 0,
12855 "This will display the W32 font dialog and return an X font string corresponding to the selection.")
12859 FRAME_PTR f
= check_x_frame (frame
);
12867 bzero (&cf
, sizeof (cf
));
12868 bzero (&lf
, sizeof (lf
));
12870 cf
.lStructSize
= sizeof (cf
);
12871 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
12872 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
;
12873 cf
.lpLogFont
= &lf
;
12875 /* Initialize as much of the font details as we can from the current
12877 hdc
= GetDC (FRAME_W32_WINDOW (f
));
12878 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
12879 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
12880 if (GetTextMetrics (hdc
, &tm
))
12882 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
12883 lf
.lfWeight
= tm
.tmWeight
;
12884 lf
.lfItalic
= tm
.tmItalic
;
12885 lf
.lfUnderline
= tm
.tmUnderlined
;
12886 lf
.lfStrikeOut
= tm
.tmStruckOut
;
12887 lf
.lfCharSet
= tm
.tmCharSet
;
12888 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
12890 SelectObject (hdc
, oldobj
);
12891 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
12893 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
12896 return build_string (buf
);
12899 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
, Sw32_send_sys_command
, 1, 2, 0,
12900 "Send frame a Windows WM_SYSCOMMAND message of type COMMAND.\n\
12901 Some useful values for command are 0xf030 to maximise frame (0xf020\n\
12902 to minimize), 0xf120 to restore frame to original size, and 0xf100\n\
12903 to activate the menubar for keyboard access. 0xf140 activates the\n\
12904 screen saver if defined.\n\
12906 If optional parameter FRAME is not specified, use selected frame.")
12908 Lisp_Object command
, frame
;
12911 FRAME_PTR f
= check_x_frame (frame
);
12913 CHECK_NUMBER (command
, 0);
12915 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
12920 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
12921 "Get Windows to perform OPERATION on DOCUMENT.\n\
12922 This is a wrapper around the ShellExecute system function, which\n\
12923 invokes the application registered to handle OPERATION for DOCUMENT.\n\
12924 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be\n\
12925 nil for the default action), and DOCUMENT is typically the name of a\n\
12926 document file or URL, but can also be a program executable to run or\n\
12927 a directory to open in the Windows Explorer.\n\
12929 If DOCUMENT is a program executable, PARAMETERS can be a string\n\
12930 containing command line parameters, but otherwise should be nil.\n\
12932 SHOW-FLAG can be used to control whether the invoked application is hidden\n\
12933 or minimized. If SHOW-FLAG is nil, the application is displayed normally,\n\
12934 otherwise it is an integer representing a ShowWindow flag:\n\
12936 0 - start hidden\n\
12937 1 - start normally\n\
12938 3 - start maximized\n\
12939 6 - start minimized")
12940 (operation
, document
, parameters
, show_flag
)
12941 Lisp_Object operation
, document
, parameters
, show_flag
;
12943 Lisp_Object current_dir
;
12945 CHECK_STRING (document
, 0);
12947 /* Encode filename and current directory. */
12948 current_dir
= ENCODE_FILE (current_buffer
->directory
);
12949 document
= ENCODE_FILE (document
);
12950 if ((int) ShellExecute (NULL
,
12951 (STRINGP (operation
) ?
12952 XSTRING (operation
)->data
: NULL
),
12953 XSTRING (document
)->data
,
12954 (STRINGP (parameters
) ?
12955 XSTRING (parameters
)->data
: NULL
),
12956 XSTRING (current_dir
)->data
,
12957 (INTEGERP (show_flag
) ?
12958 XINT (show_flag
) : SW_SHOWDEFAULT
))
12961 error ("ShellExecute failed: %s", w32_strerror (0));
12964 /* Lookup virtual keycode from string representing the name of a
12965 non-ascii keystroke into the corresponding virtual key, using
12966 lispy_function_keys. */
12968 lookup_vk_code (char *key
)
12972 for (i
= 0; i
< 256; i
++)
12973 if (lispy_function_keys
[i
] != 0
12974 && strcmp (lispy_function_keys
[i
], key
) == 0)
12980 /* Convert a one-element vector style key sequence to a hot key
12983 w32_parse_hot_key (key
)
12986 /* Copied from Fdefine_key and store_in_keymap. */
12987 register Lisp_Object c
;
12989 int lisp_modifiers
;
12991 struct gcpro gcpro1
;
12993 CHECK_VECTOR (key
, 0);
12995 if (XFASTINT (Flength (key
)) != 1)
13000 c
= Faref (key
, make_number (0));
13002 if (CONSP (c
) && lucid_event_type_list_p (c
))
13003 c
= Fevent_convert_list (c
);
13007 if (! INTEGERP (c
) && ! SYMBOLP (c
))
13008 error ("Key definition is invalid");
13010 /* Work out the base key and the modifiers. */
13013 c
= parse_modifiers (c
);
13014 lisp_modifiers
= Fcar (Fcdr (c
));
13018 vk_code
= lookup_vk_code (XSYMBOL (c
)->name
->data
);
13020 else if (INTEGERP (c
))
13022 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
13023 /* Many ascii characters are their own virtual key code. */
13024 vk_code
= XINT (c
) & CHARACTERBITS
;
13027 if (vk_code
< 0 || vk_code
> 255)
13030 if ((lisp_modifiers
& meta_modifier
) != 0
13031 && !NILP (Vw32_alt_is_meta
))
13032 lisp_modifiers
|= alt_modifier
;
13034 /* Supply defs missing from mingw32. */
13036 #define MOD_ALT 0x0001
13037 #define MOD_CONTROL 0x0002
13038 #define MOD_SHIFT 0x0004
13039 #define MOD_WIN 0x0008
13042 /* Convert lisp modifiers to Windows hot-key form. */
13043 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
13044 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
13045 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
13046 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
13048 return HOTKEY (vk_code
, w32_modifiers
);
13051 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
, Sw32_register_hot_key
, 1, 1, 0,
13052 "Register KEY as a hot-key combination.\n\
13053 Certain key combinations like Alt-Tab are reserved for system use on\n\
13054 Windows, and therefore are normally intercepted by the system. However,\n\
13055 most of these key combinations can be received by registering them as\n\
13056 hot-keys, overriding their special meaning.\n\
13058 KEY must be a one element key definition in vector form that would be\n\
13059 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta\n\
13060 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper\n\
13061 is always interpreted as the Windows modifier keys.\n\
13063 The return value is the hotkey-id if registered, otherwise nil.")
13067 key
= w32_parse_hot_key (key
);
13069 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
13071 /* Reuse an empty slot if possible. */
13072 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
13074 /* Safe to add new key to list, even if we have focus. */
13076 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
13080 /* Notify input thread about new hot-key definition, so that it
13081 takes effect without needing to switch focus. */
13082 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
13089 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
, Sw32_unregister_hot_key
, 1, 1, 0,
13090 "Unregister HOTKEY as a hot-key combination.")
13096 if (!INTEGERP (key
))
13097 key
= w32_parse_hot_key (key
);
13099 item
= Fmemq (key
, w32_grabbed_keys
);
13103 /* Notify input thread about hot-key definition being removed, so
13104 that it takes effect without needing focus switch. */
13105 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
13106 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
13109 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13116 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
, Sw32_registered_hot_keys
, 0, 0, 0,
13117 "Return list of registered hot-key IDs.")
13120 return Fcopy_sequence (w32_grabbed_keys
);
13123 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
, Sw32_reconstruct_hot_key
, 1, 1, 0,
13124 "Convert hot-key ID to a lisp key combination.")
13126 Lisp_Object hotkeyid
;
13128 int vk_code
, w32_modifiers
;
13131 CHECK_NUMBER (hotkeyid
, 0);
13133 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
13134 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
13136 if (lispy_function_keys
[vk_code
])
13137 key
= intern (lispy_function_keys
[vk_code
]);
13139 key
= make_number (vk_code
);
13141 key
= Fcons (key
, Qnil
);
13142 if (w32_modifiers
& MOD_SHIFT
)
13143 key
= Fcons (Qshift
, key
);
13144 if (w32_modifiers
& MOD_CONTROL
)
13145 key
= Fcons (Qctrl
, key
);
13146 if (w32_modifiers
& MOD_ALT
)
13147 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
13148 if (w32_modifiers
& MOD_WIN
)
13149 key
= Fcons (Qhyper
, key
);
13154 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
, Sw32_toggle_lock_key
, 1, 2, 0,
13155 "Toggle the state of the lock key KEY.\n\
13156 KEY can be `capslock', `kp-numlock', or `scroll'.\n\
13157 If the optional parameter NEW-STATE is a number, then the state of KEY\n\
13158 is set to off if the low bit of NEW-STATE is zero, otherwise on.")
13160 Lisp_Object key
, new_state
;
13165 if (EQ (key
, intern ("capslock")))
13166 vk_code
= VK_CAPITAL
;
13167 else if (EQ (key
, intern ("kp-numlock")))
13168 vk_code
= VK_NUMLOCK
;
13169 else if (EQ (key
, intern ("scroll")))
13170 vk_code
= VK_SCROLL
;
13174 if (!dwWindowsThreadId
)
13175 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
13177 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
13178 (WPARAM
) vk_code
, (LPARAM
) new_state
))
13181 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13182 return make_number (msg
.wParam
);
13187 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
13188 "Return storage information about the file system FILENAME is on.\n\
13189 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total\n\
13190 storage of the file system, FREE is the free storage, and AVAIL is the\n\
13191 storage available to a non-superuser. All 3 numbers are in bytes.\n\
13192 If the underlying system call fails, value is nil.")
13194 Lisp_Object filename
;
13196 Lisp_Object encoded
, value
;
13198 CHECK_STRING (filename
, 0);
13199 filename
= Fexpand_file_name (filename
, Qnil
);
13200 encoded
= ENCODE_FILE (filename
);
13204 /* Determining the required information on Windows turns out, sadly,
13205 to be more involved than one would hope. The original Win32 api
13206 call for this will return bogus information on some systems, but we
13207 must dynamically probe for the replacement api, since that was
13208 added rather late on. */
13210 HMODULE hKernel
= GetModuleHandle ("kernel32");
13211 BOOL (*pfn_GetDiskFreeSpaceEx
)
13212 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
13213 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
13215 /* On Windows, we may need to specify the root directory of the
13216 volume holding FILENAME. */
13217 char rootname
[MAX_PATH
];
13218 char *name
= XSTRING (encoded
)->data
;
13220 /* find the root name of the volume if given */
13221 if (isalpha (name
[0]) && name
[1] == ':')
13223 rootname
[0] = name
[0];
13224 rootname
[1] = name
[1];
13225 rootname
[2] = '\\';
13228 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
13230 char *str
= rootname
;
13234 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
13244 if (pfn_GetDiskFreeSpaceEx
)
13246 LARGE_INTEGER availbytes
;
13247 LARGE_INTEGER freebytes
;
13248 LARGE_INTEGER totalbytes
;
13250 if (pfn_GetDiskFreeSpaceEx(rootname
,
13254 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
13255 make_float ((double) freebytes
.QuadPart
),
13256 make_float ((double) availbytes
.QuadPart
));
13260 DWORD sectors_per_cluster
;
13261 DWORD bytes_per_sector
;
13262 DWORD free_clusters
;
13263 DWORD total_clusters
;
13265 if (GetDiskFreeSpace(rootname
,
13266 §ors_per_cluster
,
13270 value
= list3 (make_float ((double) total_clusters
13271 * sectors_per_cluster
* bytes_per_sector
),
13272 make_float ((double) free_clusters
13273 * sectors_per_cluster
* bytes_per_sector
),
13274 make_float ((double) free_clusters
13275 * sectors_per_cluster
* bytes_per_sector
));
13284 /* This is zero if not using MS-Windows. */
13287 /* The section below is built by the lisp expression at the top of the file,
13288 just above where these variables are declared. */
13289 /*&&& init symbols here &&&*/
13290 Qauto_raise
= intern ("auto-raise");
13291 staticpro (&Qauto_raise
);
13292 Qauto_lower
= intern ("auto-lower");
13293 staticpro (&Qauto_lower
);
13294 Qbar
= intern ("bar");
13296 Qborder_color
= intern ("border-color");
13297 staticpro (&Qborder_color
);
13298 Qborder_width
= intern ("border-width");
13299 staticpro (&Qborder_width
);
13300 Qbox
= intern ("box");
13302 Qcursor_color
= intern ("cursor-color");
13303 staticpro (&Qcursor_color
);
13304 Qcursor_type
= intern ("cursor-type");
13305 staticpro (&Qcursor_type
);
13306 Qgeometry
= intern ("geometry");
13307 staticpro (&Qgeometry
);
13308 Qicon_left
= intern ("icon-left");
13309 staticpro (&Qicon_left
);
13310 Qicon_top
= intern ("icon-top");
13311 staticpro (&Qicon_top
);
13312 Qicon_type
= intern ("icon-type");
13313 staticpro (&Qicon_type
);
13314 Qicon_name
= intern ("icon-name");
13315 staticpro (&Qicon_name
);
13316 Qinternal_border_width
= intern ("internal-border-width");
13317 staticpro (&Qinternal_border_width
);
13318 Qleft
= intern ("left");
13319 staticpro (&Qleft
);
13320 Qright
= intern ("right");
13321 staticpro (&Qright
);
13322 Qmouse_color
= intern ("mouse-color");
13323 staticpro (&Qmouse_color
);
13324 Qnone
= intern ("none");
13325 staticpro (&Qnone
);
13326 Qparent_id
= intern ("parent-id");
13327 staticpro (&Qparent_id
);
13328 Qscroll_bar_width
= intern ("scroll-bar-width");
13329 staticpro (&Qscroll_bar_width
);
13330 Qsuppress_icon
= intern ("suppress-icon");
13331 staticpro (&Qsuppress_icon
);
13332 Qundefined_color
= intern ("undefined-color");
13333 staticpro (&Qundefined_color
);
13334 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
13335 staticpro (&Qvertical_scroll_bars
);
13336 Qvisibility
= intern ("visibility");
13337 staticpro (&Qvisibility
);
13338 Qwindow_id
= intern ("window-id");
13339 staticpro (&Qwindow_id
);
13340 Qx_frame_parameter
= intern ("x-frame-parameter");
13341 staticpro (&Qx_frame_parameter
);
13342 Qx_resource_name
= intern ("x-resource-name");
13343 staticpro (&Qx_resource_name
);
13344 Quser_position
= intern ("user-position");
13345 staticpro (&Quser_position
);
13346 Quser_size
= intern ("user-size");
13347 staticpro (&Quser_size
);
13348 Qscreen_gamma
= intern ("screen-gamma");
13349 staticpro (&Qscreen_gamma
);
13350 Qline_spacing
= intern ("line-spacing");
13351 staticpro (&Qline_spacing
);
13352 Qcenter
= intern ("center");
13353 staticpro (&Qcenter
);
13354 /* This is the end of symbol initialization. */
13356 Qhyper
= intern ("hyper");
13357 staticpro (&Qhyper
);
13358 Qsuper
= intern ("super");
13359 staticpro (&Qsuper
);
13360 Qmeta
= intern ("meta");
13361 staticpro (&Qmeta
);
13362 Qalt
= intern ("alt");
13364 Qctrl
= intern ("ctrl");
13365 staticpro (&Qctrl
);
13366 Qcontrol
= intern ("control");
13367 staticpro (&Qcontrol
);
13368 Qshift
= intern ("shift");
13369 staticpro (&Qshift
);
13371 /* Text property `display' should be nonsticky by default. */
13372 Vtext_property_default_nonsticky
13373 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
13376 Qlaplace
= intern ("laplace");
13377 staticpro (&Qlaplace
);
13379 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
13380 staticpro (&Qface_set_after_frame_default
);
13382 Fput (Qundefined_color
, Qerror_conditions
,
13383 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
13384 Fput (Qundefined_color
, Qerror_message
,
13385 build_string ("Undefined color"));
13387 staticpro (&w32_grabbed_keys
);
13388 w32_grabbed_keys
= Qnil
;
13390 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
13391 "An array of color name mappings for windows.");
13392 Vw32_color_map
= Qnil
;
13394 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
13395 "Non-nil if alt key presses are passed on to Windows.\n\
13396 When non-nil, for example, alt pressed and released and then space will\n\
13397 open the System menu. When nil, Emacs silently swallows alt key events.");
13398 Vw32_pass_alt_to_system
= Qnil
;
13400 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
13401 "Non-nil if the alt key is to be considered the same as the meta key.\n\
13402 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta.");
13403 Vw32_alt_is_meta
= Qt
;
13405 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
13406 "If non-zero, the virtual key code for an alternative quit key.");
13407 XSETINT (Vw32_quit_key
, 0);
13409 DEFVAR_LISP ("w32-pass-lwindow-to-system",
13410 &Vw32_pass_lwindow_to_system
,
13411 "Non-nil if the left \"Windows\" key is passed on to Windows.\n\
13412 When non-nil, the Start menu is opened by tapping the key.");
13413 Vw32_pass_lwindow_to_system
= Qt
;
13415 DEFVAR_LISP ("w32-pass-rwindow-to-system",
13416 &Vw32_pass_rwindow_to_system
,
13417 "Non-nil if the right \"Windows\" key is passed on to Windows.\n\
13418 When non-nil, the Start menu is opened by tapping the key.");
13419 Vw32_pass_rwindow_to_system
= Qt
;
13421 DEFVAR_INT ("w32-phantom-key-code",
13422 &Vw32_phantom_key_code
,
13423 "Virtual key code used to generate \"phantom\" key presses.\n\
13424 Value is a number between 0 and 255.\n\
13426 Phantom key presses are generated in order to stop the system from\n\
13427 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or\n\
13428 `w32-pass-rwindow-to-system' is nil.");
13429 /* Although 255 is technically not a valid key code, it works and
13430 means that this hack won't interfere with any real key code. */
13431 Vw32_phantom_key_code
= 255;
13433 DEFVAR_LISP ("w32-enable-num-lock",
13434 &Vw32_enable_num_lock
,
13435 "Non-nil if Num Lock should act normally.\n\
13436 Set to nil to see Num Lock as the key `kp-numlock'.");
13437 Vw32_enable_num_lock
= Qt
;
13439 DEFVAR_LISP ("w32-enable-caps-lock",
13440 &Vw32_enable_caps_lock
,
13441 "Non-nil if Caps Lock should act normally.\n\
13442 Set to nil to see Caps Lock as the key `capslock'.");
13443 Vw32_enable_caps_lock
= Qt
;
13445 DEFVAR_LISP ("w32-scroll-lock-modifier",
13446 &Vw32_scroll_lock_modifier
,
13447 "Modifier to use for the Scroll Lock on state.\n\
13448 The value can be hyper, super, meta, alt, control or shift for the\n\
13449 respective modifier, or nil to see Scroll Lock as the key `scroll'.\n\
13450 Any other value will cause the key to be ignored.");
13451 Vw32_scroll_lock_modifier
= Qt
;
13453 DEFVAR_LISP ("w32-lwindow-modifier",
13454 &Vw32_lwindow_modifier
,
13455 "Modifier to use for the left \"Windows\" key.\n\
13456 The value can be hyper, super, meta, alt, control or shift for the\n\
13457 respective modifier, or nil to appear as the key `lwindow'.\n\
13458 Any other value will cause the key to be ignored.");
13459 Vw32_lwindow_modifier
= Qnil
;
13461 DEFVAR_LISP ("w32-rwindow-modifier",
13462 &Vw32_rwindow_modifier
,
13463 "Modifier to use for the right \"Windows\" key.\n\
13464 The value can be hyper, super, meta, alt, control or shift for the\n\
13465 respective modifier, or nil to appear as the key `rwindow'.\n\
13466 Any other value will cause the key to be ignored.");
13467 Vw32_rwindow_modifier
= Qnil
;
13469 DEFVAR_LISP ("w32-apps-modifier",
13470 &Vw32_apps_modifier
,
13471 "Modifier to use for the \"Apps\" key.\n\
13472 The value can be hyper, super, meta, alt, control or shift for the\n\
13473 respective modifier, or nil to appear as the key `apps'.\n\
13474 Any other value will cause the key to be ignored.");
13475 Vw32_apps_modifier
= Qnil
;
13477 DEFVAR_LISP ("w32-enable-synthesized-fonts", &Vw32_enable_synthesized_fonts
,
13478 "Non-nil enables selection of artificially italicized and bold fonts.");
13479 Vw32_enable_synthesized_fonts
= Qnil
;
13481 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
13482 "Non-nil enables Windows palette management to map colors exactly.");
13483 Vw32_enable_palette
= Qt
;
13485 DEFVAR_INT ("w32-mouse-button-tolerance",
13486 &Vw32_mouse_button_tolerance
,
13487 "Analogue of double click interval for faking middle mouse events.\n\
13488 The value is the minimum time in milliseconds that must elapse between\n\
13489 left/right button down events before they are considered distinct events.\n\
13490 If both mouse buttons are depressed within this interval, a middle mouse\n\
13491 button down event is generated instead.");
13492 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
13494 DEFVAR_INT ("w32-mouse-move-interval",
13495 &Vw32_mouse_move_interval
,
13496 "Minimum interval between mouse move events.\n\
13497 The value is the minimum time in milliseconds that must elapse between\n\
13498 successive mouse move (or scroll bar drag) events before they are\n\
13499 reported as lisp events.");
13500 XSETINT (Vw32_mouse_move_interval
, 0);
13502 init_x_parm_symbols ();
13504 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
13505 "List of directories to search for bitmap files for w32.");
13506 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
13508 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
13509 "The shape of the pointer when over text.\n\
13510 Changing the value does not affect existing frames\n\
13511 unless you set the mouse color.");
13512 Vx_pointer_shape
= Qnil
;
13514 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
13515 "The name Emacs uses to look up resources; for internal use only.\n\
13516 `x-get-resource' uses this as the first component of the instance name\n\
13517 when requesting resource values.\n\
13518 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
13519 was invoked, or to the value specified with the `-name' or `-rn'\n\
13520 switches, if present.");
13521 Vx_resource_name
= Qnil
;
13523 Vx_nontext_pointer_shape
= Qnil
;
13525 Vx_mode_pointer_shape
= Qnil
;
13527 DEFVAR_LISP ("x-busy-pointer-shape", &Vx_busy_pointer_shape
,
13528 "The shape of the pointer when Emacs is busy.\n\
13529 This variable takes effect when you create a new frame\n\
13530 or when you set the mouse color.");
13531 Vx_busy_pointer_shape
= Qnil
;
13533 DEFVAR_BOOL ("display-busy-cursor", &display_busy_cursor_p
,
13534 "Non-zero means Emacs displays a busy cursor on window systems.");
13535 display_busy_cursor_p
= 1;
13537 DEFVAR_LISP ("busy-cursor-delay", &Vbusy_cursor_delay
,
13538 "*Seconds to wait before displaying a busy-cursor.\n\
13539 Value must be an integer or float.");
13540 Vbusy_cursor_delay
= make_number (DEFAULT_BUSY_CURSOR_DELAY
);
13542 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
13543 &Vx_sensitive_text_pointer_shape
,
13544 "The shape of the pointer when over mouse-sensitive text.\n\
13545 This variable takes effect when you create a new frame\n\
13546 or when you set the mouse color.");
13547 Vx_sensitive_text_pointer_shape
= Qnil
;
13549 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
13550 &Vx_window_horizontal_drag_shape
,
13551 "Pointer shape to use for indicating a window can be dragged horizontally.\n\
13552 This variable takes effect when you create a new frame\n\
13553 or when you set the mouse color.");
13554 Vx_window_horizontal_drag_shape
= Qnil
;
13556 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
13557 "A string indicating the foreground color of the cursor box.");
13558 Vx_cursor_fore_pixel
= Qnil
;
13560 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
13561 "Non-nil if no window manager is in use.\n\
13562 Emacs doesn't try to figure this out; this is always nil\n\
13563 unless you set it to something else.");
13564 /* We don't have any way to find this out, so set it to nil
13565 and maybe the user would like to set it to t. */
13566 Vx_no_window_manager
= Qnil
;
13568 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
13569 &Vx_pixel_size_width_font_regexp
,
13570 "Regexp matching a font name whose width is the same as `PIXEL_SIZE'.\n\
13572 Since Emacs gets width of a font matching with this regexp from\n\
13573 PIXEL_SIZE field of the name, font finding mechanism gets faster for\n\
13574 such a font. This is especially effective for such large fonts as\n\
13575 Chinese, Japanese, and Korean.");
13576 Vx_pixel_size_width_font_regexp
= Qnil
;
13578 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
13579 "Time after which cached images are removed from the cache.\n\
13580 When an image has not been displayed this many seconds, remove it\n\
13581 from the image cache. Value must be an integer or nil with nil\n\
13582 meaning don't clear the cache.");
13583 Vimage_cache_eviction_delay
= make_number (30 * 60);
13585 DEFVAR_LISP ("w32-bdf-filename-alist",
13586 &Vw32_bdf_filename_alist
,
13587 "List of bdf fonts and their corresponding filenames.");
13588 Vw32_bdf_filename_alist
= Qnil
;
13590 DEFVAR_BOOL ("w32-strict-fontnames",
13591 &w32_strict_fontnames
,
13592 "Non-nil means only use fonts that are exact matches for those requested.\n\
13593 Default is nil, which allows old fontnames that are not XLFD compliant,\n\
13594 and allows third-party CJK display to work by specifying false charset\n\
13595 fields to trick Emacs into translating to Big5, SJIS etc.\n\
13596 Setting this to t will prevent wrong fonts being selected when\n\
13597 fontsets are automatically created.");
13598 w32_strict_fontnames
= 0;
13600 DEFVAR_BOOL ("w32-strict-painting",
13601 &w32_strict_painting
,
13602 "Non-nil means use strict rules for repainting frames.\n\
13603 Set this to nil to get the old behaviour for repainting; this should\n\
13604 only be necessary if the default setting causes problems.");
13605 w32_strict_painting
= 1;
13607 DEFVAR_LISP ("w32-system-coding-system",
13608 &Vw32_system_coding_system
,
13609 "Coding system used by Windows system functions, such as for font names.");
13610 Vw32_system_coding_system
= Qnil
;
13612 DEFVAR_LISP ("w32-charset-info-alist",
13613 &Vw32_charset_info_alist
,
13614 "Alist linking Emacs character sets to Windows fonts\n\
13615 and codepages. Each entry should be of the form:\n\
13617 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))\n\
13619 where CHARSET_NAME is a string used in font names to identify the charset,\n\
13620 WINDOWS_CHARSET is a symbol that can be one of:\n\
13621 w32-charset-ansi, w32-charset-default, w32-charset-symbol,\n\
13622 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,\n\
13623 w32-charset-chinesebig5, "
13624 #ifdef JOHAB_CHARSET
13625 "w32-charset-johab, w32-charset-hebrew,\n\
13626 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,\n\
13627 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,\n\
13628 w32-charset-russian, w32-charset-mac, w32-charset-baltic,\n"
13630 #ifdef UNICODE_CHARSET
13631 "w32-charset-unicode, "
13633 "or w32-charset-oem.\n\
13634 CODEPAGE should be an integer specifying the codepage that should be used\n\
13635 to display the character set, t to do no translation and output as Unicode,\n\
13636 or nil to do no translation and output as 8 bit (or multibyte on far-east\n\
13637 versions of Windows) characters.");
13638 Vw32_charset_info_alist
= Qnil
;
13640 staticpro (&Qw32_charset_ansi
);
13641 Qw32_charset_ansi
= intern ("w32-charset-ansi");
13642 staticpro (&Qw32_charset_symbol
);
13643 Qw32_charset_symbol
= intern ("w32-charset-symbol");
13644 staticpro (&Qw32_charset_shiftjis
);
13645 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
13646 staticpro (&Qw32_charset_hangeul
);
13647 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
13648 staticpro (&Qw32_charset_chinesebig5
);
13649 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
13650 staticpro (&Qw32_charset_gb2312
);
13651 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
13652 staticpro (&Qw32_charset_oem
);
13653 Qw32_charset_oem
= intern ("w32-charset-oem");
13655 #ifdef JOHAB_CHARSET
13657 static int w32_extra_charsets_defined
= 1;
13658 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
, "");
13660 staticpro (&Qw32_charset_johab
);
13661 Qw32_charset_johab
= intern ("w32-charset-johab");
13662 staticpro (&Qw32_charset_easteurope
);
13663 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
13664 staticpro (&Qw32_charset_turkish
);
13665 Qw32_charset_turkish
= intern ("w32-charset-turkish");
13666 staticpro (&Qw32_charset_baltic
);
13667 Qw32_charset_baltic
= intern ("w32-charset-baltic");
13668 staticpro (&Qw32_charset_russian
);
13669 Qw32_charset_russian
= intern ("w32-charset-russian");
13670 staticpro (&Qw32_charset_arabic
);
13671 Qw32_charset_arabic
= intern ("w32-charset-arabic");
13672 staticpro (&Qw32_charset_greek
);
13673 Qw32_charset_greek
= intern ("w32-charset-greek");
13674 staticpro (&Qw32_charset_hebrew
);
13675 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
13676 staticpro (&Qw32_charset_vietnamese
);
13677 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
13678 staticpro (&Qw32_charset_thai
);
13679 Qw32_charset_thai
= intern ("w32-charset-thai");
13680 staticpro (&Qw32_charset_mac
);
13681 Qw32_charset_mac
= intern ("w32-charset-mac");
13685 #ifdef UNICODE_CHARSET
13687 static int w32_unicode_charset_defined
= 1;
13688 DEFVAR_BOOL ("w32-unicode-charset-defined",
13689 &w32_unicode_charset_defined
, "");
13691 staticpro (&Qw32_charset_unicode
);
13692 Qw32_charset_unicode
= intern ("w32-charset-unicode");
13695 defsubr (&Sx_get_resource
);
13696 #if 0 /* TODO: Port to W32 */
13697 defsubr (&Sx_change_window_property
);
13698 defsubr (&Sx_delete_window_property
);
13699 defsubr (&Sx_window_property
);
13701 defsubr (&Sxw_display_color_p
);
13702 defsubr (&Sx_display_grayscale_p
);
13703 defsubr (&Sxw_color_defined_p
);
13704 defsubr (&Sxw_color_values
);
13705 defsubr (&Sx_server_max_request_size
);
13706 defsubr (&Sx_server_vendor
);
13707 defsubr (&Sx_server_version
);
13708 defsubr (&Sx_display_pixel_width
);
13709 defsubr (&Sx_display_pixel_height
);
13710 defsubr (&Sx_display_mm_width
);
13711 defsubr (&Sx_display_mm_height
);
13712 defsubr (&Sx_display_screens
);
13713 defsubr (&Sx_display_planes
);
13714 defsubr (&Sx_display_color_cells
);
13715 defsubr (&Sx_display_visual_class
);
13716 defsubr (&Sx_display_backing_store
);
13717 defsubr (&Sx_display_save_under
);
13718 defsubr (&Sx_parse_geometry
);
13719 defsubr (&Sx_create_frame
);
13720 defsubr (&Sx_open_connection
);
13721 defsubr (&Sx_close_connection
);
13722 defsubr (&Sx_display_list
);
13723 defsubr (&Sx_synchronize
);
13725 /* W32 specific functions */
13727 defsubr (&Sw32_focus_frame
);
13728 defsubr (&Sw32_select_font
);
13729 defsubr (&Sw32_define_rgb_color
);
13730 defsubr (&Sw32_default_color_map
);
13731 defsubr (&Sw32_load_color_file
);
13732 defsubr (&Sw32_send_sys_command
);
13733 defsubr (&Sw32_shell_execute
);
13734 defsubr (&Sw32_register_hot_key
);
13735 defsubr (&Sw32_unregister_hot_key
);
13736 defsubr (&Sw32_registered_hot_keys
);
13737 defsubr (&Sw32_reconstruct_hot_key
);
13738 defsubr (&Sw32_toggle_lock_key
);
13739 defsubr (&Sw32_find_bdf_fonts
);
13741 defsubr (&Sfile_system_info
);
13743 /* Setting callback functions for fontset handler. */
13744 get_font_info_func
= w32_get_font_info
;
13746 #if 0 /* This function pointer doesn't seem to be used anywhere.
13747 And the pointer assigned has the wrong type, anyway. */
13748 list_fonts_func
= w32_list_fonts
;
13751 load_font_func
= w32_load_font
;
13752 find_ccl_program_func
= w32_find_ccl_program
;
13753 query_font_func
= w32_query_font
;
13754 set_frame_fontset_func
= x_set_font
;
13755 check_window_system_func
= check_w32
;
13757 #if 0 /* TODO Image support for W32 */
13759 Qxbm
= intern ("xbm");
13761 QCtype
= intern (":type");
13762 staticpro (&QCtype
);
13763 QCalgorithm
= intern (":algorithm");
13764 staticpro (&QCalgorithm
);
13765 QCheuristic_mask
= intern (":heuristic-mask");
13766 staticpro (&QCheuristic_mask
);
13767 QCcolor_symbols
= intern (":color-symbols");
13768 staticpro (&QCcolor_symbols
);
13769 QCascent
= intern (":ascent");
13770 staticpro (&QCascent
);
13771 QCmargin
= intern (":margin");
13772 staticpro (&QCmargin
);
13773 QCrelief
= intern (":relief");
13774 staticpro (&QCrelief
);
13775 Qpostscript
= intern ("postscript");
13776 staticpro (&Qpostscript
);
13777 QCloader
= intern (":loader");
13778 staticpro (&QCloader
);
13779 QCbounding_box
= intern (":bounding-box");
13780 staticpro (&QCbounding_box
);
13781 QCpt_width
= intern (":pt-width");
13782 staticpro (&QCpt_width
);
13783 QCpt_height
= intern (":pt-height");
13784 staticpro (&QCpt_height
);
13785 QCindex
= intern (":index");
13786 staticpro (&QCindex
);
13787 Qpbm
= intern ("pbm");
13791 Qxpm
= intern ("xpm");
13796 Qjpeg
= intern ("jpeg");
13797 staticpro (&Qjpeg
);
13801 Qtiff
= intern ("tiff");
13802 staticpro (&Qtiff
);
13806 Qgif
= intern ("gif");
13811 Qpng
= intern ("png");
13815 defsubr (&Sclear_image_cache
);
13818 defsubr (&Simagep
);
13819 defsubr (&Slookup_image
);
13823 busy_cursor_atimer
= NULL
;
13824 busy_cursor_shown_p
= 0;
13825 #ifdef TODO /* Tooltip support not complete. */
13826 defsubr (&Sx_show_tip
);
13827 defsubr (&Sx_hide_tip
);
13830 staticpro (&tip_timer
);
13832 staticpro (&tip_frame
);
13834 defsubr (&Sx_file_dialog
);
13841 image_types
= NULL
;
13842 Vimage_types
= Qnil
;
13844 #if 0 /* TODO : Image support for W32 */
13845 define_image_type (&xbm_type
);
13846 define_image_type (&gs_type
);
13847 define_image_type (&pbm_type
);
13850 define_image_type (&xpm_type
);
13854 define_image_type (&jpeg_type
);
13858 define_image_type (&tiff_type
);
13862 define_image_type (&gif_type
);
13866 define_image_type (&png_type
);
13877 button
= MessageBox (NULL
,
13878 "A fatal error has occurred!\n\n"
13879 "Select Abort to exit, Retry to debug, Ignore to continue",
13880 "Emacs Abort Dialog",
13881 MB_ICONEXCLAMATION
| MB_TASKMODAL
13882 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
13897 /* For convenience when debugging. */
13901 return GetLastError ();