summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--new/button_darwin.m15
-rw-r--r--new/uipriv_darwin.h10
-rw-r--r--new/window_darwin.m27
3 files changed, 43 insertions, 9 deletions
diff --git a/new/button_darwin.m b/new/button_darwin.m
index 87c4525..d4b2a2b 100644
--- a/new/button_darwin.m
+++ b/new/button_darwin.m
@@ -1,6 +1,19 @@
// 7 april 2015
#import "uipriv_darwin.h"
+#ifdef uiLogAllocations
+@interface loggingNSButton : NSButton
+@end
+
+@implementation loggingNSButton
+
+uiLogObjCClassAllocations
+
+@end
+#else
+#define loggingNSButton NSButton
+#endif
+
@interface button : NSObject
@property uiControl *c;
@property void (*onClicked)(uiControl *, void *);
@@ -30,7 +43,7 @@ uiControl *uiNewButton(const char *text)
NSButton *bb;
b = [button new];
- b.c = uiDarwinNewControl([NSButton class], NO, NO, b);
+ b.c = uiDarwinNewControl([loggingNSButton class], NO, NO, b);
bb = (NSButton *) uiControlHandle(b.c);
[bb setTitle:toNSString(text)];
diff --git a/new/uipriv_darwin.h b/new/uipriv_darwin.h
index e1b38af..514297c 100644
--- a/new/uipriv_darwin.h
+++ b/new/uipriv_darwin.h
@@ -11,14 +11,16 @@
struct uiSizing {
};
+// TODO see if we can override alloc instead
#ifdef uiLogAllocations
#import <stdio.h>
#define uiLogObjCClassAllocations \
-- (id)init \
++ (id)alloc \
{ \
- self = [super init]; \
- fprintf(stderr, "%p alloc %s\n", self, [[self className] UTF8String]); \
- return self; \
+ id thing; \
+ thing = [super alloc]; \
+ fprintf(stderr, "%p alloc %s\n", thing, [[self className] UTF8String]); \
+ return thing; \
} \
- (void)dealloc \
{ \
diff --git a/new/window_darwin.m b/new/window_darwin.m
index 795c2e0..8d582c3 100644
--- a/new/window_darwin.m
+++ b/new/window_darwin.m
@@ -4,6 +4,19 @@
// TODO
// - showing on size
+#ifdef uiLogAllocations
+@interface loggingNSWindow : NSWindow
+@end
+
+@implementation loggingNSWindow
+
+uiLogObjCClassAllocations
+
+@end
+#else
+#define loggingNSWindow NSWindow
+#endif
+
@interface uiWindowDelegate : NSObject <NSWindowDelegate>
@property uiWindow *w;
@property int (*onClosing)(uiWindow *, void *);
@@ -14,7 +27,6 @@
uiLogObjCClassAllocations
-// TODO will this *destroy* the window?
- (BOOL)windowShouldClose:(id)win
{
// return exact constants to be safe
@@ -23,6 +35,11 @@ uiLogObjCClassAllocations
return NO;
}
+- (void)windowWillClose:(NSNotification *)note
+{
+ [self release];
+}
+
@end
struct uiWindow {
@@ -43,13 +60,16 @@ uiWindow *uiNewWindow(char *title, int width, int height)
w = uiNew(uiWindow);
- w->w = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height)
+ w->w = [[loggingNSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height)
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
backing:NSBackingStoreBuffered
defer:YES];
[w->w setTitle:toNSString(title)];
// TODO substitutions
+ // this is what will destroy the window on close
+ [w->w setReleasedWhenClosed:YES];
+
w->container = [[uiContainer alloc] initWithFrame:NSZeroRect];
[w->w setContentView:((NSView *) w->container)];
@@ -63,8 +83,7 @@ uiWindow *uiNewWindow(char *title, int width, int height)
void uiWindowDestroy(uiWindow *w)
{
- // TODO
- // TODO will w->d be destroyed?
+ [w->w close];
}
uintptr_t uiWindowHandle(uiWindow *w)