NSMatrix and selecting ranges with setSelectionFrom
NSMatrix and selecting ranges with setSelectionFrom
- Subject: NSMatrix and selecting ranges with setSelectionFrom
- From: Aaron Braunstein <email@hidden>
- Date: Thu, 28 Oct 2004 15:15:21 -0700
I normally try to muscle my way through problems before resorting to submitting questions to the list, but I can't seem to figure this one out. Sadly, I've been unable to find any reference to a problem like this being reported by anybody else, so I'm presuming that I'm missing something obvious. Any assistance would be greatly appreciated.
In short, I've come to the conclusion that - unlike NSTableView - NSMatrix doesn't seem to offer built-in support for standard selection behavior (i.e. discontinuous selections, shift-selecting for ranges, highlighting, etc.) I'm therefore doing it myself in my own NSMatrix and NSImageCell subclasses. I've gotten single-click and command-click selections to work as they should. The problem arises when I try to implement shift-clicking of ranges. In my event handler, I detect that a shift-click has occurred and make my decision as to what range to highlight - if any. I then call setSelectionFrom:to:anchor:highlight to do the job. Therein lies the rub. Nothing gets highlighted and when I query the matrix via selectedCells, I find that only one of my specified range of cells is getting selected.
Figuring there's only three parameters to deal with, I set up a small test to see how the various permutations of the method would behave. Given a 5col x 3row matrix, I tried each of the following to get select the middle 3 elements of the top row.
[theMatrix setSelectionFrom:1 to:1 anchor:1 highlight:YES]; // Selects cell 1 only
[theMatrix setSelectionFrom:1 to:1 anchor:3 highlight:YES]; // Selects cell 1 only
[theMatrix setSelectionFrom:1 to:3 anchor:1 highlight:YES]; // Selects cell 3 only
[theMatrix setSelectionFrom:1 to:3 anchor:3 highlight:YES]; // Selects cell 3 only
[theMatrix setSelectionFrom:3 to:1 anchor:1 highlight:YES]; // Selects cell 1 only
[theMatrix setSelectionFrom:3 to:1 anchor:3 highlight:YES]; // Selects cell 1 only
[theMatrix setSelectionFrom:3 to:3 anchor:1 highlight:YES]; // Selects cell 3 only
[theMatrix setSelectionFrom:3 to:3 anchor:3 highlight:YES]; // Selects cell 3 only
As I mentioned before, none of the cells highlight. I could only tell what was selected by querying selectedCells. What am I missing?
I know I could do this iteratively, but it seems to me that if there's a call there already to do the job I should be using it instead of hacking stuff myself.
--
Aaron Braunstein
"Good enough" shouldn't be.
From there the fall into mediocrity and indifference is a short one. _______________________________________________
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