Revision: 21060
          http://sourceforge.net/p/bibdesk/svn/21060
Author:   hofman
Date:     2016-09-17 12:22:41 +0000 (Sat, 17 Sep 2016)
Log Message:
-----------
Put zoom popup button for preview views in below the views rather than in the 
scroller when they can auto hide

Modified Paths:
--------------
    trunk/bibdesk/BDSKColoredView.m
    trunk/bibdesk/BDSKPreviewer.h
    trunk/bibdesk/BDSKPreviewer.m
    trunk/bibdesk/BDSKZoomablePDFView.m
    trunk/bibdesk/BDSKZoomableTextView.m
    trunk/bibdesk/BibDocument_UI.m
    trunk/bibdesk/NSScrollView_BDSKExtensions.h
    trunk/bibdesk/NSScrollView_BDSKExtensions.m

Modified: trunk/bibdesk/BDSKColoredView.m
===================================================================
--- trunk/bibdesk/BDSKColoredView.m     2016-09-16 06:23:42 UTC (rev 21059)
+++ trunk/bibdesk/BDSKColoredView.m     2016-09-17 12:22:41 UTC (rev 21060)
@@ -66,10 +66,12 @@
 }
 
 - (void)drawRect:(NSRect)rect {
-       [NSGraphicsContext saveGraphicsState];
-    [backgroundColor set];
-    NSRectFill(rect);
-       [NSGraphicsContext restoreGraphicsState];
+    if (backgroundColor) {
+        [NSGraphicsContext saveGraphicsState];
+        [backgroundColor setFill];
+        [NSBezierPath fillRect:rect];
+        [NSGraphicsContext restoreGraphicsState];
+    }
     [super drawRect:rect];
 }
 

Modified: trunk/bibdesk/BDSKPreviewer.h
===================================================================
--- trunk/bibdesk/BDSKPreviewer.h       2016-09-16 06:23:42 UTC (rev 21059)
+++ trunk/bibdesk/BDSKPreviewer.h       2016-09-17 12:22:41 UTC (rev 21060)
@@ -77,6 +77,7 @@
 + (BDSKPreviewer *)sharedPreviewer;
 
 - (PDFView *)pdfView;
+- (NSView *)pdfContentView;
 - (BDSKOverlayPanel *)progressOverlay;
 
 - (CGFloat)PDFScaleFactor;

Modified: trunk/bibdesk/BDSKPreviewer.m
===================================================================
--- trunk/bibdesk/BDSKPreviewer.m       2016-09-16 06:23:42 UTC (rev 21059)
+++ trunk/bibdesk/BDSKPreviewer.m       2016-09-17 12:22:41 UTC (rev 21060)
@@ -187,6 +187,12 @@
     return pdfView;
 }
 
+- (NSView *)pdfContentView;
+{
+    [self window];
+    return [[[[tabView tabViewItemAtIndex:BDSKPreviewerTabIndexPDF] view] 
subviews] firstObject];
+}
+
 - (BDSKOverlayPanel *)progressOverlay;
 {
     [self window];

Modified: trunk/bibdesk/BDSKZoomablePDFView.m
===================================================================
--- trunk/bibdesk/BDSKZoomablePDFView.m 2016-09-16 06:23:42 UTC (rev 21059)
+++ trunk/bibdesk/BDSKZoomablePDFView.m 2016-09-17 12:22:41 UTC (rev 21060)
@@ -42,6 +42,8 @@
 #import "NSScrollView_BDSKExtensions.h"
 #import "NSView_BDSKExtensions.h"
 #import "BDSKHighlightingPopUpButton.h"
+#import "BDSKCollapsibleView.h"
+#import "BDSKColoredView.h"
 
 
 @interface BDSKZoomablePDFView (BDSKPrivate)
@@ -60,33 +62,22 @@
 #define BDSKMinDefaultScaleMenuFactor (BDSKDefaultScaleMenuFactors[1])
 #define BDSKDefaultScaleMenuFactorsCount (sizeof(BDSKDefaultScaleMenuFactors) 
/ sizeof(CGFloat))
 
-#define BDSKScaleMenuFontSize ((CGFloat)11.0)
+#define BDSKScaleMenuFontSize 10.0
+#define BDSKScaleMenuHeight 15.0
+#define BDSKScaleMenuWidthOffset 20.0
 
 #pragma mark Instance methods
 
-- (id)initWithFrame:(NSRect)frameRect {
-    self = [super initWithFrame:frameRect];
-    if (self) {
-        scalePopUpButton = nil;
-        [self makeScalePopUpButton];
-    }
-    return self;
-}
-
-- (id)initWithCoder:(NSCoder *)decoder {
-    self = [super initWithCoder:decoder];
-    if (self) {
-        scalePopUpButton = nil;
-        [self makeScalePopUpButton];
-    }
-    return self;
-}
-
 - (void)dealloc {
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
     BDSKDESTROY(scalePopUpButton);
     [super dealloc];
 }
 
+- (void)awakeFromNib {
+    [self makeScalePopUpButton];
+}
+
 - (IBAction)printSelection:(id)sender {
     NSPrintInfo *printInfo = [[[[self window] windowController] document] 
printInfo];
     if (printInfo == nil)
@@ -208,14 +199,13 @@
     
 #pragma mark Popup button
 
-static void sizePopUpToItemAtIndex(NSPopUpButton *popUpButton, NSUInteger 
anIndex) {
-    NSUInteger i = [popUpButton indexOfSelectedItem];
-    [popUpButton selectItemAtIndex:anIndex];
-    [popUpButton sizeToFit];
-    NSSize frameSize = [popUpButton frame].size;
-    frameSize.width -= 22.0 + 2 * [[popUpButton cell] controlSize];
-    [popUpButton setFrameSize:frameSize];
-    [popUpButton selectItemAtIndex:i];
+- (void)handleScrollerStyleDidChange:(NSNotification *)notification {
+    NSView *view = [self superview];
+    if ([view respondsToSelector:@selector(setBackgroundColor:)]) {
+        CGFloat white = [NSScroller preferredScrollerStyle] == 
NSScrollerStyleLegacy ? 0.97 : 1.0;
+        [(BDSKColoredView *)view setBackgroundColor:[NSColor 
colorWithCalibratedWhite:white alpha:1.0]];
+        [view setNeedsDisplay:YES];
+    }
 }
 
 - (void)makeScalePopUpButton {
@@ -223,20 +213,18 @@
     if (scalePopUpButton == nil) {
         
         NSScrollView *scrollView = [self scrollView];
-        [scrollView setHasHorizontalScroller:YES];
         
         // create it        
         scalePopUpButton = [[BDSKHighlightingPopUpButton allocWithZone:[self 
zone]] initWithFrame:NSMakeRect(0.0, 0.0, 1.0, 1.0) pullsDown:NO];
         
-        NSControlSize controlSize = [[scrollView horizontalScroller] 
controlSize];
-        [[scalePopUpButton cell] setControlSize:controlSize];
+        [[scalePopUpButton cell] setControlSize:NSSmallControlSize];
                [scalePopUpButton setBordered:NO];
                [scalePopUpButton setEnabled:YES];
                [scalePopUpButton setRefusesFirstResponder:YES];
                [[scalePopUpButton cell] setUsesItemFromMenu:YES];
         
         // set a suitable font, the control size is 0, 1 or 2
-        [scalePopUpButton setFont:[NSFont toolTipsFontOfSize: 
BDSKScaleMenuFontSize - controlSize]];
+        [scalePopUpButton setFont:[NSFont 
toolTipsFontOfSize:BDSKScaleMenuFontSize]];
         
         NSUInteger cnt, numberOfDefaultItems = 
BDSKDefaultScaleMenuFactorsCount;
         id curItem;
@@ -258,15 +246,18 @@
             curItem = [scalePopUpButton itemAtIndex:cnt];
             [curItem setRepresentedObject:(BDSKDefaultScaleMenuFactors[cnt] > 
0.0 ? [NSNumber numberWithDouble:BDSKDefaultScaleMenuFactors[cnt]] : nil)];
         }
+        
+        // Make sure the popup is big enough to fit the largest cell
+        [scalePopUpButton selectItemAtIndex:maxIndex];
+        [scalePopUpButton sizeToFit];
+        [scalePopUpButton setFrameSize:NSMakeSize(NSWidth([scalePopUpButton 
frame]) - BDSKScaleMenuWidthOffset, BDSKScaleMenuHeight)];
+        
         // select the appropriate item, adjusting the scaleFactor if necessary
         if([self autoScales])
             [self setScaleFactor:0.0 adjustPopup:YES];
         else
             [self setScaleFactor:[self scaleFactor] adjustPopup:YES];
         
-        // Make sure the popup is big enough to fit the largest cell
-        sizePopUpToItemAtIndex(scalePopUpButton, maxIndex);
-        
                // don't let it become first responder
                [scalePopUpButton setRefusesFirstResponder:YES];
         
@@ -274,8 +265,39 @@
         [scalePopUpButton setTarget:self];
         [scalePopUpButton setAction:@selector(scalePopUpAction:)];
         
-        // put it in the scrollview
-        [scrollView setPlacards:[NSArray arrayWithObject:scalePopUpButton]];
+        if ([NSScroller respondsToSelector:@selector(preferredScrollerStyle)]) 
{
+            
+            // on 10.7+, put it in an enclosing collapsible view
+            NSRect popUpRect, pdfRect = [self frame];
+            
+            BDSKCollapsibleView *containerView = [[[BDSKCollapsibleView alloc] 
initWithFrame:pdfRect] autorelease];
+            
+            pdfRect.origin = NSZeroPoint;
+            NSDivideRect(pdfRect, &popUpRect, &pdfRect, 
NSHeight([scalePopUpButton frame]), NSMinYEdge);
+            popUpRect.size.width = NSWidth([scalePopUpButton frame]);
+            
+            [containerView setContentView:[[[BDSKColoredView alloc] init] 
autorelease]];
+            [containerView setMinSize:popUpRect.size];
+            [containerView setAutoresizingMask:NSViewWidthSizable | 
NSViewHeightSizable];
+            [[self superview] addSubview:containerView];
+            
+            [scalePopUpButton setAutoresizingMask:NSViewMaxXMargin | 
NSViewMaxYMargin];
+            [scalePopUpButton setFrame:popUpRect];
+            [containerView addSubview:scalePopUpButton];
+            
+            [self setFrame:pdfRect];
+            [containerView addSubview:self];
+            
+            [self handleScrollerStyleDidChange:nil];
+            [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleScrollerStyleDidChange:) 
name:@"NSPreferredScrollerStyleDidChangeNotification" object:nil];
+            
+        } else {
+            
+            // on 10.6, put it in the scroll view
+            [scrollView setHasHorizontalScroller:YES];
+            [scrollView setPlacards:[NSArray 
arrayWithObject:scalePopUpButton]];
+            
+        }
     }
 }
 

Modified: trunk/bibdesk/BDSKZoomableTextView.m
===================================================================
--- trunk/bibdesk/BDSKZoomableTextView.m        2016-09-16 06:23:42 UTC (rev 
21059)
+++ trunk/bibdesk/BDSKZoomableTextView.m        2016-09-17 12:22:41 UTC (rev 
21060)
@@ -41,6 +41,8 @@
 #import "NSView_BDSKExtensions.h"
 #import "BDSKHighlightingPopUpButton.h"
 #import "NSPrintOperation_BDSKExtensions.h"
+#import "BDSKCollapsibleView.h"
+#import "BDSKColoredView.h"
 
 
 @interface BDSKZoomableTextView (BDSKPrivate)
@@ -59,7 +61,9 @@
 #define BDSKMinDefaultScaleMenuFactor (BDSKDefaultScaleMenuFactors[1])
 #define BDSKDefaultScaleMenuFactorsCount (sizeof(BDSKDefaultScaleMenuFactors) 
/ sizeof(CGFloat))
 
-#define BDSKScaleMenuFontSize ((CGFloat)11.0)
+#define BDSKScaleMenuFontSize 10.0
+#define BDSKScaleMenuHeight 15.0
+#define BDSKScaleMenuWidthOffset 20.0
 
 #pragma mark Instance methods
 
@@ -68,7 +72,6 @@
     if (self) {
                scaleFactor = 1.0;
         pinchZoomFactor = 1.0;
-        [self makeScalePopUpButton];
     }
     return self;
 }
@@ -78,21 +81,16 @@
     if (self) {
                scaleFactor = 1.0;
         pinchZoomFactor = 1.0;
-        [self makeScalePopUpButton];
     }
     return self;
 }
 
 - (void)dealloc {
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
     BDSKDESTROY(scalePopUpButton);
     [super dealloc];
 }
 
-- (void)viewDidMoveToSuperview {
-    [super viewDidMoveToSuperview];
-    [self makeScalePopUpButton];
-}
-
 - (IBAction)printSelection:(id)sender {
     NSPrintInfo *printInfo = [[[[self window] windowController] document] 
printInfo];
     if (printInfo == nil)
@@ -101,32 +99,35 @@
     [printOp runOperationModalForWindow:[self window] delegate:nil 
didRunSelector:NULL contextInfo:NULL];
 }
 
+- (void)awakeFromNib {
+    [self makeScalePopUpButton];
+}
+
 #pragma mark Instance methods - scaling related
 
-static void sizePopUpToItemAtIndex(NSPopUpButton *popUpButton, NSUInteger 
anIndex) {
-    NSUInteger i = [popUpButton indexOfSelectedItem];
-    [popUpButton selectItemAtIndex:anIndex];
-    [popUpButton sizeToFit];
-    NSSize frameSize = [popUpButton frame].size;
-    frameSize.width -= 22.0 + 2 * [[popUpButton cell] controlSize];
-    [popUpButton setFrameSize:frameSize];
-    [popUpButton selectItemAtIndex:i];
+- (void)handleScrollerStyleDidChange:(NSNotification *)notification {
+    NSView *view = [[self enclosingScrollView] superview];
+    if ([view respondsToSelector:@selector(setBackgroundColor:)]) {
+        CGFloat white = [NSScroller preferredScrollerStyle] == 
NSScrollerStyleLegacy ? 0.97 : 1.0;
+        [(BDSKColoredView *)view setBackgroundColor:[NSColor 
colorWithCalibratedWhite:white alpha:1.0]];
+        [view setNeedsDisplay:YES];
+    }
 }
 
 - (void)makeScalePopUpButton {
-    if (scalePopUpButton == nil && [self enclosingScrollView]) {
-        [[self enclosingScrollView] setHasHorizontalScroller:YES];
+    if (scalePopUpButton == nil) {
+        NSScrollView *scrollView = [self enclosingScrollView];
         
         // create it
         scalePopUpButton = [[BDSKHighlightingPopUpButton allocWithZone:[self 
zone]] initWithFrame:NSMakeRect(0.0, 0.0, 1.0, 1.0) pullsDown:NO];
-        [[scalePopUpButton cell] setControlSize:[[[self enclosingScrollView] 
horizontalScroller] controlSize]];
+        [[scalePopUpButton cell] setControlSize:NSSmallControlSize];
                [scalePopUpButton setBordered:NO];
                [scalePopUpButton setEnabled:YES];
                [scalePopUpButton setRefusesFirstResponder:YES];
                [[scalePopUpButton cell] setUsesItemFromMenu:YES];
         
         // set a suitable font, the control size is 0, 1 or 2
-        [scalePopUpButton setFont:[NSFont toolTipsFontOfSize: 
BDSKScaleMenuFontSize - [[scalePopUpButton cell] controlSize]]];
+        [scalePopUpButton setFont:[NSFont 
toolTipsFontOfSize:BDSKScaleMenuFontSize]];
                
         NSUInteger cnt, numberOfDefaultItems = 
BDSKDefaultScaleMenuFactorsCount;
         id curItem;
@@ -148,6 +149,12 @@
             curItem = [scalePopUpButton itemAtIndex:cnt];
             [curItem setRepresentedObject:(BDSKDefaultScaleMenuFactors[cnt] > 
0.0 ? [NSNumber numberWithDouble:BDSKDefaultScaleMenuFactors[cnt]] : nil)];
         }
+        
+        // Make sure the popup is big enough to fit the largest cell
+        [scalePopUpButton selectItemAtIndex:maxIndex];
+        [scalePopUpButton sizeToFit];
+        [scalePopUpButton setFrameSize:NSMakeSize(NSWidth([scalePopUpButton 
frame]) - BDSKScaleMenuWidthOffset, BDSKScaleMenuHeight)];
+        
         // select the appropriate item, adjusting the scaleFactor if necessary
                [self setScaleFactor:scaleFactor adjustPopup:YES];
         
@@ -155,14 +162,41 @@
         [scalePopUpButton setTarget:self];
         [scalePopUpButton setAction:@selector(scalePopUpAction:)];
         
-        // Make sure the popup is big enough to fit the largest cell
-        sizePopUpToItemAtIndex(scalePopUpButton, maxIndex);
-        
                // don't let it become first responder
                [scalePopUpButton setRefusesFirstResponder:YES];
         
-        // put it in the scrollview
-        [[self enclosingScrollView] setPlacards:[NSArray 
arrayWithObject:scalePopUpButton]];
+        if ([NSScroller respondsToSelector:@selector(preferredScrollerStyle)]) 
{
+            
+            // on 10.7+, put it in an enclosing collapsible view
+            NSRect popUpRect, scrollViewRect = [scrollView frame];
+            BDSKCollapsibleView *containerView = [[[BDSKCollapsibleView alloc] 
initWithFrame:scrollViewRect] autorelease];
+            
+            scrollViewRect.origin = NSZeroPoint;
+            NSDivideRect(scrollViewRect, &popUpRect, &scrollViewRect, 
NSHeight([scalePopUpButton frame]), NSMinYEdge);
+            popUpRect.size.width = NSWidth([scalePopUpButton frame]);
+            
+            [containerView setContentView:[[[BDSKColoredView alloc] init] 
autorelease]];
+            [containerView setMinSize:popUpRect.size];
+            [containerView setAutoresizingMask:NSViewWidthSizable | 
NSViewHeightSizable];
+            [[scrollView superview] addSubview:containerView];
+            
+            [scalePopUpButton setAutoresizingMask:NSViewMaxXMargin | 
NSViewMaxYMargin];
+            [scalePopUpButton setFrame:popUpRect];
+            [containerView addSubview:scalePopUpButton];
+            
+            [scrollView setFrame:scrollViewRect];
+            [containerView addSubview:scrollView];
+            
+            [self handleScrollerStyleDidChange:nil];
+            [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleScrollerStyleDidChange:) 
name:@"NSPreferredScrollerStyleDidChangeNotification" object:nil];
+            
+        } else {
+            
+            // on 10.6, put it in the scroll view
+            [scrollView setHasHorizontalScroller:YES];
+            [scrollView setPlacards:[NSArray 
arrayWithObject:scalePopUpButton]];
+            
+        }
     }
 }
 

Modified: trunk/bibdesk/BibDocument_UI.m
===================================================================
--- trunk/bibdesk/BibDocument_UI.m      2016-09-16 06:23:42 UTC (rev 21059)
+++ trunk/bibdesk/BibDocument_UI.m      2016-09-17 12:22:41 UTC (rev 21060)
@@ -204,7 +204,7 @@
         previewer = [[BDSKPreviewer alloc] init];
         NSDictionary *xatrrDefaults = [self 
mainWindowSetupDictionaryFromExtendedAttributes];
         [previewer setPDFScaleFactor:[xatrrDefaults 
doubleForKey:BDSKPreviewPDFScaleFactorKey defaultValue:0.0]];
-        [[bottomPreviewTabView tabViewItemAtIndex:BDSKPreviewDisplayTeX] 
setView:[previewer pdfView]];
+        [[bottomPreviewTabView tabViewItemAtIndex:BDSKPreviewDisplayTeX] 
setView:[previewer pdfContentView]];
     }
     
     [[previewer progressOverlay] overlayView:bottomPreviewTabView];

Modified: trunk/bibdesk/NSScrollView_BDSKExtensions.h
===================================================================
--- trunk/bibdesk/NSScrollView_BDSKExtensions.h 2016-09-16 06:23:42 UTC (rev 
21059)
+++ trunk/bibdesk/NSScrollView_BDSKExtensions.h 2016-09-17 12:22:41 UTC (rev 
21060)
@@ -45,3 +45,19 @@
 - (void)setPlacards:(NSArray *)newPlacards;
 
 @end
+
+#if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < 
MAC_OS_X_VERSION_10_7
+
+enum {
+    NSScrollerStyleLegacy,
+    NSScrollerStyleOverlay
+};
+typedef NSInteger NSScrollerStyle;
+
+@interface NSScroller (BDSKLionDeclarations)
++ (NSScrollerStyle)preferredScrollerStyle;
+- (NSScrollerStyle)scrollerStyle;
+- (void)setScrollerStyle:(NSScrollerStyle)newScrollerStyle;
+@end
+
+#endif

Modified: trunk/bibdesk/NSScrollView_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/NSScrollView_BDSKExtensions.m 2016-09-16 06:23:42 UTC (rev 
21059)
+++ trunk/bibdesk/NSScrollView_BDSKExtensions.m 2016-09-17 12:22:41 UTC (rev 
21060)
@@ -40,22 +40,7 @@
 #import "BDSKRuntime.h"
 #import "NSView_BDSKExtensions.h"
 
-#if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < 
MAC_OS_X_VERSION_10_7
 
-enum {
-   NSScrollerStyleLegacy,
-   NSScrollerStyleOverlay
-};
-typedef NSInteger NSScrollerStyle;
-
-@interface NSScroller (BDSKLionDeclarations)
-+ (NSScrollerStyle)preferredScrollerStyle;
-- (NSScrollerStyle)scrollerStyle;
-- (void)setScrollerStyle:(NSScrollerStyle)newScrollerStyle;
-@end
-
-#endif
-
 @interface BDSKPlacardView : NSView
 - (void)tile;
 @end

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