Fixed compiler errors and bugs. uiButton on Mac OS X works!

This commit is contained in:
Pietro Gagliardi 2015-04-07 16:38:51 -04:00
parent 2b40ad90ad
commit 28adb7fee5
7 changed files with 31 additions and 18 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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);
}

View File

@ -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;

View File

@ -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

View File

@ -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 *);

View File

@ -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));
}