• 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
Updating NSMatrix selection bindings (custom selection behavior)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Updating NSMatrix selection bindings (custom selection behavior)


  • Subject: Updating NSMatrix selection bindings (custom selection behavior)
  • From: "Lawrence Sanbourne" <email@hidden>
  • Date: Mon, 17 Apr 2006 16:21:18 -0500

Hello,

I've created an NSMatrix subclass that re-implements -mouseDown so
that I can support drag and drop in the future. (This was previously
described at <http://www.cocoabuilder.com/archive/message/cocoa/2004/6/24/110438>.)
I've also changed the selection behavior to match what iPhoto does
when the user shift-clicks. My code is at the bottom of this message.

The problem is that the bound controller isn't getting updated. (It's
bound to NSMatrix's selectedObjects key.) So I figured I needed to
override NSMatrix's selection modification methods and notify the
bound controller, but this isn't doing the trick. I'm calling this
method from each overridden selection modification method:

- (void)updateSelectionBindings {
	int selectedCellPos = [self selectedRow] * [self numberOfColumns] +
[self selectedColumn];
	NSCell *selectedCell = [self cellAtRow:[self selectedRow]
column:[self selectedColumn]];

	[[observedObjects objectForKey:@"selectedIndex"] setValue:[NSNumber
numberWithInt:selectedCellPos] forKey:[keyPaths
objectForKey:@"selectedIndex"]];
	[[observedObjects objectForKey:@"selectedObject"]
setValue:[selectedCell objectValue] forKey:[keyPaths
objectForKey:@"selectedObject"]];
	[[observedObjects objectForKey:@"selectedTag"] setValue:[NSNumber
numberWithInt:[selectedCell tag]] forKey:[keyPaths
objectForKey:@"selectedTag"]];
	[[observedObjects objectForKey:@"selectedValue"]
setValue:[selectedCell objectValue] forKey:[keyPaths
objectForKey:@"selectedValue"]];
	// ...
}

So, I think I don't understand how bindings work under the hood. How
should I be fixing my selection problems?

Looking forward to any help!

Larry

The -mouseUp code, as promised:

// Reference: http://www.cocoadev.com/index.pl?DragMatrix
- (void)mouseUp:(NSEvent *)theEvent {
	int clickedRow, clickedCol;
	// Send event to super if there was no accompanying down event (i.e.,
drag started) or if the clicked area isn't in the view.
	if (![self downEvent] || ![self getRow:&clickedRow column:&clickedCol
forPoint:[self convertPoint:[theEvent locationInWindow]
fromView:nil]]) {
		[super mouseUp:theEvent];
		return;
	}

	if ([theEvent modifierFlags] & NSCommandKeyMask) {
		int position = clickedRow * [self numberOfColumns] + clickedCol;
		[self addSelectedCellAtPosition:position];
	} else if ([theEvent modifierFlags] & NSShiftKeyMask && [self
selectedRow] != -1 && [self selectedColumn] != -1) {
		int lastSelectedPosition = [self selectedRow] * [self
numberOfColumns] + [self selectedColumn];
		int clickedPosition = clickedRow * [self numberOfColumns] + clickedCol;

		// Loop forwards or backwards depending on where clickedPosition is
in relation to lastSelectedPosition.
		int delta = (lastSelectedPosition > clickedPosition ? 1 : -1);

		// Select everything in between lastSelectedPosition and clickedPosition.
		int position;
		for (position = clickedPosition; (delta > 0 && position <
lastSelectedPosition) || (delta < 0 && position >
lastSelectedPosition); position += delta) {
			[self addSelectedCellAtPosition:position];
		}
	} else {
		[self selectCellAtRow:clickedRow column:clickedCol];
	}
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: webkit -> print
  • Next by Date: Re: addObserver:forKeyPath:options:context
  • Previous by thread: Re: webkit -> print
  • Next by thread: can't run app from applications folder -- permissions problem?
  • Index(es):
    • Date
    • Thread