(Buffer Internals): Describe new auto_save_file_format field of the
[emacs.git] / src / macfns.c
blob3b09b344a550f67b7435bb42ad44a6b4e5995f09
1 /* Graphical user interface functions for Mac OS.
2 Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Contributed by Andrew Choi (akochoi@mac.com). */
23 #include <config.h>
25 #include <signal.h>
26 #include <stdio.h>
27 #include <math.h>
28 #include <limits.h>
29 #include <errno.h>
31 #include "lisp.h"
32 #include "charset.h"
33 #include "macterm.h"
34 #include "frame.h"
35 #include "window.h"
36 #include "buffer.h"
37 #include "dispextern.h"
38 #include "fontset.h"
39 #include "intervals.h"
40 #include "keyboard.h"
41 #include "blockinput.h"
42 #include "epaths.h"
43 #include "termhooks.h"
44 #include "coding.h"
45 #include "systime.h"
47 /* #include "bitmaps/gray.xbm" */
48 #define gray_width 2
49 #define gray_height 2
50 static unsigned char gray_bits[] = {
51 0x01, 0x02};
53 /*#include <commdlg.h>
54 #include <shellapi.h>*/
55 #include <ctype.h>
56 #include <sys/types.h>
57 #include <sys/stat.h>
59 #include <stdlib.h>
60 #include <string.h>
62 /*extern void free_frame_menubar ();
63 extern double atof ();
64 extern int w32_console_toggle_lock_key (int vk_code, Lisp_Object new_state);
65 extern int quit_char;*/
67 extern char *lispy_function_keys[];
69 /* The gray bitmap `bitmaps/gray'. This is done because macterm.c uses
70 it, and including `bitmaps/gray' more than once is a problem when
71 config.h defines `static' as an empty replacement string. */
73 int gray_bitmap_width = gray_width;
74 int gray_bitmap_height = gray_height;
75 unsigned char *gray_bitmap_bits = gray_bits;
77 /* Non-zero means we're allowed to display an hourglass cursor. */
79 int display_hourglass_p;
81 /* The background and shape of the mouse pointer, and shape when not
82 over text or in the modeline. */
84 Lisp_Object Vx_pointer_shape, Vx_nontext_pointer_shape, Vx_mode_pointer_shape;
85 Lisp_Object Vx_hourglass_pointer_shape;
87 /* The shape when over mouse-sensitive text. */
89 Lisp_Object Vx_sensitive_text_pointer_shape;
91 /* If non-nil, the pointer shape to indicate that windows can be
92 dragged horizontally. */
94 Lisp_Object Vx_window_horizontal_drag_shape;
96 /* Color of chars displayed in cursor box. */
98 Lisp_Object Vx_cursor_fore_pixel;
100 /* Nonzero if using Windows. */
102 static int mac_in_use;
104 /* Non nil if no window manager is in use. */
106 Lisp_Object Vx_no_window_manager;
108 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
110 Lisp_Object Vx_pixel_size_width_font_regexp;
112 /* Evaluate this expression to rebuild the section of syms_of_macfns
113 that initializes and staticpros the symbols declared below. Note
114 that Emacs 18 has a bug that keeps C-x C-e from being able to
115 evaluate this expression.
117 (progn
118 ;; Accumulate a list of the symbols we want to initialize from the
119 ;; declarations at the top of the file.
120 (goto-char (point-min))
121 (search-forward "/\*&&& symbols declared here &&&*\/\n")
122 (let (symbol-list)
123 (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
124 (setq symbol-list
125 (cons (buffer-substring (match-beginning 1) (match-end 1))
126 symbol-list))
127 (forward-line 1))
128 (setq symbol-list (nreverse symbol-list))
129 ;; Delete the section of syms_of_... where we initialize the symbols.
130 (search-forward "\n /\*&&& init symbols here &&&*\/\n")
131 (let ((start (point)))
132 (while (looking-at "^ Q")
133 (forward-line 2))
134 (kill-region start (point)))
135 ;; Write a new symbol initialization section.
136 (while symbol-list
137 (insert (format " %s = intern (\"" (car symbol-list)))
138 (let ((start (point)))
139 (insert (substring (car symbol-list) 1))
140 (subst-char-in-region start (point) ?_ ?-))
141 (insert (format "\");\n staticpro (&%s);\n" (car symbol-list)))
142 (setq symbol-list (cdr symbol-list)))))
146 /*&&& symbols declared here &&&*/
147 Lisp_Object Qnone;
148 Lisp_Object Qsuppress_icon;
149 Lisp_Object Qundefined_color;
150 Lisp_Object Qcancel_timer;
151 Lisp_Object Qhyper;
152 Lisp_Object Qsuper;
153 Lisp_Object Qmeta;
154 Lisp_Object Qalt;
155 Lisp_Object Qctrl;
156 Lisp_Object Qcontrol;
157 Lisp_Object Qshift;
159 extern Lisp_Object Vwindow_system_version;
161 extern int mac_initialized;
164 /* compare two strings ignoring case */
166 static int
167 stricmp (const char *s, const char *t)
169 for ( ; tolower (*s) == tolower (*t); s++, t++)
170 if (*s == '\0')
171 return 0;
172 return tolower (*s) - tolower (*t);
175 /* compare two strings up to n characters, ignoring case */
177 static int
178 strnicmp (const char *s, const char *t, unsigned int n)
180 for ( ; n-- > 0 && tolower (*s) == tolower (*t); s++, t++)
181 if (*s == '\0')
182 return 0;
183 return n == 0 ? 0 : tolower (*s) - tolower (*t);
187 /* Error if we are not running on Mac OS. */
189 void
190 check_mac ()
192 if (! mac_in_use)
193 error ("Mac OS not in use or not initialized");
196 /* Nonzero if we can use mouse menus.
197 You should not call this unless HAVE_MENUS is defined. */
200 have_menus_p ()
202 return mac_in_use;
205 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
206 and checking validity for Mac. */
208 FRAME_PTR
209 check_x_frame (frame)
210 Lisp_Object frame;
212 FRAME_PTR f;
214 if (NILP (frame))
215 frame = selected_frame;
216 CHECK_LIVE_FRAME (frame);
217 f = XFRAME (frame);
218 if (! FRAME_MAC_P (f))
219 error ("non-mac frame used");
220 return f;
223 /* Let the user specify a display with a frame.
224 nil stands for the selected frame--or, if that is not a mac frame,
225 the first display on the list. */
227 struct mac_display_info *
228 check_x_display_info (frame)
229 Lisp_Object frame;
231 if (!mac_initialized)
233 mac_initialize ();
234 mac_initialized = 1;
237 if (NILP (frame))
239 struct frame *sf = XFRAME (selected_frame);
241 if (FRAME_MAC_P (sf) && FRAME_LIVE_P (sf))
242 return FRAME_MAC_DISPLAY_INFO (sf);
243 else
244 return &one_mac_display_info;
246 else if (STRINGP (frame))
247 return x_display_info_for_name (frame);
248 else
250 FRAME_PTR f;
252 CHECK_LIVE_FRAME (frame);
253 f = XFRAME (frame);
254 if (! FRAME_MAC_P (f))
255 error ("non-mac frame used");
256 return FRAME_MAC_DISPLAY_INFO (f);
260 /* Return the Emacs frame-object corresponding to a mac window.
261 It could be the frame's main window or an icon window. */
263 /* This function can be called during GC, so use GC_xxx type test macros. */
265 struct frame *
266 x_window_to_frame (dpyinfo, wdesc)
267 struct mac_display_info *dpyinfo;
268 WindowPtr wdesc;
270 Lisp_Object tail, frame;
271 struct frame *f;
273 for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
275 frame = XCAR (tail);
276 if (!GC_FRAMEP (frame))
277 continue;
278 f = XFRAME (frame);
279 if (!FRAME_W32_P (f) || FRAME_MAC_DISPLAY_INFO (f) != dpyinfo)
280 continue;
281 /*if (f->output_data.w32->hourglass_window == wdesc)
282 return f;*/
284 /* MAC_TODO: Check tooltips when supported. */
285 if (FRAME_MAC_WINDOW (f) == wdesc)
286 return f;
288 return 0;
292 static Lisp_Object unwind_create_frame P_ ((Lisp_Object));
294 void x_set_foreground_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
295 void x_set_background_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
296 void x_set_mouse_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
297 void x_set_cursor_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
298 void x_set_border_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
299 void x_set_cursor_type P_ ((struct frame *, Lisp_Object, Lisp_Object));
300 void x_set_icon_type P_ ((struct frame *, Lisp_Object, Lisp_Object));
301 void x_set_icon_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
302 void x_explicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
303 void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
304 void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object));
305 void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
306 void x_set_scroll_bar_foreground P_ ((struct frame *, Lisp_Object,
307 Lisp_Object));
308 void x_set_scroll_bar_background P_ ((struct frame *, Lisp_Object,
309 Lisp_Object));
310 static Lisp_Object x_default_scroll_bar_color_parameter P_ ((struct frame *,
311 Lisp_Object,
312 Lisp_Object,
313 char *, char *,
314 int));
315 /* Store the screen positions of frame F into XPTR and YPTR.
316 These are the positions of the containing window manager window,
317 not Emacs's own window. */
319 void
320 x_real_positions (f, xptr, yptr)
321 FRAME_PTR f;
322 int *xptr, *yptr;
324 Point pt;
325 GrafPtr oldport;
327 GetPort (&oldport);
328 SetPortWindowPort (FRAME_MAC_WINDOW (f));
330 #if TARGET_API_MAC_CARBON
332 Rect r;
334 GetWindowPortBounds (FRAME_MAC_WINDOW (f), &r);
335 SetPt (&pt, r.left, r.top);
337 #else /* not TARGET_API_MAC_CARBON */
338 SetPt (&pt,
339 FRAME_MAC_WINDOW (f)->portRect.left,
340 FRAME_MAC_WINDOW (f)->portRect.top);
341 #endif /* not TARGET_API_MAC_CARBON */
342 LocalToGlobal (&pt);
343 SetPort (oldport);
345 /* MAC has no frame pixel diff. */
346 f->x_pixels_diff = 0;
347 f->y_pixels_diff = 0;
349 *xptr = pt.h;
350 *yptr = pt.v;
354 /* The default colors for the Mac color map */
355 typedef struct colormap_t
357 unsigned long color;
358 char *name;
359 } colormap_t;
361 colormap_t mac_color_map[] =
363 { RGB_TO_ULONG(255, 250, 250), "snow" },
364 { RGB_TO_ULONG(248, 248, 255), "ghost white" },
365 { RGB_TO_ULONG(248, 248, 255), "GhostWhite" },
366 { RGB_TO_ULONG(245, 245, 245), "white smoke" },
367 { RGB_TO_ULONG(245, 245, 245), "WhiteSmoke" },
368 { RGB_TO_ULONG(220, 220, 220), "gainsboro" },
369 { RGB_TO_ULONG(255, 250, 240), "floral white" },
370 { RGB_TO_ULONG(255, 250, 240), "FloralWhite" },
371 { RGB_TO_ULONG(253, 245, 230), "old lace" },
372 { RGB_TO_ULONG(253, 245, 230), "OldLace" },
373 { RGB_TO_ULONG(250, 240, 230), "linen" },
374 { RGB_TO_ULONG(250, 235, 215), "antique white" },
375 { RGB_TO_ULONG(250, 235, 215), "AntiqueWhite" },
376 { RGB_TO_ULONG(255, 239, 213), "papaya whip" },
377 { RGB_TO_ULONG(255, 239, 213), "PapayaWhip" },
378 { RGB_TO_ULONG(255, 235, 205), "blanched almond" },
379 { RGB_TO_ULONG(255, 235, 205), "BlanchedAlmond" },
380 { RGB_TO_ULONG(255, 228, 196), "bisque" },
381 { RGB_TO_ULONG(255, 218, 185), "peach puff" },
382 { RGB_TO_ULONG(255, 218, 185), "PeachPuff" },
383 { RGB_TO_ULONG(255, 222, 173), "navajo white" },
384 { RGB_TO_ULONG(255, 222, 173), "NavajoWhite" },
385 { RGB_TO_ULONG(255, 228, 181), "moccasin" },
386 { RGB_TO_ULONG(255, 248, 220), "cornsilk" },
387 { RGB_TO_ULONG(255, 255, 240), "ivory" },
388 { RGB_TO_ULONG(255, 250, 205), "lemon chiffon" },
389 { RGB_TO_ULONG(255, 250, 205), "LemonChiffon" },
390 { RGB_TO_ULONG(255, 245, 238), "seashell" },
391 { RGB_TO_ULONG(240, 255, 240), "honeydew" },
392 { RGB_TO_ULONG(245, 255, 250), "mint cream" },
393 { RGB_TO_ULONG(245, 255, 250), "MintCream" },
394 { RGB_TO_ULONG(240, 255, 255), "azure" },
395 { RGB_TO_ULONG(240, 248, 255), "alice blue" },
396 { RGB_TO_ULONG(240, 248, 255), "AliceBlue" },
397 { RGB_TO_ULONG(230, 230, 250), "lavender" },
398 { RGB_TO_ULONG(255, 240, 245), "lavender blush" },
399 { RGB_TO_ULONG(255, 240, 245), "LavenderBlush" },
400 { RGB_TO_ULONG(255, 228, 225), "misty rose" },
401 { RGB_TO_ULONG(255, 228, 225), "MistyRose" },
402 { RGB_TO_ULONG(255, 255, 255), "white" },
403 { RGB_TO_ULONG(0 , 0 , 0 ), "black" },
404 { RGB_TO_ULONG(47 , 79 , 79 ), "dark slate gray" },
405 { RGB_TO_ULONG(47 , 79 , 79 ), "DarkSlateGray" },
406 { RGB_TO_ULONG(47 , 79 , 79 ), "dark slate grey" },
407 { RGB_TO_ULONG(47 , 79 , 79 ), "DarkSlateGrey" },
408 { RGB_TO_ULONG(105, 105, 105), "dim gray" },
409 { RGB_TO_ULONG(105, 105, 105), "DimGray" },
410 { RGB_TO_ULONG(105, 105, 105), "dim grey" },
411 { RGB_TO_ULONG(105, 105, 105), "DimGrey" },
412 { RGB_TO_ULONG(112, 128, 144), "slate gray" },
413 { RGB_TO_ULONG(112, 128, 144), "SlateGray" },
414 { RGB_TO_ULONG(112, 128, 144), "slate grey" },
415 { RGB_TO_ULONG(112, 128, 144), "SlateGrey" },
416 { RGB_TO_ULONG(119, 136, 153), "light slate gray" },
417 { RGB_TO_ULONG(119, 136, 153), "LightSlateGray" },
418 { RGB_TO_ULONG(119, 136, 153), "light slate grey" },
419 { RGB_TO_ULONG(119, 136, 153), "LightSlateGrey" },
420 { RGB_TO_ULONG(190, 190, 190), "gray" },
421 { RGB_TO_ULONG(190, 190, 190), "grey" },
422 { RGB_TO_ULONG(211, 211, 211), "light grey" },
423 { RGB_TO_ULONG(211, 211, 211), "LightGrey" },
424 { RGB_TO_ULONG(211, 211, 211), "light gray" },
425 { RGB_TO_ULONG(211, 211, 211), "LightGray" },
426 { RGB_TO_ULONG(25 , 25 , 112), "midnight blue" },
427 { RGB_TO_ULONG(25 , 25 , 112), "MidnightBlue" },
428 { RGB_TO_ULONG(0 , 0 , 128), "navy" },
429 { RGB_TO_ULONG(0 , 0 , 128), "navy blue" },
430 { RGB_TO_ULONG(0 , 0 , 128), "NavyBlue" },
431 { RGB_TO_ULONG(100, 149, 237), "cornflower blue" },
432 { RGB_TO_ULONG(100, 149, 237), "CornflowerBlue" },
433 { RGB_TO_ULONG(72 , 61 , 139), "dark slate blue" },
434 { RGB_TO_ULONG(72 , 61 , 139), "DarkSlateBlue" },
435 { RGB_TO_ULONG(106, 90 , 205), "slate blue" },
436 { RGB_TO_ULONG(106, 90 , 205), "SlateBlue" },
437 { RGB_TO_ULONG(123, 104, 238), "medium slate blue" },
438 { RGB_TO_ULONG(123, 104, 238), "MediumSlateBlue" },
439 { RGB_TO_ULONG(132, 112, 255), "light slate blue" },
440 { RGB_TO_ULONG(132, 112, 255), "LightSlateBlue" },
441 { RGB_TO_ULONG(0 , 0 , 205), "medium blue" },
442 { RGB_TO_ULONG(0 , 0 , 205), "MediumBlue" },
443 { RGB_TO_ULONG(65 , 105, 225), "royal blue" },
444 { RGB_TO_ULONG(65 , 105, 225), "RoyalBlue" },
445 { RGB_TO_ULONG(0 , 0 , 255), "blue" },
446 { RGB_TO_ULONG(30 , 144, 255), "dodger blue" },
447 { RGB_TO_ULONG(30 , 144, 255), "DodgerBlue" },
448 { RGB_TO_ULONG(0 , 191, 255), "deep sky blue" },
449 { RGB_TO_ULONG(0 , 191, 255), "DeepSkyBlue" },
450 { RGB_TO_ULONG(135, 206, 235), "sky blue" },
451 { RGB_TO_ULONG(135, 206, 235), "SkyBlue" },
452 { RGB_TO_ULONG(135, 206, 250), "light sky blue" },
453 { RGB_TO_ULONG(135, 206, 250), "LightSkyBlue" },
454 { RGB_TO_ULONG(70 , 130, 180), "steel blue" },
455 { RGB_TO_ULONG(70 , 130, 180), "SteelBlue" },
456 { RGB_TO_ULONG(176, 196, 222), "light steel blue" },
457 { RGB_TO_ULONG(176, 196, 222), "LightSteelBlue" },
458 { RGB_TO_ULONG(173, 216, 230), "light blue" },
459 { RGB_TO_ULONG(173, 216, 230), "LightBlue" },
460 { RGB_TO_ULONG(176, 224, 230), "powder blue" },
461 { RGB_TO_ULONG(176, 224, 230), "PowderBlue" },
462 { RGB_TO_ULONG(175, 238, 238), "pale turquoise" },
463 { RGB_TO_ULONG(175, 238, 238), "PaleTurquoise" },
464 { RGB_TO_ULONG(0 , 206, 209), "dark turquoise" },
465 { RGB_TO_ULONG(0 , 206, 209), "DarkTurquoise" },
466 { RGB_TO_ULONG(72 , 209, 204), "medium turquoise" },
467 { RGB_TO_ULONG(72 , 209, 204), "MediumTurquoise" },
468 { RGB_TO_ULONG(64 , 224, 208), "turquoise" },
469 { RGB_TO_ULONG(0 , 255, 255), "cyan" },
470 { RGB_TO_ULONG(224, 255, 255), "light cyan" },
471 { RGB_TO_ULONG(224, 255, 255), "LightCyan" },
472 { RGB_TO_ULONG(95 , 158, 160), "cadet blue" },
473 { RGB_TO_ULONG(95 , 158, 160), "CadetBlue" },
474 { RGB_TO_ULONG(102, 205, 170), "medium aquamarine" },
475 { RGB_TO_ULONG(102, 205, 170), "MediumAquamarine" },
476 { RGB_TO_ULONG(127, 255, 212), "aquamarine" },
477 { RGB_TO_ULONG(0 , 100, 0 ), "dark green" },
478 { RGB_TO_ULONG(0 , 100, 0 ), "DarkGreen" },
479 { RGB_TO_ULONG(85 , 107, 47 ), "dark olive green" },
480 { RGB_TO_ULONG(85 , 107, 47 ), "DarkOliveGreen" },
481 { RGB_TO_ULONG(143, 188, 143), "dark sea green" },
482 { RGB_TO_ULONG(143, 188, 143), "DarkSeaGreen" },
483 { RGB_TO_ULONG(46 , 139, 87 ), "sea green" },
484 { RGB_TO_ULONG(46 , 139, 87 ), "SeaGreen" },
485 { RGB_TO_ULONG(60 , 179, 113), "medium sea green" },
486 { RGB_TO_ULONG(60 , 179, 113), "MediumSeaGreen" },
487 { RGB_TO_ULONG(32 , 178, 170), "light sea green" },
488 { RGB_TO_ULONG(32 , 178, 170), "LightSeaGreen" },
489 { RGB_TO_ULONG(152, 251, 152), "pale green" },
490 { RGB_TO_ULONG(152, 251, 152), "PaleGreen" },
491 { RGB_TO_ULONG(0 , 255, 127), "spring green" },
492 { RGB_TO_ULONG(0 , 255, 127), "SpringGreen" },
493 { RGB_TO_ULONG(124, 252, 0 ), "lawn green" },
494 { RGB_TO_ULONG(124, 252, 0 ), "LawnGreen" },
495 { RGB_TO_ULONG(0 , 255, 0 ), "green" },
496 { RGB_TO_ULONG(127, 255, 0 ), "chartreuse" },
497 { RGB_TO_ULONG(0 , 250, 154), "medium spring green" },
498 { RGB_TO_ULONG(0 , 250, 154), "MediumSpringGreen" },
499 { RGB_TO_ULONG(173, 255, 47 ), "green yellow" },
500 { RGB_TO_ULONG(173, 255, 47 ), "GreenYellow" },
501 { RGB_TO_ULONG(50 , 205, 50 ), "lime green" },
502 { RGB_TO_ULONG(50 , 205, 50 ), "LimeGreen" },
503 { RGB_TO_ULONG(154, 205, 50 ), "yellow green" },
504 { RGB_TO_ULONG(154, 205, 50 ), "YellowGreen" },
505 { RGB_TO_ULONG(34 , 139, 34 ), "forest green" },
506 { RGB_TO_ULONG(34 , 139, 34 ), "ForestGreen" },
507 { RGB_TO_ULONG(107, 142, 35 ), "olive drab" },
508 { RGB_TO_ULONG(107, 142, 35 ), "OliveDrab" },
509 { RGB_TO_ULONG(189, 183, 107), "dark khaki" },
510 { RGB_TO_ULONG(189, 183, 107), "DarkKhaki" },
511 { RGB_TO_ULONG(240, 230, 140), "khaki" },
512 { RGB_TO_ULONG(238, 232, 170), "pale goldenrod" },
513 { RGB_TO_ULONG(238, 232, 170), "PaleGoldenrod" },
514 { RGB_TO_ULONG(250, 250, 210), "light goldenrod yellow" },
515 { RGB_TO_ULONG(250, 250, 210), "LightGoldenrodYellow" },
516 { RGB_TO_ULONG(255, 255, 224), "light yellow" },
517 { RGB_TO_ULONG(255, 255, 224), "LightYellow" },
518 { RGB_TO_ULONG(255, 255, 0 ), "yellow" },
519 { RGB_TO_ULONG(255, 215, 0 ), "gold" },
520 { RGB_TO_ULONG(238, 221, 130), "light goldenrod" },
521 { RGB_TO_ULONG(238, 221, 130), "LightGoldenrod" },
522 { RGB_TO_ULONG(218, 165, 32 ), "goldenrod" },
523 { RGB_TO_ULONG(184, 134, 11 ), "dark goldenrod" },
524 { RGB_TO_ULONG(184, 134, 11 ), "DarkGoldenrod" },
525 { RGB_TO_ULONG(188, 143, 143), "rosy brown" },
526 { RGB_TO_ULONG(188, 143, 143), "RosyBrown" },
527 { RGB_TO_ULONG(205, 92 , 92 ), "indian red" },
528 { RGB_TO_ULONG(205, 92 , 92 ), "IndianRed" },
529 { RGB_TO_ULONG(139, 69 , 19 ), "saddle brown" },
530 { RGB_TO_ULONG(139, 69 , 19 ), "SaddleBrown" },
531 { RGB_TO_ULONG(160, 82 , 45 ), "sienna" },
532 { RGB_TO_ULONG(205, 133, 63 ), "peru" },
533 { RGB_TO_ULONG(222, 184, 135), "burlywood" },
534 { RGB_TO_ULONG(245, 245, 220), "beige" },
535 { RGB_TO_ULONG(245, 222, 179), "wheat" },
536 { RGB_TO_ULONG(244, 164, 96 ), "sandy brown" },
537 { RGB_TO_ULONG(244, 164, 96 ), "SandyBrown" },
538 { RGB_TO_ULONG(210, 180, 140), "tan" },
539 { RGB_TO_ULONG(210, 105, 30 ), "chocolate" },
540 { RGB_TO_ULONG(178, 34 , 34 ), "firebrick" },
541 { RGB_TO_ULONG(165, 42 , 42 ), "brown" },
542 { RGB_TO_ULONG(233, 150, 122), "dark salmon" },
543 { RGB_TO_ULONG(233, 150, 122), "DarkSalmon" },
544 { RGB_TO_ULONG(250, 128, 114), "salmon" },
545 { RGB_TO_ULONG(255, 160, 122), "light salmon" },
546 { RGB_TO_ULONG(255, 160, 122), "LightSalmon" },
547 { RGB_TO_ULONG(255, 165, 0 ), "orange" },
548 { RGB_TO_ULONG(255, 140, 0 ), "dark orange" },
549 { RGB_TO_ULONG(255, 140, 0 ), "DarkOrange" },
550 { RGB_TO_ULONG(255, 127, 80 ), "coral" },
551 { RGB_TO_ULONG(240, 128, 128), "light coral" },
552 { RGB_TO_ULONG(240, 128, 128), "LightCoral" },
553 { RGB_TO_ULONG(255, 99 , 71 ), "tomato" },
554 { RGB_TO_ULONG(255, 69 , 0 ), "orange red" },
555 { RGB_TO_ULONG(255, 69 , 0 ), "OrangeRed" },
556 { RGB_TO_ULONG(255, 0 , 0 ), "red" },
557 { RGB_TO_ULONG(255, 105, 180), "hot pink" },
558 { RGB_TO_ULONG(255, 105, 180), "HotPink" },
559 { RGB_TO_ULONG(255, 20 , 147), "deep pink" },
560 { RGB_TO_ULONG(255, 20 , 147), "DeepPink" },
561 { RGB_TO_ULONG(255, 192, 203), "pink" },
562 { RGB_TO_ULONG(255, 182, 193), "light pink" },
563 { RGB_TO_ULONG(255, 182, 193), "LightPink" },
564 { RGB_TO_ULONG(219, 112, 147), "pale violet red" },
565 { RGB_TO_ULONG(219, 112, 147), "PaleVioletRed" },
566 { RGB_TO_ULONG(176, 48 , 96 ), "maroon" },
567 { RGB_TO_ULONG(199, 21 , 133), "medium violet red" },
568 { RGB_TO_ULONG(199, 21 , 133), "MediumVioletRed" },
569 { RGB_TO_ULONG(208, 32 , 144), "violet red" },
570 { RGB_TO_ULONG(208, 32 , 144), "VioletRed" },
571 { RGB_TO_ULONG(255, 0 , 255), "magenta" },
572 { RGB_TO_ULONG(238, 130, 238), "violet" },
573 { RGB_TO_ULONG(221, 160, 221), "plum" },
574 { RGB_TO_ULONG(218, 112, 214), "orchid" },
575 { RGB_TO_ULONG(186, 85 , 211), "medium orchid" },
576 { RGB_TO_ULONG(186, 85 , 211), "MediumOrchid" },
577 { RGB_TO_ULONG(153, 50 , 204), "dark orchid" },
578 { RGB_TO_ULONG(153, 50 , 204), "DarkOrchid" },
579 { RGB_TO_ULONG(148, 0 , 211), "dark violet" },
580 { RGB_TO_ULONG(148, 0 , 211), "DarkViolet" },
581 { RGB_TO_ULONG(138, 43 , 226), "blue violet" },
582 { RGB_TO_ULONG(138, 43 , 226), "BlueViolet" },
583 { RGB_TO_ULONG(160, 32 , 240), "purple" },
584 { RGB_TO_ULONG(147, 112, 219), "medium purple" },
585 { RGB_TO_ULONG(147, 112, 219), "MediumPurple" },
586 { RGB_TO_ULONG(216, 191, 216), "thistle" },
587 { RGB_TO_ULONG(255, 250, 250), "snow1" },
588 { RGB_TO_ULONG(238, 233, 233), "snow2" },
589 { RGB_TO_ULONG(205, 201, 201), "snow3" },
590 { RGB_TO_ULONG(139, 137, 137), "snow4" },
591 { RGB_TO_ULONG(255, 245, 238), "seashell1" },
592 { RGB_TO_ULONG(238, 229, 222), "seashell2" },
593 { RGB_TO_ULONG(205, 197, 191), "seashell3" },
594 { RGB_TO_ULONG(139, 134, 130), "seashell4" },
595 { RGB_TO_ULONG(255, 239, 219), "AntiqueWhite1" },
596 { RGB_TO_ULONG(238, 223, 204), "AntiqueWhite2" },
597 { RGB_TO_ULONG(205, 192, 176), "AntiqueWhite3" },
598 { RGB_TO_ULONG(139, 131, 120), "AntiqueWhite4" },
599 { RGB_TO_ULONG(255, 228, 196), "bisque1" },
600 { RGB_TO_ULONG(238, 213, 183), "bisque2" },
601 { RGB_TO_ULONG(205, 183, 158), "bisque3" },
602 { RGB_TO_ULONG(139, 125, 107), "bisque4" },
603 { RGB_TO_ULONG(255, 218, 185), "PeachPuff1" },
604 { RGB_TO_ULONG(238, 203, 173), "PeachPuff2" },
605 { RGB_TO_ULONG(205, 175, 149), "PeachPuff3" },
606 { RGB_TO_ULONG(139, 119, 101), "PeachPuff4" },
607 { RGB_TO_ULONG(255, 222, 173), "NavajoWhite1" },
608 { RGB_TO_ULONG(238, 207, 161), "NavajoWhite2" },
609 { RGB_TO_ULONG(205, 179, 139), "NavajoWhite3" },
610 { RGB_TO_ULONG(139, 121, 94), "NavajoWhite4" },
611 { RGB_TO_ULONG(255, 250, 205), "LemonChiffon1" },
612 { RGB_TO_ULONG(238, 233, 191), "LemonChiffon2" },
613 { RGB_TO_ULONG(205, 201, 165), "LemonChiffon3" },
614 { RGB_TO_ULONG(139, 137, 112), "LemonChiffon4" },
615 { RGB_TO_ULONG(255, 248, 220), "cornsilk1" },
616 { RGB_TO_ULONG(238, 232, 205), "cornsilk2" },
617 { RGB_TO_ULONG(205, 200, 177), "cornsilk3" },
618 { RGB_TO_ULONG(139, 136, 120), "cornsilk4" },
619 { RGB_TO_ULONG(255, 255, 240), "ivory1" },
620 { RGB_TO_ULONG(238, 238, 224), "ivory2" },
621 { RGB_TO_ULONG(205, 205, 193), "ivory3" },
622 { RGB_TO_ULONG(139, 139, 131), "ivory4" },
623 { RGB_TO_ULONG(240, 255, 240), "honeydew1" },
624 { RGB_TO_ULONG(224, 238, 224), "honeydew2" },
625 { RGB_TO_ULONG(193, 205, 193), "honeydew3" },
626 { RGB_TO_ULONG(131, 139, 131), "honeydew4" },
627 { RGB_TO_ULONG(255, 240, 245), "LavenderBlush1" },
628 { RGB_TO_ULONG(238, 224, 229), "LavenderBlush2" },
629 { RGB_TO_ULONG(205, 193, 197), "LavenderBlush3" },
630 { RGB_TO_ULONG(139, 131, 134), "LavenderBlush4" },
631 { RGB_TO_ULONG(255, 228, 225), "MistyRose1" },
632 { RGB_TO_ULONG(238, 213, 210), "MistyRose2" },
633 { RGB_TO_ULONG(205, 183, 181), "MistyRose3" },
634 { RGB_TO_ULONG(139, 125, 123), "MistyRose4" },
635 { RGB_TO_ULONG(240, 255, 255), "azure1" },
636 { RGB_TO_ULONG(224, 238, 238), "azure2" },
637 { RGB_TO_ULONG(193, 205, 205), "azure3" },
638 { RGB_TO_ULONG(131, 139, 139), "azure4" },
639 { RGB_TO_ULONG(131, 111, 255), "SlateBlue1" },
640 { RGB_TO_ULONG(122, 103, 238), "SlateBlue2" },
641 { RGB_TO_ULONG(105, 89 , 205), "SlateBlue3" },
642 { RGB_TO_ULONG(71 , 60 , 139), "SlateBlue4" },
643 { RGB_TO_ULONG(72 , 118, 255), "RoyalBlue1" },
644 { RGB_TO_ULONG(67 , 110, 238), "RoyalBlue2" },
645 { RGB_TO_ULONG(58 , 95 , 205), "RoyalBlue3" },
646 { RGB_TO_ULONG(39 , 64 , 139), "RoyalBlue4" },
647 { RGB_TO_ULONG(0 , 0 , 255), "blue1" },
648 { RGB_TO_ULONG(0 , 0 , 238), "blue2" },
649 { RGB_TO_ULONG(0 , 0 , 205), "blue3" },
650 { RGB_TO_ULONG(0 , 0 , 139), "blue4" },
651 { RGB_TO_ULONG(30 , 144, 255), "DodgerBlue1" },
652 { RGB_TO_ULONG(28 , 134, 238), "DodgerBlue2" },
653 { RGB_TO_ULONG(24 , 116, 205), "DodgerBlue3" },
654 { RGB_TO_ULONG(16 , 78 , 139), "DodgerBlue4" },
655 { RGB_TO_ULONG(99 , 184, 255), "SteelBlue1" },
656 { RGB_TO_ULONG(92 , 172, 238), "SteelBlue2" },
657 { RGB_TO_ULONG(79 , 148, 205), "SteelBlue3" },
658 { RGB_TO_ULONG(54 , 100, 139), "SteelBlue4" },
659 { RGB_TO_ULONG(0 , 191, 255), "DeepSkyBlue1" },
660 { RGB_TO_ULONG(0 , 178, 238), "DeepSkyBlue2" },
661 { RGB_TO_ULONG(0 , 154, 205), "DeepSkyBlue3" },
662 { RGB_TO_ULONG(0 , 104, 139), "DeepSkyBlue4" },
663 { RGB_TO_ULONG(135, 206, 255), "SkyBlue1" },
664 { RGB_TO_ULONG(126, 192, 238), "SkyBlue2" },
665 { RGB_TO_ULONG(108, 166, 205), "SkyBlue3" },
666 { RGB_TO_ULONG(74 , 112, 139), "SkyBlue4" },
667 { RGB_TO_ULONG(176, 226, 255), "LightSkyBlue1" },
668 { RGB_TO_ULONG(164, 211, 238), "LightSkyBlue2" },
669 { RGB_TO_ULONG(141, 182, 205), "LightSkyBlue3" },
670 { RGB_TO_ULONG(96 , 123, 139), "LightSkyBlue4" },
671 { RGB_TO_ULONG(198, 226, 255), "SlateGray1" },
672 { RGB_TO_ULONG(185, 211, 238), "SlateGray2" },
673 { RGB_TO_ULONG(159, 182, 205), "SlateGray3" },
674 { RGB_TO_ULONG(108, 123, 139), "SlateGray4" },
675 { RGB_TO_ULONG(202, 225, 255), "LightSteelBlue1" },
676 { RGB_TO_ULONG(188, 210, 238), "LightSteelBlue2" },
677 { RGB_TO_ULONG(162, 181, 205), "LightSteelBlue3" },
678 { RGB_TO_ULONG(110, 123, 139), "LightSteelBlue4" },
679 { RGB_TO_ULONG(191, 239, 255), "LightBlue1" },
680 { RGB_TO_ULONG(178, 223, 238), "LightBlue2" },
681 { RGB_TO_ULONG(154, 192, 205), "LightBlue3" },
682 { RGB_TO_ULONG(104, 131, 139), "LightBlue4" },
683 { RGB_TO_ULONG(224, 255, 255), "LightCyan1" },
684 { RGB_TO_ULONG(209, 238, 238), "LightCyan2" },
685 { RGB_TO_ULONG(180, 205, 205), "LightCyan3" },
686 { RGB_TO_ULONG(122, 139, 139), "LightCyan4" },
687 { RGB_TO_ULONG(187, 255, 255), "PaleTurquoise1" },
688 { RGB_TO_ULONG(174, 238, 238), "PaleTurquoise2" },
689 { RGB_TO_ULONG(150, 205, 205), "PaleTurquoise3" },
690 { RGB_TO_ULONG(102, 139, 139), "PaleTurquoise4" },
691 { RGB_TO_ULONG(152, 245, 255), "CadetBlue1" },
692 { RGB_TO_ULONG(142, 229, 238), "CadetBlue2" },
693 { RGB_TO_ULONG(122, 197, 205), "CadetBlue3" },
694 { RGB_TO_ULONG(83 , 134, 139), "CadetBlue4" },
695 { RGB_TO_ULONG(0 , 245, 255), "turquoise1" },
696 { RGB_TO_ULONG(0 , 229, 238), "turquoise2" },
697 { RGB_TO_ULONG(0 , 197, 205), "turquoise3" },
698 { RGB_TO_ULONG(0 , 134, 139), "turquoise4" },
699 { RGB_TO_ULONG(0 , 255, 255), "cyan1" },
700 { RGB_TO_ULONG(0 , 238, 238), "cyan2" },
701 { RGB_TO_ULONG(0 , 205, 205), "cyan3" },
702 { RGB_TO_ULONG(0 , 139, 139), "cyan4" },
703 { RGB_TO_ULONG(151, 255, 255), "DarkSlateGray1" },
704 { RGB_TO_ULONG(141, 238, 238), "DarkSlateGray2" },
705 { RGB_TO_ULONG(121, 205, 205), "DarkSlateGray3" },
706 { RGB_TO_ULONG(82 , 139, 139), "DarkSlateGray4" },
707 { RGB_TO_ULONG(127, 255, 212), "aquamarine1" },
708 { RGB_TO_ULONG(118, 238, 198), "aquamarine2" },
709 { RGB_TO_ULONG(102, 205, 170), "aquamarine3" },
710 { RGB_TO_ULONG(69 , 139, 116), "aquamarine4" },
711 { RGB_TO_ULONG(193, 255, 193), "DarkSeaGreen1" },
712 { RGB_TO_ULONG(180, 238, 180), "DarkSeaGreen2" },
713 { RGB_TO_ULONG(155, 205, 155), "DarkSeaGreen3" },
714 { RGB_TO_ULONG(105, 139, 105), "DarkSeaGreen4" },
715 { RGB_TO_ULONG(84 , 255, 159), "SeaGreen1" },
716 { RGB_TO_ULONG(78 , 238, 148), "SeaGreen2" },
717 { RGB_TO_ULONG(67 , 205, 128), "SeaGreen3" },
718 { RGB_TO_ULONG(46 , 139, 87 ), "SeaGreen4" },
719 { RGB_TO_ULONG(154, 255, 154), "PaleGreen1" },
720 { RGB_TO_ULONG(144, 238, 144), "PaleGreen2" },
721 { RGB_TO_ULONG(124, 205, 124), "PaleGreen3" },
722 { RGB_TO_ULONG(84 , 139, 84 ), "PaleGreen4" },
723 { RGB_TO_ULONG(0 , 255, 127), "SpringGreen1" },
724 { RGB_TO_ULONG(0 , 238, 118), "SpringGreen2" },
725 { RGB_TO_ULONG(0 , 205, 102), "SpringGreen3" },
726 { RGB_TO_ULONG(0 , 139, 69 ), "SpringGreen4" },
727 { RGB_TO_ULONG(0 , 255, 0 ), "green1" },
728 { RGB_TO_ULONG(0 , 238, 0 ), "green2" },
729 { RGB_TO_ULONG(0 , 205, 0 ), "green3" },
730 { RGB_TO_ULONG(0 , 139, 0 ), "green4" },
731 { RGB_TO_ULONG(127, 255, 0 ), "chartreuse1" },
732 { RGB_TO_ULONG(118, 238, 0 ), "chartreuse2" },
733 { RGB_TO_ULONG(102, 205, 0 ), "chartreuse3" },
734 { RGB_TO_ULONG(69 , 139, 0 ), "chartreuse4" },
735 { RGB_TO_ULONG(192, 255, 62 ), "OliveDrab1" },
736 { RGB_TO_ULONG(179, 238, 58 ), "OliveDrab2" },
737 { RGB_TO_ULONG(154, 205, 50 ), "OliveDrab3" },
738 { RGB_TO_ULONG(105, 139, 34 ), "OliveDrab4" },
739 { RGB_TO_ULONG(202, 255, 112), "DarkOliveGreen1" },
740 { RGB_TO_ULONG(188, 238, 104), "DarkOliveGreen2" },
741 { RGB_TO_ULONG(162, 205, 90 ), "DarkOliveGreen3" },
742 { RGB_TO_ULONG(110, 139, 61 ), "DarkOliveGreen4" },
743 { RGB_TO_ULONG(255, 246, 143), "khaki1" },
744 { RGB_TO_ULONG(238, 230, 133), "khaki2" },
745 { RGB_TO_ULONG(205, 198, 115), "khaki3" },
746 { RGB_TO_ULONG(139, 134, 78 ), "khaki4" },
747 { RGB_TO_ULONG(255, 236, 139), "LightGoldenrod1" },
748 { RGB_TO_ULONG(238, 220, 130), "LightGoldenrod2" },
749 { RGB_TO_ULONG(205, 190, 112), "LightGoldenrod3" },
750 { RGB_TO_ULONG(139, 129, 76 ), "LightGoldenrod4" },
751 { RGB_TO_ULONG(255, 255, 224), "LightYellow1" },
752 { RGB_TO_ULONG(238, 238, 209), "LightYellow2" },
753 { RGB_TO_ULONG(205, 205, 180), "LightYellow3" },
754 { RGB_TO_ULONG(139, 139, 122), "LightYellow4" },
755 { RGB_TO_ULONG(255, 255, 0 ), "yellow1" },
756 { RGB_TO_ULONG(238, 238, 0 ), "yellow2" },
757 { RGB_TO_ULONG(205, 205, 0 ), "yellow3" },
758 { RGB_TO_ULONG(139, 139, 0 ), "yellow4" },
759 { RGB_TO_ULONG(255, 215, 0 ), "gold1" },
760 { RGB_TO_ULONG(238, 201, 0 ), "gold2" },
761 { RGB_TO_ULONG(205, 173, 0 ), "gold3" },
762 { RGB_TO_ULONG(139, 117, 0 ), "gold4" },
763 { RGB_TO_ULONG(255, 193, 37 ), "goldenrod1" },
764 { RGB_TO_ULONG(238, 180, 34 ), "goldenrod2" },
765 { RGB_TO_ULONG(205, 155, 29 ), "goldenrod3" },
766 { RGB_TO_ULONG(139, 105, 20 ), "goldenrod4" },
767 { RGB_TO_ULONG(255, 185, 15 ), "DarkGoldenrod1" },
768 { RGB_TO_ULONG(238, 173, 14 ), "DarkGoldenrod2" },
769 { RGB_TO_ULONG(205, 149, 12 ), "DarkGoldenrod3" },
770 { RGB_TO_ULONG(139, 101, 8 ), "DarkGoldenrod4" },
771 { RGB_TO_ULONG(255, 193, 193), "RosyBrown1" },
772 { RGB_TO_ULONG(238, 180, 180), "RosyBrown2" },
773 { RGB_TO_ULONG(205, 155, 155), "RosyBrown3" },
774 { RGB_TO_ULONG(139, 105, 105), "RosyBrown4" },
775 { RGB_TO_ULONG(255, 106, 106), "IndianRed1" },
776 { RGB_TO_ULONG(238, 99 , 99 ), "IndianRed2" },
777 { RGB_TO_ULONG(205, 85 , 85 ), "IndianRed3" },
778 { RGB_TO_ULONG(139, 58 , 58 ), "IndianRed4" },
779 { RGB_TO_ULONG(255, 130, 71 ), "sienna1" },
780 { RGB_TO_ULONG(238, 121, 66 ), "sienna2" },
781 { RGB_TO_ULONG(205, 104, 57 ), "sienna3" },
782 { RGB_TO_ULONG(139, 71 , 38 ), "sienna4" },
783 { RGB_TO_ULONG(255, 211, 155), "burlywood1" },
784 { RGB_TO_ULONG(238, 197, 145), "burlywood2" },
785 { RGB_TO_ULONG(205, 170, 125), "burlywood3" },
786 { RGB_TO_ULONG(139, 115, 85 ), "burlywood4" },
787 { RGB_TO_ULONG(255, 231, 186), "wheat1" },
788 { RGB_TO_ULONG(238, 216, 174), "wheat2" },
789 { RGB_TO_ULONG(205, 186, 150), "wheat3" },
790 { RGB_TO_ULONG(139, 126, 102), "wheat4" },
791 { RGB_TO_ULONG(255, 165, 79 ), "tan1" },
792 { RGB_TO_ULONG(238, 154, 73 ), "tan2" },
793 { RGB_TO_ULONG(205, 133, 63 ), "tan3" },
794 { RGB_TO_ULONG(139, 90 , 43 ), "tan4" },
795 { RGB_TO_ULONG(255, 127, 36 ), "chocolate1" },
796 { RGB_TO_ULONG(238, 118, 33 ), "chocolate2" },
797 { RGB_TO_ULONG(205, 102, 29 ), "chocolate3" },
798 { RGB_TO_ULONG(139, 69 , 19 ), "chocolate4" },
799 { RGB_TO_ULONG(255, 48 , 48 ), "firebrick1" },
800 { RGB_TO_ULONG(238, 44 , 44 ), "firebrick2" },
801 { RGB_TO_ULONG(205, 38 , 38 ), "firebrick3" },
802 { RGB_TO_ULONG(139, 26 , 26 ), "firebrick4" },
803 { RGB_TO_ULONG(255, 64 , 64 ), "brown1" },
804 { RGB_TO_ULONG(238, 59 , 59 ), "brown2" },
805 { RGB_TO_ULONG(205, 51 , 51 ), "brown3" },
806 { RGB_TO_ULONG(139, 35 , 35 ), "brown4" },
807 { RGB_TO_ULONG(255, 140, 105), "salmon1" },
808 { RGB_TO_ULONG(238, 130, 98 ), "salmon2" },
809 { RGB_TO_ULONG(205, 112, 84 ), "salmon3" },
810 { RGB_TO_ULONG(139, 76 , 57 ), "salmon4" },
811 { RGB_TO_ULONG(255, 160, 122), "LightSalmon1" },
812 { RGB_TO_ULONG(238, 149, 114), "LightSalmon2" },
813 { RGB_TO_ULONG(205, 129, 98 ), "LightSalmon3" },
814 { RGB_TO_ULONG(139, 87 , 66 ), "LightSalmon4" },
815 { RGB_TO_ULONG(255, 165, 0 ), "orange1" },
816 { RGB_TO_ULONG(238, 154, 0 ), "orange2" },
817 { RGB_TO_ULONG(205, 133, 0 ), "orange3" },
818 { RGB_TO_ULONG(139, 90 , 0 ), "orange4" },
819 { RGB_TO_ULONG(255, 127, 0 ), "DarkOrange1" },
820 { RGB_TO_ULONG(238, 118, 0 ), "DarkOrange2" },
821 { RGB_TO_ULONG(205, 102, 0 ), "DarkOrange3" },
822 { RGB_TO_ULONG(139, 69 , 0 ), "DarkOrange4" },
823 { RGB_TO_ULONG(255, 114, 86 ), "coral1" },
824 { RGB_TO_ULONG(238, 106, 80 ), "coral2" },
825 { RGB_TO_ULONG(205, 91 , 69 ), "coral3" },
826 { RGB_TO_ULONG(139, 62 , 47 ), "coral4" },
827 { RGB_TO_ULONG(255, 99 , 71 ), "tomato1" },
828 { RGB_TO_ULONG(238, 92 , 66 ), "tomato2" },
829 { RGB_TO_ULONG(205, 79 , 57 ), "tomato3" },
830 { RGB_TO_ULONG(139, 54 , 38 ), "tomato4" },
831 { RGB_TO_ULONG(255, 69 , 0 ), "OrangeRed1" },
832 { RGB_TO_ULONG(238, 64 , 0 ), "OrangeRed2" },
833 { RGB_TO_ULONG(205, 55 , 0 ), "OrangeRed3" },
834 { RGB_TO_ULONG(139, 37 , 0 ), "OrangeRed4" },
835 { RGB_TO_ULONG(255, 0 , 0 ), "red1" },
836 { RGB_TO_ULONG(238, 0 , 0 ), "red2" },
837 { RGB_TO_ULONG(205, 0 , 0 ), "red3" },
838 { RGB_TO_ULONG(139, 0 , 0 ), "red4" },
839 { RGB_TO_ULONG(255, 20 , 147), "DeepPink1" },
840 { RGB_TO_ULONG(238, 18 , 137), "DeepPink2" },
841 { RGB_TO_ULONG(205, 16 , 118), "DeepPink3" },
842 { RGB_TO_ULONG(139, 10 , 80 ), "DeepPink4" },
843 { RGB_TO_ULONG(255, 110, 180), "HotPink1" },
844 { RGB_TO_ULONG(238, 106, 167), "HotPink2" },
845 { RGB_TO_ULONG(205, 96 , 144), "HotPink3" },
846 { RGB_TO_ULONG(139, 58 , 98 ), "HotPink4" },
847 { RGB_TO_ULONG(255, 181, 197), "pink1" },
848 { RGB_TO_ULONG(238, 169, 184), "pink2" },
849 { RGB_TO_ULONG(205, 145, 158), "pink3" },
850 { RGB_TO_ULONG(139, 99 , 108), "pink4" },
851 { RGB_TO_ULONG(255, 174, 185), "LightPink1" },
852 { RGB_TO_ULONG(238, 162, 173), "LightPink2" },
853 { RGB_TO_ULONG(205, 140, 149), "LightPink3" },
854 { RGB_TO_ULONG(139, 95 , 101), "LightPink4" },
855 { RGB_TO_ULONG(255, 130, 171), "PaleVioletRed1" },
856 { RGB_TO_ULONG(238, 121, 159), "PaleVioletRed2" },
857 { RGB_TO_ULONG(205, 104, 137), "PaleVioletRed3" },
858 { RGB_TO_ULONG(139, 71 , 93 ), "PaleVioletRed4" },
859 { RGB_TO_ULONG(255, 52 , 179), "maroon1" },
860 { RGB_TO_ULONG(238, 48 , 167), "maroon2" },
861 { RGB_TO_ULONG(205, 41 , 144), "maroon3" },
862 { RGB_TO_ULONG(139, 28 , 98 ), "maroon4" },
863 { RGB_TO_ULONG(255, 62 , 150), "VioletRed1" },
864 { RGB_TO_ULONG(238, 58 , 140), "VioletRed2" },
865 { RGB_TO_ULONG(205, 50 , 120), "VioletRed3" },
866 { RGB_TO_ULONG(139, 34 , 82 ), "VioletRed4" },
867 { RGB_TO_ULONG(255, 0 , 255), "magenta1" },
868 { RGB_TO_ULONG(238, 0 , 238), "magenta2" },
869 { RGB_TO_ULONG(205, 0 , 205), "magenta3" },
870 { RGB_TO_ULONG(139, 0 , 139), "magenta4" },
871 { RGB_TO_ULONG(255, 131, 250), "orchid1" },
872 { RGB_TO_ULONG(238, 122, 233), "orchid2" },
873 { RGB_TO_ULONG(205, 105, 201), "orchid3" },
874 { RGB_TO_ULONG(139, 71 , 137), "orchid4" },
875 { RGB_TO_ULONG(255, 187, 255), "plum1" },
876 { RGB_TO_ULONG(238, 174, 238), "plum2" },
877 { RGB_TO_ULONG(205, 150, 205), "plum3" },
878 { RGB_TO_ULONG(139, 102, 139), "plum4" },
879 { RGB_TO_ULONG(224, 102, 255), "MediumOrchid1" },
880 { RGB_TO_ULONG(209, 95 , 238), "MediumOrchid2" },
881 { RGB_TO_ULONG(180, 82 , 205), "MediumOrchid3" },
882 { RGB_TO_ULONG(122, 55 , 139), "MediumOrchid4" },
883 { RGB_TO_ULONG(191, 62 , 255), "DarkOrchid1" },
884 { RGB_TO_ULONG(178, 58 , 238), "DarkOrchid2" },
885 { RGB_TO_ULONG(154, 50 , 205), "DarkOrchid3" },
886 { RGB_TO_ULONG(104, 34 , 139), "DarkOrchid4" },
887 { RGB_TO_ULONG(155, 48 , 255), "purple1" },
888 { RGB_TO_ULONG(145, 44 , 238), "purple2" },
889 { RGB_TO_ULONG(125, 38 , 205), "purple3" },
890 { RGB_TO_ULONG(85 , 26 , 139), "purple4" },
891 { RGB_TO_ULONG(171, 130, 255), "MediumPurple1" },
892 { RGB_TO_ULONG(159, 121, 238), "MediumPurple2" },
893 { RGB_TO_ULONG(137, 104, 205), "MediumPurple3" },
894 { RGB_TO_ULONG(93 , 71 , 139), "MediumPurple4" },
895 { RGB_TO_ULONG(255, 225, 255), "thistle1" },
896 { RGB_TO_ULONG(238, 210, 238), "thistle2" },
897 { RGB_TO_ULONG(205, 181, 205), "thistle3" },
898 { RGB_TO_ULONG(139, 123, 139), "thistle4" },
899 { RGB_TO_ULONG(0 , 0 , 0 ), "gray0" },
900 { RGB_TO_ULONG(0 , 0 , 0 ), "grey0" },
901 { RGB_TO_ULONG(3 , 3 , 3 ), "gray1" },
902 { RGB_TO_ULONG(3 , 3 , 3 ), "grey1" },
903 { RGB_TO_ULONG(5 , 5 , 5 ), "gray2" },
904 { RGB_TO_ULONG(5 , 5 , 5 ), "grey2" },
905 { RGB_TO_ULONG(8 , 8 , 8 ), "gray3" },
906 { RGB_TO_ULONG(8 , 8 , 8 ), "grey3" },
907 { RGB_TO_ULONG(10 , 10 , 10 ), "gray4" },
908 { RGB_TO_ULONG(10 , 10 , 10 ), "grey4" },
909 { RGB_TO_ULONG(13 , 13 , 13 ), "gray5" },
910 { RGB_TO_ULONG(13 , 13 , 13 ), "grey5" },
911 { RGB_TO_ULONG(15 , 15 , 15 ), "gray6" },
912 { RGB_TO_ULONG(15 , 15 , 15 ), "grey6" },
913 { RGB_TO_ULONG(18 , 18 , 18 ), "gray7" },
914 { RGB_TO_ULONG(18 , 18 , 18 ), "grey7" },
915 { RGB_TO_ULONG(20 , 20 , 20 ), "gray8" },
916 { RGB_TO_ULONG(20 , 20 , 20 ), "grey8" },
917 { RGB_TO_ULONG(23 , 23 , 23 ), "gray9" },
918 { RGB_TO_ULONG(23 , 23 , 23 ), "grey9" },
919 { RGB_TO_ULONG(26 , 26 , 26 ), "gray10" },
920 { RGB_TO_ULONG(26 , 26 , 26 ), "grey10" },
921 { RGB_TO_ULONG(28 , 28 , 28 ), "gray11" },
922 { RGB_TO_ULONG(28 , 28 , 28 ), "grey11" },
923 { RGB_TO_ULONG(31 , 31 , 31 ), "gray12" },
924 { RGB_TO_ULONG(31 , 31 , 31 ), "grey12" },
925 { RGB_TO_ULONG(33 , 33 , 33 ), "gray13" },
926 { RGB_TO_ULONG(33 , 33 , 33 ), "grey13" },
927 { RGB_TO_ULONG(36 , 36 , 36 ), "gray14" },
928 { RGB_TO_ULONG(36 , 36 , 36 ), "grey14" },
929 { RGB_TO_ULONG(38 , 38 , 38 ), "gray15" },
930 { RGB_TO_ULONG(38 , 38 , 38 ), "grey15" },
931 { RGB_TO_ULONG(41 , 41 , 41 ), "gray16" },
932 { RGB_TO_ULONG(41 , 41 , 41 ), "grey16" },
933 { RGB_TO_ULONG(43 , 43 , 43 ), "gray17" },
934 { RGB_TO_ULONG(43 , 43 , 43 ), "grey17" },
935 { RGB_TO_ULONG(46 , 46 , 46 ), "gray18" },
936 { RGB_TO_ULONG(46 , 46 , 46 ), "grey18" },
937 { RGB_TO_ULONG(48 , 48 , 48 ), "gray19" },
938 { RGB_TO_ULONG(48 , 48 , 48 ), "grey19" },
939 { RGB_TO_ULONG(51 , 51 , 51 ), "gray20" },
940 { RGB_TO_ULONG(51 , 51 , 51 ), "grey20" },
941 { RGB_TO_ULONG(54 , 54 , 54 ), "gray21" },
942 { RGB_TO_ULONG(54 , 54 , 54 ), "grey21" },
943 { RGB_TO_ULONG(56 , 56 , 56 ), "gray22" },
944 { RGB_TO_ULONG(56 , 56 , 56 ), "grey22" },
945 { RGB_TO_ULONG(59 , 59 , 59 ), "gray23" },
946 { RGB_TO_ULONG(59 , 59 , 59 ), "grey23" },
947 { RGB_TO_ULONG(61 , 61 , 61 ), "gray24" },
948 { RGB_TO_ULONG(61 , 61 , 61 ), "grey24" },
949 { RGB_TO_ULONG(64 , 64 , 64 ), "gray25" },
950 { RGB_TO_ULONG(64 , 64 , 64 ), "grey25" },
951 { RGB_TO_ULONG(66 , 66 , 66 ), "gray26" },
952 { RGB_TO_ULONG(66 , 66 , 66 ), "grey26" },
953 { RGB_TO_ULONG(69 , 69 , 69 ), "gray27" },
954 { RGB_TO_ULONG(69 , 69 , 69 ), "grey27" },
955 { RGB_TO_ULONG(71 , 71 , 71 ), "gray28" },
956 { RGB_TO_ULONG(71 , 71 , 71 ), "grey28" },
957 { RGB_TO_ULONG(74 , 74 , 74 ), "gray29" },
958 { RGB_TO_ULONG(74 , 74 , 74 ), "grey29" },
959 { RGB_TO_ULONG(77 , 77 , 77 ), "gray30" },
960 { RGB_TO_ULONG(77 , 77 , 77 ), "grey30" },
961 { RGB_TO_ULONG(79 , 79 , 79 ), "gray31" },
962 { RGB_TO_ULONG(79 , 79 , 79 ), "grey31" },
963 { RGB_TO_ULONG(82 , 82 , 82 ), "gray32" },
964 { RGB_TO_ULONG(82 , 82 , 82 ), "grey32" },
965 { RGB_TO_ULONG(84 , 84 , 84 ), "gray33" },
966 { RGB_TO_ULONG(84 , 84 , 84 ), "grey33" },
967 { RGB_TO_ULONG(87 , 87 , 87 ), "gray34" },
968 { RGB_TO_ULONG(87 , 87 , 87 ), "grey34" },
969 { RGB_TO_ULONG(89 , 89 , 89 ), "gray35" },
970 { RGB_TO_ULONG(89 , 89 , 89 ), "grey35" },
971 { RGB_TO_ULONG(92 , 92 , 92 ), "gray36" },
972 { RGB_TO_ULONG(92 , 92 , 92 ), "grey36" },
973 { RGB_TO_ULONG(94 , 94 , 94 ), "gray37" },
974 { RGB_TO_ULONG(94 , 94 , 94 ), "grey37" },
975 { RGB_TO_ULONG(97 , 97 , 97 ), "gray38" },
976 { RGB_TO_ULONG(97 , 97 , 97 ), "grey38" },
977 { RGB_TO_ULONG(99 , 99 , 99 ), "gray39" },
978 { RGB_TO_ULONG(99 , 99 , 99 ), "grey39" },
979 { RGB_TO_ULONG(102, 102, 102), "gray40" },
980 { RGB_TO_ULONG(102, 102, 102), "grey40" },
981 { RGB_TO_ULONG(105, 105, 105), "gray41" },
982 { RGB_TO_ULONG(105, 105, 105), "grey41" },
983 { RGB_TO_ULONG(107, 107, 107), "gray42" },
984 { RGB_TO_ULONG(107, 107, 107), "grey42" },
985 { RGB_TO_ULONG(110, 110, 110), "gray43" },
986 { RGB_TO_ULONG(110, 110, 110), "grey43" },
987 { RGB_TO_ULONG(112, 112, 112), "gray44" },
988 { RGB_TO_ULONG(112, 112, 112), "grey44" },
989 { RGB_TO_ULONG(115, 115, 115), "gray45" },
990 { RGB_TO_ULONG(115, 115, 115), "grey45" },
991 { RGB_TO_ULONG(117, 117, 117), "gray46" },
992 { RGB_TO_ULONG(117, 117, 117), "grey46" },
993 { RGB_TO_ULONG(120, 120, 120), "gray47" },
994 { RGB_TO_ULONG(120, 120, 120), "grey47" },
995 { RGB_TO_ULONG(122, 122, 122), "gray48" },
996 { RGB_TO_ULONG(122, 122, 122), "grey48" },
997 { RGB_TO_ULONG(125, 125, 125), "gray49" },
998 { RGB_TO_ULONG(125, 125, 125), "grey49" },
999 { RGB_TO_ULONG(127, 127, 127), "gray50" },
1000 { RGB_TO_ULONG(127, 127, 127), "grey50" },
1001 { RGB_TO_ULONG(130, 130, 130), "gray51" },
1002 { RGB_TO_ULONG(130, 130, 130), "grey51" },
1003 { RGB_TO_ULONG(133, 133, 133), "gray52" },
1004 { RGB_TO_ULONG(133, 133, 133), "grey52" },
1005 { RGB_TO_ULONG(135, 135, 135), "gray53" },
1006 { RGB_TO_ULONG(135, 135, 135), "grey53" },
1007 { RGB_TO_ULONG(138, 138, 138), "gray54" },
1008 { RGB_TO_ULONG(138, 138, 138), "grey54" },
1009 { RGB_TO_ULONG(140, 140, 140), "gray55" },
1010 { RGB_TO_ULONG(140, 140, 140), "grey55" },
1011 { RGB_TO_ULONG(143, 143, 143), "gray56" },
1012 { RGB_TO_ULONG(143, 143, 143), "grey56" },
1013 { RGB_TO_ULONG(145, 145, 145), "gray57" },
1014 { RGB_TO_ULONG(145, 145, 145), "grey57" },
1015 { RGB_TO_ULONG(148, 148, 148), "gray58" },
1016 { RGB_TO_ULONG(148, 148, 148), "grey58" },
1017 { RGB_TO_ULONG(150, 150, 150), "gray59" },
1018 { RGB_TO_ULONG(150, 150, 150), "grey59" },
1019 { RGB_TO_ULONG(153, 153, 153), "gray60" },
1020 { RGB_TO_ULONG(153, 153, 153), "grey60" },
1021 { RGB_TO_ULONG(156, 156, 156), "gray61" },
1022 { RGB_TO_ULONG(156, 156, 156), "grey61" },
1023 { RGB_TO_ULONG(158, 158, 158), "gray62" },
1024 { RGB_TO_ULONG(158, 158, 158), "grey62" },
1025 { RGB_TO_ULONG(161, 161, 161), "gray63" },
1026 { RGB_TO_ULONG(161, 161, 161), "grey63" },
1027 { RGB_TO_ULONG(163, 163, 163), "gray64" },
1028 { RGB_TO_ULONG(163, 163, 163), "grey64" },
1029 { RGB_TO_ULONG(166, 166, 166), "gray65" },
1030 { RGB_TO_ULONG(166, 166, 166), "grey65" },
1031 { RGB_TO_ULONG(168, 168, 168), "gray66" },
1032 { RGB_TO_ULONG(168, 168, 168), "grey66" },
1033 { RGB_TO_ULONG(171, 171, 171), "gray67" },
1034 { RGB_TO_ULONG(171, 171, 171), "grey67" },
1035 { RGB_TO_ULONG(173, 173, 173), "gray68" },
1036 { RGB_TO_ULONG(173, 173, 173), "grey68" },
1037 { RGB_TO_ULONG(176, 176, 176), "gray69" },
1038 { RGB_TO_ULONG(176, 176, 176), "grey69" },
1039 { RGB_TO_ULONG(179, 179, 179), "gray70" },
1040 { RGB_TO_ULONG(179, 179, 179), "grey70" },
1041 { RGB_TO_ULONG(181, 181, 181), "gray71" },
1042 { RGB_TO_ULONG(181, 181, 181), "grey71" },
1043 { RGB_TO_ULONG(184, 184, 184), "gray72" },
1044 { RGB_TO_ULONG(184, 184, 184), "grey72" },
1045 { RGB_TO_ULONG(186, 186, 186), "gray73" },
1046 { RGB_TO_ULONG(186, 186, 186), "grey73" },
1047 { RGB_TO_ULONG(189, 189, 189), "gray74" },
1048 { RGB_TO_ULONG(189, 189, 189), "grey74" },
1049 { RGB_TO_ULONG(191, 191, 191), "gray75" },
1050 { RGB_TO_ULONG(191, 191, 191), "grey75" },
1051 { RGB_TO_ULONG(194, 194, 194), "gray76" },
1052 { RGB_TO_ULONG(194, 194, 194), "grey76" },
1053 { RGB_TO_ULONG(196, 196, 196), "gray77" },
1054 { RGB_TO_ULONG(196, 196, 196), "grey77" },
1055 { RGB_TO_ULONG(199, 199, 199), "gray78" },
1056 { RGB_TO_ULONG(199, 199, 199), "grey78" },
1057 { RGB_TO_ULONG(201, 201, 201), "gray79" },
1058 { RGB_TO_ULONG(201, 201, 201), "grey79" },
1059 { RGB_TO_ULONG(204, 204, 204), "gray80" },
1060 { RGB_TO_ULONG(204, 204, 204), "grey80" },
1061 { RGB_TO_ULONG(207, 207, 207), "gray81" },
1062 { RGB_TO_ULONG(207, 207, 207), "grey81" },
1063 { RGB_TO_ULONG(209, 209, 209), "gray82" },
1064 { RGB_TO_ULONG(209, 209, 209), "grey82" },
1065 { RGB_TO_ULONG(212, 212, 212), "gray83" },
1066 { RGB_TO_ULONG(212, 212, 212), "grey83" },
1067 { RGB_TO_ULONG(214, 214, 214), "gray84" },
1068 { RGB_TO_ULONG(214, 214, 214), "grey84" },
1069 { RGB_TO_ULONG(217, 217, 217), "gray85" },
1070 { RGB_TO_ULONG(217, 217, 217), "grey85" },
1071 { RGB_TO_ULONG(219, 219, 219), "gray86" },
1072 { RGB_TO_ULONG(219, 219, 219), "grey86" },
1073 { RGB_TO_ULONG(222, 222, 222), "gray87" },
1074 { RGB_TO_ULONG(222, 222, 222), "grey87" },
1075 { RGB_TO_ULONG(224, 224, 224), "gray88" },
1076 { RGB_TO_ULONG(224, 224, 224), "grey88" },
1077 { RGB_TO_ULONG(227, 227, 227), "gray89" },
1078 { RGB_TO_ULONG(227, 227, 227), "grey89" },
1079 { RGB_TO_ULONG(229, 229, 229), "gray90" },
1080 { RGB_TO_ULONG(229, 229, 229), "grey90" },
1081 { RGB_TO_ULONG(232, 232, 232), "gray91" },
1082 { RGB_TO_ULONG(232, 232, 232), "grey91" },
1083 { RGB_TO_ULONG(235, 235, 235), "gray92" },
1084 { RGB_TO_ULONG(235, 235, 235), "grey92" },
1085 { RGB_TO_ULONG(237, 237, 237), "gray93" },
1086 { RGB_TO_ULONG(237, 237, 237), "grey93" },
1087 { RGB_TO_ULONG(240, 240, 240), "gray94" },
1088 { RGB_TO_ULONG(240, 240, 240), "grey94" },
1089 { RGB_TO_ULONG(242, 242, 242), "gray95" },
1090 { RGB_TO_ULONG(242, 242, 242), "grey95" },
1091 { RGB_TO_ULONG(245, 245, 245), "gray96" },
1092 { RGB_TO_ULONG(245, 245, 245), "grey96" },
1093 { RGB_TO_ULONG(247, 247, 247), "gray97" },
1094 { RGB_TO_ULONG(247, 247, 247), "grey97" },
1095 { RGB_TO_ULONG(250, 250, 250), "gray98" },
1096 { RGB_TO_ULONG(250, 250, 250), "grey98" },
1097 { RGB_TO_ULONG(252, 252, 252), "gray99" },
1098 { RGB_TO_ULONG(252, 252, 252), "grey99" },
1099 { RGB_TO_ULONG(255, 255, 255), "gray100" },
1100 { RGB_TO_ULONG(255, 255, 255), "grey100" },
1101 { RGB_TO_ULONG(169, 169, 169), "dark grey" },
1102 { RGB_TO_ULONG(169, 169, 169), "DarkGrey" },
1103 { RGB_TO_ULONG(169, 169, 169), "dark gray" },
1104 { RGB_TO_ULONG(169, 169, 169), "DarkGray" },
1105 { RGB_TO_ULONG(0 , 0 , 139), "dark blue" },
1106 { RGB_TO_ULONG(0 , 0 , 139), "DarkBlue" },
1107 { RGB_TO_ULONG(0 , 139, 139), "dark cyan" },
1108 { RGB_TO_ULONG(0 , 139, 139), "DarkCyan" },
1109 { RGB_TO_ULONG(139, 0 , 139), "dark magenta" },
1110 { RGB_TO_ULONG(139, 0 , 139), "DarkMagenta" },
1111 { RGB_TO_ULONG(139, 0 , 0 ), "dark red" },
1112 { RGB_TO_ULONG(139, 0 , 0 ), "DarkRed" },
1113 { RGB_TO_ULONG(144, 238, 144), "light green" },
1114 { RGB_TO_ULONG(144, 238, 144), "LightGreen" }
1117 Lisp_Object
1118 mac_color_map_lookup (colorname)
1119 char *colorname;
1121 Lisp_Object ret = Qnil;
1122 int i;
1124 BLOCK_INPUT;
1126 for (i = 0; i < sizeof (mac_color_map) / sizeof (mac_color_map[0]); i++)
1127 if (stricmp (colorname, mac_color_map[i].name) == 0)
1129 ret = make_number (mac_color_map[i].color);
1130 break;
1133 UNBLOCK_INPUT;
1135 return ret;
1138 Lisp_Object
1139 x_to_mac_color (colorname)
1140 char * colorname;
1142 register Lisp_Object tail, ret = Qnil;
1144 BLOCK_INPUT;
1146 if (colorname[0] == '#')
1148 /* Could be an old-style RGB Device specification. */
1149 char *color;
1150 int size;
1151 color = colorname + 1;
1153 size = strlen(color);
1154 if (size == 3 || size == 6 || size == 9 || size == 12)
1156 unsigned long colorval;
1157 int i, pos;
1158 pos = 16;
1159 size /= 3;
1160 colorval = 0;
1162 for (i = 0; i < 3; i++)
1164 char *end;
1165 char t;
1166 unsigned long value;
1168 /* The check for 'x' in the following conditional takes into
1169 account the fact that strtol allows a "0x" in front of
1170 our numbers, and we don't. */
1171 if (!isxdigit(color[0]) || color[1] == 'x')
1172 break;
1173 t = color[size];
1174 color[size] = '\0';
1175 value = strtoul(color, &end, 16);
1176 color[size] = t;
1177 if (errno == ERANGE || end - color != size)
1178 break;
1179 switch (size)
1181 case 1:
1182 value = value * 0x10;
1183 break;
1184 case 2:
1185 break;
1186 case 3:
1187 value /= 0x10;
1188 break;
1189 case 4:
1190 value /= 0x100;
1191 break;
1193 colorval |= (value << pos);
1194 pos -= 8;
1195 if (i == 2)
1197 UNBLOCK_INPUT;
1198 return make_number (colorval);
1200 color = end;
1204 else if (strnicmp(colorname, "rgb:", 4) == 0)
1206 char *color;
1207 unsigned long colorval;
1208 int i, pos;
1209 pos = 0;
1211 colorval = 0;
1212 color = colorname + 4;
1213 for (i = 0; i < 3; i++)
1215 char *end;
1216 unsigned long value;
1218 /* The check for 'x' in the following conditional takes into
1219 account the fact that strtol allows a "0x" in front of
1220 our numbers, and we don't. */
1221 if (!isxdigit(color[0]) || color[1] == 'x')
1222 break;
1223 value = strtoul(color, &end, 16);
1224 if (errno == ERANGE)
1225 break;
1226 switch (end - color)
1228 case 1:
1229 value = value * 0x10 + value;
1230 break;
1231 case 2:
1232 break;
1233 case 3:
1234 value /= 0x10;
1235 break;
1236 case 4:
1237 value /= 0x100;
1238 break;
1239 default:
1240 value = ULONG_MAX;
1242 if (value == ULONG_MAX)
1243 break;
1244 colorval |= (value << pos);
1245 pos += 0x8;
1246 if (i == 2)
1248 if (*end != '\0')
1249 break;
1250 UNBLOCK_INPUT;
1251 return make_number (colorval);
1253 if (*end != '/')
1254 break;
1255 color = end + 1;
1258 else if (strnicmp(colorname, "rgbi:", 5) == 0)
1260 /* This is an RGB Intensity specification. */
1261 char *color;
1262 unsigned long colorval;
1263 int i, pos;
1264 pos = 0;
1266 colorval = 0;
1267 color = colorname + 5;
1268 for (i = 0; i < 3; i++)
1270 char *end;
1271 double value;
1272 unsigned long val;
1274 value = strtod(color, &end);
1275 if (errno == ERANGE)
1276 break;
1277 if (value < 0.0 || value > 1.0)
1278 break;
1279 val = (unsigned long)(0x100 * value);
1280 /* We used 0x100 instead of 0xFF to give a continuous
1281 range between 0.0 and 1.0 inclusive. The next statement
1282 fixes the 1.0 case. */
1283 if (val == 0x100)
1284 val = 0xFF;
1285 colorval |= (val << pos);
1286 pos += 0x8;
1287 if (i == 2)
1289 if (*end != '\0')
1290 break;
1291 UNBLOCK_INPUT;
1292 return make_number (colorval);
1294 if (*end != '/')
1295 break;
1296 color = end + 1;
1300 ret = mac_color_map_lookup (colorname);
1302 UNBLOCK_INPUT;
1303 return ret;
1306 /* Gamma-correct COLOR on frame F. */
1308 void
1309 gamma_correct (f, color)
1310 struct frame *f;
1311 unsigned long *color;
1313 if (f->gamma)
1315 unsigned long red, green, blue;
1317 red = pow (RED_FROM_ULONG (*color) / 255.0, f->gamma) * 255.0 + 0.5;
1318 green = pow (GREEN_FROM_ULONG (*color) / 255.0, f->gamma) * 255.0 + 0.5;
1319 blue = pow (BLUE_FROM_ULONG (*color) / 255.0, f->gamma) * 255.0 + 0.5;
1320 *color = RGB_TO_ULONG (red, green, blue);
1324 /* Decide if color named COLOR is valid for the display associated
1325 with the selected frame; if so, return the rgb values in COLOR_DEF.
1326 If ALLOC is nonzero, allocate a new colormap cell. */
1329 mac_defined_color (f, color, color_def, alloc)
1330 FRAME_PTR f;
1331 char *color;
1332 XColor *color_def;
1333 int alloc;
1335 register Lisp_Object tem;
1336 unsigned long mac_color_ref;
1338 tem = x_to_mac_color (color);
1340 if (!NILP (tem))
1342 if (f)
1344 /* Apply gamma correction. */
1345 mac_color_ref = XUINT (tem);
1346 gamma_correct (f, &mac_color_ref);
1347 XSETINT (tem, mac_color_ref);
1350 color_def->pixel = mac_color_ref;
1351 color_def->red = RED16_FROM_ULONG (mac_color_ref);
1352 color_def->green = GREEN16_FROM_ULONG (mac_color_ref);
1353 color_def->blue = BLUE16_FROM_ULONG (mac_color_ref);
1355 return 1;
1357 else
1359 return 0;
1363 /* Given a string ARG naming a color, compute a pixel value from it
1364 suitable for screen F.
1365 If F is not a color screen, return DEF (default) regardless of what
1366 ARG says. */
1369 x_decode_color (f, arg, def)
1370 FRAME_PTR f;
1371 Lisp_Object arg;
1372 int def;
1374 XColor cdef;
1376 CHECK_STRING (arg);
1378 if (strcmp (SDATA (arg), "black") == 0)
1379 return BLACK_PIX_DEFAULT (f);
1380 else if (strcmp (SDATA (arg), "white") == 0)
1381 return WHITE_PIX_DEFAULT (f);
1383 #if 0
1384 if (FRAME_MAC_DISPLAY_INFO (f)->n_planes) == 1)
1385 return def;
1386 #endif
1388 if (mac_defined_color (f, SDATA (arg), &cdef, 1))
1389 return cdef.pixel;
1391 /* defined_color failed; return an ultimate default. */
1392 return def;
1395 /* Functions called only from `x_set_frame_param'
1396 to set individual parameters.
1398 If FRAME_MAC_WINDOW (f) is 0,
1399 the frame is being created and its window does not exist yet.
1400 In that case, just record the parameter's new value
1401 in the standard place; do not attempt to change the window. */
1403 void
1404 x_set_foreground_color (f, arg, oldval)
1405 struct frame *f;
1406 Lisp_Object arg, oldval;
1408 unsigned long fg, old_fg;
1410 fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1411 old_fg = FRAME_FOREGROUND_PIXEL (f);
1412 FRAME_FOREGROUND_PIXEL (f) = fg;
1414 if (FRAME_MAC_WINDOW (f) != 0)
1416 update_face_from_frame_parameter (f, Qforeground_color, arg);
1417 if (FRAME_VISIBLE_P (f))
1418 redraw_frame (f);
1422 void
1423 x_set_background_color (f, arg, oldval)
1424 struct frame *f;
1425 Lisp_Object arg, oldval;
1427 FRAME_BACKGROUND_PIXEL (f)
1428 = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f));
1430 if (FRAME_MAC_WINDOW (f) != 0)
1432 update_face_from_frame_parameter (f, Qbackground_color, arg);
1434 if (FRAME_VISIBLE_P (f))
1435 redraw_frame (f);
1439 void
1440 x_set_mouse_color (f, arg, oldval)
1441 struct frame *f;
1442 Lisp_Object arg, oldval;
1444 Cursor cursor, nontext_cursor, mode_cursor, hand_cursor;
1445 int count;
1446 int mask_color;
1448 if (!EQ (Qnil, arg))
1449 f->output_data.mac->mouse_pixel
1450 = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1451 mask_color = FRAME_BACKGROUND_PIXEL (f);
1453 /* Don't let pointers be invisible. */
1454 if (mask_color == f->output_data.mac->mouse_pixel
1455 && mask_color == FRAME_BACKGROUND_PIXEL (f))
1456 f->output_data.mac->mouse_pixel = FRAME_FOREGROUND_PIXEL (f);
1458 #if 0 /* MAC_TODO : cursor changes */
1459 BLOCK_INPUT;
1461 /* It's not okay to crash if the user selects a screwy cursor. */
1462 count = x_catch_errors (FRAME_W32_DISPLAY (f));
1464 if (!EQ (Qnil, Vx_pointer_shape))
1466 CHECK_NUMBER (Vx_pointer_shape);
1467 cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XINT (Vx_pointer_shape));
1469 else
1470 cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_xterm);
1471 x_check_errors (FRAME_W32_DISPLAY (f), "bad text pointer cursor: %s");
1473 if (!EQ (Qnil, Vx_nontext_pointer_shape))
1475 CHECK_NUMBER (Vx_nontext_pointer_shape);
1476 nontext_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f),
1477 XINT (Vx_nontext_pointer_shape));
1479 else
1480 nontext_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_left_ptr);
1481 x_check_errors (FRAME_W32_DISPLAY (f), "bad nontext pointer cursor: %s");
1483 if (!EQ (Qnil, Vx_hourglass_pointer_shape))
1485 CHECK_NUMBER (Vx_hourglass_pointer_shape);
1486 hourglass_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f),
1487 XINT (Vx_hourglass_pointer_shape));
1489 else
1490 hourglass_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_watch);
1491 x_check_errors (FRAME_W32_DISPLAY (f), "bad busy pointer cursor: %s");
1493 x_check_errors (FRAME_W32_DISPLAY (f), "bad nontext pointer cursor: %s");
1494 if (!EQ (Qnil, Vx_mode_pointer_shape))
1496 CHECK_NUMBER (Vx_mode_pointer_shape);
1497 mode_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f),
1498 XINT (Vx_mode_pointer_shape));
1500 else
1501 mode_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_xterm);
1502 x_check_errors (FRAME_W32_DISPLAY (f), "bad modeline pointer cursor: %s");
1504 if (!EQ (Qnil, Vx_sensitive_text_pointer_shape))
1506 CHECK_NUMBER (Vx_sensitive_text_pointer_shape);
1507 hand_cursor
1508 = XCreateFontCursor (FRAME_W32_DISPLAY (f),
1509 XINT (Vx_sensitive_text_pointer_shape));
1511 else
1512 hand_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_crosshair);
1514 if (!NILP (Vx_window_horizontal_drag_shape))
1516 CHECK_NUMBER (Vx_window_horizontal_drag_shape);
1517 horizontal_drag_cursor
1518 = XCreateFontCursor (FRAME_W32_DISPLAY (f),
1519 XINT (Vx_window_horizontal_drag_shape));
1521 else
1522 horizontal_drag_cursor
1523 = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_sb_h_double_arrow);
1525 /* Check and report errors with the above calls. */
1526 x_check_errors (FRAME_W32_DISPLAY (f), "can't set cursor shape: %s");
1527 x_uncatch_errors (FRAME_W32_DISPLAY (f), count);
1530 XColor fore_color, back_color;
1532 fore_color.pixel = f->output_data.w32->mouse_pixel;
1533 back_color.pixel = mask_color;
1534 XQueryColor (FRAME_W32_DISPLAY (f),
1535 DefaultColormap (FRAME_W32_DISPLAY (f),
1536 DefaultScreen (FRAME_W32_DISPLAY (f))),
1537 &fore_color);
1538 XQueryColor (FRAME_W32_DISPLAY (f),
1539 DefaultColormap (FRAME_W32_DISPLAY (f),
1540 DefaultScreen (FRAME_W32_DISPLAY (f))),
1541 &back_color);
1542 XRecolorCursor (FRAME_W32_DISPLAY (f), cursor,
1543 &fore_color, &back_color);
1544 XRecolorCursor (FRAME_W32_DISPLAY (f), nontext_cursor,
1545 &fore_color, &back_color);
1546 XRecolorCursor (FRAME_W32_DISPLAY (f), mode_cursor,
1547 &fore_color, &back_color);
1548 XRecolorCursor (FRAME_W32_DISPLAY (f), hand_cursor,
1549 &fore_color, &back_color);
1550 XRecolorCursor (FRAME_W32_DISPLAY (f), hourglass_cursor,
1551 &fore_color, &back_color);
1554 if (FRAME_W32_WINDOW (f) != 0)
1555 XDefineCursor (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), cursor);
1557 if (cursor != f->output_data.w32->text_cursor && f->output_data.w32->text_cursor != 0)
1558 XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->text_cursor);
1559 f->output_data.w32->text_cursor = cursor;
1561 if (nontext_cursor != f->output_data.w32->nontext_cursor
1562 && f->output_data.w32->nontext_cursor != 0)
1563 XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->nontext_cursor);
1564 f->output_data.w32->nontext_cursor = nontext_cursor;
1566 if (hourglass_cursor != f->output_data.w32->hourglass_cursor
1567 && f->output_data.w32->hourglass_cursor != 0)
1568 XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->hourglass_cursor);
1569 f->output_data.w32->hourglass_cursor = hourglass_cursor;
1571 if (mode_cursor != f->output_data.w32->modeline_cursor
1572 && f->output_data.w32->modeline_cursor != 0)
1573 XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->modeline_cursor);
1574 f->output_data.w32->modeline_cursor = mode_cursor;
1576 if (hand_cursor != f->output_data.w32->hand_cursor
1577 && f->output_data.w32->hand_cursor != 0)
1578 XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->hand_cursor);
1579 f->output_data.w32->hand_cursor = hand_cursor;
1581 XFlush (FRAME_W32_DISPLAY (f));
1582 UNBLOCK_INPUT;
1584 update_face_from_frame_parameter (f, Qmouse_color, arg);
1585 #endif /* MAC_TODO */
1588 void
1589 x_set_cursor_color (f, arg, oldval)
1590 struct frame *f;
1591 Lisp_Object arg, oldval;
1593 unsigned long fore_pixel, pixel;
1595 if (!NILP (Vx_cursor_fore_pixel))
1596 fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel,
1597 WHITE_PIX_DEFAULT (f));
1598 else
1599 fore_pixel = FRAME_BACKGROUND_PIXEL (f);
1601 pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1603 /* Make sure that the cursor color differs from the background color. */
1604 if (pixel == FRAME_BACKGROUND_PIXEL (f))
1606 pixel = f->output_data.mac->mouse_pixel;
1607 if (pixel == fore_pixel)
1608 fore_pixel = FRAME_BACKGROUND_PIXEL (f);
1611 f->output_data.mac->cursor_foreground_pixel = fore_pixel;
1612 f->output_data.mac->cursor_pixel = pixel;
1614 if (FRAME_MAC_WINDOW (f) != 0)
1616 BLOCK_INPUT;
1617 /* Update frame's cursor_gc. */
1618 f->output_data.mac->cursor_gc->foreground = fore_pixel;
1619 f->output_data.mac->cursor_gc->background = pixel;
1621 UNBLOCK_INPUT;
1623 if (FRAME_VISIBLE_P (f))
1625 x_update_cursor (f, 0);
1626 x_update_cursor (f, 1);
1630 update_face_from_frame_parameter (f, Qcursor_color, arg);
1633 /* Set the border-color of frame F to pixel value PIX.
1634 Note that this does not fully take effect if done before
1635 F has a window. */
1637 void
1638 x_set_border_pixel (f, pix)
1639 struct frame *f;
1640 int pix;
1643 f->output_data.mac->border_pixel = pix;
1645 if (FRAME_MAC_WINDOW (f) != 0 && f->border_width > 0)
1647 if (FRAME_VISIBLE_P (f))
1648 redraw_frame (f);
1652 /* Set the border-color of frame F to value described by ARG.
1653 ARG can be a string naming a color.
1654 The border-color is used for the border that is drawn by the server.
1655 Note that this does not fully take effect if done before
1656 F has a window; it must be redone when the window is created. */
1658 void
1659 x_set_border_color (f, arg, oldval)
1660 struct frame *f;
1661 Lisp_Object arg, oldval;
1663 int pix;
1665 CHECK_STRING (arg);
1666 pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1667 x_set_border_pixel (f, pix);
1668 update_face_from_frame_parameter (f, Qborder_color, arg);
1672 void
1673 x_set_cursor_type (f, arg, oldval)
1674 FRAME_PTR f;
1675 Lisp_Object arg, oldval;
1677 set_frame_cursor_types (f, arg);
1679 /* Make sure the cursor gets redrawn. */
1680 cursor_type_changed = 1;
1683 #if 0 /* MAC_TODO: really no icon for Mac */
1684 void
1685 x_set_icon_type (f, arg, oldval)
1686 struct frame *f;
1687 Lisp_Object arg, oldval;
1689 int result;
1691 if (NILP (arg) && NILP (oldval))
1692 return;
1694 if (STRINGP (arg) && STRINGP (oldval)
1695 && EQ (Fstring_equal (oldval, arg), Qt))
1696 return;
1698 if (SYMBOLP (arg) && SYMBOLP (oldval) && EQ (arg, oldval))
1699 return;
1701 BLOCK_INPUT;
1703 result = x_bitmap_icon (f, arg);
1704 if (result)
1706 UNBLOCK_INPUT;
1707 error ("No icon window available");
1710 UNBLOCK_INPUT;
1712 #endif /* MAC_TODO */
1714 void
1715 x_set_icon_name (f, arg, oldval)
1716 struct frame *f;
1717 Lisp_Object arg, oldval;
1719 int result;
1721 if (STRINGP (arg))
1723 if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
1724 return;
1726 else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
1727 return;
1729 f->icon_name = arg;
1731 #if 0 /* MAC_TODO */
1732 if (f->output_data.w32->icon_bitmap != 0)
1733 return;
1735 BLOCK_INPUT;
1737 result = x_text_icon (f,
1738 (char *) SDATA ((!NILP (f->icon_name)
1739 ? f->icon_name
1740 : !NILP (f->title)
1741 ? f->title
1742 : f->name)));
1744 if (result)
1746 UNBLOCK_INPUT;
1747 error ("No icon window available");
1750 /* If the window was unmapped (and its icon was mapped),
1751 the new icon is not mapped, so map the window in its stead. */
1752 if (FRAME_VISIBLE_P (f))
1754 #ifdef USE_X_TOOLKIT
1755 XtPopup (f->output_data.w32->widget, XtGrabNone);
1756 #endif
1757 XMapWindow (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f));
1760 XFlush (FRAME_W32_DISPLAY (f));
1761 UNBLOCK_INPUT;
1762 #endif /* MAC_TODO */
1766 void
1767 x_set_menu_bar_lines (f, value, oldval)
1768 struct frame *f;
1769 Lisp_Object value, oldval;
1771 int nlines;
1772 int olines = FRAME_MENU_BAR_LINES (f);
1774 /* Right now, menu bars don't work properly in minibuf-only frames;
1775 most of the commands try to apply themselves to the minibuffer
1776 frame itself, and get an error because you can't switch buffers
1777 in or split the minibuffer window. */
1778 if (FRAME_MINIBUF_ONLY_P (f))
1779 return;
1781 if (INTEGERP (value))
1782 nlines = XINT (value);
1783 else
1784 nlines = 0;
1786 FRAME_MENU_BAR_LINES (f) = 0;
1787 if (nlines)
1788 FRAME_EXTERNAL_MENU_BAR (f) = 1;
1789 else
1791 if (FRAME_EXTERNAL_MENU_BAR (f) == 1)
1792 free_frame_menubar (f);
1793 FRAME_EXTERNAL_MENU_BAR (f) = 0;
1795 /* Adjust the frame size so that the client (text) dimensions
1796 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
1797 set correctly. */
1798 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
1799 do_pending_window_change (0);
1801 adjust_glyphs (f);
1805 /* Set the number of lines used for the tool bar of frame F to VALUE.
1806 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1807 is the old number of tool bar lines. This function changes the
1808 height of all windows on frame F to match the new tool bar height.
1809 The frame's height doesn't change. */
1811 void
1812 x_set_tool_bar_lines (f, value, oldval)
1813 struct frame *f;
1814 Lisp_Object value, oldval;
1816 int delta, nlines, root_height;
1817 Lisp_Object root_window;
1819 /* Treat tool bars like menu bars. */
1820 if (FRAME_MINIBUF_ONLY_P (f))
1821 return;
1823 /* Use VALUE only if an integer >= 0. */
1824 if (INTEGERP (value) && XINT (value) >= 0)
1825 nlines = XFASTINT (value);
1826 else
1827 nlines = 0;
1829 /* Make sure we redisplay all windows in this frame. */
1830 ++windows_or_buffers_changed;
1832 delta = nlines - FRAME_TOOL_BAR_LINES (f);
1834 /* Don't resize the tool-bar to more than we have room for. */
1835 root_window = FRAME_ROOT_WINDOW (f);
1836 root_height = WINDOW_TOTAL_LINES (XWINDOW (root_window));
1837 if (root_height - delta < 1)
1839 delta = root_height - 1;
1840 nlines = FRAME_TOOL_BAR_LINES (f) + delta;
1843 FRAME_TOOL_BAR_LINES (f) = nlines;
1844 change_window_heights (root_window, delta);
1845 adjust_glyphs (f);
1847 /* We also have to make sure that the internal border at the top of
1848 the frame, below the menu bar or tool bar, is redrawn when the
1849 tool bar disappears. This is so because the internal border is
1850 below the tool bar if one is displayed, but is below the menu bar
1851 if there isn't a tool bar. The tool bar draws into the area
1852 below the menu bar. */
1853 if (FRAME_MAC_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0)
1855 updating_frame = f;
1856 clear_frame ();
1857 clear_current_matrices (f);
1858 updating_frame = NULL;
1861 /* If the tool bar gets smaller, the internal border below it
1862 has to be cleared. It was formerly part of the display
1863 of the larger tool bar, and updating windows won't clear it. */
1864 if (delta < 0)
1866 int height = FRAME_INTERNAL_BORDER_WIDTH (f);
1867 int width = FRAME_PIXEL_WIDTH (f);
1868 int y = nlines * FRAME_LINE_HEIGHT (f);
1870 BLOCK_INPUT;
1871 XClearArea (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f),
1872 0, y, width, height, 0);
1873 UNBLOCK_INPUT;
1875 if (WINDOWP (f->tool_bar_window))
1876 clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix);
1881 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1882 w32_id_name.
1884 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1885 name; if NAME is a string, set F's name to NAME and set
1886 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1888 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1889 suggesting a new name, which lisp code should override; if
1890 F->explicit_name is set, ignore the new name; otherwise, set it. */
1892 void
1893 x_set_name (f, name, explicit)
1894 struct frame *f;
1895 Lisp_Object name;
1896 int explicit;
1898 /* Make sure that requests from lisp code override requests from
1899 Emacs redisplay code. */
1900 if (explicit)
1902 /* If we're switching from explicit to implicit, we had better
1903 update the mode lines and thereby update the title. */
1904 if (f->explicit_name && NILP (name))
1905 update_mode_lines = 1;
1907 f->explicit_name = ! NILP (name);
1909 else if (f->explicit_name)
1910 return;
1912 /* If NAME is nil, set the name to the w32_id_name. */
1913 if (NILP (name))
1915 /* Check for no change needed in this very common case
1916 before we do any consing. */
1917 if (!strcmp (FRAME_MAC_DISPLAY_INFO (f)->mac_id_name,
1918 SDATA (f->name)))
1919 return;
1920 name = build_string (FRAME_MAC_DISPLAY_INFO (f)->mac_id_name);
1922 else
1923 CHECK_STRING (name);
1925 /* Don't change the name if it's already NAME. */
1926 if (! NILP (Fstring_equal (name, f->name)))
1927 return;
1929 f->name = name;
1931 /* For setting the frame title, the title parameter should override
1932 the name parameter. */
1933 if (! NILP (f->title))
1934 name = f->title;
1936 if (FRAME_MAC_WINDOW (f))
1938 if (STRING_MULTIBYTE (name))
1939 #if TARGET_API_MAC_CARBON
1940 name = ENCODE_UTF_8 (name);
1941 #else
1942 return;
1943 #endif
1945 BLOCK_INPUT;
1948 #if TARGET_API_MAC_CARBON
1949 CFStringRef windowTitle =
1950 CFStringCreateWithCString (NULL, SDATA (name),
1951 kCFStringEncodingUTF8);
1953 SetWindowTitleWithCFString (FRAME_MAC_WINDOW (f), windowTitle);
1954 CFRelease (windowTitle);
1955 #else
1956 Str255 windowTitle;
1957 if (strlen (SDATA (name)) < 255)
1959 strcpy (windowTitle, SDATA (name));
1960 c2pstr (windowTitle);
1961 SetWTitle (FRAME_MAC_WINDOW (f), windowTitle);
1963 #endif
1966 UNBLOCK_INPUT;
1970 /* This function should be called when the user's lisp code has
1971 specified a name for the frame; the name will override any set by the
1972 redisplay code. */
1973 void
1974 x_explicitly_set_name (f, arg, oldval)
1975 FRAME_PTR f;
1976 Lisp_Object arg, oldval;
1978 x_set_name (f, arg, 1);
1981 /* This function should be called by Emacs redisplay code to set the
1982 name; names set this way will never override names set by the user's
1983 lisp code. */
1984 void
1985 x_implicitly_set_name (f, arg, oldval)
1986 FRAME_PTR f;
1987 Lisp_Object arg, oldval;
1989 x_set_name (f, arg, 0);
1992 /* Change the title of frame F to NAME.
1993 If NAME is nil, use the frame name as the title.
1995 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1996 name; if NAME is a string, set F's name to NAME and set
1997 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1999 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2000 suggesting a new name, which lisp code should override; if
2001 F->explicit_name is set, ignore the new name; otherwise, set it. */
2003 void
2004 x_set_title (f, name, old_name)
2005 struct frame *f;
2006 Lisp_Object name, old_name;
2008 /* Don't change the title if it's already NAME. */
2009 if (EQ (name, f->title))
2010 return;
2012 update_mode_lines = 1;
2014 f->title = name;
2016 if (NILP (name))
2017 name = f->name;
2019 if (FRAME_MAC_WINDOW (f))
2021 if (STRING_MULTIBYTE (name))
2022 #if TARGET_API_MAC_CARBON
2023 name = ENCODE_UTF_8 (name);
2024 #else
2025 return;
2026 #endif
2028 BLOCK_INPUT;
2031 #if TARGET_API_MAC_CARBON
2032 CFStringRef windowTitle =
2033 CFStringCreateWithCString (NULL, SDATA (name),
2034 kCFStringEncodingUTF8);
2036 SetWindowTitleWithCFString (FRAME_MAC_WINDOW (f), windowTitle);
2037 CFRelease (windowTitle);
2038 #else
2039 Str255 windowTitle;
2040 if (strlen (SDATA (name)) < 255)
2042 strcpy (windowTitle, SDATA (name));
2043 c2pstr (windowTitle);
2044 SetWTitle (FRAME_MAC_WINDOW (f), windowTitle);
2046 #endif
2049 UNBLOCK_INPUT;
2053 void
2054 x_set_scroll_bar_default_width (f)
2055 struct frame *f;
2057 /* Imitate X without X Toolkit */
2059 int wid = FRAME_COLUMN_WIDTH (f);
2061 #ifdef MAC_OSX
2062 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = 16; /* Aqua scroll bars. */
2063 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) +
2064 wid - 1) / wid;
2065 #else /* not MAC_OSX */
2066 /* Make the actual width at least 14 pixels and a multiple of a
2067 character width. */
2068 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid;
2070 /* Use all of that space (aside from required margins) for the
2071 scroll bar. */
2072 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = 0;
2073 #endif /* not MAC_OSX */
2077 /* Subroutines of creating a frame. */
2079 char *
2080 x_get_string_resource (rdb, name, class)
2081 XrmDatabase rdb;
2082 char *name, *class;
2084 /* MAC_TODO: implement resource strings */
2085 return (char *)0;
2088 /* Return the value of parameter PARAM.
2090 First search ALIST, then Vdefault_frame_alist, then the X defaults
2091 database, using ATTRIBUTE as the attribute name and CLASS as its class.
2093 Convert the resource to the type specified by desired_type.
2095 If no default is specified, return Qunbound. If you call
2096 mac_get_arg, make sure you deal with Qunbound in a reasonable way,
2097 and don't let it get stored in any Lisp-visible variables! */
2099 static Lisp_Object
2100 mac_get_arg (alist, param, attribute, class, type)
2101 Lisp_Object alist, param;
2102 char *attribute;
2103 char *class;
2104 enum resource_types type;
2106 return x_get_arg (check_x_display_info (Qnil),
2107 alist, param, attribute, class, type);
2111 /* XParseGeometry copied from w32xfns.c */
2114 * XParseGeometry parses strings of the form
2115 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
2116 * width, height, xoffset, and yoffset are unsigned integers.
2117 * Example: "=80x24+300-49"
2118 * The equal sign is optional.
2119 * It returns a bitmask that indicates which of the four values
2120 * were actually found in the string. For each value found,
2121 * the corresponding argument is updated; for each value
2122 * not found, the corresponding argument is left unchanged.
2125 static int
2126 read_integer (string, NextString)
2127 register char *string;
2128 char **NextString;
2130 register int Result = 0;
2131 int Sign = 1;
2133 if (*string == '+')
2134 string++;
2135 else if (*string == '-')
2137 string++;
2138 Sign = -1;
2140 for (; (*string >= '0') && (*string <= '9'); string++)
2142 Result = (Result * 10) + (*string - '0');
2144 *NextString = string;
2145 if (Sign >= 0)
2146 return (Result);
2147 else
2148 return (-Result);
2152 XParseGeometry (string, x, y, width, height)
2153 char *string;
2154 int *x, *y;
2155 unsigned int *width, *height; /* RETURN */
2157 int mask = NoValue;
2158 register char *strind;
2159 unsigned int tempWidth, tempHeight;
2160 int tempX, tempY;
2161 char *nextCharacter;
2163 if ((string == NULL) || (*string == '\0')) return (mask);
2164 if (*string == '=')
2165 string++; /* ignore possible '=' at beg of geometry spec */
2167 strind = (char *)string;
2168 if (*strind != '+' && *strind != '-' && *strind != 'x')
2170 tempWidth = read_integer (strind, &nextCharacter);
2171 if (strind == nextCharacter)
2172 return (0);
2173 strind = nextCharacter;
2174 mask |= WidthValue;
2177 if (*strind == 'x' || *strind == 'X')
2179 strind++;
2180 tempHeight = read_integer (strind, &nextCharacter);
2181 if (strind == nextCharacter)
2182 return (0);
2183 strind = nextCharacter;
2184 mask |= HeightValue;
2187 if ((*strind == '+') || (*strind == '-'))
2189 if (*strind == '-')
2191 strind++;
2192 tempX = -read_integer (strind, &nextCharacter);
2193 if (strind == nextCharacter)
2194 return (0);
2195 strind = nextCharacter;
2196 mask |= XNegative;
2199 else
2201 strind++;
2202 tempX = read_integer (strind, &nextCharacter);
2203 if (strind == nextCharacter)
2204 return (0);
2205 strind = nextCharacter;
2207 mask |= XValue;
2208 if ((*strind == '+') || (*strind == '-'))
2210 if (*strind == '-')
2212 strind++;
2213 tempY = -read_integer (strind, &nextCharacter);
2214 if (strind == nextCharacter)
2215 return (0);
2216 strind = nextCharacter;
2217 mask |= YNegative;
2220 else
2222 strind++;
2223 tempY = read_integer (strind, &nextCharacter);
2224 if (strind == nextCharacter)
2225 return (0);
2226 strind = nextCharacter;
2228 mask |= YValue;
2232 /* If strind isn't at the end of the string the it's an invalid
2233 geometry specification. */
2235 if (*strind != '\0') return (0);
2237 if (mask & XValue)
2238 *x = tempX;
2239 if (mask & YValue)
2240 *y = tempY;
2241 if (mask & WidthValue)
2242 *width = tempWidth;
2243 if (mask & HeightValue)
2244 *height = tempHeight;
2245 return (mask);
2249 #if 0 /* MAC_TODO */
2250 /* Create and set up the Mac window for frame F. */
2252 static void
2253 mac_window (f, window_prompting, minibuffer_only)
2254 struct frame *f;
2255 long window_prompting;
2256 int minibuffer_only;
2258 Rect r;
2260 BLOCK_INPUT;
2262 /* Use the resource name as the top-level window name
2263 for looking up resources. Make a non-Lisp copy
2264 for the window manager, so GC relocation won't bother it.
2266 Elsewhere we specify the window name for the window manager. */
2269 char *str = (char *) SDATA (Vx_resource_name);
2270 f->namebuf = (char *) xmalloc (strlen (str) + 1);
2271 strcpy (f->namebuf, str);
2274 SetRect (&r, f->left_pos, f->top_pos,
2275 f->left_pos + FRAME_PIXEL_WIDTH (f),
2276 f->top_pos + FRAME_PIXEL_HEIGHT (f));
2277 FRAME_MAC_WINDOW (f)
2278 = NewCWindow (NULL, &r, "\p", 1, zoomDocProc, (WindowPtr) -1, 1, (long) f->output_data.mac);
2280 validate_x_resource_name ();
2282 /* x_set_name normally ignores requests to set the name if the
2283 requested name is the same as the current name. This is the one
2284 place where that assumption isn't correct; f->name is set, but
2285 the server hasn't been told. */
2287 Lisp_Object name;
2288 int explicit = f->explicit_name;
2290 f->explicit_name = 0;
2291 name = f->name;
2292 f->name = Qnil;
2293 x_set_name (f, name, explicit);
2296 ShowWindow (FRAME_MAC_WINDOW (f));
2298 UNBLOCK_INPUT;
2300 if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f))
2301 initialize_frame_menubar (f);
2303 if (FRAME_MAC_WINDOW (f) == 0)
2304 error ("Unable to create window");
2306 #endif /* MAC_TODO */
2308 /* Handle the icon stuff for this window. Perhaps later we might
2309 want an x_set_icon_position which can be called interactively as
2310 well. */
2312 static void
2313 x_icon (f, parms)
2314 struct frame *f;
2315 Lisp_Object parms;
2317 Lisp_Object icon_x, icon_y;
2319 /* Set the position of the icon. Note that Windows 95 groups all
2320 icons in the tray. */
2321 icon_x = mac_get_arg (parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
2322 icon_y = mac_get_arg (parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
2323 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
2325 CHECK_NUMBER (icon_x);
2326 CHECK_NUMBER (icon_y);
2328 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
2329 error ("Both left and top icon corners of icon must be specified");
2331 BLOCK_INPUT;
2333 if (! EQ (icon_x, Qunbound))
2334 x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y));
2336 #if 0 /* TODO */
2337 /* Start up iconic or window? */
2338 x_wm_set_window_state
2339 (f, (EQ (w32_get_arg (parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL), Qicon)
2340 ? IconicState
2341 : NormalState));
2343 x_text_icon (f, (char *) SDATA ((!NILP (f->icon_name)
2344 ? f->icon_name
2345 : f->name)));
2346 #endif
2348 UNBLOCK_INPUT;
2352 void
2353 x_make_gc (f)
2354 struct frame *f;
2356 XGCValues gc_values;
2358 BLOCK_INPUT;
2360 /* Create the GCs of this frame.
2361 Note that many default values are used. */
2363 /* Normal video */
2364 gc_values.font = FRAME_FONT (f);
2365 gc_values.foreground = FRAME_FOREGROUND_PIXEL (f);
2366 gc_values.background = FRAME_BACKGROUND_PIXEL (f);
2367 f->output_data.mac->normal_gc = XCreateGC (FRAME_MAC_DISPLAY (f),
2368 FRAME_MAC_WINDOW (f),
2369 GCFont | GCForeground | GCBackground,
2370 &gc_values);
2372 /* Reverse video style. */
2373 gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
2374 gc_values.background = FRAME_FOREGROUND_PIXEL (f);
2375 f->output_data.mac->reverse_gc = XCreateGC (FRAME_MAC_DISPLAY (f),
2376 FRAME_MAC_WINDOW (f),
2377 GCFont | GCForeground | GCBackground,
2378 &gc_values);
2380 /* Cursor has cursor-color background, background-color foreground. */
2381 gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
2382 gc_values.background = f->output_data.mac->cursor_pixel;
2383 f->output_data.mac->cursor_gc = XCreateGC (FRAME_MAC_DISPLAY (f),
2384 FRAME_MAC_WINDOW (f),
2385 GCFont | GCForeground | GCBackground,
2386 &gc_values);
2388 /* Reliefs. */
2389 f->output_data.mac->white_relief.gc = 0;
2390 f->output_data.mac->black_relief.gc = 0;
2392 #if 0
2393 /* Create the gray border tile used when the pointer is not in
2394 the frame. Since this depends on the frame's pixel values,
2395 this must be done on a per-frame basis. */
2396 f->output_data.x->border_tile
2397 = (XCreatePixmapFromBitmapData
2398 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
2399 gray_bits, gray_width, gray_height,
2400 f->output_data.x->foreground_pixel,
2401 f->output_data.x->background_pixel,
2402 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))));
2403 #endif
2405 UNBLOCK_INPUT;
2409 /* Free what was was allocated in x_make_gc. */
2411 void
2412 x_free_gcs (f)
2413 struct frame *f;
2415 Display *dpy = FRAME_MAC_DISPLAY (f);
2417 BLOCK_INPUT;
2419 if (f->output_data.mac->normal_gc)
2421 XFreeGC (dpy, f->output_data.mac->normal_gc);
2422 f->output_data.mac->normal_gc = 0;
2425 if (f->output_data.mac->reverse_gc)
2427 XFreeGC (dpy, f->output_data.mac->reverse_gc);
2428 f->output_data.mac->reverse_gc = 0;
2431 if (f->output_data.mac->cursor_gc)
2433 XFreeGC (dpy, f->output_data.mac->cursor_gc);
2434 f->output_data.mac->cursor_gc = 0;
2437 #if 0
2438 if (f->output_data.mac->border_tile)
2440 XFreePixmap (dpy, f->output_data.mac->border_tile);
2441 f->output_data.mac->border_tile = 0;
2443 #endif
2445 if (f->output_data.mac->white_relief.gc)
2447 XFreeGC (dpy, f->output_data.mac->white_relief.gc);
2448 f->output_data.mac->white_relief.gc = 0;
2451 if (f->output_data.mac->black_relief.gc)
2453 XFreeGC (dpy, f->output_data.mac->black_relief.gc);
2454 f->output_data.mac->black_relief.gc = 0;
2457 UNBLOCK_INPUT;
2461 /* Handler for signals raised during x_create_frame and
2462 x_create_top_frame. FRAME is the frame which is partially
2463 constructed. */
2465 static Lisp_Object
2466 unwind_create_frame (frame)
2467 Lisp_Object frame;
2469 struct frame *f = XFRAME (frame);
2471 /* If frame is ``official'', nothing to do. */
2472 if (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame))
2474 #if GLYPH_DEBUG
2475 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2476 #endif
2478 x_free_frame_resources (f);
2480 /* Check that reference counts are indeed correct. */
2481 xassert (dpyinfo->reference_count == dpyinfo_refcount);
2482 xassert (dpyinfo->image_cache->refcount == image_cache_refcount);
2483 return Qt;
2486 return Qnil;
2490 DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
2491 1, 1, 0,
2492 doc: /* Make a new window, which is called a \"frame\" in Emacs terms.
2493 Returns an Emacs frame object.
2494 ALIST is an alist of frame parameters.
2495 If the parameters specify that the frame should not have a minibuffer,
2496 and do not specify a specific minibuffer window to use,
2497 then `default-minibuffer-frame' must be a frame whose minibuffer can
2498 be shared by the new frame.
2500 This function is an internal primitive--use `make-frame' instead. */)
2501 (parms)
2502 Lisp_Object parms;
2504 struct frame *f;
2505 Lisp_Object frame, tem;
2506 Lisp_Object name;
2507 int minibuffer_only = 0;
2508 long window_prompting = 0;
2509 int width, height;
2510 int count = SPECPDL_INDEX ();
2511 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
2512 Lisp_Object display;
2513 struct mac_display_info *dpyinfo = NULL;
2514 Lisp_Object parent;
2515 struct kboard *kb;
2516 char x_frame_name[10];
2517 static int x_frame_count = 2; /* begins at 2 because terminal frame is F1 */
2519 check_mac ();
2521 /* Use this general default value to start with
2522 until we know if this frame has a specified name. */
2523 Vx_resource_name = Vinvocation_name;
2525 display = mac_get_arg (parms, Qdisplay, 0, 0, RES_TYPE_STRING);
2526 if (EQ (display, Qunbound))
2527 display = Qnil;
2528 dpyinfo = check_x_display_info (display);
2529 #ifdef MULTI_KBOARD
2530 kb = dpyinfo->kboard;
2531 #else
2532 kb = &the_only_kboard;
2533 #endif
2535 name = mac_get_arg (parms, Qname, "name", "Name", RES_TYPE_STRING);
2536 if (!STRINGP (name)
2537 && ! EQ (name, Qunbound)
2538 && ! NILP (name))
2539 error ("Invalid frame name--not a string or nil");
2541 if (STRINGP (name))
2542 Vx_resource_name = name;
2544 /* See if parent window is specified. */
2545 parent = mac_get_arg (parms, Qparent_id, NULL, NULL, RES_TYPE_NUMBER);
2546 if (EQ (parent, Qunbound))
2547 parent = Qnil;
2548 if (! NILP (parent))
2549 CHECK_NUMBER (parent);
2551 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
2552 /* No need to protect DISPLAY because that's not used after passing
2553 it to make_frame_without_minibuffer. */
2554 frame = Qnil;
2555 GCPRO4 (parms, parent, name, frame);
2556 tem = mac_get_arg (parms, Qminibuffer, "minibuffer", "Minibuffer",
2557 RES_TYPE_SYMBOL);
2558 if (EQ (tem, Qnone) || NILP (tem))
2559 f = make_frame_without_minibuffer (Qnil, kb, display);
2560 else if (EQ (tem, Qonly))
2562 f = make_minibuffer_frame ();
2563 minibuffer_only = 1;
2565 else if (WINDOWP (tem))
2566 f = make_frame_without_minibuffer (tem, kb, display);
2567 else
2568 f = make_frame (1);
2570 if (EQ (name, Qunbound) || NILP (name))
2572 sprintf (x_frame_name, "F%d", x_frame_count++);
2573 f->name = build_string (x_frame_name);
2574 f->explicit_name = 0;
2576 else
2578 f->name = name;
2579 f->explicit_name = 1;
2582 XSETFRAME (frame, f);
2584 /* Note that X Windows does support scroll bars. */
2585 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
2587 f->output_method = output_mac;
2588 f->output_data.mac = (struct mac_output *) xmalloc (sizeof (struct mac_output));
2589 bzero (f->output_data.mac, sizeof (struct mac_output));
2590 FRAME_FONTSET (f) = -1;
2591 record_unwind_protect (unwind_create_frame, frame);
2593 f->icon_name
2594 = mac_get_arg (parms, Qicon_name, "iconName", "Title", RES_TYPE_STRING);
2595 if (! STRINGP (f->icon_name))
2596 f->icon_name = Qnil;
2598 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
2599 #ifdef MULTI_KBOARD
2600 FRAME_KBOARD (f) = kb;
2601 #endif
2603 /* Specify the parent under which to make this window. */
2605 if (!NILP (parent))
2607 f->output_data.mac->parent_desc = (Window) XFASTINT (parent);
2608 f->output_data.mac->explicit_parent = 1;
2610 else
2612 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window;
2613 f->output_data.mac->explicit_parent = 0;
2616 /* Set the name; the functions to which we pass f expect the name to
2617 be set. */
2618 if (EQ (name, Qunbound) || NILP (name))
2620 f->name = build_string (dpyinfo->mac_id_name);
2621 f->explicit_name = 0;
2623 else
2625 f->name = name;
2626 f->explicit_name = 1;
2627 /* use the frame's title when getting resources for this frame. */
2628 specbind (Qx_resource_name, name);
2631 /* Extract the window parameters from the supplied values
2632 that are needed to determine window geometry. */
2634 Lisp_Object font;
2636 font = mac_get_arg (parms, Qfont, "font", "Font", RES_TYPE_STRING);
2638 BLOCK_INPUT;
2639 /* First, try whatever font the caller has specified. */
2640 if (STRINGP (font))
2642 tem = Fquery_fontset (font, Qnil);
2643 if (STRINGP (tem))
2644 font = x_new_fontset (f, SDATA (tem));
2645 else
2646 font = x_new_font (f, SDATA (font));
2649 /* Try out a font which we hope has bold and italic variations. */
2650 if (! STRINGP (font))
2651 font = x_new_font (f, "-ETL-fixed-medium-r-*--*-160-*-*-*-*-iso8859-1");
2652 /* If those didn't work, look for something which will at least work. */
2653 if (! STRINGP (font))
2654 font = x_new_font (f, "-*-monaco-*-12-*-mac-roman");
2655 if (! STRINGP (font))
2656 font = x_new_font (f, "-*-courier-*-10-*-mac-roman");
2657 if (! STRINGP (font))
2658 error ("Cannot find any usable font");
2659 UNBLOCK_INPUT;
2661 x_default_parameter (f, parms, Qfont, font,
2662 "font", "Font", RES_TYPE_STRING);
2665 x_default_parameter (f, parms, Qborder_width, make_number (0),
2666 "borderwidth", "BorderWidth", RES_TYPE_NUMBER);
2667 /* This defaults to 2 in order to match xterm. We recognize either
2668 internalBorderWidth or internalBorder (which is what xterm calls
2669 it). */
2670 if (NILP (Fassq (Qinternal_border_width, parms)))
2672 Lisp_Object value;
2674 value = mac_get_arg (parms, Qinternal_border_width,
2675 "internalBorder", "InternalBorder", RES_TYPE_NUMBER);
2676 if (! EQ (value, Qunbound))
2677 parms = Fcons (Fcons (Qinternal_border_width, value),
2678 parms);
2680 /* Default internalBorderWidth to 0 on Windows to match other programs. */
2681 x_default_parameter (f, parms, Qinternal_border_width, make_number (0),
2682 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER);
2683 x_default_parameter (f, parms, Qvertical_scroll_bars, Qright,
2684 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL);
2686 /* Also do the stuff which must be set before the window exists. */
2687 x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
2688 "foreground", "Foreground", RES_TYPE_STRING);
2689 x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
2690 "background", "Background", RES_TYPE_STRING);
2691 x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
2692 "pointerColor", "Foreground", RES_TYPE_STRING);
2693 x_default_parameter (f, parms, Qcursor_color, build_string ("black"),
2694 "cursorColor", "Foreground", RES_TYPE_STRING);
2695 x_default_parameter (f, parms, Qborder_color, build_string ("black"),
2696 "borderColor", "BorderColor", RES_TYPE_STRING);
2697 x_default_parameter (f, parms, Qscreen_gamma, Qnil,
2698 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
2699 x_default_parameter (f, parms, Qline_spacing, Qnil,
2700 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
2701 x_default_parameter (f, parms, Qleft_fringe, Qnil,
2702 "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
2703 x_default_parameter (f, parms, Qright_fringe, Qnil,
2704 "rightFringe", "RightFringe", RES_TYPE_NUMBER);
2707 /* Init faces before x_default_parameter is called for scroll-bar
2708 parameters because that function calls x_set_scroll_bar_width,
2709 which calls change_frame_size, which calls Fset_window_buffer,
2710 which runs hooks, which call Fvertical_motion. At the end, we
2711 end up in init_iterator with a null face cache, which should not
2712 happen. */
2713 init_frame_faces (f);
2715 x_default_parameter (f, parms, Qmenu_bar_lines, make_number (1),
2716 "menuBar", "MenuBar", RES_TYPE_NUMBER);
2717 x_default_parameter (f, parms, Qtool_bar_lines, make_number (1),
2718 "toolBar", "ToolBar", RES_TYPE_NUMBER);
2719 x_default_parameter (f, parms, Qbuffer_predicate, Qnil,
2720 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL);
2721 x_default_parameter (f, parms, Qtitle, Qnil,
2722 "title", "Title", RES_TYPE_STRING);
2724 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window;
2726 #if TARGET_API_MAC_CARBON
2727 f->output_data.mac->text_cursor = kThemeIBeamCursor;
2728 f->output_data.mac->nontext_cursor = kThemeArrowCursor;
2729 f->output_data.mac->modeline_cursor = kThemeArrowCursor;
2730 f->output_data.mac->hand_cursor = kThemePointingHandCursor;
2731 f->output_data.mac->hourglass_cursor = kThemeWatchCursor;
2732 f->output_data.mac->horizontal_drag_cursor = kThemeResizeLeftRightCursor;
2733 #else
2734 f->output_data.mac->text_cursor = GetCursor (iBeamCursor);
2735 f->output_data.mac->nontext_cursor = &arrow_cursor;
2736 f->output_data.mac->modeline_cursor = &arrow_cursor;
2737 f->output_data.mac->hand_cursor = &arrow_cursor;
2738 f->output_data.mac->hourglass_cursor = GetCursor (watchCursor);
2739 f->output_data.mac->horizontal_drag_cursor = &arrow_cursor;
2740 #endif
2742 /* Compute the size of the window. */
2743 window_prompting = x_figure_window_size (f, parms, 1);
2745 tem = mac_get_arg (parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
2746 f->no_split = minibuffer_only || EQ (tem, Qt);
2748 /* mac_window (f, window_prompting, minibuffer_only); */
2749 make_mac_frame (f);
2751 x_icon (f, parms);
2752 x_make_gc (f);
2754 /* Now consider the frame official. */
2755 FRAME_MAC_DISPLAY_INFO (f)->reference_count++;
2756 Vframe_list = Fcons (frame, Vframe_list);
2758 /* We need to do this after creating the window, so that the
2759 icon-creation functions can say whose icon they're describing. */
2760 x_default_parameter (f, parms, Qicon_type, Qnil,
2761 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
2763 x_default_parameter (f, parms, Qauto_raise, Qnil,
2764 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
2765 x_default_parameter (f, parms, Qauto_lower, Qnil,
2766 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
2767 x_default_parameter (f, parms, Qcursor_type, Qbox,
2768 "cursorType", "CursorType", RES_TYPE_SYMBOL);
2769 x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
2770 "scrollBarWidth", "ScrollBarWidth",
2771 RES_TYPE_NUMBER);
2773 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
2774 Change will not be effected unless different from the current
2775 FRAME_LINES (f). */
2776 width = FRAME_COLS (f);
2777 height = FRAME_LINES (f);
2779 SET_FRAME_COLS (f, 0);
2780 FRAME_LINES (f) = 0;
2781 change_frame_size (f, height, width, 1, 0, 0);
2783 #if 0 /* MAC_TODO: when we have window manager hints */
2784 /* Tell the server what size and position, etc, we want, and how
2785 badly we want them. This should be done after we have the menu
2786 bar so that its size can be taken into account. */
2787 BLOCK_INPUT;
2788 x_wm_set_size_hint (f, window_prompting, 0);
2789 UNBLOCK_INPUT;
2790 #endif
2792 /* Make the window appear on the frame and enable display, unless
2793 the caller says not to. However, with explicit parent, Emacs
2794 cannot control visibility, so don't try. */
2795 if (! f->output_data.mac->explicit_parent)
2797 Lisp_Object visibility;
2799 visibility = mac_get_arg (parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL);
2800 if (EQ (visibility, Qunbound))
2801 visibility = Qt;
2803 #if 0 /* MAC_TODO: really no iconify on Mac */
2804 if (EQ (visibility, Qicon))
2805 x_iconify_frame (f);
2806 else
2807 #endif
2808 if (! NILP (visibility))
2809 x_make_frame_visible (f);
2810 else
2811 /* Must have been Qnil. */
2814 UNGCPRO;
2816 /* Make sure windows on this frame appear in calls to next-window
2817 and similar functions. */
2818 Vwindow_list = Qnil;
2820 return unbind_to (count, frame);
2823 /* FRAME is used only to get a handle on the X display. We don't pass the
2824 display info directly because we're called from frame.c, which doesn't
2825 know about that structure. */
2826 Lisp_Object
2827 x_get_focus_frame (frame)
2828 struct frame *frame;
2830 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (frame);
2831 Lisp_Object xfocus;
2832 if (! dpyinfo->x_focus_frame)
2833 return Qnil;
2835 XSETFRAME (xfocus, dpyinfo->x_focus_frame);
2836 return xfocus;
2839 DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
2840 doc: /* Internal function called by `color-defined-p', which see. */)
2841 (color, frame)
2842 Lisp_Object color, frame;
2844 XColor foo;
2845 FRAME_PTR f = check_x_frame (frame);
2847 CHECK_STRING (color);
2849 if (mac_defined_color (f, SDATA (color), &foo, 0))
2850 return Qt;
2851 else
2852 return Qnil;
2855 DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
2856 doc: /* Internal function called by `color-values', which see. */)
2857 (color, frame)
2858 Lisp_Object color, frame;
2860 XColor foo;
2861 FRAME_PTR f = check_x_frame (frame);
2863 CHECK_STRING (color);
2865 if (mac_defined_color (f, SDATA (color), &foo, 0))
2867 Lisp_Object rgb[3];
2869 rgb[0] = make_number (foo.red);
2870 rgb[1] = make_number (foo.green);
2871 rgb[2] = make_number (foo.blue);
2872 return Flist (3, rgb);
2874 else
2875 return Qnil;
2878 DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
2879 doc: /* Internal function called by `display-color-p', which see. */)
2880 (display)
2881 Lisp_Object display;
2883 struct mac_display_info *dpyinfo = check_x_display_info (display);
2885 if (!dpyinfo->color_p)
2886 return Qnil;
2888 return Qt;
2891 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p,
2892 0, 1, 0,
2893 doc: /* Return t if the X display supports shades of gray.
2894 Note that color displays do support shades of gray.
2895 The optional argument DISPLAY specifies which display to ask about.
2896 DISPLAY should be either a frame or a display name (a string).
2897 If omitted or nil, that stands for the selected frame's display. */)
2898 (display)
2899 Lisp_Object display;
2901 struct mac_display_info *dpyinfo = check_x_display_info (display);
2903 if (dpyinfo->n_planes <= 1)
2904 return Qnil;
2906 return Qt;
2909 DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
2910 0, 1, 0,
2911 doc: /* Returns the width in pixels of the X display DISPLAY.
2912 The optional argument DISPLAY specifies which display to ask about.
2913 DISPLAY should be either a frame or a display name (a string).
2914 If omitted or nil, that stands for the selected frame's display. */)
2915 (display)
2916 Lisp_Object display;
2918 struct mac_display_info *dpyinfo = check_x_display_info (display);
2920 return make_number (dpyinfo->width);
2923 DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
2924 Sx_display_pixel_height, 0, 1, 0,
2925 doc: /* Returns the height in pixels of the X display DISPLAY.
2926 The optional argument DISPLAY specifies which display to ask about.
2927 DISPLAY should be either a frame or a display name (a string).
2928 If omitted or nil, that stands for the selected frame's display. */)
2929 (display)
2930 Lisp_Object display;
2932 struct mac_display_info *dpyinfo = check_x_display_info (display);
2934 return make_number (dpyinfo->height);
2937 DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
2938 0, 1, 0,
2939 doc: /* Returns the number of bitplanes of the display DISPLAY.
2940 The optional argument DISPLAY specifies which display to ask about.
2941 DISPLAY should be either a frame or a display name (a string).
2942 If omitted or nil, that stands for the selected frame's display. */)
2943 (display)
2944 Lisp_Object display;
2946 struct mac_display_info *dpyinfo = check_x_display_info (display);
2948 return make_number (dpyinfo->n_planes);
2951 DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
2952 0, 1, 0,
2953 doc: /* Returns the number of color cells of the display DISPLAY.
2954 The optional argument DISPLAY specifies which display to ask about.
2955 DISPLAY should be either a frame or a display name (a string).
2956 If omitted or nil, that stands for the selected frame's display. */)
2957 (display)
2958 Lisp_Object display;
2960 struct mac_display_info *dpyinfo = check_x_display_info (display);
2962 /* We force 24+ bit depths to 24-bit to prevent an overflow. */
2963 return make_number (1 << min (dpyinfo->n_planes, 24));
2966 DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
2967 Sx_server_max_request_size,
2968 0, 1, 0,
2969 doc: /* Returns the maximum request size of the server of display DISPLAY.
2970 The optional argument DISPLAY specifies which display to ask about.
2971 DISPLAY should be either a frame or a display name (a string).
2972 If omitted or nil, that stands for the selected frame's display. */)
2973 (display)
2974 Lisp_Object display;
2976 struct mac_display_info *dpyinfo = check_x_display_info (display);
2978 return make_number (1);
2981 DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
2982 doc: /* Returns the vendor ID string of the Mac OS system (Apple).
2983 The optional argument DISPLAY specifies which display to ask about.
2984 DISPLAY should be either a frame or a display name (a string).
2985 If omitted or nil, that stands for the selected frame's display. */)
2986 (display)
2987 Lisp_Object display;
2989 return build_string ("Apple Computers");
2992 DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
2993 doc: /* Returns the version numbers of the server of display DISPLAY.
2994 The value is a list of three integers: the major and minor
2995 version numbers, and the vendor-specific release
2996 number. See also the function `x-server-vendor'.
2998 The optional argument DISPLAY specifies which display to ask about.
2999 DISPLAY should be either a frame or a display name (a string).
3000 If omitted or nil, that stands for the selected frame's display. */)
3001 (display)
3002 Lisp_Object display;
3004 int mac_major_version;
3005 SInt32 response;
3007 if (Gestalt (gestaltSystemVersion, &response) != noErr)
3008 error ("Cannot get Mac OS version");
3010 mac_major_version = (response >> 8) & 0xff;
3011 /* convert BCD to int */
3012 mac_major_version -= (mac_major_version >> 4) * 6;
3014 return Fcons (make_number (mac_major_version),
3015 Fcons (make_number ((response >> 4) & 0xf),
3016 Fcons (make_number (response & 0xf),
3017 Qnil)));
3020 DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
3021 doc: /* Return the number of screens on the server of display DISPLAY.
3022 The optional argument DISPLAY specifies which display to ask about.
3023 DISPLAY should be either a frame or a display name (a string).
3024 If omitted or nil, that stands for the selected frame's display. */)
3025 (display)
3026 Lisp_Object display;
3028 return make_number (1);
3031 DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0,
3032 doc: /* Return the height in millimeters of the X display DISPLAY.
3033 The optional argument DISPLAY specifies which display to ask about.
3034 DISPLAY should be either a frame or a display name (a string).
3035 If omitted or nil, that stands for the selected frame's display. */)
3036 (display)
3037 Lisp_Object display;
3039 /* MAC_TODO: this is an approximation, and only of the main display */
3041 struct mac_display_info *dpyinfo = check_x_display_info (display);
3043 return make_number ((int) (dpyinfo->height * 25.4 / dpyinfo->resy));
3046 DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
3047 doc: /* Return the width in millimeters of the X display DISPLAY.
3048 The optional argument DISPLAY specifies which display to ask about.
3049 DISPLAY should be either a frame or a display name (a string).
3050 If omitted or nil, that stands for the selected frame's display. */)
3051 (display)
3052 Lisp_Object display;
3054 /* MAC_TODO: this is an approximation, and only of the main display */
3056 struct mac_display_info *dpyinfo = check_x_display_info (display);
3058 return make_number ((int) (dpyinfo->width * 25.4 / dpyinfo->resx));
3061 DEFUN ("x-display-backing-store", Fx_display_backing_store,
3062 Sx_display_backing_store, 0, 1, 0,
3063 doc: /* Returns an indication of whether display DISPLAY does backing store.
3064 The value may be `always', `when-mapped', or `not-useful'.
3065 The optional argument DISPLAY specifies which display to ask about.
3066 DISPLAY should be either a frame or a display name (a string).
3067 If omitted or nil, that stands for the selected frame's display. */)
3068 (display)
3069 Lisp_Object display;
3071 return intern ("not-useful");
3074 DEFUN ("x-display-visual-class", Fx_display_visual_class,
3075 Sx_display_visual_class, 0, 1, 0,
3076 doc: /* Returns the visual class of the display DISPLAY.
3077 The value is one of the symbols `static-gray', `gray-scale',
3078 `static-color', `pseudo-color', `true-color', or `direct-color'.
3080 The optional argument DISPLAY specifies which display to ask about.
3081 DISPLAY should be either a frame or a display name (a string).
3082 If omitted or nil, that stands for the selected frame's display. */)
3083 (display)
3084 Lisp_Object display;
3086 struct mac_display_info *dpyinfo = check_x_display_info (display);
3088 #if 0
3089 switch (dpyinfo->visual->class)
3091 case StaticGray: return (intern ("static-gray"));
3092 case GrayScale: return (intern ("gray-scale"));
3093 case StaticColor: return (intern ("static-color"));
3094 case PseudoColor: return (intern ("pseudo-color"));
3095 case TrueColor: return (intern ("true-color"));
3096 case DirectColor: return (intern ("direct-color"));
3097 default:
3098 error ("Display has an unknown visual class");
3100 #endif /* 0 */
3102 return (intern ("true-color"));
3105 DEFUN ("x-display-save-under", Fx_display_save_under,
3106 Sx_display_save_under, 0, 1, 0,
3107 doc: /* Returns t if the display DISPLAY supports the save-under feature.
3108 The optional argument DISPLAY specifies which display to ask about.
3109 DISPLAY should be either a frame or a display name (a string).
3110 If omitted or nil, that stands for the selected frame's display. */)
3111 (display)
3112 Lisp_Object display;
3114 return Qnil;
3118 x_pixel_width (f)
3119 register struct frame *f;
3121 return FRAME_PIXEL_WIDTH (f);
3125 x_pixel_height (f)
3126 register struct frame *f;
3128 return FRAME_PIXEL_HEIGHT (f);
3132 x_char_width (f)
3133 register struct frame *f;
3135 return FRAME_COLUMN_WIDTH (f);
3139 x_char_height (f)
3140 register struct frame *f;
3142 return FRAME_LINE_HEIGHT (f);
3146 x_screen_planes (f)
3147 register struct frame *f;
3149 return FRAME_MAC_DISPLAY_INFO (f)->n_planes;
3152 /* Return the display structure for the display named NAME.
3153 Open a new connection if necessary. */
3155 struct mac_display_info *
3156 x_display_info_for_name (name)
3157 Lisp_Object name;
3159 Lisp_Object names;
3160 struct mac_display_info *dpyinfo;
3162 CHECK_STRING (name);
3164 for (dpyinfo = &one_mac_display_info, names = x_display_name_list;
3165 dpyinfo;
3166 dpyinfo = dpyinfo->next, names = XCDR (names))
3168 Lisp_Object tem;
3169 tem = Fstring_equal (XCAR (XCAR (names)), name);
3170 if (!NILP (tem))
3171 return dpyinfo;
3174 /* Use this general default value to start with. */
3175 Vx_resource_name = Vinvocation_name;
3177 validate_x_resource_name ();
3179 dpyinfo = mac_term_init (name, (unsigned char *) 0,
3180 (char *) SDATA (Vx_resource_name));
3182 if (dpyinfo == 0)
3183 error ("Cannot connect to server %s", SDATA (name));
3185 mac_in_use = 1;
3186 XSETFASTINT (Vwindow_system_version, 3);
3188 return dpyinfo;
3191 #if 0 /* MAC_TODO: implement network support */
3192 DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
3193 1, 3, 0,
3194 doc: /* Open a connection to a server.
3195 DISPLAY is the name of the display to connect to.
3196 Optional second arg XRM-STRING is a string of resources in xrdb format.
3197 If the optional third arg MUST-SUCCEED is non-nil,
3198 terminate Emacs if we can't open the connection. */)
3199 (display, xrm_string, must_succeed)
3200 Lisp_Object display, xrm_string, must_succeed;
3202 unsigned char *xrm_option;
3203 struct mac_display_info *dpyinfo;
3205 CHECK_STRING (display);
3206 if (! NILP (xrm_string))
3207 CHECK_STRING (xrm_string);
3209 if (! EQ (Vwindow_system, intern ("mac")))
3210 error ("Not using Mac OS");
3212 if (! NILP (xrm_string))
3213 xrm_option = (unsigned char *) SDATA (xrm_string);
3214 else
3215 xrm_option = (unsigned char *) 0;
3217 validate_x_resource_name ();
3219 /* This is what opens the connection and sets x_current_display.
3220 This also initializes many symbols, such as those used for input. */
3221 dpyinfo = mac_term_init (display, xrm_option,
3222 (char *) SDATA (Vx_resource_name));
3224 if (dpyinfo == 0)
3226 if (!NILP (must_succeed))
3227 fatal ("Cannot connect to server %s.\n",
3228 SDATA (display));
3229 else
3230 error ("Cannot connect to server %s", SDATA (display));
3233 mac_in_use = 1;
3235 XSETFASTINT (Vwindow_system_version, 3);
3236 return Qnil;
3239 DEFUN ("x-close-connection", Fx_close_connection,
3240 Sx_close_connection, 1, 1, 0,
3241 doc: /* Close the connection to DISPLAY's server.
3242 For DISPLAY, specify either a frame or a display name (a string).
3243 If DISPLAY is nil, that stands for the selected frame's display. */)
3244 (display)
3245 Lisp_Object display;
3247 struct mac_display_info *dpyinfo = check_x_display_info (display);
3248 int i;
3250 if (dpyinfo->reference_count > 0)
3251 error ("Display still has frames on it");
3253 BLOCK_INPUT;
3254 /* Free the fonts in the font table. */
3255 for (i = 0; i < dpyinfo->n_fonts; i++)
3256 if (dpyinfo->font_table[i].name)
3258 if (dpyinfo->font_table[i].name != dpyinfo->font_table[i].full_name)
3259 xfree (dpyinfo->font_table[i].full_name);
3260 xfree (dpyinfo->font_table[i].name);
3261 x_unload_font (dpyinfo, dpyinfo->font_table[i].font);
3263 x_destroy_all_bitmaps (dpyinfo);
3265 x_delete_display (dpyinfo);
3266 UNBLOCK_INPUT;
3268 return Qnil;
3270 #endif /* 0 */
3272 DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
3273 doc: /* Return the list of display names that Emacs has connections to. */)
3276 Lisp_Object tail, result;
3278 result = Qnil;
3279 for (tail = x_display_name_list; ! NILP (tail); tail = XCDR (tail))
3280 result = Fcons (XCAR (XCAR (tail)), result);
3282 return result;
3285 DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0,
3286 doc: /* If ON is non-nil, report errors as soon as the erring request is made.
3287 If ON is nil, allow buffering of requests.
3288 This is a noop on Mac OS systems.
3289 The optional second argument DISPLAY specifies which display to act on.
3290 DISPLAY should be either a frame or a display name (a string).
3291 If DISPLAY is omitted or nil, that stands for the selected frame's display. */)
3292 (on, display)
3293 Lisp_Object display, on;
3295 return Qnil;
3299 /***********************************************************************
3300 Window properties
3301 ***********************************************************************/
3303 DEFUN ("x-change-window-property", Fx_change_window_property,
3304 Sx_change_window_property, 2, 6, 0,
3305 doc: /* Change window property PROP to VALUE on the X window of FRAME.
3306 VALUE may be a string or a list of conses, numbers and/or strings.
3307 If an element in the list is a string, it is converted to
3308 an Atom and the value of the Atom is used. If an element is a cons,
3309 it is converted to a 32 bit number where the car is the 16 top bits and the
3310 cdr is the lower 16 bits.
3311 FRAME nil or omitted means use the selected frame.
3312 If TYPE is given and non-nil, it is the name of the type of VALUE.
3313 If TYPE is not given or nil, the type is STRING.
3314 FORMAT gives the size in bits of each element if VALUE is a list.
3315 It must be one of 8, 16 or 32.
3316 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
3317 If OUTER_P is non-nil, the property is changed for the outer X window of
3318 FRAME. Default is to change on the edit X window.
3320 Value is VALUE. */)
3321 (prop, value, frame, type, format, outer_p)
3322 Lisp_Object prop, value, frame, type, format, outer_p;
3324 #if 0 /* MAC_TODO : port window properties to Mac */
3325 struct frame *f = check_x_frame (frame);
3326 Atom prop_atom;
3328 CHECK_STRING (prop);
3329 CHECK_STRING (value);
3331 BLOCK_INPUT;
3332 prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False);
3333 XChangeProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f),
3334 prop_atom, XA_STRING, 8, PropModeReplace,
3335 SDATA (value), SCHARS (value));
3337 /* Make sure the property is set when we return. */
3338 XFlush (FRAME_W32_DISPLAY (f));
3339 UNBLOCK_INPUT;
3341 #endif /* MAC_TODO */
3343 return value;
3347 DEFUN ("x-delete-window-property", Fx_delete_window_property,
3348 Sx_delete_window_property, 1, 2, 0,
3349 doc: /* Remove window property PROP from X window of FRAME.
3350 FRAME nil or omitted means use the selected frame. Value is PROP. */)
3351 (prop, frame)
3352 Lisp_Object prop, frame;
3354 #if 0 /* MAC_TODO : port window properties to Mac */
3356 struct frame *f = check_x_frame (frame);
3357 Atom prop_atom;
3359 CHECK_STRING (prop);
3360 BLOCK_INPUT;
3361 prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False);
3362 XDeleteProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), prop_atom);
3364 /* Make sure the property is removed when we return. */
3365 XFlush (FRAME_W32_DISPLAY (f));
3366 UNBLOCK_INPUT;
3367 #endif /* MAC_TODO */
3369 return prop;
3373 DEFUN ("x-window-property", Fx_window_property, Sx_window_property,
3374 1, 2, 0,
3375 doc: /* Value is the value of window property PROP on FRAME.
3376 If FRAME is nil or omitted, use the selected frame. Value is nil
3377 if FRAME hasn't a property with name PROP or if PROP has no string
3378 value. */)
3379 (prop, frame)
3380 Lisp_Object prop, frame;
3382 #if 0 /* MAC_TODO : port window properties to Mac */
3384 struct frame *f = check_x_frame (frame);
3385 Atom prop_atom;
3386 int rc;
3387 Lisp_Object prop_value = Qnil;
3388 char *tmp_data = NULL;
3389 Atom actual_type;
3390 int actual_format;
3391 unsigned long actual_size, bytes_remaining;
3393 CHECK_STRING (prop);
3394 BLOCK_INPUT;
3395 prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False);
3396 rc = XGetWindowProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f),
3397 prop_atom, 0, 0, False, XA_STRING,
3398 &actual_type, &actual_format, &actual_size,
3399 &bytes_remaining, (unsigned char **) &tmp_data);
3400 if (rc == Success)
3402 int size = bytes_remaining;
3404 XFree (tmp_data);
3405 tmp_data = NULL;
3407 rc = XGetWindowProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f),
3408 prop_atom, 0, bytes_remaining,
3409 False, XA_STRING,
3410 &actual_type, &actual_format,
3411 &actual_size, &bytes_remaining,
3412 (unsigned char **) &tmp_data);
3413 if (rc == Success)
3414 prop_value = make_string (tmp_data, size);
3416 XFree (tmp_data);
3419 UNBLOCK_INPUT;
3421 return prop_value;
3423 #endif /* MAC_TODO */
3424 return Qnil;
3429 /***********************************************************************
3430 Hourglass cursor
3431 ***********************************************************************/
3433 /* If non-null, an asynchronous timer that, when it expires, displays
3434 an hourglass cursor on all frames. */
3436 static struct atimer *hourglass_atimer;
3438 /* Non-zero means an hourglass cursor is currently shown. */
3440 static int hourglass_shown_p;
3442 /* Number of seconds to wait before displaying an hourglass cursor. */
3444 static Lisp_Object Vhourglass_delay;
3446 /* Default number of seconds to wait before displaying an hourglass
3447 cursor. */
3449 #define DEFAULT_HOURGLASS_DELAY 1
3451 /* Function prototypes. */
3453 static void show_hourglass P_ ((struct atimer *));
3454 static void hide_hourglass P_ ((void));
3457 /* Cancel a currently active hourglass timer, and start a new one. */
3459 void
3460 start_hourglass ()
3462 #if 0 /* MAC_TODO: cursor shape changes. */
3463 EMACS_TIME delay;
3464 int secs, usecs = 0;
3466 cancel_hourglass ();
3468 if (INTEGERP (Vhourglass_delay)
3469 && XINT (Vhourglass_delay) > 0)
3470 secs = XFASTINT (Vhourglass_delay);
3471 else if (FLOATP (Vhourglass_delay)
3472 && XFLOAT_DATA (Vhourglass_delay) > 0)
3474 Lisp_Object tem;
3475 tem = Ftruncate (Vhourglass_delay, Qnil);
3476 secs = XFASTINT (tem);
3477 usecs = (XFLOAT_DATA (Vhourglass_delay) - secs) * 1000000;
3479 else
3480 secs = DEFAULT_HOURGLASS_DELAY;
3482 EMACS_SET_SECS_USECS (delay, secs, usecs);
3483 hourglass_atimer = start_atimer (ATIMER_RELATIVE, delay,
3484 show_hourglass, NULL);
3485 #endif /* MAC_TODO */
3489 /* Cancel the hourglass cursor timer if active, hide an hourglass
3490 cursor if shown. */
3492 void
3493 cancel_hourglass ()
3495 if (hourglass_atimer)
3497 cancel_atimer (hourglass_atimer);
3498 hourglass_atimer = NULL;
3501 if (hourglass_shown_p)
3502 hide_hourglass ();
3506 /* Timer function of hourglass_atimer. TIMER is equal to
3507 hourglass_atimer.
3509 Display an hourglass cursor on all frames by mapping the frames'
3510 hourglass_window. Set the hourglass_p flag in the frames'
3511 output_data.x structure to indicate that an hourglass cursor is
3512 shown on the frames. */
3514 static void
3515 show_hourglass (timer)
3516 struct atimer *timer;
3518 #if 0 /* MAC_TODO: cursor shape changes. */
3519 /* The timer implementation will cancel this timer automatically
3520 after this function has run. Set hourglass_atimer to null
3521 so that we know the timer doesn't have to be canceled. */
3522 hourglass_atimer = NULL;
3524 if (!hourglass_shown_p)
3526 Lisp_Object rest, frame;
3528 BLOCK_INPUT;
3530 FOR_EACH_FRAME (rest, frame)
3531 if (FRAME_W32_P (XFRAME (frame)))
3533 struct frame *f = XFRAME (frame);
3535 f->output_data.w32->hourglass_p = 1;
3537 if (!f->output_data.w32->hourglass_window)
3539 unsigned long mask = CWCursor;
3540 XSetWindowAttributes attrs;
3542 attrs.cursor = f->output_data.w32->hourglass_cursor;
3544 f->output_data.w32->hourglass_window
3545 = XCreateWindow (FRAME_X_DISPLAY (f),
3546 FRAME_OUTER_WINDOW (f),
3547 0, 0, 32000, 32000, 0, 0,
3548 InputOnly,
3549 CopyFromParent,
3550 mask, &attrs);
3553 XMapRaised (FRAME_X_DISPLAY (f),
3554 f->output_data.w32->hourglass_window);
3555 XFlush (FRAME_X_DISPLAY (f));
3558 hourglass_shown_p = 1;
3559 UNBLOCK_INPUT;
3561 #endif /* MAC_TODO */
3565 /* Hide the hourglass cursor on all frames, if it is currently shown. */
3567 static void
3568 hide_hourglass ()
3570 #if 0 /* MAC_TODO: cursor shape changes. */
3571 if (hourglass_shown_p)
3573 Lisp_Object rest, frame;
3575 BLOCK_INPUT;
3576 FOR_EACH_FRAME (rest, frame)
3578 struct frame *f = XFRAME (frame);
3580 if (FRAME_W32_P (f)
3581 /* Watch out for newly created frames. */
3582 && f->output_data.x->hourglass_window)
3584 XUnmapWindow (FRAME_X_DISPLAY (f),
3585 f->output_data.x->hourglass_window);
3586 /* Sync here because XTread_socket looks at the
3587 hourglass_p flag that is reset to zero below. */
3588 XSync (FRAME_X_DISPLAY (f), False);
3589 f->output_data.x->hourglass_p = 0;
3593 hourglass_shown_p = 0;
3594 UNBLOCK_INPUT;
3596 #endif /* MAC_TODO */
3601 /***********************************************************************
3602 Tool tips
3603 ***********************************************************************/
3605 static Lisp_Object x_create_tip_frame P_ ((struct mac_display_info *,
3606 Lisp_Object, Lisp_Object));
3607 static void compute_tip_xy P_ ((struct frame *, Lisp_Object, Lisp_Object,
3608 Lisp_Object, int, int, int *, int *));
3610 /* The frame of a currently visible tooltip. */
3612 Lisp_Object tip_frame;
3614 /* If non-nil, a timer started that hides the last tooltip when it
3615 fires. */
3617 Lisp_Object tip_timer;
3618 Window tip_window;
3620 /* If non-nil, a vector of 3 elements containing the last args
3621 with which x-show-tip was called. See there. */
3623 Lisp_Object last_show_tip_args;
3625 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
3627 Lisp_Object Vx_max_tooltip_size;
3630 static Lisp_Object
3631 unwind_create_tip_frame (frame)
3632 Lisp_Object frame;
3634 Lisp_Object deleted;
3636 deleted = unwind_create_frame (frame);
3637 if (EQ (deleted, Qt))
3639 tip_window = NULL;
3640 tip_frame = Qnil;
3643 return deleted;
3647 /* Create a frame for a tooltip on the display described by DPYINFO.
3648 PARMS is a list of frame parameters. TEXT is the string to
3649 display in the tip frame. Value is the frame.
3651 Note that functions called here, esp. x_default_parameter can
3652 signal errors, for instance when a specified color name is
3653 undefined. We have to make sure that we're in a consistent state
3654 when this happens. */
3656 static Lisp_Object
3657 x_create_tip_frame (dpyinfo, parms, text)
3658 struct mac_display_info *dpyinfo;
3659 Lisp_Object parms, text;
3661 struct frame *f;
3662 Lisp_Object frame, tem;
3663 Lisp_Object name;
3664 long window_prompting = 0;
3665 int width, height;
3666 int count = SPECPDL_INDEX ();
3667 struct gcpro gcpro1, gcpro2, gcpro3;
3668 struct kboard *kb;
3669 int face_change_count_before = face_change_count;
3670 Lisp_Object buffer;
3671 struct buffer *old_buffer;
3673 check_mac ();
3675 /* Use this general default value to start with until we know if
3676 this frame has a specified name. */
3677 Vx_resource_name = Vinvocation_name;
3679 #ifdef MULTI_KBOARD
3680 kb = dpyinfo->kboard;
3681 #else
3682 kb = &the_only_kboard;
3683 #endif
3685 /* Get the name of the frame to use for resource lookup. */
3686 name = mac_get_arg (parms, Qname, "name", "Name", RES_TYPE_STRING);
3687 if (!STRINGP (name)
3688 && !EQ (name, Qunbound)
3689 && !NILP (name))
3690 error ("Invalid frame name--not a string or nil");
3691 Vx_resource_name = name;
3693 frame = Qnil;
3694 GCPRO3 (parms, name, frame);
3695 f = make_frame (1);
3696 XSETFRAME (frame, f);
3698 buffer = Fget_buffer_create (build_string (" *tip*"));
3699 Fset_window_buffer (FRAME_ROOT_WINDOW (f), buffer, Qnil);
3700 old_buffer = current_buffer;
3701 set_buffer_internal_1 (XBUFFER (buffer));
3702 current_buffer->truncate_lines = Qnil;
3703 specbind (Qinhibit_read_only, Qt);
3704 specbind (Qinhibit_modification_hooks, Qt);
3705 Ferase_buffer ();
3706 Finsert (1, &text);
3707 set_buffer_internal_1 (old_buffer);
3709 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
3710 record_unwind_protect (unwind_create_tip_frame, frame);
3712 /* By setting the output method, we're essentially saying that
3713 the frame is live, as per FRAME_LIVE_P. If we get a signal
3714 from this point on, x_destroy_window might screw up reference
3715 counts etc. */
3716 f->output_method = output_mac;
3717 f->output_data.mac =
3718 (struct mac_output *) xmalloc (sizeof (struct mac_output));
3719 bzero (f->output_data.mac, sizeof (struct mac_output));
3721 FRAME_FONTSET (f) = -1;
3722 f->icon_name = Qnil;
3724 #if 0 /* GLYPH_DEBUG TODO: image support. */
3725 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
3726 dpyinfo_refcount = dpyinfo->reference_count;
3727 #endif /* GLYPH_DEBUG */
3728 #ifdef MULTI_KBOARD
3729 FRAME_KBOARD (f) = kb;
3730 #endif
3731 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window;
3732 f->output_data.mac->explicit_parent = 0;
3734 /* Set the name; the functions to which we pass f expect the name to
3735 be set. */
3736 if (EQ (name, Qunbound) || NILP (name))
3738 f->name = build_string (dpyinfo->mac_id_name);
3739 f->explicit_name = 0;
3741 else
3743 f->name = name;
3744 f->explicit_name = 1;
3745 /* use the frame's title when getting resources for this frame. */
3746 specbind (Qx_resource_name, name);
3749 /* Extract the window parameters from the supplied values that are
3750 needed to determine window geometry. */
3752 Lisp_Object font;
3754 font = mac_get_arg (parms, Qfont, "font", "Font", RES_TYPE_STRING);
3756 BLOCK_INPUT;
3757 /* First, try whatever font the caller has specified. */
3758 if (STRINGP (font))
3760 tem = Fquery_fontset (font, Qnil);
3761 if (STRINGP (tem))
3762 font = x_new_fontset (f, SDATA (tem));
3763 else
3764 font = x_new_font (f, SDATA (font));
3767 /* Try out a font which we hope has bold and italic variations. */
3768 if (! STRINGP (font))
3769 font = x_new_font (f, "-ETL-fixed-medium-r-*--*-160-*-*-*-*-iso8859-1");
3770 /* If those didn't work, look for something which will at least work. */
3771 if (! STRINGP (font))
3772 font = x_new_font (f, "-*-monaco-*-12-*-mac-roman");
3773 if (! STRINGP (font))
3774 font = x_new_font (f, "-*-courier-*-10-*-mac-roman");
3775 UNBLOCK_INPUT;
3776 if (! STRINGP (font))
3777 error ("Cannot find any usable font");
3779 x_default_parameter (f, parms, Qfont, font,
3780 "font", "Font", RES_TYPE_STRING);
3783 x_default_parameter (f, parms, Qborder_width, make_number (2),
3784 "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
3786 /* This defaults to 2 in order to match xterm. We recognize either
3787 internalBorderWidth or internalBorder (which is what xterm calls
3788 it). */
3789 if (NILP (Fassq (Qinternal_border_width, parms)))
3791 Lisp_Object value;
3793 value = mac_get_arg (parms, Qinternal_border_width,
3794 "internalBorder", "internalBorder", RES_TYPE_NUMBER);
3795 if (! EQ (value, Qunbound))
3796 parms = Fcons (Fcons (Qinternal_border_width, value),
3797 parms);
3800 x_default_parameter (f, parms, Qinternal_border_width, make_number (1),
3801 "internalBorderWidth", "internalBorderWidth",
3802 RES_TYPE_NUMBER);
3804 /* Also do the stuff which must be set before the window exists. */
3805 x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
3806 "foreground", "Foreground", RES_TYPE_STRING);
3807 x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
3808 "background", "Background", RES_TYPE_STRING);
3809 x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
3810 "pointerColor", "Foreground", RES_TYPE_STRING);
3811 x_default_parameter (f, parms, Qcursor_color, build_string ("black"),
3812 "cursorColor", "Foreground", RES_TYPE_STRING);
3813 x_default_parameter (f, parms, Qborder_color, build_string ("black"),
3814 "borderColor", "BorderColor", RES_TYPE_STRING);
3816 /* Init faces before x_default_parameter is called for scroll-bar
3817 parameters because that function calls x_set_scroll_bar_width,
3818 which calls change_frame_size, which calls Fset_window_buffer,
3819 which runs hooks, which call Fvertical_motion. At the end, we
3820 end up in init_iterator with a null face cache, which should not
3821 happen. */
3822 init_frame_faces (f);
3824 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window;
3826 window_prompting = x_figure_window_size (f, parms, 0);
3829 Rect r;
3831 BLOCK_INPUT;
3832 SetRect (&r, 0, 0, 1, 1);
3833 if (CreateNewWindow (kHelpWindowClass,
3834 #ifdef MAC_OS_X_VERSION_10_2
3835 kWindowIgnoreClicksAttribute |
3836 #endif
3837 kWindowNoActivatesAttribute,
3838 &r, &tip_window) == noErr)
3840 FRAME_MAC_WINDOW (f) = tip_window;
3841 SetWRefCon (tip_window, (long) f->output_data.mac);
3842 /* so that update events can find this mac_output struct */
3843 f->output_data.mac->mFP = f;
3844 ShowWindow (tip_window);
3846 UNBLOCK_INPUT;
3849 x_make_gc (f);
3851 x_default_parameter (f, parms, Qauto_raise, Qnil,
3852 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
3853 x_default_parameter (f, parms, Qauto_lower, Qnil,
3854 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
3855 x_default_parameter (f, parms, Qcursor_type, Qbox,
3856 "cursorType", "CursorType", RES_TYPE_SYMBOL);
3858 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3859 Change will not be effected unless different from the current
3860 FRAME_LINES (f). */
3861 width = FRAME_COLS (f);
3862 height = FRAME_LINES (f);
3863 SET_FRAME_COLS (f, 0);
3864 FRAME_LINES (f) = 0;
3865 change_frame_size (f, height, width, 1, 0, 0);
3867 /* Add `tooltip' frame parameter's default value. */
3868 if (NILP (Fframe_parameter (frame, intern ("tooltip"))))
3869 Fmodify_frame_parameters (frame, Fcons (Fcons (intern ("tooltip"), Qt),
3870 Qnil));
3872 /* Set up faces after all frame parameters are known. This call
3873 also merges in face attributes specified for new frames.
3875 Frame parameters may be changed if .Xdefaults contains
3876 specifications for the default font. For example, if there is an
3877 `Emacs.default.attributeBackground: pink', the `background-color'
3878 attribute of the frame get's set, which let's the internal border
3879 of the tooltip frame appear in pink. Prevent this. */
3881 Lisp_Object bg = Fframe_parameter (frame, Qbackground_color);
3883 /* Set tip_frame here, so that */
3884 tip_frame = frame;
3885 call1 (Qface_set_after_frame_default, frame);
3887 if (!EQ (bg, Fframe_parameter (frame, Qbackground_color)))
3888 Fmodify_frame_parameters (frame, Fcons (Fcons (Qbackground_color, bg),
3889 Qnil));
3892 f->no_split = 1;
3894 UNGCPRO;
3896 /* It is now ok to make the frame official even if we get an error
3897 below. And the frame needs to be on Vframe_list or making it
3898 visible won't work. */
3899 Vframe_list = Fcons (frame, Vframe_list);
3901 /* Now that the frame is official, it counts as a reference to
3902 its display. */
3903 FRAME_MAC_DISPLAY_INFO (f)->reference_count++;
3905 /* Setting attributes of faces of the tooltip frame from resources
3906 and similar will increment face_change_count, which leads to the
3907 clearing of all current matrices. Since this isn't necessary
3908 here, avoid it by resetting face_change_count to the value it
3909 had before we created the tip frame. */
3910 face_change_count = face_change_count_before;
3912 /* Discard the unwind_protect. */
3913 return unbind_to (count, frame);
3917 /* Compute where to display tip frame F. PARMS is the list of frame
3918 parameters for F. DX and DY are specified offsets from the current
3919 location of the mouse. WIDTH and HEIGHT are the width and height
3920 of the tooltip. Return coordinates relative to the root window of
3921 the display in *ROOT_X, and *ROOT_Y. */
3923 static void
3924 compute_tip_xy (f, parms, dx, dy, width, height, root_x, root_y)
3925 struct frame *f;
3926 Lisp_Object parms, dx, dy;
3927 int width, height;
3928 int *root_x, *root_y;
3930 Lisp_Object left, top;
3932 /* User-specified position? */
3933 left = Fcdr (Fassq (Qleft, parms));
3934 top = Fcdr (Fassq (Qtop, parms));
3936 /* Move the tooltip window where the mouse pointer is. Resize and
3937 show it. */
3938 if (!INTEGERP (left) || !INTEGERP (top))
3940 Point mouse_pos;
3942 BLOCK_INPUT;
3943 GetMouse (&mouse_pos);
3944 LocalToGlobal (&mouse_pos);
3945 *root_x = mouse_pos.h;
3946 *root_y = mouse_pos.v;
3947 UNBLOCK_INPUT;
3950 if (INTEGERP (top))
3951 *root_y = XINT (top);
3952 else if (*root_y + XINT (dy) - height < 0)
3953 *root_y -= XINT (dy);
3954 else
3956 *root_y -= height;
3957 *root_y += XINT (dy);
3960 if (INTEGERP (left))
3961 *root_x = XINT (left);
3962 else if (*root_x + XINT (dx) + width <= FRAME_MAC_DISPLAY_INFO (f)->width)
3963 /* It fits to the right of the pointer. */
3964 *root_x += XINT (dx);
3965 else if (width + XINT (dx) <= *root_x)
3966 /* It fits to the left of the pointer. */
3967 *root_x -= width + XINT (dx);
3968 else
3969 /* Put it left-justified on the screen -- it ought to fit that way. */
3970 *root_x = 0;
3974 DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
3975 doc: /* Show STRING in a "tooltip" window on frame FRAME.
3976 A tooltip window is a small X window displaying a string.
3978 FRAME nil or omitted means use the selected frame.
3980 PARMS is an optional list of frame parameters which can be used to
3981 change the tooltip's appearance.
3983 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
3984 means use the default timeout of 5 seconds.
3986 If the list of frame parameters PARAMS contains a `left' parameters,
3987 the tooltip is displayed at that x-position. Otherwise it is
3988 displayed at the mouse position, with offset DX added (default is 5 if
3989 DX isn't specified). Likewise for the y-position; if a `top' frame
3990 parameter is specified, it determines the y-position of the tooltip
3991 window, otherwise it is displayed at the mouse position, with offset
3992 DY added (default is -10).
3994 A tooltip's maximum size is specified by `x-max-tooltip-size'.
3995 Text larger than the specified size is clipped. */)
3996 (string, frame, parms, timeout, dx, dy)
3997 Lisp_Object string, frame, parms, timeout, dx, dy;
3999 struct frame *f;
4000 struct window *w;
4001 int root_x, root_y;
4002 struct buffer *old_buffer;
4003 struct text_pos pos;
4004 int i, width, height;
4005 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
4006 int old_windows_or_buffers_changed = windows_or_buffers_changed;
4007 int count = SPECPDL_INDEX ();
4009 specbind (Qinhibit_redisplay, Qt);
4011 GCPRO4 (string, parms, frame, timeout);
4013 CHECK_STRING (string);
4014 f = check_x_frame (frame);
4015 if (NILP (timeout))
4016 timeout = make_number (5);
4017 else
4018 CHECK_NATNUM (timeout);
4020 if (NILP (dx))
4021 dx = make_number (5);
4022 else
4023 CHECK_NUMBER (dx);
4025 if (NILP (dy))
4026 dy = make_number (-10);
4027 else
4028 CHECK_NUMBER (dy);
4030 if (NILP (last_show_tip_args))
4031 last_show_tip_args = Fmake_vector (make_number (3), Qnil);
4033 if (!NILP (tip_frame))
4035 Lisp_Object last_string = AREF (last_show_tip_args, 0);
4036 Lisp_Object last_frame = AREF (last_show_tip_args, 1);
4037 Lisp_Object last_parms = AREF (last_show_tip_args, 2);
4039 if (EQ (frame, last_frame)
4040 && !NILP (Fequal (last_string, string))
4041 && !NILP (Fequal (last_parms, parms)))
4043 struct frame *f = XFRAME (tip_frame);
4045 /* Only DX and DY have changed. */
4046 if (!NILP (tip_timer))
4048 Lisp_Object timer = tip_timer;
4049 tip_timer = Qnil;
4050 call1 (Qcancel_timer, timer);
4053 BLOCK_INPUT;
4054 compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f),
4055 FRAME_PIXEL_HEIGHT (f), &root_x, &root_y);
4056 MoveWindow (FRAME_MAC_WINDOW (f), root_x, root_y, false);
4057 UNBLOCK_INPUT;
4058 goto start_timer;
4062 /* Hide a previous tip, if any. */
4063 Fx_hide_tip ();
4065 ASET (last_show_tip_args, 0, string);
4066 ASET (last_show_tip_args, 1, frame);
4067 ASET (last_show_tip_args, 2, parms);
4069 /* Add default values to frame parameters. */
4070 if (NILP (Fassq (Qname, parms)))
4071 parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms);
4072 if (NILP (Fassq (Qinternal_border_width, parms)))
4073 parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms);
4074 if (NILP (Fassq (Qborder_width, parms)))
4075 parms = Fcons (Fcons (Qborder_width, make_number (1)), parms);
4076 if (NILP (Fassq (Qborder_color, parms)))
4077 parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms);
4078 if (NILP (Fassq (Qbackground_color, parms)))
4079 parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")),
4080 parms);
4082 /* Create a frame for the tooltip, and record it in the global
4083 variable tip_frame. */
4084 frame = x_create_tip_frame (FRAME_MAC_DISPLAY_INFO (f), parms, string);
4085 f = XFRAME (frame);
4087 /* Set up the frame's root window. */
4088 w = XWINDOW (FRAME_ROOT_WINDOW (f));
4089 w->left_col = w->top_line = make_number (0);
4091 if (CONSP (Vx_max_tooltip_size)
4092 && INTEGERP (XCAR (Vx_max_tooltip_size))
4093 && XINT (XCAR (Vx_max_tooltip_size)) > 0
4094 && INTEGERP (XCDR (Vx_max_tooltip_size))
4095 && XINT (XCDR (Vx_max_tooltip_size)) > 0)
4097 w->total_cols = XCAR (Vx_max_tooltip_size);
4098 w->total_lines = XCDR (Vx_max_tooltip_size);
4100 else
4102 w->total_cols = make_number (80);
4103 w->total_lines = make_number (40);
4106 FRAME_TOTAL_COLS (f) = XINT (w->total_cols);
4107 adjust_glyphs (f);
4108 w->pseudo_window_p = 1;
4110 /* Display the tooltip text in a temporary buffer. */
4111 old_buffer = current_buffer;
4112 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->buffer));
4113 current_buffer->truncate_lines = Qnil;
4114 clear_glyph_matrix (w->desired_matrix);
4115 clear_glyph_matrix (w->current_matrix);
4116 SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
4117 try_window (FRAME_ROOT_WINDOW (f), pos);
4119 /* Compute width and height of the tooltip. */
4120 width = height = 0;
4121 for (i = 0; i < w->desired_matrix->nrows; ++i)
4123 struct glyph_row *row = &w->desired_matrix->rows[i];
4124 struct glyph *last;
4125 int row_width;
4127 /* Stop at the first empty row at the end. */
4128 if (!row->enabled_p || !row->displays_text_p)
4129 break;
4131 /* Let the row go over the full width of the frame. */
4132 row->full_width_p = 1;
4134 /* There's a glyph at the end of rows that is used to place
4135 the cursor there. Don't include the width of this glyph. */
4136 if (row->used[TEXT_AREA])
4138 last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1];
4139 row_width = row->pixel_width - last->pixel_width;
4141 else
4142 row_width = row->pixel_width;
4144 height += row->height;
4145 width = max (width, row_width);
4148 /* Add the frame's internal border to the width and height the X
4149 window should have. */
4150 height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
4151 width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
4153 /* Move the tooltip window where the mouse pointer is. Resize and
4154 show it. */
4155 compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
4157 BLOCK_INPUT;
4158 MoveWindow (FRAME_MAC_WINDOW (f), root_x, root_y, false);
4159 SizeWindow (FRAME_MAC_WINDOW (f), width, height, true);
4160 BringToFront (FRAME_MAC_WINDOW (f));
4161 UNBLOCK_INPUT;
4163 /* Draw into the window. */
4164 w->must_be_updated_p = 1;
4165 update_single_window (w, 1);
4167 /* Restore original current buffer. */
4168 set_buffer_internal_1 (old_buffer);
4169 windows_or_buffers_changed = old_windows_or_buffers_changed;
4171 start_timer:
4172 /* Let the tip disappear after timeout seconds. */
4173 tip_timer = call3 (intern ("run-at-time"), timeout, Qnil,
4174 intern ("x-hide-tip"));
4176 UNGCPRO;
4177 return unbind_to (count, Qnil);
4181 DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
4182 doc: /* Hide the current tooltip window, if there is any.
4183 Value is t if tooltip was open, nil otherwise. */)
4186 int count;
4187 Lisp_Object deleted, frame, timer;
4188 struct gcpro gcpro1, gcpro2;
4190 /* Return quickly if nothing to do. */
4191 if (NILP (tip_timer) && NILP (tip_frame))
4192 return Qnil;
4194 frame = tip_frame;
4195 timer = tip_timer;
4196 GCPRO2 (frame, timer);
4197 tip_frame = tip_timer = deleted = Qnil;
4199 count = SPECPDL_INDEX ();
4200 specbind (Qinhibit_redisplay, Qt);
4201 specbind (Qinhibit_quit, Qt);
4203 if (!NILP (timer))
4204 call1 (Qcancel_timer, timer);
4206 if (FRAMEP (frame))
4208 Fdelete_frame (frame, Qnil);
4209 deleted = Qt;
4212 UNGCPRO;
4213 return unbind_to (count, deleted);
4218 #ifdef TARGET_API_MAC_CARBON
4219 /***********************************************************************
4220 File selection dialog
4221 ***********************************************************************/
4224 There is a relatively standard way to do this using applescript to run
4225 a (choose file) method. However, this doesn't do "the right thing"
4226 by working only if the find-file occurred during a menu or toolbar
4227 click. So we must do the file dialog by hand, using the navigation
4228 manager. This also has more flexibility in determining the default
4229 directory and whether or not we are going to choose a file.
4232 extern Lisp_Object Qfile_name_history;
4234 DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 4, 0,
4235 doc: /* Read file name, prompting with PROMPT in directory DIR.
4236 Use a file selection dialog.
4237 Select DEFAULT-FILENAME in the dialog's file selection box, if
4238 specified. Ensure that file exists if MUSTMATCH is non-nil. */)
4239 (prompt, dir, default_filename, mustmatch)
4240 Lisp_Object prompt, dir, default_filename, mustmatch;
4242 struct frame *f = SELECTED_FRAME ();
4243 Lisp_Object file = Qnil;
4244 int count = SPECPDL_INDEX ();
4245 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
4246 char filename[1001];
4247 int default_filter_index = 1; /* 1: All Files, 2: Directories only */
4249 GCPRO5 (prompt, dir, default_filename, mustmatch, file);
4250 CHECK_STRING (prompt);
4251 CHECK_STRING (dir);
4253 /* Create the dialog with PROMPT as title, using DIR as initial
4254 directory and using "*" as pattern. */
4255 dir = Fexpand_file_name (dir, Qnil);
4258 OSStatus status;
4259 NavDialogCreationOptions options;
4260 NavDialogRef dialogRef;
4261 NavTypeListHandle fileTypes = NULL;
4262 NavUserAction userAction;
4263 CFStringRef message=NULL, client=NULL, saveName = NULL;
4265 /* No need for a callback function because we are modal */
4266 NavGetDefaultDialogCreationOptions(&options);
4267 options.modality = kWindowModalityAppModal;
4268 options.location.h = options.location.v = -1;
4269 options.optionFlags = kNavDefaultNavDlogOptions;
4270 options.optionFlags |= kNavAllFilesInPopup; /* All files allowed */
4271 options.optionFlags |= kNavSelectAllReadableItem;
4272 if (!NILP(prompt))
4274 message = CFStringCreateWithCStringNoCopy(NULL, SDATA(prompt),
4275 kCFStringEncodingUTF8,
4276 kCFAllocatorNull);
4277 options.message = message;
4279 /* Don't set the application, let it use default.
4280 client = CFStringCreateWithCStringNoCopy(NULL, "Emacs",
4281 kCFStringEncodingMacRoman, NULL);
4282 options.clientName = client;
4285 /* Do Dired hack copied from w32fns.c */
4286 if (!NILP(prompt) && strncmp (SDATA(prompt), "Dired", 5) == 0)
4287 status = NavCreateChooseFolderDialog(&options, NULL, NULL, NULL,
4288 &dialogRef);
4289 else if (NILP (mustmatch))
4291 /* This is a save dialog */
4292 if (!NILP(default_filename))
4294 saveName = CFStringCreateWithCString(NULL, SDATA(default_filename),
4295 kCFStringEncodingUTF8);
4296 options.saveFileName = saveName;
4297 options.optionFlags |= kNavSelectDefaultLocation;
4299 /* MAC_TODO: Find a better way to determine if this is a save
4300 or load dialog than comparing dir with default_filename */
4301 if (EQ(dir, default_filename))
4303 status = NavCreateChooseFileDialog(&options, fileTypes,
4304 NULL, NULL, NULL, NULL,
4305 &dialogRef);
4307 else {
4308 status = NavCreatePutFileDialog(&options,
4309 'TEXT', kNavGenericSignature,
4310 NULL, NULL, &dialogRef);
4313 else
4315 /* This is an open dialog*/
4316 status = NavCreateChooseFileDialog(&options, fileTypes,
4317 NULL, NULL, NULL, NULL,
4318 &dialogRef);
4321 /* Set the default location and continue*/
4322 if (status == noErr) {
4323 if (!NILP(dir)) {
4324 FSRef defLoc;
4325 AEDesc defLocAed;
4326 status = FSPathMakeRef(SDATA(dir), &defLoc, NULL);
4327 if (status == noErr)
4329 AECreateDesc(typeFSRef, &defLoc, sizeof(FSRef), &defLocAed);
4330 NavCustomControl(dialogRef, kNavCtlSetLocation, (void*) &defLocAed);
4332 AEDisposeDesc(&defLocAed);
4335 BLOCK_INPUT;
4336 status = NavDialogRun(dialogRef);
4337 UNBLOCK_INPUT;
4340 if (saveName) CFRelease(saveName);
4341 if (client) CFRelease(client);
4342 if (message) CFRelease(message);
4344 if (status == noErr) {
4345 userAction = NavDialogGetUserAction(dialogRef);
4346 switch (userAction)
4348 case kNavUserActionNone:
4349 case kNavUserActionCancel:
4350 NavDialogDispose(dialogRef);
4351 Fsignal (Qquit, Qnil); /* Treat cancel like C-g */
4352 return;
4353 case kNavUserActionOpen:
4354 case kNavUserActionChoose:
4355 case kNavUserActionSaveAs:
4357 NavReplyRecord reply;
4358 AEDesc aed;
4359 FSRef fsRef;
4360 status = NavDialogGetReply(dialogRef, &reply);
4361 AECoerceDesc(&reply.selection, typeFSRef, &aed);
4362 AEGetDescData(&aed, (void *) &fsRef, sizeof (FSRef));
4363 FSRefMakePath(&fsRef, (UInt8 *) filename, 1000);
4364 AEDisposeDesc(&aed);
4365 if (reply.saveFileName)
4367 /* If it was a saved file, we need to add the file name */
4368 int len = strlen(filename);
4369 if (len && filename[len-1] != '/')
4370 filename[len++] = '/';
4371 CFStringGetCString(reply.saveFileName, filename+len,
4372 1000-len, kCFStringEncodingUTF8);
4374 file = DECODE_FILE(build_string (filename));
4375 NavDisposeReply(&reply);
4377 break;
4379 NavDialogDispose(dialogRef);
4381 else {
4382 /* Fall back on minibuffer if there was a problem */
4383 file = Fcompleting_read (prompt, intern ("read-file-name-internal"),
4384 dir, mustmatch, dir, Qfile_name_history,
4385 default_filename, Qnil);
4389 UNGCPRO;
4391 /* Make "Cancel" equivalent to C-g. */
4392 if (NILP (file))
4393 Fsignal (Qquit, Qnil);
4395 return unbind_to (count, file);
4399 #endif
4401 /***********************************************************************
4402 Initialization
4403 ***********************************************************************/
4405 /* Keep this list in the same order as frame_parms in frame.c.
4406 Use 0 for unsupported frame parameters. */
4408 frame_parm_handler mac_frame_parm_handlers[] =
4410 x_set_autoraise,
4411 x_set_autolower,
4412 x_set_background_color,
4413 x_set_border_color,
4414 x_set_border_width,
4415 x_set_cursor_color,
4416 x_set_cursor_type,
4417 x_set_font,
4418 x_set_foreground_color,
4419 x_set_icon_name,
4420 0, /* MAC_TODO: x_set_icon_type, */
4421 x_set_internal_border_width,
4422 x_set_menu_bar_lines,
4423 x_set_mouse_color,
4424 x_explicitly_set_name,
4425 x_set_scroll_bar_width,
4426 x_set_title,
4427 x_set_unsplittable,
4428 x_set_vertical_scroll_bars,
4429 x_set_visibility,
4430 x_set_tool_bar_lines,
4431 0, /* MAC_TODO: x_set_scroll_bar_foreground, */
4432 0, /* MAC_TODO: x_set_scroll_bar_background, */
4433 x_set_screen_gamma,
4434 x_set_line_spacing,
4435 0, /* MAC_TODO: x_set_fringe_width, */
4436 0, /* MAC_TODO: x_set_fringe_width, */
4437 0, /* x_set_wait_for_wm, */
4438 0, /* MAC_TODO: x_set_fullscreen, */
4441 void
4442 syms_of_macfns ()
4444 /* Certainly running on Mac. */
4445 mac_in_use = 1;
4447 /* The section below is built by the lisp expression at the top of the file,
4448 just above where these variables are declared. */
4449 /*&&& init symbols here &&&*/
4450 Qnone = intern ("none");
4451 staticpro (&Qnone);
4452 Qsuppress_icon = intern ("suppress-icon");
4453 staticpro (&Qsuppress_icon);
4454 Qundefined_color = intern ("undefined-color");
4455 staticpro (&Qundefined_color);
4456 Qcancel_timer = intern ("cancel-timer");
4457 staticpro (&Qcancel_timer);
4459 Qhyper = intern ("hyper");
4460 staticpro (&Qhyper);
4461 Qsuper = intern ("super");
4462 staticpro (&Qsuper);
4463 Qmeta = intern ("meta");
4464 staticpro (&Qmeta);
4465 Qalt = intern ("alt");
4466 staticpro (&Qalt);
4467 Qctrl = intern ("ctrl");
4468 staticpro (&Qctrl);
4469 Qcontrol = intern ("control");
4470 staticpro (&Qcontrol);
4471 Qshift = intern ("shift");
4472 staticpro (&Qshift);
4473 /* This is the end of symbol initialization. */
4475 /* Text property `display' should be nonsticky by default. */
4476 Vtext_property_default_nonsticky
4477 = Fcons (Fcons (Qdisplay, Qt), Vtext_property_default_nonsticky);
4479 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4480 staticpro (&Qface_set_after_frame_default);
4482 Fput (Qundefined_color, Qerror_conditions,
4483 Fcons (Qundefined_color, Fcons (Qerror, Qnil)));
4484 Fput (Qundefined_color, Qerror_message,
4485 build_string ("Undefined color"));
4487 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape,
4488 doc: /* The shape of the pointer when over text.
4489 Changing the value does not affect existing frames
4490 unless you set the mouse color. */);
4491 Vx_pointer_shape = Qnil;
4493 Vx_nontext_pointer_shape = Qnil;
4495 Vx_mode_pointer_shape = Qnil;
4497 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape,
4498 doc: /* The shape of the pointer when Emacs is hourglass.
4499 This variable takes effect when you create a new frame
4500 or when you set the mouse color. */);
4501 Vx_hourglass_pointer_shape = Qnil;
4503 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p,
4504 doc: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
4505 display_hourglass_p = 1;
4507 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay,
4508 doc: /* *Seconds to wait before displaying an hourglass pointer.
4509 Value must be an integer or float. */);
4510 Vhourglass_delay = make_number (DEFAULT_HOURGLASS_DELAY);
4512 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
4513 &Vx_sensitive_text_pointer_shape,
4514 doc: /* The shape of the pointer when over mouse-sensitive text.
4515 This variable takes effect when you create a new frame
4516 or when you set the mouse color. */);
4517 Vx_sensitive_text_pointer_shape = Qnil;
4519 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel,
4520 doc: /* A string indicating the foreground color of the cursor box. */);
4521 Vx_cursor_fore_pixel = Qnil;
4523 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size,
4524 doc: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
4525 Text larger than this is clipped. */);
4526 Vx_max_tooltip_size = Fcons (make_number (80), make_number (40));
4528 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager,
4529 doc: /* Non-nil if no window manager is in use.
4530 Emacs doesn't try to figure this out; this is always nil
4531 unless you set it to something else. */);
4532 /* We don't have any way to find this out, so set it to nil
4533 and maybe the user would like to set it to t. */
4534 Vx_no_window_manager = Qnil;
4536 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
4537 &Vx_pixel_size_width_font_regexp,
4538 doc: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
4540 Since Emacs gets width of a font matching with this regexp from
4541 PIXEL_SIZE field of the name, font finding mechanism gets faster for
4542 such a font. This is especially effective for such large fonts as
4543 Chinese, Japanese, and Korean. */);
4544 Vx_pixel_size_width_font_regexp = Qnil;
4546 /* X window properties. */
4547 defsubr (&Sx_change_window_property);
4548 defsubr (&Sx_delete_window_property);
4549 defsubr (&Sx_window_property);
4551 defsubr (&Sxw_display_color_p);
4552 defsubr (&Sx_display_grayscale_p);
4553 defsubr (&Sxw_color_defined_p);
4554 defsubr (&Sxw_color_values);
4555 defsubr (&Sx_server_max_request_size);
4556 defsubr (&Sx_server_vendor);
4557 defsubr (&Sx_server_version);
4558 defsubr (&Sx_display_pixel_width);
4559 defsubr (&Sx_display_pixel_height);
4560 defsubr (&Sx_display_mm_width);
4561 defsubr (&Sx_display_mm_height);
4562 defsubr (&Sx_display_screens);
4563 defsubr (&Sx_display_planes);
4564 defsubr (&Sx_display_color_cells);
4565 defsubr (&Sx_display_visual_class);
4566 defsubr (&Sx_display_backing_store);
4567 defsubr (&Sx_display_save_under);
4568 defsubr (&Sx_create_frame);
4569 #if 0 /* MAC_TODO: implement network support */
4570 defsubr (&Sx_open_connection);
4571 defsubr (&Sx_close_connection);
4572 #endif
4573 defsubr (&Sx_display_list);
4574 defsubr (&Sx_synchronize);
4576 /* Setting callback functions for fontset handler. */
4577 get_font_info_func = x_get_font_info;
4579 #if 0 /* This function pointer doesn't seem to be used anywhere.
4580 And the pointer assigned has the wrong type, anyway. */
4581 list_fonts_func = x_list_fonts;
4582 #endif
4584 load_font_func = x_load_font;
4585 find_ccl_program_func = x_find_ccl_program;
4586 query_font_func = x_query_font;
4587 set_frame_fontset_func = x_set_font;
4588 check_window_system_func = check_mac;
4590 hourglass_atimer = NULL;
4591 hourglass_shown_p = 0;
4593 defsubr (&Sx_show_tip);
4594 defsubr (&Sx_hide_tip);
4595 tip_timer = Qnil;
4596 staticpro (&tip_timer);
4597 tip_frame = Qnil;
4598 staticpro (&tip_frame);
4600 last_show_tip_args = Qnil;
4601 staticpro (&last_show_tip_args);
4603 #if TARGET_API_MAC_CARBON
4604 defsubr (&Sx_file_dialog);
4605 #endif
4608 /* arch-tag: d7591289-f374-4377-b245-12f5dbbb8edc
4609 (do not change this comment) */