Better monitoring of Objective-C objects (including main GUI objects).
This commit is contained in:
parent
fc8f9c6719
commit
9e4e11da8c
|
@ -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)];
|
||||
|
|
|
@ -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 \
|
||||
{ \
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue