Revision: 12955
          http://sourceforge.net/p/skim-app/code/12955
Author:   hofman
Date:     2022-06-26 14:44:30 +0000 (Sun, 26 Jun 2022)
Log Message:
-----------
Update display for reading bar through delegate method. Change reading bar 
through navigation methods.

Modified Paths:
--------------
    trunk/SKPDFView.m
    trunk/SKReadingBar.h
    trunk/SKReadingBar.m

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2022-06-25 19:09:57 UTC (rev 12954)
+++ trunk/SKPDFView.m   2022-06-26 14:44:30 UTC (rev 12955)
@@ -188,7 +188,7 @@
 
 #pragma mark -
 
-@interface SKPDFView ()
+@interface SKPDFView () <SKReadingBarDelegate>
 @property (retain) SKReadingBar *readingBar;
 @property (retain) SKSyncDot *syncDot;
 @end
@@ -565,7 +565,7 @@
             readingBarLine = 0;
         }
         if (page) {
-            SKReadingBar *aReadingBar = [[SKReadingBar alloc] 
initWithPage:page line:readingBarLine];
+            SKReadingBar *aReadingBar = [[SKReadingBar alloc] 
initWithPage:page line:readingBarLine delegate:self];
             [self setReadingBar:aReadingBar];
             [aReadingBar release];
         }
@@ -984,7 +984,7 @@
         userInfo = [NSDictionary dictionaryWithObjectsAndKeys:page, 
SKPDFViewOldPageKey, nil];
     } else {
         page = [self currentPage];
-        SKReadingBar *aReadingBar = [[SKReadingBar alloc] initWithPage:page 
line:0];
+        SKReadingBar *aReadingBar = [[SKReadingBar alloc] initWithPage:page 
line:0 delegate:self];
         bounds = [aReadingBar currentBoundsForBox:[self displayBox]];
         [self goToRect:NSInsetRect([aReadingBar currentBounds], 0.0, -20.0) 
onPage:page];
         [self setReadingBar:aReadingBar];
@@ -999,6 +999,51 @@
     [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewReadingBarDidChangeNotification object:self 
userInfo:userInfo];
 }
 
+- (void)readingBar:(SKReadingBar *)aReadingBar 
didChangeBounds:(NSRect)oldBounds onPage:(PDFPage *)oldPage 
toBounds:(NSRect)newBounds onPage:(PDFPage *)newPage scroll:(BOOL)shouldScroll {
+    [syncDot setShouldHideReadingBar:NO];
+    
+    if (shouldScroll) {
+        NSRect rect = newBounds;
+        NSInteger lineAngle = [newPage lineDirectionAngle];
+        if ((lineAngle % 180)) {
+            rect = NSInsetRect(rect, 0.0, -20.0) ;
+            if (([self displayMode] & kPDFDisplaySinglePageContinuous)) {
+                NSRect visibleRect = [self convertRect:[self 
visibleContentRect] toPage:newPage];
+                rect = NSInsetRect(rect, 0.0, - floor( ( NSHeight(visibleRect) 
- NSHeight(rect) ) / 2.0 ) );
+                if (NSWidth(rect) <= NSWidth(visibleRect)) {
+                    if (NSMinX(rect) > NSMinX(visibleRect))
+                        rect.origin.x = fmax(NSMinX(visibleRect), NSMaxX(rect) 
- NSWidth(visibleRect));
+                } else if (lineAngle == 90) {
+                    rect.origin.x = NSMaxX(rect) - NSWidth(visibleRect);
+                }
+                rect.size.width = NSWidth(visibleRect);
+            }
+        } else {
+            rect = NSInsetRect(rect, -20.0, 0.0) ;
+            if (([self displayMode] & kPDFDisplaySinglePageContinuous)) {
+                NSRect visibleRect = [self convertRect:[self 
visibleContentRect] toPage:newPage];
+                rect = NSInsetRect(rect, - floor( ( NSWidth(visibleRect) - 
NSWidth(rect) ) / 2.0 ), 0.0 );
+                if (NSHeight(rect) <= NSHeight(visibleRect)) {
+                    if (NSMinY(rect) > NSMinY(visibleRect))
+                        rect.origin.y = fmax(NSMinY(visibleRect), NSMaxY(rect) 
- NSHeight(visibleRect));
+                } else if (lineAngle == 180) {
+                    rect.origin.y = NSMaxY(rect) - NSHeight(visibleRect);
+                }
+                rect.size.height = NSHeight(visibleRect);
+            }
+        }
+        [self goToRect:rect onPage:newPage];
+    }
+    
+    if (oldPage)
+        [self setNeedsDisplayInRect:[SKReadingBar bounds:oldBounds 
forBox:[self displayBox] onPage:oldPage] ofPage:oldPage];
+    if (newPage)
+        [self setNeedsDisplayInRect:[SKReadingBar bounds:newBounds 
forBox:[self displayBox] onPage:newPage] ofPage:newPage];
+    
+    NSDictionary *userInfo = newPage ? [NSDictionary 
dictionaryWithObjectsAndKeys:newPage, SKPDFViewNewPageKey, oldPage, 
SKPDFViewOldPageKey, nil] : [NSDictionary dictionaryWithObjectsAndKeys:oldPage, 
SKPDFViewOldPageKey, nil];
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewReadingBarDidChangeNotification object:self 
userInfo:userInfo];
+}
+
 #pragma mark Pacer
 
 - (void)setPacerSpeed:(CGFloat)speed {
@@ -2932,11 +2977,9 @@
                     shouldHideReadingBar = YES;
                 [self stopPacer];
                 BOOL invert = [[NSUserDefaults standardUserDefaults] 
boolForKey:SKReadingBarInvertKey];
-                PDFPage *oldPage = nil;
-                NSRect oldRect = NSZeroRect;
                 NSInteger line = [page indexOfLineRectAtPoint:point lower:YES];
                 if ([self hasReadingBar] == NO) {
-                    SKReadingBar *aReadingBar = [[SKReadingBar alloc] 
initWithPage:page line:line];
+                    SKReadingBar *aReadingBar = [[SKReadingBar alloc] 
initWithPage:page line:line delegate:self];
                     [self setReadingBar:aReadingBar];
                     [aReadingBar release];
                     if (invert)
@@ -2943,15 +2986,11 @@
                         [self requiresDisplay];
                     else
                         [self setNeedsDisplayInRect:[readingBar 
currentBoundsForBox:[self displayBox]] ofPage:[readingBar page]];
+                    NSDictionary *userInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:[readingBar page], SKPDFViewNewPageKey, nil];
+                    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewReadingBarDidChangeNotification object:self 
userInfo:userInfo];
                 } else {
-                    oldPage = [readingBar page];
-                    oldRect = [readingBar currentBoundsForBox:[self 
displayBox]];
                     [readingBar goToLine:line onPage:page];
-                    [self setNeedsDisplayInRect:oldRect ofPage:oldPage];
-                    [self setNeedsDisplayInRect:[readingBar 
currentBoundsForBox:[self displayBox]] ofPage:[readingBar page]];
                 }
-                NSDictionary *userInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:[readingBar page], SKPDFViewNewPageKey, oldPage, 
SKPDFViewOldPageKey, nil];
-                [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewReadingBarDidChangeNotification object:self 
userInfo:userInfo];
             } else if ([sel hasCharacters] && [self toolMode] == 
SKTextToolMode) {
                 [self setCurrentSelection:sel];
             }
@@ -3696,8 +3735,6 @@
 
 // @@ Horizontal layout
 - (void)doMoveReadingBarForKey:(unichar)eventChar {
-    PDFPage *oldPage = [readingBar page];
-    NSRect oldBounds = [readingBar currentBoundsForBox:[self displayBox]];
     BOOL moved = NO;
     if (eventChar == NSDownArrowFunctionKey || eventChar == 0)
         moved = [readingBar goToNextLine];
@@ -3707,51 +3744,8 @@
         moved = [readingBar goToNextPage];
     else if (eventChar == NSLeftArrowFunctionKey)
         moved = [readingBar goToPreviousPage];
-    if (moved) {
-        PDFPage *newPage = [readingBar page];
-        NSRect newBounds = [readingBar currentBoundsForBox:[self displayBox]];
-        NSRect rect = [readingBar currentBounds];
-        NSInteger lineAngle = [newPage lineDirectionAngle];
-        if ((lineAngle % 180)) {
-            rect = NSInsetRect(rect, 0.0, -20.0) ;
-            if (([self displayMode] & kPDFDisplaySinglePageContinuous)) {
-                NSRect visibleRect = [self convertRect:[self 
visibleContentRect] toPage:newPage];
-                rect = NSInsetRect(rect, 0.0, - floor( ( NSHeight(visibleRect) 
- NSHeight(rect) ) / 2.0 ) );
-                if (NSWidth(rect) <= NSWidth(visibleRect)) {
-                    if (NSMinX(rect) > NSMinX(visibleRect))
-                        rect.origin.x = fmax(NSMinX(visibleRect), NSMaxX(rect) 
- NSWidth(visibleRect));
-                } else if (lineAngle == 90) {
-                    rect.origin.x = NSMaxX(rect) - NSWidth(visibleRect);
-                }
-                rect.size.width = NSWidth(visibleRect);
-            }
-        } else {
-            rect = NSInsetRect(rect, -20.0, 0.0) ;
-            if (([self displayMode] & kPDFDisplaySinglePageContinuous)) {
-                NSRect visibleRect = [self convertRect:[self 
visibleContentRect] toPage:newPage];
-                rect = NSInsetRect(rect, - floor( ( NSWidth(visibleRect) - 
NSWidth(rect) ) / 2.0 ), 0.0 );
-                if (NSHeight(rect) <= NSHeight(visibleRect)) {
-                    if (NSMinY(rect) > NSMinY(visibleRect))
-                        rect.origin.y = fmax(NSMinY(visibleRect), NSMaxY(rect) 
- NSHeight(visibleRect));
-                } else if (lineAngle == 180) {
-                    rect.origin.y = NSMaxY(rect) - NSHeight(visibleRect);
-                }
-                rect.size.height = NSHeight(visibleRect);
-            }
-        }
-        [self goToRect:rect onPage:newPage];
-        if ([oldPage isEqual:newPage]) {
-            [self setNeedsDisplayInRect:NSUnionRect(oldBounds, newBounds) 
ofPage:oldPage];
-        } else {
-            [self setNeedsDisplayInRect:oldBounds ofPage:oldPage];
-            [self setNeedsDisplayInRect:newBounds ofPage:newPage];
-        }
-        if (eventChar != 0)
-            [self updatePacer];
-        NSDictionary *userInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:oldPage, SKPDFViewOldPageKey, newPage, 
SKPDFViewNewPageKey, nil];
-        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewReadingBarDidChangeNotification object:self 
userInfo:userInfo];
-    }
-    [syncDot setShouldHideReadingBar:NO];
+    if (moved && eventChar != 0)
+        [self updatePacer];
 }
 
 - (void)doResizeReadingBarForKey:(unichar)eventChar {
@@ -3761,15 +3755,9 @@
     else if (eventChar == NSUpArrowFunctionKey)
         numberOfLines--;
     if (numberOfLines > 0) {
-        PDFPage *page = [readingBar page];
-        NSRect rect = [readingBar currentBoundsForBox:[self displayBox]];
         [readingBar setNumberOfLines:numberOfLines];
-        [self setNeedsDisplayInRect:NSUnionRect(rect, [readingBar 
currentBoundsForBox:[self displayBox]]) ofPage:page];
         [self updatePacer];
-        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewReadingBarDidChangeNotification object:self
-            userInfo:[NSDictionary dictionaryWithObjectsAndKeys:page, 
SKPDFViewOldPageKey, page, SKPDFViewNewPageKey, nil]];
     }
-    [syncDot setShouldHideReadingBar:NO];
 }
 
 - (void)doMoveAnnotationWithEvent:(NSEvent *)theEvent offset:(NSPoint)offset {
@@ -4488,7 +4476,6 @@
     PDFPage *readingBarPage = [readingBar page];
     PDFPage *page = readingBarPage;
     NSInteger numberOfLines = [[page lineRects] count];
-       NSMutableDictionary *userInfo = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:page, SKPDFViewOldPageKey, nil];
     NSInteger lineAngle = [page lineDirectionAngle];
     
     NSEvent *lastMouseEvent = theEvent;
@@ -4553,20 +4540,8 @@
         currentLine = MAX(0, MIN(numberOfLines - (NSInteger)[readingBar 
numberOfLines], currentLine));
         
         if ([page isEqual:readingBarPage] == NO || currentLine != [readingBar 
currentLine]) {
-            NSRect newRect, oldRect = [readingBar currentBoundsForBox:[self 
displayBox]];
-            [self setNeedsDisplayInRect:[readingBar currentBoundsForBox:[self 
displayBox]] ofPage:readingBarPage];
             [readingBar goToLine:currentLine onPage:page];
-            newRect = [readingBar currentBoundsForBox:[self displayBox]];
-            if ([page isEqual:readingBarPage]) {
-                [self setNeedsDisplayInRect:NSUnionRect(oldRect, newRect) 
ofPage:page];
-            } else {
-                [self setNeedsDisplayInRect:oldRect ofPage:readingBarPage];
-                [self setNeedsDisplayInRect:newRect ofPage:page];
-            }
-            [userInfo setObject:readingBarPage forKey:SKPDFViewOldPageKey];
-            [userInfo setObject:page forKey:SKPDFViewNewPageKey];
             readingBarPage = page;
-            [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewReadingBarDidChangeNotification object:self 
userInfo:userInfo];
             lastMouseLoc = mouseLocInDocument;
         }
     }
@@ -4574,7 +4549,6 @@
     [NSEvent stopPeriodicEvents];
     
     [self updatePacer];
-    [syncDot setShouldHideReadingBar:NO];
     
     [NSCursor pop];
     // ??? PDFView's delayed layout seems to reset the cursor to an arrow
@@ -4584,7 +4558,6 @@
 - (void)doResizeReadingBarWithEvent:(NSEvent *)theEvent {
     PDFPage *page = [readingBar page];
     NSInteger firstLine = [readingBar currentLine];
-       NSDictionary *userInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:page, SKPDFViewOldPageKey, page, 
SKPDFViewNewPageKey, nil];
     
     [[NSCursor resizeUpDownCursor] push];
     
@@ -4602,15 +4575,10 @@
         NSInteger numberOfLines = MAX(0, [page indexOfLineRectAtPoint:point 
lower:YES]) - firstLine + 1;
         
         if (numberOfLines > 0 && numberOfLines != (NSInteger)[readingBar 
numberOfLines]) {
-            NSRect oldRect = [readingBar currentBoundsForBox:[self 
displayBox]];
             [readingBar setNumberOfLines:numberOfLines];
-            [self setNeedsDisplayInRect:NSUnionRect(oldRect, [readingBar 
currentBoundsForBox:[self displayBox]]) ofPage:page];
-            [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewReadingBarDidChangeNotification object:self 
userInfo:userInfo];
         }
     }
     
-    [syncDot setShouldHideReadingBar:NO];
-    
     [NSCursor pop];
     // ??? PDFView's delayed layout seems to reset the cursor to an arrow
     [self performSelector:@selector(setCursorForMouse:) withObject:theEvent 
afterDelay:0];

Modified: trunk/SKReadingBar.h
===================================================================
--- trunk/SKReadingBar.h        2022-06-25 19:09:57 UTC (rev 12954)
+++ trunk/SKReadingBar.h        2022-06-26 14:44:30 UTC (rev 12955)
@@ -39,6 +39,7 @@
 #import <Cocoa/Cocoa.h>
 #import <Quartz/Quartz.h>
 
+@protocol SKReadingBarDelegate;
 
 @interface SKReadingBar : NSObject {
     PDFPage *page;
@@ -46,16 +47,19 @@
     NSInteger currentLine;
     NSUInteger numberOfLines;
     NSRect currentBounds;
+    id <SKReadingBarDelegate> delegate;
 }
 
-@property (retain) PDFPage *page;
-@property (nonatomic) NSInteger currentLine;
+@property (readonly, retain) PDFPage *page;
+@property (nonatomic, readonly) NSInteger currentLine;
 @property (nonatomic) NSUInteger numberOfLines;
 @property (nonatomic) NSInteger maxLine;
 @property (readonly) NSRect currentBounds;
+@property (nonatomic, assign) id <SKReadingBarDelegate> delegate;
 
-- (id)initWithPage:(PDFPage *)aPage line:(NSInteger)line;
+- (id)initWithPage:(PDFPage *)aPage line:(NSInteger)line delegate:(id 
<SKReadingBarDelegate>)aDelegate;
 
++ (NSRect)bounds:(NSRect)rect forBox:(PDFDisplayBox)box onPage:(PDFPage 
*)aPage;
 - (NSRect)currentBoundsForBox:(PDFDisplayBox)box;
 
 - (BOOL)goToNextLine;
@@ -69,3 +73,10 @@
 - (void)drawForPage:(PDFPage *)pdfPage withBox:(PDFDisplayBox)box 
active:(BOOL)active;
 
 @end
+
+
+@protocol SKReadingBarDelegate <NSObject>
+
+- (void)readingBar:(SKReadingBar *)readingBar 
didChangeBounds:(NSRect)oldBounds onPage:(PDFPage *)oldPage 
toBounds:(NSRect)newBounds onPage:(PDFPage *)newPage scroll:(BOOL)shouldScroll;
+
+@end

Modified: trunk/SKReadingBar.m
===================================================================
--- trunk/SKReadingBar.m        2022-06-25 19:09:57 UTC (rev 12954)
+++ trunk/SKReadingBar.m        2022-06-26 14:44:30 UTC (rev 12955)
@@ -45,16 +45,21 @@
 
 #define SKReadingBarNumberOfLinesKey @"SKReadingBarNumberOfLines"
 
+@interface SKReadingBar ()
+@property (retain) PDFPage *page;
+@property NSRect currentBounds;
+@end
 
 @implementation SKReadingBar
 
-@synthesize currentLine, numberOfLines;
-@dynamic page, currentBounds, maxLine;
+@synthesize page, currentLine, numberOfLines, currentBounds, delegate;
+@dynamic maxLine;
 
-- (id)initWithPage:(PDFPage *)aPage line:(NSInteger)line {
+- (id)initWithPage:(PDFPage *)aPage line:(NSInteger)line delegate:(id 
<SKReadingBarDelegate>)aDelegate {
     self = [super init];
     if (self) {
         numberOfLines = MAX(1, [[NSUserDefaults standardUserDefaults] 
integerForKey:SKReadingBarNumberOfLinesKey]);
+        delegate = aDelegate;
         NSPointerArray *lines = [aPage lineRects];
         if ([lines count]) {
             page = [aPage retain];
@@ -104,36 +109,16 @@
 }
 
 - (id)init {
-    return [self initWithPage:nil line:-1];
+    return [self initWithPage:nil line:-1 delegate:nil];
 }
 
 - (void)dealloc {
+    delegate = nil;
     SKDESTROY(page);
     SKDESTROY(lineRects);
     [super dealloc];
 }
 
-- (PDFPage *)page {
-    PDFPage *aPage = nil;
-    @synchronized (self) {
-        aPage = [page retain];
-    }
-    return [aPage autorelease];
-}
-
-- (void)setPage:(PDFPage *)newPage {
-    @synchronized (self) {
-        if (page != newPage) {
-            [page release];
-            page = [newPage retain];
-            [lineRects release];
-            lineRects = [[page lineRects] retain];
-            currentLine = -1;
-            currentBounds = NSZeroRect;
-        }
-    }
-}
-
 - (void)updateCurrentBounds {
     NSRect rect = NSZeroRect;
     if (currentLine >= 0) {
@@ -141,20 +126,19 @@
         for (i = currentLine; i < endLine; i++)
             rect = NSUnionRect(rect, [lineRects rectAtIndex:i]);
     }
-    @synchronized (self) {
-        currentBounds = page == nil ? NSZeroRect : rect;
-    }
+    [self setCurrentBounds:page == nil ? NSZeroRect : rect];
 }
 
-- (void)setCurrentLine:(NSInteger)line {
-    currentLine = line;
-    [self updateCurrentBounds];
-}
-
 - (void)setNumberOfLines:(NSUInteger)number {
-    numberOfLines = number;
-    [self updateCurrentBounds];
-    [[NSUserDefaults standardUserDefaults] setInteger:numberOfLines 
forKey:SKReadingBarNumberOfLinesKey];
+    if (number != numberOfLines) {
+        PDFPage *oldPage = currentLine != -1 ? page : nil;
+        NSRect oldBounds = currentBounds;
+        numberOfLines = number;
+        [self updateCurrentBounds];
+        [[NSUserDefaults standardUserDefaults] setInteger:numberOfLines 
forKey:SKReadingBarNumberOfLinesKey];
+        if (delegate && NSEqualRects(oldBounds, currentBounds) == NO)
+            [delegate readingBar:self didChangeBounds:oldBounds onPage:oldPage 
toBounds:currentBounds onPage:page scroll:NO];
+    }
 }
 
 - (NSInteger)maxLine {
@@ -162,25 +146,11 @@
     return lineCount == 0 ? -1 : MAX(0, lineCount - (NSInteger)numberOfLines);
 }
 
-- (NSRect)currentBounds {
-    NSRect bounds;
-    @synchronized (self) {
-        bounds = currentBounds;
-    }
-    return bounds;
-}
-
-- (NSRect)currentBoundsForBox:(PDFDisplayBox)box {
-    NSRect rect, bounds;
-    BOOL rotated;
-    @synchronized (self) {
-        rect = currentBounds;
-        bounds = [page boundsForBox:box];
-        rotated = ([page lineDirectionAngle] % 180) == 0;
-    }
++ (NSRect)bounds:(NSRect)rect forBox:(PDFDisplayBox)box onPage:(PDFPage 
*)aPage {
     if (NSEqualRects(rect, NSZeroRect))
         return NSZeroRect;
-    if (rotated) {
+    NSRect bounds = [aPage boundsForBox:box];
+    if (([aPage lineDirectionAngle] % 180) == 0) {
         rect.origin.y = NSMinY(bounds);
         rect.size.height = NSHeight(bounds);
     } else {
@@ -190,6 +160,10 @@
     return rect;
 }
 
+- (NSRect)currentBoundsForBox:(PDFDisplayBox)box {
+    return [[self class] bounds:[self currentBounds] forBox:box onPage:[self 
page]];
+}
+
 - (BOOL)goToNextPageAtTop:(BOOL)atTop {
     BOOL didMove = NO;
     PDFDocument *doc = [page document];
@@ -199,10 +173,7 @@
         PDFPage *nextPage = [doc pageAtIndex:i];
         NSPointerArray *lines = [nextPage lineRects];
         if ([lines count]) {
-            @synchronized (self) {
-                [page release];
-                page = [nextPage retain];
-            }
+            [self setPage:nextPage];
             [lineRects release];
             lineRects = [lines retain];
             currentLine = atTop ? 0 : [self maxLine];
@@ -223,10 +194,7 @@
         PDFPage *prevPage = [doc pageAtIndex:i];
         NSPointerArray *lines = [prevPage lineRects];
         if ([lines count]) {
-            @synchronized (self) {
-                [page release];
-                page = [prevPage retain];
-            }
+            [self setPage:prevPage];
             [lineRects release];
             lineRects = [lines retain];
             currentLine = atTop ? 0 : [self maxLine];
@@ -239,6 +207,8 @@
 }
 
 - (BOOL)goToNextLine {
+    PDFPage *oldPage = currentLine != -1 ? page : nil;
+    NSRect oldBounds = currentBounds;
     BOOL didMove = NO;
     if (currentLine < [self maxLine]) {
         ++currentLine;
@@ -247,10 +217,14 @@
     } else if ([self goToNextPageAtTop:YES]) {
         didMove = YES;
     }
+    if (didMove && delegate)
+        [delegate readingBar:self didChangeBounds:oldBounds onPage:oldPage 
toBounds:currentBounds onPage:page scroll:YES];
     return didMove;
 }
 
 - (BOOL)goToPreviousLine {
+    PDFPage *oldPage = currentLine != -1 ? page : nil;
+    NSRect oldBounds = currentBounds;
     BOOL didMove = NO;
     if (currentLine == -1 && [lineRects count])
         currentLine = [lineRects count];
@@ -261,24 +235,46 @@
     } else if ([self goToPreviousPageAtTop:NO]) {
         didMove = YES;
     }
+    if (didMove && delegate)
+        [delegate readingBar:self didChangeBounds:oldBounds onPage:oldPage 
toBounds:currentBounds onPage:page scroll:YES];
     return didMove;
 }
 
 - (BOOL)goToNextPage {
-    return [self goToNextPageAtTop:YES];
+    PDFPage *oldPage = currentLine != -1 ? page : nil;
+    NSRect oldBounds = currentBounds;
+    BOOL didMove = [self goToNextPageAtTop:YES];
+    if (didMove && delegate)
+        [delegate readingBar:self didChangeBounds:oldBounds onPage:oldPage 
toBounds:currentBounds onPage:page scroll:YES];
+    return didMove;
 }
 
 - (BOOL)goToPreviousPage {
-    return [self goToPreviousPageAtTop:YES];
+    PDFPage *oldPage = currentLine != -1 ? page : nil;
+    NSRect oldBounds = currentBounds;
+    BOOL didMove = [self goToPreviousPageAtTop:YES];
+    if (didMove && delegate)
+        [delegate readingBar:self didChangeBounds:oldBounds onPage:oldPage 
toBounds:currentBounds onPage:page scroll:YES];
+    return didMove;
 }
 
 - (void)goToLine:(NSInteger)line onPage:(PDFPage *)aPage {
-    if (page != aPage)
+    PDFPage *oldPage = currentLine != -1 ? page : nil;
+    NSRect oldBounds = currentBounds;
+    if (page != aPage) {
         [self setPage:aPage];
-    if ([lineRects count])
-        [self setCurrentLine:MAX(0, MIN([self maxLine], line))];
-    else
+        [lineRects release];
+        lineRects = [[page lineRects] retain];
+        currentLine = -1;
+    }
+    if ([lineRects count]) {
+        currentLine = MAX(0, MIN([self maxLine], line));
+        [self updateCurrentBounds];
+    } else {
         [self goToNextPageAtTop:YES] || [self goToPreviousPageAtTop:NO];
+    }
+    if (delegate && (page != oldPage || NSEqualRects(oldBounds, currentBounds) 
== NO))
+        [delegate readingBar:self didChangeBounds:oldBounds onPage:oldPage 
toBounds:currentBounds onPage:page scroll:NO];
 }
 
 - (void)drawForPage:(PDFPage *)pdfPage withBox:(PDFDisplayBox)box 
inContext:(CGContextRef)context {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to