summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-07 16:38:51 -0400
committerPietro Gagliardi <[email protected]>2015-04-07 16:38:51 -0400
commit77a60d63a6aa6ffc02c541a8cdc7483744cc827c (patch)
tree95da186810be45a756d8433e437c268ef3714456
parent3969095a33a518023564ec32f8373bbad913b6c3 (diff)
Fixed compiler errors and bugs. uiButton on Mac OS X works!
-rw-r--r--new/button_darwin.m12
-rw-r--r--new/container_darwin.m2
-rw-r--r--new/main_darwin.m6
-rw-r--r--new/newcontrol_darwin.m20
-rw-r--r--new/ui_darwin.h2
-rw-r--r--new/uipriv_darwin.h6
-rw-r--r--new/window_darwin.m1
7 files changed, 31 insertions, 18 deletions
diff --git a/new/button_darwin.m b/new/button_darwin.m
index 85d25fa..7daf209 100644
--- a/new/button_darwin.m
+++ b/new/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/new/container_darwin.m b/new/container_darwin.m
index 7f628a3..d23eedf 100644
--- a/new/container_darwin.m
+++ b/new/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/new/main_darwin.m b/new/main_darwin.m
index d19af08..307b0a3 100644
--- a/new/main_darwin.m
+++ b/new/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/new/newcontrol_darwin.m b/new/newcontrol_darwin.m
index 1b3b799..10f2438 100644
--- a/new/newcontrol_darwin.m
+++ b/new/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/new/ui_darwin.h b/new/ui_darwin.h
index 0e7afb2..02d0faa 100644
--- a/new/ui_darwin.h
+++ b/new/ui_darwin.h
@@ -11,7 +11,7 @@ This file assumes that you have imported <Cocoa/Cocoa.h> 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/new/uipriv_darwin.h b/new/uipriv_darwin.h
index c613810..3c9c731 100644
--- a/new/uipriv_darwin.h
+++ b/new/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/new/window_darwin.m b/new/window_darwin.m
index b74714a..1ff9297 100644
--- a/new/window_darwin.m
+++ b/new/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));
}