Renamed toNSString() and fromNSString() to uiprivToNSString() and uiprivFromNSString(), respectively.

This commit is contained in:
Pietro Gagliardi 2018-05-03 22:38:21 -04:00
parent 4fe74fbd56
commit 5a113e1e0b
16 changed files with 34 additions and 33 deletions

View File

@ -1,13 +1,4 @@
#define toNSString(str) [NSString stringWithUTF8String:(str)]
#define fromNSString(str) [(str) UTF8String]
#ifndef NSAppKitVersionNumber10_9
#define NSAppKitVersionNumber10_9 1265
#endif
/*TODO remove this*/typedef struct uiImage uiImage;
// menu.m
@interface menuManager : NSObject {
struct mapTable *items;

View File

@ -75,7 +75,7 @@ char *uiButtonText(uiButton *b)
void uiButtonSetText(uiButton *b, const char *text)
{
[b->button setTitle:toNSString(text)];
[b->button setTitle:uiprivToNSString(text)];
}
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
@ -96,7 +96,7 @@ uiButton *uiNewButton(const char *text)
uiDarwinNewControl(uiButton, b);
b->button = [[NSButton alloc] initWithFrame:NSZeroRect];
[b->button setTitle:toNSString(text)];
[b->button setTitle:uiprivToNSString(text)];
[b->button setButtonType:NSMomentaryPushInButton];
[b->button setBordered:YES];
[b->button setBezelStyle:NSRoundedBezelStyle];

View File

@ -75,7 +75,7 @@ char *uiCheckboxText(uiCheckbox *c)
void uiCheckboxSetText(uiCheckbox *c, const char *text)
{
[c->button setTitle:toNSString(text)];
[c->button setTitle:uiprivToNSString(text)];
}
void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data)
@ -111,7 +111,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
uiDarwinNewControl(uiCheckbox, c);
c->button = [[NSButton alloc] initWithFrame:NSZeroRect];
[c->button setTitle:toNSString(text)];
[c->button setTitle:uiprivToNSString(text)];
[c->button setButtonType:NSSwitchButton];
// doesn't seem to have an associated bezel style
[c->button setBordered:NO];

View File

@ -78,7 +78,7 @@ static void uiComboboxDestroy(uiControl *cc)
void uiComboboxAppend(uiCombobox *c, const char *text)
{
[c->pbac addObject:toNSString(text)];
[c->pbac addObject:uiprivToNSString(text)];
}
int uiComboboxSelected(uiCombobox *c)

View File

@ -106,7 +106,7 @@ static void uiEditableComboboxDestroy(uiControl *cc)
void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text)
{
[c->cb addItemWithObjectValue:toNSString(text)];
[c->cb addItemWithObjectValue:uiprivToNSString(text)];
}
char *uiEditableComboboxText(uiEditableCombobox *c)
@ -118,7 +118,7 @@ void uiEditableComboboxSetText(uiEditableCombobox *c, const char *text)
{
NSString *t;
t = toNSString(text);
t = uiprivToNSString(text);
[c->cb setStringValue:t];
// yes, let's imitate the behavior that caused uiEditableCombobox to be separate in the first place!
// just to avoid confusion when users see an option in the list in the text field but not selected in the list

View File

@ -145,7 +145,7 @@ char *uiEntryText(uiEntry *e)
void uiEntrySetText(uiEntry *e, const char *text)
{
[e->textfield setStringValue:toNSString(text)];
[e->textfield setStringValue:uiprivToNSString(text)];
// don't queue the control for resize; entry sizes are independent of their contents
}

View File

@ -531,7 +531,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy)
// or at leat allow this and implicitly turn it into a spacer
if (c == NULL)
uiprivUserBug("You cannot add NULL to a uiForm.");
[f->view append:toNSString(label) c:c stretchy:stretchy];
[f->view append:uiprivToNSString(label) c:c stretchy:stretchy];
}
void uiFormDelete(uiForm *f, int n)

View File

@ -131,7 +131,7 @@ char *uiGroupTitle(uiGroup *g)
void uiGroupSetTitle(uiGroup *g, const char *title)
{
[g->box setTitle:toNSString(title)];
[g->box setTitle:uiprivToNSString(title)];
}
void uiGroupSetChild(uiGroup *g, uiControl *child)
@ -178,7 +178,7 @@ uiGroup *uiNewGroup(const char *title)
uiDarwinNewControl(uiGroup, g);
g->box = [[NSBox alloc] initWithFrame:NSZeroRect];
[g->box setTitle:toNSString(title)];
[g->box setTitle:uiprivToNSString(title)];
[g->box setBoxType:NSBoxPrimary];
[g->box setBorderType:NSLineBorder];
[g->box setTransparent:NO];

View File

@ -15,7 +15,7 @@ char *uiLabelText(uiLabel *l)
void uiLabelSetText(uiLabel *l, const char *text)
{
[l->textfield setStringValue:toNSString(text)];
[l->textfield setStringValue:uiprivToNSString(text)];
}
NSTextField *newLabel(NSString *str)
@ -37,7 +37,7 @@ uiLabel *uiNewLabel(const char *text)
uiDarwinNewControl(uiLabel, l);
l->textfield = newLabel(toNSString(text));
l->textfield = newLabel(uiprivToNSString(text));
return l;
}

View File

@ -259,7 +259,7 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name)
[m->menu addItem:item->item];
break;
default:
item->item = [[NSMenuItem alloc] initWithTitle:toNSString(name) action:@selector(onClicked:) keyEquivalent:@""];
item->item = [[NSMenuItem alloc] initWithTitle:uiprivToNSString(name) action:@selector(onClicked:) keyEquivalent:@""];
[item->item setTarget:appDelegate().menuManager];
[m->menu addItem:item->item];
break;
@ -321,10 +321,10 @@ uiMenu *uiNewMenu(const char *name)
m = uiprivNew(uiMenu);
m->menu = [[NSMenu alloc] initWithTitle:toNSString(name)];
m->menu = [[NSMenu alloc] initWithTitle:uiprivToNSString(name)];
// use automatic menu item enabling for all menus for consistency's sake
m->item = [[NSMenuItem alloc] initWithTitle:toNSString(name) action:NULL keyEquivalent:@""];
m->item = [[NSMenuItem alloc] initWithTitle:uiprivToNSString(name) action:NULL keyEquivalent:@""];
[m->item setSubmenu:m->menu];
m->items = [NSMutableArray new];

View File

@ -78,7 +78,7 @@ char *uiMultilineEntryText(uiMultilineEntry *e)
void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text)
{
[[e->tv textStorage] replaceCharactersInRange:NSMakeRange(0, [[e->tv string] length])
withString:toNSString(text)];
withString:uiprivToNSString(text)];
// must be called explicitly according to the documentation of shouldChangeTextInRange:replacementString:
e->changing = YES;
[e->tv didChangeText];
@ -89,7 +89,7 @@ void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text)
void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text)
{
[[e->tv textStorage] replaceCharactersInRange:NSMakeRange([[e->tv string] length], 0)
withString:toNSString(text)];
withString:uiprivToNSString(text)];
e->changing = YES;
[e->tv didChangeText];
e->changing = NO;

View File

@ -87,7 +87,7 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
NSLayoutConstraint *constraint;
b = [[NSButton alloc] initWithFrame:NSZeroRect];
[b setTitle:toNSString(text)];
[b setTitle:uiprivToNSString(text)];
[b setButtonType:NSRadioButton];
// doesn't seem to have an associated bezel style
[b setBordered:NO];

View File

@ -103,8 +103,8 @@ static void msgbox(NSWindow *parent, const char *title, const char *description,
[a setAlertStyle:style];
[a setShowsHelp:NO];
[a setShowsSuppressionButton:NO];
[a setMessageText:toNSString(title)];
[a setInformativeText:toNSString(description)];
[a setMessageText:uiprivToNSString(title)];
[a setInformativeText:uiprivToNSString(description)];
[a addButtonWithTitle:@"OK"];
cm = [[libuiCodeModalAlertPanel alloc] initWithPanel:a parent:parent];
[cm run];

View File

@ -220,7 +220,7 @@ void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child)
[t->pages insertObject:page atIndex:n];
i = [[[NSTabViewItem alloc] initWithIdentifier:pageID] autorelease];
[i setLabel:toNSString(name)];
[i setLabel:uiprivToNSString(name)];
[i setView:view];
[t->tabview insertTabViewItem:i atIndex:n];

View File

@ -12,4 +12,14 @@
#error Sorry, libui cannot be compiled with ARC.
#endif
#define uiprivToNSString(str) [NSString stringWithUTF8String:(str)]
#define uiprivFromNSString(str) [(str) UTF8String]
// TODO find a better place for this
#ifndef NSAppKitVersionNumber10_9
#define NSAppKitVersionNumber10_9 1265
#endif
/*TODO remove this*/typedef struct uiImage uiImage;
#import "OLD_uipriv_darwin.h"

View File

@ -252,7 +252,7 @@ char *uiWindowTitle(uiWindow *w)
void uiWindowSetTitle(uiWindow *w, const char *title)
{
[w->window setTitle:toNSString(title)];
[w->window setTitle:uiprivToNSString(title)];
}
void uiWindowContentSize(uiWindow *w, int *width, int *height)
@ -379,7 +379,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
styleMask:defaultStyleMask
backing:NSBackingStoreBuffered
defer:YES];
[w->window setTitle:toNSString(title)];
[w->window setTitle:uiprivToNSString(title)];
// do NOT release when closed
// we manually do this in uiWindowDestroy() above