Re: [SOLVED, with reservations] Re: Turn off menu highlight in outline view?
Re: [SOLVED, with reservations] Re: Turn off menu highlight in outline view?
- Subject: Re: [SOLVED, with reservations] Re: Turn off menu highlight in outline view?
- From: Graham Cox <email@hidden>
- Date: Tue, 18 Aug 2009 21:50:32 +1000
On 18/08/2009, at 9:07 PM, I. Savant wrote:
It's not quite the same because a menu is another view and the
table view is merely holding a reference to it. This is more an
encapsulation problem.
Sorry for being so quick to "play the MVC card". ;-)
In a way though, I think you're right. MVC can be applied at many
different levels, and within the microcosm of the table view in
isolation, the menu and the table's current selection are part of its
"model". In this case the menu is a data structure that supplies the
relevant commands that the table can respond to at this moment in
time. While there's not much you can do with it except display it or
not, in theory that information could be presented quite differently.
Taking a slightly bigger view, it is an encapsulation problem too.
It's unexpected, and a surprise to me, for sure, that -menuForEvent:
is doing this drawing. So surprising that I had to carefully check my
results before I really believed it.
Here's a fun little method I wrote to explore this - it just fakes an
event that gradually tracks from the top of the table to the bottom.
As you can see, you wouldn't really expect it to draw anything, but it
does highlight each row in turn. The call to the window's -
displayIfNeeded is required to flush the drawing out during the loop.
<mLayersTable> is the ivar for the tableview (in fact an outline view
- I haven't tested this against a table view).
- (void) showMenuHighlightSideEffect
{
NSEvent* fakeMouseDown;
NSPoint mp;
NSRect tableFrame = [mLayersTable bounds];
int en = 12345;
mp.x = NSMidX( tableFrame );
mp.y = NSMinY( tableFrame );
while( mp.y <= NSMaxY( tableFrame ))
{
NSPoint windowLocation = [mLayersTable convertPoint:mp toView:nil];
fakeMouseDown = [NSEvent mouseEventWithType:NSRightMouseDown
location:windowLocation
modifierFlags:0
timestamp:GetCurrentEventTime()
windowNumber:[[mLayersTable window] windowNumber]
context:[NSGraphicsContext currentContext]
eventNumber:en++
clickCount:1
pressure:1.0];
NSMenu* menu = [mLayersTable menuForEvent:fakeMouseDown];
[[mLayersTable window] displayIfNeeded];
NSLog(@"menu = %@", menu );
mp.y++;
}
}
--Graham
_______________________________________________
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