From 01f49716d8f3642436d339a6e68e559bc383da70 Mon Sep 17 00:00:00 2001 From: CaS Date: Wed, 6 Mar 2002 09:49:07 +0000 Subject: [PATCH] Text storage bugfix and view deallocation bugfix. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@13019 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 ++++++ Source/GSTextStorage.m | 71 +++++++++++++++++++++++++++++++++--------- Source/NSView.m | 27 ++++++++++------ 3 files changed, 83 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa321810f..46e27287d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2002-03-06 Richard Frith-Macdonald + + * Source/GSTextStorage.m: Applied fix for left-over attributes + at end of string. Patch supplied by Alexander Malmberg + . Reformatting to conform to GNUstep + standards, and optimisation by me. + * Source/NSView.m: -dealloc remove subviews from this view as + suggested by Nicola. + 2002-03-05 Gregory John Casamento * Source/NSOutlineView.m modified to the methods which diff --git a/Source/GSTextStorage.m b/Source/GSTextStorage.m index 5fc9c8f1a..34741dce0 100644 --- a/Source/GSTextStorage.m +++ b/Source/GSTextStorage.m @@ -61,6 +61,7 @@ #include +static NSDictionary *blank; static NSLock *attrLock = nil; static GSIMapTable_t attrMap; static SEL lockSel; @@ -235,6 +236,7 @@ static void _setup() if (infCls == 0) { NSMutableArray *a; + NSDictionary *d; GSIMapInitWithZoneAndCapacity(&attrMap, NSDefaultMallocZone(), 32); @@ -256,6 +258,10 @@ static void _setup() oatImp = [a methodForSelector: oatSel]; remImp = (void (*)())[a methodForSelector: remSel]; RELEASE(a); + + d = [NSDictionary new]; + blank = cacheAttributes(d); + RELEASE(d); } } @@ -278,7 +284,7 @@ _setAttributesFrom( if (aRange.length <= 0) { - attr = [NSDictionary dictionary]; + attr = blank; } else { @@ -406,7 +412,7 @@ _attributesAtIndexEffectiveRange( { info = OBJECTAT(i); NSAssert(info->loc > l, NSInternalInconsistencyException); - NSAssert(info->loc <= len, NSInternalInconsistencyException); + NSAssert(info->loc < len, NSInternalInconsistencyException); l = info->loc; } } @@ -489,7 +495,7 @@ _attributesAtIndexEffectiveRange( if (attributes == nil) { - attributes = [NSDictionary dictionary]; + attributes = blank; } attributes = cacheAttributes(attributes); info = NEWINFO(z, attributes, 0); @@ -548,7 +554,7 @@ _attributesAtIndexEffectiveRange( } if (attributes == nil) { - attributes = [NSDictionary dictionary]; + attributes = blank; } attributes = cacheAttributes(attributes); SANITY(); @@ -709,6 +715,8 @@ SANITY(); attrs = _attributesAtIndexEffectiveRange(start, &effectiveRange, tmpLength, _infoArray, &arrayIndex); + moveLocations = [aString length] - range.length; + arrayIndex++; if (NSMaxRange(effectiveRange) < NSMaxRange(range)) { @@ -737,10 +745,31 @@ SANITY(); } } } - info->loc = NSMaxRange(range); - } + if (NSMaxRange(range) < [_textChars length]) + { + info->loc = NSMaxRange(range); + } + else + { + if (arrayIndex != 0) + { + REMOVEAT(arrayIndex); + arraySize--; + } + else + { + NSDictionary *d = blank; - moveLocations = [aString length] - range.length; + unCacheAttributes(info->attrs); + DESTROY(info->attrs); + d = cacheAttributes(d); + info->attrs = d; + /* set location so it will be correct after being modified + below */ + info->loc = NSMaxRange(range); + } + } + } /* * If we are replacing a range with a zero length string and the @@ -751,15 +780,29 @@ SANITY(); { attrs = _attributesAtIndexEffectiveRange(start, &effectiveRange, tmpLength, _infoArray, &arrayIndex); - arrayIndex ++; + arrayIndex++; if (effectiveRange.location == range.location - && effectiveRange.length == range.length) - { - arrayIndex--; - REMOVEAT(arrayIndex); - arraySize--; - } + && effectiveRange.length == range.length) + { + arrayIndex--; + if (arrayIndex != 0) + { + REMOVEAT(arrayIndex); + arraySize--; + } + else + { + NSDictionary *d = blank; + + info = OBJECTAT(0); + unCacheAttributes(info->attrs); + DESTROY(info->attrs); + d = cacheAttributes(d); + info->attrs = d; + info->loc = NSMaxRange(range); + } + } } /* diff --git a/Source/NSView.m b/Source/NSView.m index 4f4717e52..3fb3fbc26 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -279,12 +279,18 @@ GSSetDragTypes(NSView* obj, NSArray *types) - (void) dealloc { - if (_nextKeyView) - [_nextKeyView setPreviousKeyView: nil]; - - if (_previousKeyView) - [_previousKeyView setNextKeyView: nil]; - + while ([_sub_views count] > 0) + { + [[_sub_views lastObject] removeFromSuperviewWithoutNeedingDisplay]; + } + if (_nextKeyView != nil) + { + [_nextKeyView setPreviousKeyView: nil]; + } + if (_previousKeyView != nil) + { + [_previousKeyView setNextKeyView: nil]; + } RELEASE(_matrixToWindow); RELEASE(_matrixFromWindow); RELEASE(_frameMatrix); @@ -464,7 +470,8 @@ GSSetDragTypes(NSView* obj, NSArray *types) redisplay.

This is dangerous to use during display, since it alters the - rectangles needing display.

*/ + rectangles needing display. In this case, you can use the + -removeFromSuperviewWithoutNeedingDisplay method instead.

*/ - (void) removeFromSuperview { if (_super_view != nil) @@ -475,7 +482,7 @@ GSSetDragTypes(NSView* obj, NSArray *types) } /** -

Removes the view from the receivers list of subviews and from +

Removes aSubview from the receivers list of subviews and from the responder chain.

Also invokes [aView -viewWillMoveToWindow: nil] to handle @@ -491,8 +498,8 @@ GSSetDragTypes(NSView* obj, NSArray *types) * which assumes the view is still in the view hierarchy */ for (view = [_window firstResponder]; - view != nil && [view respondsToSelector:@selector(superview)]; - view = [view superview] ) + view != nil && [view respondsToSelector:@selector(superview)]; + view = [view superview]) { if (view == aSubview) {