Performed [21405] and [21406], moving the contact list to Source, on adium-1.1
[adiumx.git] / Source / AIWindowDraggingView.m
blobc75f0abf412142b20eda3de8a1d714499515b6e6
1 //
2 //  AIWindowDraggingView.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 3/6/06.
6 //
8 #import "AIWindowDraggingView.h"
10 /*!
11  * @class AIWindowDraggingView
12  * @brief This NSView subclass makes the window move when it is dragged by the view itself (but not by subviews).
13  *
14  * The code is, for reference, a stripped down version of the code powering AIBorderlessWindow's dragging movements.
15  *
16  * On mouse down, the window's frame is noted; deltas as the mouse moves are used to determine the window's
17  * own movements.
18  */
19 @implementation AIWindowDraggingView
20 /*!
21  * @brief Mouse dragged
22  */
23 - (void)mouseDragged:(NSEvent *)theEvent
25         NSWindow        *window = [self window];
26         NSPoint         currentLocation, newOrigin;
27         NSRect          newWindowFrame;
28         
29         /* If we get here and aren't yet in a left mouse event, which can happen if the user began dragging while
30          * a contextual menu is showing, start off from the right position by getting our originalMouseLocation.
31          */             
32         if (!inLeftMouseEvent) {
33                 //Grab the mouse location in global coordinates
34                 originalMouseLocation = [window convertBaseToScreen:[theEvent locationInWindow]];
35                 windowFrame = [window frame];
36                 inLeftMouseEvent = YES;         
37         }
38         
39         newOrigin = windowFrame.origin;
40         newWindowFrame = windowFrame;
41         
42         //Grab the current mouse location to compare with the location of the mouse when the drag started (stored in mouseDown:)
43         currentLocation = [NSEvent mouseLocation];
44         newOrigin.x += (currentLocation.x - originalMouseLocation.x);
45         newOrigin.y += currentLocation.y - originalMouseLocation.y;
46         
47         newWindowFrame.origin = newOrigin;
48         
49         [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowWillMoveNotification object:window];
50         [window setFrameOrigin:newWindowFrame.origin];
51         [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidMoveNotification object:window];          
54 /*!
55  * @brief Mouse down
56  *
57  * We start tracking the a drag operation here when the user first clicks the mouse without command presed
58  * to establish the initial location.
59  */
60 - (void)mouseDown:(NSEvent *)theEvent
62         NSWindow        *window = [self window];
63         
64         //grab the mouse location in global coordinates
65         originalMouseLocation = [window convertBaseToScreen:[theEvent locationInWindow]];
66         windowFrame = [window frame];
67         inLeftMouseEvent = YES;
70 /*!
71  * @brief Mouse up
72  */
73 - (void)mouseUp:(NSEvent *)theEvent
75         inLeftMouseEvent = NO;
78 @end