Merge branch 'master' of github.com:andlabs/libui

This commit is contained in:
Pietro Gagliardi 2016-05-25 23:14:05 -04:00
commit c856ff1976
10 changed files with 30 additions and 31 deletions

View File

@ -23,13 +23,10 @@ void initAlloc(void)
void uninitAlloc(void) void uninitAlloc(void)
{ {
NSMutableString *str; NSMutableString *str;
NSUInteger i;
NSValue *v; NSValue *v;
// delegates might have mapTables allocated // delegates might have mapTables allocated
// TODO verify they are empty // TODO verify they are empty
for (i = 0; i < [delegates count]; i++)
[[delegates objectAtIndex:i] release];
[delegates release]; [delegates release];
if ([allocations count] == 0) { if ([allocations count] == 0) {
[allocations release]; [allocations release];

View File

@ -103,7 +103,7 @@ uiButton *uiNewButton(const char *text)
uiDarwinSetControlFont(b->button, NSRegularControlSize); uiDarwinSetControlFont(b->button, NSRegularControlSize);
if (buttonDelegate == nil) { if (buttonDelegate == nil) {
buttonDelegate = [buttonDelegateClass new]; buttonDelegate = [[buttonDelegateClass new] autorelease];
[delegates addObject:buttonDelegate]; [delegates addObject:buttonDelegate];
} }
[buttonDelegate registerButton:b]; [buttonDelegate registerButton:b];

View File

@ -118,7 +118,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
uiDarwinSetControlFont(c->button, NSRegularControlSize); uiDarwinSetControlFont(c->button, NSRegularControlSize);
if (checkboxDelegate == nil) { if (checkboxDelegate == nil) {
checkboxDelegate = [checkboxDelegateClass new]; checkboxDelegate = [[checkboxDelegateClass new] autorelease];
[delegates addObject:checkboxDelegate]; [delegates addObject:checkboxDelegate];
} }
[checkboxDelegate registerCheckbox:c]; [checkboxDelegate registerCheckbox:c];

View File

@ -135,7 +135,7 @@ uiCombobox *uiNewCombobox(void)
options:nil]; options:nil];
if (comboboxDelegate == nil) { if (comboboxDelegate == nil) {
comboboxDelegate = [comboboxDelegateClass new]; comboboxDelegate = [[comboboxDelegateClass new] autorelease];
[delegates addObject:comboboxDelegate]; [delegates addObject:comboboxDelegate];
} }
[comboboxDelegate registerCombobox:c]; [comboboxDelegate registerCombobox:c];

View File

@ -175,7 +175,7 @@ uiEditableCombobox *uiNewEditableCombobox(void)
uiDarwinSetControlFont(c->cb, NSRegularControlSize); uiDarwinSetControlFont(c->cb, NSRegularControlSize);
if (comboboxDelegate == nil) { if (comboboxDelegate == nil) {
comboboxDelegate = [editableComboboxDelegateClass new]; comboboxDelegate = [[editableComboboxDelegateClass new] autorelease];
[delegates addObject:comboboxDelegate]; [delegates addObject:comboboxDelegate];
} }
[comboboxDelegate registerCombobox:c]; [comboboxDelegate registerCombobox:c];

View File

@ -158,7 +158,7 @@ uiEntry *uiNewEntry(void)
e->textfield = newEditableTextField(); e->textfield = newEditableTextField();
if (entryDelegate == nil) { if (entryDelegate == nil) {
entryDelegate = [entryDelegateClass new]; entryDelegate = [[entryDelegateClass new] autorelease];
[delegates addObject:entryDelegate]; [delegates addObject:entryDelegate];
} }
[entryDelegate registerEntry:e]; [entryDelegate registerEntry:e];

View File

@ -3,6 +3,8 @@
static BOOL canQuit = NO; static BOOL canQuit = NO;
static NSAutoreleasePool *globalPool; static NSAutoreleasePool *globalPool;
static applicationClass* app;
static appDelegate* delegate;
@implementation applicationClass @implementation applicationClass
@ -101,15 +103,14 @@ uiInitOptions options;
const char *uiInit(uiInitOptions *o) const char *uiInit(uiInitOptions *o)
{ {
globalPool = [[NSAutoreleasePool alloc] init];
@autoreleasepool { @autoreleasepool {
options = *o; options = *o;
[applicationClass sharedApplication]; app = [[applicationClass sharedApplication] retain];
// don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy! // don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy!
// see https://github.com/andlabs/ui/issues/6 // see https://github.com/andlabs/ui/issues/6
[realNSApp() setActivationPolicy:NSApplicationActivationPolicyRegular]; [realNSApp() setActivationPolicy:NSApplicationActivationPolicyRegular];
[realNSApp() setDelegate:[appDelegate new]]; delegate = [appDelegate new];
[realNSApp() setDelegate:delegate];
initAlloc(); initAlloc();
@ -118,20 +119,26 @@ const char *uiInit(uiInitOptions *o)
[realNSApp() setMainMenu:[appDelegate().menuManager makeMenubar]]; [realNSApp() setMainMenu:[appDelegate().menuManager makeMenubar]];
setupFontPanel(); setupFontPanel();
return NULL;
} }
globalPool = [[NSAutoreleasePool alloc] init];
return NULL;
} }
void uiUninit(void) void uiUninit(void)
{ {
@autoreleasepool { if (!globalPool) {
[appDelegate() release]; userbug("You must call uiInit() first!");
[realNSApp() setDelegate:nil];
[realNSApp() release];
uninitAlloc();
} }
[globalPool release]; [globalPool release];
@autoreleasepool {
[delegate release];
[realNSApp() setDelegate:nil];
[app release];
uninitAlloc();
}
} }
void uiFreeInitError(const char *err) void uiFreeInitError(const char *err)

View File

@ -138,7 +138,7 @@ uiSlider *uiNewSlider(intmax_t min, intmax_t max)
[cell setSliderType:NSLinearSlider]; [cell setSliderType:NSLinearSlider];
if (sliderDelegate == nil) { if (sliderDelegate == nil) {
sliderDelegate = [sliderDelegateClass new]; sliderDelegate = [[sliderDelegateClass new] autorelease];
[delegates addObject:sliderDelegate]; [delegates addObject:sliderDelegate];
} }
[sliderDelegate registerSlider:s]; [sliderDelegate registerSlider:s];

View File

@ -35,8 +35,8 @@ struct uiTab {
{ {
self = [super init]; self = [super init];
if (self != nil) { if (self != nil) {
self->view = v; self->view = [v retain];
self->pageID = o; self->pageID = [o retain];
} }
return self; return self;
} }
@ -189,14 +189,14 @@ void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child)
uiControlSetParent(child, uiControl(t)); uiControlSetParent(child, uiControl(t));
view = [[NSView alloc] initWithFrame:NSZeroRect]; view = [[[NSView alloc] initWithFrame:NSZeroRect] autorelease];
// TODO if we turn off the autoresizing mask, nothing shows up; didn't this get documented somewhere? // TODO if we turn off the autoresizing mask, nothing shows up; didn't this get documented somewhere?
uiDarwinControlSetSuperview(uiDarwinControl(child), view); uiDarwinControlSetSuperview(uiDarwinControl(child), view);
uiDarwinControlSyncEnableState(uiDarwinControl(child), uiControlEnabledToUser(uiControl(t))); uiDarwinControlSyncEnableState(uiDarwinControl(child), uiControlEnabledToUser(uiControl(t)));
// the documentation says these can be nil but the headers say these must not be; let's be safe and make them non-nil anyway // the documentation says these can be nil but the headers say these must not be; let's be safe and make them non-nil anyway
pageID = [NSObject new]; pageID = [NSObject new];
page = [[tabPage alloc] initWithView:view pageID:pageID]; page = [[[tabPage alloc] initWithView:view pageID:pageID] autorelease];
page.c = child; page.c = child;
// don't hug, just in case we're a stretchy tab // don't hug, just in case we're a stretchy tab
@ -206,16 +206,11 @@ void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child)
uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationVertical); uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationVertical);
[t->pages insertObject:page atIndex:n]; [t->pages insertObject:page atIndex:n];
[page release]; // no need for initial reference
i = [[NSTabViewItem alloc] initWithIdentifier:pageID]; i = [[[NSTabViewItem alloc] initWithIdentifier:pageID] autorelease];
[i setLabel:toNSString(name)]; [i setLabel:toNSString(name)];
[i setView:view]; [i setView:view];
[t->tabview insertTabViewItem:i atIndex:n]; [t->tabview insertTabViewItem:i atIndex:n];
// TODO release i?
[pageID release]; // no need for initial reference
[view release];
tabRelayout(t); tabRelayout(t);
} }

View File

@ -258,7 +258,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
[w->window setReleasedWhenClosed:NO]; [w->window setReleasedWhenClosed:NO];
if (windowDelegate == nil) { if (windowDelegate == nil) {
windowDelegate = [windowDelegateClass new]; windowDelegate = [[windowDelegateClass new] autorelease];
[delegates addObject:windowDelegate]; [delegates addObject:windowDelegate];
} }
[windowDelegate registerWindow:w]; [windowDelegate registerWindow:w];