libui/darwin/group.m

145 lines
3.6 KiB
Mathematica
Raw Normal View History

2015-08-14 21:50:20 -05:00
// 14 august 2015
#import "uipriv_darwin.h"
// TODO test empty groups
2015-08-14 21:50:20 -05:00
struct uiGroup {
uiDarwinControl c;
libuiIntrinsicBox *box;
2015-08-14 21:50:20 -05:00
uiControl *child;
int margined;
struct singleChildConstraints constraints;
2015-08-14 21:50:20 -05:00
};
static void removeConstraints(uiGroup *g)
{
singleChildConstraintsRemove(&(g->constraints), g->box);
}
static void uiGroupDestroy(uiControl *c)
{
uiGroup *g = uiGroup(c);
removeConstraints(g);
if (g->child != NULL) {
uiControlSetParent(g->child, NULL);
uiDarwinControlSetSuperview(uiDarwinControl(g->child), nil);
uiControlDestroy(g->child);
}
[g->box release];
uiFreeControl(uiControl(g));
}
uiDarwinControlDefaultHandle(uiGroup, box)
uiDarwinControlDefaultParent(uiGroup, box)
uiDarwinControlDefaultSetParent(uiGroup, box)
uiDarwinControlDefaultToplevel(uiGroup, box)
uiDarwinControlDefaultVisible(uiGroup, box)
uiDarwinControlDefaultShow(uiGroup, box)
uiDarwinControlDefaultHide(uiGroup, box)
uiDarwinControlDefaultEnabled(uiGroup, box)
uiDarwinControlDefaultEnable(uiGroup, box)
uiDarwinControlDefaultDisable(uiGroup, box)
static void uiGroupSyncEnableState(uiDarwinControl *c, int enabled)
{
uiGroup *g = uiGroup(c);
if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(g), enabled))
return;
if (g->child != NULL)
uiDarwinControlSyncEnableState(uiDarwinControl(g->child), enabled);
}
2015-08-14 21:50:20 -05:00
uiDarwinControlDefaultSetSuperview(uiGroup, box)
2016-04-25 12:38:17 -05:00
static void groupRelayout(uiGroup *g)
{
NSView *childView;
removeConstraints(g);
if (g->child == NULL)
return;
childView = (NSView *) uiControlHandle(g->child);
singleChildConstraintsEstablish(&(g->constraints),
g->box, childView,
uiDarwinControlHugsTrailingEdge(uiDarwinControl(g->child)),
uiDarwinControlHugsBottom(uiDarwinControl(g->child)),
g->margined,
@"uiGroup");
}
uiDarwinControlDefaultHugsTrailingEdge(uiGroup, box)
uiDarwinControlDefaultHugsBottom(uiGroup, box)
static void uiGroupChildEdgeHuggingChanged(uiDarwinControl *c)
{
uiGroup *g = uiGroup(c);
groupRelayout(g);
}
2015-08-14 21:50:20 -05:00
char *uiGroupTitle(uiGroup *g)
{
2015-08-22 10:17:13 -05:00
return uiDarwinNSStringToText([g->box title]);
2015-08-14 21:50:20 -05:00
}
2015-08-17 17:30:04 -05:00
void uiGroupSetTitle(uiGroup *g, const char *title)
2015-08-14 21:50:20 -05:00
{
2015-08-17 17:30:04 -05:00
[g->box setTitle:toNSString(title)];
2015-08-14 21:50:20 -05:00
// changing the text might necessitate a change in the groupbox's size
uiDarwinControlTriggerRelayout(uiDarwinControl(g));
2015-08-14 21:50:20 -05:00
}
void uiGroupSetChild(uiGroup *g, uiControl *child)
{
NSView *childView;
if (g->child != NULL) {
removeConstraints(g);
childView = (NSView *) uiControlHandle(g->child);
[childView removeFromSuperview];
2015-08-14 21:50:20 -05:00
uiControlSetParent(g->child, NULL);
}
2015-08-14 21:50:20 -05:00
g->child = child;
[g->box libui_setHasChild:(g->child != NULL)];
2015-08-14 21:50:20 -05:00
if (g->child != NULL) {
childView = (NSView *) uiControlHandle(g->child);
2015-08-14 21:50:20 -05:00
uiControlSetParent(g->child, uiControl(g));
uiDarwinControlSetSuperview(uiDarwinControl(g->child), [g->box contentView]);
uiDarwinControlSyncEnableState(uiDarwinControl(g->child), uiControlEnabledToUser(uiControl(g)));
2015-08-14 21:50:20 -05:00
}
groupRelayout(g);
2015-08-14 21:50:20 -05:00
}
int uiGroupMargined(uiGroup *g)
{
return g->margined;
}
void uiGroupSetMargined(uiGroup *g, int margined)
{
g->margined = margined;
singleChildConstraintsSetMargined(&(w->constraints), w->margined);
// TODO issue a relayout command?
2015-08-14 21:50:20 -05:00
}
uiGroup *uiNewGroup(const char *title)
{
uiGroup *g;
uiDarwinNewControl(uiGroup, g);
2015-08-14 21:50:20 -05:00
g->box = [[libuiIntrinsicBox alloc] initWithFrame:NSZeroRect];
2015-08-17 17:30:04 -05:00
[g->box setTitle:toNSString(title)];
2015-08-14 21:50:20 -05:00
[g->box setBoxType:NSBoxPrimary];
2015-08-17 17:30:04 -05:00
[g->box setBorderType:NSLineBorder];
2015-08-14 21:50:20 -05:00
[g->box setTransparent:NO];
[g->box setTitlePosition:NSAtTop];
2015-08-17 17:30:04 -05:00
// we can't use uiDarwinSetControlFont() because the selector is different
[g->box setTitleFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
[g->box libui_setHasChild:NO];
2015-08-14 21:50:20 -05:00
return g;
}