Skip to content

Commit 6ed5496

Browse files
committedOct 17, 2008
PGClipView now divides scrolling into three modes. Also, a bug is fixed that prevented multiple columns opening.
1 parent 7f31291 commit 6ed5496

6 files changed

+49
-38
lines changed
 

‎PGClipView.h

+15-7
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ DEALINGS WITH THE SOFTWARE. */
2727
// Other
2828
#import "PGGeometry.h"
2929

30+
enum {
31+
PGScrollKeepCurrent = 0,
32+
PGScrollNoAnimation = 1,
33+
PGScrollAllowAnimation = 2
34+
};
35+
typedef unsigned PGScrollMode;
36+
3037
enum {
3138
PGScrollByLine = 0,
3239
PGScrollByPage = 1
3340
};
34-
typedef int PGScrollType;
41+
typedef unsigned PGScrollType;
3542

3643
@interface PGClipView : NSView
3744
{
@@ -79,19 +86,20 @@ typedef int PGScrollType;
7986
- (BOOL)shouldExitForMovementInDirection:(PGRectEdgeMask)mask;
8087

8188
- (NSPoint)position;
82-
- (BOOL)scrollTo:(NSPoint)aPoint allowAnimation:(BOOL)flag;
83-
- (BOOL)scrollBy:(NSSize)aSize allowAnimation:(BOOL)flag;
84-
- (BOOL)scrollToEdge:(PGRectEdgeMask)mask allowAnimation:(BOOL)flag;
85-
- (BOOL)scrollToLocation:(PGPageLocation)location allowAnimation:(BOOL)flag;
89+
- (NSPoint)positionForScrollMode:(PGScrollMode)mode;
90+
- (BOOL)scrollTo:(NSPoint)aPoint mode:(PGScrollMode)mode;
91+
- (BOOL)scrollBy:(NSSize)aSize mode:(PGScrollMode)mode;
92+
- (BOOL)scrollToEdge:(PGRectEdgeMask)mask mode:(PGScrollMode)mode;
93+
- (BOOL)scrollToLocation:(PGPageLocation)location mode:(PGScrollMode)mode;
8694
- (void)stopAnimatedScrolling;
8795

8896
- (PGRectEdgeMask)pinLocation;
8997
- (void)setPinLocation:(PGRectEdgeMask)mask;
9098
- (NSSize)pinLocationOffset;
91-
- (BOOL)scrollPinLocationToOffset:(NSSize)aSize allowAnimation:(BOOL)flag;
99+
- (BOOL)scrollPinLocationToOffset:(NSSize)aSize;
92100

93101
- (NSPoint)center;
94-
- (BOOL)scrollCenterTo:(NSPoint)aPoint allowAnimation:(BOOL)flag;
102+
- (BOOL)scrollCenterTo:(NSPoint)aPoint mode:(PGScrollMode)mode;
95103

96104
- (BOOL)handleMouseDown:(NSEvent *)firstEvent;
97105
- (void)arrowKeyDown:(NSEvent *)firstEvent;

‎PGClipView.m

+27-24
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ - (void)setBoundsInset:(PGInset)inset
118118
{
119119
NSPoint const p = [self position];
120120
_boundsInset = inset;
121-
[self scrollTo:p allowAnimation:NO];
121+
[self scrollTo:p mode:PGScrollNoAnimation];
122122
}
123123
- (NSRect)insetBounds
124124
{
@@ -234,12 +234,16 @@ - (NSPoint)position
234234
{
235235
return _scrollTimer ? _position : _immediatePosition;
236236
}
237+
- (NSPoint)positionForScrollMode:(PGScrollMode)mode
238+
{
239+
return PGScrollKeepCurrent == mode ? _immediatePosition : [self position];
240+
}
237241

238242
- (BOOL)scrollTo:(NSPoint)aPoint
239-
allowAnimation:(BOOL)flag
243+
mode:(PGScrollMode)mode
240244
{
241-
if(!PGAnimateScrolling || !flag) {
242-
[self stopAnimatedScrolling];
245+
if(PGScrollAllowAnimation != mode) {
246+
if(PGAnimateScrolling && PGScrollNoAnimation == mode) [self stopAnimatedScrolling];
243247
return [self _scrollTo:aPoint];
244248
}
245249
NSPoint const newTargetPosition = PGPointInRect(aPoint, [self scrollableRectWithBorder:YES]);
@@ -252,20 +256,20 @@ - (BOOL)scrollTo:(NSPoint)aPoint
252256
return YES;
253257
}
254258
- (BOOL)scrollBy:(NSSize)aSize
255-
allowAnimation:(BOOL)flag
259+
mode:(PGScrollMode)mode
256260
{
257-
return [self scrollTo:PGOffsetPointBySize([self position], aSize) allowAnimation:flag];
261+
return [self scrollTo:PGOffsetPointBySize([self positionForScrollMode:mode], aSize) mode:mode];
258262
}
259263
- (BOOL)scrollToEdge:(PGRectEdgeMask)mask
260-
allowAnimation:(BOOL)flag
264+
mode:(PGScrollMode)mode
261265
{
262266
NSAssert(!PGHasContradictoryRectEdges(mask), @"Can't scroll to contradictory edges.");
263-
return [self scrollBy:PGRectEdgeMaskToSizeWithMagnitude(mask, FLT_MAX) allowAnimation:flag];
267+
return [self scrollBy:PGRectEdgeMaskToSizeWithMagnitude(mask, FLT_MAX) mode:mode];
264268
}
265269
- (BOOL)scrollToLocation:(PGPageLocation)location
266-
allowAnimation:(BOOL)flag
270+
mode:(PGScrollMode)mode
267271
{
268-
return [self scrollToEdge:[[self delegate] clipView:self directionFor:location] allowAnimation:flag];
272+
return [self scrollToEdge:[[self delegate] clipView:self directionFor:location] mode:mode];
269273
}
270274

271275
- (void)stopAnimatedScrolling
@@ -295,13 +299,12 @@ - (NSSize)pinLocationOffset
295299
return NSMakeSize(diff.width * 2.0f / NSWidth(_documentFrame), diff.height * 2.0f / NSHeight(_documentFrame));
296300
}
297301
- (BOOL)scrollPinLocationToOffset:(NSSize)aSize
298-
allowAnimation:(BOOL)flag
299302
{
300303
NSSize o = aSize;
301304
NSRect const b = [self insetBounds];
302305
PGRectEdgeMask const pin = [self pinLocation];
303306
if([[self documentView] scalesContentWithFrameSizeInClipView:self]) o = NSMakeSize(o.width * NSWidth(_documentFrame) * 0.5f, o.height * NSHeight(_documentFrame) * 0.5f);
304-
return [self scrollTo:PGOffsetPointBySize([self position], PGPointDiff(PGOffsetPointBySize(PGPointOfPartOfRect(_documentFrame, pin), o), PGPointOfPartOfRect(b, pin))) allowAnimation:flag];
307+
return [self scrollBy:PGPointDiff(PGOffsetPointBySize(PGPointOfPartOfRect(_documentFrame, pin), o), PGPointOfPartOfRect(b, pin)) mode:PGScrollKeepCurrent];
305308
}
306309

307310
#pragma mark -
@@ -313,11 +316,11 @@ - (NSPoint)center
313316
return PGOffsetPointByXY([self position], inset.minX + NSWidth(b) / 2, inset.minY + NSHeight(b) / 2);
314317
}
315318
- (BOOL)scrollCenterTo:(NSPoint)aPoint
316-
allowAnimation:(BOOL)flag
319+
mode:(PGScrollMode)mode
317320
{
318321
NSRect const b = [self insetBounds];
319322
PGInset const inset = [self boundsInset];
320-
return [self scrollTo:PGOffsetPointByXY(aPoint, -inset.minX - NSWidth(b) / 2, -inset.minY - NSHeight(b) / 2) allowAnimation:flag];
323+
return [self scrollTo:PGOffsetPointByXY(aPoint, -inset.minX - NSWidth(b) / 2, -inset.minY - NSHeight(b) / 2) mode:mode];
321324
}
322325

323326
#pragma mark -
@@ -356,8 +359,8 @@ - (BOOL)handleMouseDown:(NSEvent *)firstEvent
356359
} else [[NSCursor closedHandCursor] push];
357360
[self PG_cancelPreviousPerformRequestsWithSelector:@selector(_beginPreliminaryDrag) object:nil];
358361
}
359-
if(PGMouseHiddenDraggingStyle) [self scrollBy:NSMakeSize(-[latestEvent deltaX], [latestEvent deltaY]) allowAnimation:NO];
360-
else [self scrollTo:PGOffsetPointByXY(dragPoint, -[latestEvent locationInWindow].x, -[latestEvent locationInWindow].y) allowAnimation:NO];
362+
if(PGMouseHiddenDraggingStyle) [self scrollBy:NSMakeSize(-[latestEvent deltaX], [latestEvent deltaY]) mode:PGScrollNoAnimation];
363+
else [self scrollTo:PGOffsetPointByXY(dragPoint, -[latestEvent locationInWindow].x, -[latestEvent locationInWindow].y) mode:PGScrollNoAnimation];
361364
finalPoint = PGPointInRect(PGOffsetPointByXY(finalPoint, [latestEvent deltaX], -[latestEvent deltaY]), availableDragRect);
362365
}
363366
[self PG_cancelPreviousPerformRequestsWithSelector:@selector(_beginPreliminaryDrag) object:nil];
@@ -391,7 +394,7 @@ - (void)arrowKeyDown:(NSEvent *)firstEvent
391394
if(currentTime > pageTurnTime + PGPageTurnMovementDelay) {
392395
NSSize const d = [self distanceInDirection:PGNonContradictoryRectEdges(pressedDirections) forScrollType:PGScrollByLine];
393396
float const timeAdjustment = lastScrollTime ? PGAnimationFramerate / (currentTime - lastScrollTime) : 1;
394-
[self scrollBy:NSMakeSize(d.width / timeAdjustment, d.height / timeAdjustment) allowAnimation:NO];
397+
[self scrollBy:NSMakeSize(d.width / timeAdjustment, d.height / timeAdjustment) mode:PGScrollNoAnimation];
395398
}
396399
lastScrollTime = currentTime;
397400
continue;
@@ -420,7 +423,7 @@ - (void)arrowKeyDown:(NSEvent *)firstEvent
420423
- (void)scrollInDirection:(PGRectEdgeMask)direction
421424
type:(PGScrollType)scrollType
422425
{
423-
if(![self shouldExitForMovementInDirection:direction] || ![[self delegate] clipView:self shouldExitEdges:direction]) [self scrollBy:[self distanceInDirection:direction forScrollType:scrollType] allowAnimation:YES];
426+
if(![self shouldExitForMovementInDirection:direction] || ![[self delegate] clipView:self shouldExitEdges:direction]) [self scrollBy:[self distanceInDirection:direction forScrollType:scrollType] mode:PGScrollAllowAnimation];
424427
}
425428
- (void)magicPanForward:(BOOL)forward
426429
acrossFirst:(BOOL)across
@@ -439,7 +442,7 @@ - (void)magicPanForward:(BOOL)forward
439442
} else if(across) position.x = FLT_MAX * (mask & PGMinXEdgeMask ? 1 : -1);
440443
else position.y = FLT_MAX * (mask & PGMinYEdgeMask ? 1 : -1);
441444
}
442-
[self scrollTo:position allowAnimation:YES];
445+
[self scrollTo:position mode:PGScrollAllowAnimation];
443446
}
444447

445448
#pragma mark -
@@ -449,7 +452,7 @@ - (void)viewFrameDidChange:(NSNotification *)aNotif
449452
[self stopAnimatedScrolling];
450453
NSSize const offset = [self pinLocationOffset];
451454
_documentFrame = [documentView frame];
452-
[self scrollPinLocationToOffset:offset allowAnimation:NO];
455+
[self scrollPinLocationToOffset:offset];
453456
}
454457

455458
#pragma mark Private Protocol
@@ -458,7 +461,7 @@ - (BOOL)_setPosition:(NSPoint)aPoint
458461
markForRedisplayIfNeeded:(BOOL)flag
459462
{
460463
NSPoint const newPosition = PGPointInRect(aPoint, [self scrollableRectWithBorder:YES]);
461-
[[self PG_enclosingClipView] scrollBy:NSMakeSize(aPoint.x - newPosition.x, aPoint.y - newPosition.y) allowAnimation:NO];
464+
[[self PG_enclosingClipView] scrollBy:NSMakeSize(aPoint.x - newPosition.x, aPoint.y - newPosition.y) mode:PGScrollKeepCurrent];
462465
if(NSEqualPoints(newPosition, _immediatePosition)) return NO;
463466
_immediatePosition = newPosition;
464467
[self setBoundsOrigin:NSMakePoint(floorf(_immediatePosition.x), floorf(_immediatePosition.y))];
@@ -605,7 +608,7 @@ - (void)scrollWheel:(NSEvent *)anEvent
605608
{
606609
[NSCursor setHiddenUntilMouseMoves:YES];
607610
float const x = -[anEvent deltaX], y = [anEvent deltaY];
608-
[self scrollBy:NSMakeSize(x * PGLineScrollDistance, y * PGLineScrollDistance) allowAnimation:YES];
611+
[self scrollBy:NSMakeSize(x * PGLineScrollDistance, y * PGLineScrollDistance) mode:PGScrollAllowAnimation];
609612
}
610613

611614
#pragma mark -
@@ -699,11 +702,11 @@ - (void)moveRight:(id)sender
699702

700703
- (IBAction)moveToBeginningOfDocument:(id)sender
701704
{
702-
[self scrollToLocation:PGHomeLocation allowAnimation:YES];
705+
[self scrollToLocation:PGHomeLocation mode:PGScrollAllowAnimation];
703706
}
704707
- (IBAction)moveToEndOfDocument:(id)sender
705708
{
706-
[self scrollToLocation:PGEndLocation allowAnimation:YES];
709+
[self scrollToLocation:PGEndLocation mode:PGScrollAllowAnimation];
707710
}
708711
- (IBAction)scrollPageUp:(id)sender
709712
{

‎PGColumnView.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ - (void)setColumnWidth:(float)width
120120

121121
- (void)scrollToTopOfColumnWithView:(NSView *)aView
122122
{
123-
[[_clipViews objectAtIndex:[_views indexOfObjectIdenticalTo:aView]] scrollToEdge:PGMaxYEdgeMask allowAnimation:NO];
123+
[[_clipViews objectAtIndex:[_views indexOfObjectIdenticalTo:aView]] scrollToEdge:PGMaxYEdgeMask mode:PGScrollKeepCurrent];
124124
}
125125
- (void)scrollToLastColumn
126126
{
127-
[_clipView scrollToEdge:PGMaxXEdgeMask allowAnimation:YES];
127+
[_clipView scrollToEdge:PGMaxXEdgeMask mode:PGScrollAllowAnimation];
128128
}
129129

130130
#pragma mark -

‎PGDisplayController.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ - (BOOL)setActiveDocument:(PGDocument *)document
352352
[self _setActiveNode:node];
353353
[clipView setDocumentView:view];
354354
[view setImageRep:[view rep] orientation:[view orientation] size:[self _sizeForImageRep:[view rep] orientation:[view orientation]]];
355-
[clipView scrollPinLocationToOffset:offset allowAnimation:NO];
355+
[clipView scrollPinLocationToOffset:offset];
356356
[self _readFinished];
357357
} else {
358358
[clipView setDocumentView:view];
@@ -532,7 +532,7 @@ - (void)nodeReadyForViewing:(NSNotification *)aNotif
532532
PGOrientation const orientation = [[self activeNode] orientation];
533533
[_imageView setImageRep:rep orientation:orientation size:[self _sizeForImageRep:rep orientation:orientation]];
534534
[clipView setDocumentView:_imageView];
535-
[clipView scrollToLocation:_initialLocation allowAnimation:NO];
535+
[clipView scrollToLocation:_initialLocation mode:PGScrollNoAnimation];
536536
[[self window] makeFirstResponder:clipView];
537537
}
538538
if(![_imageView superview]) [_imageView setImageRep:nil orientation:PGUpright size:NSZeroSize];
@@ -1008,7 +1008,7 @@ - (void)clipView:(PGClipView *)sender
10081008
- (void)clipView:(PGClipView *)sender
10091009
rotateByDegrees:(float)amount
10101010
{
1011-
[clipView scrollCenterTo:[clipView convertPoint:[_imageView rotateByDegrees:amount adjustingPoint:[_imageView convertPoint:[clipView center] fromView:clipView]] fromView:_imageView] allowAnimation:NO];
1011+
[clipView scrollCenterTo:[clipView convertPoint:[_imageView rotateByDegrees:amount adjustingPoint:[_imageView convertPoint:[clipView center] fromView:clipView]] fromView:_imageView] mode:PGScrollNoAnimation];
10121012
}
10131013
- (void)clipViewGestureDidEnd:(PGClipView *)sender
10141014
{

‎PGThumbnailBrowser.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ - (void)setSelection:(NSSet *)items
9393
[path addObject:ancestor];
9494
} while(ancestor);
9595
id pathItem;
96-
NSEnumerator *const pathItemEnum = [path objectEnumerator];
96+
NSEnumerator *const pathItemEnum = [path reverseObjectEnumerator];
9797
while((pathItem = [pathItemEnum nextObject])) [[self lastView] setSelection:[NSSet setWithObject:pathItem]];
9898
[[self lastView] setSelection:items];
9999
[self scrollToLastColumn];

‎PGWindowController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ - (void)nodeReadyForViewing:(NSNotification *)aNotif
105105
_shouldSaveFrame = NO;
106106
[[self window] setFrame:[[self window] PG_zoomedFrame] display:YES]; // Don't just send -zoom: because that will use the user size if the window is already the system size.
107107
_shouldSaveFrame = YES;
108-
[clipView scrollToLocation:_initialLocation allowAnimation:NO];
108+
[clipView scrollToLocation:_initialLocation mode:PGScrollNoAnimation];
109109
_shouldZoomOnNextImageLoad = NO;
110110
}
111111

0 commit comments

Comments
 (0)
Please sign in to comment.