Re: NSMatrix selections
Re: NSMatrix selections
- Subject: Re: NSMatrix selections
- From: Tom Waters <email@hidden>
- Date: Sat, 9 Jun 2001 17:26:46 -0700
On Friday, June 8, 2001, at 12:52 PM, Tom Waters wrote:
I've been digging deeper into NSBrowser and have my own NSMatrix
subclass in use to support drag and drop, etc.
I note that NSMatrix also doesn't have a method for making
discontinuous selections, even though the user can make them through
the interface.
NSMatrix adds setSelectionFrom:to:anchor:highlight: which allows for
multiple selection, but I'm assuming that selectCellAtRow:column
selects only a single cell, as that is the behavior that NSBrowser
shows.
Here's a simple example of what I mean.
Create a new Cocoa application.
Edit the main nib file, throw an NSBrowser and a button into the window.
Subclass NSApplication with a class called BrowserBug
make an outlet on BrowserBug called browser, and an action called doit:
set File's Owner's custom class to BrowserBug
hook up the button to File's Owner and connect the doit: message.
hook up the NSBrowser instance to File's Owner and connect it to the
delegate outlet.
hook up File's Owner to the NSBrowser instance and connect it to the
browser outlet.
put the following code into BrowserBug.m
All this example does is provide 10 rows for each column of the browser,
with the first 5 being branches and the last 5 being leaves. When you
press the button, it tries to select four discontinuous rows, and you
can see that only the last one sticks.
Is there any way to select multiple discontinuous rows in an NSBrowser
column? (or NSMatrix?)
#import <Cocoa/Cocoa.h>
@interface BrowserBug : NSApplication
{
IBOutlet NSBrowser *browser;
}
@end
@implementation BrowserBug
- (int)browser:(NSBrowser *)browser numberOfRowsInColumn: (int)col
{
return 10;
}
- (void)browser:(NSBrowser *)browser willDisplayCell:(NSBrowserCell
*)cell atRow:(int)row column:(int)col
{
[cell setTitle: [NSString stringWithFormat: @"%d %d", col, row]];
[cell setLeaf: (row > 4)];
}
- (IBAction)doit:(id)sender
{
int col = [browser lastColumn];
[browser selectRow: 2 inColumn: col];
[browser selectRow: 4 inColumn: col];
[browser selectRow: 6 inColumn: col];
[browser selectRow: 8 inColumn: col];
}
@end