Re: Displaying a non-contentual menu & attachPopUpWithFrame
Re: Displaying a non-contentual menu & attachPopUpWithFrame
- Subject: Re: Displaying a non-contentual menu & attachPopUpWithFrame
- From: Eric Gorr <email@hidden>
- Date: Fri, 15 Jan 2010 11:31:45 -0500
Hello Mr. Ammon,
It does help. Thank you!
To test this out, I simply subclassed NSButton and only replaced the mouseDown: method with the following:
- (void) mouseDown:(NSEvent *)theEvent
{
NSPopUpButtonCell *cell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
NSMenu *tempMenu = [[[NSMenu alloc] init] autorelease];
[tempMenu addItemWithTitle:@"first item" action:NULL keyEquivalent:@""];
[tempMenu addItemWithTitle:@"second item" action:NULL keyEquivalent:@""];
[tempMenu addItemWithTitle:@"third item" action:NULL keyEquivalent:@""];
NSRect viewBounds = [self bounds];
[cell setMenu:tempMenu];
[cell performClickWithFrame:viewBounds inView:self];
[cell release];
}
Is there any reason why I shouldn't pass in the view bounds to performClickWithFrame:inView:?
Is it possible to have more control over where the menu appears relative to the view? For example, I would like to have the menu appear to the right of the view so the view is not obscured by the menu. I tried:
[cell performClickWithFrame:NSMakeRect(NSMaxX(viewBounds), 0, 1, 1) inView:self];
which comes close...the menu is shifted to the right, but still obscures part of the view. I haven't tried playing around with popUpMenuPositioningItem: atLocation: inView: from NSMenu in 10.6 to see if it will work any differently, but only because I need to stay with the 10.5 SDK for now.
Oh, as Mr. Sluder suggested, I have filed a documentation bug - rdar://7546017
Thanks again.
On Jan 13, 2010, at 2:59 PM, Peter Ammon wrote:
> On SnowLeopard and later, use the NSMenu method popUpMenuPositioningItem: atLocation: inView:.
>
> Before SnowLeopard, this is probably the easiest way:
>
> NSPopUpButtonCell *cell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
> [cell setMenu:menu];
> [cell performClickWithFrame:NSMakeRect(menuLoc.x, menuLoc.y, 0, 0) inView:theView];
> [cell release];
>
> Hope this helps,
_______________________________________________
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