Fixed initial Mac OS X code.
This commit is contained in:
parent
e4d6d11925
commit
685844c594
|
@ -1,12 +1,14 @@
|
||||||
// 4 december 2014
|
// 4 december 2014
|
||||||
#include "ui_darwin.h"
|
#include "ui_darwin.h"
|
||||||
|
|
||||||
|
// TODO is there a better alternative to NSCAssert()? preferably a built-in allocator that panics on out of memory for us?
|
||||||
|
|
||||||
void *uiAlloc(size_t size)
|
void *uiAlloc(size_t size)
|
||||||
{
|
{
|
||||||
void *out;
|
void *out;
|
||||||
|
|
||||||
out = malloc(size);
|
out = malloc(size);
|
||||||
NSAssert(out != NULL, @"out of memory in uiAlloc()");
|
NSCAssert(out != NULL, @"out of memory in uiAlloc()");
|
||||||
memset(out, 0, size);
|
memset(out, 0, size);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +20,7 @@ void *uiRealloc(void *p, size_t size)
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return uiAlloc(size);
|
return uiAlloc(size);
|
||||||
out = realloc(p, size);
|
out = realloc(p, size);
|
||||||
NSAssert(out != NULL, @"out of memory in uiRealloc()");
|
NSCAssert(out != NULL, @"out of memory in uiRealloc()");
|
||||||
// TODO zero the extra memory
|
// TODO zero the extra memory
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// 6 april 2015
|
// 6 april 2015
|
||||||
#include "ui_darwin.m"
|
#include "ui_darwin.h"
|
||||||
|
|
||||||
@interface uiApplication : NSApplication
|
@interface uiApplication : NSApplication
|
||||||
@end
|
@end
|
||||||
|
@ -31,6 +31,7 @@ uiInitError *uiInit(uiInitOptions *o)
|
||||||
|
|
||||||
const char *uiInitErrorMessage(uiInitError *err)
|
const char *uiInitErrorMessage(uiInitError *err)
|
||||||
{
|
{
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiInitErrorFree(uiInitError *err)
|
void uiInitErrorFree(uiInitError *err)
|
||||||
|
|
|
@ -26,5 +26,6 @@ int main(void)
|
||||||
uiWindowShow(w);
|
uiWindowShow(w);
|
||||||
|
|
||||||
uiMain();
|
uiMain();
|
||||||
|
printf("after uiMain()\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#import "ui.h"
|
#import "ui.h"
|
||||||
|
|
||||||
|
#define toNSString(str) [NSString stringWithUTF8String:(str)]
|
||||||
|
|
||||||
// alloc_darwin.m
|
// alloc_darwin.m
|
||||||
extern void *uiAlloc(size_t);
|
extern void *uiAlloc(size_t);
|
||||||
extern void *uiRealloc(void *, size_t);
|
extern void *uiRealloc(void *, size_t);
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// 6 april 2015
|
// 6 april 2015
|
||||||
#include "ui_darwin.h"
|
#include "ui_darwin.h"
|
||||||
|
|
||||||
@interface uiWindowDelegate : NSWindowDelegate
|
@interface uiWindowDelegate : NSObject <NSWindowDelegate>
|
||||||
@property void (*onClosing)(uiWindow *, void *);
|
@property uiWindow *w;
|
||||||
|
@property int (*onClosing)(uiWindow *, void *);
|
||||||
@property void *onClosingData;
|
@property void *onClosingData;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@
|
||||||
- (BOOL)windowShouldClose:(id)win
|
- (BOOL)windowShouldClose:(id)win
|
||||||
{
|
{
|
||||||
// return exact constants to be safe
|
// return exact constants to be safe
|
||||||
if ((*(self.onClosing))(self.onClosingData))
|
if ((*(self.onClosing))(self.w, self.onClosingData))
|
||||||
return YES;
|
return YES;
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
@ -39,9 +40,11 @@ uiWindow *uiNewWindow(char *title, int width, int height)
|
||||||
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
|
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
|
||||||
backing:NSBackingStoreBuffered
|
backing:NSBackingStoreBuffered
|
||||||
defer:YES];
|
defer:YES];
|
||||||
|
[w->w setTitle:toNSString(title)];
|
||||||
// TODO substitutions
|
// TODO substitutions
|
||||||
|
|
||||||
w->d = [uiWindowDelegate new];
|
w->d = [uiWindowDelegate new];
|
||||||
|
w->d.w = w;
|
||||||
w->d.onClosing = defaultOnClosing;
|
w->d.onClosing = defaultOnClosing;
|
||||||
[w->w setDelegate:w->d];
|
[w->w setDelegate:w->d];
|
||||||
|
|
||||||
|
@ -71,7 +74,7 @@ void uiWindowHide(uiWindow *w)
|
||||||
[w->w orderOut:w->w];
|
[w->w orderOut:w->w];
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiWindowOnClosing(uiWindow *w, int (*)(uiWindow *f, void *), void *data)
|
void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
|
||||||
{
|
{
|
||||||
w->d.onClosing = f;
|
w->d.onClosing = f;
|
||||||
w->d.onClosingData = data;
|
w->d.onClosingData = data;
|
||||||
|
|
Loading…
Reference in New Issue