Re: NSTextView Custom Class "Not Applicable"
Re: NSTextView Custom Class "Not Applicable"
- Subject: Re: NSTextView Custom Class "Not Applicable"
- From: Timothy Ritchey <email@hidden>
- Date: Mon, 15 Apr 2002 14:48:07 -0500
Here is the code I use in RRSpreadSheet to deal with an NSTextView that
is the editor for a large number of cells that make up the spreadsheet.
If you set yourself up as the delagate, you can implement the following
selector, and then control what happens with different keystrokes:
- (BOOL)textView:(NSTextView *)aTextView
doCommandBySelector:(SEL)aSelector
{
// check to see if we got a return or tab, and move accordingly
NSEvent *event = [NSApp currentEvent];
unsigned int modifier = [event modifierFlags];
id cell = nil;
int newIndex;
RRPosition *newPos = [RRPosition
positionForRow:[trackingCellPosition row]
column:[trackingCellPosition column]];
unichar key = [[event characters] characterAtIndex:0];
if([event keyCode] == 48 && modifier & NSShiftKeyMask) {
newIndex = [newPos column] - 1;
if(newIndex < 0)
newIndex = 0;
[newPos setColumn:newIndex];
} else if([event keyCode] == 48) {
// move one column to the right
newIndex = [newPos column] + 1;
if(newIndex == [columns count])
[self addColumns:1];
[newPos setColumn:newIndex];
}else if([event keyCode] == 36) {
// move one row down
newIndex = [newPos row] + 1;
if(newIndex == [rows count])
[self addRows:1];
[newPos setRow:newIndex];
} else if(key == NSDownArrowFunctionKey) {
// move one row down
newIndex = [newPos row] + 1;
if(newIndex == [rows count])
[self addRows:1];
[newPos setRow:newIndex];
} else if(key == NSUpArrowFunctionKey) {
newIndex = [newPos row] - 1;
if(newIndex < 0)
newIndex = 0;
[newPos setRow:newIndex];
} else if(key == NSRightArrowFunctionKey && allowRightArrowMove) {
// move one row down
newIndex = [newPos column] + 1;
if(newIndex == [columns count])
[self addColumns:1];
[newPos setColumn:newIndex];
} else if(key == NSLeftArrowFunctionKey && allowLeftArrowMove) {
newIndex = [newPos column] - 1;
if(newIndex < 0)
newIndex = 0;
[newPos setColumn:newIndex];
} else {
return NO;
}
cell = [cells objectForKey:newPos];
if(!cell)
cell = [self createCellForRow:[newPos row] column:[newPos
column]];
if(currentlyEditingCell) {
[self textShouldEndEditing:textEditor];
[self beginEditingCell:cell];
} else {
[self deselectCellAtRow:[trackingCellPosition row]
column:[trackingCellPosition column]];
}
return YES;
}
On Monday, April 15, 2002, at 01:23 PM, Manfred Lippert wrote:
BTW: I am trying to filter some keys in an NSTextView. Is there a
better way
than subclassing NSTextView? (Some delegate methods I haven't seen?)
Yes, there usually is, but it depends a bit on which keys you are
looking for.
I am looking for Control+TAB or Option+TAB ...
... OK, here is the full story: ;-)
(Perhaps you know LittleSecrets; if not, you can take a look at it on
http://www.littlesecrets.de)
I have an NSOutlineView and an NSTextView in a window. If I am in the
OutlineView and press the TAB key, I can jump from the OutlineView to
the
TextView. But I can not jump back, because there is instead a Tabulator
inserted in the TextView, of course.
A few weeks ago, if I pressed Control+TAB, I _could_ jump from TextView
to
OutlineView. But this suddenly does not work anymore! I don't know why.
Does anyone know?
So I choose to implement it myself to be 100% sure Control+TAB always
works
and does not depend on some mystic system behaviour. ;-)
Bad news: I successfully subclassed NSTextView now (thanx to Peter
Horn!)
and I override keyDown. But it is NOT called, when Control+TAB is
pressed!
Anyone knows why?
OK, I choose to use Option+TAB now ... I can filter that in keyDown.
Some more bad news: I tried to jump to my OutlineView with
[window makeFirstResponder:outlineView];
But this also does not work?!?
Again: Does anyone know why? ;-}
Thank you,
Mani
_______________________________________________
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.
_______________________________________________
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.