Source

CocoaPDF / TronScrollView.mm

Full commit
//
//  TronScrollView.m
//
//  Created by Quincy on 10-08-07.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "TronScrollView.h"
#import "TronPDFView.h"

@implementation TronScrollView

-(void)viewDidMoveToWindow {
    [super viewDidMoveToWindow];
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(handleFrameChange:) 
                                                 name:NSViewFrameDidChangeNotification 
                                               object:self];
    /*
    [[NSNotificationCenter defaultCenter] addObserver:self
                                            selector:@selector(handleScrollChange:)
                                                 name:TronPDFViewScrollChangedNotification object:[self documentView]];
     */
}

-(BOOL)scrollsDynamically {
    return YES;
}

-(void)reflectScrolledClipView:(NSClipView *)cView {
    NSLog(@"reflectScrolledClipView");
    [super reflectScrolledClipView:cView];
    TronPDFView * pdfView = [self documentView];
    if ([pdfView inLiveResize]) {
        double vPos = [pdfView currentVerticalScrollPosition];
        double hPos = [pdfView currentHorizontalScrollPosition];
        [[self verticalScroller] setDoubleValue:vPos];
        [[self horizontalScroller] setDoubleValue:hPos];
        [pdfView update];
    } else {
        float vPos = [[self verticalScroller] floatValue];
        float hPos = [[self horizontalScroller] floatValue];
        [pdfView setScroll:hPos verticalPosition:vPos];
    }
    [pdfView setNeedsDisplay:YES];
}
     
-(void)handleFrameChange:(NSNotification*)notification {
    NSLog(@"TronScrollView handleFrameChanged");
    TronPDFView * pdfView = [self documentView];
    NSScroller * hScroller = [self horizontalScroller];
    NSScroller * vScroller = [self verticalScroller];
    float oldh = [hScroller floatValue];
    float oldv = [vScroller floatValue];
    [pdfView windowResized];
    float h = [hScroller floatValue];
    float v = [vScroller floatValue];
    //[self setScroll:oldh verticalPosition:oldv];
    NSLog(@"oldh: %0.4f, oldV: %0.4f, h: %0.4f, v: %0.4f", oldh, oldv, h, v);
}


-(void)setScroll:(double) horizontalPosition verticalPosition:(double) vPos {
    NSLog(@"TronScrollView setScroll");
    NSScroller * hScroller = [self horizontalScroller];
    NSScroller * vScroller = [self verticalScroller];
    
    if (hScroller) {
        [hScroller setDoubleValue:horizontalPosition];
    }
    
    if (vScroller) {
        [vScroller setDoubleValue:vPos];
    }
}


@end