mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:40:47 +00:00
Implemented double owning policy for the text network (ie, allocation
deallocation stuff) git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8340 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b273ed105e
commit
1e7f6d4db9
1 changed files with 74 additions and 27 deletions
101
Source/NSText.m
101
Source/NSText.m
|
@ -118,7 +118,8 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
|
|
||||||
nc = [NSNotificationCenter defaultCenter];
|
nc = [NSNotificationCenter defaultCenter];
|
||||||
|
|
||||||
types = [NSArray arrayWithObjects: NSStringPboardType, NSRTFPboardType, NSRTFDPboardType, nil];
|
types = [NSArray arrayWithObjects: NSStringPboardType,
|
||||||
|
NSRTFPboardType, NSRTFDPboardType, nil];
|
||||||
|
|
||||||
[[NSApplication sharedApplication] registerServicesMenuSendTypes: types
|
[[NSApplication sharedApplication] registerServicesMenuSendTypes: types
|
||||||
returnTypes: types];
|
returnTypes: types];
|
||||||
|
@ -139,19 +140,44 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
|
|
||||||
- (id) initWithFrame: (NSRect)frameRect
|
- (id) initWithFrame: (NSRect)frameRect
|
||||||
{
|
{
|
||||||
NSTextContainer *aTextContainer = [self buildUpTextNetwork: frameRect.size];
|
NSTextContainer *aTextContainer;
|
||||||
|
|
||||||
return [self initWithFrame: frameRect textContainer: aTextContainer];
|
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);
|
||||||
RELEASE(_textStorage);
|
|
||||||
RELEASE(_textContainer);
|
|
||||||
RELEASE(_layoutManager);
|
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
@ -1395,7 +1421,6 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
[super encodeWithCoder: aCoder];
|
[super encodeWithCoder: aCoder];
|
||||||
|
|
||||||
[aCoder encodeConditionalObject: _delegate];
|
[aCoder encodeConditionalObject: _delegate];
|
||||||
[aCoder encodeObject: _textStorage];
|
|
||||||
|
|
||||||
flag = _tf.is_field_editor;
|
flag = _tf.is_field_editor;
|
||||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
||||||
|
@ -1435,10 +1460,11 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
- initWithCoder: aDecoder
|
- initWithCoder: aDecoder
|
||||||
{
|
{
|
||||||
BOOL flag;
|
BOOL flag;
|
||||||
|
NSTextContainer *aTextContainer;
|
||||||
|
|
||||||
[super initWithCoder: aDecoder];
|
[super initWithCoder: aDecoder];
|
||||||
|
|
||||||
_delegate = [aDecoder decodeObject];
|
_delegate = [aDecoder decodeObject];
|
||||||
_textStorage = [aDecoder decodeObject];
|
|
||||||
|
|
||||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
||||||
_tf.is_field_editor = flag;
|
_tf.is_field_editor = flag;
|
||||||
|
@ -1474,11 +1500,12 @@ 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 layout informations that don't get stored
|
/* build up the rest of the text system, which doesn't get stored
|
||||||
{
|
<doesn't even implement the Coding protocol>. */
|
||||||
NSTextContainer *aTextContainer = [self buildUpTextNetwork: _frame.size];
|
aTextContainer = [self buildUpTextNetwork: _frame.size];
|
||||||
[aTextContainer setTextView: (NSTextView*)self];
|
[aTextContainer setTextView: (NSTextView*)self];
|
||||||
}
|
/* See initWithFrame: for comments on this RELEASE */
|
||||||
|
RELEASE (self);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -1551,7 +1578,7 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
[super initWithFrame: frameRect];
|
[super initWithFrame: frameRect];
|
||||||
|
|
||||||
[self setMinSize: frameRect.size];
|
[self setMinSize: frameRect.size];
|
||||||
[self setMaxSize: NSMakeSize(HUGE,HUGE)];
|
[self setMaxSize: NSMakeSize (HUGE,HUGE)];
|
||||||
|
|
||||||
_tf.is_field_editor = NO;
|
_tf.is_field_editor = NO;
|
||||||
_tf.is_editable = YES;
|
_tf.is_editable = YES;
|
||||||
|
@ -1564,8 +1591,8 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
_tf.uses_font_panel = YES;
|
_tf.uses_font_panel = YES;
|
||||||
_tf.uses_ruler = YES;
|
_tf.uses_ruler = YES;
|
||||||
_tf.is_ruler_visible = NO;
|
_tf.is_ruler_visible = NO;
|
||||||
ASSIGN(_caret_color, [NSColor blackColor]);
|
ASSIGN (_caret_color, [NSColor blackColor]);
|
||||||
[self setTypingAttributes: [[self class] defaultTypingAttributes]];
|
[self setTypingAttributes: [isa defaultTypingAttributes]];
|
||||||
|
|
||||||
[self setBackgroundColor: [NSColor textBackgroundColor]];
|
[self setBackgroundColor: [NSColor textBackgroundColor]];
|
||||||
|
|
||||||
|
@ -1583,9 +1610,9 @@ NSRange MakeRangeFromAbs (unsigned a1, unsigned a2)
|
||||||
- (void) setTextContainer: (NSTextContainer*)aTextContainer
|
- (void) setTextContainer: (NSTextContainer*)aTextContainer
|
||||||
{
|
{
|
||||||
// FIXME: This builds up circular references between those objects
|
// FIXME: This builds up circular references between those objects
|
||||||
ASSIGN(_textContainer, aTextContainer);
|
_textContainer = aTextContainer;
|
||||||
ASSIGN(_layoutManager, [aTextContainer layoutManager]);
|
_layoutManager = [aTextContainer layoutManager];
|
||||||
ASSIGN(_textStorage, [_layoutManager textStorage]);
|
_textStorage = [_layoutManager textStorage];
|
||||||
|
|
||||||
// Hack to get the layout change
|
// Hack to get the layout change
|
||||||
[_textContainer setContainerSize: _frame.size];
|
[_textContainer setContainerSize: _frame.size];
|
||||||
|
@ -2323,17 +2350,37 @@ other than copy/paste or dragging. */
|
||||||
|
|
||||||
- (NSTextContainer*) buildUpTextNetwork: (NSSize)aSize;
|
- (NSTextContainer*) buildUpTextNetwork: (NSSize)aSize;
|
||||||
{
|
{
|
||||||
NSTextContainer *aTextContainer = [[NSTextContainer alloc] initWithContainerSize: aSize];
|
NSTextContainer *textContainer;
|
||||||
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
|
NSLayoutManager *layoutManager;
|
||||||
NSTextStorage *textStorage = [[NSTextStorage alloc] init];
|
NSTextStorage *textStorage;
|
||||||
|
|
||||||
[layoutManager addTextContainer: aTextContainer];
|
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];
|
[textStorage addLayoutManager: layoutManager];
|
||||||
AUTORELEASE(aTextContainer);
|
RELEASE (layoutManager);
|
||||||
AUTORELEASE(layoutManager);
|
|
||||||
AUTORELEASE(textStorage);
|
|
||||||
|
|
||||||
return aTextContainer;
|
/* 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue