NSTextStorageをサブクラス化するには、以下のようなメソッドを追加しておく必要がある。
(www.cocoadev.comより)
//#####################
- (id)init {
self = [super init];
if (self) {
m_attributedString = [[NSMutableAttributedString alloc] init];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[m_attributedString release];
[super dealloc];
}
- (NSString *)string
{
return [m_attributedString string];
}
- (NSDictionary *)attributesAtIndex:(unsigned)index effectiveRange:(NSRangePointer)aRange
{
return [m_attributedString attributesAtIndex:index effectiveRange:aRange];
}
- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str
{
[m_attributedString replaceCharactersInRange:range withString:str];
int lengthChange = [str length] - range.length;
[self edited:NSTextStorageEditedCharacters range:range changeInLength:lengthChange];
}
- (void)setAttributes:(NSDictionary *)attributes range:(NSRange)range
{
[m_attributedString setAttributes:attributes range:range];
[self edited:NSTextStorageEditedAttributes range:range changeInLength:0];
}
@end


