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