summaryrefslogtreecommitdiff
path: root/new/window_darwin.m
diff options
context:
space:
mode:
Diffstat (limited to 'new/window_darwin.m')
-rw-r--r--new/window_darwin.m78
1 files changed, 78 insertions, 0 deletions
diff --git a/new/window_darwin.m b/new/window_darwin.m
new file mode 100644
index 0000000..4469690
--- /dev/null
+++ b/new/window_darwin.m
@@ -0,0 +1,78 @@
+// 6 april 2015
+#include "ui_darwin.h"
+
+@interface uiWindowDelegate : NSWindowDelegate
+@property void (*onClosing)(uiWindow *, void *);
+@property void *onClosingData;
+@end
+
+@implementation uiWindowDelegate
+
+// TODO will this *destroy* the window?
+- (BOOL)windowShouldClose:(id)win
+{
+ // return exact constants to be safe
+ if ((*(self.onClosing))(self.onClosingData))
+ return YES;
+ return NO;
+}
+
+@end
+
+struct uiWindow {
+ NSWindow *w;
+ 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];
+ // TODO substitutions
+
+ w->d = [uiWindowDelegate new];
+ 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];
+}
+
+void uiWindowOnClosing(uiWindow *w, int (*)(uiWindow *f, void *), void *data)
+{
+ w->d.onClosing = f;
+ w->d.onClosingData = data;
+}