Now, groups can retrieve a list of the contacts in that group. I probably should...
[adiumx.git] / Source / AIContactInfoImageViewWithImagePicker.m
blob21a4299bed69e0eb31961dfa7f3969cc57459d8e
1 //
2 //  AIContactInfoImageViewWithImagePicker.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 10/1/06.
6 //
8 #import "AIContactInfoImageViewWithImagePicker.h"
9 #import <AIUtilities/AIBezierPathAdditions.h>
10 #import <AIUtilities/AIImageAdditions.h>
12 @interface AIContactInfoImageViewWithImagePicker (PRIVATE)
13 - (void)resetCursorRects;
14 - (NSRect)_snapbackRectForFrame:(NSRect)cellFrame;
15 @end
17 @implementation AIContactInfoImageViewWithImagePicker
19 - (void)configureTracking
21         resetImageTrackingTag = -1;
22         [self resetCursorRects];                        
25 - (id)initWithFrame:(NSRect)inFrame
27         if ((self = [super initWithFrame:inFrame])) {
28                 [self configureTracking];
29         }
30         
31         return self;
34 - (void)awakeFromNib
36         if ([[self superclass] instancesRespondToSelector:@selector(awakeFromNib)]) {
37         [super awakeFromNib];
38         }
39         
40         [self configureTracking];
43 - (void)dealloc
45         if (resetImageTrackingTag != -1) {
46                 [self removeTrackingRect:resetImageTrackingTag];
47                 resetImageTrackingTag = -1;
48         }
49         
50         [super dealloc];
54 - (void)drawRect:(NSRect)inRect
56         [NSGraphicsContext saveGraphicsState];
57         
58         inRect = NSInsetRect(inRect, 1, 1);
59         
60         NSBezierPath    *clipPath = [NSBezierPath bezierPathWithRoundedRect:inRect radius:3];
61         
62         [[NSColor windowFrameColor] set];
63         [clipPath setLineWidth:1];
64         [clipPath stroke];
65         
66         //Ensure we have an even/odd winding rule in effect
67         [clipPath setWindingRule:NSEvenOddWindingRule];
68         [clipPath addClip];
69         
70         [NSGraphicsContext saveGraphicsState];
71         [super drawRect:inRect];
72         [NSGraphicsContext restoreGraphicsState];
74         // Draw snapback image
75         if (showResetImageButton) {
76                 NSImage *snapbackImage = [NSImage imageNamed:@"SRSnapback" forClass:[self class]];
77                 NSRect snapBackRect = [self _snapbackRectForFrame:[self bounds]];
78                 if (resetImageHovered) {
79                         [[[NSColor blackColor] colorWithAlphaComponent:0.8] set];               
80                 } else {
81                         [[[NSColor blackColor] colorWithAlphaComponent:0.5] set];
82                 }
83                 
84                 [[NSBezierPath bezierPathWithOvalInRect:snapBackRect] fill];
85                 [snapbackImage dissolveToPoint:snapBackRect.origin fraction:1.0];
86         }
87                 
88         /*
89         if (hovered) {
90                 [[[NSColor blackColor] colorWithAlphaComponent:0.40] set];
91                 [clipPath fill];
92                 
93                 //Draw the arrow
94                 NSBezierPath    *arrowPath = [NSBezierPath bezierPath];
95                 NSRect                  frame = [self frame];
96                 [arrowPath moveToPoint:NSMakePoint(frame.size.width - ARROW_XOFFSET - ARROW_WIDTH, 
97                                                                                    (ARROW_YOFFSET + ARROW_HEIGHT))];
98                 [arrowPath relativeLineToPoint:NSMakePoint(ARROW_WIDTH, 0)];
99                 [arrowPath relativeLineToPoint:NSMakePoint(-(ARROW_WIDTH/2), -(ARROW_HEIGHT))];
100                 
101                 [[NSColor whiteColor] set];
102                 [arrowPath fill];
103         }
104         */
106         [NSGraphicsContext restoreGraphicsState];
109 #pragma mark Snapback
110 - (NSRect)_snapbackRectForFrame:(NSRect)cellFrame
111 {       
112         if (!showResetImageButton) return NSZeroRect;
113         
114         NSRect snapbackRect;
115         NSImage *snapbackImage = [NSImage imageNamed:@"SRSnapback" forClass:[self class]];
117         snapbackRect.origin = NSMakePoint(NSMaxX(cellFrame) - [snapbackImage size].width - 1, 2);
118         snapbackRect.size = [snapbackImage size];
120         return snapbackRect;
123 - (void)mouseEntered:(NSEvent *)theEvent
125         if ([[self window] isKeyWindow] || [self acceptsFirstMouse: theEvent]) {
126                 resetImageHovered = YES;
127                 [self display];
128         }
129         
130         [super mouseEntered:theEvent];
133 - (void)mouseExited:(NSEvent*)theEvent
134 {       
135         if ([[self window] isKeyWindow] || [self acceptsFirstMouse: theEvent]) {
136                 resetImageHovered = NO;
137                 [self display];
138         }
140         [super mouseEntered:theEvent];
143 - (void)mouseDown:(NSEvent *)inEvent
145         NSPoint mouseLocation = [self convertPoint:[inEvent locationInWindow] fromView:nil];
146         if ([self mouse:mouseLocation inRect:[self _snapbackRectForFrame:[self bounds]]]) {
147                 if ([[self delegate] respondsToSelector:@selector(deleteInImageViewWithImagePicker:)]) {
148                         [[self delegate] deleteInImageViewWithImagePicker:self];
149                 }
151         } else {
152                 [super mouseDown:inEvent];
153         }
156 - (void)setShowResetImageButton:(BOOL)inShowResetImageButton
158         showResetImageButton = inShowResetImageButton;
160         [self resetCursorRects];
164 #pragma mark Tracking rects
165 //Remove old tracking rects when we change superviews
166 - (void)viewWillMoveToSuperview:(NSView *)newSuperview
168         if (resetImageTrackingTag != -1) {
169                 [self removeTrackingRect:resetImageTrackingTag];
170                 resetImageTrackingTag = -1;
171         }
172         
173         [super viewWillMoveToSuperview:newSuperview];
176 - (void)viewDidMoveToSuperview
178         [super viewDidMoveToSuperview];
179         
180         [self resetCursorRects];
183 - (void)viewWillMoveToWindow:(NSWindow *)newWindow
185         if (resetImageTrackingTag != -1) {
186                 [self removeTrackingRect:resetImageTrackingTag];
187                 resetImageTrackingTag = -1;
188         }
189         
190         [super viewWillMoveToWindow:newWindow];
193 - (void)viewDidMoveToWindow
195         [super viewDidMoveToWindow];
196         
197         [self resetCursorRects];
200 - (void)frameDidChange:(NSNotification *)inNotification
202         [self resetCursorRects];
205 //Reset our cursor tracking
206 - (void)resetCursorRects
208         //Stop any existing tracking
209         if (resetImageTrackingTag != -1) {
210                 [self removeTrackingRect:resetImageTrackingTag];
211                 resetImageTrackingTag = -1;
212         }
213         
214         //Add a tracking rect if our superview and window are ready
215         if (showResetImageButton && [self superview] && [self window]) {
216                 NSRect  snapbackRect = [self _snapbackRectForFrame:[self bounds]];
217                 NSPoint mouseLocation = [self convertPoint:[[NSApp currentEvent] locationInWindow] fromView:nil];
218                 BOOL    mouseInside = [self mouse:mouseLocation inRect:snapbackRect];
220                 resetImageTrackingTag = [self addTrackingRect:snapbackRect owner:self userData:nil assumeInside:mouseInside];
221                 if (mouseInside) [self mouseEntered:nil];
222         }
225 @end