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