NSImageView affecting window draggability?
NSImageView affecting window draggability?
- Subject: NSImageView affecting window draggability?
- From: "Mike R. Manzano" <email@hidden>
- Date: Mon, 9 Jul 2007 15:30:31 -0700
Hi,
I have a borderless window that overrides -mouseDown and -
mouseDragged to make the window draggable from anywhere within the
window (the window is one big drag bar).
If I place my own subclass of NSView within the content view, the
code works fine and I can drag windows around. However, if I instead
use an NSImageView instead of an NSView, the windows are no longer
draggable. It seems that my mouseDown and mouseMoved are no longer
called.
Anyone know what is special about an NSImageView that would cause
this to happen?
FYI, here's my drag code in my NSWindow subclass:
- (void)mouseDragged:(NSEvent *)theEvent
{
NSPoint currentLocation;
NSPoint newOrigin;
NSRect screenFrame = [[NSScreen mainScreen] frame];
NSRect windowFrame = [self frame];
//grab the current global mouse location; we could just as easily
get the mouse location
//in the same way as we do in -mouseDown:
currentLocation = [self convertBaseToScreen:[self
mouseLocationOutsideOfEventStream]];
newOrigin.x = currentLocation.x - initialLocation.x;
newOrigin.y = currentLocation.y - initialLocation.y;
// Don't let window get dragged up under the menu bar
if( (newOrigin.y+windowFrame.size.height) > (screenFrame.origin.y
+screenFrame.size.height) ){
newOrigin.y=screenFrame.origin.y + (screenFrame.size.height-
windowFrame.size.height);
}
//go ahead and move the window to the new location
[self setFrameOrigin:newOrigin];
}
//We start tracking the a drag operation here when the user first
clicks the mouse,
//to establish the initial location.
- (void)mouseDown:(NSEvent *)theEvent
{
NSRect windowFrame = [self frame];
//grab the mouse location in global coordinates
initialLocation = [self convertBaseToScreen:[theEvent
locationInWindow]];
initialLocation.x -= windowFrame.origin.x;
initialLocation.y -= windowFrame.origin.y;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden