diff options
author | Alan Third <alan@idiocy.org> | 2021-08-22 21:50:09 +0100 |
---|---|---|
committer | Alan Third <alan@idiocy.org> | 2021-08-31 20:50:12 +0100 |
commit | 4ef7ac18ac319921f3f7df34dd957b4941e66db2 (patch) | |
tree | a6904ab47587e3a5146f7f1e9074e3bdd1436e57 | |
parent | 32fbd5530d93cbd93315217de79028b356314b11 (diff) | |
download | emacs-4ef7ac18ac319921f3f7df34dd957b4941e66db2.tar.gz |
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.
-rw-r--r-- | src/nsfns.m | 3 | ||||
-rw-r--r-- | src/nsmenu.m | 16 | ||||
-rw-r--r-- | src/nsterm.h | 4 |
3 files changed, 11 insertions, 12 deletions
diff --git a/src/nsfns.m b/src/nsfns.m index f4b25b9c99e..3eba2bf8105 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -3028,6 +3028,9 @@ all_nonzero_ascii (unsigned char *str, ptrdiff_t n) encoded form (e.g. UTF-8). */ + (NSString *)stringWithLispString:(Lisp_Object)string { + if (!STRINGP (string)) + return nil; + /* Shortcut for the common case. */ if (all_nonzero_ascii (SDATA (string), SBYTES (string))) return [NSString stringWithCString: SSDATA (string) diff --git a/src/nsmenu.m b/src/nsmenu.m index 3493e4e131d..0e271e2197b 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -1034,9 +1034,7 @@ update_frame_tool_bar (struct frame *f) struct image *img; Lisp_Object image; Lisp_Object labelObj; - const char *labelText; Lisp_Object helpObj; - const char *helpText; /* Check if this is a separator. */ if (EQ (TOOLPROP (TOOL_BAR_ITEM_TYPE), Qt)) @@ -1062,11 +1060,9 @@ update_frame_tool_bar (struct frame *f) idx = -1; } labelObj = TOOLPROP (TOOL_BAR_ITEM_LABEL); - labelText = NILP (labelObj) ? "" : SSDATA (labelObj); helpObj = TOOLPROP (TOOL_BAR_ITEM_HELP); if (NILP (helpObj)) helpObj = TOOLPROP (TOOL_BAR_ITEM_CAPTION); - helpText = NILP (helpObj) ? "" : SSDATA (helpObj); /* Ignore invalid image specifications. */ if (!valid_image_p (image)) @@ -1088,8 +1084,8 @@ update_frame_tool_bar (struct frame *f) [toolbar addDisplayItemWithImage: img->pixmap idx: k++ tag: i - labelText: labelText - helpText: helpText + labelText: [NSString stringWithLispString:labelObj] + helpText: [NSString stringWithLispString:helpObj] enabled: enabled_p]; #undef TOOLPROP } @@ -1193,8 +1189,8 @@ update_frame_tool_bar (struct frame *f) - (void) addDisplayItemWithImage: (EmacsImage *)img idx: (int)idx tag: (int)tag - labelText: (const char *)label - helpText: (const char *)help + labelText: (NSString *)label + helpText: (NSString *)help enabled: (BOOL)enabled { NSTRACE ("[EmacsToolbar addDisplayItemWithImage: ...]"); @@ -1211,8 +1207,8 @@ update_frame_tool_bar (struct frame *f) item = [[[NSToolbarItem alloc] initWithItemIdentifier: identifier] autorelease]; [item setImage: img]; - [item setLabel: [NSString stringWithUTF8String: label]]; - [item setToolTip: [NSString stringWithUTF8String: help]]; + [item setLabel: label]; + [item setToolTip: help]; [item setTarget: emacsView]; [item setAction: @selector (toolbarClicked:)]; [identifierToItem setObject: item forKey: identifier]; diff --git a/src/nsterm.h b/src/nsterm.h index 215e8e40fa7..8640b97d8ad 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -549,8 +549,8 @@ typedef id instancetype; - (void) addDisplayItemWithImage: (EmacsImage *)img idx: (int)idx tag: (int)tag - labelText: (const char *)label - helpText: (const char *)help + labelText: (NSString *)label + helpText: (NSString *)help enabled: (BOOL)enabled; /* delegate methods */ |