Implementation of -rangeOfTextTable:atIndex: method on

NSAttributedString.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29420 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2010-01-27 14:10:38 +00:00
parent 84683f1c4d
commit b04fdf46b9
2 changed files with 72 additions and 1 deletions

View file

@ -1,3 +1,8 @@
2010-01-27 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSAttributedString.m (-rangeOfTextTable:atIndex:): Add
implementation for this method, done during LindauSTEP.
2010-01-27 Quentin Mathe <quentin.mathe@gmail.com>
* Headers/GNUstepGUI/GSTheme.h:

View file

@ -52,6 +52,7 @@
#include "AppKit/NSFontManager.h"
// For the colour name spaces
#include "AppKit/NSGraphics.h"
#import "AppKit/NSTextTable.h"
#include "GNUstepGUI/GSTextConverter.h"
#include "GSGuiPrivate.h"
@ -1147,10 +1148,75 @@ documentAttributes: (NSDictionary **)dict
return NSMakeRange(NSNotFound, 0);
}
static inline
BOOL containsTable(NSArray *textBlocks, NSTextTable *table)
{
NSEnumerator *benum = [textBlocks objectEnumerator];
NSTextTableBlock *block;
while ((block = [benum nextObject]))
{
if ([table isEqual: [block table]])
{
return YES;
}
}
return NO;
}
- (NSRange) rangeOfTextTable: (NSTextTable *)table
atIndex: (NSUInteger)location
{
// FIXME
NSRange effRange;
NSParagraphStyle *style = [self attribute: NSParagraphStyleAttributeName
atIndex: location
effectiveRange: &effRange];
if (style != nil)
{
NSArray *textBlocks = [style textBlocks];
if ((textBlocks != nil) && containsTable(textBlocks, table))
{
NSRange newEffRange;
unsigned len = [self length];
while ((effRange.location > 0) && style && textBlocks)
{
style = [self attribute: NSParagraphStyleAttributeName
atIndex: effRange.location - 1
effectiveRange: &newEffRange];
if (style != nil)
{
textBlocks = [style textBlocks];
if ((textBlocks != nil) && containsTable(textBlocks, table))
{
effRange.location = newEffRange.location;
effRange.length += newEffRange.length;
}
}
}
while (NSMaxRange(effRange) < len && style && textBlocks)
{
style = [self attribute: NSParagraphStyleAttributeName
atIndex: NSMaxRange(effRange)
effectiveRange: &newEffRange];
if (style != nil)
{
textBlocks = [style textBlocks];
if ((textBlocks != nil) && containsTable(textBlocks, table))
{
effRange.length += newEffRange.length;
}
}
}
return effRange;
}
}
return NSMakeRange(NSNotFound, 0);
}