aboutsummaryrefslogtreecommitdiffstats
path: root/ScrollingTextView.m
blob: 196cf281f431957c6ae8c94b16a54248e5709d43 (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
59
60
61
62
63
#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)keyDownToSuper: (NSEvent *)anEvent
{
    [super keyDown: anEvent];
}

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