Add -_didInvalidateLayout method that is called whenever any layout information has been invalidated. Use it in NSLayoutManager to resize text views.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@15915 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2003-02-09 17:05:18 +00:00
parent 7d1592daa3
commit 5d2f6b4f2f
4 changed files with 58 additions and 5 deletions

View file

@ -1,3 +1,10 @@
2003-02-09 18:02 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/GSLayoutManager_internal.h,
Source/GSLayoutManager.m, Source/NSLayoutManager.m: Add
-_didInvalidateLayout method that is called whenever layout has
been invalidated. Use it in NSLayoutManager to resize text views.
2003-02-09 15:23 Alexander Malmberg <alexander@malmberg.org>
* Source/NSTextView_actions.m: Fix several movement actions (used

View file

@ -164,6 +164,19 @@ typedef struct GSLayoutManager_textcontainer_s
BOOL started, complete;
unsigned int pos, length;
/*
This should be set to YES whenever any layout information for this text
container has been invalidated. It is reset to NO in -_didInvalidateLayout.
All methods called externally that invalidate layout (directly or
indirectly) should call -_didInvalidateLayout at some safe point after
all invalidation is done.
In GSLayoutManager, -_didInvalidateLayout only resets the flags. However,
subclasses might need to actually do something. NSLayoutManager needs to
tell its NSTextView:s to resize.
*/
BOOL was_invalidated;
linefrag_t *linefrags;
int num_linefrags;
} textcontainer_t;
@ -198,6 +211,8 @@ typedef struct GSLayoutManager_textcontainer_s
-(void) _doLayout; /* TODO: this is just a hack until proper incremental layout is done */
-(void) _doLayoutToGlyph: (unsigned int)glyphIndex;
-(void) _doLayoutToContainer: (int)cindex;
-(void) _didInvalidateLayout;
@end

View file

@ -1295,6 +1295,7 @@ it should still be safe. might lose opportunities to merge runs, though.
tc->linefrags = NULL;
tc->num_linefrags = 0;
tc->pos = tc->length = 0;
tc->was_invalidated = YES;
}
for (i = idx - 1, tc = textcontainers + idx - 1; i >= 0; i--, tc--)
{
@ -1368,6 +1369,18 @@ it should still be safe. might lose opportunities to merge runs, though.
[self _doLayout];
}
-(void) _didInvalidateLayout
{
int i;
textcontainer_t *tc;
for (tc = textcontainers, i = 0; i < num_textcontainers; i++, tc++)
{
tc->was_invalidated = NO;
}
}
@end
@ -1380,6 +1393,7 @@ it should still be safe. might lose opportunities to merge runs, though.
{
[self _invalidateLayoutFromContainer: 0];
#if 0
/* TODO: need to bring this up to date and fix it */
unsigned int from_glyph = glyphs->glyph_length;
int i, j;
textcontainer_t *tc;
@ -1926,6 +1940,8 @@ forStartOfGlyphRange: (NSRange)glyphRange
textcontainers[i].textContainer = [aTextContainer retain];
[aTextContainer setLayoutManager: self];
[self _didInvalidateLayout];
}
- (void) removeTextContainerAtIndex: (unsigned int)index
@ -1949,6 +1965,8 @@ forStartOfGlyphRange: (NSRange)glyphRange
free(textcontainers);
textcontainers = NULL;
}
[self _didInvalidateLayout];
}
- (void) textContainerChangedGeometry: (NSTextContainer *)aContainer
@ -1963,6 +1981,7 @@ forStartOfGlyphRange: (NSRange)glyphRange
return;
}
[self _invalidateLayoutFromContainer: i];
[self _didInvalidateLayout];
}
@ -2069,6 +2088,7 @@ See [NSTextView -setTextContainer:] for more information about these calls.
{
[tc->textContainer setLayoutManager: self];
}
[self _didInvalidateLayout];
}
/**
@ -2125,6 +2145,7 @@ See [NSTextView -setTextContainer:] for more information about these calls.
return;
usesScreenFonts = flag;
[self _invalidateEverything];
[self _didInvalidateLayout];
}
- (NSFont *) substituteFontForFont: (NSFont *)originalFont
@ -2161,6 +2182,7 @@ See [NSTextView -setTextContainer:] for more information about these calls.
showsInvisibleCharacters = flag;
[self _invalidateEverything];
[self _didInvalidateLayout];
}
- (BOOL) showsInvisibleCharacters
{
@ -2174,6 +2196,7 @@ See [NSTextView -setTextContainer:] for more information about these calls.
return;
showsControlCharacters = flag;
[self _invalidateEverything];
[self _didInvalidateLayout];
}
- (BOOL) showsControlCharacters
{
@ -2209,6 +2232,8 @@ See [NSTextView -setTextContainer:] for more information about these calls.
[self invalidateLayoutForCharacterRange: r
isSoft: YES
actualCharacterRange: NULL];
[self _didInvalidateLayout];
}

View file

@ -1450,9 +1450,6 @@ TODO: not really clear what these should do
changeInLength: (int)lengthChange
invalidatedRange: (NSRange)invalidatedRange
{
unsigned int g;
int i;
[super textStorage: aTextStorage
edited: mask
range: range
@ -1490,22 +1487,31 @@ TODO: not really clear what these should do
}
}
}
}
-(void) _didInvalidateLayout
{
unsigned int g;
int i;
/* Invalidate display from the first glyph not laid out (which will
generally be the first glyph to have been invalidated). */
g = layout_glyph;
[super _didInvalidateLayout];
for (i = 0; i < num_textcontainers; i++)
{
if (textcontainers[i].complete &&
g < textcontainers[i].pos + textcontainers[i].length)
continue;
[[textcontainers[i].textContainer textView] sizeToFit]; /* TODO? */
[[textcontainers[i].textContainer textView] sizeToFit];
[[textcontainers[i].textContainer textView] setNeedsDisplay: YES];
}
}
@end