aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsfns.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/nsfns.m')
-rw-r--r--src/nsfns.m331
1 files changed, 221 insertions, 110 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index 0452086201e..206c4155d01 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -1,6 +1,6 @@
1/* Functions for the NeXT/Open/GNUstep and MacOSX window system. 1/* Functions for the NeXT/Open/GNUstep and MacOSX window system.
2 2
3Copyright (C) 1989, 1992-1994, 2005-2006, 2008-2011 3Copyright (C) 1989, 1992-1994, 2005-2006, 2008-2012
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
@@ -97,6 +97,13 @@ Lisp_Object Fx_open_connection (Lisp_Object, Lisp_Object, Lisp_Object);
97 97
98extern BOOL ns_in_resize; 98extern BOOL ns_in_resize;
99 99
100/* Static variables to handle applescript execution. */
101static Lisp_Object as_script, *as_result;
102static int as_status;
103
104#if GLYPH_DEBUG
105static ptrdiff_t image_cache_refcount;
106#endif
100 107
101/* ========================================================================== 108/* ==========================================================================
102 109
@@ -321,6 +328,7 @@ static void
321x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 328x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
322{ 329{
323 NSColor *col; 330 NSColor *col;
331 CGFloat r, g, b, alpha;
324 332
325 if (ns_lisp_to_color (arg, &col)) 333 if (ns_lisp_to_color (arg, &col))
326 { 334 {
@@ -332,6 +340,10 @@ x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
332 [f->output_data.ns->foreground_color release]; 340 [f->output_data.ns->foreground_color release];
333 f->output_data.ns->foreground_color = col; 341 f->output_data.ns->foreground_color = col;
334 342
343 [col getRed: &r green: &g blue: &b alpha: &alpha];
344 FRAME_FOREGROUND_PIXEL (f) =
345 ARGB_TO_ULONG ((int)(alpha*0xff), (int)(r*0xff), (int)(g*0xff), (int)(b*0xff));
346
335 if (FRAME_NS_VIEW (f)) 347 if (FRAME_NS_VIEW (f))
336 { 348 {
337 update_face_from_frame_parameter (f, Qforeground_color, arg); 349 update_face_from_frame_parameter (f, Qforeground_color, arg);
@@ -348,7 +360,7 @@ x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
348 struct face *face; 360 struct face *face;
349 NSColor *col; 361 NSColor *col;
350 NSView *view = FRAME_NS_VIEW (f); 362 NSView *view = FRAME_NS_VIEW (f);
351 float alpha; 363 CGFloat r, g, b, alpha;
352 364
353 if (ns_lisp_to_color (arg, &col)) 365 if (ns_lisp_to_color (arg, &col))
354 { 366 {
@@ -364,10 +376,14 @@ x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
364 [col retain]; 376 [col retain];
365 [f->output_data.ns->background_color release]; 377 [f->output_data.ns->background_color release];
366 f->output_data.ns->background_color = col; 378 f->output_data.ns->background_color = col;
379
380 [col getRed: &r green: &g blue: &b alpha: &alpha];
381 FRAME_BACKGROUND_PIXEL (f) =
382 ARGB_TO_ULONG ((int)(alpha*0xff), (int)(r*0xff), (int)(g*0xff), (int)(b*0xff));
383
367 if (view != nil) 384 if (view != nil)
368 { 385 {
369 [[view window] setBackgroundColor: col]; 386 [[view window] setBackgroundColor: col];
370 alpha = [col alphaComponent];
371 387
372 if (alpha != 1.0) 388 if (alpha != 1.0)
373 [[view window] setOpaque: NO]; 389 [[view window] setOpaque: NO];
@@ -378,9 +394,8 @@ x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
378 if (face) 394 if (face)
379 { 395 {
380 col = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f); 396 col = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f);
381 face->background 397 face->background = ns_index_color
382 = (EMACS_UINT) [[col colorWithAlphaComponent: alpha] retain]; 398 ([col colorWithAlphaComponent: alpha], f);
383 [col release];
384 399
385 update_face_from_frame_parameter (f, Qbackground_color, arg); 400 update_face_from_frame_parameter (f, Qbackground_color, arg);
386 } 401 }
@@ -754,7 +769,7 @@ ns_implicitly_set_icon_type (struct frame *f)
754{ 769{
755 Lisp_Object tem; 770 Lisp_Object tem;
756 EmacsView *view = FRAME_NS_VIEW (f); 771 EmacsView *view = FRAME_NS_VIEW (f);
757 id image =nil; 772 id image = nil;
758 Lisp_Object chain, elt; 773 Lisp_Object chain, elt;
759 NSAutoreleasePool *pool; 774 NSAutoreleasePool *pool;
760 BOOL setMini = YES; 775 BOOL setMini = YES;
@@ -781,7 +796,7 @@ ns_implicitly_set_icon_type (struct frame *f)
781 } 796 }
782 797
783 for (chain = Vns_icon_type_alist; 798 for (chain = Vns_icon_type_alist;
784 (image = nil) && CONSP (chain); 799 image == nil && CONSP (chain);
785 chain = XCDR (chain)) 800 chain = XCDR (chain))
786 { 801 {
787 elt = XCAR (chain); 802 elt = XCAR (chain);
@@ -1026,6 +1041,75 @@ frame_parm_handler ns_frame_parm_handlers[] =
1026}; 1041};
1027 1042
1028 1043
1044/* Handler for signals raised during x_create_frame.
1045 FRAME is the frame which is partially constructed. */
1046
1047static Lisp_Object
1048unwind_create_frame (Lisp_Object frame)
1049{
1050 struct frame *f = XFRAME (frame);
1051
1052 /* If frame is already dead, nothing to do. This can happen if the
1053 display is disconnected after the frame has become official, but
1054 before x_create_frame removes the unwind protect. */
1055 if (!FRAME_LIVE_P (f))
1056 return Qnil;
1057
1058 /* If frame is ``official'', nothing to do. */
1059 if (NILP (Fmemq (frame, Vframe_list)))
1060 {
1061#if GLYPH_DEBUG && XASSERTS
1062 struct ns_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
1063#endif
1064
1065 x_free_frame_resources (f);
1066 free_glyphs (f);
1067
1068#if GLYPH_DEBUG
1069 /* Check that reference counts are indeed correct. */
1070 xassert (dpyinfo->terminal->image_cache->refcount == image_cache_refcount);
1071#endif
1072 return Qt;
1073 }
1074
1075 return Qnil;
1076}
1077
1078/*
1079 * Read geometry related parameters from preferences if not in PARMS.
1080 * Returns the union of parms and any preferences read.
1081 */
1082
1083static Lisp_Object
1084get_geometry_from_preferences (struct ns_display_info *dpyinfo,
1085 Lisp_Object parms)
1086{
1087 struct {
1088 const char *val;
1089 const char *cls;
1090 Lisp_Object tem;
1091 } r[] = {
1092 { "width", "Width", Qwidth },
1093 { "height", "Height", Qheight },
1094 { "left", "Left", Qleft },
1095 { "top", "Top", Qtop },
1096 };
1097
1098 int i;
1099 for (i = 0; i < sizeof (r)/sizeof (r[0]); ++i)
1100 {
1101 if (NILP (Fassq (r[i].tem, parms)))
1102 {
1103 Lisp_Object value
1104 = x_get_arg (dpyinfo, parms, r[i].tem, r[i].val, r[i].cls,
1105 RES_TYPE_NUMBER);
1106 if (! EQ (value, Qunbound))
1107 parms = Fcons (Fcons (r[i].tem, value), parms);
1108 }
1109 }
1110
1111 return parms;
1112}
1029 1113
1030/* ========================================================================== 1114/* ==========================================================================
1031 1115
@@ -1035,46 +1119,50 @@ frame_parm_handler ns_frame_parm_handlers[] =
1035 1119
1036DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, 1120DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
1037 1, 1, 0, 1121 1, 1, 0,
1038 doc: /* Make a new Nextstep window, called a \"frame\" in Emacs terms. 1122 doc: /* Make a new Nextstep window, called a "frame" in Emacs terms.
1039Return an Emacs frame object. 1123Return an Emacs frame object.
1040PARMS is an alist of frame parameters. 1124PARMS is an alist of frame parameters.
1041If the parameters specify that the frame should not have a minibuffer, 1125If the parameters specify that the frame should not have a minibuffer,
1042and do not specify a specific minibuffer window to use, 1126and do not specify a specific minibuffer window to use,
1043then `default-minibuffer-frame' must be a frame whose minibuffer can 1127then `default-minibuffer-frame' must be a frame whose minibuffer can
1044be shared by the new frame. */) 1128be shared by the new frame.
1129
1130This function is an internal primitive--use `make-frame' instead. */)
1045 (Lisp_Object parms) 1131 (Lisp_Object parms)
1046{ 1132{
1047 static int desc_ctr = 1;
1048 struct frame *f; 1133 struct frame *f;
1049 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1050 Lisp_Object frame, tem; 1134 Lisp_Object frame, tem;
1051 Lisp_Object name; 1135 Lisp_Object name;
1052 int minibuffer_only = 0; 1136 int minibuffer_only = 0;
1137 int window_prompting = 0;
1138 int width, height;
1053 int count = specpdl_ptr - specpdl; 1139 int count = specpdl_ptr - specpdl;
1140 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1054 Lisp_Object display; 1141 Lisp_Object display;
1055 struct ns_display_info *dpyinfo = NULL; 1142 struct ns_display_info *dpyinfo = NULL;
1056 Lisp_Object parent; 1143 Lisp_Object parent;
1057 struct kboard *kb; 1144 struct kboard *kb;
1058 Lisp_Object tfont, tfontsize; 1145 Lisp_Object tfont, tfontsize;
1059 int window_prompting = 0; 1146 static int desc_ctr = 1;
1060 int width, height;
1061 1147
1062 check_ns (); 1148 check_ns ();
1063 1149
1064 /* Seems a little strange, but other terms do it. Perhaps the code below 1150 /* x_get_arg modifies parms. */
1065 is modifying something? */
1066 parms = Fcopy_alist (parms); 1151 parms = Fcopy_alist (parms);
1067 1152
1153 /* Use this general default value to start with
1154 until we know if this frame has a specified name. */
1155 Vx_resource_name = Vinvocation_name;
1156
1068 display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_STRING); 1157 display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_STRING);
1069 if (EQ (display, Qunbound)) 1158 if (EQ (display, Qunbound))
1070 display = Qnil; 1159 display = Qnil;
1071 dpyinfo = check_ns_display_info (display); 1160 dpyinfo = check_ns_display_info (display);
1161 kb = dpyinfo->terminal->kboard;
1072 1162
1073 if (!dpyinfo->terminal->name) 1163 if (!dpyinfo->terminal->name)
1074 error ("Terminal is not live, can't create new frames on it"); 1164 error ("Terminal is not live, can't create new frames on it");
1075 1165
1076 kb = dpyinfo->terminal->kboard;
1077
1078 name = x_get_arg (dpyinfo, parms, Qname, 0, 0, RES_TYPE_STRING); 1166 name = x_get_arg (dpyinfo, parms, Qname, 0, 0, RES_TYPE_STRING);
1079 if (!STRINGP (name) 1167 if (!STRINGP (name)
1080 && ! EQ (name, Qunbound) 1168 && ! EQ (name, Qunbound)
@@ -1083,8 +1171,6 @@ be shared by the new frame. */)
1083 1171
1084 if (STRINGP (name)) 1172 if (STRINGP (name))
1085 Vx_resource_name = name; 1173 Vx_resource_name = name;
1086 else
1087 Vx_resource_name = Vinvocation_name;
1088 1174
1089 parent = x_get_arg (dpyinfo, parms, Qparent_id, 0, 0, RES_TYPE_NUMBER); 1175 parent = x_get_arg (dpyinfo, parms, Qparent_id, 0, 0, RES_TYPE_NUMBER);
1090 if (EQ (parent, Qunbound)) 1176 if (EQ (parent, Qunbound))
@@ -1092,57 +1178,36 @@ be shared by the new frame. */)
1092 if (! NILP (parent)) 1178 if (! NILP (parent))
1093 CHECK_NUMBER (parent); 1179 CHECK_NUMBER (parent);
1094 1180
1181 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
1182 /* No need to protect DISPLAY because that's not used after passing
1183 it to make_frame_without_minibuffer. */
1095 frame = Qnil; 1184 frame = Qnil;
1096 GCPRO4 (parms, parent, name, frame); 1185 GCPRO4 (parms, parent, name, frame);
1097
1098 tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer", 1186 tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer",
1099 RES_TYPE_SYMBOL); 1187 RES_TYPE_SYMBOL);
1100 if (EQ (tem, Qnone) || NILP (tem)) 1188 if (EQ (tem, Qnone) || NILP (tem))
1101 {
1102 f = make_frame_without_minibuffer (Qnil, kb, display); 1189 f = make_frame_without_minibuffer (Qnil, kb, display);
1103 }
1104 else if (EQ (tem, Qonly)) 1190 else if (EQ (tem, Qonly))
1105 { 1191 {
1106 f = make_minibuffer_frame (); 1192 f = make_minibuffer_frame ();
1107 minibuffer_only = 1; 1193 minibuffer_only = 1;
1108 } 1194 }
1109 else if (WINDOWP (tem)) 1195 else if (WINDOWP (tem))
1110 {
1111 f = make_frame_without_minibuffer (tem, kb, display); 1196 f = make_frame_without_minibuffer (tem, kb, display);
1112 }
1113 else 1197 else
1114 {
1115 f = make_frame (1); 1198 f = make_frame (1);
1116 }
1117
1118 /* Set the name; the functions to which we pass f expect the name to
1119 be set. */
1120 if (EQ (name, Qunbound) || NILP (name) || (XTYPE (name) != Lisp_String))
1121 {
1122 f->name = build_string ([ns_app_name UTF8String]);
1123 f->explicit_name =0;
1124 }
1125 else
1126 {
1127 f->name = name;
1128 f->explicit_name = 1;
1129 specbind (Qx_resource_name, name);
1130 }
1131 1199
1132 XSETFRAME (frame, f); 1200 XSETFRAME (frame, f);
1133 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1; 1201 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
1134 1202
1135 f->terminal = dpyinfo->terminal; 1203 f->terminal = dpyinfo->terminal;
1136 f->terminal->reference_count++;
1137 1204
1138 f->output_method = output_ns; 1205 f->output_method = output_ns;
1139 f->output_data.ns = (struct ns_output *)xmalloc (sizeof *(f->output_data.ns)); 1206 f->output_data.ns = (struct ns_output *)xmalloc (sizeof *(f->output_data.ns));
1140 memset (f->output_data.ns, 0, sizeof (*(f->output_data.ns))); 1207 memset (f->output_data.ns, 0, sizeof *(f->output_data.ns));
1141 1208
1142 FRAME_FONTSET (f) = -1; 1209 FRAME_FONTSET (f) = -1;
1143 1210
1144 /* record_unwind_protect (unwind_create_frame, frame); safety; maybe later? */
1145
1146 f->icon_name = x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title", 1211 f->icon_name = x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title",
1147 RES_TYPE_STRING); 1212 RES_TYPE_STRING);
1148 if (! STRINGP (f->icon_name)) 1213 if (! STRINGP (f->icon_name))
@@ -1150,6 +1215,9 @@ be shared by the new frame. */)
1150 1215
1151 FRAME_NS_DISPLAY_INFO (f) = dpyinfo; 1216 FRAME_NS_DISPLAY_INFO (f) = dpyinfo;
1152 1217
1218 /* With FRAME_NS_DISPLAY_INFO set up, this unwind-protect is safe. */
1219 record_unwind_protect (unwind_create_frame, frame);
1220
1153 f->output_data.ns->window_desc = desc_ctr++; 1221 f->output_data.ns->window_desc = desc_ctr++;
1154 if (!NILP (parent)) 1222 if (!NILP (parent))
1155 { 1223 {
@@ -1162,6 +1230,20 @@ be shared by the new frame. */)
1162 f->output_data.ns->explicit_parent = 0; 1230 f->output_data.ns->explicit_parent = 0;
1163 } 1231 }
1164 1232
1233 /* Set the name; the functions to which we pass f expect the name to
1234 be set. */
1235 if (EQ (name, Qunbound) || NILP (name) || ! STRINGP (name))
1236 {
1237 f->name = build_string ([ns_app_name UTF8String]);
1238 f->explicit_name = 0;
1239 }
1240 else
1241 {
1242 f->name = name;
1243 f->explicit_name = 1;
1244 specbind (Qx_resource_name, name);
1245 }
1246
1165 f->resx = dpyinfo->resx; 1247 f->resx = dpyinfo->resx;
1166 f->resy = dpyinfo->resy; 1248 f->resy = dpyinfo->resy;
1167 1249
@@ -1204,18 +1286,22 @@ be shared by the new frame. */)
1204 "foreground", "Foreground", RES_TYPE_STRING); 1286 "foreground", "Foreground", RES_TYPE_STRING);
1205 x_default_parameter (f, parms, Qbackground_color, build_string ("White"), 1287 x_default_parameter (f, parms, Qbackground_color, build_string ("White"),
1206 "background", "Background", RES_TYPE_STRING); 1288 "background", "Background", RES_TYPE_STRING);
1207 /* FIXME: not suppported yet in Nextstep */ 1289 /* FIXME: not supported yet in Nextstep */
1208 x_default_parameter (f, parms, Qline_spacing, Qnil, 1290 x_default_parameter (f, parms, Qline_spacing, Qnil,
1209 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER); 1291 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
1210 x_default_parameter (f, parms, Qleft_fringe, Qnil, 1292 x_default_parameter (f, parms, Qleft_fringe, Qnil,
1211 "leftFringe", "LeftFringe", RES_TYPE_NUMBER); 1293 "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
1212 x_default_parameter (f, parms, Qright_fringe, Qnil, 1294 x_default_parameter (f, parms, Qright_fringe, Qnil,
1213 "rightFringe", "RightFringe", RES_TYPE_NUMBER); 1295 "rightFringe", "RightFringe", RES_TYPE_NUMBER);
1214 /* end PENDING */ 1296
1297#if GLYPH_DEBUG
1298 image_cache_refcount =
1299 FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0;
1300#endif
1215 1301
1216 init_frame_faces (f); 1302 init_frame_faces (f);
1217 1303
1218 /* The X resources controlling the menu-bar and tool-bar are 1304 /* The resources controlling the menu-bar and tool-bar are
1219 processed specially at startup, and reflected in the mode 1305 processed specially at startup, and reflected in the mode
1220 variables; ignore them here. */ 1306 variables; ignore them here. */
1221 x_default_parameter (f, parms, Qmenu_bar_lines, 1307 x_default_parameter (f, parms, Qmenu_bar_lines,
@@ -1232,38 +1318,7 @@ be shared by the new frame. */)
1232 x_default_parameter (f, parms, Qtitle, Qnil, "title", "Title", 1318 x_default_parameter (f, parms, Qtitle, Qnil, "title", "Title",
1233 RES_TYPE_STRING); 1319 RES_TYPE_STRING);
1234 1320
1235/* TODO: other terms seem to get away w/o this complexity.. */ 1321 parms = get_geometry_from_preferences (dpyinfo, parms);
1236 if (NILP (Fassq (Qwidth, parms)))
1237 {
1238 Lisp_Object value
1239 = x_get_arg (dpyinfo, parms, Qwidth, "width", "Width",
1240 RES_TYPE_NUMBER);
1241 if (! EQ (value, Qunbound))
1242 parms = Fcons (Fcons (Qwidth, value), parms);
1243 }
1244 if (NILP (Fassq (Qheight, parms)))
1245 {
1246 Lisp_Object value
1247 = x_get_arg (dpyinfo, parms, Qheight, "height", "Height",
1248 RES_TYPE_NUMBER);
1249 if (! EQ (value, Qunbound))
1250 parms = Fcons (Fcons (Qheight, value), parms);
1251 }
1252 if (NILP (Fassq (Qleft, parms)))
1253 {
1254 Lisp_Object value
1255 = x_get_arg (dpyinfo, parms, Qleft, "left", "Left", RES_TYPE_NUMBER);
1256 if (! EQ (value, Qunbound))
1257 parms = Fcons (Fcons (Qleft, value), parms);
1258 }
1259 if (NILP (Fassq (Qtop, parms)))
1260 {
1261 Lisp_Object value
1262 = x_get_arg (dpyinfo, parms, Qtop, "top", "Top", RES_TYPE_NUMBER);
1263 if (! EQ (value, Qunbound))
1264 parms = Fcons (Fcons (Qtop, value), parms);
1265 }
1266
1267 window_prompting = x_figure_window_size (f, parms, 1); 1322 window_prompting = x_figure_window_size (f, parms, 1);
1268 1323
1269 tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); 1324 tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
@@ -1285,23 +1340,27 @@ be shared by the new frame. */)
1285 1340
1286 x_icon (f, parms); 1341 x_icon (f, parms);
1287 1342
1343 /* ns_display_info does not have a reference_count. */
1344 f->terminal->reference_count++;
1345
1288 /* It is now ok to make the frame official even if we get an error below. 1346 /* It is now ok to make the frame official even if we get an error below.
1289 The frame needs to be on Vframe_list or making it visible won't work. */ 1347 The frame needs to be on Vframe_list or making it visible won't work. */
1290 Vframe_list = Fcons (frame, Vframe_list); 1348 Vframe_list = Fcons (frame, Vframe_list);
1291 /*FRAME_NS_DISPLAY_INFO (f)->reference_count++; */ 1349
1292 1350 x_default_parameter (f, parms, Qicon_type, Qnil,
1293 x_default_parameter (f, parms, Qicon_type, Qnil, "bitmapIcon", "BitmapIcon", 1351 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
1294 RES_TYPE_SYMBOL); 1352
1295 x_default_parameter (f, parms, Qauto_raise, Qnil, "autoRaise", "AutoRaiseLower", 1353 x_default_parameter (f, parms, Qauto_raise, Qnil,
1296 RES_TYPE_BOOLEAN); 1354 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
1297 x_default_parameter (f, parms, Qauto_lower, Qnil, "autoLower", "AutoLower", 1355 x_default_parameter (f, parms, Qauto_lower, Qnil,
1298 RES_TYPE_BOOLEAN); 1356 "autoLower", "AutoLower", RES_TYPE_BOOLEAN);
1299 x_default_parameter (f, parms, Qcursor_type, Qbox, "cursorType", "CursorType", 1357 x_default_parameter (f, parms, Qcursor_type, Qbox,
1300 RES_TYPE_SYMBOL); 1358 "cursorType", "CursorType", RES_TYPE_SYMBOL);
1301 x_default_parameter (f, parms, Qscroll_bar_width, Qnil, "scrollBarWidth", 1359 x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
1302 "ScrollBarWidth", RES_TYPE_NUMBER); 1360 "scrollBarWidth", "ScrollBarWidth",
1303 x_default_parameter (f, parms, Qalpha, Qnil, "alpha", "Alpha", 1361 RES_TYPE_NUMBER);
1304 RES_TYPE_NUMBER); 1362 x_default_parameter (f, parms, Qalpha, Qnil,
1363 "alpha", "Alpha", RES_TYPE_NUMBER);
1305 1364
1306 width = FRAME_COLS (f); 1365 width = FRAME_COLS (f);
1307 height = FRAME_LINES (f); 1366 height = FRAME_LINES (f);
@@ -1312,20 +1371,24 @@ be shared by the new frame. */)
1312 1371
1313 if (! f->output_data.ns->explicit_parent) 1372 if (! f->output_data.ns->explicit_parent)
1314 { 1373 {
1315 tem = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL); 1374 Lisp_Object visibility;
1316 if (EQ (tem, Qunbound)) 1375
1317 tem = Qt; 1376 visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
1318 x_set_visibility (f, tem, Qnil); 1377 RES_TYPE_SYMBOL);
1319 if (EQ (tem, Qicon)) 1378 if (EQ (visibility, Qunbound))
1379 visibility = Qt;
1380
1381 if (EQ (visibility, Qicon))
1320 x_iconify_frame (f); 1382 x_iconify_frame (f);
1321 else if (! NILP (tem)) 1383 else if (! NILP (visibility))
1322 { 1384 {
1323 x_make_frame_visible (f); 1385 x_make_frame_visible (f);
1324 f->async_visible = 1;
1325 [[FRAME_NS_VIEW (f) window] makeKeyWindow]; 1386 [[FRAME_NS_VIEW (f) window] makeKeyWindow];
1326 } 1387 }
1327 else 1388 else
1328 f->async_visible = 0; 1389 {
1390 /* Must have been Qnil. */
1391 }
1329 } 1392 }
1330 1393
1331 if (FRAME_HAS_MINIBUF_P (f) 1394 if (FRAME_HAS_MINIBUF_P (f)
@@ -1340,6 +1403,9 @@ be shared by the new frame. */)
1340 f->param_alist = Fcons (XCAR (tem), f->param_alist); 1403 f->param_alist = Fcons (XCAR (tem), f->param_alist);
1341 1404
1342 UNGCPRO; 1405 UNGCPRO;
1406
1407 /* Make sure windows on this frame appear in calls to next-window
1408 and similar functions. */
1343 Vwindow_list = Qnil; 1409 Vwindow_list = Qnil;
1344 1410
1345 return unbind_to (count, frame); 1411 return unbind_to (count, frame);
@@ -1479,6 +1545,17 @@ Optional arg INIT, if non-nil, provides a default file name to use. */)
1479 return ret ? fname : Qnil; 1545 return ret ? fname : Qnil;
1480} 1546}
1481 1547
1548const char *
1549ns_get_defaults_value (const char *key)
1550{
1551 NSObject *obj = [[NSUserDefaults standardUserDefaults]
1552 objectForKey: [NSString stringWithUTF8String: key]];
1553
1554 if (!obj) return NULL;
1555
1556 return [[NSString stringWithFormat: @"%@", obj] UTF8String];
1557}
1558
1482 1559
1483DEFUN ("ns-get-resource", Fns_get_resource, Sns_get_resource, 2, 2, 0, 1560DEFUN ("ns-get-resource", Fns_get_resource, Sns_get_resource, 2, 2, 0,
1484 doc: /* Return the value of the property NAME of OWNER from the defaults database. 1561 doc: /* Return the value of the property NAME of OWNER from the defaults database.
@@ -1493,9 +1570,7 @@ If OWNER is nil, Emacs is assumed. */)
1493 CHECK_STRING (name); 1570 CHECK_STRING (name);
1494/*fprintf (stderr, "ns-get-resource checking resource '%s'\n", SDATA (name)); */ 1571/*fprintf (stderr, "ns-get-resource checking resource '%s'\n", SDATA (name)); */
1495 1572
1496 value =[[[NSUserDefaults standardUserDefaults] 1573 value = ns_get_defaults_value (SDATA (name));
1497 objectForKey: [NSString stringWithUTF8String: SDATA (name)]]
1498 UTF8String];
1499 1574
1500 if (value) 1575 if (value)
1501 return build_string (value); 1576 return build_string (value);
@@ -1624,7 +1699,7 @@ If omitted or nil, the selected frame's display is used. */)
1624 1699
1625DEFUN ("x-display-backing-store", Fx_display_backing_store, 1700DEFUN ("x-display-backing-store", Fx_display_backing_store,
1626 Sx_display_backing_store, 0, 1, 0, 1701 Sx_display_backing_store, 0, 1, 0,
1627 doc: /* Return whether the Nexstep display DISPLAY supports backing store. 1702 doc: /* Return whether the Nextstep display DISPLAY supports backing store.
1628The value may be `buffered', `retained', or `non-retained'. 1703The value may be `buffered', `retained', or `non-retained'.
1629DISPLAY should be a frame, the display name as a string, or a terminal ID. 1704DISPLAY should be a frame, the display name as a string, or a terminal ID.
1630If omitted or nil, the selected frame's display is used. */) 1705If omitted or nil, the selected frame's display is used. */)
@@ -1814,7 +1889,7 @@ DEFUN ("ns-emacs-info-panel", Fns_emacs_info_panel, Sns_emacs_info_panel,
1814 1889
1815 1890
1816DEFUN ("ns-font-name", Fns_font_name, Sns_font_name, 1, 1, 0, 1891DEFUN ("ns-font-name", Fns_font_name, Sns_font_name, 1, 1, 0,
1817 doc: /* Determine font postscript or family name for font NAME. 1892 doc: /* Determine font PostScript or family name for font NAME.
1818NAME should be a string containing either the font name or an XLFD 1893NAME should be a string containing either the font name or an XLFD
1819font descriptor. If string contains `fontset' and not 1894font descriptor. If string contains `fontset' and not
1820`fontset-startup', it is left alone. */) 1895`fontset-startup', it is left alone. */)
@@ -2043,6 +2118,15 @@ ns_do_applescript (Lisp_Object script, Lisp_Object *result)
2043 return 0; 2118 return 0;
2044} 2119}
2045 2120
2121/* Helper function called from sendEvent to run applescript
2122 from within the main event loop. */
2123
2124void
2125ns_run_ascript (void)
2126{
2127 as_status = ns_do_applescript (as_script, as_result);
2128}
2129
2046DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0, 2130DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0,
2047 doc: /* Execute AppleScript SCRIPT and return the result. 2131 doc: /* Execute AppleScript SCRIPT and return the result.
2048If compilation and execution are successful, the resulting script value 2132If compilation and execution are successful, the resulting script value
@@ -2052,12 +2136,37 @@ In case the execution fails, an error is signaled. */)
2052{ 2136{
2053 Lisp_Object result; 2137 Lisp_Object result;
2054 int status; 2138 int status;
2139 NSEvent *nxev;
2055 2140
2056 CHECK_STRING (script); 2141 CHECK_STRING (script);
2057 check_ns (); 2142 check_ns ();
2058 2143
2059 BLOCK_INPUT; 2144 BLOCK_INPUT;
2060 status = ns_do_applescript (script, &result); 2145
2146 as_script = script;
2147 as_result = &result;
2148
2149 /* executing apple script requires the event loop to run, otherwise
2150 errors aren't returned and executeAndReturnError hangs forever.
2151 Post an event that runs applescript and then start the event loop.
2152 The event loop is exited when the script is done. */
2153 nxev = [NSEvent otherEventWithType: NSApplicationDefined
2154 location: NSMakePoint (0, 0)
2155 modifierFlags: 0
2156 timestamp: 0
2157 windowNumber: [[NSApp mainWindow] windowNumber]
2158 context: [NSApp context]
2159 subtype: 0
2160 data1: 0
2161 data2: NSAPP_DATA2_RUNASSCRIPT];
2162
2163 [NSApp postEvent: nxev atStart: NO];
2164 [NSApp run];
2165
2166 status = as_status;
2167 as_status = 0;
2168 as_script = Qnil;
2169 as_result = 0;
2061 UNBLOCK_INPUT; 2170 UNBLOCK_INPUT;
2062 if (status == 0) 2171 if (status == 0)
2063 return result; 2172 return result;
@@ -2116,8 +2225,7 @@ x_get_string_resource (XrmDatabase rdb, char *name, char *class)
2116 /* --quick was passed, so this is a no-op. */ 2225 /* --quick was passed, so this is a no-op. */
2117 return NULL; 2226 return NULL;
2118 2227
2119 res = [[[NSUserDefaults standardUserDefaults] objectForKey: 2228 res = ns_get_defaults_value (toCheck);
2120 [NSString stringWithUTF8String: toCheck]] UTF8String];
2121 return !res ? NULL : 2229 return !res ? NULL :
2122 (!strncasecmp (res, "YES", 3) ? "true" : 2230 (!strncasecmp (res, "YES", 3) ? "true" :
2123 (!strncasecmp (res, "NO", 2) ? "false" : res)); 2231 (!strncasecmp (res, "NO", 2) ? "false" : res));
@@ -2661,4 +2769,7 @@ be used as the image of the icon representing the frame. */);
2661 /* used only in fontset.c */ 2769 /* used only in fontset.c */
2662 check_window_system_func = check_ns; 2770 check_window_system_func = check_ns;
2663 2771
2772 as_status = 0;
2773 as_script = Qnil;
2774 as_result = 0;
2664} 2775}