Commits

Anonymous committed f806646

Adding BWToolbarPullDownItem

Comments (0)

Files changed (4)

BWToolbarPullDownItem.h

+//
+//  BWToolbarPullDownItem.h
+//  BWToolkit
+//
+//  Created by Mike Abdullah on 14/01/2010.
+//  All code is provided under the New BSD license.
+//
+
+#import <Cocoa/Cocoa.h>
+#import "BWToolbarItem.h"
+
+@interface BWToolbarPullDownItem : BWToolbarItem
+{
+  @private
+    NSPopUpButton   *_popUpButton;
+}
+
+
+// You shouldn't have any need to access the button directly, but here it is if you do
+@property(nonatomic, retain, readonly) NSPopUpButton *popUpButton;
+
+@end

BWToolbarPullDownItem.m

+//
+//  BWToolbarPullDownItem.m
+//  BWToolkit
+//
+//  Created by Mike Abdullah on 14/01/2010.
+//  All code is provided under the New BSD license.
+//
+
+#import "BWToolbarPullDownItem.h"
+
+#import "BWIWorkPopUpButton.h"
+
+
+@implementation BWToolbarPullDownItem
+
+- (id)initWithItemIdentifier:(NSString *)itemIdentifier;
+{
+    [super initWithItemIdentifier:itemIdentifier];
+    
+    // Prepare basic pull-down button
+    _popUpButton = [[BWIWorkPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:YES];
+    NSPopUpButtonCell *cell = [_popUpButton cell];
+    
+    [_popUpButton setBezelStyle:NSSmallSquareBezelStyle];   // otherwise menu covers bottom bit of button
+    [cell setArrowPosition:NSPopUpArrowAtBottom];
+    [_popUpButton setBordered:NO];
+    [cell setImageScaling:NSImageScaleProportionallyDown];
+    
+    [_popUpButton setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
+    [cell setControlSize:NSSmallControlSize];
+    
+    
+    // Ensure there is a single item to generate cell appearance from
+    if ([[_popUpButton itemArray] count] == 0) [_popUpButton addItemWithTitle:@""];
+    
+    [self setView:_popUpButton];
+    
+    return self;
+}
+
+- (void)dealloc
+{
+    [_popUpButton release];
+    
+    [super dealloc];
+}
+
+#pragma mark Properties
+
+- (void)setImage:(NSImage *)anImage
+{
+    // NSToolbarItem would normally forward this on to its view. That would be fine, but NSPopUpButton ignores -setImage: so handle it ourself
+    [[[self popUpButton] itemAtIndex:0] setImage:anImage];
+}
+
+- (NSSize)minSize
+{
+    NSSize result;
+    result.height = ([[self toolbar] sizeMode] == NSToolbarSizeModeSmall) ? 24.0f : 32.0f;
+    result.width = result.height + 8;   // to account for arrow
+    
+    return result;
+}
+
+@synthesize popUpButton = _popUpButton;
+
+- (NSMenuItem *)menuFormRepresentation
+{
+    NSMenuItem *result = [super menuFormRepresentation];
+    
+    // Use a submenu to display the button's items
+    NSMenu *submenu = [[[self popUpButton] menu] copy];
+    [result setSubmenu:submenu];
+    [submenu release];
+            
+    [result setAction:[self action]]; // otherwise submenu ony appears after mouse is held down
+    
+    return result;
+}
+
+@end

BWToolkit.xcodeproj/project.pbxproj

 		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 */; };
+		27021FE011A54B2800E77AD7 /* BWToolbarPullDownItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 27021FDE11A54B2800E77AD7 /* BWToolbarPullDownItem.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		27021FE111A54B2800E77AD7 /* BWToolbarPullDownItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 27021FDF11A54B2800E77AD7 /* BWToolbarPullDownItem.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 */; };
 		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>"; };
+		27021FDE11A54B2800E77AD7 /* BWToolbarPullDownItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BWToolbarPullDownItem.h; sourceTree = "<group>"; };
+		27021FDF11A54B2800E77AD7 /* BWToolbarPullDownItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BWToolbarPullDownItem.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>"; };
 			children = (
 				27021FA911A5477300E77AD7 /* BWIWorkPopUpButton.h */,
 				27021FAA11A5477300E77AD7 /* BWIWorkPopUpButton.m */,
+				27021FDE11A54B2800E77AD7 /* BWToolbarPullDownItem.h */,
+				27021FDF11A54B2800E77AD7 /* BWToolbarPullDownItem.m */,
 				CA630AE00DC7FB6300AD7F9E /* BWToolbarShowColorsItem.h */,
 				CA630AE10DC7FB6300AD7F9E /* BWToolbarShowColorsItem.m */,
 				CA630AE20DC7FB6300AD7F9E /* BWToolbarShowFontsItem.h */,
 				CAAC333A0FE5DA5700C66575 /* NSApplication+BWAdditions.h in Headers */,
 				27AEE321112B4A9300C2648F /* BWTabViewController.h in Headers */,
 				27021FAB11A5477300E77AD7 /* BWIWorkPopUpButton.h in Headers */,
+				27021FE011A54B2800E77AD7 /* BWToolbarPullDownItem.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 				CAAC333B0FE5DA5700C66575 /* NSApplication+BWAdditions.m in Sources */,
 				27AEE322112B4A9300C2648F /* BWTabViewController.m in Sources */,
 				27021FAC11A5477300E77AD7 /* BWIWorkPopUpButton.m in Sources */,
+				27021FE111A54B2800E77AD7 /* BWToolbarPullDownItem.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

BWToolkitFramework.h

 #import "BWTokenField.h"
 #import "BWTokenFieldCell.h"
 #import "BWToolbarItem.h"
+#import "BWToolbarPullDownItem.h"
 #import "BWToolbarShowColorsItem.h"
 #import "BWToolbarShowFontsItem.h"
 #import "BWTransparentButton.h"