//
//  MPDrawable.h
//  MathPad
//
//  Created by Kim Wittenburg on 07.08.14.
//  Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//

@import Cocoa;
#import "MPExpressionStorage.h"

#define MPNull [NSNull null]

@interface MPLayout : NSObject

#pragma mark Creation Methods
- (instancetype)init;
- (instancetype)initWithElementAtPath:(NSIndexPath *)path
                     inRootExpression:(MPExpression *)rootExpression
                               parent:(MPLayout *)parent;

#pragma mark Properties
- (NSFont *)font;
- (CGFloat)fontSize;
- (NSFont *)normalFont;
- (CGFloat)normalFontSize;
- (NSFont *)smallFont;
- (CGFloat)smallFontSize;

#pragma mark Cache Tree
@property (readonly, nonatomic, weak) MPLayout *parent;

#pragma mark Cache Methods
// Querying Caches
- (id)cachableObjectForIndex:(NSUInteger)index
                   generator:(id(^)())generator;

// Clearing Caches
- (void)clearCacheInRange:(NSRange)range
        replacementLength:(NSUInteger)replacementLength;
- (void)invalidate;

#pragma mark Calculation and Drawing Methods
- (CTLineRef)createLineForString:(NSString *)aString;

@property (nonatomic, getter = isFlipped) BOOL flipped;
@property (nonatomic) BOOL usesSmallSize;
- (NSRect)bounds;

- (NSRect)boundingRectForRangePath:(MPRangePath *)rangePath; /* if rangePath.length is 0 the returned rect will have a width of 0 */

- (void)drawAtPoint:(NSPoint)point;

@end

@interface MPLayout (MPSubclassImplement)
- (MPLayout *)childLayoutAtIndex:(NSUInteger)index; // To be implemented
- (NSRect)generateBounds; // To be implemented
- (NSRect)boundingRectForRange:(NSRange)range; // To be implemented, use rangePath instead, this one has wrong origin
- (NSPoint)offsetOfChildLayoutAtIndex:(NSUInteger)index;
- (NSIndexPath *)indexPathForMousePoint:(NSPoint)point;
- (void)draw; // To be implemented
@end