Better monitoring of Objective-C objects (including main GUI objects).

This commit is contained in:
Pietro Gagliardi 2015-04-08 02:28:42 -04:00
parent d37bc67158
commit 5597606f18
3 changed files with 43 additions and 9 deletions

View File

@ -1,6 +1,19 @@
// 7 april 2015 // 7 april 2015
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
#ifdef uiLogAllocations
@interface loggingNSButton : NSButton
@end
@implementation loggingNSButton
uiLogObjCClassAllocations
@end
#else
#define loggingNSButton NSButton
#endif
@interface button : NSObject @interface button : NSObject
@property uiControl *c; @property uiControl *c;
@property void (*onClicked)(uiControl *, void *); @property void (*onClicked)(uiControl *, void *);
@ -30,7 +43,7 @@ uiControl *uiNewButton(const char *text)
NSButton *bb; NSButton *bb;
b = [button new]; 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 = (NSButton *) uiControlHandle(b.c);
[bb setTitle:toNSString(text)]; [bb setTitle:toNSString(text)];

View File

@ -11,14 +11,16 @@
struct uiSizing { struct uiSizing {
}; };
// TODO see if we can override alloc instead
#ifdef uiLogAllocations #ifdef uiLogAllocations
#import <stdio.h> #import <stdio.h>
#define uiLogObjCClassAllocations \ #define uiLogObjCClassAllocations \
- (id)init \ + (id)alloc \
{ \ { \
self = [super init]; \ id thing; \
fprintf(stderr, "%p alloc %s\n", self, [[self className] UTF8String]); \ thing = [super alloc]; \
return self; \ fprintf(stderr, "%p alloc %s\n", thing, [[self className] UTF8String]); \
return thing; \
} \ } \
- (void)dealloc \ - (void)dealloc \
{ \ { \

View File

@ -4,6 +4,19 @@
// TODO // TODO
// - showing on size // - showing on size
#ifdef uiLogAllocations
@interface loggingNSWindow : NSWindow
@end
@implementation loggingNSWindow
uiLogObjCClassAllocations
@end
#else
#define loggingNSWindow NSWindow
#endif
@interface uiWindowDelegate : NSObject <NSWindowDelegate> @interface uiWindowDelegate : NSObject <NSWindowDelegate>
@property uiWindow *w; @property uiWindow *w;
@property int (*onClosing)(uiWindow *, void *); @property int (*onClosing)(uiWindow *, void *);
@ -14,7 +27,6 @@
uiLogObjCClassAllocations uiLogObjCClassAllocations
// TODO will this *destroy* the window?
- (BOOL)windowShouldClose:(id)win - (BOOL)windowShouldClose:(id)win
{ {
// return exact constants to be safe // return exact constants to be safe
@ -23,6 +35,11 @@ uiLogObjCClassAllocations
return NO; return NO;
} }
- (void)windowWillClose:(NSNotification *)note
{
[self release];
}
@end @end
struct uiWindow { struct uiWindow {
@ -43,13 +60,16 @@ uiWindow *uiNewWindow(char *title, int width, int height)
w = uiNew(uiWindow); 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) styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:YES]; defer:YES];
[w->w setTitle:toNSString(title)]; [w->w setTitle:toNSString(title)];
// TODO substitutions // TODO substitutions
// this is what will destroy the window on close
[w->w setReleasedWhenClosed:YES];
w->container = [[uiContainer alloc] initWithFrame:NSZeroRect]; w->container = [[uiContainer alloc] initWithFrame:NSZeroRect];
[w->w setContentView:((NSView *) w->container)]; [w->w setContentView:((NSView *) w->container)];
@ -63,8 +83,7 @@ uiWindow *uiNewWindow(char *title, int width, int height)
void uiWindowDestroy(uiWindow *w) void uiWindowDestroy(uiWindow *w)
{ {
// TODO [w->w close];
// TODO will w->d be destroyed?
} }
uintptr_t uiWindowHandle(uiWindow *w) uintptr_t uiWindowHandle(uiWindow *w)