-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeHead.m
More file actions
executable file
·90 lines (75 loc) · 2.08 KB
/
Copy pathTreeHead.m
File metadata and controls
executable file
·90 lines (75 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// ##############################################################
// TreeHead.m
// Magic Number Machine
//
// Created by Matt Gallagher on Sun May 25 2003.
// Copyright (c) 2003 Matt Gallagher. All rights reserved.
// ##############################################################
#import "TreeHead.h"
#import "DataManager.h"
//
// About TreeHead
//
// The root node of the expression tree must always be a TreeHead. Implements some
// default behaviour for a node which never has a parent.
//
@implementation TreeHead
//
// treeHeadWithValue
//
// This is the constructor for this class. Links the class to the manager, sets the starting
// point for the inputPoint.
//
+ (Expression*)treeHeadWithValue:(BigCFloat*)newValue andManager:(DataManager*)newManager
{
Expression *newExpression;
// Create the expression
newExpression = [[TreeHead alloc] initWithParent:nil andManager:newManager];
// Link in the manager
[newManager setCurrentExpression:newExpression];
// Set the inputPoint
[newExpression inputPoint];
// Either create a value (and have it be the initial input point) or leave child nil and
// become the input point ourselves
if (newValue != nil)
{
[newExpression replaceChild:nil withValue:newValue];
}
return newExpression;
}
//
// binaryOpPressed
//
// Always create a binary operation under this node
//
- (void)binaryOpPressed:(int)op
{
// Split the child into a binary operation.
[self replaceChild:child withBinOp:op];
}
//
// getCaretPoint
//
// If the head of the tree is the insertion point, then just return a point at the middle right
// of the bounds
//
- (NSPoint)getCaretPoint
{
NSPoint caretPoint;
NSAssert(isBoundsValid == YES, @"Display bounds requested before being received.\n");
caretPoint = displayBounds.origin;
caretPoint.x += displayBounds.size.width + 3.0;
caretPoint.y += displayBounds.size.height / 2.0;
return caretPoint;
}
//
// postOpPressed
//
// Always put the post op under this node.
//
- (void)postOpPressed:(int)op
{
// Create a postOp at the child node and set it as the input point
[self replaceChild:child withPostOp:op];
}
@end