From 8868ad3b53af233c5d28b4f530a4f4d2c14a0dc2 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 1 Aug 2015 21:41:36 -0400 Subject: [PATCH] Stored parents in the various tControls. This is neccessary for making tRelayout on all controls. --- redo/osxaltest/box.m | 9 ++++++--- redo/osxaltest/button.m | 6 +++++- redo/osxaltest/osxaltest.h | 2 +- redo/osxaltest/spinbox.m | 6 +++++- redo/osxaltest/window.m | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/redo/osxaltest/box.m b/redo/osxaltest/box.m index baa1f1fe..77a6694b 100644 --- a/redo/osxaltest/box.m +++ b/redo/osxaltest/box.m @@ -5,6 +5,7 @@ NSMutableArray *children; NSView *sv; BOOL vertical; + id parent; } - (id)tInitVertical:(BOOL)vert @@ -14,6 +15,7 @@ self->children = [NSMutableArray new]; self->sv = nil; self->vertical = vert; + self->parent = nil; } return self; } @@ -21,19 +23,20 @@ - (void)tAddControl:(id)c stretchy:(BOOL)s { if (self->sv != nil) - [c tAddToView:self->sv]; + [c tSetParent:self->parent addToView:self->sv]; [self->children addObject:c]; // TODO mark as needing relayout } -- (void)tAddToView:(NSView *)v +- (void)tSetParent:(id)p addToView:(NSView *)v { + self->parent = p; self->sv = v; [self->children enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { id c; c = (id) obj; - [c tAddToView:self->sv]; + [c tSetParent:self->parent addToView:self->sv]; }]; } diff --git a/redo/osxaltest/button.m b/redo/osxaltest/button.m index ed54996c..1229cbd8 100644 --- a/redo/osxaltest/button.m +++ b/redo/osxaltest/button.m @@ -3,6 +3,7 @@ @implementation tButton { NSButton *b; + id parent; } - (id)tInitWithText:(NSString *)text @@ -16,12 +17,15 @@ [self->b setBezelStyle:NSRoundedBezelStyle]; [self->b setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]]; [self->b setTranslatesAutoresizingMaskIntoConstraints:NO]; + + self->parent = nil; } return self; } -- (void)tAddToView:(NSView *)v +- (void)tSetParent:(id)p addToView:(NSView *)v { + self->parent = p; [v addSubview:self->b]; } diff --git a/redo/osxaltest/osxaltest.h b/redo/osxaltest/osxaltest.h index 1224f8cc..1253cd1c 100644 --- a/redo/osxaltest/osxaltest.h +++ b/redo/osxaltest/osxaltest.h @@ -4,7 +4,7 @@ @protocol tControl @required -- (void)tAddToView:(NSView *)v; +- (void)tSetParent:(id)p addToView:(NSView *)v; - (void)tFillAutoLayoutHorz:(NSMutableArray *)horz vert:(NSMutableArray *)vert extra:(NSMutableArray *)extra diff --git a/redo/osxaltest/spinbox.m b/redo/osxaltest/spinbox.m index 64a4f934..3b3ea54e 100644 --- a/redo/osxaltest/spinbox.m +++ b/redo/osxaltest/spinbox.m @@ -4,6 +4,7 @@ @implementation tSpinbox { NSTextField *t; NSStepper *s; + id parent; } - (id)init @@ -25,12 +26,15 @@ [self->s setValueWraps:NO]; [self->s setAutorepeat:YES]; [self->s setTranslatesAutoresizingMaskIntoConstraints:NO]; + + self->parent = nil; } return self; } -- (void)tAddToView:(NSView *)v +- (void)tSetParent:(id)p addToView:(NSView *)v { + self->parent = p; [v addSubview:self->t]; [v addSubview:self->s]; } diff --git a/redo/osxaltest/window.m b/redo/osxaltest/window.m index 942e3053..66fa60a1 100644 --- a/redo/osxaltest/window.m +++ b/redo/osxaltest/window.m @@ -23,7 +23,7 @@ - (void)tSetControl:(id)cc { self->c = cc; - [self->c tAddToView:[self->w contentView]]; + [self->c tSetParent:self addToView:[self->w contentView]]; [self tRelayout]; }