[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 42601d3 4/7: Make NS toolbar use NSString instead of C strings
From: |
Alan Third |
Subject: |
master 42601d3 4/7: Make NS toolbar use NSString instead of C strings |
Date: |
Wed, 22 Dec 2021 15:49:23 -0500 (EST) |
branch: master
commit 42601d3a938ee5a12a557840aef11c4d3bb180f6
Author: Alan Third <alan@idiocy.org>
Commit: Alan Third <alan@idiocy.org>
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.
---
src/nsfns.m | 3 +++
src/nsmenu.m | 16 ++++++----------
src/nsterm.h | 4 ++--
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/nsfns.m b/src/nsfns.m
index 7cb2cf7..643da01 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -3140,6 +3140,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 29201e6..f42cd38 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -1081,9 +1081,7 @@ update_frame_tool_bar_1 (struct frame *f, EmacsToolbar
*toolbar)
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))
@@ -1109,11 +1107,9 @@ update_frame_tool_bar_1 (struct frame *f, EmacsToolbar
*toolbar)
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))
@@ -1135,8 +1131,8 @@ update_frame_tool_bar_1 (struct frame *f, EmacsToolbar
*toolbar)
[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
}
@@ -1252,8 +1248,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: ...]");
@@ -1270,8 +1266,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 3413bb1..75b31c6 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -551,8 +551,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 */
- master updated (5b0121b -> ec1312d), Alan Third, 2021/12/22
- master 0f427be 1/7: Simplify NS color handling, Alan Third, 2021/12/22
- master 89749a6 5/7: Make NS toolbar item ID more unique (bug#50160), Alan Third, 2021/12/22
- master 11c0b25 2/7: Further cleanup of NS color code, Alan Third, 2021/12/22
- master 42601d3 4/7: Make NS toolbar use NSString instead of C strings,
Alan Third <=
- master ec1312d 7/7: Add native HEIC support on macOS (bug#51381), Alan Third, 2021/12/22
- master ab0d7a2 6/7: Allow resizing undecorated frames on macOS (bug#28512, bug#31795), Alan Third, 2021/12/22
- master 308ad05 3/7: Fix macfont backend color handling, Alan Third, 2021/12/22