pt_BR strings updates
[adiumx.git] / Source / AIContactListImagePicker.m
blob1bc4bbe6a3c0bd90e26170c7ccc5fad5e02c8842
1 //
2 //  AIContactListImagePicker.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 12/16/05.
6 //  Copyright 2006 The Adium Team. All rights reserved.
7 //
9 #import "AIContactListImagePicker.h"
10 #import <Adium/AIAccount.h>
11 #import <AIAdium.h>
12 #import <Adium/AIAccountControllerProtocol.h>
13 #import <Adium/AIContactControllerProtocol.h>
14 #import "AIContactListRecentImagesWindowController.h"
15 #import <AIUtilities/AIBezierPathAdditions.h>
16 #import <AIUtilities/AIApplicationAdditions.h>
18 #define ARROW_WIDTH             8
19 #define ARROW_HEIGHT    (ARROW_WIDTH/2.0)
20 #define ARROW_XOFFSET   2
21 #define ARROW_YOFFSET   3
23 @implementation AIContactListImagePicker
25 - (void)configureTracking
27         [[NSNotificationCenter defaultCenter] addObserver:self 
28                                                                                          selector:@selector(frameDidChange:)
29                                                                                                  name:NSViewFrameDidChangeNotification
30                                                                                            object:self];
31         [self setPostsFrameChangedNotifications:YES];
32         
33         trackingTag = -1;
34         [self resetCursorRects];                        
37 - (id)initWithFrame:(NSRect)inFrame
39         if ((self = [super initWithFrame:inFrame])) {
40                 [self configureTracking];
41                 imageMenu = nil;
42         }
43         
44         return self;
47 - (void)awakeFromNib
49         if ([[self superclass] instancesRespondToSelector:@selector(awakeFromNib)]) {
50         [super awakeFromNib];
51         }
53         [self configureTracking];
56 - (void)dealloc
58         [[NSNotificationCenter defaultCenter] removeObserver:self];
60         if (trackingTag != -1) {
61                 [self removeTrackingRect:trackingTag];
62                 trackingTag = -1;
63         }
64         
65         [imageMenu release]; imageMenu = nil;
66         
67         [super dealloc];
70 #pragma mark Drawing
72 - (void)drawRect:(NSRect)inRect
74         [NSGraphicsContext saveGraphicsState];
76         inRect = NSInsetRect(inRect, 1, 1);
78         NSBezierPath    *clipPath = [NSBezierPath bezierPathWithRoundedRect:inRect radius:3];
80         [[NSColor windowFrameColor] set];
81         [clipPath setLineWidth:1];
82         [clipPath stroke];
84         //Ensure we have an even/odd winding rule in effect
85         [clipPath setWindingRule:NSEvenOddWindingRule];
86         [clipPath addClip];
87         
88         [super drawRect:inRect];
89         
90         if (hovered) {
91                 [[[NSColor blackColor] colorWithAlphaComponent:0.40] set];
92                 [clipPath fill];
94                 //Draw the arrow
95                 NSBezierPath    *arrowPath = [NSBezierPath bezierPath];
96                 NSRect                  frame = [self frame];
97                 [arrowPath moveToPoint:NSMakePoint(frame.size.width - ARROW_XOFFSET - ARROW_WIDTH, 
98                                                                                    (ARROW_YOFFSET + ARROW_HEIGHT))];
99                 [arrowPath relativeLineToPoint:NSMakePoint(ARROW_WIDTH, 0)];
100                 [arrowPath relativeLineToPoint:NSMakePoint(-(ARROW_WIDTH/2), -(ARROW_HEIGHT))];
101                 
102                 [[NSColor whiteColor] set];
103                 [arrowPath fill];
104         }
106         [NSGraphicsContext restoreGraphicsState];
109 #pragma mark Mouse movement
111 - (void)setHovered:(BOOL)inHovered
113         hovered = inHovered;
114         
115         [self setNeedsDisplay:YES];
118 - (void)mouseEntered:(NSEvent *)inEvent
120         [self setHovered:YES];
121         
122         [super mouseEntered:inEvent];   
125 - (void)mouseExited:(NSEvent *)inEvent
127         [self setHovered:NO];
128         
129         [super mouseExited:inEvent];
133 - (void)displayPicturePopUpForEvent:(NSEvent *)theEvent
135         if(NSClassFromString(@"NSIPRecentPicture")) {
136                 NSRect  myFrame = [self frame];
137                 NSPoint bottomRightPoint = NSMakePoint(NSMaxX(myFrame), NSMinY(myFrame));
138                 bottomRightPoint = [[self window] convertBaseToScreen:[[self superview] convertPoint:bottomRightPoint toView:nil]];
139                 [AIContactListRecentImagesWindowController showWindowFromPoint:bottomRightPoint
140                                                                                                                    imagePicker:self
141                                                                                              recentPictureSelector:@selector(didSetImage:forAccount:)];
142                 
143         }
144                                 
147 //Custom mouse down tracking to display our menu and highlight
148 - (void)mouseDown:(NSEvent *)theEvent
150         [self displayPicturePopUpForEvent:theEvent];
153 #pragma mark Tracking rects
154 //Remove old tracking rects when we change superviews
155 - (void)viewWillMoveToSuperview:(NSView *)newSuperview
157         if (trackingTag != -1) {
158                 [self removeTrackingRect:trackingTag];
159                 trackingTag = -1;
160         }
161         
162         [super viewWillMoveToSuperview:newSuperview];
165 - (void)viewDidMoveToSuperview
167         [super viewDidMoveToSuperview];
168         
169         [self resetCursorRects];
172 - (void)viewWillMoveToWindow:(NSWindow *)newWindow
174         if (trackingTag != -1) {
175                 [self removeTrackingRect:trackingTag];
176                 trackingTag = -1;
177         }
178         
179         [super viewWillMoveToWindow:newWindow];
182 - (void)viewDidMoveToWindow
184         [super viewDidMoveToWindow];
185         
186         [self resetCursorRects];
189 - (void)frameDidChange:(NSNotification *)inNotification
191         [self resetCursorRects];
194 //Reset our cursor tracking
195 - (void)resetCursorRects
197         //Stop any existing tracking
198         if (trackingTag != -1) {
199                 [self removeTrackingRect:trackingTag];
200                 trackingTag = -1;
201         }
202         
203         //Add a tracking rect if our superview and window are ready
204         if ([self superview] && [self window]) {
205                 NSRect  myFrame = [self frame];
206                 NSRect  trackRect = NSMakeRect(0, 0, myFrame.size.width, myFrame.size.height);
207                 
208                 if (trackRect.size.width > myFrame.size.width) {
209                         trackRect.size.width = myFrame.size.width;
210                 }
211                 
212                 NSPoint localPoint = [self convertPoint:[[self window] convertScreenToBase:[NSEvent mouseLocation]]
213                                                                            fromView:nil];
214                 BOOL    mouseInside = NSPointInRect(localPoint, myFrame);
216                 trackingTag = [self addTrackingRect:trackRect owner:self userData:nil assumeInside:mouseInside];
217                 if (mouseInside) [self mouseEntered:nil];
218         }
221 @end