mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-28 16:40:50 +00:00
Made NSText an abstract class always allocating an instance of the
concrete subclass NSTextView git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8359 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
64c416ad2f
commit
6e50f1c47f
1 changed files with 34 additions and 101 deletions
133
Source/NSText.m
133
Source/NSText.m
|
@ -64,6 +64,8 @@
|
||||||
|
|
||||||
static NSNotificationCenter *nc;
|
static NSNotificationCenter *nc;
|
||||||
|
|
||||||
|
static Class abstract;
|
||||||
|
static Class concrete;
|
||||||
|
|
||||||
@interface NSText(GNUstepPrivate)
|
@interface NSText(GNUstepPrivate)
|
||||||
/*
|
/*
|
||||||
|
@ -73,8 +75,6 @@ static NSNotificationCenter *nc;
|
||||||
- (NSRect) rectForCharacterIndex: (unsigned)index;
|
- (NSRect) rectForCharacterIndex: (unsigned)index;
|
||||||
- (NSRect) rectForCharacterRange: (NSRange)aRange;
|
- (NSRect) rectForCharacterRange: (NSRange)aRange;
|
||||||
|
|
||||||
- (NSTextContainer*) buildUpTextNetwork: (NSSize)aSize;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* various GNU extensions
|
* various GNU extensions
|
||||||
*/
|
*/
|
||||||
|
@ -123,9 +123,20 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
|
|
||||||
[[NSApplication sharedApplication] registerServicesMenuSendTypes: types
|
[[NSApplication sharedApplication] registerServicesMenuSendTypes: types
|
||||||
returnTypes: types];
|
returnTypes: types];
|
||||||
|
|
||||||
|
abstract = self;
|
||||||
|
concrete = [NSTextView class];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (id) allocWithZone: (NSZone*)zone
|
||||||
|
{
|
||||||
|
if (self == abstract)
|
||||||
|
return NSAllocateObject (concrete, 0, zone);
|
||||||
|
else
|
||||||
|
return NSAllocateObject (self, 0, zone);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Instance methods
|
// Instance methods
|
||||||
//
|
//
|
||||||
|
@ -140,41 +151,12 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
|
|
||||||
- (id) initWithFrame: (NSRect)frameRect
|
- (id) initWithFrame: (NSRect)frameRect
|
||||||
{
|
{
|
||||||
NSTextContainer *aTextContainer;
|
[self subclassResponsibility: _cmd];
|
||||||
|
return nil;
|
||||||
aTextContainer = [self buildUpTextNetwork: frameRect.size];
|
|
||||||
|
|
||||||
self = [self initWithFrame: frameRect textContainer: aTextContainer];
|
|
||||||
|
|
||||||
/* At this point the situation is as follows:
|
|
||||||
|
|
||||||
textView (us) --RETAINs--> textStorage
|
|
||||||
textStorage --RETAINs--> layoutManager
|
|
||||||
layoutManager --RETAINs--> textContainer
|
|
||||||
textContainter --RETAINs --> textView (us) */
|
|
||||||
|
|
||||||
/* The text system should be destroyed when the textView (us) is
|
|
||||||
released. To get this result, we send a RELEASE message to us
|
|
||||||
breaking the RETAIN cycle. */
|
|
||||||
RELEASE (self);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
if (_tf.owns_text_network == YES)
|
|
||||||
{
|
|
||||||
/* Prevent recursive dealloc */
|
|
||||||
if (_tf.is_in_dealloc == YES)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_tf.is_in_dealloc = YES;
|
|
||||||
/* This releases all the text objects (us included) in fall */
|
|
||||||
RELEASE (_textStorage);
|
|
||||||
}
|
|
||||||
|
|
||||||
RELEASE(_background_color);
|
RELEASE(_background_color);
|
||||||
RELEASE(_caret_color);
|
RELEASE(_caret_color);
|
||||||
RELEASE(_typingAttributes);
|
RELEASE(_typingAttributes);
|
||||||
|
@ -185,42 +167,36 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
/*
|
/*
|
||||||
* Getting and Setting Contents
|
* Getting and Setting Contents
|
||||||
*/
|
*/
|
||||||
- (void) replaceCharactersInRange: (NSRange)aRange
|
- (void) replaceCharactersInRange: (NSRange)aRange withRTF: (NSData *)rtfData
|
||||||
withRTF: (NSData*)rtfData
|
|
||||||
{
|
{
|
||||||
[self replaceRange: aRange
|
NSAttributedString *attr;
|
||||||
withAttributedString: AUTORELEASE([[NSAttributedString alloc]
|
|
||||||
initWithRTF: rtfData
|
attr = [[NSAttributedString alloc] initWithRTF: rtfData
|
||||||
documentAttributes: NULL])];
|
documentAttributes: NULL];
|
||||||
|
AUTORELEASE (attr);
|
||||||
|
[self replaceRange: aRange withAttributedString: attr];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) replaceCharactersInRange: (NSRange)aRange
|
- (void) replaceCharactersInRange: (NSRange)aRange
|
||||||
withRTFD: (NSData*)rtfdData
|
withRTFD: (NSData *)rtfdData
|
||||||
{
|
{
|
||||||
[self replaceRange: aRange
|
NSAttributedString *attr;
|
||||||
withAttributedString: AUTORELEASE([[NSAttributedString alloc]
|
|
||||||
initWithRTFD: rtfdData
|
attr = [[NSAttributedString alloc] initWithRTFD: rtfdData
|
||||||
documentAttributes: NULL])];
|
documentAttributes: NULL];
|
||||||
|
AUTORELEASE (attr);
|
||||||
|
[self replaceRange: aRange withAttributedString: attr];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) replaceCharactersInRange: (NSRange)aRange
|
- (void) replaceCharactersInRange: (NSRange)aRange
|
||||||
withString: (NSString*)aString
|
withString: (NSString*)aString
|
||||||
{
|
{
|
||||||
if (aRange.location == NSNotFound)
|
[self subclassResponsibility: _cmd];
|
||||||
return;
|
|
||||||
|
|
||||||
if (![self shouldChangeTextInRange: aRange
|
|
||||||
replacementString: aString])
|
|
||||||
return;
|
|
||||||
[_textStorage beginEditing];
|
|
||||||
[_textStorage replaceCharactersInRange: aRange withString: aString];
|
|
||||||
[_textStorage endEditing];
|
|
||||||
[self didChangeText];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setString: (NSString*)aString
|
- (void) setString: (NSString*)aString
|
||||||
{
|
{
|
||||||
[self replaceCharactersInRange: NSMakeRange(0, [_textStorage length])
|
[self replaceCharactersInRange: NSMakeRange (0, [[self string] length])
|
||||||
withString: aString];
|
withString: aString];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1415,7 +1391,7 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
//
|
//
|
||||||
// NSCoding protocol
|
// NSCoding protocol
|
||||||
//
|
//
|
||||||
- (void)encodeWithCoder: aCoder
|
- (void) encodeWithCoder: (NSCoder *)aCoder
|
||||||
{
|
{
|
||||||
BOOL flag;
|
BOOL flag;
|
||||||
[super encodeWithCoder: aCoder];
|
[super encodeWithCoder: aCoder];
|
||||||
|
@ -1457,10 +1433,9 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
[aCoder encodeValueOfObjCType: @encode(NSSize) at: &_maxSize];
|
[aCoder encodeValueOfObjCType: @encode(NSSize) at: &_maxSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithCoder: aDecoder
|
- (id) initWithCoder: (NSCoder *)aDecoder
|
||||||
{
|
{
|
||||||
BOOL flag;
|
BOOL flag;
|
||||||
NSTextContainer *aTextContainer;
|
|
||||||
|
|
||||||
[super initWithCoder: aDecoder];
|
[super initWithCoder: aDecoder];
|
||||||
|
|
||||||
|
@ -1500,13 +1475,6 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
[aDecoder decodeValueOfObjCType: @encode(NSSize) at: &_minSize];
|
[aDecoder decodeValueOfObjCType: @encode(NSSize) at: &_minSize];
|
||||||
[aDecoder decodeValueOfObjCType: @encode(NSSize) at: &_maxSize];
|
[aDecoder decodeValueOfObjCType: @encode(NSSize) at: &_maxSize];
|
||||||
|
|
||||||
/* build up the rest of the text system, which doesn't get stored
|
|
||||||
<doesn't even implement the Coding protocol>. */
|
|
||||||
aTextContainer = [self buildUpTextNetwork: _frame.size];
|
|
||||||
[aTextContainer setTextView: (NSTextView*)self];
|
|
||||||
/* See initWithFrame: for comments on this RELEASE */
|
|
||||||
RELEASE (self);
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2348,41 +2316,6 @@ other than copy/paste or dragging. */
|
||||||
inTextContainer: [self textContainer]];
|
inTextContainer: [self textContainer]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTextContainer*) buildUpTextNetwork: (NSSize)aSize;
|
|
||||||
{
|
|
||||||
NSTextContainer *textContainer;
|
|
||||||
NSLayoutManager *layoutManager;
|
|
||||||
NSTextStorage *textStorage;
|
|
||||||
|
|
||||||
textStorage = [[NSTextStorage alloc] init];
|
|
||||||
|
|
||||||
layoutManager = [[NSLayoutManager alloc] init];
|
|
||||||
/*
|
|
||||||
[textStorage addLayoutManager: layoutManager];
|
|
||||||
RELEASE (layoutManager);
|
|
||||||
*/
|
|
||||||
|
|
||||||
textContainer = [[NSTextContainer alloc] initWithContainerSize: aSize];
|
|
||||||
[layoutManager addTextContainer: textContainer];
|
|
||||||
RELEASE (textContainer);
|
|
||||||
|
|
||||||
/* FIXME: The following two lines should go *before* */
|
|
||||||
[textStorage addLayoutManager: layoutManager];
|
|
||||||
RELEASE (layoutManager);
|
|
||||||
|
|
||||||
/* The situation at this point is as follows:
|
|
||||||
|
|
||||||
textView (us) --RETAINs--> textStorage
|
|
||||||
textStorage --RETAINs--> layoutManager
|
|
||||||
layoutManager --RETAINs--> textContainer */
|
|
||||||
|
|
||||||
/* We keep a flag to remember that we are directly responsible for
|
|
||||||
managing the text objects. */
|
|
||||||
_tf.owns_text_network = YES;
|
|
||||||
|
|
||||||
return textContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) drawInsertionPointAtIndex: (unsigned) index
|
- (void) drawInsertionPointAtIndex: (unsigned) index
|
||||||
color: (NSColor*) color
|
color: (NSColor*) color
|
||||||
turnedOn: (BOOL) flag
|
turnedOn: (BOOL) flag
|
||||||
|
|
Loading…
Reference in a new issue