From 72abd9bc39fe80a629c952db1a784e395a243ccf Mon Sep 17 00:00:00 2001 From: Kim Wittenburg Date: Thu, 8 Jan 2015 21:58:15 +0100 Subject: [PATCH] Corrected MVC Implementation --- MathKit/MPExpressionStorage.h | 27 +++------------------------ MathKit/MPExpressionStorage.m | 10 ---------- MathKit/MPExpressionView.m | 6 +++--- MathKit/MPLayout.h | 17 ++++++++++++++++- MathKit/MPLayout.m | 12 ++++++++++++ 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/MathKit/MPExpressionStorage.h b/MathKit/MPExpressionStorage.h index 96b3407..3f0dc6f 100644 --- a/MathKit/MPExpressionStorage.h +++ b/MathKit/MPExpressionStorage.h @@ -21,38 +21,17 @@ /*! @class MPExpressionStorage - @abstract An expression storage manages the contents of an expression view - and notifies it when the underlying expression changes. + @abstract An expression storage manages the contents of an expression view. */ @interface MPExpressionStorage : MPExpression -/*! - @property expressionView - @abstract The receiver's expression view. - - @discussion The expression view is the view that displays the contents of an - expression storage. Normally you should not call the setter of - this property. It is automatically assigned when the @link - //apple_ref/occ/instp/MPExpressionView/expressionStorage@/link - property of the respective @link - //apple_ref/occ/cl/MPExpressionView@/link instance is set. - - When this property is set the receiver assumes that the - displaying expression view has changed (regardless of wether the - actual value of the property changed or not). It then adapts to - the properties of the new expression view and discards the - current root layout. - */ -@property (nonatomic, weak) MPExpressionView *expressionView; - - /*! @property rootLayout @abstract The receiver's root layout. @discussion The root layout is the root node of the layout tree that draws - the receiver's contents. For more information see the - documentation on the @link + the receiver's contents in an expression view. For more + information see the documentation on the @link //apple_ref/occ/cl/MPLayout@/link class. */ @property (nonatomic, strong) MPExpressionLayout *rootLayout; diff --git a/MathKit/MPExpressionStorage.m b/MathKit/MPExpressionStorage.m index d8a762f..d2995a9 100644 --- a/MathKit/MPExpressionStorage.m +++ b/MathKit/MPExpressionStorage.m @@ -37,14 +37,6 @@ } -- (void)setExpressionView:(MPExpressionView *)expressionView -{ - _expressionView = expressionView; - self.rootLayout = [[MPExpressionLayout alloc] initWithExpression:self parent:nil]; - self.rootLayout.flipped = expressionView.flipped; -} - - - (void)changedElementsInRangePath:(MPRangePath *)rangePath replacementLength:(NSUInteger)replacementLength { @@ -58,8 +50,6 @@ } [current clearCacheInRange:rangePath.rangeAtLastIndex replacementLength:replacementLength]; - [self.expressionView invalidateIntrinsicContentSize]; - self.expressionView.needsDisplay = YES; } @end diff --git a/MathKit/MPExpressionView.m b/MathKit/MPExpressionView.m index eb96e16..ff6e0b1 100644 --- a/MathKit/MPExpressionView.m +++ b/MathKit/MPExpressionView.m @@ -348,7 +348,7 @@ { // Setup the Expression Storage MPExpressionStorage *expressionStorage = [[MPExpressionStorage alloc] init]; - expressionStorage.expressionView = self; + expressionStorage.rootLayout.expressionView = self; _expressionStorage = expressionStorage; [self initializeButtons]; @@ -472,9 +472,9 @@ - (void)setExpressionStorage:(MPExpressionStorage *)expressionStorage { - _expressionStorage.expressionView = nil; + _expressionStorage.rootLayout.expressionView = nil; _expressionStorage = expressionStorage;; - _expressionStorage.expressionView = self; + _expressionStorage.rootLayout.expressionView = self; [self invalidateIntrinsicContentSize]; } diff --git a/MathKit/MPLayout.h b/MathKit/MPLayout.h index 085f1b8..b7605d2 100644 --- a/MathKit/MPLayout.h +++ b/MathKit/MPLayout.h @@ -86,7 +86,7 @@ -@class MPLayout, MPRangePath; +@class MPLayout, MPExpressionView, MPRangePath; /*! @@ -149,6 +149,21 @@ */ +/*! + @property expressionView + @abstract The receiver's expression view. + + @discussion The expression view is the view in which the receivin + MPLayout instance draws itself into. Normally you + should not call the setter of this property. It is automatically + assigned when the @link + //apple_ref/occ/instp/MPExpressionView/expressionStorage@/link + property of the respective @link + //apple_ref/occ/cl/MPExpressionView@/link instance is set. + */ +@property (nonatomic, weak) MPExpressionView *expressionView; + + /*! @method font @abstract Returns the receiver's context inferred font. diff --git a/MathKit/MPLayout.m b/MathKit/MPLayout.m index 980faa3..4b36cdf 100644 --- a/MathKit/MPLayout.m +++ b/MathKit/MPLayout.m @@ -8,6 +8,8 @@ #import "MPLayout.h" +#import "MPExpressionView.h" + #import "MPRangePath.h" #import "NSIndexPath+MPAdditions.h" @@ -54,6 +56,14 @@ #pragma mark Properties +- (void)setExpressionView:(MPExpressionView *)expressionView +{ + self.flipped = expressionView.flipped; + [_cache removeAllObjects]; + [self invalidate]; +} + + - (NSFont *)normalFontWithSize:(CGFloat)size { return [NSFont fontWithName:@"CMU Serif" @@ -135,6 +145,8 @@ [_cache replaceObjectsInRange:range withObjectsFromArray:placeholders]; [self invalidate]; + [self.expressionView invalidateIntrinsicContentSize]; + self.expressionView.needsDisplay = YES; }