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
)
178 struct ns_display_info
*dpyinfo
;
182 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
183 if (!NILP
(Fstring_equal
(XCAR
(dpyinfo
->name_list_element
), name
)))
186 error ("Emacs
for OpenStep does not yet support multi
-display."
);
188 Fx_open_connection
(name
, Qnil
, Qnil
);
189 dpyinfo
= x_display_list
;
192 error ("OpenStep on
%s not responding.\n", SDATA (name));
198 ns_filename_from_panel
(NSSavePanel
*panel
)
200 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
201 NSURL
*url
= [panel URL
];
202 NSString
*str
= [url
path];
205 return [panel filename
];
210 ns_directory_from_panel
(NSSavePanel
*panel
)
212 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
213 NSURL
*url
= [panel directoryURL
];
214 NSString
*str
= [url
path];
217 return [panel directory
];
222 interpret_services_menu
(NSMenu
*menu, Lisp_Object prefix
, Lisp_Object old
)
223 /* --------------------------------------------------------------------------
224 Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
225 -------------------------------------------------------------------------- */
235 count
= [menu numberOfItems
];
236 for (i
= 0; i
<count
; i
++)
238 item
= [menu itemAtIndex
: i
];
239 name
= [[item
title] UTF8String
];
242 nameStr
= build_string
(name
);
244 if ([item hasSubmenu
])
246 old
= interpret_services_menu
([item submenu
],
247 Fcons
(nameStr
, prefix
), old
);
251 keys
= [item keyEquivalent
];
252 if (keys
&& [keys
length] )
254 key
= [keys characterAtIndex
: 0];
255 res
= make_number
(key|super_modifier
);
261 old
= Fcons
(Fcons
(res
,
262 Freverse
(Fcons
(nameStr
,
272 /* ==========================================================================
274 Frame parameter setters
276 ========================================================================== */
280 x_set_foreground_color
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
283 EmacsCGFloat r
, g
, b
, alpha
;
285 if (ns_lisp_to_color
(arg
, &col
))
287 store_frame_param
(f
, Qforeground_color
, oldval
);
288 error ("Unknown color"
);
292 [f
->output_data.ns
->foreground_color release
];
293 f
->output_data.ns
->foreground_color
= col
;
295 [col getRed
: &r green
: &g blue
: &b alpha
: &alpha
];
296 FRAME_FOREGROUND_PIXEL
(f
) =
297 ARGB_TO_ULONG
((int
)(alpha
*0xff), (int
)(r
*0xff), (int
)(g
*0xff), (int
)(b
*0xff));
299 if (FRAME_NS_VIEW
(f
))
301 update_face_from_frame_parameter
(f
, Qforeground_color
, arg
);
302 /*recompute_basic_faces (f); */
303 if (FRAME_VISIBLE_P
(f
))
310 x_set_background_color
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
314 NSView
*view = FRAME_NS_VIEW
(f
);
315 EmacsCGFloat r
, g
, b
, alpha
;
317 if (ns_lisp_to_color
(arg
, &col
))
319 store_frame_param
(f
, Qbackground_color
, oldval
);
320 error ("Unknown color"
);
323 /* clear the frame; in some instances the NS-internal GC appears not to
324 update, or it does update and cannot clear old text properly */
325 if (FRAME_VISIBLE_P
(f
))
329 [f
->output_data.ns
->background_color release
];
330 f
->output_data.ns
->background_color
= col
;
332 [col getRed
: &r green
: &g blue
: &b alpha
: &alpha
];
333 FRAME_BACKGROUND_PIXEL
(f
) =
334 ARGB_TO_ULONG
((int
)(alpha
*0xff), (int
)(r
*0xff), (int
)(g
*0xff), (int
)(b
*0xff));
338 [[view window
] setBackgroundColor
: col
];
340 if (alpha
!= (EmacsCGFloat
) 1.0)
341 [[view window
] setOpaque
: NO
];
343 [[view window
] setOpaque
: YES
];
345 face
= FRAME_DEFAULT_FACE
(f
);
348 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
);
349 face
->background
= ns_index_color
350 ([col colorWithAlphaComponent
: alpha
], f
);
352 update_face_from_frame_parameter
(f
, Qbackground_color
, arg
);
355 if (FRAME_VISIBLE_P
(f
))
362 x_set_cursor_color
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
366 if (ns_lisp_to_color
(arg
, &col
))
368 store_frame_param
(f
, Qcursor_color
, oldval
);
369 error ("Unknown color"
);
372 [FRAME_CURSOR_COLOR
(f
) release
];
373 FRAME_CURSOR_COLOR
(f
) = [col retain
];
375 if (FRAME_VISIBLE_P
(f
))
377 x_update_cursor
(f
, 0);
378 x_update_cursor
(f
, 1);
380 update_face_from_frame_parameter
(f
, Qcursor_color
, arg
);
385 x_set_icon_name
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
387 NSView
*view = FRAME_NS_VIEW
(f
);
388 NSTRACE
(x_set_icon_name
);
390 /* see if it's changed */
393 if (STRINGP
(oldval
) && EQ
(Fstring_equal
(oldval
, arg
), Qt
))
396 else if (!STRINGP
(oldval
) && EQ
(oldval
, Qnil
) == EQ
(arg
, Qnil
))
399 fset_icon_name
(f
, arg
);
403 if (!NILP
(f
->title))
406 /* explicit name and no icon-name -> explicit_name */
407 if (f
->explicit_name
)
411 /* no explicit name and no icon-name ->
412 name has to be rebuild from icon_title_format */
413 windows_or_buffers_changed
++;
418 /* Don't change the name if it's already NAME. */
419 if ([[view window
] miniwindowTitle
] &&
420 ([[[view window
] miniwindowTitle
]
421 isEqualToString
: [NSString stringWithUTF8String
:
425 [[view window
] setMiniwindowTitle
:
426 [NSString stringWithUTF8String
: SSDATA
(arg
)]];
430 ns_set_name_internal
(struct frame
*f
, Lisp_Object name
)
433 Lisp_Object encoded_name
, encoded_icon_name
;
435 NSView
*view = FRAME_NS_VIEW
(f
);
438 encoded_name
= ENCODE_UTF_8
(name
);
441 str
= [NSString stringWithUTF8String
: SSDATA
(encoded_name
)];
443 /* Don't change the name if it's already NAME. */
444 if (! [[[view window
] title] isEqualToString
: str
])
445 [[view window
] setTitle
: str
];
447 if (!STRINGP
(f
->icon_name
))
448 encoded_icon_name
= encoded_name
;
450 encoded_icon_name
= ENCODE_UTF_8
(f
->icon_name
);
452 str
= [NSString stringWithUTF8String
: SSDATA
(encoded_icon_name
)];
454 if ([[view window
] miniwindowTitle
] &&
455 ! [[[view window
] miniwindowTitle
] isEqualToString
: str
])
456 [[view window
] setMiniwindowTitle
: str
];
461 ns_set_name
(struct frame
*f
, Lisp_Object name
, int explicit
)
463 NSTRACE
(ns_set_name
);
465 /* Make sure that requests from lisp code override requests from
466 Emacs redisplay code. */
469 /* If we're switching from explicit to implicit, we had better
470 update the mode lines and thereby update the title. */
471 if (f
->explicit_name
&& NILP
(name
))
472 update_mode_lines
= 1;
474 f
->explicit_name
= ! NILP
(name
);
476 else if (f
->explicit_name
)
480 name
= build_string
([ns_app_name UTF8String
]);
484 /* Don't change the name if it's already NAME. */
485 if (! NILP
(Fstring_equal
(name
, f
->name
)))
490 /* title overrides explicit name */
491 if (! NILP
(f
->title))
494 ns_set_name_internal
(f
, name
);
498 /* This function should be called when the user's lisp code has
499 specified a name for the frame; the name will override any set by the
502 x_explicitly_set_name
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
504 NSTRACE
(x_explicitly_set_name
);
505 ns_set_name
(f
, arg
, 1);
509 /* This function should be called by Emacs redisplay code to set the
510 name; names set this way will never override names set by the user's
513 x_implicitly_set_name
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
515 NSTRACE
(x_implicitly_set_name
);
517 /* Deal with NS specific format t. */
518 if (FRAME_NS_P
(f
) && ((FRAME_ICONIFIED_P
(f
) && EQ
(Vicon_title_format
, Qt
))
519 || EQ
(Vframe_title_format
, Qt
)))
520 ns_set_name_as_filename
(f
);
522 ns_set_name
(f
, arg
, 0);
526 /* Change the title of frame F to NAME.
527 If NAME is nil, use the frame name as the title. */
530 x_set_title
(struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
532 NSTRACE
(x_set_title
);
533 /* Don't change the title if it's already NAME. */
534 if (EQ
(name
, f
->title))
537 update_mode_lines
= 1;
539 fset_title
(f
, name
);
546 ns_set_name_internal
(f
, name
);
551 ns_set_name_as_filename
(struct frame
*f
)
554 Lisp_Object name
, filename
;
555 Lisp_Object buf
= XWINDOW
(f
->selected_window
)->contents
;
557 NSAutoreleasePool
*pool
;
559 Lisp_Object encoded_name
, encoded_filename
;
561 NSTRACE
(ns_set_name_as_filename
);
563 if (f
->explicit_name ||
! NILP
(f
->title))
567 pool
= [[NSAutoreleasePool alloc
] init
];
568 filename
= BVAR
(XBUFFER
(buf
), filename
);
569 name
= BVAR
(XBUFFER
(buf
), name
);
573 if (! NILP
(filename
))
574 name
= Ffile_name_nondirectory
(filename
);
576 name
= build_string
([ns_app_name UTF8String
]);
580 encoded_name
= ENCODE_UTF_8
(name
);
583 view = FRAME_NS_VIEW
(f
);
585 title = FRAME_ICONIFIED_P
(f
) ?
[[[view window
] miniwindowTitle
] UTF8String
]
586 : [[[view window
] title] UTF8String
];
588 if (title && (! strcmp (title, SSDATA
(encoded_name
))))
595 str
= [NSString stringWithUTF8String
: SSDATA
(encoded_name
)];
596 if (str
== nil
) str
= @"Bad coding"
;
598 if (FRAME_ICONIFIED_P
(f
))
599 [[view window
] setMiniwindowTitle
: str
];
604 if (! NILP
(filename
))
607 encoded_filename
= ENCODE_UTF_8
(filename
);
610 fstr
= [NSString stringWithUTF8String
: SSDATA
(encoded_filename
)];
611 if (fstr
== nil
) fstr
= @""
;
613 /* work around a bug observed on 10.3 and later where
614 setTitleWithRepresentedFilename does not clear out previous state
615 if given filename does not exist */
616 if (! [[NSFileManager defaultManager
] fileExistsAtPath
: fstr
])
617 [[view window
] setRepresentedFilename
: @""
];
623 [[view window
] setRepresentedFilename
: fstr
];
624 [[view window
] setTitle
: str
];
634 ns_set_doc_edited
(struct frame
*f
, Lisp_Object arg
)
636 NSView
*view = FRAME_NS_VIEW
(f
);
637 NSAutoreleasePool
*pool
;
638 if (!MINI_WINDOW_P
(XWINDOW
(f
->selected_window
)))
641 pool
= [[NSAutoreleasePool alloc
] init
];
642 [[view window
] setDocumentEdited
: !NILP
(arg
)];
650 x_set_menu_bar_lines
(struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
653 if (FRAME_MINIBUF_ONLY_P
(f
))
656 if (TYPE_RANGED_INTEGERP
(int
, value
))
657 nlines
= XINT
(value
);
661 FRAME_MENU_BAR_LINES
(f
) = 0;
664 FRAME_EXTERNAL_MENU_BAR
(f
) = 1;
665 /* does for all frames, whereas we just want for one frame
666 [NSMenu setMenuBarVisible: YES]; */
670 if (FRAME_EXTERNAL_MENU_BAR
(f
) == 1)
671 free_frame_menubar
(f
);
672 /* [NSMenu setMenuBarVisible: NO]; */
673 FRAME_EXTERNAL_MENU_BAR
(f
) = 0;
678 /* toolbar support */
680 x_set_tool_bar_lines
(struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
684 if (FRAME_MINIBUF_ONLY_P
(f
))
687 if (RANGED_INTEGERP
(0, value
, INT_MAX
))
688 nlines
= XFASTINT
(value
);
694 FRAME_EXTERNAL_TOOL_BAR
(f
) = 1;
695 update_frame_tool_bar
(f
);
699 if (FRAME_EXTERNAL_TOOL_BAR
(f
))
701 free_frame_tool_bar
(f
);
702 FRAME_EXTERNAL_TOOL_BAR
(f
) = 0;
706 x_set_window_size
(f
, 0, f
->text_cols
, f
->text_lines
);
711 ns_implicitly_set_icon_type
(struct frame
*f
)
714 EmacsView
*view = FRAME_NS_VIEW
(f
);
716 Lisp_Object chain
, elt
;
717 NSAutoreleasePool
*pool
;
720 NSTRACE
(ns_implicitly_set_icon_type
);
723 pool
= [[NSAutoreleasePool alloc
] init
];
724 if (f
->output_data.ns
->miniimage
725 && [[NSString stringWithUTF8String
: SSDATA
(f
->name
)]
726 isEqualToString
: [(NSImage
*)f
->output_data.ns
->miniimage name
]])
733 tem
= assq_no_quit
(Qicon_type
, f
->param_alist
);
734 if (CONSP
(tem
) && ! NILP
(XCDR
(tem
)))
741 for (chain
= Vns_icon_type_alist
;
742 image == nil
&& CONSP
(chain
);
743 chain
= XCDR
(chain
))
746 /* special case: 't' means go by file type */
747 if (SYMBOLP
(elt
) && EQ
(elt
, Qt
) && SSDATA
(f
->name
)[0] == '/')
750 = [NSString stringWithUTF8String
: SSDATA
(f
->name
)];
751 if ([[NSFileManager defaultManager
] fileExistsAtPath
: str
])
752 image = [[[NSWorkspace sharedWorkspace
] iconForFile
: str
] retain
];
754 else if (CONSP
(elt
) &&
755 STRINGP
(XCAR
(elt
)) &&
756 STRINGP
(XCDR
(elt
)) &&
757 fast_string_match
(XCAR
(elt
), f
->name
) >= 0)
759 image = [EmacsImage allocInitFromFile
: XCDR
(elt
)];
761 image = [[NSImage imageNamed
:
762 [NSString stringWithUTF8String
:
763 SSDATA
(XCDR
(elt
))]] retain
];
769 image = [[[NSWorkspace sharedWorkspace
] iconForFileType
: @"
text"
] retain
];
773 [f
->output_data.ns
->miniimage release
];
774 f
->output_data.ns
->miniimage
= image;
775 [view setMiniwindowImage
: setMini
];
782 x_set_icon_type
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
784 EmacsView
*view = FRAME_NS_VIEW
(f
);
788 NSTRACE
(x_set_icon_type
);
790 if (!NILP
(arg
) && SYMBOLP
(arg
))
792 arg
=build_string
(SSDATA
(SYMBOL_NAME
(arg
)));
793 store_frame_param
(f
, Qicon_type
, arg
);
796 /* do it the implicit way */
799 ns_implicitly_set_icon_type
(f
);
805 image = [EmacsImage allocInitFromFile
: arg
];
807 image =[NSImage imageNamed
: [NSString stringWithUTF8String
:
812 image = [NSImage imageNamed
: @"
text"
];
816 f
->output_data.ns
->miniimage
= image;
817 [view setMiniwindowImage
: setMini
];
821 /* TODO: move to nsterm? */
823 ns_lisp_to_cursor_type
(Lisp_Object arg
)
826 if (XTYPE
(arg
) == Lisp_String
)
828 else if (XTYPE
(arg
) == Lisp_Symbol
)
829 str
= SSDATA
(SYMBOL_NAME
(arg
));
831 if (!strcmp (str
, "box"
)) return FILLED_BOX_CURSOR
;
832 if (!strcmp (str
, "hollow"
)) return HOLLOW_BOX_CURSOR
;
833 if (!strcmp (str
, "hbar"
)) return HBAR_CURSOR
;
834 if (!strcmp (str
, "
bar"
)) return BAR_CURSOR
;
835 if (!strcmp (str
, "no"
)) return NO_CURSOR
;
841 ns_cursor_type_to_lisp
(int arg
)
845 case FILLED_BOX_CURSOR
: return Qbox
;
846 case HOLLOW_BOX_CURSOR
: return intern
("hollow"
);
847 case HBAR_CURSOR
: return intern
("hbar"
);
848 case BAR_CURSOR
: return intern
("
bar"
);
850 default
: return intern
("no"
);
854 /* This is the same as the xfns.c definition. */
856 x_set_cursor_type
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
858 set_frame_cursor_types
(f
, arg
);
861 /* called to set mouse pointer color, but all other terms use it to
862 initialize pointer types (and don't set the color ;) */
864 x_set_mouse_color
(struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
866 /* don't think we can do this on Nextstep */
871 #define Xstr
(x
) Str
(x
)
874 ns_appkit_version_str
(void
)
878 #ifdef NS_IMPL_GNUSTEP
879 sprintf(tmp
, "gnustep
-gui
-%s", Xstr(GNUSTEP_GUI_VERSION));
880 #elif defined
(NS_IMPL_COCOA
)
881 sprintf(tmp
, "apple
-appkit
-%.2f", NSAppKitVersionNumber);
885 return build_string
(tmp
);
889 /* This is for use by x-server-version and collapses all version info we
890 have into a single int. For a better picture of the implementation
891 running, use ns_appkit_version_str.*/
893 ns_appkit_version_int
(void
)
895 #ifdef NS_IMPL_GNUSTEP
896 return GNUSTEP_GUI_MAJOR_VERSION
* 100 + GNUSTEP_GUI_MINOR_VERSION
;
897 #elif defined
(NS_IMPL_COCOA
)
898 return (int
)NSAppKitVersionNumber
;
905 x_icon
(struct frame
*f
, Lisp_Object parms
)
906 /* --------------------------------------------------------------------------
907 Strangely-named function to set icon position parameters in frame.
908 This is irrelevant under OS X, but might be needed under GNUstep,
909 depending on the window manager used. Note, this is not a standard
910 frame parameter-setter; it is called directly from x-create-frame.
911 -------------------------------------------------------------------------- */
913 Lisp_Object icon_x
, icon_y
;
914 struct ns_display_info
*dpyinfo
= check_ns_display_info
(Qnil
);
916 f
->output_data.ns
->icon_top
= Qnil
;
917 f
->output_data.ns
->icon_left
= Qnil
;
919 /* Set the position of the icon. */
920 icon_x
= x_get_arg
(dpyinfo
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
921 icon_y
= x_get_arg
(dpyinfo
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
922 if (!EQ
(icon_x
, Qunbound
) && !EQ
(icon_y
, Qunbound
))
924 CHECK_NUMBER
(icon_x
);
925 CHECK_NUMBER
(icon_y
);
926 f
->output_data.ns
->icon_top
= icon_y
;
927 f
->output_data.ns
->icon_left
= icon_x
;
929 else if (!EQ
(icon_x
, Qunbound
) ||
!EQ
(icon_y
, Qunbound
))
930 error ("Both left and top icon corners of icon must be specified"
);
934 /* Note: see frame.c for template, also where generic functions are impl */
935 frame_parm_handler ns_frame_parm_handlers
[] =
937 x_set_autoraise
, /* generic OK */
938 x_set_autolower
, /* generic OK */
939 x_set_background_color
,
940 0, /* x_set_border_color, may be impossible under Nextstep */
941 0, /* x_set_border_width, may be impossible under Nextstep */
944 x_set_font
, /* generic OK */
945 x_set_foreground_color
,
948 x_set_internal_border_width
, /* generic OK */
949 x_set_menu_bar_lines
,
951 x_explicitly_set_name
,
952 x_set_scroll_bar_width
, /* generic OK */
954 x_set_unsplittable
, /* generic OK */
955 x_set_vertical_scroll_bars
, /* generic OK */
956 x_set_visibility
, /* generic OK */
957 x_set_tool_bar_lines
,
958 0, /* x_set_scroll_bar_foreground, will ignore (not possible on NS) */
959 0, /* x_set_scroll_bar_background, will ignore (not possible on NS) */
960 x_set_screen_gamma
, /* generic OK */
961 x_set_line_spacing
, /* generic OK, sets f->extra_line_spacing to int */
962 x_set_fringe_width
, /* generic OK */
963 x_set_fringe_width
, /* generic OK */
964 0, /* x_set_wait_for_wm, will ignore */
965 x_set_fullscreen
, /* generic OK */
966 x_set_font_backend
, /* generic OK */
968 0, /* x_set_sticky */
969 0, /* x_set_tool_bar_position */
973 /* Handler for signals raised during x_create_frame.
974 FRAME is the frame which is partially constructed. */
977 unwind_create_frame
(Lisp_Object frame
)
979 struct frame
*f
= XFRAME
(frame
);
981 /* If frame is already dead, nothing to do. This can happen if the
982 display is disconnected after the frame has become official, but
983 before x_create_frame removes the unwind protect. */
984 if (!FRAME_LIVE_P
(f
))
987 /* If frame is ``official'', nothing to do. */
988 if (NILP
(Fmemq
(frame
, Vframe_list
)))
990 #
if defined GLYPH_DEBUG
&& defined ENABLE_CHECKING
991 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(f
);
994 x_free_frame_resources
(f
);
998 /* Check that reference counts are indeed correct. */
999 eassert
(dpyinfo
->terminal->image_cache
->refcount
== image_cache_refcount
);
1005 * Read geometry related parameters from preferences if not in PARMS.
1006 * Returns the union of parms and any preferences read.
1010 get_geometry_from_preferences
(struct ns_display_info
*dpyinfo
,
1018 { "width"
, "Width"
, Qwidth
},
1019 { "height"
, "Height"
, Qheight
},
1020 { "left"
, "Left"
, Qleft
},
1021 { "top"
, "Top"
, Qtop
},
1025 for (i
= 0; i
< sizeof
(r
)/sizeof
(r
[0]); ++i
)
1027 if (NILP
(Fassq
(r
[i
].tem
, parms
)))
1030 = x_get_arg
(dpyinfo
, parms
, r
[i
].tem
, r
[i
].val
, r
[i
].cls
,
1032 if (! EQ
(value
, Qunbound
))
1033 parms
= Fcons
(Fcons
(r
[i
].tem
, value
), parms
);
1040 /* ==========================================================================
1044 ========================================================================== */
1046 DEFUN
("x
-create
-frame"
, Fx_create_frame
, Sx_create_frame
,
1048 doc: /* Make a new Nextstep window, called a "frame" in Emacs terms.
1049 Return an Emacs frame object.
1050 PARMS is an alist of frame parameters.
1051 If the parameters specify that the frame should not have a minibuffer,
1052 and do not specify a specific minibuffer window to use,
1053 then `default-minibuffer-frame' must be a frame whose minibuffer can
1054 be shared by the new frame.
1056 This function is an internal primitive--use `make-frame' instead. */)
1060 Lisp_Object frame
, tem
;
1062 int minibuffer_only
= 0;
1063 long window_prompting
= 0;
1065 ptrdiff_t count
= specpdl_ptr
- specpdl
;
1066 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1067 Lisp_Object display
;
1068 struct ns_display_info
*dpyinfo
= NULL;
1071 static int desc_ctr
= 1;
1073 /* x_get_arg modifies parms. */
1074 parms
= Fcopy_alist
(parms
);
1076 /* Use this general default value to start with
1077 until we know if this frame has a specified name. */
1078 Vx_resource_name
= Vinvocation_name
;
1080 display
= x_get_arg
(dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_STRING
);
1081 if (EQ
(display
, Qunbound
))
1083 dpyinfo
= check_ns_display_info
(display
);
1084 kb
= dpyinfo
->terminal->kboard
;
1086 if (!dpyinfo
->terminal->name
)
1087 error ("
Terminal is not live
, can
't create new frames on it");
1089 name = x_get_arg (dpyinfo, parms, Qname, 0, 0, RES_TYPE_STRING);
1091 && ! EQ (name, Qunbound)
1093 error ("Invalid frame name--not a string or nil");
1096 Vx_resource_name = name;
1098 parent = x_get_arg (dpyinfo, parms, Qparent_id, 0, 0, RES_TYPE_NUMBER);
1099 if (EQ (parent, Qunbound))
1101 if (! NILP (parent))
1102 CHECK_NUMBER (parent);
1104 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
1105 /* No need to protect DISPLAY because that's not used after passing
1106 it to make_frame_without_minibuffer. */
1108 GCPRO4
(parms
, parent
, name
, frame
);
1109 tem
= x_get_arg
(dpyinfo
, parms
, Qminibuffer
, "minibuffer"
, "Minibuffer"
,
1111 if (EQ
(tem
, Qnone
) || NILP
(tem
))
1112 f
= make_frame_without_minibuffer
(Qnil
, kb
, display
);
1113 else if (EQ
(tem
, Qonly
))
1115 f
= make_minibuffer_frame
();
1116 minibuffer_only
= 1;
1118 else if (WINDOWP
(tem
))
1119 f
= make_frame_without_minibuffer
(tem
, kb
, display
);
1123 XSETFRAME
(frame
, f
);
1125 f
->terminal = dpyinfo
->terminal;
1127 f
->output_method
= output_ns
;
1128 f
->output_data.ns
= xzalloc
(sizeof
*f
->output_data.ns
);
1130 FRAME_FONTSET
(f
) = -1;
1132 fset_icon_name
(f
, x_get_arg
(dpyinfo
, parms
, Qicon_name
,
1133 "iconName"
, "
Title"
,
1135 if (! STRINGP
(f
->icon_name
))
1136 fset_icon_name
(f
, Qnil
);
1138 FRAME_DISPLAY_INFO
(f
) = dpyinfo
;
1140 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
1141 record_unwind_protect
(unwind_create_frame
, frame
);
1143 f
->output_data.ns
->window_desc
= desc_ctr
++;
1144 if (TYPE_RANGED_INTEGERP
(Window
, parent
))
1146 f
->output_data.ns
->parent_desc
= XFASTINT
(parent
);
1147 f
->output_data.ns
->explicit_parent
= 1;
1151 f
->output_data.ns
->parent_desc
= FRAME_DISPLAY_INFO
(f
)->root_window
;
1152 f
->output_data.ns
->explicit_parent
= 0;
1155 /* Set the name; the functions to which we pass f expect the name to
1157 if (EQ
(name
, Qunbound
) || NILP
(name
) ||
! STRINGP
(name
))
1159 fset_name
(f
, build_string
([ns_app_name UTF8String
]));
1160 f
->explicit_name
= 0;
1164 fset_name
(f
, name
);
1165 f
->explicit_name
= 1;
1166 specbind
(Qx_resource_name
, name
);
1171 #ifdef NS_IMPL_COCOA
1172 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_5
1173 if (CTGetCoreTextVersion
!= NULL
1174 && CTGetCoreTextVersion
() >= kCTVersionNumber10_5
)
1175 mac_register_font_driver
(f
);
1178 register_font_driver
(&nsfont_driver
, f
);
1180 x_default_parameter
(f
, parms
, Qfont_backend
, Qnil
,
1181 "fontBackend"
, "FontBackend"
, RES_TYPE_STRING
);
1184 /* use for default font name */
1185 id font
= [NSFont userFixedPitchFontOfSize
: -1.0]; /* default */
1186 x_default_parameter
(f
, parms
, Qfontsize
,
1187 make_number
(0 /*(int)[font pointSize]*/),
1188 "fontSize"
, "FontSize"
, RES_TYPE_NUMBER
);
1189 // Remove
' Regular', not handled by backends.
1190 char *fontname
= xstrdup
([[font displayName
] UTF8String
]);
1191 int len
= strlen
(fontname
);
1192 if (len
> 8 && strcmp (fontname
+ len
- 8, " Regular"
) == 0)
1193 fontname
[len
-8] = '\0';
1194 x_default_parameter
(f
, parms
, Qfont
,
1195 build_string
(fontname
),
1196 "font"
, "Font"
, RES_TYPE_STRING
);
1201 x_default_parameter
(f
, parms
, Qborder_width
, make_number
(0),
1202 "borderwidth"
, "BorderWidth"
, RES_TYPE_NUMBER
);
1203 x_default_parameter
(f
, parms
, Qinternal_border_width
, make_number
(2),
1204 "internalBorderWidth"
, "InternalBorderWidth"
,
1207 /* default scrollbars on right on Mac */
1210 #ifdef NS_IMPL_GNUSTEP
1215 x_default_parameter
(f
, parms
, Qvertical_scroll_bars
, spos
,
1216 "verticalScrollBars"
, "VerticalScrollBars"
,
1219 x_default_parameter
(f
, parms
, Qforeground_color
, build_string
("Black"
),
1220 "foreground"
, "Foreground"
, RES_TYPE_STRING
);
1221 x_default_parameter
(f
, parms
, Qbackground_color
, build_string
("
White"
),
1222 "background"
, "Background"
, RES_TYPE_STRING
);
1223 /* FIXME: not supported yet in Nextstep */
1224 x_default_parameter
(f
, parms
, Qline_spacing
, Qnil
,
1225 "lineSpacing"
, "LineSpacing"
, RES_TYPE_NUMBER
);
1226 x_default_parameter
(f
, parms
, Qleft_fringe
, Qnil
,
1227 "leftFringe"
, "LeftFringe"
, RES_TYPE_NUMBER
);
1228 x_default_parameter
(f
, parms
, Qright_fringe
, Qnil
,
1229 "rightFringe"
, "RightFringe"
, RES_TYPE_NUMBER
);
1232 image_cache_refcount
=
1233 FRAME_IMAGE_CACHE
(f
) ? FRAME_IMAGE_CACHE
(f
)->refcount
: 0;
1236 init_frame_faces
(f
);
1238 /* The resources controlling the menu-bar and tool-bar are
1239 processed specially at startup, and reflected in the mode
1240 variables; ignore them here. */
1241 x_default_parameter
(f
, parms
, Qmenu_bar_lines
,
1242 NILP
(Vmenu_bar_mode
)
1243 ? make_number
(0) : make_number
(1),
1244 NULL, NULL, RES_TYPE_NUMBER
);
1245 x_default_parameter
(f
, parms
, Qtool_bar_lines
,
1246 NILP
(Vtool_bar_mode
)
1247 ? make_number
(0) : make_number
(1),
1248 NULL, NULL, RES_TYPE_NUMBER
);
1250 x_default_parameter
(f
, parms
, Qbuffer_predicate
, Qnil
, "bufferPredicate"
,
1251 "BufferPredicate"
, RES_TYPE_SYMBOL
);
1252 x_default_parameter
(f
, parms
, Qtitle
, Qnil
, "
title"
, "
Title"
,
1255 parms
= get_geometry_from_preferences
(dpyinfo
, parms
);
1256 window_prompting
= x_figure_window_size
(f
, parms
, 1);
1258 tem
= x_get_arg
(dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
1259 f
->no_split
= minibuffer_only ||
(!EQ
(tem
, Qunbound
) && !EQ
(tem
, Qnil
));
1261 /* NOTE: on other terms, this is done in set_mouse_color, however this
1262 was not getting called under Nextstep */
1263 f
->output_data.ns
->text_cursor
= [NSCursor IBeamCursor
];
1264 f
->output_data.ns
->nontext_cursor
= [NSCursor arrowCursor
];
1265 f
->output_data.ns
->modeline_cursor
= [NSCursor pointingHandCursor
];
1266 f
->output_data.ns
->hand_cursor
= [NSCursor pointingHandCursor
];
1267 f
->output_data.ns
->hourglass_cursor
= [NSCursor disappearingItemCursor
];
1268 f
->output_data.ns
->horizontal_drag_cursor
= [NSCursor resizeLeftRightCursor
];
1269 FRAME_DISPLAY_INFO
(f
)->vertical_scroll_bar_cursor
1270 = [NSCursor arrowCursor
];
1271 f
->output_data.ns
->current_pointer
= f
->output_data.ns
->text_cursor
;
1273 [[EmacsView alloc
] initFrameFromEmacs
: f
];
1277 /* ns_display_info does not have a reference_count. */
1278 f
->terminal->reference_count
++;
1280 /* It is now ok to make the frame official even if we get an error below.
1281 The frame needs to be on Vframe_list or making it visible won't work. */
1282 Vframe_list
= Fcons
(frame
, Vframe_list
);
1284 x_default_parameter
(f
, parms
, Qicon_type
, Qnil
,
1285 "bitmapIcon"
, "BitmapIcon"
, RES_TYPE_SYMBOL
);
1287 x_default_parameter
(f
, parms
, Qauto_raise
, Qnil
,
1288 "autoRaise"
, "AutoRaiseLower"
, RES_TYPE_BOOLEAN
);
1289 x_default_parameter
(f
, parms
, Qauto_lower
, Qnil
,
1290 "autoLower"
, "AutoLower"
, RES_TYPE_BOOLEAN
);
1291 x_default_parameter
(f
, parms
, Qcursor_type
, Qbox
,
1292 "cursorType"
, "CursorType"
, RES_TYPE_SYMBOL
);
1293 x_default_parameter
(f
, parms
, Qscroll_bar_width
, Qnil
,
1294 "scrollBarWidth"
, "ScrollBarWidth"
,
1296 x_default_parameter
(f
, parms
, Qalpha
, Qnil
,
1297 "alpha"
, "Alpha"
, RES_TYPE_NUMBER
);
1298 x_default_parameter
(f
, parms
, Qfullscreen
, Qnil
,
1299 "fullscreen"
, "Fullscreen"
, RES_TYPE_SYMBOL
);
1301 width
= FRAME_COLS
(f
);
1302 height
= FRAME_LINES
(f
);
1304 SET_FRAME_COLS
(f
, 0);
1305 FRAME_LINES
(f
) = 0;
1306 change_frame_size
(f
, height
, width
, 1, 0, 0);
1308 if (! f
->output_data.ns
->explicit_parent
)
1310 Lisp_Object visibility
;
1312 visibility
= x_get_arg
(dpyinfo
, parms
, Qvisibility
, 0, 0,
1314 if (EQ
(visibility
, Qunbound
))
1317 if (EQ
(visibility
, Qicon
))
1318 x_iconify_frame
(f
);
1319 else if (! NILP
(visibility
))
1321 x_make_frame_visible
(f
);
1322 [[FRAME_NS_VIEW
(f
) window
] makeKeyWindow
];
1326 /* Must have been Qnil. */
1330 if (FRAME_HAS_MINIBUF_P
(f
)
1331 && (!FRAMEP
(KVAR
(kb
, Vdefault_minibuffer_frame
))
1332 ||
!FRAME_LIVE_P
(XFRAME
(KVAR
(kb
, Vdefault_minibuffer_frame
)))))
1333 kset_default_minibuffer_frame
(kb
, frame
);
1335 /* All remaining specified parameters, which have not been "used"
1336 by x_get_arg and friends, now go in the misc. alist of the frame. */
1337 for (tem
= parms
; CONSP
(tem
); tem
= XCDR
(tem
))
1338 if (CONSP
(XCAR
(tem
)) && !NILP
(XCAR
(XCAR
(tem
))))
1339 fset_param_alist
(f
, Fcons
(XCAR
(tem
), f
->param_alist
));
1343 if (window_prompting
& USPosition
)
1344 x_set_offset
(f
, f
->left_pos
, f
->top_pos
, 1);
1346 /* Make sure windows on this frame appear in calls to next-window
1347 and similar functions. */
1348 Vwindow_list
= Qnil
;
1350 return unbind_to
(count
, frame
);
1354 x_focus_frame
(struct frame
*f
)
1356 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(f
);
1358 if (dpyinfo
->x_focus_frame
!= f
)
1360 EmacsView
*view = FRAME_NS_VIEW
(f
);
1362 [NSApp activateIgnoringOtherApps
: YES
];
1363 [[view window
] makeKeyAndOrderFront
: view];
1369 DEFUN
("ns
-popup
-font
-panel"
, Fns_popup_font_panel
, Sns_popup_font_panel
,
1371 doc: /* Pop up the font panel. */)
1374 struct frame
*f
= decode_window_system_frame
(frame
);
1375 id fm
= [NSFontManager sharedFontManager
];
1376 struct font
*font
= f
->output_data.ns
->font
;
1378 if (EQ
(font
->driver
->type, Qns
))
1379 nsfont
= ((struct nsfont_info
*)font
)->nsfont
;
1380 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_5
1382 nsfont
= (NSFont
*) macfont_get_nsctfont
(font
);
1384 [fm setSelectedFont
: nsfont isMultiple
: NO
];
1385 [fm orderFrontFontPanel
: NSApp
];
1390 DEFUN
("ns
-popup
-color
-panel"
, Fns_popup_color_panel
, Sns_popup_color_panel
,
1392 doc: /* Pop up the color panel. */)
1395 check_window_system
(NULL);
1396 [NSApp orderFrontColorPanel
: NSApp
];
1404 #
if ! defined
(NS_IMPL_COCOA
) || \
1405 MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
1406 NSString
*dirS
, *initS
;
1412 ns_run_file_dialog
(void
)
1414 if (ns_fd_data.panel
== nil
) return;
1415 #
if defined
(NS_IMPL_COCOA
) && \
1416 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
1417 ns_fd_data.ret
= [ns_fd_data.panel runModal
];
1419 if (ns_fd_data.no_types
)
1421 ns_fd_data.ret
= [ns_fd_data.panel
1422 runModalForDirectory
: ns_fd_data.dirS
1423 file
: ns_fd_data.initS
];
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.panel
= nil
;
1436 DEFUN
("ns
-read
-file
-name"
, Fns_read_file_name
, Sns_read_file_name
, 1, 5, 0,
1437 doc: /* Use a graphical panel to read a file name, using prompt PROMPT.
1438 Optional arg DIR, if non-nil, supplies a default directory.
1439 Optional arg MUSTMATCH, if non-nil, means the returned file or
1440 directory must exist.
1441 Optional arg INIT, if non-nil, provides a default file name to use.
1442 Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1443 (Lisp_Object prompt
, Lisp_Object
dir, Lisp_Object mustmatch
,
1444 Lisp_Object init
, Lisp_Object dir_only_p
)
1446 static id fileDelegate
= nil
;
1448 BOOL isSave
= NILP
(mustmatch
) && NILP
(dir_only_p
);
1452 NSString
*promptS
= NILP
(prompt
) ||
!STRINGP
(prompt
) ? nil
:
1453 [NSString stringWithUTF8String
: SSDATA
(prompt
)];
1454 NSString
*dirS
= NILP
(dir) ||
!STRINGP
(dir) ?
1455 [NSString stringWithUTF8String
: SSDATA
(BVAR
(current_buffer
, directory
))] :
1456 [NSString stringWithUTF8String
: SSDATA
(dir)];
1457 NSString
*initS
= NILP
(init
) ||
!STRINGP
(init
) ? nil
:
1458 [NSString stringWithUTF8String
: SSDATA
(init
)];
1461 check_window_system
(NULL);
1463 if (fileDelegate
== nil
)
1464 fileDelegate
= [EmacsFileDelegate new
];
1466 [NSCursor setHiddenUntilMouseMoves
: NO
];
1468 if ([dirS characterAtIndex
: 0] == '~')
1469 dirS
= [dirS stringByExpandingTildeInPath
];
1472 (id
)[EmacsSavePanel savePanel
] : (id
)[EmacsOpenPanel openPanel
];
1474 [panel setTitle
: promptS
];
1476 [panel setAllowsOtherFileTypes
: YES
];
1477 [panel setTreatsFilePackagesAsDirectories
: YES
];
1478 [panel setDelegate
: fileDelegate
];
1480 if (! NILP
(dir_only_p
))
1482 [panel setCanChooseDirectories
: YES
];
1483 [panel setCanChooseFiles
: NO
];
1487 /* This is not quite what the documentation says, but it is compatible
1488 with the Gtk+ code. Also, the menu entry says "Open File...". */
1489 [panel setCanChooseDirectories
: NO
];
1490 [panel setCanChooseFiles
: YES
];
1494 ns_fd_data.panel
= panel
;
1495 ns_fd_data.ret
= NO
;
1496 #
if defined
(NS_IMPL_COCOA
) && \
1497 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
1498 if (! NILP
(mustmatch
) ||
! NILP
(dir_only_p
))
1499 [panel setAllowedFileTypes
: nil
];
1500 if (dirS
) [panel setDirectoryURL
: [NSURL fileURLWithPath
: dirS
]];
1501 if (initS
&& NILP
(Ffile_directory_p
(init
)))
1502 [panel setNameFieldStringValue
: [initS lastPathComponent
]];
1504 [panel setNameFieldStringValue
: @""
];
1507 ns_fd_data.no_types
= NILP
(mustmatch
) && NILP
(dir_only_p
);
1508 ns_fd_data.dirS
= dirS
;
1509 ns_fd_data.initS
= initS
;
1512 /* runModalForDirectory/runModal restarts the main event loop when done,
1513 so we must start an event loop and then pop up the file dialog.
1514 The file dialog may pop up a confirm dialog after Ok has been pressed,
1515 so we can not simply pop down on the Ok/Cancel press.
1517 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
1518 location
: NSMakePoint
(0, 0)
1521 windowNumber
: [[NSApp mainWindow
] windowNumber
]
1522 context
: [NSApp context
]
1525 data2
: NSAPP_DATA2_RUNFILEDIALOG
];
1527 [NSApp postEvent
: nxev atStart
: NO
];
1528 while (ns_fd_data.panel
!= nil
)
1531 ret
= (ns_fd_data.ret
== NSOKButton
);
1535 NSString
*str
= ns_filename_from_panel
(panel
);
1536 if (! str
) str
= ns_directory_from_panel
(panel
);
1537 if (! str
) ret
= NO
;
1538 else fname
= build_string
([str UTF8String
]);
1541 [[FRAME_NS_VIEW
(SELECTED_FRAME
()) window
] makeKeyWindow
];
1544 return ret ? fname
: Qnil
;
1548 ns_get_defaults_value
(const
char *key
)
1550 NSObject
*obj
= [[NSUserDefaults standardUserDefaults
]
1551 objectForKey
: [NSString stringWithUTF8String
: key
]];
1553 if (!obj
) return NULL;
1555 return [[NSString stringWithFormat
: @"
%@", obj] UTF8String];
1559 DEFUN
("ns
-get-resource"
, Fns_get_resource
, Sns_get_resource
, 2, 2, 0,
1560 doc: /* Return the value of the property NAME of OWNER from the defaults database.
1561 If OWNER is nil, Emacs is assumed. */)
1562 (Lisp_Object owner
, Lisp_Object name
)
1566 check_window_system
(NULL);
1568 owner
= build_string
([ns_app_name UTF8String
]);
1569 CHECK_STRING
(name
);
1571 value
= ns_get_defaults_value
(SSDATA
(name
));
1574 return build_string
(value
);
1579 DEFUN
("ns
-set-resource"
, Fns_set_resource
, Sns_set_resource
, 3, 3, 0,
1580 doc: /* Set property NAME of OWNER to VALUE, from the defaults database.
1581 If OWNER is nil, Emacs is assumed.
1582 If VALUE is nil, the default is removed. */)
1583 (Lisp_Object owner
, Lisp_Object name
, Lisp_Object value
)
1585 check_window_system
(NULL);
1587 owner
= build_string
([ns_app_name UTF8String
]);
1588 CHECK_STRING
(name
);
1591 [[NSUserDefaults standardUserDefaults
] removeObjectForKey
:
1592 [NSString stringWithUTF8String
: SSDATA
(name
)]];
1596 CHECK_STRING
(value
);
1597 [[NSUserDefaults standardUserDefaults
] setObject
:
1598 [NSString stringWithUTF8String
: SSDATA
(value
)]
1599 forKey
: [NSString stringWithUTF8String
:
1607 DEFUN
("x
-server
-max-request
-size"
, Fx_server_max_request_size
,
1608 Sx_server_max_request_size
,
1610 doc: /* This function is a no-op. It is only present for completeness. */)
1611 (Lisp_Object
terminal)
1613 check_ns_display_info
(terminal);
1614 /* This function has no real equivalent under NeXTstep. Return nil to
1620 DEFUN
("x
-server
-vendor"
, Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
1621 doc: /* Return the "vendor ID" string of Nextstep display server TERMINAL.
1622 \(Labeling every distributor as a "vendor" embodies the false assumption
1623 that operating systems cannot be developed and distributed noncommercially.)
1624 The optional argument TERMINAL specifies which display to ask about.
1625 TERMINAL should be a terminal object, a frame or a display name (a string).
1626 If omitted or nil, that stands for the selected frame's display. */)
1627 (Lisp_Object
terminal)
1629 check_ns_display_info
(terminal);
1630 #ifdef NS_IMPL_GNUSTEP
1631 return build_string
("GNU"
);
1633 return build_string
("Apple"
);
1638 DEFUN
("x
-server
-version"
, Fx_server_version
, Sx_server_version
, 0, 1, 0,
1639 doc: /* Return the version numbers of the server of display TERMINAL.
1640 The value is a list of three integers: the major and minor
1641 version numbers of the X Protocol in use, and the distributor-specific release
1642 number. See also the function `x-server-vendor'.
1644 The optional argument TERMINAL specifies which display to ask about.
1645 TERMINAL should be a terminal object, a frame or a display name (a string).
1646 If omitted or nil, that stands for the selected frame's display. */)
1647 (Lisp_Object
terminal)
1649 check_ns_display_info
(terminal);
1650 /*NOTE: it is unclear what would best correspond with "protocol";
1651 we return 10.3, meaning Panther, since this is roughly the
1652 level that GNUstep's APIs correspond to.
1653 The last number is where we distinguish between the Apple
1654 and GNUstep implementations ("distributor-specific release
1655 number") and give int'ized versions of major.minor. */
1656 return list3i
(10, 3, ns_appkit_version_int
());
1660 DEFUN
("x
-display
-screens"
, Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
1661 doc: /* Return the number of screens on Nextstep display server TERMINAL.
1662 The optional argument TERMINAL specifies which display to ask about.
1663 TERMINAL should be a terminal object, a frame or a display name (a string).
1664 If omitted or nil, that stands for the selected frame's display.
1666 Note: "screen" here is not in Nextstep terminology but in X11's. For
1667 the number of physical monitors, use `(length
1668 (display-monitor-attributes-list TERMINAL))' instead. */)
1669 (Lisp_Object
terminal)
1671 check_ns_display_info
(terminal);
1672 return make_number
(1);
1676 DEFUN
("x
-display
-mm
-height"
, Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
1677 doc: /* Return the height in millimeters of the Nextstep display TERMINAL.
1678 The optional argument TERMINAL specifies which display to ask about.
1679 TERMINAL should be a terminal object, a frame or a display name (a string).
1680 If omitted or nil, that stands for the selected frame's display.
1682 On \"multi-monitor\" setups this refers to the height in millimeters for
1683 all physical monitors associated with TERMINAL. To get information
1684 for each physical monitor, use `display-monitor-attributes-list'. */)
1685 (Lisp_Object
terminal)
1687 struct ns_display_info
*dpyinfo
= check_ns_display_info
(terminal);
1689 return make_number
(x_display_pixel_height
(dpyinfo
) / (92.0/25.4));
1693 DEFUN
("x
-display
-mm
-width"
, Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
1694 doc: /* Return the width in millimeters of the Nextstep display TERMINAL.
1695 The optional argument TERMINAL specifies which display to ask about.
1696 TERMINAL should be a terminal object, a frame or a display name (a string).
1697 If omitted or nil, that stands for the selected frame's display.
1699 On \"multi-monitor\" setups this refers to the width in millimeters for
1700 all physical monitors associated with TERMINAL. To get information
1701 for each physical monitor, use `display-monitor-attributes-list'. */)
1702 (Lisp_Object
terminal)
1704 struct ns_display_info
*dpyinfo
= check_ns_display_info
(terminal);
1706 return make_number
(x_display_pixel_width
(dpyinfo
) / (92.0/25.4));
1710 DEFUN
("x
-display
-backing
-store"
, Fx_display_backing_store
,
1711 Sx_display_backing_store
, 0, 1, 0,
1712 doc: /* Return an indication of whether the Nextstep display TERMINAL does backing store.
1713 The value may be `buffered', `retained', or `non-retained'.
1714 The optional argument TERMINAL specifies which display to ask about.
1715 TERMINAL should be a terminal object, a frame or a display name (a string).
1716 If omitted or nil, that stands for the selected frame's display. */)
1717 (Lisp_Object
terminal)
1719 check_ns_display_info
(terminal);
1720 switch ([ns_get_window
(terminal) backingType
])
1722 case NSBackingStoreBuffered
:
1723 return intern
("buffered"
);
1724 case NSBackingStoreRetained
:
1725 return intern
("retained"
);
1726 case NSBackingStoreNonretained
:
1727 return intern
("non
-retained"
);
1729 error ("Strange value
for backingType parameter of frame"
);
1731 return Qnil
; /* not reached, shut compiler up */
1735 DEFUN
("x
-display
-visual
-class"
, Fx_display_visual_class
,
1736 Sx_display_visual_class
, 0, 1, 0,
1737 doc: /* Return the visual class of the Nextstep display TERMINAL.
1738 The value is one of the symbols `static-gray', `gray-scale',
1739 `static-color', `pseudo-color', `true-color', or `direct-color'.
1741 The optional argument TERMINAL specifies which display to ask about.
1742 TERMINAL should a terminal object, a frame or a display name (a string).
1743 If omitted or nil, that stands for the selected frame's display. */)
1744 (Lisp_Object
terminal)
1746 NSWindowDepth depth
;
1748 check_ns_display_info
(terminal);
1749 depth
= [[[NSScreen screens
] objectAtIndex
:0] depth
];
1751 if ( depth
== NSBestDepth
(NSCalibratedWhiteColorSpace
, 2, 2, YES
, NULL))
1752 return intern
("static
-gray"
);
1753 else if (depth
== NSBestDepth
(NSCalibratedWhiteColorSpace
, 8, 8, YES
, NULL))
1754 return intern
("
gray-scale"
);
1755 else if ( depth
== NSBestDepth
(NSCalibratedRGBColorSpace
, 8, 8, YES
, NULL))
1756 return intern
("pseudo
-color"
);
1757 else if ( depth
== NSBestDepth
(NSCalibratedRGBColorSpace
, 4, 12, NO
, NULL))
1758 return intern
("true
-color"
);
1759 else if ( depth
== NSBestDepth
(NSCalibratedRGBColorSpace
, 8, 24, NO
, NULL))
1760 return intern
("direct
-color"
);
1762 /* color mgmt as far as we do it is really handled by Nextstep itself anyway */
1763 return intern
("direct
-color"
);
1767 DEFUN
("x
-display
-save-under"
, Fx_display_save_under
,
1768 Sx_display_save_under
, 0, 1, 0,
1769 doc: /* Return t if TERMINAL supports the save-under feature.
1770 The optional argument TERMINAL specifies which display to ask about.
1771 TERMINAL should be a terminal object, a frame or a display name (a string).
1772 If omitted or nil, that stands for the selected frame's display. */)
1773 (Lisp_Object
terminal)
1775 check_ns_display_info
(terminal);
1776 switch ([ns_get_window
(terminal) backingType
])
1778 case NSBackingStoreBuffered
:
1781 case NSBackingStoreRetained
:
1782 case NSBackingStoreNonretained
:
1786 error ("Strange value
for backingType parameter of frame"
);
1788 return Qnil
; /* not reached, shut compiler up */
1792 DEFUN
("x
-open
-connection"
, Fx_open_connection
, Sx_open_connection
,
1794 doc: /* Open a connection to a display server.
1795 DISPLAY is the name of the display to connect to.
1796 Optional second arg XRM-STRING is a string of resources in xrdb format.
1797 If the optional third arg MUST-SUCCEED is non-nil,
1798 terminate Emacs if we can't open the connection.
1799 \(In the Nextstep version, the last two arguments are currently ignored.) */)
1800 (Lisp_Object display
, Lisp_Object resource_string
, Lisp_Object must_succeed
)
1802 struct ns_display_info
*dpyinfo
;
1804 CHECK_STRING
(display
);
1806 nxatoms_of_nsselect
();
1807 dpyinfo
= ns_term_init
(display
);
1810 if (!NILP
(must_succeed
))
1811 fatal
("OpenStep on
%s not responding.\n",
1814 error ("OpenStep on
%s not responding.\n",
1822 DEFUN
("x
-close-connection"
, Fx_close_connection
, Sx_close_connection
,
1824 doc: /* Close the connection to TERMINAL's Nextstep display server.
1825 For TERMINAL, specify a terminal object, a frame or a display name (a
1826 string). If TERMINAL is nil, that stands for the selected frame's
1828 (Lisp_Object
terminal)
1830 check_ns_display_info
(terminal);
1831 [NSApp terminate
: NSApp
];
1836 DEFUN
("x
-display
-list"
, Fx_display_list
, Sx_display_list
, 0, 0, 0,
1837 doc: /* Return the list of display names that Emacs has connections to. */)
1840 Lisp_Object result
= Qnil
;
1841 struct ns_display_info
*ndi
;
1843 for (ndi
= x_display_list
; ndi
; ndi
= ndi
->next
)
1844 result
= Fcons
(XCAR
(ndi
->name_list_element
), result
);
1850 DEFUN
("ns
-hide
-others"
, Fns_hide_others
, Sns_hide_others
,
1852 doc: /* Hides all applications other than Emacs. */)
1855 check_window_system
(NULL);
1856 [NSApp hideOtherApplications
: NSApp
];
1860 DEFUN
("ns
-hide
-emacs"
, Fns_hide_emacs
, Sns_hide_emacs
,
1862 doc: /* If ON is non-nil, the entire Emacs application is hidden.
1863 Otherwise if Emacs is hidden, it is unhidden.
1864 If ON is equal to `activate', Emacs is unhidden and becomes
1865 the active application. */)
1868 check_window_system
(NULL);
1869 if (EQ
(on
, intern
("activate"
)))
1871 [NSApp unhide
: NSApp
];
1872 [NSApp activateIgnoringOtherApps
: YES
];
1875 [NSApp unhide
: NSApp
];
1877 [NSApp hide
: NSApp
];
1882 DEFUN
("ns
-emacs
-info-panel"
, Fns_emacs_info_panel
, Sns_emacs_info_panel
,
1884 doc: /* Shows the 'Info' or 'About' panel for Emacs. */)
1887 check_window_system
(NULL);
1888 [NSApp orderFrontStandardAboutPanel
: nil
];
1893 DEFUN
("ns
-font
-name"
, Fns_font_name
, Sns_font_name
, 1, 1, 0,
1894 doc: /* Determine font PostScript or family name for font NAME.
1895 NAME should be a string containing either the font name or an XLFD
1896 font descriptor. If string contains `fontset' and not
1897 `fontset-startup', it is left alone. */)
1901 CHECK_STRING
(name
);
1906 if (strstr
(nm
, "fontset"
) && !strstr
(nm
, "fontset
-startup"
))
1909 return build_string
(ns_xlfd_to_fontname
(SSDATA
(name
)));
1913 DEFUN
("ns
-list
-colors"
, Fns_list_colors
, Sns_list_colors
, 0, 1, 0,
1914 doc: /* Return a list of all available colors.
1915 The optional argument FRAME is currently ignored. */)
1918 Lisp_Object list
= Qnil
;
1919 NSEnumerator
*colorlists
;
1924 CHECK_FRAME
(frame
);
1925 if (! FRAME_NS_P
(XFRAME
(frame
)))
1926 error ("non
-Nextstep frame used in `ns
-list
-colors
'");
1931 colorlists = [[NSColorList availableColorLists] objectEnumerator];
1932 while ((clist = [colorlists nextObject]))
1934 if ([[clist name] length] < 7 ||
1935 [[clist name] rangeOfString: @"PANTONE"].location == 0)
1937 NSEnumerator *cnames = [[clist allKeys] reverseObjectEnumerator];
1939 while ((cname = [cnames nextObject]))
1940 list = Fcons (build_string ([cname UTF8String]), list);
1941 /* for (i = [[clist allKeys] count] - 1; i >= 0; i--)
1942 list = Fcons (build_string ([[[clist allKeys] objectAtIndex: i]
1943 UTF8String]), list); */
1953 DEFUN ("ns-list-services", Fns_list_services, Sns_list_services, 0, 0, 0,
1954 doc: /* List available Nextstep services by querying NSApp. */)
1957 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1958 /* You can't
get services like this in
10.6+. */
1961 Lisp_Object ret
= Qnil
;
1963 #ifdef NS_IMPL_COCOA
1967 check_window_system
(NULL);
1968 svcs
= [[NSMenu alloc
] initWithTitle
: @"Services"
];
1969 [NSApp setServicesMenu
: svcs
];
1970 [NSApp registerServicesMenuSendTypes
: ns_send_types
1971 returnTypes
: ns_return_types
];
1973 /* On Tiger, services menu updating was made lazier (waits for user to
1974 actually click on the menu), so we have to force things along: */
1975 #ifdef NS_IMPL_COCOA
1976 delegate
= [svcs delegate
];
1977 if (delegate
!= nil
)
1979 if ([delegate respondsToSelector
: @selector
(menuNeedsUpdate
:)])
1980 [delegate menuNeedsUpdate
: svcs
];
1981 if ([delegate respondsToSelector
:
1982 @selector
(menu:updateItem
:atIndex
:shouldCancel
:)])
1984 int i
, len
= [delegate numberOfItemsInMenu
: svcs
];
1985 for (i
=0; i
<len
; i
++)
1986 [svcs addItemWithTitle
: @"" action
: NULL keyEquivalent
: @""
];
1987 for (i
=0; i
<len
; i
++)
1988 if (![delegate
menu: svcs
1989 updateItem
: (NSMenuItem
*)[svcs itemAtIndex
: i
]
1990 atIndex
: i shouldCancel
: NO
])
1996 [svcs setAutoenablesItems
: NO
];
1997 #ifdef NS_IMPL_COCOA
1998 [svcs update
]; /* on OS X, converts from '/' structure */
2001 ret
= interpret_services_menu
(svcs
, Qnil
, ret
);
2007 DEFUN
("ns
-perform
-service"
, Fns_perform_service
, Sns_perform_service
,
2009 doc: /* Perform Nextstep SERVICE on SEND.
2010 SEND should be either a string or nil.
2011 The return value is the result of the service, as string, or nil if
2012 there was no result. */)
2013 (Lisp_Object service
, Lisp_Object send
)
2019 CHECK_STRING
(service
);
2020 check_window_system
(NULL);
2022 utfStr
= SSDATA
(service
);
2023 svcName
= [NSString stringWithUTF8String
: utfStr
];
2025 pb
=[NSPasteboard pasteboardWithUniqueName
];
2026 ns_string_to_pasteboard
(pb
, send
);
2028 if (NSPerformService
(svcName
, pb
) == NO
)
2029 Fsignal
(Qquit
, list1
(build_string
("service not available"
)));
2031 if ([[pb types
] count
] == 0)
2032 return build_string
(""
);
2033 return ns_string_from_pasteboard
(pb
);
2037 DEFUN
("ns
-convert
-utf8
-nfd
-to
-nfc"
, Fns_convert_utf8_nfd_to_nfc
,
2038 Sns_convert_utf8_nfd_to_nfc
, 1, 1, 0,
2039 doc: /* Return an NFC string that matches the UTF-8 NFD string STR. */)
2042 /* TODO: If GNUstep ever implements precomposedStringWithCanonicalMapping,
2045 Lisp_Object ret
= Qnil
;
2046 NSAutoreleasePool
*pool
;
2049 pool
= [[NSAutoreleasePool alloc
] init
];
2050 utfStr
= [NSString stringWithUTF8String
: SSDATA
(str
)];
2051 #ifdef NS_IMPL_COCOA
2053 utfStr
= [utfStr precomposedStringWithCanonicalMapping
];
2057 const
char *cstr
= [utfStr UTF8String
];
2059 ret
= build_string
(cstr
);
2064 error ("Invalid UTF
-8"
);
2070 #ifdef NS_IMPL_COCOA
2072 /* Compile and execute the AppleScript SCRIPT and return the error
2073 status as function value. A zero is returned if compilation and
2074 execution is successful, in which case *RESULT is set to a Lisp
2075 string or a number containing the resulting script value. Otherwise,
2078 ns_do_applescript
(Lisp_Object
script, Lisp_Object
*result
)
2080 NSAppleEventDescriptor
*desc
;
2081 NSDictionary
* errorDict
;
2082 NSAppleEventDescriptor
* returnDescriptor
= NULL;
2084 NSAppleScript
* scriptObject
=
2085 [[NSAppleScript alloc
] initWithSource
:
2086 [NSString stringWithUTF8String
: SSDATA
(script)]];
2088 returnDescriptor
= [scriptObject executeAndReturnError
: &errorDict
];
2089 [scriptObject release
];
2093 if (returnDescriptor
!= NULL)
2095 // successful execution
2096 if (kAENullEvent
!= [returnDescriptor descriptorType
])
2099 // script returned an AppleScript result
2100 if ((typeUnicodeText
== [returnDescriptor descriptorType
]) ||
2101 #
if defined
(NS_IMPL_COCOA
)
2102 (typeUTF16ExternalRepresentation
2103 == [returnDescriptor descriptorType
]) ||
2105 (typeUTF8Text
== [returnDescriptor descriptorType
]) ||
2106 (typeCString
== [returnDescriptor descriptorType
]))
2108 desc
= [returnDescriptor coerceToDescriptorType
: typeUTF8Text
];
2110 *result
= build_string
([[desc stringValue
] UTF8String
]);
2114 /* use typeUTF16ExternalRepresentation? */
2115 // coerce the result to the appropriate ObjC
type
2116 desc
= [returnDescriptor coerceToDescriptorType
: typeUTF8Text
];
2118 *result
= make_number
([desc int32Value
]);
2124 // no
script result
, return error
2130 /* Helper function called from sendEvent to run applescript
2131 from within the main event loop. */
2134 ns_run_ascript
(void
)
2136 if (! NILP
(as_script
))
2137 as_status
= ns_do_applescript
(as_script
, as_result
);
2141 DEFUN
("ns
-do
-applescript"
, Fns_do_applescript
, Sns_do_applescript
, 1, 1, 0,
2142 doc: /* Execute AppleScript SCRIPT and return the result.
2143 If compilation and execution are successful, the resulting script value
2144 is returned as a string, a number or, in the case of other constructs, t.
2145 In case the execution fails, an error is signaled. */)
2146 (Lisp_Object
script)
2152 CHECK_STRING
(script);
2153 check_window_system
(NULL);
2158 as_result
= &result
;
2160 /* executing apple script requires the event loop to run, otherwise
2161 errors aren't returned and executeAndReturnError hangs forever.
2162 Post an event that runs applescript and then start the event loop.
2163 The event loop is exited when the script is done. */
2164 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
2165 location
: NSMakePoint
(0, 0)
2168 windowNumber
: [[NSApp mainWindow
] windowNumber
]
2169 context
: [NSApp context
]
2172 data2
: NSAPP_DATA2_RUNASSCRIPT
];
2174 [NSApp postEvent
: nxev atStart
: NO
];
2176 // If there are other events
, the event loop may exit. Keep running
2177 // until the
script has been handled. */
2178 while (! NILP
(as_script
))
2187 else if (!STRINGP
(result
))
2188 error ("AppleScript
error %d", status);
2190 error ("
%s", SSDATA (result));
2196 /* ==========================================================================
2198 Miscellaneous functions not called through hooks
2200 ========================================================================== */
2202 /* called from frame.c */
2203 struct ns_display_info
*
2204 check_x_display_info
(Lisp_Object frame
)
2206 return check_ns_display_info
(frame
);
2211 x_set_scroll_bar_default_width
(struct frame
*f
)
2213 int wid
= FRAME_COLUMN_WIDTH
(f
);
2214 FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) = NS_SCROLL_BAR_WIDTH_DEFAULT
;
2215 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) +
2219 /* terms impl this instead of x-get-resource directly */
2221 x_get_string_resource
(XrmDatabase rdb
, const
char *name
, const
char *class)
2223 /* remove appname prefix; TODO: allow for !="Emacs" */
2224 const
char *res
, *toCheck
= class + (!strncmp
(class, "Emacs."
, 6) ?
6 : 0);
2226 check_window_system
(NULL);
2228 if (inhibit_x_resources
)
2229 /* --quick was passed, so this is a no-op. */
2232 res
= ns_get_defaults_value
(toCheck
);
2233 return (!res ?
NULL :
2234 (!c_strncasecmp
(res
, "YES"
, 3) ? "true"
:
2235 (!c_strncasecmp
(res
, "NO"
, 2) ? "false"
: (char *) res
)));
2240 x_get_focus_frame
(struct frame
*frame
)
2242 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(frame
);
2243 Lisp_Object nsfocus
;
2245 if (!dpyinfo
->x_focus_frame
)
2248 XSETFRAME
(nsfocus
, dpyinfo
->x_focus_frame
);
2252 /* ==========================================================================
2254 Lisp definitions that, for whatever reason, we can't alias as 'ns-XXX'.
2256 ========================================================================== */
2259 DEFUN
("xw
-color
-defined
-p"
, Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
2260 doc: /* Internal function called by `color-defined-p', which see.
2261 \(Note that the Nextstep version of this function ignores FRAME.) */)
2262 (Lisp_Object color
, Lisp_Object frame
)
2265 check_window_system
(NULL);
2266 return ns_lisp_to_color
(color
, &col
) ? Qnil
: Qt
;
2270 DEFUN
("xw
-color
-values"
, Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
2271 doc: /* Internal function called by `color-values', which see. */)
2272 (Lisp_Object color
, Lisp_Object frame
)
2275 EmacsCGFloat red
, green
, blue
, alpha
;
2277 check_window_system
(NULL);
2278 CHECK_STRING
(color
);
2280 if (ns_lisp_to_color
(color
, &col
))
2283 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
2284 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
2285 return list3i
(lrint
(red
* 65280), lrint
(green
* 65280),
2286 lrint
(blue
* 65280));
2290 DEFUN
("xw
-display
-color
-p"
, Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
2291 doc: /* Internal function called by `display-color-p', which see. */)
2292 (Lisp_Object
terminal)
2294 NSWindowDepth depth
;
2295 NSString
*colorSpace
;
2297 check_ns_display_info
(terminal);
2298 depth
= [[[NSScreen screens
] objectAtIndex
:0] depth
];
2299 colorSpace
= NSColorSpaceFromDepth
(depth
);
2301 return [colorSpace isEqualToString
: NSDeviceWhiteColorSpace
]
2302 ||
[colorSpace isEqualToString
: NSCalibratedWhiteColorSpace
]
2307 DEFUN
("x
-display
-grayscale
-p"
, Fx_display_grayscale_p
, Sx_display_grayscale_p
,
2309 doc: /* Return t if the Nextstep display supports shades of gray.
2310 Note that color displays do support shades of gray.
2311 The optional argument TERMINAL specifies which display to ask about.
2312 TERMINAL should be a terminal object, a frame or a display name (a string).
2313 If omitted or nil, that stands for the selected frame's display. */)
2314 (Lisp_Object
terminal)
2316 NSWindowDepth depth
;
2318 check_ns_display_info
(terminal);
2319 depth
= [[[NSScreen screens
] objectAtIndex
:0] depth
];
2321 return NSBitsPerPixelFromDepth
(depth
) > 1 ? Qt
: Qnil
;
2325 DEFUN
("x
-display
-pixel
-width"
, Fx_display_pixel_width
, Sx_display_pixel_width
,
2327 doc: /* Return the width in pixels of the Nextstep display TERMINAL.
2328 The optional argument TERMINAL specifies which display to ask about.
2329 TERMINAL should be a terminal object, a frame or a display name (a string).
2330 If omitted or nil, that stands for the selected frame's display.
2332 On \"multi-monitor\" setups this refers to the pixel width for all
2333 physical monitors associated with TERMINAL. To get information for
2334 each physical monitor, use `display-monitor-attributes-list'. */)
2335 (Lisp_Object
terminal)
2337 struct ns_display_info
*dpyinfo
= check_ns_display_info
(terminal);
2339 return make_number
(x_display_pixel_width
(dpyinfo
));
2343 DEFUN
("x
-display
-pixel
-height"
, Fx_display_pixel_height
,
2344 Sx_display_pixel_height
, 0, 1, 0,
2345 doc: /* Return the height in pixels of the Nextstep display TERMINAL.
2346 The optional argument TERMINAL specifies which display to ask about.
2347 TERMINAL should be a terminal object, a frame or a display name (a string).
2348 If omitted or nil, that stands for the selected frame's display.
2350 On \"multi-monitor\" setups this refers to the pixel height for all
2351 physical monitors associated with TERMINAL. To get information for
2352 each physical monitor, use `display-monitor-attributes-list'. */)
2353 (Lisp_Object
terminal)
2355 struct ns_display_info
*dpyinfo
= check_ns_display_info
(terminal);
2357 return make_number
(x_display_pixel_height
(dpyinfo
));
2360 #ifdef NS_IMPL_COCOA
2361 /* Returns the name for the screen that DICT came from, or NULL.
2362 Caller must free return value.
2366 ns_screen_name
(CGDirectDisplayID did
)
2369 NSDictionary
*info = (NSDictionary
*)
2370 IODisplayCreateInfoDictionary
(CGDisplayIOServicePort
(did
),
2371 kIODisplayOnlyPreferredName
);
2373 = [info objectForKey
:
2374 [NSString stringWithUTF8String
:kDisplayProductName
]];
2376 if ([names count
] > 0) {
2377 NSString
*n
= [names objectForKey
: [[names allKeys
] objectAtIndex
:0]];
2379 name
= xstrdup
([n UTF8String
]);
2388 ns_make_monitor_attribute_list
(struct MonitorInfo
*monitors
,
2390 int primary_monitor
,
2393 Lisp_Object monitor_frames
= Fmake_vector
(make_number
(n_monitors
), Qnil
);
2394 Lisp_Object frame
, rest
;
2395 NSArray
*screens
= [NSScreen screens
];
2398 FOR_EACH_FRAME
(rest
, frame
)
2400 struct frame
*f
= XFRAME
(frame
);
2404 NSView
*view = FRAME_NS_VIEW
(f
);
2405 NSScreen
*screen
= [[view window
] screen
];
2409 for (k
= 0; i
== -1 && k
< [screens count
]; ++k
)
2411 if ([screens objectAtIndex
: k
] == screen
)
2416 ASET
(monitor_frames
, i
, Fcons
(frame
, AREF
(monitor_frames
, i
)));
2420 return make_monitor_attribute_list
(monitors
, n_monitors
, primary_monitor
,
2421 monitor_frames
, source
);
2424 DEFUN
("ns
-display
-monitor
-attributes
-list"
,
2425 Fns_display_monitor_attributes_list
,
2426 Sns_display_monitor_attributes_list
,
2428 doc: /* Return a list of physical monitor attributes on the X display TERMINAL.
2430 The optional argument TERMINAL specifies which display to ask about.
2431 TERMINAL should be a terminal object, a frame or a display name (a string).
2432 If omitted or nil, that stands for the selected frame's display.
2434 In addition to the standard attribute keys listed in
2435 `display-monitor-attributes-list', the following keys are contained in
2438 source -- String describing the source from which multi-monitor
2439 information is obtained, \"NS\" is always the source."
2441 Internal use only, use `display-monitor-attributes-list' instead. */)
2442 (Lisp_Object
terminal)
2444 struct terminal *term
= get_terminal
(terminal, 1);
2446 NSUInteger i
, n_monitors
;
2447 struct MonitorInfo
*monitors
;
2448 Lisp_Object attributes_list
= Qnil
;
2449 CGFloat primary_display_height
= 0;
2451 if (term
->type != output_ns
)
2454 screens
= [NSScreen screens
];
2455 n_monitors
= [screens count
];
2456 if (n_monitors
== 0)
2459 monitors
= xzalloc
(n_monitors
* sizeof
*monitors
);
2461 for (i
= 0; i
< [screens count
]; ++i
)
2463 NSScreen
*s
= [screens objectAtIndex
:i
];
2464 struct MonitorInfo
*m
= &monitors
[i
];
2465 NSRect fr
= [s frame
];
2466 NSRect vfr
= [s visibleFrame
];
2469 #ifdef NS_IMPL_COCOA
2470 NSDictionary
*dict
= [s deviceDescription
];
2471 NSNumber
*nid
= [dict objectForKey
:@"NSScreenNumber"
];
2472 CGDirectDisplayID did
= [nid unsignedIntValue
];
2476 primary_display_height
= fr.
size.height
;
2477 y
= (short
) fr.origin.y
;
2478 vy
= (short
) vfr.origin.y
;
2482 // Flip y coordinate as NS has y starting from the bottom.
2483 y
= (short
) (primary_display_height
- fr.
size.height
- fr.origin.y
);
2484 vy
= (short
) (primary_display_height
-
2485 vfr.
size.height
- vfr.origin.y
);
2488 m
->geom.x
= (short
) fr.origin.x
;
2490 m
->geom.width
= (unsigned short
) fr.
size.width
;
2491 m
->geom.height
= (unsigned short
) fr.
size.height
;
2493 m
->work.x
= (short
) vfr.origin.x
;
2494 // y is flipped on NS
, so vy
- y are pixels missing at the bottom
,
2495 // and fr.
size.height
- vfr.
size.height are pixels missing in total.
2496 // Pixels missing at top are
2497 // fr.
size.height
- vfr.
size.height
- vy
+ y.
2498 // work.y is then pixels missing at top
+ y.
2499 m
->work.y
= (short
) (fr.
size.height
- vfr.
size.height
) - vy
+ y
+ y
;
2500 m
->work.width
= (unsigned short
) vfr.
size.width
;
2501 m
->work.height
= (unsigned short
) vfr.
size.height
;
2503 #ifdef NS_IMPL_COCOA
2504 m
->name
= ns_screen_name
(did
);
2507 CGSize mms
= CGDisplayScreenSize
(did
);
2508 m
->mm_width
= (int
) mms.width
;
2509 m
->mm_height
= (int
) mms.height
;
2513 // Assume
92 dpi as x
-display
-mm
-height
/x
-display
-mm
-width does.
2514 m
->mm_width
= (int
) (25.4 * fr.
size.width
/ 92.0);
2515 m
->mm_height
= (int
) (25.4 * fr.
size.height
/ 92.0);
2519 // Primary monitor is always first
for NS.
2520 attributes_list
= ns_make_monitor_attribute_list
(monitors
, n_monitors
,
2523 free_monitors
(monitors
, n_monitors
);
2524 return attributes_list
;
2528 DEFUN
("x
-display
-planes"
, Fx_display_planes
, Sx_display_planes
,
2530 doc: /* Return the number of bitplanes of the Nextstep display TERMINAL.
2531 The optional argument TERMINAL specifies which display to ask about.
2532 TERMINAL should be a terminal object, a frame or a display name (a string).
2533 If omitted or nil, that stands for the selected frame's display. */)
2534 (Lisp_Object
terminal)
2536 check_ns_display_info
(terminal);
2538 (NSBitsPerPixelFromDepth
([[[NSScreen screens
] objectAtIndex
:0] depth
]));
2542 DEFUN
("x
-display
-color
-cells"
, Fx_display_color_cells
, Sx_display_color_cells
,
2544 doc: /* Returns the number of color cells of the Nextstep display TERMINAL.
2545 The optional argument TERMINAL specifies which display to ask about.
2546 TERMINAL should be a terminal object, a frame or a display name (a string).
2547 If omitted or nil, that stands for the selected frame's display. */)
2548 (Lisp_Object
terminal)
2550 struct ns_display_info
*dpyinfo
= check_ns_display_info
(terminal);
2551 /* We force 24+ bit depths to 24-bit to prevent an overflow. */
2552 return make_number
(1 << min (dpyinfo
->n_planes
, 24));
2556 /* Unused dummy def needed for compatibility. */
2557 Lisp_Object tip_frame
;
2559 /* TODO: move to xdisp or similar */
2561 compute_tip_xy
(struct frame
*f
,
2570 Lisp_Object left
, top
;
2571 EmacsView
*view = FRAME_NS_VIEW
(f
);
2572 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(f
);
2575 /* Start with user-specified or mouse position. */
2576 left
= Fcdr
(Fassq
(Qleft
, parms
));
2577 top
= Fcdr
(Fassq
(Qtop
, parms
));
2579 if (!INTEGERP
(left
) ||
!INTEGERP
(top
))
2581 pt.x
= dpyinfo
->last_mouse_motion_x
;
2582 pt.y
= dpyinfo
->last_mouse_motion_y
;
2583 /* Convert to screen coordinates */
2584 pt
= [view convertPoint
: pt toView
: nil
];
2585 pt
= [[view window
] convertBaseToScreen
: pt
];
2589 /* Absolute coordinates. */
2591 pt.y
= x_display_pixel_height
(FRAME_DISPLAY_INFO
(f
)) - XINT
(top
)
2595 /* Ensure in bounds. (Note, screen origin = lower left.) */
2596 if (INTEGERP
(left
))
2598 else if (pt.x
+ XINT
(dx
) <= 0)
2599 *root_x
= 0; /* Can happen for negative dx */
2600 else if (pt.x
+ XINT
(dx
) + width
2601 <= x_display_pixel_width
(FRAME_DISPLAY_INFO
(f
)))
2602 /* It fits to the right of the pointer. */
2603 *root_x
= pt.x
+ XINT
(dx
);
2604 else if (width
+ XINT
(dx
) <= pt.x
)
2605 /* It fits to the left of the pointer. */
2606 *root_x
= pt.x
- width
- XINT
(dx
);
2608 /* Put it left justified on the screen -- it ought to fit that way. */
2613 else if (pt.y
- XINT
(dy
) - height
>= 0)
2614 /* It fits below the pointer. */
2615 *root_y
= pt.y
- height
- XINT
(dy
);
2616 else if (pt.y
+ XINT
(dy
) + height
2617 <= x_display_pixel_height
(FRAME_DISPLAY_INFO
(f
)))
2618 /* It fits above the pointer */
2619 *root_y
= pt.y
+ XINT
(dy
);
2621 /* Put it on the top. */
2622 *root_y
= x_display_pixel_height
(FRAME_DISPLAY_INFO
(f
)) - height
;
2626 DEFUN
("x
-show
-tip"
, Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
2627 doc: /* Show STRING in a \"tooltip\" window on frame FRAME.
2628 A tooltip window is a small window displaying a string.
2630 This is an internal function; Lisp code should call `tooltip-show'.
2632 FRAME nil or omitted means use the selected frame.
2634 PARMS is an optional list of frame parameters which can be used to
2635 change the tooltip's appearance.
2637 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
2638 means use the default timeout of 5 seconds.
2640 If the list of frame parameters PARMS contains a `left' parameter,
2641 the tooltip is displayed at that x-position. Otherwise it is
2642 displayed at the mouse position, with offset DX added (default is 5 if
2643 DX isn't specified). Likewise for the y-position; if a `top' frame
2644 parameter is specified, it determines the y-position of the tooltip
2645 window, otherwise it is displayed at the mouse position, with offset
2646 DY added (default is -10).
2648 A tooltip's maximum size is specified by `x-max-tooltip-size'.
2649 Text larger than the specified size is clipped. */)
2650 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
2653 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2654 ptrdiff_t count
= SPECPDL_INDEX
();
2659 specbind
(Qinhibit_redisplay
, Qt
);
2661 GCPRO4
(string
, parms
, frame
, timeout
);
2663 CHECK_STRING
(string
);
2664 str
= SSDATA
(string
);
2665 f
= decode_window_system_frame
(frame
);
2667 timeout
= make_number
(5);
2669 CHECK_NATNUM
(timeout
);
2672 dx
= make_number
(5);
2677 dy
= make_number
(-10);
2682 if (ns_tooltip
== nil
)
2683 ns_tooltip
= [[EmacsTooltip alloc
] init
];
2687 [ns_tooltip setText
: str
];
2688 size = [ns_tooltip frame
].
size;
2690 /* Move the tooltip window where the mouse pointer is. Resize and
2692 compute_tip_xy
(f
, parms
, dx
, dy
, (int
)size.width
, (int
)size.height
,
2695 [ns_tooltip showAtX
: root_x Y
: root_y
for: XINT
(timeout
)];
2699 return unbind_to
(count
, Qnil
);
2703 DEFUN
("x
-hide
-tip"
, Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
2704 doc: /* Hide the current tooltip window, if there is any.
2705 Value is t if tooltip was open, nil otherwise. */)
2708 if (ns_tooltip
== nil ||
![ns_tooltip isActive
])
2715 /* ==========================================================================
2717 Class implementations
2719 ========================================================================== */
2722 Handle arrow/function/control keys and copy/paste/cut in file dialogs.
2723 Return YES if handled, NO if not.
2726 handlePanelKeys
(NSSavePanel
*panel
, NSEvent
*theEvent
)
2732 if ([theEvent
type] != NSKeyDown
) return NO
;
2733 s
= [theEvent characters
];
2735 for (i
= 0; i
< [s
length]; ++i
)
2737 int ch
= (int
) [s characterAtIndex
: i
];
2740 case NSHomeFunctionKey
:
2741 case NSDownArrowFunctionKey
:
2742 case NSUpArrowFunctionKey
:
2743 case NSLeftArrowFunctionKey
:
2744 case NSRightArrowFunctionKey
:
2745 case NSPageUpFunctionKey
:
2746 case NSPageDownFunctionKey
:
2747 case NSEndFunctionKey
:
2748 /* Don't send command modified keys, as those are handled in the
2749 performKeyEquivalent method of the super class.
2751 if (! ([theEvent modifierFlags
] & NSCommandKeyMask
))
2753 [panel sendEvent
: theEvent
];
2757 /* As we don't have the standard key commands for
2758 copy/paste/cut/select-all in our edit menu, we must handle
2759 them here. TODO: handle Emacs key bindings for copy/cut/select-all
2760 here, paste works, because we have that in our Edit menu.
2761 I.e. refactor out code in nsterm.m, keyDown: to figure out the
2767 case 'a': // Select
all
2768 if ([theEvent modifierFlags
] & NSCommandKeyMask
)
2777 : @selector
(selectAll
:))))
2782 // Send
all control keys
, as the
text field supports C
-a
, C
-f
, C
-e
2784 if ([theEvent modifierFlags
] & NSControlKeyMask
)
2786 [panel sendEvent
: theEvent
];
2797 @implementation EmacsSavePanel
2798 - (BOOL
)performKeyEquivalent
:(NSEvent
*)theEvent
2800 BOOL ret
= handlePanelKeys
(self
, theEvent
);
2802 ret
= [super performKeyEquivalent
:theEvent
];
2808 @implementation EmacsOpenPanel
2809 - (BOOL
)performKeyEquivalent
:(NSEvent
*)theEvent
2811 // NSOpenPanel inherits NSSavePanel
, so passing self is OK.
2812 BOOL ret
= handlePanelKeys
(self
, theEvent
);
2814 ret
= [super performKeyEquivalent
:theEvent
];
2820 @implementation EmacsFileDelegate
2821 /* --------------------------------------------------------------------------
2822 Delegate methods for Open/Save panels
2823 -------------------------------------------------------------------------- */
2824 - (BOOL
)panel
: (id
)sender isValidFilename
: (NSString
*)filename
2828 - (BOOL
)panel
: (id
)sender shouldShowFilename
: (NSString
*)filename
2832 - (NSString
*)panel
: (id
)sender userEnteredFilename
: (NSString
*)filename
2833 confirmed
: (BOOL
)okFlag
2842 /* ==========================================================================
2844 Lisp interface declaration
2846 ========================================================================== */
2850 syms_of_nsfns
(void
)
2852 Qfontsize
= intern_c_string
("fontsize"
);
2853 staticpro
(&Qfontsize
);
2855 DEFVAR_LISP
("ns
-icon
-type-alist"
, Vns_icon_type_alist
,
2856 doc: /* Alist of elements (REGEXP . IMAGE) for images of icons associated to frames.
2857 If the title of a frame matches REGEXP, then IMAGE.tiff is
2858 selected as the image of the icon representing the frame when it's
2859 miniaturized. If an element is t, then Emacs tries to select an icon
2860 based on the filetype of the visited file.
2862 The images have to be installed in a folder called English.lproj in the
2863 Emacs folder. You have to restart Emacs after installing new icons.
2865 Example: Install an icon Gnus.tiff and execute the following code
2867 (setq ns-icon-type-alist
2868 (append ns-icon-type-alist
2869 '((\"^\\\\*\\\\(Group\\\\*$\\\\|Summary \\\\|Article\\\\*$\\\\)\"
2872 When you miniaturize a Group, Summary or Article frame, Gnus.tiff will
2873 be used as the image of the icon representing the frame. */);
2874 Vns_icon_type_alist
= list1
(Qt
);
2876 DEFVAR_LISP
("ns
-version-string"
, Vns_version_string
,
2877 doc: /* Toolkit version for NS Windowing. */);
2878 Vns_version_string
= ns_appkit_version_str
();
2880 defsubr
(&Sns_read_file_name
);
2881 defsubr
(&Sns_get_resource
);
2882 defsubr
(&Sns_set_resource
);
2883 defsubr
(&Sxw_display_color_p
); /* this and next called directly by C code */
2884 defsubr
(&Sx_display_grayscale_p
);
2885 defsubr
(&Sns_font_name
);
2886 defsubr
(&Sns_list_colors
);
2887 #ifdef NS_IMPL_COCOA
2888 defsubr
(&Sns_do_applescript
);
2890 defsubr
(&Sxw_color_defined_p
);
2891 defsubr
(&Sxw_color_values
);
2892 defsubr
(&Sx_server_max_request_size
);
2893 defsubr
(&Sx_server_vendor
);
2894 defsubr
(&Sx_server_version
);
2895 defsubr
(&Sx_display_pixel_width
);
2896 defsubr
(&Sx_display_pixel_height
);
2897 defsubr
(&Sns_display_monitor_attributes_list
);
2898 defsubr
(&Sx_display_mm_width
);
2899 defsubr
(&Sx_display_mm_height
);
2900 defsubr
(&Sx_display_screens
);
2901 defsubr
(&Sx_display_planes
);
2902 defsubr
(&Sx_display_color_cells
);
2903 defsubr
(&Sx_display_visual_class
);
2904 defsubr
(&Sx_display_backing_store
);
2905 defsubr
(&Sx_display_save_under
);
2906 defsubr
(&Sx_create_frame
);
2907 defsubr
(&Sx_open_connection
);
2908 defsubr
(&Sx_close_connection
);
2909 defsubr
(&Sx_display_list
);
2911 defsubr
(&Sns_hide_others
);
2912 defsubr
(&Sns_hide_emacs
);
2913 defsubr
(&Sns_emacs_info_panel
);
2914 defsubr
(&Sns_list_services
);
2915 defsubr
(&Sns_perform_service
);
2916 defsubr
(&Sns_convert_utf8_nfd_to_nfc
);
2917 defsubr
(&Sns_popup_font_panel
);
2918 defsubr
(&Sns_popup_color_panel
);
2920 defsubr
(&Sx_show_tip
);
2921 defsubr
(&Sx_hide_tip
);