Added bins to the OS X backend. Let's try this again I guess :/

This commit is contained in:
Pietro Gagliardi 2015-07-29 12:28:13 -04:00
parent 3d79ccf24c
commit 0128e9f85e
4 changed files with 94 additions and 13 deletions

69
redo/darwin/bin.m Normal file
View File

@ -0,0 +1,69 @@
// 28 april 2015
#import "uipriv_darwin.h"
// This is a uiControl wrapper a la GtkBin on GTK+.
// It serves the function of tabPage on Windows: it allows uiWindow and uiTab to give their children a real uiControl as a parent while not screwing with the internal NSView structure of those uiControls.
// It also provides margins.
struct bin {
uiControl c;
NSView *view;
uiControl *child;
int margined;
};
uiDefineControlType(bin, binType, struct bin)
static uintptr_t binHandle(uiControl *c)
{
struct bin *b = (struct bin *) c;
return (uintptr_t) (b->view);
}
uiControl *newBin(void)
{
struct bin *b;
b = (struct bin *) uiNewControl(binType());
// a simple NSView will do fine
b->view = [[NSView alloc] initWithFrame:NSZeroRect];
uiDarwinMakeSingleWidgetControl(uiControl(b), b->view, NO);
uiControl(b)->Handle = binHandle;
return uiControl(b);
}
void binSetChild(uiControl *c, uiControl *child)
{
struct bin *b = (struct bin *) c;
NSView *childView;
if (b->child != NULL) {
childView = (NSView *) uiControlHandle(b->child);
[childView removeFromSuperview];
}
b->child = child;
if (b->child != NULL) {
uiControlSetParent(b->child, uiControl(b));
childView = (NSView *) uiControlHandle(b->child);
// TODO auto layout to autoresize
}
}
int binMargined(uiControl *c)
{
struct bin *b = (struct bin *) c;
return b->margined;
}
void binSetMargined(uiControl *c, int margined)
{
struct bin *b = (struct bin *) c;
b->margined = margined;
// TODO use auto layout
}

View File

@ -24,10 +24,12 @@ static void tabCommitDestroy(uiControl *c)
// the above loop serves the purpose of binSetParent()
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
NSValue *v = (NSValue *) obj;
uiBin *p;
uiControl *bin;
p = (uiBin *) [v pointerValue];
uiControlDestroy(uiControl(p));
bin = (uiControl *) [v pointerValue];
binSetChild(bin, NULL);
// TODO destroy the child
uiControlDestroy(uiControl(bin));
}];
// and finally destroy ourselves
[t->pages release];
@ -59,13 +61,14 @@ static void tabContainerUpdate(uiControl *c)
struct tab *t = (struct tab *) c;
(*(t->baseEnable))(uiControl(t));
// TODO enumerate over page CONTROLS instead
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
NSValue *v = (NSValue *) obj;
uiBin *page;
uiControl *bin;
page = (uiBin *) [v pointerValue];
bin = (uiControl *) [v pointerValue];
// TODO get the right function
uiContainerUpdate(uiControl(page));
uiContainerUpdate(uiControl(bin));
}];
}
@ -73,11 +76,11 @@ static void tabContainerUpdate(uiControl *c)
static void tabAppend(uiTab *tt, const char *name, uiControl *child)
{
struct tab *t = (struct tab *) tt;
uiBin *page;
uiControl *page;
NSTabViewItem *i;
page = newBin();
uiBinSetMainControl(page, child);
binSetChild(page, child);
[t->pages addObject:[NSValue valueWithPointer:page]];
[t->margined addObject:[NSNumber numberWithInt:0]];
@ -90,11 +93,11 @@ static void tabAppend(uiTab *tt, const char *name, uiControl *child)
static void tabInsertAt(uiTab *tt, const char *name, uintmax_t n, uiControl *child)
{
struct tab *t = (struct tab *) tt;
uiBin *page;
uiControl *page;
NSTabViewItem *i;
page = newBin();
uiBinSetMainControl(page, child);
binSetChild(page, child);
[t->pages insertObject:[NSValue valueWithPointer:page] atIndex:n];
[t->margined insertObject:[NSNumber numberWithInt:0] atIndex:n];
@ -108,7 +111,7 @@ static void tabDelete(uiTab *tt, uintmax_t n)
{
struct tab *t = (struct tab *) tt;
NSValue *v;
uiBin *page;
uiControl *page;
NSTabViewItem *i;
v = (NSValue *) [t->pages objectAtIndex:n];
@ -117,7 +120,7 @@ static void tabDelete(uiTab *tt, uintmax_t n)
[t->margined removeObjectAtIndex:n];
// make sure the children of the tab aren't destroyed
uiBinSetMainControl(page, NULL);
binSetChild(page, NULL);
// remove the bin from the tab view
// this serves the purpose of uiBinRemoveOSParent()
@ -166,11 +169,12 @@ static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
[t->margined replaceObjectAtIndex:n withObject:v];
pagev = (NSValue *) [t->pages objectAtIndex:n];
page = (uiBin *) [pagev pointerValue];
/* TODO
if ([v intValue])
uiBinSetMargins(page, tabLeftMargin, tabTopMargin, tabRightMargin, tabBottomMargin);
else
uiBinSetMargins(page, 0, 0, 0, 0);
uiContainerUpdate(uiContainer(page));
*/
}
uiTab *uiNewTab(void)

View File

@ -56,5 +56,11 @@ extern uiWindow *windowFromNSWindow(NSWindow *);
extern void initAlloc(void);
extern void uninitAlloc(void);
// bin.c
extern uiControl *newBin(void);
extern void binSetChild(uiControl *, uiControl *);
extern int binMargined(uiControl *);
extern void binSetMargined(uiControl *, int);
// TODO
#define PUT_CODE_HERE 0

View File

@ -48,6 +48,8 @@ static uintptr_t tabHandle(uiControl *c)
return (uintptr_t) (t->widget);
}
// TODO tabContainerUpdate()?
static void tabAppend(uiTab *tt, const char *name, uiControl *child)
{
struct tab *t = (struct tab *) tt;