2 // AIContactListNameButton.m
5 // Created by Evan Schoenberg on 2/23/06.
8 #import "AIContactListNameButton.h"
9 #import <AIUtilities/AIParagraphStyleAdditions.h>
10 #import <AIUtilities/AIObjectAdditions.h>
12 @implementation AIContactListNameButton
14 - (void)drawRect:(NSRect)inRect
16 if (!textField_editor) {
17 [super drawRect:inRect];
22 * @brief Begin editing a specified name
24 - (void)editName:(NSString *)startingString
26 if (!textField_editor) {
29 editingFrame = [self frame];
30 editingFrame.origin = NSMakePoint(3, 1);
32 NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle styleWithAlignment:NSLeftTextAlignment
33 lineBreakMode:NSLineBreakByTruncatingMiddle];
34 [paragraphStyle setMaximumLineHeight:editingFrame.size.height];
35 NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:(startingString ? startingString : @"")
36 attributes:[NSDictionary dictionaryWithObjectsAndKeys:
37 [[self cell] font], NSFontAttributeName,
38 paragraphStyle, NSParagraphStyleAttributeName,
40 textField_editor = [[NSTextField alloc] initWithFrame:editingFrame];
41 [textField_editor setAttributedStringValue:attributedString];
42 [attributedString release];
44 [textField_editor setFocusRingType:NSFocusRingTypeNone];
45 [textField_editor setDelegate:self];
46 [textField_editor setEditable:YES];
47 [textField_editor setFont:[[self cell] font]];
48 [textField_editor setBordered:NO];
49 [textField_editor setDrawsBackground:NO];
50 [[textField_editor cell] setDrawsBackground:NO];
51 [[textField_editor cell] setScrollable:YES];
53 [self addSubview:textField_editor];
54 [[self window] makeFirstResponder:textField_editor];
55 [[self superview] display];
60 * @brief The text finished editing
62 - (void)controlTextDidEndEditing:(NSNotification *)aNotification
64 [editTarget mainPerformSelector:editSelector
66 withObject:[textField_editor stringValue]
67 withObject:editUserInfo];
69 [textField_editor removeFromSuperview];
70 [textField_editor release]; textField_editor = nil;
72 [self resetCursorRects];
76 * @brief Edit the name
78 * @param startingString The name to initially show in the editor. We don't use our title because the title might have been filtered
79 * @param inTarget The target to notify, which must implement inSelector
80 * @param inSelector The selector, which should be of the form nameView:didChangeToString:userInfo:
81 * @param inUserInfo Userinfo which will be passed back to inTarget via inSelector
83 - (void)editNameStartingWithString:(NSString *)startingString notifyingTarget:(id)inTarget selector:(SEL)inSelector userInfo:(id)inUserInfo
85 [self editName:startingString];
87 if (editTarget != inTarget) {
89 editTarget = [inTarget retain];
92 editSelector = inSelector;
94 if (inUserInfo != editUserInfo) {
95 [editUserInfo release];
96 editUserInfo = [inUserInfo retain];
100 - (NSRect)trackingRect
102 NSRect trackingRect = [super trackingRect];
104 //Don't let the bottommost part of our view qualify for highlighting; this lets it get closer to views below without leaving whitespace.
105 trackingRect.size.height -= 2;