diff options
| author | Pietro Gagliardi <[email protected]> | 2015-04-08 03:38:08 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-04-08 03:38:08 -0400 |
| commit | 4ab6251449b4c88869b12514f67c8731ab14c93c (patch) | |
| tree | 2d732d884cb8a8e4ada340ea423321ff17e35ad3 | |
| parent | 5597606f188833979a7dbcf4a833e55e678f6e82 (diff) | |
Wrote up cleanup gunk on Mac OS X. Really gunk; I don't like what all this does but I don't think there's another way.
| -rw-r--r-- | new/button_darwin.m | 53 | ||||
| -rw-r--r-- | new/container_darwin.m | 5 | ||||
| -rw-r--r-- | new/init_darwin.m | 2 | ||||
| -rw-r--r-- | new/newcontrol_darwin.m | 10 | ||||
| -rw-r--r-- | new/uipriv_darwin.h | 21 | ||||
| -rw-r--r-- | new/util_darwin.m | 10 | ||||
| -rw-r--r-- | new/window_darwin.m | 4 |
7 files changed, 67 insertions, 38 deletions
diff --git a/new/button_darwin.m b/new/button_darwin.m index d4b2a2b..d422718 100644 --- a/new/button_darwin.m +++ b/new/button_darwin.m @@ -1,30 +1,19 @@ // 7 april 2015 #import "uipriv_darwin.h" -#ifdef uiLogAllocations -@interface loggingNSButton : NSButton +@interface uiNSButton : NSButton <uiFreeOnDealloc> +@property uiControl *uiC; +@property void (*uiOnClicked)(uiControl *, void *); +@property void *uiOnClickedData; +@property NSMutableArray *uiFreeList; @end -@implementation loggingNSButton +@implementation uiNSButton -uiLogObjCClassAllocations +uiLogObjCClassAllocations(uiDoFreeOnDealloc(self.uiFreeList);) +uiFreeOnDeallocImpl -@end -#else -#define loggingNSButton NSButton -#endif - -@interface button : NSObject -@property uiControl *c; -@property void (*onClicked)(uiControl *, void *); -@property void *onClickedData; -@end - -@implementation button - -uiLogObjCClassAllocations - -- (IBAction)buttonClicked:(id)sender +- (IBAction)uiButtonClicked:(id)sender { (*(self.onClicked))(self.c, self.onClickedData); } @@ -39,21 +28,21 @@ static void defaultOnClicked(uiControl *c, void *data) // TODO destruction uiControl *uiNewButton(const char *text) { - button *b; - NSButton *bb; + uiControl *c; + uiNSButton *b; - b = [button new]; - b.c = uiDarwinNewControl([loggingNSButton class], NO, NO, b); + c = uiDarwinNewControl([uiNSButton class], NO, NO, NULL); + b = (uiNSButton *) uiControlHandle(c); + b.c = c; - bb = (NSButton *) uiControlHandle(b.c); - [bb setTitle:toNSString(text)]; - [bb setButtonType:NSMomentaryPushInButton]; - [bb setBordered:YES]; - [bb setBezelStyle:NSRoundedBezelStyle]; + [b setTitle:toNSString(text)]; + [b setButtonType:NSMomentaryPushInButton]; + [b setBordered:YES]; + [b setBezelStyle:NSRoundedBezelStyle]; setStandardControlFont((NSControl *) bb); - [bb setTarget:b]; - [bb setAction:@selector(buttonClicked:)]; + [b setTarget:b]; + [b setAction:@selector(uiButtonClicked:)]; b.onClicked = defaultOnClicked; @@ -66,7 +55,7 @@ void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data) { button *b; - b = (button *) uiDarwinControlData(c); + b = (uiNSButton *) uiControlHandle(c); b.onClicked = f; b.onClickedData = data; } diff --git a/new/container_darwin.m b/new/container_darwin.m index f869f2c..af1acee 100644 --- a/new/container_darwin.m +++ b/new/container_darwin.m @@ -10,7 +10,10 @@ // thanks to mikeash and JtRip in irc.freenode.net/#macdev @implementation uiContainer -uiLogObjCClassAllocations +uiLogObjCClassAllocations( + if (self.child != NULL) + uiControlDestroy(self.child); +) - (void)setFrameSize:(NSSize)s { diff --git a/new/init_darwin.m b/new/init_darwin.m index d26c3fa..bd27dee 100644 --- a/new/init_darwin.m +++ b/new/init_darwin.m @@ -6,7 +6,7 @@ @implementation uiApplication -uiLogObjCClassAllocations +uiLogObjCClassAllocations() // hey look! we're overriding terminate:! // we're going to make sure we can go back to main() whether Cocoa likes it or not! diff --git a/new/newcontrol_darwin.m b/new/newcontrol_darwin.m index 9b9dd7b..5a346f1 100644 --- a/new/newcontrol_darwin.m +++ b/new/newcontrol_darwin.m @@ -13,6 +13,11 @@ struct uiSingleViewControl { #define S(c) ((uiSingleViewControl *) (c)) +static void singleDestroy(uiControl *c) +{ + [S(c)->view release]; +} + static uintptr_t singleHandle(uiControl *c) { return (uintptr_t) (S(c)->view); @@ -59,6 +64,7 @@ static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, i uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void *data) { uiSingleViewControl *c; + uiFreeOnDealloc *freer; c = uiNew(uiSingleViewControl); // thanks to autoxr and arwyn in irc.freenode.net/#macdev @@ -79,6 +85,7 @@ uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHas c->immediate = (NSView *) (c->scrollView); } + c->control.destroy = singleDestroy; c->control.handle = singleHandle; c->control.setParent = singleSetParent; c->control.preferredSize = singlePreferredSize; @@ -86,6 +93,9 @@ uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHas c->data = data; + freer = (uiFreeOnDealloc *) (c->view); + [freer uiFreeOnDealloc:c]; + return (uiControl *) c; } diff --git a/new/uipriv_darwin.h b/new/uipriv_darwin.h index 514297c..5e8c82e 100644 --- a/new/uipriv_darwin.h +++ b/new/uipriv_darwin.h @@ -14,7 +14,7 @@ struct uiSizing { // TODO see if we can override alloc instead #ifdef uiLogAllocations #import <stdio.h> -#define uiLogObjCClassAllocations \ +#define uiLogObjCClassAllocations(deallocCode) \ + (id)alloc \ { \ id thing; \ @@ -24,15 +24,32 @@ struct uiSizing { } \ - (void)dealloc \ { \ + deallocCode \ [super dealloc]; \ fprintf(stderr, "%p free\n", self); \ } #else -#define uiLogObjCClassAllocations +#define uiLogObjCClassAllocations(deallocCode) \ +- (void)dealloc \ +{ \ + deallocCode \ + [super dealloc]; \ +} #endif // util_darwin.m extern void setStandardControlFont(NSControl *); +@protocol uiFreeOnDealloc +- (void)uiFreeOnDealloc:(void *)p; +@end +#define uiFreeOnDeallocImpl \ +- (void)uiFreeOnDealloc:(void *)p \ +{ \ + if (self.uiFreeList == nil) \ + self.uiFreeList = [NSMutableArray new]; \ + [self.uiFreeList addObject:[NSValue valueWIthPointer:p]]; \ +} +extern void uiDoFreeOnDealloc(NSMutableArray *); // container_darwin.m @interface uiContainer : NSView diff --git a/new/util_darwin.m b/new/util_darwin.m index d8166e9..4ed562a 100644 --- a/new/util_darwin.m +++ b/new/util_darwin.m @@ -6,3 +6,13 @@ void setStandardControlFont(NSControl *control) { [control setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]]; } + +void uiDoFreeOnDealloc(NSMutableArray *m) +{ + [m enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { + NSValue *v = (NSValue *) obj; + + uiFree([v pointerValue]); + }]; + [m release]; +} diff --git a/new/window_darwin.m b/new/window_darwin.m index 8d582c3..ad5506a 100644 --- a/new/window_darwin.m +++ b/new/window_darwin.m @@ -10,7 +10,7 @@ @implementation loggingNSWindow -uiLogObjCClassAllocations +uiLogObjCClassAllocations() @end #else @@ -25,7 +25,7 @@ uiLogObjCClassAllocations @implementation uiWindowDelegate -uiLogObjCClassAllocations +uiLogObjCClassAllocations() - (BOOL)windowShouldClose:(id)win { |
