mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 00:50:38 +00:00
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:
parent
84683f1c4d
commit
b04fdf46b9
2 changed files with 72 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue