<snip>

...then I get the highlight back again! This indicates that the NSOutlineView's implementation of this highlight is being done in a dubiously skanky way, drawing directly as part of the -menuForEvent: method, rather than flagging the menu tracking and drawing as part of the standard drawing mechanism. So, to prove that, I ended up doing this:

- (NSMenu*)             menuForEvent:(NSEvent*) event
{
#pragma unused(event)
        return [self menu];
}

Ah! sorry for the confusion this has caused, but it is clearly documented. Here are the release notes for Leopard:

http://developer.apple.com/releasenotes/Cocoa/AppKit.html

Copied below is the pertinent information:

NSTableView/NSOutlineView - Contextual menu support

NSTableView and NSOutlineView now have better contextual menu support. Please see the DragNDropOutlineView demo application for an example of how to properly do contextual menus with a TableView.

The key thing to note is that clickedRow and clickedColumn will now both be valid when a contextual menu is popped up. In addition, one can dynamically set the popup menu for a particular cell/column in the delegate method willDisplayCell:. NSTableView handles this by properly overriding menuForEvent:, setting the clickedRow/ clickedColumn, and calling [NSCell menuForEvent:inRect:ofView] to find the correct menu. If no menu was returned, the menu for the NSTableView will be used. If one right clicks on a selection of items, all the items are highlighted. One should check to see if clickedRow is one of the selected rows, and if it is then do the menu operation on all the selected rows. The clickedRow and clickedColumn properties will still be valid when the action is sent from the NSMenuItem.


Unfortunately, you may have stumbled upon one deficiency; there is no way to have the menu apply for the table as a whole. As you discovered, the way to fix this is to override -menuForEvent:.


...which also gives the desired result, suppressing the highlight. It means that one surprising side-effect of returning a menu in - menuForEvent: built in code will be that if you want the standard row highlight, you won't get it without invoking super, even if you don't want super's menu.

It seems strange to me that this method is doing highlighting duty when all it's meant for is to return a property.

To me, it doesn't seem strange. It is AppKit that displays the menu, and it allows a consistent user interface to be used throughout, and we wanted to work easily and without trouble to the developer.

I'm open to suggestions and ways on improving things -- please do log bugs and/or enhancement requests, and ways you would expect the highlighting to work but does not.

thanks,
corbin

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to