2015-04-06 18:04:13 -05:00
|
|
|
// 6 april 2015
|
2015-04-06 23:26:27 -05:00
|
|
|
#import "uipriv_darwin.h"
|
2015-04-06 18:04:13 -05:00
|
|
|
|
2015-04-07 15:59:23 -05:00
|
|
|
// TODO
|
|
|
|
// - showing on size
|
|
|
|
|
2015-04-06 19:01:14 -05:00
|
|
|
@interface uiWindowDelegate : NSObject <NSWindowDelegate>
|
|
|
|
@property uiWindow *w;
|
|
|
|
@property int (*onClosing)(uiWindow *, void *);
|
2015-04-06 18:04:13 -05:00
|
|
|
@property void *onClosingData;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation uiWindowDelegate
|
|
|
|
|
|
|
|
// TODO will this *destroy* the window?
|
|
|
|
- (BOOL)windowShouldClose:(id)win
|
|
|
|
{
|
|
|
|
// return exact constants to be safe
|
2015-04-06 19:01:14 -05:00
|
|
|
if ((*(self.onClosing))(self.w, self.onClosingData))
|
2015-04-06 18:04:13 -05:00
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
struct uiWindow {
|
|
|
|
NSWindow *w;
|
2015-04-07 14:45:00 -05:00
|
|
|
uiContainer *container;
|
|
|
|
uiControl *child;
|
2015-04-06 18:04:13 -05:00
|
|
|
uiWindowDelegate *d;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int defaultOnClosing(uiWindow *w, void *data)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiWindow *uiNewWindow(char *title, int width, int height)
|
|
|
|
{
|
|
|
|
uiWindow *w;
|
|
|
|
|
|
|
|
w = (uiWindow *) uiAlloc(sizeof (uiWindow));
|
|
|
|
|
|
|
|
w->w = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height)
|
|
|
|
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:YES];
|
2015-04-06 19:01:14 -05:00
|
|
|
[w->w setTitle:toNSString(title)];
|
2015-04-06 18:04:13 -05:00
|
|
|
// TODO substitutions
|
|
|
|
|
2015-04-07 14:45:00 -05:00
|
|
|
w->container = [[uiContainer alloc] initWithFrame:NSZeroRect];
|
|
|
|
[w->w setContentView:((NSView *) w->container)];
|
|
|
|
|
2015-04-06 18:04:13 -05:00
|
|
|
w->d = [uiWindowDelegate new];
|
2015-04-06 19:01:14 -05:00
|
|
|
w->d.w = w;
|
2015-04-06 18:04:13 -05:00
|
|
|
w->d.onClosing = defaultOnClosing;
|
|
|
|
[w->w setDelegate:w->d];
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowDestroy(uiWindow *w)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
// TODO will w->d be destroyed?
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t uiWindowHandle(uiWindow *w)
|
|
|
|
{
|
|
|
|
return (uintptr_t) (w->w);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO titles
|
|
|
|
|
|
|
|
void uiWindowShow(uiWindow *w)
|
|
|
|
{
|
|
|
|
[w->w makeKeyAndOrderFront:w->w];
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowHide(uiWindow *w)
|
|
|
|
{
|
|
|
|
[w->w orderOut:w->w];
|
|
|
|
}
|
|
|
|
|
2015-04-06 19:01:14 -05:00
|
|
|
void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
|
2015-04-06 18:04:13 -05:00
|
|
|
{
|
|
|
|
w->d.onClosing = f;
|
|
|
|
w->d.onClosingData = data;
|
|
|
|
}
|
2015-04-07 14:45:00 -05:00
|
|
|
|
|
|
|
void uiWindowSetChild(uiWindow *w, uiControl *c)
|
|
|
|
{
|
|
|
|
w->child = c;
|
2015-04-07 15:38:51 -05:00
|
|
|
w->container.child = c;
|
2015-04-07 14:45:00 -05:00
|
|
|
(*(w->child->setParent))(w->child, (uintptr_t) (w->container));
|
|
|
|
}
|