-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCustomCell.m
93 lines (76 loc) · 2.98 KB
/
CustomCell.m
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
91
92
93
//
// CustomCell.m
// CustomOutlineView
//
// Created by Steven Streeting on 07/08/2010.
// Copyright 2010 Torus Knot Software Ltd.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following condition:
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "CustomCell.h"
#import "CustomCellController.h"
#import "OutlineEntry.h"
@implementation CustomCell
-(id)init
{
if (self = [super initTextCell:@""])
{
}
return self;
}
-(void)setController:(CustomCellController*)ctrl
{
controller = ctrl;
}
#pragma mark -
#pragma mark Drawing
- (NSRect)titleRectForBounds:(NSRect)cellRect inView:(NSView*)controlView
{
// Returns the proper bound for the cell's title while being edited
NSRect textFrame;
textFrame = [controller.detailTitle frame];
cellRect.origin.x += textFrame.origin.x;
cellRect.size.height = textFrame.size.height;
return cellRect;
}
- (void)editWithFrame:(NSRect)aRect inView:(NSView*)controlView editor:(NSText*)textObj delegate:(id)anObject event:(NSEvent*)theEvent
{
isEditing = YES;
NSRect textFrame = [self titleRectForBounds:aRect inView:controlView];
[super editWithFrame:textFrame inView:controlView editor:textObj delegate:anObject event:theEvent];
}
- (void)selectWithFrame:(NSRect)aRect inView:(NSView*)controlView editor:(NSText*)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength
{
isEditing = YES;
NSRect textFrame = [self titleRectForBounds:aRect inView:controlView];
[super selectWithFrame:textFrame inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
}
- (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView *)controlView
{
// Override this to allow editing of the name by clicking anywhere in the box
return NSCellHitContentArea | NSCellHitEditableTextArea | NSCellHitEditableTextArea;
}
-(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
{
// A single cell instance is used to render every row, so we can't store the
// custom view here
[controller showViews:controlView frame:cellFrame highlight:[self isHighlighted] && !isEditing];
}
-(void)endEditing:(NSText *)textObj
{
isEditing = NO;
[super endEditing:textObj];
}
@end