diff --git a/redo/reredo/darwin/alloc.m b/redo/reredo/darwin/alloc.m index b20cd538..f569641a 100644 --- a/redo/reredo/darwin/alloc.m +++ b/redo/reredo/darwin/alloc.m @@ -3,10 +3,12 @@ #import "uipriv_darwin.h" NSMutableArray *allocations; +NSMutableArray *delegates; void initAlloc(void) { allocations = [NSMutableArray new]; + delegates = [NSMutableArray new]; } #define UINT8(p) ((uint8_t *) (p)) @@ -21,6 +23,11 @@ void initAlloc(void) void uninitAlloc(void) { if ([allocations count] == 0) { + NSInteger i; + + for (i = 0; i < [delegates count]; i++) + [[delegates objectAtIndex:i] release]; + [delegates release]; [allocations release]; return; } diff --git a/redo/reredo/darwin/button.m b/redo/reredo/darwin/button.m index 683789c1..657bca8c 100644 --- a/redo/reredo/darwin/button.m +++ b/redo/reredo/darwin/button.m @@ -26,7 +26,6 @@ struct uiButton { return self; } -// TODO have this called - (void)dealloc { if ([self->buttons count] != 0) @@ -103,8 +102,10 @@ uiButton *uiNewButton(const char *text) [b->button setBezelStyle:NSRoundedBezelStyle]; uiDarwinSetControlFont(b->button, NSRegularControlSize); - if (buttonDelegate == nil) + if (buttonDelegate == nil) { buttonDelegate = [buttonDelegateClass new]; + [delegates addObject:buttonDelegate]; + } [buttonDelegate registerButton:b]; uiButtonOnClicked(b, defaultOnClicked, NULL); diff --git a/redo/reredo/darwin/checkbox.m b/redo/reredo/darwin/checkbox.m index 36fb0871..01819aed 100644 --- a/redo/reredo/darwin/checkbox.m +++ b/redo/reredo/darwin/checkbox.m @@ -3,13 +3,13 @@ struct uiCheckbox { uiDarwinControl c; - NSButton *button; // TODO rename to checkbox? + NSButton *button; void (*onToggled)(uiCheckbox *, void *); void *onToggledData; }; @interface checkboxDelegateClass : NSObject { - NSMapTable *buttons; // TODO rename to checkboxes? + NSMapTable *buttons; } - (IBAction)onToggled:(id)sender; - (void)registerCheckbox:(uiCheckbox *)c; @@ -26,7 +26,6 @@ struct uiCheckbox { return self; } -// TODO have this called - (void)dealloc { if ([self->buttons count] != 0) @@ -117,8 +116,10 @@ uiCheckbox *uiNewCheckbox(const char *text) [c->button setBordered:NO]; uiDarwinSetControlFont(c->button, NSRegularControlSize); - if (checkboxDelegate == nil) + if (checkboxDelegate == nil) { checkboxDelegate = [checkboxDelegateClass new]; + [delegates addObject:checkboxDelegate]; + } [checkboxDelegate registerCheckbox:c]; uiCheckboxOnToggled(c, defaultOnToggled, NULL); diff --git a/redo/reredo/darwin/entry.m b/redo/reredo/darwin/entry.m index d8e2858c..464909c5 100644 --- a/redo/reredo/darwin/entry.m +++ b/redo/reredo/darwin/entry.m @@ -28,7 +28,6 @@ struct uiEntry { return self; } -// TODO have this called - (void)dealloc { if ([self->entries count] != 0) @@ -131,8 +130,10 @@ uiEntry *uiNewEntry(void) [e->textfield setSelectable:YES]; // otherwise the setting is masked by the editable default of YES finishNewTextField(e->textfield, YES); - if (entryDelegate == nil) + if (entryDelegate == nil) { entryDelegate = [entryDelegateClass new]; + [delegates addObject:entryDelegate]; + } [entryDelegate registerEntry:e]; uiEntryOnChanged(e, defaultOnChanged, NULL); diff --git a/redo/reredo/darwin/uipriv_darwin.h b/redo/reredo/darwin/uipriv_darwin.h index ac447922..4041a185 100644 --- a/redo/reredo/darwin/uipriv_darwin.h +++ b/redo/reredo/darwin/uipriv_darwin.h @@ -46,6 +46,7 @@ extern void finishNewTextField(NSTextField *, BOOL); extern uiWindow *windowFromNSWindow(NSWindow *); // alloc.m +extern NSMutableArray *delegates; extern void initAlloc(void); extern void uninitAlloc(void); diff --git a/redo/reredo/darwin/window.m b/redo/reredo/darwin/window.m index e913aff2..cb5d7872 100644 --- a/redo/reredo/darwin/window.m +++ b/redo/reredo/darwin/window.m @@ -29,7 +29,6 @@ struct uiWindow { return self; } -// TODO have this called - (void)dealloc { if ([self->windows count] != 0) @@ -191,8 +190,10 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) // the only thing that closes the window is us anyway [w->window setReleasedWhenClosed:YES]; - if (windowDelegate == nil) + if (windowDelegate == nil) { windowDelegate = [windowDelegateClass new]; + [delegates addObject:windowDelegate]; + } [windowDelegate registerWindow:w]; uiWindowOnClosing(w, defaultOnClosing, NULL);