* ccl.c (CCL_CODE_RANGE): Allow negative numbers. (Bug#8751)
[bpt/emacs.git] / src / nsfns.m
CommitLineData
edfda783 1/* Functions for the NeXT/Open/GNUstep and MacOSX window system.
e9bffc61 2
95df8112
GM
3Copyright (C) 1989, 1992-1994, 2005-2006, 2008-2011
4 Free Software Foundation, 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
AR
33#include <signal.h>
34#include <math.h>
b024548b 35#include <setjmp.h>
5a06864f 36
edfda783
AR
37#include "lisp.h"
38#include "blockinput.h"
39#include "nsterm.h"
40#include "window.h"
41#include "buffer.h"
42#include "keyboard.h"
43#include "termhooks.h"
44#include "fontset.h"
edfda783
AR
45#include "character.h"
46#include "font.h"
47
48#if 0
49int fns_trace_num = 1;
50#define NSTRACE(x) fprintf (stderr, "%s:%d: [%d] " #x "\n", \
51 __FILE__, __LINE__, ++fns_trace_num)
52#else
53#define NSTRACE(x)
54#endif
55
56#ifdef HAVE_NS
57
58extern NSArray *ns_send_types, *ns_return_types, *ns_drag_types;
59
60extern Lisp_Object Qforeground_color;
61extern Lisp_Object Qbackground_color;
62extern Lisp_Object Qcursor_color;
63extern Lisp_Object Qinternal_border_width;
64extern Lisp_Object Qvisibility;
65extern Lisp_Object Qcursor_type;
66extern Lisp_Object Qicon_type;
67extern Lisp_Object Qicon_name;
68extern Lisp_Object Qicon_left;
69extern Lisp_Object Qicon_top;
70extern Lisp_Object Qleft;
71extern Lisp_Object Qright;
72extern Lisp_Object Qtop;
73extern Lisp_Object Qdisplay;
74extern Lisp_Object Qvertical_scroll_bars;
75extern Lisp_Object Qauto_raise;
76extern Lisp_Object Qauto_lower;
77extern Lisp_Object Qbox;
78extern Lisp_Object Qscroll_bar_width;
79extern Lisp_Object Qx_resource_name;
80extern Lisp_Object Qface_set_after_frame_default;
81extern Lisp_Object Qunderline, Qundefined;
82extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth;
83extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle;
7ffdf101 84extern Lisp_Object Qnone;
edfda783 85
5d1d3d04 86
edfda783
AR
87Lisp_Object Qbuffered;
88Lisp_Object Qfontsize;
89
90/* hack for OS X file panels */
91char panelOK = 0;
92
edfda783
AR
93EmacsTooltip *ns_tooltip;
94
95/* Need forward declaration here to preserve organizational integrity of file */
9e50ff0c 96Lisp_Object Fx_open_connection (Lisp_Object, Lisp_Object, Lisp_Object);
edfda783
AR
97
98extern BOOL ns_in_resize;
99
100
101/* ==========================================================================
102
103 Internal utility functions
104
105 ========================================================================== */
106
107
108void
109check_ns (void)
110{
111 if (NSApp == nil)
112 error ("OpenStep is not in use or not initialized");
113}
114
115
116/* Nonzero if we can use mouse menus. */
117int
3d608a86 118have_menus_p (void)
edfda783
AR
119{
120 return NSApp != nil;
121}
122
123
124/* Extract a frame as a FRAME_PTR, defaulting to the selected frame
125 and checking validity for NS. */
126static FRAME_PTR
127check_ns_frame (Lisp_Object frame)
128{
129 FRAME_PTR f;
130
131 if (NILP (frame))
132 f = SELECTED_FRAME ();
133 else
134 {
135 CHECK_LIVE_FRAME (frame);
136 f = XFRAME (frame);
137 }
138 if (! FRAME_NS_P (f))
d26fbe1a 139 error ("non-Nextstep frame used");
edfda783
AR
140 return f;
141}
142
143
d26fbe1a
CY
144/* Let the user specify an Nextstep display with a frame.
145 nil stands for the selected frame--or, if that is not an Nextstep frame,
146 the first Nextstep display on the list. */
edfda783
AR
147static struct ns_display_info *
148check_ns_display_info (Lisp_Object frame)
149{
150 if (NILP (frame))
151 {
152 struct frame *f = SELECTED_FRAME ();
153 if (FRAME_NS_P (f) && FRAME_LIVE_P (f) )
154 return FRAME_NS_DISPLAY_INFO (f);
9e50ff0c
DN
155 else if (x_display_list != 0)
156 return x_display_list;
edfda783 157 else
d26fbe1a 158 error ("Nextstep windows are not in use or not initialized");
edfda783
AR
159 }
160 else if (INTEGERP (frame))
161 {
162 struct terminal *t = get_terminal (frame, 1);
163
164 if (t->type != output_ns)
d26fbe1a 165 error ("Terminal %d is not a Nextstep display", XINT (frame));
edfda783
AR
166
167 return t->display_info.ns;
168 }
169 else if (STRINGP (frame))
170 return ns_display_info_for_name (frame);
171 else
172 {
173 FRAME_PTR f;
174
175 CHECK_LIVE_FRAME (frame);
176 f = XFRAME (frame);
177 if (! FRAME_NS_P (f))
d26fbe1a 178 error ("non-Nextstep frame used");
edfda783
AR
179 return FRAME_NS_DISPLAY_INFO (f);
180 }
181 return NULL; /* shut compiler up */
182}
183
184
185static id
186ns_get_window (Lisp_Object maybeFrame)
187{
188 id view =nil, window =nil;
189
190 if (!FRAMEP (maybeFrame) || !FRAME_NS_P (XFRAME (maybeFrame)))
191 maybeFrame = selected_frame;/*wrong_type_argument (Qframep, maybeFrame); */
192
193 if (!NILP (maybeFrame))
194 view = FRAME_NS_VIEW (XFRAME (maybeFrame));
195 if (view) window =[view window];
196
197 return window;
198}
199
200
201static NSScreen *
5996e1b7 202ns_get_screen (Lisp_Object screen)
edfda783 203{
474217c8
CY
204 struct frame *f;
205 struct terminal *terminal;
206
207 if (EQ (Qt, screen)) /* not documented */
208 return [NSScreen mainScreen];
209
210 terminal = get_terminal (screen, 1);
5996e1b7 211 if (terminal->type != output_ns)
474217c8
CY
212 return NULL;
213
214 if (NILP (screen))
215 f = SELECTED_FRAME ();
216 else if (FRAMEP (screen))
217 f = XFRAME (screen);
5996e1b7 218 else
edfda783 219 {
5996e1b7 220 struct ns_display_info *dpyinfo = terminal->display_info.ns;
5d1d3d04
J
221 f = dpyinfo->x_focus_frame
222 ? dpyinfo->x_focus_frame : dpyinfo->x_highlight_frame;
edfda783 223 }
474217c8
CY
224
225 return ((f && FRAME_NS_P (f)) ? [[FRAME_NS_VIEW (f) window] screen]
226 : NULL);
edfda783
AR
227}
228
229
230/* Return the X display structure for the display named NAME.
231 Open a new connection if necessary. */
232struct ns_display_info *
3d608a86 233ns_display_info_for_name (Lisp_Object name)
edfda783
AR
234{
235 Lisp_Object names;
236 struct ns_display_info *dpyinfo;
237
238 CHECK_STRING (name);
239
9e50ff0c 240 for (dpyinfo = x_display_list, names = ns_display_name_list;
edfda783
AR
241 dpyinfo;
242 dpyinfo = dpyinfo->next, names = XCDR (names))
243 {
244 Lisp_Object tem;
245 tem = Fstring_equal (XCAR (XCAR (names)), name);
246 if (!NILP (tem))
247 return dpyinfo;
248 }
249
250 error ("Emacs for OpenStep does not yet support multi-display.");
251
9e50ff0c
DN
252 Fx_open_connection (name, Qnil, Qnil);
253 dpyinfo = x_display_list;
edfda783
AR
254
255 if (dpyinfo == 0)
facfbbbd 256 error ("OpenStep on %s not responding.\n", SDATA (name));
edfda783
AR
257
258 return dpyinfo;
259}
260
261
262static Lisp_Object
263interpret_services_menu (NSMenu *menu, Lisp_Object prefix, Lisp_Object old)
264/* --------------------------------------------------------------------------
265 Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
266 -------------------------------------------------------------------------- */
267{
268 int i, count;
15034960 269 NSMenuItem *item;
edfda783
AR
270 const char *name;
271 Lisp_Object nameStr;
272 unsigned short key;
273 NSString *keys;
274 Lisp_Object res;
275
276 count = [menu numberOfItems];
277 for (i = 0; i<count; i++)
278 {
279 item = [menu itemAtIndex: i];
280 name = [[item title] UTF8String];
281 if (!name) continue;
282
283 nameStr = build_string (name);
284
285 if ([item hasSubmenu])
286 {
287 old = interpret_services_menu ([item submenu],
288 Fcons (nameStr, prefix), old);
289 }
290 else
291 {
292 keys = [item keyEquivalent];
293 if (keys && [keys length] )
294 {
295 key = [keys characterAtIndex: 0];
296 res = make_number (key|super_modifier);
297 }
298 else
299 {
300 res = Qundefined;
301 }
302 old = Fcons (Fcons (res,
303 Freverse (Fcons (nameStr,
304 prefix))),
305 old);
306 }
307 }
308 return old;
309}
310
311
312
313/* ==========================================================================
314
315 Frame parameter setters
316
317 ========================================================================== */
318
319
320static void
89e2438a 321x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783
AR
322{
323 NSColor *col;
324
325 if (ns_lisp_to_color (arg, &col))
326 {
327 store_frame_param (f, Qforeground_color, oldval);
328 error ("Unknown color");
329 }
330
331 [col retain];
332 [f->output_data.ns->foreground_color release];
333 f->output_data.ns->foreground_color = col;
334
335 if (FRAME_NS_VIEW (f))
336 {
337 update_face_from_frame_parameter (f, Qforeground_color, arg);
338 /*recompute_basic_faces (f); */
339 if (FRAME_VISIBLE_P (f))
340 redraw_frame (f);
341 }
342}
343
344
345static void
89e2438a 346x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783
AR
347{
348 struct face *face;
349 NSColor *col;
350 NSView *view = FRAME_NS_VIEW (f);
351 float alpha;
352
353 if (ns_lisp_to_color (arg, &col))
354 {
355 store_frame_param (f, Qbackground_color, oldval);
356 error ("Unknown color");
357 }
358
359 /* clear the frame; in some instances the NS-internal GC appears not to
360 update, or it does update and cannot clear old text properly */
361 if (FRAME_VISIBLE_P (f))
362 ns_clear_frame (f);
363
364 [col retain];
365 [f->output_data.ns->background_color release];
366 f->output_data.ns->background_color = col;
367 if (view != nil)
368 {
369 [[view window] setBackgroundColor: col];
370 alpha = [col alphaComponent];
371
edfda783
AR
372 if (alpha != 1.0)
373 [[view window] setOpaque: NO];
374 else
375 [[view window] setOpaque: YES];
376
377 face = FRAME_DEFAULT_FACE (f);
378 if (face)
379 {
45d325c4 380 col = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f);
facfbbbd
SM
381 face->background
382 = (EMACS_UINT) [[col colorWithAlphaComponent: alpha] retain];
edfda783
AR
383 [col release];
384
385 update_face_from_frame_parameter (f, Qbackground_color, arg);
386 }
387
388 if (FRAME_VISIBLE_P (f))
389 redraw_frame (f);
390 }
391}
392
393
394static void
89e2438a 395x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783
AR
396{
397 NSColor *col;
398
399 if (ns_lisp_to_color (arg, &col))
400 {
401 store_frame_param (f, Qcursor_color, oldval);
402 error ("Unknown color");
403 }
404
c8c057de
AR
405 [FRAME_CURSOR_COLOR (f) release];
406 FRAME_CURSOR_COLOR (f) = [col retain];
edfda783
AR
407
408 if (FRAME_VISIBLE_P (f))
409 {
410 x_update_cursor (f, 0);
411 x_update_cursor (f, 1);
412 }
413 update_face_from_frame_parameter (f, Qcursor_color, arg);
414}
415
c8c057de 416
edfda783 417static void
89e2438a 418x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783
AR
419{
420 NSView *view = FRAME_NS_VIEW (f);
89e2438a 421 NSTRACE (x_set_icon_name);
edfda783
AR
422
423 if (ns_in_resize)
424 return;
425
426 /* see if it's changed */
427 if (STRINGP (arg))
428 {
429 if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
430 return;
431 }
432 else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
433 return;
434
435 f->icon_name = arg;
436
437 if (NILP (arg))
438 {
439 if (!NILP (f->title))
440 arg = f->title;
441 else
442 /* explicit name and no icon-name -> explicit_name */
443 if (f->explicit_name)
444 arg = f->name;
445 else
446 {
447 /* no explicit name and no icon-name ->
448 name has to be rebuild from icon_title_format */
449 windows_or_buffers_changed++;
450 return;
451 }
452 }
453
454 /* Don't change the name if it's already NAME. */
455 if ([[view window] miniwindowTitle] &&
456 ([[[view window] miniwindowTitle]
457 isEqualToString: [NSString stringWithUTF8String:
facfbbbd 458 SDATA (arg)]]))
edfda783
AR
459 return;
460
461 [[view window] setMiniwindowTitle:
facfbbbd 462 [NSString stringWithUTF8String: SDATA (arg)]];
edfda783
AR
463}
464
edfda783 465static void
5bbb4727 466ns_set_name_internal (FRAME_PTR f, Lisp_Object name)
edfda783 467{
5bbb4727
JD
468 struct gcpro gcpro1;
469 Lisp_Object encoded_name, encoded_icon_name;
470 NSString *str;
edfda783 471 NSView *view = FRAME_NS_VIEW (f);
edfda783 472
5bbb4727
JD
473 GCPRO1 (name);
474 encoded_name = ENCODE_UTF_8 (name);
475 UNGCPRO;
edfda783 476
5bbb4727 477 str = [NSString stringWithUTF8String: SDATA (encoded_name)];
edfda783 478
5bbb4727
JD
479 /* Don't change the name if it's already NAME. */
480 if (! [[[view window] title] isEqualToString: str])
481 [[view window] setTitle: str];
edfda783 482
5bbb4727
JD
483 if (!STRINGP (f->icon_name))
484 encoded_icon_name = encoded_name;
edfda783 485 else
5fdb398c 486 encoded_icon_name = ENCODE_UTF_8 (f->icon_name);
5bbb4727
JD
487
488 str = [NSString stringWithUTF8String: SDATA (encoded_icon_name)];
edfda783 489
edfda783 490 if ([[view window] miniwindowTitle] &&
5bbb4727
JD
491 ! [[[view window] miniwindowTitle] isEqualToString: str])
492 [[view window] setMiniwindowTitle: str];
edfda783 493
edfda783
AR
494}
495
edfda783
AR
496static void
497ns_set_name (struct frame *f, Lisp_Object name, int explicit)
498{
fec8f0fe 499 NSView *view;
edfda783
AR
500 NSTRACE (ns_set_name);
501
502 if (ns_in_resize)
503 return;
504
505 /* Make sure that requests from lisp code override requests from
506 Emacs redisplay code. */
507 if (explicit)
508 {
509 /* If we're switching from explicit to implicit, we had better
510 update the mode lines and thereby update the title. */
511 if (f->explicit_name && NILP (name))
512 update_mode_lines = 1;
513
514 f->explicit_name = ! NILP (name);
515 }
516 else if (f->explicit_name)
517 return;
518
519 if (NILP (name))
56d513e6 520 name = build_string([ns_app_name UTF8String]);
5bbb4727
JD
521 else
522 CHECK_STRING (name);
523
524 /* Don't change the name if it's already NAME. */
525 if (! NILP (Fstring_equal (name, f->name)))
526 return;
edfda783
AR
527
528 f->name = name;
529
530 /* title overrides explicit name */
531 if (! NILP (f->title))
532 name = f->title;
533
5bbb4727 534 ns_set_name_internal (f, name);
edfda783
AR
535}
536
537
538/* This function should be called when the user's lisp code has
539 specified a name for the frame; the name will override any set by the
540 redisplay code. */
541static void
89e2438a 542x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
edfda783 543{
89e2438a 544 NSTRACE (x_explicitly_set_name);
edfda783
AR
545 ns_set_name (f, arg, 1);
546}
547
548
549/* This function should be called by Emacs redisplay code to set the
550 name; names set this way will never override names set by the user's
551 lisp code. */
552void
553x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
554{
555 NSTRACE (x_implicitly_set_name);
5bbb4727
JD
556
557 /* Deal with NS specific format t. */
558 if (FRAME_NS_P (f) && ((FRAME_ICONIFIED_P (f) && EQ (Vicon_title_format, Qt))
559 || EQ (Vframe_title_format, Qt)))
9ae6e189 560 ns_set_name_as_filename (f);
edfda783
AR
561 else
562 ns_set_name (f, arg, 0);
563}
564
565
566/* Change the title of frame F to NAME.
5bbb4727 567 If NAME is nil, use the frame name as the title. */
edfda783 568
edfda783 569static void
89e2438a 570x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
edfda783 571{
89e2438a 572 NSTRACE (x_set_title);
edfda783
AR
573 /* Don't change the title if it's already NAME. */
574 if (EQ (name, f->title))
575 return;
576
577 update_mode_lines = 1;
578
579 f->title = name;
5bbb4727
JD
580
581 if (NILP (name))
582 name = f->name;
583 else
584 CHECK_STRING (name);
585
586 ns_set_name_internal (f, name);
edfda783
AR
587}
588
589
590void
591ns_set_name_as_filename (struct frame *f)
592{
fec8f0fe 593 NSView *view;
aeb7e951 594 Lisp_Object name, filename;
edfda783
AR
595 Lisp_Object buf = XWINDOW (f->selected_window)->buffer;
596 const char *title;
597 NSAutoreleasePool *pool;
5bbb4727 598 struct gcpro gcpro1;
aeb7e951
JD
599 Lisp_Object encoded_name, encoded_filename;
600 NSString *str;
edfda783
AR
601 NSTRACE (ns_set_name_as_filename);
602
603 if (f->explicit_name || ! NILP (f->title) || ns_in_resize)
604 return;
605
606 BLOCK_INPUT;
607 pool = [[NSAutoreleasePool alloc] init];
124c9ff0
JD
608 filename = BVAR (XBUFFER (buf), filename);
609 name = BVAR (XBUFFER (buf), name);
edfda783
AR
610
611 if (NILP (name))
aeb7e951
JD
612 {
613 if (! NILP (filename))
614 name = Ffile_name_nondirectory (filename);
615 else
616 name = build_string ([ns_app_name UTF8String]);
617 }
edfda783 618
5bbb4727
JD
619 GCPRO1 (name);
620 encoded_name = ENCODE_UTF_8 (name);
621 UNGCPRO;
622
fec8f0fe
CY
623 view = FRAME_NS_VIEW (f);
624
edfda783
AR
625 title = FRAME_ICONIFIED_P (f) ? [[[view window] miniwindowTitle] UTF8String]
626 : [[[view window] title] UTF8String];
627
5bbb4727 628 if (title && (! strcmp (title, SDATA (encoded_name))))
edfda783
AR
629 {
630 [pool release];
631 UNBLOCK_INPUT;
632 return;
633 }
634
aeb7e951
JD
635 str = [NSString stringWithUTF8String: SDATA (encoded_name)];
636 if (str == nil) str = @"Bad coding";
637
638 if (FRAME_ICONIFIED_P (f))
639 [[view window] setMiniwindowTitle: str];
5fdb398c 640 else
edfda783 641 {
aeb7e951
JD
642 NSString *fstr;
643
644 if (! NILP (filename))
edfda783 645 {
aeb7e951
JD
646 GCPRO1 (filename);
647 encoded_filename = ENCODE_UTF_8 (filename);
648 UNGCPRO;
649
650 fstr = [NSString stringWithUTF8String: SDATA (encoded_filename)];
651 if (fstr == nil) fstr = @"";
652#ifdef NS_IMPL_COCOA
653 /* work around a bug observed on 10.3 and later where
654 setTitleWithRepresentedFilename does not clear out previous state
655 if given filename does not exist */
656 if (! [[NSFileManager defaultManager] fileExistsAtPath: fstr])
657 [[view window] setRepresentedFilename: @""];
658#endif
edfda783
AR
659 }
660 else
aeb7e951
JD
661 fstr = @"";
662
663 [[view window] setRepresentedFilename: fstr];
664 [[view window] setTitle: str];
edfda783
AR
665 f->name = name;
666 }
aeb7e951 667
edfda783
AR
668 [pool release];
669 UNBLOCK_INPUT;
670}
671
672
673void
6521c534 674ns_set_doc_edited (struct frame *f, Lisp_Object arg)
edfda783
AR
675{
676 NSView *view = FRAME_NS_VIEW (f);
677 NSAutoreleasePool *pool;
9ae6e189
CY
678 if (!MINI_WINDOW_P (XWINDOW (f->selected_window)))
679 {
680 BLOCK_INPUT;
681 pool = [[NSAutoreleasePool alloc] init];
682 [[view window] setDocumentEdited: !NILP (arg)];
683 [pool release];
684 UNBLOCK_INPUT;
685 }
edfda783
AR
686}
687
688
cc98b6a0
DN
689void
690x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
edfda783
AR
691{
692 int nlines;
693 int olines = FRAME_MENU_BAR_LINES (f);
694 if (FRAME_MINIBUF_ONLY_P (f))
695 return;
696
697 if (INTEGERP (value))
698 nlines = XINT (value);
699 else
700 nlines = 0;
701
702 FRAME_MENU_BAR_LINES (f) = 0;
703 if (nlines)
704 {
705 FRAME_EXTERNAL_MENU_BAR (f) = 1;
cc98b6a0
DN
706 /* does for all frames, whereas we just want for one frame
707 [NSMenu setMenuBarVisible: YES]; */
edfda783
AR
708 }
709 else
710 {
711 if (FRAME_EXTERNAL_MENU_BAR (f) == 1)
712 free_frame_menubar (f);
cc98b6a0 713 /* [NSMenu setMenuBarVisible: NO]; */
edfda783
AR
714 FRAME_EXTERNAL_MENU_BAR (f) = 0;
715 }
716}
717
718
3fe53a83 719/* toolbar support */
cc98b6a0
DN
720void
721x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
edfda783
AR
722{
723 int nlines;
724 Lisp_Object root_window;
725
726 if (FRAME_MINIBUF_ONLY_P (f))
727 return;
728
729 if (INTEGERP (value) && XINT (value) >= 0)
730 nlines = XFASTINT (value);
731 else
732 nlines = 0;
733
734 if (nlines)
735 {
736 FRAME_EXTERNAL_TOOL_BAR (f) = 1;
737 update_frame_tool_bar (f);
738 }
739 else
740 {
741 if (FRAME_EXTERNAL_TOOL_BAR (f))
742 {
743 free_frame_tool_bar (f);
744 FRAME_EXTERNAL_TOOL_BAR (f) = 0;
745 }
746 }
747
748 x_set_window_size (f, 0, f->text_cols, f->text_lines);
749}
750
751
edfda783
AR
752void
753ns_implicitly_set_icon_type (struct frame *f)
754{
755 Lisp_Object tem;
756 EmacsView *view = FRAME_NS_VIEW (f);
757 id image =nil;
758 Lisp_Object chain, elt;
759 NSAutoreleasePool *pool;
760 BOOL setMini = YES;
761
762 NSTRACE (ns_implicitly_set_icon_type);
763
764 BLOCK_INPUT;
765 pool = [[NSAutoreleasePool alloc] init];
766 if (f->output_data.ns->miniimage
facfbbbd 767 && [[NSString stringWithUTF8String: SDATA (f->name)]
edfda783
AR
768 isEqualToString: [(NSImage *)f->output_data.ns->miniimage name]])
769 {
770 [pool release];
771 UNBLOCK_INPUT;
772 return;
773 }
774
775 tem = assq_no_quit (Qicon_type, f->param_alist);
776 if (CONSP (tem) && ! NILP (XCDR (tem)))
777 {
778 [pool release];
779 UNBLOCK_INPUT;
780 return;
781 }
782
783 for (chain = Vns_icon_type_alist;
784 (image = nil) && CONSP (chain);
785 chain = XCDR (chain))
786 {
787 elt = XCAR (chain);
788 /* special case: 't' means go by file type */
facfbbbd 789 if (SYMBOLP (elt) && EQ (elt, Qt) && SDATA (f->name)[0] == '/')
edfda783 790 {
facfbbbd
SM
791 NSString *str
792 = [NSString stringWithUTF8String: SDATA (f->name)];
edfda783
AR
793 if ([[NSFileManager defaultManager] fileExistsAtPath: str])
794 image = [[[NSWorkspace sharedWorkspace] iconForFile: str] retain];
795 }
796 else if (CONSP (elt) &&
797 STRINGP (XCAR (elt)) &&
798 STRINGP (XCDR (elt)) &&
799 fast_string_match (XCAR (elt), f->name) >= 0)
800 {
801 image = [EmacsImage allocInitFromFile: XCDR (elt)];
802 if (image == nil)
803 image = [[NSImage imageNamed:
804 [NSString stringWithUTF8String:
facfbbbd 805 SDATA (XCDR (elt))]] retain];
edfda783
AR
806 }
807 }
808
809 if (image == nil)
810 {
811 image = [[[NSWorkspace sharedWorkspace] iconForFileType: @"text"] retain];
812 setMini = NO;
813 }
814
815 [f->output_data.ns->miniimage release];
816 f->output_data.ns->miniimage = image;
817 [view setMiniwindowImage: setMini];
818 [pool release];
819 UNBLOCK_INPUT;
820}
821
822
823static void
89e2438a 824x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783
AR
825{
826 EmacsView *view = FRAME_NS_VIEW (f);
827 id image = nil;
828 BOOL setMini = YES;
829
89e2438a 830 NSTRACE (x_set_icon_type);
edfda783
AR
831
832 if (!NILP (arg) && SYMBOLP (arg))
833 {
facfbbbd 834 arg =build_string (SDATA (SYMBOL_NAME (arg)));
edfda783
AR
835 store_frame_param (f, Qicon_type, arg);
836 }
837
838 /* do it the implicit way */
839 if (NILP (arg))
840 {
841 ns_implicitly_set_icon_type (f);
842 return;
843 }
844
845 CHECK_STRING (arg);
846
847 image = [EmacsImage allocInitFromFile: arg];
848 if (image == nil)
849 image =[NSImage imageNamed: [NSString stringWithUTF8String:
facfbbbd 850 SDATA (arg)]];
edfda783
AR
851
852 if (image == nil)
853 {
854 image = [NSImage imageNamed: @"text"];
855 setMini = NO;
856 }
857
858 f->output_data.ns->miniimage = image;
859 [view setMiniwindowImage: setMini];
860}
861
862
3fe53a83 863/* Xism; we stub out (we do implement this in ns-win.el) */
edfda783
AR
864int
865XParseGeometry (char *string, int *x, int *y,
866 unsigned int *width, unsigned int *height)
867{
868 message1 ("Warning: XParseGeometry not supported under NS.\n");
869 return 0;
870}
871
872
6fb5f7da 873/* TODO: move to nsterm? */
edfda783
AR
874int
875ns_lisp_to_cursor_type (Lisp_Object arg)
876{
877 char *str;
878 if (XTYPE (arg) == Lisp_String)
facfbbbd 879 str = SDATA (arg);
edfda783 880 else if (XTYPE (arg) == Lisp_Symbol)
facfbbbd 881 str = SDATA (SYMBOL_NAME (arg));
edfda783 882 else return -1;
c8c057de
AR
883 if (!strcmp (str, "box")) return FILLED_BOX_CURSOR;
884 if (!strcmp (str, "hollow")) return HOLLOW_BOX_CURSOR;
885 if (!strcmp (str, "hbar")) return HBAR_CURSOR;
886 if (!strcmp (str, "bar")) return BAR_CURSOR;
887 if (!strcmp (str, "no")) return NO_CURSOR;
edfda783
AR
888 return -1;
889}
890
891
892Lisp_Object
893ns_cursor_type_to_lisp (int arg)
894{
895 switch (arg)
896 {
c8c057de
AR
897 case FILLED_BOX_CURSOR: return Qbox;
898 case HOLLOW_BOX_CURSOR: return intern ("hollow");
899 case HBAR_CURSOR: return intern ("hbar");
900 case BAR_CURSOR: return intern ("bar");
901 case NO_CURSOR:
902 default: return intern ("no");
edfda783
AR
903 }
904}
905
89e2438a 906/* This is the same as the xfns.c definition. */
06197b17 907void
3d608a86 908x_set_cursor_type (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
edfda783 909{
06197b17 910 set_frame_cursor_types (f, arg);
edfda783 911
06197b17
DR
912 /* Make sure the cursor gets redrawn. */
913 cursor_type_changed = 1;
edfda783 914}
06197b17 915\f
edfda783 916
3fe53a83
AR
917/* called to set mouse pointer color, but all other terms use it to
918 initialize pointer types (and don't set the color ;) */
edfda783 919static void
89e2438a 920x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
edfda783 921{
d26fbe1a 922 /* don't think we can do this on Nextstep */
edfda783
AR
923}
924
925
cb83c00b
AR
926#define Str(x) #x
927#define Xstr(x) Str(x)
928
929static Lisp_Object
3d608a86 930ns_appkit_version_str (void)
cb83c00b
AR
931{
932 char tmp[80];
933
934#ifdef NS_IMPL_GNUSTEP
935 sprintf(tmp, "gnustep-gui-%s", Xstr(GNUSTEP_GUI_VERSION));
936#elif defined(NS_IMPL_COCOA)
937 sprintf(tmp, "apple-appkit-%.2f", NSAppKitVersionNumber);
938#else
939 tmp = "ns-unknown";
940#endif
941 return build_string (tmp);
942}
943
944
f5497e45
AR
945/* This is for use by x-server-version and collapses all version info we
946 have into a single int. For a better picture of the implementation
947 running, use ns_appkit_version_str.*/
948static int
3d608a86 949ns_appkit_version_int (void)
f5497e45
AR
950{
951#ifdef NS_IMPL_GNUSTEP
13cd8a29 952 return GNUSTEP_GUI_MAJOR_VERSION * 100 + GNUSTEP_GUI_MINOR_VERSION;
f5497e45
AR
953#elif defined(NS_IMPL_COCOA)
954 return (int)NSAppKitVersionNumber;
955#endif
956 return 0;
957}
958
959
edfda783 960static void
952913d4 961x_icon (struct frame *f, Lisp_Object parms)
edfda783
AR
962/* --------------------------------------------------------------------------
963 Strangely-named function to set icon position parameters in frame.
964 This is irrelevant under OS X, but might be needed under GNUstep,
965 depending on the window manager used. Note, this is not a standard
966 frame parameter-setter; it is called directly from x-create-frame.
967 -------------------------------------------------------------------------- */
968{
969 Lisp_Object icon_x, icon_y;
970 struct ns_display_info *dpyinfo = check_ns_display_info (Qnil);
971
972 f->output_data.ns->icon_top = Qnil;
973 f->output_data.ns->icon_left = Qnil;
974
975 /* Set the position of the icon. */
976 icon_x = x_get_arg (dpyinfo, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
977 icon_y = x_get_arg (dpyinfo, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
978 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
979 {
980 CHECK_NUMBER (icon_x);
981 CHECK_NUMBER (icon_y);
982 f->output_data.ns->icon_top = icon_y;
983 f->output_data.ns->icon_left = icon_x;
984 }
985 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
986 error ("Both left and top icon corners of icon must be specified");
987}
988
989
3fe53a83 990/* Note: see frame.c for template, also where generic functions are impl */
edfda783
AR
991frame_parm_handler ns_frame_parm_handlers[] =
992{
993 x_set_autoraise, /* generic OK */
994 x_set_autolower, /* generic OK */
89e2438a 995 x_set_background_color,
d26fbe1a
CY
996 0, /* x_set_border_color, may be impossible under Nextstep */
997 0, /* x_set_border_width, may be impossible under Nextstep */
89e2438a
DN
998 x_set_cursor_color,
999 x_set_cursor_type,
edfda783 1000 x_set_font, /* generic OK */
89e2438a
DN
1001 x_set_foreground_color,
1002 x_set_icon_name,
1003 x_set_icon_type,
edfda783 1004 x_set_internal_border_width, /* generic OK */
cc98b6a0 1005 x_set_menu_bar_lines,
89e2438a
DN
1006 x_set_mouse_color,
1007 x_explicitly_set_name,
edfda783 1008 x_set_scroll_bar_width, /* generic OK */
89e2438a 1009 x_set_title,
edfda783
AR
1010 x_set_unsplittable, /* generic OK */
1011 x_set_vertical_scroll_bars, /* generic OK */
1012 x_set_visibility, /* generic OK */
cc98b6a0 1013 x_set_tool_bar_lines,
edfda783
AR
1014 0, /* x_set_scroll_bar_foreground, will ignore (not possible on NS) */
1015 0, /* x_set_scroll_bar_background, will ignore (not possible on NS) */
1016 x_set_screen_gamma, /* generic OK */
1017 x_set_line_spacing, /* generic OK, sets f->extra_line_spacing to int */
1018 x_set_fringe_width, /* generic OK */
1019 x_set_fringe_width, /* generic OK */
1020 0, /* x_set_wait_for_wm, will ignore */
1021 0, /* x_set_fullscreen will ignore */
dee721c0 1022 x_set_font_backend, /* generic OK */
cad9ef74 1023 x_set_alpha,
5fdb398c
PE
1024 0, /* x_set_sticky */
1025 0, /* x_set_tool_bar_position */
edfda783
AR
1026};
1027
1028
cb83c00b
AR
1029
1030/* ==========================================================================
1031
1032 Lisp definitions
1033
1034 ========================================================================== */
1035
9e50ff0c 1036DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
edfda783 1037 1, 1, 0,
51d5ef9f 1038 doc: /* Make a new Nextstep window, called a \"frame\" in Emacs terms.
d26fbe1a
CY
1039Return an Emacs frame object.
1040PARMS is an alist of frame parameters.
1041If the parameters specify that the frame should not have a minibuffer,
1042and do not specify a specific minibuffer window to use,
1043then `default-minibuffer-frame' must be a frame whose minibuffer can
51d5ef9f 1044be shared by the new frame. */)
5842a27b 1045 (Lisp_Object parms)
edfda783
AR
1046{
1047 static int desc_ctr = 1;
1048 struct frame *f;
1049 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1050 Lisp_Object frame, tem;
1051 Lisp_Object name;
1052 int minibuffer_only = 0;
1053 int count = specpdl_ptr - specpdl;
1054 Lisp_Object display;
1055 struct ns_display_info *dpyinfo = NULL;
1056 Lisp_Object parent;
1057 struct kboard *kb;
1058 Lisp_Object tfont, tfontsize;
1059 int window_prompting = 0;
1060 int width, height;
1061
1062 check_ns ();
1063
bd6ce2ba
AR
1064 /* Seems a little strange, but other terms do it. Perhaps the code below
1065 is modifying something? */
1066 parms = Fcopy_alist (parms);
1067
edfda783
AR
1068 display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_STRING);
1069 if (EQ (display, Qunbound))
1070 display = Qnil;
1071 dpyinfo = check_ns_display_info (display);
1072
1073 if (!dpyinfo->terminal->name)
1074 error ("Terminal is not live, can't create new frames on it");
1075
1076 kb = dpyinfo->terminal->kboard;
1077
1078 name = x_get_arg (dpyinfo, parms, Qname, 0, 0, RES_TYPE_STRING);
1079 if (!STRINGP (name)
1080 && ! EQ (name, Qunbound)
1081 && ! NILP (name))
1082 error ("Invalid frame name--not a string or nil");
1083
1084 if (STRINGP (name))
1085 Vx_resource_name = name;
bd6ce2ba
AR
1086 else
1087 Vx_resource_name = Vinvocation_name;
edfda783
AR
1088
1089 parent = x_get_arg (dpyinfo, parms, Qparent_id, 0, 0, RES_TYPE_NUMBER);
1090 if (EQ (parent, Qunbound))
1091 parent = Qnil;
1092 if (! NILP (parent))
1093 CHECK_NUMBER (parent);
1094
1095 frame = Qnil;
1096 GCPRO4 (parms, parent, name, frame);
1097
1098 tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer",
1099 RES_TYPE_SYMBOL);
1100 if (EQ (tem, Qnone) || NILP (tem))
1101 {
1102 f = make_frame_without_minibuffer (Qnil, kb, display);
1103 }
1104 else if (EQ (tem, Qonly))
1105 {
1106 f = make_minibuffer_frame ();
1107 minibuffer_only = 1;
1108 }
1109 else if (WINDOWP (tem))
1110 {
1111 f = make_frame_without_minibuffer (tem, kb, display);
1112 }
1113 else
1114 {
1115 f = make_frame (1);
1116 }
1117
1118 /* Set the name; the functions to which we pass f expect the name to
1119 be set. */
1120 if (EQ (name, Qunbound) || NILP (name) || (XTYPE (name) != Lisp_String))
1121 {
56d513e6 1122 f->name = build_string ([ns_app_name UTF8String]);
edfda783
AR
1123 f->explicit_name =0;
1124 }
1125 else
1126 {
1127 f->name = name;
1128 f->explicit_name = 1;
1129 specbind (Qx_resource_name, name);
1130 }
1131
1132 XSETFRAME (frame, f);
1133 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
1134
1135 f->terminal = dpyinfo->terminal;
1136 f->terminal->reference_count++;
1137
1138 f->output_method = output_ns;
1139 f->output_data.ns = (struct ns_output *)xmalloc (sizeof *(f->output_data.ns));
72af86bd 1140 memset (f->output_data.ns, 0, sizeof (*(f->output_data.ns)));
edfda783
AR
1141
1142 FRAME_FONTSET (f) = -1;
1143
1144 /* record_unwind_protect (unwind_create_frame, frame); safety; maybe later? */
1145
1146 f->icon_name = x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title",
1147 RES_TYPE_STRING);
bd6ce2ba 1148 if (! STRINGP (f->icon_name))
edfda783
AR
1149 f->icon_name = Qnil;
1150
1151 FRAME_NS_DISPLAY_INFO (f) = dpyinfo;
1152
1153 f->output_data.ns->window_desc = desc_ctr++;
1154 if (!NILP (parent))
1155 {
1156 f->output_data.ns->parent_desc = (Window) XFASTINT (parent);
1157 f->output_data.ns->explicit_parent = 1;
1158 }
1159 else
1160 {
1161 f->output_data.ns->parent_desc = FRAME_NS_DISPLAY_INFO (f)->root_window;
1162 f->output_data.ns->explicit_parent = 0;
1163 }
1164
1165 f->resx = dpyinfo->resx;
1166 f->resy = dpyinfo->resy;
1167
1168 BLOCK_INPUT;
1169 register_font_driver (&nsfont_driver, f);
1170 x_default_parameter (f, parms, Qfont_backend, Qnil,
1171 "fontBackend", "FontBackend", RES_TYPE_STRING);
1172
1173 {
1174 /* use for default font name */
1175 id font = [NSFont userFixedPitchFontOfSize: -1.0]; /* default */
1176 tfontsize = x_default_parameter (f, parms, Qfontsize,
1177 make_number (0 /*(int)[font pointSize]*/),
1178 "fontSize", "FontSize", RES_TYPE_NUMBER);
1179 tfont = x_default_parameter (f, parms, Qfont,
1180 build_string ([[font fontName] UTF8String]),
1181 "font", "Font", RES_TYPE_STRING);
1182 }
1183 UNBLOCK_INPUT;
1184
1185 x_default_parameter (f, parms, Qborder_width, make_number (0),
1186 "borderwidth", "BorderWidth", RES_TYPE_NUMBER);
1187 x_default_parameter (f, parms, Qinternal_border_width, make_number (2),
1188 "internalBorderWidth", "InternalBorderWidth",
1189 RES_TYPE_NUMBER);
1190
1191 /* default scrollbars on right on Mac */
1192 {
facfbbbd 1193 Lisp_Object spos
edfda783 1194#ifdef NS_IMPL_GNUSTEP
facfbbbd 1195 = Qt;
edfda783 1196#else
facfbbbd 1197 = Qright;
edfda783 1198#endif
facfbbbd
SM
1199 x_default_parameter (f, parms, Qvertical_scroll_bars, spos,
1200 "verticalScrollBars", "VerticalScrollBars",
1201 RES_TYPE_SYMBOL);
edfda783
AR
1202 }
1203 x_default_parameter (f, parms, Qforeground_color, build_string ("Black"),
1204 "foreground", "Foreground", RES_TYPE_STRING);
1205 x_default_parameter (f, parms, Qbackground_color, build_string ("White"),
1206 "background", "Background", RES_TYPE_STRING);
d26fbe1a 1207 /* FIXME: not suppported yet in Nextstep */
edfda783
AR
1208 x_default_parameter (f, parms, Qline_spacing, Qnil,
1209 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
1210 x_default_parameter (f, parms, Qleft_fringe, Qnil,
1211 "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
1212 x_default_parameter (f, parms, Qright_fringe, Qnil,
1213 "rightFringe", "RightFringe", RES_TYPE_NUMBER);
1214 /* end PENDING */
1215
1216 init_frame_faces (f);
1217
6431f2e6
CY
1218 /* The X resources controlling the menu-bar and tool-bar are
1219 processed specially at startup, and reflected in the mode
1220 variables; ignore them here. */
1221 x_default_parameter (f, parms, Qmenu_bar_lines,
1222 NILP (Vmenu_bar_mode)
1223 ? make_number (0) : make_number (1),
1224 NULL, NULL, RES_TYPE_NUMBER);
1225 x_default_parameter (f, parms, Qtool_bar_lines,
1226 NILP (Vtool_bar_mode)
1227 ? make_number (0) : make_number (1),
1228 NULL, NULL, RES_TYPE_NUMBER);
1229
edfda783
AR
1230 x_default_parameter (f, parms, Qbuffer_predicate, Qnil, "bufferPredicate",
1231 "BufferPredicate", RES_TYPE_SYMBOL);
1232 x_default_parameter (f, parms, Qtitle, Qnil, "title", "Title",
1233 RES_TYPE_STRING);
1234
6fb5f7da 1235/* TODO: other terms seem to get away w/o this complexity.. */
edfda783
AR
1236 if (NILP (Fassq (Qwidth, parms)))
1237 {
facfbbbd
SM
1238 Lisp_Object value
1239 = x_get_arg (dpyinfo, parms, Qwidth, "width", "Width",
1240 RES_TYPE_NUMBER);
edfda783
AR
1241 if (! EQ (value, Qunbound))
1242 parms = Fcons (Fcons (Qwidth, value), parms);
1243 }
1244 if (NILP (Fassq (Qheight, parms)))
1245 {
facfbbbd
SM
1246 Lisp_Object value
1247 = x_get_arg (dpyinfo, parms, Qheight, "height", "Height",
1248 RES_TYPE_NUMBER);
edfda783
AR
1249 if (! EQ (value, Qunbound))
1250 parms = Fcons (Fcons (Qheight, value), parms);
1251 }
1252 if (NILP (Fassq (Qleft, parms)))
1253 {
facfbbbd
SM
1254 Lisp_Object value
1255 = x_get_arg (dpyinfo, parms, Qleft, "left", "Left", RES_TYPE_NUMBER);
edfda783
AR
1256 if (! EQ (value, Qunbound))
1257 parms = Fcons (Fcons (Qleft, value), parms);
1258 }
1259 if (NILP (Fassq (Qtop, parms)))
1260 {
facfbbbd
SM
1261 Lisp_Object value
1262 = x_get_arg (dpyinfo, parms, Qtop, "top", "Top", RES_TYPE_NUMBER);
edfda783
AR
1263 if (! EQ (value, Qunbound))
1264 parms = Fcons (Fcons (Qtop, value), parms);
1265 }
1266
1267 window_prompting = x_figure_window_size (f, parms, 1);
1268
1269 tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
1270 f->no_split = minibuffer_only || (!EQ (tem, Qunbound) && !EQ (tem, Qnil));
1271
1272 /* NOTE: on other terms, this is done in set_mouse_color, however this
d26fbe1a 1273 was not getting called under Nextstep */
edfda783
AR
1274 f->output_data.ns->text_cursor = [NSCursor IBeamCursor];
1275 f->output_data.ns->nontext_cursor = [NSCursor arrowCursor];
1276 f->output_data.ns->modeline_cursor = [NSCursor pointingHandCursor];
1277 f->output_data.ns->hand_cursor = [NSCursor pointingHandCursor];
1278 f->output_data.ns->hourglass_cursor = [NSCursor disappearingItemCursor];
1279 f->output_data.ns->horizontal_drag_cursor = [NSCursor resizeLeftRightCursor];
facfbbbd
SM
1280 FRAME_NS_DISPLAY_INFO (f)->vertical_scroll_bar_cursor
1281 = [NSCursor arrowCursor];
edfda783
AR
1282 f->output_data.ns->current_pointer = f->output_data.ns->text_cursor;
1283
1284 [[EmacsView alloc] initFrameFromEmacs: f];
1285
952913d4 1286 x_icon (f, parms);
edfda783
AR
1287
1288 /* It is now ok to make the frame official even if we get an error below.
1289 The frame needs to be on Vframe_list or making it visible won't work. */
1290 Vframe_list = Fcons (frame, Vframe_list);
1291 /*FRAME_NS_DISPLAY_INFO (f)->reference_count++; */
1292
edfda783
AR
1293 x_default_parameter (f, parms, Qicon_type, Qnil, "bitmapIcon", "BitmapIcon",
1294 RES_TYPE_SYMBOL);
bd6ce2ba 1295 x_default_parameter (f, parms, Qauto_raise, Qnil, "autoRaise", "AutoRaiseLower",
edfda783
AR
1296 RES_TYPE_BOOLEAN);
1297 x_default_parameter (f, parms, Qauto_lower, Qnil, "autoLower", "AutoLower",
1298 RES_TYPE_BOOLEAN);
bd6ce2ba
AR
1299 x_default_parameter (f, parms, Qcursor_type, Qbox, "cursorType", "CursorType",
1300 RES_TYPE_SYMBOL);
1301 x_default_parameter (f, parms, Qscroll_bar_width, Qnil, "scrollBarWidth",
1302 "ScrollBarWidth", RES_TYPE_NUMBER);
78ff4c61 1303 x_default_parameter (f, parms, Qalpha, Qnil, "alpha", "Alpha",
bd6ce2ba 1304 RES_TYPE_NUMBER);
edfda783
AR
1305
1306 width = FRAME_COLS (f);
1307 height = FRAME_LINES (f);
1308
1309 SET_FRAME_COLS (f, 0);
1310 FRAME_LINES (f) = 0;
1311 change_frame_size (f, height, width, 1, 0, 0);
1312
1313 if (! f->output_data.ns->explicit_parent)
1314 {
15891144
DR
1315 tem = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL);
1316 if (EQ (tem, Qunbound))
1317 tem = Qt;
1318 x_set_visibility (f, tem, Qnil);
1319 if (EQ (tem, Qicon))
1320 x_iconify_frame (f);
1321 else if (! NILP (tem))
1322 {
1323 x_make_frame_visible (f);
1324 f->async_visible = 1;
1325 [[FRAME_NS_VIEW (f) window] makeKeyWindow];
1326 }
1327 else
1328 f->async_visible = 0;
edfda783
AR
1329 }
1330
1331 if (FRAME_HAS_MINIBUF_P (f)
124c9ff0
JD
1332 && (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
1333 || !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame)))))
1334 KVAR (kb, Vdefault_minibuffer_frame) = frame;
edfda783
AR
1335
1336 /* All remaining specified parameters, which have not been "used"
1337 by x_get_arg and friends, now go in the misc. alist of the frame. */
1338 for (tem = parms; CONSP (tem); tem = XCDR (tem))
1339 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
1340 f->param_alist = Fcons (XCAR (tem), f->param_alist);
1341
1342 UNGCPRO;
1343 Vwindow_list = Qnil;
1344
1345 return unbind_to (count, frame);
1346}
1347
1348
9e50ff0c 1349DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
edfda783
AR
1350 doc: /* Set the input focus to FRAME.
1351FRAME nil means use the selected frame. */)
5842a27b 1352 (Lisp_Object frame)
edfda783
AR
1353{
1354 struct frame *f = check_ns_frame (frame);
1355 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f);
1356
9e50ff0c 1357 if (dpyinfo->x_focus_frame != f)
edfda783
AR
1358 {
1359 EmacsView *view = FRAME_NS_VIEW (f);
1360 BLOCK_INPUT;
4acaaa2b 1361 [NSApp activateIgnoringOtherApps: YES];
edfda783
AR
1362 [[view window] makeKeyAndOrderFront: view];
1363 UNBLOCK_INPUT;
1364 }
1365
1366 return Qnil;
1367}
1368
1369
edfda783 1370DEFUN ("ns-popup-font-panel", Fns_popup_font_panel, Sns_popup_font_panel,
51d5ef9f
AR
1371 0, 1, "",
1372 doc: /* Pop up the font panel. */)
5842a27b 1373 (Lisp_Object frame)
edfda783
AR
1374{
1375 id fm;
1376 struct frame *f;
1377
1378 check_ns ();
320e80c0 1379 fm = [NSFontManager sharedFontManager];
edfda783
AR
1380 if (NILP (frame))
1381 f = SELECTED_FRAME ();
1382 else
1383 {
1384 CHECK_FRAME (frame);
1385 f = XFRAME (frame);
1386 }
1387
1388 [fm setSelectedFont: ((struct nsfont_info *)f->output_data.ns->font)->nsfont
1389 isMultiple: NO];
1390 [fm orderFrontFontPanel: NSApp];
1391 return Qnil;
1392}
1393
1394
b066e6b6 1395DEFUN ("ns-popup-color-panel", Fns_popup_color_panel, Sns_popup_color_panel,
51d5ef9f
AR
1396 0, 1, "",
1397 doc: /* Pop up the color panel. */)
5842a27b 1398 (Lisp_Object frame)
edfda783
AR
1399{
1400 struct frame *f;
1401
1402 check_ns ();
1403 if (NILP (frame))
1404 f = SELECTED_FRAME ();
1405 else
1406 {
1407 CHECK_FRAME (frame);
1408 f = XFRAME (frame);
1409 }
1410
1411 [NSApp orderFrontColorPanel: NSApp];
1412 return Qnil;
1413}
1414
1415
1416DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 4, 0,
51d5ef9f 1417 doc: /* Use a graphical panel to read a file name, using prompt PROMPT.
d26fbe1a 1418Optional arg DIR, if non-nil, supplies a default directory.
45cb8994
CY
1419Optional arg MUSTMATCH, if non-nil, means the returned file or
1420directory must exist.
51d5ef9f 1421Optional arg INIT, if non-nil, provides a default file name to use. */)
f7ff1b0f 1422 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object mustmatch, Lisp_Object init)
edfda783
AR
1423{
1424 static id fileDelegate = nil;
1425 int ret;
1426 id panel;
ba301db3 1427 Lisp_Object fname;
edfda783
AR
1428
1429 NSString *promptS = NILP (prompt) || !STRINGP (prompt) ? nil :
facfbbbd 1430 [NSString stringWithUTF8String: SDATA (prompt)];
edfda783 1431 NSString *dirS = NILP (dir) || !STRINGP (dir) ?
124c9ff0 1432 [NSString stringWithUTF8String: SDATA (BVAR (current_buffer, directory))] :
facfbbbd 1433 [NSString stringWithUTF8String: SDATA (dir)];
edfda783 1434 NSString *initS = NILP (init) || !STRINGP (init) ? nil :
facfbbbd 1435 [NSString stringWithUTF8String: SDATA (init)];
edfda783
AR
1436
1437 check_ns ();
1438
1439 if (fileDelegate == nil)
1440 fileDelegate = [EmacsFileDelegate new];
1441
1442 [NSCursor setHiddenUntilMouseMoves: NO];
1443
1444 if ([dirS characterAtIndex: 0] == '~')
1445 dirS = [dirS stringByExpandingTildeInPath];
1446
45cb8994 1447 panel = NILP (mustmatch) ?
f2f7f42c 1448 (id)[EmacsSavePanel savePanel] : (id)[EmacsOpenPanel openPanel];
edfda783
AR
1449
1450 [panel setTitle: promptS];
1451
1452 /* Puma (10.1) does not have */
1453 if ([panel respondsToSelector: @selector (setAllowsOtherFileTypes:)])
1454 [panel setAllowsOtherFileTypes: YES];
1455
1456 [panel setTreatsFilePackagesAsDirectories: YES];
1457 [panel setDelegate: fileDelegate];
1458
1459 panelOK = 0;
ba301db3 1460 BLOCK_INPUT;
45cb8994 1461 if (NILP (mustmatch))
edfda783
AR
1462 {
1463 ret = [panel runModalForDirectory: dirS file: initS];
1464 }
1465 else
1466 {
1467 [panel setCanChooseDirectories: YES];
1468 ret = [panel runModalForDirectory: dirS file: initS types: nil];
1469 }
1470
575fb8bd 1471 ret = (ret == NSOKButton) || panelOK;
edfda783 1472
ba301db3
AR
1473 if (ret)
1474 fname = build_string ([[panel filename] UTF8String]);
b066e6b6 1475
edfda783 1476 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
ba301db3 1477 UNBLOCK_INPUT;
edfda783 1478
ba301db3 1479 return ret ? fname : Qnil;
edfda783
AR
1480}
1481
1482
1483DEFUN ("ns-get-resource", Fns_get_resource, Sns_get_resource, 2, 2, 0,
51d5ef9f
AR
1484 doc: /* Return the value of the property NAME of OWNER from the defaults database.
1485If OWNER is nil, Emacs is assumed. */)
5842a27b 1486 (Lisp_Object owner, Lisp_Object name)
edfda783
AR
1487{
1488 const char *value;
1489
1490 check_ns ();
1491 if (NILP (owner))
56d513e6 1492 owner = build_string([ns_app_name UTF8String]);
edfda783
AR
1493 CHECK_STRING (name);
1494/*fprintf (stderr, "ns-get-resource checking resource '%s'\n", SDATA (name)); */
1495
1496 value =[[[NSUserDefaults standardUserDefaults]
facfbbbd 1497 objectForKey: [NSString stringWithUTF8String: SDATA (name)]]
edfda783
AR
1498 UTF8String];
1499
1500 if (value)
1501 return build_string (value);
edfda783
AR
1502 return Qnil;
1503}
1504
1505
1506DEFUN ("ns-set-resource", Fns_set_resource, Sns_set_resource, 3, 3, 0,
51d5ef9f 1507 doc: /* Set property NAME of OWNER to VALUE, from the defaults database.
d26fbe1a 1508If OWNER is nil, Emacs is assumed.
51d5ef9f 1509If VALUE is nil, the default is removed. */)
5842a27b 1510 (Lisp_Object owner, Lisp_Object name, Lisp_Object value)
edfda783
AR
1511{
1512 check_ns ();
1513 if (NILP (owner))
56d513e6 1514 owner = build_string ([ns_app_name UTF8String]);
edfda783
AR
1515 CHECK_STRING (name);
1516 if (NILP (value))
1517 {
1518 [[NSUserDefaults standardUserDefaults] removeObjectForKey:
facfbbbd 1519 [NSString stringWithUTF8String: SDATA (name)]];
edfda783
AR
1520 }
1521 else
1522 {
1523 CHECK_STRING (value);
1524 [[NSUserDefaults standardUserDefaults] setObject:
facfbbbd 1525 [NSString stringWithUTF8String: SDATA (value)]
edfda783 1526 forKey: [NSString stringWithUTF8String:
facfbbbd 1527 SDATA (name)]];
edfda783
AR
1528 }
1529
1530 return Qnil;
1531}
1532
1533
952913d4
DN
1534DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
1535 Sx_server_max_request_size,
edfda783 1536 0, 1, 0,
51d5ef9f 1537 doc: /* This function is a no-op. It is only present for completeness. */)
5842a27b 1538 (Lisp_Object display)
edfda783
AR
1539{
1540 check_ns ();
1541 /* This function has no real equivalent under NeXTstep. Return nil to
1542 indicate this. */
1543 return Qnil;
1544}
1545
1546
9e50ff0c 1547DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
51d5ef9f 1548 doc: /* Return the vendor ID string of Nextstep display server DISPLAY.
d26fbe1a 1549DISPLAY should be either a frame or a display name (a string).
51d5ef9f 1550If omitted or nil, the selected frame's display is used. */)
5842a27b 1551 (Lisp_Object display)
edfda783 1552{
edfda783
AR
1553#ifdef NS_IMPL_GNUSTEP
1554 return build_string ("GNU");
1555#else
1556 return build_string ("Apple");
1557#endif
1558}
1559
1560
9e50ff0c 1561DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
f5497e45
AR
1562 doc: /* Return the version numbers of the server of DISPLAY.
1563The value is a list of three integers: the major and minor
1564version numbers of the X Protocol in use, and the distributor-specific
1565release number. See also the function `x-server-vendor'.
1566
1567The optional argument DISPLAY specifies which display to ask about.
d26fbe1a 1568DISPLAY should be either a frame or a display name (a string).
f5497e45 1569If omitted or nil, that stands for the selected frame's display. */)
5842a27b 1570 (Lisp_Object display)
edfda783 1571{
f5497e45
AR
1572 /*NOTE: it is unclear what would best correspond with "protocol";
1573 we return 10.3, meaning Panther, since this is roughly the
1574 level that GNUstep's APIs correspond to.
1575 The last number is where we distinguish between the Apple
1576 and GNUstep implementations ("distributor-specific release
1577 number") and give int'ized versions of major.minor. */
1578 return Fcons (make_number (10),
1579 Fcons (make_number (3),
1580 Fcons (make_number (ns_appkit_version_int()), Qnil)));
edfda783
AR
1581}
1582
1583
9e50ff0c 1584DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
51d5ef9f 1585 doc: /* Return the number of screens on Nextstep display server DISPLAY.
d26fbe1a 1586DISPLAY should be a frame, the display name as a string, or a terminal ID.
51d5ef9f 1587If omitted or nil, the selected frame's display is used. */)
5842a27b 1588 (Lisp_Object display)
edfda783
AR
1589{
1590 int num;
1591
1592 check_ns ();
1593 num = [[NSScreen screens] count];
1594
1595 return (num != 0) ? make_number (num) : Qnil;
1596}
1597
1598
9e50ff0c 1599DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height,
edfda783 1600 0, 1, 0,
51d5ef9f 1601 doc: /* Return the height of Nextstep display server DISPLAY, in millimeters.
d26fbe1a 1602DISPLAY should be a frame, the display name as a string, or a terminal ID.
51d5ef9f 1603If omitted or nil, the selected frame's display is used. */)
5842a27b 1604 (Lisp_Object display)
edfda783
AR
1605{
1606 check_ns ();
1607 return make_number ((int)
1608 ([ns_get_screen (display) frame].size.height/(92.0/25.4)));
1609}
1610
1611
9e50ff0c 1612DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width,
edfda783 1613 0, 1, 0,
51d5ef9f 1614 doc: /* Return the width of Nextstep display server DISPLAY, in millimeters.
d26fbe1a 1615DISPLAY should be a frame, the display name as a string, or a terminal ID.
51d5ef9f 1616If omitted or nil, the selected frame's display is used. */)
5842a27b 1617 (Lisp_Object display)
edfda783
AR
1618{
1619 check_ns ();
1620 return make_number ((int)
1621 ([ns_get_screen (display) frame].size.width/(92.0/25.4)));
1622}
1623
1624
9e50ff0c 1625DEFUN ("x-display-backing-store", Fx_display_backing_store,
51d5ef9f
AR
1626 Sx_display_backing_store, 0, 1, 0,
1627 doc: /* Return whether the Nexstep display DISPLAY supports backing store.
d26fbe1a
CY
1628The value may be `buffered', `retained', or `non-retained'.
1629DISPLAY should be a frame, the display name as a string, or a terminal ID.
51d5ef9f 1630If omitted or nil, the selected frame's display is used. */)
5842a27b 1631 (Lisp_Object display)
edfda783
AR
1632{
1633 check_ns ();
1634 switch ([ns_get_window (display) backingType])
1635 {
1636 case NSBackingStoreBuffered:
1637 return intern ("buffered");
1638 case NSBackingStoreRetained:
1639 return intern ("retained");
1640 case NSBackingStoreNonretained:
1641 return intern ("non-retained");
1642 default:
1643 error ("Strange value for backingType parameter of frame");
1644 }
1645 return Qnil; /* not reached, shut compiler up */
1646}
1647
1648
9e50ff0c 1649DEFUN ("x-display-visual-class", Fx_display_visual_class,
51d5ef9f
AR
1650 Sx_display_visual_class, 0, 1, 0,
1651 doc: /* Return the visual class of the Nextstep display server DISPLAY.
d26fbe1a
CY
1652The value is one of the symbols `static-gray', `gray-scale',
1653`static-color', `pseudo-color', `true-color', or `direct-color'.
1654DISPLAY should be a frame, the display name as a string, or a terminal ID.
51d5ef9f 1655If omitted or nil, the selected frame's display is used. */)
5842a27b 1656 (Lisp_Object display)
edfda783
AR
1657{
1658 NSWindowDepth depth;
1659 check_ns ();
1660 depth = [ns_get_screen (display) depth];
1661
1662 if ( depth == NSBestDepth (NSCalibratedWhiteColorSpace, 2, 2, YES, NULL))
1663 return intern ("static-gray");
1664 else if (depth == NSBestDepth (NSCalibratedWhiteColorSpace, 8, 8, YES, NULL))
1665 return intern ("gray-scale");
1666 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 8, 8, YES, NULL))
1667 return intern ("pseudo-color");
1668 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 4, 12, NO, NULL))
1669 return intern ("true-color");
1670 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 8, 24, NO, NULL))
1671 return intern ("direct-color");
1672 else
d26fbe1a 1673 /* color mgmt as far as we do it is really handled by Nextstep itself anyway */
edfda783
AR
1674 return intern ("direct-color");
1675}
1676
1677
9e50ff0c 1678DEFUN ("x-display-save-under", Fx_display_save_under,
51d5ef9f 1679 Sx_display_save_under, 0, 1, 0,
4f4f2973 1680 doc: /* Return t if DISPLAY supports the save-under feature.
d26fbe1a
CY
1681The optional argument DISPLAY specifies which display to ask about.
1682DISPLAY should be a frame, the display name as a string, or a terminal ID.
51d5ef9f 1683If omitted or nil, the selected frame's display is used. */)
5842a27b 1684 (Lisp_Object display)
edfda783
AR
1685{
1686 check_ns ();
1687 switch ([ns_get_window (display) backingType])
1688 {
1689 case NSBackingStoreBuffered:
1690 return Qt;
1691
1692 case NSBackingStoreRetained:
1693 case NSBackingStoreNonretained:
1694 return Qnil;
1695
1696 default:
1697 error ("Strange value for backingType parameter of frame");
1698 }
1699 return Qnil; /* not reached, shut compiler up */
1700}
1701
1702
9e50ff0c 1703DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
51d5ef9f 1704 1, 3, 0,
4f4f2973 1705 doc: /* Open a connection to a display server.
d26fbe1a 1706DISPLAY is the name of the display to connect to.
4f4f2973
GM
1707Optional second arg XRM-STRING is a string of resources in xrdb format.
1708If the optional third arg MUST-SUCCEED is non-nil,
1709terminate Emacs if we can't open the connection.
1710\(In the Nextstep version, the last two arguments are currently ignored.) */)
5842a27b 1711 (Lisp_Object display, Lisp_Object resource_string, Lisp_Object must_succeed)
edfda783
AR
1712{
1713 struct ns_display_info *dpyinfo;
1714
1715 CHECK_STRING (display);
1716
1717 nxatoms_of_nsselect ();
1718 dpyinfo = ns_term_init (display);
1719 if (dpyinfo == 0)
1720 {
1721 if (!NILP (must_succeed))
1722 fatal ("OpenStep on %s not responding.\n",
facfbbbd 1723 SDATA (display));
edfda783
AR
1724 else
1725 error ("OpenStep on %s not responding.\n",
facfbbbd 1726 SDATA (display));
edfda783
AR
1727 }
1728
1729 /* Register our external input/output types, used for determining
1730 applicable services and also drag/drop eligibility. */
1731 ns_send_types = [[NSArray arrayWithObject: NSStringPboardType] retain];
1732 ns_return_types = [[NSArray arrayWithObject: NSStringPboardType] retain];
1733 ns_drag_types = [[NSArray arrayWithObjects:
1734 NSStringPboardType,
1735 NSTabularTextPboardType,
1736 NSFilenamesPboardType,
1737 NSURLPboardType,
1738 NSColorPboardType,
1739 NSFontPboardType, nil] retain];
1740
1741 return Qnil;
1742}
1743
1744
9e50ff0c 1745DEFUN ("x-close-connection", Fx_close_connection, Sx_close_connection,
51d5ef9f
AR
1746 1, 1, 0,
1747 doc: /* Close the connection to the current Nextstep display server.
b066e6b6 1748The argument DISPLAY is currently ignored. */)
5842a27b 1749 (Lisp_Object display)
edfda783
AR
1750{
1751 check_ns ();
edfda783
AR
1752 /*ns_delete_terminal (dpyinfo->terminal); */
1753 [NSApp terminate: NSApp];
1754 return Qnil;
1755}
1756
1757
9e50ff0c 1758DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
51d5ef9f 1759 doc: /* Return the list of display names that Emacs has connections to. */)
5842a27b 1760 (void)
edfda783
AR
1761{
1762 Lisp_Object tail, result;
1763
1764 result = Qnil;
1765 for (tail = ns_display_name_list; CONSP (tail); tail = XCDR (tail))
1766 result = Fcons (XCAR (XCAR (tail)), result);
1767
1768 return result;
1769}
1770
1771
1772DEFUN ("ns-hide-others", Fns_hide_others, Sns_hide_others,
51d5ef9f 1773 0, 0, 0,
b066e6b6 1774 doc: /* Hides all applications other than Emacs. */)
5842a27b 1775 (void)
edfda783
AR
1776{
1777 check_ns ();
1778 [NSApp hideOtherApplications: NSApp];
1779 return Qnil;
1780}
1781
1782DEFUN ("ns-hide-emacs", Fns_hide_emacs, Sns_hide_emacs,
51d5ef9f 1783 1, 1, 0,
b066e6b6
JB
1784 doc: /* If ON is non-nil, the entire Emacs application is hidden.
1785Otherwise if Emacs is hidden, it is unhidden.
1786If ON is equal to `activate', Emacs is unhidden and becomes
51d5ef9f 1787the active application. */)
5842a27b 1788 (Lisp_Object on)
edfda783
AR
1789{
1790 check_ns ();
1791 if (EQ (on, intern ("activate")))
1792 {
1793 [NSApp unhide: NSApp];
1794 [NSApp activateIgnoringOtherApps: YES];
1795 }
1796 else if (NILP (on))
1797 [NSApp unhide: NSApp];
1798 else
1799 [NSApp hide: NSApp];
1800 return Qnil;
1801}
1802
1803
1804DEFUN ("ns-emacs-info-panel", Fns_emacs_info_panel, Sns_emacs_info_panel,
51d5ef9f
AR
1805 0, 0, 0,
1806 doc: /* Shows the 'Info' or 'About' panel for Emacs. */)
5842a27b 1807 (void)
edfda783
AR
1808{
1809 check_ns ();
1810 [NSApp orderFrontStandardAboutPanel: nil];
1811 return Qnil;
1812}
1813
1814
edfda783 1815DEFUN ("ns-font-name", Fns_font_name, Sns_font_name, 1, 1, 0,
51d5ef9f 1816 doc: /* Determine font postscript or family name for font NAME.
d26fbe1a
CY
1817NAME should be a string containing either the font name or an XLFD
1818font descriptor. If string contains `fontset' and not
51d5ef9f 1819`fontset-startup', it is left alone. */)
5842a27b 1820 (Lisp_Object name)
edfda783
AR
1821{
1822 char *nm;
1823 CHECK_STRING (name);
1824 nm = SDATA (name);
1825
1826 if (nm[0] != '-')
1827 return name;
1828 if (strstr (nm, "fontset") && !strstr (nm, "fontset-startup"))
1829 return name;
1830
1831 return build_string (ns_xlfd_to_fontname (SDATA (name)));
1832}
1833
1834
1835DEFUN ("ns-list-colors", Fns_list_colors, Sns_list_colors, 0, 1, 0,
51d5ef9f
AR
1836 doc: /* Return a list of all available colors.
1837The optional argument FRAME is currently ignored. */)
5842a27b 1838 (Lisp_Object frame)
edfda783
AR
1839{
1840 Lisp_Object list = Qnil;
1841 NSEnumerator *colorlists;
1842 NSColorList *clist;
1843
1844 if (!NILP (frame))
1845 {
1846 CHECK_FRAME (frame);
1847 if (! FRAME_NS_P (XFRAME (frame)))
d26fbe1a 1848 error ("non-Nextstep frame used in `ns-list-colors'");
edfda783
AR
1849 }
1850
1851 BLOCK_INPUT;
1852
1853 colorlists = [[NSColorList availableColorLists] objectEnumerator];
1854 while (clist = [colorlists nextObject])
1855 {
1856 if ([[clist name] length] < 7 ||
1857 [[clist name] rangeOfString: @"PANTONE"].location == 0)
1858 {
1859 NSEnumerator *cnames = [[clist allKeys] reverseObjectEnumerator];
1860 NSString *cname;
1861 while (cname = [cnames nextObject])
1862 list = Fcons (build_string ([cname UTF8String]), list);
1863/* for (i = [[clist allKeys] count] - 1; i >= 0; i--)
1864 list = Fcons (build_string ([[[clist allKeys] objectAtIndex: i]
1865 UTF8String]), list); */
1866 }
1867 }
1868
1869 UNBLOCK_INPUT;
1870
1871 return list;
1872}
1873
1874
1875DEFUN ("ns-list-services", Fns_list_services, Sns_list_services, 0, 0, 0,
51d5ef9f 1876 doc: /* List available Nextstep services by querying NSApp. */)
5842a27b 1877 (void)
edfda783
AR
1878{
1879 Lisp_Object ret = Qnil;
1880 NSMenu *svcs;
1881 id delegate;
1882
1883 check_ns ();
1884 svcs = [[NSMenu alloc] initWithTitle: @"Services"];
1885 [NSApp setServicesMenu: svcs]; /* this and next rebuild on <10.4 */
1886 [NSApp registerServicesMenuSendTypes: ns_send_types
1887 returnTypes: ns_return_types];
1888
1889/* On Tiger, services menu updating was made lazier (waits for user to
1890 actually click on the menu), so we have to force things along: */
1891#ifdef NS_IMPL_COCOA
1892 if (NSAppKitVersionNumber >= 744.0)
1893 {
1894 delegate = [svcs delegate];
1895 if (delegate != nil)
1896 {
1897 if ([delegate respondsToSelector: @selector (menuNeedsUpdate:)])
1898 [delegate menuNeedsUpdate: svcs];
1899 if ([delegate respondsToSelector:
1900 @selector (menu:updateItem:atIndex:shouldCancel:)])
1901 {
1902 int i, len = [delegate numberOfItemsInMenu: svcs];
1903 for (i =0; i<len; i++)
1904 [svcs addItemWithTitle: @"" action: NULL keyEquivalent: @""];
1905 for (i =0; i<len; i++)
1906 if (![delegate menu: svcs
1907 updateItem: (NSMenuItem *)[svcs itemAtIndex: i]
1908 atIndex: i shouldCancel: NO])
1909 break;
1910 }
1911 }
1912 }
1913#endif
1914
1915 [svcs setAutoenablesItems: NO];
1916#ifdef NS_IMPL_COCOA
1917 [svcs update]; /* on OS X, converts from '/' structure */
1918#endif
1919
1920 ret = interpret_services_menu (svcs, Qnil, ret);
1921 return ret;
1922}
1923
1924
1925DEFUN ("ns-perform-service", Fns_perform_service, Sns_perform_service,
51d5ef9f
AR
1926 2, 2, 0,
1927 doc: /* Perform Nextstep SERVICE on SEND.
d26fbe1a
CY
1928SEND should be either a string or nil.
1929The return value is the result of the service, as string, or nil if
51d5ef9f 1930there was no result. */)
5842a27b 1931 (Lisp_Object service, Lisp_Object send)
edfda783
AR
1932{
1933 id pb;
1934 NSString *svcName;
1935 char *utfStr;
1936 int len;
1937
1938 CHECK_STRING (service);
1939 check_ns ();
1940
facfbbbd 1941 utfStr = SDATA (service);
edfda783
AR
1942 svcName = [NSString stringWithUTF8String: utfStr];
1943
1944 pb =[NSPasteboard pasteboardWithUniqueName];
1945 ns_string_to_pasteboard (pb, send);
1946
1947 if (NSPerformService (svcName, pb) == NO)
1948 Fsignal (Qquit, Fcons (build_string ("service not available"), Qnil));
1949
1950 if ([[pb types] count] == 0)
1951 return build_string ("");
1952 return ns_string_from_pasteboard (pb);
1953}
1954
1955
1956DEFUN ("ns-convert-utf8-nfd-to-nfc", Fns_convert_utf8_nfd_to_nfc,
1957 Sns_convert_utf8_nfd_to_nfc, 1, 1, 0,
b066e6b6 1958 doc: /* Return an NFC string that matches the UTF-8 NFD string STR. */)
5842a27b 1959 (Lisp_Object str)
edfda783 1960{
f2f7f42c
AR
1961/* TODO: If GNUstep ever implements precomposedStringWithCanonicalMapping,
1962 remove this. */
edfda783
AR
1963 NSString *utfStr;
1964
1965 CHECK_STRING (str);
f2f7f42c
AR
1966 utfStr = [NSString stringWithUTF8String: SDATA (str)];
1967 if (![utfStr respondsToSelector:
1968 @selector (precomposedStringWithCanonicalMapping)])
1969 {
1970 message1
1971 ("Warning: ns-convert-utf8-nfd-to-nfc unsupported under GNUstep.\n");
1972 return Qnil;
1973 }
1974 else
1975 utfStr = [utfStr precomposedStringWithCanonicalMapping];
edfda783
AR
1976 return build_string ([utfStr UTF8String]);
1977}
1978
1979
583ff3c3
AR
1980#ifdef NS_IMPL_COCOA
1981
1982/* Compile and execute the AppleScript SCRIPT and return the error
1983 status as function value. A zero is returned if compilation and
1984 execution is successful, in which case *RESULT is set to a Lisp
1985 string or a number containing the resulting script value. Otherwise,
1986 1 is returned. */
1987static int
3d608a86 1988ns_do_applescript (Lisp_Object script, Lisp_Object *result)
583ff3c3
AR
1989{
1990 NSAppleEventDescriptor *desc;
1991 NSDictionary* errorDict;
1992 NSAppleEventDescriptor* returnDescriptor = NULL;
1993
1994 NSAppleScript* scriptObject =
1995 [[NSAppleScript alloc] initWithSource:
1996 [NSString stringWithUTF8String: SDATA (script)]];
1997
1998 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
1999 [scriptObject release];
b066e6b6 2000
583ff3c3 2001 *result = Qnil;
b066e6b6 2002
583ff3c3
AR
2003 if (returnDescriptor != NULL)
2004 {
2005 // successful execution
2006 if (kAENullEvent != [returnDescriptor descriptorType])
2007 {
2008 *result = Qt;
2009 // script returned an AppleScript result
2010 if ((typeUnicodeText == [returnDescriptor descriptorType]) ||
a39e2539 2011#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
b066e6b6 2012 (typeUTF16ExternalRepresentation
583ff3c3 2013 == [returnDescriptor descriptorType]) ||
a39e2539 2014#endif
583ff3c3
AR
2015 (typeUTF8Text == [returnDescriptor descriptorType]) ||
2016 (typeCString == [returnDescriptor descriptorType]))
2017 {
2018 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2019 if (desc)
2020 *result = build_string([[desc stringValue] UTF8String]);
2021 }
2022 else
2023 {
2024 /* use typeUTF16ExternalRepresentation? */
2025 // coerce the result to the appropriate ObjC type
2026 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2027 if (desc)
2028 *result = make_number([desc int32Value]);
2029 }
2030 }
2031 }
2032 else
2033 {
2034 // no script result, return error
2035 return 1;
2036 }
2037 return 0;
2038}
2039
2040DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0,
b066e6b6
JB
2041 doc: /* Execute AppleScript SCRIPT and return the result.
2042If compilation and execution are successful, the resulting script value
2043is returned as a string, a number or, in the case of other constructs, t.
2044In case the execution fails, an error is signaled. */)
5842a27b 2045 (Lisp_Object script)
583ff3c3
AR
2046{
2047 Lisp_Object result;
5fdb398c 2048 int status;
583ff3c3
AR
2049
2050 CHECK_STRING (script);
2051 check_ns ();
2052
2053 BLOCK_INPUT;
2054 status = ns_do_applescript (script, &result);
2055 UNBLOCK_INPUT;
2056 if (status == 0)
2057 return result;
2058 else if (!STRINGP (result))
2059 error ("AppleScript error %d", status);
2060 else
2061 error ("%s", SDATA (result));
2062}
2063#endif
2064
2065
2066
edfda783
AR
2067/* ==========================================================================
2068
2069 Miscellaneous functions not called through hooks
2070
2071 ========================================================================== */
2072
2073
3fe53a83 2074/* called from image.c */
edfda783
AR
2075FRAME_PTR
2076check_x_frame (Lisp_Object frame)
2077{
2078 return check_ns_frame (frame);
2079}
2080
3fe53a83
AR
2081
2082/* called from frame.c */
edfda783
AR
2083struct ns_display_info *
2084check_x_display_info (Lisp_Object frame)
2085{
2086 return check_ns_display_info (frame);
2087}
2088
2089
edfda783 2090void
3d608a86 2091x_set_scroll_bar_default_width (struct frame *f)
edfda783
AR
2092{
2093 int wid = FRAME_COLUMN_WIDTH (f);
2094 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = NS_SCROLL_BAR_WIDTH_DEFAULT;
2095 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) +
2096 wid - 1) / wid;
2097}
2098
2099
3fe53a83 2100/* terms impl this instead of x-get-resource directly */
edfda783
AR
2101const char *
2102x_get_string_resource (XrmDatabase rdb, char *name, char *class)
2103{
6fb5f7da 2104 /* remove appname prefix; TODO: allow for !="Emacs" */
edfda783
AR
2105 char *toCheck = class + (!strncmp (class, "Emacs.", 6) ? 6 : 0);
2106 const char *res;
2107 check_ns ();
2108
386a49d3
AR
2109 if (inhibit_x_resources)
2110 /* --quick was passed, so this is a no-op. */
2111 return NULL;
edfda783 2112
386a49d3
AR
2113 res = [[[NSUserDefaults standardUserDefaults] objectForKey:
2114 [NSString stringWithUTF8String: toCheck]] UTF8String];
edfda783
AR
2115 return !res ? NULL :
2116 (!strncasecmp (res, "YES", 3) ? "true" :
2117 (!strncasecmp (res, "NO", 2) ? "false" : res));
2118}
2119
2120
2121Lisp_Object
2122x_get_focus_frame (struct frame *frame)
2123{
2124 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (frame);
2125 Lisp_Object nsfocus;
2126
9e50ff0c 2127 if (!dpyinfo->x_focus_frame)
edfda783
AR
2128 return Qnil;
2129
9e50ff0c 2130 XSETFRAME (nsfocus, dpyinfo->x_focus_frame);
edfda783
AR
2131 return nsfocus;
2132}
2133
2134
2135int
2136x_pixel_width (struct frame *f)
2137{
2138 return FRAME_PIXEL_WIDTH (f);
2139}
2140
2141
2142int
2143x_pixel_height (struct frame *f)
2144{
2145 return FRAME_PIXEL_HEIGHT (f);
2146}
2147
2148
2149int
2150x_char_width (struct frame *f)
2151{
2152 return FRAME_COLUMN_WIDTH (f);
2153}
2154
2155
2156int
2157x_char_height (struct frame *f)
2158{
2159 return FRAME_LINE_HEIGHT (f);
2160}
2161
2162
2163int
2164x_screen_planes (struct frame *f)
2165{
2166 return FRAME_NS_DISPLAY_INFO (f)->n_planes;
2167}
2168
2169
2170void
3d608a86 2171x_sync (struct frame *f)
edfda783
AR
2172{
2173 /* XXX Not implemented XXX */
2174 return;
2175}
2176
2177
2178
2179/* ==========================================================================
2180
2181 Lisp definitions that, for whatever reason, we can't alias as 'ns-XXX'.
2182
2183 ========================================================================== */
2184
2185
952913d4 2186DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
4f4f2973
GM
2187 doc: /* Internal function called by `color-defined-p', which see.
2188\(Note that the Nextstep version of this function ignores FRAME.) */)
5842a27b 2189 (Lisp_Object color, Lisp_Object frame)
edfda783
AR
2190{
2191 NSColor * col;
2192 check_ns ();
2193 return ns_lisp_to_color (color, &col) ? Qnil : Qt;
2194}
2195
2196
952913d4 2197DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
fb67c21b 2198 doc: /* Internal function called by `color-values', which see. */)
5842a27b 2199 (Lisp_Object color, Lisp_Object frame)
edfda783
AR
2200{
2201 NSColor * col;
09b1339d 2202 CGFloat red, green, blue, alpha;
edfda783
AR
2203
2204 check_ns ();
2205 CHECK_STRING (color);
2206
2207 if (ns_lisp_to_color (color, &col))
2208 return Qnil;
2209
2210 [[col colorUsingColorSpaceName: NSCalibratedRGBColorSpace]
2211 getRed: &red green: &green blue: &blue alpha: &alpha];
fb67c21b
YM
2212 return list3 (make_number (lrint (red*65280)),
2213 make_number (lrint (green*65280)),
2214 make_number (lrint (blue*65280)));
edfda783
AR
2215}
2216
2217
2218DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
4f4f2973 2219 doc: /* Internal function called by `display-color-p', which see. */)
5842a27b 2220 (Lisp_Object display)
edfda783
AR
2221{
2222 NSWindowDepth depth;
2223 NSString *colorSpace;
2224 check_ns ();
2225 depth = [ns_get_screen (display) depth];
2226 colorSpace = NSColorSpaceFromDepth (depth);
2227
2228 return [colorSpace isEqualToString: NSDeviceWhiteColorSpace]
2229 || [colorSpace isEqualToString: NSCalibratedWhiteColorSpace]
2230 ? Qnil : Qt;
2231}
2232
2233
2234DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p,
2235 Sx_display_grayscale_p, 0, 1, 0,
51d5ef9f 2236 doc: /* Return t if the Nextstep display supports shades of gray.
d26fbe1a
CY
2237Note that color displays do support shades of gray.
2238The optional argument DISPLAY specifies which display to ask about.
2239DISPLAY should be either a frame, a display name (a string), or terminal ID.
51d5ef9f 2240If omitted or nil, that stands for the selected frame's display. */)
5842a27b 2241 (Lisp_Object display)
edfda783
AR
2242{
2243 NSWindowDepth depth;
2244 check_ns ();
2245 depth = [ns_get_screen (display) depth];
2246
2247 return NSBitsPerPixelFromDepth (depth) > 1 ? Qt : Qnil;
2248}
2249
2250
952913d4 2251DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
edfda783 2252 0, 1, 0,
b066e6b6 2253 doc: /* Return the width in pixels of the Nextstep display DISPLAY.
d26fbe1a
CY
2254The optional argument DISPLAY specifies which display to ask about.
2255DISPLAY should be either a frame, a display name (a string), or terminal ID.
51d5ef9f 2256If omitted or nil, that stands for the selected frame's display. */)
5842a27b 2257 (Lisp_Object display)
edfda783
AR
2258{
2259 check_ns ();
2260 return make_number ((int) [ns_get_screen (display) frame].size.width);
2261}
2262
2263
952913d4
DN
2264DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
2265 Sx_display_pixel_height, 0, 1, 0,
b066e6b6 2266 doc: /* Return the height in pixels of the Nextstep display DISPLAY.
d26fbe1a
CY
2267The optional argument DISPLAY specifies which display to ask about.
2268DISPLAY should be either a frame, a display name (a string), or terminal ID.
51d5ef9f 2269If omitted or nil, that stands for the selected frame's display. */)
5842a27b 2270 (Lisp_Object display)
edfda783
AR
2271{
2272 check_ns ();
2273 return make_number ((int) [ns_get_screen (display) frame].size.height);
2274}
2275
583ff3c3 2276
edfda783
AR
2277DEFUN ("display-usable-bounds", Fns_display_usable_bounds,
2278 Sns_display_usable_bounds, 0, 1, 0,
b066e6b6 2279 doc: /* Return the bounds of the usable part of the screen.
d26fbe1a
CY
2280The return value is a list of integers (LEFT TOP WIDTH HEIGHT), which
2281are the boundaries of the usable part of the screen, excluding areas
2282reserved for the Mac menu, dock, and so forth.
2283
2284The screen queried corresponds to DISPLAY, which should be either a
2285frame, a display name (a string), or terminal ID. If omitted or nil,
51d5ef9f 2286that stands for the selected frame's display. */)
5842a27b 2287 (Lisp_Object display)
edfda783
AR
2288{
2289 int top;
474217c8 2290 NSScreen *screen;
edfda783
AR
2291 NSRect vScreen;
2292
2293 check_ns ();
474217c8
CY
2294 screen = ns_get_screen (display);
2295 if (!screen)
2296 return Qnil;
2297
2298 vScreen = [screen visibleFrame];
edfda783 2299
474217c8
CY
2300 /* NS coordinate system is upside-down.
2301 Transform to screen-specific coordinates. */
edfda783 2302 return list4 (make_number ((int) vScreen.origin.x),
474217c8
CY
2303 make_number ((int) [screen frame].size.height
2304 - vScreen.size.height - vScreen.origin.y),
edfda783
AR
2305 make_number ((int) vScreen.size.width),
2306 make_number ((int) vScreen.size.height));
2307}
2308
2309
952913d4 2310DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
edfda783 2311 0, 1, 0,
b066e6b6 2312 doc: /* Return the number of bitplanes of the Nextstep display DISPLAY.
d26fbe1a
CY
2313The optional argument DISPLAY specifies which display to ask about.
2314DISPLAY should be either a frame, a display name (a string), or terminal ID.
51d5ef9f 2315If omitted or nil, that stands for the selected frame's display. */)
5842a27b 2316 (Lisp_Object display)
edfda783
AR
2317{
2318 check_ns ();
2319 return make_number
b9126609 2320 (NSBitsPerPixelFromDepth ([ns_get_screen (display) depth]));
edfda783
AR
2321}
2322
2323
952913d4
DN
2324DEFUN ("x-display-color-cells", Fx_display_color_cells,
2325 Sx_display_color_cells, 0, 1, 0,
51d5ef9f 2326 doc: /* Returns the number of color cells of the Nextstep display DISPLAY.
d26fbe1a
CY
2327The optional argument DISPLAY specifies which display to ask about.
2328DISPLAY should be either a frame, a display name (a string), or terminal ID.
51d5ef9f 2329If omitted or nil, that stands for the selected frame's display. */)
5842a27b 2330 (Lisp_Object display)
edfda783 2331{
5d1d3d04 2332 struct ns_display_info *dpyinfo;
edfda783 2333 check_ns ();
5fdb398c 2334
5d1d3d04 2335 dpyinfo = check_ns_display_info (display);
edfda783
AR
2336 /* We force 24+ bit depths to 24-bit to prevent an overflow. */
2337 return make_number (1 << min (dpyinfo->n_planes, 24));
2338}
2339
2340
2341/* Unused dummy def needed for compatibility. */
2342Lisp_Object tip_frame;
2343
6fb5f7da 2344/* TODO: move to xdisp or similar */
edfda783 2345static void
3d608a86
J
2346compute_tip_xy (struct frame *f,
2347 Lisp_Object parms,
2348 Lisp_Object dx,
2349 Lisp_Object dy,
2350 int width,
2351 int height,
2352 int *root_x,
2353 int *root_y)
edfda783
AR
2354{
2355 Lisp_Object left, top;
2356 EmacsView *view = FRAME_NS_VIEW (f);
2357 NSPoint pt;
b066e6b6 2358
edfda783
AR
2359 /* Start with user-specified or mouse position. */
2360 left = Fcdr (Fassq (Qleft, parms));
edfda783 2361 top = Fcdr (Fassq (Qtop, parms));
edfda783 2362
7a18115b
J
2363 if (!INTEGERP (left) || !INTEGERP (top))
2364 {
2365 pt = last_mouse_motion_position;
2366 /* Convert to screen coordinates */
2367 pt = [view convertPoint: pt toView: nil];
2368 pt = [[view window] convertBaseToScreen: pt];
2369 }
2370 else
2371 {
2372 /* Absolute coordinates. */
2373 pt.x = XINT (left);
2374 pt.y = x_display_pixel_height (FRAME_NS_DISPLAY_INFO (f)) - XINT (top)
2375 - height;
2376 }
5fdb398c 2377
edfda783 2378 /* Ensure in bounds. (Note, screen origin = lower left.) */
7a18115b
J
2379 if (INTEGERP (left))
2380 *root_x = pt.x;
2381 else if (pt.x + XINT (dx) <= 0)
edfda783 2382 *root_x = 0; /* Can happen for negative dx */
889bd438
CY
2383 else if (pt.x + XINT (dx) + width
2384 <= x_display_pixel_width (FRAME_NS_DISPLAY_INFO (f)))
edfda783
AR
2385 /* It fits to the right of the pointer. */
2386 *root_x = pt.x + XINT (dx);
2387 else if (width + XINT (dx) <= pt.x)
2388 /* It fits to the left of the pointer. */
2389 *root_x = pt.x - width - XINT (dx);
2390 else
2391 /* Put it left justified on the screen -- it ought to fit that way. */
2392 *root_x = 0;
2393
7a18115b
J
2394 if (INTEGERP (top))
2395 *root_y = pt.y;
2396 else if (pt.y - XINT (dy) - height >= 0)
edfda783
AR
2397 /* It fits below the pointer. */
2398 *root_y = pt.y - height - XINT (dy);
889bd438
CY
2399 else if (pt.y + XINT (dy) + height
2400 <= x_display_pixel_height (FRAME_NS_DISPLAY_INFO (f)))
edfda783
AR
2401 /* It fits above the pointer */
2402 *root_y = pt.y + XINT (dy);
2403 else
2404 /* Put it on the top. */
889bd438 2405 *root_y = x_display_pixel_height (FRAME_NS_DISPLAY_INFO (f)) - height;
edfda783
AR
2406}
2407
2408
2409DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
b066e6b6 2410 doc: /* Show STRING in a \"tooltip\" window on frame FRAME.
edfda783
AR
2411A tooltip window is a small window displaying a string.
2412
4f4f2973
GM
2413This is an internal function; Lisp code should call `tooltip-show'.
2414
edfda783
AR
2415FRAME nil or omitted means use the selected frame.
2416
2417PARMS is an optional list of frame parameters which can be used to
2418change the tooltip's appearance.
2419
2420Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
2421means use the default timeout of 5 seconds.
2422
2423If the list of frame parameters PARMS contains a `left' parameter,
2424the tooltip is displayed at that x-position. Otherwise it is
2425displayed at the mouse position, with offset DX added (default is 5 if
2426DX isn't specified). Likewise for the y-position; if a `top' frame
2427parameter is specified, it determines the y-position of the tooltip
2428window, otherwise it is displayed at the mouse position, with offset
2429DY added (default is -10).
2430
2431A tooltip's maximum size is specified by `x-max-tooltip-size'.
2432Text larger than the specified size is clipped. */)
5842a27b 2433 (Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy)
edfda783
AR
2434{
2435 int root_x, root_y;
2436 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
2437 int count = SPECPDL_INDEX ();
2438 struct frame *f;
2439 char *str;
2440 NSSize size;
2441
2442 specbind (Qinhibit_redisplay, Qt);
2443
2444 GCPRO4 (string, parms, frame, timeout);
2445
2446 CHECK_STRING (string);
facfbbbd 2447 str = SDATA (string);
edfda783
AR
2448 f = check_x_frame (frame);
2449 if (NILP (timeout))
2450 timeout = make_number (5);
2451 else
2452 CHECK_NATNUM (timeout);
2453
2454 if (NILP (dx))
2455 dx = make_number (5);
2456 else
2457 CHECK_NUMBER (dx);
2458
2459 if (NILP (dy))
2460 dy = make_number (-10);
2461 else
2462 CHECK_NUMBER (dy);
2463
2464 BLOCK_INPUT;
2465 if (ns_tooltip == nil)
2466 ns_tooltip = [[EmacsTooltip alloc] init];
2467 else
2468 Fx_hide_tip ();
2469
2470 [ns_tooltip setText: str];
2471 size = [ns_tooltip frame].size;
2472
2473 /* Move the tooltip window where the mouse pointer is. Resize and
2474 show it. */
2475 compute_tip_xy (f, parms, dx, dy, (int)size.width, (int)size.height,
2476 &root_x, &root_y);
2477
2478 [ns_tooltip showAtX: root_x Y: root_y for: XINT (timeout)];
2479 UNBLOCK_INPUT;
2480
2481 UNGCPRO;
2482 return unbind_to (count, Qnil);
2483}
2484
2485
2486DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
2487 doc: /* Hide the current tooltip window, if there is any.
2488Value is t if tooltip was open, nil otherwise. */)
5842a27b 2489 (void)
edfda783
AR
2490{
2491 if (ns_tooltip == nil || ![ns_tooltip isActive])
2492 return Qnil;
2493 [ns_tooltip hide];
2494 return Qt;
2495}
2496
2497
cc98b6a0
DN
2498/* ==========================================================================
2499
2500 Class implementations
2501
2502 ========================================================================== */
2503
2504
2505@implementation EmacsSavePanel
2506#ifdef NS_IMPL_COCOA
2507/* --------------------------------------------------------------------------
2508 These are overridden to intercept on OS X: ending panel restarts NSApp
2509 event loop if it is stopped. Not sure if this is correct behavior,
2510 perhaps should check if running and if so send an appdefined.
2511 -------------------------------------------------------------------------- */
2512- (void) ok: (id)sender
2513{
2514 [super ok: sender];
2515 panelOK = 1;
2516 [NSApp stop: self];
2517}
2518- (void) cancel: (id)sender
2519{
2520 [super cancel: sender];
2521 [NSApp stop: self];
2522}
2523#endif
2524@end
2525
2526
2527@implementation EmacsOpenPanel
2528#ifdef NS_IMPL_COCOA
2529/* --------------------------------------------------------------------------
2530 These are overridden to intercept on OS X: ending panel restarts NSApp
2531 event loop if it is stopped. Not sure if this is correct behavior,
2532 perhaps should check if running and if so send an appdefined.
2533 -------------------------------------------------------------------------- */
2534- (void) ok: (id)sender
2535{
2536 [super ok: sender];
2537 panelOK = 1;
2538 [NSApp stop: self];
2539}
2540- (void) cancel: (id)sender
2541{
2542 [super cancel: sender];
2543 [NSApp stop: self];
2544}
2545#endif
2546@end
2547
2548
2549@implementation EmacsFileDelegate
2550/* --------------------------------------------------------------------------
2551 Delegate methods for Open/Save panels
2552 -------------------------------------------------------------------------- */
2553- (BOOL)panel: (id)sender isValidFilename: (NSString *)filename
2554{
2555 return YES;
2556}
2557- (BOOL)panel: (id)sender shouldShowFilename: (NSString *)filename
2558{
2559 return YES;
2560}
2561- (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
2562 confirmed: (BOOL)okFlag
2563{
2564 return filename;
2565}
2566@end
2567
2568#endif
2569
ba301db3 2570
edfda783
AR
2571/* ==========================================================================
2572
2573 Lisp interface declaration
2574
2575 ========================================================================== */
2576
2577
2578void
3d608a86 2579syms_of_nsfns (void)
edfda783
AR
2580{
2581 int i;
2582
088dcc3e 2583 Qfontsize = intern_c_string ("fontsize");
edfda783
AR
2584 staticpro (&Qfontsize);
2585
fb9d0f5a 2586 DEFVAR_LISP ("ns-icon-type-alist", Vns_icon_type_alist,
51d5ef9f 2587 doc: /* Alist of elements (REGEXP . IMAGE) for images of icons associated to frames.
d26fbe1a
CY
2588If the title of a frame matches REGEXP, then IMAGE.tiff is
2589selected as the image of the icon representing the frame when it's
2590miniaturized. If an element is t, then Emacs tries to select an icon
2591based on the filetype of the visited file.
2592
2593The images have to be installed in a folder called English.lproj in the
2594Emacs folder. You have to restart Emacs after installing new icons.
2595
2596Example: Install an icon Gnus.tiff and execute the following code
2597
2598 (setq ns-icon-type-alist
2599 (append ns-icon-type-alist
2600 '((\"^\\\\*\\\\(Group\\\\*$\\\\|Summary \\\\|Article\\\\*$\\\\)\"
2601 . \"Gnus\"))))
2602
2603When you miniaturize a Group, Summary or Article frame, Gnus.tiff will
51d5ef9f 2604be used as the image of the icon representing the frame. */);
edfda783
AR
2605 Vns_icon_type_alist = Fcons (Qt, Qnil);
2606
fb9d0f5a 2607 DEFVAR_LISP ("ns-version-string", Vns_version_string,
cb83c00b 2608 doc: /* Toolkit version for NS Windowing. */);
f5497e45 2609 Vns_version_string = ns_appkit_version_str ();
cb83c00b 2610
edfda783
AR
2611 defsubr (&Sns_read_file_name);
2612 defsubr (&Sns_get_resource);
2613 defsubr (&Sns_set_resource);
2614 defsubr (&Sxw_display_color_p); /* this and next called directly by C code */
2615 defsubr (&Sx_display_grayscale_p);
edfda783
AR
2616 defsubr (&Sns_font_name);
2617 defsubr (&Sns_list_colors);
74876614 2618#ifdef NS_IMPL_COCOA
583ff3c3 2619 defsubr (&Sns_do_applescript);
74876614 2620#endif
952913d4
DN
2621 defsubr (&Sxw_color_defined_p);
2622 defsubr (&Sxw_color_values);
2623 defsubr (&Sx_server_max_request_size);
9e50ff0c
DN
2624 defsubr (&Sx_server_vendor);
2625 defsubr (&Sx_server_version);
952913d4
DN
2626 defsubr (&Sx_display_pixel_width);
2627 defsubr (&Sx_display_pixel_height);
edfda783 2628 defsubr (&Sns_display_usable_bounds);
9e50ff0c
DN
2629 defsubr (&Sx_display_mm_width);
2630 defsubr (&Sx_display_mm_height);
2631 defsubr (&Sx_display_screens);
952913d4
DN
2632 defsubr (&Sx_display_planes);
2633 defsubr (&Sx_display_color_cells);
9e50ff0c
DN
2634 defsubr (&Sx_display_visual_class);
2635 defsubr (&Sx_display_backing_store);
2636 defsubr (&Sx_display_save_under);
2637 defsubr (&Sx_create_frame);
9e50ff0c
DN
2638 defsubr (&Sx_open_connection);
2639 defsubr (&Sx_close_connection);
2640 defsubr (&Sx_display_list);
edfda783
AR
2641
2642 defsubr (&Sns_hide_others);
2643 defsubr (&Sns_hide_emacs);
2644 defsubr (&Sns_emacs_info_panel);
2645 defsubr (&Sns_list_services);
2646 defsubr (&Sns_perform_service);
2647 defsubr (&Sns_convert_utf8_nfd_to_nfc);
9e50ff0c 2648 defsubr (&Sx_focus_frame);
edfda783
AR
2649 defsubr (&Sns_popup_font_panel);
2650 defsubr (&Sns_popup_color_panel);
2651
2652 defsubr (&Sx_show_tip);
2653 defsubr (&Sx_hide_tip);
2654
2655 /* used only in fontset.c */
2656 check_window_system_func = check_ns;
2657
2658}