build-aux/msys-to-w32: Fix a typo in a comment.
[bpt/emacs.git] / src / nsfns.m
CommitLineData
edfda783 1/* Functions for the NeXT/Open/GNUstep and MacOSX window system.
e9bffc61 2
ab422c4d
PE
3Copyright (C) 1989, 1992-1994, 2005-2006, 2008-2013 Free Software
4Foundation, Inc.
edfda783
AR
5
6This file is part of GNU Emacs.
7
32d235f8 8GNU Emacs is free software: you can redistribute it and/or modify
edfda783 9it under the terms of the GNU General Public License as published by
32d235f8
GM
10the Free Software Foundation, either version 3 of the License, or
11(at your option) any later version.
edfda783
AR
12
13GNU Emacs is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
32d235f8 19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
edfda783 20
32d235f8 21/*
edfda783
AR
22Originally by Carl Edman
23Updated by Christian Limpach (chris@nice.ch)
24OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com)
25MacOSX/Aqua port by Christophe de Dinechin (descubes@earthlink.net)
26GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
edfda783
AR
27*/
28
5a06864f
AR
29/* This should be the first include, as it may set up #defines affecting
30 interpretation of even the system includes. */
08a494a3 31#include <config.h>
5a06864f 32
edfda783 33#include <math.h>
fee5959d 34#include <c-strcase.h>
5a06864f 35
edfda783
AR
36#include "lisp.h"
37#include "blockinput.h"
38#include "nsterm.h"
39#include "window.h"
e5560ff7 40#include "character.h"
edfda783
AR
41#include "buffer.h"
42#include "keyboard.h"
43#include "termhooks.h"
44#include "fontset.h"
edfda783
AR
45#include "font.h"
46
4465bfb4
JD
47#ifdef NS_IMPL_COCOA
48#include <IOKit/graphics/IOGraphicsLib.h>
3fa2054e
JD
49#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
50#include "macfont.h"
51#endif
4465bfb4
JD
52#endif
53
edfda783
AR
54#if 0
55int fns_trace_num = 1;
56#define NSTRACE(x) fprintf (stderr, "%s:%d: [%d] " #x "\n", \
57 __FILE__, __LINE__, ++fns_trace_num)
58#else
59#define NSTRACE(x)
60#endif
61
62#ifdef HAVE_NS
63
64extern NSArray *ns_send_types, *ns_return_types, *ns_drag_types;
65
66extern Lisp_Object Qforeground_color;
67extern Lisp_Object Qbackground_color;
68extern Lisp_Object Qcursor_color;
69extern Lisp_Object Qinternal_border_width;
70extern Lisp_Object Qvisibility;
71extern Lisp_Object Qcursor_type;
72extern Lisp_Object Qicon_type;
73extern Lisp_Object Qicon_name;
74extern Lisp_Object Qicon_left;
75extern Lisp_Object Qicon_top;
76extern Lisp_Object Qleft;
77extern Lisp_Object Qright;
78extern Lisp_Object Qtop;
79extern Lisp_Object Qdisplay;
80extern Lisp_Object Qvertical_scroll_bars;
81extern Lisp_Object Qauto_raise;
82extern Lisp_Object Qauto_lower;
83extern Lisp_Object Qbox;
84extern Lisp_Object Qscroll_bar_width;
85extern Lisp_Object Qx_resource_name;
86extern Lisp_Object Qface_set_after_frame_default;
87extern Lisp_Object Qunderline, Qundefined;
88extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth;
89extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle;
90
5d1d3d04 91
edfda783
AR
92Lisp_Object Qbuffered;
93Lisp_Object Qfontsize;
94
0fb0a4f3 95EmacsTooltip *ns_tooltip = nil;
edfda783
AR
96
97/* Need forward declaration here to preserve organizational integrity of file */
9e50ff0c 98Lisp_Object Fx_open_connection (Lisp_Object, Lisp_Object, Lisp_Object);
edfda783 99
08e3161a
JD
100/* Static variables to handle applescript execution. */
101static Lisp_Object as_script, *as_result;
102static int as_status;
edfda783 103
ef884f23 104#ifdef GLYPH_DEBUG
a97f8f3f
JD
105static ptrdiff_t image_cache_refcount;
106#endif
107
4465bfb4 108
edfda783
AR
109/* ==========================================================================
110
111 Internal utility functions
112
113 ========================================================================== */
114
91e8418b
YM
115/* Let the user specify a Nextstep display with a Lisp object.
116 OBJECT may be nil, a frame or a terminal object.
117 nil stands for the selected frame--or, if that is not a Nextstep frame,
d26fbe1a 118 the first Nextstep display on the list. */
91e8418b 119
edfda783 120static struct ns_display_info *
91e8418b 121check_ns_display_info (Lisp_Object object)
edfda783 122{
91e8418b
YM
123 struct ns_display_info *dpyinfo = NULL;
124
125 if (NILP (object))
edfda783 126 {
91e8418b
YM
127 struct frame *sf = XFRAME (selected_frame);
128
129 if (FRAME_NS_P (sf) && FRAME_LIVE_P (sf))
aad3612f 130 dpyinfo = FRAME_DISPLAY_INFO (sf);
9e50ff0c 131 else if (x_display_list != 0)
91e8418b 132 dpyinfo = x_display_list;
edfda783 133 else
d26fbe1a 134 error ("Nextstep windows are not in use or not initialized");
edfda783 135 }
91e8418b 136 else if (TERMINALP (object))
edfda783 137 {
91e8418b 138 struct terminal *t = get_terminal (object, 1);
edfda783
AR
139
140 if (t->type != output_ns)
91e8418b 141 error ("Terminal %d is not a Nextstep display", t->id);
edfda783 142
91e8418b 143 dpyinfo = t->display_info.ns;
edfda783 144 }
91e8418b
YM
145 else if (STRINGP (object))
146 dpyinfo = ns_display_info_for_name (object);
edfda783
AR
147 else
148 {
a10c8269 149 struct frame *f = decode_window_system_frame (object);
aad3612f 150 dpyinfo = FRAME_DISPLAY_INFO (f);
edfda783 151 }
91e8418b
YM
152
153 return dpyinfo;
edfda783
AR
154}
155
156
157static id
158ns_get_window (Lisp_Object maybeFrame)
159{
160 id view =nil, window =nil;
161
162 if (!FRAMEP (maybeFrame) || !FRAME_NS_P (XFRAME (maybeFrame)))
163 maybeFrame = selected_frame;/*wrong_type_argument (Qframep, maybeFrame); */
164
165 if (!NILP (maybeFrame))
166 view = FRAME_NS_VIEW (XFRAME (maybeFrame));
167 if (view) window =[view window];
168
169 return window;
170}
171
172
edfda783
AR
173/* Return the X display structure for the display named NAME.
174 Open a new connection if necessary. */
175struct ns_display_info *
3d608a86 176ns_display_info_for_name (Lisp_Object name)
edfda783 177{
edfda783
AR
178 struct ns_display_info *dpyinfo;
179
180 CHECK_STRING (name);
181
d141d701
DA
182 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
183 if (!NILP (Fstring_equal (XCAR (dpyinfo->name_list_element), name)))
184 return dpyinfo;
edfda783
AR
185
186 error ("Emacs for OpenStep does not yet support multi-display.");
187
9e50ff0c
DN
188 Fx_open_connection (name, Qnil, Qnil);
189 dpyinfo = x_display_list;
edfda783
AR
190
191 if (dpyinfo == 0)
facfbbbd 192 error ("OpenStep on %s not responding.\n", SDATA (name));
edfda783
AR
193
194 return dpyinfo;
195}
196
8f2906f5
JD
197static NSString *
198ns_filename_from_panel (NSSavePanel *panel)
199{
200#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
201 NSURL *url = [panel URL];
202 NSString *str = [url path];
203 return str;
204#else
205 return [panel filename];
206#endif
207}
208
209static NSString *
210ns_directory_from_panel (NSSavePanel *panel)
211{
212#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
213 NSURL *url = [panel directoryURL];
214 NSString *str = [url path];
215 return str;
216#else
217 return [panel directory];
218#endif
219}
edfda783
AR
220
221static Lisp_Object
222interpret_services_menu (NSMenu *menu, Lisp_Object prefix, Lisp_Object old)
223/* --------------------------------------------------------------------------
224 Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
225 -------------------------------------------------------------------------- */
226{
227 int i, count;
15034960 228 NSMenuItem *item;
edfda783
AR
229 const char *name;
230 Lisp_Object nameStr;
231 unsigned short key;
232 NSString *keys;
233 Lisp_Object res;
234
235 count = [menu numberOfItems];
236 for (i = 0; i<count; i++)
237 {
238 item = [menu itemAtIndex: i];
239 name = [[item title] UTF8String];
240 if (!name) continue;
241
242 nameStr = build_string (name);
243
244 if ([item hasSubmenu])
245 {
246 old = interpret_services_menu ([item submenu],
247 Fcons (nameStr, prefix), old);
248 }
249 else
250 {
251 keys = [item keyEquivalent];
252 if (keys && [keys length] )
253 {
254 key = [keys characterAtIndex: 0];
255 res = make_number (key|super_modifier);
256 }
257 else
258 {
259 res = Qundefined;
260 }
261 old = Fcons (Fcons (res,
262 Freverse (Fcons (nameStr,
263 prefix))),
264 old);
265 }
266 }
267 return old;
268}
269
270
271
272/* ==========================================================================
273
274 Frame parameter setters
275
276 ========================================================================== */
277
278
279static void
89e2438a 280x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783
AR
281{
282 NSColor *col;
c0342369 283 EmacsCGFloat r, g, b, alpha;
edfda783
AR
284
285 if (ns_lisp_to_color (arg, &col))
286 {
287 store_frame_param (f, Qforeground_color, oldval);
288 error ("Unknown color");
289 }
290
291 [col retain];
292 [f->output_data.ns->foreground_color release];
293 f->output_data.ns->foreground_color = col;
294
d8c2fa78
AA
295 [col getRed: &r green: &g blue: &b alpha: &alpha];
296 FRAME_FOREGROUND_PIXEL (f) =
297 ARGB_TO_ULONG ((int)(alpha*0xff), (int)(r*0xff), (int)(g*0xff), (int)(b*0xff));
298
edfda783
AR
299 if (FRAME_NS_VIEW (f))
300 {
301 update_face_from_frame_parameter (f, Qforeground_color, arg);
302 /*recompute_basic_faces (f); */
303 if (FRAME_VISIBLE_P (f))
304 redraw_frame (f);
305 }
306}
307
308
309static void
89e2438a 310x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783
AR
311{
312 struct face *face;
313 NSColor *col;
314 NSView *view = FRAME_NS_VIEW (f);
c0342369 315 EmacsCGFloat r, g, b, alpha;
edfda783
AR
316
317 if (ns_lisp_to_color (arg, &col))
318 {
319 store_frame_param (f, Qbackground_color, oldval);
320 error ("Unknown color");
321 }
322
323 /* clear the frame; in some instances the NS-internal GC appears not to
324 update, or it does update and cannot clear old text properly */
325 if (FRAME_VISIBLE_P (f))
326 ns_clear_frame (f);
327
328 [col retain];
329 [f->output_data.ns->background_color release];
330 f->output_data.ns->background_color = col;
d8c2fa78
AA
331
332 [col getRed: &r green: &g blue: &b alpha: &alpha];
333 FRAME_BACKGROUND_PIXEL (f) =
334 ARGB_TO_ULONG ((int)(alpha*0xff), (int)(r*0xff), (int)(g*0xff), (int)(b*0xff));
335
edfda783
AR
336 if (view != nil)
337 {
338 [[view window] setBackgroundColor: col];
edfda783 339
c0342369 340 if (alpha != (EmacsCGFloat) 1.0)
edfda783
AR
341 [[view window] setOpaque: NO];
342 else
343 [[view window] setOpaque: YES];
344
345 face = FRAME_DEFAULT_FACE (f);
346 if (face)
347 {
45d325c4 348 col = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f);
204ee57f
JD
349 face->background = ns_index_color
350 ([col colorWithAlphaComponent: alpha], f);
edfda783
AR
351
352 update_face_from_frame_parameter (f, Qbackground_color, arg);
353 }
354
355 if (FRAME_VISIBLE_P (f))
356 redraw_frame (f);
357 }
358}
359
360
361static void
89e2438a 362x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783
AR
363{
364 NSColor *col;
365
366 if (ns_lisp_to_color (arg, &col))
367 {
368 store_frame_param (f, Qcursor_color, oldval);
369 error ("Unknown color");
370 }
371
c8c057de
AR
372 [FRAME_CURSOR_COLOR (f) release];
373 FRAME_CURSOR_COLOR (f) = [col retain];
edfda783
AR
374
375 if (FRAME_VISIBLE_P (f))
376 {
377 x_update_cursor (f, 0);
378 x_update_cursor (f, 1);
379 }
380 update_face_from_frame_parameter (f, Qcursor_color, arg);
381}
382
c8c057de 383
edfda783 384static void
89e2438a 385x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783
AR
386{
387 NSView *view = FRAME_NS_VIEW (f);
89e2438a 388 NSTRACE (x_set_icon_name);
edfda783 389
edfda783
AR
390 /* see if it's changed */
391 if (STRINGP (arg))
392 {
393 if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
394 return;
395 }
396 else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
397 return;
398
f00af5b1 399 fset_icon_name (f, arg);
edfda783
AR
400
401 if (NILP (arg))
402 {
e69b0960
DA
403 if (!NILP (f->title))
404 arg = f->title;
edfda783 405 else
94ae2ad4 406 /* Explicit name and no icon-name -> explicit_name. */
edfda783 407 if (f->explicit_name)
e69b0960 408 arg = f->name;
edfda783
AR
409 else
410 {
94ae2ad4
SM
411 /* No explicit name and no icon-name ->
412 name has to be rebuild from icon_title_format. */
413 windows_or_buffers_changed = 62;
edfda783
AR
414 return;
415 }
416 }
417
418 /* Don't change the name if it's already NAME. */
94ae2ad4
SM
419 if ([[view window] miniwindowTitle]
420 && ([[[view window] miniwindowTitle]
edfda783 421 isEqualToString: [NSString stringWithUTF8String:
94ae2ad4 422 SSDATA (arg)]]))
edfda783
AR
423 return;
424
425 [[view window] setMiniwindowTitle:
0dc8cf50 426 [NSString stringWithUTF8String: SSDATA (arg)]];
edfda783
AR
427}
428
edfda783 429static void
a10c8269 430ns_set_name_internal (struct frame *f, Lisp_Object name)
edfda783 431{
5bbb4727
JD
432 struct gcpro gcpro1;
433 Lisp_Object encoded_name, encoded_icon_name;
434 NSString *str;
edfda783 435 NSView *view = FRAME_NS_VIEW (f);
edfda783 436
5bbb4727
JD
437 GCPRO1 (name);
438 encoded_name = ENCODE_UTF_8 (name);
439 UNGCPRO;
edfda783 440
0dc8cf50 441 str = [NSString stringWithUTF8String: SSDATA (encoded_name)];
edfda783 442
5bbb4727
JD
443 /* Don't change the name if it's already NAME. */
444 if (! [[[view window] title] isEqualToString: str])
445 [[view window] setTitle: str];
edfda783 446
e69b0960 447 if (!STRINGP (f->icon_name))
5bbb4727 448 encoded_icon_name = encoded_name;
edfda783 449 else
e69b0960 450 encoded_icon_name = ENCODE_UTF_8 (f->icon_name);
5bbb4727 451
0dc8cf50 452 str = [NSString stringWithUTF8String: SSDATA (encoded_icon_name)];
edfda783 453
2ec9db5d
SM
454 if ([[view window] miniwindowTitle]
455 && ! [[[view window] miniwindowTitle] isEqualToString: str])
5bbb4727 456 [[view window] setMiniwindowTitle: str];
edfda783 457
edfda783
AR
458}
459
edfda783
AR
460static void
461ns_set_name (struct frame *f, Lisp_Object name, int explicit)
462{
edfda783
AR
463 NSTRACE (ns_set_name);
464
edfda783
AR
465 /* Make sure that requests from lisp code override requests from
466 Emacs redisplay code. */
467 if (explicit)
468 {
469 /* If we're switching from explicit to implicit, we had better
470 update the mode lines and thereby update the title. */
471 if (f->explicit_name && NILP (name))
2ec9db5d 472 update_mode_lines = 21;
edfda783
AR
473
474 f->explicit_name = ! NILP (name);
475 }
476 else if (f->explicit_name)
477 return;
478
479 if (NILP (name))
2ec9db5d 480 name = build_string ([ns_app_name UTF8String]);
5bbb4727
JD
481 else
482 CHECK_STRING (name);
483
484 /* Don't change the name if it's already NAME. */
e69b0960 485 if (! NILP (Fstring_equal (name, f->name)))
5bbb4727 486 return;
edfda783 487
f00af5b1 488 fset_name (f, name);
edfda783 489
2ec9db5d 490 /* Title overrides explicit name. */
e69b0960
DA
491 if (! NILP (f->title))
492 name = f->title;
edfda783 493
5bbb4727 494 ns_set_name_internal (f, name);
edfda783
AR
495}
496
497
498/* This function should be called when the user's lisp code has
499 specified a name for the frame; the name will override any set by the
500 redisplay code. */
501static void
a10c8269 502x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783 503{
89e2438a 504 NSTRACE (x_explicitly_set_name);
edfda783
AR
505 ns_set_name (f, arg, 1);
506}
507
508
509/* This function should be called by Emacs redisplay code to set the
510 name; names set this way will never override names set by the user's
511 lisp code. */
512void
a10c8269 513x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783
AR
514{
515 NSTRACE (x_implicitly_set_name);
5bbb4727
JD
516
517 /* Deal with NS specific format t. */
518 if (FRAME_NS_P (f) && ((FRAME_ICONIFIED_P (f) && EQ (Vicon_title_format, Qt))
519 || EQ (Vframe_title_format, Qt)))
9ae6e189 520 ns_set_name_as_filename (f);
edfda783
AR
521 else
522 ns_set_name (f, arg, 0);
523}
524
525
526/* Change the title of frame F to NAME.
5bbb4727 527 If NAME is nil, use the frame name as the title. */
edfda783 528
edfda783 529static void
89e2438a 530x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
edfda783 531{
89e2438a 532 NSTRACE (x_set_title);
edfda783 533 /* Don't change the title if it's already NAME. */
e69b0960 534 if (EQ (name, f->title))
edfda783
AR
535 return;
536
2ec9db5d 537 update_mode_lines = 22;
edfda783 538
f00af5b1 539 fset_title (f, name);
5bbb4727
JD
540
541 if (NILP (name))
e69b0960 542 name = f->name;
5bbb4727
JD
543 else
544 CHECK_STRING (name);
545
546 ns_set_name_internal (f, name);
edfda783
AR
547}
548
549
550void
551ns_set_name_as_filename (struct frame *f)
552{
fec8f0fe 553 NSView *view;
aeb7e951 554 Lisp_Object name, filename;
e74aeda8 555 Lisp_Object buf = XWINDOW (f->selected_window)->contents;
edfda783
AR
556 const char *title;
557 NSAutoreleasePool *pool;
5bbb4727 558 struct gcpro gcpro1;
aeb7e951
JD
559 Lisp_Object encoded_name, encoded_filename;
560 NSString *str;
edfda783
AR
561 NSTRACE (ns_set_name_as_filename);
562
3bc0a2f7 563 if (f->explicit_name || ! NILP (f->title))
edfda783
AR
564 return;
565
4d7e6e51 566 block_input ();
edfda783 567 pool = [[NSAutoreleasePool alloc] init];
124c9ff0
JD
568 filename = BVAR (XBUFFER (buf), filename);
569 name = BVAR (XBUFFER (buf), name);
edfda783
AR
570
571 if (NILP (name))
aeb7e951
JD
572 {
573 if (! NILP (filename))
574 name = Ffile_name_nondirectory (filename);
575 else
576 name = build_string ([ns_app_name UTF8String]);
577 }
edfda783 578
5bbb4727
JD
579 GCPRO1 (name);
580 encoded_name = ENCODE_UTF_8 (name);
581 UNGCPRO;
582
fec8f0fe
CY
583 view = FRAME_NS_VIEW (f);
584
edfda783
AR
585 title = FRAME_ICONIFIED_P (f) ? [[[view window] miniwindowTitle] UTF8String]
586 : [[[view window] title] UTF8String];
587
0dc8cf50 588 if (title && (! strcmp (title, SSDATA (encoded_name))))
edfda783
AR
589 {
590 [pool release];
4d7e6e51 591 unblock_input ();
edfda783
AR
592 return;
593 }
594
0dc8cf50 595 str = [NSString stringWithUTF8String: SSDATA (encoded_name)];
aeb7e951
JD
596 if (str == nil) str = @"Bad coding";
597
598 if (FRAME_ICONIFIED_P (f))
599 [[view window] setMiniwindowTitle: str];
5fdb398c 600 else
edfda783 601 {
aeb7e951
JD
602 NSString *fstr;
603
604 if (! NILP (filename))
edfda783 605 {
aeb7e951
JD
606 GCPRO1 (filename);
607 encoded_filename = ENCODE_UTF_8 (filename);
608 UNGCPRO;
609
0dc8cf50 610 fstr = [NSString stringWithUTF8String: SSDATA (encoded_filename)];
aeb7e951
JD
611 if (fstr == nil) fstr = @"";
612#ifdef NS_IMPL_COCOA
613 /* work around a bug observed on 10.3 and later where
614 setTitleWithRepresentedFilename does not clear out previous state
615 if given filename does not exist */
616 if (! [[NSFileManager defaultManager] fileExistsAtPath: fstr])
617 [[view window] setRepresentedFilename: @""];
618#endif
edfda783
AR
619 }
620 else
aeb7e951
JD
621 fstr = @"";
622
623 [[view window] setRepresentedFilename: fstr];
624 [[view window] setTitle: str];
f00af5b1 625 fset_name (f, name);
edfda783 626 }
aeb7e951 627
edfda783 628 [pool release];
4d7e6e51 629 unblock_input ();
edfda783
AR
630}
631
632
633void
6521c534 634ns_set_doc_edited (struct frame *f, Lisp_Object arg)
edfda783
AR
635{
636 NSView *view = FRAME_NS_VIEW (f);
637 NSAutoreleasePool *pool;
e69b0960 638 if (!MINI_WINDOW_P (XWINDOW (f->selected_window)))
9ae6e189 639 {
4d7e6e51 640 block_input ();
9ae6e189
CY
641 pool = [[NSAutoreleasePool alloc] init];
642 [[view window] setDocumentEdited: !NILP (arg)];
643 [pool release];
4d7e6e51 644 unblock_input ();
9ae6e189 645 }
edfda783
AR
646}
647
648
cc98b6a0
DN
649void
650x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
edfda783
AR
651{
652 int nlines;
edfda783
AR
653 if (FRAME_MINIBUF_ONLY_P (f))
654 return;
655
d311d28c 656 if (TYPE_RANGED_INTEGERP (int, value))
edfda783
AR
657 nlines = XINT (value);
658 else
659 nlines = 0;
660
661 FRAME_MENU_BAR_LINES (f) = 0;
662 if (nlines)
663 {
664 FRAME_EXTERNAL_MENU_BAR (f) = 1;
cc98b6a0
DN
665 /* does for all frames, whereas we just want for one frame
666 [NSMenu setMenuBarVisible: YES]; */
edfda783
AR
667 }
668 else
669 {
670 if (FRAME_EXTERNAL_MENU_BAR (f) == 1)
671 free_frame_menubar (f);
cc98b6a0 672 /* [NSMenu setMenuBarVisible: NO]; */
edfda783
AR
673 FRAME_EXTERNAL_MENU_BAR (f) = 0;
674 }
675}
676
677
3fe53a83 678/* toolbar support */
cc98b6a0
DN
679void
680x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
edfda783
AR
681{
682 int nlines;
edfda783
AR
683
684 if (FRAME_MINIBUF_ONLY_P (f))
685 return;
686
d311d28c 687 if (RANGED_INTEGERP (0, value, INT_MAX))
edfda783
AR
688 nlines = XFASTINT (value);
689 else
690 nlines = 0;
691
692 if (nlines)
693 {
694 FRAME_EXTERNAL_TOOL_BAR (f) = 1;
695 update_frame_tool_bar (f);
696 }
697 else
698 {
699 if (FRAME_EXTERNAL_TOOL_BAR (f))
700 {
701 free_frame_tool_bar (f);
702 FRAME_EXTERNAL_TOOL_BAR (f) = 0;
703 }
704 }
705
880e6158 706 x_set_window_size (f, 0, f->text_cols, f->text_lines, 0);
edfda783
AR
707}
708
709
c0342369 710static void
edfda783
AR
711ns_implicitly_set_icon_type (struct frame *f)
712{
713 Lisp_Object tem;
714 EmacsView *view = FRAME_NS_VIEW (f);
204ee57f 715 id image = nil;
edfda783
AR
716 Lisp_Object chain, elt;
717 NSAutoreleasePool *pool;
718 BOOL setMini = YES;
719
720 NSTRACE (ns_implicitly_set_icon_type);
721
4d7e6e51 722 block_input ();
edfda783
AR
723 pool = [[NSAutoreleasePool alloc] init];
724 if (f->output_data.ns->miniimage
e69b0960 725 && [[NSString stringWithUTF8String: SSDATA (f->name)]
edfda783
AR
726 isEqualToString: [(NSImage *)f->output_data.ns->miniimage name]])
727 {
728 [pool release];
4d7e6e51 729 unblock_input ();
edfda783
AR
730 return;
731 }
732
e69b0960 733 tem = assq_no_quit (Qicon_type, f->param_alist);
edfda783
AR
734 if (CONSP (tem) && ! NILP (XCDR (tem)))
735 {
736 [pool release];
4d7e6e51 737 unblock_input ();
edfda783
AR
738 return;
739 }
740
741 for (chain = Vns_icon_type_alist;
204ee57f 742 image == nil && CONSP (chain);
edfda783
AR
743 chain = XCDR (chain))
744 {
745 elt = XCAR (chain);
746 /* special case: 't' means go by file type */
e69b0960 747 if (SYMBOLP (elt) && EQ (elt, Qt) && SSDATA (f->name)[0] == '/')
edfda783 748 {
facfbbbd 749 NSString *str
e69b0960 750 = [NSString stringWithUTF8String: SSDATA (f->name)];
edfda783
AR
751 if ([[NSFileManager defaultManager] fileExistsAtPath: str])
752 image = [[[NSWorkspace sharedWorkspace] iconForFile: str] retain];
753 }
754 else if (CONSP (elt) &&
755 STRINGP (XCAR (elt)) &&
756 STRINGP (XCDR (elt)) &&
e69b0960 757 fast_string_match (XCAR (elt), f->name) >= 0)
edfda783
AR
758 {
759 image = [EmacsImage allocInitFromFile: XCDR (elt)];
760 if (image == nil)
761 image = [[NSImage imageNamed:
762 [NSString stringWithUTF8String:
0dc8cf50 763 SSDATA (XCDR (elt))]] retain];
edfda783
AR
764 }
765 }
766
767 if (image == nil)
768 {
769 image = [[[NSWorkspace sharedWorkspace] iconForFileType: @"text"] retain];
770 setMini = NO;
771 }
772
773 [f->output_data.ns->miniimage release];
774 f->output_data.ns->miniimage = image;
775 [view setMiniwindowImage: setMini];
776 [pool release];
4d7e6e51 777 unblock_input ();
edfda783
AR
778}
779
780
781static void
89e2438a 782x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783
AR
783{
784 EmacsView *view = FRAME_NS_VIEW (f);
785 id image = nil;
786 BOOL setMini = YES;
787
89e2438a 788 NSTRACE (x_set_icon_type);
edfda783
AR
789
790 if (!NILP (arg) && SYMBOLP (arg))
791 {
0dc8cf50 792 arg =build_string (SSDATA (SYMBOL_NAME (arg)));
edfda783
AR
793 store_frame_param (f, Qicon_type, arg);
794 }
795
796 /* do it the implicit way */
797 if (NILP (arg))
798 {
799 ns_implicitly_set_icon_type (f);
800 return;
801 }
802
803 CHECK_STRING (arg);
804
805 image = [EmacsImage allocInitFromFile: arg];
806 if (image == nil)
807 image =[NSImage imageNamed: [NSString stringWithUTF8String:
0dc8cf50 808 SSDATA (arg)]];
edfda783
AR
809
810 if (image == nil)
811 {
812 image = [NSImage imageNamed: @"text"];
813 setMini = NO;
814 }
815
816 f->output_data.ns->miniimage = image;
817 [view setMiniwindowImage: setMini];
818}
819
820
6fb5f7da 821/* TODO: move to nsterm? */
edfda783
AR
822int
823ns_lisp_to_cursor_type (Lisp_Object arg)
824{
825 char *str;
826 if (XTYPE (arg) == Lisp_String)
0dc8cf50 827 str = SSDATA (arg);
edfda783 828 else if (XTYPE (arg) == Lisp_Symbol)
0dc8cf50 829 str = SSDATA (SYMBOL_NAME (arg));
edfda783 830 else return -1;
c8c057de
AR
831 if (!strcmp (str, "box")) return FILLED_BOX_CURSOR;
832 if (!strcmp (str, "hollow")) return HOLLOW_BOX_CURSOR;
833 if (!strcmp (str, "hbar")) return HBAR_CURSOR;
834 if (!strcmp (str, "bar")) return BAR_CURSOR;
835 if (!strcmp (str, "no")) return NO_CURSOR;
edfda783
AR
836 return -1;
837}
838
839
840Lisp_Object
841ns_cursor_type_to_lisp (int arg)
842{
843 switch (arg)
844 {
c8c057de
AR
845 case FILLED_BOX_CURSOR: return Qbox;
846 case HOLLOW_BOX_CURSOR: return intern ("hollow");
847 case HBAR_CURSOR: return intern ("hbar");
848 case BAR_CURSOR: return intern ("bar");
849 case NO_CURSOR:
850 default: return intern ("no");
edfda783
AR
851 }
852}
853
89e2438a 854/* This is the same as the xfns.c definition. */
c0342369 855static void
a10c8269 856x_set_cursor_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783 857{
06197b17 858 set_frame_cursor_types (f, arg);
edfda783 859}
edfda783 860
3fe53a83
AR
861/* called to set mouse pointer color, but all other terms use it to
862 initialize pointer types (and don't set the color ;) */
edfda783 863static void
89e2438a 864x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783 865{
d26fbe1a 866 /* don't think we can do this on Nextstep */
edfda783
AR
867}
868
869
cb83c00b
AR
870#define Str(x) #x
871#define Xstr(x) Str(x)
872
873static Lisp_Object
3d608a86 874ns_appkit_version_str (void)
cb83c00b
AR
875{
876 char tmp[80];
877
878#ifdef NS_IMPL_GNUSTEP
879 sprintf(tmp, "gnustep-gui-%s", Xstr(GNUSTEP_GUI_VERSION));
cf7a0de6 880#elif defined (NS_IMPL_COCOA)
cb83c00b
AR
881 sprintf(tmp, "apple-appkit-%.2f", NSAppKitVersionNumber);
882#else
883 tmp = "ns-unknown";
884#endif
885 return build_string (tmp);
886}
887
888
f5497e45
AR
889/* This is for use by x-server-version and collapses all version info we
890 have into a single int. For a better picture of the implementation
891 running, use ns_appkit_version_str.*/
892static int
3d608a86 893ns_appkit_version_int (void)
f5497e45
AR
894{
895#ifdef NS_IMPL_GNUSTEP
13cd8a29 896 return GNUSTEP_GUI_MAJOR_VERSION * 100 + GNUSTEP_GUI_MINOR_VERSION;
cf7a0de6 897#elif defined (NS_IMPL_COCOA)
f5497e45
AR
898 return (int)NSAppKitVersionNumber;
899#endif
900 return 0;
901}
902
903
edfda783 904static void
952913d4 905x_icon (struct frame *f, Lisp_Object parms)
edfda783
AR
906/* --------------------------------------------------------------------------
907 Strangely-named function to set icon position parameters in frame.
908 This is irrelevant under OS X, but might be needed under GNUstep,
909 depending on the window manager used. Note, this is not a standard
910 frame parameter-setter; it is called directly from x-create-frame.
911 -------------------------------------------------------------------------- */
912{
913 Lisp_Object icon_x, icon_y;
914 struct ns_display_info *dpyinfo = check_ns_display_info (Qnil);
915
916 f->output_data.ns->icon_top = Qnil;
917 f->output_data.ns->icon_left = Qnil;
918
919 /* Set the position of the icon. */
920 icon_x = x_get_arg (dpyinfo, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
921 icon_y = x_get_arg (dpyinfo, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
922 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
923 {
924 CHECK_NUMBER (icon_x);
925 CHECK_NUMBER (icon_y);
926 f->output_data.ns->icon_top = icon_y;
927 f->output_data.ns->icon_left = icon_x;
928 }
929 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
930 error ("Both left and top icon corners of icon must be specified");
931}
932
933
3fe53a83 934/* Note: see frame.c for template, also where generic functions are impl */
edfda783
AR
935frame_parm_handler ns_frame_parm_handlers[] =
936{
937 x_set_autoraise, /* generic OK */
938 x_set_autolower, /* generic OK */
89e2438a 939 x_set_background_color,
d26fbe1a
CY
940 0, /* x_set_border_color, may be impossible under Nextstep */
941 0, /* x_set_border_width, may be impossible under Nextstep */
89e2438a
DN
942 x_set_cursor_color,
943 x_set_cursor_type,
edfda783 944 x_set_font, /* generic OK */
89e2438a
DN
945 x_set_foreground_color,
946 x_set_icon_name,
947 x_set_icon_type,
edfda783 948 x_set_internal_border_width, /* generic OK */
c619527c
JD
949 0, /* x_set_right_divider_width */
950 0, /* x_set_bottom_divider_width */
cc98b6a0 951 x_set_menu_bar_lines,
89e2438a
DN
952 x_set_mouse_color,
953 x_explicitly_set_name,
edfda783 954 x_set_scroll_bar_width, /* generic OK */
89e2438a 955 x_set_title,
edfda783
AR
956 x_set_unsplittable, /* generic OK */
957 x_set_vertical_scroll_bars, /* generic OK */
958 x_set_visibility, /* generic OK */
cc98b6a0 959 x_set_tool_bar_lines,
edfda783
AR
960 0, /* x_set_scroll_bar_foreground, will ignore (not possible on NS) */
961 0, /* x_set_scroll_bar_background, will ignore (not possible on NS) */
962 x_set_screen_gamma, /* generic OK */
963 x_set_line_spacing, /* generic OK, sets f->extra_line_spacing to int */
964 x_set_fringe_width, /* generic OK */
965 x_set_fringe_width, /* generic OK */
966 0, /* x_set_wait_for_wm, will ignore */
dd946752 967 x_set_fullscreen, /* generic OK */
dee721c0 968 x_set_font_backend, /* generic OK */
cad9ef74 969 x_set_alpha,
5fdb398c
PE
970 0, /* x_set_sticky */
971 0, /* x_set_tool_bar_position */
edfda783
AR
972};
973
974
a97f8f3f
JD
975/* Handler for signals raised during x_create_frame.
976 FRAME is the frame which is partially constructed. */
977
27e498e6 978static void
a97f8f3f
JD
979unwind_create_frame (Lisp_Object frame)
980{
981 struct frame *f = XFRAME (frame);
982
983 /* If frame is already dead, nothing to do. This can happen if the
984 display is disconnected after the frame has become official, but
985 before x_create_frame removes the unwind protect. */
986 if (!FRAME_LIVE_P (f))
27e498e6 987 return;
a97f8f3f
JD
988
989 /* If frame is ``official'', nothing to do. */
97f18cc8 990 if (NILP (Fmemq (frame, Vframe_list)))
a97f8f3f 991 {
ef884f23 992#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
aad3612f 993 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
a97f8f3f
JD
994#endif
995
996 x_free_frame_resources (f);
997 free_glyphs (f);
998
ef884f23 999#ifdef GLYPH_DEBUG
a97f8f3f 1000 /* Check that reference counts are indeed correct. */
ef884f23 1001 eassert (dpyinfo->terminal->image_cache->refcount == image_cache_refcount);
a97f8f3f 1002#endif
a97f8f3f 1003 }
a97f8f3f
JD
1004}
1005
a0c3fad0
JD
1006/*
1007 * Read geometry related parameters from preferences if not in PARMS.
1008 * Returns the union of parms and any preferences read.
1009 */
a97f8f3f 1010
a0c3fad0
JD
1011static Lisp_Object
1012get_geometry_from_preferences (struct ns_display_info *dpyinfo,
1013 Lisp_Object parms)
1014{
1015 struct {
1016 const char *val;
1017 const char *cls;
1018 Lisp_Object tem;
1019 } r[] = {
1020 { "width", "Width", Qwidth },
1021 { "height", "Height", Qheight },
1022 { "left", "Left", Qleft },
1023 { "top", "Top", Qtop },
1024 };
1025
1026 int i;
1027 for (i = 0; i < sizeof (r)/sizeof (r[0]); ++i)
1028 {
1029 if (NILP (Fassq (r[i].tem, parms)))
1030 {
1031 Lisp_Object value
1032 = x_get_arg (dpyinfo, parms, r[i].tem, r[i].val, r[i].cls,
1033 RES_TYPE_NUMBER);
1034 if (! EQ (value, Qunbound))
1035 parms = Fcons (Fcons (r[i].tem, value), parms);
1036 }
1037 }
a97f8f3f 1038
a0c3fad0
JD
1039 return parms;
1040}
cb83c00b
AR
1041
1042/* ==========================================================================
1043
1044 Lisp definitions
1045
1046 ========================================================================== */
1047
9e50ff0c 1048DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
edfda783 1049 1, 1, 0,
a97f8f3f 1050 doc: /* Make a new Nextstep window, called a "frame" in Emacs terms.
d26fbe1a
CY
1051Return an Emacs frame object.
1052PARMS is an alist of frame parameters.
1053If the parameters specify that the frame should not have a minibuffer,
1054and do not specify a specific minibuffer window to use,
1055then `default-minibuffer-frame' must be a frame whose minibuffer can
a97f8f3f
JD
1056be shared by the new frame.
1057
1058This function is an internal primitive--use `make-frame' instead. */)
5842a27b 1059 (Lisp_Object parms)
edfda783 1060{
edfda783 1061 struct frame *f;
edfda783
AR
1062 Lisp_Object frame, tem;
1063 Lisp_Object name;
1064 int minibuffer_only = 0;
959067a1 1065 long window_prompting = 0;
a97f8f3f 1066 int width, height;
d311d28c 1067 ptrdiff_t count = specpdl_ptr - specpdl;
a97f8f3f 1068 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
edfda783
AR
1069 Lisp_Object display;
1070 struct ns_display_info *dpyinfo = NULL;
1071 Lisp_Object parent;
1072 struct kboard *kb;
a97f8f3f 1073 static int desc_ctr = 1;
edfda783 1074
a97f8f3f 1075 /* x_get_arg modifies parms. */
bd6ce2ba
AR
1076 parms = Fcopy_alist (parms);
1077
a97f8f3f
JD
1078 /* Use this general default value to start with
1079 until we know if this frame has a specified name. */
1080 Vx_resource_name = Vinvocation_name;
1081
edfda783
AR
1082 display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_STRING);
1083 if (EQ (display, Qunbound))
1084 display = Qnil;
1085 dpyinfo = check_ns_display_info (display);
a97f8f3f 1086 kb = dpyinfo->terminal->kboard;
edfda783
AR
1087
1088 if (!dpyinfo->terminal->name)
1089 error ("Terminal is not live, can't create new frames on it");
1090
edfda783
AR
1091 name = x_get_arg (dpyinfo, parms, Qname, 0, 0, RES_TYPE_STRING);
1092 if (!STRINGP (name)
1093 && ! EQ (name, Qunbound)
1094 && ! NILP (name))
1095 error ("Invalid frame name--not a string or nil");
1096
1097 if (STRINGP (name))
1098 Vx_resource_name = name;
1099
1100 parent = x_get_arg (dpyinfo, parms, Qparent_id, 0, 0, RES_TYPE_NUMBER);
1101 if (EQ (parent, Qunbound))
1102 parent = Qnil;
1103 if (! NILP (parent))
1104 CHECK_NUMBER (parent);
1105
a97f8f3f
JD
1106 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
1107 /* No need to protect DISPLAY because that's not used after passing
1108 it to make_frame_without_minibuffer. */
edfda783
AR
1109 frame = Qnil;
1110 GCPRO4 (parms, parent, name, frame);
edfda783
AR
1111 tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer",
1112 RES_TYPE_SYMBOL);
1113 if (EQ (tem, Qnone) || NILP (tem))
edfda783 1114 f = make_frame_without_minibuffer (Qnil, kb, display);
edfda783
AR
1115 else if (EQ (tem, Qonly))
1116 {
1117 f = make_minibuffer_frame ();
1118 minibuffer_only = 1;
1119 }
1120 else if (WINDOWP (tem))
edfda783 1121 f = make_frame_without_minibuffer (tem, kb, display);
edfda783 1122 else
edfda783 1123 f = make_frame (1);
edfda783
AR
1124
1125 XSETFRAME (frame, f);
edfda783
AR
1126
1127 f->terminal = dpyinfo->terminal;
edfda783
AR
1128
1129 f->output_method = output_ns;
38182d90 1130 f->output_data.ns = xzalloc (sizeof *f->output_data.ns);
edfda783
AR
1131
1132 FRAME_FONTSET (f) = -1;
1133
f00af5b1
PE
1134 fset_icon_name (f, x_get_arg (dpyinfo, parms, Qicon_name,
1135 "iconName", "Title",
1136 RES_TYPE_STRING));
e69b0960 1137 if (! STRINGP (f->icon_name))
f00af5b1 1138 fset_icon_name (f, Qnil);
edfda783 1139
aad3612f 1140 FRAME_DISPLAY_INFO (f) = dpyinfo;
edfda783 1141
aad3612f 1142 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
a97f8f3f
JD
1143 record_unwind_protect (unwind_create_frame, frame);
1144
edfda783 1145 f->output_data.ns->window_desc = desc_ctr++;
d311d28c 1146 if (TYPE_RANGED_INTEGERP (Window, parent))
edfda783 1147 {
d311d28c 1148 f->output_data.ns->parent_desc = XFASTINT (parent);
edfda783
AR
1149 f->output_data.ns->explicit_parent = 1;
1150 }
1151 else
1152 {
aad3612f 1153 f->output_data.ns->parent_desc = FRAME_DISPLAY_INFO (f)->root_window;
edfda783
AR
1154 f->output_data.ns->explicit_parent = 0;
1155 }
1156
a97f8f3f
JD
1157 /* Set the name; the functions to which we pass f expect the name to
1158 be set. */
1159 if (EQ (name, Qunbound) || NILP (name) || ! STRINGP (name))
1160 {
f00af5b1 1161 fset_name (f, build_string ([ns_app_name UTF8String]));
a97f8f3f
JD
1162 f->explicit_name = 0;
1163 }
1164 else
1165 {
f00af5b1 1166 fset_name (f, name);
a97f8f3f
JD
1167 f->explicit_name = 1;
1168 specbind (Qx_resource_name, name);
1169 }
1170
4d7e6e51 1171 block_input ();
3fa2054e 1172
745d3809
JD
1173#ifdef NS_IMPL_COCOA
1174#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
3fa2054e
JD
1175 if (CTGetCoreTextVersion != NULL
1176 && CTGetCoreTextVersion () >= kCTVersionNumber10_5)
1177 mac_register_font_driver (f);
3fa2054e 1178#endif
745d3809
JD
1179#endif
1180 register_font_driver (&nsfont_driver, f);
3fa2054e 1181
edfda783
AR
1182 x_default_parameter (f, parms, Qfont_backend, Qnil,
1183 "fontBackend", "FontBackend", RES_TYPE_STRING);
1184
1185 {
1186 /* use for default font name */
1187 id font = [NSFont userFixedPitchFontOfSize: -1.0]; /* default */
c0342369 1188 x_default_parameter (f, parms, Qfontsize,
edfda783
AR
1189 make_number (0 /*(int)[font pointSize]*/),
1190 "fontSize", "FontSize", RES_TYPE_NUMBER);
3fa2054e
JD
1191 // Remove ' Regular', not handled by backends.
1192 char *fontname = xstrdup ([[font displayName] UTF8String]);
1193 int len = strlen (fontname);
1194 if (len > 8 && strcmp (fontname + len - 8, " Regular") == 0)
1195 fontname[len-8] = '\0';
c0342369 1196 x_default_parameter (f, parms, Qfont,
3fa2054e 1197 build_string (fontname),
edfda783 1198 "font", "Font", RES_TYPE_STRING);
c8b09927 1199 xfree (fontname);
edfda783 1200 }
4d7e6e51 1201 unblock_input ();
edfda783
AR
1202
1203 x_default_parameter (f, parms, Qborder_width, make_number (0),
1204 "borderwidth", "BorderWidth", RES_TYPE_NUMBER);
1205 x_default_parameter (f, parms, Qinternal_border_width, make_number (2),
1206 "internalBorderWidth", "InternalBorderWidth",
1207 RES_TYPE_NUMBER);
1208
1209 /* default scrollbars on right on Mac */
1210 {
facfbbbd 1211 Lisp_Object spos
edfda783 1212#ifdef NS_IMPL_GNUSTEP
facfbbbd 1213 = Qt;
edfda783 1214#else
facfbbbd 1215 = Qright;
edfda783 1216#endif
facfbbbd
SM
1217 x_default_parameter (f, parms, Qvertical_scroll_bars, spos,
1218 "verticalScrollBars", "VerticalScrollBars",
1219 RES_TYPE_SYMBOL);
edfda783
AR
1220 }
1221 x_default_parameter (f, parms, Qforeground_color, build_string ("Black"),
1222 "foreground", "Foreground", RES_TYPE_STRING);
1223 x_default_parameter (f, parms, Qbackground_color, build_string ("White"),
1224 "background", "Background", RES_TYPE_STRING);
22bcf204 1225 /* FIXME: not supported yet in Nextstep */
edfda783
AR
1226 x_default_parameter (f, parms, Qline_spacing, Qnil,
1227 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
1228 x_default_parameter (f, parms, Qleft_fringe, Qnil,
1229 "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
1230 x_default_parameter (f, parms, Qright_fringe, Qnil,
1231 "rightFringe", "RightFringe", RES_TYPE_NUMBER);
edfda783 1232
ef884f23 1233#ifdef GLYPH_DEBUG
a97f8f3f
JD
1234 image_cache_refcount =
1235 FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0;
1236#endif
edfda783
AR
1237
1238 init_frame_faces (f);
1239
a97f8f3f 1240 /* The resources controlling the menu-bar and tool-bar are
6431f2e6
CY
1241 processed specially at startup, and reflected in the mode
1242 variables; ignore them here. */
1243 x_default_parameter (f, parms, Qmenu_bar_lines,
1244 NILP (Vmenu_bar_mode)
1245 ? make_number (0) : make_number (1),
1246 NULL, NULL, RES_TYPE_NUMBER);
1247 x_default_parameter (f, parms, Qtool_bar_lines,
1248 NILP (Vtool_bar_mode)
1249 ? make_number (0) : make_number (1),
1250 NULL, NULL, RES_TYPE_NUMBER);
1251
edfda783
AR
1252 x_default_parameter (f, parms, Qbuffer_predicate, Qnil, "bufferPredicate",
1253 "BufferPredicate", RES_TYPE_SYMBOL);
1254 x_default_parameter (f, parms, Qtitle, Qnil, "title", "Title",
1255 RES_TYPE_STRING);
1256
a0c3fad0 1257 parms = get_geometry_from_preferences (dpyinfo, parms);
edfda783
AR
1258 window_prompting = x_figure_window_size (f, parms, 1);
1259
1260 tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
1261 f->no_split = minibuffer_only || (!EQ (tem, Qunbound) && !EQ (tem, Qnil));
1262
1263 /* NOTE: on other terms, this is done in set_mouse_color, however this
d26fbe1a 1264 was not getting called under Nextstep */
edfda783
AR
1265 f->output_data.ns->text_cursor = [NSCursor IBeamCursor];
1266 f->output_data.ns->nontext_cursor = [NSCursor arrowCursor];
1267 f->output_data.ns->modeline_cursor = [NSCursor pointingHandCursor];
1268 f->output_data.ns->hand_cursor = [NSCursor pointingHandCursor];
1269 f->output_data.ns->hourglass_cursor = [NSCursor disappearingItemCursor];
1270 f->output_data.ns->horizontal_drag_cursor = [NSCursor resizeLeftRightCursor];
880e6158 1271 f->output_data.ns->vertical_drag_cursor = [NSCursor resizeUpDownCursor];
aad3612f 1272 FRAME_DISPLAY_INFO (f)->vertical_scroll_bar_cursor
facfbbbd 1273 = [NSCursor arrowCursor];
edfda783
AR
1274 f->output_data.ns->current_pointer = f->output_data.ns->text_cursor;
1275
1276 [[EmacsView alloc] initFrameFromEmacs: f];
1277
952913d4 1278 x_icon (f, parms);
edfda783 1279
a97f8f3f
JD
1280 /* ns_display_info does not have a reference_count. */
1281 f->terminal->reference_count++;
1282
edfda783
AR
1283 /* It is now ok to make the frame official even if we get an error below.
1284 The frame needs to be on Vframe_list or making it visible won't work. */
1285 Vframe_list = Fcons (frame, Vframe_list);
a97f8f3f
JD
1286
1287 x_default_parameter (f, parms, Qicon_type, Qnil,
1288 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
1289
1290 x_default_parameter (f, parms, Qauto_raise, Qnil,
1291 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
1292 x_default_parameter (f, parms, Qauto_lower, Qnil,
1293 "autoLower", "AutoLower", RES_TYPE_BOOLEAN);
1294 x_default_parameter (f, parms, Qcursor_type, Qbox,
1295 "cursorType", "CursorType", RES_TYPE_SYMBOL);
1296 x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
1297 "scrollBarWidth", "ScrollBarWidth",
1298 RES_TYPE_NUMBER);
1299 x_default_parameter (f, parms, Qalpha, Qnil,
1300 "alpha", "Alpha", RES_TYPE_NUMBER);
04fafa46
JD
1301 x_default_parameter (f, parms, Qfullscreen, Qnil,
1302 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
edfda783
AR
1303
1304 width = FRAME_COLS (f);
1305 height = FRAME_LINES (f);
1306
1307 SET_FRAME_COLS (f, 0);
1308 FRAME_LINES (f) = 0;
880e6158 1309 change_frame_size (f, width, height, 1, 0, 0, 0);
edfda783
AR
1310
1311 if (! f->output_data.ns->explicit_parent)
1312 {
a97f8f3f
JD
1313 Lisp_Object visibility;
1314
1315 visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
1316 RES_TYPE_SYMBOL);
1317 if (EQ (visibility, Qunbound))
1318 visibility = Qt;
1319
1320 if (EQ (visibility, Qicon))
15891144 1321 x_iconify_frame (f);
a97f8f3f 1322 else if (! NILP (visibility))
15891144
DR
1323 {
1324 x_make_frame_visible (f);
15891144
DR
1325 [[FRAME_NS_VIEW (f) window] makeKeyWindow];
1326 }
1327 else
a97f8f3f
JD
1328 {
1329 /* Must have been Qnil. */
1330 }
edfda783
AR
1331 }
1332
1333 if (FRAME_HAS_MINIBUF_P (f)
124c9ff0
JD
1334 && (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
1335 || !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame)))))
15dbb4d6 1336 kset_default_minibuffer_frame (kb, frame);
edfda783
AR
1337
1338 /* All remaining specified parameters, which have not been "used"
1339 by x_get_arg and friends, now go in the misc. alist of the frame. */
1340 for (tem = parms; CONSP (tem); tem = XCDR (tem))
1341 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
f00af5b1 1342 fset_param_alist (f, Fcons (XCAR (tem), f->param_alist));
edfda783
AR
1343
1344 UNGCPRO;
a97f8f3f 1345
e543ae91
JD
1346 if (window_prompting & USPosition)
1347 x_set_offset (f, f->left_pos, f->top_pos, 1);
1348
a97f8f3f
JD
1349 /* Make sure windows on this frame appear in calls to next-window
1350 and similar functions. */
edfda783
AR
1351 Vwindow_list = Qnil;
1352
1353 return unbind_to (count, frame);
1354}
1355
fcd42c11
DA
1356void
1357x_focus_frame (struct frame *f)
edfda783 1358{
aad3612f 1359 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
edfda783 1360
9e50ff0c 1361 if (dpyinfo->x_focus_frame != f)
edfda783
AR
1362 {
1363 EmacsView *view = FRAME_NS_VIEW (f);
4d7e6e51 1364 block_input ();
4acaaa2b 1365 [NSApp activateIgnoringOtherApps: YES];
edfda783 1366 [[view window] makeKeyAndOrderFront: view];
4d7e6e51 1367 unblock_input ();
edfda783 1368 }
edfda783
AR
1369}
1370
1371
edfda783 1372DEFUN ("ns-popup-font-panel", Fns_popup_font_panel, Sns_popup_font_panel,
51d5ef9f
AR
1373 0, 1, "",
1374 doc: /* Pop up the font panel. */)
5842a27b 1375 (Lisp_Object frame)
edfda783 1376{
7452b7bd
DA
1377 struct frame *f = decode_window_system_frame (frame);
1378 id fm = [NSFontManager sharedFontManager];
3fa2054e
JD
1379 struct font *font = f->output_data.ns->font;
1380 NSFont *nsfont;
1381 if (EQ (font->driver->type, Qns))
1382 nsfont = ((struct nsfont_info *)font)->nsfont;
1383#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
1384 else
1385 nsfont = (NSFont *) macfont_get_nsctfont (font);
1386#endif
1387 [fm setSelectedFont: nsfont isMultiple: NO];
edfda783
AR
1388 [fm orderFrontFontPanel: NSApp];
1389 return Qnil;
1390}
1391
1392
b066e6b6 1393DEFUN ("ns-popup-color-panel", Fns_popup_color_panel, Sns_popup_color_panel,
51d5ef9f
AR
1394 0, 1, "",
1395 doc: /* Pop up the color panel. */)
5842a27b 1396 (Lisp_Object frame)
edfda783 1397{
7452b7bd 1398 check_window_system (NULL);
edfda783
AR
1399 [NSApp orderFrontColorPanel: NSApp];
1400 return Qnil;
1401}
1402
1afb1d07
JD
1403static struct
1404{
1405 id panel;
1406 BOOL ret;
1407#if ! defined (NS_IMPL_COCOA) || \
1408 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
1409 NSString *dirS, *initS;
1410 BOOL no_types;
1411#endif
1412} ns_fd_data;
1413
1414void
1415ns_run_file_dialog (void)
1416{
1417 if (ns_fd_data.panel == nil) return;
1418#if defined (NS_IMPL_COCOA) && \
1419 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1420 ns_fd_data.ret = [ns_fd_data.panel runModal];
1421#else
1422 if (ns_fd_data.no_types)
1423 {
1424 ns_fd_data.ret = [ns_fd_data.panel
1425 runModalForDirectory: ns_fd_data.dirS
1426 file: ns_fd_data.initS];
1427 }
1428 else
1429 {
1430 ns_fd_data.ret = [ns_fd_data.panel
1431 runModalForDirectory: ns_fd_data.dirS
1432 file: ns_fd_data.initS
1433 types: nil];
1434 }
1435#endif
1436 ns_fd_data.panel = nil;
1437}
edfda783 1438
d7e642cc 1439DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 5, 0,
51d5ef9f 1440 doc: /* Use a graphical panel to read a file name, using prompt PROMPT.
d26fbe1a 1441Optional arg DIR, if non-nil, supplies a default directory.
45cb8994
CY
1442Optional arg MUSTMATCH, if non-nil, means the returned file or
1443directory must exist.
d7e642cc
JD
1444Optional arg INIT, if non-nil, provides a default file name to use.
1445Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1446 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object mustmatch,
1447 Lisp_Object init, Lisp_Object dir_only_p)
edfda783
AR
1448{
1449 static id fileDelegate = nil;
8f2906f5 1450 BOOL ret;
c0342369 1451 BOOL isSave = NILP (mustmatch) && NILP (dir_only_p);
edfda783 1452 id panel;
ba301db3 1453 Lisp_Object fname;
edfda783
AR
1454
1455 NSString *promptS = NILP (prompt) || !STRINGP (prompt) ? nil :
0dc8cf50 1456 [NSString stringWithUTF8String: SSDATA (prompt)];
edfda783 1457 NSString *dirS = NILP (dir) || !STRINGP (dir) ?
0dc8cf50
JD
1458 [NSString stringWithUTF8String: SSDATA (BVAR (current_buffer, directory))] :
1459 [NSString stringWithUTF8String: SSDATA (dir)];
edfda783 1460 NSString *initS = NILP (init) || !STRINGP (init) ? nil :
0dc8cf50 1461 [NSString stringWithUTF8String: SSDATA (init)];
1afb1d07 1462 NSEvent *nxev;
edfda783 1463
7452b7bd 1464 check_window_system (NULL);
edfda783
AR
1465
1466 if (fileDelegate == nil)
1467 fileDelegate = [EmacsFileDelegate new];
1468
1469 [NSCursor setHiddenUntilMouseMoves: NO];
1470
1471 if ([dirS characterAtIndex: 0] == '~')
1472 dirS = [dirS stringByExpandingTildeInPath];
1473
c0342369 1474 panel = isSave ?
f2f7f42c 1475 (id)[EmacsSavePanel savePanel] : (id)[EmacsOpenPanel openPanel];
edfda783
AR
1476
1477 [panel setTitle: promptS];
1478
d7e642cc 1479 [panel setAllowsOtherFileTypes: YES];
edfda783
AR
1480 [panel setTreatsFilePackagesAsDirectories: YES];
1481 [panel setDelegate: fileDelegate];
1482
677d5c92 1483 if (! NILP (dir_only_p))
d7e642cc
JD
1484 {
1485 [panel setCanChooseDirectories: YES];
1486 [panel setCanChooseFiles: NO];
1487 }
c0342369 1488 else if (! isSave)
8f2906f5
JD
1489 {
1490 /* This is not quite what the documentation says, but it is compatible
1491 with the Gtk+ code. Also, the menu entry says "Open File...". */
1492 [panel setCanChooseDirectories: NO];
1493 [panel setCanChooseFiles: YES];
1494 }
677d5c92 1495
1afb1d07
JD
1496 block_input ();
1497 ns_fd_data.panel = panel;
1498 ns_fd_data.ret = NO;
d7e642cc
JD
1499#if defined (NS_IMPL_COCOA) && \
1500 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1501 if (! NILP (mustmatch) || ! NILP (dir_only_p))
1502 [panel setAllowedFileTypes: nil];
1503 if (dirS) [panel setDirectoryURL: [NSURL fileURLWithPath: dirS]];
1504 if (initS && NILP (Ffile_directory_p (init)))
1505 [panel setNameFieldStringValue: [initS lastPathComponent]];
1506 else
1507 [panel setNameFieldStringValue: @""];
677d5c92 1508
d7e642cc 1509#else
1afb1d07
JD
1510 ns_fd_data.no_types = NILP (mustmatch) && NILP (dir_only_p);
1511 ns_fd_data.dirS = dirS;
1512 ns_fd_data.initS = initS;
d7e642cc 1513#endif
edfda783 1514
1afb1d07
JD
1515 /* runModalForDirectory/runModal restarts the main event loop when done,
1516 so we must start an event loop and then pop up the file dialog.
1517 The file dialog may pop up a confirm dialog after Ok has been pressed,
1518 so we can not simply pop down on the Ok/Cancel press.
1519 */
1520 nxev = [NSEvent otherEventWithType: NSApplicationDefined
1521 location: NSMakePoint (0, 0)
1522 modifierFlags: 0
1523 timestamp: 0
1524 windowNumber: [[NSApp mainWindow] windowNumber]
1525 context: [NSApp context]
1526 subtype: 0
1527 data1: 0
1528 data2: NSAPP_DATA2_RUNFILEDIALOG];
1529
1530 [NSApp postEvent: nxev atStart: NO];
1531 while (ns_fd_data.panel != nil)
1532 [NSApp run];
1533
1534 ret = (ns_fd_data.ret == NSOKButton);
edfda783 1535
a37d34f3 1536 if (ret)
8f2906f5 1537 {
c0342369
JD
1538 NSString *str = ns_filename_from_panel (panel);
1539 if (! str) str = ns_directory_from_panel (panel);
8f2906f5
JD
1540 if (! str) ret = NO;
1541 else fname = build_string ([str UTF8String]);
1542 }
b066e6b6 1543
edfda783 1544 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
4d7e6e51 1545 unblock_input ();
edfda783 1546
ba301db3 1547 return ret ? fname : Qnil;
edfda783
AR
1548}
1549
f7dfe5d6
JD
1550const char *
1551ns_get_defaults_value (const char *key)
1552{
1553 NSObject *obj = [[NSUserDefaults standardUserDefaults]
1554 objectForKey: [NSString stringWithUTF8String: key]];
1555
1556 if (!obj) return NULL;
1557
1558 return [[NSString stringWithFormat: @"%@", obj] UTF8String];
1559}
1560
edfda783
AR
1561
1562DEFUN ("ns-get-resource", Fns_get_resource, Sns_get_resource, 2, 2, 0,
51d5ef9f
AR
1563 doc: /* Return the value of the property NAME of OWNER from the defaults database.
1564If OWNER is nil, Emacs is assumed. */)
5842a27b 1565 (Lisp_Object owner, Lisp_Object name)
edfda783
AR
1566{
1567 const char *value;
1568
7452b7bd 1569 check_window_system (NULL);
edfda783 1570 if (NILP (owner))
56d513e6 1571 owner = build_string([ns_app_name UTF8String]);
edfda783 1572 CHECK_STRING (name);
edfda783 1573
0dc8cf50 1574 value = ns_get_defaults_value (SSDATA (name));
edfda783
AR
1575
1576 if (value)
1577 return build_string (value);
edfda783
AR
1578 return Qnil;
1579}
1580
1581
1582DEFUN ("ns-set-resource", Fns_set_resource, Sns_set_resource, 3, 3, 0,
51d5ef9f 1583 doc: /* Set property NAME of OWNER to VALUE, from the defaults database.
d26fbe1a 1584If OWNER is nil, Emacs is assumed.
51d5ef9f 1585If VALUE is nil, the default is removed. */)
5842a27b 1586 (Lisp_Object owner, Lisp_Object name, Lisp_Object value)
edfda783 1587{
7452b7bd 1588 check_window_system (NULL);
edfda783 1589 if (NILP (owner))
56d513e6 1590 owner = build_string ([ns_app_name UTF8String]);
edfda783
AR
1591 CHECK_STRING (name);
1592 if (NILP (value))
1593 {
1594 [[NSUserDefaults standardUserDefaults] removeObjectForKey:
0dc8cf50 1595 [NSString stringWithUTF8String: SSDATA (name)]];
edfda783
AR
1596 }
1597 else
1598 {
1599 CHECK_STRING (value);
1600 [[NSUserDefaults standardUserDefaults] setObject:
0dc8cf50 1601 [NSString stringWithUTF8String: SSDATA (value)]
edfda783 1602 forKey: [NSString stringWithUTF8String:
0dc8cf50 1603 SSDATA (name)]];
edfda783
AR
1604 }
1605
1606 return Qnil;
1607}
1608
1609
952913d4
DN
1610DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
1611 Sx_server_max_request_size,
edfda783 1612 0, 1, 0,
51d5ef9f 1613 doc: /* This function is a no-op. It is only present for completeness. */)
91e8418b 1614 (Lisp_Object terminal)
edfda783 1615{
91e8418b 1616 check_ns_display_info (terminal);
edfda783
AR
1617 /* This function has no real equivalent under NeXTstep. Return nil to
1618 indicate this. */
1619 return Qnil;
1620}
1621
1622
9e50ff0c 1623DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
91e8418b
YM
1624 doc: /* Return the "vendor ID" string of Nextstep display server TERMINAL.
1625\(Labeling every distributor as a "vendor" embodies the false assumption
1626that operating systems cannot be developed and distributed noncommercially.)
1627The optional argument TERMINAL specifies which display to ask about.
1628TERMINAL should be a terminal object, a frame or a display name (a string).
1629If omitted or nil, that stands for the selected frame's display. */)
1630 (Lisp_Object terminal)
edfda783 1631{
91e8418b 1632 check_ns_display_info (terminal);
edfda783
AR
1633#ifdef NS_IMPL_GNUSTEP
1634 return build_string ("GNU");
1635#else
1636 return build_string ("Apple");
1637#endif
1638}
1639
1640
9e50ff0c 1641DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
91e8418b 1642 doc: /* Return the version numbers of the server of display TERMINAL.
f5497e45 1643The value is a list of three integers: the major and minor
91e8418b
YM
1644version numbers of the X Protocol in use, and the distributor-specific release
1645number. See also the function `x-server-vendor'.
f5497e45 1646
91e8418b
YM
1647The optional argument TERMINAL specifies which display to ask about.
1648TERMINAL should be a terminal object, a frame or a display name (a string).
f5497e45 1649If omitted or nil, that stands for the selected frame's display. */)
91e8418b 1650 (Lisp_Object terminal)
edfda783 1651{
91e8418b 1652 check_ns_display_info (terminal);
f5497e45
AR
1653 /*NOTE: it is unclear what would best correspond with "protocol";
1654 we return 10.3, meaning Panther, since this is roughly the
1655 level that GNUstep's APIs correspond to.
1656 The last number is where we distinguish between the Apple
1657 and GNUstep implementations ("distributor-specific release
1658 number") and give int'ized versions of major.minor. */
3de717bd 1659 return list3i (10, 3, ns_appkit_version_int ());
edfda783
AR
1660}
1661
1662
9e50ff0c 1663DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
91e8418b
YM
1664 doc: /* Return the number of screens on Nextstep display server TERMINAL.
1665The optional argument TERMINAL specifies which display to ask about.
1666TERMINAL should be a terminal object, a frame or a display name (a string).
1667If omitted or nil, that stands for the selected frame's display.
edfda783 1668
91e8418b
YM
1669Note: "screen" here is not in Nextstep terminology but in X11's. For
1670the number of physical monitors, use `(length
1671(display-monitor-attributes-list TERMINAL))' instead. */)
1672 (Lisp_Object terminal)
1673{
1674 check_ns_display_info (terminal);
1675 return make_number (1);
edfda783
AR
1676}
1677
1678
91e8418b
YM
1679DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0,
1680 doc: /* Return the height in millimeters of the Nextstep display TERMINAL.
1681The optional argument TERMINAL specifies which display to ask about.
1682TERMINAL should be a terminal object, a frame or a display name (a string).
1683If omitted or nil, that stands for the selected frame's display.
1684
1685On \"multi-monitor\" setups this refers to the height in millimeters for
1686all physical monitors associated with TERMINAL. To get information
1687for each physical monitor, use `display-monitor-attributes-list'. */)
1688 (Lisp_Object terminal)
edfda783 1689{
91e8418b
YM
1690 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
1691
1692 return make_number (x_display_pixel_height (dpyinfo) / (92.0/25.4));
edfda783
AR
1693}
1694
1695
91e8418b
YM
1696DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
1697 doc: /* Return the width in millimeters of the Nextstep display TERMINAL.
1698The optional argument TERMINAL specifies which display to ask about.
1699TERMINAL should be a terminal object, a frame or a display name (a string).
1700If omitted or nil, that stands for the selected frame's display.
1701
1702On \"multi-monitor\" setups this refers to the width in millimeters for
1703all physical monitors associated with TERMINAL. To get information
1704for each physical monitor, use `display-monitor-attributes-list'. */)
1705 (Lisp_Object terminal)
edfda783 1706{
91e8418b
YM
1707 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
1708
1709 return make_number (x_display_pixel_width (dpyinfo) / (92.0/25.4));
edfda783
AR
1710}
1711
1712
9e50ff0c 1713DEFUN ("x-display-backing-store", Fx_display_backing_store,
51d5ef9f 1714 Sx_display_backing_store, 0, 1, 0,
91e8418b 1715 doc: /* Return an indication of whether the Nextstep display TERMINAL does backing store.
d26fbe1a 1716The value may be `buffered', `retained', or `non-retained'.
91e8418b
YM
1717The optional argument TERMINAL specifies which display to ask about.
1718TERMINAL should be a terminal object, a frame or a display name (a string).
1719If omitted or nil, that stands for the selected frame's display. */)
1720 (Lisp_Object terminal)
edfda783 1721{
91e8418b
YM
1722 check_ns_display_info (terminal);
1723 switch ([ns_get_window (terminal) backingType])
edfda783
AR
1724 {
1725 case NSBackingStoreBuffered:
1726 return intern ("buffered");
1727 case NSBackingStoreRetained:
1728 return intern ("retained");
1729 case NSBackingStoreNonretained:
1730 return intern ("non-retained");
1731 default:
1732 error ("Strange value for backingType parameter of frame");
1733 }
1734 return Qnil; /* not reached, shut compiler up */
1735}
1736
1737
9e50ff0c 1738DEFUN ("x-display-visual-class", Fx_display_visual_class,
51d5ef9f 1739 Sx_display_visual_class, 0, 1, 0,
91e8418b 1740 doc: /* Return the visual class of the Nextstep display TERMINAL.
d26fbe1a
CY
1741The value is one of the symbols `static-gray', `gray-scale',
1742`static-color', `pseudo-color', `true-color', or `direct-color'.
91e8418b
YM
1743
1744The optional argument TERMINAL specifies which display to ask about.
1745TERMINAL should a terminal object, a frame or a display name (a string).
1746If omitted or nil, that stands for the selected frame's display. */)
1747 (Lisp_Object terminal)
edfda783
AR
1748{
1749 NSWindowDepth depth;
a37d34f3 1750
91e8418b
YM
1751 check_ns_display_info (terminal);
1752 depth = [[[NSScreen screens] objectAtIndex:0] depth];
edfda783
AR
1753
1754 if ( depth == NSBestDepth (NSCalibratedWhiteColorSpace, 2, 2, YES, NULL))
1755 return intern ("static-gray");
1756 else if (depth == NSBestDepth (NSCalibratedWhiteColorSpace, 8, 8, YES, NULL))
1757 return intern ("gray-scale");
1758 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 8, 8, YES, NULL))
1759 return intern ("pseudo-color");
1760 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 4, 12, NO, NULL))
1761 return intern ("true-color");
1762 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 8, 24, NO, NULL))
1763 return intern ("direct-color");
1764 else
d26fbe1a 1765 /* color mgmt as far as we do it is really handled by Nextstep itself anyway */
edfda783
AR
1766 return intern ("direct-color");
1767}
1768
1769
9e50ff0c 1770DEFUN ("x-display-save-under", Fx_display_save_under,
51d5ef9f 1771 Sx_display_save_under, 0, 1, 0,
91e8418b
YM
1772 doc: /* Return t if TERMINAL supports the save-under feature.
1773The optional argument TERMINAL specifies which display to ask about.
1774TERMINAL should be a terminal object, a frame or a display name (a string).
1775If omitted or nil, that stands for the selected frame's display. */)
1776 (Lisp_Object terminal)
1777{
1778 check_ns_display_info (terminal);
1779 switch ([ns_get_window (terminal) backingType])
edfda783
AR
1780 {
1781 case NSBackingStoreBuffered:
1782 return Qt;
1783
1784 case NSBackingStoreRetained:
1785 case NSBackingStoreNonretained:
1786 return Qnil;
1787
1788 default:
1789 error ("Strange value for backingType parameter of frame");
1790 }
1791 return Qnil; /* not reached, shut compiler up */
1792}
1793
1794
9e50ff0c 1795DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
51d5ef9f 1796 1, 3, 0,
4f4f2973 1797 doc: /* Open a connection to a display server.
d26fbe1a 1798DISPLAY is the name of the display to connect to.
4f4f2973
GM
1799Optional second arg XRM-STRING is a string of resources in xrdb format.
1800If the optional third arg MUST-SUCCEED is non-nil,
1801terminate Emacs if we can't open the connection.
1802\(In the Nextstep version, the last two arguments are currently ignored.) */)
5842a27b 1803 (Lisp_Object display, Lisp_Object resource_string, Lisp_Object must_succeed)
edfda783
AR
1804{
1805 struct ns_display_info *dpyinfo;
1806
1807 CHECK_STRING (display);
1808
1809 nxatoms_of_nsselect ();
1810 dpyinfo = ns_term_init (display);
1811 if (dpyinfo == 0)
1812 {
1813 if (!NILP (must_succeed))
1814 fatal ("OpenStep on %s not responding.\n",
0dc8cf50 1815 SSDATA (display));
edfda783
AR
1816 else
1817 error ("OpenStep on %s not responding.\n",
0dc8cf50 1818 SSDATA (display));
edfda783
AR
1819 }
1820
edfda783
AR
1821 return Qnil;
1822}
1823
1824
9e50ff0c 1825DEFUN ("x-close-connection", Fx_close_connection, Sx_close_connection,
51d5ef9f 1826 1, 1, 0,
91e8418b
YM
1827 doc: /* Close the connection to TERMINAL's Nextstep display server.
1828For TERMINAL, specify a terminal object, a frame or a display name (a
1829string). If TERMINAL is nil, that stands for the selected frame's
1830terminal. */)
1831 (Lisp_Object terminal)
edfda783 1832{
91e8418b 1833 check_ns_display_info (terminal);
edfda783
AR
1834 [NSApp terminate: NSApp];
1835 return Qnil;
1836}
1837
1838
9e50ff0c 1839DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
51d5ef9f 1840 doc: /* Return the list of display names that Emacs has connections to. */)
5842a27b 1841 (void)
edfda783 1842{
d141d701
DA
1843 Lisp_Object result = Qnil;
1844 struct ns_display_info *ndi;
edfda783 1845
d141d701
DA
1846 for (ndi = x_display_list; ndi; ndi = ndi->next)
1847 result = Fcons (XCAR (ndi->name_list_element), result);
edfda783
AR
1848
1849 return result;
1850}
1851
1852
1853DEFUN ("ns-hide-others", Fns_hide_others, Sns_hide_others,
51d5ef9f 1854 0, 0, 0,
b066e6b6 1855 doc: /* Hides all applications other than Emacs. */)
5842a27b 1856 (void)
edfda783 1857{
7452b7bd 1858 check_window_system (NULL);
edfda783
AR
1859 [NSApp hideOtherApplications: NSApp];
1860 return Qnil;
1861}
1862
1863DEFUN ("ns-hide-emacs", Fns_hide_emacs, Sns_hide_emacs,
51d5ef9f 1864 1, 1, 0,
b066e6b6
JB
1865 doc: /* If ON is non-nil, the entire Emacs application is hidden.
1866Otherwise if Emacs is hidden, it is unhidden.
1867If ON is equal to `activate', Emacs is unhidden and becomes
51d5ef9f 1868the active application. */)
5842a27b 1869 (Lisp_Object on)
edfda783 1870{
7452b7bd 1871 check_window_system (NULL);
edfda783
AR
1872 if (EQ (on, intern ("activate")))
1873 {
1874 [NSApp unhide: NSApp];
1875 [NSApp activateIgnoringOtherApps: YES];
1876 }
1877 else if (NILP (on))
1878 [NSApp unhide: NSApp];
1879 else
1880 [NSApp hide: NSApp];
1881 return Qnil;
1882}
1883
1884
1885DEFUN ("ns-emacs-info-panel", Fns_emacs_info_panel, Sns_emacs_info_panel,
51d5ef9f
AR
1886 0, 0, 0,
1887 doc: /* Shows the 'Info' or 'About' panel for Emacs. */)
5842a27b 1888 (void)
edfda783 1889{
7452b7bd 1890 check_window_system (NULL);
edfda783
AR
1891 [NSApp orderFrontStandardAboutPanel: nil];
1892 return Qnil;
1893}
1894
1895
edfda783 1896DEFUN ("ns-font-name", Fns_font_name, Sns_font_name, 1, 1, 0,
7877f373 1897 doc: /* Determine font PostScript or family name for font NAME.
d26fbe1a
CY
1898NAME should be a string containing either the font name or an XLFD
1899font descriptor. If string contains `fontset' and not
51d5ef9f 1900`fontset-startup', it is left alone. */)
5842a27b 1901 (Lisp_Object name)
edfda783
AR
1902{
1903 char *nm;
1904 CHECK_STRING (name);
0dc8cf50 1905 nm = SSDATA (name);
edfda783
AR
1906
1907 if (nm[0] != '-')
1908 return name;
1909 if (strstr (nm, "fontset") && !strstr (nm, "fontset-startup"))
1910 return name;
1911
0dc8cf50 1912 return build_string (ns_xlfd_to_fontname (SSDATA (name)));
edfda783
AR
1913}
1914
1915
1916DEFUN ("ns-list-colors", Fns_list_colors, Sns_list_colors, 0, 1, 0,
51d5ef9f
AR
1917 doc: /* Return a list of all available colors.
1918The optional argument FRAME is currently ignored. */)
5842a27b 1919 (Lisp_Object frame)
edfda783
AR
1920{
1921 Lisp_Object list = Qnil;
1922 NSEnumerator *colorlists;
1923 NSColorList *clist;
1924
1925 if (!NILP (frame))
1926 {
1927 CHECK_FRAME (frame);
1928 if (! FRAME_NS_P (XFRAME (frame)))
d26fbe1a 1929 error ("non-Nextstep frame used in `ns-list-colors'");
edfda783
AR
1930 }
1931
4d7e6e51 1932 block_input ();
edfda783
AR
1933
1934 colorlists = [[NSColorList availableColorLists] objectEnumerator];
0dc8cf50 1935 while ((clist = [colorlists nextObject]))
edfda783
AR
1936 {
1937 if ([[clist name] length] < 7 ||
1938 [[clist name] rangeOfString: @"PANTONE"].location == 0)
1939 {
1940 NSEnumerator *cnames = [[clist allKeys] reverseObjectEnumerator];
1941 NSString *cname;
0dc8cf50 1942 while ((cname = [cnames nextObject]))
edfda783
AR
1943 list = Fcons (build_string ([cname UTF8String]), list);
1944/* for (i = [[clist allKeys] count] - 1; i >= 0; i--)
1945 list = Fcons (build_string ([[[clist allKeys] objectAtIndex: i]
1946 UTF8String]), list); */
1947 }
1948 }
1949
4d7e6e51 1950 unblock_input ();
edfda783
AR
1951
1952 return list;
1953}
1954
1955
1956DEFUN ("ns-list-services", Fns_list_services, Sns_list_services, 0, 0, 0,
51d5ef9f 1957 doc: /* List available Nextstep services by querying NSApp. */)
5842a27b 1958 (void)
edfda783 1959{
699c10bd
JD
1960#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1961 /* You can't get services like this in 10.6+. */
1962 return Qnil;
1963#else
edfda783
AR
1964 Lisp_Object ret = Qnil;
1965 NSMenu *svcs;
c0342369 1966#ifdef NS_IMPL_COCOA
edfda783 1967 id delegate;
c0342369 1968#endif
edfda783 1969
7452b7bd 1970 check_window_system (NULL);
edfda783 1971 svcs = [[NSMenu alloc] initWithTitle: @"Services"];
335f5ae4 1972 [NSApp setServicesMenu: svcs];
edfda783
AR
1973 [NSApp registerServicesMenuSendTypes: ns_send_types
1974 returnTypes: ns_return_types];
1975
1976/* On Tiger, services menu updating was made lazier (waits for user to
1977 actually click on the menu), so we have to force things along: */
1978#ifdef NS_IMPL_COCOA
335f5ae4
JD
1979 delegate = [svcs delegate];
1980 if (delegate != nil)
edfda783 1981 {
335f5ae4
JD
1982 if ([delegate respondsToSelector: @selector (menuNeedsUpdate:)])
1983 [delegate menuNeedsUpdate: svcs];
1984 if ([delegate respondsToSelector:
1985 @selector (menu:updateItem:atIndex:shouldCancel:)])
edfda783 1986 {
335f5ae4
JD
1987 int i, len = [delegate numberOfItemsInMenu: svcs];
1988 for (i =0; i<len; i++)
1989 [svcs addItemWithTitle: @"" action: NULL keyEquivalent: @""];
1990 for (i =0; i<len; i++)
1991 if (![delegate menu: svcs
1992 updateItem: (NSMenuItem *)[svcs itemAtIndex: i]
1993 atIndex: i shouldCancel: NO])
1994 break;
edfda783
AR
1995 }
1996 }
1997#endif
1998
1999 [svcs setAutoenablesItems: NO];
2000#ifdef NS_IMPL_COCOA
2001 [svcs update]; /* on OS X, converts from '/' structure */
2002#endif
2003
2004 ret = interpret_services_menu (svcs, Qnil, ret);
2005 return ret;
699c10bd 2006#endif
edfda783
AR
2007}
2008
2009
2010DEFUN ("ns-perform-service", Fns_perform_service, Sns_perform_service,
51d5ef9f
AR
2011 2, 2, 0,
2012 doc: /* Perform Nextstep SERVICE on SEND.
d26fbe1a
CY
2013SEND should be either a string or nil.
2014The return value is the result of the service, as string, or nil if
51d5ef9f 2015there was no result. */)
5842a27b 2016 (Lisp_Object service, Lisp_Object send)
edfda783
AR
2017{
2018 id pb;
2019 NSString *svcName;
2020 char *utfStr;
edfda783
AR
2021
2022 CHECK_STRING (service);
7452b7bd 2023 check_window_system (NULL);
edfda783 2024
0dc8cf50 2025 utfStr = SSDATA (service);
edfda783
AR
2026 svcName = [NSString stringWithUTF8String: utfStr];
2027
2028 pb =[NSPasteboard pasteboardWithUniqueName];
2029 ns_string_to_pasteboard (pb, send);
2030
2031 if (NSPerformService (svcName, pb) == NO)
6c6f1994 2032 Fsignal (Qquit, list1 (build_string ("service not available")));
edfda783
AR
2033
2034 if ([[pb types] count] == 0)
2035 return build_string ("");
2036 return ns_string_from_pasteboard (pb);
2037}
2038
2039
2040DEFUN ("ns-convert-utf8-nfd-to-nfc", Fns_convert_utf8_nfd_to_nfc,
2041 Sns_convert_utf8_nfd_to_nfc, 1, 1, 0,
b066e6b6 2042 doc: /* Return an NFC string that matches the UTF-8 NFD string STR. */)
5842a27b 2043 (Lisp_Object str)
edfda783 2044{
f2f7f42c
AR
2045/* TODO: If GNUstep ever implements precomposedStringWithCanonicalMapping,
2046 remove this. */
edfda783 2047 NSString *utfStr;
0486beac
JD
2048 Lisp_Object ret = Qnil;
2049 NSAutoreleasePool *pool;
edfda783
AR
2050
2051 CHECK_STRING (str);
0486beac
JD
2052 pool = [[NSAutoreleasePool alloc] init];
2053 utfStr = [NSString stringWithUTF8String: SSDATA (str)];
c0342369 2054#ifdef NS_IMPL_COCOA
0486beac
JD
2055 if (utfStr)
2056 utfStr = [utfStr precomposedStringWithCanonicalMapping];
c0342369 2057#endif
0486beac
JD
2058 if (utfStr)
2059 {
2060 const char *cstr = [utfStr UTF8String];
2061 if (cstr)
2062 ret = build_string (cstr);
2063 }
2064
423d3b3f 2065 [pool release];
0486beac
JD
2066 if (NILP (ret))
2067 error ("Invalid UTF-8");
2068
423d3b3f 2069 return ret;
edfda783
AR
2070}
2071
2072
583ff3c3
AR
2073#ifdef NS_IMPL_COCOA
2074
2075/* Compile and execute the AppleScript SCRIPT and return the error
2076 status as function value. A zero is returned if compilation and
2077 execution is successful, in which case *RESULT is set to a Lisp
2078 string or a number containing the resulting script value. Otherwise,
2079 1 is returned. */
2080static int
3d608a86 2081ns_do_applescript (Lisp_Object script, Lisp_Object *result)
583ff3c3
AR
2082{
2083 NSAppleEventDescriptor *desc;
2084 NSDictionary* errorDict;
2085 NSAppleEventDescriptor* returnDescriptor = NULL;
2086
2087 NSAppleScript* scriptObject =
2088 [[NSAppleScript alloc] initWithSource:
0dc8cf50 2089 [NSString stringWithUTF8String: SSDATA (script)]];
583ff3c3
AR
2090
2091 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
2092 [scriptObject release];
b066e6b6 2093
583ff3c3 2094 *result = Qnil;
b066e6b6 2095
583ff3c3
AR
2096 if (returnDescriptor != NULL)
2097 {
2098 // successful execution
2099 if (kAENullEvent != [returnDescriptor descriptorType])
2100 {
2101 *result = Qt;
2102 // script returned an AppleScript result
2103 if ((typeUnicodeText == [returnDescriptor descriptorType]) ||
335f5ae4 2104#if defined (NS_IMPL_COCOA)
b066e6b6 2105 (typeUTF16ExternalRepresentation
583ff3c3 2106 == [returnDescriptor descriptorType]) ||
a39e2539 2107#endif
583ff3c3
AR
2108 (typeUTF8Text == [returnDescriptor descriptorType]) ||
2109 (typeCString == [returnDescriptor descriptorType]))
2110 {
2111 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2112 if (desc)
2113 *result = build_string([[desc stringValue] UTF8String]);
2114 }
2115 else
2116 {
2117 /* use typeUTF16ExternalRepresentation? */
2118 // coerce the result to the appropriate ObjC type
2119 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2120 if (desc)
2121 *result = make_number([desc int32Value]);
2122 }
2123 }
2124 }
2125 else
2126 {
2127 // no script result, return error
2128 return 1;
2129 }
2130 return 0;
2131}
2132
08e3161a
JD
2133/* Helper function called from sendEvent to run applescript
2134 from within the main event loop. */
2135
2136void
2137ns_run_ascript (void)
2138{
cf162aee
JD
2139 if (! NILP (as_script))
2140 as_status = ns_do_applescript (as_script, as_result);
2141 as_script = Qnil;
08e3161a
JD
2142}
2143
583ff3c3 2144DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0,
b066e6b6
JB
2145 doc: /* Execute AppleScript SCRIPT and return the result.
2146If compilation and execution are successful, the resulting script value
2147is returned as a string, a number or, in the case of other constructs, t.
2148In case the execution fails, an error is signaled. */)
5842a27b 2149 (Lisp_Object script)
583ff3c3
AR
2150{
2151 Lisp_Object result;
5fdb398c 2152 int status;
08e3161a 2153 NSEvent *nxev;
583ff3c3
AR
2154
2155 CHECK_STRING (script);
7452b7bd 2156 check_window_system (NULL);
583ff3c3 2157
4d7e6e51 2158 block_input ();
08e3161a
JD
2159
2160 as_script = script;
2161 as_result = &result;
2162
2163 /* executing apple script requires the event loop to run, otherwise
2164 errors aren't returned and executeAndReturnError hangs forever.
2165 Post an event that runs applescript and then start the event loop.
2166 The event loop is exited when the script is done. */
2167 nxev = [NSEvent otherEventWithType: NSApplicationDefined
2168 location: NSMakePoint (0, 0)
2169 modifierFlags: 0
2170 timestamp: 0
2171 windowNumber: [[NSApp mainWindow] windowNumber]
2172 context: [NSApp context]
2173 subtype: 0
2174 data1: 0
2175 data2: NSAPP_DATA2_RUNASSCRIPT];
2176
2177 [NSApp postEvent: nxev atStart: NO];
cf162aee
JD
2178
2179 // If there are other events, the event loop may exit. Keep running
677d5c92 2180 // until the script has been handled. */
cf162aee
JD
2181 while (! NILP (as_script))
2182 [NSApp run];
08e3161a
JD
2183
2184 status = as_status;
2185 as_status = 0;
08e3161a 2186 as_result = 0;
4d7e6e51 2187 unblock_input ();
583ff3c3
AR
2188 if (status == 0)
2189 return result;
2190 else if (!STRINGP (result))
2191 error ("AppleScript error %d", status);
2192 else
0dc8cf50 2193 error ("%s", SSDATA (result));
583ff3c3
AR
2194}
2195#endif
2196
2197
2198
edfda783
AR
2199/* ==========================================================================
2200
2201 Miscellaneous functions not called through hooks
2202
2203 ========================================================================== */
2204
3fe53a83 2205/* called from frame.c */
edfda783
AR
2206struct ns_display_info *
2207check_x_display_info (Lisp_Object frame)
2208{
2209 return check_ns_display_info (frame);
2210}
2211
2212
edfda783 2213void
3d608a86 2214x_set_scroll_bar_default_width (struct frame *f)
edfda783
AR
2215{
2216 int wid = FRAME_COLUMN_WIDTH (f);
2217 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = NS_SCROLL_BAR_WIDTH_DEFAULT;
2218 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) +
2219 wid - 1) / wid;
2220}
2221
3fe53a83 2222/* terms impl this instead of x-get-resource directly */
a6c2ee1b
DA
2223char *
2224x_get_string_resource (XrmDatabase rdb, const char *name, const char *class)
edfda783 2225{
6fb5f7da 2226 /* remove appname prefix; TODO: allow for !="Emacs" */
a6c2ee1b
DA
2227 const char *res, *toCheck = class + (!strncmp (class, "Emacs.", 6) ? 6 : 0);
2228
7452b7bd 2229 check_window_system (NULL);
edfda783 2230
386a49d3
AR
2231 if (inhibit_x_resources)
2232 /* --quick was passed, so this is a no-op. */
2233 return NULL;
edfda783 2234
f7dfe5d6 2235 res = ns_get_defaults_value (toCheck);
a6c2ee1b
DA
2236 return (!res ? NULL :
2237 (!c_strncasecmp (res, "YES", 3) ? "true" :
2238 (!c_strncasecmp (res, "NO", 2) ? "false" : (char *) res)));
edfda783
AR
2239}
2240
2241
2242Lisp_Object
2243x_get_focus_frame (struct frame *frame)
2244{
aad3612f 2245 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
edfda783
AR
2246 Lisp_Object nsfocus;
2247
9e50ff0c 2248 if (!dpyinfo->x_focus_frame)
edfda783
AR
2249 return Qnil;
2250
9e50ff0c 2251 XSETFRAME (nsfocus, dpyinfo->x_focus_frame);
edfda783
AR
2252 return nsfocus;
2253}
2254
edfda783
AR
2255/* ==========================================================================
2256
2257 Lisp definitions that, for whatever reason, we can't alias as 'ns-XXX'.
2258
2259 ========================================================================== */
2260
2261
952913d4 2262DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
4f4f2973
GM
2263 doc: /* Internal function called by `color-defined-p', which see.
2264\(Note that the Nextstep version of this function ignores FRAME.) */)
5842a27b 2265 (Lisp_Object color, Lisp_Object frame)
edfda783
AR
2266{
2267 NSColor * col;
7452b7bd 2268 check_window_system (NULL);
edfda783
AR
2269 return ns_lisp_to_color (color, &col) ? Qnil : Qt;
2270}
2271
2272
952913d4 2273DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
fb67c21b 2274 doc: /* Internal function called by `color-values', which see. */)
5842a27b 2275 (Lisp_Object color, Lisp_Object frame)
edfda783
AR
2276{
2277 NSColor * col;
c0342369 2278 EmacsCGFloat red, green, blue, alpha;
edfda783 2279
7452b7bd 2280 check_window_system (NULL);
edfda783
AR
2281 CHECK_STRING (color);
2282
2283 if (ns_lisp_to_color (color, &col))
2284 return Qnil;
2285
2286 [[col colorUsingColorSpaceName: NSCalibratedRGBColorSpace]
2287 getRed: &red green: &green blue: &blue alpha: &alpha];
3de717bd
DA
2288 return list3i (lrint (red * 65280), lrint (green * 65280),
2289 lrint (blue * 65280));
edfda783
AR
2290}
2291
2292
2293DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
4f4f2973 2294 doc: /* Internal function called by `display-color-p', which see. */)
91e8418b 2295 (Lisp_Object terminal)
edfda783
AR
2296{
2297 NSWindowDepth depth;
2298 NSString *colorSpace;
a37d34f3 2299
91e8418b
YM
2300 check_ns_display_info (terminal);
2301 depth = [[[NSScreen screens] objectAtIndex:0] depth];
edfda783
AR
2302 colorSpace = NSColorSpaceFromDepth (depth);
2303
2304 return [colorSpace isEqualToString: NSDeviceWhiteColorSpace]
2305 || [colorSpace isEqualToString: NSCalibratedWhiteColorSpace]
2306 ? Qnil : Qt;
2307}
2308
2309
91e8418b
YM
2310DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p,
2311 0, 1, 0,
51d5ef9f 2312 doc: /* Return t if the Nextstep display supports shades of gray.
d26fbe1a 2313Note that color displays do support shades of gray.
91e8418b
YM
2314The optional argument TERMINAL specifies which display to ask about.
2315TERMINAL should be a terminal object, a frame or a display name (a string).
2316If omitted or nil, that stands for the selected frame's display. */)
2317 (Lisp_Object terminal)
edfda783
AR
2318{
2319 NSWindowDepth depth;
7452b7bd 2320
91e8418b
YM
2321 check_ns_display_info (terminal);
2322 depth = [[[NSScreen screens] objectAtIndex:0] depth];
edfda783
AR
2323
2324 return NSBitsPerPixelFromDepth (depth) > 1 ? Qt : Qnil;
2325}
2326
2327
952913d4 2328DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
edfda783 2329 0, 1, 0,
91e8418b
YM
2330 doc: /* Return the width in pixels of the Nextstep display TERMINAL.
2331The optional argument TERMINAL specifies which display to ask about.
2332TERMINAL should be a terminal object, a frame or a display name (a string).
2333If omitted or nil, that stands for the selected frame's display.
2334
2335On \"multi-monitor\" setups this refers to the pixel width for all
2336physical monitors associated with TERMINAL. To get information for
2337each physical monitor, use `display-monitor-attributes-list'. */)
2338 (Lisp_Object terminal)
edfda783 2339{
91e8418b
YM
2340 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
2341
2342 return make_number (x_display_pixel_width (dpyinfo));
edfda783
AR
2343}
2344
2345
952913d4
DN
2346DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
2347 Sx_display_pixel_height, 0, 1, 0,
91e8418b
YM
2348 doc: /* Return the height in pixels of the Nextstep display TERMINAL.
2349The optional argument TERMINAL specifies which display to ask about.
2350TERMINAL should be a terminal object, a frame or a display name (a string).
2351If omitted or nil, that stands for the selected frame's display.
2352
2353On \"multi-monitor\" setups this refers to the pixel height for all
2354physical monitors associated with TERMINAL. To get information for
2355each physical monitor, use `display-monitor-attributes-list'. */)
2356 (Lisp_Object terminal)
edfda783 2357{
91e8418b
YM
2358 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
2359
2360 return make_number (x_display_pixel_height (dpyinfo));
edfda783
AR
2361}
2362
4465bfb4 2363#ifdef NS_IMPL_COCOA
ceb486d4
JD
2364
2365/* Returns the name for the screen that OBJ represents, or NULL.
4465bfb4
JD
2366 Caller must free return value.
2367*/
583ff3c3 2368
6799bb26 2369static char *
ceb486d4 2370ns_get_name_from_ioreg (io_object_t obj)
4465bfb4
JD
2371{
2372 char *name = NULL;
ceb486d4 2373
4465bfb4 2374 NSDictionary *info = (NSDictionary *)
ceb486d4
JD
2375 IODisplayCreateInfoDictionary (obj, kIODisplayOnlyPreferredName);
2376 NSDictionary *names = [info objectForKey:
2377 [NSString stringWithUTF8String:
2378 kDisplayProductName]];
2379
2380 if ([names count] > 0)
2381 {
2382 NSString *n = [names objectForKey: [[names allKeys]
2383 objectAtIndex:0]];
2384 if (n != nil) name = xstrdup ([n UTF8String]);
2385 }
d26fbe1a 2386
4465bfb4 2387 [info release];
ceb486d4
JD
2388
2389 return name;
2390}
2391
2392/* Returns the name for the screen that DID came from, or NULL.
2393 Caller must free return value.
2394*/
2395
2396static char *
2397ns_screen_name (CGDirectDisplayID did)
2398{
2399 char *name = NULL;
2400
2401#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
2402 mach_port_t masterPort;
2403 io_iterator_t it;
2404 io_object_t obj;
2405
2406 // CGDisplayIOServicePort is deprecated. Do it another (harder) way.
2407
2408 if (IOMasterPort (MACH_PORT_NULL, &masterPort) != kIOReturnSuccess
2409 || IOServiceGetMatchingServices (masterPort,
2410 IOServiceMatching ("IONDRVDevice"),
2411 &it) != kIOReturnSuccess)
2412 return name;
2413
2414 /* Must loop until we find a name. Many devices can have the same unit
2415 number (represents different GPU parts), but only one has a name. */
2416 while (! name && (obj = IOIteratorNext (it)))
2417 {
2418 CFMutableDictionaryRef props;
2419 const void *val;
2420
2421 if (IORegistryEntryCreateCFProperties (obj,
2422 &props,
2423 kCFAllocatorDefault,
2424 kNilOptions) == kIOReturnSuccess
2425 && props != nil
2426 && (val = CFDictionaryGetValue(props, @"IOFBDependentIndex")))
2427 {
2428 unsigned nr = [(NSNumber *)val unsignedIntegerValue];
2429 if (nr == CGDisplayUnitNumber (did))
2430 name = ns_get_name_from_ioreg (obj);
2431 }
2432
2433 CFRelease (props);
2434 IOObjectRelease (obj);
2435 }
2436
2437 IOObjectRelease (it);
2438
2439#else
2440
2441 name = ns_get_name_from_ioreg (CGDisplayIOServicePort (did));
2442
2443#endif
4465bfb4
JD
2444 return name;
2445}
2446#endif
2447
2448static Lisp_Object
2449ns_make_monitor_attribute_list (struct MonitorInfo *monitors,
2450 int n_monitors,
2451 int primary_monitor,
2452 const char *source)
2453{
2454 Lisp_Object monitor_frames = Fmake_vector (make_number (n_monitors), Qnil);
6799bb26 2455 Lisp_Object frame, rest;
4465bfb4
JD
2456 NSArray *screens = [NSScreen screens];
2457 int i;
2458
2459 FOR_EACH_FRAME (rest, frame)
2460 {
2461 struct frame *f = XFRAME (frame);
2462
2463 if (FRAME_NS_P (f))
2464 {
2465 NSView *view = FRAME_NS_VIEW (f);
2466 NSScreen *screen = [[view window] screen];
2467 NSUInteger k;
2468
2469 i = -1;
2470 for (k = 0; i == -1 && k < [screens count]; ++k)
2471 {
2472 if ([screens objectAtIndex: k] == screen)
2473 i = (int)k;
2474 }
2475
2476 if (i > -1)
2477 ASET (monitor_frames, i, Fcons (frame, AREF (monitor_frames, i)));
2478 }
2479 }
2480
6799bb26
JD
2481 return make_monitor_attribute_list (monitors, n_monitors, primary_monitor,
2482 monitor_frames, source);
4465bfb4
JD
2483}
2484
2485DEFUN ("ns-display-monitor-attributes-list",
2486 Fns_display_monitor_attributes_list,
2487 Sns_display_monitor_attributes_list,
2488 0, 1, 0,
2489 doc: /* Return a list of physical monitor attributes on the X display TERMINAL.
2490
2491The optional argument TERMINAL specifies which display to ask about.
2492TERMINAL should be a terminal object, a frame or a display name (a string).
2493If omitted or nil, that stands for the selected frame's display.
2494
2495In addition to the standard attribute keys listed in
2496`display-monitor-attributes-list', the following keys are contained in
2497the attributes:
2498
2499 source -- String describing the source from which multi-monitor
2500 information is obtained, \"NS\" is always the source."
2501
2502Internal use only, use `display-monitor-attributes-list' instead. */)
2503 (Lisp_Object terminal)
edfda783 2504{
4465bfb4
JD
2505 struct terminal *term = get_terminal (terminal, 1);
2506 NSArray *screens;
2507 NSUInteger i, n_monitors;
2508 struct MonitorInfo *monitors;
2509 Lisp_Object attributes_list = Qnil;
2510 CGFloat primary_display_height = 0;
edfda783 2511
4465bfb4
JD
2512 if (term->type != output_ns)
2513 return Qnil;
2514
2515 screens = [NSScreen screens];
2516 n_monitors = [screens count];
2517 if (n_monitors == 0)
474217c8
CY
2518 return Qnil;
2519
7d652d97 2520 monitors = xzalloc (n_monitors * sizeof *monitors);
4465bfb4
JD
2521
2522 for (i = 0; i < [screens count]; ++i)
2523 {
2524 NSScreen *s = [screens objectAtIndex:i];
2525 struct MonitorInfo *m = &monitors[i];
2526 NSRect fr = [s frame];
2527 NSRect vfr = [s visibleFrame];
4465bfb4
JD
2528 short y, vy;
2529
2530#ifdef NS_IMPL_COCOA
c0342369 2531 NSDictionary *dict = [s deviceDescription];
4465bfb4
JD
2532 NSNumber *nid = [dict objectForKey:@"NSScreenNumber"];
2533 CGDirectDisplayID did = [nid unsignedIntValue];
2534#endif
2535 if (i == 0)
2536 {
2537 primary_display_height = fr.size.height;
2538 y = (short) fr.origin.y;
2539 vy = (short) vfr.origin.y;
2540 }
2541 else
2542 {
2543 // Flip y coordinate as NS has y starting from the bottom.
2544 y = (short) (primary_display_height - fr.size.height - fr.origin.y);
2545 vy = (short) (primary_display_height -
2546 vfr.size.height - vfr.origin.y);
2547 }
cf7a0de6 2548
4465bfb4
JD
2549 m->geom.x = (short) fr.origin.x;
2550 m->geom.y = y;
2551 m->geom.width = (unsigned short) fr.size.width;
2552 m->geom.height = (unsigned short) fr.size.height;
2553
2554 m->work.x = (short) vfr.origin.x;
2555 // y is flipped on NS, so vy - y are pixels missing at the bottom,
2556 // and fr.size.height - vfr.size.height are pixels missing in total.
2557 // Pixels missing at top are
2558 // fr.size.height - vfr.size.height - vy + y.
2559 // work.y is then pixels missing at top + y.
2560 m->work.y = (short) (fr.size.height - vfr.size.height) - vy + y + y;
2561 m->work.width = (unsigned short) vfr.size.width;
2562 m->work.height = (unsigned short) vfr.size.height;
2563
2564#ifdef NS_IMPL_COCOA
2565 m->name = ns_screen_name (did);
2566
2567 {
2568 CGSize mms = CGDisplayScreenSize (did);
2569 m->mm_width = (int) mms.width;
2570 m->mm_height = (int) mms.height;
2571 }
2572
2573#else
2574 // Assume 92 dpi as x-display-mm-height/x-display-mm-width does.
2575 m->mm_width = (int) (25.4 * fr.size.width / 92.0);
2576 m->mm_height = (int) (25.4 * fr.size.height / 92.0);
2577#endif
2578 }
2579
2580 // Primary monitor is always first for NS.
2581 attributes_list = ns_make_monitor_attribute_list (monitors, n_monitors,
2582 0, "NS");
edfda783 2583
4465bfb4
JD
2584 free_monitors (monitors, n_monitors);
2585 return attributes_list;
edfda783
AR
2586}
2587
2588
952913d4 2589DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
edfda783 2590 0, 1, 0,
91e8418b
YM
2591 doc: /* Return the number of bitplanes of the Nextstep display TERMINAL.
2592The optional argument TERMINAL specifies which display to ask about.
2593TERMINAL should be a terminal object, a frame or a display name (a string).
51d5ef9f 2594If omitted or nil, that stands for the selected frame's display. */)
91e8418b 2595 (Lisp_Object terminal)
edfda783 2596{
91e8418b 2597 check_ns_display_info (terminal);
edfda783 2598 return make_number
91e8418b 2599 (NSBitsPerPixelFromDepth ([[[NSScreen screens] objectAtIndex:0] depth]));
edfda783
AR
2600}
2601
2602
91e8418b
YM
2603DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
2604 0, 1, 0,
2605 doc: /* Returns the number of color cells of the Nextstep display TERMINAL.
2606The optional argument TERMINAL specifies which display to ask about.
2607TERMINAL should be a terminal object, a frame or a display name (a string).
51d5ef9f 2608If omitted or nil, that stands for the selected frame's display. */)
91e8418b 2609 (Lisp_Object terminal)
edfda783 2610{
91e8418b 2611 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
edfda783
AR
2612 /* We force 24+ bit depths to 24-bit to prevent an overflow. */
2613 return make_number (1 << min (dpyinfo->n_planes, 24));
2614}
2615
2616
2617/* Unused dummy def needed for compatibility. */
2618Lisp_Object tip_frame;
2619
6fb5f7da 2620/* TODO: move to xdisp or similar */
edfda783 2621static void
3d608a86
J
2622compute_tip_xy (struct frame *f,
2623 Lisp_Object parms,
2624 Lisp_Object dx,
2625 Lisp_Object dy,
2626 int width,
2627 int height,
2628 int *root_x,
2629 int *root_y)
edfda783
AR
2630{
2631 Lisp_Object left, top;
2632 EmacsView *view = FRAME_NS_VIEW (f);
18da0d8a 2633 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
edfda783 2634 NSPoint pt;
b066e6b6 2635
edfda783
AR
2636 /* Start with user-specified or mouse position. */
2637 left = Fcdr (Fassq (Qleft, parms));
edfda783 2638 top = Fcdr (Fassq (Qtop, parms));
edfda783 2639
7a18115b
J
2640 if (!INTEGERP (left) || !INTEGERP (top))
2641 {
18da0d8a
DA
2642 pt.x = dpyinfo->last_mouse_motion_x;
2643 pt.y = dpyinfo->last_mouse_motion_y;
7a18115b
J
2644 /* Convert to screen coordinates */
2645 pt = [view convertPoint: pt toView: nil];
2646 pt = [[view window] convertBaseToScreen: pt];
2647 }
2648 else
2649 {
2650 /* Absolute coordinates. */
2651 pt.x = XINT (left);
aad3612f 2652 pt.y = x_display_pixel_height (FRAME_DISPLAY_INFO (f)) - XINT (top)
7a18115b
J
2653 - height;
2654 }
5fdb398c 2655
edfda783 2656 /* Ensure in bounds. (Note, screen origin = lower left.) */
7a18115b
J
2657 if (INTEGERP (left))
2658 *root_x = pt.x;
2659 else if (pt.x + XINT (dx) <= 0)
edfda783 2660 *root_x = 0; /* Can happen for negative dx */
889bd438 2661 else if (pt.x + XINT (dx) + width
aad3612f 2662 <= x_display_pixel_width (FRAME_DISPLAY_INFO (f)))
edfda783
AR
2663 /* It fits to the right of the pointer. */
2664 *root_x = pt.x + XINT (dx);
2665 else if (width + XINT (dx) <= pt.x)
2666 /* It fits to the left of the pointer. */
2667 *root_x = pt.x - width - XINT (dx);
2668 else
2669 /* Put it left justified on the screen -- it ought to fit that way. */
2670 *root_x = 0;
2671
7a18115b
J
2672 if (INTEGERP (top))
2673 *root_y = pt.y;
2674 else if (pt.y - XINT (dy) - height >= 0)
edfda783
AR
2675 /* It fits below the pointer. */
2676 *root_y = pt.y - height - XINT (dy);
889bd438 2677 else if (pt.y + XINT (dy) + height
aad3612f 2678 <= x_display_pixel_height (FRAME_DISPLAY_INFO (f)))
edfda783
AR
2679 /* It fits above the pointer */
2680 *root_y = pt.y + XINT (dy);
2681 else
2682 /* Put it on the top. */
aad3612f 2683 *root_y = x_display_pixel_height (FRAME_DISPLAY_INFO (f)) - height;
edfda783
AR
2684}
2685
2686
2687DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
b066e6b6 2688 doc: /* Show STRING in a \"tooltip\" window on frame FRAME.
edfda783
AR
2689A tooltip window is a small window displaying a string.
2690
4f4f2973
GM
2691This is an internal function; Lisp code should call `tooltip-show'.
2692
edfda783
AR
2693FRAME nil or omitted means use the selected frame.
2694
2695PARMS is an optional list of frame parameters which can be used to
2696change the tooltip's appearance.
2697
2698Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
2699means use the default timeout of 5 seconds.
2700
2701If the list of frame parameters PARMS contains a `left' parameter,
2702the tooltip is displayed at that x-position. Otherwise it is
2703displayed at the mouse position, with offset DX added (default is 5 if
2704DX isn't specified). Likewise for the y-position; if a `top' frame
2705parameter is specified, it determines the y-position of the tooltip
2706window, otherwise it is displayed at the mouse position, with offset
2707DY added (default is -10).
2708
2709A tooltip's maximum size is specified by `x-max-tooltip-size'.
2710Text larger than the specified size is clipped. */)
5842a27b 2711 (Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy)
edfda783
AR
2712{
2713 int root_x, root_y;
2714 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
d311d28c 2715 ptrdiff_t count = SPECPDL_INDEX ();
edfda783
AR
2716 struct frame *f;
2717 char *str;
2718 NSSize size;
2719
2720 specbind (Qinhibit_redisplay, Qt);
2721
2722 GCPRO4 (string, parms, frame, timeout);
2723
2724 CHECK_STRING (string);
0dc8cf50 2725 str = SSDATA (string);
7452b7bd 2726 f = decode_window_system_frame (frame);
edfda783
AR
2727 if (NILP (timeout))
2728 timeout = make_number (5);
2729 else
2730 CHECK_NATNUM (timeout);
2731
2732 if (NILP (dx))
2733 dx = make_number (5);
2734 else
2735 CHECK_NUMBER (dx);
2736
2737 if (NILP (dy))
2738 dy = make_number (-10);
2739 else
2740 CHECK_NUMBER (dy);
2741
4d7e6e51 2742 block_input ();
edfda783
AR
2743 if (ns_tooltip == nil)
2744 ns_tooltip = [[EmacsTooltip alloc] init];
2745 else
2746 Fx_hide_tip ();
2747
2748 [ns_tooltip setText: str];
2749 size = [ns_tooltip frame].size;
2750
2751 /* Move the tooltip window where the mouse pointer is. Resize and
2752 show it. */
2753 compute_tip_xy (f, parms, dx, dy, (int)size.width, (int)size.height,
2754 &root_x, &root_y);
2755
2756 [ns_tooltip showAtX: root_x Y: root_y for: XINT (timeout)];
4d7e6e51 2757 unblock_input ();
edfda783
AR
2758
2759 UNGCPRO;
2760 return unbind_to (count, Qnil);
2761}
2762
2763
2764DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
2765 doc: /* Hide the current tooltip window, if there is any.
2766Value is t if tooltip was open, nil otherwise. */)
5842a27b 2767 (void)
edfda783
AR
2768{
2769 if (ns_tooltip == nil || ![ns_tooltip isActive])
2770 return Qnil;
2771 [ns_tooltip hide];
2772 return Qt;
2773}
2774
2775
cc98b6a0
DN
2776/* ==========================================================================
2777
2778 Class implementations
2779
2780 ========================================================================== */
2781
edbdcec0
JD
2782/*
2783 Handle arrow/function/control keys and copy/paste/cut in file dialogs.
a37d34f3 2784 Return YES if handled, NO if not.
edbdcec0
JD
2785 */
2786static BOOL
2787handlePanelKeys (NSSavePanel *panel, NSEvent *theEvent)
2788{
2789 NSString *s;
2790 int i;
2791 BOOL ret = NO;
2792
2793 if ([theEvent type] != NSKeyDown) return NO;
2794 s = [theEvent characters];
2795
2796 for (i = 0; i < [s length]; ++i)
2797 {
2798 int ch = (int) [s characterAtIndex: i];
2799 switch (ch)
2800 {
2801 case NSHomeFunctionKey:
2802 case NSDownArrowFunctionKey:
2803 case NSUpArrowFunctionKey:
2804 case NSLeftArrowFunctionKey:
2805 case NSRightArrowFunctionKey:
2806 case NSPageUpFunctionKey:
2807 case NSPageDownFunctionKey:
2808 case NSEndFunctionKey:
9d3f2fc2
JD
2809 /* Don't send command modified keys, as those are handled in the
2810 performKeyEquivalent method of the super class.
2811 */
2812 if (! ([theEvent modifierFlags] & NSCommandKeyMask))
2813 {
2814 [panel sendEvent: theEvent];
2815 ret = YES;
2816 }
edbdcec0
JD
2817 break;
2818 /* As we don't have the standard key commands for
2819 copy/paste/cut/select-all in our edit menu, we must handle
2820 them here. TODO: handle Emacs key bindings for copy/cut/select-all
2821 here, paste works, because we have that in our Edit menu.
2822 I.e. refactor out code in nsterm.m, keyDown: to figure out the
2823 correct modifier.
2824 */
2825 case 'x': // Cut
2826 case 'c': // Copy
2827 case 'v': // Paste
2828 case 'a': // Select all
2829 if ([theEvent modifierFlags] & NSCommandKeyMask)
2830 {
2831 [NSApp sendAction:
2832 (ch == 'x'
2833 ? @selector(cut:)
2834 : (ch == 'c'
2835 ? @selector(copy:)
2836 : (ch == 'v'
2837 ? @selector(paste:)
2838 : @selector(selectAll:))))
2839 to:nil from:panel];
2840 ret = YES;
2841 }
2842 default:
2843 // Send all control keys, as the text field supports C-a, C-f, C-e
2844 // C-b and more.
2845 if ([theEvent modifierFlags] & NSControlKeyMask)
2846 {
2847 [panel sendEvent: theEvent];
2848 ret = YES;
2849 }
2850 break;
2851 }
2852 }
2853
2854
2855 return ret;
2856}
cc98b6a0
DN
2857
2858@implementation EmacsSavePanel
edbdcec0
JD
2859- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
2860{
2861 BOOL ret = handlePanelKeys (self, theEvent);
2862 if (! ret)
2863 ret = [super performKeyEquivalent:theEvent];
2864 return ret;
2865}
cc98b6a0
DN
2866@end
2867
2868
2869@implementation EmacsOpenPanel
edbdcec0
JD
2870- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
2871{
2872 // NSOpenPanel inherits NSSavePanel, so passing self is OK.
2873 BOOL ret = handlePanelKeys (self, theEvent);
2874 if (! ret)
2875 ret = [super performKeyEquivalent:theEvent];
2876 return ret;
2877}
cc98b6a0
DN
2878@end
2879
2880
2881@implementation EmacsFileDelegate
2882/* --------------------------------------------------------------------------
2883 Delegate methods for Open/Save panels
2884 -------------------------------------------------------------------------- */
2885- (BOOL)panel: (id)sender isValidFilename: (NSString *)filename
2886{
2887 return YES;
2888}
2889- (BOOL)panel: (id)sender shouldShowFilename: (NSString *)filename
2890{
2891 return YES;
2892}
2893- (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
2894 confirmed: (BOOL)okFlag
2895{
2896 return filename;
2897}
2898@end
2899
2900#endif
2901
ba301db3 2902
edfda783
AR
2903/* ==========================================================================
2904
2905 Lisp interface declaration
2906
2907 ========================================================================== */
2908
2909
2910void
3d608a86 2911syms_of_nsfns (void)
edfda783 2912{
088dcc3e 2913 Qfontsize = intern_c_string ("fontsize");
edfda783
AR
2914 staticpro (&Qfontsize);
2915
fb9d0f5a 2916 DEFVAR_LISP ("ns-icon-type-alist", Vns_icon_type_alist,
51d5ef9f 2917 doc: /* Alist of elements (REGEXP . IMAGE) for images of icons associated to frames.
d26fbe1a
CY
2918If the title of a frame matches REGEXP, then IMAGE.tiff is
2919selected as the image of the icon representing the frame when it's
2920miniaturized. If an element is t, then Emacs tries to select an icon
2921based on the filetype of the visited file.
2922
2923The images have to be installed in a folder called English.lproj in the
2924Emacs folder. You have to restart Emacs after installing new icons.
2925
2926Example: Install an icon Gnus.tiff and execute the following code
2927
2928 (setq ns-icon-type-alist
2929 (append ns-icon-type-alist
2930 '((\"^\\\\*\\\\(Group\\\\*$\\\\|Summary \\\\|Article\\\\*$\\\\)\"
2931 . \"Gnus\"))))
2932
2933When you miniaturize a Group, Summary or Article frame, Gnus.tiff will
51d5ef9f 2934be used as the image of the icon representing the frame. */);
6c6f1994 2935 Vns_icon_type_alist = list1 (Qt);
edfda783 2936
fb9d0f5a 2937 DEFVAR_LISP ("ns-version-string", Vns_version_string,
cb83c00b 2938 doc: /* Toolkit version for NS Windowing. */);
f5497e45 2939 Vns_version_string = ns_appkit_version_str ();
cb83c00b 2940
edfda783
AR
2941 defsubr (&Sns_read_file_name);
2942 defsubr (&Sns_get_resource);
2943 defsubr (&Sns_set_resource);
2944 defsubr (&Sxw_display_color_p); /* this and next called directly by C code */
2945 defsubr (&Sx_display_grayscale_p);
edfda783
AR
2946 defsubr (&Sns_font_name);
2947 defsubr (&Sns_list_colors);
74876614 2948#ifdef NS_IMPL_COCOA
583ff3c3 2949 defsubr (&Sns_do_applescript);
74876614 2950#endif
952913d4
DN
2951 defsubr (&Sxw_color_defined_p);
2952 defsubr (&Sxw_color_values);
2953 defsubr (&Sx_server_max_request_size);
9e50ff0c
DN
2954 defsubr (&Sx_server_vendor);
2955 defsubr (&Sx_server_version);
952913d4
DN
2956 defsubr (&Sx_display_pixel_width);
2957 defsubr (&Sx_display_pixel_height);
4465bfb4 2958 defsubr (&Sns_display_monitor_attributes_list);
9e50ff0c
DN
2959 defsubr (&Sx_display_mm_width);
2960 defsubr (&Sx_display_mm_height);
2961 defsubr (&Sx_display_screens);
952913d4
DN
2962 defsubr (&Sx_display_planes);
2963 defsubr (&Sx_display_color_cells);
9e50ff0c
DN
2964 defsubr (&Sx_display_visual_class);
2965 defsubr (&Sx_display_backing_store);
2966 defsubr (&Sx_display_save_under);
2967 defsubr (&Sx_create_frame);
9e50ff0c
DN
2968 defsubr (&Sx_open_connection);
2969 defsubr (&Sx_close_connection);
2970 defsubr (&Sx_display_list);
edfda783
AR
2971
2972 defsubr (&Sns_hide_others);
2973 defsubr (&Sns_hide_emacs);
2974 defsubr (&Sns_emacs_info_panel);
2975 defsubr (&Sns_list_services);
2976 defsubr (&Sns_perform_service);
2977 defsubr (&Sns_convert_utf8_nfd_to_nfc);
edfda783
AR
2978 defsubr (&Sns_popup_font_panel);
2979 defsubr (&Sns_popup_color_panel);
2980
2981 defsubr (&Sx_show_tip);
2982 defsubr (&Sx_hide_tip);
2983
08e3161a
JD
2984 as_status = 0;
2985 as_script = Qnil;
2986 as_result = 0;
edfda783 2987}