mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:40:47 +00:00
Call size to fit on view after layout changes.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8033 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
52eca4c236
commit
cf9c1b616a
1 changed files with 36 additions and 63 deletions
|
@ -121,7 +121,6 @@ static NSCharacterSet *invSelectionWordGranularitySet;
|
||||||
- (NSRange) lineRangeForRect: (NSRect) aRect;
|
- (NSRange) lineRangeForRect: (NSRect) aRect;
|
||||||
- (NSSize) _sizeOfRange: (NSRange) range;
|
- (NSSize) _sizeOfRange: (NSRange) range;
|
||||||
- (float) width;
|
- (float) width;
|
||||||
- (float) maxWidth;
|
|
||||||
|
|
||||||
// return value is identical to the real line number
|
// return value is identical to the real line number
|
||||||
- (int) lineLayoutIndexForGlyphIndex: (unsigned) anIndex;
|
- (int) lineLayoutIndexForGlyphIndex: (unsigned) anIndex;
|
||||||
|
@ -129,10 +128,12 @@ static NSCharacterSet *invSelectionWordGranularitySet;
|
||||||
- (NSRange) glyphRangeForLineLayoutRange: (NSRange) aRange;
|
- (NSRange) glyphRangeForLineLayoutRange: (NSRange) aRange;
|
||||||
- (unsigned) lineLayoutIndexForPoint: (NSPoint)point;
|
- (unsigned) lineLayoutIndexForPoint: (NSPoint)point;
|
||||||
|
|
||||||
- (void) setNeedsDisplayForLineRange: (NSRange) redrawLineRange;
|
- (void) setNeedsDisplayForLineRange: (NSRange) redrawLineRange
|
||||||
|
inTextContainer:(NSTextContainer *)aTextContainer;
|
||||||
// override for special layout of text
|
// override for special layout of text
|
||||||
- (NSRange) rebuildForRange: (NSRange)aRange
|
- (NSRange) rebuildForRange: (NSRange)aRange
|
||||||
delta: (int)insertionDelta;
|
delta: (int)insertionDelta
|
||||||
|
inTextContainer:(NSTextContainer *)aTextContainer;
|
||||||
// low level, override but never invoke (use setNeedsDisplayForLineRange:)
|
// low level, override but never invoke (use setNeedsDisplayForLineRange:)
|
||||||
- (void) drawLinesInLineRange: (NSRange)aRange;
|
- (void) drawLinesInLineRange: (NSRange)aRange;
|
||||||
- (void) drawSelectionAsRangeNoCaret: (NSRange)aRange;
|
- (void) drawSelectionAsRangeNoCaret: (NSRange)aRange;
|
||||||
|
@ -396,8 +397,12 @@ static NSCharacterSet *invSelectionWordGranularitySet;
|
||||||
actualCharacterRange: (NSRange*)actualRange
|
actualCharacterRange: (NSRange*)actualRange
|
||||||
{
|
{
|
||||||
NSRange lineRange;
|
NSRange lineRange;
|
||||||
|
NSTextContainer *aTextContainer = [_textContainers objectAtIndex: 0];
|
||||||
|
|
||||||
lineRange = [self rebuildForRange: aRange delta: 0];
|
lineRange = [self rebuildForRange: aRange
|
||||||
|
delta: 0
|
||||||
|
inTextContainer: aTextContainer];
|
||||||
|
[[aTextContainer textView] sizeToFit];
|
||||||
|
|
||||||
if (actualRange)
|
if (actualRange)
|
||||||
*actualRange = [self glyphRangeForLineLayoutRange: lineRange];
|
*actualRange = [self glyphRangeForLineLayoutRange: lineRange];
|
||||||
|
@ -410,25 +415,31 @@ static NSCharacterSet *invSelectionWordGranularitySet;
|
||||||
invalidatedRange:(NSRange)invalidatedCharRange;
|
invalidatedRange:(NSRange)invalidatedCharRange;
|
||||||
{
|
{
|
||||||
NSRange lineRange;
|
NSRange lineRange;
|
||||||
|
NSTextContainer *aTextContainer = [_textContainers objectAtIndex: 0];
|
||||||
|
|
||||||
// No editing
|
// No editing
|
||||||
if (!mask)
|
if (!mask)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lineRange = [self rebuildForRange: aRange
|
lineRange = [self rebuildForRange: aRange
|
||||||
delta: delta];
|
delta: delta
|
||||||
[self setNeedsDisplayForLineRange: lineRange];
|
inTextContainer: aTextContainer];
|
||||||
|
// ScrollView interaction
|
||||||
|
[[aTextContainer textView] sizeToFit];
|
||||||
|
|
||||||
|
[self setNeedsDisplayForLineRange: lineRange
|
||||||
|
inTextContainer: aTextContainer];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)drawBackgroundForGlyphRange:(NSRange)glyphRange
|
- (void)drawBackgroundForGlyphRange:(NSRange)glyphRange
|
||||||
atPoint:(NSPoint)containerOrigin
|
atPoint:(NSPoint)containerOrigin
|
||||||
{
|
{
|
||||||
NSTextContainer *aContainer = [_textContainers objectAtIndex: 0];
|
NSTextContainer *aTextContainer = [_textContainers objectAtIndex: 0];
|
||||||
NSRect rect = [self boundingRectForGlyphRange: glyphRange
|
NSRect rect = [self boundingRectForGlyphRange: glyphRange
|
||||||
inTextContainer: aContainer];
|
inTextContainer: aTextContainer];
|
||||||
|
|
||||||
// clear area under text
|
// clear area under text
|
||||||
[[[aContainer textView] backgroundColor] set];
|
[[[aTextContainer textView] backgroundColor] set];
|
||||||
NSRectFill(rect);
|
NSRectFill(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,14 +510,6 @@ static NSCharacterSet *invSelectionWordGranularitySet;
|
||||||
return [[_textContainers objectAtIndex: 0] containerSize].width;
|
return [[_textContainers objectAtIndex: 0] containerSize].width;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (float) maxWidth
|
|
||||||
{
|
|
||||||
if ([[self firstTextView] isHorizontallyResizable])
|
|
||||||
return HUGE;
|
|
||||||
else
|
|
||||||
return [self width];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (unsigned) lineLayoutIndexForPoint: (NSPoint)point
|
- (unsigned) lineLayoutIndexForPoint: (NSPoint)point
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -695,8 +698,9 @@ static NSCharacterSet *invSelectionWordGranularitySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setNeedsDisplayForLineRange: (NSRange)redrawLineRange
|
- (void) setNeedsDisplayForLineRange: (NSRange)redrawLineRange
|
||||||
|
inTextContainer:(NSTextContainer *)aTextContainer
|
||||||
{
|
{
|
||||||
float width = [self width];
|
float width = [aTextContainer containerSize].width;
|
||||||
|
|
||||||
if ([_lineLayoutInformation count]
|
if ([_lineLayoutInformation count]
|
||||||
&& redrawLineRange.location < [_lineLayoutInformation count]
|
&& redrawLineRange.location < [_lineLayoutInformation count]
|
||||||
|
@ -715,24 +719,6 @@ static NSCharacterSet *invSelectionWordGranularitySet;
|
||||||
displayRect.size.width = width - displayRect.origin.x;
|
displayRect.size.width = width - displayRect.origin.x;
|
||||||
[[self firstTextView] setNeedsDisplayInRect: displayRect];
|
[[self firstTextView] setNeedsDisplayInRect: displayRect];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// clean up the remaining area below the text
|
|
||||||
{
|
|
||||||
NSRect myFrame = [self frame];
|
|
||||||
float lowestY = 0;
|
|
||||||
|
|
||||||
if ([_lineLayoutInformation count])
|
|
||||||
lowestY = NSMaxY ([[_lineLayoutInformation lastObject] lineRect]);
|
|
||||||
|
|
||||||
if (![_lineLayoutInformation count]
|
|
||||||
|| (lowestY < NSMaxY(myFrame)))
|
|
||||||
{
|
|
||||||
[[self firstTextView] setNeedsDisplayInRect: NSMakeRect(0, lowestY,
|
|
||||||
width, NSMaxY(myFrame) - lowestY)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) _relocLayoutArray: (NSMutableArray*)ghostArray
|
- (BOOL) _relocLayoutArray: (NSMutableArray*)ghostArray
|
||||||
|
@ -802,11 +788,11 @@ scanRange(NSScanner *scanner, NSCharacterSet* aSet)
|
||||||
// returns count of lines actually updated
|
// returns count of lines actually updated
|
||||||
- (NSRange) rebuildForRange: (NSRange)aRange
|
- (NSRange) rebuildForRange: (NSRange)aRange
|
||||||
delta: (int)insertionDelta
|
delta: (int)insertionDelta
|
||||||
|
inTextContainer:(NSTextContainer *)aTextContainer
|
||||||
{
|
{
|
||||||
int aLine = 0;
|
int aLine = 0;
|
||||||
NSPoint drawingPoint = NSZeroPoint;
|
NSPoint drawingPoint = NSZeroPoint;
|
||||||
float maxWidth = [self maxWidth];
|
float width = [aTextContainer containerSize].width;
|
||||||
float width = [self width];
|
|
||||||
unsigned startingIndex = 0;
|
unsigned startingIndex = 0;
|
||||||
unsigned currentLineIndex;
|
unsigned currentLineIndex;
|
||||||
// for optimization detection
|
// for optimization detection
|
||||||
|
@ -816,7 +802,7 @@ scanRange(NSScanner *scanner, NSCharacterSet* aSet)
|
||||||
unsigned paraPos;
|
unsigned paraPos;
|
||||||
|
|
||||||
// sanity check that it is possible to do the layout
|
// sanity check that it is possible to do the layout
|
||||||
if (maxWidth == 0.0)
|
if (width == 0.0)
|
||||||
{
|
{
|
||||||
NSLog(@"NSText formatting with empty frame");
|
NSLog(@"NSText formatting with empty frame");
|
||||||
return NSMakeRange(0,0);
|
return NSMakeRange(0,0);
|
||||||
|
@ -861,20 +847,6 @@ scanRange(NSScanner *scanner, NSCharacterSet* aSet)
|
||||||
startingIndex = NSMaxRange(lastValidLineInfo->lineRange);
|
startingIndex = NSMaxRange(lastValidLineInfo->lineRange);
|
||||||
drawingPoint = aRect.origin;
|
drawingPoint = aRect.origin;
|
||||||
drawingPoint.y += aRect.size.height;
|
drawingPoint.y += aRect.size.height;
|
||||||
|
|
||||||
// keep paragraph - terminating space on same line as paragraph
|
|
||||||
if ((((int)[_lineLayoutInformation count]) - 1) >= aLine)
|
|
||||||
{
|
|
||||||
_GNULineLayoutInfo *anchorLine
|
|
||||||
= [_lineLayoutInformation objectAtIndex: aLine];
|
|
||||||
NSRect anchorRect = anchorLine->lineRect;
|
|
||||||
|
|
||||||
if (anchorRect.origin.x > drawingPoint.x
|
|
||||||
&& aRect.origin.y == anchorRect.origin.y)
|
|
||||||
{
|
|
||||||
drawingPoint = anchorRect.origin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[_lineLayoutInformation removeObjectsInRange:
|
[_lineLayoutInformation removeObjectsInRange:
|
||||||
|
@ -883,13 +855,14 @@ scanRange(NSScanner *scanner, NSCharacterSet* aSet)
|
||||||
|
|
||||||
if (!length)
|
if (!length)
|
||||||
{
|
{
|
||||||
// If there is no text add one empty box
|
// FIXME: This should be done via extra line fragment
|
||||||
[_lineLayoutInformation
|
// If there is no text add one empty box
|
||||||
addObject: [_GNULineLayoutInfo
|
[_lineLayoutInformation
|
||||||
lineLayoutWithRange: NSMakeRange (0, 0)
|
addObject: [_GNULineLayoutInfo
|
||||||
rect: NSMakeRect (0, 0, width, 12)
|
lineLayoutWithRange: NSMakeRange (0, 0)
|
||||||
usedRect: NSMakeRect (0, 0, 0, 12)]];
|
rect: NSMakeRect (0, 0, width, 12)
|
||||||
return NSMakeRange(0,1);
|
usedRect: NSMakeRect (0, 0, 0, 12)]];
|
||||||
|
return NSMakeRange(0,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentLineIndex = aLine;
|
currentLineIndex = aLine;
|
||||||
|
@ -962,7 +935,7 @@ scanRange(NSScanner *scanner, NSCharacterSet* aSet)
|
||||||
// handle case where single word is broader than width
|
// handle case where single word is broader than width
|
||||||
// (buckle word) <!> unfinished and untested
|
// (buckle word) <!> unfinished and untested
|
||||||
// for richText (absolute position see above)
|
// for richText (absolute position see above)
|
||||||
if (advanceSize.width > maxWidth)
|
if (advanceSize.width > width)
|
||||||
{
|
{
|
||||||
if (isBuckled)
|
if (isBuckled)
|
||||||
{
|
{
|
||||||
|
@ -970,7 +943,7 @@ scanRange(NSScanner *scanner, NSCharacterSet* aSet)
|
||||||
unsigned lastVisibleCharIndex;
|
unsigned lastVisibleCharIndex;
|
||||||
|
|
||||||
for (lastVisibleCharIndex = currentStringRange.length;
|
for (lastVisibleCharIndex = currentStringRange.length;
|
||||||
currentSize.width >= maxWidth && lastVisibleCharIndex;
|
currentSize.width >= width && lastVisibleCharIndex;
|
||||||
lastVisibleCharIndex--)
|
lastVisibleCharIndex--)
|
||||||
{
|
{
|
||||||
currentSize = [self _sizeOfRange: NSMakeRange(
|
currentSize = [self _sizeOfRange: NSMakeRange(
|
||||||
|
@ -993,7 +966,7 @@ scanRange(NSScanner *scanner, NSCharacterSet* aSet)
|
||||||
isBuckled = NO;
|
isBuckled = NO;
|
||||||
|
|
||||||
// line to long
|
// line to long
|
||||||
if (currentLineRect.size.width + advanceSize.width > maxWidth ||
|
if (currentLineRect.size.width + advanceSize.width > width ||
|
||||||
isBuckled)
|
isBuckled)
|
||||||
{
|
{
|
||||||
// end of line -> word wrap
|
// end of line -> word wrap
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue