More OS X uiControl work... kinda. At least all the controls that were in previously are now back in; that just leaes the new ones now.
This commit is contained in:
parent
62b5365577
commit
2e4af8a123
227
darwin/tab.m
227
darwin/tab.m
|
@ -1,227 +0,0 @@
|
||||||
// 12 april 2015
|
|
||||||
#import "uipriv_darwin.h"
|
|
||||||
|
|
||||||
// TODO rewrite this whole file to take advantage of bin functions
|
|
||||||
|
|
||||||
struct tab {
|
|
||||||
uiTab t;
|
|
||||||
NSTabView *tabview;
|
|
||||||
NSMutableArray *pages;
|
|
||||||
NSMutableArray *margined;
|
|
||||||
void (*baseEnable)(uiControl *);
|
|
||||||
void (*baseDisable)(uiControl *);
|
|
||||||
void (*baseSysFunc)(uiControl *, uiControlSysFuncParams *);
|
|
||||||
};
|
|
||||||
|
|
||||||
static void destroy(void *data)
|
|
||||||
{
|
|
||||||
struct tab *t = (struct tab *) data;
|
|
||||||
|
|
||||||
// first destroy all tab pages so we can destroy all the bins
|
|
||||||
while ([t->tabview numberOfTabViewItems] != 0)
|
|
||||||
[t->tabview removeTabViewItem:[t->tabview tabViewItemAtIndex:0]];
|
|
||||||
// then destroy all the bins, destroying children in the process
|
|
||||||
// the above loop serves the purpose of binSetParent()
|
|
||||||
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
||||||
NSValue *v = (NSValue *) obj;
|
|
||||||
uiBin *p;
|
|
||||||
|
|
||||||
p = (uiBin *) [v pointerValue];
|
|
||||||
uiControlDestroy(uiControl(p));
|
|
||||||
}];
|
|
||||||
// and finally destroy ourselves
|
|
||||||
[t->pages release];
|
|
||||||
[t->margined release];
|
|
||||||
uiFree(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
// the default new control implementation uses -sizeToFit, which we don't have with NSTabView
|
|
||||||
// fortunately, we do have -minimumSize
|
|
||||||
static void tabPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
|
||||||
{
|
|
||||||
struct tab *t = (struct tab *) c;
|
|
||||||
NSSize s;
|
|
||||||
|
|
||||||
s = [t->tabview minimumSize];
|
|
||||||
*width = (intmax_t) (s.width);
|
|
||||||
*height = (intmax_t) (s.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tabEnable(uiControl *c)
|
|
||||||
{
|
|
||||||
struct tab *t = (struct tab *) c;
|
|
||||||
|
|
||||||
(*(t->baseEnable))(uiControl(t));
|
|
||||||
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
||||||
NSValue *v = (NSValue *) obj;
|
|
||||||
uiBin *page;
|
|
||||||
|
|
||||||
page = (uiBin *) [v pointerValue];
|
|
||||||
uiControlEnable(uiControl(page));
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tabDisable(uiControl *c)
|
|
||||||
{
|
|
||||||
struct tab *t = (struct tab *) c;
|
|
||||||
|
|
||||||
(*(t->baseDisable))(uiControl(t));
|
|
||||||
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
||||||
NSValue *v = (NSValue *) obj;
|
|
||||||
uiBin *page;
|
|
||||||
|
|
||||||
page = (uiBin *) [v pointerValue];
|
|
||||||
uiControlDisable(uiControl(page));
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tabSysFunc(uiControl *c, uiControlSysFuncParams *p)
|
|
||||||
{
|
|
||||||
struct tab *t = (struct tab *) c;
|
|
||||||
|
|
||||||
(*(t->baseSysFunc))(uiControl(t), p);
|
|
||||||
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
||||||
NSValue *v = (NSValue *) obj;
|
|
||||||
uiBin *page;
|
|
||||||
|
|
||||||
page = (uiBin *) [v pointerValue];
|
|
||||||
uiControlSysFunc(uiControl(page), p);
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tabAppendPage(uiTab *tt, const char *name, uiControl *child)
|
|
||||||
{
|
|
||||||
struct tab *t = (struct tab *) tt;
|
|
||||||
uiBin *page;
|
|
||||||
NSTabViewItem *i;
|
|
||||||
|
|
||||||
page = newBin();
|
|
||||||
uiBinSetMainControl(page, child);
|
|
||||||
[t->pages addObject:[NSValue valueWithPointer:page]];
|
|
||||||
[t->margined addObject:[NSNumber numberWithInt:0]];
|
|
||||||
|
|
||||||
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
|
||||||
[i setLabel:toNSString(name)];
|
|
||||||
[i setView:((NSView *) uiControlHandle(uiControl(page)))];
|
|
||||||
[t->tabview addTabViewItem:i];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tabInsertPageBefore(uiTab *tt, const char *name, uintmax_t n, uiControl *child)
|
|
||||||
{
|
|
||||||
struct tab *t = (struct tab *) tt;
|
|
||||||
uiBin *page;
|
|
||||||
NSTabViewItem *i;
|
|
||||||
|
|
||||||
page = newBin();
|
|
||||||
uiBinSetMainControl(page, child);
|
|
||||||
[t->pages insertObject:[NSValue valueWithPointer:page] atIndex:n];
|
|
||||||
[t->margined insertObject:[NSNumber numberWithInt:0] atIndex:n];
|
|
||||||
|
|
||||||
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
|
||||||
[i setLabel:toNSString(name)];
|
|
||||||
[i setView:((NSView *) uiControlHandle(uiControl(page)))];
|
|
||||||
[t->tabview insertTabViewItem:i atIndex:n];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tabDeletePage(uiTab *tt, uintmax_t n)
|
|
||||||
{
|
|
||||||
struct tab *t = (struct tab *) tt;
|
|
||||||
NSValue *v;
|
|
||||||
uiBin *page;
|
|
||||||
NSTabViewItem *i;
|
|
||||||
|
|
||||||
v = (NSValue *) [t->pages objectAtIndex:n];
|
|
||||||
page = (uiBin *) [v pointerValue];
|
|
||||||
[t->pages removeObjectAtIndex:n];
|
|
||||||
[t->margined removeObjectAtIndex:n];
|
|
||||||
|
|
||||||
// make sure the children of the tab aren't destroyed
|
|
||||||
uiBinSetMainControl(page, NULL);
|
|
||||||
|
|
||||||
// remove the bin from the tab view
|
|
||||||
// this serves the purpose of uiBinRemoveOSParent()
|
|
||||||
i = [t->tabview tabViewItemAtIndex:n];
|
|
||||||
[t->tabview removeTabViewItem:i];
|
|
||||||
|
|
||||||
// then destroy the bin
|
|
||||||
uiControlDestroy(uiControl(page));
|
|
||||||
}
|
|
||||||
|
|
||||||
static uintmax_t tabNumPages(uiTab *tt)
|
|
||||||
{
|
|
||||||
struct tab *t = (struct tab *) tt;
|
|
||||||
|
|
||||||
return [t->pages count];
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tabMargined(uiTab *tt, uintmax_t n)
|
|
||||||
{
|
|
||||||
struct tab *t = (struct tab *) tt;
|
|
||||||
NSNumber *v;
|
|
||||||
|
|
||||||
v = (NSNumber *) [t->margined objectAtIndex:n];
|
|
||||||
return [v intValue];
|
|
||||||
}
|
|
||||||
|
|
||||||
// These are based on measurements from Interface Builder.
|
|
||||||
// These seem to be based on Auto Layout constants, but I don't see an API that exposes these...
|
|
||||||
#define tabLeftMargin 17
|
|
||||||
#define tabTopMargin 3
|
|
||||||
#define tabRightMargin 17
|
|
||||||
#define tabBottomMargin 17
|
|
||||||
|
|
||||||
// notes:
|
|
||||||
// top margin of a tab to its parent should be 12, not 20
|
|
||||||
// our system doesn't allow this...
|
|
||||||
|
|
||||||
static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
|
|
||||||
{
|
|
||||||
struct tab *t = (struct tab *) tt;
|
|
||||||
NSNumber *v;
|
|
||||||
NSValue *pagev;
|
|
||||||
uiBin *page;
|
|
||||||
|
|
||||||
v = [NSNumber numberWithInt:margined];
|
|
||||||
[t->margined replaceObjectAtIndex:n withObject:v];
|
|
||||||
pagev = (NSValue *) [t->pages objectAtIndex:n];
|
|
||||||
page = (uiBin *) [pagev pointerValue];
|
|
||||||
if ([v intValue])
|
|
||||||
uiBinSetMargins(page, tabLeftMargin, tabTopMargin, tabRightMargin, tabBottomMargin);
|
|
||||||
else
|
|
||||||
uiBinSetMargins(page, 0, 0, 0, 0);
|
|
||||||
uiContainerUpdate(uiContainer(page));
|
|
||||||
}
|
|
||||||
|
|
||||||
uiTab *uiNewTab(void)
|
|
||||||
{
|
|
||||||
struct tab *t;
|
|
||||||
|
|
||||||
t = uiNew(struct tab);
|
|
||||||
|
|
||||||
uiDarwinMakeControl(uiControl(t), [NSTabView class], NO, NO, destroy, t);
|
|
||||||
|
|
||||||
t->tabview = (NSTabView *) uiControlHandle(uiControl(t));
|
|
||||||
|
|
||||||
// also good for NSTabView (same selector and everything)
|
|
||||||
setStandardControlFont((NSControl *) (t->tabview));
|
|
||||||
|
|
||||||
t->pages = [NSMutableArray new];
|
|
||||||
t->margined = [NSMutableArray new];
|
|
||||||
|
|
||||||
uiControl(t)->PreferredSize = tabPreferredSize;
|
|
||||||
t->baseEnable = uiControl(t)->Enable;
|
|
||||||
uiControl(t)->Enable = tabEnable;
|
|
||||||
t->baseDisable = uiControl(t)->Disable;
|
|
||||||
uiControl(t)->Disable = tabDisable;
|
|
||||||
t->baseSysFunc = uiControl(t)->SysFunc;
|
|
||||||
uiControl(t)->SysFunc = tabSysFunc;
|
|
||||||
|
|
||||||
uiTab(t)->AppendPage = tabAppendPage;
|
|
||||||
uiTab(t)->InsertPageBefore = tabInsertPageBefore;
|
|
||||||
uiTab(t)->DeletePage = tabDeletePage;
|
|
||||||
uiTab(t)->NumPages = tabNumPages;
|
|
||||||
uiTab(t)->Margined = tabMargined;
|
|
||||||
uiTab(t)->SetMargined = tabSetMargined;
|
|
||||||
|
|
||||||
return uiTab(t);
|
|
||||||
}
|
|
|
@ -1,60 +1,176 @@
|
||||||
// 11 june 2015
|
// 11 june 2015
|
||||||
#include "uipriv_darwin.h"
|
#include "uipriv_darwin.h"
|
||||||
|
|
||||||
|
// TODO rewrite this whole file to take advantage of what we used to call bin functions
|
||||||
|
|
||||||
struct tab {
|
struct tab {
|
||||||
uiTab t;
|
uiTab t;
|
||||||
OSTYPE *OSHANDLE;
|
NSTabView *tabview;
|
||||||
|
NSMutableArray *pages;
|
||||||
|
NSMutableArray *margined;
|
||||||
|
void (*baseCommitDestroy)(uiControl *);
|
||||||
};
|
};
|
||||||
|
|
||||||
uiDefineControlType(uiTab, uiTypeTab, struct tab)
|
uiDefineControlType(uiTab, uiTypeTab, struct tab)
|
||||||
|
|
||||||
|
static void tabCommitDestroy(uiControl *c)
|
||||||
|
{
|
||||||
|
struct tab *t = (struct tab *) c;
|
||||||
|
|
||||||
|
// first destroy all tab pages so we can destroy all the bins
|
||||||
|
while ([t->tabview numberOfTabViewItems] != 0)
|
||||||
|
[t->tabview removeTabViewItem:[t->tabview tabViewItemAtIndex:0]];
|
||||||
|
// then destroy all the bins, destroying children in the process
|
||||||
|
// the above loop serves the purpose of binSetParent()
|
||||||
|
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||||
|
NSValue *v = (NSValue *) obj;
|
||||||
|
uiBin *p;
|
||||||
|
|
||||||
|
p = (uiBin *) [v pointerValue];
|
||||||
|
uiControlDestroy(uiControl(p));
|
||||||
|
}];
|
||||||
|
// and finally destroy ourselves
|
||||||
|
[t->pages release];
|
||||||
|
[t->margined release];
|
||||||
|
(*(t->baseCommitDestroy))(uiControl(t));
|
||||||
|
}
|
||||||
|
|
||||||
static uintptr_t tabHandle(uiControl *c)
|
static uintptr_t tabHandle(uiControl *c)
|
||||||
{
|
{
|
||||||
struct tab *t = (struct tab *) c;
|
struct tab *t = (struct tab *) c;
|
||||||
|
|
||||||
return (uintptr_t) (t->OSHANDLE);
|
return (uintptr_t) (t->tabview);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the default new control implementation uses -sizeToFit, which we don't have with NSTabView
|
||||||
|
// fortunately, we do have -minimumSize
|
||||||
|
static void tabPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
||||||
|
{
|
||||||
|
struct tab *t = (struct tab *) c;
|
||||||
|
NSSize s;
|
||||||
|
|
||||||
|
s = [t->tabview minimumSize];
|
||||||
|
*width = (intmax_t) (s.width);
|
||||||
|
*height = (intmax_t) (s.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tabContainerUpdate(uiControl *c)
|
||||||
|
{
|
||||||
|
struct tab *t = (struct tab *) c;
|
||||||
|
|
||||||
|
(*(t->baseEnable))(uiControl(t));
|
||||||
|
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||||
|
NSValue *v = (NSValue *) obj;
|
||||||
|
uiBin *page;
|
||||||
|
|
||||||
|
page = (uiBin *) [v pointerValue];
|
||||||
|
// TODO get the right function
|
||||||
|
uiContainerUpdate(uiControl(page));
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO merge with InsertAt
|
||||||
static void tabAppend(uiTab *tt, const char *name, uiControl *child)
|
static void tabAppend(uiTab *tt, const char *name, uiControl *child)
|
||||||
{
|
{
|
||||||
struct tab *t = (struct tab *) tt;
|
struct tab *t = (struct tab *) tt;
|
||||||
|
uiBin *page;
|
||||||
|
NSTabViewItem *i;
|
||||||
|
|
||||||
uiTabInsertAt(tt, name, PUT_CODE_HERE, child);
|
page = newBin();
|
||||||
|
uiBinSetMainControl(page, child);
|
||||||
|
[t->pages addObject:[NSValue valueWithPointer:page]];
|
||||||
|
[t->margined addObject:[NSNumber numberWithInt:0]];
|
||||||
|
|
||||||
|
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
||||||
|
[i setLabel:toNSString(name)];
|
||||||
|
[i setView:((NSView *) uiControlHandle(uiControl(page)))];
|
||||||
|
[t->tabview addTabViewItem:i];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tabInsertAt(uiTab *tt, const char *name, uintmax_t n, uiControl *child)
|
static void tabInsertAt(uiTab *tt, const char *name, uintmax_t n, uiControl *child)
|
||||||
{
|
{
|
||||||
struct tab *t = (struct tab *) tt;
|
struct tab *t = (struct tab *) tt;
|
||||||
|
uiBin *page;
|
||||||
|
NSTabViewItem *i;
|
||||||
|
|
||||||
PUT_CODE_HERE;
|
page = newBin();
|
||||||
|
uiBinSetMainControl(page, child);
|
||||||
|
[t->pages insertObject:[NSValue valueWithPointer:page] atIndex:n];
|
||||||
|
[t->margined insertObject:[NSNumber numberWithInt:0] atIndex:n];
|
||||||
|
|
||||||
|
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
||||||
|
[i setLabel:toNSString(name)];
|
||||||
|
[i setView:((NSView *) uiControlHandle(uiControl(page)))];
|
||||||
|
[t->tabview insertTabViewItem:i atIndex:n];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tabDelete(uiTab *tt, uintmax_t n)
|
static void tabDelete(uiTab *tt, uintmax_t n)
|
||||||
{
|
{
|
||||||
struct tab *t = (struct tab *) tt;
|
struct tab *t = (struct tab *) tt;
|
||||||
|
NSValue *v;
|
||||||
|
uiBin *page;
|
||||||
|
NSTabViewItem *i;
|
||||||
|
|
||||||
PUT_CODE_HERE;
|
v = (NSValue *) [t->pages objectAtIndex:n];
|
||||||
|
page = (uiBin *) [v pointerValue];
|
||||||
|
[t->pages removeObjectAtIndex:n];
|
||||||
|
[t->margined removeObjectAtIndex:n];
|
||||||
|
|
||||||
|
// make sure the children of the tab aren't destroyed
|
||||||
|
uiBinSetMainControl(page, NULL);
|
||||||
|
|
||||||
|
// remove the bin from the tab view
|
||||||
|
// this serves the purpose of uiBinRemoveOSParent()
|
||||||
|
i = [t->tabview tabViewItemAtIndex:n];
|
||||||
|
[t->tabview removeTabViewItem:i];
|
||||||
|
|
||||||
|
// then destroy the bin
|
||||||
|
uiControlDestroy(uiControl(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
static uintmax_t tabNumPages(uiTab *tt)
|
static uintmax_t tabNumPages(uiTab *tt)
|
||||||
{
|
{
|
||||||
struct tab *t = (struct tab *) tt;
|
struct tab *t = (struct tab *) tt;
|
||||||
|
|
||||||
return PUT_CODE_HERE;
|
return [t->pages count];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tabMargined(uiTab *tt, uintmax_t n)
|
static int tabMargined(uiTab *tt, uintmax_t n)
|
||||||
{
|
{
|
||||||
struct tab *t = (struct tab *) tt;
|
struct tab *t = (struct tab *) tt;
|
||||||
|
NSNumber *v;
|
||||||
|
|
||||||
return PUT_CODE_HERE;
|
v = (NSNumber *) [t->margined objectAtIndex:n];
|
||||||
|
return [v intValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These are based on measurements from Interface Builder.
|
||||||
|
// These seem to be based on Auto Layout constants, but I don't see an API that exposes these...
|
||||||
|
#define tabLeftMargin 17
|
||||||
|
#define tabTopMargin 3
|
||||||
|
#define tabRightMargin 17
|
||||||
|
#define tabBottomMargin 17
|
||||||
|
|
||||||
|
// notes:
|
||||||
|
// top margin of a tab to its parent should be 12, not 20
|
||||||
|
// our system doesn't allow this...
|
||||||
|
|
||||||
static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
|
static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
|
||||||
{
|
{
|
||||||
struct tab *t = (struct tab *) tt;
|
struct tab *t = (struct tab *) tt;
|
||||||
|
NSNumber *v;
|
||||||
|
NSValue *pagev;
|
||||||
|
uiBin *page;
|
||||||
|
|
||||||
PUT_CODE_HERE;
|
v = [NSNumber numberWithInt:margined];
|
||||||
|
[t->margined replaceObjectAtIndex:n withObject:v];
|
||||||
|
pagev = (NSValue *) [t->pages objectAtIndex:n];
|
||||||
|
page = (uiBin *) [pagev pointerValue];
|
||||||
|
if ([v intValue])
|
||||||
|
uiBinSetMargins(page, tabLeftMargin, tabTopMargin, tabRightMargin, tabBottomMargin);
|
||||||
|
else
|
||||||
|
uiBinSetMargins(page, 0, 0, 0, 0);
|
||||||
|
uiContainerUpdate(uiContainer(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
uiTab *uiNewTab(void)
|
uiTab *uiNewTab(void)
|
||||||
|
@ -63,9 +179,18 @@ uiTab *uiNewTab(void)
|
||||||
|
|
||||||
t = (struct tab *) MAKE_CONTROL_INSTANCE(uiTypeTab());
|
t = (struct tab *) MAKE_CONTROL_INSTANCE(uiTypeTab());
|
||||||
|
|
||||||
PUT_CODE_HERE;
|
t->tabview = [[NSTabView alloc] initWithFrame:NSZeroRect];
|
||||||
|
// also good for NSTabView (same selector and everything)
|
||||||
|
uiDarwinMakeSingleViewControl(uiControl(t), t->tabview, YES);
|
||||||
|
|
||||||
|
t->pages = [NSMutableArray new];
|
||||||
|
t->margined = [NSMutableArray new];
|
||||||
|
|
||||||
uiControl(t)->Handle = tabHandle;
|
uiControl(t)->Handle = tabHandle;
|
||||||
|
uiControl(t)->PreferredSize = tabPreferredSize;
|
||||||
|
t->baseCommitDestroy = uiControl(t)->CommitDestroy;
|
||||||
|
uiControl(t)->CommitDestroy = tabCommitDestroy;
|
||||||
|
uiControl(t)->ContainerUpdate = tabContainerUpdate;
|
||||||
|
|
||||||
uiTab(t)->Append = tabAppend;
|
uiTab(t)->Append = tabAppend;
|
||||||
uiTab(t)->InsertAt = tabInsertAt;
|
uiTab(t)->InsertAt = tabInsertAt;
|
||||||
|
|
Loading…
Reference in New Issue