• 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: acceptsFirstMouse with NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: acceptsFirstMouse with NSTableView


  • Subject: Re: acceptsFirstMouse with NSTableView
  • From: Bill Cheeseman <email@hidden>
  • Date: Tue, 02 Sep 2008 05:20:52 -0400
  • Thread-topic: acceptsFirstMouse with NSTableView

on 2008-09-01 11:41 PM, Ron Wagner at email@hidden wrote:

> I am trying to get an NSTableView to change it's selection when
> clicking on one if it's cells when it's window is not active. I have
> subclassed NSTableView, overridden acceptsFirstMouse: and return YES
> unconditionally, and verified that it is getting called. Can't seem to
> get it to change behavior. Still takes once click to activate the
> window and a second click to select the clicked on cell. What is the
> trick to getting this to work?

In general, holding the Command key down while clicking user controls in a
background application appears to be the standard Mac OS X convention for
keeping the application in the background. But it doesn't work in table
views without a little help.

In PreFab UI Browser 2.0, I allow a Command-click on a table view row to
select the row while leaving the application in the background by
subclassing NSTableView and overriding -mouseDown:, as shown below. The call
to the -tableView:shouldSelectRow: delegate method is in there because I
implement it anyway for other reasons; if you don't need that, you'll have
to modify this snippet a little.

@implementation PFClickthroughTableView

- (void)mouseDown:(NSEvent *)event {
    // Allow Command-click on a table row to select the row under the mouse
if the application is in the background, without bringing the application to
the front; normally, Command-click would deselect the row.
    if (![NSApp isActive] && ([event modifierFlags] & NSCommandKeyMask)) {
        NSInteger row = [self rowAtPoint:[self convertPoint:[event
locationInWindow] fromView:nil]];
        if ([[self delegate] tableView:self shouldSelectRow:row]) {
            [self selectRowIndexes:[NSIndexSet indexSetWithIndex:row]
byExtendingSelection:NO];
            [self sendAction:[self action] to:[self target]];
        }
        return;
    }
    [super mouseDown:event];
}


--

Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
www.quecheesoftware.com

PreFab Software - www.prefabsoftware.com


_______________________________________________

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

  • Follow-Ups:
    • Re: acceptsFirstMouse with NSTableView
      • From: Corbin Dunn <email@hidden>
References: 
 >acceptsFirstMouse with NSTableView (From: Ron Wagner <email@hidden>)

  • Prev by Date: Re: Problem with NSUserDefaultsController
  • Next by Date: Re: Trouble with Scripting Bridge
  • Previous by thread: acceptsFirstMouse with NSTableView
  • Next by thread: Re: acceptsFirstMouse with NSTableView
  • Index(es):
    • Date
    • Thread