summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-07 15:45:00 -0400
committerPietro Gagliardi <[email protected]>2015-04-07 15:45:56 -0400
commit96e25cf50293d2c8f33bbd4d2578a4e2b63441f9 (patch)
tree59e11ab0eeff206f4bbfb1460d44b35e4e5dc7ea
parenta013fe638412809fe3dd18f0231d68d1ce469d56 (diff)
Added the Mac OS X uiContainer. Added it to uiWindow. Added the Mac OS X coordinate system mirroring to the new control logic. Renamed *_darwin.c to *_darwin.m.
-rw-r--r--new/container_darwin.m22
-rw-r--r--new/newcontrol_darwin.m (renamed from new/newcontrol_darwin.c)3
-rw-r--r--new/uipriv_darwin.h5
-rw-r--r--new/window_darwin.m11
4 files changed, 40 insertions, 1 deletions
diff --git a/new/container_darwin.m b/new/container_darwin.m
new file mode 100644
index 0000000..7f628a3
--- /dev/null
+++ b/new/container_darwin.m
@@ -0,0 +1,22 @@
+// 4 august 2014
+#import "uipriv_darwin.h"
+
+// calling -[className] on the content views of NSWindow, NSTabItem, and NSBox all return NSView, so I'm assuming I just need to override these
+// fornunately:
+// - NSWindow resizing calls -[setFrameSize:] (but not -[setFrame:])
+// - NSTab resizing calls both -[setFrame:] and -[setFrameSIze:] on the current tab
+// - NSTab switching tabs calls both -[setFrame:] and -[setFrameSize:] on the new tab
+// so we just override setFrameSize:
+// thanks to mikeash and JtRip in irc.freenode.net/#macdev
+@implementation uiContainer
+
+- (void)setFrameSize:(NSSize)s
+{
+ uiSizing d;
+
+ [super setFrameSize:s];
+ if (self.child != NULL)
+ (*(self.child->resize))(self.child, 0, 0, [self bounds].size.width, [self bounds].size.height, d);
+}
+
+@end
diff --git a/new/newcontrol_darwin.c b/new/newcontrol_darwin.m
index 66a7ecc..1b3b799 100644
--- a/new/newcontrol_darwin.c
+++ b/new/newcontrol_darwin.m
@@ -39,7 +39,8 @@ static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, i
NSRect frame;
frame.origin.x = x;
- frame.origin.y = y;
+ // mac os x coordinate system has (0,0) in the lower-left
+ frame.origin.y = [[S(c)->immediate superview] bounds].size.height - y;
frame.size.width = width;
frame.size.height = height;
frame = [S(c)->immediate frameForAlignmentRect:frame];
diff --git a/new/uipriv_darwin.h b/new/uipriv_darwin.h
index 191355f..f45b8e6 100644
--- a/new/uipriv_darwin.h
+++ b/new/uipriv_darwin.h
@@ -11,3 +11,8 @@
extern void *uiAlloc(size_t);
extern void *uiRealloc(void *, size_t);
extern void uiFree(void *);
+
+// container_darwin.m
+@interface uiContainer : NSView
+@property uiControl *child;
+@end
diff --git a/new/window_darwin.m b/new/window_darwin.m
index 30c3a1a..b74714a 100644
--- a/new/window_darwin.m
+++ b/new/window_darwin.m
@@ -22,6 +22,8 @@
struct uiWindow {
NSWindow *w;
+ uiContainer *container;
+ uiControl *child;
uiWindowDelegate *d;
};
@@ -43,6 +45,9 @@ uiWindow *uiNewWindow(char *title, int width, int height)
[w->w setTitle:toNSString(title)];
// TODO substitutions
+ w->container = [[uiContainer alloc] initWithFrame:NSZeroRect];
+ [w->w setContentView:((NSView *) w->container)];
+
w->d = [uiWindowDelegate new];
w->d.w = w;
w->d.onClosing = defaultOnClosing;
@@ -79,3 +84,9 @@ void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
w->d.onClosing = f;
w->d.onClosingData = data;
}
+
+void uiWindowSetChild(uiWindow *w, uiControl *c)
+{
+ w->child = c;
+ (*(w->child->setParent))(w->child, (uintptr_t) (w->container));
+}