Use initialize, not load, wherever possible.
[adiumx.git] / Source / AIClickThroughThemeDocumentButton.m
blobf8c79cd0d9de9fcbacd82b7b339268e36e441cdb
1 //
2 //  AIClickThroughThemeDocumentButton.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 12/26/05.
6 //
8 #import "AIClickThroughThemeDocumentButton.h"
10 /*!
11  * @class AIClickThroughThemeDocumentButton
12  * @brief This NSThemeDocumentButton subclass makes the window move when it is dragged.
13  *
14  * Normally, an NSThemeDocumentButton eats mouseDown: and mouseDragged: events for its own nefarious
15  * purposes, namely drag & drop of the window's document to other locations.  We want to utilize the display
16  * of a document button, but we don't have an associated document, so dragging appears to just do nothing.
17  *
18  * With this replacement class, dragging the document button properly moves the window.  The code is, for
19  * reference, a stripped down version of the code powering AIBorderlessWindow's dragging movements.
20  *
21  * On mouse down, the window's frame is noted; deltas as the mouse moves are used to determine the window's
22  * own movements.
23  */
24 @implementation AIClickThroughThemeDocumentButton
26 /*!
27  * @brief Mouse dragged
28  */
29 - (void)mouseDragged:(NSEvent *)theEvent
31         NSWindow        *window = [self window];
32         NSPoint         currentLocation, newOrigin;
33         NSRect          newWindowFrame;
34         
35         /* If we get here and aren't yet in a left mouse event, which can happen if the user began dragging while
36          * a contextual menu is showing, start off from the right position by getting our originalMouseLocation.
37          */             
38         if (!inLeftMouseEvent) {
39                 //Grab the mouse location in global coordinates
40                 originalMouseLocation = [window convertBaseToScreen:[theEvent locationInWindow]];
41                 windowFrame = [window frame];
42                 inLeftMouseEvent = YES;         
43         }
44         
45         newOrigin = windowFrame.origin;
46         newWindowFrame = windowFrame;
47         
48         //Grab the current mouse location to compare with the location of the mouse when the drag started (stored in mouseDown:)
49         currentLocation = [NSEvent mouseLocation];
50         newOrigin.x += (currentLocation.x - originalMouseLocation.x);
51         newOrigin.y += currentLocation.y - originalMouseLocation.y;
53         newWindowFrame.origin = newOrigin;
55         [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowWillMoveNotification object:window];
56         [window setFrameOrigin:newWindowFrame.origin];
57         [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidMoveNotification object:window];          
60 /*!
61  * @brief Mouse down
62  *
63  * We start tracking the a drag operation here when the user first clicks the mouse without command presed
64  * to establish the initial location.
65  */
66 - (void)mouseDown:(NSEvent *)theEvent
68         NSWindow        *window = [self window];
70         //grab the mouse location in global coordinates
71         originalMouseLocation = [window convertBaseToScreen:[theEvent locationInWindow]];
72         windowFrame = [window frame];
73         inLeftMouseEvent = YES;
76 /*!
77  * @brief Mouse up
78  */
79 - (void)mouseUp:(NSEvent *)theEvent
81         inLeftMouseEvent = NO;
84 /*!
85  * @brief HACK: When deallocing, we crash in setRepresentedFilename presumably because of an NSCoder failure in AIMesageWindow
86  */
87 - (void)setRepresentedFilename:(NSString *)inFilename
89         //Empty
92 /*!
93  * @brief Don't allow the document button to try to show a popup menu
94  *
95  * If we do, we'll crash, since there shouldn't actually *be* a theem document button with no represented filename and no document.
96  */
97 - (void)showPopup
99         //Empty
102 @end