2015-08-14 21:50:20 -05:00
|
|
|
// 14 august 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
|
|
|
struct uiGroup {
|
|
|
|
uiDarwinControl c;
|
2016-05-12 00:31:47 -05:00
|
|
|
NSBox *box;
|
2015-08-14 21:50:20 -05:00
|
|
|
uiControl *child;
|
2016-05-13 12:28:20 -05:00
|
|
|
NSLayoutPriority oldHorzHuggingPri;
|
|
|
|
NSLayoutPriority oldVertHuggingPri;
|
2015-08-14 21:50:20 -05:00
|
|
|
int margined;
|
2018-05-05 19:15:32 -05:00
|
|
|
uiprivSingleChildConstraints constraints;
|
2016-05-12 11:26:43 -05:00
|
|
|
NSLayoutPriority horzHuggingPri;
|
|
|
|
NSLayoutPriority vertHuggingPri;
|
2015-08-14 21:50:20 -05:00
|
|
|
};
|
|
|
|
|
2016-05-11 17:28:42 -05:00
|
|
|
static void removeConstraints(uiGroup *g)
|
|
|
|
{
|
2016-05-12 11:34:35 -05:00
|
|
|
// set to contentView instead of to the box itself, otherwise we get clipping underneath the label
|
2018-05-05 19:15:32 -05:00
|
|
|
uiprivSingleChildConstraintsRemove(&(g->constraints), [g->box contentView]);
|
2016-05-11 17:28:42 -05:00
|
|
|
}
|
|
|
|
|
2016-04-25 11:42:43 -05:00
|
|
|
static void uiGroupDestroy(uiControl *c)
|
2015-08-17 16:27:27 -05:00
|
|
|
{
|
2016-04-25 11:42:43 -05:00
|
|
|
uiGroup *g = uiGroup(c);
|
|
|
|
|
2016-05-11 17:28:42 -05:00
|
|
|
removeConstraints(g);
|
2015-08-17 16:27:27 -05:00
|
|
|
if (g->child != NULL) {
|
|
|
|
uiControlSetParent(g->child, NULL);
|
2016-05-11 23:43:52 -05:00
|
|
|
uiDarwinControlSetSuperview(uiDarwinControl(g->child), nil);
|
2015-08-17 16:27:27 -05:00
|
|
|
uiControlDestroy(g->child);
|
|
|
|
}
|
2016-04-25 11:42:43 -05:00
|
|
|
[g->box release];
|
|
|
|
uiFreeControl(uiControl(g));
|
2015-08-17 16:27:27 -05:00
|
|
|
}
|
|
|
|
|
2016-04-25 11:42:43 -05:00
|
|
|
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)
|
|
|
|
|
2016-04-25 16:52:16 -05:00
|
|
|
static void uiGroupSyncEnableState(uiDarwinControl *c, int enabled)
|
2015-08-21 00:09:07 -05:00
|
|
|
{
|
|
|
|
uiGroup *g = uiGroup(c);
|
|
|
|
|
2016-04-25 17:07:29 -05:00
|
|
|
if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(g), enabled))
|
|
|
|
return;
|
2015-08-21 00:09:07 -05:00
|
|
|
if (g->child != NULL)
|
2016-04-25 16:52:16 -05:00
|
|
|
uiDarwinControlSyncEnableState(uiDarwinControl(g->child), enabled);
|
2015-08-21 00:09:07 -05:00
|
|
|
}
|
2015-08-14 21:50:20 -05:00
|
|
|
|
2016-04-25 11:42:43 -05:00
|
|
|
uiDarwinControlDefaultSetSuperview(uiGroup, box)
|
2016-05-07 00:34:33 -05:00
|
|
|
|
2016-04-25 12:38:17 -05:00
|
|
|
static void groupRelayout(uiGroup *g)
|
2015-08-18 19:15:09 -05:00
|
|
|
{
|
|
|
|
NSView *childView;
|
|
|
|
|
2016-05-11 17:28:42 -05:00
|
|
|
removeConstraints(g);
|
2015-08-18 19:15:09 -05:00
|
|
|
if (g->child == NULL)
|
|
|
|
return;
|
|
|
|
childView = (NSView *) uiControlHandle(g->child);
|
2018-05-05 19:15:32 -05:00
|
|
|
uiprivSingleChildConstraintsEstablish(&(g->constraints),
|
2016-05-12 11:34:35 -05:00
|
|
|
[g->box contentView], childView,
|
2016-05-11 17:28:42 -05:00
|
|
|
uiDarwinControlHugsTrailingEdge(uiDarwinControl(g->child)),
|
|
|
|
uiDarwinControlHugsBottom(uiDarwinControl(g->child)),
|
|
|
|
g->margined,
|
|
|
|
@"uiGroup");
|
2016-05-12 19:18:22 -05:00
|
|
|
// needed for some very rare drawing errors...
|
2018-05-05 19:15:32 -05:00
|
|
|
uiprivJiggleViewLayout(g->box);
|
2016-05-11 17:28:42 -05:00
|
|
|
}
|
|
|
|
|
2016-05-12 11:26:43 -05:00
|
|
|
// TODO rename these since I'm starting to get confused by what they mean by hugging
|
|
|
|
BOOL uiGroupHugsTrailingEdge(uiDarwinControl *c)
|
|
|
|
{
|
|
|
|
uiGroup *g = uiGroup(c);
|
|
|
|
|
|
|
|
// TODO make a function?
|
|
|
|
return g->horzHuggingPri < NSLayoutPriorityWindowSizeStayPut;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL uiGroupHugsBottom(uiDarwinControl *c)
|
|
|
|
{
|
|
|
|
uiGroup *g = uiGroup(c);
|
|
|
|
|
|
|
|
return g->vertHuggingPri < NSLayoutPriorityWindowSizeStayPut;
|
|
|
|
}
|
2016-05-11 17:28:42 -05:00
|
|
|
|
2016-05-11 23:43:52 -05:00
|
|
|
static void uiGroupChildEdgeHuggingChanged(uiDarwinControl *c)
|
2016-05-11 17:28:42 -05:00
|
|
|
{
|
|
|
|
uiGroup *g = uiGroup(c);
|
|
|
|
|
|
|
|
groupRelayout(g);
|
2015-08-18 19:15:09 -05:00
|
|
|
}
|
|
|
|
|
2016-05-12 11:26:43 -05:00
|
|
|
static NSLayoutPriority uiGroupHuggingPriority(uiDarwinControl *c, NSLayoutConstraintOrientation orientation)
|
|
|
|
{
|
|
|
|
uiGroup *g = uiGroup(c);
|
|
|
|
|
|
|
|
if (orientation == NSLayoutConstraintOrientationHorizontal)
|
|
|
|
return g->horzHuggingPri;
|
|
|
|
return g->vertHuggingPri;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uiGroupSetHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation)
|
|
|
|
{
|
|
|
|
uiGroup *g = uiGroup(c);
|
|
|
|
|
|
|
|
if (orientation == NSLayoutConstraintOrientationHorizontal)
|
|
|
|
g->horzHuggingPri = priority;
|
|
|
|
else
|
|
|
|
g->vertHuggingPri = priority;
|
|
|
|
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(g));
|
|
|
|
}
|
|
|
|
|
2016-06-14 09:37:19 -05:00
|
|
|
static void uiGroupChildVisibilityChanged(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
|
|
|
{
|
2018-05-03 21:38:21 -05:00
|
|
|
[g->box setTitle:uiprivToNSString(title)];
|
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) {
|
2016-05-11 17:28:42 -05:00
|
|
|
removeConstraints(g);
|
2016-05-13 12:28:20 -05:00
|
|
|
uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), g->oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal);
|
|
|
|
uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), g->oldVertHuggingPri, NSLayoutConstraintOrientationVertical);
|
2015-08-14 21:50:20 -05:00
|
|
|
uiControlSetParent(g->child, NULL);
|
2016-05-13 12:28:20 -05:00
|
|
|
uiDarwinControlSetSuperview(uiDarwinControl(g->child), nil);
|
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));
|
2016-05-01 11:00:10 -05:00
|
|
|
uiDarwinControlSetSuperview(uiDarwinControl(g->child), [g->box contentView]);
|
2016-04-25 16:52:16 -05:00
|
|
|
uiDarwinControlSyncEnableState(uiDarwinControl(g->child), uiControlEnabledToUser(uiControl(g)));
|
2016-05-13 12:28:20 -05:00
|
|
|
// don't hug, just in case we're a stretchy group
|
|
|
|
g->oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(g->child), NSLayoutConstraintOrientationHorizontal);
|
|
|
|
g->oldVertHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(g->child), NSLayoutConstraintOrientationVertical);
|
|
|
|
uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationHorizontal);
|
|
|
|
uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationVertical);
|
2015-08-14 21:50:20 -05:00
|
|
|
}
|
2016-04-25 11:42:43 -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;
|
2018-05-05 19:15:32 -05:00
|
|
|
uiprivSingleChildConstraintsSetMargined(&(g->constraints), g->margined);
|
2015-08-14 21:50:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiGroup *uiNewGroup(const char *title)
|
|
|
|
{
|
|
|
|
uiGroup *g;
|
|
|
|
|
2016-04-25 11:42:43 -05:00
|
|
|
uiDarwinNewControl(uiGroup, g);
|
2015-08-14 21:50:20 -05:00
|
|
|
|
2016-05-12 00:31:47 -05:00
|
|
|
g->box = [[NSBox alloc] initWithFrame:NSZeroRect];
|
2018-05-03 21:38:21 -05:00
|
|
|
[g->box setTitle:uiprivToNSString(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
|
|
|
|
2016-05-12 11:26:43 -05:00
|
|
|
// default to low hugging to not hug edges
|
|
|
|
g->horzHuggingPri = NSLayoutPriorityDefaultLow;
|
|
|
|
g->vertHuggingPri = NSLayoutPriorityDefaultLow;
|
|
|
|
|
2015-08-14 21:50:20 -05:00
|
|
|
return g;
|
|
|
|
}
|