NSBrowser with checkboxes?

  • I need to create an NSBorwser where each cell also has a checkbox, in
    addition to the normal image and text. I've checked the list archives
    and circa 2004 the answer was to subclass NSBrowserCell and subclass
    the NSMatrix the browser uses to intercept the click and route it to
    the checkbox.

    Is this still the recommended implementation, or is there an easier
    way to do this now?

    Thanks,
    Dave
  • On 13/12/2007, at 8:33 AM, Dave Camp wrote:

    > I need to create an NSBorwser where each cell also has a checkbox,
    > in addition to the normal image and text. I've checked the list
    > archives and circa 2004 the answer was to subclass NSBrowserCell
    > and subclass the NSMatrix the browser uses to intercept the click
    > and route it to the checkbox.
    >
    > Is this still the recommended implementation, or is there an easier
    > way to do this now?
    >
    > Thanks,
    > Dave

    Hi Dave,

    I haven't actually run this, but it does set up a switch button
    (checkbox) in a table cell when I build and run.  I used this method
    to add a circular push button.  This is taken from an example by Joar
    Wingfors.

    - (void)awakeFromNib
    {
    NSButtonCell *switchCell = [[[NSButtonCell alloc] init] autorelease];
    [switchCell setButtonType:NSSwitchButton];
    [switchCell setTitle:@"OK"];
    [switchCell setControlSize:NSSmallControlSize];
    [switchCell setTarget:self];
    [myTableColumnOutlet setDataCell:switchCell];
    }

    HTH,

    Ron
  • On Dec 12, 2007, at 7:02 PM, Ron Fleckner wrote:

    > On 13/12/2007, at 8:33 AM, Dave Camp wrote:
    >
    >> I need to create an NSBorwser where each cell also has a checkbox,
    >> in addition to the normal image and text. I've checked the list
    >> archives and circa 2004 the answer was to subclass NSBrowserCell
    >> and subclass the NSMatrix the browser uses to intercept the click
    >> and route it to the checkbox.
    >>
    >> Is this still the recommended implementation, or is there an easier
    >> way to do this now?
    >>
    >> Thanks,
    >> Dave
    >
    > Hi Dave,
    >
    > I haven't actually run this, but it does set up a switch button
    > (checkbox) in a table cell when I build and run.  I used this method
    > to add a circular push button.  This is taken from an example by
    > Joar Wingfors.

    Is that for an NSTableView or an NSBrowser? NSBrowser seems to reject
    any cells that aren't decendents of NSBrowserCell. I'm working on a
    subclass of NSBrowserCell that also has a member NSButtonCell but I
    don't think I've overridden enough mouse tracking methods yet. Back to
    the grindstone...

    Dave
  • On 13/12/2007, at 2:36 PM, Dave Camp wrote:

    > On Dec 12, 2007, at 7:02 PM, Ron Fleckner wrote:
    >
    >> On 13/12/2007, at 8:33 AM, Dave Camp wrote:
    >>
    >>> I need to create an NSBorwser where each cell also has a
    >>> checkbox, in addition to the normal image and text. I've checked
    >>> the list archives and circa 2004 the answer was to subclass
    >>> NSBrowserCell and subclass the NSMatrix the browser uses to
    >>> intercept the click and route it to the checkbox.
    >>>
    >>> Is this still the recommended implementation, or is there an
    >>> easier way to do this now?
    >>>
    >>> Thanks,
    >>> Dave
    >>
    >> Hi Dave,
    >>
    >> I haven't actually run this, but it does set up a switch button
    >> (checkbox) in a table cell when I build and run.  I used this
    >> method to add a circular push button.  This is taken from an
    >> example by Joar Wingfors.
    >
    > Is that for an NSTableView or an NSBrowser? NSBrowser seems to
    > reject any cells that aren't decendents of NSBrowserCell. I'm
    > working on a subclass of NSBrowserCell that also has a member
    > NSButtonCell but I don't think I've overridden enough mouse
    > tracking methods yet. Back to the grindstone...
    >
    > Dave

    Uh, yeah, it's for a tableview.  Sorry.

    Good luck,

    Ron
  • My current attempt at this is a subclass of NSBrowserCell which also
    creates an NSButton. I've overridden the following methods to dispatch
    calls to either the NSButton or super depending on the coordinates:

    - drawWithFrame:nView:
    - startTrackingAt:inView:
    - continueTracking:at:inView:
    - stopTracking:at:inView:mouseIsUp:
    - trackMouse:inRect:ofView:untilMouseUp:

    That gets me part of the desired functionality. The checkbox and the
    browser cell display and track the mouse as expected, and clicking the
    checkbox toggles it on and off.

    What I can't get to work is the action message from the checkbox. I've
    set the target and action for the embedded checkbox to send a message
    to my window controller. I need this so that the window controller can
    tell which checkbox was clicked and do something to the item that cell
    represents. What happens is that my window controller gets called, but
    the sender is the enclosing NSMatrix, not the cell itself.

    Looking at the docs for NSMatrix, I can see there are rules for how to
    dispatch action messages when both the target and action of a cell are
    not set, but I've verified in the debugger that the action and target
    are in fact set in my embedded checkbox.

    Thoughts?

    Dave
  • > My current attempt at this is a subclass of NSBrowserCell which also
    > creates an NSButton. I've overridden the following methods to
    > dispatch calls to either the NSButton or super depending on the
    > coordinates:

    I’ll assume you mean an NSButton cell.

    > What I can't get to work is the action message from the checkbox.
    > I've set the target and action for the embedded checkbox to send a
    > message to my window controller. I need this so that the window
    > controller can tell which checkbox was clicked and do something to
    > the item that cell represents. What happens is that my window
    > controller gets called, but the sender is the enclosing NSMatrix,
    > not the cell itself.

    That’s the expected behavior for an NSControl; the control view, not
    the cell, is used as the sender of the action message. The cell you
    clicked on should be accessible as the key cell (-[NSMatrix keyCell]).

    -Ben
  • On Dec 13, 2007, at 2:21 PM, Benjamin Stiglitz wrote:

    >> My current attempt at this is a subclass of NSBrowserCell which
    >> also creates an NSButton. I've overridden the following methods to
    >> dispatch calls to either the NSButton or super depending on the
    >> coordinates:
    >
    > I’ll assume you mean an NSButton cell.
    >
    >> What I can't get to work is the action message from the checkbox.
    >> I've set the target and action for the embedded checkbox to send a
    >> message to my window controller. I need this so that the window
    >> controller can tell which checkbox was clicked and do something to
    >> the item that cell represents. What happens is that my window
    >> controller gets called, but the sender is the enclosing NSMatrix,
    >> not the cell itself.
    >
    > That’s the expected behavior for an NSControl; the control view, not
    > the cell, is used as the sender of the action message. The cell you
    > clicked on should be accessible as the key cell (-[NSMatrix keyCell]).

    That's exactly what I needed!

    Thanks,
    Dave
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today