Revision: 24093
          http://sourceforge.net/p/bibdesk/svn/24093
Author:   hofman
Date:     2019-07-31 11:36:02 +0000 (Wed, 31 Jul 2019)
Log Message:
-----------
move preview zoom controls back to strip below the view

Modified Paths:
--------------
    trunk/bibdesk/BDSKZoomablePDFView.h
    trunk/bibdesk/BDSKZoomablePDFView.m
    trunk/bibdesk/BDSKZoomableTextView.h
    trunk/bibdesk/BDSKZoomableTextView.m

Modified: trunk/bibdesk/BDSKZoomablePDFView.h
===================================================================
--- trunk/bibdesk/BDSKZoomablePDFView.h 2019-07-31 06:30:30 UTC (rev 24092)
+++ trunk/bibdesk/BDSKZoomablePDFView.h 2019-07-31 11:36:02 UTC (rev 24093)
@@ -42,8 +42,6 @@
 
 @interface BDSKZoomablePDFView : PDFView {
     NSPopUpButton *scalePopUpButton;
-    NSView *controlView;
-    NSTrackingArea *trackingArea;
     CGFloat startScale;
 }
 

Modified: trunk/bibdesk/BDSKZoomablePDFView.m
===================================================================
--- trunk/bibdesk/BDSKZoomablePDFView.m 2019-07-31 06:30:30 UTC (rev 24092)
+++ trunk/bibdesk/BDSKZoomablePDFView.m 2019-07-31 11:36:02 UTC (rev 24093)
@@ -72,8 +72,6 @@
 - (void)dealloc {
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     BDSKDESTROY(scalePopUpButton);
-    BDSKDESTROY(controlView);
-    BDSKDESTROY(trackingArea);
     [super dealloc];
 }
 
@@ -202,54 +200,17 @@
     
 #pragma mark Popup button
 
-- (void)handleScrollViewFrameDidChange:(NSNotification *)notification {
-    NSScrollView *scrollView = [self scrollView];
-    if (trackingArea)
-        [scrollView removeTrackingArea:trackingArea];
-    NSRect rect = [scrollView bounds];
-    if (NSHeight(rect) > NSHeight([controlView frame])) {
-        rect = BDSKSliceRect(rect, NSHeight([controlView frame]), [scrollView 
isFlipped] ? NSMinYEdge : NSMaxYEdge);
-        trackingArea = [[NSTrackingArea alloc] initWithRect:rect 
options:NSTrackingActiveInKeyWindow | NSTrackingMouseEnteredAndExited 
owner:self userInfo:nil];
-        [scrollView addTrackingArea:trackingArea];
+- (void)handleScrollerStyleDidChange:(NSNotification *)notification {
+    BDSKColoredView *view = (BDSKColoredView *)[self superview];
+    if ([view respondsToSelector:@selector(setBackgroundColor:)]) {
+        if ([NSScroller preferredScrollerStyle] == NSScrollerStyleLegacy)
+            [view setBackgroundColor:[NSColor 
colorWithCalibratedAquaWhite:0.97 alpha:1.0 darkAquaWhite:0.125 alpha:1.0]];
+        else
+            [view setBackgroundColor:[NSColor controlBackgroundColor]];
+        [view setNeedsDisplay:YES];
     }
 }
 
-- (void)showControlView {
-    NSScrollView *scrollView = [self scrollView];
-    NSRect rect = [scrollView bounds];
-    rect = BDSKSliceRect(rect, NSHeight([controlView frame]), NSMinYEdge);
-    [controlView setFrame:rect];
-    [controlView setAlphaValue:0.0];
-    [scrollView addSubview:controlView positioned:NSWindowAbove 
relativeTo:[[scrollView subviews] lastObject]];
-    [[controlView animator] setAlphaValue:1.0];
-}
-
-- (void)mouseEntered:(NSEvent *)theEvent {
-    if ([[BDSKZoomablePDFView superclass] instancesRespondToSelector:_cmd])
-        [super mouseEntered:theEvent];
-    if (trackingArea && [theEvent trackingArea] == trackingArea) {
-        [self performSelectorOnce:@selector(showControlView) withObject:nil 
afterDelay:0.5];
-    }
-}
-
-- (void)mouseExited:(NSEvent *)theEvent {
-    if ([[BDSKZoomablePDFView superclass] instancesRespondToSelector:_cmd])
-        [super mouseExited:theEvent];
-    if (trackingArea && [theEvent trackingArea] == trackingArea) {
-        [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(showControlView) object:nil];
-        [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
-            [[controlView animator] setAlphaValue:0.0];
-        } completionHandler:^{
-            [controlView removeFromSuperview];
-        }];
-    }
-}
-
-- (void)mouseDown:(NSEvent *)theEvent {
-    [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(showControlView) object:nil];
-    [super mouseDown:theEvent];
-}
-
 - (void)makeScalePopUpButton {
     
     if (scalePopUpButton == nil) {
@@ -307,7 +268,7 @@
         [scalePopUpButton setTarget:self];
         [scalePopUpButton setAction:@selector(scalePopUpAction:)];
         
-        BDSKCollapsibleView *containerView = [[BDSKCollapsibleView alloc] 
initWithFrame:[scalePopUpButton frame]];
+        BDSKCollapsibleView *containerView = [[[BDSKCollapsibleView alloc] 
initWithFrame:[scalePopUpButton frame]] autorelease];
         BDSKColoredView *coloredView = [[[BDSKColoredView alloc] init] 
autorelease];
         
         // @@ Dark mode
@@ -315,14 +276,17 @@
         [coloredView setBackgroundColor:[NSColor 
colorWithCalibratedAquaWhite:0.97 alpha:0.95 darkAquaWhite:0.125 alpha:0.95]];
         [containerView setContentView:coloredView];
         [containerView setMinSize:[containerView frame].size];
-        [containerView setAutoresizingMask:NSViewWidthSizable];
+        [containerView setAutoresizingMask:NSViewWidthSizable | 
NSViewHeightSizable];
         [scalePopUpButton setAutoresizingMask:NSViewMaxXMargin | 
NSViewMaxYMargin];
         [containerView addSubview:scalePopUpButton];
         
-        controlView = containerView;
+        [containerView setFrame:[self frame]];
+        [[self superview] addSubview:containerView];
+        [self setFrame:BDSKShrinkRect([containerView bounds], 
NSHeight([scalePopUpButton frame]), NSMinYEdge)];
+        [containerView addSubview:self];
         
-        [self handleScrollViewFrameDidChange:nil];
-        [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleScrollViewFrameDidChange:) 
name:NSViewFrameDidChangeNotification object:scrollView];
+        [self handleScrollerStyleDidChange:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleScrollerStyleDidChange:) 
name:NSPreferredScrollerStyleDidChangeNotification object:nil];
     }
 }
 

Modified: trunk/bibdesk/BDSKZoomableTextView.h
===================================================================
--- trunk/bibdesk/BDSKZoomableTextView.h        2019-07-31 06:30:30 UTC (rev 
24092)
+++ trunk/bibdesk/BDSKZoomableTextView.h        2019-07-31 11:36:02 UTC (rev 
24093)
@@ -42,7 +42,6 @@
 @interface BDSKZoomableTextView : NSTextView {
     NSPopUpButton *scalePopUpButton;
     NSView *controlView;
-    NSTrackingArea *trackingArea;
     CGFloat scaleFactor;
     CGFloat pinchZoomFactor;
 }

Modified: trunk/bibdesk/BDSKZoomableTextView.m
===================================================================
--- trunk/bibdesk/BDSKZoomableTextView.m        2019-07-31 06:30:30 UTC (rev 
24092)
+++ trunk/bibdesk/BDSKZoomableTextView.m        2019-07-31 11:36:02 UTC (rev 
24093)
@@ -91,8 +91,6 @@
 - (void)dealloc {
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     BDSKDESTROY(scalePopUpButton);
-    BDSKDESTROY(controlView);
-    BDSKDESTROY(trackingArea);
     [super dealloc];
 }
 
@@ -110,54 +108,17 @@
 
 #pragma mark Instance methods - scaling related
 
-- (void)handleScrollViewFrameDidChange:(NSNotification *)notification {
-    NSScrollView *scrollView = [self enclosingScrollView];
-    if (trackingArea)
-        [scrollView removeTrackingArea:trackingArea];
-    NSRect rect = [scrollView bounds];
-    if (NSHeight(rect) > NSHeight([controlView frame])) {
-        rect = BDSKSliceRect(rect, NSHeight([controlView frame]), [scrollView 
isFlipped] ? NSMinYEdge : NSMaxYEdge);
-        trackingArea = [[NSTrackingArea alloc] initWithRect:rect 
options:NSTrackingActiveInKeyWindow | NSTrackingMouseEnteredAndExited 
owner:self userInfo:nil];
-        [scrollView addTrackingArea:trackingArea];
+- (void)handleScrollerStyleDidChange:(NSNotification *)notification {
+    BDSKColoredView *view = (BDSKColoredView *)[[self enclosingScrollView] 
superview];
+    if ([view respondsToSelector:@selector(setBackgroundColor:)]) {
+        if ([NSScroller preferredScrollerStyle] == NSScrollerStyleLegacy)
+            [view setBackgroundColor:[NSColor 
colorWithCalibratedAquaWhite:0.97 alpha:1.0 darkAquaWhite:0.125 alpha:1.0]];
+        else
+            [view setBackgroundColor:[NSColor controlBackgroundColor]];
+        [view setNeedsDisplay:YES];
     }
 }
 
-- (void)showControlView {
-    NSScrollView *scrollView = [self enclosingScrollView];
-    NSRect rect = [scrollView bounds];
-    rect = BDSKSliceRect(rect, NSHeight([controlView frame]), NSMinYEdge);
-    [controlView setFrame:rect];
-    [controlView setAlphaValue:0.0];
-    [scrollView addSubview:controlView positioned:NSWindowAbove 
relativeTo:[[scrollView subviews] lastObject]];
-    [[controlView animator] setAlphaValue:1.0];
-}
-
-- (void)mouseEntered:(NSEvent *)theEvent {
-    if ([[BDSKZoomableTextView superclass] instancesRespondToSelector:_cmd])
-        [super mouseEntered:theEvent];
-    if (trackingArea && [theEvent trackingArea] == trackingArea) {
-        [self performSelectorOnce:@selector(showControlView) withObject:nil 
afterDelay:0.5];
-    }
-}
-
-- (void)mouseExited:(NSEvent *)theEvent {
-    if ([[BDSKZoomableTextView superclass] instancesRespondToSelector:_cmd])
-        [super mouseExited:theEvent];
-    if (trackingArea && [theEvent trackingArea] == trackingArea) {
-        [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(showControlView) object:nil];
-        [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
-                [[controlView animator] setAlphaValue:0.0];
-            } completionHandler:^{
-                [controlView removeFromSuperview];
-            }];
-    }
-}
-
-- (void)mouseDown:(NSEvent *)theEvent {
-    [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(showControlView) object:nil];
-    [super mouseDown:theEvent];
-}
-
 - (void)makeScalePopUpButton {
     if (scalePopUpButton == nil) {
         NSScrollView *scrollView = [self enclosingScrollView];
@@ -209,22 +170,25 @@
                // don't let it become first responder
                [scalePopUpButton setRefusesFirstResponder:YES];
         
-        BDSKCollapsibleView *containerView = [[BDSKCollapsibleView alloc] 
initWithFrame:[scalePopUpButton frame]];
+        BDSKCollapsibleView *containerView = [[[BDSKCollapsibleView alloc] 
initWithFrame:[scalePopUpButton frame]] autorelease];
         BDSKColoredView *coloredView = [[[BDSKColoredView alloc] init] 
autorelease];
         
         // @@ Dark mode
         
-        [coloredView setBackgroundColor:[NSColor 
colorWithCalibratedAquaWhite:0.97 alpha:0.95 darkAquaWhite:0.125 alpha:0.95]];
+        [coloredView setBackgroundColor:[NSColor controlBackgroundColor]];
         [containerView setContentView:coloredView];
         [containerView setMinSize:[containerView frame].size];
-        [containerView setAutoresizingMask:NSViewWidthSizable];
+        [containerView setAutoresizingMask:NSViewWidthSizable | 
NSViewHeightSizable];
         [scalePopUpButton setAutoresizingMask:NSViewMaxXMargin | 
NSViewMaxYMargin];
         [containerView addSubview:scalePopUpButton];
         
-        controlView = containerView;
+        [containerView setFrame:[scrollView frame]];
+        [[scrollView superview] addSubview:containerView];
+        [scrollView setFrame:BDSKShrinkRect([containerView bounds], 
NSHeight([scalePopUpButton frame]), NSMinYEdge)];
+        [containerView addSubview:scrollView];
         
-        [self handleScrollViewFrameDidChange:nil];
-        [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleScrollViewFrameDidChange:) 
name:NSViewFrameDidChangeNotification object:scrollView];
+        [self handleScrollerStyleDidChange:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleScrollerStyleDidChange:) 
name:NSPreferredScrollerStyleDidChangeNotification object:nil];
     }
 }
 

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



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to