• 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
setting bound value in NSActionCell subclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

setting bound value in NSActionCell subclass


  • Subject: setting bound value in NSActionCell subclass
  • From: Erik Stein <email@hidden>
  • Date: Sun, 21 Dec 2003 21:48:35 +0100

hello --

i try to implement some sort of NSSliderCell (actually it's
a cell like the rating stars in iTunes). This cell is used as
dataCell in a NSArrayController driven table view.

the following is in my document awakeFromNib method:

[[tableView tableColumnWithIdentifier:@"rating"] setDataCell:[[[CardRatingCell alloc] init] autorelease]];


the value binding of the table column is bound to the
arrayController's selection's "rating" exposed binding
(which returns a NSNumber in my implementation).

the displaying of the stars corresponding corresponding
to the rating is working fine.

i now try to change this value from the cell when the user
clicks in to the cell:

- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)flag
{
// We only get this message when the mouse went up, because stupid table view
// is eating all other mouse events while trying to catch a row drag.

float leftBorderX = NSMinX(cellFrame);
float distanceFromLeft = 0.0;

NSPoint mousePoint = [controlView convertPoint:[theEvent locationInWindow] fromView:nil];

distanceFromLeft = mousePoint.x - leftBorderX;
unsigned int newRatingValue = ceil(distanceFromLeft / 10);

[self setObjectValue:[NSNumber numberWithInt:newRatingValue]];
[(NSControl *)controlView updateCell:self];

return YES;
}

this implementation is derived from the ClockControl sample code (which
does not use the new controller layer).

(i could implement this in continueTracking: or stopTracking:, but because
the table view allows drag and drop, the cell only get's single mouseup
events.)

the question is now:

how to i set the new value from inside a cell so the the model does
reflect it?

[self setObjectValue:[NSNumber numberWithInt:newRatingValue]];

does not have any effect at all.

observing with shark what a NSSliderCell is doing in this situation reveals
the following:

-[NSApplication sendEvent:]
-[NSWindow sendEvent:]
-[NSTableView mouseDown:]
-[NSSliderCell trackMouse:inRect:ofView:untilMouseUp:]
-[NSCell trackMouse:inRect:ofView:untilMouseUp:]
-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
-[NSView displayIfNeeded]
-[NSSliderCell continueTracking:at:inView:]
-[NSWindow currentEvent]
-[NSView convertPoint:fromView:]
-[NSCell _sendActionFrom:]
-[NSControl sendAction:to:]
-[_NSBindingAdaptor objectDidTriggerAction:]
-[_NSBindingAdaptor _objectDidTriggerAction:bindingAdaptor:]
-[NSValueBinder performAction:]
-[NSValueBinder applyDisplayedValueWithHandleErrors:]
-[NSValueBinder _applyObjectValue:forBinding:handleErrors:]
-[_NSValueBinderPlugin applyObjectValue:forBinding:operation:]
-[NSBinder setValue:forBinding:atIndex:error:]
-[NSBinder _setValue:forKeyPath:ofObject:atIndex:validateImmediately: raisesForNotApplicableKeys:error:]
-[NSArrayController _setMultipleValue:forKeyPath:atIndex:]
_NSRemoveHandler2

so it seems that the official way would be to send some sort
of action to some sort of object.

thanks for your help,

-- erik
_______________________________________________
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.

  • Prev by Date: Re: Drawing custom text attributes
  • Next by Date: Adding "Bindings"
  • Previous by thread: Re: Drawing custom text attributes
  • Next by thread: Adding "Bindings"
  • Index(es):
    • Date
    • Thread