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