Revision: 2949
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2949&view=rev
Author:   hofman
Date:     2007-09-20 07:18:12 -0700 (Thu, 20 Sep 2007)

Log Message:
-----------
Size scale popup in PDF views to largest item.

Modified Paths:
--------------
    trunk/BDSKZoomablePDFView.m
    trunk/SKSecondaryPDFView.m

Modified: trunk/BDSKZoomablePDFView.m
===================================================================
--- trunk/BDSKZoomablePDFView.m 2007-09-20 13:31:42 UTC (rev 2948)
+++ trunk/BDSKZoomablePDFView.m 2007-09-20 14:18:12 UTC (rev 2949)
@@ -103,18 +103,32 @@
         NSScrollView *scrollView = [self scrollView];
         [scrollView setAlwaysHasHorizontalScroller:YES];
 
-        unsigned cnt, numberOfDefaultItems = 
(sizeof(BDSKDefaultScaleMenuLabels) / sizeof(NSString *));
-        id curItem;
-
         // create it        
         scalePopUpButton = [[BDSKHeaderPopUpButton allocWithZone:[self zone]] 
initWithFrame:NSMakeRect(0.0, 0.0, 1.0, 1.0) pullsDown:NO];
         
         NSControlSize controlSize = [[scrollView horizontalScroller] 
controlSize];
         [[scalePopUpButton cell] setControlSize:controlSize];
                
+        unsigned cnt, numberOfDefaultItems = 
(sizeof(BDSKDefaultScaleMenuLabels) / sizeof(NSString *));
+        id curItem;
+        NSString *label;
+        float width, maxWidth = 0.0;
+        NSSize size = NSMakeSize(1000.0, 1000.0);
+        NSDictionary *attrs = [[scalePopUpButton attributedTitle] 
attributesAtIndex:0 effectiveRange:NULL];
+        unsigned maxIndex = 0;
+
+        // set a suitable font, the control size is 0, 1 or 2
+        [scalePopUpButton setFont:[NSFont toolTipsFontOfSize: 
BDSKScaleMenuFontSize - controlSize]];
+
         // fill it
         for (cnt = 0; cnt < numberOfDefaultItems; cnt++) {
-            [scalePopUpButton 
addItemWithTitle:NSLocalizedStringFromTable(BDSKDefaultScaleMenuLabels[cnt], 
@"ZoomValues", nil)];
+            label = 
NSLocalizedStringFromTable(BDSKDefaultScaleMenuLabels[cnt], @"ZoomValues", nil);
+            width = NSWidth([label boundingRectWithSize:size options:0 
attributes:attrs]);
+            if (width > maxWidth) {
+                maxWidth = width;
+                maxIndex = cnt;
+            }
+            [scalePopUpButton addItemWithTitle:label];
             curItem = [scalePopUpButton itemAtIndex:cnt];
             [curItem setRepresentedObject:(BDSKDefaultScaleMenuFactors[cnt] > 
0.0 ? [NSNumber numberWithFloat:BDSKDefaultScaleMenuFactors[cnt]] : nil)];
         }
@@ -128,11 +142,10 @@
         [scalePopUpButton setTarget:self];
         [scalePopUpButton setAction:@selector(scalePopUpAction:)];
 
-        // set a suitable font, the control size is 0, 1 or 2
-        [scalePopUpButton setFont:[NSFont toolTipsFontOfSize: 
BDSKScaleMenuFontSize - controlSize]];
-
-        // Make sure the popup is big enough to fit the cells.
+        // Make sure the popup is big enough to fit the largest cell
+        [scalePopUpButton setTitle:[[scalePopUpButton itemAtIndex:maxIndex] 
title]];
         [scalePopUpButton sizeToFit];
+        [scalePopUpButton synchronizeTitleAndSelectedItem];
 
                // don't let it become first responder
                [scalePopUpButton setRefusesFirstResponder:YES];

Modified: trunk/SKSecondaryPDFView.m
===================================================================
--- trunk/SKSecondaryPDFView.m  2007-09-20 13:31:42 UTC (rev 2948)
+++ trunk/SKSecondaryPDFView.m  2007-09-20 14:18:12 UTC (rev 2949)
@@ -133,18 +133,32 @@
         NSScrollView *scrollView = [self scrollView];
         [scrollView setAlwaysHasHorizontalScroller:YES];
 
-        unsigned cnt, numberOfDefaultItems = (sizeof(SKDefaultScaleMenuLabels) 
/ sizeof(NSString *));
-        id curItem;
-
         // create it        
         scalePopUpButton = [[BDSKHeaderPopUpButton allocWithZone:[self zone]] 
initWithFrame:NSMakeRect(0.0, 0.0, 1.0, 1.0) pullsDown:NO];
         
         NSControlSize controlSize = [[scrollView horizontalScroller] 
controlSize];
         [[scalePopUpButton cell] setControlSize:controlSize];
+
+        // set a suitable font, the control size is 0, 1 or 2
+        [scalePopUpButton setFont:[NSFont toolTipsFontOfSize: 
SKPopUpMenuFontSize - controlSize]];
+
+        unsigned cnt, numberOfDefaultItems = (sizeof(SKDefaultScaleMenuLabels) 
/ sizeof(NSString *));
+        id curItem;
+        NSString *label;
+        float width, maxWidth = 0.0;
+        NSSize size = NSMakeSize(1000.0, 1000.0);
+        NSDictionary *attrs = [[scalePopUpButton attributedTitle] 
attributesAtIndex:0 effectiveRange:NULL];
+        unsigned maxIndex = 0;
                
         // fill it
         for (cnt = 0; cnt < numberOfDefaultItems; cnt++) {
-            [scalePopUpButton 
addItemWithTitle:NSLocalizedStringFromTable(SKDefaultScaleMenuLabels[cnt], 
@"ZoomValues", nil)];
+            label = NSLocalizedStringFromTable(SKDefaultScaleMenuLabels[cnt], 
@"ZoomValues", nil);
+            width = NSWidth([label boundingRectWithSize:size options:0 
attributes:attrs]);
+            if (width > maxWidth) {
+                maxWidth = width;
+                maxIndex = cnt;
+            }
+            [scalePopUpButton addItemWithTitle:label];
             curItem = [scalePopUpButton itemAtIndex:cnt];
             [curItem setRepresentedObject:(SKDefaultScaleMenuFactors[cnt] > 
0.0 ? [NSNumber numberWithFloat:SKDefaultScaleMenuFactors[cnt]] : nil)];
         }
@@ -158,11 +172,10 @@
         [scalePopUpButton setTarget:self];
         [scalePopUpButton setAction:@selector(scalePopUpAction:)];
 
-        // set a suitable font, the control size is 0, 1 or 2
-        [scalePopUpButton setFont:[NSFont toolTipsFontOfSize: 
SKPopUpMenuFontSize - controlSize]];
-
-        // Make sure the popup is big enough to fit the cells.
+        // Make sure the popup is big enough to fit the largest cell
+        [scalePopUpButton setTitle:[[scalePopUpButton itemAtIndex:maxIndex] 
title]];
         [scalePopUpButton sizeToFit];
+        [scalePopUpButton synchronizeTitleAndSelectedItem];
 
                // don't let it become first responder
                [scalePopUpButton setRefusesFirstResponder:YES];


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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to