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>
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.
@ -40,8 +42,8 @@
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
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/NSValue.h>
@ -51,11 +53,6 @@
#include <AppKit/NSTextStorage.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
-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
implemented here, but this is _not_ the place to add new actions.
When changing attributes, the range returned by
rangeForUserCharacterAttributeChange or rangeForUserParagraphAttributeChange
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.
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.
(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?
Not all user actions are here. Exceptions:
-toggleRuler:
-copy:
-copyFont:
-copyRuler:
@ -108,9 +96,6 @@ Not all user actions are here. Exceptions:
-selectAll: (implemented in NSText)
-toggleContinuousSpellChecking:
Not all methods that handle user-induced text modifications are here.
Exceptions:
(TODO)
@ -372,7 +357,6 @@ static NSNumber *float_plus_one(NSNumber *cur)
[_layoutManager->_typingAttributes removeObjectForKey: NSSuperscriptAttributeName];
[_layoutManager->_typingAttributes removeObjectForKey: NSBaselineOffsetAttributeName];
[self didChangeText];
}
@ -685,10 +669,22 @@ added to the selection (1,3).
- (unsigned int) _movementOrigin
{
if (_layoutManager->_selectionAffinity == NSSelectionAffinityUpstream)
return _layoutManager->_selected_range.location;
NSRange range = [self selectedRange];
if ([self selectionAffinity] == NSSelectionAffinityUpstream)
return range.location;
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
@ -696,11 +692,7 @@ added to the selection (1,3).
{
if (select)
{
unsigned int anchor;
if (_layoutManager->_selectionAffinity == NSSelectionAffinityDownstream)
anchor = _layoutManager->_selected_range.location;
else
anchor = NSMaxRange(_layoutManager->_selected_range);
unsigned int anchor = [self _movementEnd];
if (anchor < cindex)
{
@ -750,7 +742,6 @@ added to the selection (1,3).
_originalInsertionPointCharacterIndex = cindex;
}
cindex = [_layoutManager characterIndexMoving: direction
fromCharacterIndex: cindex
originalCharacterIndex: _originalInsertionPointCharacterIndex
@ -766,56 +757,17 @@ added to the selection (1,3).
/*
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
check if there was a reason for that.
*/
- (void) moveUp: (id)sender
{
[self _move: GSInsertionPointMoveUp
distance: 0.0
select: NO];
}
- (void) moveUpAndModifySelection: (id)sender
{
[self _move: GSInsertionPointMoveUp
@ -829,6 +781,7 @@ check if there was a reason for that.
distance: 0.0
select: NO];
}
- (void) moveDownAndModifySelection: (id)sender
{
[self _move: GSInsertionPointMoveDown
@ -854,15 +807,18 @@ check if there was a reason for that.
- (void) moveBackward: (id)sender
{
unsigned int to = [self _movementOrigin];
if (to == 0)
return;
to--;
[self _moveTo: to
select: NO];
}
- (void) moveBackwardAndModifySelection: (id)sender
{
unsigned int to = [self _movementOrigin];
if (to == 0)
return;
to--;
@ -873,6 +829,7 @@ check if there was a reason for that.
- (void) moveForward: (id)sender
{
unsigned int to = [self _movementOrigin];
if (to == [_textStorage length])
return;
to++;
@ -882,6 +839,7 @@ check if there was a reason for that.
- (void) moveForwardAndModifySelection: (id)sender
{
unsigned int to = [self _movementOrigin];
if (to == [_textStorage length])
return;
to++;
@ -892,14 +850,17 @@ check if there was a reason for that.
- (void) moveWordBackward: (id)sender
{
unsigned int newLocation;
newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin]
forward: NO];
[self _moveTo: newLocation
select: NO];
}
- (void) moveWordBackwardAndModifySelection: (id)sender
{
unsigned int newLocation;
newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin]
forward: NO];
[self _moveTo: newLocation
@ -909,14 +870,17 @@ check if there was a reason for that.
- (void) moveWordForward: (id)sender
{
unsigned newLocation;
newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin]
forward: YES];
[self _moveTo: newLocation
select: NO];
}
- (void) moveWordForwardAndModifySelection: (id)sender
{
unsigned newLocation;
newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin]
forward: YES];
[self _moveTo: newLocation
@ -928,18 +892,19 @@ check if there was a reason for that.
[self _moveTo: 0
select: NO];
}
- (void) moveToEndOfDocument: (id)sender
{
[self _moveTo: [_textStorage length]
select: NO];
}
- (void) moveToBeginningOfParagraph: (id)sender
{
NSRange aRange;
aRange = [[_textStorage string] lineRangeForRange: NSMakeRange([self _movementOrigin], 0)];
aRange = [[_textStorage string] lineRangeForRange:
NSMakeRange([self _movementOrigin], 0)];
[self _moveTo: aRange.location
select: NO];
}
@ -950,7 +915,8 @@ check if there was a reason for that.
unsigned newLocation;
unsigned maxRange;
aRange = [[_textStorage string] lineRangeForRange: NSMakeRange([self _movementOrigin], 0)];
aRange = [[_textStorage string] lineRangeForRange:
NSMakeRange([self _movementOrigin], 0)];
maxRange = NSMaxRange (aRange);
if (maxRange == 0)
@ -1013,7 +979,6 @@ and layout is left-to-right */
select: NO];
}
/**
* Tries to move the selection/insertion point down one page of the
* visible rect in the receiver while trying to maintain the
@ -1085,8 +1050,6 @@ and layout is left-to-right */
select: NO];
}
- (void) scrollLineDown: (id)sender
{
// TODO
@ -1146,29 +1109,23 @@ insertion point. (see also: miswart)
*/
- (void) transpose: (id)sender
{
NSRange range;
NSRange range = [self selectedRange];
NSString *string;
NSString *replacementString;
unichar chars[2];
unichar tmp;
/* Do nothing if we are at beginning of text. */
if (_layoutManager->_selected_range.location < 2)
if (range.location < 2)
{
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];
chars[0] = [string characterAtIndex: (_layoutManager->_selected_range.location - 2)];
chars[1] = [string characterAtIndex: (_layoutManager->_selected_range.location - 1)];
/* Swap them. */
tmp = chars[0];
chars[0] = chars[1];
chars[1] = tmp;
chars[1] = [string characterAtIndex: range.location];
chars[0] = [string characterAtIndex: (range.location + 1)];
/* Replace the original chars with the swapped ones. */
replacementString = [NSString stringWithCharacters: chars length: 2];
@ -1182,7 +1139,6 @@ insertion point. (see also: miswart)
}
}
- (void) delete: (id)sender
{
[self deleteForward: sender];
@ -1193,6 +1149,7 @@ insertion point. (see also: miswart)
- (void) _alignUser: (NSTextAlignment)alignment
{
NSRange r = [self rangeForUserParagraphAttributeChange];
if (r.location == NSNotFound)
return;
if (![self shouldChangeTextInRange: r
@ -1208,31 +1165,31 @@ insertion point. (see also: miswart)
{
[self _alignUser: NSCenterTextAlignment];
}
- (void) alignLeft: (id)sender
{
[self _alignUser: NSLeftTextAlignment];
}
- (void) alignRight: (id)sender
{
[self _alignUser: NSRightTextAlignment];
}
- (void) alignJustified: (id)sender
{
[self _alignUser: NSJustifiedTextAlignment];
}
- (void) toggleContinuousSpellChecking: (id)sender
{
[self setContinuousSpellCheckingEnabled:
![self isContinuousSpellCheckingEnabled]];
}
- (void) toggleRuler: (id)sender
{
[self setRulerVisible: !_tf.is_ruler_visible];
}
@end