Re: NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys
Re: NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys
- Subject: Re: NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys
- From: Eric Gorr <email@hidden>
- Date: Mon, 19 Jan 2009 14:47:26 -0500
On Jan 19, 2009, at 10:40 AM, Eric Gorr wrote:
The problem appears to be that my trackMouse code consumes the
mouseUp event and that is preventing [super mouseDown:theEvent] from
terminating.
One possible solution is to add a method to my custom cell class to
set a flag which tells the trackMouse method that it was being
called due to the shift or cmd key being held down. And, when this
is the case, I don't dequeue the mouseUP event...calling NSApp's
nextEventMatchingMask instead of NSWindow's, which was originally
suggested.
theEvent = [NSApp nextEventMatchingMask:(NSLeftMouseUpMask |
NSLeftMouseDraggedMask | NSMouseEnteredMask | NSMouseExitedMask)
untilDate:[NSDate
dateWithTimeIntervalSinceNow:20]
inMode:NSEventTrackingRunLoopMode
dequeue:shouldDequeue];
This seems a bit hackish and am thinking there would be a better
solution.
Actually, there may be.
Since this is all about selection, going down a different, but related
path, I am working with outlineViewSelectionDidChange. In my delegate,
my method currently looks like:
- (void)outlineViewSelectionDidChange:(NSNotification *)notification
{
static BOOL reentry = NO;
if ( reentry == NO ) {
reentry = YES;
[resourcesThumbnails deselectAll:self];
NSEvent *currentEvent = [NSApp currentEvent];
NSPoint point = [resourcesThumbnails
convertPoint:[currentEvent locationInWindow] fromView:nil];
NSInteger row = [resourcesThumbnails
rowAtPoint:point];
id item = [resourcesThumbnails
itemAtRow:row];
BOOL isGroupItem = [self
outlineView:resourcesThumbnails isGroupItem:item];
if ( !isGroupItem ) {
NSUInteger modifierFlags = [currentEvent modifierFlags];
BOOL withShiftKey = ( modifierFlags &
NSShiftKeyMask ) == NSShiftKeyMask;
BOOL withCmdKey = ( modifierFlags &
NSCommandKeyMask ) == NSCommandKeyMask;
MyCell *aCell = (MyCell *)[resourcesThumbnails
preparedCellAtColumn:0 row:row];
NSRect cellRect = [resourcesThumbnails
frameOfCellAtColumn:0 row:row];
NSInteger resourceIndex = [aCell
subItemHitTest:currentEvent inRect:cellRect
ofView:resourcesThumbnails ];
NSDictionary *itemData = [item
objectAtIndex:resourceIndex];
NSValue *itemPointer = [itemData
objectForKey:@"Name"];
TSBResourceItem *itemInfo = (TSBResourceItemPtr)
[itemPointer pointerValue];
[resourcesThumbnails deselectedAllResources];
[resourcesThumbnails selectResource:itemInfo->fGroupID
itemID:itemInfo->fItemID];
[resourcesThumbnails setNeedsDisplay:YES];
[resourcesThumbnails display];
}
reentry = NO;
}
}
The hackish part is the need to use the static variable since
deselecting everything in the table causes the notification to be sent
again.
The nice part is that I don't have to do anything special to handle
the shift or cmd key, don't have to alter the NSOutlineView's
mouseDown method, and can still determine exactly which item in the
table was hit.
Now, I still have to write all of the anchor selection code, etc., but
that's fairly straightforward.
I think I'm happy with this solution, given my other options, but
always welcome comments.
_______________________________________________
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
References: | |
| >Custom tracking in a NSTextFieldCell (From: Eric Gorr <email@hidden>) |
| >Re: Custom tracking in a NSTextFieldCell (From: Eric Gorr <email@hidden>) |
| >NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys (From: Eric Gorr <email@hidden>) |
| >Re: NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys (From: Eric Gorr <email@hidden>) |
| >Re: NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys (From: Corbin Dunn <email@hidden>) |
| >Re: NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys (From: Eric Gorr <email@hidden>) |
| >Re: NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys (From: Corbin Dunn <email@hidden>) |
| >Re: NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys (From: Eric Gorr <email@hidden>) |
| >Re: NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys (From: Eric Gorr <email@hidden>) |
| >Re: NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys (From: Corbin Dunn <email@hidden>) |
| >Re: NSOutlineView, tracking in a custom NSTextFieldCell, & Shift&Cmd Keys (From: Eric Gorr <email@hidden>) |