Anonymous avatar Anonymous committed b043b63

Adding BWIWorkPopUpButton

Comments (0)

Files changed (4)

BWIWorkPopUpButton.h

+//
+//  BWIWorkPopUpButton.h
+//  BWToolkit
+//
+//  Created by Mike Abdullah on 24/01/2008.
+//  All code is provided under the New BSD license.
+//
+//  Tweaks standard NSPopUpButton to closer match iWork's controls:
+//  -   Pull down arrows on borderless buttons are drawn in bottom right corner
+//  -   Images are given nearly the full cell to draw into
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface BWIWorkPopUpButton : NSPopUpButton
+@end
+
+
+#pragma mark -
+
+
+@interface BWIWorkPopUpButtonCell : NSPopUpButtonCell
+@end

BWIWorkPopUpButton.m

+//
+//  BWIWorkPopUpButton.m
+//  BWToolkit
+//
+//  Created by Mike Abdullah on 24/01/2008.
+//  Pulldown arrow drawing courtesy of Pieter Omvlee.
+//  All code is provided under the New BSD license.
+//
+
+#import "BWIWorkPopUpButton.h"
+
+
+@implementation BWIWorkPopUpButton
+
++ (Class)cellClass { return [BWIWorkPopUpButtonCell class]; }
+
+@end
+
+
+#pragma mark -
+
+
+@implementation BWIWorkPopUpButtonCell
+
+#pragma mark Layout
+
+- (NSRect)imageRectForBounds:(NSRect)theRect;
+{
+    NSRect result = theRect;
+    
+    if ([self isBordered])
+    {
+        result = [super imageRectForBounds:theRect];
+    }
+    else
+    {
+        // Fill entire cell with image, minus the space for popup arrow
+        result.size.width -= 8.0f;
+    }
+    
+    return result;
+}
+
+#pragma mark Drawing
+
+- (NSBezierPath *)arrowBezierInRect:(NSRect)r
+{
+    NSBezierPath *arrow = [NSBezierPath bezierPath];
+    [arrow moveToPoint:NSMakePoint(NSMinX(r), NSMinY(r))];
+    [arrow lineToPoint:NSMakePoint(NSMaxX(r), NSMinY(r))];
+    [arrow lineToPoint:NSMakePoint(NSMidX(r), NSMaxY(r))];
+    
+    return arrow;
+}
+
+- (void)drawBorderAndBackgroundWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
+{
+    // NSPopUpButtonCell doesn't respect NSPopUpArrowAtBottom unless the cell is also bordered. So, we take over drawing to do our own arrow
+    if (![self isBordered] && [self arrowPosition] == NSPopUpArrowAtBottom)
+    {
+        // Draw the arrow right-hand corner, 5px from bottom
+        NSRect arrowRect = NSMakeRect(NSMaxX(cellFrame) - 6,
+                                      NSMaxY(cellFrame) - 9,
+                                      6,
+                                      4);
+        
+        [[NSColor colorWithDeviceWhite:0.2 alpha:1.0] set];
+        [[self arrowBezierInRect:arrowRect] fill];
+    }
+    else
+    {
+        [super drawBorderAndBackgroundWithFrame:cellFrame inView:controlView];
+    }
+}
+
+@end
+
+

BWToolkit.xcodeproj/project.pbxproj

 
 /* Begin PBXBuildFile section */
 		13F8B89007B43554008AE28D /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD92D38A0106425D02CA0E72 /* Cocoa.framework */; };
+		27021FAB11A5477300E77AD7 /* BWIWorkPopUpButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 27021FA911A5477300E77AD7 /* BWIWorkPopUpButton.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		27021FAC11A5477300E77AD7 /* BWIWorkPopUpButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 27021FAA11A5477300E77AD7 /* BWIWorkPopUpButton.m */; };
 		276E2795112CC3C700F58850 /* BWTabViewController.classdescription in Resources */ = {isa = PBXBuildFile; fileRef = 276E2794112CC3C700F58850 /* BWTabViewController.classdescription */; };
 		27AEE321112B4A9300C2648F /* BWTabViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 27AEE31A112B4A6400C2648F /* BWTabViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		27AEE322112B4A9300C2648F /* BWTabViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 27AEE31B112B4A6400C2648F /* BWTabViewController.m */; };
 		CAEE09FE0FD7D4E9001A1C3F /* BWGradientBoxInspector.m in Sources */ = {isa = PBXBuildFile; fileRef = CAEE09FD0FD7D4E9001A1C3F /* BWGradientBoxInspector.m */; };
 		CAEE0A000FD7D544001A1C3F /* BWGradientBoxInspector.xib in Resources */ = {isa = PBXBuildFile; fileRef = CAEE09FF0FD7D544001A1C3F /* BWGradientBoxInspector.xib */; };
 		CAEE0A020FD7D557001A1C3F /* BWGradientBoxIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = CAEE0A010FD7D557001A1C3F /* BWGradientBoxIntegration.m */; };
-		CAF6B8450E049A6500CA1768 /* ButtonBarPullDownArrow.pdf in Resources */ = {isa = PBXBuildFile; fileRef = CAF6B8440E049A6500CA1768 /* ButtonBarPullDownArrow.pdf */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
 		13F8B88807B434F6008AE28D /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
 		13F8B88907B434F6008AE28D /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
 		13F8B88A07B434F6008AE28D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
+		27021FA911A5477300E77AD7 /* BWIWorkPopUpButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BWIWorkPopUpButton.h; sourceTree = "<group>"; };
+		27021FAA11A5477300E77AD7 /* BWIWorkPopUpButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BWIWorkPopUpButton.m; sourceTree = "<group>"; };
 		276E2794112CC3C700F58850 /* BWTabViewController.classdescription */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = BWTabViewController.classdescription; sourceTree = "<group>"; };
 		27AEE31A112B4A6400C2648F /* BWTabViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BWTabViewController.h; sourceTree = "<group>"; };
 		27AEE31B112B4A6400C2648F /* BWTabViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BWTabViewController.m; sourceTree = "<group>"; };
 		CA630ADE0DC7FB3800AD7F9E /* Toolbar Items */ = {
 			isa = PBXGroup;
 			children = (
+				27021FA911A5477300E77AD7 /* BWIWorkPopUpButton.h */,
+				27021FAA11A5477300E77AD7 /* BWIWorkPopUpButton.m */,
 				CA630AE00DC7FB6300AD7F9E /* BWToolbarShowColorsItem.h */,
 				CA630AE10DC7FB6300AD7F9E /* BWToolbarShowColorsItem.m */,
 				CA630AE20DC7FB6300AD7F9E /* BWToolbarShowFontsItem.h */,
 				CAEE07C20FD7BB18001A1C3F /* BWStyledTextFieldCell.h in Headers */,
 				CAAC333A0FE5DA5700C66575 /* NSApplication+BWAdditions.h in Headers */,
 				27AEE321112B4A9300C2648F /* BWTabViewController.h in Headers */,
+				27021FAB11A5477300E77AD7 /* BWIWorkPopUpButton.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 				CA991BD20DFA8B3D00FE0577 /* TexturedSliderPhotoLarge.tif in Resources */,
 				CA991BD30DFA8B3D00FE0577 /* TexturedSliderSpeakerQuiet.png in Resources */,
 				CA991BD40DFA8B3D00FE0577 /* TexturedSliderSpeakerLoud.png in Resources */,
-				CAF6B8450E049A6500CA1768 /* ButtonBarPullDownArrow.pdf in Resources */,
 				CA4070B70E0B66C300B56AB7 /* ToolbarItemColors.tiff in Resources */,
 				CA4070B80E0B66C300B56AB7 /* ToolbarItemFonts.tiff in Resources */,
 				CA4A524B0E1EF21500BC7395 /* Library-SheetController.tif in Resources */,
 				CAEE07C30FD7BB18001A1C3F /* BWStyledTextFieldCell.m in Sources */,
 				CAAC333B0FE5DA5700C66575 /* NSApplication+BWAdditions.m in Sources */,
 				27AEE322112B4A9300C2648F /* BWTabViewController.m in Sources */,
+				27021FAC11A5477300E77AD7 /* BWIWorkPopUpButton.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

BWToolkitFramework.h

 #import "BWHyperlinkButton.h"
 #import "BWHyperlinkButtonCell.h"
 #import "BWInsetTextField.h"
+#import "BWIWorkPopUpButton.h"
 #import "BWSelectableToolbar.h"
 #import "BWSheetController.h"
 #import "BWSplitView.h"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.