1 /* Functions for the NeXT/Open/GNUstep and MacOSX window system.
3 Copyright (C) 1989, 1992-1994, 2005-2006, 2008-2013 Free Software
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 Originally by Carl Edman
23 Updated by Christian Limpach (chris@nice.ch)
24 OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com)
25 MacOSX/Aqua port by Christophe de Dinechin (descubes@earthlink.net)
26 GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
29 /* This should be the first include, as it may set up #defines affecting
30 interpretation of even the system includes. */
34 #include <c-strcase.h>
37 #include "blockinput.h"
40 #include "character.h"
43 #include "termhooks.h"
48 int fns_trace_num = 1;
49 #define NSTRACE(x) fprintf (stderr, "%s:%d: [%d] " #x "\n", \
50 __FILE__, __LINE__, ++fns_trace_num)
57 extern NSArray *ns_send_types, *ns_return_types, *ns_drag_types;
59 extern Lisp_Object Qforeground_color;
60 extern Lisp_Object Qbackground_color;
61 extern Lisp_Object Qcursor_color;
62 extern Lisp_Object Qinternal_border_width;
63 extern Lisp_Object Qvisibility;
64 extern Lisp_Object Qcursor_type;
65 extern Lisp_Object Qicon_type;
66 extern Lisp_Object Qicon_name;
67 extern Lisp_Object Qicon_left;
68 extern Lisp_Object Qicon_top;
69 extern Lisp_Object Qleft;
70 extern Lisp_Object Qright;
71 extern Lisp_Object Qtop;
72 extern Lisp_Object Qdisplay;
73 extern Lisp_Object Qvertical_scroll_bars;
74 extern Lisp_Object Qauto_raise;
75 extern Lisp_Object Qauto_lower;
76 extern Lisp_Object Qbox;
77 extern Lisp_Object Qscroll_bar_width;
78 extern Lisp_Object Qx_resource_name;
79 extern Lisp_Object Qface_set_after_frame_default;
80 extern Lisp_Object Qunderline, Qundefined;
81 extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth;
82 extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle;
85 Lisp_Object Qbuffered;
86 Lisp_Object Qfontsize;
88 /* hack for OS X file panels */
91 EmacsTooltip *ns_tooltip;
93 /* Need forward declaration here to preserve organizational integrity of file */
94 Lisp_Object Fx_open_connection (Lisp_Object, Lisp_Object, Lisp_Object);
96 /* Static variables to handle applescript execution. */
97 static Lisp_Object as_script, *as_result;
101 static ptrdiff_t image_cache_refcount;
104 /* ==========================================================================
106 Internal utility functions
108 ========================================================================== */
115 error ("OpenStep is not in use or not initialized");
119 /* Nonzero if we can use mouse menus. */
127 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
128 and checking validity for NS. */
130 check_ns_frame (Lisp_Object frame)
135 f = SELECTED_FRAME ();
138 CHECK_LIVE_FRAME (frame);
141 if (! FRAME_NS_P (f))
142 error ("non-Nextstep frame used");
147 /* Let the user specify an Nextstep display with a frame.
148 nil stands for the selected frame--or, if that is not an Nextstep frame,
149 the first Nextstep display on the list. */
150 static struct ns_display_info *
151 check_ns_display_info (Lisp_Object frame)
155 struct frame *f = SELECTED_FRAME ();
156 if (FRAME_NS_P (f) && FRAME_LIVE_P (f) )
157 return FRAME_NS_DISPLAY_INFO (f);
158 else if (x_display_list != 0)
159 return x_display_list;
161 error ("Nextstep windows are not in use or not initialized");
163 else if (INTEGERP (frame))
165 struct terminal *t = get_terminal (frame, 1);
167 if (t->type != output_ns)
168 error ("Terminal %"pI"d is not a Nextstep display", XINT (frame));
170 return t->display_info.ns;
172 else if (STRINGP (frame))
173 return ns_display_info_for_name (frame);
178 CHECK_LIVE_FRAME (frame);
180 if (! FRAME_NS_P (f))
181 error ("non-Nextstep frame used");
182 return FRAME_NS_DISPLAY_INFO (f);
184 return NULL; /* shut compiler up */
189 ns_get_window (Lisp_Object maybeFrame)
191 id view =nil, window =nil;
193 if (!FRAMEP (maybeFrame) || !FRAME_NS_P (XFRAME (maybeFrame)))
194 maybeFrame = selected_frame;/*wrong_type_argument (Qframep, maybeFrame); */
196 if (!NILP (maybeFrame))
197 view = FRAME_NS_VIEW (XFRAME (maybeFrame));
198 if (view) window =[view window];
205 ns_get_screen (Lisp_Object screen)
208 struct terminal *terminal;
210 if (EQ (Qt, screen)) /* not documented */
211 return [NSScreen mainScreen];
213 terminal = get_terminal (screen, 1);
214 if (terminal->type != output_ns)
218 f = SELECTED_FRAME ();
219 else if (FRAMEP (screen))
223 struct ns_display_info *dpyinfo = terminal->display_info.ns;
224 f = dpyinfo->x_focus_frame
225 ? dpyinfo->x_focus_frame : dpyinfo->x_highlight_frame;
228 return ((f && FRAME_NS_P (f)) ? [[FRAME_NS_VIEW (f) window] screen]
233 /* Return the X display structure for the display named NAME.
234 Open a new connection if necessary. */
235 struct ns_display_info *
236 ns_display_info_for_name (Lisp_Object name)
239 struct ns_display_info *dpyinfo;
243 for (dpyinfo = x_display_list, names = ns_display_name_list;
245 dpyinfo = dpyinfo->next, names = XCDR (names))
248 tem = Fstring_equal (XCAR (XCAR (names)), name);
253 error ("Emacs for OpenStep does not yet support multi-display.");
255 Fx_open_connection (name, Qnil, Qnil);
256 dpyinfo = x_display_list;
259 error ("OpenStep on %s not responding.\n", SDATA (name));
266 interpret_services_menu (NSMenu *menu, Lisp_Object prefix, Lisp_Object old)
267 /* --------------------------------------------------------------------------
268 Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
269 -------------------------------------------------------------------------- */
279 count = [menu numberOfItems];
280 for (i = 0; i<count; i++)
282 item = [menu itemAtIndex: i];
283 name = [[item title] UTF8String];
286 nameStr = build_string (name);
288 if ([item hasSubmenu])
290 old = interpret_services_menu ([item submenu],
291 Fcons (nameStr, prefix), old);
295 keys = [item keyEquivalent];
296 if (keys && [keys length] )
298 key = [keys characterAtIndex: 0];
299 res = make_number (key|super_modifier);
305 old = Fcons (Fcons (res,
306 Freverse (Fcons (nameStr,
316 /* ==========================================================================
318 Frame parameter setters
320 ========================================================================== */
324 x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
327 CGFloat r, g, b, alpha;
329 if (ns_lisp_to_color (arg, &col))
331 store_frame_param (f, Qforeground_color, oldval);
332 error ("Unknown color");
336 [f->output_data.ns->foreground_color release];
337 f->output_data.ns->foreground_color = col;
339 [col getRed: &r green: &g blue: &b alpha: &alpha];
340 FRAME_FOREGROUND_PIXEL (f) =
341 ARGB_TO_ULONG ((int)(alpha*0xff), (int)(r*0xff), (int)(g*0xff), (int)(b*0xff));
343 if (FRAME_NS_VIEW (f))
345 update_face_from_frame_parameter (f, Qforeground_color, arg);
346 /*recompute_basic_faces (f); */
347 if (FRAME_VISIBLE_P (f))
354 x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
358 NSView *view = FRAME_NS_VIEW (f);
359 CGFloat r, g, b, alpha;
361 if (ns_lisp_to_color (arg, &col))
363 store_frame_param (f, Qbackground_color, oldval);
364 error ("Unknown color");
367 /* clear the frame; in some instances the NS-internal GC appears not to
368 update, or it does update and cannot clear old text properly */
369 if (FRAME_VISIBLE_P (f))
373 [f->output_data.ns->background_color release];
374 f->output_data.ns->background_color = col;
376 [col getRed: &r green: &g blue: &b alpha: &alpha];
377 FRAME_BACKGROUND_PIXEL (f) =
378 ARGB_TO_ULONG ((int)(alpha*0xff), (int)(r*0xff), (int)(g*0xff), (int)(b*0xff));
382 [[view window] setBackgroundColor: col];
385 [[view window] setOpaque: NO];
387 [[view window] setOpaque: YES];
389 face = FRAME_DEFAULT_FACE (f);
392 col = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f);
393 face->background = ns_index_color
394 ([col colorWithAlphaComponent: alpha], f);
396 update_face_from_frame_parameter (f, Qbackground_color, arg);
399 if (FRAME_VISIBLE_P (f))
406 x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
410 if (ns_lisp_to_color (arg, &col))
412 store_frame_param (f, Qcursor_color, oldval);
413 error ("Unknown color");
416 [FRAME_CURSOR_COLOR (f) release];
417 FRAME_CURSOR_COLOR (f) = [col retain];
419 if (FRAME_VISIBLE_P (f))
421 x_update_cursor (f, 0);
422 x_update_cursor (f, 1);
424 update_face_from_frame_parameter (f, Qcursor_color, arg);
429 x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
431 NSView *view = FRAME_NS_VIEW (f);
432 NSTRACE (x_set_icon_name);
434 /* see if it's changed */
437 if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
440 else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
443 fset_icon_name (f, arg);
447 if (!NILP (f->title))
450 /* explicit name and no icon-name -> explicit_name */
451 if (f->explicit_name)
455 /* no explicit name and no icon-name ->
456 name has to be rebuild from icon_title_format */
457 windows_or_buffers_changed++;
462 /* Don't change the name if it's already NAME. */
463 if ([[view window] miniwindowTitle] &&
464 ([[[view window] miniwindowTitle]
465 isEqualToString: [NSString stringWithUTF8String:
469 [[view window] setMiniwindowTitle:
470 [NSString stringWithUTF8String: SSDATA (arg)]];
474 ns_set_name_internal (FRAME_PTR f, Lisp_Object name)
477 Lisp_Object encoded_name, encoded_icon_name;
479 NSView *view = FRAME_NS_VIEW (f);
482 encoded_name = ENCODE_UTF_8 (name);
485 str = [NSString stringWithUTF8String: SSDATA (encoded_name)];
487 /* Don't change the name if it's already NAME. */
488 if (! [[[view window] title] isEqualToString: str])
489 [[view window] setTitle: str];
491 if (!STRINGP (f->icon_name))
492 encoded_icon_name = encoded_name;
494 encoded_icon_name = ENCODE_UTF_8 (f->icon_name);
496 str = [NSString stringWithUTF8String: SSDATA (encoded_icon_name)];
498 if ([[view window] miniwindowTitle] &&
499 ! [[[view window] miniwindowTitle] isEqualToString: str])
500 [[view window] setMiniwindowTitle: str];
505 ns_set_name (struct frame *f, Lisp_Object name, int explicit)
507 NSTRACE (ns_set_name);
509 /* Make sure that requests from lisp code override requests from
510 Emacs redisplay code. */
513 /* If we're switching from explicit to implicit, we had better
514 update the mode lines and thereby update the title. */
515 if (f->explicit_name && NILP (name))
516 update_mode_lines = 1;
518 f->explicit_name = ! NILP (name);
520 else if (f->explicit_name)
524 name = build_string([ns_app_name UTF8String]);
528 /* Don't change the name if it's already NAME. */
529 if (! NILP (Fstring_equal (name, f->name)))
534 /* title overrides explicit name */
535 if (! NILP (f->title))
538 ns_set_name_internal (f, name);
542 /* This function should be called when the user's lisp code has
543 specified a name for the frame; the name will override any set by the
546 x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
548 NSTRACE (x_explicitly_set_name);
549 ns_set_name (f, arg, 1);
553 /* This function should be called by Emacs redisplay code to set the
554 name; names set this way will never override names set by the user's
557 x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
559 NSTRACE (x_implicitly_set_name);
561 /* Deal with NS specific format t. */
562 if (FRAME_NS_P (f) && ((FRAME_ICONIFIED_P (f) && EQ (Vicon_title_format, Qt))
563 || EQ (Vframe_title_format, Qt)))
564 ns_set_name_as_filename (f);
566 ns_set_name (f, arg, 0);
570 /* Change the title of frame F to NAME.
571 If NAME is nil, use the frame name as the title. */
574 x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
576 NSTRACE (x_set_title);
577 /* Don't change the title if it's already NAME. */
578 if (EQ (name, f->title))
581 update_mode_lines = 1;
583 fset_title (f, name);
590 ns_set_name_internal (f, name);
595 ns_set_name_as_filename (struct frame *f)
598 Lisp_Object name, filename;
599 Lisp_Object buf = XWINDOW (f->selected_window)->buffer;
601 NSAutoreleasePool *pool;
603 Lisp_Object encoded_name, encoded_filename;
605 NSTRACE (ns_set_name_as_filename);
607 if (f->explicit_name || ! NILP (f->title))
611 pool = [[NSAutoreleasePool alloc] init];
612 filename = BVAR (XBUFFER (buf), filename);
613 name = BVAR (XBUFFER (buf), name);
617 if (! NILP (filename))
618 name = Ffile_name_nondirectory (filename);
620 name = build_string ([ns_app_name UTF8String]);
624 encoded_name = ENCODE_UTF_8 (name);
627 view = FRAME_NS_VIEW (f);
629 title = FRAME_ICONIFIED_P (f) ? [[[view window] miniwindowTitle] UTF8String]
630 : [[[view window] title] UTF8String];
632 if (title && (! strcmp (title, SSDATA (encoded_name))))
639 str = [NSString stringWithUTF8String: SSDATA (encoded_name)];
640 if (str == nil) str = @"Bad coding";
642 if (FRAME_ICONIFIED_P (f))
643 [[view window] setMiniwindowTitle: str];
648 if (! NILP (filename))
651 encoded_filename = ENCODE_UTF_8 (filename);
654 fstr = [NSString stringWithUTF8String: SSDATA (encoded_filename)];
655 if (fstr == nil) fstr = @"";
657 /* work around a bug observed on 10.3 and later where
658 setTitleWithRepresentedFilename does not clear out previous state
659 if given filename does not exist */
660 if (! [[NSFileManager defaultManager] fileExistsAtPath: fstr])
661 [[view window] setRepresentedFilename: @""];
667 [[view window] setRepresentedFilename: fstr];
668 [[view window] setTitle: str];
678 ns_set_doc_edited (struct frame *f, Lisp_Object arg)
680 NSView *view = FRAME_NS_VIEW (f);
681 NSAutoreleasePool *pool;
682 if (!MINI_WINDOW_P (XWINDOW (f->selected_window)))
685 pool = [[NSAutoreleasePool alloc] init];
686 [[view window] setDocumentEdited: !NILP (arg)];
694 x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
697 if (FRAME_MINIBUF_ONLY_P (f))
700 if (TYPE_RANGED_INTEGERP (int, value))
701 nlines = XINT (value);
705 FRAME_MENU_BAR_LINES (f) = 0;
708 FRAME_EXTERNAL_MENU_BAR (f) = 1;
709 /* does for all frames, whereas we just want for one frame
710 [NSMenu setMenuBarVisible: YES]; */
714 if (FRAME_EXTERNAL_MENU_BAR (f) == 1)
715 free_frame_menubar (f);
716 /* [NSMenu setMenuBarVisible: NO]; */
717 FRAME_EXTERNAL_MENU_BAR (f) = 0;
722 /* toolbar support */
724 x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
728 if (FRAME_MINIBUF_ONLY_P (f))
731 if (RANGED_INTEGERP (0, value, INT_MAX))
732 nlines = XFASTINT (value);
738 FRAME_EXTERNAL_TOOL_BAR (f) = 1;
739 update_frame_tool_bar (f);
743 if (FRAME_EXTERNAL_TOOL_BAR (f))
745 free_frame_tool_bar (f);
746 FRAME_EXTERNAL_TOOL_BAR (f) = 0;
750 x_set_window_size (f, 0, f->text_cols, f->text_lines);
755 ns_implicitly_set_icon_type (struct frame *f)
758 EmacsView *view = FRAME_NS_VIEW (f);
760 Lisp_Object chain, elt;
761 NSAutoreleasePool *pool;
764 NSTRACE (ns_implicitly_set_icon_type);
767 pool = [[NSAutoreleasePool alloc] init];
768 if (f->output_data.ns->miniimage
769 && [[NSString stringWithUTF8String: SSDATA (f->name)]
770 isEqualToString: [(NSImage *)f->output_data.ns->miniimage name]])
777 tem = assq_no_quit (Qicon_type, f->param_alist);
778 if (CONSP (tem) && ! NILP (XCDR (tem)))
785 for (chain = Vns_icon_type_alist;
786 image == nil && CONSP (chain);
787 chain = XCDR (chain))
790 /* special case: 't' means go by file type */
791 if (SYMBOLP (elt) && EQ (elt, Qt) && SSDATA (f->name)[0] == '/')
794 = [NSString stringWithUTF8String: SSDATA (f->name)];
795 if ([[NSFileManager defaultManager] fileExistsAtPath: str])
796 image = [[[NSWorkspace sharedWorkspace] iconForFile: str] retain];
798 else if (CONSP (elt) &&
799 STRINGP (XCAR (elt)) &&
800 STRINGP (XCDR (elt)) &&
801 fast_string_match (XCAR (elt), f->name) >= 0)
803 image = [EmacsImage allocInitFromFile: XCDR (elt)];
805 image = [[NSImage imageNamed:
806 [NSString stringWithUTF8String:
807 SSDATA (XCDR (elt))]] retain];
813 image = [[[NSWorkspace sharedWorkspace] iconForFileType: @"text"] retain];
817 [f->output_data.ns->miniimage release];
818 f->output_data.ns->miniimage = image;
819 [view setMiniwindowImage: setMini];
826 x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
828 EmacsView *view = FRAME_NS_VIEW (f);
832 NSTRACE (x_set_icon_type);
834 if (!NILP (arg) && SYMBOLP (arg))
836 arg =build_string (SSDATA (SYMBOL_NAME (arg)));
837 store_frame_param (f, Qicon_type, arg);
840 /* do it the implicit way */
843 ns_implicitly_set_icon_type (f);
849 image = [EmacsImage allocInitFromFile: arg];
851 image =[NSImage imageNamed: [NSString stringWithUTF8String:
856 image = [NSImage imageNamed: @"text"];
860 f->output_data.ns->miniimage = image;
861 [view setMiniwindowImage: setMini];
865 /* TODO: move to nsterm? */
867 ns_lisp_to_cursor_type (Lisp_Object arg)
870 if (XTYPE (arg) == Lisp_String)
872 else if (XTYPE (arg) == Lisp_Symbol)
873 str = SSDATA (SYMBOL_NAME (arg));
875 if (!strcmp (str, "box")) return FILLED_BOX_CURSOR;
876 if (!strcmp (str, "hollow")) return HOLLOW_BOX_CURSOR;
877 if (!strcmp (str, "hbar")) return HBAR_CURSOR;
878 if (!strcmp (str, "bar")) return BAR_CURSOR;
879 if (!strcmp (str, "no")) return NO_CURSOR;
885 ns_cursor_type_to_lisp (int arg)
889 case FILLED_BOX_CURSOR: return Qbox;
890 case HOLLOW_BOX_CURSOR: return intern ("hollow");
891 case HBAR_CURSOR: return intern ("hbar");
892 case BAR_CURSOR: return intern ("bar");
894 default: return intern ("no");
898 /* This is the same as the xfns.c definition. */
900 x_set_cursor_type (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
902 set_frame_cursor_types (f, arg);
904 /* Make sure the cursor gets redrawn. */
905 cursor_type_changed = 1;
909 /* called to set mouse pointer color, but all other terms use it to
910 initialize pointer types (and don't set the color ;) */
912 x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
914 /* don't think we can do this on Nextstep */
919 #define Xstr(x) Str(x)
922 ns_appkit_version_str (void)
926 #ifdef NS_IMPL_GNUSTEP
927 sprintf(tmp, "gnustep-gui-%s", Xstr(GNUSTEP_GUI_VERSION));
928 #elif defined(NS_IMPL_COCOA)
929 sprintf(tmp, "apple-appkit-%.2f", NSAppKitVersionNumber);
933 return build_string (tmp);
937 /* This is for use by x-server-version and collapses all version info we
938 have into a single int. For a better picture of the implementation
939 running, use ns_appkit_version_str.*/
941 ns_appkit_version_int (void)
943 #ifdef NS_IMPL_GNUSTEP
944 return GNUSTEP_GUI_MAJOR_VERSION * 100 + GNUSTEP_GUI_MINOR_VERSION;
945 #elif defined(NS_IMPL_COCOA)
946 return (int)NSAppKitVersionNumber;
953 x_icon (struct frame *f, Lisp_Object parms)
954 /* --------------------------------------------------------------------------
955 Strangely-named function to set icon position parameters in frame.
956 This is irrelevant under OS X, but might be needed under GNUstep,
957 depending on the window manager used. Note, this is not a standard
958 frame parameter-setter; it is called directly from x-create-frame.
959 -------------------------------------------------------------------------- */
961 Lisp_Object icon_x, icon_y;
962 struct ns_display_info *dpyinfo = check_ns_display_info (Qnil);
964 f->output_data.ns->icon_top = Qnil;
965 f->output_data.ns->icon_left = Qnil;
967 /* Set the position of the icon. */
968 icon_x = x_get_arg (dpyinfo, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
969 icon_y = x_get_arg (dpyinfo, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
970 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
972 CHECK_NUMBER (icon_x);
973 CHECK_NUMBER (icon_y);
974 f->output_data.ns->icon_top = icon_y;
975 f->output_data.ns->icon_left = icon_x;
977 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
978 error ("Both left and top icon corners of icon must be specified");
982 /* Note: see frame.c for template, also where generic functions are impl */
983 frame_parm_handler ns_frame_parm_handlers[] =
985 x_set_autoraise, /* generic OK */
986 x_set_autolower, /* generic OK */
987 x_set_background_color,
988 0, /* x_set_border_color, may be impossible under Nextstep */
989 0, /* x_set_border_width, may be impossible under Nextstep */
992 x_set_font, /* generic OK */
993 x_set_foreground_color,
996 x_set_internal_border_width, /* generic OK */
997 x_set_menu_bar_lines,
999 x_explicitly_set_name,
1000 x_set_scroll_bar_width, /* generic OK */
1002 x_set_unsplittable, /* generic OK */
1003 x_set_vertical_scroll_bars, /* generic OK */
1004 x_set_visibility, /* generic OK */
1005 x_set_tool_bar_lines,
1006 0, /* x_set_scroll_bar_foreground, will ignore (not possible on NS) */
1007 0, /* x_set_scroll_bar_background, will ignore (not possible on NS) */
1008 x_set_screen_gamma, /* generic OK */
1009 x_set_line_spacing, /* generic OK, sets f->extra_line_spacing to int */
1010 x_set_fringe_width, /* generic OK */
1011 x_set_fringe_width, /* generic OK */
1012 0, /* x_set_wait_for_wm, will ignore */
1013 x_set_fullscreen, /* generic OK */
1014 x_set_font_backend, /* generic OK */
1016 0, /* x_set_sticky */
1017 0, /* x_set_tool_bar_position */
1021 /* Handler for signals raised during x_create_frame.
1022 FRAME is the frame which is partially constructed. */
1025 unwind_create_frame (Lisp_Object frame)
1027 struct frame *f = XFRAME (frame);
1029 /* If frame is already dead, nothing to do. This can happen if the
1030 display is disconnected after the frame has become official, but
1031 before x_create_frame removes the unwind protect. */
1032 if (!FRAME_LIVE_P (f))
1035 /* If frame is ``official'', nothing to do. */
1036 if (NILP (Fmemq (frame, Vframe_list)))
1038 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
1039 struct ns_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
1042 x_free_frame_resources (f);
1046 /* Check that reference counts are indeed correct. */
1047 eassert (dpyinfo->terminal->image_cache->refcount == image_cache_refcount);
1056 * Read geometry related parameters from preferences if not in PARMS.
1057 * Returns the union of parms and any preferences read.
1061 get_geometry_from_preferences (struct ns_display_info *dpyinfo,
1069 { "width", "Width", Qwidth },
1070 { "height", "Height", Qheight },
1071 { "left", "Left", Qleft },
1072 { "top", "Top", Qtop },
1076 for (i = 0; i < sizeof (r)/sizeof (r[0]); ++i)
1078 if (NILP (Fassq (r[i].tem, parms)))
1081 = x_get_arg (dpyinfo, parms, r[i].tem, r[i].val, r[i].cls,
1083 if (! EQ (value, Qunbound))
1084 parms = Fcons (Fcons (r[i].tem, value), parms);
1091 /* ==========================================================================
1095 ========================================================================== */
1097 DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
1099 doc: /* Make a new Nextstep window, called a "frame" in Emacs terms.
1100 Return an Emacs frame object.
1101 PARMS is an alist of frame parameters.
1102 If the parameters specify that the frame should not have a minibuffer,
1103 and do not specify a specific minibuffer window to use,
1104 then `default-minibuffer-frame' must be a frame whose minibuffer can
1105 be shared by the new frame.
1107 This function is an internal primitive--use `make-frame' instead. */)
1111 Lisp_Object frame, tem;
1113 int minibuffer_only = 0;
1114 int window_prompting = 0;
1116 ptrdiff_t count = specpdl_ptr - specpdl;
1117 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1118 Lisp_Object display;
1119 struct ns_display_info *dpyinfo = NULL;
1122 Lisp_Object tfont, tfontsize;
1123 static int desc_ctr = 1;
1127 /* x_get_arg modifies parms. */
1128 parms = Fcopy_alist (parms);
1130 /* Use this general default value to start with
1131 until we know if this frame has a specified name. */
1132 Vx_resource_name = Vinvocation_name;
1134 display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_STRING);
1135 if (EQ (display, Qunbound))
1137 dpyinfo = check_ns_display_info (display);
1138 kb = dpyinfo->terminal->kboard;
1140 if (!dpyinfo->terminal->name)
1141 error ("Terminal is not live, can't create new frames on it");
1143 name = x_get_arg (dpyinfo, parms, Qname, 0, 0, RES_TYPE_STRING);
1145 && ! EQ (name, Qunbound)
1147 error ("Invalid frame name--not a string or nil");
1150 Vx_resource_name = name;
1152 parent = x_get_arg (dpyinfo, parms, Qparent_id, 0, 0, RES_TYPE_NUMBER);
1153 if (EQ (parent, Qunbound))
1155 if (! NILP (parent))
1156 CHECK_NUMBER (parent);
1158 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
1159 /* No need to protect DISPLAY because that's not used after passing
1160 it to make_frame_without_minibuffer. */
1162 GCPRO4 (parms, parent, name, frame);
1163 tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer",
1165 if (EQ (tem, Qnone) || NILP (tem))
1166 f = make_frame_without_minibuffer (Qnil, kb, display);
1167 else if (EQ (tem, Qonly))
1169 f = make_minibuffer_frame ();
1170 minibuffer_only = 1;
1172 else if (WINDOWP (tem))
1173 f = make_frame_without_minibuffer (tem, kb, display);
1177 XSETFRAME (frame, f);
1178 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
1180 f->terminal = dpyinfo->terminal;
1182 f->output_method = output_ns;
1183 f->output_data.ns = xzalloc (sizeof *f->output_data.ns);
1185 FRAME_FONTSET (f) = -1;
1187 fset_icon_name (f, x_get_arg (dpyinfo, parms, Qicon_name,
1188 "iconName", "Title",
1190 if (! STRINGP (f->icon_name))
1191 fset_icon_name (f, Qnil);
1193 FRAME_NS_DISPLAY_INFO (f) = dpyinfo;
1195 /* With FRAME_NS_DISPLAY_INFO set up, this unwind-protect is safe. */
1196 record_unwind_protect (unwind_create_frame, frame);
1198 f->output_data.ns->window_desc = desc_ctr++;
1199 if (TYPE_RANGED_INTEGERP (Window, parent))
1201 f->output_data.ns->parent_desc = XFASTINT (parent);
1202 f->output_data.ns->explicit_parent = 1;
1206 f->output_data.ns->parent_desc = FRAME_NS_DISPLAY_INFO (f)->root_window;
1207 f->output_data.ns->explicit_parent = 0;
1210 /* Set the name; the functions to which we pass f expect the name to
1212 if (EQ (name, Qunbound) || NILP (name) || ! STRINGP (name))
1214 fset_name (f, build_string ([ns_app_name UTF8String]));
1215 f->explicit_name = 0;
1219 fset_name (f, name);
1220 f->explicit_name = 1;
1221 specbind (Qx_resource_name, name);
1224 f->resx = dpyinfo->resx;
1225 f->resy = dpyinfo->resy;
1228 register_font_driver (&nsfont_driver, f);
1229 x_default_parameter (f, parms, Qfont_backend, Qnil,
1230 "fontBackend", "FontBackend", RES_TYPE_STRING);
1233 /* use for default font name */
1234 id font = [NSFont userFixedPitchFontOfSize: -1.0]; /* default */
1235 tfontsize = x_default_parameter (f, parms, Qfontsize,
1236 make_number (0 /*(int)[font pointSize]*/),
1237 "fontSize", "FontSize", RES_TYPE_NUMBER);
1238 tfont = x_default_parameter (f, parms, Qfont,
1239 build_string ([[font fontName] UTF8String]),
1240 "font", "Font", RES_TYPE_STRING);
1244 x_default_parameter (f, parms, Qborder_width, make_number (0),
1245 "borderwidth", "BorderWidth", RES_TYPE_NUMBER);
1246 x_default_parameter (f, parms, Qinternal_border_width, make_number (2),
1247 "internalBorderWidth", "InternalBorderWidth",
1250 /* default scrollbars on right on Mac */
1253 #ifdef NS_IMPL_GNUSTEP
1258 x_default_parameter (f, parms, Qvertical_scroll_bars, spos,
1259 "verticalScrollBars", "VerticalScrollBars",
1262 x_default_parameter (f, parms, Qforeground_color, build_string ("Black"),
1263 "foreground", "Foreground", RES_TYPE_STRING);
1264 x_default_parameter (f, parms, Qbackground_color, build_string ("White"),
1265 "background", "Background", RES_TYPE_STRING);
1266 /* FIXME: not supported yet in Nextstep */
1267 x_default_parameter (f, parms, Qline_spacing, Qnil,
1268 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
1269 x_default_parameter (f, parms, Qleft_fringe, Qnil,
1270 "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
1271 x_default_parameter (f, parms, Qright_fringe, Qnil,
1272 "rightFringe", "RightFringe", RES_TYPE_NUMBER);
1275 image_cache_refcount =
1276 FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0;
1279 init_frame_faces (f);
1281 /* The resources controlling the menu-bar and tool-bar are
1282 processed specially at startup, and reflected in the mode
1283 variables; ignore them here. */
1284 x_default_parameter (f, parms, Qmenu_bar_lines,
1285 NILP (Vmenu_bar_mode)
1286 ? make_number (0) : make_number (1),
1287 NULL, NULL, RES_TYPE_NUMBER);
1288 x_default_parameter (f, parms, Qtool_bar_lines,
1289 NILP (Vtool_bar_mode)
1290 ? make_number (0) : make_number (1),
1291 NULL, NULL, RES_TYPE_NUMBER);
1293 x_default_parameter (f, parms, Qbuffer_predicate, Qnil, "bufferPredicate",
1294 "BufferPredicate", RES_TYPE_SYMBOL);
1295 x_default_parameter (f, parms, Qtitle, Qnil, "title", "Title",
1298 parms = get_geometry_from_preferences (dpyinfo, parms);
1299 window_prompting = x_figure_window_size (f, parms, 1);
1301 tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
1302 f->no_split = minibuffer_only || (!EQ (tem, Qunbound) && !EQ (tem, Qnil));
1304 /* NOTE: on other terms, this is done in set_mouse_color, however this
1305 was not getting called under Nextstep */
1306 f->output_data.ns->text_cursor = [NSCursor IBeamCursor];
1307 f->output_data.ns->nontext_cursor = [NSCursor arrowCursor];
1308 f->output_data.ns->modeline_cursor = [NSCursor pointingHandCursor];
1309 f->output_data.ns->hand_cursor = [NSCursor pointingHandCursor];
1310 f->output_data.ns->hourglass_cursor = [NSCursor disappearingItemCursor];
1311 f->output_data.ns->horizontal_drag_cursor = [NSCursor resizeLeftRightCursor];
1312 FRAME_NS_DISPLAY_INFO (f)->vertical_scroll_bar_cursor
1313 = [NSCursor arrowCursor];
1314 f->output_data.ns->current_pointer = f->output_data.ns->text_cursor;
1316 [[EmacsView alloc] initFrameFromEmacs: f];
1320 /* ns_display_info does not have a reference_count. */
1321 f->terminal->reference_count++;
1323 /* It is now ok to make the frame official even if we get an error below.
1324 The frame needs to be on Vframe_list or making it visible won't work. */
1325 Vframe_list = Fcons (frame, Vframe_list);
1327 x_default_parameter (f, parms, Qicon_type, Qnil,
1328 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
1330 x_default_parameter (f, parms, Qauto_raise, Qnil,
1331 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
1332 x_default_parameter (f, parms, Qauto_lower, Qnil,
1333 "autoLower", "AutoLower", RES_TYPE_BOOLEAN);
1334 x_default_parameter (f, parms, Qcursor_type, Qbox,
1335 "cursorType", "CursorType", RES_TYPE_SYMBOL);
1336 x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
1337 "scrollBarWidth", "ScrollBarWidth",
1339 x_default_parameter (f, parms, Qalpha, Qnil,
1340 "alpha", "Alpha", RES_TYPE_NUMBER);
1341 x_default_parameter (f, parms, Qfullscreen, Qnil,
1342 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
1344 width = FRAME_COLS (f);
1345 height = FRAME_LINES (f);
1347 SET_FRAME_COLS (f, 0);
1348 FRAME_LINES (f) = 0;
1349 change_frame_size (f, height, width, 1, 0, 0);
1351 if (! f->output_data.ns->explicit_parent)
1353 Lisp_Object visibility;
1355 visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
1357 if (EQ (visibility, Qunbound))
1360 if (EQ (visibility, Qicon))
1361 x_iconify_frame (f);
1362 else if (! NILP (visibility))
1364 x_make_frame_visible (f);
1365 [[FRAME_NS_VIEW (f) window] makeKeyWindow];
1369 /* Must have been Qnil. */
1373 if (FRAME_HAS_MINIBUF_P (f)
1374 && (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
1375 || !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame)))))
1376 kset_default_minibuffer_frame (kb, frame);
1378 /* All remaining specified parameters, which have not been "used"
1379 by x_get_arg and friends, now go in the misc. alist of the frame. */
1380 for (tem = parms; CONSP (tem); tem = XCDR (tem))
1381 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
1382 fset_param_alist (f, Fcons (XCAR (tem), f->param_alist));
1386 if (window_prompting & USPosition)
1387 x_set_offset (f, f->left_pos, f->top_pos, 1);
1389 /* Make sure windows on this frame appear in calls to next-window
1390 and similar functions. */
1391 Vwindow_list = Qnil;
1393 return unbind_to (count, frame);
1397 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
1398 doc: /* Set the input focus to FRAME.
1399 FRAME nil means use the selected frame. */)
1402 struct frame *f = check_ns_frame (frame);
1403 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f);
1405 if (dpyinfo->x_focus_frame != f)
1407 EmacsView *view = FRAME_NS_VIEW (f);
1409 [NSApp activateIgnoringOtherApps: YES];
1410 [[view window] makeKeyAndOrderFront: view];
1418 DEFUN ("ns-popup-font-panel", Fns_popup_font_panel, Sns_popup_font_panel,
1420 doc: /* Pop up the font panel. */)
1427 fm = [NSFontManager sharedFontManager];
1429 f = SELECTED_FRAME ();
1432 CHECK_FRAME (frame);
1436 [fm setSelectedFont: ((struct nsfont_info *)f->output_data.ns->font)->nsfont
1438 [fm orderFrontFontPanel: NSApp];
1443 DEFUN ("ns-popup-color-panel", Fns_popup_color_panel, Sns_popup_color_panel,
1445 doc: /* Pop up the color panel. */)
1452 f = SELECTED_FRAME ();
1455 CHECK_FRAME (frame);
1459 [NSApp orderFrontColorPanel: NSApp];
1464 DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 5, 0,
1465 doc: /* Use a graphical panel to read a file name, using prompt PROMPT.
1466 Optional arg DIR, if non-nil, supplies a default directory.
1467 Optional arg MUSTMATCH, if non-nil, means the returned file or
1468 directory must exist.
1469 Optional arg INIT, if non-nil, provides a default file name to use.
1470 Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1471 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object mustmatch,
1472 Lisp_Object init, Lisp_Object dir_only_p)
1474 static id fileDelegate = nil;
1479 NSString *promptS = NILP (prompt) || !STRINGP (prompt) ? nil :
1480 [NSString stringWithUTF8String: SSDATA (prompt)];
1481 NSString *dirS = NILP (dir) || !STRINGP (dir) ?
1482 [NSString stringWithUTF8String: SSDATA (BVAR (current_buffer, directory))] :
1483 [NSString stringWithUTF8String: SSDATA (dir)];
1484 NSString *initS = NILP (init) || !STRINGP (init) ? nil :
1485 [NSString stringWithUTF8String: SSDATA (init)];
1489 if (fileDelegate == nil)
1490 fileDelegate = [EmacsFileDelegate new];
1492 [NSCursor setHiddenUntilMouseMoves: NO];
1494 if ([dirS characterAtIndex: 0] == '~')
1495 dirS = [dirS stringByExpandingTildeInPath];
1497 panel = NILP (mustmatch) && NILP (dir_only_p) ?
1498 (id)[EmacsSavePanel savePanel] : (id)[EmacsOpenPanel openPanel];
1500 [panel setTitle: promptS];
1502 [panel setAllowsOtherFileTypes: YES];
1503 [panel setTreatsFilePackagesAsDirectories: YES];
1504 [panel setDelegate: fileDelegate];
1507 if (! NILP (dir_only_p))
1509 [panel setCanChooseDirectories: YES];
1510 [panel setCanChooseFiles: NO];
1514 #if defined (NS_IMPL_COCOA) && \
1515 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1516 if (! NILP (mustmatch) || ! NILP (dir_only_p))
1517 [panel setAllowedFileTypes: nil];
1518 if (dirS) [panel setDirectoryURL: [NSURL fileURLWithPath: dirS]];
1519 if (initS && NILP (Ffile_directory_p (init)))
1520 [panel setNameFieldStringValue: [initS lastPathComponent]];
1522 [panel setNameFieldStringValue: @""];
1524 ret = [panel runModal];
1526 if (NILP (mustmatch) && NILP (dir_only_p))
1528 ret = [panel runModalForDirectory: dirS file: initS];
1532 [panel setCanChooseDirectories: YES];
1533 ret = [panel runModalForDirectory: dirS file: initS types: nil];
1537 ret = (ret == NSOKButton) || panelOK;
1540 fname = build_string ([[panel filename] UTF8String]);
1542 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
1545 return ret ? fname : Qnil;
1549 ns_get_defaults_value (const char *key)
1551 NSObject *obj = [[NSUserDefaults standardUserDefaults]
1552 objectForKey: [NSString stringWithUTF8String: key]];
1554 if (!obj) return NULL;
1556 return [[NSString stringWithFormat: @"%@", obj] UTF8String];
1560 DEFUN ("ns-get-resource", Fns_get_resource, Sns_get_resource, 2, 2, 0,
1561 doc: /* Return the value of the property NAME of OWNER from the defaults database.
1562 If OWNER is nil, Emacs is assumed. */)
1563 (Lisp_Object owner, Lisp_Object name)
1569 owner = build_string([ns_app_name UTF8String]);
1570 CHECK_STRING (name);
1571 /*fprintf (stderr, "ns-get-resource checking resource '%s'\n", SSDATA (name)); */
1573 value = ns_get_defaults_value (SSDATA (name));
1576 return build_string (value);
1581 DEFUN ("ns-set-resource", Fns_set_resource, Sns_set_resource, 3, 3, 0,
1582 doc: /* Set property NAME of OWNER to VALUE, from the defaults database.
1583 If OWNER is nil, Emacs is assumed.
1584 If VALUE is nil, the default is removed. */)
1585 (Lisp_Object owner, Lisp_Object name, Lisp_Object value)
1589 owner = build_string ([ns_app_name UTF8String]);
1590 CHECK_STRING (name);
1593 [[NSUserDefaults standardUserDefaults] removeObjectForKey:
1594 [NSString stringWithUTF8String: SSDATA (name)]];
1598 CHECK_STRING (value);
1599 [[NSUserDefaults standardUserDefaults] setObject:
1600 [NSString stringWithUTF8String: SSDATA (value)]
1601 forKey: [NSString stringWithUTF8String:
1609 DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
1610 Sx_server_max_request_size,
1612 doc: /* This function is a no-op. It is only present for completeness. */)
1613 (Lisp_Object display)
1616 /* This function has no real equivalent under NeXTstep. Return nil to
1622 DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
1623 doc: /* Return the vendor ID string of Nextstep display server DISPLAY.
1624 DISPLAY should be either a frame or a display name (a string).
1625 If omitted or nil, the selected frame's display is used. */)
1626 (Lisp_Object display)
1628 #ifdef NS_IMPL_GNUSTEP
1629 return build_string ("GNU");
1631 return build_string ("Apple");
1636 DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
1637 doc: /* Return the version numbers of the server of DISPLAY.
1638 The value is a list of three integers: the major and minor
1639 version numbers of the X Protocol in use, and the distributor-specific
1640 release number. See also the function `x-server-vendor'.
1642 The optional argument DISPLAY specifies which display to ask about.
1643 DISPLAY should be either a frame or a display name (a string).
1644 If omitted or nil, that stands for the selected frame's display. */)
1645 (Lisp_Object display)
1647 /*NOTE: it is unclear what would best correspond with "protocol";
1648 we return 10.3, meaning Panther, since this is roughly the
1649 level that GNUstep's APIs correspond to.
1650 The last number is where we distinguish between the Apple
1651 and GNUstep implementations ("distributor-specific release
1652 number") and give int'ized versions of major.minor. */
1653 return Fcons (make_number (10),
1654 Fcons (make_number (3),
1655 Fcons (make_number (ns_appkit_version_int()), Qnil)));
1659 DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
1660 doc: /* Return the number of screens on Nextstep display server DISPLAY.
1661 DISPLAY should be a frame, the display name as a string, or a terminal ID.
1662 If omitted or nil, the selected frame's display is used. */)
1663 (Lisp_Object display)
1668 num = [[NSScreen screens] count];
1670 return (num != 0) ? make_number (num) : Qnil;
1674 DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height,
1676 doc: /* Return the height of Nextstep display server DISPLAY, in millimeters.
1677 DISPLAY should be a frame, the display name as a string, or a terminal ID.
1678 If omitted or nil, the selected frame's display is used. */)
1679 (Lisp_Object display)
1682 return make_number ((int)
1683 ([ns_get_screen (display) frame].size.height/(92.0/25.4)));
1687 DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width,
1689 doc: /* Return the width of Nextstep display server DISPLAY, in millimeters.
1690 DISPLAY should be a frame, the display name as a string, or a terminal ID.
1691 If omitted or nil, the selected frame's display is used. */)
1692 (Lisp_Object display)
1695 return make_number ((int)
1696 ([ns_get_screen (display) frame].size.width/(92.0/25.4)));
1700 DEFUN ("x-display-backing-store", Fx_display_backing_store,
1701 Sx_display_backing_store, 0, 1, 0,
1702 doc: /* Return whether the Nextstep display DISPLAY supports backing store.
1703 The value may be `buffered', `retained', or `non-retained'.
1704 DISPLAY should be a frame, the display name as a string, or a terminal ID.
1705 If omitted or nil, the selected frame's display is used. */)
1706 (Lisp_Object display)
1709 switch ([ns_get_window (display) backingType])
1711 case NSBackingStoreBuffered:
1712 return intern ("buffered");
1713 case NSBackingStoreRetained:
1714 return intern ("retained");
1715 case NSBackingStoreNonretained:
1716 return intern ("non-retained");
1718 error ("Strange value for backingType parameter of frame");
1720 return Qnil; /* not reached, shut compiler up */
1724 DEFUN ("x-display-visual-class", Fx_display_visual_class,
1725 Sx_display_visual_class, 0, 1, 0,
1726 doc: /* Return the visual class of the Nextstep display server DISPLAY.
1727 The value is one of the symbols `static-gray', `gray-scale',
1728 `static-color', `pseudo-color', `true-color', or `direct-color'.
1729 DISPLAY should be a frame, the display name as a string, or a terminal ID.
1730 If omitted or nil, the selected frame's display is used. */)
1731 (Lisp_Object display)
1733 NSWindowDepth depth;
1735 depth = [ns_get_screen (display) depth];
1737 if ( depth == NSBestDepth (NSCalibratedWhiteColorSpace, 2, 2, YES, NULL))
1738 return intern ("static-gray");
1739 else if (depth == NSBestDepth (NSCalibratedWhiteColorSpace, 8, 8, YES, NULL))
1740 return intern ("gray-scale");
1741 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 8, 8, YES, NULL))
1742 return intern ("pseudo-color");
1743 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 4, 12, NO, NULL))
1744 return intern ("true-color");
1745 else if ( depth == NSBestDepth (NSCalibratedRGBColorSpace, 8, 24, NO, NULL))
1746 return intern ("direct-color");
1748 /* color mgmt as far as we do it is really handled by Nextstep itself anyway */
1749 return intern ("direct-color");
1753 DEFUN ("x-display-save-under", Fx_display_save_under,
1754 Sx_display_save_under, 0, 1, 0,
1755 doc: /* Return t if DISPLAY supports the save-under feature.
1756 The optional argument DISPLAY specifies which display to ask about.
1757 DISPLAY should be a frame, the display name as a string, or a terminal ID.
1758 If omitted or nil, the selected frame's display is used. */)
1759 (Lisp_Object display)
1762 switch ([ns_get_window (display) backingType])
1764 case NSBackingStoreBuffered:
1767 case NSBackingStoreRetained:
1768 case NSBackingStoreNonretained:
1772 error ("Strange value for backingType parameter of frame");
1774 return Qnil; /* not reached, shut compiler up */
1778 DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
1780 doc: /* Open a connection to a display server.
1781 DISPLAY is the name of the display to connect to.
1782 Optional second arg XRM-STRING is a string of resources in xrdb format.
1783 If the optional third arg MUST-SUCCEED is non-nil,
1784 terminate Emacs if we can't open the connection.
1785 \(In the Nextstep version, the last two arguments are currently ignored.) */)
1786 (Lisp_Object display, Lisp_Object resource_string, Lisp_Object must_succeed)
1788 struct ns_display_info *dpyinfo;
1790 CHECK_STRING (display);
1792 nxatoms_of_nsselect ();
1793 dpyinfo = ns_term_init (display);
1796 if (!NILP (must_succeed))
1797 fatal ("OpenStep on %s not responding.\n",
1800 error ("OpenStep on %s not responding.\n",
1808 DEFUN ("x-close-connection", Fx_close_connection, Sx_close_connection,
1810 doc: /* Close the connection to the current Nextstep display server.
1811 The argument DISPLAY is currently ignored. */)
1812 (Lisp_Object display)
1815 /*ns_delete_terminal (dpyinfo->terminal); */
1816 [NSApp terminate: NSApp];
1821 DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
1822 doc: /* Return the list of display names that Emacs has connections to. */)
1825 Lisp_Object tail, result;
1828 for (tail = ns_display_name_list; CONSP (tail); tail = XCDR (tail))
1829 result = Fcons (XCAR (XCAR (tail)), result);
1835 DEFUN ("ns-hide-others", Fns_hide_others, Sns_hide_others,
1837 doc: /* Hides all applications other than Emacs. */)
1841 [NSApp hideOtherApplications: NSApp];
1845 DEFUN ("ns-hide-emacs", Fns_hide_emacs, Sns_hide_emacs,
1847 doc: /* If ON is non-nil, the entire Emacs application is hidden.
1848 Otherwise if Emacs is hidden, it is unhidden.
1849 If ON is equal to `activate', Emacs is unhidden and becomes
1850 the active application. */)
1854 if (EQ (on, intern ("activate")))
1856 [NSApp unhide: NSApp];
1857 [NSApp activateIgnoringOtherApps: YES];
1860 [NSApp unhide: NSApp];
1862 [NSApp hide: NSApp];
1867 DEFUN ("ns-emacs-info-panel", Fns_emacs_info_panel, Sns_emacs_info_panel,
1869 doc: /* Shows the 'Info' or 'About' panel for Emacs. */)
1873 [NSApp orderFrontStandardAboutPanel: nil];
1878 DEFUN ("ns-font-name", Fns_font_name, Sns_font_name, 1, 1, 0,
1879 doc: /* Determine font PostScript or family name for font NAME.
1880 NAME should be a string containing either the font name or an XLFD
1881 font descriptor. If string contains `fontset' and not
1882 `fontset-startup', it is left alone. */)
1886 CHECK_STRING (name);
1891 if (strstr (nm, "fontset") && !strstr (nm, "fontset-startup"))
1894 return build_string (ns_xlfd_to_fontname (SSDATA (name)));
1898 DEFUN ("ns-list-colors", Fns_list_colors, Sns_list_colors, 0, 1, 0,
1899 doc: /* Return a list of all available colors.
1900 The optional argument FRAME is currently ignored. */)
1903 Lisp_Object list = Qnil;
1904 NSEnumerator *colorlists;
1909 CHECK_FRAME (frame);
1910 if (! FRAME_NS_P (XFRAME (frame)))
1911 error ("non-Nextstep frame used in `ns-list-colors'");
1916 colorlists = [[NSColorList availableColorLists] objectEnumerator];
1917 while ((clist = [colorlists nextObject]))
1919 if ([[clist name] length] < 7 ||
1920 [[clist name] rangeOfString: @"PANTONE"].location == 0)
1922 NSEnumerator *cnames = [[clist allKeys] reverseObjectEnumerator];
1924 while ((cname = [cnames nextObject]))
1925 list = Fcons (build_string ([cname UTF8String]), list);
1926 /* for (i = [[clist allKeys] count] - 1; i >= 0; i--)
1927 list = Fcons (build_string ([[[clist allKeys] objectAtIndex: i]
1928 UTF8String]), list); */
1938 DEFUN ("ns-list-services", Fns_list_services, Sns_list_services, 0, 0, 0,
1939 doc: /* List available Nextstep services by querying NSApp. */)
1942 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1943 /* You can't get services like this in 10.6+. */
1946 Lisp_Object ret = Qnil;
1951 svcs = [[NSMenu alloc] initWithTitle: @"Services"];
1952 [NSApp setServicesMenu: svcs];
1953 [NSApp registerServicesMenuSendTypes: ns_send_types
1954 returnTypes: ns_return_types];
1956 /* On Tiger, services menu updating was made lazier (waits for user to
1957 actually click on the menu), so we have to force things along: */
1958 #ifdef NS_IMPL_COCOA
1959 delegate = [svcs delegate];
1960 if (delegate != nil)
1962 if ([delegate respondsToSelector: @selector (menuNeedsUpdate:)])
1963 [delegate menuNeedsUpdate: svcs];
1964 if ([delegate respondsToSelector:
1965 @selector (menu:updateItem:atIndex:shouldCancel:)])
1967 int i, len = [delegate numberOfItemsInMenu: svcs];
1968 for (i =0; i<len; i++)
1969 [svcs addItemWithTitle: @"" action: NULL keyEquivalent: @""];
1970 for (i =0; i<len; i++)
1971 if (![delegate menu: svcs
1972 updateItem: (NSMenuItem *)[svcs itemAtIndex: i]
1973 atIndex: i shouldCancel: NO])
1979 [svcs setAutoenablesItems: NO];
1980 #ifdef NS_IMPL_COCOA
1981 [svcs update]; /* on OS X, converts from '/' structure */
1984 ret = interpret_services_menu (svcs, Qnil, ret);
1990 DEFUN ("ns-perform-service", Fns_perform_service, Sns_perform_service,
1992 doc: /* Perform Nextstep SERVICE on SEND.
1993 SEND should be either a string or nil.
1994 The return value is the result of the service, as string, or nil if
1995 there was no result. */)
1996 (Lisp_Object service, Lisp_Object send)
2002 CHECK_STRING (service);
2005 utfStr = SSDATA (service);
2006 svcName = [NSString stringWithUTF8String: utfStr];
2008 pb =[NSPasteboard pasteboardWithUniqueName];
2009 ns_string_to_pasteboard (pb, send);
2011 if (NSPerformService (svcName, pb) == NO)
2012 Fsignal (Qquit, Fcons (build_string ("service not available"), Qnil));
2014 if ([[pb types] count] == 0)
2015 return build_string ("");
2016 return ns_string_from_pasteboard (pb);
2020 DEFUN ("ns-convert-utf8-nfd-to-nfc", Fns_convert_utf8_nfd_to_nfc,
2021 Sns_convert_utf8_nfd_to_nfc, 1, 1, 0,
2022 doc: /* Return an NFC string that matches the UTF-8 NFD string STR. */)
2025 /* TODO: If GNUstep ever implements precomposedStringWithCanonicalMapping,
2030 utfStr = [NSString stringWithUTF8String: SSDATA (str)];
2031 if (![utfStr respondsToSelector:
2032 @selector (precomposedStringWithCanonicalMapping)])
2035 ("Warning: ns-convert-utf8-nfd-to-nfc unsupported under GNUstep.\n");
2039 utfStr = [utfStr precomposedStringWithCanonicalMapping];
2040 return build_string ([utfStr UTF8String]);
2044 #ifdef NS_IMPL_COCOA
2046 /* Compile and execute the AppleScript SCRIPT and return the error
2047 status as function value. A zero is returned if compilation and
2048 execution is successful, in which case *RESULT is set to a Lisp
2049 string or a number containing the resulting script value. Otherwise,
2052 ns_do_applescript (Lisp_Object script, Lisp_Object *result)
2054 NSAppleEventDescriptor *desc;
2055 NSDictionary* errorDict;
2056 NSAppleEventDescriptor* returnDescriptor = NULL;
2058 NSAppleScript* scriptObject =
2059 [[NSAppleScript alloc] initWithSource:
2060 [NSString stringWithUTF8String: SSDATA (script)]];
2062 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
2063 [scriptObject release];
2067 if (returnDescriptor != NULL)
2069 // successful execution
2070 if (kAENullEvent != [returnDescriptor descriptorType])
2073 // script returned an AppleScript result
2074 if ((typeUnicodeText == [returnDescriptor descriptorType]) ||
2075 #if defined (NS_IMPL_COCOA)
2076 (typeUTF16ExternalRepresentation
2077 == [returnDescriptor descriptorType]) ||
2079 (typeUTF8Text == [returnDescriptor descriptorType]) ||
2080 (typeCString == [returnDescriptor descriptorType]))
2082 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2084 *result = build_string([[desc stringValue] UTF8String]);
2088 /* use typeUTF16ExternalRepresentation? */
2089 // coerce the result to the appropriate ObjC type
2090 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2092 *result = make_number([desc int32Value]);
2098 // no script result, return error
2104 /* Helper function called from sendEvent to run applescript
2105 from within the main event loop. */
2108 ns_run_ascript (void)
2110 as_status = ns_do_applescript (as_script, as_result);
2113 DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0,
2114 doc: /* Execute AppleScript SCRIPT and return the result.
2115 If compilation and execution are successful, the resulting script value
2116 is returned as a string, a number or, in the case of other constructs, t.
2117 In case the execution fails, an error is signaled. */)
2118 (Lisp_Object script)
2124 CHECK_STRING (script);
2130 as_result = &result;
2132 /* executing apple script requires the event loop to run, otherwise
2133 errors aren't returned and executeAndReturnError hangs forever.
2134 Post an event that runs applescript and then start the event loop.
2135 The event loop is exited when the script is done. */
2136 nxev = [NSEvent otherEventWithType: NSApplicationDefined
2137 location: NSMakePoint (0, 0)
2140 windowNumber: [[NSApp mainWindow] windowNumber]
2141 context: [NSApp context]
2144 data2: NSAPP_DATA2_RUNASSCRIPT];
2146 [NSApp postEvent: nxev atStart: NO];
2156 else if (!STRINGP (result))
2157 error ("AppleScript error %d", status);
2159 error ("%s", SSDATA (result));
2165 /* ==========================================================================
2167 Miscellaneous functions not called through hooks
2169 ========================================================================== */
2172 /* called from image.c */
2174 check_x_frame (Lisp_Object frame)
2176 return check_ns_frame (frame);
2180 /* called from frame.c */
2181 struct ns_display_info *
2182 check_x_display_info (Lisp_Object frame)
2184 return check_ns_display_info (frame);
2189 x_set_scroll_bar_default_width (struct frame *f)
2191 int wid = FRAME_COLUMN_WIDTH (f);
2192 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = NS_SCROLL_BAR_WIDTH_DEFAULT;
2193 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) +
2198 /* terms impl this instead of x-get-resource directly */
2200 x_get_string_resource (XrmDatabase rdb, char *name, char *class)
2202 /* remove appname prefix; TODO: allow for !="Emacs" */
2203 char *toCheck = class + (!strncmp (class, "Emacs.", 6) ? 6 : 0);
2207 if (inhibit_x_resources)
2208 /* --quick was passed, so this is a no-op. */
2211 res = ns_get_defaults_value (toCheck);
2212 return !res ? NULL :
2213 (!c_strncasecmp (res, "YES", 3) ? "true" :
2214 (!c_strncasecmp (res, "NO", 2) ? "false" : res));
2219 x_get_focus_frame (struct frame *frame)
2221 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (frame);
2222 Lisp_Object nsfocus;
2224 if (!dpyinfo->x_focus_frame)
2227 XSETFRAME (nsfocus, dpyinfo->x_focus_frame);
2233 x_pixel_width (struct frame *f)
2235 return FRAME_PIXEL_WIDTH (f);
2240 x_pixel_height (struct frame *f)
2242 return FRAME_PIXEL_HEIGHT (f);
2247 x_char_width (struct frame *f)
2249 return FRAME_COLUMN_WIDTH (f);
2254 x_char_height (struct frame *f)
2256 return FRAME_LINE_HEIGHT (f);
2261 x_screen_planes (struct frame *f)
2263 return FRAME_NS_DISPLAY_INFO (f)->n_planes;
2268 x_sync (struct frame *f)
2270 /* XXX Not implemented XXX */
2276 /* ==========================================================================
2278 Lisp definitions that, for whatever reason, we can't alias as 'ns-XXX'.
2280 ========================================================================== */
2283 DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
2284 doc: /* Internal function called by `color-defined-p', which see.
2285 \(Note that the Nextstep version of this function ignores FRAME.) */)
2286 (Lisp_Object color, Lisp_Object frame)
2290 return ns_lisp_to_color (color, &col) ? Qnil : Qt;
2294 DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
2295 doc: /* Internal function called by `color-values', which see. */)
2296 (Lisp_Object color, Lisp_Object frame)
2299 CGFloat red, green, blue, alpha;
2302 CHECK_STRING (color);
2304 if (ns_lisp_to_color (color, &col))
2307 [[col colorUsingColorSpaceName: NSCalibratedRGBColorSpace]
2308 getRed: &red green: &green blue: &blue alpha: &alpha];
2309 return list3 (make_number (lrint (red*65280)),
2310 make_number (lrint (green*65280)),
2311 make_number (lrint (blue*65280)));
2315 DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
2316 doc: /* Internal function called by `display-color-p', which see. */)
2317 (Lisp_Object display)
2319 NSWindowDepth depth;
2320 NSString *colorSpace;
2322 depth = [ns_get_screen (display) depth];
2323 colorSpace = NSColorSpaceFromDepth (depth);
2325 return [colorSpace isEqualToString: NSDeviceWhiteColorSpace]
2326 || [colorSpace isEqualToString: NSCalibratedWhiteColorSpace]
2331 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p,
2332 Sx_display_grayscale_p, 0, 1, 0,
2333 doc: /* Return t if the Nextstep display supports shades of gray.
2334 Note that color displays do support shades of gray.
2335 The optional argument DISPLAY specifies which display to ask about.
2336 DISPLAY should be either a frame, a display name (a string), or terminal ID.
2337 If omitted or nil, that stands for the selected frame's display. */)
2338 (Lisp_Object display)
2340 NSWindowDepth depth;
2342 depth = [ns_get_screen (display) depth];
2344 return NSBitsPerPixelFromDepth (depth) > 1 ? Qt : Qnil;
2348 DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
2350 doc: /* Return the width in pixels of the Nextstep display DISPLAY.
2351 The optional argument DISPLAY specifies which display to ask about.
2352 DISPLAY should be either a frame, a display name (a string), or terminal ID.
2353 If omitted or nil, that stands for the selected frame's display. */)
2354 (Lisp_Object display)
2357 return make_number ((int) [ns_get_screen (display) frame].size.width);
2361 DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
2362 Sx_display_pixel_height, 0, 1, 0,
2363 doc: /* Return the height in pixels of the Nextstep display DISPLAY.
2364 The optional argument DISPLAY specifies which display to ask about.
2365 DISPLAY should be either a frame, a display name (a string), or terminal ID.
2366 If omitted or nil, that stands for the selected frame's display. */)
2367 (Lisp_Object display)
2370 return make_number ((int) [ns_get_screen (display) frame].size.height);
2374 DEFUN ("display-usable-bounds", Fns_display_usable_bounds,
2375 Sns_display_usable_bounds, 0, 1, 0,
2376 doc: /* Return the bounds of the usable part of the screen.
2377 The return value is a list of integers (LEFT TOP WIDTH HEIGHT), which
2378 are the boundaries of the usable part of the screen, excluding areas
2379 reserved for the Mac menu, dock, and so forth.
2381 The screen queried corresponds to DISPLAY, which should be either a
2382 frame, a display name (a string), or terminal ID. If omitted or nil,
2383 that stands for the selected frame's display. */)
2384 (Lisp_Object display)
2390 screen = ns_get_screen (display);
2394 vScreen = [screen visibleFrame];
2396 /* NS coordinate system is upside-down.
2397 Transform to screen-specific coordinates. */
2398 return list4 (make_number ((int) vScreen.origin.x),
2399 make_number ((int) [screen frame].size.height
2400 - vScreen.size.height - vScreen.origin.y),
2401 make_number ((int) vScreen.size.width),
2402 make_number ((int) vScreen.size.height));
2406 DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
2408 doc: /* Return the number of bitplanes of the Nextstep display DISPLAY.
2409 The optional argument DISPLAY specifies which display to ask about.
2410 DISPLAY should be either a frame, a display name (a string), or terminal ID.
2411 If omitted or nil, that stands for the selected frame's display. */)
2412 (Lisp_Object display)
2416 (NSBitsPerPixelFromDepth ([ns_get_screen (display) depth]));
2420 DEFUN ("x-display-color-cells", Fx_display_color_cells,
2421 Sx_display_color_cells, 0, 1, 0,
2422 doc: /* Returns the number of color cells of the Nextstep display DISPLAY.
2423 The optional argument DISPLAY specifies which display to ask about.
2424 DISPLAY should be either a frame, a display name (a string), or terminal ID.
2425 If omitted or nil, that stands for the selected frame's display. */)
2426 (Lisp_Object display)
2428 struct ns_display_info *dpyinfo;
2431 dpyinfo = check_ns_display_info (display);
2432 /* We force 24+ bit depths to 24-bit to prevent an overflow. */
2433 return make_number (1 << min (dpyinfo->n_planes, 24));
2437 /* Unused dummy def needed for compatibility. */
2438 Lisp_Object tip_frame;
2440 /* TODO: move to xdisp or similar */
2442 compute_tip_xy (struct frame *f,
2451 Lisp_Object left, top;
2452 EmacsView *view = FRAME_NS_VIEW (f);
2455 /* Start with user-specified or mouse position. */
2456 left = Fcdr (Fassq (Qleft, parms));
2457 top = Fcdr (Fassq (Qtop, parms));
2459 if (!INTEGERP (left) || !INTEGERP (top))
2461 pt = last_mouse_motion_position;
2462 /* Convert to screen coordinates */
2463 pt = [view convertPoint: pt toView: nil];
2464 pt = [[view window] convertBaseToScreen: pt];
2468 /* Absolute coordinates. */
2470 pt.y = x_display_pixel_height (FRAME_NS_DISPLAY_INFO (f)) - XINT (top)
2474 /* Ensure in bounds. (Note, screen origin = lower left.) */
2475 if (INTEGERP (left))
2477 else if (pt.x + XINT (dx) <= 0)
2478 *root_x = 0; /* Can happen for negative dx */
2479 else if (pt.x + XINT (dx) + width
2480 <= x_display_pixel_width (FRAME_NS_DISPLAY_INFO (f)))
2481 /* It fits to the right of the pointer. */
2482 *root_x = pt.x + XINT (dx);
2483 else if (width + XINT (dx) <= pt.x)
2484 /* It fits to the left of the pointer. */
2485 *root_x = pt.x - width - XINT (dx);
2487 /* Put it left justified on the screen -- it ought to fit that way. */
2492 else if (pt.y - XINT (dy) - height >= 0)
2493 /* It fits below the pointer. */
2494 *root_y = pt.y - height - XINT (dy);
2495 else if (pt.y + XINT (dy) + height
2496 <= x_display_pixel_height (FRAME_NS_DISPLAY_INFO (f)))
2497 /* It fits above the pointer */
2498 *root_y = pt.y + XINT (dy);
2500 /* Put it on the top. */
2501 *root_y = x_display_pixel_height (FRAME_NS_DISPLAY_INFO (f)) - height;
2505 DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
2506 doc: /* Show STRING in a \"tooltip\" window on frame FRAME.
2507 A tooltip window is a small window displaying a string.
2509 This is an internal function; Lisp code should call `tooltip-show'.
2511 FRAME nil or omitted means use the selected frame.
2513 PARMS is an optional list of frame parameters which can be used to
2514 change the tooltip's appearance.
2516 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
2517 means use the default timeout of 5 seconds.
2519 If the list of frame parameters PARMS contains a `left' parameter,
2520 the tooltip is displayed at that x-position. Otherwise it is
2521 displayed at the mouse position, with offset DX added (default is 5 if
2522 DX isn't specified). Likewise for the y-position; if a `top' frame
2523 parameter is specified, it determines the y-position of the tooltip
2524 window, otherwise it is displayed at the mouse position, with offset
2525 DY added (default is -10).
2527 A tooltip's maximum size is specified by `x-max-tooltip-size'.
2528 Text larger than the specified size is clipped. */)
2529 (Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy)
2532 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
2533 ptrdiff_t count = SPECPDL_INDEX ();
2538 specbind (Qinhibit_redisplay, Qt);
2540 GCPRO4 (string, parms, frame, timeout);
2542 CHECK_STRING (string);
2543 str = SSDATA (string);
2544 f = check_x_frame (frame);
2546 timeout = make_number (5);
2548 CHECK_NATNUM (timeout);
2551 dx = make_number (5);
2556 dy = make_number (-10);
2561 if (ns_tooltip == nil)
2562 ns_tooltip = [[EmacsTooltip alloc] init];
2566 [ns_tooltip setText: str];
2567 size = [ns_tooltip frame].size;
2569 /* Move the tooltip window where the mouse pointer is. Resize and
2571 compute_tip_xy (f, parms, dx, dy, (int)size.width, (int)size.height,
2574 [ns_tooltip showAtX: root_x Y: root_y for: XINT (timeout)];
2578 return unbind_to (count, Qnil);
2582 DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
2583 doc: /* Hide the current tooltip window, if there is any.
2584 Value is t if tooltip was open, nil otherwise. */)
2587 if (ns_tooltip == nil || ![ns_tooltip isActive])
2594 /* ==========================================================================
2596 Class implementations
2598 ========================================================================== */
2601 @implementation EmacsSavePanel
2602 #ifdef NS_IMPL_COCOA
2603 /* --------------------------------------------------------------------------
2604 These are overridden to intercept on OS X: ending panel restarts NSApp
2605 event loop if it is stopped. Not sure if this is correct behavior,
2606 perhaps should check if running and if so send an appdefined.
2607 -------------------------------------------------------------------------- */
2608 - (void) ok: (id)sender
2614 - (void) cancel: (id)sender
2616 [super cancel: sender];
2623 @implementation EmacsOpenPanel
2624 #ifdef NS_IMPL_COCOA
2625 /* --------------------------------------------------------------------------
2626 These are overridden to intercept on OS X: ending panel restarts NSApp
2627 event loop if it is stopped. Not sure if this is correct behavior,
2628 perhaps should check if running and if so send an appdefined.
2629 -------------------------------------------------------------------------- */
2630 - (void) ok: (id)sender
2636 - (void) cancel: (id)sender
2638 [super cancel: sender];
2645 @implementation EmacsFileDelegate
2646 /* --------------------------------------------------------------------------
2647 Delegate methods for Open/Save panels
2648 -------------------------------------------------------------------------- */
2649 - (BOOL)panel: (id)sender isValidFilename: (NSString *)filename
2653 - (BOOL)panel: (id)sender shouldShowFilename: (NSString *)filename
2657 - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
2658 confirmed: (BOOL)okFlag
2667 /* ==========================================================================
2669 Lisp interface declaration
2671 ========================================================================== */
2675 syms_of_nsfns (void)
2677 Qfontsize = intern_c_string ("fontsize");
2678 staticpro (&Qfontsize);
2680 DEFVAR_LISP ("ns-icon-type-alist", Vns_icon_type_alist,
2681 doc: /* Alist of elements (REGEXP . IMAGE) for images of icons associated to frames.
2682 If the title of a frame matches REGEXP, then IMAGE.tiff is
2683 selected as the image of the icon representing the frame when it's
2684 miniaturized. If an element is t, then Emacs tries to select an icon
2685 based on the filetype of the visited file.
2687 The images have to be installed in a folder called English.lproj in the
2688 Emacs folder. You have to restart Emacs after installing new icons.
2690 Example: Install an icon Gnus.tiff and execute the following code
2692 (setq ns-icon-type-alist
2693 (append ns-icon-type-alist
2694 '((\"^\\\\*\\\\(Group\\\\*$\\\\|Summary \\\\|Article\\\\*$\\\\)\"
2697 When you miniaturize a Group, Summary or Article frame, Gnus.tiff will
2698 be used as the image of the icon representing the frame. */);
2699 Vns_icon_type_alist = Fcons (Qt, Qnil);
2701 DEFVAR_LISP ("ns-version-string", Vns_version_string,
2702 doc: /* Toolkit version for NS Windowing. */);
2703 Vns_version_string = ns_appkit_version_str ();
2705 defsubr (&Sns_read_file_name);
2706 defsubr (&Sns_get_resource);
2707 defsubr (&Sns_set_resource);
2708 defsubr (&Sxw_display_color_p); /* this and next called directly by C code */
2709 defsubr (&Sx_display_grayscale_p);
2710 defsubr (&Sns_font_name);
2711 defsubr (&Sns_list_colors);
2712 #ifdef NS_IMPL_COCOA
2713 defsubr (&Sns_do_applescript);
2715 defsubr (&Sxw_color_defined_p);
2716 defsubr (&Sxw_color_values);
2717 defsubr (&Sx_server_max_request_size);
2718 defsubr (&Sx_server_vendor);
2719 defsubr (&Sx_server_version);
2720 defsubr (&Sx_display_pixel_width);
2721 defsubr (&Sx_display_pixel_height);
2722 defsubr (&Sns_display_usable_bounds);
2723 defsubr (&Sx_display_mm_width);
2724 defsubr (&Sx_display_mm_height);
2725 defsubr (&Sx_display_screens);
2726 defsubr (&Sx_display_planes);
2727 defsubr (&Sx_display_color_cells);
2728 defsubr (&Sx_display_visual_class);
2729 defsubr (&Sx_display_backing_store);
2730 defsubr (&Sx_display_save_under);
2731 defsubr (&Sx_create_frame);
2732 defsubr (&Sx_open_connection);
2733 defsubr (&Sx_close_connection);
2734 defsubr (&Sx_display_list);
2736 defsubr (&Sns_hide_others);
2737 defsubr (&Sns_hide_emacs);
2738 defsubr (&Sns_emacs_info_panel);
2739 defsubr (&Sns_list_services);
2740 defsubr (&Sns_perform_service);
2741 defsubr (&Sns_convert_utf8_nfd_to_nfc);
2742 defsubr (&Sx_focus_frame);
2743 defsubr (&Sns_popup_font_panel);
2744 defsubr (&Sns_popup_color_panel);
2746 defsubr (&Sx_show_tip);
2747 defsubr (&Sx_hide_tip);
2749 /* used only in fontset.c */
2750 check_window_system_func = check_ns;