From 28adb7fee542840831ab3f820d0fb75e465f0a97 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 7 Apr 2015 16:38:51 -0400 Subject: [PATCH] Fixed compiler errors and bugs. uiButton on Mac OS X works! --- button_darwin.m | 12 ++++++------ container_darwin.m | 2 +- main_darwin.m | 6 ++++++ newcontrol_darwin.m | 20 ++++++++++---------- ui_darwin.h | 2 +- uipriv_darwin.h | 6 ++++++ window_darwin.m | 1 + 7 files changed, 31 insertions(+), 18 deletions(-) diff --git a/button_darwin.m b/button_darwin.m index 85d25fa3..7daf209b 100644 --- a/button_darwin.m +++ b/button_darwin.m @@ -28,9 +28,9 @@ uiControl *uiNewButton(const char *text) NSButton *bb; b = [button new]; - b->c = uiDarwinNewControl([NSButton class], NO, NO, b); + b.c = uiDarwinNewControl([NSButton class], NO, NO, b); - bb = (NSButton *) uiDarwinControlData(b->c); + bb = (NSButton *) uiControlHandle(b.c); [bb setTitle:toNSString(text)]; [bb setButtonType:NSMomentaryPushInButton]; [bb setBordered:YES]; @@ -40,9 +40,9 @@ uiControl *uiNewButton(const char *text) [bb setTarget:b]; [bb setAction:@selector(buttonClicked:)]; - b->onClicked = defaultOnClicked; + b.onClicked = defaultOnClicked; - return b->c; + return b.c; } // TODO text @@ -52,6 +52,6 @@ void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data) button *b; b = (button *) uiDarwinControlData(c); - b->onClicked = f; - b->onClickedData = data; + b.onClicked = f; + b.onClickedData = data; } diff --git a/container_darwin.m b/container_darwin.m index 7f628a3a..d23eedf5 100644 --- a/container_darwin.m +++ b/container_darwin.m @@ -16,7 +16,7 @@ [super setFrameSize:s]; if (self.child != NULL) - (*(self.child->resize))(self.child, 0, 0, [self bounds].size.width, [self bounds].size.height, d); + (*(self.child->resize))(self.child, [self bounds].origin.y, [self bounds].origin.y, [self bounds].size.width, [self bounds].size.height, &d); } @end diff --git a/main_darwin.m b/main_darwin.m index d19af087..307b0a3f 100644 --- a/main_darwin.m +++ b/main_darwin.m @@ -26,3 +26,9 @@ void uiQuit(void) [NSApp postEvent:e atStart:NO]; // let pending events take priority // TODO really wait? } + +// TODO move somewhere else +uintptr_t uiControlHandle(uiControl *c) +{ + return (*(c->handle))(c); +} diff --git a/newcontrol_darwin.m b/newcontrol_darwin.m index 1b3b7996..10f24388 100644 --- a/newcontrol_darwin.m +++ b/newcontrol_darwin.m @@ -1,13 +1,13 @@ // 7 april 2015 #include "uipriv_darwin.h" -typedef struct uiSingleWidgetControl uiSingleWidgetControl; +typedef struct uiSingleViewControl uiSingleViewControl; struct uiSingleViewControl { uiControl control; - NSView *control; + NSView *view; NSScrollView *scrollView; - NSView *immediate; // the control that is added to the parent container; either control or scrollView + NSView *immediate; // the control that is added to the parent container; either view or scrollView void *data; }; @@ -15,7 +15,7 @@ struct uiSingleViewControl { static uintptr_t singleHandle(uiControl *c) { - return (uintptr_t) (S(c)->control); + return (uintptr_t) (S(c)->view); } static void singleSetParent(uiControl *c, uintptr_t parent) @@ -40,7 +40,7 @@ static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, i frame.origin.x = x; // mac os x coordinate system has (0,0) in the lower-left - frame.origin.y = [[S(c)->immediate superview] bounds].size.height - y; + frame.origin.y = ([[S(c)->immediate superview] bounds].size.height - height) - y; frame.size.width = width; frame.size.height = height; frame = [S(c)->immediate frameForAlignmentRect:frame]; @@ -63,15 +63,15 @@ uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHas { uiSingleViewControl *c; - c = g_new0(uiSingleViewControl, 1); + c = uiNew(uiSingleViewControl); // thanks to autoxr and arwyn in irc.freenode.net/#macdev - c->widget = (NSView *) [[class alloc] initWithFrame:NSZeroRect]; - c->immediate = c->control; + c->view = (NSView *) [[class alloc] initWithFrame:NSZeroRect]; + c->immediate = c->view; // TODO turn into bit field? if (inScrollView) { c->scrollView = [[NSScrollView alloc] initWithFrame:NSZeroRect]; - [c->scrollView setDocumentView:c->control]; + [c->scrollView setDocumentView:c->view]; [c->scrollView setHasHorizontalScroller:YES]; [c->scrollView setHasVerticalScroller:YES]; [c->scrollView setAutohidesScrollers:YES]; @@ -79,7 +79,7 @@ uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHas [c->scrollView setBorderType:NSBezelBorder]; else [c->scrollView setBorderType:NSNoBorder]; - c->immediate = (NSView *) (c->scrolledWindow); + c->immediate = (NSView *) (c->scrollView); } c->control.handle = singleHandle; diff --git a/ui_darwin.h b/ui_darwin.h index 0e7afb2a..02d0faa5 100644 --- a/ui_darwin.h +++ b/ui_darwin.h @@ -11,7 +11,7 @@ This file assumes that you have imported and "ui.h" beforehand. // The first parameter should come from [RealControlType class]. // The two scrollView parameters allow placing scrollbars on the new control. // The data parameter can be accessed with uiDarwinControlData(). -extern uiControl *uiDarwinNewControl(Class class, gboolean inScrollView, gboolean scrollViewHasBorder, void *data); +extern uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void *data); extern void *uiDarwinControlData(uiControl *c); #endif diff --git a/uipriv_darwin.h b/uipriv_darwin.h index c6138108..3c9c7316 100644 --- a/uipriv_darwin.h +++ b/uipriv_darwin.h @@ -7,8 +7,14 @@ #define toNSString(str) [NSString stringWithUTF8String:(str)] +// TODO move this to the right place +struct uiSizing { +}; + // alloc_darwin.m extern void *uiAlloc(size_t); +// TODO use this in existing files +#define uiNew(T) ((T *) uiAlloc(sizeof (T))) extern void *uiRealloc(void *, size_t); extern void uiFree(void *); diff --git a/window_darwin.m b/window_darwin.m index b74714a2..1ff9297a 100644 --- a/window_darwin.m +++ b/window_darwin.m @@ -88,5 +88,6 @@ void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) void uiWindowSetChild(uiWindow *w, uiControl *c) { w->child = c; + w->container.child = c; (*(w->child->setParent))(w->child, (uintptr_t) (w->container)); }