* lisp/electric.el (electric-indent-just-newline): New command.
[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
AR
405 else
406 /* explicit name and no icon-name -> explicit_name */
407 if (f->explicit_name)
e69b0960 408 arg = f->name;
edfda783
AR
409 else
410 {
411 /* no explicit name and no icon-name ->
412 name has to be rebuild from icon_title_format */
413 windows_or_buffers_changed++;
414 return;
415 }
416 }
417
418 /* Don't change the name if it's already NAME. */
419 if ([[view window] miniwindowTitle] &&
420 ([[[view window] miniwindowTitle]
421 isEqualToString: [NSString stringWithUTF8String:
0dc8cf50 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
edfda783 454 if ([[view window] miniwindowTitle] &&
5bbb4727
JD
455 ! [[[view window] miniwindowTitle] isEqualToString: str])
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))
472 update_mode_lines = 1;
473
474 f->explicit_name = ! NILP (name);
475 }
476 else if (f->explicit_name)
477 return;
478
479 if (NILP (name))
56d513e6 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
AR
489
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
537 update_mode_lines = 1;
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
706 x_set_window_size (f, 0, f->text_cols, f->text_lines);
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 */
cc98b6a0 949 x_set_menu_bar_lines,
89e2438a
DN
950 x_set_mouse_color,
951 x_explicitly_set_name,
edfda783 952 x_set_scroll_bar_width, /* generic OK */
89e2438a 953 x_set_title,
edfda783
AR
954 x_set_unsplittable, /* generic OK */
955 x_set_vertical_scroll_bars, /* generic OK */
956 x_set_visibility, /* generic OK */
cc98b6a0 957 x_set_tool_bar_lines,
edfda783
AR
958 0, /* x_set_scroll_bar_foreground, will ignore (not possible on NS) */
959 0, /* x_set_scroll_bar_background, will ignore (not possible on NS) */
960 x_set_screen_gamma, /* generic OK */
961 x_set_line_spacing, /* generic OK, sets f->extra_line_spacing to int */
962 x_set_fringe_width, /* generic OK */
963 x_set_fringe_width, /* generic OK */
964 0, /* x_set_wait_for_wm, will ignore */
dd946752 965 x_set_fullscreen, /* generic OK */
dee721c0 966 x_set_font_backend, /* generic OK */
cad9ef74 967 x_set_alpha,
5fdb398c
PE
968 0, /* x_set_sticky */
969 0, /* x_set_tool_bar_position */
edfda783
AR
970};
971
972
a97f8f3f
JD
973/* Handler for signals raised during x_create_frame.
974 FRAME is the frame which is partially constructed. */
975
27e498e6 976static void
a97f8f3f
JD
977unwind_create_frame (Lisp_Object frame)
978{
979 struct frame *f = XFRAME (frame);
980
981 /* If frame is already dead, nothing to do. This can happen if the
982 display is disconnected after the frame has become official, but
983 before x_create_frame removes the unwind protect. */
984 if (!FRAME_LIVE_P (f))
27e498e6 985 return;
a97f8f3f
JD
986
987 /* If frame is ``official'', nothing to do. */
97f18cc8 988 if (NILP (Fmemq (frame, Vframe_list)))
a97f8f3f 989 {
ef884f23 990#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
aad3612f 991 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
a97f8f3f
JD
992#endif
993
994 x_free_frame_resources (f);
995 free_glyphs (f);
996
ef884f23 997#ifdef GLYPH_DEBUG
a97f8f3f 998 /* Check that reference counts are indeed correct. */
ef884f23 999 eassert (dpyinfo->terminal->image_cache->refcount == image_cache_refcount);
a97f8f3f 1000#endif
a97f8f3f 1001 }
a97f8f3f
JD
1002}
1003
a0c3fad0
JD
1004/*
1005 * Read geometry related parameters from preferences if not in PARMS.
1006 * Returns the union of parms and any preferences read.
1007 */
a97f8f3f 1008
a0c3fad0
JD
1009static Lisp_Object
1010get_geometry_from_preferences (struct ns_display_info *dpyinfo,
1011 Lisp_Object parms)
1012{
1013 struct {
1014 const char *val;
1015 const char *cls;
1016 Lisp_Object tem;
1017 } r[] = {
1018 { "width", "Width", Qwidth },
1019 { "height", "Height", Qheight },
1020 { "left", "Left", Qleft },
1021 { "top", "Top", Qtop },
1022 };
1023
1024 int i;
1025 for (i = 0; i < sizeof (r)/sizeof (r[0]); ++i)
1026 {
1027 if (NILP (Fassq (r[i].tem, parms)))
1028 {
1029 Lisp_Object value
1030 = x_get_arg (dpyinfo, parms, r[i].tem, r[i].val, r[i].cls,
1031 RES_TYPE_NUMBER);
1032 if (! EQ (value, Qunbound))
1033 parms = Fcons (Fcons (r[i].tem, value), parms);
1034 }
1035 }
a97f8f3f 1036
a0c3fad0
JD
1037 return parms;
1038}
cb83c00b
AR
1039
1040/* ==========================================================================
1041
1042 Lisp definitions
1043
1044 ========================================================================== */
1045
9e50ff0c 1046DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
edfda783 1047 1, 1, 0,
a97f8f3f 1048 doc: /* Make a new Nextstep window, called a "frame" in Emacs terms.
d26fbe1a
CY
1049Return an Emacs frame object.
1050PARMS is an alist of frame parameters.
1051If the parameters specify that the frame should not have a minibuffer,
1052and do not specify a specific minibuffer window to use,
1053then `default-minibuffer-frame' must be a frame whose minibuffer can
a97f8f3f
JD
1054be shared by the new frame.
1055
1056This function is an internal primitive--use `make-frame' instead. */)
5842a27b 1057 (Lisp_Object parms)
edfda783 1058{
edfda783 1059 struct frame *f;
edfda783
AR
1060 Lisp_Object frame, tem;
1061 Lisp_Object name;
1062 int minibuffer_only = 0;
959067a1 1063 long window_prompting = 0;
a97f8f3f 1064 int width, height;
d311d28c 1065 ptrdiff_t count = specpdl_ptr - specpdl;
a97f8f3f 1066 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
edfda783
AR
1067 Lisp_Object display;
1068 struct ns_display_info *dpyinfo = NULL;
1069 Lisp_Object parent;
1070 struct kboard *kb;
a97f8f3f 1071 static int desc_ctr = 1;
edfda783 1072
a97f8f3f 1073 /* x_get_arg modifies parms. */
bd6ce2ba
AR
1074 parms = Fcopy_alist (parms);
1075
a97f8f3f
JD
1076 /* Use this general default value to start with
1077 until we know if this frame has a specified name. */
1078 Vx_resource_name = Vinvocation_name;
1079
edfda783
AR
1080 display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_STRING);
1081 if (EQ (display, Qunbound))
1082 display = Qnil;
1083 dpyinfo = check_ns_display_info (display);
a97f8f3f 1084 kb = dpyinfo->terminal->kboard;
edfda783
AR
1085
1086 if (!dpyinfo->terminal->name)
1087 error ("Terminal is not live, can't create new frames on it");
1088
edfda783
AR
1089 name = x_get_arg (dpyinfo, parms, Qname, 0, 0, RES_TYPE_STRING);
1090 if (!STRINGP (name)
1091 && ! EQ (name, Qunbound)
1092 && ! NILP (name))
1093 error ("Invalid frame name--not a string or nil");
1094
1095 if (STRINGP (name))
1096 Vx_resource_name = name;
1097
1098 parent = x_get_arg (dpyinfo, parms, Qparent_id, 0, 0, RES_TYPE_NUMBER);
1099 if (EQ (parent, Qunbound))
1100 parent = Qnil;
1101 if (! NILP (parent))
1102 CHECK_NUMBER (parent);
1103
a97f8f3f
JD
1104 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
1105 /* No need to protect DISPLAY because that's not used after passing
1106 it to make_frame_without_minibuffer. */
edfda783
AR
1107 frame = Qnil;
1108 GCPRO4 (parms, parent, name, frame);
edfda783
AR
1109 tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer",
1110 RES_TYPE_SYMBOL);
1111 if (EQ (tem, Qnone) || NILP (tem))
edfda783 1112 f = make_frame_without_minibuffer (Qnil, kb, display);
edfda783
AR
1113 else if (EQ (tem, Qonly))
1114 {
1115 f = make_minibuffer_frame ();
1116 minibuffer_only = 1;
1117 }
1118 else if (WINDOWP (tem))
edfda783 1119 f = make_frame_without_minibuffer (tem, kb, display);
edfda783 1120 else
edfda783 1121 f = make_frame (1);
edfda783
AR
1122
1123 XSETFRAME (frame, f);
edfda783
AR
1124
1125 f->terminal = dpyinfo->terminal;
edfda783
AR
1126
1127 f->output_method = output_ns;
38182d90 1128 f->output_data.ns = xzalloc (sizeof *f->output_data.ns);
edfda783
AR
1129
1130 FRAME_FONTSET (f) = -1;
1131
f00af5b1
PE
1132 fset_icon_name (f, x_get_arg (dpyinfo, parms, Qicon_name,
1133 "iconName", "Title",
1134 RES_TYPE_STRING));
e69b0960 1135 if (! STRINGP (f->icon_name))
f00af5b1 1136 fset_icon_name (f, Qnil);
edfda783 1137
aad3612f 1138 FRAME_DISPLAY_INFO (f) = dpyinfo;
edfda783 1139
aad3612f 1140 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
a97f8f3f
JD
1141 record_unwind_protect (unwind_create_frame, frame);
1142
edfda783 1143 f->output_data.ns->window_desc = desc_ctr++;
d311d28c 1144 if (TYPE_RANGED_INTEGERP (Window, parent))
edfda783 1145 {
d311d28c 1146 f->output_data.ns->parent_desc = XFASTINT (parent);
edfda783
AR
1147 f->output_data.ns->explicit_parent = 1;
1148 }
1149 else
1150 {
aad3612f 1151 f->output_data.ns->parent_desc = FRAME_DISPLAY_INFO (f)->root_window;
edfda783
AR
1152 f->output_data.ns->explicit_parent = 0;
1153 }
1154
a97f8f3f
JD
1155 /* Set the name; the functions to which we pass f expect the name to
1156 be set. */
1157 if (EQ (name, Qunbound) || NILP (name) || ! STRINGP (name))
1158 {
f00af5b1 1159 fset_name (f, build_string ([ns_app_name UTF8String]));
a97f8f3f
JD
1160 f->explicit_name = 0;
1161 }
1162 else
1163 {
f00af5b1 1164 fset_name (f, name);
a97f8f3f
JD
1165 f->explicit_name = 1;
1166 specbind (Qx_resource_name, name);
1167 }
1168
4d7e6e51 1169 block_input ();
3fa2054e 1170
745d3809
JD
1171#ifdef NS_IMPL_COCOA
1172#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
3fa2054e
JD
1173 if (CTGetCoreTextVersion != NULL
1174 && CTGetCoreTextVersion () >= kCTVersionNumber10_5)
1175 mac_register_font_driver (f);
3fa2054e 1176#endif
745d3809
JD
1177#endif
1178 register_font_driver (&nsfont_driver, f);
3fa2054e 1179
edfda783
AR
1180 x_default_parameter (f, parms, Qfont_backend, Qnil,
1181 "fontBackend", "FontBackend", RES_TYPE_STRING);
1182
1183 {
1184 /* use for default font name */
1185 id font = [NSFont userFixedPitchFontOfSize: -1.0]; /* default */
c0342369 1186 x_default_parameter (f, parms, Qfontsize,
edfda783
AR
1187 make_number (0 /*(int)[font pointSize]*/),
1188 "fontSize", "FontSize", RES_TYPE_NUMBER);
3fa2054e
JD
1189 // Remove ' Regular', not handled by backends.
1190 char *fontname = xstrdup ([[font displayName] UTF8String]);
1191 int len = strlen (fontname);
1192 if (len > 8 && strcmp (fontname + len - 8, " Regular") == 0)
1193 fontname[len-8] = '\0';
c0342369 1194 x_default_parameter (f, parms, Qfont,
3fa2054e 1195 build_string (fontname),
edfda783 1196 "font", "Font", RES_TYPE_STRING);
c8b09927 1197 xfree (fontname);
edfda783 1198 }
4d7e6e51 1199 unblock_input ();
edfda783
AR
1200
1201 x_default_parameter (f, parms, Qborder_width, make_number (0),
1202 "borderwidth", "BorderWidth", RES_TYPE_NUMBER);
1203 x_default_parameter (f, parms, Qinternal_border_width, make_number (2),
1204 "internalBorderWidth", "InternalBorderWidth",
1205 RES_TYPE_NUMBER);
1206
1207 /* default scrollbars on right on Mac */
1208 {
facfbbbd 1209 Lisp_Object spos
edfda783 1210#ifdef NS_IMPL_GNUSTEP
facfbbbd 1211 = Qt;
edfda783 1212#else
facfbbbd 1213 = Qright;
edfda783 1214#endif
facfbbbd
SM
1215 x_default_parameter (f, parms, Qvertical_scroll_bars, spos,
1216 "verticalScrollBars", "VerticalScrollBars",
1217 RES_TYPE_SYMBOL);
edfda783
AR
1218 }
1219 x_default_parameter (f, parms, Qforeground_color, build_string ("Black"),
1220 "foreground", "Foreground", RES_TYPE_STRING);
1221 x_default_parameter (f, parms, Qbackground_color, build_string ("White"),
1222 "background", "Background", RES_TYPE_STRING);
22bcf204 1223 /* FIXME: not supported yet in Nextstep */
edfda783
AR
1224 x_default_parameter (f, parms, Qline_spacing, Qnil,
1225 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
1226 x_default_parameter (f, parms, Qleft_fringe, Qnil,
1227 "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
1228 x_default_parameter (f, parms, Qright_fringe, Qnil,
1229 "rightFringe", "RightFringe", RES_TYPE_NUMBER);
edfda783 1230
ef884f23 1231#ifdef GLYPH_DEBUG
a97f8f3f
JD
1232 image_cache_refcount =
1233 FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0;
1234#endif
edfda783
AR
1235
1236 init_frame_faces (f);
1237
a97f8f3f 1238 /* The resources controlling the menu-bar and tool-bar are
6431f2e6
CY
1239 processed specially at startup, and reflected in the mode
1240 variables; ignore them here. */
1241 x_default_parameter (f, parms, Qmenu_bar_lines,
1242 NILP (Vmenu_bar_mode)
1243 ? make_number (0) : make_number (1),
1244 NULL, NULL, RES_TYPE_NUMBER);
1245 x_default_parameter (f, parms, Qtool_bar_lines,
1246 NILP (Vtool_bar_mode)
1247 ? make_number (0) : make_number (1),
1248 NULL, NULL, RES_TYPE_NUMBER);
1249
edfda783
AR
1250 x_default_parameter (f, parms, Qbuffer_predicate, Qnil, "bufferPredicate",
1251 "BufferPredicate", RES_TYPE_SYMBOL);
1252 x_default_parameter (f, parms, Qtitle, Qnil, "title", "Title",
1253 RES_TYPE_STRING);
1254
a0c3fad0 1255 parms = get_geometry_from_preferences (dpyinfo, parms);
edfda783
AR
1256 window_prompting = x_figure_window_size (f, parms, 1);
1257
1258 tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
1259 f->no_split = minibuffer_only || (!EQ (tem, Qunbound) && !EQ (tem, Qnil));
1260
1261 /* NOTE: on other terms, this is done in set_mouse_color, however this
d26fbe1a 1262 was not getting called under Nextstep */
edfda783
AR
1263 f->output_data.ns->text_cursor = [NSCursor IBeamCursor];
1264 f->output_data.ns->nontext_cursor = [NSCursor arrowCursor];
1265 f->output_data.ns->modeline_cursor = [NSCursor pointingHandCursor];
1266 f->output_data.ns->hand_cursor = [NSCursor pointingHandCursor];
1267 f->output_data.ns->hourglass_cursor = [NSCursor disappearingItemCursor];
1268 f->output_data.ns->horizontal_drag_cursor = [NSCursor resizeLeftRightCursor];
aad3612f 1269 FRAME_DISPLAY_INFO (f)->vertical_scroll_bar_cursor
facfbbbd 1270 = [NSCursor arrowCursor];
edfda783
AR
1271 f->output_data.ns->current_pointer = f->output_data.ns->text_cursor;
1272
1273 [[EmacsView alloc] initFrameFromEmacs: f];
1274
952913d4 1275 x_icon (f, parms);
edfda783 1276
a97f8f3f
JD
1277 /* ns_display_info does not have a reference_count. */
1278 f->terminal->reference_count++;
1279
edfda783
AR
1280 /* It is now ok to make the frame official even if we get an error below.
1281 The frame needs to be on Vframe_list or making it visible won't work. */
1282 Vframe_list = Fcons (frame, Vframe_list);
a97f8f3f
JD
1283
1284 x_default_parameter (f, parms, Qicon_type, Qnil,
1285 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
1286
1287 x_default_parameter (f, parms, Qauto_raise, Qnil,
1288 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
1289 x_default_parameter (f, parms, Qauto_lower, Qnil,
1290 "autoLower", "AutoLower", RES_TYPE_BOOLEAN);
1291 x_default_parameter (f, parms, Qcursor_type, Qbox,
1292 "cursorType", "CursorType", RES_TYPE_SYMBOL);
1293 x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
1294 "scrollBarWidth", "ScrollBarWidth",
1295 RES_TYPE_NUMBER);
1296 x_default_parameter (f, parms, Qalpha, Qnil,
1297 "alpha", "Alpha", RES_TYPE_NUMBER);
04fafa46
JD
1298 x_default_parameter (f, parms, Qfullscreen, Qnil,
1299 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
edfda783
AR
1300
1301 width = FRAME_COLS (f);
1302 height = FRAME_LINES (f);
1303
1304 SET_FRAME_COLS (f, 0);
1305 FRAME_LINES (f) = 0;
1306 change_frame_size (f, height, width, 1, 0, 0);
1307
1308 if (! f->output_data.ns->explicit_parent)
1309 {
a97f8f3f
JD
1310 Lisp_Object visibility;
1311
1312 visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
1313 RES_TYPE_SYMBOL);
1314 if (EQ (visibility, Qunbound))
1315 visibility = Qt;
1316
1317 if (EQ (visibility, Qicon))
15891144 1318 x_iconify_frame (f);
a97f8f3f 1319 else if (! NILP (visibility))
15891144
DR
1320 {
1321 x_make_frame_visible (f);
15891144
DR
1322 [[FRAME_NS_VIEW (f) window] makeKeyWindow];
1323 }
1324 else
a97f8f3f
JD
1325 {
1326 /* Must have been Qnil. */
1327 }
edfda783
AR
1328 }
1329
1330 if (FRAME_HAS_MINIBUF_P (f)
124c9ff0
JD
1331 && (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
1332 || !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame)))))
15dbb4d6 1333 kset_default_minibuffer_frame (kb, frame);
edfda783
AR
1334
1335 /* All remaining specified parameters, which have not been "used"
1336 by x_get_arg and friends, now go in the misc. alist of the frame. */
1337 for (tem = parms; CONSP (tem); tem = XCDR (tem))
1338 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
f00af5b1 1339 fset_param_alist (f, Fcons (XCAR (tem), f->param_alist));
edfda783
AR
1340
1341 UNGCPRO;
a97f8f3f 1342
e543ae91
JD
1343 if (window_prompting & USPosition)
1344 x_set_offset (f, f->left_pos, f->top_pos, 1);
1345
a97f8f3f
JD
1346 /* Make sure windows on this frame appear in calls to next-window
1347 and similar functions. */
edfda783
AR
1348 Vwindow_list = Qnil;
1349
1350 return unbind_to (count, frame);
1351}
1352
fcd42c11
DA
1353void
1354x_focus_frame (struct frame *f)
edfda783 1355{
aad3612f 1356 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
edfda783 1357
9e50ff0c 1358 if (dpyinfo->x_focus_frame != f)
edfda783
AR
1359 {
1360 EmacsView *view = FRAME_NS_VIEW (f);
4d7e6e51 1361 block_input ();
4acaaa2b 1362 [NSApp activateIgnoringOtherApps: YES];
edfda783 1363 [[view window] makeKeyAndOrderFront: view];
4d7e6e51 1364 unblock_input ();
edfda783 1365 }
edfda783
AR
1366}
1367
1368
edfda783 1369DEFUN ("ns-popup-font-panel", Fns_popup_font_panel, Sns_popup_font_panel,
51d5ef9f
AR
1370 0, 1, "",
1371 doc: /* Pop up the font panel. */)
5842a27b 1372 (Lisp_Object frame)
edfda783 1373{
7452b7bd
DA
1374 struct frame *f = decode_window_system_frame (frame);
1375 id fm = [NSFontManager sharedFontManager];
3fa2054e
JD
1376 struct font *font = f->output_data.ns->font;
1377 NSFont *nsfont;
1378 if (EQ (font->driver->type, Qns))
1379 nsfont = ((struct nsfont_info *)font)->nsfont;
1380#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
1381 else
1382 nsfont = (NSFont *) macfont_get_nsctfont (font);
1383#endif
1384 [fm setSelectedFont: nsfont isMultiple: NO];
edfda783
AR
1385 [fm orderFrontFontPanel: NSApp];
1386 return Qnil;
1387}
1388
1389
b066e6b6 1390DEFUN ("ns-popup-color-panel", Fns_popup_color_panel, Sns_popup_color_panel,
51d5ef9f
AR
1391 0, 1, "",
1392 doc: /* Pop up the color panel. */)
5842a27b 1393 (Lisp_Object frame)
edfda783 1394{
7452b7bd 1395 check_window_system (NULL);
edfda783
AR
1396 [NSApp orderFrontColorPanel: NSApp];
1397 return Qnil;
1398}
1399
1afb1d07
JD
1400static struct
1401{
1402 id panel;
1403 BOOL ret;
1404#if ! defined (NS_IMPL_COCOA) || \
1405 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
1406 NSString *dirS, *initS;
1407 BOOL no_types;
1408#endif
1409} ns_fd_data;
1410
1411void
1412ns_run_file_dialog (void)
1413{
1414 if (ns_fd_data.panel == nil) return;
1415#if defined (NS_IMPL_COCOA) && \
1416 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1417 ns_fd_data.ret = [ns_fd_data.panel runModal];
1418#else
1419 if (ns_fd_data.no_types)
1420 {
1421 ns_fd_data.ret = [ns_fd_data.panel
1422 runModalForDirectory: ns_fd_data.dirS
1423 file: ns_fd_data.initS];
1424 }
1425 else
1426 {
1427 ns_fd_data.ret = [ns_fd_data.panel
1428 runModalForDirectory: ns_fd_data.dirS
1429 file: ns_fd_data.initS
1430 types: nil];
1431 }
1432#endif
1433 ns_fd_data.panel = nil;
1434}
edfda783 1435
d7e642cc 1436DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 5, 0,
51d5ef9f 1437 doc: /* Use a graphical panel to read a file name, using prompt PROMPT.
d26fbe1a 1438Optional arg DIR, if non-nil, supplies a default directory.
45cb8994
CY
1439Optional arg MUSTMATCH, if non-nil, means the returned file or
1440directory must exist.
d7e642cc
JD
1441Optional arg INIT, if non-nil, provides a default file name to use.
1442Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1443 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object mustmatch,
1444 Lisp_Object init, Lisp_Object dir_only_p)
edfda783
AR
1445{
1446 static id fileDelegate = nil;
8f2906f5 1447 BOOL ret;
c0342369 1448 BOOL isSave = NILP (mustmatch) && NILP (dir_only_p);
edfda783 1449 id panel;
ba301db3 1450 Lisp_Object fname;
edfda783
AR
1451
1452 NSString *promptS = NILP (prompt) || !STRINGP (prompt) ? nil :
0dc8cf50 1453 [NSString stringWithUTF8String: SSDATA (prompt)];
edfda783 1454 NSString *dirS = NILP (dir) || !STRINGP (dir) ?
0dc8cf50
JD
1455 [NSString stringWithUTF8String: SSDATA (BVAR (current_buffer, directory))] :
1456 [NSString stringWithUTF8String: SSDATA (dir)];
edfda783 1457 NSString *initS = NILP (init) || !STRINGP (init) ? nil :
0dc8cf50 1458 [NSString stringWithUTF8String: SSDATA (init)];
1afb1d07 1459 NSEvent *nxev;
edfda783 1460
7452b7bd 1461 check_window_system (NULL);
edfda783
AR
1462
1463 if (fileDelegate == nil)
1464 fileDelegate = [EmacsFileDelegate new];
1465
1466 [NSCursor setHiddenUntilMouseMoves: NO];
1467
1468 if ([dirS characterAtIndex: 0] == '~')
1469 dirS = [dirS stringByExpandingTildeInPath];
1470
c0342369 1471 panel = isSave ?
f2f7f42c 1472 (id)[EmacsSavePanel savePanel] : (id)[EmacsOpenPanel openPanel];
edfda783
AR
1473
1474 [panel setTitle: promptS];
1475
d7e642cc 1476 [panel setAllowsOtherFileTypes: YES];
edfda783
AR
1477 [panel setTreatsFilePackagesAsDirectories: YES];
1478 [panel setDelegate: fileDelegate];
1479
677d5c92 1480 if (! NILP (dir_only_p))
d7e642cc
JD
1481 {
1482 [panel setCanChooseDirectories: YES];
1483 [panel setCanChooseFiles: NO];
1484 }
c0342369 1485 else if (! isSave)
8f2906f5
JD
1486 {
1487 /* This is not quite what the documentation says, but it is compatible
1488 with the Gtk+ code. Also, the menu entry says "Open File...". */
1489 [panel setCanChooseDirectories: NO];
1490 [panel setCanChooseFiles: YES];
1491 }
677d5c92 1492
1afb1d07
JD
1493 block_input ();
1494 ns_fd_data.panel = panel;
1495 ns_fd_data.ret = NO;
d7e642cc
JD
1496#if defined (NS_IMPL_COCOA) && \
1497 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1498 if (! NILP (mustmatch) || ! NILP (dir_only_p))
1499 [panel setAllowedFileTypes: nil];
1500 if (dirS) [panel setDirectoryURL: [NSURL fileURLWithPath: dirS]];
1501 if (initS && NILP (Ffile_directory_p (init)))
1502 [panel setNameFieldStringValue: [initS lastPathComponent]];
1503 else
1504 [panel setNameFieldStringValue: @""];
677d5c92 1505
d7e642cc 1506#else
1afb1d07
JD
1507 ns_fd_data.no_types = NILP (mustmatch) && NILP (dir_only_p);
1508 ns_fd_data.dirS = dirS;
1509 ns_fd_data.initS = initS;
d7e642cc 1510#endif
edfda783 1511
1afb1d07
JD
1512 /* runModalForDirectory/runModal restarts the main event loop when done,
1513 so we must start an event loop and then pop up the file dialog.
1514 The file dialog may pop up a confirm dialog after Ok has been pressed,
1515 so we can not simply pop down on the Ok/Cancel press.
1516 */
1517 nxev = [NSEvent otherEventWithType: NSApplicationDefined
1518 location: NSMakePoint (0, 0)
1519 modifierFlags: 0
1520 timestamp: 0
1521 windowNumber: [[NSApp mainWindow] windowNumber]
1522 context: [NSApp context]
1523 subtype: 0
1524 data1: 0
1525 data2: NSAPP_DATA2_RUNFILEDIALOG];
1526
1527 [NSApp postEvent: nxev atStart: NO];
1528 while (ns_fd_data.panel != nil)
1529 [NSApp run];
1530
1531 ret = (ns_fd_data.ret == NSOKButton);
edfda783 1532
a37d34f3 1533 if (ret)
8f2906f5 1534 {
c0342369
JD
1535 NSString *str = ns_filename_from_panel (panel);
1536 if (! str) str = ns_directory_from_panel (panel);
8f2906f5
JD
1537 if (! str) ret = NO;
1538 else fname = build_string ([str UTF8String]);
1539 }
b066e6b6 1540
edfda783 1541 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
4d7e6e51 1542 unblock_input ();
edfda783 1543
ba301db3 1544 return ret ? fname : Qnil;
edfda783
AR
1545}
1546
f7dfe5d6
JD
1547const char *
1548ns_get_defaults_value (const char *key)
1549{
1550 NSObject *obj = [[NSUserDefaults standardUserDefaults]
1551 objectForKey: [NSString stringWithUTF8String: key]];
1552
1553 if (!obj) return NULL;
1554
1555 return [[NSString stringWithFormat: @"%@", obj] UTF8String];
1556}
1557
edfda783
AR
1558
1559DEFUN ("ns-get-resource", Fns_get_resource, Sns_get_resource, 2, 2, 0,
51d5ef9f
AR
1560 doc: /* Return the value of the property NAME of OWNER from the defaults database.
1561If OWNER is nil, Emacs is assumed. */)
5842a27b 1562 (Lisp_Object owner, Lisp_Object name)
edfda783
AR
1563{
1564 const char *value;
1565
7452b7bd 1566 check_window_system (NULL);
edfda783 1567 if (NILP (owner))
56d513e6 1568 owner = build_string([ns_app_name UTF8String]);
edfda783 1569 CHECK_STRING (name);
edfda783 1570
0dc8cf50 1571 value = ns_get_defaults_value (SSDATA (name));
edfda783
AR
1572
1573 if (value)
1574 return build_string (value);
edfda783
AR
1575 return Qnil;
1576}
1577
1578
1579DEFUN ("ns-set-resource", Fns_set_resource, Sns_set_resource, 3, 3, 0,
51d5ef9f 1580 doc: /* Set property NAME of OWNER to VALUE, from the defaults database.
d26fbe1a 1581If OWNER is nil, Emacs is assumed.
51d5ef9f 1582If VALUE is nil, the default is removed. */)
5842a27b 1583 (Lisp_Object owner, Lisp_Object name, Lisp_Object value)
edfda783 1584{
7452b7bd 1585 check_window_system (NULL);
edfda783 1586 if (NILP (owner))
56d513e6 1587 owner = build_string ([ns_app_name UTF8String]);
edfda783
AR
1588 CHECK_STRING (name);
1589 if (NILP (value))
1590 {
1591 [[NSUserDefaults standardUserDefaults] removeObjectForKey:
0dc8cf50 1592 [NSString stringWithUTF8String: SSDATA (name)]];
edfda783
AR
1593 }
1594 else
1595 {
1596 CHECK_STRING (value);
1597 [[NSUserDefaults standardUserDefaults] setObject:
0dc8cf50 1598 [NSString stringWithUTF8String: SSDATA (value)]
edfda783 1599 forKey: [NSString stringWithUTF8String:
0dc8cf50 1600 SSDATA (name)]];
edfda783
AR
1601 }
1602
1603 return Qnil;
1604}
1605
1606
952913d4
DN
1607DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
1608 Sx_server_max_request_size,
edfda783 1609 0, 1, 0,
51d5ef9f 1610 doc: /* This function is a no-op. It is only present for completeness. */)
91e8418b 1611 (Lisp_Object terminal)
edfda783 1612{
91e8418b 1613 check_ns_display_info (terminal);
edfda783
AR
1614 /* This function has no real equivalent under NeXTstep. Return nil to
1615 indicate this. */
1616 return Qnil;
1617}
1618
1619
9e50ff0c 1620DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
91e8418b
YM
1621 doc: /* Return the "vendor ID" string of Nextstep display server TERMINAL.
1622\(Labeling every distributor as a "vendor" embodies the false assumption
1623that operating systems cannot be developed and distributed noncommercially.)
1624The optional argument TERMINAL specifies which display to ask about.
1625TERMINAL should be a terminal object, a frame or a display name (a string).
1626If omitted or nil, that stands for the selected frame's display. */)
1627 (Lisp_Object terminal)
edfda783 1628{
91e8418b 1629 check_ns_display_info (terminal);
edfda783
AR
1630#ifdef NS_IMPL_GNUSTEP
1631 return build_string ("GNU");
1632#else
1633 return build_string ("Apple");
1634#endif
1635}
1636
1637
9e50ff0c 1638DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
91e8418b 1639 doc: /* Return the version numbers of the server of display TERMINAL.
f5497e45 1640The value is a list of three integers: the major and minor
91e8418b
YM
1641version numbers of the X Protocol in use, and the distributor-specific release
1642number. See also the function `x-server-vendor'.
f5497e45 1643
91e8418b
YM
1644The optional argument TERMINAL specifies which display to ask about.
1645TERMINAL should be a terminal object, a frame or a display name (a string).
f5497e45 1646If omitted or nil, that stands for the selected frame's display. */)
91e8418b 1647 (Lisp_Object terminal)
edfda783 1648{
91e8418b 1649 check_ns_display_info (terminal);
f5497e45
AR
1650 /*NOTE: it is unclear what would best correspond with "protocol";
1651 we return 10.3, meaning Panther, since this is roughly the
1652 level that GNUstep's APIs correspond to.
1653 The last number is where we distinguish between the Apple
1654 and GNUstep implementations ("distributor-specific release
1655 number") and give int'ized versions of major.minor. */
3de717bd 1656 return list3i (10, 3, ns_appkit_version_int ());
edfda783
AR
1657}
1658
1659
9e50ff0c 1660DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
91e8418b
YM
1661 doc: /* Return the number of screens on Nextstep display server TERMINAL.
1662The optional argument TERMINAL specifies which display to ask about.
1663TERMINAL should be a terminal object, a frame or a display name (a string).
1664If omitted or nil, that stands for the selected frame's display.
edfda783 1665
91e8418b
YM
1666Note: "screen" here is not in Nextstep terminology but in X11's. For
1667the number of physical monitors, use `(length
1668(display-monitor-attributes-list TERMINAL))' instead. */)
1669 (Lisp_Object terminal)
1670{
1671 check_ns_display_info (terminal);
1672 return make_number (1);
edfda783
AR
1673}
1674
1675
91e8418b
YM
1676DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0,
1677 doc: /* Return the height in millimeters of the Nextstep display TERMINAL.
1678The optional argument TERMINAL specifies which display to ask about.
1679TERMINAL should be a terminal object, a frame or a display name (a string).
1680If omitted or nil, that stands for the selected frame's display.
1681
1682On \"multi-monitor\" setups this refers to the height in millimeters for
1683all physical monitors associated with TERMINAL. To get information
1684for each physical monitor, use `display-monitor-attributes-list'. */)
1685 (Lisp_Object terminal)
edfda783 1686{
91e8418b
YM
1687 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
1688
1689 return make_number (x_display_pixel_height (dpyinfo) / (92.0/25.4));
edfda783
AR
1690}
1691
1692
91e8418b
YM
1693DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
1694 doc: /* Return the width in millimeters of the Nextstep display TERMINAL.
1695The optional argument TERMINAL specifies which display to ask about.
1696TERMINAL should be a terminal object, a frame or a display name (a string).
1697If omitted or nil, that stands for the selected frame's display.
1698
1699On \"multi-monitor\" setups this refers to the width in millimeters for
1700all physical monitors associated with TERMINAL. To get information
1701for each physical monitor, use `display-monitor-attributes-list'. */)
1702 (Lisp_Object terminal)
edfda783 1703{
91e8418b
YM
1704 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
1705
1706 return make_number (x_display_pixel_width (dpyinfo) / (92.0/25.4));
edfda783
AR
1707}
1708
1709
9e50ff0c 1710DEFUN ("x-display-backing-store", Fx_display_backing_store,
51d5ef9f 1711 Sx_display_backing_store, 0, 1, 0,
91e8418b 1712 doc: /* Return an indication of whether the Nextstep display TERMINAL does backing store.
d26fbe1a 1713The value may be `buffered', `retained', or `non-retained'.
91e8418b
YM
1714The optional argument TERMINAL specifies which display to ask about.
1715TERMINAL should be a terminal object, a frame or a display name (a string).
1716If omitted or nil, that stands for the selected frame's display. */)
1717 (Lisp_Object terminal)
edfda783 1718{
91e8418b
YM
1719 check_ns_display_info (terminal);
1720 switch ([ns_get_window (terminal) backingType])
edfda783
AR
1721 {
1722 case NSBackingStoreBuffered:
1723 return intern ("buffered");
1724 case NSBackingStoreRetained:
1725 return intern ("retained");
1726 case NSBackingStoreNonretained:
1727 return intern ("non-retained");
1728 default:
1729 error ("Strange value for backingType parameter of frame");
1730 }
1731 return Qnil; /* not reached, shut compiler up */
1732}
1733
1734
9e50ff0c 1735DEFUN ("x-display-visual-class", Fx_display_visual_class,
51d5ef9f 1736 Sx_display_visual_class, 0, 1, 0,
91e8418b 1737 doc: /* Return the visual class of the Nextstep display TERMINAL.
d26fbe1a
CY
1738The value is one of the symbols `static-gray', `gray-scale',
1739`static-color', `pseudo-color', `true-color', or `direct-color'.
91e8418b
YM
1740
1741The optional argument TERMINAL specifies which display to ask about.
1742TERMINAL should a terminal object, a frame or a display name (a string).
1743If omitted or nil, that stands for the selected frame's display. */)
1744 (Lisp_Object terminal)
edfda783
AR
1745{
1746 NSWindowDepth depth;
a37d34f3 1747
91e8418b
YM
1748 check_ns_display_info (terminal);
1749 depth = [[[NSScreen screens] objectAtIndex:0] depth];
edfda783
AR
1750
1751 if ( depth == NSBestDepth (NSCalibratedWhiteColorSpace, 2, 2, YES, NULL))
1752 return intern ("static-gray");
1753 else if (depth == NSBestDepth (NSCalibratedWhiteColorSpace, 8, 8, YES, NULL))
1754 return intern ("gray-scale");
1755 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 8, 8, YES, NULL))
1756 return intern ("pseudo-color");
1757 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 4, 12, NO, NULL))
1758 return intern ("true-color");
1759 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 8, 24, NO, NULL))
1760 return intern ("direct-color");
1761 else
d26fbe1a 1762 /* color mgmt as far as we do it is really handled by Nextstep itself anyway */
edfda783
AR
1763 return intern ("direct-color");
1764}
1765
1766
9e50ff0c 1767DEFUN ("x-display-save-under", Fx_display_save_under,
51d5ef9f 1768 Sx_display_save_under, 0, 1, 0,
91e8418b
YM
1769 doc: /* Return t if TERMINAL supports the save-under feature.
1770The optional argument TERMINAL specifies which display to ask about.
1771TERMINAL should be a terminal object, a frame or a display name (a string).
1772If omitted or nil, that stands for the selected frame's display. */)
1773 (Lisp_Object terminal)
1774{
1775 check_ns_display_info (terminal);
1776 switch ([ns_get_window (terminal) backingType])
edfda783
AR
1777 {
1778 case NSBackingStoreBuffered:
1779 return Qt;
1780
1781 case NSBackingStoreRetained:
1782 case NSBackingStoreNonretained:
1783 return Qnil;
1784
1785 default:
1786 error ("Strange value for backingType parameter of frame");
1787 }
1788 return Qnil; /* not reached, shut compiler up */
1789}
1790
1791
9e50ff0c 1792DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
51d5ef9f 1793 1, 3, 0,
4f4f2973 1794 doc: /* Open a connection to a display server.
d26fbe1a 1795DISPLAY is the name of the display to connect to.
4f4f2973
GM
1796Optional second arg XRM-STRING is a string of resources in xrdb format.
1797If the optional third arg MUST-SUCCEED is non-nil,
1798terminate Emacs if we can't open the connection.
1799\(In the Nextstep version, the last two arguments are currently ignored.) */)
5842a27b 1800 (Lisp_Object display, Lisp_Object resource_string, Lisp_Object must_succeed)
edfda783
AR
1801{
1802 struct ns_display_info *dpyinfo;
1803
1804 CHECK_STRING (display);
1805
1806 nxatoms_of_nsselect ();
1807 dpyinfo = ns_term_init (display);
1808 if (dpyinfo == 0)
1809 {
1810 if (!NILP (must_succeed))
1811 fatal ("OpenStep on %s not responding.\n",
0dc8cf50 1812 SSDATA (display));
edfda783
AR
1813 else
1814 error ("OpenStep on %s not responding.\n",
0dc8cf50 1815 SSDATA (display));
edfda783
AR
1816 }
1817
edfda783
AR
1818 return Qnil;
1819}
1820
1821
9e50ff0c 1822DEFUN ("x-close-connection", Fx_close_connection, Sx_close_connection,
51d5ef9f 1823 1, 1, 0,
91e8418b
YM
1824 doc: /* Close the connection to TERMINAL's Nextstep display server.
1825For TERMINAL, specify a terminal object, a frame or a display name (a
1826string). If TERMINAL is nil, that stands for the selected frame's
1827terminal. */)
1828 (Lisp_Object terminal)
edfda783 1829{
91e8418b 1830 check_ns_display_info (terminal);
edfda783
AR
1831 [NSApp terminate: NSApp];
1832 return Qnil;
1833}
1834
1835
9e50ff0c 1836DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
51d5ef9f 1837 doc: /* Return the list of display names that Emacs has connections to. */)
5842a27b 1838 (void)
edfda783 1839{
d141d701
DA
1840 Lisp_Object result = Qnil;
1841 struct ns_display_info *ndi;
edfda783 1842
d141d701
DA
1843 for (ndi = x_display_list; ndi; ndi = ndi->next)
1844 result = Fcons (XCAR (ndi->name_list_element), result);
edfda783
AR
1845
1846 return result;
1847}
1848
1849
1850DEFUN ("ns-hide-others", Fns_hide_others, Sns_hide_others,
51d5ef9f 1851 0, 0, 0,
b066e6b6 1852 doc: /* Hides all applications other than Emacs. */)
5842a27b 1853 (void)
edfda783 1854{
7452b7bd 1855 check_window_system (NULL);
edfda783
AR
1856 [NSApp hideOtherApplications: NSApp];
1857 return Qnil;
1858}
1859
1860DEFUN ("ns-hide-emacs", Fns_hide_emacs, Sns_hide_emacs,
51d5ef9f 1861 1, 1, 0,
b066e6b6
JB
1862 doc: /* If ON is non-nil, the entire Emacs application is hidden.
1863Otherwise if Emacs is hidden, it is unhidden.
1864If ON is equal to `activate', Emacs is unhidden and becomes
51d5ef9f 1865the active application. */)
5842a27b 1866 (Lisp_Object on)
edfda783 1867{
7452b7bd 1868 check_window_system (NULL);
edfda783
AR
1869 if (EQ (on, intern ("activate")))
1870 {
1871 [NSApp unhide: NSApp];
1872 [NSApp activateIgnoringOtherApps: YES];
1873 }
1874 else if (NILP (on))
1875 [NSApp unhide: NSApp];
1876 else
1877 [NSApp hide: NSApp];
1878 return Qnil;
1879}
1880
1881
1882DEFUN ("ns-emacs-info-panel", Fns_emacs_info_panel, Sns_emacs_info_panel,
51d5ef9f
AR
1883 0, 0, 0,
1884 doc: /* Shows the 'Info' or 'About' panel for Emacs. */)
5842a27b 1885 (void)
edfda783 1886{
7452b7bd 1887 check_window_system (NULL);
edfda783
AR
1888 [NSApp orderFrontStandardAboutPanel: nil];
1889 return Qnil;
1890}
1891
1892
edfda783 1893DEFUN ("ns-font-name", Fns_font_name, Sns_font_name, 1, 1, 0,
7877f373 1894 doc: /* Determine font PostScript or family name for font NAME.
d26fbe1a
CY
1895NAME should be a string containing either the font name or an XLFD
1896font descriptor. If string contains `fontset' and not
51d5ef9f 1897`fontset-startup', it is left alone. */)
5842a27b 1898 (Lisp_Object name)
edfda783
AR
1899{
1900 char *nm;
1901 CHECK_STRING (name);
0dc8cf50 1902 nm = SSDATA (name);
edfda783
AR
1903
1904 if (nm[0] != '-')
1905 return name;
1906 if (strstr (nm, "fontset") && !strstr (nm, "fontset-startup"))
1907 return name;
1908
0dc8cf50 1909 return build_string (ns_xlfd_to_fontname (SSDATA (name)));
edfda783
AR
1910}
1911
1912
1913DEFUN ("ns-list-colors", Fns_list_colors, Sns_list_colors, 0, 1, 0,
51d5ef9f
AR
1914 doc: /* Return a list of all available colors.
1915The optional argument FRAME is currently ignored. */)
5842a27b 1916 (Lisp_Object frame)
edfda783
AR
1917{
1918 Lisp_Object list = Qnil;
1919 NSEnumerator *colorlists;
1920 NSColorList *clist;
1921
1922 if (!NILP (frame))
1923 {
1924 CHECK_FRAME (frame);
1925 if (! FRAME_NS_P (XFRAME (frame)))
d26fbe1a 1926 error ("non-Nextstep frame used in `ns-list-colors'");
edfda783
AR
1927 }
1928
4d7e6e51 1929 block_input ();
edfda783
AR
1930
1931 colorlists = [[NSColorList availableColorLists] objectEnumerator];
0dc8cf50 1932 while ((clist = [colorlists nextObject]))
edfda783
AR
1933 {
1934 if ([[clist name] length] < 7 ||
1935 [[clist name] rangeOfString: @"PANTONE"].location == 0)
1936 {
1937 NSEnumerator *cnames = [[clist allKeys] reverseObjectEnumerator];
1938 NSString *cname;
0dc8cf50 1939 while ((cname = [cnames nextObject]))
edfda783
AR
1940 list = Fcons (build_string ([cname UTF8String]), list);
1941/* for (i = [[clist allKeys] count] - 1; i >= 0; i--)
1942 list = Fcons (build_string ([[[clist allKeys] objectAtIndex: i]
1943 UTF8String]), list); */
1944 }
1945 }
1946
4d7e6e51 1947 unblock_input ();
edfda783
AR
1948
1949 return list;
1950}
1951
1952
1953DEFUN ("ns-list-services", Fns_list_services, Sns_list_services, 0, 0, 0,
51d5ef9f 1954 doc: /* List available Nextstep services by querying NSApp. */)
5842a27b 1955 (void)
edfda783 1956{
699c10bd
JD
1957#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1958 /* You can't get services like this in 10.6+. */
1959 return Qnil;
1960#else
edfda783
AR
1961 Lisp_Object ret = Qnil;
1962 NSMenu *svcs;
c0342369 1963#ifdef NS_IMPL_COCOA
edfda783 1964 id delegate;
c0342369 1965#endif
edfda783 1966
7452b7bd 1967 check_window_system (NULL);
edfda783 1968 svcs = [[NSMenu alloc] initWithTitle: @"Services"];
335f5ae4 1969 [NSApp setServicesMenu: svcs];
edfda783
AR
1970 [NSApp registerServicesMenuSendTypes: ns_send_types
1971 returnTypes: ns_return_types];
1972
1973/* On Tiger, services menu updating was made lazier (waits for user to
1974 actually click on the menu), so we have to force things along: */
1975#ifdef NS_IMPL_COCOA
335f5ae4
JD
1976 delegate = [svcs delegate];
1977 if (delegate != nil)
edfda783 1978 {
335f5ae4
JD
1979 if ([delegate respondsToSelector: @selector (menuNeedsUpdate:)])
1980 [delegate menuNeedsUpdate: svcs];
1981 if ([delegate respondsToSelector:
1982 @selector (menu:updateItem:atIndex:shouldCancel:)])
edfda783 1983 {
335f5ae4
JD
1984 int i, len = [delegate numberOfItemsInMenu: svcs];
1985 for (i =0; i<len; i++)
1986 [svcs addItemWithTitle: @"" action: NULL keyEquivalent: @""];
1987 for (i =0; i<len; i++)
1988 if (![delegate menu: svcs
1989 updateItem: (NSMenuItem *)[svcs itemAtIndex: i]
1990 atIndex: i shouldCancel: NO])
1991 break;
edfda783
AR
1992 }
1993 }
1994#endif
1995
1996 [svcs setAutoenablesItems: NO];
1997#ifdef NS_IMPL_COCOA
1998 [svcs update]; /* on OS X, converts from '/' structure */
1999#endif
2000
2001 ret = interpret_services_menu (svcs, Qnil, ret);
2002 return ret;
699c10bd 2003#endif
edfda783
AR
2004}
2005
2006
2007DEFUN ("ns-perform-service", Fns_perform_service, Sns_perform_service,
51d5ef9f
AR
2008 2, 2, 0,
2009 doc: /* Perform Nextstep SERVICE on SEND.
d26fbe1a
CY
2010SEND should be either a string or nil.
2011The return value is the result of the service, as string, or nil if
51d5ef9f 2012there was no result. */)
5842a27b 2013 (Lisp_Object service, Lisp_Object send)
edfda783
AR
2014{
2015 id pb;
2016 NSString *svcName;
2017 char *utfStr;
edfda783
AR
2018
2019 CHECK_STRING (service);
7452b7bd 2020 check_window_system (NULL);
edfda783 2021
0dc8cf50 2022 utfStr = SSDATA (service);
edfda783
AR
2023 svcName = [NSString stringWithUTF8String: utfStr];
2024
2025 pb =[NSPasteboard pasteboardWithUniqueName];
2026 ns_string_to_pasteboard (pb, send);
2027
2028 if (NSPerformService (svcName, pb) == NO)
6c6f1994 2029 Fsignal (Qquit, list1 (build_string ("service not available")));
edfda783
AR
2030
2031 if ([[pb types] count] == 0)
2032 return build_string ("");
2033 return ns_string_from_pasteboard (pb);
2034}
2035
2036
2037DEFUN ("ns-convert-utf8-nfd-to-nfc", Fns_convert_utf8_nfd_to_nfc,
2038 Sns_convert_utf8_nfd_to_nfc, 1, 1, 0,
b066e6b6 2039 doc: /* Return an NFC string that matches the UTF-8 NFD string STR. */)
5842a27b 2040 (Lisp_Object str)
edfda783 2041{
f2f7f42c
AR
2042/* TODO: If GNUstep ever implements precomposedStringWithCanonicalMapping,
2043 remove this. */
edfda783 2044 NSString *utfStr;
0486beac
JD
2045 Lisp_Object ret = Qnil;
2046 NSAutoreleasePool *pool;
edfda783
AR
2047
2048 CHECK_STRING (str);
0486beac
JD
2049 pool = [[NSAutoreleasePool alloc] init];
2050 utfStr = [NSString stringWithUTF8String: SSDATA (str)];
c0342369 2051#ifdef NS_IMPL_COCOA
0486beac
JD
2052 if (utfStr)
2053 utfStr = [utfStr precomposedStringWithCanonicalMapping];
c0342369 2054#endif
0486beac
JD
2055 if (utfStr)
2056 {
2057 const char *cstr = [utfStr UTF8String];
2058 if (cstr)
2059 ret = build_string (cstr);
2060 }
2061
423d3b3f 2062 [pool release];
0486beac
JD
2063 if (NILP (ret))
2064 error ("Invalid UTF-8");
2065
423d3b3f 2066 return ret;
edfda783
AR
2067}
2068
2069
583ff3c3
AR
2070#ifdef NS_IMPL_COCOA
2071
2072/* Compile and execute the AppleScript SCRIPT and return the error
2073 status as function value. A zero is returned if compilation and
2074 execution is successful, in which case *RESULT is set to a Lisp
2075 string or a number containing the resulting script value. Otherwise,
2076 1 is returned. */
2077static int
3d608a86 2078ns_do_applescript (Lisp_Object script, Lisp_Object *result)
583ff3c3
AR
2079{
2080 NSAppleEventDescriptor *desc;
2081 NSDictionary* errorDict;
2082 NSAppleEventDescriptor* returnDescriptor = NULL;
2083
2084 NSAppleScript* scriptObject =
2085 [[NSAppleScript alloc] initWithSource:
0dc8cf50 2086 [NSString stringWithUTF8String: SSDATA (script)]];
583ff3c3
AR
2087
2088 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
2089 [scriptObject release];
b066e6b6 2090
583ff3c3 2091 *result = Qnil;
b066e6b6 2092
583ff3c3
AR
2093 if (returnDescriptor != NULL)
2094 {
2095 // successful execution
2096 if (kAENullEvent != [returnDescriptor descriptorType])
2097 {
2098 *result = Qt;
2099 // script returned an AppleScript result
2100 if ((typeUnicodeText == [returnDescriptor descriptorType]) ||
335f5ae4 2101#if defined (NS_IMPL_COCOA)
b066e6b6 2102 (typeUTF16ExternalRepresentation
583ff3c3 2103 == [returnDescriptor descriptorType]) ||
a39e2539 2104#endif
583ff3c3
AR
2105 (typeUTF8Text == [returnDescriptor descriptorType]) ||
2106 (typeCString == [returnDescriptor descriptorType]))
2107 {
2108 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2109 if (desc)
2110 *result = build_string([[desc stringValue] UTF8String]);
2111 }
2112 else
2113 {
2114 /* use typeUTF16ExternalRepresentation? */
2115 // coerce the result to the appropriate ObjC type
2116 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2117 if (desc)
2118 *result = make_number([desc int32Value]);
2119 }
2120 }
2121 }
2122 else
2123 {
2124 // no script result, return error
2125 return 1;
2126 }
2127 return 0;
2128}
2129
08e3161a
JD
2130/* Helper function called from sendEvent to run applescript
2131 from within the main event loop. */
2132
2133void
2134ns_run_ascript (void)
2135{
cf162aee
JD
2136 if (! NILP (as_script))
2137 as_status = ns_do_applescript (as_script, as_result);
2138 as_script = Qnil;
08e3161a
JD
2139}
2140
583ff3c3 2141DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0,
b066e6b6
JB
2142 doc: /* Execute AppleScript SCRIPT and return the result.
2143If compilation and execution are successful, the resulting script value
2144is returned as a string, a number or, in the case of other constructs, t.
2145In case the execution fails, an error is signaled. */)
5842a27b 2146 (Lisp_Object script)
583ff3c3
AR
2147{
2148 Lisp_Object result;
5fdb398c 2149 int status;
08e3161a 2150 NSEvent *nxev;
583ff3c3
AR
2151
2152 CHECK_STRING (script);
7452b7bd 2153 check_window_system (NULL);
583ff3c3 2154
4d7e6e51 2155 block_input ();
08e3161a
JD
2156
2157 as_script = script;
2158 as_result = &result;
2159
2160 /* executing apple script requires the event loop to run, otherwise
2161 errors aren't returned and executeAndReturnError hangs forever.
2162 Post an event that runs applescript and then start the event loop.
2163 The event loop is exited when the script is done. */
2164 nxev = [NSEvent otherEventWithType: NSApplicationDefined
2165 location: NSMakePoint (0, 0)
2166 modifierFlags: 0
2167 timestamp: 0
2168 windowNumber: [[NSApp mainWindow] windowNumber]
2169 context: [NSApp context]
2170 subtype: 0
2171 data1: 0
2172 data2: NSAPP_DATA2_RUNASSCRIPT];
2173
2174 [NSApp postEvent: nxev atStart: NO];
cf162aee
JD
2175
2176 // If there are other events, the event loop may exit. Keep running
677d5c92 2177 // until the script has been handled. */
cf162aee
JD
2178 while (! NILP (as_script))
2179 [NSApp run];
08e3161a
JD
2180
2181 status = as_status;
2182 as_status = 0;
08e3161a 2183 as_result = 0;
4d7e6e51 2184 unblock_input ();
583ff3c3
AR
2185 if (status == 0)
2186 return result;
2187 else if (!STRINGP (result))
2188 error ("AppleScript error %d", status);
2189 else
0dc8cf50 2190 error ("%s", SSDATA (result));
583ff3c3
AR
2191}
2192#endif
2193
2194
2195
edfda783
AR
2196/* ==========================================================================
2197
2198 Miscellaneous functions not called through hooks
2199
2200 ========================================================================== */
2201
3fe53a83 2202/* called from frame.c */
edfda783
AR
2203struct ns_display_info *
2204check_x_display_info (Lisp_Object frame)
2205{
2206 return check_ns_display_info (frame);
2207}
2208
2209
edfda783 2210void
3d608a86 2211x_set_scroll_bar_default_width (struct frame *f)
edfda783
AR
2212{
2213 int wid = FRAME_COLUMN_WIDTH (f);
2214 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = NS_SCROLL_BAR_WIDTH_DEFAULT;
2215 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) +
2216 wid - 1) / wid;
2217}
2218
3fe53a83 2219/* terms impl this instead of x-get-resource directly */
a6c2ee1b
DA
2220char *
2221x_get_string_resource (XrmDatabase rdb, const char *name, const char *class)
edfda783 2222{
6fb5f7da 2223 /* remove appname prefix; TODO: allow for !="Emacs" */
a6c2ee1b
DA
2224 const char *res, *toCheck = class + (!strncmp (class, "Emacs.", 6) ? 6 : 0);
2225
7452b7bd 2226 check_window_system (NULL);
edfda783 2227
386a49d3
AR
2228 if (inhibit_x_resources)
2229 /* --quick was passed, so this is a no-op. */
2230 return NULL;
edfda783 2231
f7dfe5d6 2232 res = ns_get_defaults_value (toCheck);
a6c2ee1b
DA
2233 return (!res ? NULL :
2234 (!c_strncasecmp (res, "YES", 3) ? "true" :
2235 (!c_strncasecmp (res, "NO", 2) ? "false" : (char *) res)));
edfda783
AR
2236}
2237
2238
2239Lisp_Object
2240x_get_focus_frame (struct frame *frame)
2241{
aad3612f 2242 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
edfda783
AR
2243 Lisp_Object nsfocus;
2244
9e50ff0c 2245 if (!dpyinfo->x_focus_frame)
edfda783
AR
2246 return Qnil;
2247
9e50ff0c 2248 XSETFRAME (nsfocus, dpyinfo->x_focus_frame);
edfda783
AR
2249 return nsfocus;
2250}
2251
edfda783
AR
2252/* ==========================================================================
2253
2254 Lisp definitions that, for whatever reason, we can't alias as 'ns-XXX'.
2255
2256 ========================================================================== */
2257
2258
952913d4 2259DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
4f4f2973
GM
2260 doc: /* Internal function called by `color-defined-p', which see.
2261\(Note that the Nextstep version of this function ignores FRAME.) */)
5842a27b 2262 (Lisp_Object color, Lisp_Object frame)
edfda783
AR
2263{
2264 NSColor * col;
7452b7bd 2265 check_window_system (NULL);
edfda783
AR
2266 return ns_lisp_to_color (color, &col) ? Qnil : Qt;
2267}
2268
2269
952913d4 2270DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
fb67c21b 2271 doc: /* Internal function called by `color-values', which see. */)
5842a27b 2272 (Lisp_Object color, Lisp_Object frame)
edfda783
AR
2273{
2274 NSColor * col;
c0342369 2275 EmacsCGFloat red, green, blue, alpha;
edfda783 2276
7452b7bd 2277 check_window_system (NULL);
edfda783
AR
2278 CHECK_STRING (color);
2279
2280 if (ns_lisp_to_color (color, &col))
2281 return Qnil;
2282
2283 [[col colorUsingColorSpaceName: NSCalibratedRGBColorSpace]
2284 getRed: &red green: &green blue: &blue alpha: &alpha];
3de717bd
DA
2285 return list3i (lrint (red * 65280), lrint (green * 65280),
2286 lrint (blue * 65280));
edfda783
AR
2287}
2288
2289
2290DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
4f4f2973 2291 doc: /* Internal function called by `display-color-p', which see. */)
91e8418b 2292 (Lisp_Object terminal)
edfda783
AR
2293{
2294 NSWindowDepth depth;
2295 NSString *colorSpace;
a37d34f3 2296
91e8418b
YM
2297 check_ns_display_info (terminal);
2298 depth = [[[NSScreen screens] objectAtIndex:0] depth];
edfda783
AR
2299 colorSpace = NSColorSpaceFromDepth (depth);
2300
2301 return [colorSpace isEqualToString: NSDeviceWhiteColorSpace]
2302 || [colorSpace isEqualToString: NSCalibratedWhiteColorSpace]
2303 ? Qnil : Qt;
2304}
2305
2306
91e8418b
YM
2307DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p,
2308 0, 1, 0,
51d5ef9f 2309 doc: /* Return t if the Nextstep display supports shades of gray.
d26fbe1a 2310Note that color displays do support shades of gray.
91e8418b
YM
2311The optional argument TERMINAL specifies which display to ask about.
2312TERMINAL should be a terminal object, a frame or a display name (a string).
2313If omitted or nil, that stands for the selected frame's display. */)
2314 (Lisp_Object terminal)
edfda783
AR
2315{
2316 NSWindowDepth depth;
7452b7bd 2317
91e8418b
YM
2318 check_ns_display_info (terminal);
2319 depth = [[[NSScreen screens] objectAtIndex:0] depth];
edfda783
AR
2320
2321 return NSBitsPerPixelFromDepth (depth) > 1 ? Qt : Qnil;
2322}
2323
2324
952913d4 2325DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
edfda783 2326 0, 1, 0,
91e8418b
YM
2327 doc: /* Return the width in pixels of the Nextstep display TERMINAL.
2328The optional argument TERMINAL specifies which display to ask about.
2329TERMINAL should be a terminal object, a frame or a display name (a string).
2330If omitted or nil, that stands for the selected frame's display.
2331
2332On \"multi-monitor\" setups this refers to the pixel width for all
2333physical monitors associated with TERMINAL. To get information for
2334each physical monitor, use `display-monitor-attributes-list'. */)
2335 (Lisp_Object terminal)
edfda783 2336{
91e8418b
YM
2337 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
2338
2339 return make_number (x_display_pixel_width (dpyinfo));
edfda783
AR
2340}
2341
2342
952913d4
DN
2343DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
2344 Sx_display_pixel_height, 0, 1, 0,
91e8418b
YM
2345 doc: /* Return the height in pixels of the Nextstep display TERMINAL.
2346The optional argument TERMINAL specifies which display to ask about.
2347TERMINAL should be a terminal object, a frame or a display name (a string).
2348If omitted or nil, that stands for the selected frame's display.
2349
2350On \"multi-monitor\" setups this refers to the pixel height for all
2351physical monitors associated with TERMINAL. To get information for
2352each physical monitor, use `display-monitor-attributes-list'. */)
2353 (Lisp_Object terminal)
edfda783 2354{
91e8418b
YM
2355 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
2356
2357 return make_number (x_display_pixel_height (dpyinfo));
edfda783
AR
2358}
2359
4465bfb4 2360#ifdef NS_IMPL_COCOA
ceb486d4
JD
2361
2362/* Returns the name for the screen that OBJ represents, or NULL.
4465bfb4
JD
2363 Caller must free return value.
2364*/
583ff3c3 2365
6799bb26 2366static char *
ceb486d4 2367ns_get_name_from_ioreg (io_object_t obj)
4465bfb4
JD
2368{
2369 char *name = NULL;
ceb486d4 2370
4465bfb4 2371 NSDictionary *info = (NSDictionary *)
ceb486d4
JD
2372 IODisplayCreateInfoDictionary (obj, kIODisplayOnlyPreferredName);
2373 NSDictionary *names = [info objectForKey:
2374 [NSString stringWithUTF8String:
2375 kDisplayProductName]];
2376
2377 if ([names count] > 0)
2378 {
2379 NSString *n = [names objectForKey: [[names allKeys]
2380 objectAtIndex:0]];
2381 if (n != nil) name = xstrdup ([n UTF8String]);
2382 }
d26fbe1a 2383
4465bfb4 2384 [info release];
ceb486d4
JD
2385
2386 return name;
2387}
2388
2389/* Returns the name for the screen that DID came from, or NULL.
2390 Caller must free return value.
2391*/
2392
2393static char *
2394ns_screen_name (CGDirectDisplayID did)
2395{
2396 char *name = NULL;
2397
2398#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
2399 mach_port_t masterPort;
2400 io_iterator_t it;
2401 io_object_t obj;
2402
2403 // CGDisplayIOServicePort is deprecated. Do it another (harder) way.
2404
2405 if (IOMasterPort (MACH_PORT_NULL, &masterPort) != kIOReturnSuccess
2406 || IOServiceGetMatchingServices (masterPort,
2407 IOServiceMatching ("IONDRVDevice"),
2408 &it) != kIOReturnSuccess)
2409 return name;
2410
2411 /* Must loop until we find a name. Many devices can have the same unit
2412 number (represents different GPU parts), but only one has a name. */
2413 while (! name && (obj = IOIteratorNext (it)))
2414 {
2415 CFMutableDictionaryRef props;
2416 const void *val;
2417
2418 if (IORegistryEntryCreateCFProperties (obj,
2419 &props,
2420 kCFAllocatorDefault,
2421 kNilOptions) == kIOReturnSuccess
2422 && props != nil
2423 && (val = CFDictionaryGetValue(props, @"IOFBDependentIndex")))
2424 {
2425 unsigned nr = [(NSNumber *)val unsignedIntegerValue];
2426 if (nr == CGDisplayUnitNumber (did))
2427 name = ns_get_name_from_ioreg (obj);
2428 }
2429
2430 CFRelease (props);
2431 IOObjectRelease (obj);
2432 }
2433
2434 IOObjectRelease (it);
2435
2436#else
2437
2438 name = ns_get_name_from_ioreg (CGDisplayIOServicePort (did));
2439
2440#endif
4465bfb4
JD
2441 return name;
2442}
2443#endif
2444
2445static Lisp_Object
2446ns_make_monitor_attribute_list (struct MonitorInfo *monitors,
2447 int n_monitors,
2448 int primary_monitor,
2449 const char *source)
2450{
2451 Lisp_Object monitor_frames = Fmake_vector (make_number (n_monitors), Qnil);
6799bb26 2452 Lisp_Object frame, rest;
4465bfb4
JD
2453 NSArray *screens = [NSScreen screens];
2454 int i;
2455
2456 FOR_EACH_FRAME (rest, frame)
2457 {
2458 struct frame *f = XFRAME (frame);
2459
2460 if (FRAME_NS_P (f))
2461 {
2462 NSView *view = FRAME_NS_VIEW (f);
2463 NSScreen *screen = [[view window] screen];
2464 NSUInteger k;
2465
2466 i = -1;
2467 for (k = 0; i == -1 && k < [screens count]; ++k)
2468 {
2469 if ([screens objectAtIndex: k] == screen)
2470 i = (int)k;
2471 }
2472
2473 if (i > -1)
2474 ASET (monitor_frames, i, Fcons (frame, AREF (monitor_frames, i)));
2475 }
2476 }
2477
6799bb26
JD
2478 return make_monitor_attribute_list (monitors, n_monitors, primary_monitor,
2479 monitor_frames, source);
4465bfb4
JD
2480}
2481
2482DEFUN ("ns-display-monitor-attributes-list",
2483 Fns_display_monitor_attributes_list,
2484 Sns_display_monitor_attributes_list,
2485 0, 1, 0,
2486 doc: /* Return a list of physical monitor attributes on the X display TERMINAL.
2487
2488The optional argument TERMINAL specifies which display to ask about.
2489TERMINAL should be a terminal object, a frame or a display name (a string).
2490If omitted or nil, that stands for the selected frame's display.
2491
2492In addition to the standard attribute keys listed in
2493`display-monitor-attributes-list', the following keys are contained in
2494the attributes:
2495
2496 source -- String describing the source from which multi-monitor
2497 information is obtained, \"NS\" is always the source."
2498
2499Internal use only, use `display-monitor-attributes-list' instead. */)
2500 (Lisp_Object terminal)
edfda783 2501{
4465bfb4
JD
2502 struct terminal *term = get_terminal (terminal, 1);
2503 NSArray *screens;
2504 NSUInteger i, n_monitors;
2505 struct MonitorInfo *monitors;
2506 Lisp_Object attributes_list = Qnil;
2507 CGFloat primary_display_height = 0;
edfda783 2508
4465bfb4
JD
2509 if (term->type != output_ns)
2510 return Qnil;
2511
2512 screens = [NSScreen screens];
2513 n_monitors = [screens count];
2514 if (n_monitors == 0)
474217c8
CY
2515 return Qnil;
2516
7d652d97 2517 monitors = xzalloc (n_monitors * sizeof *monitors);
4465bfb4
JD
2518
2519 for (i = 0; i < [screens count]; ++i)
2520 {
2521 NSScreen *s = [screens objectAtIndex:i];
2522 struct MonitorInfo *m = &monitors[i];
2523 NSRect fr = [s frame];
2524 NSRect vfr = [s visibleFrame];
4465bfb4
JD
2525 short y, vy;
2526
2527#ifdef NS_IMPL_COCOA
c0342369 2528 NSDictionary *dict = [s deviceDescription];
4465bfb4
JD
2529 NSNumber *nid = [dict objectForKey:@"NSScreenNumber"];
2530 CGDirectDisplayID did = [nid unsignedIntValue];
2531#endif
2532 if (i == 0)
2533 {
2534 primary_display_height = fr.size.height;
2535 y = (short) fr.origin.y;
2536 vy = (short) vfr.origin.y;
2537 }
2538 else
2539 {
2540 // Flip y coordinate as NS has y starting from the bottom.
2541 y = (short) (primary_display_height - fr.size.height - fr.origin.y);
2542 vy = (short) (primary_display_height -
2543 vfr.size.height - vfr.origin.y);
2544 }
cf7a0de6 2545
4465bfb4
JD
2546 m->geom.x = (short) fr.origin.x;
2547 m->geom.y = y;
2548 m->geom.width = (unsigned short) fr.size.width;
2549 m->geom.height = (unsigned short) fr.size.height;
2550
2551 m->work.x = (short) vfr.origin.x;
2552 // y is flipped on NS, so vy - y are pixels missing at the bottom,
2553 // and fr.size.height - vfr.size.height are pixels missing in total.
2554 // Pixels missing at top are
2555 // fr.size.height - vfr.size.height - vy + y.
2556 // work.y is then pixels missing at top + y.
2557 m->work.y = (short) (fr.size.height - vfr.size.height) - vy + y + y;
2558 m->work.width = (unsigned short) vfr.size.width;
2559 m->work.height = (unsigned short) vfr.size.height;
2560
2561#ifdef NS_IMPL_COCOA
2562 m->name = ns_screen_name (did);
2563
2564 {
2565 CGSize mms = CGDisplayScreenSize (did);
2566 m->mm_width = (int) mms.width;
2567 m->mm_height = (int) mms.height;
2568 }
2569
2570#else
2571 // Assume 92 dpi as x-display-mm-height/x-display-mm-width does.
2572 m->mm_width = (int) (25.4 * fr.size.width / 92.0);
2573 m->mm_height = (int) (25.4 * fr.size.height / 92.0);
2574#endif
2575 }
2576
2577 // Primary monitor is always first for NS.
2578 attributes_list = ns_make_monitor_attribute_list (monitors, n_monitors,
2579 0, "NS");
edfda783 2580
4465bfb4
JD
2581 free_monitors (monitors, n_monitors);
2582 return attributes_list;
edfda783
AR
2583}
2584
2585
952913d4 2586DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
edfda783 2587 0, 1, 0,
91e8418b
YM
2588 doc: /* Return the number of bitplanes of the Nextstep display TERMINAL.
2589The optional argument TERMINAL specifies which display to ask about.
2590TERMINAL should be a terminal object, a frame or a display name (a string).
51d5ef9f 2591If omitted or nil, that stands for the selected frame's display. */)
91e8418b 2592 (Lisp_Object terminal)
edfda783 2593{
91e8418b 2594 check_ns_display_info (terminal);
edfda783 2595 return make_number
91e8418b 2596 (NSBitsPerPixelFromDepth ([[[NSScreen screens] objectAtIndex:0] depth]));
edfda783
AR
2597}
2598
2599
91e8418b
YM
2600DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
2601 0, 1, 0,
2602 doc: /* Returns the number of color cells of the Nextstep display TERMINAL.
2603The optional argument TERMINAL specifies which display to ask about.
2604TERMINAL should be a terminal object, a frame or a display name (a string).
51d5ef9f 2605If omitted or nil, that stands for the selected frame's display. */)
91e8418b 2606 (Lisp_Object terminal)
edfda783 2607{
91e8418b 2608 struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
edfda783
AR
2609 /* We force 24+ bit depths to 24-bit to prevent an overflow. */
2610 return make_number (1 << min (dpyinfo->n_planes, 24));
2611}
2612
2613
2614/* Unused dummy def needed for compatibility. */
2615Lisp_Object tip_frame;
2616
6fb5f7da 2617/* TODO: move to xdisp or similar */
edfda783 2618static void
3d608a86
J
2619compute_tip_xy (struct frame *f,
2620 Lisp_Object parms,
2621 Lisp_Object dx,
2622 Lisp_Object dy,
2623 int width,
2624 int height,
2625 int *root_x,
2626 int *root_y)
edfda783
AR
2627{
2628 Lisp_Object left, top;
2629 EmacsView *view = FRAME_NS_VIEW (f);
18da0d8a 2630 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
edfda783 2631 NSPoint pt;
b066e6b6 2632
edfda783
AR
2633 /* Start with user-specified or mouse position. */
2634 left = Fcdr (Fassq (Qleft, parms));
edfda783 2635 top = Fcdr (Fassq (Qtop, parms));
edfda783 2636
7a18115b
J
2637 if (!INTEGERP (left) || !INTEGERP (top))
2638 {
18da0d8a
DA
2639 pt.x = dpyinfo->last_mouse_motion_x;
2640 pt.y = dpyinfo->last_mouse_motion_y;
7a18115b
J
2641 /* Convert to screen coordinates */
2642 pt = [view convertPoint: pt toView: nil];
2643 pt = [[view window] convertBaseToScreen: pt];
2644 }
2645 else
2646 {
2647 /* Absolute coordinates. */
2648 pt.x = XINT (left);
aad3612f 2649 pt.y = x_display_pixel_height (FRAME_DISPLAY_INFO (f)) - XINT (top)
7a18115b
J
2650 - height;
2651 }
5fdb398c 2652
edfda783 2653 /* Ensure in bounds. (Note, screen origin = lower left.) */
7a18115b
J
2654 if (INTEGERP (left))
2655 *root_x = pt.x;
2656 else if (pt.x + XINT (dx) <= 0)
edfda783 2657 *root_x = 0; /* Can happen for negative dx */
889bd438 2658 else if (pt.x + XINT (dx) + width
aad3612f 2659 <= x_display_pixel_width (FRAME_DISPLAY_INFO (f)))
edfda783
AR
2660 /* It fits to the right of the pointer. */
2661 *root_x = pt.x + XINT (dx);
2662 else if (width + XINT (dx) <= pt.x)
2663 /* It fits to the left of the pointer. */
2664 *root_x = pt.x - width - XINT (dx);
2665 else
2666 /* Put it left justified on the screen -- it ought to fit that way. */
2667 *root_x = 0;
2668
7a18115b
J
2669 if (INTEGERP (top))
2670 *root_y = pt.y;
2671 else if (pt.y - XINT (dy) - height >= 0)
edfda783
AR
2672 /* It fits below the pointer. */
2673 *root_y = pt.y - height - XINT (dy);
889bd438 2674 else if (pt.y + XINT (dy) + height
aad3612f 2675 <= x_display_pixel_height (FRAME_DISPLAY_INFO (f)))
edfda783
AR
2676 /* It fits above the pointer */
2677 *root_y = pt.y + XINT (dy);
2678 else
2679 /* Put it on the top. */
aad3612f 2680 *root_y = x_display_pixel_height (FRAME_DISPLAY_INFO (f)) - height;
edfda783
AR
2681}
2682
2683
2684DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
b066e6b6 2685 doc: /* Show STRING in a \"tooltip\" window on frame FRAME.
edfda783
AR
2686A tooltip window is a small window displaying a string.
2687
4f4f2973
GM
2688This is an internal function; Lisp code should call `tooltip-show'.
2689
edfda783
AR
2690FRAME nil or omitted means use the selected frame.
2691
2692PARMS is an optional list of frame parameters which can be used to
2693change the tooltip's appearance.
2694
2695Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
2696means use the default timeout of 5 seconds.
2697
2698If the list of frame parameters PARMS contains a `left' parameter,
2699the tooltip is displayed at that x-position. Otherwise it is
2700displayed at the mouse position, with offset DX added (default is 5 if
2701DX isn't specified). Likewise for the y-position; if a `top' frame
2702parameter is specified, it determines the y-position of the tooltip
2703window, otherwise it is displayed at the mouse position, with offset
2704DY added (default is -10).
2705
2706A tooltip's maximum size is specified by `x-max-tooltip-size'.
2707Text larger than the specified size is clipped. */)
5842a27b 2708 (Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy)
edfda783
AR
2709{
2710 int root_x, root_y;
2711 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
d311d28c 2712 ptrdiff_t count = SPECPDL_INDEX ();
edfda783
AR
2713 struct frame *f;
2714 char *str;
2715 NSSize size;
2716
2717 specbind (Qinhibit_redisplay, Qt);
2718
2719 GCPRO4 (string, parms, frame, timeout);
2720
2721 CHECK_STRING (string);
0dc8cf50 2722 str = SSDATA (string);
7452b7bd 2723 f = decode_window_system_frame (frame);
edfda783
AR
2724 if (NILP (timeout))
2725 timeout = make_number (5);
2726 else
2727 CHECK_NATNUM (timeout);
2728
2729 if (NILP (dx))
2730 dx = make_number (5);
2731 else
2732 CHECK_NUMBER (dx);
2733
2734 if (NILP (dy))
2735 dy = make_number (-10);
2736 else
2737 CHECK_NUMBER (dy);
2738
4d7e6e51 2739 block_input ();
edfda783
AR
2740 if (ns_tooltip == nil)
2741 ns_tooltip = [[EmacsTooltip alloc] init];
2742 else
2743 Fx_hide_tip ();
2744
2745 [ns_tooltip setText: str];
2746 size = [ns_tooltip frame].size;
2747
2748 /* Move the tooltip window where the mouse pointer is. Resize and
2749 show it. */
2750 compute_tip_xy (f, parms, dx, dy, (int)size.width, (int)size.height,
2751 &root_x, &root_y);
2752
2753 [ns_tooltip showAtX: root_x Y: root_y for: XINT (timeout)];
4d7e6e51 2754 unblock_input ();
edfda783
AR
2755
2756 UNGCPRO;
2757 return unbind_to (count, Qnil);
2758}
2759
2760
2761DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
2762 doc: /* Hide the current tooltip window, if there is any.
2763Value is t if tooltip was open, nil otherwise. */)
5842a27b 2764 (void)
edfda783
AR
2765{
2766 if (ns_tooltip == nil || ![ns_tooltip isActive])
2767 return Qnil;
2768 [ns_tooltip hide];
2769 return Qt;
2770}
2771
2772
cc98b6a0
DN
2773/* ==========================================================================
2774
2775 Class implementations
2776
2777 ========================================================================== */
2778
edbdcec0
JD
2779/*
2780 Handle arrow/function/control keys and copy/paste/cut in file dialogs.
a37d34f3 2781 Return YES if handled, NO if not.
edbdcec0
JD
2782 */
2783static BOOL
2784handlePanelKeys (NSSavePanel *panel, NSEvent *theEvent)
2785{
2786 NSString *s;
2787 int i;
2788 BOOL ret = NO;
2789
2790 if ([theEvent type] != NSKeyDown) return NO;
2791 s = [theEvent characters];
2792
2793 for (i = 0; i < [s length]; ++i)
2794 {
2795 int ch = (int) [s characterAtIndex: i];
2796 switch (ch)
2797 {
2798 case NSHomeFunctionKey:
2799 case NSDownArrowFunctionKey:
2800 case NSUpArrowFunctionKey:
2801 case NSLeftArrowFunctionKey:
2802 case NSRightArrowFunctionKey:
2803 case NSPageUpFunctionKey:
2804 case NSPageDownFunctionKey:
2805 case NSEndFunctionKey:
9d3f2fc2
JD
2806 /* Don't send command modified keys, as those are handled in the
2807 performKeyEquivalent method of the super class.
2808 */
2809 if (! ([theEvent modifierFlags] & NSCommandKeyMask))
2810 {
2811 [panel sendEvent: theEvent];
2812 ret = YES;
2813 }
edbdcec0
JD
2814 break;
2815 /* As we don't have the standard key commands for
2816 copy/paste/cut/select-all in our edit menu, we must handle
2817 them here. TODO: handle Emacs key bindings for copy/cut/select-all
2818 here, paste works, because we have that in our Edit menu.
2819 I.e. refactor out code in nsterm.m, keyDown: to figure out the
2820 correct modifier.
2821 */
2822 case 'x': // Cut
2823 case 'c': // Copy
2824 case 'v': // Paste
2825 case 'a': // Select all
2826 if ([theEvent modifierFlags] & NSCommandKeyMask)
2827 {
2828 [NSApp sendAction:
2829 (ch == 'x'
2830 ? @selector(cut:)
2831 : (ch == 'c'
2832 ? @selector(copy:)
2833 : (ch == 'v'
2834 ? @selector(paste:)
2835 : @selector(selectAll:))))
2836 to:nil from:panel];
2837 ret = YES;
2838 }
2839 default:
2840 // Send all control keys, as the text field supports C-a, C-f, C-e
2841 // C-b and more.
2842 if ([theEvent modifierFlags] & NSControlKeyMask)
2843 {
2844 [panel sendEvent: theEvent];
2845 ret = YES;
2846 }
2847 break;
2848 }
2849 }
2850
2851
2852 return ret;
2853}
cc98b6a0
DN
2854
2855@implementation EmacsSavePanel
edbdcec0
JD
2856- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
2857{
2858 BOOL ret = handlePanelKeys (self, theEvent);
2859 if (! ret)
2860 ret = [super performKeyEquivalent:theEvent];
2861 return ret;
2862}
cc98b6a0
DN
2863@end
2864
2865
2866@implementation EmacsOpenPanel
edbdcec0
JD
2867- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
2868{
2869 // NSOpenPanel inherits NSSavePanel, so passing self is OK.
2870 BOOL ret = handlePanelKeys (self, theEvent);
2871 if (! ret)
2872 ret = [super performKeyEquivalent:theEvent];
2873 return ret;
2874}
cc98b6a0
DN
2875@end
2876
2877
2878@implementation EmacsFileDelegate
2879/* --------------------------------------------------------------------------
2880 Delegate methods for Open/Save panels
2881 -------------------------------------------------------------------------- */
2882- (BOOL)panel: (id)sender isValidFilename: (NSString *)filename
2883{
2884 return YES;
2885}
2886- (BOOL)panel: (id)sender shouldShowFilename: (NSString *)filename
2887{
2888 return YES;
2889}
2890- (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
2891 confirmed: (BOOL)okFlag
2892{
2893 return filename;
2894}
2895@end
2896
2897#endif
2898
ba301db3 2899
edfda783
AR
2900/* ==========================================================================
2901
2902 Lisp interface declaration
2903
2904 ========================================================================== */
2905
2906
2907void
3d608a86 2908syms_of_nsfns (void)
edfda783 2909{
088dcc3e 2910 Qfontsize = intern_c_string ("fontsize");
edfda783
AR
2911 staticpro (&Qfontsize);
2912
fb9d0f5a 2913 DEFVAR_LISP ("ns-icon-type-alist", Vns_icon_type_alist,
51d5ef9f 2914 doc: /* Alist of elements (REGEXP . IMAGE) for images of icons associated to frames.
d26fbe1a
CY
2915If the title of a frame matches REGEXP, then IMAGE.tiff is
2916selected as the image of the icon representing the frame when it's
2917miniaturized. If an element is t, then Emacs tries to select an icon
2918based on the filetype of the visited file.
2919
2920The images have to be installed in a folder called English.lproj in the
2921Emacs folder. You have to restart Emacs after installing new icons.
2922
2923Example: Install an icon Gnus.tiff and execute the following code
2924
2925 (setq ns-icon-type-alist
2926 (append ns-icon-type-alist
2927 '((\"^\\\\*\\\\(Group\\\\*$\\\\|Summary \\\\|Article\\\\*$\\\\)\"
2928 . \"Gnus\"))))
2929
2930When you miniaturize a Group, Summary or Article frame, Gnus.tiff will
51d5ef9f 2931be used as the image of the icon representing the frame. */);
6c6f1994 2932 Vns_icon_type_alist = list1 (Qt);
edfda783 2933
fb9d0f5a 2934 DEFVAR_LISP ("ns-version-string", Vns_version_string,
cb83c00b 2935 doc: /* Toolkit version for NS Windowing. */);
f5497e45 2936 Vns_version_string = ns_appkit_version_str ();
cb83c00b 2937
edfda783
AR
2938 defsubr (&Sns_read_file_name);
2939 defsubr (&Sns_get_resource);
2940 defsubr (&Sns_set_resource);
2941 defsubr (&Sxw_display_color_p); /* this and next called directly by C code */
2942 defsubr (&Sx_display_grayscale_p);
edfda783
AR
2943 defsubr (&Sns_font_name);
2944 defsubr (&Sns_list_colors);
74876614 2945#ifdef NS_IMPL_COCOA
583ff3c3 2946 defsubr (&Sns_do_applescript);
74876614 2947#endif
952913d4
DN
2948 defsubr (&Sxw_color_defined_p);
2949 defsubr (&Sxw_color_values);
2950 defsubr (&Sx_server_max_request_size);
9e50ff0c
DN
2951 defsubr (&Sx_server_vendor);
2952 defsubr (&Sx_server_version);
952913d4
DN
2953 defsubr (&Sx_display_pixel_width);
2954 defsubr (&Sx_display_pixel_height);
4465bfb4 2955 defsubr (&Sns_display_monitor_attributes_list);
9e50ff0c
DN
2956 defsubr (&Sx_display_mm_width);
2957 defsubr (&Sx_display_mm_height);
2958 defsubr (&Sx_display_screens);
952913d4
DN
2959 defsubr (&Sx_display_planes);
2960 defsubr (&Sx_display_color_cells);
9e50ff0c
DN
2961 defsubr (&Sx_display_visual_class);
2962 defsubr (&Sx_display_backing_store);
2963 defsubr (&Sx_display_save_under);
2964 defsubr (&Sx_create_frame);
9e50ff0c
DN
2965 defsubr (&Sx_open_connection);
2966 defsubr (&Sx_close_connection);
2967 defsubr (&Sx_display_list);
edfda783
AR
2968
2969 defsubr (&Sns_hide_others);
2970 defsubr (&Sns_hide_emacs);
2971 defsubr (&Sns_emacs_info_panel);
2972 defsubr (&Sns_list_services);
2973 defsubr (&Sns_perform_service);
2974 defsubr (&Sns_convert_utf8_nfd_to_nfc);
edfda783
AR
2975 defsubr (&Sns_popup_font_panel);
2976 defsubr (&Sns_popup_color_panel);
2977
2978 defsubr (&Sx_show_tip);
2979 defsubr (&Sx_hide_tip);
2980
08e3161a
JD
2981 as_status = 0;
2982 as_script = Qnil;
2983 as_result = 0;
edfda783 2984}