2 // AIClickThroughThemeDocumentButton.m
5 // Created by Evan Schoenberg on 12/26/05.
8 #import "AIClickThroughThemeDocumentButton.h"
11 * @class AIClickThroughThemeDocumentButton
12 * @brief This NSThemeDocumentButton subclass makes the window move when it is dragged.
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.
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.
21 * On mouse down, the window's frame is noted; deltas as the mouse moves are used to determine the window's
24 @implementation AIClickThroughThemeDocumentButton
27 * @brief Mouse dragged
29 - (void)mouseDragged:(NSEvent *)theEvent
31 NSWindow *window = [self window];
32 NSPoint currentLocation, newOrigin;
33 NSRect newWindowFrame;
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.
38 if (!inLeftMouseEvent) {
39 //Grab the mouse location in global coordinates
40 originalMouseLocation = [window convertBaseToScreen:[theEvent locationInWindow]];
41 windowFrame = [window frame];
42 inLeftMouseEvent = YES;
45 newOrigin = windowFrame.origin;
46 newWindowFrame = windowFrame;
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];
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.
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;
79 - (void)mouseUp:(NSEvent *)theEvent
81 inLeftMouseEvent = NO;
85 * @brief HACK: When deallocing, we crash in setRepresentedFilename presumably because of an NSCoder failure in AIMesageWindow
87 - (void)setRepresentedFilename:(NSString *)inFilename
93 * @brief Don't allow the document button to try to show a popup menu
95 * If we do, we'll crash, since there shouldn't actually *be* a theem document button with no represented filename and no document.