aboutsummaryrefslogtreecommitdiffstats
path: root/ScrollingTextView.m
blob: e3091a81e19b65603dc5160b76bfe4f0a686213f (plain)
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
#import "ScrollingTextView.h"

@implementation ScrollingTextView
- (id)initWithFrame: (NSRect)aFrame
{
    self = [super initWithFrame: aFrame];
    [[self layoutManager] setDelegate: self];
    return self;
}

- (void)layoutManager: (NSLayoutManager *)aLayoutManager
didCompleteLayoutForTextContainer: (NSTextContainer *)aTextContainer
                atEnd:(BOOL)flag
{
    if (flag) {
        NSClipView *clipView;
        
        clipView = (NSClipView *)[self superview];
        if ([clipView isKindOfClass: [NSClipView class]]) {
            [clipView scrollToPoint:
                [clipView constrainScrollPoint: NSMakePoint(0.0, [self frame].size.height)]];
            [[clipView superview] reflectScrolledClipView: clipView];
        }
    }
}

- (BOOL)performKeyEquivalent: (NSEvent *)anEvent
{
    NSDocument *targetDoc;
    BOOL rc;
    
    rc = NO;
    targetDoc = [[[self window] windowController] document];
    if ([targetDoc respondsToSelector: @selector(handleEvent:from:)])
        rc = [[targetDoc performSelector: @selector(handleEvent:from:)
                             withObject: anEvent
                              withObject: self] boolValue] ? YES : [super performKeyEquivalent: anEvent];
    return rc;
}

- (void)keyDown: (NSEvent *)anEvent
{
    if ([[self delegate] respondsToSelector: @selector(handleEvent:from:)]) {
        if ([[[self delegate] performSelector: @selector(handleEvent:from:) withObject: anEvent
                                   withObject:self] boolValue] == NO)
            [super keyDown: anEvent];
    } else
        [super keyDown: anEvent];
}

- (void)changeFont: (id)sender
{
    if ([[self delegate] respondsToSelector: @selector(changeFont:)]) {
        [[self delegate] performSelector: @selector(changeFont:)
                              withObject: sender];
    }
}
@end