2015-08-14 21:50:20 -05:00
|
|
|
// 14 august 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
|
|
|
struct uiGroup {
|
|
|
|
uiDarwinControl c;
|
|
|
|
NSBox *box;
|
|
|
|
uiControl *child;
|
|
|
|
int margined;
|
|
|
|
};
|
|
|
|
|
2015-08-17 16:27:27 -05:00
|
|
|
static void onDestroy(uiGroup *);
|
|
|
|
|
2015-08-14 21:50:20 -05:00
|
|
|
uiDarwinDefineControlWithOnDestroy(
|
|
|
|
uiGroup, // type name
|
|
|
|
uiGroupType, // type function
|
|
|
|
box, // handle
|
2015-08-17 16:27:27 -05:00
|
|
|
onDestroy(this); // on destroy
|
2015-08-14 21:50:20 -05:00
|
|
|
)
|
|
|
|
|
2015-08-17 16:27:27 -05:00
|
|
|
static void onDestroy(uiGroup *g)
|
|
|
|
{
|
|
|
|
if (g->child != NULL) {
|
|
|
|
uiControlSetParent(g->child, NULL);
|
|
|
|
uiControlDestroy(g->child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-21 00:09:07 -05:00
|
|
|
static void groupContainerUpdateState(uiControl *c)
|
|
|
|
{
|
|
|
|
uiGroup *g = uiGroup(c);
|
|
|
|
|
|
|
|
if (g->child != NULL)
|
|
|
|
controlUpdateState(g->child);
|
|
|
|
}
|
2015-08-14 21:50:20 -05:00
|
|
|
|
2015-08-18 19:15:09 -05:00
|
|
|
static void groupRelayout(uiDarwinControl *c)
|
|
|
|
{
|
2015-08-18 20:23:48 -05:00
|
|
|
uiGroup *g = uiGroup(c);
|
2015-08-18 19:15:09 -05:00
|
|
|
uiDarwinControl *cc;
|
|
|
|
NSView *childView;
|
|
|
|
|
|
|
|
if (g->child == NULL)
|
|
|
|
return;
|
2015-08-22 20:29:22 -05:00
|
|
|
[g->box removeConstraints:[g->box constraints]];
|
2015-08-18 19:15:09 -05:00
|
|
|
cc = uiDarwinControl(g->child);
|
|
|
|
childView = (NSView *) uiControlHandle(g->child);
|
|
|
|
// first relayout the child
|
|
|
|
(*(cc->Relayout))(cc);
|
|
|
|
// now relayout ourselves
|
2015-08-20 16:04:23 -05:00
|
|
|
// see below on using the content view
|
|
|
|
layoutSingleView(g->box, childView, g->margined);
|
|
|
|
// we need to explicitly tell the NSBox to recompute its own size based on the new content layout
|
|
|
|
[g->box sizeToFit];
|
2015-08-18 19:15:09 -05:00
|
|
|
}
|
|
|
|
|
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
|
2015-08-18 19:15:09 -05:00
|
|
|
uiDarwinControlTriggerRelayout(uiDarwinControl(g));
|
2015-08-14 21:50:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiGroupSetChild(uiGroup *g, uiControl *child)
|
|
|
|
{
|
2015-08-17 16:27:27 -05:00
|
|
|
NSView *childView;
|
|
|
|
|
|
|
|
if (g->child != NULL) {
|
|
|
|
childView = (NSView *) uiControlHandle(g->child);
|
|
|
|
[childView removeFromSuperview];
|
2015-08-14 21:50:20 -05:00
|
|
|
uiControlSetParent(g->child, NULL);
|
2015-08-17 16:27:27 -05:00
|
|
|
}
|
2015-08-14 21:50:20 -05:00
|
|
|
g->child = child;
|
|
|
|
if (g->child != NULL) {
|
2015-08-17 16:27:27 -05:00
|
|
|
childView = (NSView *) uiControlHandle(g->child);
|
2015-08-14 21:50:20 -05:00
|
|
|
uiControlSetParent(g->child, uiControl(g));
|
2015-08-20 16:04:23 -05:00
|
|
|
// we have to add controls to the box itself NOT the content view
|
|
|
|
// otherwise, things get really glitchy
|
|
|
|
// we also need to call -sizeToFit, but we'll do that in the relayout that's triggered below (see above)
|
|
|
|
[g->box addSubview:childView];
|
2015-08-18 19:15:09 -05:00
|
|
|
uiDarwinControlTriggerRelayout(uiDarwinControl(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;
|
2015-08-18 19:15:09 -05:00
|
|
|
if (g->child != NULL)
|
|
|
|
uiDarwinControlTriggerRelayout(uiDarwinControl(g));
|
2015-08-14 21:50:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiGroup *uiNewGroup(const char *title)
|
|
|
|
{
|
|
|
|
uiGroup *g;
|
|
|
|
|
|
|
|
g = (uiGroup *) uiNewControl(uiGroupType());
|
|
|
|
|
|
|
|
g->box = [[NSBox 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]]];
|
2015-08-14 21:50:20 -05:00
|
|
|
|
|
|
|
uiDarwinFinishNewControl(g, uiGroup);
|
2015-08-21 00:09:07 -05:00
|
|
|
uiControl(g)->ContainerUpdateState = groupContainerUpdateState;
|
2015-08-18 19:15:09 -05:00
|
|
|
uiDarwinControl(g)->Relayout = groupRelayout;
|
2015-08-14 21:50:20 -05:00
|
|
|
|
|
|
|
return g;
|
|
|
|
}
|