1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 92, 93, 94, 95, 1996, 1997, 1998, 1999, 2000, 2001
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"
40 #include "intervals.h"
41 #include "blockinput.h"
44 #include "termhooks.h"
49 #include "bitmaps/gray.xbm"
55 extern void free_frame_menubar ();
56 extern void x_compute_fringe_widths
P_ ((struct frame
*, int));
57 extern double atof ();
58 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
59 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
60 extern void w32_free_menu_strings
P_ ((HWND
));
64 /* A definition of XColor for non-X frames. */
65 #ifndef HAVE_X_WINDOWS
68 unsigned short red
, green
, blue
;
74 extern char *lispy_function_keys
[];
76 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
77 it, and including `bitmaps/gray' more than once is a problem when
78 config.h defines `static' as an empty replacement string. */
80 int gray_bitmap_width
= gray_width
;
81 int gray_bitmap_height
= gray_height
;
82 unsigned char *gray_bitmap_bits
= gray_bits
;
84 /* The colormap for converting color names to RGB values */
85 Lisp_Object Vw32_color_map
;
87 /* Non nil if alt key presses are passed on to Windows. */
88 Lisp_Object Vw32_pass_alt_to_system
;
90 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
92 Lisp_Object Vw32_alt_is_meta
;
94 /* If non-zero, the windows virtual key code for an alternative quit key. */
95 Lisp_Object Vw32_quit_key
;
97 /* Non nil if left window key events are passed on to Windows (this only
98 affects whether "tapping" the key opens the Start menu). */
99 Lisp_Object Vw32_pass_lwindow_to_system
;
101 /* Non nil if right window key events are passed on to Windows (this
102 only affects whether "tapping" the key opens the Start menu). */
103 Lisp_Object Vw32_pass_rwindow_to_system
;
105 /* Virtual key code used to generate "phantom" key presses in order
106 to stop system from acting on Windows key events. */
107 Lisp_Object Vw32_phantom_key_code
;
109 /* Modifier associated with the left "Windows" key, or nil to act as a
111 Lisp_Object Vw32_lwindow_modifier
;
113 /* Modifier associated with the right "Windows" key, or nil to act as a
115 Lisp_Object Vw32_rwindow_modifier
;
117 /* Modifier associated with the "Apps" key, or nil to act as a normal
119 Lisp_Object Vw32_apps_modifier
;
121 /* Value is nil if Num Lock acts as a function key. */
122 Lisp_Object Vw32_enable_num_lock
;
124 /* Value is nil if Caps Lock acts as a function key. */
125 Lisp_Object Vw32_enable_caps_lock
;
127 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
128 Lisp_Object Vw32_scroll_lock_modifier
;
130 /* Switch to control whether we inhibit requests for synthesized bold
131 and italic versions of fonts. */
132 int w32_enable_synthesized_fonts
;
134 /* Enable palette management. */
135 Lisp_Object Vw32_enable_palette
;
137 /* Control how close left/right button down events must be to
138 be converted to a middle button down event. */
139 Lisp_Object Vw32_mouse_button_tolerance
;
141 /* Minimum interval between mouse movement (and scroll bar drag)
142 events that are passed on to the event loop. */
143 Lisp_Object Vw32_mouse_move_interval
;
145 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
146 int w32_pass_extra_mouse_buttons_to_system
;
148 /* The name we're using in resource queries. */
149 Lisp_Object Vx_resource_name
;
151 /* Non nil if no window manager is in use. */
152 Lisp_Object Vx_no_window_manager
;
154 /* Non-zero means we're allowed to display a hourglass pointer. */
156 int display_hourglass_p
;
158 /* The background and shape of the mouse pointer, and shape when not
159 over text or in the modeline. */
161 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
162 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
164 /* The shape when over mouse-sensitive text. */
166 Lisp_Object Vx_sensitive_text_pointer_shape
;
168 /* Color of chars displayed in cursor box. */
170 Lisp_Object Vx_cursor_fore_pixel
;
172 /* Nonzero if using Windows. */
174 static int w32_in_use
;
176 /* Search path for bitmap files. */
178 Lisp_Object Vx_bitmap_file_path
;
180 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
182 Lisp_Object Vx_pixel_size_width_font_regexp
;
184 /* Alist of bdf fonts and the files that define them. */
185 Lisp_Object Vw32_bdf_filename_alist
;
187 /* A flag to control whether fonts are matched strictly or not. */
188 int w32_strict_fontnames
;
190 /* A flag to control whether we should only repaint if GetUpdateRect
191 indicates there is an update region. */
192 int w32_strict_painting
;
194 /* Associative list linking character set strings to Windows codepages. */
195 Lisp_Object Vw32_charset_info_alist
;
197 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
198 #ifndef VIETNAMESE_CHARSET
199 #define VIETNAMESE_CHARSET 163
202 Lisp_Object Qauto_raise
;
203 Lisp_Object Qauto_lower
;
205 Lisp_Object Qborder_color
;
206 Lisp_Object Qborder_width
;
208 Lisp_Object Qcursor_color
;
209 Lisp_Object Qcursor_type
;
210 Lisp_Object Qgeometry
;
211 Lisp_Object Qicon_left
;
212 Lisp_Object Qicon_top
;
213 Lisp_Object Qicon_type
;
214 Lisp_Object Qicon_name
;
215 Lisp_Object Qinternal_border_width
;
218 Lisp_Object Qmouse_color
;
220 Lisp_Object Qparent_id
;
221 Lisp_Object Qscroll_bar_width
;
222 Lisp_Object Qsuppress_icon
;
223 Lisp_Object Qundefined_color
;
224 Lisp_Object Qvertical_scroll_bars
;
225 Lisp_Object Qvisibility
;
226 Lisp_Object Qwindow_id
;
227 Lisp_Object Qx_frame_parameter
;
228 Lisp_Object Qx_resource_name
;
229 Lisp_Object Quser_position
;
230 Lisp_Object Quser_size
;
231 Lisp_Object Qscreen_gamma
;
232 Lisp_Object Qline_spacing
;
234 Lisp_Object Qcancel_timer
;
240 Lisp_Object Qcontrol
;
243 Lisp_Object Qw32_charset_ansi
;
244 Lisp_Object Qw32_charset_default
;
245 Lisp_Object Qw32_charset_symbol
;
246 Lisp_Object Qw32_charset_shiftjis
;
247 Lisp_Object Qw32_charset_hangeul
;
248 Lisp_Object Qw32_charset_gb2312
;
249 Lisp_Object Qw32_charset_chinesebig5
;
250 Lisp_Object Qw32_charset_oem
;
252 #ifndef JOHAB_CHARSET
253 #define JOHAB_CHARSET 130
256 Lisp_Object Qw32_charset_easteurope
;
257 Lisp_Object Qw32_charset_turkish
;
258 Lisp_Object Qw32_charset_baltic
;
259 Lisp_Object Qw32_charset_russian
;
260 Lisp_Object Qw32_charset_arabic
;
261 Lisp_Object Qw32_charset_greek
;
262 Lisp_Object Qw32_charset_hebrew
;
263 Lisp_Object Qw32_charset_vietnamese
;
264 Lisp_Object Qw32_charset_thai
;
265 Lisp_Object Qw32_charset_johab
;
266 Lisp_Object Qw32_charset_mac
;
269 #ifdef UNICODE_CHARSET
270 Lisp_Object Qw32_charset_unicode
;
273 extern Lisp_Object Qtop
;
274 extern Lisp_Object Qdisplay
;
275 extern Lisp_Object Qtool_bar_lines
;
277 /* State variables for emulating a three button mouse. */
282 static int button_state
= 0;
283 static W32Msg saved_mouse_button_msg
;
284 static unsigned mouse_button_timer
; /* non-zero when timer is active */
285 static W32Msg saved_mouse_move_msg
;
286 static unsigned mouse_move_timer
;
288 /* Window that is tracking the mouse. */
289 static HWND track_mouse_window
;
290 FARPROC track_mouse_event_fn
;
292 /* W95 mousewheel handler */
293 unsigned int msh_mousewheel
= 0;
295 #define MOUSE_BUTTON_ID 1
296 #define MOUSE_MOVE_ID 2
298 /* The below are defined in frame.c. */
300 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
301 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
, Qbuffer_predicate
, Qtitle
;
302 extern Lisp_Object Qtool_bar_lines
;
304 extern Lisp_Object Vwindow_system_version
;
306 Lisp_Object Qface_set_after_frame_default
;
309 int image_cache_refcount
, dpyinfo_refcount
;
313 /* From w32term.c. */
314 extern Lisp_Object Vw32_num_mouse_buttons
;
315 extern Lisp_Object Vw32_recognize_altgr
;
317 extern HWND w32_system_caret_hwnd
;
318 extern int w32_system_caret_width
;
319 extern int w32_system_caret_height
;
320 extern int w32_system_caret_x
;
321 extern int w32_system_caret_y
;
324 /* Error if we are not connected to MS-Windows. */
329 error ("MS-Windows not in use or not initialized");
332 /* Nonzero if we can use mouse menus.
333 You should not call this unless HAVE_MENUS is defined. */
341 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
342 and checking validity for W32. */
345 check_x_frame (frame
)
351 frame
= selected_frame
;
352 CHECK_LIVE_FRAME (frame
);
354 if (! FRAME_W32_P (f
))
355 error ("non-w32 frame used");
359 /* Let the user specify an display with a frame.
360 nil stands for the selected frame--or, if that is not a w32 frame,
361 the first display on the list. */
363 static struct w32_display_info
*
364 check_x_display_info (frame
)
369 struct frame
*sf
= XFRAME (selected_frame
);
371 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
372 return FRAME_W32_DISPLAY_INFO (sf
);
374 return &one_w32_display_info
;
376 else if (STRINGP (frame
))
377 return x_display_info_for_name (frame
);
382 CHECK_LIVE_FRAME (frame
);
384 if (! FRAME_W32_P (f
))
385 error ("non-w32 frame used");
386 return FRAME_W32_DISPLAY_INFO (f
);
390 /* Return the Emacs frame-object corresponding to an w32 window.
391 It could be the frame's main window or an icon window. */
393 /* This function can be called during GC, so use GC_xxx type test macros. */
396 x_window_to_frame (dpyinfo
, wdesc
)
397 struct w32_display_info
*dpyinfo
;
400 Lisp_Object tail
, frame
;
403 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
406 if (!GC_FRAMEP (frame
))
409 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
411 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
414 if (FRAME_W32_WINDOW (f
) == wdesc
)
422 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
423 id, which is just an int that this section returns. Bitmaps are
424 reference counted so they can be shared among frames.
426 Bitmap indices are guaranteed to be > 0, so a negative number can
427 be used to indicate no bitmap.
429 If you use x_create_bitmap_from_data, then you must keep track of
430 the bitmaps yourself. That is, creating a bitmap from the same
431 data more than once will not be caught. */
434 /* Functions to access the contents of a bitmap, given an id. */
437 x_bitmap_height (f
, id
)
441 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
445 x_bitmap_width (f
, id
)
449 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
453 x_bitmap_pixmap (f
, id
)
457 return (int) FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
461 /* Allocate a new bitmap record. Returns index of new record. */
464 x_allocate_bitmap_record (f
)
467 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
470 if (dpyinfo
->bitmaps
== NULL
)
472 dpyinfo
->bitmaps_size
= 10;
474 = (struct w32_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
475 dpyinfo
->bitmaps_last
= 1;
479 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
480 return ++dpyinfo
->bitmaps_last
;
482 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
483 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
486 dpyinfo
->bitmaps_size
*= 2;
488 = (struct w32_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
489 dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
490 return ++dpyinfo
->bitmaps_last
;
493 /* Add one reference to the reference count of the bitmap with id ID. */
496 x_reference_bitmap (f
, id
)
500 ++FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
503 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
506 x_create_bitmap_from_data (f
, bits
, width
, height
)
509 unsigned int width
, height
;
511 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
515 bitmap
= CreateBitmap (width
, height
,
516 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_planes
,
517 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_cbits
,
523 id
= x_allocate_bitmap_record (f
);
524 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
525 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
526 dpyinfo
->bitmaps
[id
- 1].hinst
= NULL
;
527 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
528 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
529 dpyinfo
->bitmaps
[id
- 1].height
= height
;
530 dpyinfo
->bitmaps
[id
- 1].width
= width
;
535 /* Create bitmap from file FILE for frame F. */
538 x_create_bitmap_from_file (f
, file
)
543 #if 0 /* TODO : bitmap support */
544 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
545 unsigned int width
, height
;
547 int xhot
, yhot
, result
, id
;
553 /* Look for an existing bitmap with the same name. */
554 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
556 if (dpyinfo
->bitmaps
[id
].refcount
557 && dpyinfo
->bitmaps
[id
].file
558 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) XSTRING (file
)->data
))
560 ++dpyinfo
->bitmaps
[id
].refcount
;
565 /* Search bitmap-file-path for the file, if appropriate. */
566 fd
= openp (Vx_bitmap_file_path
, file
, Qnil
, &found
, 0);
571 filename
= (char *) XSTRING (found
)->data
;
573 hinst
= LoadLibraryEx (filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
579 result
= XReadBitmapFile (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
580 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
581 if (result
!= BitmapSuccess
)
584 id
= x_allocate_bitmap_record (f
);
585 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
586 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
587 dpyinfo
->bitmaps
[id
- 1].file
= (char *) xmalloc (XSTRING (file
)->size
+ 1);
588 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
589 dpyinfo
->bitmaps
[id
- 1].height
= height
;
590 dpyinfo
->bitmaps
[id
- 1].width
= width
;
591 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, XSTRING (file
)->data
);
597 /* Remove reference to bitmap with id number ID. */
600 x_destroy_bitmap (f
, id
)
604 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
608 --dpyinfo
->bitmaps
[id
- 1].refcount
;
609 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
612 DeleteObject (dpyinfo
->bitmaps
[id
- 1].pixmap
);
613 if (dpyinfo
->bitmaps
[id
- 1].file
)
615 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
616 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
623 /* Free all the bitmaps for the display specified by DPYINFO. */
626 x_destroy_all_bitmaps (dpyinfo
)
627 struct w32_display_info
*dpyinfo
;
630 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
631 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
633 DeleteObject (dpyinfo
->bitmaps
[i
].pixmap
);
634 if (dpyinfo
->bitmaps
[i
].file
)
635 xfree (dpyinfo
->bitmaps
[i
].file
);
637 dpyinfo
->bitmaps_last
= 0;
640 /* Connect the frame-parameter names for W32 frames
641 to the ways of passing the parameter values to the window system.
643 The name of a parameter, as a Lisp symbol,
644 has an `x-frame-parameter' property which is an integer in Lisp
645 but can be interpreted as an `enum x_frame_parm' in C. */
649 X_PARM_FOREGROUND_COLOR
,
650 X_PARM_BACKGROUND_COLOR
,
657 X_PARM_INTERNAL_BORDER_WIDTH
,
661 X_PARM_VERT_SCROLL_BAR
,
663 X_PARM_MENU_BAR_LINES
667 struct x_frame_parm_table
670 void (*setter
) P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
673 BOOL my_show_window
P_ ((struct frame
*, HWND
, int));
674 void my_set_window_pos
P_ ((HWND
, HWND
, int, int, int, int, UINT
));
675 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
676 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
677 static void x_change_window_heights
P_ ((Lisp_Object
, int));
678 /* TODO: Native Input Method support; see x_create_im. */
679 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
680 static void x_set_line_spacing
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
681 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
682 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
683 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
684 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
685 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
686 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
687 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
688 void x_set_font
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
689 static void x_set_fringe_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
690 void x_set_border_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
691 void x_set_internal_border_width
P_ ((struct frame
*, Lisp_Object
,
693 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
694 void x_set_autoraise
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
695 void x_set_autolower
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
696 void x_set_vertical_scroll_bars
P_ ((struct frame
*, Lisp_Object
,
698 void x_set_visibility
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
699 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
700 void x_set_scroll_bar_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
701 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
702 void x_set_unsplittable
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
703 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
704 static void x_set_screen_gamma
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
705 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
708 static struct x_frame_parm_table x_frame_parms
[] =
710 {"auto-raise", x_set_autoraise
},
711 {"auto-lower", x_set_autolower
},
712 {"background-color", x_set_background_color
},
713 {"border-color", x_set_border_color
},
714 {"border-width", x_set_border_width
},
715 {"cursor-color", x_set_cursor_color
},
716 {"cursor-type", x_set_cursor_type
},
717 {"font", x_set_font
},
718 {"foreground-color", x_set_foreground_color
},
719 {"icon-name", x_set_icon_name
},
720 {"icon-type", x_set_icon_type
},
721 {"internal-border-width", x_set_internal_border_width
},
722 {"menu-bar-lines", x_set_menu_bar_lines
},
723 {"mouse-color", x_set_mouse_color
},
724 {"name", x_explicitly_set_name
},
725 {"scroll-bar-width", x_set_scroll_bar_width
},
726 {"title", x_set_title
},
727 {"unsplittable", x_set_unsplittable
},
728 {"vertical-scroll-bars", x_set_vertical_scroll_bars
},
729 {"visibility", x_set_visibility
},
730 {"tool-bar-lines", x_set_tool_bar_lines
},
731 {"screen-gamma", x_set_screen_gamma
},
732 {"line-spacing", x_set_line_spacing
},
733 {"left-fringe", x_set_fringe_width
},
734 {"right-fringe", x_set_fringe_width
}
737 /* Attach the `x-frame-parameter' properties to
738 the Lisp symbol names of parameters relevant to W32. */
741 init_x_parm_symbols ()
745 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
746 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
750 /* Change the parameters of frame F as specified by ALIST.
751 If a parameter is not specially recognized, do nothing;
752 otherwise call the `x_set_...' function for that parameter. */
755 x_set_frame_parameters (f
, alist
)
761 /* If both of these parameters are present, it's more efficient to
762 set them both at once. So we wait until we've looked at the
763 entire list before we set them. */
767 Lisp_Object left
, top
;
769 /* Same with these. */
770 Lisp_Object icon_left
, icon_top
;
772 /* Record in these vectors all the parms specified. */
776 int left_no_change
= 0, top_no_change
= 0;
777 int icon_left_no_change
= 0, icon_top_no_change
= 0;
779 struct gcpro gcpro1
, gcpro2
;
782 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
785 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
786 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
788 /* Extract parm names and values into those vectors. */
791 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
796 parms
[i
] = Fcar (elt
);
797 values
[i
] = Fcdr (elt
);
800 /* TAIL and ALIST are not used again below here. */
803 GCPRO2 (*parms
, *values
);
807 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
808 because their values appear in VALUES and strings are not valid. */
809 top
= left
= Qunbound
;
810 icon_left
= icon_top
= Qunbound
;
812 /* Provide default values for HEIGHT and WIDTH. */
813 if (FRAME_NEW_WIDTH (f
))
814 width
= FRAME_NEW_WIDTH (f
);
816 width
= FRAME_WIDTH (f
);
818 if (FRAME_NEW_HEIGHT (f
))
819 height
= FRAME_NEW_HEIGHT (f
);
821 height
= FRAME_HEIGHT (f
);
823 /* Process foreground_color and background_color before anything else.
824 They are independent of other properties, but other properties (e.g.,
825 cursor_color) are dependent upon them. */
826 /* Process default font as well, since fringe widths depends on it. */
827 for (p
= 0; p
< i
; p
++)
829 Lisp_Object prop
, val
;
833 if (EQ (prop
, Qforeground_color
)
834 || EQ (prop
, Qbackground_color
)
837 register Lisp_Object param_index
, old_value
;
839 old_value
= get_frame_param (f
, prop
);
841 if (NILP (Fequal (val
, old_value
)))
843 store_frame_param (f
, prop
, val
);
845 param_index
= Fget (prop
, Qx_frame_parameter
);
846 if (NATNUMP (param_index
)
847 && (XFASTINT (param_index
)
848 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
849 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
854 /* Now process them in reverse of specified order. */
855 for (i
--; i
>= 0; i
--)
857 Lisp_Object prop
, val
;
862 if (EQ (prop
, Qwidth
) && NUMBERP (val
))
863 width
= XFASTINT (val
);
864 else if (EQ (prop
, Qheight
) && NUMBERP (val
))
865 height
= XFASTINT (val
);
866 else if (EQ (prop
, Qtop
))
868 else if (EQ (prop
, Qleft
))
870 else if (EQ (prop
, Qicon_top
))
872 else if (EQ (prop
, Qicon_left
))
874 else if (EQ (prop
, Qforeground_color
)
875 || EQ (prop
, Qbackground_color
)
877 /* Processed above. */
881 register Lisp_Object param_index
, old_value
;
883 old_value
= get_frame_param (f
, prop
);
885 store_frame_param (f
, prop
, val
);
887 param_index
= Fget (prop
, Qx_frame_parameter
);
888 if (NATNUMP (param_index
)
889 && (XFASTINT (param_index
)
890 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
891 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
895 /* Don't die if just one of these was set. */
896 if (EQ (left
, Qunbound
))
899 if (f
->output_data
.w32
->left_pos
< 0)
900 left
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->left_pos
), Qnil
));
902 XSETINT (left
, f
->output_data
.w32
->left_pos
);
904 if (EQ (top
, Qunbound
))
907 if (f
->output_data
.w32
->top_pos
< 0)
908 top
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->top_pos
), Qnil
));
910 XSETINT (top
, f
->output_data
.w32
->top_pos
);
913 /* If one of the icon positions was not set, preserve or default it. */
914 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
916 icon_left_no_change
= 1;
917 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
918 if (NILP (icon_left
))
919 XSETINT (icon_left
, 0);
921 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
923 icon_top_no_change
= 1;
924 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
926 XSETINT (icon_top
, 0);
929 /* Don't set these parameters unless they've been explicitly
930 specified. The window might be mapped or resized while we're in
931 this function, and we don't want to override that unless the lisp
932 code has asked for it.
934 Don't set these parameters unless they actually differ from the
935 window's current parameters; the window may not actually exist
940 check_frame_size (f
, &height
, &width
);
942 XSETFRAME (frame
, f
);
944 if (width
!= FRAME_WIDTH (f
)
945 || height
!= FRAME_HEIGHT (f
)
946 || FRAME_NEW_HEIGHT (f
) || FRAME_NEW_WIDTH (f
))
947 Fset_frame_size (frame
, make_number (width
), make_number (height
));
949 if ((!NILP (left
) || !NILP (top
))
950 && ! (left_no_change
&& top_no_change
)
951 && ! (NUMBERP (left
) && XINT (left
) == f
->output_data
.w32
->left_pos
952 && NUMBERP (top
) && XINT (top
) == f
->output_data
.w32
->top_pos
))
957 /* Record the signs. */
958 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
959 if (EQ (left
, Qminus
))
960 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
961 else if (INTEGERP (left
))
963 leftpos
= XINT (left
);
965 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
967 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
968 && CONSP (XCDR (left
))
969 && INTEGERP (XCAR (XCDR (left
))))
971 leftpos
= - XINT (XCAR (XCDR (left
)));
972 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
974 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
975 && CONSP (XCDR (left
))
976 && INTEGERP (XCAR (XCDR (left
))))
978 leftpos
= XINT (XCAR (XCDR (left
)));
981 if (EQ (top
, Qminus
))
982 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
983 else if (INTEGERP (top
))
987 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
989 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
990 && CONSP (XCDR (top
))
991 && INTEGERP (XCAR (XCDR (top
))))
993 toppos
= - XINT (XCAR (XCDR (top
)));
994 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
996 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
997 && CONSP (XCDR (top
))
998 && INTEGERP (XCAR (XCDR (top
))))
1000 toppos
= XINT (XCAR (XCDR (top
)));
1004 /* Store the numeric value of the position. */
1005 f
->output_data
.w32
->top_pos
= toppos
;
1006 f
->output_data
.w32
->left_pos
= leftpos
;
1008 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
1010 /* Actually set that position, and convert to absolute. */
1011 x_set_offset (f
, leftpos
, toppos
, -1);
1014 if ((!NILP (icon_left
) || !NILP (icon_top
))
1015 && ! (icon_left_no_change
&& icon_top_no_change
))
1016 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
1022 /* Store the screen positions of frame F into XPTR and YPTR.
1023 These are the positions of the containing window manager window,
1024 not Emacs's own window. */
1027 x_real_positions (f
, xptr
, yptr
)
1036 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
1037 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
1043 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
1049 /* Insert a description of internally-recorded parameters of frame X
1050 into the parameter alist *ALISTPTR that is to be given to the user.
1051 Only parameters that are specific to W32
1052 and whose values are not correctly recorded in the frame's
1053 param_alist need to be considered here. */
1056 x_report_frame_params (f
, alistptr
)
1058 Lisp_Object
*alistptr
;
1063 /* Represent negative positions (off the top or left screen edge)
1064 in a way that Fmodify_frame_parameters will understand correctly. */
1065 XSETINT (tem
, f
->output_data
.w32
->left_pos
);
1066 if (f
->output_data
.w32
->left_pos
>= 0)
1067 store_in_alist (alistptr
, Qleft
, tem
);
1069 store_in_alist (alistptr
, Qleft
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1071 XSETINT (tem
, f
->output_data
.w32
->top_pos
);
1072 if (f
->output_data
.w32
->top_pos
>= 0)
1073 store_in_alist (alistptr
, Qtop
, tem
);
1075 store_in_alist (alistptr
, Qtop
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1077 store_in_alist (alistptr
, Qborder_width
,
1078 make_number (f
->output_data
.w32
->border_width
));
1079 store_in_alist (alistptr
, Qinternal_border_width
,
1080 make_number (f
->output_data
.w32
->internal_border_width
));
1081 store_in_alist (alistptr
, Qleft_fringe
,
1082 make_number (f
->output_data
.w32
->left_fringe_width
));
1083 store_in_alist (alistptr
, Qright_fringe
,
1084 make_number (f
->output_data
.w32
->right_fringe_width
));
1085 store_in_alist (alistptr
, Qscroll_bar_width
,
1086 make_number (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
1087 ? FRAME_SCROLL_BAR_PIXEL_WIDTH(f
)
1089 sprintf (buf
, "%ld", (long) FRAME_W32_WINDOW (f
));
1090 store_in_alist (alistptr
, Qwindow_id
,
1091 build_string (buf
));
1092 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
1093 FRAME_SAMPLE_VISIBILITY (f
);
1094 store_in_alist (alistptr
, Qvisibility
,
1095 (FRAME_VISIBLE_P (f
) ? Qt
1096 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
1097 store_in_alist (alistptr
, Qdisplay
,
1098 XCAR (FRAME_W32_DISPLAY_INFO (f
)->name_list_element
));
1102 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
1103 Sw32_define_rgb_color
, 4, 4, 0,
1104 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
1105 This adds or updates a named color to w32-color-map, making it
1106 available for use. The original entry's RGB ref is returned, or nil
1107 if the entry is new. */)
1108 (red
, green
, blue
, name
)
1109 Lisp_Object red
, green
, blue
, name
;
1112 Lisp_Object oldrgb
= Qnil
;
1116 CHECK_NUMBER (green
);
1117 CHECK_NUMBER (blue
);
1118 CHECK_STRING (name
);
1120 XSET (rgb
, Lisp_Int
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
1124 /* replace existing entry in w32-color-map or add new entry. */
1125 entry
= Fassoc (name
, Vw32_color_map
);
1128 entry
= Fcons (name
, rgb
);
1129 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
1133 oldrgb
= Fcdr (entry
);
1134 Fsetcdr (entry
, rgb
);
1142 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
1143 Sw32_load_color_file
, 1, 1, 0,
1144 doc
: /* Create an alist of color entries from an external file.
1145 Assign this value to w32-color-map to replace the existing color map.
1147 The file should define one named RGB color per line like so:
1149 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
1151 Lisp_Object filename
;
1154 Lisp_Object cmap
= Qnil
;
1155 Lisp_Object abspath
;
1157 CHECK_STRING (filename
);
1158 abspath
= Fexpand_file_name (filename
, Qnil
);
1160 fp
= fopen (XSTRING (filename
)->data
, "rt");
1164 int red
, green
, blue
;
1169 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
1170 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
1172 char *name
= buf
+ num
;
1173 num
= strlen (name
) - 1;
1174 if (name
[num
] == '\n')
1176 cmap
= Fcons (Fcons (build_string (name
),
1177 make_number (RGB (red
, green
, blue
))),
1189 /* The default colors for the w32 color map */
1190 typedef struct colormap_t
1196 colormap_t w32_color_map
[] =
1198 {"snow" , PALETTERGB (255,250,250)},
1199 {"ghost white" , PALETTERGB (248,248,255)},
1200 {"GhostWhite" , PALETTERGB (248,248,255)},
1201 {"white smoke" , PALETTERGB (245,245,245)},
1202 {"WhiteSmoke" , PALETTERGB (245,245,245)},
1203 {"gainsboro" , PALETTERGB (220,220,220)},
1204 {"floral white" , PALETTERGB (255,250,240)},
1205 {"FloralWhite" , PALETTERGB (255,250,240)},
1206 {"old lace" , PALETTERGB (253,245,230)},
1207 {"OldLace" , PALETTERGB (253,245,230)},
1208 {"linen" , PALETTERGB (250,240,230)},
1209 {"antique white" , PALETTERGB (250,235,215)},
1210 {"AntiqueWhite" , PALETTERGB (250,235,215)},
1211 {"papaya whip" , PALETTERGB (255,239,213)},
1212 {"PapayaWhip" , PALETTERGB (255,239,213)},
1213 {"blanched almond" , PALETTERGB (255,235,205)},
1214 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
1215 {"bisque" , PALETTERGB (255,228,196)},
1216 {"peach puff" , PALETTERGB (255,218,185)},
1217 {"PeachPuff" , PALETTERGB (255,218,185)},
1218 {"navajo white" , PALETTERGB (255,222,173)},
1219 {"NavajoWhite" , PALETTERGB (255,222,173)},
1220 {"moccasin" , PALETTERGB (255,228,181)},
1221 {"cornsilk" , PALETTERGB (255,248,220)},
1222 {"ivory" , PALETTERGB (255,255,240)},
1223 {"lemon chiffon" , PALETTERGB (255,250,205)},
1224 {"LemonChiffon" , PALETTERGB (255,250,205)},
1225 {"seashell" , PALETTERGB (255,245,238)},
1226 {"honeydew" , PALETTERGB (240,255,240)},
1227 {"mint cream" , PALETTERGB (245,255,250)},
1228 {"MintCream" , PALETTERGB (245,255,250)},
1229 {"azure" , PALETTERGB (240,255,255)},
1230 {"alice blue" , PALETTERGB (240,248,255)},
1231 {"AliceBlue" , PALETTERGB (240,248,255)},
1232 {"lavender" , PALETTERGB (230,230,250)},
1233 {"lavender blush" , PALETTERGB (255,240,245)},
1234 {"LavenderBlush" , PALETTERGB (255,240,245)},
1235 {"misty rose" , PALETTERGB (255,228,225)},
1236 {"MistyRose" , PALETTERGB (255,228,225)},
1237 {"white" , PALETTERGB (255,255,255)},
1238 {"black" , PALETTERGB ( 0, 0, 0)},
1239 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
1240 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
1241 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
1242 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
1243 {"dim gray" , PALETTERGB (105,105,105)},
1244 {"DimGray" , PALETTERGB (105,105,105)},
1245 {"dim grey" , PALETTERGB (105,105,105)},
1246 {"DimGrey" , PALETTERGB (105,105,105)},
1247 {"slate gray" , PALETTERGB (112,128,144)},
1248 {"SlateGray" , PALETTERGB (112,128,144)},
1249 {"slate grey" , PALETTERGB (112,128,144)},
1250 {"SlateGrey" , PALETTERGB (112,128,144)},
1251 {"light slate gray" , PALETTERGB (119,136,153)},
1252 {"LightSlateGray" , PALETTERGB (119,136,153)},
1253 {"light slate grey" , PALETTERGB (119,136,153)},
1254 {"LightSlateGrey" , PALETTERGB (119,136,153)},
1255 {"gray" , PALETTERGB (190,190,190)},
1256 {"grey" , PALETTERGB (190,190,190)},
1257 {"light grey" , PALETTERGB (211,211,211)},
1258 {"LightGrey" , PALETTERGB (211,211,211)},
1259 {"light gray" , PALETTERGB (211,211,211)},
1260 {"LightGray" , PALETTERGB (211,211,211)},
1261 {"midnight blue" , PALETTERGB ( 25, 25,112)},
1262 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
1263 {"navy" , PALETTERGB ( 0, 0,128)},
1264 {"navy blue" , PALETTERGB ( 0, 0,128)},
1265 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
1266 {"cornflower blue" , PALETTERGB (100,149,237)},
1267 {"CornflowerBlue" , PALETTERGB (100,149,237)},
1268 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
1269 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
1270 {"slate blue" , PALETTERGB (106, 90,205)},
1271 {"SlateBlue" , PALETTERGB (106, 90,205)},
1272 {"medium slate blue" , PALETTERGB (123,104,238)},
1273 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
1274 {"light slate blue" , PALETTERGB (132,112,255)},
1275 {"LightSlateBlue" , PALETTERGB (132,112,255)},
1276 {"medium blue" , PALETTERGB ( 0, 0,205)},
1277 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
1278 {"royal blue" , PALETTERGB ( 65,105,225)},
1279 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
1280 {"blue" , PALETTERGB ( 0, 0,255)},
1281 {"dodger blue" , PALETTERGB ( 30,144,255)},
1282 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
1283 {"deep sky blue" , PALETTERGB ( 0,191,255)},
1284 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
1285 {"sky blue" , PALETTERGB (135,206,235)},
1286 {"SkyBlue" , PALETTERGB (135,206,235)},
1287 {"light sky blue" , PALETTERGB (135,206,250)},
1288 {"LightSkyBlue" , PALETTERGB (135,206,250)},
1289 {"steel blue" , PALETTERGB ( 70,130,180)},
1290 {"SteelBlue" , PALETTERGB ( 70,130,180)},
1291 {"light steel blue" , PALETTERGB (176,196,222)},
1292 {"LightSteelBlue" , PALETTERGB (176,196,222)},
1293 {"light blue" , PALETTERGB (173,216,230)},
1294 {"LightBlue" , PALETTERGB (173,216,230)},
1295 {"powder blue" , PALETTERGB (176,224,230)},
1296 {"PowderBlue" , PALETTERGB (176,224,230)},
1297 {"pale turquoise" , PALETTERGB (175,238,238)},
1298 {"PaleTurquoise" , PALETTERGB (175,238,238)},
1299 {"dark turquoise" , PALETTERGB ( 0,206,209)},
1300 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
1301 {"medium turquoise" , PALETTERGB ( 72,209,204)},
1302 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
1303 {"turquoise" , PALETTERGB ( 64,224,208)},
1304 {"cyan" , PALETTERGB ( 0,255,255)},
1305 {"light cyan" , PALETTERGB (224,255,255)},
1306 {"LightCyan" , PALETTERGB (224,255,255)},
1307 {"cadet blue" , PALETTERGB ( 95,158,160)},
1308 {"CadetBlue" , PALETTERGB ( 95,158,160)},
1309 {"medium aquamarine" , PALETTERGB (102,205,170)},
1310 {"MediumAquamarine" , PALETTERGB (102,205,170)},
1311 {"aquamarine" , PALETTERGB (127,255,212)},
1312 {"dark green" , PALETTERGB ( 0,100, 0)},
1313 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
1314 {"dark olive green" , PALETTERGB ( 85,107, 47)},
1315 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
1316 {"dark sea green" , PALETTERGB (143,188,143)},
1317 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
1318 {"sea green" , PALETTERGB ( 46,139, 87)},
1319 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
1320 {"medium sea green" , PALETTERGB ( 60,179,113)},
1321 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
1322 {"light sea green" , PALETTERGB ( 32,178,170)},
1323 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
1324 {"pale green" , PALETTERGB (152,251,152)},
1325 {"PaleGreen" , PALETTERGB (152,251,152)},
1326 {"spring green" , PALETTERGB ( 0,255,127)},
1327 {"SpringGreen" , PALETTERGB ( 0,255,127)},
1328 {"lawn green" , PALETTERGB (124,252, 0)},
1329 {"LawnGreen" , PALETTERGB (124,252, 0)},
1330 {"green" , PALETTERGB ( 0,255, 0)},
1331 {"chartreuse" , PALETTERGB (127,255, 0)},
1332 {"medium spring green" , PALETTERGB ( 0,250,154)},
1333 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
1334 {"green yellow" , PALETTERGB (173,255, 47)},
1335 {"GreenYellow" , PALETTERGB (173,255, 47)},
1336 {"lime green" , PALETTERGB ( 50,205, 50)},
1337 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
1338 {"yellow green" , PALETTERGB (154,205, 50)},
1339 {"YellowGreen" , PALETTERGB (154,205, 50)},
1340 {"forest green" , PALETTERGB ( 34,139, 34)},
1341 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
1342 {"olive drab" , PALETTERGB (107,142, 35)},
1343 {"OliveDrab" , PALETTERGB (107,142, 35)},
1344 {"dark khaki" , PALETTERGB (189,183,107)},
1345 {"DarkKhaki" , PALETTERGB (189,183,107)},
1346 {"khaki" , PALETTERGB (240,230,140)},
1347 {"pale goldenrod" , PALETTERGB (238,232,170)},
1348 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
1349 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
1350 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
1351 {"light yellow" , PALETTERGB (255,255,224)},
1352 {"LightYellow" , PALETTERGB (255,255,224)},
1353 {"yellow" , PALETTERGB (255,255, 0)},
1354 {"gold" , PALETTERGB (255,215, 0)},
1355 {"light goldenrod" , PALETTERGB (238,221,130)},
1356 {"LightGoldenrod" , PALETTERGB (238,221,130)},
1357 {"goldenrod" , PALETTERGB (218,165, 32)},
1358 {"dark goldenrod" , PALETTERGB (184,134, 11)},
1359 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
1360 {"rosy brown" , PALETTERGB (188,143,143)},
1361 {"RosyBrown" , PALETTERGB (188,143,143)},
1362 {"indian red" , PALETTERGB (205, 92, 92)},
1363 {"IndianRed" , PALETTERGB (205, 92, 92)},
1364 {"saddle brown" , PALETTERGB (139, 69, 19)},
1365 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
1366 {"sienna" , PALETTERGB (160, 82, 45)},
1367 {"peru" , PALETTERGB (205,133, 63)},
1368 {"burlywood" , PALETTERGB (222,184,135)},
1369 {"beige" , PALETTERGB (245,245,220)},
1370 {"wheat" , PALETTERGB (245,222,179)},
1371 {"sandy brown" , PALETTERGB (244,164, 96)},
1372 {"SandyBrown" , PALETTERGB (244,164, 96)},
1373 {"tan" , PALETTERGB (210,180,140)},
1374 {"chocolate" , PALETTERGB (210,105, 30)},
1375 {"firebrick" , PALETTERGB (178,34, 34)},
1376 {"brown" , PALETTERGB (165,42, 42)},
1377 {"dark salmon" , PALETTERGB (233,150,122)},
1378 {"DarkSalmon" , PALETTERGB (233,150,122)},
1379 {"salmon" , PALETTERGB (250,128,114)},
1380 {"light salmon" , PALETTERGB (255,160,122)},
1381 {"LightSalmon" , PALETTERGB (255,160,122)},
1382 {"orange" , PALETTERGB (255,165, 0)},
1383 {"dark orange" , PALETTERGB (255,140, 0)},
1384 {"DarkOrange" , PALETTERGB (255,140, 0)},
1385 {"coral" , PALETTERGB (255,127, 80)},
1386 {"light coral" , PALETTERGB (240,128,128)},
1387 {"LightCoral" , PALETTERGB (240,128,128)},
1388 {"tomato" , PALETTERGB (255, 99, 71)},
1389 {"orange red" , PALETTERGB (255, 69, 0)},
1390 {"OrangeRed" , PALETTERGB (255, 69, 0)},
1391 {"red" , PALETTERGB (255, 0, 0)},
1392 {"hot pink" , PALETTERGB (255,105,180)},
1393 {"HotPink" , PALETTERGB (255,105,180)},
1394 {"deep pink" , PALETTERGB (255, 20,147)},
1395 {"DeepPink" , PALETTERGB (255, 20,147)},
1396 {"pink" , PALETTERGB (255,192,203)},
1397 {"light pink" , PALETTERGB (255,182,193)},
1398 {"LightPink" , PALETTERGB (255,182,193)},
1399 {"pale violet red" , PALETTERGB (219,112,147)},
1400 {"PaleVioletRed" , PALETTERGB (219,112,147)},
1401 {"maroon" , PALETTERGB (176, 48, 96)},
1402 {"medium violet red" , PALETTERGB (199, 21,133)},
1403 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
1404 {"violet red" , PALETTERGB (208, 32,144)},
1405 {"VioletRed" , PALETTERGB (208, 32,144)},
1406 {"magenta" , PALETTERGB (255, 0,255)},
1407 {"violet" , PALETTERGB (238,130,238)},
1408 {"plum" , PALETTERGB (221,160,221)},
1409 {"orchid" , PALETTERGB (218,112,214)},
1410 {"medium orchid" , PALETTERGB (186, 85,211)},
1411 {"MediumOrchid" , PALETTERGB (186, 85,211)},
1412 {"dark orchid" , PALETTERGB (153, 50,204)},
1413 {"DarkOrchid" , PALETTERGB (153, 50,204)},
1414 {"dark violet" , PALETTERGB (148, 0,211)},
1415 {"DarkViolet" , PALETTERGB (148, 0,211)},
1416 {"blue violet" , PALETTERGB (138, 43,226)},
1417 {"BlueViolet" , PALETTERGB (138, 43,226)},
1418 {"purple" , PALETTERGB (160, 32,240)},
1419 {"medium purple" , PALETTERGB (147,112,219)},
1420 {"MediumPurple" , PALETTERGB (147,112,219)},
1421 {"thistle" , PALETTERGB (216,191,216)},
1422 {"gray0" , PALETTERGB ( 0, 0, 0)},
1423 {"grey0" , PALETTERGB ( 0, 0, 0)},
1424 {"dark grey" , PALETTERGB (169,169,169)},
1425 {"DarkGrey" , PALETTERGB (169,169,169)},
1426 {"dark gray" , PALETTERGB (169,169,169)},
1427 {"DarkGray" , PALETTERGB (169,169,169)},
1428 {"dark blue" , PALETTERGB ( 0, 0,139)},
1429 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
1430 {"dark cyan" , PALETTERGB ( 0,139,139)},
1431 {"DarkCyan" , PALETTERGB ( 0,139,139)},
1432 {"dark magenta" , PALETTERGB (139, 0,139)},
1433 {"DarkMagenta" , PALETTERGB (139, 0,139)},
1434 {"dark red" , PALETTERGB (139, 0, 0)},
1435 {"DarkRed" , PALETTERGB (139, 0, 0)},
1436 {"light green" , PALETTERGB (144,238,144)},
1437 {"LightGreen" , PALETTERGB (144,238,144)},
1440 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
1441 0, 0, 0, doc
: /* Return the default color map. */)
1445 colormap_t
*pc
= w32_color_map
;
1452 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
1454 cmap
= Fcons (Fcons (build_string (pc
->name
),
1455 make_number (pc
->colorref
)),
1464 w32_to_x_color (rgb
)
1473 color
= Frassq (rgb
, Vw32_color_map
);
1478 return (Fcar (color
));
1484 w32_color_map_lookup (colorname
)
1487 Lisp_Object tail
, ret
= Qnil
;
1491 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
1493 register Lisp_Object elt
, tem
;
1496 if (!CONSP (elt
)) continue;
1500 if (lstrcmpi (XSTRING (tem
)->data
, colorname
) == 0)
1502 ret
= XUINT (Fcdr (elt
));
1516 x_to_w32_color (colorname
)
1519 register Lisp_Object ret
= Qnil
;
1523 if (colorname
[0] == '#')
1525 /* Could be an old-style RGB Device specification. */
1528 color
= colorname
+ 1;
1530 size
= strlen(color
);
1531 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
1539 for (i
= 0; i
< 3; i
++)
1543 unsigned long value
;
1545 /* The check for 'x' in the following conditional takes into
1546 account the fact that strtol allows a "0x" in front of
1547 our numbers, and we don't. */
1548 if (!isxdigit(color
[0]) || color
[1] == 'x')
1552 value
= strtoul(color
, &end
, 16);
1554 if (errno
== ERANGE
|| end
- color
!= size
)
1559 value
= value
* 0x10;
1570 colorval
|= (value
<< pos
);
1581 else if (strnicmp(colorname
, "rgb:", 4) == 0)
1589 color
= colorname
+ 4;
1590 for (i
= 0; i
< 3; i
++)
1593 unsigned long value
;
1595 /* The check for 'x' in the following conditional takes into
1596 account the fact that strtol allows a "0x" in front of
1597 our numbers, and we don't. */
1598 if (!isxdigit(color
[0]) || color
[1] == 'x')
1600 value
= strtoul(color
, &end
, 16);
1601 if (errno
== ERANGE
)
1603 switch (end
- color
)
1606 value
= value
* 0x10 + value
;
1619 if (value
== ULONG_MAX
)
1621 colorval
|= (value
<< pos
);
1635 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1637 /* This is an RGB Intensity specification. */
1644 color
= colorname
+ 5;
1645 for (i
= 0; i
< 3; i
++)
1651 value
= strtod(color
, &end
);
1652 if (errno
== ERANGE
)
1654 if (value
< 0.0 || value
> 1.0)
1656 val
= (UINT
)(0x100 * value
);
1657 /* We used 0x100 instead of 0xFF to give an continuous
1658 range between 0.0 and 1.0 inclusive. The next statement
1659 fixes the 1.0 case. */
1662 colorval
|= (val
<< pos
);
1676 /* I am not going to attempt to handle any of the CIE color schemes
1677 or TekHVC, since I don't know the algorithms for conversion to
1680 /* If we fail to lookup the color name in w32_color_map, then check the
1681 colorname to see if it can be crudely approximated: If the X color
1682 ends in a number (e.g., "darkseagreen2"), strip the number and
1683 return the result of looking up the base color name. */
1684 ret
= w32_color_map_lookup (colorname
);
1687 int len
= strlen (colorname
);
1689 if (isdigit (colorname
[len
- 1]))
1691 char *ptr
, *approx
= alloca (len
+ 1);
1693 strcpy (approx
, colorname
);
1694 ptr
= &approx
[len
- 1];
1695 while (ptr
> approx
&& isdigit (*ptr
))
1698 ret
= w32_color_map_lookup (approx
);
1708 w32_regenerate_palette (FRAME_PTR f
)
1710 struct w32_palette_entry
* list
;
1711 LOGPALETTE
* log_palette
;
1712 HPALETTE new_palette
;
1715 /* don't bother trying to create palette if not supported */
1716 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1719 log_palette
= (LOGPALETTE
*)
1720 alloca (sizeof (LOGPALETTE
) +
1721 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1722 log_palette
->palVersion
= 0x300;
1723 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1725 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1727 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1728 i
++, list
= list
->next
)
1729 log_palette
->palPalEntry
[i
] = list
->entry
;
1731 new_palette
= CreatePalette (log_palette
);
1735 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1736 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1737 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1739 /* Realize display palette and garbage all frames. */
1740 release_frame_dc (f
, get_frame_dc (f
));
1745 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1746 #define SET_W32_COLOR(pe, color) \
1749 pe.peRed = GetRValue (color); \
1750 pe.peGreen = GetGValue (color); \
1751 pe.peBlue = GetBValue (color); \
1756 /* Keep these around in case we ever want to track color usage. */
1758 w32_map_color (FRAME_PTR f
, COLORREF color
)
1760 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1762 if (NILP (Vw32_enable_palette
))
1765 /* check if color is already mapped */
1768 if (W32_COLOR (list
->entry
) == color
)
1776 /* not already mapped, so add to list and recreate Windows palette */
1777 list
= (struct w32_palette_entry
*)
1778 xmalloc (sizeof (struct w32_palette_entry
));
1779 SET_W32_COLOR (list
->entry
, color
);
1781 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1782 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1783 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1785 /* set flag that palette must be regenerated */
1786 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1790 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1792 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1793 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1795 if (NILP (Vw32_enable_palette
))
1798 /* check if color is already mapped */
1801 if (W32_COLOR (list
->entry
) == color
)
1803 if (--list
->refcount
== 0)
1807 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1817 /* set flag that palette must be regenerated */
1818 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1823 /* Gamma-correct COLOR on frame F. */
1826 gamma_correct (f
, color
)
1832 *color
= PALETTERGB (
1833 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1834 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1835 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1840 /* Decide if color named COLOR is valid for the display associated with
1841 the selected frame; if so, return the rgb values in COLOR_DEF.
1842 If ALLOC is nonzero, allocate a new colormap cell. */
1845 w32_defined_color (f
, color
, color_def
, alloc
)
1851 register Lisp_Object tem
;
1852 COLORREF w32_color_ref
;
1854 tem
= x_to_w32_color (color
);
1860 /* Apply gamma correction. */
1861 w32_color_ref
= XUINT (tem
);
1862 gamma_correct (f
, &w32_color_ref
);
1863 XSETINT (tem
, w32_color_ref
);
1866 /* Map this color to the palette if it is enabled. */
1867 if (!NILP (Vw32_enable_palette
))
1869 struct w32_palette_entry
* entry
=
1870 one_w32_display_info
.color_list
;
1871 struct w32_palette_entry
** prev
=
1872 &one_w32_display_info
.color_list
;
1874 /* check if color is already mapped */
1877 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1879 prev
= &entry
->next
;
1880 entry
= entry
->next
;
1883 if (entry
== NULL
&& alloc
)
1885 /* not already mapped, so add to list */
1886 entry
= (struct w32_palette_entry
*)
1887 xmalloc (sizeof (struct w32_palette_entry
));
1888 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1891 one_w32_display_info
.num_colors
++;
1893 /* set flag that palette must be regenerated */
1894 one_w32_display_info
.regen_palette
= TRUE
;
1897 /* Ensure COLORREF value is snapped to nearest color in (default)
1898 palette by simulating the PALETTERGB macro. This works whether
1899 or not the display device has a palette. */
1900 w32_color_ref
= XUINT (tem
) | 0x2000000;
1902 color_def
->pixel
= w32_color_ref
;
1903 color_def
->red
= GetRValue (w32_color_ref
);
1904 color_def
->green
= GetGValue (w32_color_ref
);
1905 color_def
->blue
= GetBValue (w32_color_ref
);
1915 /* Given a string ARG naming a color, compute a pixel value from it
1916 suitable for screen F.
1917 If F is not a color screen, return DEF (default) regardless of what
1921 x_decode_color (f
, arg
, def
)
1930 if (strcmp (XSTRING (arg
)->data
, "black") == 0)
1931 return BLACK_PIX_DEFAULT (f
);
1932 else if (strcmp (XSTRING (arg
)->data
, "white") == 0)
1933 return WHITE_PIX_DEFAULT (f
);
1935 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1938 /* w32_defined_color is responsible for coping with failures
1939 by looking for a near-miss. */
1940 if (w32_defined_color (f
, XSTRING (arg
)->data
, &cdef
, 1))
1943 /* defined_color failed; return an ultimate default. */
1947 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
1948 the previous value of that parameter, NEW_VALUE is the new value. */
1951 x_set_line_spacing (f
, new_value
, old_value
)
1953 Lisp_Object new_value
, old_value
;
1955 if (NILP (new_value
))
1956 f
->extra_line_spacing
= 0;
1957 else if (NATNUMP (new_value
))
1958 f
->extra_line_spacing
= XFASTINT (new_value
);
1960 Fsignal (Qerror
, Fcons (build_string ("Invalid line-spacing"),
1961 Fcons (new_value
, Qnil
)));
1962 if (FRAME_VISIBLE_P (f
))
1967 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
1968 the previous value of that parameter, NEW_VALUE is the new value. */
1971 x_set_screen_gamma (f
, new_value
, old_value
)
1973 Lisp_Object new_value
, old_value
;
1975 if (NILP (new_value
))
1977 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
1978 /* The value 0.4545 is the normal viewing gamma. */
1979 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
1981 Fsignal (Qerror
, Fcons (build_string ("Invalid screen-gamma"),
1982 Fcons (new_value
, Qnil
)));
1984 clear_face_cache (0);
1988 /* Functions called only from `x_set_frame_param'
1989 to set individual parameters.
1991 If FRAME_W32_WINDOW (f) is 0,
1992 the frame is being created and its window does not exist yet.
1993 In that case, just record the parameter's new value
1994 in the standard place; do not attempt to change the window. */
1997 x_set_foreground_color (f
, arg
, oldval
)
1999 Lisp_Object arg
, oldval
;
2001 struct w32_output
*x
= f
->output_data
.w32
;
2002 PIX_TYPE fg
, old_fg
;
2004 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2005 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
2006 FRAME_FOREGROUND_PIXEL (f
) = fg
;
2008 if (FRAME_W32_WINDOW (f
) != 0)
2010 if (x
->cursor_pixel
== old_fg
)
2011 x
->cursor_pixel
= fg
;
2013 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
2014 if (FRAME_VISIBLE_P (f
))
2020 x_set_background_color (f
, arg
, oldval
)
2022 Lisp_Object arg
, oldval
;
2024 FRAME_BACKGROUND_PIXEL (f
)
2025 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
2027 if (FRAME_W32_WINDOW (f
) != 0)
2029 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
2030 FRAME_BACKGROUND_PIXEL (f
));
2032 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
2034 if (FRAME_VISIBLE_P (f
))
2040 x_set_mouse_color (f
, arg
, oldval
)
2042 Lisp_Object arg
, oldval
;
2044 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
2048 if (!EQ (Qnil
, arg
))
2049 f
->output_data
.w32
->mouse_pixel
2050 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2051 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
2053 /* Don't let pointers be invisible. */
2054 if (mask_color
== f
->output_data
.w32
->mouse_pixel
2055 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
2056 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
2058 #if 0 /* TODO : cursor changes */
2061 /* It's not okay to crash if the user selects a screwy cursor. */
2062 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
2064 if (!EQ (Qnil
, Vx_pointer_shape
))
2066 CHECK_NUMBER (Vx_pointer_shape
);
2067 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
2070 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2071 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
2073 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
2075 CHECK_NUMBER (Vx_nontext_pointer_shape
);
2076 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2077 XINT (Vx_nontext_pointer_shape
));
2080 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
2081 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2083 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
2085 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
2086 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2087 XINT (Vx_hourglass_pointer_shape
));
2090 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
2091 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
2093 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2094 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
2096 CHECK_NUMBER (Vx_mode_pointer_shape
);
2097 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2098 XINT (Vx_mode_pointer_shape
));
2101 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2102 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
2104 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
2106 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
2108 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2109 XINT (Vx_sensitive_text_pointer_shape
));
2112 cross_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
2114 if (!NILP (Vx_window_horizontal_drag_shape
))
2116 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
2117 horizontal_drag_cursor
2118 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
2119 XINT (Vx_window_horizontal_drag_shape
));
2122 horizontal_drag_cursor
2123 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
2125 /* Check and report errors with the above calls. */
2126 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
2127 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
2130 XColor fore_color
, back_color
;
2132 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
2133 back_color
.pixel
= mask_color
;
2134 XQueryColor (FRAME_W32_DISPLAY (f
),
2135 DefaultColormap (FRAME_W32_DISPLAY (f
),
2136 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2138 XQueryColor (FRAME_W32_DISPLAY (f
),
2139 DefaultColormap (FRAME_W32_DISPLAY (f
),
2140 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2142 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
2143 &fore_color
, &back_color
);
2144 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
2145 &fore_color
, &back_color
);
2146 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
2147 &fore_color
, &back_color
);
2148 XRecolorCursor (FRAME_W32_DISPLAY (f
), cross_cursor
,
2149 &fore_color
, &back_color
);
2150 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
2151 &fore_color
, &back_color
);
2154 if (FRAME_W32_WINDOW (f
) != 0)
2155 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
2157 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
2158 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
2159 f
->output_data
.w32
->text_cursor
= cursor
;
2161 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
2162 && f
->output_data
.w32
->nontext_cursor
!= 0)
2163 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
2164 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
2166 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
2167 && f
->output_data
.w32
->hourglass_cursor
!= 0)
2168 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
2169 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
2171 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
2172 && f
->output_data
.w32
->modeline_cursor
!= 0)
2173 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
2174 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
2176 if (cross_cursor
!= f
->output_data
.w32
->cross_cursor
2177 && f
->output_data
.w32
->cross_cursor
!= 0)
2178 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->cross_cursor
);
2179 f
->output_data
.w32
->cross_cursor
= cross_cursor
;
2181 XFlush (FRAME_W32_DISPLAY (f
));
2184 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
2188 /* Defined in w32term.c. */
2189 void x_update_cursor (struct frame
*f
, int on_p
);
2192 x_set_cursor_color (f
, arg
, oldval
)
2194 Lisp_Object arg
, oldval
;
2196 unsigned long fore_pixel
, pixel
;
2198 if (!NILP (Vx_cursor_fore_pixel
))
2199 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
2200 WHITE_PIX_DEFAULT (f
));
2202 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2204 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2206 /* Make sure that the cursor color differs from the background color. */
2207 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
2209 pixel
= f
->output_data
.w32
->mouse_pixel
;
2210 if (pixel
== fore_pixel
)
2211 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2214 FRAME_FOREGROUND_PIXEL (f
) = fore_pixel
;
2215 f
->output_data
.w32
->cursor_pixel
= pixel
;
2217 if (FRAME_W32_WINDOW (f
) != 0)
2219 if (FRAME_VISIBLE_P (f
))
2221 x_update_cursor (f
, 0);
2222 x_update_cursor (f
, 1);
2226 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
2229 /* Set the border-color of frame F to pixel value PIX.
2230 Note that this does not fully take effect if done before
2233 x_set_border_pixel (f
, pix
)
2237 f
->output_data
.w32
->border_pixel
= pix
;
2239 if (FRAME_W32_WINDOW (f
) != 0 && f
->output_data
.w32
->border_width
> 0)
2241 if (FRAME_VISIBLE_P (f
))
2246 /* Set the border-color of frame F to value described by ARG.
2247 ARG can be a string naming a color.
2248 The border-color is used for the border that is drawn by the server.
2249 Note that this does not fully take effect if done before
2250 F has a window; it must be redone when the window is created. */
2253 x_set_border_color (f
, arg
, oldval
)
2255 Lisp_Object arg
, oldval
;
2260 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2261 x_set_border_pixel (f
, pix
);
2262 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
2265 /* Value is the internal representation of the specified cursor type
2266 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
2267 of the bar cursor. */
2269 enum text_cursor_kinds
2270 x_specified_cursor_type (arg
, width
)
2274 enum text_cursor_kinds type
;
2281 else if (CONSP (arg
)
2282 && EQ (XCAR (arg
), Qbar
)
2283 && INTEGERP (XCDR (arg
))
2284 && XINT (XCDR (arg
)) >= 0)
2287 *width
= XINT (XCDR (arg
));
2289 else if (NILP (arg
))
2292 /* Treat anything unknown as "box cursor".
2293 It was bad to signal an error; people have trouble fixing
2294 .Xdefaults with Emacs, when it has something bad in it. */
2295 type
= FILLED_BOX_CURSOR
;
2301 x_set_cursor_type (f
, arg
, oldval
)
2303 Lisp_Object arg
, oldval
;
2307 FRAME_DESIRED_CURSOR (f
) = x_specified_cursor_type (arg
, &width
);
2308 f
->output_data
.w32
->cursor_width
= width
;
2310 /* Make sure the cursor gets redrawn. This is overkill, but how
2311 often do people change cursor types? */
2312 update_mode_lines
++;
2316 x_set_icon_type (f
, arg
, oldval
)
2318 Lisp_Object arg
, oldval
;
2322 if (NILP (arg
) && NILP (oldval
))
2325 if (STRINGP (arg
) && STRINGP (oldval
)
2326 && EQ (Fstring_equal (oldval
, arg
), Qt
))
2329 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
2334 result
= x_bitmap_icon (f
, arg
);
2338 error ("No icon window available");
2344 /* Return non-nil if frame F wants a bitmap icon. */
2352 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
2360 x_set_icon_name (f
, arg
, oldval
)
2362 Lisp_Object arg
, oldval
;
2366 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
2369 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
2375 if (f
->output_data
.w32
->icon_bitmap
!= 0)
2380 result
= x_text_icon (f
,
2381 (char *) XSTRING ((!NILP (f
->icon_name
)
2390 error ("No icon window available");
2393 /* If the window was unmapped (and its icon was mapped),
2394 the new icon is not mapped, so map the window in its stead. */
2395 if (FRAME_VISIBLE_P (f
))
2397 #ifdef USE_X_TOOLKIT
2398 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
2400 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
2403 XFlush (FRAME_W32_DISPLAY (f
));
2408 extern Lisp_Object
x_new_font ();
2409 extern Lisp_Object
x_new_fontset();
2412 x_set_font (f
, arg
, oldval
)
2414 Lisp_Object arg
, oldval
;
2417 Lisp_Object fontset_name
;
2419 int old_fontset
= FRAME_FONTSET(f
);
2423 fontset_name
= Fquery_fontset (arg
, Qnil
);
2426 result
= (STRINGP (fontset_name
)
2427 ? x_new_fontset (f
, XSTRING (fontset_name
)->data
)
2428 : x_new_font (f
, XSTRING (arg
)->data
));
2431 if (EQ (result
, Qnil
))
2432 error ("Font `%s' is not defined", XSTRING (arg
)->data
);
2433 else if (EQ (result
, Qt
))
2434 error ("The characters of the given font have varying widths");
2435 else if (STRINGP (result
))
2437 if (STRINGP (fontset_name
))
2439 /* Fontset names are built from ASCII font names, so the
2440 names may be equal despite there was a change. */
2441 if (old_fontset
== FRAME_FONTSET (f
))
2444 else if (!NILP (Fequal (result
, oldval
)))
2447 store_frame_param (f
, Qfont
, result
);
2448 recompute_basic_faces (f
);
2453 do_pending_window_change (0);
2455 /* Don't call `face-set-after-frame-default' when faces haven't been
2456 initialized yet. This is the case when called from
2457 Fx_create_frame. In that case, the X widget or window doesn't
2458 exist either, and we can end up in x_report_frame_params with a
2459 null widget which gives a segfault. */
2460 if (FRAME_FACE_CACHE (f
))
2462 XSETFRAME (frame
, f
);
2463 call1 (Qface_set_after_frame_default
, frame
);
2468 x_set_fringe_width (f
, new_value
, old_value
)
2470 Lisp_Object new_value
, old_value
;
2472 x_compute_fringe_widths (f
, 1);
2476 x_set_border_width (f
, arg
, oldval
)
2478 Lisp_Object arg
, oldval
;
2482 if (XINT (arg
) == f
->output_data
.w32
->border_width
)
2485 if (FRAME_W32_WINDOW (f
) != 0)
2486 error ("Cannot change the border width of a window");
2488 f
->output_data
.w32
->border_width
= XINT (arg
);
2492 x_set_internal_border_width (f
, arg
, oldval
)
2494 Lisp_Object arg
, oldval
;
2496 int old
= f
->output_data
.w32
->internal_border_width
;
2499 f
->output_data
.w32
->internal_border_width
= XINT (arg
);
2500 if (f
->output_data
.w32
->internal_border_width
< 0)
2501 f
->output_data
.w32
->internal_border_width
= 0;
2503 if (f
->output_data
.w32
->internal_border_width
== old
)
2506 if (FRAME_W32_WINDOW (f
) != 0)
2508 x_set_window_size (f
, 0, f
->width
, f
->height
);
2509 SET_FRAME_GARBAGED (f
);
2510 do_pending_window_change (0);
2513 SET_FRAME_GARBAGED (f
);
2517 x_set_visibility (f
, value
, oldval
)
2519 Lisp_Object value
, oldval
;
2522 XSETFRAME (frame
, f
);
2525 Fmake_frame_invisible (frame
, Qt
);
2526 else if (EQ (value
, Qicon
))
2527 Ficonify_frame (frame
);
2529 Fmake_frame_visible (frame
);
2533 /* Change window heights in windows rooted in WINDOW by N lines. */
2536 x_change_window_heights (window
, n
)
2540 struct window
*w
= XWINDOW (window
);
2542 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
2543 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
2545 if (INTEGERP (w
->orig_top
))
2546 XSETFASTINT (w
->orig_top
, XFASTINT (w
->orig_top
) + n
);
2547 if (INTEGERP (w
->orig_height
))
2548 XSETFASTINT (w
->orig_height
, XFASTINT (w
->orig_height
) - n
);
2550 /* Handle just the top child in a vertical split. */
2551 if (!NILP (w
->vchild
))
2552 x_change_window_heights (w
->vchild
, n
);
2554 /* Adjust all children in a horizontal split. */
2555 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2557 w
= XWINDOW (window
);
2558 x_change_window_heights (window
, n
);
2563 x_set_menu_bar_lines (f
, value
, oldval
)
2565 Lisp_Object value
, oldval
;
2568 int olines
= FRAME_MENU_BAR_LINES (f
);
2570 /* Right now, menu bars don't work properly in minibuf-only frames;
2571 most of the commands try to apply themselves to the minibuffer
2572 frame itself, and get an error because you can't switch buffers
2573 in or split the minibuffer window. */
2574 if (FRAME_MINIBUF_ONLY_P (f
))
2577 if (INTEGERP (value
))
2578 nlines
= XINT (value
);
2582 FRAME_MENU_BAR_LINES (f
) = 0;
2584 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2587 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2588 free_frame_menubar (f
);
2589 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2591 /* Adjust the frame size so that the client (text) dimensions
2592 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
2594 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2595 do_pending_window_change (0);
2601 /* Set the number of lines used for the tool bar of frame F to VALUE.
2602 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2603 is the old number of tool bar lines. This function changes the
2604 height of all windows on frame F to match the new tool bar height.
2605 The frame's height doesn't change. */
2608 x_set_tool_bar_lines (f
, value
, oldval
)
2610 Lisp_Object value
, oldval
;
2612 int delta
, nlines
, root_height
;
2613 Lisp_Object root_window
;
2615 /* Treat tool bars like menu bars. */
2616 if (FRAME_MINIBUF_ONLY_P (f
))
2619 /* Use VALUE only if an integer >= 0. */
2620 if (INTEGERP (value
) && XINT (value
) >= 0)
2621 nlines
= XFASTINT (value
);
2625 /* Make sure we redisplay all windows in this frame. */
2626 ++windows_or_buffers_changed
;
2628 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2630 /* Don't resize the tool-bar to more than we have room for. */
2631 root_window
= FRAME_ROOT_WINDOW (f
);
2632 root_height
= XINT (XWINDOW (root_window
)->height
);
2633 if (root_height
- delta
< 1)
2635 delta
= root_height
- 1;
2636 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
2639 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2640 x_change_window_heights (root_window
, delta
);
2643 /* We also have to make sure that the internal border at the top of
2644 the frame, below the menu bar or tool bar, is redrawn when the
2645 tool bar disappears. This is so because the internal border is
2646 below the tool bar if one is displayed, but is below the menu bar
2647 if there isn't a tool bar. The tool bar draws into the area
2648 below the menu bar. */
2649 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
2653 clear_current_matrices (f
);
2654 updating_frame
= NULL
;
2657 /* If the tool bar gets smaller, the internal border below it
2658 has to be cleared. It was formerly part of the display
2659 of the larger tool bar, and updating windows won't clear it. */
2662 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2663 int width
= PIXEL_WIDTH (f
);
2664 int y
= nlines
* CANON_Y_UNIT (f
);
2668 HDC hdc
= get_frame_dc (f
);
2669 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
2670 release_frame_dc (f
, hdc
);
2674 if (WINDOWP (f
->tool_bar_window
))
2675 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
2680 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2683 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2684 name; if NAME is a string, set F's name to NAME and set
2685 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2687 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2688 suggesting a new name, which lisp code should override; if
2689 F->explicit_name is set, ignore the new name; otherwise, set it. */
2692 x_set_name (f
, name
, explicit)
2697 /* Make sure that requests from lisp code override requests from
2698 Emacs redisplay code. */
2701 /* If we're switching from explicit to implicit, we had better
2702 update the mode lines and thereby update the title. */
2703 if (f
->explicit_name
&& NILP (name
))
2704 update_mode_lines
= 1;
2706 f
->explicit_name
= ! NILP (name
);
2708 else if (f
->explicit_name
)
2711 /* If NAME is nil, set the name to the w32_id_name. */
2714 /* Check for no change needed in this very common case
2715 before we do any consing. */
2716 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
2717 XSTRING (f
->name
)->data
))
2719 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
2722 CHECK_STRING (name
);
2724 /* Don't change the name if it's already NAME. */
2725 if (! NILP (Fstring_equal (name
, f
->name
)))
2730 /* For setting the frame title, the title parameter should override
2731 the name parameter. */
2732 if (! NILP (f
->title
))
2735 if (FRAME_W32_WINDOW (f
))
2737 if (STRING_MULTIBYTE (name
))
2738 name
= ENCODE_SYSTEM (name
);
2741 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2746 /* This function should be called when the user's lisp code has
2747 specified a name for the frame; the name will override any set by the
2750 x_explicitly_set_name (f
, arg
, oldval
)
2752 Lisp_Object arg
, oldval
;
2754 x_set_name (f
, arg
, 1);
2757 /* This function should be called by Emacs redisplay code to set the
2758 name; names set this way will never override names set by the user's
2761 x_implicitly_set_name (f
, arg
, oldval
)
2763 Lisp_Object arg
, oldval
;
2765 x_set_name (f
, arg
, 0);
2768 /* Change the title of frame F to NAME.
2769 If NAME is nil, use the frame name as the title.
2771 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2772 name; if NAME is a string, set F's name to NAME and set
2773 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2775 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2776 suggesting a new name, which lisp code should override; if
2777 F->explicit_name is set, ignore the new name; otherwise, set it. */
2780 x_set_title (f
, name
, old_name
)
2782 Lisp_Object name
, old_name
;
2784 /* Don't change the title if it's already NAME. */
2785 if (EQ (name
, f
->title
))
2788 update_mode_lines
= 1;
2795 if (FRAME_W32_WINDOW (f
))
2797 if (STRING_MULTIBYTE (name
))
2798 name
= ENCODE_SYSTEM (name
);
2801 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2807 x_set_autoraise (f
, arg
, oldval
)
2809 Lisp_Object arg
, oldval
;
2811 f
->auto_raise
= !EQ (Qnil
, arg
);
2815 x_set_autolower (f
, arg
, oldval
)
2817 Lisp_Object arg
, oldval
;
2819 f
->auto_lower
= !EQ (Qnil
, arg
);
2823 x_set_unsplittable (f
, arg
, oldval
)
2825 Lisp_Object arg
, oldval
;
2827 f
->no_split
= !NILP (arg
);
2831 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2833 Lisp_Object arg
, oldval
;
2835 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2836 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2837 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2838 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2840 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = NILP (arg
) ?
2841 vertical_scroll_bar_none
:
2842 /* Put scroll bars on the right by default, as is conventional
2845 ? vertical_scroll_bar_left
2846 : vertical_scroll_bar_right
;
2848 /* We set this parameter before creating the window for the
2849 frame, so we can get the geometry right from the start.
2850 However, if the window hasn't been created yet, we shouldn't
2851 call x_set_window_size. */
2852 if (FRAME_W32_WINDOW (f
))
2853 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2854 do_pending_window_change (0);
2859 x_set_scroll_bar_width (f
, arg
, oldval
)
2861 Lisp_Object arg
, oldval
;
2863 int wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
2867 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2868 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) +
2870 if (FRAME_W32_WINDOW (f
))
2871 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2872 do_pending_window_change (0);
2874 else if (INTEGERP (arg
) && XINT (arg
) > 0
2875 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2877 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2878 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2880 if (FRAME_W32_WINDOW (f
))
2881 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2882 do_pending_window_change (0);
2884 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2885 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2886 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2889 /* Subroutines of creating an frame. */
2891 /* Make sure that Vx_resource_name is set to a reasonable value.
2892 Fix it up, or set it to `emacs' if it is too hopeless. */
2895 validate_x_resource_name ()
2898 /* Number of valid characters in the resource name. */
2900 /* Number of invalid characters in the resource name. */
2905 if (STRINGP (Vx_resource_name
))
2907 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
2910 len
= STRING_BYTES (XSTRING (Vx_resource_name
));
2912 /* Only letters, digits, - and _ are valid in resource names.
2913 Count the valid characters and count the invalid ones. */
2914 for (i
= 0; i
< len
; i
++)
2917 if (! ((c
>= 'a' && c
<= 'z')
2918 || (c
>= 'A' && c
<= 'Z')
2919 || (c
>= '0' && c
<= '9')
2920 || c
== '-' || c
== '_'))
2927 /* Not a string => completely invalid. */
2928 bad_count
= 5, good_count
= 0;
2930 /* If name is valid already, return. */
2934 /* If name is entirely invalid, or nearly so, use `emacs'. */
2936 || (good_count
== 1 && bad_count
> 0))
2938 Vx_resource_name
= build_string ("emacs");
2942 /* Name is partly valid. Copy it and replace the invalid characters
2943 with underscores. */
2945 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
2947 for (i
= 0; i
< len
; i
++)
2949 int c
= XSTRING (new)->data
[i
];
2950 if (! ((c
>= 'a' && c
<= 'z')
2951 || (c
>= 'A' && c
<= 'Z')
2952 || (c
>= '0' && c
<= '9')
2953 || c
== '-' || c
== '_'))
2954 XSTRING (new)->data
[i
] = '_';
2959 extern char *x_get_string_resource ();
2961 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
2962 doc
: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
2963 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
2964 class, where INSTANCE is the name under which Emacs was invoked, or
2965 the name specified by the `-name' or `-rn' command-line arguments.
2967 The optional arguments COMPONENT and SUBCLASS add to the key and the
2968 class, respectively. You must specify both of them or neither.
2969 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
2970 and the class is `Emacs.CLASS.SUBCLASS'. */)
2971 (attribute
, class, component
, subclass
)
2972 Lisp_Object attribute
, class, component
, subclass
;
2974 register char *value
;
2978 CHECK_STRING (attribute
);
2979 CHECK_STRING (class);
2981 if (!NILP (component
))
2982 CHECK_STRING (component
);
2983 if (!NILP (subclass
))
2984 CHECK_STRING (subclass
);
2985 if (NILP (component
) != NILP (subclass
))
2986 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
2988 validate_x_resource_name ();
2990 /* Allocate space for the components, the dots which separate them,
2991 and the final '\0'. Make them big enough for the worst case. */
2992 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vx_resource_name
))
2993 + (STRINGP (component
)
2994 ? STRING_BYTES (XSTRING (component
)) : 0)
2995 + STRING_BYTES (XSTRING (attribute
))
2998 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2999 + STRING_BYTES (XSTRING (class))
3000 + (STRINGP (subclass
)
3001 ? STRING_BYTES (XSTRING (subclass
)) : 0)
3004 /* Start with emacs.FRAMENAME for the name (the specific one)
3005 and with `Emacs' for the class key (the general one). */
3006 strcpy (name_key
, XSTRING (Vx_resource_name
)->data
);
3007 strcpy (class_key
, EMACS_CLASS
);
3009 strcat (class_key
, ".");
3010 strcat (class_key
, XSTRING (class)->data
);
3012 if (!NILP (component
))
3014 strcat (class_key
, ".");
3015 strcat (class_key
, XSTRING (subclass
)->data
);
3017 strcat (name_key
, ".");
3018 strcat (name_key
, XSTRING (component
)->data
);
3021 strcat (name_key
, ".");
3022 strcat (name_key
, XSTRING (attribute
)->data
);
3024 value
= x_get_string_resource (Qnil
,
3025 name_key
, class_key
);
3027 if (value
!= (char *) 0)
3028 return build_string (value
);
3033 /* Used when C code wants a resource value. */
3036 x_get_resource_string (attribute
, class)
3037 char *attribute
, *class;
3041 struct frame
*sf
= SELECTED_FRAME ();
3043 /* Allocate space for the components, the dots which separate them,
3044 and the final '\0'. */
3045 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vinvocation_name
))
3046 + strlen (attribute
) + 2);
3047 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
3048 + strlen (class) + 2);
3050 sprintf (name_key
, "%s.%s",
3051 XSTRING (Vinvocation_name
)->data
,
3053 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
3055 return x_get_string_resource (sf
, name_key
, class_key
);
3058 /* Types we might convert a resource string into. */
3068 /* Return the value of parameter PARAM.
3070 First search ALIST, then Vdefault_frame_alist, then the X defaults
3071 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3073 Convert the resource to the type specified by desired_type.
3075 If no default is specified, return Qunbound. If you call
3076 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
3077 and don't let it get stored in any Lisp-visible variables! */
3080 w32_get_arg (alist
, param
, attribute
, class, type
)
3081 Lisp_Object alist
, param
;
3084 enum resource_types type
;
3086 register Lisp_Object tem
;
3088 tem
= Fassq (param
, alist
);
3090 tem
= Fassq (param
, Vdefault_frame_alist
);
3096 tem
= Fx_get_resource (build_string (attribute
),
3097 build_string (class),
3105 case RES_TYPE_NUMBER
:
3106 return make_number (atoi (XSTRING (tem
)->data
));
3108 case RES_TYPE_FLOAT
:
3109 return make_float (atof (XSTRING (tem
)->data
));
3111 case RES_TYPE_BOOLEAN
:
3112 tem
= Fdowncase (tem
);
3113 if (!strcmp (XSTRING (tem
)->data
, "on")
3114 || !strcmp (XSTRING (tem
)->data
, "true"))
3119 case RES_TYPE_STRING
:
3122 case RES_TYPE_SYMBOL
:
3123 /* As a special case, we map the values `true' and `on'
3124 to Qt, and `false' and `off' to Qnil. */
3127 lower
= Fdowncase (tem
);
3128 if (!strcmp (XSTRING (lower
)->data
, "on")
3129 || !strcmp (XSTRING (lower
)->data
, "true"))
3131 else if (!strcmp (XSTRING (lower
)->data
, "off")
3132 || !strcmp (XSTRING (lower
)->data
, "false"))
3135 return Fintern (tem
, Qnil
);
3148 /* Record in frame F the specified or default value according to ALIST
3149 of the parameter named PROP (a Lisp symbol).
3150 If no value is specified for PROP, look for an X default for XPROP
3151 on the frame named NAME.
3152 If that is not found either, use the value DEFLT. */
3155 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3162 enum resource_types type
;
3166 tem
= w32_get_arg (alist
, prop
, xprop
, xclass
, type
);
3167 if (EQ (tem
, Qunbound
))
3169 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3173 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3174 doc
: /* Parse an X-style geometry string STRING.
3175 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3176 The properties returned may include `top', `left', `height', and `width'.
3177 The value of `left' or `top' may be an integer,
3178 or a list (+ N) meaning N pixels relative to top/left corner,
3179 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3184 unsigned int width
, height
;
3187 CHECK_STRING (string
);
3189 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
3190 &x
, &y
, &width
, &height
);
3193 if (geometry
& XValue
)
3195 Lisp_Object element
;
3197 if (x
>= 0 && (geometry
& XNegative
))
3198 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3199 else if (x
< 0 && ! (geometry
& XNegative
))
3200 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3202 element
= Fcons (Qleft
, make_number (x
));
3203 result
= Fcons (element
, result
);
3206 if (geometry
& YValue
)
3208 Lisp_Object element
;
3210 if (y
>= 0 && (geometry
& YNegative
))
3211 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3212 else if (y
< 0 && ! (geometry
& YNegative
))
3213 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3215 element
= Fcons (Qtop
, make_number (y
));
3216 result
= Fcons (element
, result
);
3219 if (geometry
& WidthValue
)
3220 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3221 if (geometry
& HeightValue
)
3222 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3227 /* Calculate the desired size and position of this window,
3228 and return the flags saying which aspects were specified.
3230 This function does not make the coordinates positive. */
3232 #define DEFAULT_ROWS 40
3233 #define DEFAULT_COLS 80
3236 x_figure_window_size (f
, parms
)
3240 register Lisp_Object tem0
, tem1
, tem2
;
3241 long window_prompting
= 0;
3243 /* Default values if we fall through.
3244 Actually, if that happens we should get
3245 window manager prompting. */
3246 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3247 f
->height
= DEFAULT_ROWS
;
3248 /* Window managers expect that if program-specified
3249 positions are not (0,0), they're intentional, not defaults. */
3250 f
->output_data
.w32
->top_pos
= 0;
3251 f
->output_data
.w32
->left_pos
= 0;
3253 /* Ensure that old new_width and new_height will not override the
3255 FRAME_NEW_WIDTH (f
) = 0;
3256 FRAME_NEW_HEIGHT (f
) = 0;
3258 tem0
= w32_get_arg (parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3259 tem1
= w32_get_arg (parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3260 tem2
= w32_get_arg (parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3261 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3263 if (!EQ (tem0
, Qunbound
))
3265 CHECK_NUMBER (tem0
);
3266 f
->height
= XINT (tem0
);
3268 if (!EQ (tem1
, Qunbound
))
3270 CHECK_NUMBER (tem1
);
3271 SET_FRAME_WIDTH (f
, XINT (tem1
));
3273 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3274 window_prompting
|= USSize
;
3276 window_prompting
|= PSize
;
3279 f
->output_data
.w32
->vertical_scroll_bar_extra
3280 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3282 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3283 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3284 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
3285 x_compute_fringe_widths (f
, 0);
3286 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3287 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3289 tem0
= w32_get_arg (parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3290 tem1
= w32_get_arg (parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3291 tem2
= w32_get_arg (parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3292 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3294 if (EQ (tem0
, Qminus
))
3296 f
->output_data
.w32
->top_pos
= 0;
3297 window_prompting
|= YNegative
;
3299 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3300 && CONSP (XCDR (tem0
))
3301 && INTEGERP (XCAR (XCDR (tem0
))))
3303 f
->output_data
.w32
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3304 window_prompting
|= YNegative
;
3306 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3307 && CONSP (XCDR (tem0
))
3308 && INTEGERP (XCAR (XCDR (tem0
))))
3310 f
->output_data
.w32
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3312 else if (EQ (tem0
, Qunbound
))
3313 f
->output_data
.w32
->top_pos
= 0;
3316 CHECK_NUMBER (tem0
);
3317 f
->output_data
.w32
->top_pos
= XINT (tem0
);
3318 if (f
->output_data
.w32
->top_pos
< 0)
3319 window_prompting
|= YNegative
;
3322 if (EQ (tem1
, Qminus
))
3324 f
->output_data
.w32
->left_pos
= 0;
3325 window_prompting
|= XNegative
;
3327 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3328 && CONSP (XCDR (tem1
))
3329 && INTEGERP (XCAR (XCDR (tem1
))))
3331 f
->output_data
.w32
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3332 window_prompting
|= XNegative
;
3334 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3335 && CONSP (XCDR (tem1
))
3336 && INTEGERP (XCAR (XCDR (tem1
))))
3338 f
->output_data
.w32
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3340 else if (EQ (tem1
, Qunbound
))
3341 f
->output_data
.w32
->left_pos
= 0;
3344 CHECK_NUMBER (tem1
);
3345 f
->output_data
.w32
->left_pos
= XINT (tem1
);
3346 if (f
->output_data
.w32
->left_pos
< 0)
3347 window_prompting
|= XNegative
;
3350 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3351 window_prompting
|= USPosition
;
3353 window_prompting
|= PPosition
;
3356 return window_prompting
;
3361 extern LRESULT CALLBACK
w32_wnd_proc ();
3364 w32_init_class (hinst
)
3369 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3370 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
3372 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
3373 wc
.hInstance
= hinst
;
3374 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
3375 wc
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
3376 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
3377 wc
.lpszMenuName
= NULL
;
3378 wc
.lpszClassName
= EMACS_CLASS
;
3380 return (RegisterClass (&wc
));
3384 w32_createscrollbar (f
, bar
)
3386 struct scroll_bar
* bar
;
3388 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
3389 /* Position and size of scroll bar. */
3390 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3392 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3394 FRAME_W32_WINDOW (f
),
3401 w32_createwindow (f
)
3407 rect
.left
= rect
.top
= 0;
3408 rect
.right
= PIXEL_WIDTH (f
);
3409 rect
.bottom
= PIXEL_HEIGHT (f
);
3411 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3412 FRAME_EXTERNAL_MENU_BAR (f
));
3414 /* Do first time app init */
3418 w32_init_class (hinst
);
3421 FRAME_W32_WINDOW (f
) = hwnd
3422 = CreateWindow (EMACS_CLASS
,
3424 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
3425 f
->output_data
.w32
->left_pos
,
3426 f
->output_data
.w32
->top_pos
,
3427 rect
.right
- rect
.left
,
3428 rect
.bottom
- rect
.top
,
3436 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
3437 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
3438 SetWindowLong (hwnd
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
3439 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
3440 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3442 /* Enable drag-n-drop. */
3443 DragAcceptFiles (hwnd
, TRUE
);
3445 /* Do this to discard the default setting specified by our parent. */
3446 ShowWindow (hwnd
, SW_HIDE
);
3451 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
3458 wmsg
->msg
.hwnd
= hwnd
;
3459 wmsg
->msg
.message
= msg
;
3460 wmsg
->msg
.wParam
= wParam
;
3461 wmsg
->msg
.lParam
= lParam
;
3462 wmsg
->msg
.time
= GetMessageTime ();
3467 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
3468 between left and right keys as advertised. We test for this
3469 support dynamically, and set a flag when the support is absent. If
3470 absent, we keep track of the left and right control and alt keys
3471 ourselves. This is particularly necessary on keyboards that rely
3472 upon the AltGr key, which is represented as having the left control
3473 and right alt keys pressed. For these keyboards, we need to know
3474 when the left alt key has been pressed in addition to the AltGr key
3475 so that we can properly support M-AltGr-key sequences (such as M-@
3476 on Swedish keyboards). */
3478 #define EMACS_LCONTROL 0
3479 #define EMACS_RCONTROL 1
3480 #define EMACS_LMENU 2
3481 #define EMACS_RMENU 3
3483 static int modifiers
[4];
3484 static int modifiers_recorded
;
3485 static int modifier_key_support_tested
;
3488 test_modifier_support (unsigned int wparam
)
3492 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
3494 if (wparam
== VK_CONTROL
)
3504 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
3505 modifiers_recorded
= 1;
3507 modifiers_recorded
= 0;
3508 modifier_key_support_tested
= 1;
3512 record_keydown (unsigned int wparam
, unsigned int lparam
)
3516 if (!modifier_key_support_tested
)
3517 test_modifier_support (wparam
);
3519 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3522 if (wparam
== VK_CONTROL
)
3523 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3525 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3531 record_keyup (unsigned int wparam
, unsigned int lparam
)
3535 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3538 if (wparam
== VK_CONTROL
)
3539 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3541 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3546 /* Emacs can lose focus while a modifier key has been pressed. When
3547 it regains focus, be conservative and clear all modifiers since
3548 we cannot reconstruct the left and right modifier state. */
3554 if (GetFocus () == NULL
)
3555 /* Emacs doesn't have keyboard focus. Do nothing. */
3558 ctrl
= GetAsyncKeyState (VK_CONTROL
);
3559 alt
= GetAsyncKeyState (VK_MENU
);
3561 if (!(ctrl
& 0x08000))
3562 /* Clear any recorded control modifier state. */
3563 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3565 if (!(alt
& 0x08000))
3566 /* Clear any recorded alt modifier state. */
3567 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3569 /* Update the state of all modifier keys, because modifiers used in
3570 hot-key combinations can get stuck on if Emacs loses focus as a
3571 result of a hot-key being pressed. */
3575 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
3577 GetKeyboardState (keystate
);
3578 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
3579 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
3580 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
3581 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
3582 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
3583 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
3584 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
3585 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
3586 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
3587 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
3588 SetKeyboardState (keystate
);
3592 /* Synchronize modifier state with what is reported with the current
3593 keystroke. Even if we cannot distinguish between left and right
3594 modifier keys, we know that, if no modifiers are set, then neither
3595 the left or right modifier should be set. */
3599 if (!modifiers_recorded
)
3602 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
3603 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3605 if (!(GetKeyState (VK_MENU
) & 0x8000))
3606 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3610 modifier_set (int vkey
)
3612 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
3613 return (GetKeyState (vkey
) & 0x1);
3614 if (!modifiers_recorded
)
3615 return (GetKeyState (vkey
) & 0x8000);
3620 return modifiers
[EMACS_LCONTROL
];
3622 return modifiers
[EMACS_RCONTROL
];
3624 return modifiers
[EMACS_LMENU
];
3626 return modifiers
[EMACS_RMENU
];
3628 return (GetKeyState (vkey
) & 0x8000);
3631 /* Convert between the modifier bits W32 uses and the modifier bits
3635 w32_key_to_modifier (int key
)
3637 Lisp_Object key_mapping
;
3642 key_mapping
= Vw32_lwindow_modifier
;
3645 key_mapping
= Vw32_rwindow_modifier
;
3648 key_mapping
= Vw32_apps_modifier
;
3651 key_mapping
= Vw32_scroll_lock_modifier
;
3657 /* NB. This code runs in the input thread, asychronously to the lisp
3658 thread, so we must be careful to ensure access to lisp data is
3659 thread-safe. The following code is safe because the modifier
3660 variable values are updated atomically from lisp and symbols are
3661 not relocated by GC. Also, we don't have to worry about seeing GC
3663 if (EQ (key_mapping
, Qhyper
))
3664 return hyper_modifier
;
3665 if (EQ (key_mapping
, Qsuper
))
3666 return super_modifier
;
3667 if (EQ (key_mapping
, Qmeta
))
3668 return meta_modifier
;
3669 if (EQ (key_mapping
, Qalt
))
3670 return alt_modifier
;
3671 if (EQ (key_mapping
, Qctrl
))
3672 return ctrl_modifier
;
3673 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
3674 return ctrl_modifier
;
3675 if (EQ (key_mapping
, Qshift
))
3676 return shift_modifier
;
3678 /* Don't generate any modifier if not explicitly requested. */
3683 w32_get_modifiers ()
3685 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
3686 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
3687 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
3688 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
3689 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
3690 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
3691 (modifier_set (VK_MENU
) ?
3692 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
3695 /* We map the VK_* modifiers into console modifier constants
3696 so that we can use the same routines to handle both console
3697 and window input. */
3700 construct_console_modifiers ()
3705 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
3706 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
3707 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
3708 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
3709 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
3710 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
3711 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
3712 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
3713 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
3714 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
3715 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
3721 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
3725 /* Convert to emacs modifiers. */
3726 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
3732 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
3734 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
3737 if (virt_key
== VK_RETURN
)
3738 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
3740 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
3741 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
3743 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
3744 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
3746 if (virt_key
== VK_CLEAR
)
3747 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
3752 /* List of special key combinations which w32 would normally capture,
3753 but emacs should grab instead. Not directly visible to lisp, to
3754 simplify synchronization. Each item is an integer encoding a virtual
3755 key code and modifier combination to capture. */
3756 Lisp_Object w32_grabbed_keys
;
3758 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
3759 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
3760 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
3761 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
3763 /* Register hot-keys for reserved key combinations when Emacs has
3764 keyboard focus, since this is the only way Emacs can receive key
3765 combinations like Alt-Tab which are used by the system. */
3768 register_hot_keys (hwnd
)
3771 Lisp_Object keylist
;
3773 /* Use GC_CONSP, since we are called asynchronously. */
3774 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3776 Lisp_Object key
= XCAR (keylist
);
3778 /* Deleted entries get set to nil. */
3779 if (!INTEGERP (key
))
3782 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
3783 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
3788 unregister_hot_keys (hwnd
)
3791 Lisp_Object keylist
;
3793 /* Use GC_CONSP, since we are called asynchronously. */
3794 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3796 Lisp_Object key
= XCAR (keylist
);
3798 if (!INTEGERP (key
))
3801 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
3805 /* Main message dispatch loop. */
3808 w32_msg_pump (deferred_msg
* msg_buf
)
3814 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
3816 while (GetMessage (&msg
, NULL
, 0, 0))
3818 if (msg
.hwnd
== NULL
)
3820 switch (msg
.message
)
3823 /* Produced by complete_deferred_msg; just ignore. */
3825 case WM_EMACS_CREATEWINDOW
:
3826 w32_createwindow ((struct frame
*) msg
.wParam
);
3827 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3830 case WM_EMACS_SETLOCALE
:
3831 SetThreadLocale (msg
.wParam
);
3832 /* Reply is not expected. */
3834 case WM_EMACS_SETKEYBOARDLAYOUT
:
3835 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
3836 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3840 case WM_EMACS_REGISTER_HOT_KEY
:
3841 focus_window
= GetFocus ();
3842 if (focus_window
!= NULL
)
3843 RegisterHotKey (focus_window
,
3844 HOTKEY_ID (msg
.wParam
),
3845 HOTKEY_MODIFIERS (msg
.wParam
),
3846 HOTKEY_VK_CODE (msg
.wParam
));
3847 /* Reply is not expected. */
3849 case WM_EMACS_UNREGISTER_HOT_KEY
:
3850 focus_window
= GetFocus ();
3851 if (focus_window
!= NULL
)
3852 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
3853 /* Mark item as erased. NB: this code must be
3854 thread-safe. The next line is okay because the cons
3855 cell is never made into garbage and is not relocated by
3857 XSETCAR ((Lisp_Object
) msg
.lParam
, Qnil
);
3858 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3861 case WM_EMACS_TOGGLE_LOCK_KEY
:
3863 int vk_code
= (int) msg
.wParam
;
3864 int cur_state
= (GetKeyState (vk_code
) & 1);
3865 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
3867 /* NB: This code must be thread-safe. It is safe to
3868 call NILP because symbols are not relocated by GC,
3869 and pointer here is not touched by GC (so the markbit
3870 can't be set). Numbers are safe because they are
3871 immediate values. */
3872 if (NILP (new_state
)
3873 || (NUMBERP (new_state
)
3874 && ((XUINT (new_state
)) & 1) != cur_state
))
3876 one_w32_display_info
.faked_key
= vk_code
;
3878 keybd_event ((BYTE
) vk_code
,
3879 (BYTE
) MapVirtualKey (vk_code
, 0),
3880 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3881 keybd_event ((BYTE
) vk_code
,
3882 (BYTE
) MapVirtualKey (vk_code
, 0),
3883 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3884 keybd_event ((BYTE
) vk_code
,
3885 (BYTE
) MapVirtualKey (vk_code
, 0),
3886 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3887 cur_state
= !cur_state
;
3889 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3895 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
3900 DispatchMessage (&msg
);
3903 /* Exit nested loop when our deferred message has completed. */
3904 if (msg_buf
->completed
)
3909 deferred_msg
* deferred_msg_head
;
3911 static deferred_msg
*
3912 find_deferred_msg (HWND hwnd
, UINT msg
)
3914 deferred_msg
* item
;
3916 /* Don't actually need synchronization for read access, since
3917 modification of single pointer is always atomic. */
3918 /* enter_crit (); */
3920 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3921 if (item
->w32msg
.msg
.hwnd
== hwnd
3922 && item
->w32msg
.msg
.message
== msg
)
3925 /* leave_crit (); */
3931 send_deferred_msg (deferred_msg
* msg_buf
,
3937 /* Only input thread can send deferred messages. */
3938 if (GetCurrentThreadId () != dwWindowsThreadId
)
3941 /* It is an error to send a message that is already deferred. */
3942 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3945 /* Enforced synchronization is not needed because this is the only
3946 function that alters deferred_msg_head, and the following critical
3947 section is guaranteed to only be serially reentered (since only the
3948 input thread can call us). */
3950 /* enter_crit (); */
3952 msg_buf
->completed
= 0;
3953 msg_buf
->next
= deferred_msg_head
;
3954 deferred_msg_head
= msg_buf
;
3955 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
3957 /* leave_crit (); */
3959 /* Start a new nested message loop to process other messages until
3960 this one is completed. */
3961 w32_msg_pump (msg_buf
);
3963 deferred_msg_head
= msg_buf
->next
;
3965 return msg_buf
->result
;
3969 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
3971 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
3973 if (msg_buf
== NULL
)
3974 /* Message may have been cancelled, so don't abort(). */
3977 msg_buf
->result
= result
;
3978 msg_buf
->completed
= 1;
3980 /* Ensure input thread is woken so it notices the completion. */
3981 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3985 cancel_all_deferred_msgs ()
3987 deferred_msg
* item
;
3989 /* Don't actually need synchronization for read access, since
3990 modification of single pointer is always atomic. */
3991 /* enter_crit (); */
3993 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3996 item
->completed
= 1;
3999 /* leave_crit (); */
4001 /* Ensure input thread is woken so it notices the completion. */
4002 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
4010 deferred_msg dummy_buf
;
4012 /* Ensure our message queue is created */
4014 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
4016 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
4019 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
4020 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
4021 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
4023 /* This is the inital message loop which should only exit when the
4024 application quits. */
4025 w32_msg_pump (&dummy_buf
);
4031 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
4041 wmsg
.dwModifiers
= modifiers
;
4043 /* Detect quit_char and set quit-flag directly. Note that we
4044 still need to post a message to ensure the main thread will be
4045 woken up if blocked in sys_select(), but we do NOT want to post
4046 the quit_char message itself (because it will usually be as if
4047 the user had typed quit_char twice). Instead, we post a dummy
4048 message that has no particular effect. */
4051 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
4052 c
= make_ctrl_char (c
) & 0377;
4054 || (wmsg
.dwModifiers
== 0 &&
4055 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
4059 /* The choice of message is somewhat arbitrary, as long as
4060 the main thread handler just ignores it. */
4063 /* Interrupt any blocking system calls. */
4066 /* As a safety precaution, forcibly complete any deferred
4067 messages. This is a kludge, but I don't see any particularly
4068 clean way to handle the situation where a deferred message is
4069 "dropped" in the lisp thread, and will thus never be
4070 completed, eg. by the user trying to activate the menubar
4071 when the lisp thread is busy, and then typing C-g when the
4072 menubar doesn't open promptly (with the result that the
4073 menubar never responds at all because the deferred
4074 WM_INITMENU message is never completed). Another problem
4075 situation is when the lisp thread calls SendMessage (to send
4076 a window manager command) when a message has been deferred;
4077 the lisp thread gets blocked indefinitely waiting for the
4078 deferred message to be completed, which itself is waiting for
4079 the lisp thread to respond.
4081 Note that we don't want to block the input thread waiting for
4082 a reponse from the lisp thread (although that would at least
4083 solve the deadlock problem above), because we want to be able
4084 to receive C-g to interrupt the lisp thread. */
4085 cancel_all_deferred_msgs ();
4089 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4092 /* Main window procedure */
4095 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
4102 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4104 int windows_translate
;
4107 /* Note that it is okay to call x_window_to_frame, even though we are
4108 not running in the main lisp thread, because frame deletion
4109 requires the lisp thread to synchronize with this thread. Thus, if
4110 a frame struct is returned, it can be used without concern that the
4111 lisp thread might make it disappear while we are using it.
4113 NB. Walking the frame list in this thread is safe (as long as
4114 writes of Lisp_Object slots are atomic, which they are on Windows).
4115 Although delete-frame can destructively modify the frame list while
4116 we are walking it, a garbage collection cannot occur until after
4117 delete-frame has synchronized with this thread.
4119 It is also safe to use functions that make GDI calls, such as
4120 w32_clear_rect, because these functions must obtain a DC handle
4121 from the frame struct using get_frame_dc which is thread-aware. */
4126 f
= x_window_to_frame (dpyinfo
, hwnd
);
4129 HDC hdc
= get_frame_dc (f
);
4130 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
4131 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
4132 release_frame_dc (f
, hdc
);
4134 #if defined (W32_DEBUG_DISPLAY)
4135 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
4137 wmsg
.rect
.left
, wmsg
.rect
.top
,
4138 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4139 #endif /* W32_DEBUG_DISPLAY */
4142 case WM_PALETTECHANGED
:
4143 /* ignore our own changes */
4144 if ((HWND
)wParam
!= hwnd
)
4146 f
= x_window_to_frame (dpyinfo
, hwnd
);
4148 /* get_frame_dc will realize our palette and force all
4149 frames to be redrawn if needed. */
4150 release_frame_dc (f
, get_frame_dc (f
));
4155 PAINTSTRUCT paintStruct
;
4158 f
= x_window_to_frame (dpyinfo
, hwnd
);
4161 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
4165 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
4166 fails. Apparently this can happen under some
4168 if (!w32_strict_painting
|| GetUpdateRect (hwnd
, &update_rect
, FALSE
))
4171 BeginPaint (hwnd
, &paintStruct
);
4173 if (w32_strict_painting
)
4174 /* The rectangles returned by GetUpdateRect and BeginPaint
4175 do not always match. GetUpdateRect seems to be the
4176 more reliable of the two. */
4177 wmsg
.rect
= update_rect
;
4179 wmsg
.rect
= paintStruct
.rcPaint
;
4181 #if defined (W32_DEBUG_DISPLAY)
4182 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
4184 wmsg
.rect
.left
, wmsg
.rect
.top
,
4185 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4186 DebPrint ((" [update region is %d,%d-%d,%d]\n",
4187 update_rect
.left
, update_rect
.top
,
4188 update_rect
.right
, update_rect
.bottom
));
4190 EndPaint (hwnd
, &paintStruct
);
4193 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4198 /* If GetUpdateRect returns 0 (meaning there is no update
4199 region), assume the whole window needs to be repainted. */
4200 GetClientRect(hwnd
, &wmsg
.rect
);
4201 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4205 case WM_INPUTLANGCHANGE
:
4206 /* Inform lisp thread of keyboard layout changes. */
4207 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4209 /* Clear dead keys in the keyboard state; for simplicity only
4210 preserve modifier key states. */
4215 GetKeyboardState (keystate
);
4216 for (i
= 0; i
< 256; i
++)
4233 SetKeyboardState (keystate
);
4238 /* Synchronize hot keys with normal input. */
4239 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
4244 record_keyup (wParam
, lParam
);
4249 /* Ignore keystrokes we fake ourself; see below. */
4250 if (dpyinfo
->faked_key
== wParam
)
4252 dpyinfo
->faked_key
= 0;
4253 /* Make sure TranslateMessage sees them though (as long as
4254 they don't produce WM_CHAR messages). This ensures that
4255 indicator lights are toggled promptly on Windows 9x, for
4257 if (lispy_function_keys
[wParam
] != 0)
4259 windows_translate
= 1;
4265 /* Synchronize modifiers with current keystroke. */
4267 record_keydown (wParam
, lParam
);
4268 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
4270 windows_translate
= 0;
4275 if (NILP (Vw32_pass_lwindow_to_system
))
4277 /* Prevent system from acting on keyup (which opens the
4278 Start menu if no other key was pressed) by simulating a
4279 press of Space which we will ignore. */
4280 if (GetAsyncKeyState (wParam
) & 1)
4282 if (NUMBERP (Vw32_phantom_key_code
))
4283 key
= XUINT (Vw32_phantom_key_code
) & 255;
4286 dpyinfo
->faked_key
= key
;
4287 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4290 if (!NILP (Vw32_lwindow_modifier
))
4294 if (NILP (Vw32_pass_rwindow_to_system
))
4296 if (GetAsyncKeyState (wParam
) & 1)
4298 if (NUMBERP (Vw32_phantom_key_code
))
4299 key
= XUINT (Vw32_phantom_key_code
) & 255;
4302 dpyinfo
->faked_key
= key
;
4303 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4306 if (!NILP (Vw32_rwindow_modifier
))
4310 if (!NILP (Vw32_apps_modifier
))
4314 if (NILP (Vw32_pass_alt_to_system
))
4315 /* Prevent DefWindowProc from activating the menu bar if an
4316 Alt key is pressed and released by itself. */
4318 windows_translate
= 1;
4321 /* Decide whether to treat as modifier or function key. */
4322 if (NILP (Vw32_enable_caps_lock
))
4323 goto disable_lock_key
;
4324 windows_translate
= 1;
4327 /* Decide whether to treat as modifier or function key. */
4328 if (NILP (Vw32_enable_num_lock
))
4329 goto disable_lock_key
;
4330 windows_translate
= 1;
4333 /* Decide whether to treat as modifier or function key. */
4334 if (NILP (Vw32_scroll_lock_modifier
))
4335 goto disable_lock_key
;
4336 windows_translate
= 1;
4339 /* Ensure the appropriate lock key state (and indicator light)
4340 remains in the same state. We do this by faking another
4341 press of the relevant key. Apparently, this really is the
4342 only way to toggle the state of the indicator lights. */
4343 dpyinfo
->faked_key
= wParam
;
4344 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4345 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4346 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4347 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4348 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4349 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4350 /* Ensure indicator lights are updated promptly on Windows 9x
4351 (TranslateMessage apparently does this), after forwarding
4353 post_character_message (hwnd
, msg
, wParam
, lParam
,
4354 w32_get_key_modifiers (wParam
, lParam
));
4355 windows_translate
= 1;
4359 case VK_PROCESSKEY
: /* Generated by IME. */
4360 windows_translate
= 1;
4363 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
4364 which is confusing for purposes of key binding; convert
4365 VK_CANCEL events into VK_PAUSE events. */
4369 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
4370 for purposes of key binding; convert these back into
4371 VK_NUMLOCK events, at least when we want to see NumLock key
4372 presses. (Note that there is never any possibility that
4373 VK_PAUSE with Ctrl really is C-Pause as per above.) */
4374 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
4375 wParam
= VK_NUMLOCK
;
4378 /* If not defined as a function key, change it to a WM_CHAR message. */
4379 if (lispy_function_keys
[wParam
] == 0)
4381 DWORD modifiers
= construct_console_modifiers ();
4383 if (!NILP (Vw32_recognize_altgr
)
4384 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
4386 /* Always let TranslateMessage handle AltGr key chords;
4387 for some reason, ToAscii doesn't always process AltGr
4388 chords correctly. */
4389 windows_translate
= 1;
4391 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
4393 /* Handle key chords including any modifiers other
4394 than shift directly, in order to preserve as much
4395 modifier information as possible. */
4396 if ('A' <= wParam
&& wParam
<= 'Z')
4398 /* Don't translate modified alphabetic keystrokes,
4399 so the user doesn't need to constantly switch
4400 layout to type control or meta keystrokes when
4401 the normal layout translates alphabetic
4402 characters to non-ascii characters. */
4403 if (!modifier_set (VK_SHIFT
))
4404 wParam
+= ('a' - 'A');
4409 /* Try to handle other keystrokes by determining the
4410 base character (ie. translating the base key plus
4414 KEY_EVENT_RECORD key
;
4416 key
.bKeyDown
= TRUE
;
4417 key
.wRepeatCount
= 1;
4418 key
.wVirtualKeyCode
= wParam
;
4419 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
4420 key
.uChar
.AsciiChar
= 0;
4421 key
.dwControlKeyState
= modifiers
;
4423 add
= w32_kbd_patch_key (&key
);
4424 /* 0 means an unrecognised keycode, negative means
4425 dead key. Ignore both. */
4428 /* Forward asciified character sequence. */
4429 post_character_message
4430 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
4431 w32_get_key_modifiers (wParam
, lParam
));
4432 w32_kbd_patch_key (&key
);
4439 /* Let TranslateMessage handle everything else. */
4440 windows_translate
= 1;
4446 if (windows_translate
)
4448 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
4450 windows_msg
.time
= GetMessageTime ();
4451 TranslateMessage (&windows_msg
);
4459 post_character_message (hwnd
, msg
, wParam
, lParam
,
4460 w32_get_key_modifiers (wParam
, lParam
));
4463 /* Simulate middle mouse button events when left and right buttons
4464 are used together, but only if user has two button mouse. */
4465 case WM_LBUTTONDOWN
:
4466 case WM_RBUTTONDOWN
:
4467 if (XINT (Vw32_num_mouse_buttons
) > 2)
4468 goto handle_plain_button
;
4471 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
4472 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
4474 if (button_state
& this)
4477 if (button_state
== 0)
4480 button_state
|= this;
4482 if (button_state
& other
)
4484 if (mouse_button_timer
)
4486 KillTimer (hwnd
, mouse_button_timer
);
4487 mouse_button_timer
= 0;
4489 /* Generate middle mouse event instead. */
4490 msg
= WM_MBUTTONDOWN
;
4491 button_state
|= MMOUSE
;
4493 else if (button_state
& MMOUSE
)
4495 /* Ignore button event if we've already generated a
4496 middle mouse down event. This happens if the
4497 user releases and press one of the two buttons
4498 after we've faked a middle mouse event. */
4503 /* Flush out saved message. */
4504 post_msg (&saved_mouse_button_msg
);
4506 wmsg
.dwModifiers
= w32_get_modifiers ();
4507 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4509 /* Clear message buffer. */
4510 saved_mouse_button_msg
.msg
.hwnd
= 0;
4514 /* Hold onto message for now. */
4515 mouse_button_timer
=
4516 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
4517 XINT (Vw32_mouse_button_tolerance
), NULL
);
4518 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
4519 saved_mouse_button_msg
.msg
.message
= msg
;
4520 saved_mouse_button_msg
.msg
.wParam
= wParam
;
4521 saved_mouse_button_msg
.msg
.lParam
= lParam
;
4522 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
4523 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
4530 if (XINT (Vw32_num_mouse_buttons
) > 2)
4531 goto handle_plain_button
;
4534 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
4535 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
4537 if ((button_state
& this) == 0)
4540 button_state
&= ~this;
4542 if (button_state
& MMOUSE
)
4544 /* Only generate event when second button is released. */
4545 if ((button_state
& other
) == 0)
4548 button_state
&= ~MMOUSE
;
4550 if (button_state
) abort ();
4557 /* Flush out saved message if necessary. */
4558 if (saved_mouse_button_msg
.msg
.hwnd
)
4560 post_msg (&saved_mouse_button_msg
);
4563 wmsg
.dwModifiers
= w32_get_modifiers ();
4564 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4566 /* Always clear message buffer and cancel timer. */
4567 saved_mouse_button_msg
.msg
.hwnd
= 0;
4568 KillTimer (hwnd
, mouse_button_timer
);
4569 mouse_button_timer
= 0;
4571 if (button_state
== 0)
4576 case WM_XBUTTONDOWN
:
4578 if (w32_pass_extra_mouse_buttons_to_system
)
4580 /* else fall through and process them. */
4581 case WM_MBUTTONDOWN
:
4583 handle_plain_button
:
4588 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
4590 if (up
) ReleaseCapture ();
4591 else SetCapture (hwnd
);
4592 button
= (button
== 0) ? LMOUSE
:
4593 ((button
== 1) ? MMOUSE
: RMOUSE
);
4595 button_state
&= ~button
;
4597 button_state
|= button
;
4601 wmsg
.dwModifiers
= w32_get_modifiers ();
4602 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4604 /* Need to return true for XBUTTON messages, false for others,
4605 to indicate that we processed the message. */
4606 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
4609 /* If the mouse has just moved into the frame, start tracking
4610 it, so we will be notified when it leaves the frame. Mouse
4611 tracking only works under W98 and NT4 and later. On earlier
4612 versions, there is no way of telling when the mouse leaves the
4613 frame, so we just have to put up with help-echo and mouse
4614 highlighting remaining while the frame is not active. */
4615 if (track_mouse_event_fn
&& !track_mouse_window
)
4617 TRACKMOUSEEVENT tme
;
4618 tme
.cbSize
= sizeof (tme
);
4619 tme
.dwFlags
= TME_LEAVE
;
4620 tme
.hwndTrack
= hwnd
;
4622 track_mouse_event_fn (&tme
);
4623 track_mouse_window
= hwnd
;
4626 if (XINT (Vw32_mouse_move_interval
) <= 0
4627 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4629 wmsg
.dwModifiers
= w32_get_modifiers ();
4630 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4634 /* Hang onto mouse move and scroll messages for a bit, to avoid
4635 sending such events to Emacs faster than it can process them.
4636 If we get more events before the timer from the first message
4637 expires, we just replace the first message. */
4639 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4641 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4642 XINT (Vw32_mouse_move_interval
), NULL
);
4644 /* Hold onto message for now. */
4645 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4646 saved_mouse_move_msg
.msg
.message
= msg
;
4647 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4648 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4649 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4650 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4655 wmsg
.dwModifiers
= w32_get_modifiers ();
4656 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4660 wmsg
.dwModifiers
= w32_get_modifiers ();
4661 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4665 /* Flush out saved messages if necessary. */
4666 if (wParam
== mouse_button_timer
)
4668 if (saved_mouse_button_msg
.msg
.hwnd
)
4670 post_msg (&saved_mouse_button_msg
);
4671 saved_mouse_button_msg
.msg
.hwnd
= 0;
4673 KillTimer (hwnd
, mouse_button_timer
);
4674 mouse_button_timer
= 0;
4676 else if (wParam
== mouse_move_timer
)
4678 if (saved_mouse_move_msg
.msg
.hwnd
)
4680 post_msg (&saved_mouse_move_msg
);
4681 saved_mouse_move_msg
.msg
.hwnd
= 0;
4683 KillTimer (hwnd
, mouse_move_timer
);
4684 mouse_move_timer
= 0;
4689 /* Windows doesn't send us focus messages when putting up and
4690 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4691 The only indication we get that something happened is receiving
4692 this message afterwards. So this is a good time to reset our
4693 keyboard modifiers' state. */
4700 /* We must ensure menu bar is fully constructed and up to date
4701 before allowing user interaction with it. To achieve this
4702 we send this message to the lisp thread and wait for a
4703 reply (whose value is not actually needed) to indicate that
4704 the menu bar is now ready for use, so we can now return.
4706 To remain responsive in the meantime, we enter a nested message
4707 loop that can process all other messages.
4709 However, we skip all this if the message results from calling
4710 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4711 thread a message because it is blocked on us at this point. We
4712 set menubar_active before calling TrackPopupMenu to indicate
4713 this (there is no possibility of confusion with real menubar
4716 f
= x_window_to_frame (dpyinfo
, hwnd
);
4718 && (f
->output_data
.w32
->menubar_active
4719 /* We can receive this message even in the absence of a
4720 menubar (ie. when the system menu is activated) - in this
4721 case we do NOT want to forward the message, otherwise it
4722 will cause the menubar to suddenly appear when the user
4723 had requested it to be turned off! */
4724 || f
->output_data
.w32
->menubar_widget
== NULL
))
4728 deferred_msg msg_buf
;
4730 /* Detect if message has already been deferred; in this case
4731 we cannot return any sensible value to ignore this. */
4732 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4735 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4738 case WM_EXITMENULOOP
:
4739 f
= x_window_to_frame (dpyinfo
, hwnd
);
4741 /* Free memory used by owner-drawn and help-echo strings. */
4742 w32_free_menu_strings (hwnd
);
4744 /* Indicate that menubar can be modified again. */
4746 f
->output_data
.w32
->menubar_active
= 0;
4750 /* Direct handling of help_echo in menus. Should be safe now
4751 that we generate the help_echo by placing a help event in the
4754 HMENU menu
= (HMENU
) lParam
;
4755 UINT menu_item
= (UINT
) LOWORD (wParam
);
4756 UINT flags
= (UINT
) HIWORD (wParam
);
4758 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
4762 case WM_MEASUREITEM
:
4763 f
= x_window_to_frame (dpyinfo
, hwnd
);
4766 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4768 if (pMis
->CtlType
== ODT_MENU
)
4770 /* Work out dimensions for popup menu titles. */
4771 char * title
= (char *) pMis
->itemData
;
4772 HDC hdc
= GetDC (hwnd
);
4773 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4774 LOGFONT menu_logfont
;
4778 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4779 menu_logfont
.lfWeight
= FW_BOLD
;
4780 menu_font
= CreateFontIndirect (&menu_logfont
);
4781 old_font
= SelectObject (hdc
, menu_font
);
4783 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4786 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4787 pMis
->itemWidth
= size
.cx
;
4788 if (pMis
->itemHeight
< size
.cy
)
4789 pMis
->itemHeight
= size
.cy
;
4792 pMis
->itemWidth
= 0;
4794 SelectObject (hdc
, old_font
);
4795 DeleteObject (menu_font
);
4796 ReleaseDC (hwnd
, hdc
);
4803 f
= x_window_to_frame (dpyinfo
, hwnd
);
4806 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4808 if (pDis
->CtlType
== ODT_MENU
)
4810 /* Draw popup menu title. */
4811 char * title
= (char *) pDis
->itemData
;
4814 HDC hdc
= pDis
->hDC
;
4815 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4816 LOGFONT menu_logfont
;
4819 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4820 menu_logfont
.lfWeight
= FW_BOLD
;
4821 menu_font
= CreateFontIndirect (&menu_logfont
);
4822 old_font
= SelectObject (hdc
, menu_font
);
4824 /* Always draw title as if not selected. */
4827 + GetSystemMetrics (SM_CXMENUCHECK
),
4829 ETO_OPAQUE
, &pDis
->rcItem
,
4830 title
, strlen (title
), NULL
);
4832 SelectObject (hdc
, old_font
);
4833 DeleteObject (menu_font
);
4841 /* Still not right - can't distinguish between clicks in the
4842 client area of the frame from clicks forwarded from the scroll
4843 bars - may have to hook WM_NCHITTEST to remember the mouse
4844 position and then check if it is in the client area ourselves. */
4845 case WM_MOUSEACTIVATE
:
4846 /* Discard the mouse click that activates a frame, allowing the
4847 user to click anywhere without changing point (or worse!).
4848 Don't eat mouse clicks on scrollbars though!! */
4849 if (LOWORD (lParam
) == HTCLIENT
)
4850 return MA_ACTIVATEANDEAT
;
4855 /* No longer tracking mouse. */
4856 track_mouse_window
= NULL
;
4858 case WM_ACTIVATEAPP
:
4860 case WM_WINDOWPOSCHANGED
:
4862 /* Inform lisp thread that a frame might have just been obscured
4863 or exposed, so should recheck visibility of all frames. */
4864 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4868 dpyinfo
->faked_key
= 0;
4870 register_hot_keys (hwnd
);
4873 unregister_hot_keys (hwnd
);
4876 /* Relinquish the system caret. */
4877 if (w32_system_caret_hwnd
)
4880 w32_system_caret_hwnd
= NULL
;
4886 wmsg
.dwModifiers
= w32_get_modifiers ();
4887 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4891 wmsg
.dwModifiers
= w32_get_modifiers ();
4892 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4895 case WM_WINDOWPOSCHANGING
:
4896 /* Don't restrict the sizing of tip frames. */
4897 if (hwnd
== tip_window
)
4901 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
4903 wp
.length
= sizeof (WINDOWPLACEMENT
);
4904 GetWindowPlacement (hwnd
, &wp
);
4906 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
4913 DWORD internal_border
;
4914 DWORD scrollbar_extra
;
4917 wp
.length
= sizeof(wp
);
4918 GetWindowRect (hwnd
, &wr
);
4922 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
4923 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
4924 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
4925 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
4929 memset (&rect
, 0, sizeof (rect
));
4930 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
4931 GetMenu (hwnd
) != NULL
);
4933 /* Force width and height of client area to be exact
4934 multiples of the character cell dimensions. */
4935 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
4936 - 2 * internal_border
- scrollbar_extra
)
4938 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
4939 - 2 * internal_border
)
4944 /* For right/bottom sizing we can just fix the sizes.
4945 However for top/left sizing we will need to fix the X
4946 and Y positions as well. */
4951 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
4952 && (lppos
->flags
& SWP_NOMOVE
) == 0)
4954 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
4961 lppos
->flags
|= SWP_NOMOVE
;
4972 case WM_GETMINMAXINFO
:
4973 /* Hack to correct bug that allows Emacs frames to be resized
4974 below the Minimum Tracking Size. */
4975 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
4976 /* Hack to allow resizing the Emacs frame above the screen size.
4977 Note that Windows 9x limits coordinates to 16-bits. */
4978 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
4979 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
4982 case WM_EMACS_CREATESCROLLBAR
:
4983 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
4984 (struct scroll_bar
*) lParam
);
4986 case WM_EMACS_SHOWWINDOW
:
4987 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4989 case WM_EMACS_SETFOREGROUND
:
4991 HWND foreground_window
;
4992 DWORD foreground_thread
, retval
;
4994 /* On NT 5.0, and apparently Windows 98, it is necessary to
4995 attach to the thread that currently has focus in order to
4996 pull the focus away from it. */
4997 foreground_window
= GetForegroundWindow ();
4998 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4999 if (!foreground_window
5000 || foreground_thread
== GetCurrentThreadId ()
5001 || !AttachThreadInput (GetCurrentThreadId (),
5002 foreground_thread
, TRUE
))
5003 foreground_thread
= 0;
5005 retval
= SetForegroundWindow ((HWND
) wParam
);
5007 /* Detach from the previous foreground thread. */
5008 if (foreground_thread
)
5009 AttachThreadInput (GetCurrentThreadId (),
5010 foreground_thread
, FALSE
);
5015 case WM_EMACS_SETWINDOWPOS
:
5017 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
5018 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
5019 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
5022 case WM_EMACS_DESTROYWINDOW
:
5023 DragAcceptFiles ((HWND
) wParam
, FALSE
);
5024 return DestroyWindow ((HWND
) wParam
);
5026 case WM_EMACS_DESTROY_CARET
:
5027 w32_system_caret_hwnd
= NULL
;
5028 return DestroyCaret ();
5030 case WM_EMACS_TRACK_CARET
:
5031 /* If there is currently no system caret, create one. */
5032 if (w32_system_caret_hwnd
== NULL
)
5034 w32_system_caret_hwnd
= hwnd
;
5035 CreateCaret (hwnd
, NULL
, w32_system_caret_width
,
5036 w32_system_caret_height
);
5038 return SetCaretPos (w32_system_caret_x
, w32_system_caret_y
);
5040 case WM_EMACS_TRACKPOPUPMENU
:
5045 pos
= (POINT
*)lParam
;
5046 flags
= TPM_CENTERALIGN
;
5047 if (button_state
& LMOUSE
)
5048 flags
|= TPM_LEFTBUTTON
;
5049 else if (button_state
& RMOUSE
)
5050 flags
|= TPM_RIGHTBUTTON
;
5052 /* Remember we did a SetCapture on the initial mouse down event,
5053 so for safety, we make sure the capture is cancelled now. */
5057 /* Use menubar_active to indicate that WM_INITMENU is from
5058 TrackPopupMenu below, and should be ignored. */
5059 f
= x_window_to_frame (dpyinfo
, hwnd
);
5061 f
->output_data
.w32
->menubar_active
= 1;
5063 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
5067 /* Eat any mouse messages during popupmenu */
5068 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
5070 /* Get the menu selection, if any */
5071 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
5073 retval
= LOWORD (amsg
.wParam
);
5089 /* Check for messages registered at runtime. */
5090 if (msg
== msh_mousewheel
)
5092 wmsg
.dwModifiers
= w32_get_modifiers ();
5093 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
5098 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
5102 /* The most common default return code for handled messages is 0. */
5107 my_create_window (f
)
5112 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
5114 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
5118 /* Create a tooltip window. Unlike my_create_window, we do not do this
5119 indirectly via the Window thread, as we do not need to process Window
5120 messages for the tooltip. Creating tooltips indirectly also creates
5121 deadlocks when tooltips are created for menu items. */
5123 my_create_tip_window (f
)
5128 rect
.left
= rect
.top
= 0;
5129 rect
.right
= PIXEL_WIDTH (f
);
5130 rect
.bottom
= PIXEL_HEIGHT (f
);
5132 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5133 FRAME_EXTERNAL_MENU_BAR (f
));
5135 tip_window
= FRAME_W32_WINDOW (f
)
5136 = CreateWindow (EMACS_CLASS
,
5138 f
->output_data
.w32
->dwStyle
,
5139 f
->output_data
.w32
->left_pos
,
5140 f
->output_data
.w32
->top_pos
,
5141 rect
.right
- rect
.left
,
5142 rect
.bottom
- rect
.top
,
5143 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
5150 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
5151 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
5152 SetWindowLong (tip_window
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
5153 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
5155 /* Tip frames have no scrollbars. */
5156 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
5158 /* Do this to discard the default setting specified by our parent. */
5159 ShowWindow (tip_window
, SW_HIDE
);
5164 /* Create and set up the w32 window for frame F. */
5167 w32_window (f
, window_prompting
, minibuffer_only
)
5169 long window_prompting
;
5170 int minibuffer_only
;
5174 /* Use the resource name as the top-level window name
5175 for looking up resources. Make a non-Lisp copy
5176 for the window manager, so GC relocation won't bother it.
5178 Elsewhere we specify the window name for the window manager. */
5181 char *str
= (char *) XSTRING (Vx_resource_name
)->data
;
5182 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
5183 strcpy (f
->namebuf
, str
);
5186 my_create_window (f
);
5188 validate_x_resource_name ();
5190 /* x_set_name normally ignores requests to set the name if the
5191 requested name is the same as the current name. This is the one
5192 place where that assumption isn't correct; f->name is set, but
5193 the server hasn't been told. */
5196 int explicit = f
->explicit_name
;
5198 f
->explicit_name
= 0;
5201 x_set_name (f
, name
, explicit);
5206 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
5207 initialize_frame_menubar (f
);
5209 if (FRAME_W32_WINDOW (f
) == 0)
5210 error ("Unable to create window");
5213 /* Handle the icon stuff for this window. Perhaps later we might
5214 want an x_set_icon_position which can be called interactively as
5222 Lisp_Object icon_x
, icon_y
;
5224 /* Set the position of the icon. Note that Windows 95 groups all
5225 icons in the tray. */
5226 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
5227 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
5228 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
5230 CHECK_NUMBER (icon_x
);
5231 CHECK_NUMBER (icon_y
);
5233 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
5234 error ("Both left and top icon corners of icon must be specified");
5238 if (! EQ (icon_x
, Qunbound
))
5239 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
5242 /* Start up iconic or window? */
5243 x_wm_set_window_state
5244 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
5248 x_text_icon (f
, (char *) XSTRING ((!NILP (f
->icon_name
)
5261 XGCValues gc_values
;
5265 /* Create the GC's of this frame.
5266 Note that many default values are used. */
5269 gc_values
.font
= f
->output_data
.w32
->font
;
5271 /* Cursor has cursor-color background, background-color foreground. */
5272 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
5273 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
5274 f
->output_data
.w32
->cursor_gc
5275 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
5276 (GCFont
| GCForeground
| GCBackground
),
5280 f
->output_data
.w32
->white_relief
.gc
= 0;
5281 f
->output_data
.w32
->black_relief
.gc
= 0;
5287 /* Handler for signals raised during x_create_frame and
5288 x_create_top_frame. FRAME is the frame which is partially
5292 unwind_create_frame (frame
)
5295 struct frame
*f
= XFRAME (frame
);
5297 /* If frame is ``official'', nothing to do. */
5298 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
5301 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5304 x_free_frame_resources (f
);
5306 /* Check that reference counts are indeed correct. */
5307 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
5308 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
5317 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
5319 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
5320 Returns an Emacs frame object.
5321 ALIST is an alist of frame parameters.
5322 If the parameters specify that the frame should not have a minibuffer,
5323 and do not specify a specific minibuffer window to use,
5324 then `default-minibuffer-frame' must be a frame whose minibuffer can
5325 be shared by the new frame.
5327 This function is an internal primitive--use `make-frame' instead. */)
5332 Lisp_Object frame
, tem
;
5334 int minibuffer_only
= 0;
5335 long window_prompting
= 0;
5337 int count
= BINDING_STACK_SIZE ();
5338 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5339 Lisp_Object display
;
5340 struct w32_display_info
*dpyinfo
= NULL
;
5346 /* Use this general default value to start with
5347 until we know if this frame has a specified name. */
5348 Vx_resource_name
= Vinvocation_name
;
5350 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
5351 if (EQ (display
, Qunbound
))
5353 dpyinfo
= check_x_display_info (display
);
5355 kb
= dpyinfo
->kboard
;
5357 kb
= &the_only_kboard
;
5360 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5362 && ! EQ (name
, Qunbound
)
5364 error ("Invalid frame name--not a string or nil");
5367 Vx_resource_name
= name
;
5369 /* See if parent window is specified. */
5370 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
5371 if (EQ (parent
, Qunbound
))
5373 if (! NILP (parent
))
5374 CHECK_NUMBER (parent
);
5376 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
5377 /* No need to protect DISPLAY because that's not used after passing
5378 it to make_frame_without_minibuffer. */
5380 GCPRO4 (parms
, parent
, name
, frame
);
5381 tem
= w32_get_arg (parms
, Qminibuffer
, "minibuffer", "Minibuffer",
5383 if (EQ (tem
, Qnone
) || NILP (tem
))
5384 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
5385 else if (EQ (tem
, Qonly
))
5387 f
= make_minibuffer_frame ();
5388 minibuffer_only
= 1;
5390 else if (WINDOWP (tem
))
5391 f
= make_frame_without_minibuffer (tem
, kb
, display
);
5395 XSETFRAME (frame
, f
);
5397 /* Note that Windows does support scroll bars. */
5398 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
5399 /* By default, make scrollbars the system standard width. */
5400 f
->scroll_bar_pixel_width
= GetSystemMetrics (SM_CXVSCROLL
);
5402 f
->output_method
= output_w32
;
5403 f
->output_data
.w32
=
5404 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5405 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5406 FRAME_FONTSET (f
) = -1;
5407 record_unwind_protect (unwind_create_frame
, frame
);
5410 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
5411 if (! STRINGP (f
->icon_name
))
5412 f
->icon_name
= Qnil
;
5414 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
5416 FRAME_KBOARD (f
) = kb
;
5419 /* Specify the parent under which to make this window. */
5423 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
5424 f
->output_data
.w32
->explicit_parent
= 1;
5428 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5429 f
->output_data
.w32
->explicit_parent
= 0;
5432 /* Set the name; the functions to which we pass f expect the name to
5434 if (EQ (name
, Qunbound
) || NILP (name
))
5436 f
->name
= build_string (dpyinfo
->w32_id_name
);
5437 f
->explicit_name
= 0;
5442 f
->explicit_name
= 1;
5443 /* use the frame's title when getting resources for this frame. */
5444 specbind (Qx_resource_name
, name
);
5447 /* Extract the window parameters from the supplied values
5448 that are needed to determine window geometry. */
5452 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
5455 /* First, try whatever font the caller has specified. */
5458 tem
= Fquery_fontset (font
, Qnil
);
5460 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
5462 font
= x_new_font (f
, XSTRING (font
)->data
);
5464 /* Try out a font which we hope has bold and italic variations. */
5465 if (!STRINGP (font
))
5466 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
5467 if (! STRINGP (font
))
5468 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5469 /* If those didn't work, look for something which will at least work. */
5470 if (! STRINGP (font
))
5471 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
5473 if (! STRINGP (font
))
5474 font
= build_string ("Fixedsys");
5476 x_default_parameter (f
, parms
, Qfont
, font
,
5477 "font", "Font", RES_TYPE_STRING
);
5480 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5481 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5482 /* This defaults to 2 in order to match xterm. We recognize either
5483 internalBorderWidth or internalBorder (which is what xterm calls
5485 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5489 value
= w32_get_arg (parms
, Qinternal_border_width
,
5490 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
5491 if (! EQ (value
, Qunbound
))
5492 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5495 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5496 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
5497 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
5498 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qright
,
5499 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5501 /* Also do the stuff which must be set before the window exists. */
5502 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5503 "foreground", "Foreground", RES_TYPE_STRING
);
5504 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5505 "background", "Background", RES_TYPE_STRING
);
5506 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5507 "pointerColor", "Foreground", RES_TYPE_STRING
);
5508 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5509 "cursorColor", "Foreground", RES_TYPE_STRING
);
5510 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5511 "borderColor", "BorderColor", RES_TYPE_STRING
);
5512 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
5513 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5514 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
5515 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
5516 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
5517 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
5518 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
5519 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
5522 /* Init faces before x_default_parameter is called for scroll-bar
5523 parameters because that function calls x_set_scroll_bar_width,
5524 which calls change_frame_size, which calls Fset_window_buffer,
5525 which runs hooks, which call Fvertical_motion. At the end, we
5526 end up in init_iterator with a null face cache, which should not
5528 init_frame_faces (f
);
5530 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
5531 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
5532 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (0),
5533 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
5534 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
5535 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5536 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
5537 "title", "Title", RES_TYPE_STRING
);
5539 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5540 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5542 /* Add the tool-bar height to the initial frame height so that the
5543 user gets a text display area of the size he specified with -g or
5544 via .Xdefaults. Later changes of the tool-bar height don't
5545 change the frame size. This is done so that users can create
5546 tall Emacs frames without having to guess how tall the tool-bar
5548 if (FRAME_TOOL_BAR_LINES (f
))
5550 int margin
, relief
, bar_height
;
5552 relief
= (tool_bar_button_relief
>= 0
5553 ? tool_bar_button_relief
5554 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
5556 if (INTEGERP (Vtool_bar_button_margin
)
5557 && XINT (Vtool_bar_button_margin
) > 0)
5558 margin
= XFASTINT (Vtool_bar_button_margin
);
5559 else if (CONSP (Vtool_bar_button_margin
)
5560 && INTEGERP (XCDR (Vtool_bar_button_margin
))
5561 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
5562 margin
= XFASTINT (XCDR (Vtool_bar_button_margin
));
5566 bar_height
= DEFAULT_TOOL_BAR_IMAGE_HEIGHT
+ 2 * margin
+ 2 * relief
;
5567 f
->height
+= (bar_height
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
5570 window_prompting
= x_figure_window_size (f
, parms
);
5572 if (window_prompting
& XNegative
)
5574 if (window_prompting
& YNegative
)
5575 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
5577 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
5581 if (window_prompting
& YNegative
)
5582 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
5584 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
5587 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
5589 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5590 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5592 w32_window (f
, window_prompting
, minibuffer_only
);
5597 /* Now consider the frame official. */
5598 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5599 Vframe_list
= Fcons (frame
, Vframe_list
);
5601 /* We need to do this after creating the window, so that the
5602 icon-creation functions can say whose icon they're describing. */
5603 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
5604 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5606 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5607 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5608 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5609 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5610 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5611 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5612 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
5613 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5615 /* Dimensions, especially f->height, must be done via change_frame_size.
5616 Change will not be effected unless different from the current
5622 SET_FRAME_WIDTH (f
, 0);
5623 change_frame_size (f
, height
, width
, 1, 0, 0);
5625 /* Tell the server what size and position, etc, we want, and how
5626 badly we want them. This should be done after we have the menu
5627 bar so that its size can be taken into account. */
5629 x_wm_set_size_hint (f
, window_prompting
, 0);
5632 /* Avoid a bug that causes the new frame to never become visible if
5633 an echo area message is displayed during the following call1. */
5634 specbind(Qredisplay_dont_pause
, Qt
);
5636 /* Set up faces after all frame parameters are known. This call
5637 also merges in face attributes specified for new frames. If we
5638 don't do this, the `menu' face for instance won't have the right
5639 colors, and the menu bar won't appear in the specified colors for
5641 call1 (Qface_set_after_frame_default
, frame
);
5643 /* Make the window appear on the frame and enable display, unless
5644 the caller says not to. However, with explicit parent, Emacs
5645 cannot control visibility, so don't try. */
5646 if (! f
->output_data
.w32
->explicit_parent
)
5648 Lisp_Object visibility
;
5650 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5651 if (EQ (visibility
, Qunbound
))
5654 if (EQ (visibility
, Qicon
))
5655 x_iconify_frame (f
);
5656 else if (! NILP (visibility
))
5657 x_make_frame_visible (f
);
5659 /* Must have been Qnil. */
5664 /* Make sure windows on this frame appear in calls to next-window
5665 and similar functions. */
5666 Vwindow_list
= Qnil
;
5668 return unbind_to (count
, frame
);
5671 /* FRAME is used only to get a handle on the X display. We don't pass the
5672 display info directly because we're called from frame.c, which doesn't
5673 know about that structure. */
5675 x_get_focus_frame (frame
)
5676 struct frame
*frame
;
5678 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
5680 if (! dpyinfo
->w32_focus_frame
)
5683 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5687 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
5688 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
5692 x_focus_on_frame (check_x_frame (frame
));
5697 /* Return the charset portion of a font name. */
5698 char * xlfd_charset_of_font (char * fontname
)
5700 char *charset
, *encoding
;
5702 encoding
= strrchr(fontname
, '-');
5703 if (!encoding
|| encoding
== fontname
)
5706 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
5707 if (*charset
== '-')
5710 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
5716 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
5717 int size
, char* filename
);
5718 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
5719 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
5721 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
5723 static struct font_info
*
5724 w32_load_system_font (f
,fontname
,size
)
5729 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5730 Lisp_Object font_names
;
5732 /* Get a list of all the fonts that match this name. Once we
5733 have a list of matching fonts, we compare them against the fonts
5734 we already have loaded by comparing names. */
5735 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
5737 if (!NILP (font_names
))
5742 /* First check if any are already loaded, as that is cheaper
5743 than loading another one. */
5744 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5745 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
5746 if (dpyinfo
->font_table
[i
].name
5747 && (!strcmp (dpyinfo
->font_table
[i
].name
,
5748 XSTRING (XCAR (tail
))->data
)
5749 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
5750 XSTRING (XCAR (tail
))->data
)))
5751 return (dpyinfo
->font_table
+ i
);
5753 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
5755 else if (w32_strict_fontnames
)
5757 /* If EnumFontFamiliesEx was available, we got a full list of
5758 fonts back so stop now to avoid the possibility of loading a
5759 random font. If we had to fall back to EnumFontFamilies, the
5760 list is incomplete, so continue whether the font we want was
5762 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5763 FARPROC enum_font_families_ex
5764 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
5765 if (enum_font_families_ex
)
5769 /* Load the font and add it to the table. */
5771 char *full_name
, *encoding
, *charset
;
5773 struct font_info
*fontp
;
5779 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
5782 if (!*lf
.lfFaceName
)
5783 /* If no name was specified for the font, we get a random font
5784 from CreateFontIndirect - this is not particularly
5785 desirable, especially since CreateFontIndirect does not
5786 fill out the missing name in lf, so we never know what we
5790 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
5791 bzero (font
, sizeof (*font
));
5793 /* Set bdf to NULL to indicate that this is a Windows font. */
5798 font
->hfont
= CreateFontIndirect (&lf
);
5800 if (font
->hfont
== NULL
)
5809 codepage
= w32_codepage_for_font (fontname
);
5811 hdc
= GetDC (dpyinfo
->root_window
);
5812 oldobj
= SelectObject (hdc
, font
->hfont
);
5814 ok
= GetTextMetrics (hdc
, &font
->tm
);
5815 if (codepage
== CP_UNICODE
)
5816 font
->double_byte_p
= 1;
5819 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
5820 don't report themselves as double byte fonts, when
5821 patently they are. So instead of trusting
5822 GetFontLanguageInfo, we check the properties of the
5823 codepage directly, since that is ultimately what we are
5824 working from anyway. */
5825 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
5827 GetCPInfo (codepage
, &cpi
);
5828 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
5831 SelectObject (hdc
, oldobj
);
5832 ReleaseDC (dpyinfo
->root_window
, hdc
);
5833 /* Fill out details in lf according to the font that was
5835 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
5836 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
5837 lf
.lfWeight
= font
->tm
.tmWeight
;
5838 lf
.lfItalic
= font
->tm
.tmItalic
;
5839 lf
.lfCharSet
= font
->tm
.tmCharSet
;
5840 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
5841 ? VARIABLE_PITCH
: FIXED_PITCH
);
5842 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
5843 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
5845 w32_cache_char_metrics (font
);
5852 w32_unload_font (dpyinfo
, font
);
5856 /* Find a free slot in the font table. */
5857 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
5858 if (dpyinfo
->font_table
[i
].name
== NULL
)
5861 /* If no free slot found, maybe enlarge the font table. */
5862 if (i
== dpyinfo
->n_fonts
5863 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
5866 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
5867 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
5869 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
5872 fontp
= dpyinfo
->font_table
+ i
;
5873 if (i
== dpyinfo
->n_fonts
)
5876 /* Now fill in the slots of *FONTP. */
5879 fontp
->font_idx
= i
;
5880 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
5881 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
5883 charset
= xlfd_charset_of_font (fontname
);
5885 /* Cache the W32 codepage for a font. This makes w32_encode_char
5886 (called for every glyph during redisplay) much faster. */
5887 fontp
->codepage
= codepage
;
5889 /* Work out the font's full name. */
5890 full_name
= (char *)xmalloc (100);
5891 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
5892 fontp
->full_name
= full_name
;
5895 /* If all else fails - just use the name we used to load it. */
5897 fontp
->full_name
= fontp
->name
;
5900 fontp
->size
= FONT_WIDTH (font
);
5901 fontp
->height
= FONT_HEIGHT (font
);
5903 /* The slot `encoding' specifies how to map a character
5904 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
5905 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
5906 (0:0x20..0x7F, 1:0xA0..0xFF,
5907 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
5908 2:0xA020..0xFF7F). For the moment, we don't know which charset
5909 uses this font. So, we set information in fontp->encoding[1]
5910 which is never used by any charset. If mapping can't be
5911 decided, set FONT_ENCODING_NOT_DECIDED. */
5913 /* SJIS fonts need to be set to type 4, all others seem to work as
5914 type FONT_ENCODING_NOT_DECIDED. */
5915 encoding
= strrchr (fontp
->name
, '-');
5916 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
5917 fontp
->encoding
[1] = 4;
5919 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
5921 /* The following three values are set to 0 under W32, which is
5922 what they get set to if XGetFontProperty fails under X. */
5923 fontp
->baseline_offset
= 0;
5924 fontp
->relative_compose
= 0;
5925 fontp
->default_ascent
= 0;
5927 /* Set global flag fonts_changed_p to non-zero if the font loaded
5928 has a character with a smaller width than any other character
5929 before, or if the font loaded has a smalle>r height than any
5930 other font loaded before. If this happens, it will make a
5931 glyph matrix reallocation necessary. */
5932 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
5938 /* Load font named FONTNAME of size SIZE for frame F, and return a
5939 pointer to the structure font_info while allocating it dynamically.
5940 If loading fails, return NULL. */
5942 w32_load_font (f
,fontname
,size
)
5947 Lisp_Object bdf_fonts
;
5948 struct font_info
*retval
= NULL
;
5950 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
5952 while (!retval
&& CONSP (bdf_fonts
))
5954 char *bdf_name
, *bdf_file
;
5955 Lisp_Object bdf_pair
;
5957 bdf_name
= XSTRING (XCAR (bdf_fonts
))->data
;
5958 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
5959 bdf_file
= XSTRING (XCDR (bdf_pair
))->data
;
5961 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
5963 bdf_fonts
= XCDR (bdf_fonts
);
5969 return w32_load_system_font(f
, fontname
, size
);
5974 w32_unload_font (dpyinfo
, font
)
5975 struct w32_display_info
*dpyinfo
;
5980 if (font
->per_char
) xfree (font
->per_char
);
5981 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
5983 if (font
->hfont
) DeleteObject(font
->hfont
);
5988 /* The font conversion stuff between x and w32 */
5990 /* X font string is as follows (from faces.el)
5994 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
5995 * (weight\? "\\([^-]*\\)") ; 1
5996 * (slant "\\([ior]\\)") ; 2
5997 * (slant\? "\\([^-]?\\)") ; 2
5998 * (swidth "\\([^-]*\\)") ; 3
5999 * (adstyle "[^-]*") ; 4
6000 * (pixelsize "[0-9]+")
6001 * (pointsize "[0-9][0-9]+")
6002 * (resx "[0-9][0-9]+")
6003 * (resy "[0-9][0-9]+")
6004 * (spacing "[cmp?*]")
6005 * (avgwidth "[0-9]+")
6006 * (registry "[^-]+")
6007 * (encoding "[^-]+")
6012 x_to_w32_weight (lpw
)
6015 if (!lpw
) return (FW_DONTCARE
);
6017 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
6018 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
6019 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
6020 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
6021 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
6022 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
6023 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
6024 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
6025 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
6026 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
6033 w32_to_x_weight (fnweight
)
6036 if (fnweight
>= FW_HEAVY
) return "heavy";
6037 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
6038 if (fnweight
>= FW_BOLD
) return "bold";
6039 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
6040 if (fnweight
>= FW_MEDIUM
) return "medium";
6041 if (fnweight
>= FW_NORMAL
) return "normal";
6042 if (fnweight
>= FW_LIGHT
) return "light";
6043 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
6044 if (fnweight
>= FW_THIN
) return "thin";
6050 x_to_w32_charset (lpcs
)
6053 Lisp_Object this_entry
, w32_charset
;
6055 int len
= strlen (lpcs
);
6057 /* Support "*-#nnn" format for unknown charsets. */
6058 if (strncmp (lpcs
, "*-#", 3) == 0)
6059 return atoi (lpcs
+ 3);
6061 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
6062 charset
= alloca (len
+ 1);
6063 strcpy (charset
, lpcs
);
6064 lpcs
= strchr (charset
, '*');
6068 /* Look through w32-charset-info-alist for the character set.
6069 Format of each entry is
6070 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
6072 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6074 if (NILP(this_entry
))
6076 /* At startup, we want iso8859-1 fonts to come up properly. */
6077 if (stricmp(charset
, "iso8859-1") == 0)
6078 return ANSI_CHARSET
;
6080 return DEFAULT_CHARSET
;
6083 w32_charset
= Fcar (Fcdr (this_entry
));
6085 /* Translate Lisp symbol to number. */
6086 if (w32_charset
== Qw32_charset_ansi
)
6087 return ANSI_CHARSET
;
6088 if (w32_charset
== Qw32_charset_symbol
)
6089 return SYMBOL_CHARSET
;
6090 if (w32_charset
== Qw32_charset_shiftjis
)
6091 return SHIFTJIS_CHARSET
;
6092 if (w32_charset
== Qw32_charset_hangeul
)
6093 return HANGEUL_CHARSET
;
6094 if (w32_charset
== Qw32_charset_chinesebig5
)
6095 return CHINESEBIG5_CHARSET
;
6096 if (w32_charset
== Qw32_charset_gb2312
)
6097 return GB2312_CHARSET
;
6098 if (w32_charset
== Qw32_charset_oem
)
6100 #ifdef JOHAB_CHARSET
6101 if (w32_charset
== Qw32_charset_johab
)
6102 return JOHAB_CHARSET
;
6103 if (w32_charset
== Qw32_charset_easteurope
)
6104 return EASTEUROPE_CHARSET
;
6105 if (w32_charset
== Qw32_charset_turkish
)
6106 return TURKISH_CHARSET
;
6107 if (w32_charset
== Qw32_charset_baltic
)
6108 return BALTIC_CHARSET
;
6109 if (w32_charset
== Qw32_charset_russian
)
6110 return RUSSIAN_CHARSET
;
6111 if (w32_charset
== Qw32_charset_arabic
)
6112 return ARABIC_CHARSET
;
6113 if (w32_charset
== Qw32_charset_greek
)
6114 return GREEK_CHARSET
;
6115 if (w32_charset
== Qw32_charset_hebrew
)
6116 return HEBREW_CHARSET
;
6117 if (w32_charset
== Qw32_charset_vietnamese
)
6118 return VIETNAMESE_CHARSET
;
6119 if (w32_charset
== Qw32_charset_thai
)
6120 return THAI_CHARSET
;
6121 if (w32_charset
== Qw32_charset_mac
)
6123 #endif /* JOHAB_CHARSET */
6124 #ifdef UNICODE_CHARSET
6125 if (w32_charset
== Qw32_charset_unicode
)
6126 return UNICODE_CHARSET
;
6129 return DEFAULT_CHARSET
;
6134 w32_to_x_charset (fncharset
)
6137 static char buf
[32];
6138 Lisp_Object charset_type
;
6143 /* Handle startup case of w32-charset-info-alist not
6144 being set up yet. */
6145 if (NILP(Vw32_charset_info_alist
))
6147 charset_type
= Qw32_charset_ansi
;
6149 case DEFAULT_CHARSET
:
6150 charset_type
= Qw32_charset_default
;
6152 case SYMBOL_CHARSET
:
6153 charset_type
= Qw32_charset_symbol
;
6155 case SHIFTJIS_CHARSET
:
6156 charset_type
= Qw32_charset_shiftjis
;
6158 case HANGEUL_CHARSET
:
6159 charset_type
= Qw32_charset_hangeul
;
6161 case GB2312_CHARSET
:
6162 charset_type
= Qw32_charset_gb2312
;
6164 case CHINESEBIG5_CHARSET
:
6165 charset_type
= Qw32_charset_chinesebig5
;
6168 charset_type
= Qw32_charset_oem
;
6171 /* More recent versions of Windows (95 and NT4.0) define more
6173 #ifdef EASTEUROPE_CHARSET
6174 case EASTEUROPE_CHARSET
:
6175 charset_type
= Qw32_charset_easteurope
;
6177 case TURKISH_CHARSET
:
6178 charset_type
= Qw32_charset_turkish
;
6180 case BALTIC_CHARSET
:
6181 charset_type
= Qw32_charset_baltic
;
6183 case RUSSIAN_CHARSET
:
6184 charset_type
= Qw32_charset_russian
;
6186 case ARABIC_CHARSET
:
6187 charset_type
= Qw32_charset_arabic
;
6190 charset_type
= Qw32_charset_greek
;
6192 case HEBREW_CHARSET
:
6193 charset_type
= Qw32_charset_hebrew
;
6195 case VIETNAMESE_CHARSET
:
6196 charset_type
= Qw32_charset_vietnamese
;
6199 charset_type
= Qw32_charset_thai
;
6202 charset_type
= Qw32_charset_mac
;
6205 charset_type
= Qw32_charset_johab
;
6209 #ifdef UNICODE_CHARSET
6210 case UNICODE_CHARSET
:
6211 charset_type
= Qw32_charset_unicode
;
6215 /* Encode numerical value of unknown charset. */
6216 sprintf (buf
, "*-#%u", fncharset
);
6222 char * best_match
= NULL
;
6224 /* Look through w32-charset-info-alist for the character set.
6225 Prefer ISO codepages, and prefer lower numbers in the ISO
6226 range. Only return charsets for codepages which are installed.
6228 Format of each entry is
6229 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
6231 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6234 Lisp_Object w32_charset
;
6235 Lisp_Object codepage
;
6237 Lisp_Object this_entry
= XCAR (rest
);
6239 /* Skip invalid entries in alist. */
6240 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
6241 || !CONSP (XCDR (this_entry
))
6242 || !SYMBOLP (XCAR (XCDR (this_entry
))))
6245 x_charset
= XSTRING (XCAR (this_entry
))->data
;
6246 w32_charset
= XCAR (XCDR (this_entry
));
6247 codepage
= XCDR (XCDR (this_entry
));
6249 /* Look for Same charset and a valid codepage (or non-int
6250 which means ignore). */
6251 if (w32_charset
== charset_type
6252 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
6253 || IsValidCodePage (XINT (codepage
))))
6255 /* If we don't have a match already, then this is the
6258 best_match
= x_charset
;
6259 /* If this is an ISO codepage, and the best so far isn't,
6260 then this is better. */
6261 else if (strnicmp (best_match
, "iso", 3) != 0
6262 && strnicmp (x_charset
, "iso", 3) == 0)
6263 best_match
= x_charset
;
6264 /* If both are ISO8859 codepages, choose the one with the
6265 lowest number in the encoding field. */
6266 else if (strnicmp (best_match
, "iso8859-", 8) == 0
6267 && strnicmp (x_charset
, "iso8859-", 8) == 0)
6269 int best_enc
= atoi (best_match
+ 8);
6270 int this_enc
= atoi (x_charset
+ 8);
6271 if (this_enc
> 0 && this_enc
< best_enc
)
6272 best_match
= x_charset
;
6277 /* If no match, encode the numeric value. */
6280 sprintf (buf
, "*-#%u", fncharset
);
6284 strncpy(buf
, best_match
, 31);
6291 /* Return all the X charsets that map to a font. */
6293 w32_to_all_x_charsets (fncharset
)
6296 static char buf
[32];
6297 Lisp_Object charset_type
;
6298 Lisp_Object retval
= Qnil
;
6303 /* Handle startup case of w32-charset-info-alist not
6304 being set up yet. */
6305 if (NILP(Vw32_charset_info_alist
))
6307 charset_type
= Qw32_charset_ansi
;
6309 case DEFAULT_CHARSET
:
6310 charset_type
= Qw32_charset_default
;
6312 case SYMBOL_CHARSET
:
6313 charset_type
= Qw32_charset_symbol
;
6315 case SHIFTJIS_CHARSET
:
6316 charset_type
= Qw32_charset_shiftjis
;
6318 case HANGEUL_CHARSET
:
6319 charset_type
= Qw32_charset_hangeul
;
6321 case GB2312_CHARSET
:
6322 charset_type
= Qw32_charset_gb2312
;
6324 case CHINESEBIG5_CHARSET
:
6325 charset_type
= Qw32_charset_chinesebig5
;
6328 charset_type
= Qw32_charset_oem
;
6331 /* More recent versions of Windows (95 and NT4.0) define more
6333 #ifdef EASTEUROPE_CHARSET
6334 case EASTEUROPE_CHARSET
:
6335 charset_type
= Qw32_charset_easteurope
;
6337 case TURKISH_CHARSET
:
6338 charset_type
= Qw32_charset_turkish
;
6340 case BALTIC_CHARSET
:
6341 charset_type
= Qw32_charset_baltic
;
6343 case RUSSIAN_CHARSET
:
6344 charset_type
= Qw32_charset_russian
;
6346 case ARABIC_CHARSET
:
6347 charset_type
= Qw32_charset_arabic
;
6350 charset_type
= Qw32_charset_greek
;
6352 case HEBREW_CHARSET
:
6353 charset_type
= Qw32_charset_hebrew
;
6355 case VIETNAMESE_CHARSET
:
6356 charset_type
= Qw32_charset_vietnamese
;
6359 charset_type
= Qw32_charset_thai
;
6362 charset_type
= Qw32_charset_mac
;
6365 charset_type
= Qw32_charset_johab
;
6369 #ifdef UNICODE_CHARSET
6370 case UNICODE_CHARSET
:
6371 charset_type
= Qw32_charset_unicode
;
6375 /* Encode numerical value of unknown charset. */
6376 sprintf (buf
, "*-#%u", fncharset
);
6377 return Fcons (build_string (buf
), Qnil
);
6382 /* Look through w32-charset-info-alist for the character set.
6383 Only return charsets for codepages which are installed.
6385 Format of each entry in Vw32_charset_info_alist is
6386 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
6388 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6390 Lisp_Object x_charset
;
6391 Lisp_Object w32_charset
;
6392 Lisp_Object codepage
;
6394 Lisp_Object this_entry
= XCAR (rest
);
6396 /* Skip invalid entries in alist. */
6397 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
6398 || !CONSP (XCDR (this_entry
))
6399 || !SYMBOLP (XCAR (XCDR (this_entry
))))
6402 x_charset
= XCAR (this_entry
);
6403 w32_charset
= XCAR (XCDR (this_entry
));
6404 codepage
= XCDR (XCDR (this_entry
));
6406 /* Look for Same charset and a valid codepage (or non-int
6407 which means ignore). */
6408 if (w32_charset
== charset_type
6409 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
6410 || IsValidCodePage (XINT (codepage
))))
6412 retval
= Fcons (x_charset
, retval
);
6416 /* If no match, encode the numeric value. */
6419 sprintf (buf
, "*-#%u", fncharset
);
6420 return Fcons (build_string (buf
), Qnil
);
6427 /* Get the Windows codepage corresponding to the specified font. The
6428 charset info in the font name is used to look up
6429 w32-charset-to-codepage-alist. */
6431 w32_codepage_for_font (char *fontname
)
6433 Lisp_Object codepage
, entry
;
6434 char *charset_str
, *charset
, *end
;
6436 if (NILP (Vw32_charset_info_alist
))
6439 /* Extract charset part of font string. */
6440 charset
= xlfd_charset_of_font (fontname
);
6445 charset_str
= (char *) alloca (strlen (charset
) + 1);
6446 strcpy (charset_str
, charset
);
6449 /* Remove leading "*-". */
6450 if (strncmp ("*-", charset_str
, 2) == 0)
6451 charset
= charset_str
+ 2;
6454 charset
= charset_str
;
6456 /* Stop match at wildcard (including preceding '-'). */
6457 if (end
= strchr (charset
, '*'))
6459 if (end
> charset
&& *(end
-1) == '-')
6464 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6468 codepage
= Fcdr (Fcdr (entry
));
6470 if (NILP (codepage
))
6472 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
6474 else if (INTEGERP (codepage
))
6475 return XINT (codepage
);
6482 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
6483 LOGFONT
* lplogfont
;
6486 char * specific_charset
;
6490 char height_pixels
[8];
6492 char width_pixels
[8];
6493 char *fontname_dash
;
6494 int display_resy
= one_w32_display_info
.resy
;
6495 int display_resx
= one_w32_display_info
.resx
;
6497 struct coding_system coding
;
6499 if (!lpxstr
) abort ();
6504 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
6505 fonttype
= "raster";
6506 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
6507 fonttype
= "outline";
6509 fonttype
= "unknown";
6511 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
6513 coding
.src_multibyte
= 0;
6514 coding
.dst_multibyte
= 1;
6515 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6516 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
6518 fontname
= alloca(sizeof(*fontname
) * bufsz
);
6519 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
6520 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
6521 *(fontname
+ coding
.produced
) = '\0';
6523 /* Replace dashes with underscores so the dashes are not
6525 fontname_dash
= fontname
;
6526 while (fontname_dash
= strchr (fontname_dash
, '-'))
6527 *fontname_dash
= '_';
6529 if (lplogfont
->lfHeight
)
6531 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
6532 sprintf (height_dpi
, "%u",
6533 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
6537 strcpy (height_pixels
, "*");
6538 strcpy (height_dpi
, "*");
6540 if (lplogfont
->lfWidth
)
6541 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
6543 strcpy (width_pixels
, "*");
6545 _snprintf (lpxstr
, len
- 1,
6546 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
6547 fonttype
, /* foundry */
6548 fontname
, /* family */
6549 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
6550 lplogfont
->lfItalic
?'i':'r', /* slant */
6552 /* add style name */
6553 height_pixels
, /* pixel size */
6554 height_dpi
, /* point size */
6555 display_resx
, /* resx */
6556 display_resy
, /* resy */
6557 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
6558 ? 'p' : 'c', /* spacing */
6559 width_pixels
, /* avg width */
6560 specific_charset
? specific_charset
6561 : w32_to_x_charset (lplogfont
->lfCharSet
)
6562 /* charset registry and encoding */
6565 lpxstr
[len
- 1] = 0; /* just to be sure */
6570 x_to_w32_font (lpxstr
, lplogfont
)
6572 LOGFONT
* lplogfont
;
6574 struct coding_system coding
;
6576 if (!lplogfont
) return (FALSE
);
6578 memset (lplogfont
, 0, sizeof (*lplogfont
));
6580 /* Set default value for each field. */
6582 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
6583 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
6584 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
6586 /* go for maximum quality */
6587 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
6588 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
6589 lplogfont
->lfQuality
= PROOF_QUALITY
;
6592 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
6593 lplogfont
->lfWeight
= FW_DONTCARE
;
6594 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
6599 /* Provide a simple escape mechanism for specifying Windows font names
6600 * directly -- if font spec does not beginning with '-', assume this
6602 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
6608 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
6609 width
[10], resy
[10], remainder
[50];
6611 int dpi
= one_w32_display_info
.resy
;
6613 fields
= sscanf (lpxstr
,
6614 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
6615 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
6619 /* In the general case when wildcards cover more than one field,
6620 we don't know which field is which, so don't fill any in.
6621 However, we need to cope with this particular form, which is
6622 generated by font_list_1 (invoked by try_font_list):
6623 "-raster-6x10-*-gb2312*-*"
6624 and make sure to correctly parse the charset field. */
6627 fields
= sscanf (lpxstr
,
6628 "-%*[^-]-%49[^-]-*-%49s",
6631 else if (fields
< 9)
6637 if (fields
> 0 && name
[0] != '*')
6643 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
6644 coding
.src_multibyte
= 1;
6645 coding
.dst_multibyte
= 1;
6646 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
6647 buf
= (unsigned char *) alloca (bufsize
);
6648 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6649 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
6650 if (coding
.produced
>= LF_FACESIZE
)
6651 coding
.produced
= LF_FACESIZE
- 1;
6652 buf
[coding
.produced
] = 0;
6653 strcpy (lplogfont
->lfFaceName
, buf
);
6657 lplogfont
->lfFaceName
[0] = '\0';
6662 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6666 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
6670 if (fields
> 0 && pixels
[0] != '*')
6671 lplogfont
->lfHeight
= atoi (pixels
);
6675 if (fields
> 0 && resy
[0] != '*')
6678 if (tem
> 0) dpi
= tem
;
6681 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
6682 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
6685 lplogfont
->lfPitchAndFamily
=
6686 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
6690 if (fields
> 0 && width
[0] != '*')
6691 lplogfont
->lfWidth
= atoi (width
) / 10;
6695 /* Strip the trailing '-' if present. (it shouldn't be, as it
6696 fails the test against xlfd-tight-regexp in fontset.el). */
6698 int len
= strlen (remainder
);
6699 if (len
> 0 && remainder
[len
-1] == '-')
6700 remainder
[len
-1] = 0;
6702 encoding
= remainder
;
6704 if (strncmp (encoding
, "*-", 2) == 0)
6707 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
6712 char name
[100], height
[10], width
[10], weight
[20];
6714 fields
= sscanf (lpxstr
,
6715 "%99[^:]:%9[^:]:%9[^:]:%19s",
6716 name
, height
, width
, weight
);
6718 if (fields
== EOF
) return (FALSE
);
6722 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
6723 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
6727 lplogfont
->lfFaceName
[0] = 0;
6733 lplogfont
->lfHeight
= atoi (height
);
6738 lplogfont
->lfWidth
= atoi (width
);
6742 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6745 /* This makes TrueType fonts work better. */
6746 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
6751 /* Strip the pixel height and point height from the given xlfd, and
6752 return the pixel height. If no pixel height is specified, calculate
6753 one from the point height, or if that isn't defined either, return
6754 0 (which usually signifies a scalable font).
6757 xlfd_strip_height (char *fontname
)
6759 int pixel_height
, field_number
;
6760 char *read_from
, *write_to
;
6764 pixel_height
= field_number
= 0;
6767 /* Look for height fields. */
6768 for (read_from
= fontname
; *read_from
; read_from
++)
6770 if (*read_from
== '-')
6773 if (field_number
== 7) /* Pixel height. */
6776 write_to
= read_from
;
6778 /* Find end of field. */
6779 for (;*read_from
&& *read_from
!= '-'; read_from
++)
6782 /* Split the fontname at end of field. */
6788 pixel_height
= atoi (write_to
);
6789 /* Blank out field. */
6790 if (read_from
> write_to
)
6795 /* If the pixel height field is at the end (partial xlfd),
6798 return pixel_height
;
6800 /* If we got a pixel height, the point height can be
6801 ignored. Just blank it out and break now. */
6804 /* Find end of point size field. */
6805 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6811 /* Blank out the point size field. */
6812 if (read_from
> write_to
)
6818 return pixel_height
;
6822 /* If the point height is already blank, break now. */
6823 if (*read_from
== '-')
6829 else if (field_number
== 8)
6831 /* If we didn't get a pixel height, try to get the point
6832 height and convert that. */
6834 char *point_size_start
= read_from
++;
6836 /* Find end of field. */
6837 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6846 point_size
= atoi (point_size_start
);
6848 /* Convert to pixel height. */
6849 pixel_height
= point_size
6850 * one_w32_display_info
.height_in
/ 720;
6852 /* Blank out this field and break. */
6860 /* Shift the rest of the font spec into place. */
6861 if (write_to
&& read_from
> write_to
)
6863 for (; *read_from
; read_from
++, write_to
++)
6864 *write_to
= *read_from
;
6868 return pixel_height
;
6871 /* Assume parameter 1 is fully qualified, no wildcards. */
6873 w32_font_match (fontname
, pattern
)
6877 char *regex
= alloca (strlen (pattern
) * 2 + 3);
6878 char *font_name_copy
= alloca (strlen (fontname
) + 1);
6881 /* Copy fontname so we can modify it during comparison. */
6882 strcpy (font_name_copy
, fontname
);
6887 /* Turn pattern into a regexp and do a regexp match. */
6888 for (; *pattern
; pattern
++)
6890 if (*pattern
== '?')
6892 else if (*pattern
== '*')
6903 /* Strip out font heights and compare them seperately, since
6904 rounding error can cause mismatches. This also allows a
6905 comparison between a font that declares only a pixel height and a
6906 pattern that declares the point height.
6909 int font_height
, pattern_height
;
6911 font_height
= xlfd_strip_height (font_name_copy
);
6912 pattern_height
= xlfd_strip_height (regex
);
6914 /* Compare now, and don't bother doing expensive regexp matching
6915 if the heights differ. */
6916 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
6920 return (fast_c_string_match_ignore_case (build_string (regex
),
6921 font_name_copy
) >= 0);
6924 /* Callback functions, and a structure holding info they need, for
6925 listing system fonts on W32. We need one set of functions to do the
6926 job properly, but these don't work on NT 3.51 and earlier, so we
6927 have a second set which don't handle character sets properly to
6930 In both cases, there are two passes made. The first pass gets one
6931 font from each family, the second pass lists all the fonts from
6934 typedef struct enumfont_t
6939 XFontStruct
*size_ref
;
6940 Lisp_Object
*pattern
;
6947 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
6951 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
6953 NEWTEXTMETRIC
* lptm
;
6957 /* Ignore struck out and underlined versions of fonts. */
6958 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
6961 /* Only return fonts with names starting with @ if they were
6962 explicitly specified, since Microsoft uses an initial @ to
6963 denote fonts for vertical writing, without providing a more
6964 convenient way of identifying them. */
6965 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
6966 && lpef
->logfont
.lfFaceName
[0] != '@')
6969 /* Check that the character set matches if it was specified */
6970 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6971 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6976 Lisp_Object width
= Qnil
;
6977 Lisp_Object charset_list
= Qnil
;
6978 char *charset
= NULL
;
6980 /* Truetype fonts do not report their true metrics until loaded */
6981 if (FontType
!= RASTER_FONTTYPE
)
6983 if (!NILP (*(lpef
->pattern
)))
6985 /* Scalable fonts are as big as you want them to be. */
6986 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6987 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6988 width
= make_number (lpef
->logfont
.lfWidth
);
6992 lplf
->elfLogFont
.lfHeight
= 0;
6993 lplf
->elfLogFont
.lfWidth
= 0;
6997 /* Make sure the height used here is the same as everywhere
6998 else (ie character height, not cell height). */
6999 if (lplf
->elfLogFont
.lfHeight
> 0)
7001 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
7002 if (FontType
== RASTER_FONTTYPE
)
7003 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
7005 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
7008 if (!NILP (*(lpef
->pattern
)))
7010 charset
= xlfd_charset_of_font (XSTRING(*(lpef
->pattern
))->data
);
7012 /* Ensure that charset is valid for this font.
7013 Continue if invalid in case charset contains a wildcard. */
7015 && (x_to_w32_charset (charset
) != lplf
->elfLogFont
.lfCharSet
))
7020 charset_list
= Fcons (build_string (charset
), Qnil
);
7022 charset_list
= w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
);
7024 /* Loop through the charsets. */
7025 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
7027 Lisp_Object this_charset
= Fcar (charset_list
);
7028 charset
= XSTRING (this_charset
)->data
;
7030 /* List bold and italic variations if w32-enable-synthesized-fonts
7031 is non-nil and this is a plain font. */
7032 if (w32_enable_synthesized_fonts
7033 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
7034 && lplf
->elfLogFont
.lfItalic
== FALSE
)
7036 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7039 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
7040 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7043 lplf
->elfLogFont
.lfItalic
= TRUE
;
7044 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7047 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
7048 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7052 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7061 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
7064 char * match_charset
;
7069 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
7072 if (NILP (*(lpef
->pattern
))
7073 || w32_font_match (buf
, XSTRING (*(lpef
->pattern
))->data
))
7075 /* Check if we already listed this font. This may happen if
7076 w32_enable_synthesized_fonts is non-nil, and there are real
7077 bold and italic versions of the font. */
7078 Lisp_Object font_name
= build_string (buf
);
7079 if (NILP (Fmember (font_name
, lpef
->list
)))
7081 *lpef
->tail
= Fcons (Fcons (build_string (buf
), width
), Qnil
);
7082 lpef
->tail
= &(XCDR (*lpef
->tail
));
7090 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
7092 NEWTEXTMETRIC
* lptm
;
7096 return EnumFontFamilies (lpef
->hdc
,
7097 lplf
->elfLogFont
.lfFaceName
,
7098 (FONTENUMPROC
) enum_font_cb2
,
7104 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
7105 ENUMLOGFONTEX
* lplf
;
7106 NEWTEXTMETRICEX
* lptm
;
7110 /* We are not interested in the extra info we get back from the 'Ex
7111 version - only the fact that we get character set variations
7112 enumerated seperately. */
7113 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
7118 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
7119 ENUMLOGFONTEX
* lplf
;
7120 NEWTEXTMETRICEX
* lptm
;
7124 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
7125 FARPROC enum_font_families_ex
7126 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
7127 /* We don't really expect EnumFontFamiliesEx to disappear once we
7128 get here, so don't bother handling it gracefully. */
7129 if (enum_font_families_ex
== NULL
)
7130 error ("gdi32.dll has disappeared!");
7131 return enum_font_families_ex (lpef
->hdc
,
7133 (FONTENUMPROC
) enum_fontex_cb2
,
7137 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
7138 and xterm.c in Emacs 20.3) */
7140 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
7142 char *fontname
, *ptnstr
;
7143 Lisp_Object list
, tem
, newlist
= Qnil
;
7146 list
= Vw32_bdf_filename_alist
;
7147 ptnstr
= XSTRING (pattern
)->data
;
7149 for ( ; CONSP (list
); list
= XCDR (list
))
7153 fontname
= XSTRING (XCAR (tem
))->data
;
7154 else if (STRINGP (tem
))
7155 fontname
= XSTRING (tem
)->data
;
7159 if (w32_font_match (fontname
, ptnstr
))
7161 newlist
= Fcons (XCAR (tem
), newlist
);
7163 if (n_fonts
>= max_names
)
7172 /* Return a list of names of available fonts matching PATTERN on frame
7173 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
7174 to be listed. Frame F NULL means we have not yet created any
7175 frame, which means we can't get proper size info, as we don't have
7176 a device context to use for GetTextMetrics.
7177 MAXNAMES sets a limit on how many fonts to match. */
7180 w32_list_fonts (f
, pattern
, size
, maxnames
)
7182 Lisp_Object pattern
;
7186 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
7187 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
7188 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
7191 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
7192 if (NILP (patterns
))
7193 patterns
= Fcons (pattern
, Qnil
);
7195 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
7200 tpat
= XCAR (patterns
);
7202 if (!STRINGP (tpat
))
7205 /* Avoid expensive EnumFontFamilies functions if we are not
7206 going to be able to output one of these anyway. */
7207 codepage
= w32_codepage_for_font (XSTRING (tpat
)->data
);
7208 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
7209 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
7210 && !IsValidCodePage(codepage
))
7213 /* See if we cached the result for this particular query.
7214 The cache is an alist of the form:
7215 ((PATTERN (FONTNAME . WIDTH) ...) ...)
7217 if (tem
= XCDR (dpyinfo
->name_list_element
),
7218 !NILP (list
= Fassoc (tpat
, tem
)))
7220 list
= Fcdr_safe (list
);
7221 /* We have a cached list. Don't have to get the list again. */
7226 /* At first, put PATTERN in the cache. */
7233 /* Use EnumFontFamiliesEx where it is available, as it knows
7234 about character sets. Fall back to EnumFontFamilies for
7235 older versions of NT that don't support the 'Ex function. */
7236 x_to_w32_font (XSTRING (tpat
)->data
, &ef
.logfont
);
7238 LOGFONT font_match_pattern
;
7239 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
7240 FARPROC enum_font_families_ex
7241 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
7243 /* We do our own pattern matching so we can handle wildcards. */
7244 font_match_pattern
.lfFaceName
[0] = 0;
7245 font_match_pattern
.lfPitchAndFamily
= 0;
7246 /* We can use the charset, because if it is a wildcard it will
7247 be DEFAULT_CHARSET anyway. */
7248 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
7250 ef
.hdc
= GetDC (dpyinfo
->root_window
);
7252 if (enum_font_families_ex
)
7253 enum_font_families_ex (ef
.hdc
,
7254 &font_match_pattern
,
7255 (FONTENUMPROC
) enum_fontex_cb1
,
7258 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
7261 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
7266 /* Make a list of the fonts we got back.
7267 Store that in the font cache for the display. */
7268 XSETCDR (dpyinfo
->name_list_element
,
7269 Fcons (Fcons (tpat
, list
),
7270 XCDR (dpyinfo
->name_list_element
)));
7273 if (NILP (list
)) continue; /* Try the remaining alternatives. */
7275 newlist
= second_best
= Qnil
;
7277 /* Make a list of the fonts that have the right width. */
7278 for (; CONSP (list
); list
= XCDR (list
))
7285 if (NILP (XCAR (tem
)))
7289 newlist
= Fcons (XCAR (tem
), newlist
);
7291 if (n_fonts
>= maxnames
)
7296 if (!INTEGERP (XCDR (tem
)))
7298 /* Since we don't yet know the size of the font, we must
7299 load it and try GetTextMetrics. */
7300 W32FontStruct thisinfo
;
7305 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
7309 thisinfo
.bdf
= NULL
;
7310 thisinfo
.hfont
= CreateFontIndirect (&lf
);
7311 if (thisinfo
.hfont
== NULL
)
7314 hdc
= GetDC (dpyinfo
->root_window
);
7315 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
7316 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
7317 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
7319 XSETCDR (tem
, make_number (0));
7320 SelectObject (hdc
, oldobj
);
7321 ReleaseDC (dpyinfo
->root_window
, hdc
);
7322 DeleteObject(thisinfo
.hfont
);
7325 found_size
= XINT (XCDR (tem
));
7326 if (found_size
== size
)
7328 newlist
= Fcons (XCAR (tem
), newlist
);
7330 if (n_fonts
>= maxnames
)
7333 /* keep track of the closest matching size in case
7334 no exact match is found. */
7335 else if (found_size
> 0)
7337 if (NILP (second_best
))
7340 else if (found_size
< size
)
7342 if (XINT (XCDR (second_best
)) > size
7343 || XINT (XCDR (second_best
)) < found_size
)
7348 if (XINT (XCDR (second_best
)) > size
7349 && XINT (XCDR (second_best
)) >
7356 if (!NILP (newlist
))
7358 else if (!NILP (second_best
))
7360 newlist
= Fcons (XCAR (second_best
), Qnil
);
7365 /* Include any bdf fonts. */
7366 if (n_fonts
< maxnames
)
7368 Lisp_Object combined
[2];
7369 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
7370 combined
[1] = newlist
;
7371 newlist
= Fnconc(2, combined
);
7378 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
7380 w32_get_font_info (f
, font_idx
)
7384 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
7389 w32_query_font (struct frame
*f
, char *fontname
)
7392 struct font_info
*pfi
;
7394 pfi
= FRAME_W32_FONT_TABLE (f
);
7396 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
7398 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
7404 /* Find a CCL program for a font specified by FONTP, and set the member
7405 `encoder' of the structure. */
7408 w32_find_ccl_program (fontp
)
7409 struct font_info
*fontp
;
7411 Lisp_Object list
, elt
;
7413 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
7417 && STRINGP (XCAR (elt
))
7418 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
7424 struct ccl_program
*ccl
7425 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
7427 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
7430 fontp
->font_encoder
= ccl
;
7435 /* Find BDF files in a specified directory. (use GCPRO when calling,
7436 as this calls lisp to get a directory listing). */
7438 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
7440 Lisp_Object filelist
, list
= Qnil
;
7443 if (!STRINGP(directory
))
7446 filelist
= Fdirectory_files (directory
, Qt
,
7447 build_string (".*\\.[bB][dD][fF]"), Qt
);
7449 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
7451 Lisp_Object filename
= XCAR (filelist
);
7452 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
7453 store_in_alist (&list
, build_string (fontname
), filename
);
7458 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
7460 doc
: /* Return a list of BDF fonts in DIR.
7461 The list is suitable for appending to w32-bdf-filename-alist. Fonts
7462 which do not contain an xlfd description will not be included in the
7463 list. DIR may be a list of directories. */)
7465 Lisp_Object directory
;
7467 Lisp_Object list
= Qnil
;
7468 struct gcpro gcpro1
, gcpro2
;
7470 if (!CONSP (directory
))
7471 return w32_find_bdf_fonts_in_dir (directory
);
7473 for ( ; CONSP (directory
); directory
= XCDR (directory
))
7475 Lisp_Object pair
[2];
7478 GCPRO2 (directory
, list
);
7479 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
7480 list
= Fnconc( 2, pair
);
7487 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
7488 doc
: /* Internal function called by `color-defined-p', which see. */)
7490 Lisp_Object color
, frame
;
7493 FRAME_PTR f
= check_x_frame (frame
);
7495 CHECK_STRING (color
);
7497 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7503 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
7504 doc
: /* Internal function called by `color-values', which see. */)
7506 Lisp_Object color
, frame
;
7509 FRAME_PTR f
= check_x_frame (frame
);
7511 CHECK_STRING (color
);
7513 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7517 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
7518 | GetRValue (foo
.pixel
));
7519 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
7520 | GetGValue (foo
.pixel
));
7521 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
7522 | GetBValue (foo
.pixel
));
7523 return Flist (3, rgb
);
7529 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
7530 doc
: /* Internal function called by `display-color-p', which see. */)
7532 Lisp_Object display
;
7534 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7536 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
7542 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
7543 Sx_display_grayscale_p
, 0, 1, 0,
7544 doc
: /* Return t if the X display supports shades of gray.
7545 Note that color displays do support shades of gray.
7546 The optional argument DISPLAY specifies which display to ask about.
7547 DISPLAY should be either a frame or a display name (a string).
7548 If omitted or nil, that stands for the selected frame's display. */)
7550 Lisp_Object display
;
7552 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7554 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
7560 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
7561 Sx_display_pixel_width
, 0, 1, 0,
7562 doc
: /* Returns the width in pixels of DISPLAY.
7563 The optional argument DISPLAY specifies which display to ask about.
7564 DISPLAY should be either a frame or a display name (a string).
7565 If omitted or nil, that stands for the selected frame's display. */)
7567 Lisp_Object display
;
7569 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7571 return make_number (dpyinfo
->width
);
7574 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
7575 Sx_display_pixel_height
, 0, 1, 0,
7576 doc
: /* Returns the height in pixels of DISPLAY.
7577 The optional argument DISPLAY specifies which display to ask about.
7578 DISPLAY should be either a frame or a display name (a string).
7579 If omitted or nil, that stands for the selected frame's display. */)
7581 Lisp_Object display
;
7583 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7585 return make_number (dpyinfo
->height
);
7588 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
7590 doc
: /* Returns the number of bitplanes of DISPLAY.
7591 The optional argument DISPLAY specifies which display to ask about.
7592 DISPLAY should be either a frame or a display name (a string).
7593 If omitted or nil, that stands for the selected frame's display. */)
7595 Lisp_Object display
;
7597 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7599 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7602 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
7604 doc
: /* Returns the number of color cells of DISPLAY.
7605 The optional argument DISPLAY specifies which display to ask about.
7606 DISPLAY should be either a frame or a display name (a string).
7607 If omitted or nil, that stands for the selected frame's display. */)
7609 Lisp_Object display
;
7611 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7615 hdc
= GetDC (dpyinfo
->root_window
);
7616 if (dpyinfo
->has_palette
)
7617 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
7619 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
7622 cap
= 1 << (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7624 ReleaseDC (dpyinfo
->root_window
, hdc
);
7626 return make_number (cap
);
7629 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
7630 Sx_server_max_request_size
,
7632 doc
: /* Returns the maximum request size of the server of DISPLAY.
7633 The optional argument DISPLAY specifies which display to ask about.
7634 DISPLAY should be either a frame or a display name (a string).
7635 If omitted or nil, that stands for the selected frame's display. */)
7637 Lisp_Object display
;
7639 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7641 return make_number (1);
7644 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
7645 doc
: /* Returns the vendor ID string of the W32 system (Microsoft).
7646 The optional argument DISPLAY specifies which display to ask about.
7647 DISPLAY should be either a frame or a display name (a string).
7648 If omitted or nil, that stands for the selected frame's display. */)
7650 Lisp_Object display
;
7652 return build_string ("Microsoft Corp.");
7655 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
7656 doc
: /* Returns the version numbers of the server of DISPLAY.
7657 The value is a list of three integers: the major and minor
7658 version numbers, and the vendor-specific release
7659 number. See also the function `x-server-vendor'.
7661 The optional argument DISPLAY specifies which display to ask about.
7662 DISPLAY should be either a frame or a display name (a string).
7663 If omitted or nil, that stands for the selected frame's display. */)
7665 Lisp_Object display
;
7667 return Fcons (make_number (w32_major_version
),
7668 Fcons (make_number (w32_minor_version
),
7669 Fcons (make_number (w32_build_number
), Qnil
)));
7672 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
7673 doc
: /* Returns the number of screens on the server of DISPLAY.
7674 The optional argument DISPLAY specifies which display to ask about.
7675 DISPLAY should be either a frame or a display name (a string).
7676 If omitted or nil, that stands for the selected frame's display. */)
7678 Lisp_Object display
;
7680 return make_number (1);
7683 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
7684 Sx_display_mm_height
, 0, 1, 0,
7685 doc
: /* Returns the height in millimeters of DISPLAY.
7686 The optional argument DISPLAY specifies which display to ask about.
7687 DISPLAY should be either a frame or a display name (a string).
7688 If omitted or nil, that stands for the selected frame's display. */)
7690 Lisp_Object display
;
7692 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7696 hdc
= GetDC (dpyinfo
->root_window
);
7698 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
7700 ReleaseDC (dpyinfo
->root_window
, hdc
);
7702 return make_number (cap
);
7705 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
7706 doc
: /* Returns the width in millimeters of DISPLAY.
7707 The optional argument DISPLAY specifies which display to ask about.
7708 DISPLAY should be either a frame or a display name (a string).
7709 If omitted or nil, that stands for the selected frame's display. */)
7711 Lisp_Object display
;
7713 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7718 hdc
= GetDC (dpyinfo
->root_window
);
7720 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
7722 ReleaseDC (dpyinfo
->root_window
, hdc
);
7724 return make_number (cap
);
7727 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
7728 Sx_display_backing_store
, 0, 1, 0,
7729 doc
: /* Returns an indication of whether DISPLAY does backing store.
7730 The value may be `always', `when-mapped', or `not-useful'.
7731 The optional argument DISPLAY specifies which display to ask about.
7732 DISPLAY should be either a frame or a display name (a string).
7733 If omitted or nil, that stands for the selected frame's display. */)
7735 Lisp_Object display
;
7737 return intern ("not-useful");
7740 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
7741 Sx_display_visual_class
, 0, 1, 0,
7742 doc
: /* Returns the visual class of DISPLAY.
7743 The value is one of the symbols `static-gray', `gray-scale',
7744 `static-color', `pseudo-color', `true-color', or `direct-color'.
7746 The optional argument DISPLAY specifies which display to ask about.
7747 DISPLAY should be either a frame or a display name (a string).
7748 If omitted or nil, that stands for the selected frame's display. */)
7750 Lisp_Object display
;
7752 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7753 Lisp_Object result
= Qnil
;
7755 if (dpyinfo
->has_palette
)
7756 result
= intern ("pseudo-color");
7757 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
7758 result
= intern ("static-grey");
7759 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
7760 result
= intern ("static-color");
7761 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
7762 result
= intern ("true-color");
7767 DEFUN ("x-display-save-under", Fx_display_save_under
,
7768 Sx_display_save_under
, 0, 1, 0,
7769 doc
: /* Returns t if DISPLAY supports the save-under feature.
7770 The optional argument DISPLAY specifies which display to ask about.
7771 DISPLAY should be either a frame or a display name (a string).
7772 If omitted or nil, that stands for the selected frame's display. */)
7774 Lisp_Object display
;
7781 register struct frame
*f
;
7783 return PIXEL_WIDTH (f
);
7788 register struct frame
*f
;
7790 return PIXEL_HEIGHT (f
);
7795 register struct frame
*f
;
7797 return FONT_WIDTH (f
->output_data
.w32
->font
);
7802 register struct frame
*f
;
7804 return f
->output_data
.w32
->line_height
;
7809 register struct frame
*f
;
7811 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
7814 /* Return the display structure for the display named NAME.
7815 Open a new connection if necessary. */
7817 struct w32_display_info
*
7818 x_display_info_for_name (name
)
7822 struct w32_display_info
*dpyinfo
;
7824 CHECK_STRING (name
);
7826 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
7828 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
7831 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
7836 /* Use this general default value to start with. */
7837 Vx_resource_name
= Vinvocation_name
;
7839 validate_x_resource_name ();
7841 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
7842 (char *) XSTRING (Vx_resource_name
)->data
);
7845 error ("Cannot connect to server %s", XSTRING (name
)->data
);
7848 XSETFASTINT (Vwindow_system_version
, 3);
7853 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
7854 1, 3, 0, doc
: /* Open a connection to a server.
7855 DISPLAY is the name of the display to connect to.
7856 Optional second arg XRM-STRING is a string of resources in xrdb format.
7857 If the optional third arg MUST-SUCCEED is non-nil,
7858 terminate Emacs if we can't open the connection. */)
7859 (display
, xrm_string
, must_succeed
)
7860 Lisp_Object display
, xrm_string
, must_succeed
;
7862 unsigned char *xrm_option
;
7863 struct w32_display_info
*dpyinfo
;
7865 /* If initialization has already been done, return now to avoid
7866 overwriting critical parts of one_w32_display_info. */
7870 CHECK_STRING (display
);
7871 if (! NILP (xrm_string
))
7872 CHECK_STRING (xrm_string
);
7874 if (! EQ (Vwindow_system
, intern ("w32")))
7875 error ("Not using Microsoft Windows");
7877 /* Allow color mapping to be defined externally; first look in user's
7878 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
7880 Lisp_Object color_file
;
7881 struct gcpro gcpro1
;
7883 color_file
= build_string("~/rgb.txt");
7885 GCPRO1 (color_file
);
7887 if (NILP (Ffile_readable_p (color_file
)))
7889 Fexpand_file_name (build_string ("rgb.txt"),
7890 Fsymbol_value (intern ("data-directory")));
7892 Vw32_color_map
= Fw32_load_color_file (color_file
);
7896 if (NILP (Vw32_color_map
))
7897 Vw32_color_map
= Fw32_default_color_map ();
7899 if (! NILP (xrm_string
))
7900 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
7902 xrm_option
= (unsigned char *) 0;
7904 /* Use this general default value to start with. */
7905 /* First remove .exe suffix from invocation-name - it looks ugly. */
7907 char basename
[ MAX_PATH
], *str
;
7909 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
7910 str
= strrchr (basename
, '.');
7912 Vinvocation_name
= build_string (basename
);
7914 Vx_resource_name
= Vinvocation_name
;
7916 validate_x_resource_name ();
7918 /* This is what opens the connection and sets x_current_display.
7919 This also initializes many symbols, such as those used for input. */
7920 dpyinfo
= w32_term_init (display
, xrm_option
,
7921 (char *) XSTRING (Vx_resource_name
)->data
);
7925 if (!NILP (must_succeed
))
7926 fatal ("Cannot connect to server %s.\n",
7927 XSTRING (display
)->data
);
7929 error ("Cannot connect to server %s", XSTRING (display
)->data
);
7934 XSETFASTINT (Vwindow_system_version
, 3);
7938 DEFUN ("x-close-connection", Fx_close_connection
,
7939 Sx_close_connection
, 1, 1, 0,
7940 doc
: /* Close the connection to DISPLAY's server.
7941 For DISPLAY, specify either a frame or a display name (a string).
7942 If DISPLAY is nil, that stands for the selected frame's display. */)
7944 Lisp_Object display
;
7946 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7949 if (dpyinfo
->reference_count
> 0)
7950 error ("Display still has frames on it");
7953 /* Free the fonts in the font table. */
7954 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7955 if (dpyinfo
->font_table
[i
].name
)
7957 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7958 xfree (dpyinfo
->font_table
[i
].full_name
);
7959 xfree (dpyinfo
->font_table
[i
].name
);
7960 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7962 x_destroy_all_bitmaps (dpyinfo
);
7964 x_delete_display (dpyinfo
);
7970 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7971 doc
: /* Return the list of display names that Emacs has connections to. */)
7974 Lisp_Object tail
, result
;
7977 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
7978 result
= Fcons (XCAR (XCAR (tail
)), result
);
7983 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7984 doc
: /* This is a noop on W32 systems. */)
7986 Lisp_Object display
, on
;
7993 /***********************************************************************
7995 ***********************************************************************/
7997 /* Value is the number of elements of vector VECTOR. */
7999 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
8001 /* List of supported image types. Use define_image_type to add new
8002 types. Use lookup_image_type to find a type for a given symbol. */
8004 static struct image_type
*image_types
;
8006 /* The symbol `image' which is the car of the lists used to represent
8009 extern Lisp_Object Qimage
;
8011 /* The symbol `xbm' which is used as the type symbol for XBM images. */
8017 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
8018 extern Lisp_Object QCdata
;
8019 Lisp_Object QCtype
, QCascent
, QCmargin
, QCrelief
;
8020 Lisp_Object QCconversion
, QCcolor_symbols
, QCheuristic_mask
;
8021 Lisp_Object QCindex
, QCmatrix
, QCcolor_adjustment
, QCmask
;
8023 /* Other symbols. */
8025 Lisp_Object Qlaplace
, Qemboss
, Qedge_detection
, Qheuristic
;
8027 /* Time in seconds after which images should be removed from the cache
8028 if not displayed. */
8030 Lisp_Object Vimage_cache_eviction_delay
;
8032 /* Function prototypes. */
8034 static void define_image_type
P_ ((struct image_type
*type
));
8035 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
8036 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
8037 static void x_laplace
P_ ((struct frame
*, struct image
*));
8038 static void x_emboss
P_ ((struct frame
*, struct image
*));
8039 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
8043 /* Define a new image type from TYPE. This adds a copy of TYPE to
8044 image_types and adds the symbol *TYPE->type to Vimage_types. */
8047 define_image_type (type
)
8048 struct image_type
*type
;
8050 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
8051 The initialized data segment is read-only. */
8052 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
8053 bcopy (type
, p
, sizeof *p
);
8054 p
->next
= image_types
;
8056 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
8060 /* Look up image type SYMBOL, and return a pointer to its image_type
8061 structure. Value is null if SYMBOL is not a known image type. */
8063 static INLINE
struct image_type
*
8064 lookup_image_type (symbol
)
8067 struct image_type
*type
;
8069 for (type
= image_types
; type
; type
= type
->next
)
8070 if (EQ (symbol
, *type
->type
))
8077 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
8078 valid image specification is a list whose car is the symbol
8079 `image', and whose rest is a property list. The property list must
8080 contain a value for key `:type'. That value must be the name of a
8081 supported image type. The rest of the property list depends on the
8085 valid_image_p (object
)
8090 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
8094 for (tem
= XCDR (object
); CONSP (tem
); tem
= XCDR (tem
))
8095 if (EQ (XCAR (tem
), QCtype
))
8098 if (CONSP (tem
) && SYMBOLP (XCAR (tem
)))
8100 struct image_type
*type
;
8101 type
= lookup_image_type (XCAR (tem
));
8103 valid_p
= type
->valid_p (object
);
8114 /* Log error message with format string FORMAT and argument ARG.
8115 Signaling an error, e.g. when an image cannot be loaded, is not a
8116 good idea because this would interrupt redisplay, and the error
8117 message display would lead to another redisplay. This function
8118 therefore simply displays a message. */
8121 image_error (format
, arg1
, arg2
)
8123 Lisp_Object arg1
, arg2
;
8125 add_to_log (format
, arg1
, arg2
);
8130 /***********************************************************************
8131 Image specifications
8132 ***********************************************************************/
8134 enum image_value_type
8136 IMAGE_DONT_CHECK_VALUE_TYPE
,
8138 IMAGE_STRING_OR_NIL_VALUE
,
8140 IMAGE_POSITIVE_INTEGER_VALUE
,
8141 IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
,
8142 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
8144 IMAGE_INTEGER_VALUE
,
8145 IMAGE_FUNCTION_VALUE
,
8150 /* Structure used when parsing image specifications. */
8152 struct image_keyword
8154 /* Name of keyword. */
8157 /* The type of value allowed. */
8158 enum image_value_type type
;
8160 /* Non-zero means key must be present. */
8163 /* Used to recognize duplicate keywords in a property list. */
8166 /* The value that was found. */
8171 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
8173 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
8176 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
8177 has the format (image KEYWORD VALUE ...). One of the keyword/
8178 value pairs must be `:type TYPE'. KEYWORDS is a vector of
8179 image_keywords structures of size NKEYWORDS describing other
8180 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
8183 parse_image_spec (spec
, keywords
, nkeywords
, type
)
8185 struct image_keyword
*keywords
;
8192 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
8195 plist
= XCDR (spec
);
8196 while (CONSP (plist
))
8198 Lisp_Object key
, value
;
8200 /* First element of a pair must be a symbol. */
8202 plist
= XCDR (plist
);
8206 /* There must follow a value. */
8209 value
= XCAR (plist
);
8210 plist
= XCDR (plist
);
8212 /* Find key in KEYWORDS. Error if not found. */
8213 for (i
= 0; i
< nkeywords
; ++i
)
8214 if (strcmp (keywords
[i
].name
, XSYMBOL (key
)->name
->data
) == 0)
8220 /* Record that we recognized the keyword. If a keywords
8221 was found more than once, it's an error. */
8222 keywords
[i
].value
= value
;
8223 ++keywords
[i
].count
;
8225 if (keywords
[i
].count
> 1)
8228 /* Check type of value against allowed type. */
8229 switch (keywords
[i
].type
)
8231 case IMAGE_STRING_VALUE
:
8232 if (!STRINGP (value
))
8236 case IMAGE_STRING_OR_NIL_VALUE
:
8237 if (!STRINGP (value
) && !NILP (value
))
8241 case IMAGE_SYMBOL_VALUE
:
8242 if (!SYMBOLP (value
))
8246 case IMAGE_POSITIVE_INTEGER_VALUE
:
8247 if (!INTEGERP (value
) || XINT (value
) <= 0)
8251 case IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
:
8252 if (INTEGERP (value
) && XINT (value
) >= 0)
8255 && INTEGERP (XCAR (value
)) && INTEGERP (XCDR (value
))
8256 && XINT (XCAR (value
)) >= 0 && XINT (XCDR (value
)) >= 0)
8260 case IMAGE_ASCENT_VALUE
:
8261 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
8263 else if (INTEGERP (value
)
8264 && XINT (value
) >= 0
8265 && XINT (value
) <= 100)
8269 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
8270 if (!INTEGERP (value
) || XINT (value
) < 0)
8274 case IMAGE_DONT_CHECK_VALUE_TYPE
:
8277 case IMAGE_FUNCTION_VALUE
:
8278 value
= indirect_function (value
);
8280 || COMPILEDP (value
)
8281 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
8285 case IMAGE_NUMBER_VALUE
:
8286 if (!INTEGERP (value
) && !FLOATP (value
))
8290 case IMAGE_INTEGER_VALUE
:
8291 if (!INTEGERP (value
))
8295 case IMAGE_BOOL_VALUE
:
8296 if (!NILP (value
) && !EQ (value
, Qt
))
8305 if (EQ (key
, QCtype
) && !EQ (type
, value
))
8309 /* Check that all mandatory fields are present. */
8310 for (i
= 0; i
< nkeywords
; ++i
)
8311 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
8314 return NILP (plist
);
8318 /* Return the value of KEY in image specification SPEC. Value is nil
8319 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
8320 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
8323 image_spec_value (spec
, key
, found
)
8324 Lisp_Object spec
, key
;
8329 xassert (valid_image_p (spec
));
8331 for (tail
= XCDR (spec
);
8332 CONSP (tail
) && CONSP (XCDR (tail
));
8333 tail
= XCDR (XCDR (tail
)))
8335 if (EQ (XCAR (tail
), key
))
8339 return XCAR (XCDR (tail
));
8351 /***********************************************************************
8352 Image type independent image structures
8353 ***********************************************************************/
8355 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
8356 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
8359 /* Allocate and return a new image structure for image specification
8360 SPEC. SPEC has a hash value of HASH. */
8362 static struct image
*
8363 make_image (spec
, hash
)
8367 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
8369 xassert (valid_image_p (spec
));
8370 bzero (img
, sizeof *img
);
8371 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
8372 xassert (img
->type
!= NULL
);
8374 img
->data
.lisp_val
= Qnil
;
8375 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
8381 /* Free image IMG which was used on frame F, including its resources. */
8390 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8392 /* Remove IMG from the hash table of its cache. */
8394 img
->prev
->next
= img
->next
;
8396 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
8399 img
->next
->prev
= img
->prev
;
8401 c
->images
[img
->id
] = NULL
;
8403 /* Free resources, then free IMG. */
8404 img
->type
->free (f
, img
);
8410 /* Prepare image IMG for display on frame F. Must be called before
8411 drawing an image. */
8414 prepare_image_for_display (f
, img
)
8420 /* We're about to display IMG, so set its timestamp to `now'. */
8422 img
->timestamp
= EMACS_SECS (t
);
8424 /* If IMG doesn't have a pixmap yet, load it now, using the image
8425 type dependent loader function. */
8426 if (img
->pixmap
== 0 && !img
->load_failed_p
)
8427 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8431 /* Value is the number of pixels for the ascent of image IMG when
8432 drawn in face FACE. */
8435 image_ascent (img
, face
)
8439 int height
= img
->height
+ img
->vmargin
;
8442 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
8445 ascent
= height
/ 2 - (FONT_DESCENT(face
->font
)
8446 - FONT_BASE(face
->font
)) / 2;
8448 ascent
= height
/ 2;
8451 ascent
= height
* img
->ascent
/ 100.0;
8458 /* Image background colors. */
8460 static unsigned long
8461 four_corners_best (ximg
, width
, height
)
8463 unsigned long width
, height
;
8465 #if 0 /* TODO: Image support. */
8466 unsigned long corners
[4], best
;
8469 /* Get the colors at the corners of ximg. */
8470 corners
[0] = XGetPixel (ximg
, 0, 0);
8471 corners
[1] = XGetPixel (ximg
, width
- 1, 0);
8472 corners
[2] = XGetPixel (ximg
, width
- 1, height
- 1);
8473 corners
[3] = XGetPixel (ximg
, 0, height
- 1);
8475 /* Choose the most frequently found color as background. */
8476 for (i
= best_count
= 0; i
< 4; ++i
)
8480 for (j
= n
= 0; j
< 4; ++j
)
8481 if (corners
[i
] == corners
[j
])
8485 best
= corners
[i
], best_count
= n
;
8494 /* Return the `background' field of IMG. If IMG doesn't have one yet,
8495 it is guessed heuristically. If non-zero, XIMG is an existing XImage
8496 object to use for the heuristic. */
8499 image_background (img
, f
, ximg
)
8504 if (! img
->background_valid
)
8505 /* IMG doesn't have a background yet, try to guess a reasonable value. */
8507 #if 0 /* TODO: Image support. */
8508 int free_ximg
= !ximg
;
8511 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
8512 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
8514 img
->background
= four_corners_best (ximg
, img
->width
, img
->height
);
8517 XDestroyImage (ximg
);
8519 img
->background_valid
= 1;
8523 return img
->background
;
8526 /* Return the `background_transparent' field of IMG. If IMG doesn't
8527 have one yet, it is guessed heuristically. If non-zero, MASK is an
8528 existing XImage object to use for the heuristic. */
8531 image_background_transparent (img
, f
, mask
)
8536 if (! img
->background_transparent_valid
)
8537 /* IMG doesn't have a background yet, try to guess a reasonable value. */
8539 #if 0 /* TODO: Image support. */
8542 int free_mask
= !mask
;
8545 mask
= XGetImage (FRAME_X_DISPLAY (f
), img
->mask
,
8546 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
8548 img
->background_transparent
8549 = !four_corners_best (mask
, img
->width
, img
->height
);
8552 XDestroyImage (mask
);
8556 img
->background_transparent
= 0;
8558 img
->background_transparent_valid
= 1;
8561 return img
->background_transparent
;
8565 /***********************************************************************
8566 Helper functions for X image types
8567 ***********************************************************************/
8569 static void x_clear_image_1
P_ ((struct frame
*, struct image
*, int,
8571 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
8572 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
8574 Lisp_Object color_name
,
8575 unsigned long dflt
));
8578 /* Clear X resources of image IMG on frame F. PIXMAP_P non-zero means
8579 free the pixmap if any. MASK_P non-zero means clear the mask
8580 pixmap if any. COLORS_P non-zero means free colors allocated for
8581 the image, if any. */
8584 x_clear_image_1 (f
, img
, pixmap_p
, mask_p
, colors_p
)
8587 int pixmap_p
, mask_p
, colors_p
;
8589 #if 0 /* TODO: W32 image support */
8590 if (pixmap_p
&& img
->pixmap
)
8592 XFreePixmap (FRAME_X_DISPLAY (f
), img
->pixmap
);
8594 img
->background_valid
= 0;
8597 if (mask_p
&& img
->mask
)
8599 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
8601 img
->background_transparent_valid
= 0;
8604 if (colors_p
&& img
->ncolors
)
8606 x_free_colors (f
, img
->colors
, img
->ncolors
);
8607 xfree (img
->colors
);
8614 /* Free X resources of image IMG which is used on frame F. */
8617 x_clear_image (f
, img
)
8621 #if 0 /* TODO: W32 image support */
8626 XFreePixmap (NULL
, img
->pixmap
);
8633 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
8635 /* If display has an immutable color map, freeing colors is not
8636 necessary and some servers don't allow it. So don't do it. */
8637 if (class != StaticColor
8638 && class != StaticGray
8639 && class != TrueColor
)
8643 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
8644 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
8649 xfree (img
->colors
);
8657 /* Allocate color COLOR_NAME for image IMG on frame F. If color
8658 cannot be allocated, use DFLT. Add a newly allocated color to
8659 IMG->colors, so that it can be freed again. Value is the pixel
8662 static unsigned long
8663 x_alloc_image_color (f
, img
, color_name
, dflt
)
8666 Lisp_Object color_name
;
8669 #if 0 /* TODO: allocing colors. */
8671 unsigned long result
;
8673 xassert (STRINGP (color_name
));
8675 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
8677 /* This isn't called frequently so we get away with simply
8678 reallocating the color vector to the needed size, here. */
8681 (unsigned long *) xrealloc (img
->colors
,
8682 img
->ncolors
* sizeof *img
->colors
);
8683 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
8684 result
= color
.pixel
;
8695 /***********************************************************************
8697 ***********************************************************************/
8699 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
8700 static void postprocess_image
P_ ((struct frame
*, struct image
*));
8703 /* Return a new, initialized image cache that is allocated from the
8704 heap. Call free_image_cache to free an image cache. */
8706 struct image_cache
*
8709 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
8712 bzero (c
, sizeof *c
);
8714 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
8715 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
8716 c
->buckets
= (struct image
**) xmalloc (size
);
8717 bzero (c
->buckets
, size
);
8722 /* Free image cache of frame F. Be aware that X frames share images
8726 free_image_cache (f
)
8729 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8734 /* Cache should not be referenced by any frame when freed. */
8735 xassert (c
->refcount
== 0);
8737 for (i
= 0; i
< c
->used
; ++i
)
8738 free_image (f
, c
->images
[i
]);
8742 FRAME_X_IMAGE_CACHE (f
) = NULL
;
8747 /* Clear image cache of frame F. FORCE_P non-zero means free all
8748 images. FORCE_P zero means clear only images that haven't been
8749 displayed for some time. Should be called from time to time to
8750 reduce the number of loaded images. If image-eviction-seconds is
8751 non-nil, this frees images in the cache which weren't displayed for
8752 at least that many seconds. */
8755 clear_image_cache (f
, force_p
)
8759 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8761 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
8765 int i
, any_freed_p
= 0;
8768 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
8770 for (i
= 0; i
< c
->used
; ++i
)
8772 struct image
*img
= c
->images
[i
];
8775 || (img
->timestamp
> old
)))
8777 free_image (f
, img
);
8782 /* We may be clearing the image cache because, for example,
8783 Emacs was iconified for a longer period of time. In that
8784 case, current matrices may still contain references to
8785 images freed above. So, clear these matrices. */
8788 clear_current_matrices (f
);
8789 ++windows_or_buffers_changed
;
8795 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
8797 doc
: /* Clear the image cache of FRAME.
8798 FRAME nil or omitted means use the selected frame.
8799 FRAME t means clear the image caches of all frames. */)
8807 FOR_EACH_FRAME (tail
, frame
)
8808 if (FRAME_W32_P (XFRAME (frame
)))
8809 clear_image_cache (XFRAME (frame
), 1);
8812 clear_image_cache (check_x_frame (frame
), 1);
8818 /* Compute masks and transform image IMG on frame F, as specified
8819 by the image's specification, */
8822 postprocess_image (f
, img
)
8826 #if 0 /* TODO: image support. */
8827 /* Manipulation of the image's mask. */
8830 Lisp_Object conversion
, spec
;
8835 /* `:heuristic-mask t'
8837 means build a mask heuristically.
8838 `:heuristic-mask (R G B)'
8839 `:mask (heuristic (R G B))'
8840 means build a mask from color (R G B) in the
8843 means remove a mask, if any. */
8845 mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
8847 x_build_heuristic_mask (f
, img
, mask
);
8852 mask
= image_spec_value (spec
, QCmask
, &found_p
);
8854 if (EQ (mask
, Qheuristic
))
8855 x_build_heuristic_mask (f
, img
, Qt
);
8856 else if (CONSP (mask
)
8857 && EQ (XCAR (mask
), Qheuristic
))
8859 if (CONSP (XCDR (mask
)))
8860 x_build_heuristic_mask (f
, img
, XCAR (XCDR (mask
)));
8862 x_build_heuristic_mask (f
, img
, XCDR (mask
));
8864 else if (NILP (mask
) && found_p
&& img
->mask
)
8866 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
8872 /* Should we apply an image transformation algorithm? */
8873 conversion
= image_spec_value (spec
, QCconversion
, NULL
);
8874 if (EQ (conversion
, Qdisabled
))
8875 x_disable_image (f
, img
);
8876 else if (EQ (conversion
, Qlaplace
))
8878 else if (EQ (conversion
, Qemboss
))
8880 else if (CONSP (conversion
)
8881 && EQ (XCAR (conversion
), Qedge_detection
))
8884 tem
= XCDR (conversion
);
8886 x_edge_detection (f
, img
,
8887 Fplist_get (tem
, QCmatrix
),
8888 Fplist_get (tem
, QCcolor_adjustment
));
8895 /* Return the id of image with Lisp specification SPEC on frame F.
8896 SPEC must be a valid Lisp image specification (see valid_image_p). */
8899 lookup_image (f
, spec
)
8903 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8907 struct gcpro gcpro1
;
8910 /* F must be a window-system frame, and SPEC must be a valid image
8912 xassert (FRAME_WINDOW_P (f
));
8913 xassert (valid_image_p (spec
));
8917 /* Look up SPEC in the hash table of the image cache. */
8918 hash
= sxhash (spec
, 0);
8919 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8921 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
8922 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
8925 /* If not found, create a new image and cache it. */
8928 extern Lisp_Object Qpostscript
;
8931 img
= make_image (spec
, hash
);
8932 cache_image (f
, img
);
8933 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8935 /* If we can't load the image, and we don't have a width and
8936 height, use some arbitrary width and height so that we can
8937 draw a rectangle for it. */
8938 if (img
->load_failed_p
)
8942 value
= image_spec_value (spec
, QCwidth
, NULL
);
8943 img
->width
= (INTEGERP (value
)
8944 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
8945 value
= image_spec_value (spec
, QCheight
, NULL
);
8946 img
->height
= (INTEGERP (value
)
8947 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
8951 /* Handle image type independent image attributes
8952 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF',
8953 `:background COLOR'. */
8954 Lisp_Object ascent
, margin
, relief
, bg
;
8956 ascent
= image_spec_value (spec
, QCascent
, NULL
);
8957 if (INTEGERP (ascent
))
8958 img
->ascent
= XFASTINT (ascent
);
8959 else if (EQ (ascent
, Qcenter
))
8960 img
->ascent
= CENTERED_IMAGE_ASCENT
;
8962 margin
= image_spec_value (spec
, QCmargin
, NULL
);
8963 if (INTEGERP (margin
) && XINT (margin
) >= 0)
8964 img
->vmargin
= img
->hmargin
= XFASTINT (margin
);
8965 else if (CONSP (margin
) && INTEGERP (XCAR (margin
))
8966 && INTEGERP (XCDR (margin
)))
8968 if (XINT (XCAR (margin
)) > 0)
8969 img
->hmargin
= XFASTINT (XCAR (margin
));
8970 if (XINT (XCDR (margin
)) > 0)
8971 img
->vmargin
= XFASTINT (XCDR (margin
));
8974 relief
= image_spec_value (spec
, QCrelief
, NULL
);
8975 if (INTEGERP (relief
))
8977 img
->relief
= XINT (relief
);
8978 img
->hmargin
+= abs (img
->relief
);
8979 img
->vmargin
+= abs (img
->relief
);
8982 if (! img
->background_valid
)
8984 bg
= image_spec_value (img
->spec
, QCbackground
, NULL
);
8988 = x_alloc_image_color (f
, img
, bg
,
8989 FRAME_BACKGROUND_PIXEL (f
));
8990 img
->background_valid
= 1;
8994 /* Do image transformations and compute masks, unless we
8995 don't have the image yet. */
8996 if (!EQ (*img
->type
->type
, Qpostscript
))
8997 postprocess_image (f
, img
);
9001 xassert (!interrupt_input_blocked
);
9004 /* We're using IMG, so set its timestamp to `now'. */
9005 EMACS_GET_TIME (now
);
9006 img
->timestamp
= EMACS_SECS (now
);
9010 /* Value is the image id. */
9015 /* Cache image IMG in the image cache of frame F. */
9018 cache_image (f
, img
)
9022 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
9025 /* Find a free slot in c->images. */
9026 for (i
= 0; i
< c
->used
; ++i
)
9027 if (c
->images
[i
] == NULL
)
9030 /* If no free slot found, maybe enlarge c->images. */
9031 if (i
== c
->used
&& c
->used
== c
->size
)
9034 c
->images
= (struct image
**) xrealloc (c
->images
,
9035 c
->size
* sizeof *c
->images
);
9038 /* Add IMG to c->images, and assign IMG an id. */
9044 /* Add IMG to the cache's hash table. */
9045 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
9046 img
->next
= c
->buckets
[i
];
9048 img
->next
->prev
= img
;
9050 c
->buckets
[i
] = img
;
9054 /* Call FN on every image in the image cache of frame F. Used to mark
9055 Lisp Objects in the image cache. */
9058 forall_images_in_image_cache (f
, fn
)
9060 void (*fn
) P_ ((struct image
*img
));
9062 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
9064 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
9068 for (i
= 0; i
< c
->used
; ++i
)
9077 /***********************************************************************
9079 ***********************************************************************/
9081 #if 0 /* TODO: W32 specific image code. */
9083 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
9084 XImage
**, Pixmap
*));
9085 static void x_destroy_x_image
P_ ((XImage
*));
9086 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
9089 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
9090 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
9091 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
9092 via xmalloc. Print error messages via image_error if an error
9093 occurs. Value is non-zero if successful. */
9096 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
9098 int width
, height
, depth
;
9102 #if 0 /* TODO: Image support for W32 */
9103 Display
*display
= FRAME_W32_DISPLAY (f
);
9104 Screen
*screen
= FRAME_X_SCREEN (f
);
9105 Window window
= FRAME_W32_WINDOW (f
);
9107 xassert (interrupt_input_blocked
);
9110 depth
= one_w32_display_info
.n_cbits
;
9111 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
9112 depth
, ZPixmap
, 0, NULL
, width
, height
,
9113 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
9116 image_error ("Unable to allocate X image", Qnil
, Qnil
);
9120 /* Allocate image raster. */
9121 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
9123 /* Allocate a pixmap of the same size. */
9124 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
9127 x_destroy_x_image (*ximg
);
9129 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
9137 /* Destroy XImage XIMG. Free XIMG->data. */
9140 x_destroy_x_image (ximg
)
9143 xassert (interrupt_input_blocked
);
9148 XDestroyImage (ximg
);
9153 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
9154 are width and height of both the image and pixmap. */
9157 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
9164 xassert (interrupt_input_blocked
);
9165 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
9166 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
9173 /***********************************************************************
9175 ***********************************************************************/
9177 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
9178 static char *slurp_file
P_ ((char *, int *));
9181 /* Find image file FILE. Look in data-directory, then
9182 x-bitmap-file-path. Value is the full name of the file found, or
9183 nil if not found. */
9186 x_find_image_file (file
)
9189 Lisp_Object file_found
, search_path
;
9190 struct gcpro gcpro1
, gcpro2
;
9194 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
9195 GCPRO2 (file_found
, search_path
);
9197 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
9198 fd
= openp (search_path
, file
, Qnil
, &file_found
, 0);
9210 /* Read FILE into memory. Value is a pointer to a buffer allocated
9211 with xmalloc holding FILE's contents. Value is null if an error
9212 occurred. *SIZE is set to the size of the file. */
9215 slurp_file (file
, size
)
9223 if (stat (file
, &st
) == 0
9224 && (fp
= fopen (file
, "r")) != NULL
9225 && (buf
= (char *) xmalloc (st
.st_size
),
9226 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
9247 /***********************************************************************
9249 ***********************************************************************/
9251 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
9252 static int xbm_load_image_from_file
P_ ((struct frame
*f
, struct image
*img
,
9254 static int xbm_image_p
P_ ((Lisp_Object object
));
9255 static int xbm_read_bitmap_file_data
P_ ((char *, int *, int *,
9259 /* Indices of image specification fields in xbm_format, below. */
9261 enum xbm_keyword_index
9279 /* Vector of image_keyword structures describing the format
9280 of valid XBM image specifications. */
9282 static struct image_keyword xbm_format
[XBM_LAST
] =
9284 {":type", IMAGE_SYMBOL_VALUE
, 1},
9285 {":file", IMAGE_STRING_VALUE
, 0},
9286 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9287 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9288 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9289 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
9290 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0},
9291 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9292 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9293 {":relief", IMAGE_INTEGER_VALUE
, 0},
9294 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9295 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9298 /* Structure describing the image type XBM. */
9300 static struct image_type xbm_type
=
9309 /* Tokens returned from xbm_scan. */
9318 /* Return non-zero if OBJECT is a valid XBM-type image specification.
9319 A valid specification is a list starting with the symbol `image'
9320 The rest of the list is a property list which must contain an
9323 If the specification specifies a file to load, it must contain
9324 an entry `:file FILENAME' where FILENAME is a string.
9326 If the specification is for a bitmap loaded from memory it must
9327 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
9328 WIDTH and HEIGHT are integers > 0. DATA may be:
9330 1. a string large enough to hold the bitmap data, i.e. it must
9331 have a size >= (WIDTH + 7) / 8 * HEIGHT
9333 2. a bool-vector of size >= WIDTH * HEIGHT
9335 3. a vector of strings or bool-vectors, one for each line of the
9338 Both the file and data forms may contain the additional entries
9339 `:background COLOR' and `:foreground COLOR'. If not present,
9340 foreground and background of the frame on which the image is
9341 displayed, is used. */
9344 xbm_image_p (object
)
9347 struct image_keyword kw
[XBM_LAST
];
9349 bcopy (xbm_format
, kw
, sizeof kw
);
9350 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
9353 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
9355 if (kw
[XBM_FILE
].count
)
9357 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
9365 /* Entries for `:width', `:height' and `:data' must be present. */
9366 if (!kw
[XBM_WIDTH
].count
9367 || !kw
[XBM_HEIGHT
].count
9368 || !kw
[XBM_DATA
].count
)
9371 data
= kw
[XBM_DATA
].value
;
9372 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
9373 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
9375 /* Check type of data, and width and height against contents of
9381 /* Number of elements of the vector must be >= height. */
9382 if (XVECTOR (data
)->size
< height
)
9385 /* Each string or bool-vector in data must be large enough
9386 for one line of the image. */
9387 for (i
= 0; i
< height
; ++i
)
9389 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
9393 if (XSTRING (elt
)->size
9394 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
9397 else if (BOOL_VECTOR_P (elt
))
9399 if (XBOOL_VECTOR (elt
)->size
< width
)
9406 else if (STRINGP (data
))
9408 if (XSTRING (data
)->size
9409 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
9412 else if (BOOL_VECTOR_P (data
))
9414 if (XBOOL_VECTOR (data
)->size
< width
* height
)
9421 /* Baseline must be a value between 0 and 100 (a percentage). */
9422 if (kw
[XBM_ASCENT
].count
9423 && XFASTINT (kw
[XBM_ASCENT
].value
) > 100)
9430 /* Scan a bitmap file. FP is the stream to read from. Value is
9431 either an enumerator from enum xbm_token, or a character for a
9432 single-character token, or 0 at end of file. If scanning an
9433 identifier, store the lexeme of the identifier in SVAL. If
9434 scanning a number, store its value in *IVAL. */
9437 xbm_scan (s
, end
, sval
, ival
)
9446 /* Skip white space. */
9447 while (*s
< end
&&(c
= *(*s
)++, isspace (c
)))
9452 else if (isdigit (c
))
9454 int value
= 0, digit
;
9456 if (c
== '0' && *s
< end
)
9459 if (c
== 'x' || c
== 'X')
9466 else if (c
>= 'a' && c
<= 'f')
9467 digit
= c
- 'a' + 10;
9468 else if (c
>= 'A' && c
<= 'F')
9469 digit
= c
- 'A' + 10;
9472 value
= 16 * value
+ digit
;
9475 else if (isdigit (c
))
9479 && (c
= *(*s
)++, isdigit (c
)))
9480 value
= 8 * value
+ c
- '0';
9487 && (c
= *(*s
)++, isdigit (c
)))
9488 value
= 10 * value
+ c
- '0';
9496 else if (isalpha (c
) || c
== '_')
9500 && (c
= *(*s
)++, (isalnum (c
) || c
== '_')))
9507 else if (c
== '/' && **s
== '*')
9509 /* C-style comment. */
9511 while (**s
&& (**s
!= '*' || *(*s
+ 1) != '/'))
9524 /* Replacement for XReadBitmapFileData which isn't available under old
9525 X versions. CONTENTS is a pointer to a buffer to parse; END is the
9526 buffer's end. Set *WIDTH and *HEIGHT to the width and height of
9527 the image. Return in *DATA the bitmap data allocated with xmalloc.
9528 Value is non-zero if successful. DATA null means just test if
9529 CONTENTS looks like an in-memory XBM file. */
9532 xbm_read_bitmap_data (contents
, end
, width
, height
, data
)
9533 char *contents
, *end
;
9534 int *width
, *height
;
9535 unsigned char **data
;
9538 char buffer
[BUFSIZ
];
9541 int bytes_per_line
, i
, nbytes
;
9547 LA1 = xbm_scan (contents, end, buffer, &value)
9549 #define expect(TOKEN) \
9550 if (LA1 != (TOKEN)) \
9555 #define expect_ident(IDENT) \
9556 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
9561 *width
= *height
= -1;
9564 LA1
= xbm_scan (&s
, end
, buffer
, &value
);
9566 /* Parse defines for width, height and hot-spots. */
9570 expect_ident ("define");
9571 expect (XBM_TK_IDENT
);
9573 if (LA1
== XBM_TK_NUMBER
);
9575 char *p
= strrchr (buffer
, '_');
9576 p
= p
? p
+ 1 : buffer
;
9577 if (strcmp (p
, "width") == 0)
9579 else if (strcmp (p
, "height") == 0)
9582 expect (XBM_TK_NUMBER
);
9585 if (*width
< 0 || *height
< 0)
9587 else if (data
== NULL
)
9590 /* Parse bits. Must start with `static'. */
9591 expect_ident ("static");
9592 if (LA1
== XBM_TK_IDENT
)
9594 if (strcmp (buffer
, "unsigned") == 0)
9597 expect_ident ("char");
9599 else if (strcmp (buffer
, "short") == 0)
9603 if (*width
% 16 && *width
% 16 < 9)
9606 else if (strcmp (buffer
, "char") == 0)
9614 expect (XBM_TK_IDENT
);
9620 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
9621 nbytes
= bytes_per_line
* *height
;
9622 p
= *data
= (char *) xmalloc (nbytes
);
9627 for (i
= 0; i
< nbytes
; i
+= 2)
9630 expect (XBM_TK_NUMBER
);
9633 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
9636 if (LA1
== ',' || LA1
== '}')
9644 for (i
= 0; i
< nbytes
; ++i
)
9647 expect (XBM_TK_NUMBER
);
9651 if (LA1
== ',' || LA1
== '}')
9676 /* Load XBM image IMG which will be displayed on frame F from buffer
9677 CONTENTS. END is the end of the buffer. Value is non-zero if
9681 xbm_load_image (f
, img
, contents
, end
)
9684 char *contents
, *end
;
9687 unsigned char *data
;
9690 rc
= xbm_read_bitmap_data (contents
, end
, &img
->width
, &img
->height
, &data
);
9693 int depth
= one_w32_display_info
.n_cbits
;
9694 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
9695 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
9698 xassert (img
->width
> 0 && img
->height
> 0);
9700 /* Get foreground and background colors, maybe allocate colors. */
9701 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
9703 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
9704 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
9707 background
= x_alloc_image_color (f
, img
, value
, background
);
9708 img
->background
= background
;
9709 img
->background_valid
= 1;
9712 #if 0 /* TODO : Port image display to W32 */
9714 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
9715 FRAME_W32_WINDOW (f
),
9717 img
->width
, img
->height
,
9718 foreground
, background
,
9723 if (img
->pixmap
== 0)
9725 x_clear_image (f
, img
);
9726 image_error ("Unable to create X pixmap for `%s'", img
->spec
, Qnil
);
9732 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
9738 /* Value is non-zero if DATA looks like an in-memory XBM file. */
9745 return (STRINGP (data
)
9746 && xbm_read_bitmap_data (XSTRING (data
)->data
,
9747 (XSTRING (data
)->data
9748 + STRING_BYTES (XSTRING (data
))),
9753 /* Fill image IMG which is used on frame F with pixmap data. Value is
9754 non-zero if successful. */
9762 Lisp_Object file_name
;
9764 xassert (xbm_image_p (img
->spec
));
9766 /* If IMG->spec specifies a file name, create a non-file spec from it. */
9767 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
9768 if (STRINGP (file_name
))
9773 struct gcpro gcpro1
;
9775 file
= x_find_image_file (file_name
);
9777 if (!STRINGP (file
))
9779 image_error ("Cannot find image file `%s'", file_name
, Qnil
);
9784 contents
= slurp_file (XSTRING (file
)->data
, &size
);
9785 if (contents
== NULL
)
9787 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
9792 success_p
= xbm_load_image (f
, img
, contents
, contents
+ size
);
9797 struct image_keyword fmt
[XBM_LAST
];
9800 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
9801 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
9804 int in_memory_file_p
= 0;
9806 /* See if data looks like an in-memory XBM file. */
9807 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
9808 in_memory_file_p
= xbm_file_p (data
);
9810 /* Parse the list specification. */
9811 bcopy (xbm_format
, fmt
, sizeof fmt
);
9812 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
9815 /* Get specified width, and height. */
9816 if (!in_memory_file_p
)
9818 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
9819 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
9820 xassert (img
->width
> 0 && img
->height
> 0);
9822 /* Get foreground and background colors, maybe allocate colors. */
9823 if (fmt
[XBM_FOREGROUND
].count
9824 && STRINGP (fmt
[XBM_FOREGROUND
].value
))
9825 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
9827 if (fmt
[XBM_BACKGROUND
].count
9828 && STRINGP (fmt
[XBM_BACKGROUND
].value
))
9829 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
9832 if (in_memory_file_p
)
9833 success_p
= xbm_load_image (f
, img
, XSTRING (data
)->data
,
9834 (XSTRING (data
)->data
9835 + STRING_BYTES (XSTRING (data
))));
9842 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
9844 p
= bits
= (char *) alloca (nbytes
* img
->height
);
9845 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
9847 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
9849 bcopy (XSTRING (line
)->data
, p
, nbytes
);
9851 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
9854 else if (STRINGP (data
))
9855 bits
= XSTRING (data
)->data
;
9857 bits
= XBOOL_VECTOR (data
)->data
;
9858 #ifdef TODO /* image support. */
9859 /* Create the pixmap. */
9860 depth
= one_w32_display_info
.n_cbits
;
9862 = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f
),
9865 img
->width
, img
->height
,
9866 foreground
, background
,
9873 image_error ("Unable to create pixmap for XBM image `%s'",
9875 x_clear_image (f
, img
);
9885 /***********************************************************************
9887 ***********************************************************************/
9891 static int xpm_image_p
P_ ((Lisp_Object object
));
9892 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
9893 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
9895 #include "X11/xpm.h"
9897 /* The symbol `xpm' identifying XPM-format images. */
9901 /* Indices of image specification fields in xpm_format, below. */
9903 enum xpm_keyword_index
9919 /* Vector of image_keyword structures describing the format
9920 of valid XPM image specifications. */
9922 static struct image_keyword xpm_format
[XPM_LAST
] =
9924 {":type", IMAGE_SYMBOL_VALUE
, 1},
9925 {":file", IMAGE_STRING_VALUE
, 0},
9926 {":data", IMAGE_STRING_VALUE
, 0},
9927 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9928 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9929 {":relief", IMAGE_INTEGER_VALUE
, 0},
9930 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9931 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9932 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9933 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9934 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
9937 /* Structure describing the image type XBM. */
9939 static struct image_type xpm_type
=
9949 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
9950 for XPM images. Such a list must consist of conses whose car and
9954 xpm_valid_color_symbols_p (color_symbols
)
9955 Lisp_Object color_symbols
;
9957 while (CONSP (color_symbols
))
9959 Lisp_Object sym
= XCAR (color_symbols
);
9961 || !STRINGP (XCAR (sym
))
9962 || !STRINGP (XCDR (sym
)))
9964 color_symbols
= XCDR (color_symbols
);
9967 return NILP (color_symbols
);
9971 /* Value is non-zero if OBJECT is a valid XPM image specification. */
9974 xpm_image_p (object
)
9977 struct image_keyword fmt
[XPM_LAST
];
9978 bcopy (xpm_format
, fmt
, sizeof fmt
);
9979 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
9980 /* Either `:file' or `:data' must be present. */
9981 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
9982 /* Either no `:color-symbols' or it's a list of conses
9983 whose car and cdr are strings. */
9984 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
9985 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
9986 && (fmt
[XPM_ASCENT
].count
== 0
9987 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
9991 /* Load image IMG which will be displayed on frame F. Value is
9992 non-zero if successful. */
10000 XpmAttributes attrs
;
10001 Lisp_Object specified_file
, color_symbols
;
10003 /* Configure the XPM lib. Use the visual of frame F. Allocate
10004 close colors. Return colors allocated. */
10005 bzero (&attrs
, sizeof attrs
);
10006 attrs
.visual
= FRAME_X_VISUAL (f
);
10007 attrs
.colormap
= FRAME_X_COLORMAP (f
);
10008 attrs
.valuemask
|= XpmVisual
;
10009 attrs
.valuemask
|= XpmColormap
;
10010 attrs
.valuemask
|= XpmReturnAllocPixels
;
10011 #ifdef XpmAllocCloseColors
10012 attrs
.alloc_close_colors
= 1;
10013 attrs
.valuemask
|= XpmAllocCloseColors
;
10015 attrs
.closeness
= 600;
10016 attrs
.valuemask
|= XpmCloseness
;
10019 /* If image specification contains symbolic color definitions, add
10020 these to `attrs'. */
10021 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
10022 if (CONSP (color_symbols
))
10025 XpmColorSymbol
*xpm_syms
;
10028 attrs
.valuemask
|= XpmColorSymbols
;
10030 /* Count number of symbols. */
10031 attrs
.numsymbols
= 0;
10032 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
10033 ++attrs
.numsymbols
;
10035 /* Allocate an XpmColorSymbol array. */
10036 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
10037 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
10038 bzero (xpm_syms
, size
);
10039 attrs
.colorsymbols
= xpm_syms
;
10041 /* Fill the color symbol array. */
10042 for (tail
= color_symbols
, i
= 0;
10044 ++i
, tail
= XCDR (tail
))
10046 Lisp_Object name
= XCAR (XCAR (tail
));
10047 Lisp_Object color
= XCDR (XCAR (tail
));
10048 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
10049 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
10050 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
10051 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
10055 /* Create a pixmap for the image, either from a file, or from a
10056 string buffer containing data in the same format as an XPM file. */
10058 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10059 if (STRINGP (specified_file
))
10061 Lisp_Object file
= x_find_image_file (specified_file
);
10062 if (!STRINGP (file
))
10064 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10069 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
10070 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
10075 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
10076 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
10077 XSTRING (buffer
)->data
,
10078 &img
->pixmap
, &img
->mask
,
10083 if (rc
== XpmSuccess
)
10085 /* Remember allocated colors. */
10086 img
->ncolors
= attrs
.nalloc_pixels
;
10087 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
10088 * sizeof *img
->colors
);
10089 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
10090 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
10092 img
->width
= attrs
.width
;
10093 img
->height
= attrs
.height
;
10094 xassert (img
->width
> 0 && img
->height
> 0);
10096 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
10098 XpmFreeAttributes (&attrs
);
10105 case XpmOpenFailed
:
10106 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
10109 case XpmFileInvalid
:
10110 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
10114 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
10117 case XpmColorFailed
:
10118 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
10122 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
10127 return rc
== XpmSuccess
;
10130 #endif /* HAVE_XPM != 0 */
10133 #if 0 /* TODO : Color tables on W32. */
10134 /***********************************************************************
10136 ***********************************************************************/
10138 /* An entry in the color table mapping an RGB color to a pixel color. */
10143 unsigned long pixel
;
10145 /* Next in color table collision list. */
10146 struct ct_color
*next
;
10149 /* The bucket vector size to use. Must be prime. */
10151 #define CT_SIZE 101
10153 /* Value is a hash of the RGB color given by R, G, and B. */
10155 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
10157 /* The color hash table. */
10159 struct ct_color
**ct_table
;
10161 /* Number of entries in the color table. */
10163 int ct_colors_allocated
;
10165 /* Function prototypes. */
10167 static void init_color_table
P_ ((void));
10168 static void free_color_table
P_ ((void));
10169 static unsigned long *colors_in_color_table
P_ ((int *n
));
10170 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
10171 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
10174 /* Initialize the color table. */
10177 init_color_table ()
10179 int size
= CT_SIZE
* sizeof (*ct_table
);
10180 ct_table
= (struct ct_color
**) xmalloc (size
);
10181 bzero (ct_table
, size
);
10182 ct_colors_allocated
= 0;
10186 /* Free memory associated with the color table. */
10189 free_color_table ()
10192 struct ct_color
*p
, *next
;
10194 for (i
= 0; i
< CT_SIZE
; ++i
)
10195 for (p
= ct_table
[i
]; p
; p
= next
)
10206 /* Value is a pixel color for RGB color R, G, B on frame F. If an
10207 entry for that color already is in the color table, return the
10208 pixel color of that entry. Otherwise, allocate a new color for R,
10209 G, B, and make an entry in the color table. */
10211 static unsigned long
10212 lookup_rgb_color (f
, r
, g
, b
)
10216 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
10217 int i
= hash
% CT_SIZE
;
10218 struct ct_color
*p
;
10220 for (p
= ct_table
[i
]; p
; p
= p
->next
)
10221 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
10230 color
= PALETTERGB (r
, g
, b
);
10232 ++ct_colors_allocated
;
10234 p
= (struct ct_color
*) xmalloc (sizeof *p
);
10239 p
->next
= ct_table
[i
];
10247 /* Look up pixel color PIXEL which is used on frame F in the color
10248 table. If not already present, allocate it. Value is PIXEL. */
10250 static unsigned long
10251 lookup_pixel_color (f
, pixel
)
10253 unsigned long pixel
;
10255 int i
= pixel
% CT_SIZE
;
10256 struct ct_color
*p
;
10258 for (p
= ct_table
[i
]; p
; p
= p
->next
)
10259 if (p
->pixel
== pixel
)
10270 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10271 color
.pixel
= pixel
;
10272 XQueryColor (NULL
, cmap
, &color
);
10273 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
10278 ++ct_colors_allocated
;
10280 p
= (struct ct_color
*) xmalloc (sizeof *p
);
10282 p
->g
= color
.green
;
10285 p
->next
= ct_table
[i
];
10289 return FRAME_FOREGROUND_PIXEL (f
);
10295 /* Value is a vector of all pixel colors contained in the color table,
10296 allocated via xmalloc. Set *N to the number of colors. */
10298 static unsigned long *
10299 colors_in_color_table (n
)
10303 struct ct_color
*p
;
10304 unsigned long *colors
;
10306 if (ct_colors_allocated
== 0)
10313 colors
= (unsigned long *) xmalloc (ct_colors_allocated
10315 *n
= ct_colors_allocated
;
10317 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
10318 for (p
= ct_table
[i
]; p
; p
= p
->next
)
10319 colors
[j
++] = p
->pixel
;
10328 /***********************************************************************
10330 ***********************************************************************/
10331 #if 0 /* TODO: image support. */
10332 static XColor
*x_to_xcolors
P_ ((struct frame
*, struct image
*, int));
10333 static void x_from_xcolors
P_ ((struct frame
*, struct image
*, XColor
*));
10334 static void x_detect_edges
P_ ((struct frame
*, struct image
*, int[9], int));
10336 /* Non-zero means draw a cross on images having `:conversion
10339 int cross_disabled_images
;
10341 /* Edge detection matrices for different edge-detection
10344 static int emboss_matrix
[9] = {
10345 /* x - 1 x x + 1 */
10346 2, -1, 0, /* y - 1 */
10348 0, 1, -2 /* y + 1 */
10351 static int laplace_matrix
[9] = {
10352 /* x - 1 x x + 1 */
10353 1, 0, 0, /* y - 1 */
10355 0, 0, -1 /* y + 1 */
10358 /* Value is the intensity of the color whose red/green/blue values
10359 are R, G, and B. */
10361 #define COLOR_INTENSITY(R, G, B) ((2 * (R) + 3 * (G) + (B)) / 6)
10364 /* On frame F, return an array of XColor structures describing image
10365 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P
10366 non-zero means also fill the red/green/blue members of the XColor
10367 structures. Value is a pointer to the array of XColors structures,
10368 allocated with xmalloc; it must be freed by the caller. */
10371 x_to_xcolors (f
, img
, rgb_p
)
10377 XColor
*colors
, *p
;
10380 colors
= (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *colors
);
10382 /* Get the X image IMG->pixmap. */
10383 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
10384 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
10386 /* Fill the `pixel' members of the XColor array. I wished there
10387 were an easy and portable way to circumvent XGetPixel. */
10389 for (y
= 0; y
< img
->height
; ++y
)
10393 for (x
= 0; x
< img
->width
; ++x
, ++p
)
10394 p
->pixel
= XGetPixel (ximg
, x
, y
);
10397 x_query_colors (f
, row
, img
->width
);
10400 XDestroyImage (ximg
);
10405 /* Create IMG->pixmap from an array COLORS of XColor structures, whose
10406 RGB members are set. F is the frame on which this all happens.
10407 COLORS will be freed; an existing IMG->pixmap will be freed, too. */
10410 x_from_xcolors (f
, img
, colors
)
10420 init_color_table ();
10422 x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
10425 for (y
= 0; y
< img
->height
; ++y
)
10426 for (x
= 0; x
< img
->width
; ++x
, ++p
)
10428 unsigned long pixel
;
10429 pixel
= lookup_rgb_color (f
, p
->red
, p
->green
, p
->blue
);
10430 XPutPixel (oimg
, x
, y
, pixel
);
10434 x_clear_image_1 (f
, img
, 1, 0, 1);
10436 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
10437 x_destroy_x_image (oimg
);
10438 img
->pixmap
= pixmap
;
10439 img
->colors
= colors_in_color_table (&img
->ncolors
);
10440 free_color_table ();
10444 /* On frame F, perform edge-detection on image IMG.
10446 MATRIX is a nine-element array specifying the transformation
10447 matrix. See emboss_matrix for an example.
10449 COLOR_ADJUST is a color adjustment added to each pixel of the
10453 x_detect_edges (f
, img
, matrix
, color_adjust
)
10456 int matrix
[9], color_adjust
;
10458 XColor
*colors
= x_to_xcolors (f
, img
, 1);
10462 for (i
= sum
= 0; i
< 9; ++i
)
10463 sum
+= abs (matrix
[i
]);
10465 #define COLOR(A, X, Y) ((A) + (Y) * img->width + (X))
10467 new = (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *new);
10469 for (y
= 0; y
< img
->height
; ++y
)
10471 p
= COLOR (new, 0, y
);
10472 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10473 p
= COLOR (new, img
->width
- 1, y
);
10474 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10477 for (x
= 1; x
< img
->width
- 1; ++x
)
10479 p
= COLOR (new, x
, 0);
10480 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10481 p
= COLOR (new, x
, img
->height
- 1);
10482 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10485 for (y
= 1; y
< img
->height
- 1; ++y
)
10487 p
= COLOR (new, 1, y
);
10489 for (x
= 1; x
< img
->width
- 1; ++x
, ++p
)
10491 int r
, g
, b
, y1
, x1
;
10494 for (y1
= y
- 1; y1
< y
+ 2; ++y1
)
10495 for (x1
= x
- 1; x1
< x
+ 2; ++x1
, ++i
)
10498 XColor
*t
= COLOR (colors
, x1
, y1
);
10499 r
+= matrix
[i
] * t
->red
;
10500 g
+= matrix
[i
] * t
->green
;
10501 b
+= matrix
[i
] * t
->blue
;
10504 r
= (r
/ sum
+ color_adjust
) & 0xffff;
10505 g
= (g
/ sum
+ color_adjust
) & 0xffff;
10506 b
= (b
/ sum
+ color_adjust
) & 0xffff;
10507 p
->red
= p
->green
= p
->blue
= COLOR_INTENSITY (r
, g
, b
);
10512 x_from_xcolors (f
, img
, new);
10518 /* Perform the pre-defined `emboss' edge-detection on image IMG
10526 x_detect_edges (f
, img
, emboss_matrix
, 0xffff / 2);
10530 /* Transform image IMG which is used on frame F with a Laplace
10531 edge-detection algorithm. The result is an image that can be used
10532 to draw disabled buttons, for example. */
10539 x_detect_edges (f
, img
, laplace_matrix
, 45000);
10543 /* Perform edge-detection on image IMG on frame F, with specified
10544 transformation matrix MATRIX and color-adjustment COLOR_ADJUST.
10546 MATRIX must be either
10548 - a list of at least 9 numbers in row-major form
10549 - a vector of at least 9 numbers
10551 COLOR_ADJUST nil means use a default; otherwise it must be a
10555 x_edge_detection (f
, img
, matrix
, color_adjust
)
10558 Lisp_Object matrix
, color_adjust
;
10563 if (CONSP (matrix
))
10566 i
< 9 && CONSP (matrix
) && NUMBERP (XCAR (matrix
));
10567 ++i
, matrix
= XCDR (matrix
))
10568 trans
[i
] = XFLOATINT (XCAR (matrix
));
10570 else if (VECTORP (matrix
) && ASIZE (matrix
) >= 9)
10572 for (i
= 0; i
< 9 && NUMBERP (AREF (matrix
, i
)); ++i
)
10573 trans
[i
] = XFLOATINT (AREF (matrix
, i
));
10576 if (NILP (color_adjust
))
10577 color_adjust
= make_number (0xffff / 2);
10579 if (i
== 9 && NUMBERP (color_adjust
))
10580 x_detect_edges (f
, img
, trans
, (int) XFLOATINT (color_adjust
));
10584 /* Transform image IMG on frame F so that it looks disabled. */
10587 x_disable_image (f
, img
)
10591 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10593 if (dpyinfo
->n_planes
>= 2)
10595 /* Color (or grayscale). Convert to gray, and equalize. Just
10596 drawing such images with a stipple can look very odd, so
10597 we're using this method instead. */
10598 XColor
*colors
= x_to_xcolors (f
, img
, 1);
10600 const int h
= 15000;
10601 const int l
= 30000;
10603 for (p
= colors
, end
= colors
+ img
->width
* img
->height
;
10607 int i
= COLOR_INTENSITY (p
->red
, p
->green
, p
->blue
);
10608 int i2
= (0xffff - h
- l
) * i
/ 0xffff + l
;
10609 p
->red
= p
->green
= p
->blue
= i2
;
10612 x_from_xcolors (f
, img
, colors
);
10615 /* Draw a cross over the disabled image, if we must or if we
10617 if (dpyinfo
->n_planes
< 2 || cross_disabled_images
)
10619 Display
*dpy
= FRAME_X_DISPLAY (f
);
10622 gc
= XCreateGC (dpy
, img
->pixmap
, 0, NULL
);
10623 XSetForeground (dpy
, gc
, BLACK_PIX_DEFAULT (f
));
10624 XDrawLine (dpy
, img
->pixmap
, gc
, 0, 0,
10625 img
->width
- 1, img
->height
- 1);
10626 XDrawLine (dpy
, img
->pixmap
, gc
, 0, img
->height
- 1,
10627 img
->width
- 1, 0);
10632 gc
= XCreateGC (dpy
, img
->mask
, 0, NULL
);
10633 XSetForeground (dpy
, gc
, WHITE_PIX_DEFAULT (f
));
10634 XDrawLine (dpy
, img
->mask
, gc
, 0, 0,
10635 img
->width
- 1, img
->height
- 1);
10636 XDrawLine (dpy
, img
->mask
, gc
, 0, img
->height
- 1,
10637 img
->width
- 1, 0);
10644 /* Build a mask for image IMG which is used on frame F. FILE is the
10645 name of an image file, for error messages. HOW determines how to
10646 determine the background color of IMG. If it is a list '(R G B)',
10647 with R, G, and B being integers >= 0, take that as the color of the
10648 background. Otherwise, determine the background color of IMG
10649 heuristically. Value is non-zero if successful. */
10652 x_build_heuristic_mask (f
, img
, how
)
10657 Display
*dpy
= FRAME_W32_DISPLAY (f
);
10658 XImage
*ximg
, *mask_img
;
10659 int x
, y
, rc
, use_img_background
;
10660 unsigned long bg
= 0;
10664 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
10666 img
->background_transparent_valid
= 0;
10669 /* Create an image and pixmap serving as mask. */
10670 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
10671 &mask_img
, &img
->mask
);
10675 /* Get the X image of IMG->pixmap. */
10676 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
10679 /* Determine the background color of ximg. If HOW is `(R G B)'
10680 take that as color. Otherwise, use the image's background color. */
10681 use_img_background
= 1;
10687 for (i
= 0; i
< 3 && CONSP (how
) && NATNUMP (XCAR (how
)); ++i
)
10689 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
10693 if (i
== 3 && NILP (how
))
10695 char color_name
[30];
10696 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
10697 bg
= x_alloc_image_color (f
, img
, build_string (color_name
), 0);
10698 use_img_background
= 0;
10702 if (use_img_background
)
10703 bg
= four_corners_best (ximg
, img
->width
, img
->height
);
10705 /* Set all bits in mask_img to 1 whose color in ximg is different
10706 from the background color bg. */
10707 for (y
= 0; y
< img
->height
; ++y
)
10708 for (x
= 0; x
< img
->width
; ++x
)
10709 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
10711 /* Fill in the background_transparent field while we have the mask handy. */
10712 image_background_transparent (img
, f
, mask_img
);
10714 /* Put mask_img into img->mask. */
10715 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10716 x_destroy_x_image (mask_img
);
10717 XDestroyImage (ximg
);
10724 /***********************************************************************
10725 PBM (mono, gray, color)
10726 ***********************************************************************/
10729 static int pbm_image_p
P_ ((Lisp_Object object
));
10730 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
10731 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
10733 /* The symbol `pbm' identifying images of this type. */
10737 /* Indices of image specification fields in gs_format, below. */
10739 enum pbm_keyword_index
10748 PBM_HEURISTIC_MASK
,
10755 /* Vector of image_keyword structures describing the format
10756 of valid user-defined image specifications. */
10758 static struct image_keyword pbm_format
[PBM_LAST
] =
10760 {":type", IMAGE_SYMBOL_VALUE
, 1},
10761 {":file", IMAGE_STRING_VALUE
, 0},
10762 {":data", IMAGE_STRING_VALUE
, 0},
10763 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10764 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
10765 {":relief", IMAGE_INTEGER_VALUE
, 0},
10766 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10767 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10768 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10769 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
10770 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
10773 /* Structure describing the image type `pbm'. */
10775 static struct image_type pbm_type
=
10785 /* Return non-zero if OBJECT is a valid PBM image specification. */
10788 pbm_image_p (object
)
10789 Lisp_Object object
;
10791 struct image_keyword fmt
[PBM_LAST
];
10793 bcopy (pbm_format
, fmt
, sizeof fmt
);
10795 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
10796 || (fmt
[PBM_ASCENT
].count
10797 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
10800 /* Must specify either :data or :file. */
10801 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
10805 /* Scan a decimal number from *S and return it. Advance *S while
10806 reading the number. END is the end of the string. Value is -1 at
10810 pbm_scan_number (s
, end
)
10811 unsigned char **s
, *end
;
10817 /* Skip white-space. */
10818 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
10823 /* Skip comment to end of line. */
10824 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
10827 else if (isdigit (c
))
10829 /* Read decimal number. */
10831 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
10832 val
= 10 * val
+ c
- '0';
10843 /* Read FILE into memory. Value is a pointer to a buffer allocated
10844 with xmalloc holding FILE's contents. Value is null if an error
10845 occured. *SIZE is set to the size of the file. */
10848 pbm_read_file (file
, size
)
10856 if (stat (XSTRING (file
)->data
, &st
) == 0
10857 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
10858 && (buf
= (char *) xmalloc (st
.st_size
),
10859 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
10861 *size
= st
.st_size
;
10879 /* Load PBM image IMG for use on frame F. */
10887 int width
, height
, max_color_idx
= 0;
10889 Lisp_Object file
, specified_file
;
10890 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
10891 struct gcpro gcpro1
;
10892 unsigned char *contents
= NULL
;
10893 unsigned char *end
, *p
;
10896 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10900 if (STRINGP (specified_file
))
10902 file
= x_find_image_file (specified_file
);
10903 if (!STRINGP (file
))
10905 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10910 contents
= slurp_file (XSTRING (file
)->data
, &size
);
10911 if (contents
== NULL
)
10913 image_error ("Error reading `%s'", file
, Qnil
);
10919 end
= contents
+ size
;
10924 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10925 p
= XSTRING (data
)->data
;
10926 end
= p
+ STRING_BYTES (XSTRING (data
));
10929 /* Check magic number. */
10930 if (end
- p
< 2 || *p
++ != 'P')
10932 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
10942 raw_p
= 0, type
= PBM_MONO
;
10946 raw_p
= 0, type
= PBM_GRAY
;
10950 raw_p
= 0, type
= PBM_COLOR
;
10954 raw_p
= 1, type
= PBM_MONO
;
10958 raw_p
= 1, type
= PBM_GRAY
;
10962 raw_p
= 1, type
= PBM_COLOR
;
10966 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
10970 /* Read width, height, maximum color-component. Characters
10971 starting with `#' up to the end of a line are ignored. */
10972 width
= pbm_scan_number (&p
, end
);
10973 height
= pbm_scan_number (&p
, end
);
10975 if (type
!= PBM_MONO
)
10977 max_color_idx
= pbm_scan_number (&p
, end
);
10978 if (raw_p
&& max_color_idx
> 255)
10979 max_color_idx
= 255;
10984 || (type
!= PBM_MONO
&& max_color_idx
< 0))
10987 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
10988 &ximg
, &img
->pixmap
))
10991 /* Initialize the color hash table. */
10992 init_color_table ();
10994 if (type
== PBM_MONO
)
10997 struct image_keyword fmt
[PBM_LAST
];
10998 unsigned long fg
= FRAME_FOREGROUND_PIXEL (f
);
10999 unsigned long bg
= FRAME_BACKGROUND_PIXEL (f
);
11001 /* Parse the image specification. */
11002 bcopy (pbm_format
, fmt
, sizeof fmt
);
11003 parse_image_spec (img
->spec
, fmt
, PBM_LAST
, Qpbm
);
11005 /* Get foreground and background colors, maybe allocate colors. */
11006 if (fmt
[PBM_FOREGROUND
].count
11007 && STRINGP (fmt
[PBM_FOREGROUND
].value
))
11008 fg
= x_alloc_image_color (f
, img
, fmt
[PBM_FOREGROUND
].value
, fg
);
11009 if (fmt
[PBM_BACKGROUND
].count
11010 && STRINGP (fmt
[PBM_BACKGROUND
].value
))
11012 bg
= x_alloc_image_color (f
, img
, fmt
[PBM_BACKGROUND
].value
, bg
);
11013 img
->background
= bg
;
11014 img
->background_valid
= 1;
11017 for (y
= 0; y
< height
; ++y
)
11018 for (x
= 0; x
< width
; ++x
)
11028 g
= pbm_scan_number (&p
, end
);
11030 XPutPixel (ximg
, x
, y
, g
? fg
: bg
);
11035 for (y
= 0; y
< height
; ++y
)
11036 for (x
= 0; x
< width
; ++x
)
11040 if (type
== PBM_GRAY
)
11041 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
11050 r
= pbm_scan_number (&p
, end
);
11051 g
= pbm_scan_number (&p
, end
);
11052 b
= pbm_scan_number (&p
, end
);
11055 if (r
< 0 || g
< 0 || b
< 0)
11057 xfree (ximg
->data
);
11059 XDestroyImage (ximg
);
11060 image_error ("Invalid pixel value in image `%s'",
11065 /* RGB values are now in the range 0..max_color_idx.
11066 Scale this to the range 0..0xffff supported by X. */
11067 r
= (double) r
* 65535 / max_color_idx
;
11068 g
= (double) g
* 65535 / max_color_idx
;
11069 b
= (double) b
* 65535 / max_color_idx
;
11070 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
11074 /* Store in IMG->colors the colors allocated for the image, and
11075 free the color table. */
11076 img
->colors
= colors_in_color_table (&img
->ncolors
);
11077 free_color_table ();
11079 /* Maybe fill in the background field while we have ximg handy. */
11080 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
11081 IMAGE_BACKGROUND (img
, f
, ximg
);
11083 /* Put the image into a pixmap. */
11084 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11085 x_destroy_x_image (ximg
);
11087 img
->width
= width
;
11088 img
->height
= height
;
11094 #endif /* HAVE_PBM */
11097 /***********************************************************************
11099 ***********************************************************************/
11105 /* Function prototypes. */
11107 static int png_image_p
P_ ((Lisp_Object object
));
11108 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
11110 /* The symbol `png' identifying images of this type. */
11114 /* Indices of image specification fields in png_format, below. */
11116 enum png_keyword_index
11125 PNG_HEURISTIC_MASK
,
11131 /* Vector of image_keyword structures describing the format
11132 of valid user-defined image specifications. */
11134 static struct image_keyword png_format
[PNG_LAST
] =
11136 {":type", IMAGE_SYMBOL_VALUE
, 1},
11137 {":data", IMAGE_STRING_VALUE
, 0},
11138 {":file", IMAGE_STRING_VALUE
, 0},
11139 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11140 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11141 {":relief", IMAGE_INTEGER_VALUE
, 0},
11142 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11143 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11144 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11145 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
11148 /* Structure describing the image type `png'. */
11150 static struct image_type png_type
=
11160 /* Return non-zero if OBJECT is a valid PNG image specification. */
11163 png_image_p (object
)
11164 Lisp_Object object
;
11166 struct image_keyword fmt
[PNG_LAST
];
11167 bcopy (png_format
, fmt
, sizeof fmt
);
11169 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
11170 || (fmt
[PNG_ASCENT
].count
11171 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
11174 /* Must specify either the :data or :file keyword. */
11175 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
11179 /* Error and warning handlers installed when the PNG library
11183 my_png_error (png_ptr
, msg
)
11184 png_struct
*png_ptr
;
11187 xassert (png_ptr
!= NULL
);
11188 image_error ("PNG error: %s", build_string (msg
), Qnil
);
11189 longjmp (png_ptr
->jmpbuf
, 1);
11194 my_png_warning (png_ptr
, msg
)
11195 png_struct
*png_ptr
;
11198 xassert (png_ptr
!= NULL
);
11199 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
11202 /* Memory source for PNG decoding. */
11204 struct png_memory_storage
11206 unsigned char *bytes
; /* The data */
11207 size_t len
; /* How big is it? */
11208 int index
; /* Where are we? */
11212 /* Function set as reader function when reading PNG image from memory.
11213 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
11214 bytes from the input to DATA. */
11217 png_read_from_memory (png_ptr
, data
, length
)
11218 png_structp png_ptr
;
11222 struct png_memory_storage
*tbr
11223 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
11225 if (length
> tbr
->len
- tbr
->index
)
11226 png_error (png_ptr
, "Read error");
11228 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
11229 tbr
->index
= tbr
->index
+ length
;
11232 /* Load PNG image IMG for use on frame F. Value is non-zero if
11240 Lisp_Object file
, specified_file
;
11241 Lisp_Object specified_data
;
11243 XImage
*ximg
, *mask_img
= NULL
;
11244 struct gcpro gcpro1
;
11245 png_struct
*png_ptr
= NULL
;
11246 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
11247 FILE *volatile fp
= NULL
;
11249 png_byte
*volatile pixels
= NULL
;
11250 png_byte
**volatile rows
= NULL
;
11251 png_uint_32 width
, height
;
11252 int bit_depth
, color_type
, interlace_type
;
11254 png_uint_32 row_bytes
;
11257 double screen_gamma
, image_gamma
;
11259 struct png_memory_storage tbr
; /* Data to be read */
11261 /* Find out what file to load. */
11262 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11263 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11267 if (NILP (specified_data
))
11269 file
= x_find_image_file (specified_file
);
11270 if (!STRINGP (file
))
11272 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11277 /* Open the image file. */
11278 fp
= fopen (XSTRING (file
)->data
, "rb");
11281 image_error ("Cannot open image file `%s'", file
, Qnil
);
11287 /* Check PNG signature. */
11288 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
11289 || !png_check_sig (sig
, sizeof sig
))
11291 image_error ("Not a PNG file:` %s'", file
, Qnil
);
11299 /* Read from memory. */
11300 tbr
.bytes
= XSTRING (specified_data
)->data
;
11301 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
11304 /* Check PNG signature. */
11305 if (tbr
.len
< sizeof sig
11306 || !png_check_sig (tbr
.bytes
, sizeof sig
))
11308 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
11313 /* Need to skip past the signature. */
11314 tbr
.bytes
+= sizeof (sig
);
11317 /* Initialize read and info structs for PNG lib. */
11318 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
11319 my_png_error
, my_png_warning
);
11322 if (fp
) fclose (fp
);
11327 info_ptr
= png_create_info_struct (png_ptr
);
11330 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
11331 if (fp
) fclose (fp
);
11336 end_info
= png_create_info_struct (png_ptr
);
11339 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
11340 if (fp
) fclose (fp
);
11345 /* Set error jump-back. We come back here when the PNG library
11346 detects an error. */
11347 if (setjmp (png_ptr
->jmpbuf
))
11351 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
11354 if (fp
) fclose (fp
);
11359 /* Read image info. */
11360 if (!NILP (specified_data
))
11361 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
11363 png_init_io (png_ptr
, fp
);
11365 png_set_sig_bytes (png_ptr
, sizeof sig
);
11366 png_read_info (png_ptr
, info_ptr
);
11367 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
11368 &interlace_type
, NULL
, NULL
);
11370 /* If image contains simply transparency data, we prefer to
11371 construct a clipping mask. */
11372 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
11377 /* This function is easier to write if we only have to handle
11378 one data format: RGB or RGBA with 8 bits per channel. Let's
11379 transform other formats into that format. */
11381 /* Strip more than 8 bits per channel. */
11382 if (bit_depth
== 16)
11383 png_set_strip_16 (png_ptr
);
11385 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
11387 png_set_expand (png_ptr
);
11389 /* Convert grayscale images to RGB. */
11390 if (color_type
== PNG_COLOR_TYPE_GRAY
11391 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
11392 png_set_gray_to_rgb (png_ptr
);
11394 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
11395 gamma_str
= getenv ("SCREEN_GAMMA");
11396 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
11398 /* Tell the PNG lib to handle gamma correction for us. */
11400 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
11401 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
11402 /* There is a special chunk in the image specifying the gamma. */
11403 png_set_sRGB (png_ptr
, info_ptr
, intent
);
11406 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
11407 /* Image contains gamma information. */
11408 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
11410 /* Use a default of 0.5 for the image gamma. */
11411 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
11413 /* Handle alpha channel by combining the image with a background
11414 color. Do this only if a real alpha channel is supplied. For
11415 simple transparency, we prefer a clipping mask. */
11416 if (!transparent_p
)
11418 png_color_16
*image_background
;
11419 Lisp_Object specified_bg
11420 = image_spec_value (img
->spec
, QCbackground
, NULL
);
11423 if (STRINGP (specified_bg
))
11424 /* The user specified `:background', use that. */
11427 if (w32_defined_color (f
, XSTRING (specified_bg
)->data
, &color
, 0))
11429 png_color_16 user_bg
;
11431 bzero (&user_bg
, sizeof user_bg
);
11432 user_bg
.red
= color
.red
;
11433 user_bg
.green
= color
.green
;
11434 user_bg
.blue
= color
.blue
;
11436 png_set_background (png_ptr
, &user_bg
,
11437 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
11440 else if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
11441 /* Image contains a background color with which to
11442 combine the image. */
11443 png_set_background (png_ptr
, image_background
,
11444 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
11447 /* Image does not contain a background color with which
11448 to combine the image data via an alpha channel. Use
11449 the frame's background instead. */
11452 png_color_16 frame_background
;
11454 cmap
= FRAME_X_COLORMAP (f
);
11455 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
11456 x_query_color (f
, &color
);
11458 bzero (&frame_background
, sizeof frame_background
);
11459 frame_background
.red
= color
.red
;
11460 frame_background
.green
= color
.green
;
11461 frame_background
.blue
= color
.blue
;
11463 png_set_background (png_ptr
, &frame_background
,
11464 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
11468 /* Update info structure. */
11469 png_read_update_info (png_ptr
, info_ptr
);
11471 /* Get number of channels. Valid values are 1 for grayscale images
11472 and images with a palette, 2 for grayscale images with transparency
11473 information (alpha channel), 3 for RGB images, and 4 for RGB
11474 images with alpha channel, i.e. RGBA. If conversions above were
11475 sufficient we should only have 3 or 4 channels here. */
11476 channels
= png_get_channels (png_ptr
, info_ptr
);
11477 xassert (channels
== 3 || channels
== 4);
11479 /* Number of bytes needed for one row of the image. */
11480 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
11482 /* Allocate memory for the image. */
11483 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
11484 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
11485 for (i
= 0; i
< height
; ++i
)
11486 rows
[i
] = pixels
+ i
* row_bytes
;
11488 /* Read the entire image. */
11489 png_read_image (png_ptr
, rows
);
11490 png_read_end (png_ptr
, info_ptr
);
11497 /* Create the X image and pixmap. */
11498 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
11502 /* Create an image and pixmap serving as mask if the PNG image
11503 contains an alpha channel. */
11506 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
11507 &mask_img
, &img
->mask
))
11509 x_destroy_x_image (ximg
);
11510 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
11515 /* Fill the X image and mask from PNG data. */
11516 init_color_table ();
11518 for (y
= 0; y
< height
; ++y
)
11520 png_byte
*p
= rows
[y
];
11522 for (x
= 0; x
< width
; ++x
)
11529 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
11531 /* An alpha channel, aka mask channel, associates variable
11532 transparency with an image. Where other image formats
11533 support binary transparency---fully transparent or fully
11534 opaque---PNG allows up to 254 levels of partial transparency.
11535 The PNG library implements partial transparency by combining
11536 the image with a specified background color.
11538 I'm not sure how to handle this here nicely: because the
11539 background on which the image is displayed may change, for
11540 real alpha channel support, it would be necessary to create
11541 a new image for each possible background.
11543 What I'm doing now is that a mask is created if we have
11544 boolean transparency information. Otherwise I'm using
11545 the frame's background color to combine the image with. */
11550 XPutPixel (mask_img
, x
, y
, *p
> 0);
11556 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
11557 /* Set IMG's background color from the PNG image, unless the user
11561 if (png_get_bKGD (png_ptr
, info_ptr
, &bg
))
11563 img
->background
= lookup_rgb_color (f
, bg
->red
, bg
->green
, bg
->blue
);
11564 img
->background_valid
= 1;
11568 /* Remember colors allocated for this image. */
11569 img
->colors
= colors_in_color_table (&img
->ncolors
);
11570 free_color_table ();
11573 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
11577 img
->width
= width
;
11578 img
->height
= height
;
11580 /* Maybe fill in the background field while we have ximg handy. */
11581 IMAGE_BACKGROUND (img
, f
, ximg
);
11583 /* Put the image into the pixmap, then free the X image and its buffer. */
11584 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11585 x_destroy_x_image (ximg
);
11587 /* Same for the mask. */
11590 /* Fill in the background_transparent field while we have the mask
11592 image_background_transparent (img
, f
, mask_img
);
11594 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
11595 x_destroy_x_image (mask_img
);
11602 #endif /* HAVE_PNG != 0 */
11606 /***********************************************************************
11608 ***********************************************************************/
11612 /* Work around a warning about HAVE_STDLIB_H being redefined in
11614 #ifdef HAVE_STDLIB_H
11615 #define HAVE_STDLIB_H_1
11616 #undef HAVE_STDLIB_H
11617 #endif /* HAVE_STLIB_H */
11619 #include <jpeglib.h>
11620 #include <jerror.h>
11621 #include <setjmp.h>
11623 #ifdef HAVE_STLIB_H_1
11624 #define HAVE_STDLIB_H 1
11627 static int jpeg_image_p
P_ ((Lisp_Object object
));
11628 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
11630 /* The symbol `jpeg' identifying images of this type. */
11634 /* Indices of image specification fields in gs_format, below. */
11636 enum jpeg_keyword_index
11645 JPEG_HEURISTIC_MASK
,
11651 /* Vector of image_keyword structures describing the format
11652 of valid user-defined image specifications. */
11654 static struct image_keyword jpeg_format
[JPEG_LAST
] =
11656 {":type", IMAGE_SYMBOL_VALUE
, 1},
11657 {":data", IMAGE_STRING_VALUE
, 0},
11658 {":file", IMAGE_STRING_VALUE
, 0},
11659 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11660 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11661 {":relief", IMAGE_INTEGER_VALUE
, 0},
11662 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11663 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11664 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11665 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
11668 /* Structure describing the image type `jpeg'. */
11670 static struct image_type jpeg_type
=
11680 /* Return non-zero if OBJECT is a valid JPEG image specification. */
11683 jpeg_image_p (object
)
11684 Lisp_Object object
;
11686 struct image_keyword fmt
[JPEG_LAST
];
11688 bcopy (jpeg_format
, fmt
, sizeof fmt
);
11690 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
11691 || (fmt
[JPEG_ASCENT
].count
11692 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
11695 /* Must specify either the :data or :file keyword. */
11696 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
11700 struct my_jpeg_error_mgr
11702 struct jpeg_error_mgr pub
;
11703 jmp_buf setjmp_buffer
;
11707 my_error_exit (cinfo
)
11708 j_common_ptr cinfo
;
11710 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
11711 longjmp (mgr
->setjmp_buffer
, 1);
11714 /* Init source method for JPEG data source manager. Called by
11715 jpeg_read_header() before any data is actually read. See
11716 libjpeg.doc from the JPEG lib distribution. */
11719 our_init_source (cinfo
)
11720 j_decompress_ptr cinfo
;
11725 /* Fill input buffer method for JPEG data source manager. Called
11726 whenever more data is needed. We read the whole image in one step,
11727 so this only adds a fake end of input marker at the end. */
11730 our_fill_input_buffer (cinfo
)
11731 j_decompress_ptr cinfo
;
11733 /* Insert a fake EOI marker. */
11734 struct jpeg_source_mgr
*src
= cinfo
->src
;
11735 static JOCTET buffer
[2];
11737 buffer
[0] = (JOCTET
) 0xFF;
11738 buffer
[1] = (JOCTET
) JPEG_EOI
;
11740 src
->next_input_byte
= buffer
;
11741 src
->bytes_in_buffer
= 2;
11746 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
11747 is the JPEG data source manager. */
11750 our_skip_input_data (cinfo
, num_bytes
)
11751 j_decompress_ptr cinfo
;
11754 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
11758 if (num_bytes
> src
->bytes_in_buffer
)
11759 ERREXIT (cinfo
, JERR_INPUT_EOF
);
11761 src
->bytes_in_buffer
-= num_bytes
;
11762 src
->next_input_byte
+= num_bytes
;
11767 /* Method to terminate data source. Called by
11768 jpeg_finish_decompress() after all data has been processed. */
11771 our_term_source (cinfo
)
11772 j_decompress_ptr cinfo
;
11777 /* Set up the JPEG lib for reading an image from DATA which contains
11778 LEN bytes. CINFO is the decompression info structure created for
11779 reading the image. */
11782 jpeg_memory_src (cinfo
, data
, len
)
11783 j_decompress_ptr cinfo
;
11787 struct jpeg_source_mgr
*src
;
11789 if (cinfo
->src
== NULL
)
11791 /* First time for this JPEG object? */
11792 cinfo
->src
= (struct jpeg_source_mgr
*)
11793 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
11794 sizeof (struct jpeg_source_mgr
));
11795 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
11796 src
->next_input_byte
= data
;
11799 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
11800 src
->init_source
= our_init_source
;
11801 src
->fill_input_buffer
= our_fill_input_buffer
;
11802 src
->skip_input_data
= our_skip_input_data
;
11803 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
11804 src
->term_source
= our_term_source
;
11805 src
->bytes_in_buffer
= len
;
11806 src
->next_input_byte
= data
;
11810 /* Load image IMG for use on frame F. Patterned after example.c
11811 from the JPEG lib. */
11818 struct jpeg_decompress_struct cinfo
;
11819 struct my_jpeg_error_mgr mgr
;
11820 Lisp_Object file
, specified_file
;
11821 Lisp_Object specified_data
;
11822 FILE * volatile fp
= NULL
;
11824 int row_stride
, x
, y
;
11825 XImage
*ximg
= NULL
;
11827 unsigned long *colors
;
11829 struct gcpro gcpro1
;
11831 /* Open the JPEG file. */
11832 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11833 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11837 if (NILP (specified_data
))
11839 file
= x_find_image_file (specified_file
);
11840 if (!STRINGP (file
))
11842 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11847 fp
= fopen (XSTRING (file
)->data
, "r");
11850 image_error ("Cannot open `%s'", file
, Qnil
);
11856 /* Customize libjpeg's error handling to call my_error_exit when an
11857 error is detected. This function will perform a longjmp. */
11858 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
11859 mgr
.pub
.error_exit
= my_error_exit
;
11861 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
11865 /* Called from my_error_exit. Display a JPEG error. */
11866 char buffer
[JMSG_LENGTH_MAX
];
11867 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
11868 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
11869 build_string (buffer
));
11872 /* Close the input file and destroy the JPEG object. */
11875 jpeg_destroy_decompress (&cinfo
);
11877 /* If we already have an XImage, free that. */
11878 x_destroy_x_image (ximg
);
11880 /* Free pixmap and colors. */
11881 x_clear_image (f
, img
);
11887 /* Create the JPEG decompression object. Let it read from fp.
11888 Read the JPEG image header. */
11889 jpeg_create_decompress (&cinfo
);
11891 if (NILP (specified_data
))
11892 jpeg_stdio_src (&cinfo
, fp
);
11894 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
11895 STRING_BYTES (XSTRING (specified_data
)));
11897 jpeg_read_header (&cinfo
, TRUE
);
11899 /* Customize decompression so that color quantization will be used.
11900 Start decompression. */
11901 cinfo
.quantize_colors
= TRUE
;
11902 jpeg_start_decompress (&cinfo
);
11903 width
= img
->width
= cinfo
.output_width
;
11904 height
= img
->height
= cinfo
.output_height
;
11906 /* Create X image and pixmap. */
11907 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
11909 longjmp (mgr
.setjmp_buffer
, 2);
11911 /* Allocate colors. When color quantization is used,
11912 cinfo.actual_number_of_colors has been set with the number of
11913 colors generated, and cinfo.colormap is a two-dimensional array
11914 of color indices in the range 0..cinfo.actual_number_of_colors.
11915 No more than 255 colors will be generated. */
11919 if (cinfo
.out_color_components
> 2)
11920 ir
= 0, ig
= 1, ib
= 2;
11921 else if (cinfo
.out_color_components
> 1)
11922 ir
= 0, ig
= 1, ib
= 0;
11924 ir
= 0, ig
= 0, ib
= 0;
11926 /* Use the color table mechanism because it handles colors that
11927 cannot be allocated nicely. Such colors will be replaced with
11928 a default color, and we don't have to care about which colors
11929 can be freed safely, and which can't. */
11930 init_color_table ();
11931 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
11934 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
11936 /* Multiply RGB values with 255 because X expects RGB values
11937 in the range 0..0xffff. */
11938 int r
= cinfo
.colormap
[ir
][i
] << 8;
11939 int g
= cinfo
.colormap
[ig
][i
] << 8;
11940 int b
= cinfo
.colormap
[ib
][i
] << 8;
11941 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11944 /* Remember those colors actually allocated. */
11945 img
->colors
= colors_in_color_table (&img
->ncolors
);
11946 free_color_table ();
11950 row_stride
= width
* cinfo
.output_components
;
11951 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
11953 for (y
= 0; y
< height
; ++y
)
11955 jpeg_read_scanlines (&cinfo
, buffer
, 1);
11956 for (x
= 0; x
< cinfo
.output_width
; ++x
)
11957 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
11961 jpeg_finish_decompress (&cinfo
);
11962 jpeg_destroy_decompress (&cinfo
);
11966 /* Maybe fill in the background field while we have ximg handy. */
11967 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
11968 IMAGE_BACKGROUND (img
, f
, ximg
);
11970 /* Put the image into the pixmap. */
11971 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11972 x_destroy_x_image (ximg
);
11978 #endif /* HAVE_JPEG */
11982 /***********************************************************************
11984 ***********************************************************************/
11988 #include <tiffio.h>
11990 static int tiff_image_p
P_ ((Lisp_Object object
));
11991 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
11993 /* The symbol `tiff' identifying images of this type. */
11997 /* Indices of image specification fields in tiff_format, below. */
11999 enum tiff_keyword_index
12008 TIFF_HEURISTIC_MASK
,
12014 /* Vector of image_keyword structures describing the format
12015 of valid user-defined image specifications. */
12017 static struct image_keyword tiff_format
[TIFF_LAST
] =
12019 {":type", IMAGE_SYMBOL_VALUE
, 1},
12020 {":data", IMAGE_STRING_VALUE
, 0},
12021 {":file", IMAGE_STRING_VALUE
, 0},
12022 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12023 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
12024 {":relief", IMAGE_INTEGER_VALUE
, 0},
12025 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12026 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12027 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12028 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
12031 /* Structure describing the image type `tiff'. */
12033 static struct image_type tiff_type
=
12043 /* Return non-zero if OBJECT is a valid TIFF image specification. */
12046 tiff_image_p (object
)
12047 Lisp_Object object
;
12049 struct image_keyword fmt
[TIFF_LAST
];
12050 bcopy (tiff_format
, fmt
, sizeof fmt
);
12052 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
12053 || (fmt
[TIFF_ASCENT
].count
12054 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
12057 /* Must specify either the :data or :file keyword. */
12058 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
12062 /* Reading from a memory buffer for TIFF images Based on the PNG
12063 memory source, but we have to provide a lot of extra functions.
12066 We really only need to implement read and seek, but I am not
12067 convinced that the TIFF library is smart enough not to destroy
12068 itself if we only hand it the function pointers we need to
12073 unsigned char *bytes
;
12077 tiff_memory_source
;
12080 tiff_read_from_memory (data
, buf
, size
)
12085 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
12087 if (size
> src
->len
- src
->index
)
12088 return (size_t) -1;
12089 bcopy (src
->bytes
+ src
->index
, buf
, size
);
12090 src
->index
+= size
;
12095 tiff_write_from_memory (data
, buf
, size
)
12100 return (size_t) -1;
12104 tiff_seek_in_memory (data
, off
, whence
)
12109 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
12114 case SEEK_SET
: /* Go from beginning of source. */
12118 case SEEK_END
: /* Go from end of source. */
12119 idx
= src
->len
+ off
;
12122 case SEEK_CUR
: /* Go from current position. */
12123 idx
= src
->index
+ off
;
12126 default: /* Invalid `whence'. */
12130 if (idx
> src
->len
|| idx
< 0)
12138 tiff_close_memory (data
)
12146 tiff_mmap_memory (data
, pbase
, psize
)
12151 /* It is already _IN_ memory. */
12156 tiff_unmap_memory (data
, base
, size
)
12161 /* We don't need to do this. */
12165 tiff_size_of_memory (data
)
12168 return ((tiff_memory_source
*) data
)->len
;
12173 tiff_error_handler (title
, format
, ap
)
12174 const char *title
, *format
;
12180 len
= sprintf (buf
, "TIFF error: %s ", title
);
12181 vsprintf (buf
+ len
, format
, ap
);
12182 add_to_log (buf
, Qnil
, Qnil
);
12187 tiff_warning_handler (title
, format
, ap
)
12188 const char *title
, *format
;
12194 len
= sprintf (buf
, "TIFF warning: %s ", title
);
12195 vsprintf (buf
+ len
, format
, ap
);
12196 add_to_log (buf
, Qnil
, Qnil
);
12200 /* Load TIFF image IMG for use on frame F. Value is non-zero if
12208 Lisp_Object file
, specified_file
;
12209 Lisp_Object specified_data
;
12211 int width
, height
, x
, y
;
12215 struct gcpro gcpro1
;
12216 tiff_memory_source memsrc
;
12218 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
12219 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
12223 TIFFSetErrorHandler (tiff_error_handler
);
12224 TIFFSetWarningHandler (tiff_warning_handler
);
12226 if (NILP (specified_data
))
12228 /* Read from a file */
12229 file
= x_find_image_file (specified_file
);
12230 if (!STRINGP (file
))
12232 image_error ("Cannot find image file `%s'", file
, Qnil
);
12237 /* Try to open the image file. */
12238 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
12241 image_error ("Cannot open `%s'", file
, Qnil
);
12248 /* Memory source! */
12249 memsrc
.bytes
= XSTRING (specified_data
)->data
;
12250 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
12253 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
12254 (TIFFReadWriteProc
) tiff_read_from_memory
,
12255 (TIFFReadWriteProc
) tiff_write_from_memory
,
12256 tiff_seek_in_memory
,
12258 tiff_size_of_memory
,
12260 tiff_unmap_memory
);
12264 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
12270 /* Get width and height of the image, and allocate a raster buffer
12271 of width x height 32-bit values. */
12272 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
12273 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
12274 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
12276 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
12280 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
12286 /* Create the X image and pixmap. */
12287 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
12294 /* Initialize the color table. */
12295 init_color_table ();
12297 /* Process the pixel raster. Origin is in the lower-left corner. */
12298 for (y
= 0; y
< height
; ++y
)
12300 uint32
*row
= buf
+ y
* width
;
12302 for (x
= 0; x
< width
; ++x
)
12304 uint32 abgr
= row
[x
];
12305 int r
= TIFFGetR (abgr
) << 8;
12306 int g
= TIFFGetG (abgr
) << 8;
12307 int b
= TIFFGetB (abgr
) << 8;
12308 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
12312 /* Remember the colors allocated for the image. Free the color table. */
12313 img
->colors
= colors_in_color_table (&img
->ncolors
);
12314 free_color_table ();
12316 img
->width
= width
;
12317 img
->height
= height
;
12319 /* Maybe fill in the background field while we have ximg handy. */
12320 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
12321 IMAGE_BACKGROUND (img
, f
, ximg
);
12323 /* Put the image into the pixmap, then free the X image and its buffer. */
12324 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
12325 x_destroy_x_image (ximg
);
12332 #endif /* HAVE_TIFF != 0 */
12336 /***********************************************************************
12338 ***********************************************************************/
12342 #include <gif_lib.h>
12344 static int gif_image_p
P_ ((Lisp_Object object
));
12345 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
12347 /* The symbol `gif' identifying images of this type. */
12351 /* Indices of image specification fields in gif_format, below. */
12353 enum gif_keyword_index
12362 GIF_HEURISTIC_MASK
,
12369 /* Vector of image_keyword structures describing the format
12370 of valid user-defined image specifications. */
12372 static struct image_keyword gif_format
[GIF_LAST
] =
12374 {":type", IMAGE_SYMBOL_VALUE
, 1},
12375 {":data", IMAGE_STRING_VALUE
, 0},
12376 {":file", IMAGE_STRING_VALUE
, 0},
12377 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12378 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
12379 {":relief", IMAGE_INTEGER_VALUE
, 0},
12380 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12381 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12382 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12383 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12384 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
12387 /* Structure describing the image type `gif'. */
12389 static struct image_type gif_type
=
12398 /* Return non-zero if OBJECT is a valid GIF image specification. */
12401 gif_image_p (object
)
12402 Lisp_Object object
;
12404 struct image_keyword fmt
[GIF_LAST
];
12405 bcopy (gif_format
, fmt
, sizeof fmt
);
12407 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
12408 || (fmt
[GIF_ASCENT
].count
12409 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
12412 /* Must specify either the :data or :file keyword. */
12413 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
12416 /* Reading a GIF image from memory
12417 Based on the PNG memory stuff to a certain extent. */
12421 unsigned char *bytes
;
12427 /* Make the current memory source available to gif_read_from_memory.
12428 It's done this way because not all versions of libungif support
12429 a UserData field in the GifFileType structure. */
12430 static gif_memory_source
*current_gif_memory_src
;
12433 gif_read_from_memory (file
, buf
, len
)
12438 gif_memory_source
*src
= current_gif_memory_src
;
12440 if (len
> src
->len
- src
->index
)
12443 bcopy (src
->bytes
+ src
->index
, buf
, len
);
12449 /* Load GIF image IMG for use on frame F. Value is non-zero if
12457 Lisp_Object file
, specified_file
;
12458 Lisp_Object specified_data
;
12459 int rc
, width
, height
, x
, y
, i
;
12461 ColorMapObject
*gif_color_map
;
12462 unsigned long pixel_colors
[256];
12464 struct gcpro gcpro1
;
12466 int ino
, image_left
, image_top
, image_width
, image_height
;
12467 gif_memory_source memsrc
;
12468 unsigned char *raster
;
12470 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
12471 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
12475 if (NILP (specified_data
))
12477 file
= x_find_image_file (specified_file
);
12478 if (!STRINGP (file
))
12480 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
12485 /* Open the GIF file. */
12486 gif
= DGifOpenFileName (XSTRING (file
)->data
);
12489 image_error ("Cannot open `%s'", file
, Qnil
);
12496 /* Read from memory! */
12497 current_gif_memory_src
= &memsrc
;
12498 memsrc
.bytes
= XSTRING (specified_data
)->data
;
12499 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
12502 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
12505 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
12511 /* Read entire contents. */
12512 rc
= DGifSlurp (gif
);
12513 if (rc
== GIF_ERROR
)
12515 image_error ("Error reading `%s'", img
->spec
, Qnil
);
12516 DGifCloseFile (gif
);
12521 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
12522 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
12523 if (ino
>= gif
->ImageCount
)
12525 image_error ("Invalid image number `%s' in image `%s'",
12527 DGifCloseFile (gif
);
12532 width
= img
->width
= gif
->SWidth
;
12533 height
= img
->height
= gif
->SHeight
;
12535 /* Create the X image and pixmap. */
12536 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
12538 DGifCloseFile (gif
);
12543 /* Allocate colors. */
12544 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
12545 if (!gif_color_map
)
12546 gif_color_map
= gif
->SColorMap
;
12547 init_color_table ();
12548 bzero (pixel_colors
, sizeof pixel_colors
);
12550 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
12552 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
12553 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
12554 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
12555 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
12558 img
->colors
= colors_in_color_table (&img
->ncolors
);
12559 free_color_table ();
12561 /* Clear the part of the screen image that are not covered by
12562 the image from the GIF file. Full animated GIF support
12563 requires more than can be done here (see the gif89 spec,
12564 disposal methods). Let's simply assume that the part
12565 not covered by a sub-image is in the frame's background color. */
12566 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
12567 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
12568 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
12569 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
12571 for (y
= 0; y
< image_top
; ++y
)
12572 for (x
= 0; x
< width
; ++x
)
12573 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12575 for (y
= image_top
+ image_height
; y
< height
; ++y
)
12576 for (x
= 0; x
< width
; ++x
)
12577 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12579 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
12581 for (x
= 0; x
< image_left
; ++x
)
12582 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12583 for (x
= image_left
+ image_width
; x
< width
; ++x
)
12584 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12587 /* Read the GIF image into the X image. We use a local variable
12588 `raster' here because RasterBits below is a char *, and invites
12589 problems with bytes >= 0x80. */
12590 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
12592 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
12594 static int interlace_start
[] = {0, 4, 2, 1};
12595 static int interlace_increment
[] = {8, 8, 4, 2};
12597 int row
= interlace_start
[0];
12601 for (y
= 0; y
< image_height
; y
++)
12603 if (row
>= image_height
)
12605 row
= interlace_start
[++pass
];
12606 while (row
>= image_height
)
12607 row
= interlace_start
[++pass
];
12610 for (x
= 0; x
< image_width
; x
++)
12612 int i
= raster
[(y
* image_width
) + x
];
12613 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
12617 row
+= interlace_increment
[pass
];
12622 for (y
= 0; y
< image_height
; ++y
)
12623 for (x
= 0; x
< image_width
; ++x
)
12625 int i
= raster
[y
* image_width
+ x
];
12626 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
12630 DGifCloseFile (gif
);
12632 /* Maybe fill in the background field while we have ximg handy. */
12633 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
12634 IMAGE_BACKGROUND (img
, f
, ximg
);
12636 /* Put the image into the pixmap, then free the X image and its buffer. */
12637 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
12638 x_destroy_x_image (ximg
);
12644 #endif /* HAVE_GIF != 0 */
12648 /***********************************************************************
12650 ***********************************************************************/
12652 Lisp_Object Qpostscript
;
12654 #ifdef HAVE_GHOSTSCRIPT
12655 static int gs_image_p
P_ ((Lisp_Object object
));
12656 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
12657 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
12659 /* The symbol `postscript' identifying images of this type. */
12661 /* Keyword symbols. */
12663 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
12665 /* Indices of image specification fields in gs_format, below. */
12667 enum gs_keyword_index
12685 /* Vector of image_keyword structures describing the format
12686 of valid user-defined image specifications. */
12688 static struct image_keyword gs_format
[GS_LAST
] =
12690 {":type", IMAGE_SYMBOL_VALUE
, 1},
12691 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
12692 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
12693 {":file", IMAGE_STRING_VALUE
, 1},
12694 {":loader", IMAGE_FUNCTION_VALUE
, 0},
12695 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
12696 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12697 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
12698 {":relief", IMAGE_INTEGER_VALUE
, 0},
12699 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12700 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12701 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12702 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
12705 /* Structure describing the image type `ghostscript'. */
12707 static struct image_type gs_type
=
12717 /* Free X resources of Ghostscript image IMG which is used on frame F. */
12720 gs_clear_image (f
, img
)
12724 /* IMG->data.ptr_val may contain a recorded colormap. */
12725 xfree (img
->data
.ptr_val
);
12726 x_clear_image (f
, img
);
12730 /* Return non-zero if OBJECT is a valid Ghostscript image
12734 gs_image_p (object
)
12735 Lisp_Object object
;
12737 struct image_keyword fmt
[GS_LAST
];
12741 bcopy (gs_format
, fmt
, sizeof fmt
);
12743 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
12744 || (fmt
[GS_ASCENT
].count
12745 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
12748 /* Bounding box must be a list or vector containing 4 integers. */
12749 tem
= fmt
[GS_BOUNDING_BOX
].value
;
12752 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
12753 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
12758 else if (VECTORP (tem
))
12760 if (XVECTOR (tem
)->size
!= 4)
12762 for (i
= 0; i
< 4; ++i
)
12763 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
12773 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
12782 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
12783 struct gcpro gcpro1
, gcpro2
;
12785 double in_width
, in_height
;
12786 Lisp_Object pixel_colors
= Qnil
;
12788 /* Compute pixel size of pixmap needed from the given size in the
12789 image specification. Sizes in the specification are in pt. 1 pt
12790 = 1/72 in, xdpi and ydpi are stored in the frame's X display
12792 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
12793 in_width
= XFASTINT (pt_width
) / 72.0;
12794 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
12795 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
12796 in_height
= XFASTINT (pt_height
) / 72.0;
12797 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
12799 /* Create the pixmap. */
12801 xassert (img
->pixmap
== 0);
12802 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12803 img
->width
, img
->height
,
12804 one_w32_display_info
.n_cbits
);
12809 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
12813 /* Call the loader to fill the pixmap. It returns a process object
12814 if successful. We do not record_unwind_protect here because
12815 other places in redisplay like calling window scroll functions
12816 don't either. Let the Lisp loader use `unwind-protect' instead. */
12817 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
12819 sprintf (buffer
, "%lu %lu",
12820 (unsigned long) FRAME_W32_WINDOW (f
),
12821 (unsigned long) img
->pixmap
);
12822 window_and_pixmap_id
= build_string (buffer
);
12824 sprintf (buffer
, "%lu %lu",
12825 FRAME_FOREGROUND_PIXEL (f
),
12826 FRAME_BACKGROUND_PIXEL (f
));
12827 pixel_colors
= build_string (buffer
);
12829 XSETFRAME (frame
, f
);
12830 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
12832 loader
= intern ("gs-load-image");
12834 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
12835 make_number (img
->width
),
12836 make_number (img
->height
),
12837 window_and_pixmap_id
,
12840 return PROCESSP (img
->data
.lisp_val
);
12844 /* Kill the Ghostscript process that was started to fill PIXMAP on
12845 frame F. Called from XTread_socket when receiving an event
12846 telling Emacs that Ghostscript has finished drawing. */
12849 x_kill_gs_process (pixmap
, f
)
12853 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
12857 /* Find the image containing PIXMAP. */
12858 for (i
= 0; i
< c
->used
; ++i
)
12859 if (c
->images
[i
]->pixmap
== pixmap
)
12862 /* Should someone in between have cleared the image cache, for
12863 instance, give up. */
12867 /* Kill the GS process. We should have found PIXMAP in the image
12868 cache and its image should contain a process object. */
12869 img
= c
->images
[i
];
12870 xassert (PROCESSP (img
->data
.lisp_val
));
12871 Fkill_process (img
->data
.lisp_val
, Qnil
);
12872 img
->data
.lisp_val
= Qnil
;
12874 /* On displays with a mutable colormap, figure out the colors
12875 allocated for the image by looking at the pixels of an XImage for
12877 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
12878 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
12884 /* Try to get an XImage for img->pixmep. */
12885 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
12886 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
12891 /* Initialize the color table. */
12892 init_color_table ();
12894 /* For each pixel of the image, look its color up in the
12895 color table. After having done so, the color table will
12896 contain an entry for each color used by the image. */
12897 for (y
= 0; y
< img
->height
; ++y
)
12898 for (x
= 0; x
< img
->width
; ++x
)
12900 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
12901 lookup_pixel_color (f
, pixel
);
12904 /* Record colors in the image. Free color table and XImage. */
12905 img
->colors
= colors_in_color_table (&img
->ncolors
);
12906 free_color_table ();
12907 XDestroyImage (ximg
);
12909 #if 0 /* This doesn't seem to be the case. If we free the colors
12910 here, we get a BadAccess later in x_clear_image when
12911 freeing the colors. */
12912 /* We have allocated colors once, but Ghostscript has also
12913 allocated colors on behalf of us. So, to get the
12914 reference counts right, free them once. */
12916 x_free_colors (FRAME_W32_DISPLAY (f
), cmap
,
12917 img
->colors
, img
->ncolors
, 0);
12921 image_error ("Cannot get X image of `%s'; colors will not be freed",
12927 /* Now that we have the pixmap, compute mask and transform the
12928 image if requested. */
12930 postprocess_image (f
, img
);
12934 #endif /* HAVE_GHOSTSCRIPT */
12937 /***********************************************************************
12939 ***********************************************************************/
12941 DEFUN ("x-change-window-property", Fx_change_window_property
,
12942 Sx_change_window_property
, 2, 3, 0,
12943 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
12944 PROP and VALUE must be strings. FRAME nil or omitted means use the
12945 selected frame. Value is VALUE. */)
12946 (prop
, value
, frame
)
12947 Lisp_Object frame
, prop
, value
;
12949 #if 0 /* TODO : port window properties to W32 */
12950 struct frame
*f
= check_x_frame (frame
);
12953 CHECK_STRING (prop
);
12954 CHECK_STRING (value
);
12957 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12958 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12959 prop_atom
, XA_STRING
, 8, PropModeReplace
,
12960 XSTRING (value
)->data
, XSTRING (value
)->size
);
12962 /* Make sure the property is set when we return. */
12963 XFlush (FRAME_W32_DISPLAY (f
));
12972 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
12973 Sx_delete_window_property
, 1, 2, 0,
12974 doc
: /* Remove window property PROP from X window of FRAME.
12975 FRAME nil or omitted means use the selected frame. Value is PROP. */)
12977 Lisp_Object prop
, frame
;
12979 #if 0 /* TODO : port window properties to W32 */
12981 struct frame
*f
= check_x_frame (frame
);
12984 CHECK_STRING (prop
);
12986 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12987 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
12989 /* Make sure the property is removed when we return. */
12990 XFlush (FRAME_W32_DISPLAY (f
));
12998 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
13000 doc
: /* Value is the value of window property PROP on FRAME.
13001 If FRAME is nil or omitted, use the selected frame. Value is nil
13002 if FRAME hasn't a property with name PROP or if PROP has no string
13005 Lisp_Object prop
, frame
;
13007 #if 0 /* TODO : port window properties to W32 */
13009 struct frame
*f
= check_x_frame (frame
);
13012 Lisp_Object prop_value
= Qnil
;
13013 char *tmp_data
= NULL
;
13016 unsigned long actual_size
, bytes_remaining
;
13018 CHECK_STRING (prop
);
13020 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
13021 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
13022 prop_atom
, 0, 0, False
, XA_STRING
,
13023 &actual_type
, &actual_format
, &actual_size
,
13024 &bytes_remaining
, (unsigned char **) &tmp_data
);
13027 int size
= bytes_remaining
;
13032 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
13033 prop_atom
, 0, bytes_remaining
,
13035 &actual_type
, &actual_format
,
13036 &actual_size
, &bytes_remaining
,
13037 (unsigned char **) &tmp_data
);
13039 prop_value
= make_string (tmp_data
, size
);
13054 /***********************************************************************
13056 ***********************************************************************/
13058 /* If non-null, an asynchronous timer that, when it expires, displays
13059 an hourglass cursor on all frames. */
13061 static struct atimer
*hourglass_atimer
;
13063 /* Non-zero means an hourglass cursor is currently shown. */
13065 static int hourglass_shown_p
;
13067 /* Number of seconds to wait before displaying an hourglass cursor. */
13069 static Lisp_Object Vhourglass_delay
;
13071 /* Default number of seconds to wait before displaying an hourglass
13074 #define DEFAULT_HOURGLASS_DELAY 1
13076 /* Function prototypes. */
13078 static void show_hourglass
P_ ((struct atimer
*));
13079 static void hide_hourglass
P_ ((void));
13082 /* Cancel a currently active hourglass timer, and start a new one. */
13087 #if 0 /* TODO: cursor shape changes. */
13089 int secs
, usecs
= 0;
13091 cancel_hourglass ();
13093 if (INTEGERP (Vhourglass_delay
)
13094 && XINT (Vhourglass_delay
) > 0)
13095 secs
= XFASTINT (Vhourglass_delay
);
13096 else if (FLOATP (Vhourglass_delay
)
13097 && XFLOAT_DATA (Vhourglass_delay
) > 0)
13100 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
13101 secs
= XFASTINT (tem
);
13102 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
13105 secs
= DEFAULT_HOURGLASS_DELAY
;
13107 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
13108 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
13109 show_hourglass
, NULL
);
13114 /* Cancel the hourglass cursor timer if active, hide an hourglass
13115 cursor if shown. */
13118 cancel_hourglass ()
13120 if (hourglass_atimer
)
13122 cancel_atimer (hourglass_atimer
);
13123 hourglass_atimer
= NULL
;
13126 if (hourglass_shown_p
)
13131 /* Timer function of hourglass_atimer. TIMER is equal to
13134 Display an hourglass cursor on all frames by mapping the frames'
13135 hourglass_window. Set the hourglass_p flag in the frames'
13136 output_data.x structure to indicate that an hourglass cursor is
13137 shown on the frames. */
13140 show_hourglass (timer
)
13141 struct atimer
*timer
;
13143 #if 0 /* TODO: cursor shape changes. */
13144 /* The timer implementation will cancel this timer automatically
13145 after this function has run. Set hourglass_atimer to null
13146 so that we know the timer doesn't have to be canceled. */
13147 hourglass_atimer
= NULL
;
13149 if (!hourglass_shown_p
)
13151 Lisp_Object rest
, frame
;
13155 FOR_EACH_FRAME (rest
, frame
)
13156 if (FRAME_W32_P (XFRAME (frame
)))
13158 struct frame
*f
= XFRAME (frame
);
13160 f
->output_data
.w32
->hourglass_p
= 1;
13162 if (!f
->output_data
.w32
->hourglass_window
)
13164 unsigned long mask
= CWCursor
;
13165 XSetWindowAttributes attrs
;
13167 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
13169 f
->output_data
.w32
->hourglass_window
13170 = XCreateWindow (FRAME_X_DISPLAY (f
),
13171 FRAME_OUTER_WINDOW (f
),
13172 0, 0, 32000, 32000, 0, 0,
13178 XMapRaised (FRAME_X_DISPLAY (f
),
13179 f
->output_data
.w32
->hourglass_window
);
13180 XFlush (FRAME_X_DISPLAY (f
));
13183 hourglass_shown_p
= 1;
13190 /* Hide the hourglass cursor on all frames, if it is currently shown. */
13195 #if 0 /* TODO: cursor shape changes. */
13196 if (hourglass_shown_p
)
13198 Lisp_Object rest
, frame
;
13201 FOR_EACH_FRAME (rest
, frame
)
13203 struct frame
*f
= XFRAME (frame
);
13205 if (FRAME_W32_P (f
)
13206 /* Watch out for newly created frames. */
13207 && f
->output_data
.x
->hourglass_window
)
13209 XUnmapWindow (FRAME_X_DISPLAY (f
),
13210 f
->output_data
.x
->hourglass_window
);
13211 /* Sync here because XTread_socket looks at the
13212 hourglass_p flag that is reset to zero below. */
13213 XSync (FRAME_X_DISPLAY (f
), False
);
13214 f
->output_data
.x
->hourglass_p
= 0;
13218 hourglass_shown_p
= 0;
13226 /***********************************************************************
13228 ***********************************************************************/
13230 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
13231 Lisp_Object
, Lisp_Object
));
13232 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
13233 Lisp_Object
, int, int, int *, int *));
13235 /* The frame of a currently visible tooltip. */
13237 Lisp_Object tip_frame
;
13239 /* If non-nil, a timer started that hides the last tooltip when it
13242 Lisp_Object tip_timer
;
13245 /* If non-nil, a vector of 3 elements containing the last args
13246 with which x-show-tip was called. See there. */
13248 Lisp_Object last_show_tip_args
;
13250 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
13252 Lisp_Object Vx_max_tooltip_size
;
13256 unwind_create_tip_frame (frame
)
13259 Lisp_Object deleted
;
13261 deleted
= unwind_create_frame (frame
);
13262 if (EQ (deleted
, Qt
))
13272 /* Create a frame for a tooltip on the display described by DPYINFO.
13273 PARMS is a list of frame parameters. TEXT is the string to
13274 display in the tip frame. Value is the frame.
13276 Note that functions called here, esp. x_default_parameter can
13277 signal errors, for instance when a specified color name is
13278 undefined. We have to make sure that we're in a consistent state
13279 when this happens. */
13282 x_create_tip_frame (dpyinfo
, parms
, text
)
13283 struct w32_display_info
*dpyinfo
;
13284 Lisp_Object parms
, text
;
13287 Lisp_Object frame
, tem
;
13289 long window_prompting
= 0;
13291 int count
= BINDING_STACK_SIZE ();
13292 struct gcpro gcpro1
, gcpro2
, gcpro3
;
13294 int face_change_count_before
= face_change_count
;
13295 Lisp_Object buffer
;
13296 struct buffer
*old_buffer
;
13300 /* Use this general default value to start with until we know if
13301 this frame has a specified name. */
13302 Vx_resource_name
= Vinvocation_name
;
13304 #ifdef MULTI_KBOARD
13305 kb
= dpyinfo
->kboard
;
13307 kb
= &the_only_kboard
;
13310 /* Get the name of the frame to use for resource lookup. */
13311 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
13312 if (!STRINGP (name
)
13313 && !EQ (name
, Qunbound
)
13315 error ("Invalid frame name--not a string or nil");
13316 Vx_resource_name
= name
;
13319 GCPRO3 (parms
, name
, frame
);
13320 /* Make a frame without minibuffer nor mode-line. */
13321 f
= make_frame (0);
13322 f
->wants_modeline
= 0;
13323 XSETFRAME (frame
, f
);
13325 buffer
= Fget_buffer_create (build_string (" *tip*"));
13326 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
13327 old_buffer
= current_buffer
;
13328 set_buffer_internal_1 (XBUFFER (buffer
));
13329 current_buffer
->truncate_lines
= Qnil
;
13331 Finsert (1, &text
);
13332 set_buffer_internal_1 (old_buffer
);
13334 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
13335 record_unwind_protect (unwind_create_tip_frame
, frame
);
13337 /* By setting the output method, we're essentially saying that
13338 the frame is live, as per FRAME_LIVE_P. If we get a signal
13339 from this point on, x_destroy_window might screw up reference
13341 f
->output_method
= output_w32
;
13342 f
->output_data
.w32
=
13343 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
13344 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
13346 FRAME_FONTSET (f
) = -1;
13347 f
->icon_name
= Qnil
;
13349 #if 0 /* GLYPH_DEBUG TODO: image support. */
13350 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
13351 dpyinfo_refcount
= dpyinfo
->reference_count
;
13352 #endif /* GLYPH_DEBUG */
13353 #ifdef MULTI_KBOARD
13354 FRAME_KBOARD (f
) = kb
;
13356 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
13357 f
->output_data
.w32
->explicit_parent
= 0;
13359 /* Set the name; the functions to which we pass f expect the name to
13361 if (EQ (name
, Qunbound
) || NILP (name
))
13363 f
->name
= build_string (dpyinfo
->w32_id_name
);
13364 f
->explicit_name
= 0;
13369 f
->explicit_name
= 1;
13370 /* use the frame's title when getting resources for this frame. */
13371 specbind (Qx_resource_name
, name
);
13374 /* Extract the window parameters from the supplied values
13375 that are needed to determine window geometry. */
13379 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
13382 /* First, try whatever font the caller has specified. */
13383 if (STRINGP (font
))
13385 tem
= Fquery_fontset (font
, Qnil
);
13387 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
13389 font
= x_new_font (f
, XSTRING (font
)->data
);
13392 /* Try out a font which we hope has bold and italic variations. */
13393 if (!STRINGP (font
))
13394 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
13395 if (! STRINGP (font
))
13396 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
13397 /* If those didn't work, look for something which will at least work. */
13398 if (! STRINGP (font
))
13399 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
13401 if (! STRINGP (font
))
13402 font
= build_string ("Fixedsys");
13404 x_default_parameter (f
, parms
, Qfont
, font
,
13405 "font", "Font", RES_TYPE_STRING
);
13408 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
13409 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
13410 /* This defaults to 2 in order to match xterm. We recognize either
13411 internalBorderWidth or internalBorder (which is what xterm calls
13413 if (NILP (Fassq (Qinternal_border_width
, parms
)))
13417 value
= w32_get_arg (parms
, Qinternal_border_width
,
13418 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
13419 if (! EQ (value
, Qunbound
))
13420 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
13423 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
13424 "internalBorderWidth", "internalBorderWidth",
13427 /* Also do the stuff which must be set before the window exists. */
13428 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
13429 "foreground", "Foreground", RES_TYPE_STRING
);
13430 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
13431 "background", "Background", RES_TYPE_STRING
);
13432 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
13433 "pointerColor", "Foreground", RES_TYPE_STRING
);
13434 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
13435 "cursorColor", "Foreground", RES_TYPE_STRING
);
13436 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
13437 "borderColor", "BorderColor", RES_TYPE_STRING
);
13439 /* Init faces before x_default_parameter is called for scroll-bar
13440 parameters because that function calls x_set_scroll_bar_width,
13441 which calls change_frame_size, which calls Fset_window_buffer,
13442 which runs hooks, which call Fvertical_motion. At the end, we
13443 end up in init_iterator with a null face cache, which should not
13445 init_frame_faces (f
);
13447 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
13448 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
13450 window_prompting
= x_figure_window_size (f
, parms
);
13452 /* No fringes on tip frame. */
13453 f
->output_data
.w32
->fringes_extra
= 0;
13454 f
->output_data
.w32
->fringe_cols
= 0;
13455 f
->output_data
.w32
->left_fringe_width
= 0;
13456 f
->output_data
.w32
->right_fringe_width
= 0;
13458 if (window_prompting
& XNegative
)
13460 if (window_prompting
& YNegative
)
13461 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
13463 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
13467 if (window_prompting
& YNegative
)
13468 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
13470 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
13473 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
13476 my_create_tip_window (f
);
13481 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
13482 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
13483 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
13484 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
13485 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
13486 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
13488 /* Dimensions, especially f->height, must be done via change_frame_size.
13489 Change will not be effected unless different from the current
13492 height
= f
->height
;
13494 SET_FRAME_WIDTH (f
, 0);
13495 change_frame_size (f
, height
, width
, 1, 0, 0);
13497 /* Set up faces after all frame parameters are known. This call
13498 also merges in face attributes specified for new frames.
13500 Frame parameters may be changed if .Xdefaults contains
13501 specifications for the default font. For example, if there is an
13502 `Emacs.default.attributeBackground: pink', the `background-color'
13503 attribute of the frame get's set, which let's the internal border
13504 of the tooltip frame appear in pink. Prevent this. */
13506 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
13508 /* Set tip_frame here, so that */
13510 call1 (Qface_set_after_frame_default
, frame
);
13512 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
13513 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
13521 /* It is now ok to make the frame official even if we get an error
13522 below. And the frame needs to be on Vframe_list or making it
13523 visible won't work. */
13524 Vframe_list
= Fcons (frame
, Vframe_list
);
13526 /* Now that the frame is official, it counts as a reference to
13528 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
13530 /* Setting attributes of faces of the tooltip frame from resources
13531 and similar will increment face_change_count, which leads to the
13532 clearing of all current matrices. Since this isn't necessary
13533 here, avoid it by resetting face_change_count to the value it
13534 had before we created the tip frame. */
13535 face_change_count
= face_change_count_before
;
13537 /* Discard the unwind_protect. */
13538 return unbind_to (count
, frame
);
13542 /* Compute where to display tip frame F. PARMS is the list of frame
13543 parameters for F. DX and DY are specified offsets from the current
13544 location of the mouse. WIDTH and HEIGHT are the width and height
13545 of the tooltip. Return coordinates relative to the root window of
13546 the display in *ROOT_X, and *ROOT_Y. */
13549 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
13551 Lisp_Object parms
, dx
, dy
;
13553 int *root_x
, *root_y
;
13555 Lisp_Object left
, top
;
13557 /* User-specified position? */
13558 left
= Fcdr (Fassq (Qleft
, parms
));
13559 top
= Fcdr (Fassq (Qtop
, parms
));
13561 /* Move the tooltip window where the mouse pointer is. Resize and
13563 if (!INTEGERP (left
) || !INTEGERP (top
))
13568 GetCursorPos (&pt
);
13574 if (INTEGERP (top
))
13575 *root_y
= XINT (top
);
13576 else if (*root_y
+ XINT (dy
) - height
< 0)
13577 *root_y
-= XINT (dy
);
13581 *root_y
+= XINT (dy
);
13584 if (INTEGERP (left
))
13585 *root_x
= XINT (left
);
13586 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
13587 /* It fits to the right of the pointer. */
13588 *root_x
+= XINT (dx
);
13589 else if (width
+ XINT (dx
) <= *root_x
)
13590 /* It fits to the left of the pointer. */
13591 *root_x
-= width
+ XINT (dx
);
13593 /* Put it left justified on the screen -- it ought to fit that way. */
13598 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
13599 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
13600 A tooltip window is a small window displaying a string.
13602 FRAME nil or omitted means use the selected frame.
13604 PARMS is an optional list of frame parameters which can be
13605 used to change the tooltip's appearance.
13607 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
13608 means use the default timeout of 5 seconds.
13610 If the list of frame parameters PARAMS contains a `left' parameter,
13611 the tooltip is displayed at that x-position. Otherwise it is
13612 displayed at the mouse position, with offset DX added (default is 5 if
13613 DX isn't specified). Likewise for the y-position; if a `top' frame
13614 parameter is specified, it determines the y-position of the tooltip
13615 window, otherwise it is displayed at the mouse position, with offset
13616 DY added (default is -10).
13618 A tooltip's maximum size is specified by `x-max-tooltip-size'.
13619 Text larger than the specified size is clipped. */)
13620 (string
, frame
, parms
, timeout
, dx
, dy
)
13621 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
13625 int root_x
, root_y
;
13626 struct buffer
*old_buffer
;
13627 struct text_pos pos
;
13628 int i
, width
, height
;
13629 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
13630 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
13631 int count
= BINDING_STACK_SIZE ();
13633 specbind (Qinhibit_redisplay
, Qt
);
13635 GCPRO4 (string
, parms
, frame
, timeout
);
13637 CHECK_STRING (string
);
13638 f
= check_x_frame (frame
);
13639 if (NILP (timeout
))
13640 timeout
= make_number (5);
13642 CHECK_NATNUM (timeout
);
13645 dx
= make_number (5);
13650 dy
= make_number (-10);
13654 if (NILP (last_show_tip_args
))
13655 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
13657 if (!NILP (tip_frame
))
13659 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
13660 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
13661 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
13663 if (EQ (frame
, last_frame
)
13664 && !NILP (Fequal (last_string
, string
))
13665 && !NILP (Fequal (last_parms
, parms
)))
13667 struct frame
*f
= XFRAME (tip_frame
);
13669 /* Only DX and DY have changed. */
13670 if (!NILP (tip_timer
))
13672 Lisp_Object timer
= tip_timer
;
13674 call1 (Qcancel_timer
, timer
);
13678 compute_tip_xy (f
, parms
, dx
, dy
, PIXEL_WIDTH (f
),
13679 PIXEL_HEIGHT (f
), &root_x
, &root_y
);
13680 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
13681 root_x
, root_y
, 0, 0,
13682 SWP_NOSIZE
| SWP_NOACTIVATE
);
13688 /* Hide a previous tip, if any. */
13691 ASET (last_show_tip_args
, 0, string
);
13692 ASET (last_show_tip_args
, 1, frame
);
13693 ASET (last_show_tip_args
, 2, parms
);
13695 /* Add default values to frame parameters. */
13696 if (NILP (Fassq (Qname
, parms
)))
13697 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
13698 if (NILP (Fassq (Qinternal_border_width
, parms
)))
13699 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
13700 if (NILP (Fassq (Qborder_width
, parms
)))
13701 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
13702 if (NILP (Fassq (Qborder_color
, parms
)))
13703 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
13704 if (NILP (Fassq (Qbackground_color
, parms
)))
13705 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
13708 /* Block input until the tip has been fully drawn, to avoid crashes
13709 when drawing tips in menus. */
13712 /* Create a frame for the tooltip, and record it in the global
13713 variable tip_frame. */
13714 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
13715 f
= XFRAME (frame
);
13717 /* Set up the frame's root window. */
13718 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
13719 w
->left
= w
->top
= make_number (0);
13721 if (CONSP (Vx_max_tooltip_size
)
13722 && INTEGERP (XCAR (Vx_max_tooltip_size
))
13723 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
13724 && INTEGERP (XCDR (Vx_max_tooltip_size
))
13725 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
13727 w
->width
= XCAR (Vx_max_tooltip_size
);
13728 w
->height
= XCDR (Vx_max_tooltip_size
);
13732 w
->width
= make_number (80);
13733 w
->height
= make_number (40);
13736 f
->window_width
= XINT (w
->width
);
13738 w
->pseudo_window_p
= 1;
13740 /* Display the tooltip text in a temporary buffer. */
13741 old_buffer
= current_buffer
;
13742 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
13743 current_buffer
->truncate_lines
= Qnil
;
13744 clear_glyph_matrix (w
->desired_matrix
);
13745 clear_glyph_matrix (w
->current_matrix
);
13746 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
13747 try_window (FRAME_ROOT_WINDOW (f
), pos
);
13749 /* Compute width and height of the tooltip. */
13750 width
= height
= 0;
13751 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
13753 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
13754 struct glyph
*last
;
13757 /* Stop at the first empty row at the end. */
13758 if (!row
->enabled_p
|| !row
->displays_text_p
)
13761 /* Let the row go over the full width of the frame. */
13762 row
->full_width_p
= 1;
13764 #ifdef TODO /* Investigate why some fonts need more width than is
13765 calculated for some tooltips. */
13766 /* There's a glyph at the end of rows that is use to place
13767 the cursor there. Don't include the width of this glyph. */
13768 if (row
->used
[TEXT_AREA
])
13770 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
13771 row_width
= row
->pixel_width
- last
->pixel_width
;
13775 row_width
= row
->pixel_width
;
13777 /* TODO: find why tips do not draw along baseline as instructed. */
13778 height
+= row
->height
;
13779 width
= max (width
, row_width
);
13782 /* Add the frame's internal border to the width and height the X
13783 window should have. */
13784 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
13785 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
13787 /* Move the tooltip window where the mouse pointer is. Resize and
13789 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
13792 /* Adjust Window size to take border into account. */
13794 rect
.left
= rect
.top
= 0;
13795 rect
.right
= width
;
13796 rect
.bottom
= height
;
13797 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
13798 FRAME_EXTERNAL_MENU_BAR (f
));
13800 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
13801 root_x
, root_y
, rect
.right
- rect
.left
,
13802 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
13804 /* Let redisplay know that we have made the frame visible already. */
13805 f
->async_visible
= 1;
13807 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
13810 /* Draw into the window. */
13811 w
->must_be_updated_p
= 1;
13812 update_single_window (w
, 1);
13816 /* Restore original current buffer. */
13817 set_buffer_internal_1 (old_buffer
);
13818 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
13821 /* Let the tip disappear after timeout seconds. */
13822 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
13823 intern ("x-hide-tip"));
13826 return unbind_to (count
, Qnil
);
13830 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
13831 doc
: /* Hide the current tooltip window, if there is any.
13832 Value is t if tooltip was open, nil otherwise. */)
13836 Lisp_Object deleted
, frame
, timer
;
13837 struct gcpro gcpro1
, gcpro2
;
13839 /* Return quickly if nothing to do. */
13840 if (NILP (tip_timer
) && NILP (tip_frame
))
13845 GCPRO2 (frame
, timer
);
13846 tip_frame
= tip_timer
= deleted
= Qnil
;
13848 count
= BINDING_STACK_SIZE ();
13849 specbind (Qinhibit_redisplay
, Qt
);
13850 specbind (Qinhibit_quit
, Qt
);
13853 call1 (Qcancel_timer
, timer
);
13855 if (FRAMEP (frame
))
13857 Fdelete_frame (frame
, Qnil
);
13862 return unbind_to (count
, deleted
);
13867 /***********************************************************************
13868 File selection dialog
13869 ***********************************************************************/
13871 extern Lisp_Object Qfile_name_history
;
13873 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
13874 doc
: /* Read file name, prompting with PROMPT in directory DIR.
13875 Use a file selection dialog.
13876 Select DEFAULT-FILENAME in the dialog's file selection box, if
13877 specified. Ensure that file exists if MUSTMATCH is non-nil. */)
13878 (prompt
, dir
, default_filename
, mustmatch
)
13879 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
13881 struct frame
*f
= SELECTED_FRAME ();
13882 Lisp_Object file
= Qnil
;
13883 int count
= specpdl_ptr
- specpdl
;
13884 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
13885 char filename
[MAX_PATH
+ 1];
13886 char init_dir
[MAX_PATH
+ 1];
13887 int use_dialog_p
= 1;
13889 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
13890 CHECK_STRING (prompt
);
13891 CHECK_STRING (dir
);
13893 /* Create the dialog with PROMPT as title, using DIR as initial
13894 directory and using "*" as pattern. */
13895 dir
= Fexpand_file_name (dir
, Qnil
);
13896 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
13897 init_dir
[MAX_PATH
] = '\0';
13898 unixtodos_filename (init_dir
);
13900 if (STRINGP (default_filename
))
13902 char *file_name_only
;
13903 char *full_path_name
= XSTRING (default_filename
)->data
;
13905 unixtodos_filename (full_path_name
);
13907 file_name_only
= strrchr (full_path_name
, '\\');
13908 if (!file_name_only
)
13909 file_name_only
= full_path_name
;
13914 /* If default_file_name is a directory, don't use the open
13915 file dialog, as it does not support selecting
13917 if (!(*file_name_only
))
13921 strncpy (filename
, file_name_only
, MAX_PATH
);
13922 filename
[MAX_PATH
] = '\0';
13925 filename
[0] = '\0';
13929 OPENFILENAME file_details
;
13931 /* Prevent redisplay. */
13932 specbind (Qinhibit_redisplay
, Qt
);
13935 bzero (&file_details
, sizeof (file_details
));
13936 file_details
.lStructSize
= sizeof (file_details
);
13937 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
13938 /* Undocumented Bug in Common File Dialog:
13939 If a filter is not specified, shell links are not resolved. */
13940 file_details
.lpstrFilter
= "ALL Files (*.*)\0*.*\0\0";
13941 file_details
.lpstrFile
= filename
;
13942 file_details
.nMaxFile
= sizeof (filename
);
13943 file_details
.lpstrInitialDir
= init_dir
;
13944 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
13945 file_details
.Flags
= OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
;
13947 if (!NILP (mustmatch
))
13948 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
13950 if (GetOpenFileName (&file_details
))
13952 dostounix_filename (filename
);
13953 file
= build_string (filename
);
13959 file
= unbind_to (count
, file
);
13961 /* Open File dialog will not allow folders to be selected, so resort
13962 to minibuffer completing reads for directories. */
13964 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
13965 dir
, mustmatch
, dir
, Qfile_name_history
,
13966 default_filename
, Qnil
);
13970 /* Make "Cancel" equivalent to C-g. */
13972 Fsignal (Qquit
, Qnil
);
13974 return unbind_to (count
, file
);
13979 /***********************************************************************
13980 w32 specialized functions
13981 ***********************************************************************/
13983 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
13984 doc
: /* Select a font using the W32 font dialog.
13985 Returns an X font string corresponding to the selection. */)
13986 (frame
, include_proportional
)
13987 Lisp_Object frame
, include_proportional
;
13989 FRAME_PTR f
= check_x_frame (frame
);
13997 bzero (&cf
, sizeof (cf
));
13998 bzero (&lf
, sizeof (lf
));
14000 cf
.lStructSize
= sizeof (cf
);
14001 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
14002 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
14004 /* Unless include_proportional is non-nil, limit the selection to
14005 monospaced fonts. */
14006 if (NILP (include_proportional
))
14007 cf
.Flags
|= CF_FIXEDPITCHONLY
;
14009 cf
.lpLogFont
= &lf
;
14011 /* Initialize as much of the font details as we can from the current
14013 hdc
= GetDC (FRAME_W32_WINDOW (f
));
14014 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
14015 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
14016 if (GetTextMetrics (hdc
, &tm
))
14018 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
14019 lf
.lfWeight
= tm
.tmWeight
;
14020 lf
.lfItalic
= tm
.tmItalic
;
14021 lf
.lfUnderline
= tm
.tmUnderlined
;
14022 lf
.lfStrikeOut
= tm
.tmStruckOut
;
14023 lf
.lfCharSet
= tm
.tmCharSet
;
14024 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
14026 SelectObject (hdc
, oldobj
);
14027 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
14029 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
14032 return build_string (buf
);
14035 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
14036 Sw32_send_sys_command
, 1, 2, 0,
14037 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
14038 Some useful values for command are #xf030 to maximise frame (#xf020
14039 to minimize), #xf120 to restore frame to original size, and #xf100
14040 to activate the menubar for keyboard access. #xf140 activates the
14041 screen saver if defined.
14043 If optional parameter FRAME is not specified, use selected frame. */)
14045 Lisp_Object command
, frame
;
14047 FRAME_PTR f
= check_x_frame (frame
);
14049 CHECK_NUMBER (command
);
14051 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
14056 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
14057 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
14058 This is a wrapper around the ShellExecute system function, which
14059 invokes the application registered to handle OPERATION for DOCUMENT.
14060 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
14061 nil for the default action), and DOCUMENT is typically the name of a
14062 document file or URL, but can also be a program executable to run or
14063 a directory to open in the Windows Explorer.
14065 If DOCUMENT is a program executable, PARAMETERS can be a string
14066 containing command line parameters, but otherwise should be nil.
14068 SHOW-FLAG can be used to control whether the invoked application is hidden
14069 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
14070 otherwise it is an integer representing a ShowWindow flag:
14074 3 - start maximized
14075 6 - start minimized */)
14076 (operation
, document
, parameters
, show_flag
)
14077 Lisp_Object operation
, document
, parameters
, show_flag
;
14079 Lisp_Object current_dir
;
14081 CHECK_STRING (document
);
14083 /* Encode filename and current directory. */
14084 current_dir
= ENCODE_FILE (current_buffer
->directory
);
14085 document
= ENCODE_FILE (document
);
14086 if ((int) ShellExecute (NULL
,
14087 (STRINGP (operation
) ?
14088 XSTRING (operation
)->data
: NULL
),
14089 XSTRING (document
)->data
,
14090 (STRINGP (parameters
) ?
14091 XSTRING (parameters
)->data
: NULL
),
14092 XSTRING (current_dir
)->data
,
14093 (INTEGERP (show_flag
) ?
14094 XINT (show_flag
) : SW_SHOWDEFAULT
))
14097 error ("ShellExecute failed: %s", w32_strerror (0));
14100 /* Lookup virtual keycode from string representing the name of a
14101 non-ascii keystroke into the corresponding virtual key, using
14102 lispy_function_keys. */
14104 lookup_vk_code (char *key
)
14108 for (i
= 0; i
< 256; i
++)
14109 if (lispy_function_keys
[i
] != 0
14110 && strcmp (lispy_function_keys
[i
], key
) == 0)
14116 /* Convert a one-element vector style key sequence to a hot key
14119 w32_parse_hot_key (key
)
14122 /* Copied from Fdefine_key and store_in_keymap. */
14123 register Lisp_Object c
;
14125 int lisp_modifiers
;
14127 struct gcpro gcpro1
;
14129 CHECK_VECTOR (key
);
14131 if (XFASTINT (Flength (key
)) != 1)
14136 c
= Faref (key
, make_number (0));
14138 if (CONSP (c
) && lucid_event_type_list_p (c
))
14139 c
= Fevent_convert_list (c
);
14143 if (! INTEGERP (c
) && ! SYMBOLP (c
))
14144 error ("Key definition is invalid");
14146 /* Work out the base key and the modifiers. */
14149 c
= parse_modifiers (c
);
14150 lisp_modifiers
= Fcar (Fcdr (c
));
14154 vk_code
= lookup_vk_code (XSYMBOL (c
)->name
->data
);
14156 else if (INTEGERP (c
))
14158 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
14159 /* Many ascii characters are their own virtual key code. */
14160 vk_code
= XINT (c
) & CHARACTERBITS
;
14163 if (vk_code
< 0 || vk_code
> 255)
14166 if ((lisp_modifiers
& meta_modifier
) != 0
14167 && !NILP (Vw32_alt_is_meta
))
14168 lisp_modifiers
|= alt_modifier
;
14170 /* Supply defs missing from mingw32. */
14172 #define MOD_ALT 0x0001
14173 #define MOD_CONTROL 0x0002
14174 #define MOD_SHIFT 0x0004
14175 #define MOD_WIN 0x0008
14178 /* Convert lisp modifiers to Windows hot-key form. */
14179 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
14180 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
14181 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
14182 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
14184 return HOTKEY (vk_code
, w32_modifiers
);
14187 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
14188 Sw32_register_hot_key
, 1, 1, 0,
14189 doc
: /* Register KEY as a hot-key combination.
14190 Certain key combinations like Alt-Tab are reserved for system use on
14191 Windows, and therefore are normally intercepted by the system. However,
14192 most of these key combinations can be received by registering them as
14193 hot-keys, overriding their special meaning.
14195 KEY must be a one element key definition in vector form that would be
14196 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
14197 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
14198 is always interpreted as the Windows modifier keys.
14200 The return value is the hotkey-id if registered, otherwise nil. */)
14204 key
= w32_parse_hot_key (key
);
14206 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
14208 /* Reuse an empty slot if possible. */
14209 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
14211 /* Safe to add new key to list, even if we have focus. */
14213 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
14215 XSETCAR (item
, key
);
14217 /* Notify input thread about new hot-key definition, so that it
14218 takes effect without needing to switch focus. */
14219 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
14226 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
14227 Sw32_unregister_hot_key
, 1, 1, 0,
14228 doc
: /* Unregister HOTKEY as a hot-key combination. */)
14234 if (!INTEGERP (key
))
14235 key
= w32_parse_hot_key (key
);
14237 item
= Fmemq (key
, w32_grabbed_keys
);
14241 /* Notify input thread about hot-key definition being removed, so
14242 that it takes effect without needing focus switch. */
14243 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
14244 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
14247 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
14254 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
14255 Sw32_registered_hot_keys
, 0, 0, 0,
14256 doc
: /* Return list of registered hot-key IDs. */)
14259 return Fcopy_sequence (w32_grabbed_keys
);
14262 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
14263 Sw32_reconstruct_hot_key
, 1, 1, 0,
14264 doc
: /* Convert hot-key ID to a lisp key combination. */)
14266 Lisp_Object hotkeyid
;
14268 int vk_code
, w32_modifiers
;
14271 CHECK_NUMBER (hotkeyid
);
14273 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
14274 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
14276 if (lispy_function_keys
[vk_code
])
14277 key
= intern (lispy_function_keys
[vk_code
]);
14279 key
= make_number (vk_code
);
14281 key
= Fcons (key
, Qnil
);
14282 if (w32_modifiers
& MOD_SHIFT
)
14283 key
= Fcons (Qshift
, key
);
14284 if (w32_modifiers
& MOD_CONTROL
)
14285 key
= Fcons (Qctrl
, key
);
14286 if (w32_modifiers
& MOD_ALT
)
14287 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
14288 if (w32_modifiers
& MOD_WIN
)
14289 key
= Fcons (Qhyper
, key
);
14294 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
14295 Sw32_toggle_lock_key
, 1, 2, 0,
14296 doc
: /* Toggle the state of the lock key KEY.
14297 KEY can be `capslock', `kp-numlock', or `scroll'.
14298 If the optional parameter NEW-STATE is a number, then the state of KEY
14299 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
14301 Lisp_Object key
, new_state
;
14305 if (EQ (key
, intern ("capslock")))
14306 vk_code
= VK_CAPITAL
;
14307 else if (EQ (key
, intern ("kp-numlock")))
14308 vk_code
= VK_NUMLOCK
;
14309 else if (EQ (key
, intern ("scroll")))
14310 vk_code
= VK_SCROLL
;
14314 if (!dwWindowsThreadId
)
14315 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
14317 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
14318 (WPARAM
) vk_code
, (LPARAM
) new_state
))
14321 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
14322 return make_number (msg
.wParam
);
14327 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
14328 doc
: /* Return storage information about the file system FILENAME is on.
14329 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
14330 storage of the file system, FREE is the free storage, and AVAIL is the
14331 storage available to a non-superuser. All 3 numbers are in bytes.
14332 If the underlying system call fails, value is nil. */)
14334 Lisp_Object filename
;
14336 Lisp_Object encoded
, value
;
14338 CHECK_STRING (filename
);
14339 filename
= Fexpand_file_name (filename
, Qnil
);
14340 encoded
= ENCODE_FILE (filename
);
14344 /* Determining the required information on Windows turns out, sadly,
14345 to be more involved than one would hope. The original Win32 api
14346 call for this will return bogus information on some systems, but we
14347 must dynamically probe for the replacement api, since that was
14348 added rather late on. */
14350 HMODULE hKernel
= GetModuleHandle ("kernel32");
14351 BOOL (*pfn_GetDiskFreeSpaceEx
)
14352 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
14353 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
14355 /* On Windows, we may need to specify the root directory of the
14356 volume holding FILENAME. */
14357 char rootname
[MAX_PATH
];
14358 char *name
= XSTRING (encoded
)->data
;
14360 /* find the root name of the volume if given */
14361 if (isalpha (name
[0]) && name
[1] == ':')
14363 rootname
[0] = name
[0];
14364 rootname
[1] = name
[1];
14365 rootname
[2] = '\\';
14368 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
14370 char *str
= rootname
;
14374 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
14384 if (pfn_GetDiskFreeSpaceEx
)
14386 LARGE_INTEGER availbytes
;
14387 LARGE_INTEGER freebytes
;
14388 LARGE_INTEGER totalbytes
;
14390 if (pfn_GetDiskFreeSpaceEx(rootname
,
14394 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
14395 make_float ((double) freebytes
.QuadPart
),
14396 make_float ((double) availbytes
.QuadPart
));
14400 DWORD sectors_per_cluster
;
14401 DWORD bytes_per_sector
;
14402 DWORD free_clusters
;
14403 DWORD total_clusters
;
14405 if (GetDiskFreeSpace(rootname
,
14406 §ors_per_cluster
,
14410 value
= list3 (make_float ((double) total_clusters
14411 * sectors_per_cluster
* bytes_per_sector
),
14412 make_float ((double) free_clusters
14413 * sectors_per_cluster
* bytes_per_sector
),
14414 make_float ((double) free_clusters
14415 * sectors_per_cluster
* bytes_per_sector
));
14422 /***********************************************************************
14424 ***********************************************************************/
14429 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
14431 /* This is zero if not using MS-Windows. */
14434 /* TrackMouseEvent not available in all versions of Windows, so must load
14435 it dynamically. Do it once, here, instead of every time it is used. */
14436 track_mouse_event_fn
= GetProcAddress (user32_lib
, "TrackMouseEvent");
14437 track_mouse_window
= NULL
;
14439 /* The section below is built by the lisp expression at the top of the file,
14440 just above where these variables are declared. */
14441 /*&&& init symbols here &&&*/
14442 Qauto_raise
= intern ("auto-raise");
14443 staticpro (&Qauto_raise
);
14444 Qauto_lower
= intern ("auto-lower");
14445 staticpro (&Qauto_lower
);
14446 Qbar
= intern ("bar");
14448 Qborder_color
= intern ("border-color");
14449 staticpro (&Qborder_color
);
14450 Qborder_width
= intern ("border-width");
14451 staticpro (&Qborder_width
);
14452 Qbox
= intern ("box");
14454 Qcursor_color
= intern ("cursor-color");
14455 staticpro (&Qcursor_color
);
14456 Qcursor_type
= intern ("cursor-type");
14457 staticpro (&Qcursor_type
);
14458 Qgeometry
= intern ("geometry");
14459 staticpro (&Qgeometry
);
14460 Qicon_left
= intern ("icon-left");
14461 staticpro (&Qicon_left
);
14462 Qicon_top
= intern ("icon-top");
14463 staticpro (&Qicon_top
);
14464 Qicon_type
= intern ("icon-type");
14465 staticpro (&Qicon_type
);
14466 Qicon_name
= intern ("icon-name");
14467 staticpro (&Qicon_name
);
14468 Qinternal_border_width
= intern ("internal-border-width");
14469 staticpro (&Qinternal_border_width
);
14470 Qleft
= intern ("left");
14471 staticpro (&Qleft
);
14472 Qright
= intern ("right");
14473 staticpro (&Qright
);
14474 Qmouse_color
= intern ("mouse-color");
14475 staticpro (&Qmouse_color
);
14476 Qnone
= intern ("none");
14477 staticpro (&Qnone
);
14478 Qparent_id
= intern ("parent-id");
14479 staticpro (&Qparent_id
);
14480 Qscroll_bar_width
= intern ("scroll-bar-width");
14481 staticpro (&Qscroll_bar_width
);
14482 Qsuppress_icon
= intern ("suppress-icon");
14483 staticpro (&Qsuppress_icon
);
14484 Qundefined_color
= intern ("undefined-color");
14485 staticpro (&Qundefined_color
);
14486 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
14487 staticpro (&Qvertical_scroll_bars
);
14488 Qvisibility
= intern ("visibility");
14489 staticpro (&Qvisibility
);
14490 Qwindow_id
= intern ("window-id");
14491 staticpro (&Qwindow_id
);
14492 Qx_frame_parameter
= intern ("x-frame-parameter");
14493 staticpro (&Qx_frame_parameter
);
14494 Qx_resource_name
= intern ("x-resource-name");
14495 staticpro (&Qx_resource_name
);
14496 Quser_position
= intern ("user-position");
14497 staticpro (&Quser_position
);
14498 Quser_size
= intern ("user-size");
14499 staticpro (&Quser_size
);
14500 Qscreen_gamma
= intern ("screen-gamma");
14501 staticpro (&Qscreen_gamma
);
14502 Qline_spacing
= intern ("line-spacing");
14503 staticpro (&Qline_spacing
);
14504 Qcenter
= intern ("center");
14505 staticpro (&Qcenter
);
14506 Qcancel_timer
= intern ("cancel-timer");
14507 staticpro (&Qcancel_timer
);
14508 /* This is the end of symbol initialization. */
14510 Qhyper
= intern ("hyper");
14511 staticpro (&Qhyper
);
14512 Qsuper
= intern ("super");
14513 staticpro (&Qsuper
);
14514 Qmeta
= intern ("meta");
14515 staticpro (&Qmeta
);
14516 Qalt
= intern ("alt");
14518 Qctrl
= intern ("ctrl");
14519 staticpro (&Qctrl
);
14520 Qcontrol
= intern ("control");
14521 staticpro (&Qcontrol
);
14522 Qshift
= intern ("shift");
14523 staticpro (&Qshift
);
14525 /* Text property `display' should be nonsticky by default. */
14526 Vtext_property_default_nonsticky
14527 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
14530 Qlaplace
= intern ("laplace");
14531 staticpro (&Qlaplace
);
14532 Qemboss
= intern ("emboss");
14533 staticpro (&Qemboss
);
14534 Qedge_detection
= intern ("edge-detection");
14535 staticpro (&Qedge_detection
);
14536 Qheuristic
= intern ("heuristic");
14537 staticpro (&Qheuristic
);
14538 QCmatrix
= intern (":matrix");
14539 staticpro (&QCmatrix
);
14540 QCcolor_adjustment
= intern (":color-adjustment");
14541 staticpro (&QCcolor_adjustment
);
14542 QCmask
= intern (":mask");
14543 staticpro (&QCmask
);
14545 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
14546 staticpro (&Qface_set_after_frame_default
);
14548 Fput (Qundefined_color
, Qerror_conditions
,
14549 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
14550 Fput (Qundefined_color
, Qerror_message
,
14551 build_string ("Undefined color"));
14553 staticpro (&w32_grabbed_keys
);
14554 w32_grabbed_keys
= Qnil
;
14556 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
14557 doc
: /* An array of color name mappings for windows. */);
14558 Vw32_color_map
= Qnil
;
14560 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
14561 doc
: /* Non-nil if alt key presses are passed on to Windows.
14562 When non-nil, for example, alt pressed and released and then space will
14563 open the System menu. When nil, Emacs silently swallows alt key events. */);
14564 Vw32_pass_alt_to_system
= Qnil
;
14566 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
14567 doc
: /* Non-nil if the alt key is to be considered the same as the meta key.
14568 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta. */);
14569 Vw32_alt_is_meta
= Qt
;
14571 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
14572 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
14573 XSETINT (Vw32_quit_key
, 0);
14575 DEFVAR_LISP ("w32-pass-lwindow-to-system",
14576 &Vw32_pass_lwindow_to_system
,
14577 doc
: /* Non-nil if the left \"Windows\" key is passed on to Windows.
14578 When non-nil, the Start menu is opened by tapping the key. */);
14579 Vw32_pass_lwindow_to_system
= Qt
;
14581 DEFVAR_LISP ("w32-pass-rwindow-to-system",
14582 &Vw32_pass_rwindow_to_system
,
14583 doc
: /* Non-nil if the right \"Windows\" key is passed on to Windows.
14584 When non-nil, the Start menu is opened by tapping the key. */);
14585 Vw32_pass_rwindow_to_system
= Qt
;
14587 DEFVAR_INT ("w32-phantom-key-code",
14588 &Vw32_phantom_key_code
,
14589 doc
: /* Virtual key code used to generate \"phantom\" key presses.
14590 Value is a number between 0 and 255.
14592 Phantom key presses are generated in order to stop the system from
14593 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
14594 `w32-pass-rwindow-to-system' is nil. */);
14595 /* Although 255 is technically not a valid key code, it works and
14596 means that this hack won't interfere with any real key code. */
14597 Vw32_phantom_key_code
= 255;
14599 DEFVAR_LISP ("w32-enable-num-lock",
14600 &Vw32_enable_num_lock
,
14601 doc
: /* Non-nil if Num Lock should act normally.
14602 Set to nil to see Num Lock as the key `kp-numlock'. */);
14603 Vw32_enable_num_lock
= Qt
;
14605 DEFVAR_LISP ("w32-enable-caps-lock",
14606 &Vw32_enable_caps_lock
,
14607 doc
: /* Non-nil if Caps Lock should act normally.
14608 Set to nil to see Caps Lock as the key `capslock'. */);
14609 Vw32_enable_caps_lock
= Qt
;
14611 DEFVAR_LISP ("w32-scroll-lock-modifier",
14612 &Vw32_scroll_lock_modifier
,
14613 doc
: /* Modifier to use for the Scroll Lock on state.
14614 The value can be hyper, super, meta, alt, control or shift for the
14615 respective modifier, or nil to see Scroll Lock as the key `scroll'.
14616 Any other value will cause the key to be ignored. */);
14617 Vw32_scroll_lock_modifier
= Qt
;
14619 DEFVAR_LISP ("w32-lwindow-modifier",
14620 &Vw32_lwindow_modifier
,
14621 doc
: /* Modifier to use for the left \"Windows\" key.
14622 The value can be hyper, super, meta, alt, control or shift for the
14623 respective modifier, or nil to appear as the key `lwindow'.
14624 Any other value will cause the key to be ignored. */);
14625 Vw32_lwindow_modifier
= Qnil
;
14627 DEFVAR_LISP ("w32-rwindow-modifier",
14628 &Vw32_rwindow_modifier
,
14629 doc
: /* Modifier to use for the right \"Windows\" key.
14630 The value can be hyper, super, meta, alt, control or shift for the
14631 respective modifier, or nil to appear as the key `rwindow'.
14632 Any other value will cause the key to be ignored. */);
14633 Vw32_rwindow_modifier
= Qnil
;
14635 DEFVAR_LISP ("w32-apps-modifier",
14636 &Vw32_apps_modifier
,
14637 doc
: /* Modifier to use for the \"Apps\" key.
14638 The value can be hyper, super, meta, alt, control or shift for the
14639 respective modifier, or nil to appear as the key `apps'.
14640 Any other value will cause the key to be ignored. */);
14641 Vw32_apps_modifier
= Qnil
;
14643 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
14644 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
14645 w32_enable_synthesized_fonts
= 0;
14647 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
14648 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
14649 Vw32_enable_palette
= Qt
;
14651 DEFVAR_INT ("w32-mouse-button-tolerance",
14652 &Vw32_mouse_button_tolerance
,
14653 doc
: /* Analogue of double click interval for faking middle mouse events.
14654 The value is the minimum time in milliseconds that must elapse between
14655 left/right button down events before they are considered distinct events.
14656 If both mouse buttons are depressed within this interval, a middle mouse
14657 button down event is generated instead. */);
14658 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
14660 DEFVAR_INT ("w32-mouse-move-interval",
14661 &Vw32_mouse_move_interval
,
14662 doc
: /* Minimum interval between mouse move events.
14663 The value is the minimum time in milliseconds that must elapse between
14664 successive mouse move (or scroll bar drag) events before they are
14665 reported as lisp events. */);
14666 XSETINT (Vw32_mouse_move_interval
, 0);
14668 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
14669 &w32_pass_extra_mouse_buttons_to_system
,
14670 doc
: /* Non-nil if the fourth and fifth mouse buttons are passed to Windows.
14671 Recent versions of Windows support mice with up to five buttons.
14672 Since most applications don't support these extra buttons, most mouse
14673 drivers will allow you to map them to functions at the system level.
14674 If this variable is non-nil, Emacs will pass them on, allowing the
14675 system to handle them. */);
14676 w32_pass_extra_mouse_buttons_to_system
= 0;
14678 init_x_parm_symbols ();
14680 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
14681 doc
: /* List of directories to search for bitmap files for w32. */);
14682 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
14684 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
14685 doc
: /* The shape of the pointer when over text.
14686 Changing the value does not affect existing frames
14687 unless you set the mouse color. */);
14688 Vx_pointer_shape
= Qnil
;
14690 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
14691 doc
: /* The name Emacs uses to look up resources; for internal use only.
14692 `x-get-resource' uses this as the first component of the instance name
14693 when requesting resource values.
14694 Emacs initially sets `x-resource-name' to the name under which Emacs
14695 was invoked, or to the value specified with the `-name' or `-rn'
14696 switches, if present. */);
14697 Vx_resource_name
= Qnil
;
14699 Vx_nontext_pointer_shape
= Qnil
;
14701 Vx_mode_pointer_shape
= Qnil
;
14703 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
14704 doc
: /* The shape of the pointer when Emacs is busy.
14705 This variable takes effect when you create a new frame
14706 or when you set the mouse color. */);
14707 Vx_hourglass_pointer_shape
= Qnil
;
14709 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
14710 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
14711 display_hourglass_p
= 1;
14713 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
14714 doc
: /* *Seconds to wait before displaying an hourglass pointer.
14715 Value must be an integer or float. */);
14716 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
14718 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
14719 &Vx_sensitive_text_pointer_shape
,
14720 doc
: /* The shape of the pointer when over mouse-sensitive text.
14721 This variable takes effect when you create a new frame
14722 or when you set the mouse color. */);
14723 Vx_sensitive_text_pointer_shape
= Qnil
;
14725 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
14726 &Vx_window_horizontal_drag_shape
,
14727 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
14728 This variable takes effect when you create a new frame
14729 or when you set the mouse color. */);
14730 Vx_window_horizontal_drag_shape
= Qnil
;
14732 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
14733 doc
: /* A string indicating the foreground color of the cursor box. */);
14734 Vx_cursor_fore_pixel
= Qnil
;
14736 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
14737 doc
: /* Maximum size for tooltips.
14738 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
14739 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
14741 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
14742 doc
: /* Non-nil if no window manager is in use.
14743 Emacs doesn't try to figure this out; this is always nil
14744 unless you set it to something else. */);
14745 /* We don't have any way to find this out, so set it to nil
14746 and maybe the user would like to set it to t. */
14747 Vx_no_window_manager
= Qnil
;
14749 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
14750 &Vx_pixel_size_width_font_regexp
,
14751 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
14753 Since Emacs gets width of a font matching with this regexp from
14754 PIXEL_SIZE field of the name, font finding mechanism gets faster for
14755 such a font. This is especially effective for such large fonts as
14756 Chinese, Japanese, and Korean. */);
14757 Vx_pixel_size_width_font_regexp
= Qnil
;
14759 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
14760 doc
: /* Time after which cached images are removed from the cache.
14761 When an image has not been displayed this many seconds, remove it
14762 from the image cache. Value must be an integer or nil with nil
14763 meaning don't clear the cache. */);
14764 Vimage_cache_eviction_delay
= make_number (30 * 60);
14766 DEFVAR_LISP ("w32-bdf-filename-alist",
14767 &Vw32_bdf_filename_alist
,
14768 doc
: /* List of bdf fonts and their corresponding filenames. */);
14769 Vw32_bdf_filename_alist
= Qnil
;
14771 DEFVAR_BOOL ("w32-strict-fontnames",
14772 &w32_strict_fontnames
,
14773 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
14774 Default is nil, which allows old fontnames that are not XLFD compliant,
14775 and allows third-party CJK display to work by specifying false charset
14776 fields to trick Emacs into translating to Big5, SJIS etc.
14777 Setting this to t will prevent wrong fonts being selected when
14778 fontsets are automatically created. */);
14779 w32_strict_fontnames
= 0;
14781 DEFVAR_BOOL ("w32-strict-painting",
14782 &w32_strict_painting
,
14783 doc
: /* Non-nil means use strict rules for repainting frames.
14784 Set this to nil to get the old behaviour for repainting; this should
14785 only be necessary if the default setting causes problems. */);
14786 w32_strict_painting
= 1;
14788 DEFVAR_LISP ("w32-charset-info-alist",
14789 &Vw32_charset_info_alist
,
14790 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
14791 Each entry should be of the form:
14793 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
14795 where CHARSET_NAME is a string used in font names to identify the charset,
14796 WINDOWS_CHARSET is a symbol that can be one of:
14797 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
14798 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
14799 w32-charset-chinesebig5,
14800 #ifdef JOHAB_CHARSET
14801 w32-charset-johab, w32-charset-hebrew,
14802 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
14803 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
14804 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
14806 #ifdef UNICODE_CHARSET
14807 w32-charset-unicode,
14809 or w32-charset-oem.
14810 CODEPAGE should be an integer specifying the codepage that should be used
14811 to display the character set, t to do no translation and output as Unicode,
14812 or nil to do no translation and output as 8 bit (or multibyte on far-east
14813 versions of Windows) characters. */);
14814 Vw32_charset_info_alist
= Qnil
;
14816 staticpro (&Qw32_charset_ansi
);
14817 Qw32_charset_ansi
= intern ("w32-charset-ansi");
14818 staticpro (&Qw32_charset_symbol
);
14819 Qw32_charset_symbol
= intern ("w32-charset-symbol");
14820 staticpro (&Qw32_charset_shiftjis
);
14821 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
14822 staticpro (&Qw32_charset_hangeul
);
14823 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
14824 staticpro (&Qw32_charset_chinesebig5
);
14825 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
14826 staticpro (&Qw32_charset_gb2312
);
14827 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
14828 staticpro (&Qw32_charset_oem
);
14829 Qw32_charset_oem
= intern ("w32-charset-oem");
14831 #ifdef JOHAB_CHARSET
14833 static int w32_extra_charsets_defined
= 1;
14834 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
14835 doc
: /* Internal variable. */);
14837 staticpro (&Qw32_charset_johab
);
14838 Qw32_charset_johab
= intern ("w32-charset-johab");
14839 staticpro (&Qw32_charset_easteurope
);
14840 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
14841 staticpro (&Qw32_charset_turkish
);
14842 Qw32_charset_turkish
= intern ("w32-charset-turkish");
14843 staticpro (&Qw32_charset_baltic
);
14844 Qw32_charset_baltic
= intern ("w32-charset-baltic");
14845 staticpro (&Qw32_charset_russian
);
14846 Qw32_charset_russian
= intern ("w32-charset-russian");
14847 staticpro (&Qw32_charset_arabic
);
14848 Qw32_charset_arabic
= intern ("w32-charset-arabic");
14849 staticpro (&Qw32_charset_greek
);
14850 Qw32_charset_greek
= intern ("w32-charset-greek");
14851 staticpro (&Qw32_charset_hebrew
);
14852 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
14853 staticpro (&Qw32_charset_vietnamese
);
14854 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
14855 staticpro (&Qw32_charset_thai
);
14856 Qw32_charset_thai
= intern ("w32-charset-thai");
14857 staticpro (&Qw32_charset_mac
);
14858 Qw32_charset_mac
= intern ("w32-charset-mac");
14862 #ifdef UNICODE_CHARSET
14864 static int w32_unicode_charset_defined
= 1;
14865 DEFVAR_BOOL ("w32-unicode-charset-defined",
14866 &w32_unicode_charset_defined
,
14867 doc
: /* Internal variable. */);
14869 staticpro (&Qw32_charset_unicode
);
14870 Qw32_charset_unicode
= intern ("w32-charset-unicode");
14873 defsubr (&Sx_get_resource
);
14874 #if 0 /* TODO: Port to W32 */
14875 defsubr (&Sx_change_window_property
);
14876 defsubr (&Sx_delete_window_property
);
14877 defsubr (&Sx_window_property
);
14879 defsubr (&Sxw_display_color_p
);
14880 defsubr (&Sx_display_grayscale_p
);
14881 defsubr (&Sxw_color_defined_p
);
14882 defsubr (&Sxw_color_values
);
14883 defsubr (&Sx_server_max_request_size
);
14884 defsubr (&Sx_server_vendor
);
14885 defsubr (&Sx_server_version
);
14886 defsubr (&Sx_display_pixel_width
);
14887 defsubr (&Sx_display_pixel_height
);
14888 defsubr (&Sx_display_mm_width
);
14889 defsubr (&Sx_display_mm_height
);
14890 defsubr (&Sx_display_screens
);
14891 defsubr (&Sx_display_planes
);
14892 defsubr (&Sx_display_color_cells
);
14893 defsubr (&Sx_display_visual_class
);
14894 defsubr (&Sx_display_backing_store
);
14895 defsubr (&Sx_display_save_under
);
14896 defsubr (&Sx_parse_geometry
);
14897 defsubr (&Sx_create_frame
);
14898 defsubr (&Sx_open_connection
);
14899 defsubr (&Sx_close_connection
);
14900 defsubr (&Sx_display_list
);
14901 defsubr (&Sx_synchronize
);
14903 /* W32 specific functions */
14905 defsubr (&Sw32_focus_frame
);
14906 defsubr (&Sw32_select_font
);
14907 defsubr (&Sw32_define_rgb_color
);
14908 defsubr (&Sw32_default_color_map
);
14909 defsubr (&Sw32_load_color_file
);
14910 defsubr (&Sw32_send_sys_command
);
14911 defsubr (&Sw32_shell_execute
);
14912 defsubr (&Sw32_register_hot_key
);
14913 defsubr (&Sw32_unregister_hot_key
);
14914 defsubr (&Sw32_registered_hot_keys
);
14915 defsubr (&Sw32_reconstruct_hot_key
);
14916 defsubr (&Sw32_toggle_lock_key
);
14917 defsubr (&Sw32_find_bdf_fonts
);
14919 defsubr (&Sfile_system_info
);
14921 /* Setting callback functions for fontset handler. */
14922 get_font_info_func
= w32_get_font_info
;
14924 #if 0 /* This function pointer doesn't seem to be used anywhere.
14925 And the pointer assigned has the wrong type, anyway. */
14926 list_fonts_func
= w32_list_fonts
;
14929 load_font_func
= w32_load_font
;
14930 find_ccl_program_func
= w32_find_ccl_program
;
14931 query_font_func
= w32_query_font
;
14932 set_frame_fontset_func
= x_set_font
;
14933 check_window_system_func
= check_w32
;
14935 #if 0 /* TODO Image support for W32 */
14937 Qxbm
= intern ("xbm");
14939 QCtype
= intern (":type");
14940 staticpro (&QCtype
);
14941 QCconversion
= intern (":conversion");
14942 staticpro (&QCconversion
);
14943 QCheuristic_mask
= intern (":heuristic-mask");
14944 staticpro (&QCheuristic_mask
);
14945 QCcolor_symbols
= intern (":color-symbols");
14946 staticpro (&QCcolor_symbols
);
14947 QCascent
= intern (":ascent");
14948 staticpro (&QCascent
);
14949 QCmargin
= intern (":margin");
14950 staticpro (&QCmargin
);
14951 QCrelief
= intern (":relief");
14952 staticpro (&QCrelief
);
14953 Qpostscript
= intern ("postscript");
14954 staticpro (&Qpostscript
);
14955 QCloader
= intern (":loader");
14956 staticpro (&QCloader
);
14957 QCbounding_box
= intern (":bounding-box");
14958 staticpro (&QCbounding_box
);
14959 QCpt_width
= intern (":pt-width");
14960 staticpro (&QCpt_width
);
14961 QCpt_height
= intern (":pt-height");
14962 staticpro (&QCpt_height
);
14963 QCindex
= intern (":index");
14964 staticpro (&QCindex
);
14965 Qpbm
= intern ("pbm");
14969 Qxpm
= intern ("xpm");
14974 Qjpeg
= intern ("jpeg");
14975 staticpro (&Qjpeg
);
14979 Qtiff
= intern ("tiff");
14980 staticpro (&Qtiff
);
14984 Qgif
= intern ("gif");
14989 Qpng
= intern ("png");
14993 defsubr (&Sclear_image_cache
);
14996 defsubr (&Simagep
);
14997 defsubr (&Slookup_image
);
15001 hourglass_atimer
= NULL
;
15002 hourglass_shown_p
= 0;
15003 defsubr (&Sx_show_tip
);
15004 defsubr (&Sx_hide_tip
);
15006 staticpro (&tip_timer
);
15008 staticpro (&tip_frame
);
15010 last_show_tip_args
= Qnil
;
15011 staticpro (&last_show_tip_args
);
15013 defsubr (&Sx_file_dialog
);
15020 image_types
= NULL
;
15021 Vimage_types
= Qnil
;
15023 #if 0 /* TODO : Image support for W32 */
15024 define_image_type (&xbm_type
);
15025 define_image_type (&gs_type
);
15026 define_image_type (&pbm_type
);
15029 define_image_type (&xpm_type
);
15033 define_image_type (&jpeg_type
);
15037 define_image_type (&tiff_type
);
15041 define_image_type (&gif_type
);
15045 define_image_type (&png_type
);
15056 button
= MessageBox (NULL
,
15057 "A fatal error has occurred!\n\n"
15058 "Select Abort to exit, Retry to debug, Ignore to continue",
15059 "Emacs Abort Dialog",
15060 MB_ICONEXCLAMATION
| MB_TASKMODAL
15061 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
15076 /* For convenience when debugging. */
15080 return GetLastError ();