Revision: 14473
          http://sourceforge.net/p/skim-app/code/14473
Author:   hofman
Date:     2024-09-23 16:03:13 +0000 (Mon, 23 Sep 2024)
Log Message:
-----------
Separate display code for presentation view into intermediate superclass. Add a 
preview action to the presentation options sheet.

Modified Paths:
--------------
    trunk/Base.lproj/TransitionSheet.xib
    trunk/SKPresentationOptionsSheetController.h
    trunk/SKPresentationOptionsSheetController.m
    trunk/SKPresentationView.h
    trunk/SKPresentationView.m
    trunk/SKTransitionController.h
    trunk/SKTransitionController.m
    trunk/de.lproj/TransitionSheet.strings
    trunk/en.lproj/TransitionSheet.strings
    trunk/es.lproj/TransitionSheet.strings
    trunk/fr.lproj/TransitionSheet.strings
    trunk/it.lproj/TransitionSheet.strings
    trunk/ja.lproj/TransitionSheet.strings
    trunk/nl.lproj/TransitionSheet.strings
    trunk/pl.lproj/TransitionSheet.strings
    trunk/ru.lproj/TransitionSheet.strings
    trunk/zh_CN.lproj/TransitionSheet.strings
    trunk/zh_TW.lproj/TransitionSheet.strings

Modified: trunk/Base.lproj/TransitionSheet.xib
===================================================================
--- trunk/Base.lproj/TransitionSheet.xib        2024-09-23 15:59:17 UTC (rev 
14472)
+++ trunk/Base.lproj/TransitionSheet.xib        2024-09-23 16:03:13 UTC (rev 
14473)
@@ -13,6 +13,7 @@
                 <outlet property="cancelButton" destination="31" 
id="KWh-6S-Kx4"/>
                 <outlet property="notesDocumentPopUpButton" destination="69" 
id="99"/>
                 <outlet property="okButton" destination="27" id="vvD-TX-nTy"/>
+                <outlet property="previewButton" destination="aK4-To-cWd" 
id="tF5-hw-0eF"/>
                 <outlet property="stylePopUpButton" destination="13" 
id="ckf-of-OsA"/>
                 <outlet property="tableView" destination="279" id="287"/>
                 <outlet property="tableWidthConstraint" 
destination="iKt-mE-odp" id="MPv-aK-lfF"/>
@@ -393,11 +394,25 @@
                             <autoresizingMask key="autoresizingMask"/>
                         </scroller>
                     </scrollView>
+                    <button verticalHuggingPriority="750" 
translatesAutoresizingMaskIntoConstraints="NO" id="aK4-To-cWd">
+                        <rect key="frame" x="152" y="13" width="82" 
height="32"/>
+                        <buttonCell key="cell" type="push" title="Preview" 
bezelStyle="rounded" alignment="center" borderStyle="border" inset="2" 
id="OOi-HR-fjj">
+                            <behavior key="behavior" pushIn="YES" 
lightByBackground="YES" lightByGray="YES"/>
+                            <font key="font" metaFont="system"/>
+                            <string key="keyEquivalent" base64-UTF8="YES">
+Gw
+</string>
+                        </buttonCell>
+                        <connections>
+                            <action selector="preview:" target="-2" 
id="On3-iX-X3z"/>
+                        </connections>
+                    </button>
                 </subviews>
                 <constraints>
                     <constraint firstItem="67" firstAttribute="leading" 
secondItem="276" secondAttribute="trailing" constant="8" id="2rg-eT-ead"/>
                     <constraint firstAttribute="bottom" secondItem="276" 
secondAttribute="bottom" constant="20" symbolic="YES" id="3T0-cp-NvT"/>
                     <constraint firstItem="67" firstAttribute="top" 
secondItem="138" secondAttribute="bottom" constant="8" symbolic="YES" 
id="72r-F8-Uf4"/>
+                    <constraint firstItem="31" firstAttribute="leading" 
relation="greaterThanOrEqual" secondItem="aK4-To-cWd" 
secondAttribute="trailing" constant="12" symbolic="YES" id="8F4-F1-lLq"/>
                     <constraint firstItem="138" firstAttribute="top" 
secondItem="8" secondAttribute="top" constant="20" symbolic="YES" 
id="GHg-dB-8ix"/>
                     <constraint firstAttribute="bottom" secondItem="27" 
secondAttribute="bottom" constant="20" symbolic="YES" id="MIv-MP-aBB"/>
                     <constraint firstItem="27" firstAttribute="leading" 
secondItem="31" secondAttribute="trailing" constant="12" symbolic="YES" 
id="NR2-CA-Nxl"/>
@@ -404,9 +419,10 @@
                     <constraint firstAttribute="trailing" 
relation="greaterThanOrEqual" secondItem="138" secondAttribute="trailing" 
constant="20" symbolic="YES" id="RXf-TG-FCJ"/>
                     <constraint firstItem="138" firstAttribute="leading" 
secondItem="67" secondAttribute="leading" id="UBr-68-Taj"/>
                     <constraint firstItem="276" firstAttribute="top" 
secondItem="8" secondAttribute="top" constant="20" symbolic="YES" 
id="Wa7-gP-eSb"/>
-                    <constraint firstItem="31" firstAttribute="baseline" 
secondItem="27" secondAttribute="baseline" id="ZTB-Ht-m3V"/>
+                    <constraint firstItem="aK4-To-cWd" 
firstAttribute="firstBaseline" secondItem="27" secondAttribute="firstBaseline" 
id="Zzd-CJ-GmB"/>
                     <constraint firstItem="27" firstAttribute="baseline" 
secondItem="31" secondAttribute="firstBaseline" id="brZ-zc-ukR"/>
                     <constraint firstItem="27" firstAttribute="width" 
secondItem="31" secondAttribute="width" id="buf-gV-RCb"/>
+                    <constraint firstItem="138" firstAttribute="leading" 
secondItem="aK4-To-cWd" secondAttribute="leading" id="diz-vs-P9p"/>
                     <constraint firstAttribute="trailing" secondItem="67" 
secondAttribute="trailing" constant="20" symbolic="YES" id="eM0-LM-BFY"/>
                     <constraint firstItem="68" firstAttribute="top" 
secondItem="67" secondAttribute="bottom" constant="8" symbolic="YES" 
id="f4s-ds-QZB"/>
                     <constraint firstItem="67" firstAttribute="leading" 
secondItem="8" secondAttribute="leading" constant="159" id="m1r-zo-sbv"/>

Modified: trunk/SKPresentationOptionsSheetController.h
===================================================================
--- trunk/SKPresentationOptionsSheetController.h        2024-09-23 15:59:17 UTC 
(rev 14472)
+++ trunk/SKPresentationOptionsSheetController.h        2024-09-23 16:03:13 UTC 
(rev 14473)
@@ -42,7 +42,7 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
-@class SKMainWindowController, SKThumbnail, SKTransitionInfo;
+@class SKMainWindowController, SKThumbnail, SKTransitionInfo, SKPDFPageView;
 
 @interface SKPresentationOptionsSheetController : NSWindowController 
<NSWindowDelegate, SKTableViewDelegate, NSTableViewDataSource, 
NSTouchBarDelegate> {
     NSPopUpButton *notesDocumentPopUpButton;
@@ -50,6 +50,7 @@
     NSPopUpButton *stylePopUpButton;
     NSButton *okButton;
     NSButton *cancelButton;
+    NSButton *previewButton;
     NSLayoutConstraint *boxLeadingConstraint;
     NSLayoutConstraint *tableWidthConstraint;
     NSArrayController *arrayController;
@@ -59,12 +60,14 @@
     __weak SKMainWindowController *controller;
     NSUndoManager *undoManager;
     NSMutableSet<SKTransitionInfo *> *changedTransitions;
+    NSWindow *previewWindow;
+    SKPDFPageView *previewView;
 }
 
 @property (nonatomic, nullable, strong) IBOutlet NSPopUpButton 
*notesDocumentPopUpButton;
 @property (nonatomic, nullable, strong) IBOutlet SKTableView *tableView;
 @property (nonatomic, nullable, strong) IBOutlet NSPopUpButton 
*stylePopUpButton;
-@property (nonatomic, nullable, strong) IBOutlet NSButton *okButton, 
*cancelButton;
+@property (nonatomic, nullable, strong) IBOutlet NSButton *okButton, 
*cancelButton, *previewButton;
 @property (nonatomic, nullable, strong) IBOutlet NSLayoutConstraint 
*boxLeadingConstraint, *tableWidthConstraint;
 @property (nonatomic, nullable, strong) IBOutlet NSArrayController 
*arrayController;
 @property (nonatomic) BOOL separate;
@@ -81,6 +84,8 @@
 - (void)startObservingTransitions:(NSArray<SKTransitionInfo *> *)infos;
 - (void)stopObservingTransitions:(NSArray<SKTransitionInfo *> *)infos;
 
+- (IBAction)preview:(nullable id)sender;
+
 @end
 
 NS_ASSUME_NONNULL_END

Modified: trunk/SKPresentationOptionsSheetController.m
===================================================================
--- trunk/SKPresentationOptionsSheetController.m        2024-09-23 15:59:17 UTC 
(rev 14472)
+++ trunk/SKPresentationOptionsSheetController.m        2024-09-23 16:03:13 UTC 
(rev 14473)
@@ -52,6 +52,8 @@
 #import "NSGraphics_SKExtensions.h"
 #import "NSColor_SKExtensions.h"
 #import "NSView_SKExtensions.h"
+#import "SKPresentationView.h"
+#import "SKAnimatedBorderlessWindow.h"
 
 #define PAGE_COLUMNID @"page"
 #define IMAGE_COLUMNID @"image"
@@ -80,7 +82,7 @@
 
 @implementation SKPresentationOptionsSheetController
 
-@synthesize notesDocumentPopUpButton, tableView, stylePopUpButton, okButton, 
cancelButton, tableWidthConstraint, boxLeadingConstraint, arrayController, 
separate, transition, transitions, undoManager;
+@synthesize notesDocumentPopUpButton, tableView, stylePopUpButton, okButton, 
cancelButton, previewButton, tableWidthConstraint, boxLeadingConstraint, 
arrayController, separate, transition, transitions, undoManager;
 @dynamic currentTransitions, pageTransitions, notesDocument, 
notesDocumentOffset;
 
 + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
@@ -138,6 +140,15 @@
     [notesDocumentPopUpButton selectItemAtIndex:docIndex == -1 ? 0 : docIndex];
 }
 
+- (void)validatePreviewButton {
+    if (separate) {
+        NSInteger idx = [tableView selectedRow];
+        [previewButton setEnabled:idx != -1 && [[transitions 
objectAtIndex:idx] transitionStyle] != SKNoTransition];
+    } else {
+        [previewButton setEnabled:[transition transitionStyle] != 
SKNoTransition];
+    }
+}
+
 - (void)windowDidLoad {
     // add the filter names to the popup
     NSUInteger i, count = [[SKTransitionController transitionNames] count];
@@ -183,6 +194,8 @@
         [[self undoManager] enableUndoRegistration];
     }
     
+    [self validatePreviewButton];
+    
     // set the current notes document and observe changes for the popup
     [self handleDocumentsDidChangeNotification:nil];
     NSDocument *currentDoc = [controller presentationNotesDocument];
@@ -262,6 +275,70 @@
     }
 }
 
+- (void)preview:(id)sender {
+    SKTransitionInfo *info = transition;
+    NSUInteger idx = 0;
+    if (separate) {
+        idx = [[tableView selectedRowIndexes] firstIndex];
+        if (idx == NSNotFound)
+            return;
+        info = [transitions objectAtIndex:idx];
+    }
+    if ([info transitionStyle] == SKNoTransition)
+        return;
+    
+    NSRect rect = [[[self window] screen] frame];
+    rect.size.width = round(0.5 * NSWidth(rect)) + 12.0;
+    rect.size.height = round(0.5 * NSHeight(rect)) + 30.0;
+    
+    if (previewWindow == nil) {
+        previewWindow = [[NSWindow alloc] initWithContentRect:rect 
styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView 
backing:NSBackingStoreBuffered defer:NO];
+        [previewWindow setReleasedWhenClosed:NO];
+        [previewWindow setTitlebarAppearsTransparent:YES];
+        
+        NSView *contentView = [previewWindow contentView];
+        
+        NSVisualEffectView *veView = [[NSVisualEffectView alloc] init];
+        [veView setMaterial:NSVisualEffectMaterialPopover];
+        [veView setState:NSVisualEffectStateActive];
+        [veView setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
+        [veView setTranslatesAutoresizingMaskIntoConstraints:NO];
+        [contentView addSubviewWithConstraints:veView];
+        
+        NSView *bgView = [[NSView alloc] init];
+        CALayer *layer = [CALayer layer];
+        [layer setBackgroundColor:CGColorGetConstantColor(kCGColorBlack)];
+        [layer setCornerRadius:6.0];
+        [bgView setLayer:layer];
+        [bgView setWantsLayer:YES];
+        [bgView setTranslatesAutoresizingMaskIntoConstraints:NO];
+        [contentView addSubview:bgView];
+        NSArray *constraints = @[
+            [[bgView leadingAnchor] constraintEqualToAnchor:[contentView 
leadingAnchor] constant:6.0],
+            [[contentView trailingAnchor] constraintEqualToAnchor:[bgView 
trailingAnchor] constant:6.0],
+            [[bgView topAnchor] constraintEqualToAnchor:[contentView 
topAnchor] constant:24.0],
+            [[contentView bottomAnchor] constraintEqualToAnchor:[bgView 
bottomAnchor] constant:6.0]];
+        [NSLayoutConstraint activateConstraints:constraints];
+        
+        previewView = [[SKPDFPageView alloc] init];
+        [previewView setTransitionController:[[SKTransitionController alloc] 
init]];
+        [[previewView transitionController] setShouldScale:YES];
+        [bgView addSubviewWithConstraints:previewView];
+    }
+    
+    [previewView setPage:[[controller pdfDocument] pageAtIndex:idx]];
+    [[previewView transitionController] setTransition:info];
+    
+    [previewWindow setTitle:[SKTransitionController 
localizedNameForStyle:[info transitionStyle]]];
+    [previewWindow setFrame:rect display:NO];
+    [previewWindow center];
+    [previewWindow setLevel:[[self window] level]];
+    [previewWindow makeKeyAndOrderFront:nil];
+    
+    [previewView performSelector:@selector(goToNextPage:) withObject:nil 
afterDelay:1.0];
+    [previewWindow performSelector:@selector(orderOut:) withObject:nil 
afterDelay:2.0 + [info duration]];
+}
+
 - (void)setSeparate:(BOOL)newSeparate {
     if (separate != newSeparate) {
         separate = newSeparate;
@@ -308,6 +385,8 @@
             }
         }
         [[[self undoManager] prepareWithInvocationTarget:self] 
setSeparate:separate == NO];
+        
+        [self validatePreviewButton];
     }
 }
 
@@ -398,6 +477,9 @@
             [changedTransitions addObject:object];
         }
         
+        if ([keyPath isEqualToString:TRANSITIONSTYLE_KEY])
+            [self validatePreviewButton];
+        
         [[[self undoManager] prepareWithInvocationTarget:self] 
setValue:oldValue forKey:keyPath ofTransition:object];
     } else {
         [super observeValueForKeyPath:keyPath ofObject:object change:change 
context:context];
@@ -477,6 +559,10 @@
     return [tv makeViewWithIdentifier:[tableColumn identifier] owner:self];
 }
 
+- (void)tableViewSelectionDidChange:(NSNotification *)notification {
+    [self validatePreviewButton];
+}
+
 - (id <SKImageToolTipContext>)tableView:(NSTableView *)tv 
imageContextForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row  
scale:(CGFloat *)scale {
     if ([[tableColumn identifier] isEqualToString:IMAGE_COLUMNID])
         return [[controller pdfDocument] pageAtIndex:row];

Modified: trunk/SKPresentationView.h
===================================================================
--- trunk/SKPresentationView.h  2024-09-23 15:59:17 UTC (rev 14472)
+++ trunk/SKPresentationView.h  2024-09-23 16:03:13 UTC (rev 14473)
@@ -45,10 +45,24 @@
 
 @class PDFPage, SKTransitionController, SKNavigationWindow, 
SKCursorStyleWindow;
 
-@interface SKPresentationView : NSView {
+@interface SKPDFPageView : NSView {
     NSView *pageView;
     PDFPage *page;
     SKTransitionController *transitionController;
+}
+
+@property (nonatomic, nullable, strong) PDFPage *page;
+
+@property (nonatomic, nullable, strong) SKTransitionController 
*transitionController;
+
+- (void)goToNextPage:(nullable id)sender;
+- (void)goToPreviousPage:(nullable id)sender;
+
+@end
+
+#pragma mark -
+
+@interface SKPresentationView : SKPDFPageView {
     SKNavigationWindow *navWindow;
     SKCursorStyleWindow *cursorWindow;
     NSInteger laserPointerColor;
@@ -66,8 +80,6 @@
     
 }
 
-@property (nonatomic, nullable, strong) PDFPage *page;
-
 @property (nonatomic) BOOL autoScales;
 
 @property (nonatomic) BOOL canGoToNextPage;
@@ -81,10 +93,6 @@
 @property (nonatomic) BOOL removeCursorShadow;
 @property (nonatomic) BOOL drawInPresentation;
 
-@property (nonatomic, nullable, strong) SKTransitionController 
*transitionController;
-
-- (void)goToNextPage:(nullable id)sender;
-- (void)goToPreviousPage:(nullable id)sender;
 - (void)goToFirstPage:(nullable id)sender;
 - (void)goToLastPage:(nullable id)sender;
 

Modified: trunk/SKPresentationView.m
===================================================================
--- trunk/SKPresentationView.m  2024-09-23 15:59:17 UTC (rev 14472)
+++ trunk/SKPresentationView.m  2024-09-23 16:03:13 UTC (rev 14473)
@@ -78,30 +78,13 @@
 
 static NSInteger navigationMode = SKNavigationBottom;
 
-@interface SKPresentationView () <CALayerDelegate>
-
-- (void)setCursorForMouse:(NSEvent *)theEvent;
-- (void)setCursorAndAutoHide;
-- (void)doAutoHideCursor;
-- (void)doAutoHide;
-- (void)showNavWindow;
-
-- (void)doDragWindowWithEvent:(NSEvent *)theEvent;
-- (void)doDrawFreehandNoteWithEvent:(NSEvent *)theEvent;
-- (void)showHelpMenu;
-
+@interface SKPDFPageView () <CALayerDelegate>
 @end
 
-@implementation SKPresentationView
+@implementation SKPDFPageView
 
 @synthesize page, transitionController;
-@dynamic autoScales, canGoToNextPage, canGoToPreviousPage, canGoToFirstPage, 
canGoToLastPage, cursorStyle, hasBlackout, removeCursorShadow, 
drawInPresentation;
 
-+ (void)initialize {
-    SKINITIALIZE;
-    navigationMode = [[NSUserDefaults standardUserDefaults] 
integerForKey:SKPresentationNavigationOptionKey];
-}
-
 static inline NSArray *defaultKeysToObserve() {
     if (@available(macOS 10.14, *))
         return @[SKInvertColorsInDarkModeKey, SKSepiaToneKey, SKWhitePointKey];
@@ -112,12 +95,6 @@
 - (instancetype)initWithFrame:(NSRect)frameRect {
     self = [super initWithFrame:frameRect];
     if (self) {
-        pvFlags.autoScales = YES;
-        pvFlags.cursorHidden = NO;
-        pvFlags.useArrowCursor = [[NSUserDefaults standardUserDefaults] 
boolForKey:SKUseArrowCursorInPresentationKey];
-        pvFlags.removeLaserPointerShadow = [[NSUserDefaults 
standardUserDefaults] boolForKey:SKRemoveLaserPointerShadowKey];
-        pvFlags.enableDrawing = NO == [[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableDrawingInPresentationKey];
-        
         page = nil;
         
         CALayer *layer = [CALayer layer];
@@ -134,8 +111,6 @@
         
         [self setTranslatesAutoresizingMaskIntoConstraints:NO];
         
-        [self addTrackingArea:[[NSTrackingArea alloc] initWithRect:NSZeroRect 
options:NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | 
NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect owner:self userInfo:nil]];
-        
         NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
         for (NSString *key in defaultKeysToObserve())
             [sud addObserver:self forKeyPath:key options:0 
context:&SKPresentationViewDefaultsObservationContext];
@@ -167,10 +142,6 @@
 
 #pragma mark Accessors
 
-- (BOOL)canBecomeKeyView {
-    return YES;
-}
-
 - (void)setNeedsDisplay:(BOOL)needsDisplay {
     [super setNeedsDisplay:needsDisplay];
     [pageView setNeedsDisplay:needsDisplay];
@@ -181,18 +152,6 @@
     [pageView setNeedsDisplay:YES];
 }
 
-- (BOOL)autoScales {
-    return pvFlags.autoScales;
-}
-
-- (void)setAutoScales:(BOOL)flag {
-    if (flag != pvFlags.autoScales) {
-        pvFlags.autoScales = flag;
-        [pageView setNeedsDisplay:YES];
-        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPresentationViewAutoScalesChangedNotification 
object:self];
-    }
-}
-
 - (void)setPage:(PDFPage *)newPage {
     if (newPage != page) {
         page = newPage;
@@ -201,9 +160,7 @@
     }
 }
 
-- (BOOL)hasBlackout {
-    return [pageView alphaValue] <= 0.0;
-}
+- (BOOL)autoScales { return YES; }
 
 - (void)setTransitionController:(SKTransitionController 
*)newTransitionController {
     if (newTransitionController != transitionController) {
@@ -213,42 +170,14 @@
     }
 }
 
-- (BOOL)canGoToNextPage {
-    return [page pageIndex] + 1 < [[page document] pageCount];
-}
+#pragma mark Action
 
-- (BOOL)canGoToPreviousPage {
-    return [page pageIndex] > 0;
-}
-
-- (BOOL)canGoToFirstPage {
-    return [page pageIndex] > 0;
-}
-
-- (BOOL)canGoToLastPage {
-    return [page pageIndex] + 1 < [[page document] pageCount];
-}
-
-- (NSInteger)cursorStyle {
-    return pvFlags.useArrowCursor ? -1 : laserPointerColor;
-}
-
-- (BOOL)removeCursorShadow {
-    return pvFlags.removeLaserPointerShadow;
-}
-
-- (BOOL)drawInPresentation {
-    return pvFlags.enableDrawing;
-}
-
-#pragma mark Actions
-
 - (NSRect)pageRect {
     NSRect bounds = [self bounds];
     NSRect pageRect = [page boundsForBox:kPDFDisplayBoxCropBox];
     if (([page rotation] % 180) != 0)
         pageRect = NSMakeRect(0.0, 0.0, NSHeight(pageRect), NSWidth(pageRect));
-    CGFloat scale = pvFlags.autoScales ? fmin(NSHeight(bounds) / 
NSHeight(pageRect), NSWidth(bounds) / NSWidth(pageRect)) : 1.0;
+    CGFloat scale = [self autoScales] ? fmin(NSHeight(bounds) / 
NSHeight(pageRect), NSWidth(bounds) / NSWidth(pageRect)) : 1.0;
     return NSInsetRect(bounds, 0.5 * (NSWidth(bounds) - scale * 
NSWidth(pageRect)), 0.5 * (NSHeight(bounds) - scale * NSHeight(pageRect)));
 }
 
@@ -287,6 +216,126 @@
     }
 }
 
+#pragma mark CALayer delegate
+
+- (void)drawLayer:(CALayer *)aLayer inContext:(CGContextRef)context {
+    if (page == nil)
+        return;
+    NSRect bounds = [self bounds];
+    NSRect pageRect = [page boundsForBox:kPDFDisplayBoxCropBox];
+    if (([page rotation] % 180) != 0)
+        pageRect = NSMakeRect(0.0, 0.0, NSHeight(pageRect), NSWidth(pageRect));
+    CGFloat scale = [self autoScales] ? fmin(NSHeight(bounds) / 
NSHeight(pageRect), NSWidth(bounds) / NSWidth(pageRect)) : 1.0;
+    pageRect = NSInsetRect(bounds, 0.5 * (NSWidth(bounds) - scale * 
NSWidth(pageRect)), 0.5 * (NSHeight(bounds) - scale * NSHeight(pageRect)));
+    CGContextSaveGState(context);
+    CGContextSetFillColorWithColor(context, 
CGColorGetConstantColor(kCGColorWhite));
+    CGContextFillRect(context, SKPixelAlignedRect(NSRectToCGRect(pageRect), 
context));
+    CGContextRestoreGState(context);
+    CGContextSaveGState(context);
+    CGContextSetInterpolationQuality(context, [[NSUserDefaults 
standardUserDefaults] integerForKey:SKInterpolationQualityKey] + 1);
+    CGContextTranslateCTM(context, NSMinX(pageRect), NSMinY(pageRect));
+    CGContextScaleCTM(context, scale, scale);
+    [page drawWithBox:kPDFDisplayBoxCropBox toContext:context];
+    CGContextRestoreGState(context);
+}
+
+- (BOOL)layer:(CALayer *)aLayer shouldInheritContentsScale:(CGFloat)newScale 
fromWindow:(NSWindow *)window {
+    return YES;
+}
+
+@end
+
+#pragma mark -
+
+@interface SKPresentationView ()
+
+- (void)setCursorForMouse:(NSEvent *)theEvent;
+- (void)setCursorAndAutoHide;
+- (void)doAutoHideCursor;
+- (void)doAutoHide;
+- (void)showNavWindow;
+
+- (void)doDragWindowWithEvent:(NSEvent *)theEvent;
+- (void)doDrawFreehandNoteWithEvent:(NSEvent *)theEvent;
+- (void)showHelpMenu;
+
+@end
+
+@implementation SKPresentationView
+
+@dynamic autoScales, canGoToNextPage, canGoToPreviousPage, canGoToFirstPage, 
canGoToLastPage, cursorStyle, hasBlackout, removeCursorShadow, 
drawInPresentation;
+
++ (void)initialize {
+    SKINITIALIZE;
+    navigationMode = [[NSUserDefaults standardUserDefaults] 
integerForKey:SKPresentationNavigationOptionKey];
+}
+
+- (instancetype)initWithFrame:(NSRect)frameRect {
+    self = [super initWithFrame:frameRect];
+    if (self) {
+        pvFlags.autoScales = YES;
+        pvFlags.cursorHidden = NO;
+        pvFlags.useArrowCursor = [[NSUserDefaults standardUserDefaults] 
boolForKey:SKUseArrowCursorInPresentationKey];
+        pvFlags.removeLaserPointerShadow = [[NSUserDefaults 
standardUserDefaults] boolForKey:SKRemoveLaserPointerShadowKey];
+        pvFlags.enableDrawing = NO == [[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableDrawingInPresentationKey];
+        
+        [self addTrackingArea:[[NSTrackingArea alloc] initWithRect:NSZeroRect 
options:NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | 
NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect owner:self userInfo:nil]];
+    }
+    return self;
+}
+
+#pragma mark Accessors
+
+- (BOOL)canBecomeKeyView {
+    return YES;
+}
+
+- (BOOL)autoScales {
+    return pvFlags.autoScales;
+}
+
+- (void)setAutoScales:(BOOL)flag {
+    if (flag != pvFlags.autoScales) {
+        pvFlags.autoScales = flag;
+        [pageView setNeedsDisplay:YES];
+        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPresentationViewAutoScalesChangedNotification 
object:self];
+    }
+}
+
+- (BOOL)hasBlackout {
+    return [pageView alphaValue] <= 0.0;
+}
+
+- (BOOL)canGoToNextPage {
+    return [page pageIndex] + 1 < [[page document] pageCount];
+}
+
+- (BOOL)canGoToPreviousPage {
+    return [page pageIndex] > 0;
+}
+
+- (BOOL)canGoToFirstPage {
+    return [page pageIndex] > 0;
+}
+
+- (BOOL)canGoToLastPage {
+    return [page pageIndex] + 1 < [[page document] pageCount];
+}
+
+- (NSInteger)cursorStyle {
+    return pvFlags.useArrowCursor ? -1 : laserPointerColor;
+}
+
+- (BOOL)removeCursorShadow {
+    return pvFlags.removeLaserPointerShadow;
+}
+
+- (BOOL)drawInPresentation {
+    return pvFlags.enableDrawing;
+}
+
+#pragma mark Actions
+
 - (void)goToFirstPage:(id)sender {
     PDFDocument *pdfDoc = [page document];
     NSUInteger idx = [page pageIndex];
@@ -364,7 +413,7 @@
 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
     if ([menuItem action] == @selector(goToNextPage:))
         return [self canGoToNextPage];
-    else if ([menuItem action] == @selector(goToPrerviousPage:))
+    else if ([menuItem action] == @selector(goToPreviousPage:))
         return [self canGoToPreviousPage];
     else if ([menuItem action] == @selector(goToFirstPage:))
         return [self canGoToFirstPage];
@@ -847,31 +896,4 @@
     [super viewDidMoveToWindow];
 }
 
-#pragma mark CALayer delegate
-
-- (void)drawLayer:(CALayer *)aLayer inContext:(CGContextRef)context {
-    if (page == nil)
-        return;
-    NSRect bounds = [self bounds];
-    NSRect pageRect = [page boundsForBox:kPDFDisplayBoxCropBox];
-    if (([page rotation] % 180) != 0)
-        pageRect = NSMakeRect(0.0, 0.0, NSHeight(pageRect), NSWidth(pageRect));
-    CGFloat scale = pvFlags.autoScales ? fmin(NSHeight(bounds) / 
NSHeight(pageRect), NSWidth(bounds) / NSWidth(pageRect)) : 1.0;
-    pageRect = NSInsetRect(bounds, 0.5 * (NSWidth(bounds) - scale * 
NSWidth(pageRect)), 0.5 * (NSHeight(bounds) - scale * NSHeight(pageRect)));
-    CGContextSaveGState(context);
-    CGContextSetFillColorWithColor(context, 
CGColorGetConstantColor(kCGColorWhite));
-    CGContextFillRect(context, SKPixelAlignedRect(NSRectToCGRect(pageRect), 
context));
-    CGContextRestoreGState(context);
-    CGContextSaveGState(context);
-    CGContextSetInterpolationQuality(context, [[NSUserDefaults 
standardUserDefaults] integerForKey:SKInterpolationQualityKey] + 1);
-    CGContextTranslateCTM(context, NSMinX(pageRect), NSMinY(pageRect));
-    CGContextScaleCTM(context, scale, scale);
-    [page drawWithBox:kPDFDisplayBoxCropBox toContext:context];
-    CGContextRestoreGState(context);
-}
-
-- (BOOL)layer:(CALayer *)aLayer shouldInheritContentsScale:(CGFloat)newScale 
fromWindow:(NSWindow *)window {
-    return YES;
-}
-
 @end

Modified: trunk/SKTransitionController.h
===================================================================
--- trunk/SKTransitionController.h      2024-09-23 15:59:17 UTC (rev 14472)
+++ trunk/SKTransitionController.h      2024-09-23 16:03:13 UTC (rev 14473)
@@ -48,6 +48,7 @@
     NSWindow *window;
     __weak NSView *view;
     BOOL animating;
+    BOOL shouldScale;
     
     SKTransitionInfo *transition;
     NSArray<NSDictionary<NSString *, id> *> *pageTransitions;
@@ -59,6 +60,8 @@
 
 @property (class, nonatomic, readonly) NSArray<NSString *> *transitionNames;
 
+@property (nonatomic) BOOL shouldScale;
+
 + (NSString *)nameForStyle:(SKTransitionStyle)style;
 + (SKTransitionStyle)styleForName:(NSString *)name;
 

Modified: trunk/SKTransitionController.m
===================================================================
--- trunk/SKTransitionController.m      2024-09-23 15:59:17 UTC (rev 14472)
+++ trunk/SKTransitionController.m      2024-09-23 16:03:13 UTC (rev 14473)
@@ -158,7 +158,7 @@
 
 @implementation SKTransitionController
 
-@synthesize view, transition, pageTransitions;
+@synthesize view, transition, pageTransitions, shouldScale;
 
 static NSDictionary *oldStyleNames = nil;
 
@@ -445,10 +445,11 @@
         CGRect cgBounds = scaleRect(bounds, imageScale);
         CGRect extent = [currentTransition shouldRestrict] ? cgRect : cgBounds;
         NSString *filterName = [[self class] nameForStyle:[currentTransition 
transitionStyle]];
+        CGFloat scale = shouldScale ? imageScale * NSHeight(bounds) / 
NSHeight([[[view window] screen] frame]) : imageScale;
         CIFilter *transitionFilter = [self transitionFilterWithName:filterName
                                                                rect:cgRect
                                                              extent:extent
-                                                              scale:imageScale
+                                                              scale:scale
                                                             forward:toIndex >= 
fromIndex
                                                        
initialImage:initialImage
                                                          
finalImage:finalImage];

Modified: trunk/de.lproj/TransitionSheet.strings
===================================================================
(Binary files differ)

Modified: trunk/en.lproj/TransitionSheet.strings
===================================================================
(Binary files differ)

Modified: trunk/es.lproj/TransitionSheet.strings
===================================================================
(Binary files differ)

Modified: trunk/fr.lproj/TransitionSheet.strings
===================================================================
(Binary files differ)

Modified: trunk/it.lproj/TransitionSheet.strings
===================================================================
(Binary files differ)

Modified: trunk/ja.lproj/TransitionSheet.strings
===================================================================
(Binary files differ)

Modified: trunk/nl.lproj/TransitionSheet.strings
===================================================================
(Binary files differ)

Modified: trunk/pl.lproj/TransitionSheet.strings
===================================================================
(Binary files differ)

Modified: trunk/ru.lproj/TransitionSheet.strings
===================================================================
(Binary files differ)

Modified: trunk/zh_CN.lproj/TransitionSheet.strings
===================================================================
(Binary files differ)

Modified: trunk/zh_TW.lproj/TransitionSheet.strings
===================================================================
(Binary files differ)

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



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to