Use method calls instead of some of the direct references to

NSLayoutManager ivar. General clean up.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16092 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2003-03-01 00:43:54 +00:00
parent 70ab76af44
commit 1bca606807

View file

@ -1,6 +1,8 @@
/** <title>NSTextView</title> /** <title>NSTextView</title>
Copyright (C) 1996, 1998, 2000, 2001, 2002 Free Software Foundation, Inc. <abstract>Categories which add user actions to NSTextView</abstract>
Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
Originally moved here from NSTextView.m. Originally moved here from NSTextView.m.
@ -40,8 +42,8 @@
You should have received a copy of the GNU Library General Public You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB. License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation, If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <Foundation/NSNotification.h> #include <Foundation/NSNotification.h>
#include <Foundation/NSValue.h> #include <Foundation/NSValue.h>
@ -51,11 +53,6 @@
#include <AppKit/NSTextStorage.h> #include <AppKit/NSTextStorage.h>
#include <AppKit/NSTextView.h> #include <AppKit/NSTextView.h>
/**** User actions ****/
/* TODO: all these need to be cleaned up */
/* /*
These methods are for user actions, ie. they are normally called from These methods are for user actions, ie. they are normally called from
-doCommandBySelector: (which is called by the input manager) in response -doCommandBySelector: (which is called by the input manager) in response
@ -69,7 +66,6 @@ and make sure all necessary notifications are sent. This is done by sending
All actions from NSResponder that make sense for a text view should be All actions from NSResponder that make sense for a text view should be
implemented here, but this is _not_ the place to add new actions. implemented here, but this is _not_ the place to add new actions.
When changing attributes, the range returned by When changing attributes, the range returned by
rangeForUserCharacterAttributeChange or rangeForUserParagraphAttributeChange rangeForUserCharacterAttributeChange or rangeForUserParagraphAttributeChange
should be used. If the location is NSNotFound, nothing should be done (in should be used. If the location is NSNotFound, nothing should be done (in
@ -79,21 +75,13 @@ returns YES, the attributes of the range and the typing attributes should be
changed, and -didChangeText should be called. changed, and -didChangeText should be called.
In a non-rich-text text view, the typing attributes _must_always_ hold the In a non-rich-text text view, the typing attributes _must_always_ hold the
attributes of the text. Thus, the typing attributes muse always be changed attributes of the text. Thus, the typing attributes must always be changed
in the same way that the attributes of the text are changed. in the same way that the attributes of the text are changed.
(TODO: Will need to look over methods that deal with attributes to make
sure this holds.)
TODO: can the selected range's location be NSNotFound? when? TODO: can the selected range's location be NSNotFound? when?
Not all user actions are here. Exceptions: Not all user actions are here. Exceptions:
-toggleRuler:
-copy: -copy:
-copyFont: -copyFont:
-copyRuler: -copyRuler:
@ -108,9 +96,6 @@ Not all user actions are here. Exceptions:
-selectAll: (implemented in NSText) -selectAll: (implemented in NSText)
-toggleContinuousSpellChecking:
Not all methods that handle user-induced text modifications are here. Not all methods that handle user-induced text modifications are here.
Exceptions: Exceptions:
(TODO) (TODO)
@ -372,7 +357,6 @@ static NSNumber *float_plus_one(NSNumber *cur)
[_layoutManager->_typingAttributes removeObjectForKey: NSSuperscriptAttributeName]; [_layoutManager->_typingAttributes removeObjectForKey: NSSuperscriptAttributeName];
[_layoutManager->_typingAttributes removeObjectForKey: NSBaselineOffsetAttributeName]; [_layoutManager->_typingAttributes removeObjectForKey: NSBaselineOffsetAttributeName];
[self didChangeText]; [self didChangeText];
} }
@ -685,10 +669,22 @@ added to the selection (1,3).
- (unsigned int) _movementOrigin - (unsigned int) _movementOrigin
{ {
if (_layoutManager->_selectionAffinity == NSSelectionAffinityUpstream) NSRange range = [self selectedRange];
return _layoutManager->_selected_range.location;
if ([self selectionAffinity] == NSSelectionAffinityUpstream)
return range.location;
else else
return NSMaxRange(_layoutManager->_selected_range); return NSMaxRange(range);
}
- (unsigned int) _movementEnd
{
NSRange range = [self selectedRange];
if ([self selectionAffinity] == NSSelectionAffinityDownstream)
return range.location;
else
return NSMaxRange(range);
} }
- (void) _moveTo: (unsigned int)cindex - (void) _moveTo: (unsigned int)cindex
@ -696,11 +692,7 @@ added to the selection (1,3).
{ {
if (select) if (select)
{ {
unsigned int anchor; unsigned int anchor = [self _movementEnd];
if (_layoutManager->_selectionAffinity == NSSelectionAffinityDownstream)
anchor = _layoutManager->_selected_range.location;
else
anchor = NSMaxRange(_layoutManager->_selected_range);
if (anchor < cindex) if (anchor < cindex)
{ {
@ -750,7 +742,6 @@ added to the selection (1,3).
_originalInsertionPointCharacterIndex = cindex; _originalInsertionPointCharacterIndex = cindex;
} }
cindex = [_layoutManager characterIndexMoving: direction cindex = [_layoutManager characterIndexMoving: direction
fromCharacterIndex: cindex fromCharacterIndex: cindex
originalCharacterIndex: _originalInsertionPointCharacterIndex originalCharacterIndex: _originalInsertionPointCharacterIndex
@ -766,56 +757,17 @@ added to the selection (1,3).
/* /*
Insertion point movement actions. Insertion point movement actions.
TODO: should implement: (D marks done)
D-(void) moveBackward: (id)sender;
D-(void) moveBackwardAndModifySelection: (id)sender;
D-(void) moveForward: (id)sender;
D-(void) moveForwardAndModifySelection: (id)sender;
D-(void) moveDown: (id)sender;
D-(void) moveDownAndModifySelection: (id)sender;
D-(void) moveUp: (id)sender;
D-(void) moveUpAndModifySelection: (id)sender;
D-(void) moveLeft: (id)sender;
D-(void) moveRight: (id)sender;
D-(void) moveWordBackward: (id)sender;
D-(void) moveWordBackwardAndModifySelection: (id)sender;
D-(void) moveWordForward: (id)sender;
D-(void) moveWordForwardAndModifySelection: (id)sender;
D-(void) moveToBeginningOfDocument: (id)sender;
D-(void) moveToEndOfDocument: (id)sender;
D-(void) moveToBeginningOfLine: (id)sender;
D-(void) moveToEndOfLine: (id)sender;
-(void) moveToBeginningOfParagraph: (id)sender;
-(void) moveToEndOfParagraph: (id)sender;
TODO: think hard about behavior for pageUp: and pageDown:
D-(void) pageDown: (id)sender;
D-(void) pageUp: (id)sender;
TODO: some of these used to do nothing if self is a field editor. should TODO: some of these used to do nothing if self is a field editor. should
check if there was a reason for that. check if there was a reason for that.
*/ */
- (void) moveUp: (id)sender - (void) moveUp: (id)sender
{ {
[self _move: GSInsertionPointMoveUp [self _move: GSInsertionPointMoveUp
distance: 0.0 distance: 0.0
select: NO]; select: NO];
} }
- (void) moveUpAndModifySelection: (id)sender - (void) moveUpAndModifySelection: (id)sender
{ {
[self _move: GSInsertionPointMoveUp [self _move: GSInsertionPointMoveUp
@ -829,6 +781,7 @@ check if there was a reason for that.
distance: 0.0 distance: 0.0
select: NO]; select: NO];
} }
- (void) moveDownAndModifySelection: (id)sender - (void) moveDownAndModifySelection: (id)sender
{ {
[self _move: GSInsertionPointMoveDown [self _move: GSInsertionPointMoveDown
@ -854,15 +807,18 @@ check if there was a reason for that.
- (void) moveBackward: (id)sender - (void) moveBackward: (id)sender
{ {
unsigned int to = [self _movementOrigin]; unsigned int to = [self _movementOrigin];
if (to == 0) if (to == 0)
return; return;
to--; to--;
[self _moveTo: to [self _moveTo: to
select: NO]; select: NO];
} }
- (void) moveBackwardAndModifySelection: (id)sender - (void) moveBackwardAndModifySelection: (id)sender
{ {
unsigned int to = [self _movementOrigin]; unsigned int to = [self _movementOrigin];
if (to == 0) if (to == 0)
return; return;
to--; to--;
@ -873,6 +829,7 @@ check if there was a reason for that.
- (void) moveForward: (id)sender - (void) moveForward: (id)sender
{ {
unsigned int to = [self _movementOrigin]; unsigned int to = [self _movementOrigin];
if (to == [_textStorage length]) if (to == [_textStorage length])
return; return;
to++; to++;
@ -882,6 +839,7 @@ check if there was a reason for that.
- (void) moveForwardAndModifySelection: (id)sender - (void) moveForwardAndModifySelection: (id)sender
{ {
unsigned int to = [self _movementOrigin]; unsigned int to = [self _movementOrigin];
if (to == [_textStorage length]) if (to == [_textStorage length])
return; return;
to++; to++;
@ -892,14 +850,17 @@ check if there was a reason for that.
- (void) moveWordBackward: (id)sender - (void) moveWordBackward: (id)sender
{ {
unsigned int newLocation; unsigned int newLocation;
newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin] newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin]
forward: NO]; forward: NO];
[self _moveTo: newLocation [self _moveTo: newLocation
select: NO]; select: NO];
} }
- (void) moveWordBackwardAndModifySelection: (id)sender - (void) moveWordBackwardAndModifySelection: (id)sender
{ {
unsigned int newLocation; unsigned int newLocation;
newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin] newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin]
forward: NO]; forward: NO];
[self _moveTo: newLocation [self _moveTo: newLocation
@ -909,14 +870,17 @@ check if there was a reason for that.
- (void) moveWordForward: (id)sender - (void) moveWordForward: (id)sender
{ {
unsigned newLocation; unsigned newLocation;
newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin] newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin]
forward: YES]; forward: YES];
[self _moveTo: newLocation [self _moveTo: newLocation
select: NO]; select: NO];
} }
- (void) moveWordForwardAndModifySelection: (id)sender - (void) moveWordForwardAndModifySelection: (id)sender
{ {
unsigned newLocation; unsigned newLocation;
newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin] newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin]
forward: YES]; forward: YES];
[self _moveTo: newLocation [self _moveTo: newLocation
@ -928,18 +892,19 @@ check if there was a reason for that.
[self _moveTo: 0 [self _moveTo: 0
select: NO]; select: NO];
} }
- (void) moveToEndOfDocument: (id)sender - (void) moveToEndOfDocument: (id)sender
{ {
[self _moveTo: [_textStorage length] [self _moveTo: [_textStorage length]
select: NO]; select: NO];
} }
- (void) moveToBeginningOfParagraph: (id)sender - (void) moveToBeginningOfParagraph: (id)sender
{ {
NSRange aRange; NSRange aRange;
aRange = [[_textStorage string] lineRangeForRange: NSMakeRange([self _movementOrigin], 0)]; aRange = [[_textStorage string] lineRangeForRange:
NSMakeRange([self _movementOrigin], 0)];
[self _moveTo: aRange.location [self _moveTo: aRange.location
select: NO]; select: NO];
} }
@ -950,7 +915,8 @@ check if there was a reason for that.
unsigned newLocation; unsigned newLocation;
unsigned maxRange; unsigned maxRange;
aRange = [[_textStorage string] lineRangeForRange: NSMakeRange([self _movementOrigin], 0)]; aRange = [[_textStorage string] lineRangeForRange:
NSMakeRange([self _movementOrigin], 0)];
maxRange = NSMaxRange (aRange); maxRange = NSMaxRange (aRange);
if (maxRange == 0) if (maxRange == 0)
@ -1013,7 +979,6 @@ and layout is left-to-right */
select: NO]; select: NO];
} }
/** /**
* Tries to move the selection/insertion point down one page of the * Tries to move the selection/insertion point down one page of the
* visible rect in the receiver while trying to maintain the * visible rect in the receiver while trying to maintain the
@ -1085,8 +1050,6 @@ and layout is left-to-right */
select: NO]; select: NO];
} }
- (void) scrollLineDown: (id)sender - (void) scrollLineDown: (id)sender
{ {
// TODO // TODO
@ -1146,29 +1109,23 @@ insertion point. (see also: miswart)
*/ */
- (void) transpose: (id)sender - (void) transpose: (id)sender
{ {
NSRange range; NSRange range = [self selectedRange];
NSString *string; NSString *string;
NSString *replacementString; NSString *replacementString;
unichar chars[2]; unichar chars[2];
unichar tmp;
/* Do nothing if we are at beginning of text. */ /* Do nothing if we are at beginning of text. */
if (_layoutManager->_selected_range.location < 2) if (range.location < 2)
{ {
return; return;
} }
range = NSMakeRange (_layoutManager->_selected_range.location - 2, 2); range = NSMakeRange(range.location - 2, 2);
/* Get the two chars. */ /* Get the two chars and swap them. */
string = [_textStorage string]; string = [_textStorage string];
chars[0] = [string characterAtIndex: (_layoutManager->_selected_range.location - 2)]; chars[1] = [string characterAtIndex: range.location];
chars[1] = [string characterAtIndex: (_layoutManager->_selected_range.location - 1)]; chars[0] = [string characterAtIndex: (range.location + 1)];
/* Swap them. */
tmp = chars[0];
chars[0] = chars[1];
chars[1] = tmp;
/* Replace the original chars with the swapped ones. */ /* Replace the original chars with the swapped ones. */
replacementString = [NSString stringWithCharacters: chars length: 2]; replacementString = [NSString stringWithCharacters: chars length: 2];
@ -1182,7 +1139,6 @@ insertion point. (see also: miswart)
} }
} }
- (void) delete: (id)sender - (void) delete: (id)sender
{ {
[self deleteForward: sender]; [self deleteForward: sender];
@ -1193,6 +1149,7 @@ insertion point. (see also: miswart)
- (void) _alignUser: (NSTextAlignment)alignment - (void) _alignUser: (NSTextAlignment)alignment
{ {
NSRange r = [self rangeForUserParagraphAttributeChange]; NSRange r = [self rangeForUserParagraphAttributeChange];
if (r.location == NSNotFound) if (r.location == NSNotFound)
return; return;
if (![self shouldChangeTextInRange: r if (![self shouldChangeTextInRange: r
@ -1208,31 +1165,31 @@ insertion point. (see also: miswart)
{ {
[self _alignUser: NSCenterTextAlignment]; [self _alignUser: NSCenterTextAlignment];
} }
- (void) alignLeft: (id)sender - (void) alignLeft: (id)sender
{ {
[self _alignUser: NSLeftTextAlignment]; [self _alignUser: NSLeftTextAlignment];
} }
- (void) alignRight: (id)sender - (void) alignRight: (id)sender
{ {
[self _alignUser: NSRightTextAlignment]; [self _alignUser: NSRightTextAlignment];
} }
- (void) alignJustified: (id)sender - (void) alignJustified: (id)sender
{ {
[self _alignUser: NSJustifiedTextAlignment]; [self _alignUser: NSJustifiedTextAlignment];
} }
- (void) toggleContinuousSpellChecking: (id)sender - (void) toggleContinuousSpellChecking: (id)sender
{ {
[self setContinuousSpellCheckingEnabled: [self setContinuousSpellCheckingEnabled:
![self isContinuousSpellCheckingEnabled]]; ![self isContinuousSpellCheckingEnabled]];
} }
- (void) toggleRuler: (id)sender - (void) toggleRuler: (id)sender
{ {
[self setRulerVisible: !_tf.is_ruler_visible]; [self setRulerVisible: !_tf.is_ruler_visible];
} }
@end @end