aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Third2021-08-22 21:50:09 +0100
committerAlan Third2021-12-22 20:48:19 +0000
commit42601d3a938ee5a12a557840aef11c4d3bb180f6 (patch)
treef1cf9617fafff0e7550baa7c083d197ce81b8b23 /src
parent308ad05d37a2d230c65a8799e193e25f4f8ba540 (diff)
downloademacs-42601d3a938ee5a12a557840aef11c4d3bb180f6.tar.gz
emacs-42601d3a938ee5a12a557840aef11c4d3bb180f6.zip
Make NS toolbar use NSString instead of C strings
* src/nsfns.m ([NSString stringWithLispString:]): Ensure that the lisp object is actually a string. * src/nsmenu.m (update_frame_tool_bar): Convert to NSString instead of C strings. ([EmacsToolbar addDisplayItemWithImage:idx:tag:labelText:helpText:enabled:]): No need to convert to NSString here anymore.
Diffstat (limited to 'src')
-rw-r--r--src/nsfns.m3
-rw-r--r--src/nsmenu.m16
-rw-r--r--src/nsterm.h4
3 files changed, 11 insertions, 12 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index 7cb2cf72581..643da01989f 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -3140,6 +3140,9 @@ all_nonzero_ascii (unsigned char *str, ptrdiff_t n)
3140 encoded form (e.g. UTF-8). */ 3140 encoded form (e.g. UTF-8). */
3141+ (NSString *)stringWithLispString:(Lisp_Object)string 3141+ (NSString *)stringWithLispString:(Lisp_Object)string
3142{ 3142{
3143 if (!STRINGP (string))
3144 return nil;
3145
3143 /* Shortcut for the common case. */ 3146 /* Shortcut for the common case. */
3144 if (all_nonzero_ascii (SDATA (string), SBYTES (string))) 3147 if (all_nonzero_ascii (SDATA (string), SBYTES (string)))
3145 return [NSString stringWithCString: SSDATA (string) 3148 return [NSString stringWithCString: SSDATA (string)
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 29201e69079..f42cd387022 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -1081,9 +1081,7 @@ update_frame_tool_bar_1 (struct frame *f, EmacsToolbar *toolbar)
1081 struct image *img; 1081 struct image *img;
1082 Lisp_Object image; 1082 Lisp_Object image;
1083 Lisp_Object labelObj; 1083 Lisp_Object labelObj;
1084 const char *labelText;
1085 Lisp_Object helpObj; 1084 Lisp_Object helpObj;
1086 const char *helpText;
1087 1085
1088 /* Check if this is a separator. */ 1086 /* Check if this is a separator. */
1089 if (EQ (TOOLPROP (TOOL_BAR_ITEM_TYPE), Qt)) 1087 if (EQ (TOOLPROP (TOOL_BAR_ITEM_TYPE), Qt))
@@ -1109,11 +1107,9 @@ update_frame_tool_bar_1 (struct frame *f, EmacsToolbar *toolbar)
1109 idx = -1; 1107 idx = -1;
1110 } 1108 }
1111 labelObj = TOOLPROP (TOOL_BAR_ITEM_LABEL); 1109 labelObj = TOOLPROP (TOOL_BAR_ITEM_LABEL);
1112 labelText = NILP (labelObj) ? "" : SSDATA (labelObj);
1113 helpObj = TOOLPROP (TOOL_BAR_ITEM_HELP); 1110 helpObj = TOOLPROP (TOOL_BAR_ITEM_HELP);
1114 if (NILP (helpObj)) 1111 if (NILP (helpObj))
1115 helpObj = TOOLPROP (TOOL_BAR_ITEM_CAPTION); 1112 helpObj = TOOLPROP (TOOL_BAR_ITEM_CAPTION);
1116 helpText = NILP (helpObj) ? "" : SSDATA (helpObj);
1117 1113
1118 /* Ignore invalid image specifications. */ 1114 /* Ignore invalid image specifications. */
1119 if (!valid_image_p (image)) 1115 if (!valid_image_p (image))
@@ -1135,8 +1131,8 @@ update_frame_tool_bar_1 (struct frame *f, EmacsToolbar *toolbar)
1135 [toolbar addDisplayItemWithImage: img->pixmap 1131 [toolbar addDisplayItemWithImage: img->pixmap
1136 idx: k++ 1132 idx: k++
1137 tag: i 1133 tag: i
1138 labelText: labelText 1134 labelText: [NSString stringWithLispString:labelObj]
1139 helpText: helpText 1135 helpText: [NSString stringWithLispString:helpObj]
1140 enabled: enabled_p]; 1136 enabled: enabled_p];
1141#undef TOOLPROP 1137#undef TOOLPROP
1142 } 1138 }
@@ -1252,8 +1248,8 @@ update_frame_tool_bar (struct frame *f)
1252- (void) addDisplayItemWithImage: (EmacsImage *)img 1248- (void) addDisplayItemWithImage: (EmacsImage *)img
1253 idx: (int)idx 1249 idx: (int)idx
1254 tag: (int)tag 1250 tag: (int)tag
1255 labelText: (const char *)label 1251 labelText: (NSString *)label
1256 helpText: (const char *)help 1252 helpText: (NSString *)help
1257 enabled: (BOOL)enabled 1253 enabled: (BOOL)enabled
1258{ 1254{
1259 NSTRACE ("[EmacsToolbar addDisplayItemWithImage: ...]"); 1255 NSTRACE ("[EmacsToolbar addDisplayItemWithImage: ...]");
@@ -1270,8 +1266,8 @@ update_frame_tool_bar (struct frame *f)
1270 item = [[[NSToolbarItem alloc] initWithItemIdentifier: identifier] 1266 item = [[[NSToolbarItem alloc] initWithItemIdentifier: identifier]
1271 autorelease]; 1267 autorelease];
1272 [item setImage: img]; 1268 [item setImage: img];
1273 [item setLabel: [NSString stringWithUTF8String: label]]; 1269 [item setLabel: label];
1274 [item setToolTip: [NSString stringWithUTF8String: help]]; 1270 [item setToolTip: help];
1275 [item setTarget: emacsView]; 1271 [item setTarget: emacsView];
1276 [item setAction: @selector (toolbarClicked:)]; 1272 [item setAction: @selector (toolbarClicked:)];
1277 [identifierToItem setObject: item forKey: identifier]; 1273 [identifierToItem setObject: item forKey: identifier];
diff --git a/src/nsterm.h b/src/nsterm.h
index 3413bb1f780..75b31c68f1d 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -551,8 +551,8 @@ typedef id instancetype;
551- (void) addDisplayItemWithImage: (EmacsImage *)img 551- (void) addDisplayItemWithImage: (EmacsImage *)img
552 idx: (int)idx 552 idx: (int)idx
553 tag: (int)tag 553 tag: (int)tag
554 labelText: (const char *)label 554 labelText: (NSString *)label
555 helpText: (const char *)help 555 helpText: (NSString *)help
556 enabled: (BOOL)enabled; 556 enabled: (BOOL)enabled;
557 557
558/* delegate methods */ 558/* delegate methods */