Warn about missing newline.
[MacTF.git] / iLifeControls / NFHUDPopUpButtonCell.m
blob425fd1522832904f5d3d679c11257e1360203e9c
1 //
2 //  NFHUDPopUpButtonCell.m
3 //  iLife HUD PopUpButton
4 //
5 //  Created by Sean Patrick O'Brien on 9/23/06.
6 //  Copyright 2006 Sean Patrick O'Brien. All rights reserved.
7 //
9 #import "NFHUDPopUpButtonCell.h"
10 #import "NSImage+FrameworkImage.h"
12 @implementation NFHUDPopUpButtonCell
14 -(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
16         NSString *state = [self isHighlighted] ? @"P" : @"N";
17         NSImage *leftImage = [NSImage frameworkImageNamed:[NSString stringWithFormat:@"HUDPopUpLeft%@.tiff", state]];
18         NSImage *fillImage = [NSImage frameworkImageNamed:[NSString stringWithFormat:@"HUDPopUpFill%@", state]];
19         NSImage *rightImage = [NSImage frameworkImageNamed:[NSString stringWithFormat:@"HUDPopUpRight%@", state]];
20                                 
21         NSSize size = [leftImage size];
22         float addX = size.width / 2.0;
23         float y = NSMaxY(cellFrame) - (cellFrame.size.height-size.height)/2.0;
24         float x = cellFrame.origin.x+addX;
25         float fillX = x + size.width;
26         float fillWidth = cellFrame.size.width - size.width - addX;
27         
28         [leftImage compositeToPoint:NSMakePoint(x, y) operation:NSCompositeSourceOver];
30         size = [rightImage size];
31         addX = size.width / 2.0;
32         x = NSMaxX(cellFrame) - size.width - addX;
33         fillWidth -= size.width+addX;
34         
35         [rightImage compositeToPoint:NSMakePoint(x, y) operation:NSCompositeSourceOver];
36         
37         [fillImage setScalesWhenResized:YES];
38         [fillImage setSize:NSMakeSize(fillWidth, [fillImage size].height)];
39         [fillImage compositeToPoint:NSMakePoint(fillX, y) operation:NSCompositeSourceOver];
40         
41         [self drawInteriorWithFrame:cellFrame inView:controlView];
44 - (NSRect)titleRectForBounds:(NSRect)bounds;
46         return NSOffsetRect([super titleRectForBounds:bounds], 2, 0);
49 -(void)drawTitleWithFrame:(NSRect)frame inView:(NSView *)view
51         NSMutableDictionary *attrs = [[NSMutableDictionary alloc]init];
52         [attrs addEntriesFromDictionary:[[self attributedTitle] attributesAtIndex:0 effectiveRange:NULL]];
53         NSFont *font = [NSFont fontWithName:@"LucidaGrande" size:11.0];
54         [attrs setObject:font forKey:NSFontAttributeName];
55         [attrs setObject:[NSColor whiteColor]forKey:NSForegroundColorAttributeName];
56         NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:[self title] attributes:attrs];
57         frame = [self titleRectForBounds:frame];
58         [super drawTitle:attrStr withFrame:frame inView:view];
61 @end