BWToolkit / 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
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.