Added `-[NSArray validateAsPropertyList]` and `-[NSDictionary validateAsPropertyList...
[adiumx.git] / Source / AIContactListNameButton.m
blob7be5affddaa33d7eb5cc29ae4be907066e9020ba
1 //
2 //  AIContactListNameButton.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 2/23/06.
6 //
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];
18         }
21 /*!
22  * @brief Begin editing a specified name
23  */
24 - (void)editName:(NSString *)startingString
26         if (!textField_editor) {
27                 NSRect                  editingFrame;
28                 
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,
39                                                                                                                                                                                  nil]];
40                 textField_editor = [[NSTextField alloc] initWithFrame:editingFrame];
41                 [textField_editor setAttributedStringValue:attributedString];
42                 [attributedString release];
43         
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];             
56         }       
59 /*!
60  * @brief The text finished editing
61  */
62 - (void)controlTextDidEndEditing:(NSNotification *)aNotification
64         [editTarget mainPerformSelector:editSelector
65                                                  withObject:self
66                                                  withObject:[textField_editor stringValue]
67                                                  withObject:editUserInfo];
69         [textField_editor removeFromSuperview];
70         [textField_editor release]; textField_editor = nil;
72         [self resetCursorRects];
75 /*!
76  * @brief Edit the name
77  *
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
82  */
83 - (void)editNameStartingWithString:(NSString *)startingString notifyingTarget:(id)inTarget selector:(SEL)inSelector userInfo:(id)inUserInfo
85         [self editName:startingString];
86         
87         if (editTarget != inTarget) {
88                 [editTarget release];
89                 editTarget = [inTarget retain];
90         }
91         
92         editSelector = inSelector;
93         
94         if (inUserInfo != editUserInfo) {
95                 [editUserInfo release];
96                 editUserInfo = [inUserInfo retain];
97         }
100 - (NSRect)trackingRect
102         NSRect trackingRect = [super trackingRect];
103         
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;
107         return trackingRect;
110 @end