• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Fast double click, vs slow one, different actions?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fast double click, vs slow one, different actions?


  • Subject: Re: Fast double click, vs slow one, different actions?
  • From: Paul Kim <email@hidden>
  • Date: Tue, 19 Sep 2006 21:59:48 -0400

The way I did it was not pretty but it works.

As others have said, it is the difference between two single clicks and a double click. Also, the second single click needs to be on the actual text.

Sorry this is in mostly prose form but my code has other stuff strewn in so it's hard for me to extract blocks at the moment. There might also be references to variables outside of the code but it should be pretty easy to figure out where those values come from:

- Subclass NSTableView. Added ivars and accessor methods for previouslySelectedRow and mouseDownLocation.
- In your subclass, also add a method to calculate the size of the actual text and return the rect. My implementation below (could use some work):


- (NSRect)contentRectOfCellAtColumn:(int)columnIndex row:(int)rowIndex
{
NSTableColumn *tableColumn;
NSSize size;
NSRect rect;
NSCell *cell;
NSTextAlignment alignment;

tableColumn = [[self tableColumns] objectAtIndex:columnIndex];
cell = [tableColumn dataCellForRow:rowIndex];
cell = [cell copy];
[cell setObjectValue:[[self dataSource] tableView:self objectValueForTableColumn:tableColumn row:rowIndex]];

rect = [self frameOfCellAtColumn:columnIndex row:rowIndex];
size = [cell cellSizeForBounds:rect];
alignment = [cell alignment];

switch (alignment)
{
case NSRightTextAlignment:
rect.origin.x = NSMaxX(rect) - size.width;
break;
case NSCenterTextAlignment:
case NSJustifiedTextAlignment:
rect.origin.x = NSMinX(rect) + ((NSWidth(rect) - size.width) / 2);
break;
case NSLeftTextAlignment:
// FUTURE: for localization, need to account for right-to-left text
case NSNaturalTextAlignment:
default:
break;
}
rect.size.height = size.height;
rect.size.width = size.width;
[cell release];
return rect;
}


- Override -mouseDown to record the previouslySelectedRow and mouseDownLocation. Remember to call super after.
- Set the single click action of the table to some method on some object.
- In that method, grab the previously selected row, mousedown location and calculate the cell rect.
- If the current row being selected is the same as the previous row and the mousedown location is in the cell rect you calculated AND
- If the next mouse down event does not exist within the double- click time:
![window nextEventMatchingMask:NSLeftMouseDownMask untilDate: [NSDate dateWithTimeIntervalSinceNow:(GetDblTime() / 60.0)] inMode:NSDefaultRunLoopMode dequeue:NO]
- Then: [tableView editColumn:column row:row withEvent:nil select:YES];
- Set the double action to whatever you want. It will still get called in the case of a double-click since the code above does not dequeue the mousedown event.


There are probably ways to consolidate more of the code into the table view itself instead of relying on the target but at least this should give you something to work with.

paul



On Sep 19, 2006, at 5:22 PM, Theodore H. Smith wrote:

How can I make an NSTable, give different actions, with a fast double click vs a slow one? Kind of like iTunes does.

I want it to work much like iTunes actually. Fast one will perform a normal action, and a slow one will edit the name.

No idea how to do it.

--
http://elfdata.com/plugin/



_______________________________________________
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

_______________________________________________ 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
References: 
 >Fast double click, vs slow one, different actions? (From: "Theodore H. Smith" <email@hidden>)

  • Prev by Date: Re: stepper motors + OS X
  • Next by Date: RE: How is an Cocoa application launched on top of all other windows that may be open ?
  • Previous by thread: Re: Fast double click, vs slow one, different actions?
  • Next by thread: NSViewAnimation: sliding one view down over another in a tab view
  • Index(es):
    • Date
    • Thread