2015-08-15 22:32:34 -05:00
|
|
|
// 15 august 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
2015-08-17 00:58:23 -05:00
|
|
|
// TODOs:
|
2016-05-07 09:47:59 -05:00
|
|
|
// - tab on page 2 is glitched initially and doesn't grow
|
|
|
|
// - page 3 doesn't work right; probably due to our shouldExpand logic being applied incorrectly
|
|
|
|
|
|
|
|
// TODOs to confirm
|
2015-08-23 22:10:17 -05:00
|
|
|
// - 10.8: if we switch to page 4, then switch back to page 1, check Spaced, and go back to page 4, some controls (progress bar, popup button) are clipped on the sides
|
2016-05-01 10:25:35 -05:00
|
|
|
|
2016-05-06 22:27:46 -05:00
|
|
|
@interface boxChild : NSObject
|
|
|
|
@property uiControl *c;
|
2016-05-06 19:34:02 -05:00
|
|
|
@property BOOL stretchy;
|
2016-05-11 15:46:42 -05:00
|
|
|
#if 0 /* TODO */
|
2016-05-08 10:29:09 -05:00
|
|
|
@property NSLayoutPriority oldHorzHuggingPri;
|
|
|
|
@property NSLayoutPriority oldVertHuggingPri;
|
2016-05-11 15:46:42 -05:00
|
|
|
#endif
|
2016-05-07 00:11:58 -05:00
|
|
|
- (NSView *)view;
|
2016-05-06 18:21:41 -05:00
|
|
|
@end
|
|
|
|
|
2016-05-06 22:27:46 -05:00
|
|
|
@interface boxView : NSView {
|
|
|
|
uiBox *b;
|
2016-05-07 00:11:58 -05:00
|
|
|
NSMutableArray *children;
|
2015-08-15 22:32:34 -05:00
|
|
|
BOOL vertical;
|
|
|
|
int padded;
|
2016-05-06 22:27:46 -05:00
|
|
|
|
2016-05-11 15:46:42 -05:00
|
|
|
#if 0 /* TODO */
|
2016-04-30 16:45:44 -05:00
|
|
|
NSLayoutAttribute primaryStart;
|
|
|
|
NSLayoutAttribute primaryEnd;
|
|
|
|
NSLayoutAttribute secondaryStart;
|
|
|
|
NSLayoutAttribute secondaryEnd;
|
|
|
|
NSLayoutAttribute primarySize;
|
2015-08-15 22:32:34 -05:00
|
|
|
NSLayoutConstraintOrientation primaryOrientation;
|
|
|
|
NSLayoutConstraintOrientation secondaryOrientation;
|
2016-05-11 15:46:42 -05:00
|
|
|
#endif
|
2016-05-06 22:27:46 -05:00
|
|
|
}
|
2016-05-07 00:25:32 -05:00
|
|
|
- (id)initWithVertical:(BOOL)vert b:(uiBox *)bb;
|
2016-05-07 00:11:58 -05:00
|
|
|
- (void)onDestroy;
|
|
|
|
- (void)removeOurConstraints;
|
2016-05-11 15:46:42 -05:00
|
|
|
- (void)syncEnableStates:(int)enabled;
|
|
|
|
- (CGFloat)paddingAmount;
|
2016-05-07 00:11:58 -05:00
|
|
|
- (void)append:(uiControl *)c stretchy:(int)stretchy;
|
|
|
|
- (void)delete:(uintmax_t)n;
|
|
|
|
- (int)isPadded;
|
2016-05-07 00:25:32 -05:00
|
|
|
- (void)setPadded:(int)p;
|
2016-05-06 22:27:46 -05:00
|
|
|
@end
|
2015-08-15 22:32:34 -05:00
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
struct uiBox {
|
|
|
|
uiDarwinControl c;
|
|
|
|
boxView *view;
|
|
|
|
};
|
|
|
|
|
|
|
|
@implementation boxChild
|
2015-08-15 22:32:34 -05:00
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
- (NSView *)view
|
|
|
|
{
|
|
|
|
return (NSView *) uiControlHandle(self.c);
|
2015-08-15 22:32:34 -05:00
|
|
|
}
|
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation boxView
|
|
|
|
|
2016-05-07 00:25:32 -05:00
|
|
|
- (id)initWithVertical:(BOOL)vert b:(uiBox *)bb
|
2015-08-15 22:32:34 -05:00
|
|
|
{
|
2016-05-07 00:11:58 -05:00
|
|
|
self = [super initWithFrame:NSZeroRect];
|
|
|
|
if (self != nil) {
|
2016-05-07 00:25:32 -05:00
|
|
|
// the weird names vert and bb are to shut the compiler up about shadowing because implicit this/self is stupid
|
|
|
|
self->b = bb;
|
|
|
|
self->vertical = vert;
|
2016-05-07 00:11:58 -05:00
|
|
|
self->children = [NSMutableArray new];
|
|
|
|
|
2016-05-11 15:46:42 -05:00
|
|
|
#if 0 /* TODO */
|
2016-05-07 00:11:58 -05:00
|
|
|
if (self->vertical) {
|
|
|
|
self->primaryStart = NSLayoutAttributeTop;
|
|
|
|
self->primaryEnd = NSLayoutAttributeBottom;
|
|
|
|
self->secondaryStart = NSLayoutAttributeLeading;
|
|
|
|
self->secondaryEnd = NSLayoutAttributeTrailing;
|
|
|
|
self->primarySize = NSLayoutAttributeHeight;
|
|
|
|
self->primaryOrientation = NSLayoutConstraintOrientationVertical;
|
|
|
|
self->secondaryOrientation = NSLayoutConstraintOrientationHorizontal;
|
|
|
|
} else {
|
|
|
|
self->primaryStart = NSLayoutAttributeLeading;
|
|
|
|
self->primaryEnd = NSLayoutAttributeTrailing;
|
|
|
|
self->secondaryStart = NSLayoutAttributeTop;
|
|
|
|
self->secondaryEnd = NSLayoutAttributeBottom;
|
|
|
|
self->primarySize = NSLayoutAttributeWidth;
|
|
|
|
self->primaryOrientation = NSLayoutConstraintOrientationHorizontal;
|
|
|
|
self->secondaryOrientation = NSLayoutConstraintOrientationVertical;
|
|
|
|
}
|
2016-05-11 15:46:42 -05:00
|
|
|
#endif
|
2015-08-15 22:32:34 -05:00
|
|
|
}
|
2016-05-07 00:11:58 -05:00
|
|
|
return self;
|
2015-08-15 22:32:34 -05:00
|
|
|
}
|
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
- (void)onDestroy
|
2015-08-21 00:09:07 -05:00
|
|
|
{
|
2016-05-07 00:11:58 -05:00
|
|
|
boxChild *bc;
|
2015-08-21 00:09:07 -05:00
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
[self removeOurConstraints];
|
2016-05-11 15:46:42 -05:00
|
|
|
|
|
|
|
for (bc in self->children) {
|
2016-05-07 00:11:58 -05:00
|
|
|
uiControlSetParent(bc.c, NULL);
|
|
|
|
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil);
|
|
|
|
uiControlDestroy(bc.c);
|
2015-08-21 00:09:07 -05:00
|
|
|
}
|
2016-05-07 00:11:58 -05:00
|
|
|
[self->children release];
|
2015-08-21 00:09:07 -05:00
|
|
|
}
|
2015-08-15 22:32:34 -05:00
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
- (void)removeOurConstraints
|
2015-08-15 22:32:34 -05:00
|
|
|
{
|
2016-05-11 15:46:42 -05:00
|
|
|
// TODO
|
2015-08-15 22:32:34 -05:00
|
|
|
}
|
|
|
|
|
2016-05-11 15:46:42 -05:00
|
|
|
- (void)syncEnableStates:(int)enabled
|
2015-08-15 22:32:34 -05:00
|
|
|
{
|
2016-05-11 15:46:42 -05:00
|
|
|
boxChild *bc;
|
2015-08-15 22:32:34 -05:00
|
|
|
|
2016-05-11 15:46:42 -05:00
|
|
|
for (bc in self->children)
|
|
|
|
uiDarwinControlSyncEnableState(uiDarwinControl(bc.c), enabled);
|
2016-05-07 00:11:58 -05:00
|
|
|
}
|
2016-05-06 18:21:41 -05:00
|
|
|
|
2016-05-11 15:46:42 -05:00
|
|
|
- (CGFloat)paddingAmount
|
2016-05-06 19:34:02 -05:00
|
|
|
{
|
2016-05-11 15:46:42 -05:00
|
|
|
if (!self->padded)
|
|
|
|
return 0.0;
|
|
|
|
return 8.0; // TODO named constant
|
2016-05-06 19:34:02 -05:00
|
|
|
}
|
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
// TODO something about spinbox hugging
|
2016-05-07 09:31:56 -05:00
|
|
|
- (void)updateConstraints
|
2015-08-15 22:32:34 -05:00
|
|
|
{
|
2016-05-07 09:31:56 -05:00
|
|
|
[super updateConstraints];
|
2015-08-17 18:11:35 -05:00
|
|
|
}
|
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
- (void)append:(uiControl *)c stretchy:(int)stretchy
|
2015-08-15 22:32:34 -05:00
|
|
|
{
|
2016-05-07 00:11:58 -05:00
|
|
|
boxChild *bc;
|
2016-05-08 10:29:09 -05:00
|
|
|
NSView *childView;
|
2015-08-15 22:32:34 -05:00
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
bc = [boxChild new];
|
|
|
|
bc.c = c;
|
|
|
|
bc.stretchy = stretchy;
|
2016-05-08 10:29:09 -05:00
|
|
|
childView = [bc view];
|
2016-05-11 15:46:42 -05:00
|
|
|
#if 0 /* TODO */
|
2016-05-08 10:29:09 -05:00
|
|
|
bc.oldHorzHuggingPri = horzHuggingPri(childView);
|
|
|
|
bc.oldVertHuggingPri = vertHuggingPri(childView);
|
2016-05-11 15:46:42 -05:00
|
|
|
#endif
|
2015-08-15 22:32:34 -05:00
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
uiControlSetParent(bc.c, uiControl(self->b));
|
|
|
|
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), self);
|
|
|
|
uiDarwinControlSyncEnableState(uiDarwinControl(bc.c), uiControlEnabledToUser(uiControl(self->b)));
|
2015-08-17 00:52:06 -05:00
|
|
|
|
2016-05-11 15:46:42 -05:00
|
|
|
#if 0 /*TODO */
|
2015-08-15 22:32:34 -05:00
|
|
|
// if a control is stretchy, it should not hug in the primary direction
|
|
|
|
// otherwise, it should *forcibly* hug
|
|
|
|
if (stretchy)
|
2016-05-08 10:29:09 -05:00
|
|
|
setHuggingPri(childView, NSLayoutPriorityDefaultLow, self->primaryOrientation);
|
2015-08-15 22:32:34 -05:00
|
|
|
else
|
|
|
|
// TODO will default high work?
|
2016-05-08 10:29:09 -05:00
|
|
|
setHuggingPri(childView, NSLayoutPriorityRequired, self->primaryOrientation);
|
2015-08-15 22:32:34 -05:00
|
|
|
// make sure controls don't hug their secondary direction so they fill the width of the view
|
2016-05-08 10:29:09 -05:00
|
|
|
setHuggingPri(childView, NSLayoutPriorityDefaultLow, self->secondaryOrientation);
|
2016-05-11 15:46:42 -05:00
|
|
|
#endif
|
2015-08-15 22:32:34 -05:00
|
|
|
|
2016-05-07 00:25:32 -05:00
|
|
|
[self->children addObject:bc];
|
2016-05-07 00:11:58 -05:00
|
|
|
[bc release]; // we don't need the initial reference now
|
|
|
|
|
2016-05-11 15:46:42 -05:00
|
|
|
[self removeOurConstraints];
|
2016-05-07 00:25:32 -05:00
|
|
|
[self setNeedsUpdateConstraints:YES];
|
2015-08-15 22:32:34 -05:00
|
|
|
}
|
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
- (void)delete:(uintmax_t)n
|
2015-08-15 22:32:34 -05:00
|
|
|
{
|
2016-05-07 00:11:58 -05:00
|
|
|
boxChild *bc;
|
2016-05-08 10:29:09 -05:00
|
|
|
NSView *removedView;
|
2015-08-15 22:32:34 -05:00
|
|
|
|
2016-05-11 15:46:42 -05:00
|
|
|
// TODO separate into a method?
|
|
|
|
bc = (boxChild *) [self->children objectAtIndex:n];
|
2016-05-08 10:29:09 -05:00
|
|
|
removedView = [bc view];
|
2016-05-07 00:11:58 -05:00
|
|
|
|
|
|
|
uiControlSetParent(bc.c, NULL);
|
|
|
|
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil);
|
|
|
|
|
2016-05-11 15:46:42 -05:00
|
|
|
#if 0 /* TODO */
|
2016-05-08 10:29:09 -05:00
|
|
|
setHorzHuggingPri(removedView, bc.oldHorzHuggingPri);
|
|
|
|
setVertHuggingPri(removedView, bc.oldVertHuggingPri);
|
2016-05-11 15:46:42 -05:00
|
|
|
#endif
|
2016-05-08 10:29:09 -05:00
|
|
|
|
2016-05-07 00:25:32 -05:00
|
|
|
[self->children removeObjectAtIndex:n];
|
2016-05-07 00:11:58 -05:00
|
|
|
|
2016-05-11 15:46:42 -05:00
|
|
|
[self removeOurConstraints];
|
2016-05-07 00:25:32 -05:00
|
|
|
[self setNeedsUpdateConstraints:YES];
|
2015-08-15 22:32:34 -05:00
|
|
|
}
|
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
- (int)isPadded
|
|
|
|
{
|
|
|
|
return self->padded;
|
|
|
|
}
|
|
|
|
|
2016-05-07 00:25:32 -05:00
|
|
|
- (void)setPadded:(int)p
|
2016-05-07 00:11:58 -05:00
|
|
|
{
|
|
|
|
CGFloat padding;
|
|
|
|
NSLayoutConstraint *c;
|
|
|
|
|
2016-05-07 00:25:32 -05:00
|
|
|
self->padded = p;
|
2016-05-11 15:46:42 -05:00
|
|
|
padding = [self paddingAmount];
|
|
|
|
#if 0 /* TODO */
|
|
|
|
for (c in self->inBetweens)
|
2016-05-07 00:11:58 -05:00
|
|
|
[c setConstant:padding];
|
2016-05-11 15:46:42 -05:00
|
|
|
#endif
|
2016-05-07 00:11:58 -05:00
|
|
|
// TODO call anything?
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
static void uiBoxDestroy(uiControl *c)
|
|
|
|
{
|
2016-05-07 00:25:32 -05:00
|
|
|
uiBox *b = uiBox(c);
|
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
[b->view onDestroy];
|
|
|
|
[b->view release];
|
|
|
|
uiFreeControl(uiControl(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
uiDarwinControlDefaultHandle(uiBox, view)
|
|
|
|
uiDarwinControlDefaultParent(uiBox, view)
|
|
|
|
uiDarwinControlDefaultSetParent(uiBox, view)
|
|
|
|
uiDarwinControlDefaultToplevel(uiBox, view)
|
|
|
|
uiDarwinControlDefaultVisible(uiBox, view)
|
|
|
|
uiDarwinControlDefaultShow(uiBox, view)
|
|
|
|
uiDarwinControlDefaultHide(uiBox, view)
|
|
|
|
uiDarwinControlDefaultEnabled(uiBox, view)
|
|
|
|
uiDarwinControlDefaultEnable(uiBox, view)
|
|
|
|
uiDarwinControlDefaultDisable(uiBox, view)
|
|
|
|
|
|
|
|
static void uiBoxSyncEnableState(uiDarwinControl *c, int enabled)
|
|
|
|
{
|
|
|
|
uiBox *b = uiBox(c);
|
|
|
|
|
|
|
|
if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(b), enabled))
|
|
|
|
return;
|
2016-05-11 15:46:42 -05:00
|
|
|
[b->view syncEnableStates:enabled];
|
2016-05-07 00:11:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiDarwinControlDefaultSetSuperview(uiBox, view)
|
|
|
|
|
|
|
|
void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)
|
|
|
|
{
|
|
|
|
[b->view append:c stretchy:stretchy];
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiBoxDelete(uiBox *b, uintmax_t n)
|
|
|
|
{
|
|
|
|
[b->view delete:n];
|
|
|
|
}
|
|
|
|
|
2015-08-15 22:32:34 -05:00
|
|
|
int uiBoxPadded(uiBox *b)
|
|
|
|
{
|
2016-05-07 00:11:58 -05:00
|
|
|
return [b->view isPadded];
|
2015-08-15 22:32:34 -05:00
|
|
|
}
|
|
|
|
|
2015-08-16 22:16:42 -05:00
|
|
|
void uiBoxSetPadded(uiBox *b, int padded)
|
2015-08-15 22:32:34 -05:00
|
|
|
{
|
2016-05-07 00:11:58 -05:00
|
|
|
[b->view setPadded:padded];
|
2015-08-15 22:32:34 -05:00
|
|
|
}
|
|
|
|
|
2015-08-16 22:08:00 -05:00
|
|
|
static uiBox *finishNewBox(BOOL vertical)
|
2015-08-15 22:32:34 -05:00
|
|
|
{
|
|
|
|
uiBox *b;
|
|
|
|
|
2016-04-25 11:35:01 -05:00
|
|
|
uiDarwinNewControl(uiBox, b);
|
2015-08-15 22:32:34 -05:00
|
|
|
|
2016-05-07 00:11:58 -05:00
|
|
|
b->view = [[boxView alloc] initWithVertical:vertical b:b];
|
2015-08-15 22:32:34 -05:00
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiBox *uiNewHorizontalBox(void)
|
|
|
|
{
|
|
|
|
return finishNewBox(NO);
|
|
|
|
}
|
|
|
|
|
|
|
|
uiBox *uiNewVerticalBox(void)
|
|
|
|
{
|
|
|
|
return finishNewBox(YES);
|
|
|
|
}
|