aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog5
-rw-r--r--src/nsfns.m176
2 files changed, 94 insertions, 87 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index dff7b738860..49c13b4fdfe 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
12008-07-27 Adrian Robert <Adrian.B.Robert@gmail.com>
2
3 * nsfns.m (do-applescript, do_applescript): Rename to
4 ns-do-applescript, ns_do_applescript, and move within file.
5
12008-07-27 Dan Nicolaescu <dann@ics.uci.edu> 62008-07-27 Dan Nicolaescu <dann@ics.uci.edu>
2 7
3 Remove support for Mac Carbon. 8 Remove support for Mac Carbon.
diff --git a/src/nsfns.m b/src/nsfns.m
index b8e28f1d13f..493885f3531 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -1999,6 +1999,93 @@ DEFUN ("ns-convert-utf8-nfd-to-nfc", Fns_convert_utf8_nfd_to_nfc,
1999} 1999}
2000 2000
2001 2001
2002#ifdef NS_IMPL_COCOA
2003
2004/* Compile and execute the AppleScript SCRIPT and return the error
2005 status as function value. A zero is returned if compilation and
2006 execution is successful, in which case *RESULT is set to a Lisp
2007 string or a number containing the resulting script value. Otherwise,
2008 1 is returned. */
2009static int
2010ns_do_applescript (script, result)
2011 Lisp_Object script, *result;
2012{
2013 NSAppleEventDescriptor *desc;
2014 NSDictionary* errorDict;
2015 NSAppleEventDescriptor* returnDescriptor = NULL;
2016
2017 NSAppleScript* scriptObject =
2018 [[NSAppleScript alloc] initWithSource:
2019 [NSString stringWithUTF8String: SDATA (script)]];
2020
2021 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
2022 [scriptObject release];
2023
2024 *result = Qnil;
2025
2026 if (returnDescriptor != NULL)
2027 {
2028 // successful execution
2029 if (kAENullEvent != [returnDescriptor descriptorType])
2030 {
2031 *result = Qt;
2032 // script returned an AppleScript result
2033 if ((typeUnicodeText == [returnDescriptor descriptorType]) ||
2034 (typeUTF16ExternalRepresentation
2035 == [returnDescriptor descriptorType]) ||
2036 (typeUTF8Text == [returnDescriptor descriptorType]) ||
2037 (typeCString == [returnDescriptor descriptorType]))
2038 {
2039 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2040 if (desc)
2041 *result = build_string([[desc stringValue] UTF8String]);
2042 }
2043 else
2044 {
2045 /* use typeUTF16ExternalRepresentation? */
2046 // coerce the result to the appropriate ObjC type
2047 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2048 if (desc)
2049 *result = make_number([desc int32Value]);
2050 }
2051 }
2052 }
2053 else
2054 {
2055 // no script result, return error
2056 return 1;
2057 }
2058 return 0;
2059}
2060
2061DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0,
2062 doc: /* Execute AppleScript SCRIPT and return the result. If
2063compilation and execution are successful, the resulting script value
2064is returned as a string, a number or, in the case of other constructs,
2065t. In case the execution fails, an error is signaled. */)
2066 (script)
2067 Lisp_Object script;
2068{
2069 Lisp_Object result;
2070 long status;
2071
2072 CHECK_STRING (script);
2073 check_ns ();
2074
2075 BLOCK_INPUT;
2076 status = ns_do_applescript (script, &result);
2077 UNBLOCK_INPUT;
2078 if (status == 0)
2079 return result;
2080 else if (!STRINGP (result))
2081 error ("AppleScript error %d", status);
2082 else
2083 error ("%s", SDATA (result));
2084}
2085#endif
2086
2087
2088
2002/* ========================================================================== 2089/* ==========================================================================
2003 2090
2004 Miscellaneous functions not called through hooks 2091 Miscellaneous functions not called through hooks
@@ -2121,92 +2208,6 @@ x_sync (Lisp_Object frame)
2121 ========================================================================== */ 2208 ========================================================================== */
2122 2209
2123 2210
2124#ifdef NS_IMPL_COCOA
2125
2126/* Compile and execute the AppleScript SCRIPT and return the error
2127 status as function value. A zero is returned if compilation and
2128 execution is successful, in which case *RESULT is set to a Lisp
2129 string or a number containing the resulting script value. Otherwise,
2130 1 is returned. */
2131
2132static int
2133do_applescript (script, result)
2134 Lisp_Object script, *result;
2135{
2136 NSAppleEventDescriptor *desc;
2137 NSDictionary* errorDict;
2138 NSAppleEventDescriptor* returnDescriptor = NULL;
2139
2140 NSAppleScript* scriptObject =
2141 [[NSAppleScript alloc] initWithSource:
2142 [NSString stringWithUTF8String: SDATA (script)]];
2143
2144 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
2145 [scriptObject release];
2146
2147 *result = Qnil;
2148
2149 if (returnDescriptor != NULL)
2150 {
2151 // successful execution
2152 if (kAENullEvent != [returnDescriptor descriptorType])
2153 {
2154 *result = Qt;
2155 // script returned an AppleScript result
2156 if ((typeUnicodeText == [returnDescriptor descriptorType]) ||
2157 (typeUTF16ExternalRepresentation
2158 == [returnDescriptor descriptorType]) ||
2159 (typeUTF8Text == [returnDescriptor descriptorType]) ||
2160 (typeCString == [returnDescriptor descriptorType]))
2161 {
2162 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2163 if (desc)
2164 *result = build_string([[desc stringValue] UTF8String]);
2165 }
2166 else
2167 {
2168 /* use typeUTF16ExternalRepresentation? */
2169 // coerce the result to the appropriate ObjC type
2170 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2171 if (desc)
2172 *result = make_number([desc int32Value]);
2173 }
2174 }
2175 }
2176 else
2177 {
2178 // no script result, return error
2179 return 1;
2180 }
2181 return 0;
2182}
2183
2184DEFUN ("do-applescript", Fdo_applescript, Sdo_applescript, 1, 1, 0,
2185 doc: /* Execute AppleScript SCRIPT and return the result. If
2186compilation and execution are successful, the resulting script value
2187is returned as a string, a number or, in the case of other constructs,
2188t. In case the execution fails, an error is signaled. */)
2189 (script)
2190 Lisp_Object script;
2191{
2192 Lisp_Object result;
2193 long status;
2194
2195 CHECK_STRING (script);
2196 check_ns ();
2197
2198 BLOCK_INPUT;
2199 status = do_applescript (script, &result);
2200 UNBLOCK_INPUT;
2201 if (status == 0)
2202 return result;
2203 else if (!STRINGP (result))
2204 error ("AppleScript error %d", status);
2205 else
2206 error ("%s", SDATA (result));
2207}
2208#endif
2209
2210DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, 2211DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
2211 doc: /* Return t if the current Nextstep display supports the color COLOR. 2212 doc: /* Return t if the current Nextstep display supports the color COLOR.
2212The optional argument FRAME is currently ignored. */) 2213The optional argument FRAME is currently ignored. */)
@@ -2313,6 +2314,7 @@ If omitted or nil, that stands for the selected frame's display. */)
2313 return make_number ((int) [ns_get_screen (display) frame].size.height); 2314 return make_number ((int) [ns_get_screen (display) frame].size.height);
2314} 2315}
2315 2316
2317
2316DEFUN ("display-usable-bounds", Fns_display_usable_bounds, 2318DEFUN ("display-usable-bounds", Fns_display_usable_bounds,
2317 Sns_display_usable_bounds, 0, 1, 0, 2319 Sns_display_usable_bounds, 0, 1, 0,
2318 doc: /*Return the bounds of the usable part of the screen. 2320 doc: /*Return the bounds of the usable part of the screen.
@@ -2639,7 +2641,7 @@ be used as the image of the icon representing the frame. */);
2639 defsubr (&Sns_font_name); 2641 defsubr (&Sns_font_name);
2640 defsubr (&Sns_list_colors); 2642 defsubr (&Sns_list_colors);
2641#ifdef NS_IMPL_COCOA 2643#ifdef NS_IMPL_COCOA
2642 defsubr (&Sdo_applescript); 2644 defsubr (&Sns_do_applescript);
2643#endif 2645#endif
2644 defsubr (&Sxw_color_defined_p); 2646 defsubr (&Sxw_color_defined_p);
2645 defsubr (&Sxw_color_values); 2647 defsubr (&Sxw_color_values);