unwanted cell copy being interposed during click in outline

  • In an NSOutlineView, my custom NSCell subclass has several icons in it, and
    when the user clicks on one of these I want to change it (i.e. it's a kind
    of custom checkbox).

    However, there's a problem. As the user clicks, before I get an event, Cocoa
    copies the cell and interposes the copy. Then Cocoa draws the cell; then
    when the user releases the mouse, Cocoa substitutes the original cell and
    draws again.

    So, all during mouse tracking - which is when I decide whether the user has
    clicked on an icon - there is this substitute copy in the way. However, that
    is the moment when I'm saying, aha, the user has clicked, so change the icon
    image. Great, but I'm changing the icon image in a copy! The user releases
    the mouse, and the original cell returns, with the icon unchanged.

    How am I supposed to handle this situation? Remember, the copy is made
    BEFORE the mouse starts tracking, and the original is returned AFTER the
    mouse starts tracking, so information that I store in the cell's ivars
    during tracking about how it should draw itself gets lost when the original
    cell returns. Thx - m.
    matt neuburg, phd = <matt...>, http://www.tidbits.com/matt/
    pantes anthropoi tou eidenai oregontai phusei
    AppleScript: the Definitive Guide - Second Edition!
    Take Control of Word 2004, Tiger, and more -
    Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
  • What happens if you get the column from the view, and then use
    dataCellForRow? Do you get the original or the temporary copy?

    Scott Ribe
    (303) 722-0567 voice
  • > Not sure what you mean. I'm *in* the cell. The question is - who am I?

    Right, got it. I guess in my opinion the cleanest option would be to not
    keep the state in the cell itself, but rather a pointer to an object with
    the state. Seems to fit with the current model, where cell has methods to
    set a string value or an object value (or various numbers).

    Scott Ribe
    (303) 722-0567 voice
  • > But how's that going to work? Are you suggesting that my copyWithZone
    > implementation should simply do a retain?


    > But in that case EVERY cell will
    > share the same object-pointed-to - not merely the two that are being swapped
    > back and forth during mousedown.

    No, because your data source will implement
    outlineView:objectValueForTableColumn:byItem: which will set the
    object-pointed-to as needed for the current row. Or, perhaps your delegate
    could implement outlineView:willDisplayCell:forTableColumn:item: to set the
    value, though I'm not sure that would be called at an appropriate time for
    use in tracking...

    Scott Ribe
    (303) 722-0567 voice
previous month october 2006 next month
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