mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 20:01:11 +00:00
Prefixed all ivars with underscores; fixed invalidated range
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8326 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0cec48542b
commit
8cce6d579a
2 changed files with 70 additions and 62 deletions
|
@ -1,12 +1,13 @@
|
|||
/*
|
||||
NSTextStorage.h
|
||||
|
||||
NSTextStorage is a semi-abstract subclass of NSMutableAttributedString. It
|
||||
implements change management (beginEditing/endEditing), verification of
|
||||
attributes, delegate handling, and layout management notification. The one
|
||||
aspect it does not implement is the actual attributed string storage ---
|
||||
this is left up to the subclassers, which need to override the four
|
||||
NSAttributedString and NSMutableAttributedString primitives:
|
||||
NSTextStorage is a semi-abstract subclass of
|
||||
NSMutableAttributedString. It implements change management
|
||||
(beginEditing/endEditing), verification of attributes, delegate
|
||||
handling, and layout management notification. The one aspect it
|
||||
does not implement is the actual attributed string storage ---
|
||||
this is left up to the subclassers, which need to override the
|
||||
four NSAttributedString and NSMutableAttributedString primitives:
|
||||
|
||||
- (NSString*) string;
|
||||
- (NSDictionary*) attributesAtIndex: (unsigned)index
|
||||
|
@ -42,8 +43,7 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
||||
|
||||
#ifndef _GNUstep_H_NSTextStorage
|
||||
#define _GNUstep_H_NSTextStorage
|
||||
|
@ -65,12 +65,12 @@ enum
|
|||
|
||||
@interface NSTextStorage : NSMutableAttributedString
|
||||
{
|
||||
NSRange editedRange;
|
||||
int editedDelta;
|
||||
NSMutableArray *layoutManagers;
|
||||
id delegate;
|
||||
unsigned editedMask;
|
||||
unsigned editCount;
|
||||
NSRange _editedRange;
|
||||
int _editedDelta;
|
||||
NSMutableArray *_layoutManagers;
|
||||
id _delegate;
|
||||
unsigned _editedMask;
|
||||
unsigned _editCount;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -56,7 +56,7 @@ static Class concrete;
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(layoutManagers);
|
||||
RELEASE (_layoutManagers);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ static Class concrete;
|
|||
- (id) initWithString: (NSString*)aString
|
||||
attributes: (NSDictionary*)attributes
|
||||
{
|
||||
layoutManagers = [[NSMutableArray alloc] initWithCapacity: 2];
|
||||
_layoutManagers = [[NSMutableArray alloc] initWithCapacity: 2];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -85,34 +85,36 @@ static Class concrete;
|
|||
*/
|
||||
- (void) addLayoutManager: (NSLayoutManager*)obj
|
||||
{
|
||||
if ([layoutManagers indexOfObjectIdenticalTo: obj] == NSNotFound)
|
||||
if ([_layoutManagers indexOfObjectIdenticalTo: obj] == NSNotFound)
|
||||
{
|
||||
[layoutManagers addObject: obj];
|
||||
[obj setTextStorage:self];
|
||||
[_layoutManagers addObject: obj];
|
||||
[obj setTextStorage: self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) removeLayoutManager: (NSLayoutManager*)obj
|
||||
{
|
||||
[layoutManagers removeObjectIdenticalTo: obj];
|
||||
[_layoutManagers removeObjectIdenticalTo: obj];
|
||||
}
|
||||
|
||||
- (NSArray*) layoutManagers
|
||||
{
|
||||
return layoutManagers;
|
||||
return _layoutManagers;
|
||||
}
|
||||
|
||||
- (void) beginEditing
|
||||
{
|
||||
editCount++;
|
||||
_editCount++;
|
||||
}
|
||||
|
||||
- (void) endEditing
|
||||
{
|
||||
if (editCount == 0)
|
||||
[NSException raise: NSGenericException
|
||||
format: @"endEditing without corresponding beginEditing"];
|
||||
if (--editCount == 0)
|
||||
if (_editCount == 0)
|
||||
{
|
||||
[NSException raise: NSGenericException
|
||||
format: @"endEditing without corresponding beginEditing"];
|
||||
}
|
||||
if (--_editCount == 0)
|
||||
{
|
||||
[self processEditing];
|
||||
}
|
||||
|
@ -133,18 +135,18 @@ static Class concrete;
|
|||
/*
|
||||
* Add in any new flags for this edit.
|
||||
*/
|
||||
editedMask |= mask;
|
||||
_editedMask |= mask;
|
||||
|
||||
/*
|
||||
* Extend edited range to encompass the latest edit.
|
||||
*/
|
||||
if (editedRange.length == 0)
|
||||
if (_editedRange.length == 0)
|
||||
{
|
||||
editedRange = old; // First edit.
|
||||
_editedRange = old; // First edit.
|
||||
}
|
||||
else
|
||||
{
|
||||
editedRange = NSUnionRange(editedRange, old);
|
||||
_editedRange = NSUnionRange (_editedRange, old);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -155,14 +157,13 @@ static Class concrete;
|
|||
{
|
||||
if (delta < 0)
|
||||
{
|
||||
// FIXME: this was > not >=, is that going to be a problem?
|
||||
NSAssert(old.length >= -delta, NSInvalidArgumentException);
|
||||
NSAssert (old.length >= -delta, NSInvalidArgumentException);
|
||||
}
|
||||
editedRange.length += delta;
|
||||
editedDelta += delta;
|
||||
_editedRange.length += delta;
|
||||
_editedDelta += delta;
|
||||
}
|
||||
|
||||
if (editCount == 0)
|
||||
if (_editCount == 0)
|
||||
[self processEditing];
|
||||
}
|
||||
|
||||
|
@ -177,53 +178,60 @@ static Class concrete;
|
|||
{
|
||||
NSRange r;
|
||||
int i;
|
||||
unsigned length;
|
||||
|
||||
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
NSDebugLLog(@"NSText", @"processEditing called in NSTextStorage.");
|
||||
|
||||
/*
|
||||
* The editCount gets decreased later again, so that changes by
|
||||
* the delegate dont trigger a new processEditing
|
||||
*/
|
||||
editCount++;
|
||||
* The _editCount gets decreased later again, so that changes by the
|
||||
* delegate or by ourselves when we fix attributes dont trigger a
|
||||
* new processEditing */
|
||||
_editCount++;
|
||||
[nc postNotificationName: NSTextStorageWillProcessEditingNotification
|
||||
object: self];
|
||||
|
||||
r = editedRange;
|
||||
/* Very important: we save the current _editedRange */
|
||||
r = _editedRange;
|
||||
length = [self length];
|
||||
// Multiple adds at the end might give a too long result
|
||||
if (NSMaxRange(r) > [self length])
|
||||
r.length = [self length] - r.location;
|
||||
if (NSMaxRange(r) > length)
|
||||
r.length = length - r.location;
|
||||
|
||||
/* The following call will potentially fix attributes. These changes
|
||||
are done through NSTextStorage methods, which records the changes
|
||||
by calling edited:range:changeInLength: - which modifies editedRange.
|
||||
|
||||
As a consequence, if any attribute has been fixed, r !=
|
||||
editedRange after this call. This is why we saved r in the first
|
||||
place. */
|
||||
[self fixAttributesInRange: r];
|
||||
|
||||
[nc postNotificationName: NSTextStorageDidProcessEditingNotification
|
||||
object: self];
|
||||
editCount--;
|
||||
_editCount--;
|
||||
|
||||
/*
|
||||
* Calls textStorage:edited:range:changeInLength:invalidatedRange: for
|
||||
* every layoutManager.
|
||||
*
|
||||
* FIXME: The invalidatedRange is not correct, this should include the
|
||||
* surrounding paragraphs.
|
||||
*/
|
||||
|
||||
for (i=0;i<[layoutManagers count];i++)
|
||||
for (i = 0; i < [_layoutManagers count]; i++)
|
||||
{
|
||||
NSLayoutManager *lManager = [layoutManagers objectAtIndex:i];
|
||||
NSLayoutManager *lManager = [_layoutManagers objectAtIndex: i];
|
||||
|
||||
[lManager textStorage: self edited: editedMask range: r
|
||||
changeInLength: editedDelta invalidatedRange: r];
|
||||
[lManager textStorage: self edited: _editedMask range: r
|
||||
changeInLength: _editedDelta invalidatedRange: _editedRange];
|
||||
}
|
||||
|
||||
/*
|
||||
* edited values reset to be used again in the next pass.
|
||||
*/
|
||||
|
||||
editedRange = NSMakeRange(0, 0);
|
||||
editedDelta = 0;
|
||||
editedMask = 0;
|
||||
_editedRange = NSMakeRange (0, 0);
|
||||
_editedDelta = 0;
|
||||
_editedMask = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -234,17 +242,17 @@ static Class concrete;
|
|||
*/
|
||||
- (unsigned) editedMask
|
||||
{
|
||||
return editedMask;
|
||||
return _editedMask;
|
||||
}
|
||||
|
||||
- (NSRange) editedRange
|
||||
{
|
||||
return editedRange;
|
||||
return _editedRange;
|
||||
}
|
||||
|
||||
- (int) changeInLength
|
||||
{
|
||||
return editedDelta;
|
||||
return _editedDelta;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -254,13 +262,13 @@ static Class concrete;
|
|||
{
|
||||
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
if (delegate)
|
||||
[nc removeObserver: delegate name: nil object: self];
|
||||
delegate = anObject;
|
||||
if (_delegate)
|
||||
[nc removeObserver: _delegate name: nil object: self];
|
||||
_delegate = anObject;
|
||||
|
||||
#define SET_DELEGATE_NOTIFICATION(notif_name) \
|
||||
if ([delegate respondsToSelector: @selector(textStorage##notif_name:)]) \
|
||||
[nc addObserver: delegate \
|
||||
if ([_delegate respondsToSelector: @selector(textStorage##notif_name:)]) \
|
||||
[nc addObserver: _delegate \
|
||||
selector: @selector(textStorage##notif_name:) \
|
||||
name: NSTextStorage##notif_name##Notification object: self]
|
||||
|
||||
|
@ -270,7 +278,7 @@ static Class concrete;
|
|||
|
||||
- (id) delegate
|
||||
{
|
||||
return delegate;
|
||||
return _delegate;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue