aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Third2020-08-20 23:45:38 +0100
committerAlan Third2020-08-22 16:19:37 +0100
commit96e5d8ce0d92eacbd7e237e50f0b572bb56e6d66 (patch)
tree368e91ac4d498311f31dc7a5551e89eefbf1a857 /src
parent811f5890f3ad9b35464c5ccd818091abcaf6803d (diff)
downloademacs-96e5d8ce0d92eacbd7e237e50f0b572bb56e6d66.tar.gz
emacs-96e5d8ce0d92eacbd7e237e50f0b572bb56e6d66.zip
Extend NSString further and use the new methods
* src/nsfns.m (ns_set_icon_name): (ns_set_name): (ns_set_represented_filename): (ns_implicitly_set_icon_type): (ns_set_icon_type): (ns_appkit_version_str): (Fx_create_frame): (Fns_read_file_name): (Fns_get_resource): (Fns_set_resource): (Fns_list_colors): (Fns_perform_service): (ns_do_applescript): Use the new NSString methods. ([NSString stringWithLispString:]): Fix the surrogate algorithm. ([NSString lispString]): New method. * src/nsterm.h (NSString): Add new method. * src/nsterm.m ([EmacsApp openFile:]): ([EmacsApp requestService:userData:error:]): ([EmacsApp fulfillService:withArg:]): ([EmacsView changeFont:]): ([EmacsView setMarkedText:selectedRange:]): ([EmacsView initFrameFromEmacs:]): ([EmacsView performDragOperation:]): ([EmacsView performDragOperation:]): ([EmacsView performDragOperation:]): ([EmacsWindow accessibilityAttributeValue:]): Use the new NSString methods.
Diffstat (limited to 'src')
-rw-r--r--src/nsfns.m78
-rw-r--r--src/nsterm.h1
-rw-r--r--src/nsterm.m25
3 files changed, 50 insertions, 54 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index 5fca15588d0..c7956497c4c 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -390,12 +390,11 @@ ns_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
390 /* Don't change the name if it's already NAME. */ 390 /* Don't change the name if it's already NAME. */
391 if ([[view window] miniwindowTitle] 391 if ([[view window] miniwindowTitle]
392 && ([[[view window] miniwindowTitle] 392 && ([[[view window] miniwindowTitle]
393 isEqualToString: [NSString stringWithUTF8String: 393 isEqualToString: [NSString stringWithLispString:arg]]))
394 SSDATA (arg)]]))
395 return; 394 return;
396 395
397 [[view window] setMiniwindowTitle: 396 [[view window] setMiniwindowTitle:
398 [NSString stringWithUTF8String: SSDATA (arg)]]; 397 [NSString stringWithLispString:arg]];
399} 398}
400 399
401static void 400static void
@@ -437,7 +436,7 @@ ns_set_name (struct frame *f, Lisp_Object name, int explicit)
437 return; 436 return;
438 437
439 if (NILP (name)) 438 if (NILP (name))
440 name = build_string ([ns_app_name UTF8String]); 439 name = [ns_app_name lispString];
441 else 440 else
442 CHECK_STRING (name); 441 CHECK_STRING (name);
443 442
@@ -476,7 +475,7 @@ ns_set_represented_filename (struct frame *f)
476 { 475 {
477 encoded_filename = ENCODE_UTF_8 (filename); 476 encoded_filename = ENCODE_UTF_8 (filename);
478 477
479 fstr = [NSString stringWithUTF8String: SSDATA (encoded_filename)]; 478 fstr = [NSString stringWithLispString:encoded_filename];
480 if (fstr == nil) fstr = @""; 479 if (fstr == nil) fstr = @"";
481 } 480 }
482 else 481 else
@@ -723,7 +722,7 @@ ns_implicitly_set_icon_type (struct frame *f)
723 block_input (); 722 block_input ();
724 pool = [[NSAutoreleasePool alloc] init]; 723 pool = [[NSAutoreleasePool alloc] init];
725 if (f->output_data.ns->miniimage 724 if (f->output_data.ns->miniimage
726 && [[NSString stringWithUTF8String: SSDATA (f->name)] 725 && [[NSString stringWithLispString:f->name]
727 isEqualToString: [(NSImage *)f->output_data.ns->miniimage name]]) 726 isEqualToString: [(NSImage *)f->output_data.ns->miniimage name]])
728 { 727 {
729 [pool release]; 728 [pool release];
@@ -748,7 +747,7 @@ ns_implicitly_set_icon_type (struct frame *f)
748 if (SYMBOLP (elt) && EQ (elt, Qt) && SSDATA (f->name)[0] == '/') 747 if (SYMBOLP (elt) && EQ (elt, Qt) && SSDATA (f->name)[0] == '/')
749 { 748 {
750 NSString *str 749 NSString *str
751 = [NSString stringWithUTF8String: SSDATA (f->name)]; 750 = [NSString stringWithLispString:f->name];
752 if ([[NSFileManager defaultManager] fileExistsAtPath: str]) 751 if ([[NSFileManager defaultManager] fileExistsAtPath: str])
753 image = [[[NSWorkspace sharedWorkspace] iconForFile: str] retain]; 752 image = [[[NSWorkspace sharedWorkspace] iconForFile: str] retain];
754 } 753 }
@@ -760,8 +759,7 @@ ns_implicitly_set_icon_type (struct frame *f)
760 image = [EmacsImage allocInitFromFile: XCDR (elt)]; 759 image = [EmacsImage allocInitFromFile: XCDR (elt)];
761 if (image == nil) 760 if (image == nil)
762 image = [[NSImage imageNamed: 761 image = [[NSImage imageNamed:
763 [NSString stringWithUTF8String: 762 [NSString stringWithLispString:XCDR (elt)]] retain];
764 SSDATA (XCDR (elt))]] retain];
765 } 763 }
766 } 764 }
767 765
@@ -805,8 +803,7 @@ ns_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
805 803
806 image = [EmacsImage allocInitFromFile: arg]; 804 image = [EmacsImage allocInitFromFile: arg];
807 if (image == nil) 805 if (image == nil)
808 image =[NSImage imageNamed: [NSString stringWithUTF8String: 806 image =[NSImage imageNamed: [NSString stringWithLispString:arg]];
809 SSDATA (arg)]];
810 807
811 if (image == nil) 808 if (image == nil)
812 { 809 {
@@ -840,20 +837,18 @@ ns_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
840static Lisp_Object 837static Lisp_Object
841ns_appkit_version_str (void) 838ns_appkit_version_str (void)
842{ 839{
843 char tmp[256]; 840 NSString *tmp;
844 841
845#ifdef NS_IMPL_GNUSTEP 842#ifdef NS_IMPL_GNUSTEP
846 sprintf(tmp, "gnustep-gui-%s", Xstr(GNUSTEP_GUI_VERSION)); 843 tmp = [NSString stringWithFormat:@"gnustep-gui-%s", Xstr(GNUSTEP_GUI_VERSION)];
847#elif defined (NS_IMPL_COCOA) 844#elif defined (NS_IMPL_COCOA)
848 NSString *osversion 845 tmp = [NSString stringWithFormat:@"appkit-%.2f %@",
849 = [[NSProcessInfo processInfo] operatingSystemVersionString]; 846 NSAppKitVersionNumber,
850 sprintf(tmp, "appkit-%.2f %s", 847 [[NSProcessInfo processInfo] operatingSystemVersionString]];
851 NSAppKitVersionNumber,
852 [osversion UTF8String]);
853#else 848#else
854 tmp = "ns-unknown"; 849 tmp = [NSString initWithUTF8String:@"ns-unknown"];
855#endif 850#endif
856 return build_string (tmp); 851 return [tmp lispString];
857} 852}
858 853
859 854
@@ -1157,7 +1152,7 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
1157 be set. */ 1152 be set. */
1158 if (EQ (name, Qunbound) || NILP (name) || ! STRINGP (name)) 1153 if (EQ (name, Qunbound) || NILP (name) || ! STRINGP (name))
1159 { 1154 {
1160 fset_name (f, build_string ([ns_app_name UTF8String])); 1155 fset_name (f, [ns_app_name lispString]);
1161 f->explicit_name = 0; 1156 f->explicit_name = 0;
1162 } 1157 }
1163 else 1158 else
@@ -1598,12 +1593,12 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1598 Lisp_Object fname = Qnil; 1593 Lisp_Object fname = Qnil;
1599 1594
1600 NSString *promptS = NILP (prompt) || !STRINGP (prompt) ? nil : 1595 NSString *promptS = NILP (prompt) || !STRINGP (prompt) ? nil :
1601 [NSString stringWithUTF8String: SSDATA (prompt)]; 1596 [NSString stringWithLispString:prompt];
1602 NSString *dirS = NILP (dir) || !STRINGP (dir) ? 1597 NSString *dirS = NILP (dir) || !STRINGP (dir) ?
1603 [NSString stringWithUTF8String: SSDATA (BVAR (current_buffer, directory))] : 1598 [NSString stringWithLispString:BVAR (current_buffer, directory)] :
1604 [NSString stringWithUTF8String: SSDATA (dir)]; 1599 [NSString stringWithLispString:dir];
1605 NSString *initS = NILP (init) || !STRINGP (init) ? nil : 1600 NSString *initS = NILP (init) || !STRINGP (init) ? nil :
1606 [NSString stringWithUTF8String: SSDATA (init)]; 1601 [NSString stringWithLispString:init];
1607 NSEvent *nxev; 1602 NSEvent *nxev;
1608 1603
1609 check_window_system (NULL); 1604 check_window_system (NULL);
@@ -1679,7 +1674,7 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1679 { 1674 {
1680 NSString *str = ns_filename_from_panel (panel); 1675 NSString *str = ns_filename_from_panel (panel);
1681 if (! str) str = ns_directory_from_panel (panel); 1676 if (! str) str = ns_directory_from_panel (panel);
1682 if (str) fname = build_string ([str UTF8String]); 1677 if (str) fname = [str lispString];
1683 } 1678 }
1684 1679
1685 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow]; 1680 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
@@ -1709,7 +1704,7 @@ If OWNER is nil, Emacs is assumed. */)
1709 1704
1710 check_window_system (NULL); 1705 check_window_system (NULL);
1711 if (NILP (owner)) 1706 if (NILP (owner))
1712 owner = build_string([ns_app_name UTF8String]); 1707 owner = [ns_app_name lispString];
1713 CHECK_STRING (name); 1708 CHECK_STRING (name);
1714 1709
1715 value = ns_get_defaults_value (SSDATA (name)); 1710 value = ns_get_defaults_value (SSDATA (name));
@@ -1728,20 +1723,19 @@ If VALUE is nil, the default is removed. */)
1728{ 1723{
1729 check_window_system (NULL); 1724 check_window_system (NULL);
1730 if (NILP (owner)) 1725 if (NILP (owner))
1731 owner = build_string ([ns_app_name UTF8String]); 1726 owner = [ns_app_name lispString];
1732 CHECK_STRING (name); 1727 CHECK_STRING (name);
1733 if (NILP (value)) 1728 if (NILP (value))
1734 { 1729 {
1735 [[NSUserDefaults standardUserDefaults] removeObjectForKey: 1730 [[NSUserDefaults standardUserDefaults] removeObjectForKey:
1736 [NSString stringWithUTF8String: SSDATA (name)]]; 1731 [NSString stringWithLispString:name]];
1737 } 1732 }
1738 else 1733 else
1739 { 1734 {
1740 CHECK_STRING (value); 1735 CHECK_STRING (value);
1741 [[NSUserDefaults standardUserDefaults] setObject: 1736 [[NSUserDefaults standardUserDefaults] setObject:
1742 [NSString stringWithUTF8String: SSDATA (value)] 1737 [NSString stringWithLispString:value]
1743 forKey: [NSString stringWithUTF8String: 1738 forKey: [NSString stringWithLispString:name]];
1744 SSDATA (name)]];
1745 } 1739 }
1746 1740
1747 return Qnil; 1741 return Qnil;
@@ -2033,7 +2027,7 @@ The optional argument FRAME is currently ignored. */)
2033 NSEnumerator *cnames = [[clist allKeys] reverseObjectEnumerator]; 2027 NSEnumerator *cnames = [[clist allKeys] reverseObjectEnumerator];
2034 NSString *cname; 2028 NSString *cname;
2035 while ((cname = [cnames nextObject])) 2029 while ((cname = [cnames nextObject]))
2036 list = Fcons (build_string ([cname UTF8String]), list); 2030 list = Fcons ([cname lispString], list);
2037/* for (i = [[clist allKeys] count] - 1; i >= 0; i--) 2031/* for (i = [[clist allKeys] count] - 1; i >= 0; i--)
2038 list = Fcons (build_string ([[[clist allKeys] objectAtIndex: i] 2032 list = Fcons (build_string ([[[clist allKeys] objectAtIndex: i]
2039 UTF8String]), list); */ 2033 UTF8String]), list); */
@@ -2081,13 +2075,11 @@ there was no result. */)
2081{ 2075{
2082 id pb; 2076 id pb;
2083 NSString *svcName; 2077 NSString *svcName;
2084 char *utfStr;
2085 2078
2086 CHECK_STRING (service); 2079 CHECK_STRING (service);
2087 check_window_system (NULL); 2080 check_window_system (NULL);
2088 2081
2089 utfStr = SSDATA (service); 2082 svcName = [NSString stringWithLispString:service];
2090 svcName = [NSString stringWithUTF8String: utfStr];
2091 2083
2092 pb =[NSPasteboard pasteboardWithUniqueName]; 2084 pb =[NSPasteboard pasteboardWithUniqueName];
2093 ns_string_to_pasteboard (pb, send); 2085 ns_string_to_pasteboard (pb, send);
@@ -2117,7 +2109,7 @@ ns_do_applescript (Lisp_Object script, Lisp_Object *result)
2117 2109
2118 NSAppleScript *scriptObject = 2110 NSAppleScript *scriptObject =
2119 [[NSAppleScript alloc] initWithSource: 2111 [[NSAppleScript alloc] initWithSource:
2120 [NSString stringWithUTF8String: SSDATA (script)]]; 2112 [NSString stringWithLispString:script]];
2121 2113
2122 returnDescriptor = [scriptObject executeAndReturnError: &errorDict]; 2114 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
2123 [scriptObject release]; 2115 [scriptObject release];
@@ -2140,7 +2132,7 @@ ns_do_applescript (Lisp_Object script, Lisp_Object *result)
2140 { 2132 {
2141 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text]; 2133 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2142 if (desc) 2134 if (desc)
2143 *result = build_string([[desc stringValue] UTF8String]); 2135 *result = [[desc stringValue] lispString];
2144 } 2136 }
2145 else 2137 else
2146 { 2138 {
@@ -3055,8 +3047,8 @@ all_nonzero_ascii (unsigned char *str, ptrdiff_t n)
3055 *d++ = c; 3047 *d++ = c;
3056 else if (c <= 0x10ffff) 3048 else if (c <= 0x10ffff)
3057 { 3049 {
3058 *d++ = 0xd800 + (c & 0x3ff); 3050 *d++ = 0xd800 + ((c - 0x10000) >> 10);
3059 *d++ = 0xdc00 + ((c - 0x10000) >> 10); 3051 *d++ = 0xdc00 + (c & 0x3ff);
3060 } 3052 }
3061 else 3053 else
3062 *d++ = 0xfffd; /* Not valid for UTF-16. */ 3054 *d++ = 0xfffd; /* Not valid for UTF-16. */
@@ -3066,6 +3058,12 @@ all_nonzero_ascii (unsigned char *str, ptrdiff_t n)
3066 xfree (chars); 3058 xfree (chars);
3067 return str; 3059 return str;
3068} 3060}
3061
3062/* Make a Lisp string from an NSString. */
3063- (Lisp_Object)lispString
3064{
3065 return build_string ([self UTF8String]);
3066}
3069@end 3067@end
3070 3068
3071/* ========================================================================== 3069/* ==========================================================================
diff --git a/src/nsterm.h b/src/nsterm.h
index ab868ed3442..b56bcad4dc1 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -364,6 +364,7 @@ typedef id instancetype;
364 364
365@interface NSString (EmacsString) 365@interface NSString (EmacsString)
366+ (NSString *)stringWithLispString:(Lisp_Object)string; 366+ (NSString *)stringWithLispString:(Lisp_Object)string;
367- (Lisp_Object)lispString;
367@end 368@end
368 369
369/* ========================================================================== 370/* ==========================================================================
diff --git a/src/nsterm.m b/src/nsterm.m
index 98c5b69d681..26059ab67cd 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -5909,7 +5909,7 @@ ns_term_shutdown (int sig)
5909 5909
5910 emacs_event->kind = NS_NONKEY_EVENT; 5910 emacs_event->kind = NS_NONKEY_EVENT;
5911 emacs_event->code = KEY_NS_OPEN_FILE_LINE; 5911 emacs_event->code = KEY_NS_OPEN_FILE_LINE;
5912 ns_input_file = append2 (ns_input_file, build_string ([fileName UTF8String])); 5912 ns_input_file = append2 (ns_input_file, [fileName lispString]);
5913 ns_input_line = Qnil; /* can be start or cons start,end */ 5913 ns_input_line = Qnil; /* can be start or cons start,end */
5914 emacs_event->modifiers =0; 5914 emacs_event->modifiers =0;
5915 EV_TRAILER (theEvent); 5915 EV_TRAILER (theEvent);
@@ -6273,8 +6273,7 @@ not_in_argv (NSString *arg)
6273 error: (NSString **)error 6273 error: (NSString **)error
6274{ 6274{
6275 [ns_pending_service_names addObject: userData]; 6275 [ns_pending_service_names addObject: userData];
6276 [ns_pending_service_args addObject: [NSString stringWithUTF8String: 6276 [ns_pending_service_args addObject: [NSString stringWithLispString:ns_string_from_pasteboard (pboard)]];
6277 SSDATA (ns_string_from_pasteboard (pboard))]];
6278} 6277}
6279 6278
6280 6279
@@ -6291,8 +6290,8 @@ not_in_argv (NSString *arg)
6291 6290
6292 emacs_event->kind = NS_NONKEY_EVENT; 6291 emacs_event->kind = NS_NONKEY_EVENT;
6293 emacs_event->code = KEY_NS_SPI_SERVICE_CALL; 6292 emacs_event->code = KEY_NS_SPI_SERVICE_CALL;
6294 ns_input_spi_name = build_string ([name UTF8String]); 6293 ns_input_spi_name = [name lispString];
6295 ns_input_spi_arg = build_string ([arg UTF8String]); 6294 ns_input_spi_arg = [arg lispString];
6296 emacs_event->modifiers = EV_MODIFIERS (theEvent); 6295 emacs_event->modifiers = EV_MODIFIERS (theEvent);
6297 EV_TRAILER (theEvent); 6296 EV_TRAILER (theEvent);
6298 6297
@@ -6374,7 +6373,7 @@ not_in_argv (NSString *arg)
6374 6373
6375 size = [newFont pointSize]; 6374 size = [newFont pointSize];
6376 ns_input_fontsize = make_fixnum (lrint (size)); 6375 ns_input_fontsize = make_fixnum (lrint (size));
6377 ns_input_font = build_string ([[newFont familyName] UTF8String]); 6376 ns_input_font = [[newFont familyName] lispString];
6378 EV_TRAILER (e); 6377 EV_TRAILER (e);
6379 } 6378 }
6380} 6379}
@@ -6685,7 +6684,7 @@ not_in_argv (NSString *arg)
6685 processingCompose = YES; 6684 processingCompose = YES;
6686 [workingText release]; 6685 [workingText release];
6687 workingText = [str copy]; 6686 workingText = [str copy];
6688 ns_working_text = build_string ([workingText UTF8String]); 6687 ns_working_text = [workingText lispString];
6689 6688
6690 emacs_event->kind = NS_TEXT_EVENT; 6689 emacs_event->kind = NS_TEXT_EVENT;
6691 emacs_event->code = KEY_NS_PUT_WORKING_TEXT; 6690 emacs_event->code = KEY_NS_PUT_WORKING_TEXT;
@@ -7605,7 +7604,7 @@ not_in_argv (NSString *arg)
7605 tem = f->icon_name; 7604 tem = f->icon_name;
7606 if (!NILP (tem)) 7605 if (!NILP (tem))
7607 [win setMiniwindowTitle: 7606 [win setMiniwindowTitle:
7608 [NSString stringWithUTF8String: SSDATA (tem)]]; 7607 [NSString stringWithLispString:tem]];
7609 7608
7610 if (FRAME_PARENT_FRAME (f) != NULL) 7609 if (FRAME_PARENT_FRAME (f) != NULL)
7611 { 7610 {
@@ -8609,7 +8608,7 @@ not_in_argv (NSString *arg)
8609 8608
8610 fenum = [files objectEnumerator]; 8609 fenum = [files objectEnumerator];
8611 while ( (file = [fenum nextObject]) ) 8610 while ( (file = [fenum nextObject]) )
8612 strings = Fcons (build_string ([file UTF8String]), strings); 8611 strings = Fcons ([file lispString], strings);
8613 } 8612 }
8614 else if ([type isEqualToString: NSURLPboardType]) 8613 else if ([type isEqualToString: NSURLPboardType])
8615 { 8614 {
@@ -8618,7 +8617,7 @@ not_in_argv (NSString *arg)
8618 8617
8619 type_sym = Qurl; 8618 type_sym = Qurl;
8620 8619
8621 strings = list1 (build_string ([[url absoluteString] UTF8String])); 8620 strings = list1 ([[url absoluteString] lispString]);
8622 } 8621 }
8623 else if ([type isEqualToString: NSStringPboardType] 8622 else if ([type isEqualToString: NSStringPboardType]
8624 || [type isEqualToString: NSTabularTextPboardType]) 8623 || [type isEqualToString: NSTabularTextPboardType])
@@ -8630,7 +8629,7 @@ not_in_argv (NSString *arg)
8630 8629
8631 type_sym = Qnil; 8630 type_sym = Qnil;
8632 8631
8633 strings = list1 (build_string ([data UTF8String])); 8632 strings = list1 ([data lispString]);
8634 } 8633 }
8635 else 8634 else
8636 { 8635 {
@@ -8802,9 +8801,7 @@ not_in_argv (NSString *arg)
8802 } 8801 }
8803 if (STRINGP (str)) 8802 if (STRINGP (str))
8804 { 8803 {
8805 const char *utfStr = SSDATA (str); 8804 return [NSString stringWithLispString:str];
8806 NSString *nsStr = [NSString stringWithUTF8String: utfStr];
8807 return nsStr;
8808 } 8805 }
8809 } 8806 }
8810 8807