Revision: 12506 http://sourceforge.net/p/skim-app/code/12506 Author: hofman Date: 2021-11-02 14:38:19 +0000 (Tue, 02 Nov 2021) Log Message: ----------- convenience method to add constraints for a view relative to the bounds of its superview
Modified Paths: -------------- trunk/NSView_SKExtensions.h trunk/NSView_SKExtensions.m trunk/SKMainWindowController.m trunk/SKMainWindowController_FullScreen.m trunk/SKSideWindow.m Modified: trunk/NSView_SKExtensions.h =================================================================== --- trunk/NSView_SKExtensions.h 2021-11-02 10:33:35 UTC (rev 12505) +++ trunk/NSView_SKExtensions.h 2021-11-02 14:38:19 UTC (rev 12506) @@ -58,4 +58,6 @@ - (NSBitmapImageRep *)bitmapImageRepCachingDisplayInRect:(NSRect)rect; +- (void)activateConstraintsToBoundsOfItem:(id)item; + @end Modified: trunk/NSView_SKExtensions.m =================================================================== --- trunk/NSView_SKExtensions.m 2021-11-02 10:33:35 UTC (rev 12505) +++ trunk/NSView_SKExtensions.m 2021-11-02 14:38:19 UTC (rev 12506) @@ -102,6 +102,15 @@ return imageRep; } +- (void)activateConstraintsToBoundsOfItem:(id)item { + NSArray *constraints = [NSArray arrayWithObjects: + [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:item attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0], + [NSLayoutConstraint constraintWithItem:item attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0], + [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:item attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0], + [NSLayoutConstraint constraintWithItem:item attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], nil]; + [NSLayoutConstraint activateConstraints:constraints]; +} + @end Modified: trunk/SKMainWindowController.m =================================================================== --- trunk/SKMainWindowController.m 2021-11-02 10:33:35 UTC (rev 12505) +++ trunk/SKMainWindowController.m 2021-11-02 14:38:19 UTC (rev 12506) @@ -375,18 +375,10 @@ [pdfContentView setAutoresizesSubviews:YES]; // make sure the first thing we call on the side view controllers is its view so their nib is loaded - NSArray *constraints = [NSArray arrayWithObjects: - [NSLayoutConstraint constraintWithItem:leftSideController.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:leftSideContentView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:leftSideContentView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:leftSideController.view attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:leftSideController.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:leftSideContentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:leftSideContentView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:leftSideController.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:rightSideController.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:rightSideContentView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:rightSideContentView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:rightSideController.view attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:rightSideController.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:rightSideContentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:rightSideContentView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:rightSideController.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], nil]; [leftSideContentView addSubview:leftSideController.view]; + [leftSideController.view activateConstraintsToBoundsOfItem:leftSideContentView]; [rightSideContentView addSubview:rightSideController.view]; - [NSLayoutConstraint activateConstraints:constraints]; + [rightSideController.view activateConstraintsToBoundsOfItem:rightSideContentView]; [self updateTableFont]; @@ -479,11 +471,6 @@ [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 - 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]; @@ -490,11 +477,11 @@ CGFloat rightWidth = [self rightSideWidth]; [self applyLeftSideWidth:0.0 rightSideWidth:0.0]; [pdfContentView addSubview:pdfView]; - [NSLayoutConstraint activateConstraints:constraints]; + [pdfView activateConstraintsToBoundsOfItem:pdfContentView]; [self applyLeftSideWidth:leftWidth rightSideWidth:rightWidth]; } else { [pdfContentView addSubview:pdfView]; - [NSLayoutConstraint activateConstraints:constraints]; + [pdfView activateConstraintsToBoundsOfItem:pdfContentView]; } // get the initial display mode from the PDF if present and not overridden by an explicit setup @@ -1673,11 +1660,6 @@ BOOL isPresentation = [self interactionMode] == SKPresentationMode; NSView *oldView = isPresentation ? pdfView : splitView; NSView *contentView = [oldView superview]; - NSArray *constraints = [NSArray arrayWithObjects: - [NSLayoutConstraint constraintWithItem:overviewContentView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:contentView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:contentView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:overviewContentView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:overviewContentView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:contentView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:overviewContentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], nil]; [overviewContentView setFrame:[oldView frame]]; [overviewView scrollRectToVisible:[overviewView frameForItemAtIndex:[[pdfView currentPage] pageIndex]]]; @@ -1708,7 +1690,7 @@ } [NSAnimationContext runAnimationGroup:^(NSAnimationContext * context){ [[contentView animator] replaceSubview:oldView with:overviewContentView]; - [NSLayoutConstraint activateConstraints:constraints]; + [overviewContentView activateConstraintsToBoundsOfItem:contentView]; } completionHandler:^{ [touchBarController overviewChanged]; @@ -1717,7 +1699,7 @@ }]; } else { [contentView replaceSubview:oldView with:overviewContentView]; - [NSLayoutConstraint activateConstraints:constraints]; + [overviewContentView activateConstraintsToBoundsOfItem:contentView]; } [[self window] makeFirstResponder:overviewView]; if (isPresentation) @@ -1737,11 +1719,6 @@ NSView *newView = [self interactionMode] == SKPresentationMode ? pdfView : splitView; NSView *contentView = [overviewContentView superview]; - 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 (animate) { BOOL hasLayer = [contentView wantsLayer] || [contentView layer] != nil; @@ -1751,7 +1728,7 @@ } [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){ [[contentView animator] replaceSubview:overviewContentView with:newView]; - [NSLayoutConstraint activateConstraints:constraints]; + [newView activateConstraintsToBoundsOfItem:contentView]; } completionHandler:^{ [touchBarController overviewChanged]; @@ -1763,7 +1740,7 @@ }]; } else { [contentView replaceSubview:overviewContentView with:newView]; - [NSLayoutConstraint activateConstraints:constraints]; + [newView activateConstraintsToBoundsOfItem:contentView]; [touchBarController overviewChanged]; [[self window] makeFirstResponder:pdfView]; if (handler) Modified: trunk/SKMainWindowController_FullScreen.m =================================================================== --- trunk/SKMainWindowController_FullScreen.m 2021-11-02 10:33:35 UTC (rev 12505) +++ trunk/SKMainWindowController_FullScreen.m 2021-11-02 14:38:19 UTC (rev 12506) @@ -128,13 +128,8 @@ [leftSideController.topBar setDrawsBackground:YES]; [leftSideController.view setFrame:[leftSideContentView bounds]]; - NSArray *constraints = [NSArray arrayWithObjects: - [NSLayoutConstraint constraintWithItem:leftSideController.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:leftSideContentView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:leftSideContentView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:leftSideController.view attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:leftSideController.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:leftSideContentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:leftSideContentView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:leftSideController.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], nil]; [leftSideContentView addSubview:leftSideController.view]; - [NSLayoutConstraint activateConstraints:constraints]; + [leftSideController.view activateConstraintsToBoundsOfItem:leftSideContentView]; [self setLeftSidePaneState:mwcFlags.savedLeftSidePaneState]; @@ -301,16 +296,11 @@ 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]]; [contentView addSubview:pdfView]; - [NSLayoutConstraint activateConstraints:constraints]; + [pdfView activateConstraintsToBoundsOfItem:contentView]; [pdfView layoutDocumentView]; [pdfView requiresDisplay]; [fullScreenWindow makeFirstResponder:pdfView]; @@ -446,11 +436,6 @@ 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; @@ -466,7 +451,7 @@ // this should be done before exitPresentationMode to get a smooth transition [pdfContentView addSubview:pdfView]; - [NSLayoutConstraint activateConstraints:constraints]; + [pdfView activateConstraintsToBoundsOfItem:pdfContentView]; [pdfView setBackgroundColor:backgroundColor]; [secondaryPdfView setBackgroundColor:backgroundColor]; Modified: trunk/SKSideWindow.m =================================================================== --- trunk/SKSideWindow.m 2021-11-02 10:33:35 UTC (rev 12505) +++ trunk/SKSideWindow.m 2021-11-02 14:38:19 UTC (rev 12506) @@ -43,6 +43,7 @@ #import "NSShadow_SKExtensions.h" #import "NSColor_SKExtensions.h" #import "NSGraphics_SKExtensions.h" +#import "NSView_SKExtensions.h" #define DEFAULT_WINDOW_WIDTH 300.0 #define DEFAULT_WINDOW_HEIGHT 400.0 @@ -101,13 +102,8 @@ mainContentView = [[[NSView alloc] initWithFrame:contentRect] autorelease]; [mainContentView setAutoresizingMask:NSViewMinXMargin | NSViewHeightSizable]; [backgroundView addSubview:mainContentView]; - NSArray *constraints = [NSArray arrayWithObjects: - [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:mainContentView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:mainContentView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:mainContentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0], - [NSLayoutConstraint constraintWithItem:mainContentView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], nil]; [mainContentView addSubview:view]; - [NSLayoutConstraint activateConstraints:constraints]; + [view activateConstraintsToBoundsOfItem:mainContentView]; } return self; } 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