Re: Contextual menu click in window title
Re: Contextual menu click in window title
- Subject: Re: Contextual menu click in window title
- From: Axel Andersson <email@hidden>
- Date: Fri, 9 Sep 2005 12:08:48 +0200
On Sep 9, 2005, at 05:14, Mark Alldritt wrote:
I have a non-document window and I want to provide a window title
path popup
menu, just as NSWindow does for NSDocument. The problem is that I
cannot
seem to figure out how to get my code called when there is a
mouseDown the
window title.
I've tried subclassing NSWindow, but that does not seem to do it - my
mouseDown:(NSEvent*) method is not being called.
Anyone have any ideas?
I have an implementation that does just this, for purposes of
creating path popups for windows representing remote file listings in
a network client. It relies on some other convenience methods, but I
hope you get the idea of it anyway.
@implementation ZAWindow
- (void)sendEvent:(NSEvent *)event {
BOOL handled = NO;
if([event type] == NSLeftMouseDown && [event commandKeyModifier] &&
[[self delegate] respondsToSelector:@selector
(windowTitleBarMenu:)]) {
NSPoint point;
NSRect frame;
NSSize size;
point = [event locationInWindow];
frame = [self frame];
size = [[NSFont titleBarFont] sizeOfString:[self title]];
if(frame.size.height - point.y <= size.height + 5.0 &&
point.x > (frame.size.width / 2.0) - (size.width / 2.0) &&
point.x < (frame.size.width / 2.0) + (size.width / 2.0)) {
NSMenu *menu;
NSEvent *menuEvent;
NSPoint menuPoint;
menu = [[self delegate] windowTitleBarMenu:self];
if(menu) {
menuPoint = NSMakePoint((frame.size.width / 2.0) -
(size.width / 2.0),
frame.size.height - 2.0);
menuEvent = [NSEvent mouseEventWithType:[event type]
location:menuPoint
modifierFlags:[event
modifierFlags]
timestamp:[event
timestamp]
windowNumber:[event
windowNumber]
context:[event context]
eventNumber:[event
eventNumber]
clickCount:[event
clickCount]
pressure:[event
pressure]];
[NSMenu popUpContextMenu:menu withEvent:menuEvent
forView:NULL];
handled = YES;
}
}
}
if(!handled)
[super sendEvent:event];
}
@end
-- Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden