• 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: NSTableView, PopUpButtons, and controlling selection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView, PopUpButtons, and controlling selection


  • Subject: Re: NSTableView, PopUpButtons, and controlling selection
  • From: Aaron Burghardt <email@hidden>
  • Date: Sun, 22 Jun 2003 00:35:48 -0400

On Saturday, June 21, 2003, at 09:28 PM, Aaron Burghardt wrote:

On Wednesday, June 18, 2003, at 11:12 AM, Aaron Burghardt wrote:

Hi All,

I am using an NSTableView in which one column has a PopUpButton cell.
I have the popup displaying and functioning correctly. However, I
don't want the selection in the table to change when the user clicks
on the popup, but I haven't figured out how to achieve this behavior
(the check boxes next to the song names in iTunes exhibit the behavior
I'm looking for).

I experimented with

- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView

but if I return NO, then the mouse click event doesn't reach the
popup. I also looked at subclassing NSPopUpButtonCell and tracking the
mouse in the cell, but that's too late, the selection has already
changed. I could use tracking in the cell and require a ctrl-click to
activate the popup, but I shouldn't have to resort to that.

The only other possibility I can think of is to subclass NSTableView
and override the mousedown event, but I suspect I will have to do a
lot of work to determine whether the event happened over popup cell.



OK, I've been experimenting with subclassing NSTableView to prevent the
selection from changing when a cell is clicked and have achieved
acceptable results. Here is my code:

@implementation CustomTableView

- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint location = [self convertPoint:[theEvent locationInWindow]
fromView:nil];

if ( NSPointInRect(location, [self rectOfColumn:2]) ) {

int row = [self rowAtPoint:location];
NSPopUpButtonCell *cell = [[self
tableColumnWithIdentifier:@"popup"] dataCellForRow:row];
NSRect frame = [self frameOfCellAtColumn:2 row:row];

[cell highlight:YES withFrame:frame inView:self];

if ([cell trackMouse:theEvent inRect:frame ofView:self
untilMouseUp:NO]) {
[[self dataSource] tableView:self
setObjectValue:[NSNumber numberWithInt:[cell
indexOfSelectedItem]]
forTableColumn:[self
tableColumnWithIdentifier:@"popup"]
row:row];
}

[cell highlight:NO withFrame:frame inView:self];

} else {

[super mouseDown:theEvent];

}
}

@end

Oops, I overlooked calling delegates. I had to call:

[[self delegate] tableView:self
willDisplayCell:cell
forTableColumn:[self tableColumnWithIdentifier:@"label"]
row:(int)row];

Which I added right before the [cell highlight:YES...] call.

----
Aaron Burghardt
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: NSTableView, PopUpButtons, and controlling selection (From: Aaron Burghardt <email@hidden>)

  • Prev by Date: Re: TrollTech releases QT for Mac under GPL
  • Next by Date: NSConnection timeout problem...
  • Previous by thread: Re: NSTableView, PopUpButtons, and controlling selection
  • Next by thread: NSWindowDepth Encoding
  • Index(es):
    • Date
    • Thread