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 #include
<IOKit
/graphics
/IOGraphicsLib.h
>
49 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_5
55 int fns_trace_num
= 1;
56 #define NSTRACE
(x
) fprintf (stderr
, "
%s:%d: [%d] " #x "\n", \
57 __FILE__
, __LINE__
, ++fns_trace_num
)
64 extern NSArray
*ns_send_types
, *ns_return_types
, *ns_drag_types
;
66 extern Lisp_Object Qforeground_color
;
67 extern Lisp_Object Qbackground_color
;
68 extern Lisp_Object Qcursor_color
;
69 extern Lisp_Object Qinternal_border_width
;
70 extern Lisp_Object Qvisibility
;
71 extern Lisp_Object Qcursor_type
;
72 extern Lisp_Object Qicon_type
;
73 extern Lisp_Object Qicon_name
;
74 extern Lisp_Object Qicon_left
;
75 extern Lisp_Object Qicon_top
;
76 extern Lisp_Object Qleft
;
77 extern Lisp_Object Qright
;
78 extern Lisp_Object Qtop
;
79 extern Lisp_Object Qdisplay
;
80 extern Lisp_Object Qvertical_scroll_bars
;
81 extern Lisp_Object Qauto_raise
;
82 extern Lisp_Object Qauto_lower
;
83 extern Lisp_Object Qbox
;
84 extern Lisp_Object Qscroll_bar_width
;
85 extern Lisp_Object Qx_resource_name
;
86 extern Lisp_Object Qface_set_after_frame_default
;
87 extern Lisp_Object Qunderline
, Qundefined
;
88 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
89 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
, Qbuffer_predicate
, Qtitle
;
92 Lisp_Object Qbuffered
;
93 Lisp_Object Qfontsize
;
95 EmacsTooltip
*ns_tooltip
= nil
;
97 /* Need forward declaration here to preserve organizational integrity of file */
98 Lisp_Object Fx_open_connection
(Lisp_Object
, Lisp_Object
, Lisp_Object
);
100 /* Static variables to handle applescript execution. */
101 static Lisp_Object as_script
, *as_result
;
102 static int as_status
;
105 static ptrdiff_t image_cache_refcount
;
109 /* ==========================================================================
111 Internal utility functions
113 ========================================================================== */
115 /* Let the user specify a Nextstep display with a Lisp object.
116 OBJECT may be nil, a frame or a terminal object.
117 nil stands for the selected frame--or, if that is not a Nextstep frame,
118 the first Nextstep display on the list. */
120 static
struct ns_display_info
*
121 check_ns_display_info
(Lisp_Object object
)
123 struct ns_display_info
*dpyinfo
= NULL;
127 struct frame
*sf
= XFRAME
(selected_frame
);
129 if (FRAME_NS_P
(sf
) && FRAME_LIVE_P
(sf
))
130 dpyinfo
= FRAME_DISPLAY_INFO
(sf
);
131 else if (x_display_list
!= 0)
132 dpyinfo
= x_display_list
;
134 error ("Nextstep windows are not in use or not initialized"
);
136 else if (TERMINALP
(object
))
138 struct terminal *t
= get_terminal
(object
, 1);
140 if (t
->type != output_ns
)
141 error ("
Terminal %d is not a Nextstep display", t->id);
143 dpyinfo
= t
->display_info.ns
;
145 else if (STRINGP
(object
))
146 dpyinfo
= ns_display_info_for_name
(object
);
149 struct frame
*f
= decode_window_system_frame
(object
);
150 dpyinfo
= FRAME_DISPLAY_INFO
(f
);
158 ns_get_window
(Lisp_Object maybeFrame
)
160 id
view =nil
, window
=nil
;
162 if (!FRAMEP
(maybeFrame
) ||
!FRAME_NS_P
(XFRAME
(maybeFrame
)))
163 maybeFrame
= selected_frame
;/*wrong_type_argument (Qframep, maybeFrame); */
165 if (!NILP
(maybeFrame
))
166 view = FRAME_NS_VIEW
(XFRAME
(maybeFrame
));
167 if (view) window
=[view window
];
173 /* Return the X display structure for the display named NAME.
174 Open a new connection if necessary. */
175 struct ns_display_info
*
176 ns_display_info_for_name
(Lisp_Object name
)
179 struct ns_display_info
*dpyinfo
;
183 for (dpyinfo
= x_display_list
, names
= ns_display_name_list
;
185 dpyinfo
= dpyinfo
->next
, names
= XCDR
(names
))
188 tem
= Fstring_equal
(XCAR
(XCAR
(names
)), name
);
193 error ("Emacs
for OpenStep does not yet support multi
-display."
);
195 Fx_open_connection
(name
, Qnil
, Qnil
);
196 dpyinfo
= x_display_list
;
199 error ("OpenStep on
%s not responding.\n", SDATA (name));
205 ns_filename_from_panel
(NSSavePanel
*panel
)
207 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
208 NSURL
*url
= [panel URL
];
209 NSString
*str
= [url
path];
212 return [panel filename
];
217 ns_directory_from_panel
(NSSavePanel
*panel
)
219 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
220 NSURL
*url
= [panel directoryURL
];
221 NSString
*str
= [url
path];
224 return [panel directory
];
229 interpret_services_menu
(NSMenu
*menu, Lisp_Object prefix
, Lisp_Object old
)
230 /* --------------------------------------------------------------------------
231 Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
232 -------------------------------------------------------------------------- */
242 count
= [menu numberOfItems
];
243 for (i
= 0; i
<count
; i
++)
245 item
= [menu itemAtIndex
: i
];
246 name
= [[item
title] UTF8String
];
249 nameStr
= build_string
(name
);
251 if ([item hasSubmenu
])
253 old
= interpret_services_menu
([item submenu
],
254 Fcons
(nameStr
, prefix
), old
);
258 keys
= [item keyEquivalent
];
259 if (keys
&& [keys
length] )
261 key
= [keys characterAtIndex
: 0];
262 res
= make_number
(key|super_modifier
);
268 old
= Fcons
(Fcons
(res
,
269 Freverse
(Fcons
(nameStr
,
279 /* ==========================================================================
281 Frame parameter setters
283 ========================================================================== */
287 x_set_foreground_color
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
290 EmacsCGFloat r
, g
, b
, alpha
;
292 if (ns_lisp_to_color
(arg
, &col
))
294 store_frame_param
(f
, Qforeground_color
, oldval
);
295 error ("Unknown color"
);
299 [f
->output_data.ns
->foreground_color release
];
300 f
->output_data.ns
->foreground_color
= col
;
302 [col getRed
: &r green
: &g blue
: &b alpha
: &alpha
];
303 FRAME_FOREGROUND_PIXEL
(f
) =
304 ARGB_TO_ULONG
((int
)(alpha
*0xff), (int
)(r
*0xff), (int
)(g
*0xff), (int
)(b
*0xff));
306 if (FRAME_NS_VIEW
(f
))
308 update_face_from_frame_parameter
(f
, Qforeground_color
, arg
);
309 /*recompute_basic_faces (f); */
310 if (FRAME_VISIBLE_P
(f
))
317 x_set_background_color
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
321 NSView
*view = FRAME_NS_VIEW
(f
);
322 EmacsCGFloat r
, g
, b
, alpha
;
324 if (ns_lisp_to_color
(arg
, &col
))
326 store_frame_param
(f
, Qbackground_color
, oldval
);
327 error ("Unknown color"
);
330 /* clear the frame; in some instances the NS-internal GC appears not to
331 update, or it does update and cannot clear old text properly */
332 if (FRAME_VISIBLE_P
(f
))
336 [f
->output_data.ns
->background_color release
];
337 f
->output_data.ns
->background_color
= col
;
339 [col getRed
: &r green
: &g blue
: &b alpha
: &alpha
];
340 FRAME_BACKGROUND_PIXEL
(f
) =
341 ARGB_TO_ULONG
((int
)(alpha
*0xff), (int
)(r
*0xff), (int
)(g
*0xff), (int
)(b
*0xff));
345 [[view window
] setBackgroundColor
: col
];
347 if (alpha
!= (EmacsCGFloat
) 1.0)
348 [[view window
] setOpaque
: NO
];
350 [[view window
] setOpaque
: YES
];
352 face
= FRAME_DEFAULT_FACE
(f
);
355 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
);
356 face
->background
= ns_index_color
357 ([col colorWithAlphaComponent
: alpha
], f
);
359 update_face_from_frame_parameter
(f
, Qbackground_color
, arg
);
362 if (FRAME_VISIBLE_P
(f
))
369 x_set_cursor_color
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
373 if (ns_lisp_to_color
(arg
, &col
))
375 store_frame_param
(f
, Qcursor_color
, oldval
);
376 error ("Unknown color"
);
379 [FRAME_CURSOR_COLOR
(f
) release
];
380 FRAME_CURSOR_COLOR
(f
) = [col retain
];
382 if (FRAME_VISIBLE_P
(f
))
384 x_update_cursor
(f
, 0);
385 x_update_cursor
(f
, 1);
387 update_face_from_frame_parameter
(f
, Qcursor_color
, arg
);
392 x_set_icon_name
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
394 NSView
*view = FRAME_NS_VIEW
(f
);
395 NSTRACE
(x_set_icon_name
);
397 /* see if it's changed */
400 if (STRINGP
(oldval
) && EQ
(Fstring_equal
(oldval
, arg
), Qt
))
403 else if (!STRINGP
(oldval
) && EQ
(oldval
, Qnil
) == EQ
(arg
, Qnil
))
406 fset_icon_name
(f
, arg
);
410 if (!NILP
(f
->title))
413 /* explicit name and no icon-name -> explicit_name */
414 if (f
->explicit_name
)
418 /* no explicit name and no icon-name ->
419 name has to be rebuild from icon_title_format */
420 windows_or_buffers_changed
++;
425 /* Don't change the name if it's already NAME. */
426 if ([[view window
] miniwindowTitle
] &&
427 ([[[view window
] miniwindowTitle
]
428 isEqualToString
: [NSString stringWithUTF8String
:
432 [[view window
] setMiniwindowTitle
:
433 [NSString stringWithUTF8String
: SSDATA
(arg
)]];
437 ns_set_name_internal
(struct frame
*f
, Lisp_Object name
)
440 Lisp_Object encoded_name
, encoded_icon_name
;
442 NSView
*view = FRAME_NS_VIEW
(f
);
445 encoded_name
= ENCODE_UTF_8
(name
);
448 str
= [NSString stringWithUTF8String
: SSDATA
(encoded_name
)];
450 /* Don't change the name if it's already NAME. */
451 if (! [[[view window
] title] isEqualToString
: str
])
452 [[view window
] setTitle
: str
];
454 if (!STRINGP
(f
->icon_name
))
455 encoded_icon_name
= encoded_name
;
457 encoded_icon_name
= ENCODE_UTF_8
(f
->icon_name
);
459 str
= [NSString stringWithUTF8String
: SSDATA
(encoded_icon_name
)];
461 if ([[view window
] miniwindowTitle
] &&
462 ! [[[view window
] miniwindowTitle
] isEqualToString
: str
])
463 [[view window
] setMiniwindowTitle
: str
];
468 ns_set_name
(struct frame
*f
, Lisp_Object name
, int explicit
)
470 NSTRACE
(ns_set_name
);
472 /* Make sure that requests from lisp code override requests from
473 Emacs redisplay code. */
476 /* If we're switching from explicit to implicit, we had better
477 update the mode lines and thereby update the title. */
478 if (f
->explicit_name
&& NILP
(name
))
479 update_mode_lines
= 1;
481 f
->explicit_name
= ! NILP
(name
);
483 else if (f
->explicit_name
)
487 name
= build_string
([ns_app_name UTF8String
]);
491 /* Don't change the name if it's already NAME. */
492 if (! NILP
(Fstring_equal
(name
, f
->name
)))
497 /* title overrides explicit name */
498 if (! NILP
(f
->title))
501 ns_set_name_internal
(f
, name
);
505 /* This function should be called when the user's lisp code has
506 specified a name for the frame; the name will override any set by the
509 x_explicitly_set_name
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
511 NSTRACE
(x_explicitly_set_name
);
512 ns_set_name
(f
, arg
, 1);
516 /* This function should be called by Emacs redisplay code to set the
517 name; names set this way will never override names set by the user's
520 x_implicitly_set_name
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
522 NSTRACE
(x_implicitly_set_name
);
524 /* Deal with NS specific format t. */
525 if (FRAME_NS_P
(f
) && ((FRAME_ICONIFIED_P
(f
) && EQ
(Vicon_title_format
, Qt
))
526 || EQ
(Vframe_title_format
, Qt
)))
527 ns_set_name_as_filename
(f
);
529 ns_set_name
(f
, arg
, 0);
533 /* Change the title of frame F to NAME.
534 If NAME is nil, use the frame name as the title. */
537 x_set_title
(struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
539 NSTRACE
(x_set_title
);
540 /* Don't change the title if it's already NAME. */
541 if (EQ
(name
, f
->title))
544 update_mode_lines
= 1;
546 fset_title
(f
, name
);
553 ns_set_name_internal
(f
, name
);
558 ns_set_name_as_filename
(struct frame
*f
)
561 Lisp_Object name
, filename
;
562 Lisp_Object buf
= XWINDOW
(f
->selected_window
)->contents
;
564 NSAutoreleasePool
*pool
;
566 Lisp_Object encoded_name
, encoded_filename
;
568 NSTRACE
(ns_set_name_as_filename
);
570 if (f
->explicit_name ||
! NILP
(f
->title))
574 pool
= [[NSAutoreleasePool alloc
] init
];
575 filename
= BVAR
(XBUFFER
(buf
), filename
);
576 name
= BVAR
(XBUFFER
(buf
), name
);
580 if (! NILP
(filename
))
581 name
= Ffile_name_nondirectory
(filename
);
583 name
= build_string
([ns_app_name UTF8String
]);
587 encoded_name
= ENCODE_UTF_8
(name
);
590 view = FRAME_NS_VIEW
(f
);
592 title = FRAME_ICONIFIED_P
(f
) ?
[[[view window
] miniwindowTitle
] UTF8String
]
593 : [[[view window
] title] UTF8String
];
595 if (title && (! strcmp (title, SSDATA
(encoded_name
))))
602 str
= [NSString stringWithUTF8String
: SSDATA
(encoded_name
)];
603 if (str
== nil
) str
= @"Bad coding"
;
605 if (FRAME_ICONIFIED_P
(f
))
606 [[view window
] setMiniwindowTitle
: str
];
611 if (! NILP
(filename
))
614 encoded_filename
= ENCODE_UTF_8
(filename
);
617 fstr
= [NSString stringWithUTF8String
: SSDATA
(encoded_filename
)];
618 if (fstr
== nil
) fstr
= @""
;
620 /* work around a bug observed on 10.3 and later where
621 setTitleWithRepresentedFilename does not clear out previous state
622 if given filename does not exist */
623 if (! [[NSFileManager defaultManager
] fileExistsAtPath
: fstr
])
624 [[view window
] setRepresentedFilename
: @""
];
630 [[view window
] setRepresentedFilename
: fstr
];
631 [[view window
] setTitle
: str
];
641 ns_set_doc_edited
(struct frame
*f
, Lisp_Object arg
)
643 NSView
*view = FRAME_NS_VIEW
(f
);
644 NSAutoreleasePool
*pool
;
645 if (!MINI_WINDOW_P
(XWINDOW
(f
->selected_window
)))
648 pool
= [[NSAutoreleasePool alloc
] init
];
649 [[view window
] setDocumentEdited
: !NILP
(arg
)];
657 x_set_menu_bar_lines
(struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
660 if (FRAME_MINIBUF_ONLY_P
(f
))
663 if (TYPE_RANGED_INTEGERP
(int
, value
))
664 nlines
= XINT
(value
);
668 FRAME_MENU_BAR_LINES
(f
) = 0;
671 FRAME_EXTERNAL_MENU_BAR
(f
) = 1;
672 /* does for all frames, whereas we just want for one frame
673 [NSMenu setMenuBarVisible: YES]; */
677 if (FRAME_EXTERNAL_MENU_BAR
(f
) == 1)
678 free_frame_menubar
(f
);
679 /* [NSMenu setMenuBarVisible: NO]; */
680 FRAME_EXTERNAL_MENU_BAR
(f
) = 0;
685 /* toolbar support */
687 x_set_tool_bar_lines
(struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
691 if (FRAME_MINIBUF_ONLY_P
(f
))
694 if (RANGED_INTEGERP
(0, value
, INT_MAX
))
695 nlines
= XFASTINT
(value
);
701 FRAME_EXTERNAL_TOOL_BAR
(f
) = 1;
702 update_frame_tool_bar
(f
);
706 if (FRAME_EXTERNAL_TOOL_BAR
(f
))
708 free_frame_tool_bar
(f
);
709 FRAME_EXTERNAL_TOOL_BAR
(f
) = 0;
713 x_set_window_size
(f
, 0, f
->text_cols
, f
->text_lines
);
718 ns_implicitly_set_icon_type
(struct frame
*f
)
721 EmacsView
*view = FRAME_NS_VIEW
(f
);
723 Lisp_Object chain
, elt
;
724 NSAutoreleasePool
*pool
;
727 NSTRACE
(ns_implicitly_set_icon_type
);
730 pool
= [[NSAutoreleasePool alloc
] init
];
731 if (f
->output_data.ns
->miniimage
732 && [[NSString stringWithUTF8String
: SSDATA
(f
->name
)]
733 isEqualToString
: [(NSImage
*)f
->output_data.ns
->miniimage name
]])
740 tem
= assq_no_quit
(Qicon_type
, f
->param_alist
);
741 if (CONSP
(tem
) && ! NILP
(XCDR
(tem
)))
748 for (chain
= Vns_icon_type_alist
;
749 image == nil
&& CONSP
(chain
);
750 chain
= XCDR
(chain
))
753 /* special case: 't' means go by file type */
754 if (SYMBOLP
(elt
) && EQ
(elt
, Qt
) && SSDATA
(f
->name
)[0] == '/')
757 = [NSString stringWithUTF8String
: SSDATA
(f
->name
)];
758 if ([[NSFileManager defaultManager
] fileExistsAtPath
: str
])
759 image = [[[NSWorkspace sharedWorkspace
] iconForFile
: str
] retain
];
761 else if (CONSP
(elt
) &&
762 STRINGP
(XCAR
(elt
)) &&
763 STRINGP
(XCDR
(elt
)) &&
764 fast_string_match
(XCAR
(elt
), f
->name
) >= 0)
766 image = [EmacsImage allocInitFromFile
: XCDR
(elt
)];
768 image = [[NSImage imageNamed
:
769 [NSString stringWithUTF8String
:
770 SSDATA
(XCDR
(elt
))]] retain
];
776 image = [[[NSWorkspace sharedWorkspace
] iconForFileType
: @"
text"
] retain
];
780 [f
->output_data.ns
->miniimage release
];
781 f
->output_data.ns
->miniimage
= image;
782 [view setMiniwindowImage
: setMini
];
789 x_set_icon_type
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
791 EmacsView
*view = FRAME_NS_VIEW
(f
);
795 NSTRACE
(x_set_icon_type
);
797 if (!NILP
(arg
) && SYMBOLP
(arg
))
799 arg
=build_string
(SSDATA
(SYMBOL_NAME
(arg
)));
800 store_frame_param
(f
, Qicon_type
, arg
);
803 /* do it the implicit way */
806 ns_implicitly_set_icon_type
(f
);
812 image = [EmacsImage allocInitFromFile
: arg
];
814 image =[NSImage imageNamed
: [NSString stringWithUTF8String
:
819 image = [NSImage imageNamed
: @"
text"
];
823 f
->output_data.ns
->miniimage
= image;
824 [view setMiniwindowImage
: setMini
];
828 /* TODO: move to nsterm? */
830 ns_lisp_to_cursor_type
(Lisp_Object arg
)
833 if (XTYPE
(arg
) == Lisp_String
)
835 else if (XTYPE
(arg
) == Lisp_Symbol
)
836 str
= SSDATA
(SYMBOL_NAME
(arg
));
838 if (!strcmp (str
, "box"
)) return FILLED_BOX_CURSOR
;
839 if (!strcmp (str
, "hollow"
)) return HOLLOW_BOX_CURSOR
;
840 if (!strcmp (str
, "hbar"
)) return HBAR_CURSOR
;
841 if (!strcmp (str
, "
bar"
)) return BAR_CURSOR
;
842 if (!strcmp (str
, "no"
)) return NO_CURSOR
;
848 ns_cursor_type_to_lisp
(int arg
)
852 case FILLED_BOX_CURSOR
: return Qbox
;
853 case HOLLOW_BOX_CURSOR
: return intern
("hollow"
);
854 case HBAR_CURSOR
: return intern
("hbar"
);
855 case BAR_CURSOR
: return intern
("
bar"
);
857 default
: return intern
("no"
);
861 /* This is the same as the xfns.c definition. */
863 x_set_cursor_type
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
865 set_frame_cursor_types
(f
, arg
);
868 /* called to set mouse pointer color, but all other terms use it to
869 initialize pointer types (and don't set the color ;) */
871 x_set_mouse_color
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
873 /* don't think we can do this on Nextstep */
878 #define Xstr
(x
) Str
(x
)
881 ns_appkit_version_str
(void
)
885 #ifdef NS_IMPL_GNUSTEP
886 sprintf(tmp
, "gnustep
-gui
-%s", Xstr(GNUSTEP_GUI_VERSION));
887 #elif defined
(NS_IMPL_COCOA
)
888 sprintf(tmp
, "apple
-appkit
-%.2f", NSAppKitVersionNumber);
892 return build_string
(tmp
);
896 /* This is for use by x-server-version and collapses all version info we
897 have into a single int. For a better picture of the implementation
898 running, use ns_appkit_version_str.*/
900 ns_appkit_version_int
(void
)
902 #ifdef NS_IMPL_GNUSTEP
903 return GNUSTEP_GUI_MAJOR_VERSION
* 100 + GNUSTEP_GUI_MINOR_VERSION
;
904 #elif defined
(NS_IMPL_COCOA
)
905 return (int
)NSAppKitVersionNumber
;
912 x_icon
(struct frame
*f
, Lisp_Object parms
)
913 /* --------------------------------------------------------------------------
914 Strangely-named function to set icon position parameters in frame.
915 This is irrelevant under OS X, but might be needed under GNUstep,
916 depending on the window manager used. Note, this is not a standard
917 frame parameter-setter; it is called directly from x-create-frame.
918 -------------------------------------------------------------------------- */
920 Lisp_Object icon_x
, icon_y
;
921 struct ns_display_info
*dpyinfo
= check_ns_display_info
(Qnil
);
923 f
->output_data.ns
->icon_top
= Qnil
;
924 f
->output_data.ns
->icon_left
= Qnil
;
926 /* Set the position of the icon. */
927 icon_x
= x_get_arg
(dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
928 icon_y
= x_get_arg
(dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
929 if (!EQ
(icon_x
, Qunbound
) && !EQ
(icon_y
, Qunbound
))
931 CHECK_NUMBER
(icon_x
);
932 CHECK_NUMBER
(icon_y
);
933 f
->output_data.ns
->icon_top
= icon_y
;
934 f
->output_data.ns
->icon_left
= icon_x
;
936 else if (!EQ
(icon_x
, Qunbound
) ||
!EQ
(icon_y
, Qunbound
))
937 error ("Both left and top icon corners of icon must be specified"
);
941 /* Note: see frame.c for template, also where generic functions are impl */
942 frame_parm_handler ns_frame_parm_handlers
[] =
944 x_set_autoraise
, /* generic OK */
945 x_set_autolower
, /* generic OK */
946 x_set_background_color
,
947 0, /* x_set_border_color, may be impossible under Nextstep */
948 0, /* x_set_border_width, may be impossible under Nextstep */
951 x_set_font
, /* generic OK */
952 x_set_foreground_color
,
955 x_set_internal_border_width
, /* generic OK */
956 x_set_menu_bar_lines
,
958 x_explicitly_set_name
,
959 x_set_scroll_bar_width
, /* generic OK */
961 x_set_unsplittable
, /* generic OK */
962 x_set_vertical_scroll_bars
, /* generic OK */
963 x_set_visibility
, /* generic OK */
964 x_set_tool_bar_lines
,
965 0, /* x_set_scroll_bar_foreground, will ignore (not possible on NS) */
966 0, /* x_set_scroll_bar_background, will ignore (not possible on NS) */
967 x_set_screen_gamma
, /* generic OK */
968 x_set_line_spacing
, /* generic OK, sets f->extra_line_spacing to int */
969 x_set_fringe_width
, /* generic OK */
970 x_set_fringe_width
, /* generic OK */
971 0, /* x_set_wait_for_wm, will ignore */
972 x_set_fullscreen
, /* generic OK */
973 x_set_font_backend
, /* generic OK */
975 0, /* x_set_sticky */
976 0, /* x_set_tool_bar_position */
980 /* Handler for signals raised during x_create_frame.
981 FRAME is the frame which is partially constructed. */
984 unwind_create_frame
(Lisp_Object frame
)
986 struct frame
*f
= XFRAME
(frame
);
988 /* If frame is already dead, nothing to do. This can happen if the
989 display is disconnected after the frame has become official, but
990 before x_create_frame removes the unwind protect. */
991 if (!FRAME_LIVE_P
(f
))
994 /* If frame is ``official'', nothing to do. */
995 if (NILP
(Fmemq
(frame
, Vframe_list
)))
997 #
if defined GLYPH_DEBUG
&& defined ENABLE_CHECKING
998 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(f
);
1001 x_free_frame_resources
(f
);
1005 /* Check that reference counts are indeed correct. */
1006 eassert
(dpyinfo
->terminal->image_cache
->refcount
== image_cache_refcount
);
1012 * Read geometry related parameters from preferences if not in PARMS.
1013 * Returns the union of parms and any preferences read.
1017 get_geometry_from_preferences
(struct ns_display_info
*dpyinfo
,
1025 { "width"
, "Width"
, Qwidth
},
1026 { "height"
, "Height"
, Qheight
},
1027 { "left"
, "Left"
, Qleft
},
1028 { "top"
, "Top"
, Qtop
},
1032 for (i
= 0; i
< sizeof
(r
)/sizeof
(r
[0]); ++i
)
1034 if (NILP
(Fassq
(r
[i
].tem
, parms
)))
1037 = x_get_arg
(dpyinfo
, parms
, r
[i
].tem
, r
[i
].val
, r
[i
].cls
,
1039 if (! EQ
(value
, Qunbound
))
1040 parms
= Fcons
(Fcons
(r
[i
].tem
, value
), parms
);
1047 /* ==========================================================================
1051 ========================================================================== */
1053 DEFUN
("x
-create
-frame"
, Fx_create_frame
, Sx_create_frame
,
1055 doc: /* Make a new Nextstep window, called a "frame" in Emacs terms.
1056 Return an Emacs frame object.
1057 PARMS is an alist of frame parameters.
1058 If the parameters specify that the frame should not have a minibuffer,
1059 and do not specify a specific minibuffer window to use,
1060 then `default-minibuffer-frame' must be a frame whose minibuffer can
1061 be shared by the new frame.
1063 This function is an internal primitive--use `make-frame' instead. */)
1067 Lisp_Object frame
, tem
;
1069 int minibuffer_only
= 0;
1070 long window_prompting
= 0;
1072 ptrdiff_t count
= specpdl_ptr
- specpdl
;
1073 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1074 Lisp_Object display
;
1075 struct ns_display_info
*dpyinfo
= NULL;
1078 static int desc_ctr
= 1;
1080 /* x_get_arg modifies parms. */
1081 parms
= Fcopy_alist
(parms
);
1083 /* Use this general default value to start with
1084 until we know if this frame has a specified name. */
1085 Vx_resource_name
= Vinvocation_name
;
1087 display
= x_get_arg
(dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_STRING
);
1088 if (EQ
(display
, Qunbound
))
1090 dpyinfo
= check_ns_display_info
(display
);
1091 kb
= dpyinfo
->terminal->kboard
;
1093 if (!dpyinfo
->terminal->name
)
1094 error ("
Terminal is not live
, can
't create new frames on it");
1096 name = x_get_arg (dpyinfo, parms, Qname, 0, 0, RES_TYPE_STRING);
1098 && ! EQ (name, Qunbound)
1100 error ("Invalid frame name--not a string or nil");
1103 Vx_resource_name = name;
1105 parent = x_get_arg (dpyinfo, parms, Qparent_id, 0, 0, RES_TYPE_NUMBER);
1106 if (EQ (parent, Qunbound))
1108 if (! NILP (parent))
1109 CHECK_NUMBER (parent);
1111 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
1112 /* No need to protect DISPLAY because that's not used after passing
1113 it to make_frame_without_minibuffer. */
1115 GCPRO4
(parms
, parent
, name
, frame
);
1116 tem
= x_get_arg
(dpyinfo
, parms
, Qminibuffer
, "minibuffer"
, "Minibuffer"
,
1118 if (EQ
(tem
, Qnone
) || NILP
(tem
))
1119 f
= make_frame_without_minibuffer
(Qnil
, kb
, display
);
1120 else if (EQ
(tem
, Qonly
))
1122 f
= make_minibuffer_frame
();
1123 minibuffer_only
= 1;
1125 else if (WINDOWP
(tem
))
1126 f
= make_frame_without_minibuffer
(tem
, kb
, display
);
1130 XSETFRAME
(frame
, f
);
1132 f
->terminal = dpyinfo
->terminal;
1134 f
->output_method
= output_ns
;
1135 f
->output_data.ns
= xzalloc
(sizeof
*f
->output_data.ns
);
1137 FRAME_FONTSET
(f
) = -1;
1139 fset_icon_name
(f
, x_get_arg
(dpyinfo
, parms
, Qicon_name
,
1140 "iconName"
, "
Title"
,
1142 if (! STRINGP
(f
->icon_name
))
1143 fset_icon_name
(f
, Qnil
);
1145 FRAME_DISPLAY_INFO
(f
) = dpyinfo
;
1147 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
1148 record_unwind_protect
(unwind_create_frame
, frame
);
1150 f
->output_data.ns
->window_desc
= desc_ctr
++;
1151 if (TYPE_RANGED_INTEGERP
(Window
, parent
))
1153 f
->output_data.ns
->parent_desc
= XFASTINT
(parent
);
1154 f
->output_data.ns
->explicit_parent
= 1;
1158 f
->output_data.ns
->parent_desc
= FRAME_DISPLAY_INFO
(f
)->root_window
;
1159 f
->output_data.ns
->explicit_parent
= 0;
1162 /* Set the name; the functions to which we pass f expect the name to
1164 if (EQ
(name
, Qunbound
) || NILP
(name
) ||
! STRINGP
(name
))
1166 fset_name
(f
, build_string
([ns_app_name UTF8String
]));
1167 f
->explicit_name
= 0;
1171 fset_name
(f
, name
);
1172 f
->explicit_name
= 1;
1173 specbind
(Qx_resource_name
, name
);
1178 #ifdef NS_IMPL_COCOA
1179 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_5
1180 if (CTGetCoreTextVersion
!= NULL
1181 && CTGetCoreTextVersion
() >= kCTVersionNumber10_5
)
1182 mac_register_font_driver
(f
);
1185 register_font_driver
(&nsfont_driver
, f
);
1187 x_default_parameter
(f
, parms
, Qfont_backend
, Qnil
,
1188 "fontBackend"
, "FontBackend"
, RES_TYPE_STRING
);
1191 /* use for default font name */
1192 id font
= [NSFont userFixedPitchFontOfSize
: -1.0]; /* default */
1193 x_default_parameter
(f
, parms
, Qfontsize
,
1194 make_number
(0 /*(int)[font pointSize]*/),
1195 "fontSize"
, "FontSize"
, RES_TYPE_NUMBER
);
1196 // Remove
' Regular', not handled by backends.
1197 char *fontname
= xstrdup
([[font displayName
] UTF8String
]);
1198 int len
= strlen
(fontname
);
1199 if (len
> 8 && strcmp (fontname
+ len
- 8, " Regular"
) == 0)
1200 fontname
[len
-8] = '\0';
1201 x_default_parameter
(f
, parms
, Qfont
,
1202 build_string
(fontname
),
1203 "font"
, "Font"
, RES_TYPE_STRING
);
1207 x_default_parameter
(f
, parms
, Qborder_width
, make_number
(0),
1208 "borderwidth"
, "BorderWidth"
, RES_TYPE_NUMBER
);
1209 x_default_parameter
(f
, parms
, Qinternal_border_width
, make_number
(2),
1210 "internalBorderWidth"
, "InternalBorderWidth"
,
1213 /* default scrollbars on right on Mac */
1216 #ifdef NS_IMPL_GNUSTEP
1221 x_default_parameter
(f
, parms
, Qvertical_scroll_bars
, spos
,
1222 "verticalScrollBars"
, "VerticalScrollBars"
,
1225 x_default_parameter
(f
, parms
, Qforeground_color
, build_string
("Black"
),
1226 "foreground"
, "Foreground"
, RES_TYPE_STRING
);
1227 x_default_parameter
(f
, parms
, Qbackground_color
, build_string
("
White"
),
1228 "background"
, "Background"
, RES_TYPE_STRING
);
1229 /* FIXME: not supported yet in Nextstep */
1230 x_default_parameter
(f
, parms
, Qline_spacing
, Qnil
,
1231 "lineSpacing"
, "LineSpacing"
, RES_TYPE_NUMBER
);
1232 x_default_parameter
(f
, parms
, Qleft_fringe
, Qnil
,
1233 "leftFringe"
, "LeftFringe"
, RES_TYPE_NUMBER
);
1234 x_default_parameter
(f
, parms
, Qright_fringe
, Qnil
,
1235 "rightFringe"
, "RightFringe"
, RES_TYPE_NUMBER
);
1238 image_cache_refcount
=
1239 FRAME_IMAGE_CACHE
(f
) ? FRAME_IMAGE_CACHE
(f
)->refcount
: 0;
1242 init_frame_faces
(f
);
1244 /* The resources controlling the menu-bar and tool-bar are
1245 processed specially at startup, and reflected in the mode
1246 variables; ignore them here. */
1247 x_default_parameter
(f
, parms
, Qmenu_bar_lines
,
1248 NILP
(Vmenu_bar_mode
)
1249 ? make_number
(0) : make_number
(1),
1250 NULL, NULL, RES_TYPE_NUMBER
);
1251 x_default_parameter
(f
, parms
, Qtool_bar_lines
,
1252 NILP
(Vtool_bar_mode
)
1253 ? make_number
(0) : make_number
(1),
1254 NULL, NULL, RES_TYPE_NUMBER
);
1256 x_default_parameter
(f
, parms
, Qbuffer_predicate
, Qnil
, "bufferPredicate"
,
1257 "BufferPredicate"
, RES_TYPE_SYMBOL
);
1258 x_default_parameter
(f
, parms
, Qtitle
, Qnil
, "
title"
, "
Title"
,
1261 parms
= get_geometry_from_preferences
(dpyinfo
, parms
);
1262 window_prompting
= x_figure_window_size
(f
, parms
, 1);
1264 tem
= x_get_arg
(dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
1265 f
->no_split
= minibuffer_only ||
(!EQ
(tem
, Qunbound
) && !EQ
(tem
, Qnil
));
1267 /* NOTE: on other terms, this is done in set_mouse_color, however this
1268 was not getting called under Nextstep */
1269 f
->output_data.ns
->text_cursor
= [NSCursor IBeamCursor
];
1270 f
->output_data.ns
->nontext_cursor
= [NSCursor arrowCursor
];
1271 f
->output_data.ns
->modeline_cursor
= [NSCursor pointingHandCursor
];
1272 f
->output_data.ns
->hand_cursor
= [NSCursor pointingHandCursor
];
1273 f
->output_data.ns
->hourglass_cursor
= [NSCursor disappearingItemCursor
];
1274 f
->output_data.ns
->horizontal_drag_cursor
= [NSCursor resizeLeftRightCursor
];
1275 FRAME_DISPLAY_INFO
(f
)->vertical_scroll_bar_cursor
1276 = [NSCursor arrowCursor
];
1277 f
->output_data.ns
->current_pointer
= f
->output_data.ns
->text_cursor
;
1279 [[EmacsView alloc
] initFrameFromEmacs
: f
];
1283 /* ns_display_info does not have a reference_count. */
1284 f
->terminal->reference_count
++;
1286 /* It is now ok to make the frame official even if we get an error below.
1287 The frame needs to be on Vframe_list or making it visible won't work. */
1288 Vframe_list
= Fcons
(frame
, Vframe_list
);
1290 x_default_parameter
(f
, parms
, Qicon_type
, Qnil
,
1291 "bitmapIcon"
, "BitmapIcon"
, RES_TYPE_SYMBOL
);
1293 x_default_parameter
(f
, parms
, Qauto_raise
, Qnil
,
1294 "autoRaise"
, "AutoRaiseLower"
, RES_TYPE_BOOLEAN
);
1295 x_default_parameter
(f
, parms
, Qauto_lower
, Qnil
,
1296 "autoLower"
, "AutoLower"
, RES_TYPE_BOOLEAN
);
1297 x_default_parameter
(f
, parms
, Qcursor_type
, Qbox
,
1298 "cursorType"
, "CursorType"
, RES_TYPE_SYMBOL
);
1299 x_default_parameter
(f
, parms
, Qscroll_bar_width
, Qnil
,
1300 "scrollBarWidth"
, "ScrollBarWidth"
,
1302 x_default_parameter
(f
, parms
, Qalpha
, Qnil
,
1303 "alpha"
, "Alpha"
, RES_TYPE_NUMBER
);
1304 x_default_parameter
(f
, parms
, Qfullscreen
, Qnil
,
1305 "fullscreen"
, "Fullscreen"
, RES_TYPE_SYMBOL
);
1307 width
= FRAME_COLS
(f
);
1308 height
= FRAME_LINES
(f
);
1310 SET_FRAME_COLS
(f
, 0);
1311 FRAME_LINES
(f
) = 0;
1312 change_frame_size
(f
, height
, width
, 1, 0, 0);
1314 if (! f
->output_data.ns
->explicit_parent
)
1316 Lisp_Object visibility
;
1318 visibility
= x_get_arg
(dpyinfo
, parms
, Qvisibility
, 0, 0,
1320 if (EQ
(visibility
, Qunbound
))
1323 if (EQ
(visibility
, Qicon
))
1324 x_iconify_frame
(f
);
1325 else if (! NILP
(visibility
))
1327 x_make_frame_visible
(f
);
1328 [[FRAME_NS_VIEW
(f
) window
] makeKeyWindow
];
1332 /* Must have been Qnil. */
1336 if (FRAME_HAS_MINIBUF_P
(f
)
1337 && (!FRAMEP
(KVAR
(kb
, Vdefault_minibuffer_frame
))
1338 ||
!FRAME_LIVE_P
(XFRAME
(KVAR
(kb
, Vdefault_minibuffer_frame
)))))
1339 kset_default_minibuffer_frame
(kb
, frame
);
1341 /* All remaining specified parameters, which have not been "used"
1342 by x_get_arg and friends, now go in the misc. alist of the frame. */
1343 for (tem
= parms
; CONSP
(tem
); tem
= XCDR
(tem
))
1344 if (CONSP
(XCAR
(tem
)) && !NILP
(XCAR
(XCAR
(tem
))))
1345 fset_param_alist
(f
, Fcons
(XCAR
(tem
), f
->param_alist
));
1349 if (window_prompting
& USPosition
)
1350 x_set_offset
(f
, f
->left_pos
, f
->top_pos
, 1);
1352 /* Make sure windows on this frame appear in calls to next-window
1353 and similar functions. */
1354 Vwindow_list
= Qnil
;
1356 return unbind_to
(count
, frame
);
1360 x_focus_frame
(struct frame
*f
)
1362 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(f
);
1364 if (dpyinfo
->x_focus_frame
!= f
)
1366 EmacsView
*view = FRAME_NS_VIEW
(f
);
1368 [NSApp activateIgnoringOtherApps
: YES
];
1369 [[view window
] makeKeyAndOrderFront
: view];
1375 DEFUN
("ns
-popup
-font
-panel"
, Fns_popup_font_panel
, Sns_popup_font_panel
,
1377 doc: /* Pop up the font panel. */)
1380 struct frame
*f
= decode_window_system_frame
(frame
);
1381 id fm
= [NSFontManager sharedFontManager
];
1382 struct font
*font
= f
->output_data.ns
->font
;
1384 if (EQ
(font
->driver
->type, Qns
))
1385 nsfont
= ((struct nsfont_info
*)font
)->nsfont
;
1386 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_5
1388 nsfont
= (NSFont
*) macfont_get_nsctfont
(font
);
1390 [fm setSelectedFont
: nsfont isMultiple
: NO
];
1391 [fm orderFrontFontPanel
: NSApp
];
1396 DEFUN
("ns
-popup
-color
-panel"
, Fns_popup_color_panel
, Sns_popup_color_panel
,
1398 doc: /* Pop up the color panel. */)
1401 check_window_system
(NULL);
1402 [NSApp orderFrontColorPanel
: NSApp
];
1410 #
if ! defined
(NS_IMPL_COCOA
) || \
1411 MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
1412 NSString
*dirS
, *initS
;
1418 ns_run_file_dialog
(void
)
1420 if (ns_fd_data.panel
== nil
) return;
1421 #
if defined
(NS_IMPL_COCOA
) && \
1422 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
1423 ns_fd_data.ret
= [ns_fd_data.panel runModal
];
1425 if (ns_fd_data.no_types
)
1427 ns_fd_data.ret
= [ns_fd_data.panel
1428 runModalForDirectory
: ns_fd_data.dirS
1429 file
: ns_fd_data.initS
];
1433 ns_fd_data.ret
= [ns_fd_data.panel
1434 runModalForDirectory
: ns_fd_data.dirS
1435 file
: ns_fd_data.initS
1439 ns_fd_data.panel
= nil
;
1442 DEFUN
("ns
-read
-file
-name"
, Fns_read_file_name
, Sns_read_file_name
, 1, 5, 0,
1443 doc: /* Use a graphical panel to read a file name, using prompt PROMPT.
1444 Optional arg DIR, if non-nil, supplies a default directory.
1445 Optional arg MUSTMATCH, if non-nil, means the returned file or
1446 directory must exist.
1447 Optional arg INIT, if non-nil, provides a default file name to use.
1448 Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1449 (Lisp_Object prompt
, Lisp_Object
dir, Lisp_Object mustmatch
,
1450 Lisp_Object init
, Lisp_Object dir_only_p
)
1452 static id fileDelegate
= nil
;
1454 BOOL isSave
= NILP
(mustmatch
) && NILP
(dir_only_p
);
1458 NSString
*promptS
= NILP
(prompt
) ||
!STRINGP
(prompt
) ? nil
:
1459 [NSString stringWithUTF8String
: SSDATA
(prompt
)];
1460 NSString
*dirS
= NILP
(dir) ||
!STRINGP
(dir) ?
1461 [NSString stringWithUTF8String
: SSDATA
(BVAR
(current_buffer
, directory
))] :
1462 [NSString stringWithUTF8String
: SSDATA
(dir)];
1463 NSString
*initS
= NILP
(init
) ||
!STRINGP
(init
) ? nil
:
1464 [NSString stringWithUTF8String
: SSDATA
(init
)];
1467 check_window_system
(NULL);
1469 if (fileDelegate
== nil
)
1470 fileDelegate
= [EmacsFileDelegate new
];
1472 [NSCursor setHiddenUntilMouseMoves
: NO
];
1474 if ([dirS characterAtIndex
: 0] == '~')
1475 dirS
= [dirS stringByExpandingTildeInPath
];
1478 (id
)[EmacsSavePanel savePanel
] : (id
)[EmacsOpenPanel openPanel
];
1480 [panel setTitle
: promptS
];
1482 [panel setAllowsOtherFileTypes
: YES
];
1483 [panel setTreatsFilePackagesAsDirectories
: YES
];
1484 [panel setDelegate
: fileDelegate
];
1486 if (! NILP
(dir_only_p
))
1488 [panel setCanChooseDirectories
: YES
];
1489 [panel setCanChooseFiles
: NO
];
1493 /* This is not quite what the documentation says, but it is compatible
1494 with the Gtk+ code. Also, the menu entry says "Open File...". */
1495 [panel setCanChooseDirectories
: NO
];
1496 [panel setCanChooseFiles
: YES
];
1500 ns_fd_data.panel
= panel
;
1501 ns_fd_data.ret
= NO
;
1502 #
if defined
(NS_IMPL_COCOA
) && \
1503 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
1504 if (! NILP
(mustmatch
) ||
! NILP
(dir_only_p
))
1505 [panel setAllowedFileTypes
: nil
];
1506 if (dirS
) [panel setDirectoryURL
: [NSURL fileURLWithPath
: dirS
]];
1507 if (initS
&& NILP
(Ffile_directory_p
(init
)))
1508 [panel setNameFieldStringValue
: [initS lastPathComponent
]];
1510 [panel setNameFieldStringValue
: @""
];
1513 ns_fd_data.no_types
= NILP
(mustmatch
) && NILP
(dir_only_p
);
1514 ns_fd_data.dirS
= dirS
;
1515 ns_fd_data.initS
= initS
;
1518 /* runModalForDirectory/runModal restarts the main event loop when done,
1519 so we must start an event loop and then pop up the file dialog.
1520 The file dialog may pop up a confirm dialog after Ok has been pressed,
1521 so we can not simply pop down on the Ok/Cancel press.
1523 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
1524 location
: NSMakePoint
(0, 0)
1527 windowNumber
: [[NSApp mainWindow
] windowNumber
]
1528 context
: [NSApp context
]
1531 data2
: NSAPP_DATA2_RUNFILEDIALOG
];
1533 [NSApp postEvent
: nxev atStart
: NO
];
1534 while (ns_fd_data.panel
!= nil
)
1537 ret
= (ns_fd_data.ret
== NSOKButton
);
1541 NSString
*str
= ns_filename_from_panel
(panel
);
1542 if (! str
) str
= ns_directory_from_panel
(panel
);
1543 if (! str
) ret
= NO
;
1544 else fname
= build_string
([str UTF8String
]);
1547 [[FRAME_NS_VIEW
(SELECTED_FRAME
()) window
] makeKeyWindow
];
1550 return ret ? fname
: Qnil
;
1554 ns_get_defaults_value
(const
char *key
)
1556 NSObject
*obj
= [[NSUserDefaults standardUserDefaults
]
1557 objectForKey
: [NSString stringWithUTF8String
: key
]];
1559 if (!obj
) return NULL;
1561 return [[NSString stringWithFormat
: @"
%@", obj] UTF8String];
1565 DEFUN
("ns
-get-resource"
, Fns_get_resource
, Sns_get_resource
, 2, 2, 0,
1566 doc: /* Return the value of the property NAME of OWNER from the defaults database.
1567 If OWNER is nil, Emacs is assumed. */)
1568 (Lisp_Object owner
, Lisp_Object name
)
1572 check_window_system
(NULL);
1574 owner
= build_string
([ns_app_name UTF8String
]);
1575 CHECK_STRING
(name
);
1577 value
= ns_get_defaults_value
(SSDATA
(name
));
1580 return build_string
(value
);
1585 DEFUN
("ns
-set-resource"
, Fns_set_resource
, Sns_set_resource
, 3, 3, 0,
1586 doc: /* Set property NAME of OWNER to VALUE, from the defaults database.
1587 If OWNER is nil, Emacs is assumed.
1588 If VALUE is nil, the default is removed. */)
1589 (Lisp_Object owner
, Lisp_Object name
, Lisp_Object value
)
1591 check_window_system
(NULL);
1593 owner
= build_string
([ns_app_name UTF8String
]);
1594 CHECK_STRING
(name
);
1597 [[NSUserDefaults standardUserDefaults
] removeObjectForKey
:
1598 [NSString stringWithUTF8String
: SSDATA
(name
)]];
1602 CHECK_STRING
(value
);
1603 [[NSUserDefaults standardUserDefaults
] setObject
:
1604 [NSString stringWithUTF8String
: SSDATA
(value
)]
1605 forKey
: [NSString stringWithUTF8String
:
1613 DEFUN
("x
-server
-max-request
-size"
, Fx_server_max_request_size
,
1614 Sx_server_max_request_size
,
1616 doc: /* This function is a no-op. It is only present for completeness. */)
1617 (Lisp_Object
terminal)
1619 check_ns_display_info
(terminal);
1620 /* This function has no real equivalent under NeXTstep. Return nil to
1626 DEFUN
("x
-server
-vendor"
, Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
1627 doc: /* Return the "vendor ID" string of Nextstep display server TERMINAL.
1628 \(Labeling every distributor as a "vendor" embodies the false assumption
1629 that operating systems cannot be developed and distributed noncommercially.)
1630 The optional argument TERMINAL specifies which display to ask about.
1631 TERMINAL should be a terminal object, a frame or a display name (a string).
1632 If omitted or nil, that stands for the selected frame's display. */)
1633 (Lisp_Object
terminal)
1635 check_ns_display_info
(terminal);
1636 #ifdef NS_IMPL_GNUSTEP
1637 return build_string
("GNU"
);
1639 return build_string
("Apple"
);
1644 DEFUN
("x
-server
-version"
, Fx_server_version
, Sx_server_version
, 0, 1, 0,
1645 doc: /* Return the version numbers of the server of display TERMINAL.
1646 The value is a list of three integers: the major and minor
1647 version numbers of the X Protocol in use, and the distributor-specific release
1648 number. See also the function `x-server-vendor'.
1650 The optional argument TERMINAL specifies which display to ask about.
1651 TERMINAL should be a terminal object, a frame or a display name (a string).
1652 If omitted or nil, that stands for the selected frame's display. */)
1653 (Lisp_Object
terminal)
1655 check_ns_display_info
(terminal);
1656 /*NOTE: it is unclear what would best correspond with "protocol";
1657 we return 10.3, meaning Panther, since this is roughly the
1658 level that GNUstep's APIs correspond to.
1659 The last number is where we distinguish between the Apple
1660 and GNUstep implementations ("distributor-specific release
1661 number") and give int'ized versions of major.minor. */
1662 return list3i
(10, 3, ns_appkit_version_int
());
1666 DEFUN
("x
-display
-screens"
, Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
1667 doc: /* Return the number of screens on Nextstep display server TERMINAL.
1668 The optional argument TERMINAL specifies which display to ask about.
1669 TERMINAL should be a terminal object, a frame or a display name (a string).
1670 If omitted or nil, that stands for the selected frame's display.
1672 Note: "screen" here is not in Nextstep terminology but in X11's. For
1673 the number of physical monitors, use `(length
1674 (display-monitor-attributes-list TERMINAL))' instead. */)
1675 (Lisp_Object
terminal)
1677 check_ns_display_info
(terminal);
1678 return make_number
(1);
1682 DEFUN
("x
-display
-mm
-height"
, Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
1683 doc: /* Return the height in millimeters of the Nextstep display TERMINAL.
1684 The optional argument TERMINAL specifies which display to ask about.
1685 TERMINAL should be a terminal object, a frame or a display name (a string).
1686 If omitted or nil, that stands for the selected frame's display.
1688 On \"multi-monitor\" setups this refers to the height in millimeters for
1689 all physical monitors associated with TERMINAL. To get information
1690 for each physical monitor, use `display-monitor-attributes-list'. */)
1691 (Lisp_Object
terminal)
1693 struct ns_display_info
*dpyinfo
= check_ns_display_info
(terminal);
1695 return make_number
(x_display_pixel_height
(dpyinfo
) / (92.0/25.4));
1699 DEFUN
("x
-display
-mm
-width"
, Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
1700 doc: /* Return the width in millimeters of the Nextstep display TERMINAL.
1701 The optional argument TERMINAL specifies which display to ask about.
1702 TERMINAL should be a terminal object, a frame or a display name (a string).
1703 If omitted or nil, that stands for the selected frame's display.
1705 On \"multi-monitor\" setups this refers to the width in millimeters for
1706 all physical monitors associated with TERMINAL. To get information
1707 for each physical monitor, use `display-monitor-attributes-list'. */)
1708 (Lisp_Object
terminal)
1710 struct ns_display_info
*dpyinfo
= check_ns_display_info
(terminal);
1712 return make_number
(x_display_pixel_width
(dpyinfo
) / (92.0/25.4));
1716 DEFUN
("x
-display
-backing
-store"
, Fx_display_backing_store
,
1717 Sx_display_backing_store
, 0, 1, 0,
1718 doc: /* Return an indication of whether the Nextstep display TERMINAL does backing store.
1719 The value may be `buffered', `retained', or `non-retained'.
1720 The optional argument TERMINAL specifies which display to ask about.
1721 TERMINAL should be a terminal object, a frame or a display name (a string).
1722 If omitted or nil, that stands for the selected frame's display. */)
1723 (Lisp_Object
terminal)
1725 check_ns_display_info
(terminal);
1726 switch ([ns_get_window
(terminal) backingType
])
1728 case NSBackingStoreBuffered
:
1729 return intern
("buffered"
);
1730 case NSBackingStoreRetained
:
1731 return intern
("retained"
);
1732 case NSBackingStoreNonretained
:
1733 return intern
("non
-retained"
);
1735 error ("Strange value
for backingType parameter of frame"
);
1737 return Qnil
; /* not reached, shut compiler up */
1741 DEFUN
("x
-display
-visual
-class"
, Fx_display_visual_class
,
1742 Sx_display_visual_class
, 0, 1, 0,
1743 doc: /* Return the visual class of the Nextstep display TERMINAL.
1744 The value is one of the symbols `static-gray', `gray-scale',
1745 `static-color', `pseudo-color', `true-color', or `direct-color'.
1747 The optional argument TERMINAL specifies which display to ask about.
1748 TERMINAL should a terminal object, a frame or a display name (a string).
1749 If omitted or nil, that stands for the selected frame's display. */)
1750 (Lisp_Object
terminal)
1752 NSWindowDepth depth
;
1754 check_ns_display_info
(terminal);
1755 depth
= [[[NSScreen screens
] objectAtIndex
:0] depth
];
1757 if ( depth
== NSBestDepth
(NSCalibratedWhiteColorSpace
, 2, 2, YES
, NULL))
1758 return intern
("static
-gray"
);
1759 else if (depth
== NSBestDepth
(NSCalibratedWhiteColorSpace
, 8, 8, YES
, NULL))
1760 return intern
("
gray-scale"
);
1761 else if ( depth
== NSBestDepth
(NSCalibratedRGBColorSpace
, 8, 8, YES
, NULL))
1762 return intern
("pseudo
-color"
);
1763 else if ( depth
== NSBestDepth
(NSCalibratedRGBColorSpace
, 4, 12, NO
, NULL))
1764 return intern
("true
-color"
);
1765 else if ( depth
== NSBestDepth
(NSCalibratedRGBColorSpace
, 8, 24, NO
, NULL))
1766 return intern
("direct
-color"
);
1768 /* color mgmt as far as we do it is really handled by Nextstep itself anyway */
1769 return intern
("direct
-color"
);
1773 DEFUN
("x
-display
-save-under"
, Fx_display_save_under
,
1774 Sx_display_save_under
, 0, 1, 0,
1775 doc: /* Return t if TERMINAL supports the save-under feature.
1776 The optional argument TERMINAL specifies which display to ask about.
1777 TERMINAL should be a terminal object, a frame or a display name (a string).
1778 If omitted or nil, that stands for the selected frame's display. */)
1779 (Lisp_Object
terminal)
1781 check_ns_display_info
(terminal);
1782 switch ([ns_get_window
(terminal) backingType
])
1784 case NSBackingStoreBuffered
:
1787 case NSBackingStoreRetained
:
1788 case NSBackingStoreNonretained
:
1792 error ("Strange value
for backingType parameter of frame"
);
1794 return Qnil
; /* not reached, shut compiler up */
1798 DEFUN
("x
-open
-connection"
, Fx_open_connection
, Sx_open_connection
,
1800 doc: /* Open a connection to a display server.
1801 DISPLAY is the name of the display to connect to.
1802 Optional second arg XRM-STRING is a string of resources in xrdb format.
1803 If the optional third arg MUST-SUCCEED is non-nil,
1804 terminate Emacs if we can't open the connection.
1805 \(In the Nextstep version, the last two arguments are currently ignored.) */)
1806 (Lisp_Object display
, Lisp_Object resource_string
, Lisp_Object must_succeed
)
1808 struct ns_display_info
*dpyinfo
;
1810 CHECK_STRING
(display
);
1812 nxatoms_of_nsselect
();
1813 dpyinfo
= ns_term_init
(display
);
1816 if (!NILP
(must_succeed
))
1817 fatal
("OpenStep on
%s not responding.\n",
1820 error ("OpenStep on
%s not responding.\n",
1828 DEFUN
("x
-close-connection"
, Fx_close_connection
, Sx_close_connection
,
1830 doc: /* Close the connection to TERMINAL's Nextstep display server.
1831 For TERMINAL, specify a terminal object, a frame or a display name (a
1832 string). If TERMINAL is nil, that stands for the selected frame's
1834 (Lisp_Object
terminal)
1836 check_ns_display_info
(terminal);
1837 [NSApp terminate
: NSApp
];
1842 DEFUN
("x
-display
-list"
, Fx_display_list
, Sx_display_list
, 0, 0, 0,
1843 doc: /* Return the list of display names that Emacs has connections to. */)
1846 Lisp_Object tail
, result
;
1849 for (tail
= ns_display_name_list
; CONSP
(tail
); tail
= XCDR
(tail
))
1850 result
= Fcons
(XCAR
(XCAR
(tail
)), result
);
1856 DEFUN
("ns
-hide
-others"
, Fns_hide_others
, Sns_hide_others
,
1858 doc: /* Hides all applications other than Emacs. */)
1861 check_window_system
(NULL);
1862 [NSApp hideOtherApplications
: NSApp
];
1866 DEFUN
("ns
-hide
-emacs"
, Fns_hide_emacs
, Sns_hide_emacs
,
1868 doc: /* If ON is non-nil, the entire Emacs application is hidden.
1869 Otherwise if Emacs is hidden, it is unhidden.
1870 If ON is equal to `activate', Emacs is unhidden and becomes
1871 the active application. */)
1874 check_window_system
(NULL);
1875 if (EQ
(on
, intern
("activate"
)))
1877 [NSApp unhide
: NSApp
];
1878 [NSApp activateIgnoringOtherApps
: YES
];
1881 [NSApp unhide
: NSApp
];
1883 [NSApp hide
: NSApp
];
1888 DEFUN
("ns
-emacs
-info-panel"
, Fns_emacs_info_panel
, Sns_emacs_info_panel
,
1890 doc: /* Shows the 'Info' or 'About' panel for Emacs. */)
1893 check_window_system
(NULL);
1894 [NSApp orderFrontStandardAboutPanel
: nil
];
1899 DEFUN
("ns
-font
-name"
, Fns_font_name
, Sns_font_name
, 1, 1, 0,
1900 doc: /* Determine font PostScript or family name for font NAME.
1901 NAME should be a string containing either the font name or an XLFD
1902 font descriptor. If string contains `fontset' and not
1903 `fontset-startup', it is left alone. */)
1907 CHECK_STRING
(name
);
1912 if (strstr
(nm
, "fontset"
) && !strstr
(nm
, "fontset
-startup"
))
1915 return build_string
(ns_xlfd_to_fontname
(SSDATA
(name
)));
1919 DEFUN
("ns
-list
-colors"
, Fns_list_colors
, Sns_list_colors
, 0, 1, 0,
1920 doc: /* Return a list of all available colors.
1921 The optional argument FRAME is currently ignored. */)
1924 Lisp_Object list
= Qnil
;
1925 NSEnumerator
*colorlists
;
1930 CHECK_FRAME
(frame
);
1931 if (! FRAME_NS_P
(XFRAME
(frame
)))
1932 error ("non
-Nextstep frame used in `ns
-list
-colors
'");
1937 colorlists = [[NSColorList availableColorLists] objectEnumerator];
1938 while ((clist = [colorlists nextObject]))
1940 if ([[clist name] length] < 7 ||
1941 [[clist name] rangeOfString: @"PANTONE"].location == 0)
1943 NSEnumerator *cnames = [[clist allKeys] reverseObjectEnumerator];
1945 while ((cname = [cnames nextObject]))
1946 list = Fcons (build_string ([cname UTF8String]), list);
1947 /* for (i = [[clist allKeys] count] - 1; i >= 0; i--)
1948 list = Fcons (build_string ([[[clist allKeys] objectAtIndex: i]
1949 UTF8String]), list); */
1959 DEFUN ("ns-list-services", Fns_list_services, Sns_list_services, 0, 0, 0,
1960 doc: /* List available Nextstep services by querying NSApp. */)
1963 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1964 /* You can't
get services like this in
10.6+. */
1967 Lisp_Object ret
= Qnil
;
1969 #ifdef NS_IMPL_COCOA
1973 check_window_system
(NULL);
1974 svcs
= [[NSMenu alloc
] initWithTitle
: @"Services"
];
1975 [NSApp setServicesMenu
: svcs
];
1976 [NSApp registerServicesMenuSendTypes
: ns_send_types
1977 returnTypes
: ns_return_types
];
1979 /* On Tiger, services menu updating was made lazier (waits for user to
1980 actually click on the menu), so we have to force things along: */
1981 #ifdef NS_IMPL_COCOA
1982 delegate
= [svcs delegate
];
1983 if (delegate
!= nil
)
1985 if ([delegate respondsToSelector
: @selector
(menuNeedsUpdate
:)])
1986 [delegate menuNeedsUpdate
: svcs
];
1987 if ([delegate respondsToSelector
:
1988 @selector
(menu:updateItem
:atIndex
:shouldCancel
:)])
1990 int i
, len
= [delegate numberOfItemsInMenu
: svcs
];
1991 for (i
=0; i
<len
; i
++)
1992 [svcs addItemWithTitle
: @"" action
: NULL keyEquivalent
: @""
];
1993 for (i
=0; i
<len
; i
++)
1994 if (![delegate
menu: svcs
1995 updateItem
: (NSMenuItem
*)[svcs itemAtIndex
: i
]
1996 atIndex
: i shouldCancel
: NO
])
2002 [svcs setAutoenablesItems
: NO
];
2003 #ifdef NS_IMPL_COCOA
2004 [svcs update
]; /* on OS X, converts from '/' structure */
2007 ret
= interpret_services_menu
(svcs
, Qnil
, ret
);
2013 DEFUN
("ns
-perform
-service"
, Fns_perform_service
, Sns_perform_service
,
2015 doc: /* Perform Nextstep SERVICE on SEND.
2016 SEND should be either a string or nil.
2017 The return value is the result of the service, as string, or nil if
2018 there was no result. */)
2019 (Lisp_Object service
, Lisp_Object send
)
2025 CHECK_STRING
(service
);
2026 check_window_system
(NULL);
2028 utfStr
= SSDATA
(service
);
2029 svcName
= [NSString stringWithUTF8String
: utfStr
];
2031 pb
=[NSPasteboard pasteboardWithUniqueName
];
2032 ns_string_to_pasteboard
(pb
, send
);
2034 if (NSPerformService
(svcName
, pb
) == NO
)
2035 Fsignal
(Qquit
, list1
(build_string
("service not available"
)));
2037 if ([[pb types
] count
] == 0)
2038 return build_string
(""
);
2039 return ns_string_from_pasteboard
(pb
);
2043 DEFUN
("ns
-convert
-utf8
-nfd
-to
-nfc"
, Fns_convert_utf8_nfd_to_nfc
,
2044 Sns_convert_utf8_nfd_to_nfc
, 1, 1, 0,
2045 doc: /* Return an NFC string that matches the UTF-8 NFD string STR. */)
2048 /* TODO: If GNUstep ever implements precomposedStringWithCanonicalMapping,
2051 Lisp_Object ret
= Qnil
;
2052 NSAutoreleasePool
*pool
;
2055 pool
= [[NSAutoreleasePool alloc
] init
];
2056 utfStr
= [NSString stringWithUTF8String
: SSDATA
(str
)];
2057 #ifdef NS_IMPL_COCOA
2059 utfStr
= [utfStr precomposedStringWithCanonicalMapping
];
2063 const
char *cstr
= [utfStr UTF8String
];
2065 ret
= build_string
(cstr
);
2070 error ("Invalid UTF
-8"
);
2076 #ifdef NS_IMPL_COCOA
2078 /* Compile and execute the AppleScript SCRIPT and return the error
2079 status as function value. A zero is returned if compilation and
2080 execution is successful, in which case *RESULT is set to a Lisp
2081 string or a number containing the resulting script value. Otherwise,
2084 ns_do_applescript
(Lisp_Object
script, Lisp_Object
*result
)
2086 NSAppleEventDescriptor
*desc
;
2087 NSDictionary
* errorDict
;
2088 NSAppleEventDescriptor
* returnDescriptor
= NULL;
2090 NSAppleScript
* scriptObject
=
2091 [[NSAppleScript alloc
] initWithSource
:
2092 [NSString stringWithUTF8String
: SSDATA
(script)]];
2094 returnDescriptor
= [scriptObject executeAndReturnError
: &errorDict
];
2095 [scriptObject release
];
2099 if (returnDescriptor
!= NULL)
2101 // successful execution
2102 if (kAENullEvent
!= [returnDescriptor descriptorType
])
2105 // script returned an AppleScript result
2106 if ((typeUnicodeText
== [returnDescriptor descriptorType
]) ||
2107 #
if defined
(NS_IMPL_COCOA
)
2108 (typeUTF16ExternalRepresentation
2109 == [returnDescriptor descriptorType
]) ||
2111 (typeUTF8Text
== [returnDescriptor descriptorType
]) ||
2112 (typeCString
== [returnDescriptor descriptorType
]))
2114 desc
= [returnDescriptor coerceToDescriptorType
: typeUTF8Text
];
2116 *result
= build_string
([[desc stringValue
] UTF8String
]);
2120 /* use typeUTF16ExternalRepresentation? */
2121 // coerce the result to the appropriate ObjC
type
2122 desc
= [returnDescriptor coerceToDescriptorType
: typeUTF8Text
];
2124 *result
= make_number
([desc int32Value
]);
2130 // no
script result
, return error
2136 /* Helper function called from sendEvent to run applescript
2137 from within the main event loop. */
2140 ns_run_ascript
(void
)
2142 if (! NILP
(as_script
))
2143 as_status
= ns_do_applescript
(as_script
, as_result
);
2147 DEFUN
("ns
-do
-applescript"
, Fns_do_applescript
, Sns_do_applescript
, 1, 1, 0,
2148 doc: /* Execute AppleScript SCRIPT and return the result.
2149 If compilation and execution are successful, the resulting script value
2150 is returned as a string, a number or, in the case of other constructs, t.
2151 In case the execution fails, an error is signaled. */)
2152 (Lisp_Object
script)
2158 CHECK_STRING
(script);
2159 check_window_system
(NULL);
2164 as_result
= &result
;
2166 /* executing apple script requires the event loop to run, otherwise
2167 errors aren't returned and executeAndReturnError hangs forever.
2168 Post an event that runs applescript and then start the event loop.
2169 The event loop is exited when the script is done. */
2170 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
2171 location
: NSMakePoint
(0, 0)
2174 windowNumber
: [[NSApp mainWindow
] windowNumber
]
2175 context
: [NSApp context
]
2178 data2
: NSAPP_DATA2_RUNASSCRIPT
];
2180 [NSApp postEvent
: nxev atStart
: NO
];
2182 // If there are other events
, the event loop may exit. Keep running
2183 // until the
script has been handled. */
2184 while (! NILP
(as_script
))
2193 else if (!STRINGP
(result
))
2194 error ("AppleScript
error %d", status);
2196 error ("
%s", SSDATA (result));
2202 /* ==========================================================================
2204 Miscellaneous functions not called through hooks
2206 ========================================================================== */
2208 /* called from frame.c */
2209 struct ns_display_info
*
2210 check_x_display_info
(Lisp_Object frame
)
2212 return check_ns_display_info
(frame
);
2217 x_set_scroll_bar_default_width
(struct frame
*f
)
2219 int wid
= FRAME_COLUMN_WIDTH
(f
);
2220 FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) = NS_SCROLL_BAR_WIDTH_DEFAULT
;
2221 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) +
2225 /* terms impl this instead of x-get-resource directly */
2227 x_get_string_resource
(XrmDatabase rdb
, const
char *name
, const
char *class)
2229 /* remove appname prefix; TODO: allow for !="Emacs" */
2230 const
char *res
, *toCheck
= class + (!strncmp
(class, "Emacs."
, 6) ?
6 : 0);
2232 check_window_system
(NULL);
2234 if (inhibit_x_resources
)
2235 /* --quick was passed, so this is a no-op. */
2238 res
= ns_get_defaults_value
(toCheck
);
2239 return (!res ?
NULL :
2240 (!c_strncasecmp
(res
, "YES"
, 3) ? "true"
:
2241 (!c_strncasecmp
(res
, "NO"
, 2) ? "false"
: (char *) res
)));
2246 x_get_focus_frame
(struct frame
*frame
)
2248 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(frame
);
2249 Lisp_Object nsfocus
;
2251 if (!dpyinfo
->x_focus_frame
)
2254 XSETFRAME
(nsfocus
, dpyinfo
->x_focus_frame
);
2258 /* ==========================================================================
2260 Lisp definitions that, for whatever reason, we can't alias as 'ns-XXX'.
2262 ========================================================================== */
2265 DEFUN
("xw
-color
-defined
-p"
, Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
2266 doc: /* Internal function called by `color-defined-p', which see.
2267 \(Note that the Nextstep version of this function ignores FRAME.) */)
2268 (Lisp_Object color
, Lisp_Object frame
)
2271 check_window_system
(NULL);
2272 return ns_lisp_to_color
(color
, &col
) ? Qnil
: Qt
;
2276 DEFUN
("xw
-color
-values"
, Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
2277 doc: /* Internal function called by `color-values', which see. */)
2278 (Lisp_Object color
, Lisp_Object frame
)
2281 EmacsCGFloat red
, green
, blue
, alpha
;
2283 check_window_system
(NULL);
2284 CHECK_STRING
(color
);
2286 if (ns_lisp_to_color
(color
, &col
))
2289 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
2290 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
2291 return list3i
(lrint
(red
* 65280), lrint
(green
* 65280),
2292 lrint
(blue
* 65280));
2296 DEFUN
("xw
-display
-color
-p"
, Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
2297 doc: /* Internal function called by `display-color-p', which see. */)
2298 (Lisp_Object
terminal)
2300 NSWindowDepth depth
;
2301 NSString
*colorSpace
;
2303 check_ns_display_info
(terminal);
2304 depth
= [[[NSScreen screens
] objectAtIndex
:0] depth
];
2305 colorSpace
= NSColorSpaceFromDepth
(depth
);
2307 return [colorSpace isEqualToString
: NSDeviceWhiteColorSpace
]
2308 ||
[colorSpace isEqualToString
: NSCalibratedWhiteColorSpace
]
2313 DEFUN
("x
-display
-grayscale
-p"
, Fx_display_grayscale_p
, Sx_display_grayscale_p
,
2315 doc: /* Return t if the Nextstep display supports shades of gray.
2316 Note that color displays do support shades of gray.
2317 The optional argument TERMINAL specifies which display to ask about.
2318 TERMINAL should be a terminal object, a frame or a display name (a string).
2319 If omitted or nil, that stands for the selected frame's display. */)
2320 (Lisp_Object
terminal)
2322 NSWindowDepth depth
;
2324 check_ns_display_info
(terminal);
2325 depth
= [[[NSScreen screens
] objectAtIndex
:0] depth
];
2327 return NSBitsPerPixelFromDepth
(depth
) > 1 ? Qt
: Qnil
;
2331 DEFUN
("x
-display
-pixel
-width"
, Fx_display_pixel_width
, Sx_display_pixel_width
,
2333 doc: /* Return the width in pixels of the Nextstep display TERMINAL.
2334 The optional argument TERMINAL specifies which display to ask about.
2335 TERMINAL should be a terminal object, a frame or a display name (a string).
2336 If omitted or nil, that stands for the selected frame's display.
2338 On \"multi-monitor\" setups this refers to the pixel width for all
2339 physical monitors associated with TERMINAL. To get information for
2340 each physical monitor, use `display-monitor-attributes-list'. */)
2341 (Lisp_Object
terminal)
2343 struct ns_display_info
*dpyinfo
= check_ns_display_info
(terminal);
2345 return make_number
(x_display_pixel_width
(dpyinfo
));
2349 DEFUN
("x
-display
-pixel
-height"
, Fx_display_pixel_height
,
2350 Sx_display_pixel_height
, 0, 1, 0,
2351 doc: /* Return the height in pixels of the Nextstep display TERMINAL.
2352 The optional argument TERMINAL specifies which display to ask about.
2353 TERMINAL should be a terminal object, a frame or a display name (a string).
2354 If omitted or nil, that stands for the selected frame's display.
2356 On \"multi-monitor\" setups this refers to the pixel height for all
2357 physical monitors associated with TERMINAL. To get information for
2358 each physical monitor, use `display-monitor-attributes-list'. */)
2359 (Lisp_Object
terminal)
2361 struct ns_display_info
*dpyinfo
= check_ns_display_info
(terminal);
2363 return make_number
(x_display_pixel_height
(dpyinfo
));
2366 #ifdef NS_IMPL_COCOA
2367 /* Returns the name for the screen that DICT came from, or NULL.
2368 Caller must free return value.
2372 ns_screen_name
(CGDirectDisplayID did
)
2375 NSDictionary
*info = (NSDictionary
*)
2376 IODisplayCreateInfoDictionary
(CGDisplayIOServicePort
(did
),
2377 kIODisplayOnlyPreferredName
);
2379 = [info objectForKey
:
2380 [NSString stringWithUTF8String
:kDisplayProductName
]];
2382 if ([names count
] > 0) {
2383 NSString
*n
= [names objectForKey
: [[names allKeys
] objectAtIndex
:0]];
2385 name
= xstrdup
([n UTF8String
]);
2394 ns_make_monitor_attribute_list
(struct MonitorInfo
*monitors
,
2396 int primary_monitor
,
2399 Lisp_Object monitor_frames
= Fmake_vector
(make_number
(n_monitors
), Qnil
);
2400 Lisp_Object frame
, rest
;
2401 NSArray
*screens
= [NSScreen screens
];
2404 FOR_EACH_FRAME
(rest
, frame
)
2406 struct frame
*f
= XFRAME
(frame
);
2410 NSView
*view = FRAME_NS_VIEW
(f
);
2411 NSScreen
*screen
= [[view window
] screen
];
2415 for (k
= 0; i
== -1 && k
< [screens count
]; ++k
)
2417 if ([screens objectAtIndex
: k
] == screen
)
2422 ASET
(monitor_frames
, i
, Fcons
(frame
, AREF
(monitor_frames
, i
)));
2426 return make_monitor_attribute_list
(monitors
, n_monitors
, primary_monitor
,
2427 monitor_frames
, source
);
2430 DEFUN
("ns
-display
-monitor
-attributes
-list"
,
2431 Fns_display_monitor_attributes_list
,
2432 Sns_display_monitor_attributes_list
,
2434 doc: /* Return a list of physical monitor attributes on the X display TERMINAL.
2436 The optional argument TERMINAL specifies which display to ask about.
2437 TERMINAL should be a terminal object, a frame or a display name (a string).
2438 If omitted or nil, that stands for the selected frame's display.
2440 In addition to the standard attribute keys listed in
2441 `display-monitor-attributes-list', the following keys are contained in
2444 source -- String describing the source from which multi-monitor
2445 information is obtained, \"NS\" is always the source."
2447 Internal use only, use `display-monitor-attributes-list' instead. */)
2448 (Lisp_Object
terminal)
2450 struct terminal *term
= get_terminal
(terminal, 1);
2452 NSUInteger i
, n_monitors
;
2453 struct MonitorInfo
*monitors
;
2454 Lisp_Object attributes_list
= Qnil
;
2455 CGFloat primary_display_height
= 0;
2457 if (term
->type != output_ns
)
2460 screens
= [NSScreen screens
];
2461 n_monitors
= [screens count
];
2462 if (n_monitors
== 0)
2465 monitors
= xzalloc
(n_monitors
* sizeof
*monitors
);
2467 for (i
= 0; i
< [screens count
]; ++i
)
2469 NSScreen
*s
= [screens objectAtIndex
:i
];
2470 struct MonitorInfo
*m
= &monitors
[i
];
2471 NSRect fr
= [s frame
];
2472 NSRect vfr
= [s visibleFrame
];
2475 #ifdef NS_IMPL_COCOA
2476 NSDictionary
*dict
= [s deviceDescription
];
2477 NSNumber
*nid
= [dict objectForKey
:@"NSScreenNumber"
];
2478 CGDirectDisplayID did
= [nid unsignedIntValue
];
2482 primary_display_height
= fr.
size.height
;
2483 y
= (short
) fr.origin.y
;
2484 vy
= (short
) vfr.origin.y
;
2488 // Flip y coordinate as NS has y starting from the bottom.
2489 y
= (short
) (primary_display_height
- fr.
size.height
- fr.origin.y
);
2490 vy
= (short
) (primary_display_height
-
2491 vfr.
size.height
- vfr.origin.y
);
2494 m
->geom.x
= (short
) fr.origin.x
;
2496 m
->geom.width
= (unsigned short
) fr.
size.width
;
2497 m
->geom.height
= (unsigned short
) fr.
size.height
;
2499 m
->work.x
= (short
) vfr.origin.x
;
2500 // y is flipped on NS
, so vy
- y are pixels missing at the bottom
,
2501 // and fr.
size.height
- vfr.
size.height are pixels missing in total.
2502 // Pixels missing at top are
2503 // fr.
size.height
- vfr.
size.height
- vy
+ y.
2504 // work.y is then pixels missing at top
+ y.
2505 m
->work.y
= (short
) (fr.
size.height
- vfr.
size.height
) - vy
+ y
+ y
;
2506 m
->work.width
= (unsigned short
) vfr.
size.width
;
2507 m
->work.height
= (unsigned short
) vfr.
size.height
;
2509 #ifdef NS_IMPL_COCOA
2510 m
->name
= ns_screen_name
(did
);
2513 CGSize mms
= CGDisplayScreenSize
(did
);
2514 m
->mm_width
= (int
) mms.width
;
2515 m
->mm_height
= (int
) mms.height
;
2519 // Assume
92 dpi as x
-display
-mm
-height
/x
-display
-mm
-width does.
2520 m
->mm_width
= (int
) (25.4 * fr.
size.width
/ 92.0);
2521 m
->mm_height
= (int
) (25.4 * fr.
size.height
/ 92.0);
2525 // Primary monitor is always first
for NS.
2526 attributes_list
= ns_make_monitor_attribute_list
(monitors
, n_monitors
,
2529 free_monitors
(monitors
, n_monitors
);
2530 return attributes_list
;
2534 DEFUN
("x
-display
-planes"
, Fx_display_planes
, Sx_display_planes
,
2536 doc: /* Return the number of bitplanes of the Nextstep display TERMINAL.
2537 The optional argument TERMINAL specifies which display to ask about.
2538 TERMINAL should be a terminal object, a frame or a display name (a string).
2539 If omitted or nil, that stands for the selected frame's display. */)
2540 (Lisp_Object
terminal)
2542 check_ns_display_info
(terminal);
2544 (NSBitsPerPixelFromDepth
([[[NSScreen screens
] objectAtIndex
:0] depth
]));
2548 DEFUN
("x
-display
-color
-cells"
, Fx_display_color_cells
, Sx_display_color_cells
,
2550 doc: /* Returns the number of color cells of the Nextstep display TERMINAL.
2551 The optional argument TERMINAL specifies which display to ask about.
2552 TERMINAL should be a terminal object, a frame or a display name (a string).
2553 If omitted or nil, that stands for the selected frame's display. */)
2554 (Lisp_Object
terminal)
2556 struct ns_display_info
*dpyinfo
= check_ns_display_info
(terminal);
2557 /* We force 24+ bit depths to 24-bit to prevent an overflow. */
2558 return make_number
(1 << min (dpyinfo
->n_planes
, 24));
2562 /* Unused dummy def needed for compatibility. */
2563 Lisp_Object tip_frame
;
2565 /* TODO: move to xdisp or similar */
2567 compute_tip_xy
(struct frame
*f
,
2576 Lisp_Object left
, top
;
2577 EmacsView
*view = FRAME_NS_VIEW
(f
);
2578 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(f
);
2581 /* Start with user-specified or mouse position. */
2582 left
= Fcdr
(Fassq
(Qleft
, parms
));
2583 top
= Fcdr
(Fassq
(Qtop
, parms
));
2585 if (!INTEGERP
(left
) ||
!INTEGERP
(top
))
2587 pt.x
= dpyinfo
->last_mouse_motion_x
;
2588 pt.y
= dpyinfo
->last_mouse_motion_y
;
2589 /* Convert to screen coordinates */
2590 pt
= [view convertPoint
: pt toView
: nil
];
2591 pt
= [[view window
] convertBaseToScreen
: pt
];
2595 /* Absolute coordinates. */
2597 pt.y
= x_display_pixel_height
(FRAME_DISPLAY_INFO
(f
)) - XINT
(top
)
2601 /* Ensure in bounds. (Note, screen origin = lower left.) */
2602 if (INTEGERP
(left
))
2604 else if (pt.x
+ XINT
(dx
) <= 0)
2605 *root_x
= 0; /* Can happen for negative dx */
2606 else if (pt.x
+ XINT
(dx
) + width
2607 <= x_display_pixel_width
(FRAME_DISPLAY_INFO
(f
)))
2608 /* It fits to the right of the pointer. */
2609 *root_x
= pt.x
+ XINT
(dx
);
2610 else if (width
+ XINT
(dx
) <= pt.x
)
2611 /* It fits to the left of the pointer. */
2612 *root_x
= pt.x
- width
- XINT
(dx
);
2614 /* Put it left justified on the screen -- it ought to fit that way. */
2619 else if (pt.y
- XINT
(dy
) - height
>= 0)
2620 /* It fits below the pointer. */
2621 *root_y
= pt.y
- height
- XINT
(dy
);
2622 else if (pt.y
+ XINT
(dy
) + height
2623 <= x_display_pixel_height
(FRAME_DISPLAY_INFO
(f
)))
2624 /* It fits above the pointer */
2625 *root_y
= pt.y
+ XINT
(dy
);
2627 /* Put it on the top. */
2628 *root_y
= x_display_pixel_height
(FRAME_DISPLAY_INFO
(f
)) - height
;
2632 DEFUN
("x
-show
-tip"
, Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
2633 doc: /* Show STRING in a \"tooltip\" window on frame FRAME.
2634 A tooltip window is a small window displaying a string.
2636 This is an internal function; Lisp code should call `tooltip-show'.
2638 FRAME nil or omitted means use the selected frame.
2640 PARMS is an optional list of frame parameters which can be used to
2641 change the tooltip's appearance.
2643 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
2644 means use the default timeout of 5 seconds.
2646 If the list of frame parameters PARMS contains a `left' parameter,
2647 the tooltip is displayed at that x-position. Otherwise it is
2648 displayed at the mouse position, with offset DX added (default is 5 if
2649 DX isn't specified). Likewise for the y-position; if a `top' frame
2650 parameter is specified, it determines the y-position of the tooltip
2651 window, otherwise it is displayed at the mouse position, with offset
2652 DY added (default is -10).
2654 A tooltip's maximum size is specified by `x-max-tooltip-size'.
2655 Text larger than the specified size is clipped. */)
2656 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
2659 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2660 ptrdiff_t count
= SPECPDL_INDEX
();
2665 specbind
(Qinhibit_redisplay
, Qt
);
2667 GCPRO4
(string
, parms
, frame
, timeout
);
2669 CHECK_STRING
(string
);
2670 str
= SSDATA
(string
);
2671 f
= decode_window_system_frame
(frame
);
2673 timeout
= make_number
(5);
2675 CHECK_NATNUM
(timeout
);
2678 dx
= make_number
(5);
2683 dy
= make_number
(-10);
2688 if (ns_tooltip
== nil
)
2689 ns_tooltip
= [[EmacsTooltip alloc
] init
];
2693 [ns_tooltip setText
: str
];
2694 size = [ns_tooltip frame
].
size;
2696 /* Move the tooltip window where the mouse pointer is. Resize and
2698 compute_tip_xy
(f
, parms
, dx
, dy
, (int
)size.width
, (int
)size.height
,
2701 [ns_tooltip showAtX
: root_x Y
: root_y
for: XINT
(timeout
)];
2705 return unbind_to
(count
, Qnil
);
2709 DEFUN
("x
-hide
-tip"
, Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
2710 doc: /* Hide the current tooltip window, if there is any.
2711 Value is t if tooltip was open, nil otherwise. */)
2714 if (ns_tooltip
== nil ||
![ns_tooltip isActive
])
2721 /* ==========================================================================
2723 Class implementations
2725 ========================================================================== */
2728 Handle arrow/function/control keys and copy/paste/cut in file dialogs.
2729 Return YES if handled, NO if not.
2732 handlePanelKeys
(NSSavePanel
*panel
, NSEvent
*theEvent
)
2738 if ([theEvent
type] != NSKeyDown
) return NO
;
2739 s
= [theEvent characters
];
2741 for (i
= 0; i
< [s
length]; ++i
)
2743 int ch
= (int
) [s characterAtIndex
: i
];
2746 case NSHomeFunctionKey
:
2747 case NSDownArrowFunctionKey
:
2748 case NSUpArrowFunctionKey
:
2749 case NSLeftArrowFunctionKey
:
2750 case NSRightArrowFunctionKey
:
2751 case NSPageUpFunctionKey
:
2752 case NSPageDownFunctionKey
:
2753 case NSEndFunctionKey
:
2754 /* Don't send command modified keys, as those are handled in the
2755 performKeyEquivalent method of the super class.
2757 if (! ([theEvent modifierFlags
] & NSCommandKeyMask
))
2759 [panel sendEvent
: theEvent
];
2763 /* As we don't have the standard key commands for
2764 copy/paste/cut/select-all in our edit menu, we must handle
2765 them here. TODO: handle Emacs key bindings for copy/cut/select-all
2766 here, paste works, because we have that in our Edit menu.
2767 I.e. refactor out code in nsterm.m, keyDown: to figure out the
2773 case 'a': // Select
all
2774 if ([theEvent modifierFlags
] & NSCommandKeyMask
)
2783 : @selector
(selectAll
:))))
2788 // Send
all control keys
, as the
text field supports C
-a
, C
-f
, C
-e
2790 if ([theEvent modifierFlags
] & NSControlKeyMask
)
2792 [panel sendEvent
: theEvent
];
2803 @implementation EmacsSavePanel
2804 - (BOOL
)performKeyEquivalent
:(NSEvent
*)theEvent
2806 BOOL ret
= handlePanelKeys
(self
, theEvent
);
2808 ret
= [super performKeyEquivalent
:theEvent
];
2814 @implementation EmacsOpenPanel
2815 - (BOOL
)performKeyEquivalent
:(NSEvent
*)theEvent
2817 // NSOpenPanel inherits NSSavePanel
, so passing self is OK.
2818 BOOL ret
= handlePanelKeys
(self
, theEvent
);
2820 ret
= [super performKeyEquivalent
:theEvent
];
2826 @implementation EmacsFileDelegate
2827 /* --------------------------------------------------------------------------
2828 Delegate methods for Open/Save panels
2829 -------------------------------------------------------------------------- */
2830 - (BOOL
)panel
: (id
)sender isValidFilename
: (NSString
*)filename
2834 - (BOOL
)panel
: (id
)sender shouldShowFilename
: (NSString
*)filename
2838 - (NSString
*)panel
: (id
)sender userEnteredFilename
: (NSString
*)filename
2839 confirmed
: (BOOL
)okFlag
2848 /* ==========================================================================
2850 Lisp interface declaration
2852 ========================================================================== */
2856 syms_of_nsfns
(void
)
2858 Qfontsize
= intern_c_string
("fontsize"
);
2859 staticpro
(&Qfontsize
);
2861 DEFVAR_LISP
("ns
-icon
-type-alist"
, Vns_icon_type_alist
,
2862 doc: /* Alist of elements (REGEXP . IMAGE) for images of icons associated to frames.
2863 If the title of a frame matches REGEXP, then IMAGE.tiff is
2864 selected as the image of the icon representing the frame when it's
2865 miniaturized. If an element is t, then Emacs tries to select an icon
2866 based on the filetype of the visited file.
2868 The images have to be installed in a folder called English.lproj in the
2869 Emacs folder. You have to restart Emacs after installing new icons.
2871 Example: Install an icon Gnus.tiff and execute the following code
2873 (setq ns-icon-type-alist
2874 (append ns-icon-type-alist
2875 '((\"^\\\\*\\\\(Group\\\\*$\\\\|Summary \\\\|Article\\\\*$\\\\)\"
2878 When you miniaturize a Group, Summary or Article frame, Gnus.tiff will
2879 be used as the image of the icon representing the frame. */);
2880 Vns_icon_type_alist
= list1
(Qt
);
2882 DEFVAR_LISP
("ns
-version-string"
, Vns_version_string
,
2883 doc: /* Toolkit version for NS Windowing. */);
2884 Vns_version_string
= ns_appkit_version_str
();
2886 defsubr
(&Sns_read_file_name
);
2887 defsubr
(&Sns_get_resource
);
2888 defsubr
(&Sns_set_resource
);
2889 defsubr
(&Sxw_display_color_p
); /* this and next called directly by C code */
2890 defsubr
(&Sx_display_grayscale_p
);
2891 defsubr
(&Sns_font_name
);
2892 defsubr
(&Sns_list_colors
);
2893 #ifdef NS_IMPL_COCOA
2894 defsubr
(&Sns_do_applescript
);
2896 defsubr
(&Sxw_color_defined_p
);
2897 defsubr
(&Sxw_color_values
);
2898 defsubr
(&Sx_server_max_request_size
);
2899 defsubr
(&Sx_server_vendor
);
2900 defsubr
(&Sx_server_version
);
2901 defsubr
(&Sx_display_pixel_width
);
2902 defsubr
(&Sx_display_pixel_height
);
2903 defsubr
(&Sns_display_monitor_attributes_list
);
2904 defsubr
(&Sx_display_mm_width
);
2905 defsubr
(&Sx_display_mm_height
);
2906 defsubr
(&Sx_display_screens
);
2907 defsubr
(&Sx_display_planes
);
2908 defsubr
(&Sx_display_color_cells
);
2909 defsubr
(&Sx_display_visual_class
);
2910 defsubr
(&Sx_display_backing_store
);
2911 defsubr
(&Sx_display_save_under
);
2912 defsubr
(&Sx_create_frame
);
2913 defsubr
(&Sx_open_connection
);
2914 defsubr
(&Sx_close_connection
);
2915 defsubr
(&Sx_display_list
);
2917 defsubr
(&Sns_hide_others
);
2918 defsubr
(&Sns_hide_emacs
);
2919 defsubr
(&Sns_emacs_info_panel
);
2920 defsubr
(&Sns_list_services
);
2921 defsubr
(&Sns_perform_service
);
2922 defsubr
(&Sns_convert_utf8_nfd_to_nfc
);
2923 defsubr
(&Sns_popup_font_panel
);
2924 defsubr
(&Sns_popup_color_panel
);
2926 defsubr
(&Sx_show_tip
);
2927 defsubr
(&Sx_hide_tip
);