Revision: 12492
          http://sourceforge.net/p/skim-app/code/12492
Author:   hofman
Date:     2021-10-31 15:59:51 +0000 (Sun, 31 Oct 2021)
Log Message:
-----------
Use auto layout for main pdfview

Modified Paths:
--------------
    trunk/SKMainWindowController.m
    trunk/SKMainWindowController_FullScreen.m

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2021-10-31 15:29:44 UTC (rev 12491)
+++ trunk/SKMainWindowController.m      2021-10-31 15:59:51 UTC (rev 12492)
@@ -387,7 +387,7 @@
     
     // we need to create the PDFView before setting the toolbar
     pdfView = [[SKPDFView alloc] initWithFrame:[pdfContentView bounds]];
-    [pdfView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+    [pdfView setTranslatesAutoresizingMaskIntoConstraints:NO];
     
     if ([pdfView maximumScaleFactor] < 20.0 && [pdfView 
respondsToSelector:NSSelectorFromString(@"setMaxScaleFactor:")])
         [pdfView setValue:[NSNumber numberWithDouble:20.0] 
forKey:@"maxScaleFactor"];
@@ -471,7 +471,11 @@
         [leftSideController.button setEnabled:NO 
forSegment:SKSidePaneStateOutline];
     
     // Due to a bug in Leopard we should only resize and swap in the PDFView 
after loading the PDFDocument
-    [pdfView setFrame:[pdfContentView bounds]];
+    NSArray *constraints = [NSArray arrayWithObjects:
+        [NSLayoutConstraint constraintWithItem:pdfView 
attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual 
toItem:pdfContentView attribute:NSLayoutAttributeLeading multiplier:1.0 
constant:0.0],
+        [NSLayoutConstraint constraintWithItem:pdfContentView 
attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual 
toItem:pdfView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0],
+        [NSLayoutConstraint constraintWithItem:pdfView 
attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual 
toItem:pdfContentView attribute:NSLayoutAttributeTop multiplier:1.0 
constant:0.0],
+        [NSLayoutConstraint constraintWithItem:pdfContentView 
attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual 
toItem:pdfView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], 
nil];
     if ([[pdfView document] isLocked]) {
         // PDFView has the annoying habit for the password view to force a 
full window display
         CGFloat leftWidth = [self leftSideWidth];
@@ -478,10 +482,11 @@
         CGFloat rightWidth = [self rightSideWidth];
         [self applyLeftSideWidth:0.0 rightSideWidth:0.0];
         [pdfContentView addSubview:pdfView];
-        [pdfView setFrame:[pdfContentView bounds]];
+        [NSLayoutConstraint activateConstraints:constraints];
         [self applyLeftSideWidth:leftWidth rightSideWidth:rightWidth];
     } else {
         [pdfContentView addSubview:pdfView];
+        [NSLayoutConstraint activateConstraints:constraints];
     }
     
     // get the initial display mode from the PDF if present and not overridden 
by an explicit setup
@@ -1125,7 +1130,6 @@
             CGFloat leftWidth = [self leftSideWidth];
             CGFloat rightWidth = [self rightSideWidth];
             [pdfView setDocument:document];
-            [pdfView setFrame:[pdfContentView bounds]];
             [self applyLeftSideWidth:leftWidth rightSideWidth:rightWidth];
         } else {
             NSArray *cropBoxes = [savedNormalSetup objectForKey:CROPBOXES_KEY];
@@ -1725,17 +1729,12 @@
     
     NSView *newView = [self interactionMode] == SKPresentationMode ? pdfView : 
splitView;
     NSView *contentView = [overviewContentView superview];
-    NSArray *constraints = nil;
+    NSArray *constraints = [NSArray arrayWithObjects:
+        [NSLayoutConstraint constraintWithItem:newView 
attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual 
toItem:contentView attribute:NSLayoutAttributeLeading multiplier:1.0 
constant:0.0],
+        [NSLayoutConstraint constraintWithItem:contentView 
attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual 
toItem:newView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0],
+        [NSLayoutConstraint constraintWithItem:newView 
attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual 
toItem:contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0],
+        [NSLayoutConstraint constraintWithItem:contentView 
attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual 
toItem:newView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], 
nil];
     
-    if (newView == splitView)
-        constraints = [NSArray arrayWithObjects:
-            [NSLayoutConstraint constraintWithItem:newView 
attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual 
toItem:contentView attribute:NSLayoutAttributeLeading multiplier:1.0 
constant:0.0],
-            [NSLayoutConstraint constraintWithItem:contentView 
attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual 
toItem:newView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0],
-            [NSLayoutConstraint constraintWithItem:newView 
attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual 
toItem:contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0],
-            [NSLayoutConstraint constraintWithItem:contentView 
attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual 
toItem:newView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], 
nil];
-    else
-        [newView setFrame:[overviewContentView frame]];
-    
     if (animate) {
         BOOL hasLayer = [contentView wantsLayer] || [contentView layer] != nil;
         if (hasLayer == NO) {
@@ -1744,8 +1743,7 @@
         }
         [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
                 [[contentView animator] replaceSubview:overviewContentView 
with:newView];
-                if (constraints)
-                    [NSLayoutConstraint activateConstraints:constraints];
+                [NSLayoutConstraint activateConstraints:constraints];
             }
             completionHandler:^{
                 [touchBarController overviewChanged];
@@ -1757,8 +1755,7 @@
             }];
     } else {
         [contentView replaceSubview:overviewContentView with:newView];
-        if (constraints)
-            [NSLayoutConstraint activateConstraints:constraints];
+        [NSLayoutConstraint activateConstraints:constraints];
         [touchBarController overviewChanged];
         [[self window] makeFirstResponder:pdfView];
         if (handler)

Modified: trunk/SKMainWindowController_FullScreen.m
===================================================================
--- trunk/SKMainWindowController_FullScreen.m   2021-10-31 15:29:44 UTC (rev 
12491)
+++ trunk/SKMainWindowController_FullScreen.m   2021-10-31 15:59:51 UTC (rev 
12492)
@@ -293,11 +293,17 @@
 - (void)fadeInFullScreenView {
     SKFullScreenWindow *fullScreenWindow = (SKFullScreenWindow *)[self window];
     SKFullScreenWindow *fadeWindow = [[[SKFullScreenWindow alloc] 
initWithScreen:[fullScreenWindow screen] level:[fullScreenWindow level] 
isMain:NO] autorelease];
+    NSView *contentView = [fullScreenWindow contentView];
+    NSArray *constraints = [NSArray arrayWithObjects:
+        [NSLayoutConstraint constraintWithItem:pdfView 
attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual 
toItem:contentView attribute:NSLayoutAttributeLeading multiplier:1.0 
constant:0.0],
+        [NSLayoutConstraint constraintWithItem:contentView 
attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual 
toItem:pdfView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0],
+        [NSLayoutConstraint constraintWithItem:pdfView 
attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual 
toItem:contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0],
+        [NSLayoutConstraint constraintWithItem:contentView 
attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual 
toItem:pdfView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], 
nil];
     
     [fadeWindow setFrame:[fullScreenWindow frame] display:NO];
     [fadeWindow orderWindow:NSWindowAbove relativeTo:[fullScreenWindow 
windowNumber]];
-    [pdfView setFrame:[[fullScreenWindow contentView] bounds]];
-    [[fullScreenWindow contentView] addSubview:pdfView];
+    [contentView addSubview:pdfView];
+    [NSLayoutConstraint activateConstraints:constraints];
     [pdfView layoutDocumentView];
     [pdfView requiresDisplay];
     [fullScreenWindow makeFirstResponder:pdfView];
@@ -433,6 +439,11 @@
     
     NSColor *backgroundColor = [PDFView defaultBackgroundColor];
     PDFPage *page = [[self pdfView] currentPage];
+    NSArray *constraints = [NSArray arrayWithObjects:
+        [NSLayoutConstraint constraintWithItem:pdfView 
attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual 
toItem:pdfContentView attribute:NSLayoutAttributeLeading multiplier:1.0 
constant:0.0],
+        [NSLayoutConstraint constraintWithItem:pdfContentView 
attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual 
toItem:pdfView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0],
+        [NSLayoutConstraint constraintWithItem:pdfView 
attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual 
toItem:pdfContentView attribute:NSLayoutAttributeTop multiplier:1.0 
constant:0.0],
+        [NSLayoutConstraint constraintWithItem:pdfContentView 
attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual 
toItem:pdfView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], 
nil];
     
     mwcFlags.isSwitchingFullScreen = 1;
     
@@ -447,8 +458,8 @@
     interactionMode = SKNormalMode;
     
     // this should be done before exitPresentationMode to get a smooth 
transition
-    [pdfView setFrame:[pdfContentView bounds]];
     [pdfContentView addSubview:pdfView];
+    [NSLayoutConstraint activateConstraints:constraints];
     [pdfView setBackgroundColor:backgroundColor];
     [secondaryPdfView setBackgroundColor:backgroundColor];
     

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