mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 06:10:59 +00:00
Corrected lineBreakBeforeIndex:withinRange: and reorganised the
initWithRTF* methods. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6564 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9c5f3ce9f1
commit
c4e99ce30e
1 changed files with 81 additions and 50 deletions
|
@ -87,10 +87,15 @@ paraBreakCSet()
|
||||||
|
|
||||||
@implementation NSAttributedString (AppKit)
|
@implementation NSAttributedString (AppKit)
|
||||||
|
|
||||||
|
+ (NSAttributedString *)attributedStringWithAttachment:(NSTextAttachment *)attachment
|
||||||
|
{
|
||||||
|
// FIXME: Still missing
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL) containsAttachments
|
- (BOOL) containsAttachments
|
||||||
{
|
{
|
||||||
// Currently there are no attachment in GNUstep.
|
// FIXME: Currently there are no attachment in GNUstep.
|
||||||
// FIXME.
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,20 +188,33 @@ paraBreakCSet()
|
||||||
- (unsigned) lineBreakBeforeIndex: (unsigned)location
|
- (unsigned) lineBreakBeforeIndex: (unsigned)location
|
||||||
withinRange: (NSRange)aRange
|
withinRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
NSScanner *tScanner;
|
NSString *str = [self string];
|
||||||
unsigned int sL;
|
unsigned length = [str length];
|
||||||
|
NSRange scanRange;
|
||||||
|
NSRange startRange;
|
||||||
|
|
||||||
tScanner = [[NSScanner alloc] initWithString: [[self string]
|
if (aRange.location < 0 || NSMaxRange(aRange) > length ||
|
||||||
substringWithRange: aRange]];
|
location < 0 || location > length)
|
||||||
[tScanner scanUpToString: [NSText newlineString] intoString:NULL];
|
{
|
||||||
sL = [tScanner scanLocation] + 2;
|
[NSException raise: NSRangeException
|
||||||
|
format: @"RangeError in method -lineBreakBeforeIndex:withinRange:"];
|
||||||
|
}
|
||||||
|
|
||||||
[tScanner release];
|
if (!NSLocationInRange(location, aRange))
|
||||||
|
|
||||||
if (sL > aRange.length)
|
|
||||||
return NSNotFound;
|
return NSNotFound;
|
||||||
|
|
||||||
|
scanRange = NSMakeRange(aRange.location, location - aRange.location);
|
||||||
|
startRange = [str rangeOfCharacterFromSet: wordBreakCSet()
|
||||||
|
options: NSBackwardsSearch|NSLiteralSearch
|
||||||
|
range: scanRange];
|
||||||
|
if (startRange.length == 0)
|
||||||
|
{
|
||||||
|
return NSNotFound;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return sL;
|
{
|
||||||
|
return NSMaxRange(startRange);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRange) doubleClickAtIndex: (unsigned)location
|
- (NSRange) doubleClickAtIndex: (unsigned)location
|
||||||
|
@ -207,6 +225,12 @@ paraBreakCSet()
|
||||||
NSRange startRange;
|
NSRange startRange;
|
||||||
NSRange endRange;
|
NSRange endRange;
|
||||||
|
|
||||||
|
if (location > length)
|
||||||
|
{
|
||||||
|
[NSException raise: NSRangeException
|
||||||
|
format: @"RangeError in method -doubleClickAtIndex:"];
|
||||||
|
}
|
||||||
|
|
||||||
scanRange = NSMakeRange(0, location);
|
scanRange = NSMakeRange(0, location);
|
||||||
startRange = [str rangeOfCharacterFromSet: wordBreakCSet()
|
startRange = [str rangeOfCharacterFromSet: wordBreakCSet()
|
||||||
options: NSBackwardsSearch|NSLiteralSearch
|
options: NSBackwardsSearch|NSLiteralSearch
|
||||||
|
@ -237,48 +261,47 @@ paraBreakCSet()
|
||||||
- (unsigned) nextWordFromIndex: (unsigned)location
|
- (unsigned) nextWordFromIndex: (unsigned)location
|
||||||
forward: (BOOL)isForward
|
forward: (BOOL)isForward
|
||||||
{
|
{
|
||||||
if (isForward)
|
|
||||||
{
|
|
||||||
NSString *str = [self string];
|
NSString *str = [self string];
|
||||||
unsigned length = [str length];
|
unsigned length = [str length];
|
||||||
NSRange range;
|
NSRange range;
|
||||||
|
|
||||||
range = NSMakeRange(location, length - location);
|
if (location < 0 || location > length)
|
||||||
range = [str rangeOfCharacterFromSet: wordBreakCSet()
|
|
||||||
options: NSLiteralSearch
|
|
||||||
range: range];
|
|
||||||
if (range.length == 0)
|
|
||||||
return NSNotFound;
|
|
||||||
location = range.location;
|
|
||||||
range = NSMakeRange(location, length - location);
|
|
||||||
range = [str rangeOfCharacterFromSet: wordCSet()
|
|
||||||
options: NSLiteralSearch
|
|
||||||
range: range];
|
|
||||||
if (range.length == 0)
|
|
||||||
return NSNotFound;
|
|
||||||
return range.location;
|
|
||||||
}
|
|
||||||
else if (location > 0)
|
|
||||||
{
|
{
|
||||||
NSString *str = [self string];
|
[NSException raise: NSRangeException
|
||||||
NSRange range;
|
format: @"RangeError in method -nextWordFromIndex:forward:"];
|
||||||
|
}
|
||||||
|
|
||||||
range = NSMakeRange(0, location);
|
if (isForward)
|
||||||
|
{
|
||||||
|
range = NSMakeRange(location, length - location);
|
||||||
range = [str rangeOfCharacterFromSet: wordBreakCSet()
|
range = [str rangeOfCharacterFromSet: wordBreakCSet()
|
||||||
options: NSBackwardsSearch|NSLiteralSearch
|
options: NSLiteralSearch
|
||||||
range: range];
|
range: range];
|
||||||
location = range.location;
|
if (range.length == 0)
|
||||||
range = NSMakeRange(0, location);
|
return location;
|
||||||
|
range = NSMakeRange(range.location, length - range.location);
|
||||||
range = [str rangeOfCharacterFromSet: wordCSet()
|
range = [str rangeOfCharacterFromSet: wordCSet()
|
||||||
options: NSLiteralSearch
|
options: NSLiteralSearch
|
||||||
range: range];
|
range: range];
|
||||||
if (range.length == 0)
|
if (range.length == 0)
|
||||||
return NSNotFound;
|
return location;
|
||||||
return range.location;
|
return range.location;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return NSNotFound;
|
range = NSMakeRange(0, location);
|
||||||
|
range = [str rangeOfCharacterFromSet: wordBreakCSet()
|
||||||
|
options: NSBackwardsSearch|NSLiteralSearch
|
||||||
|
range: range];
|
||||||
|
if (range.length == 0)
|
||||||
|
return location;
|
||||||
|
range = NSMakeRange(0, range.location);
|
||||||
|
range = [str rangeOfCharacterFromSet: wordCSet()
|
||||||
|
options: NSLiteralSearch
|
||||||
|
range: range];
|
||||||
|
if (range.length == 0)
|
||||||
|
return location;
|
||||||
|
return range.location;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,14 +312,6 @@ paraBreakCSet()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
- (id) initWithRTFD: (NSData*)data
|
|
||||||
documentAttributes: (NSDictionary**)dict
|
|
||||||
{
|
|
||||||
// FIXME: We use RTF, as there are currently no additional images
|
|
||||||
return [self initWithRTF: data
|
|
||||||
documentAttributes: dict];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) initWithPath: (NSString*)path
|
- (id) initWithPath: (NSString*)path
|
||||||
documentAttributes: (NSDictionary**)dict
|
documentAttributes: (NSDictionary**)dict
|
||||||
{
|
{
|
||||||
|
@ -324,10 +339,25 @@ documentAttributes: (NSDictionary**)dict
|
||||||
return [self initWithRTF: [wrapper regularFileContents]
|
return [self initWithRTF: [wrapper regularFileContents]
|
||||||
documentAttributes: dict];
|
documentAttributes: dict];
|
||||||
else if ([wrapper isDirectory])
|
else if ([wrapper isDirectory])
|
||||||
// FIXME: We should read the main file in the directory
|
{
|
||||||
return self;
|
NSDictionary *files = [wrapper fileWrappers];
|
||||||
|
NSFileWrapper *contents;
|
||||||
|
|
||||||
return self;
|
// We try to read the main file in the directory
|
||||||
|
if ((contents = [files objectForKey: @"TXT.rtf"]) != nil)
|
||||||
|
return [self initWithRTF: [contents regularFileContents]
|
||||||
|
documentAttributes: dict];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) initWithRTFD: (NSData*)data
|
||||||
|
documentAttributes: (NSDictionary**)dict
|
||||||
|
{
|
||||||
|
// FIXME: We use RTF, as there are currently no additional images
|
||||||
|
return [self initWithRTF: data
|
||||||
|
documentAttributes: dict];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithRTF: (NSData*)data
|
- (id) initWithRTF: (NSData*)data
|
||||||
|
@ -711,6 +741,7 @@ documentAttributes: (NSDictionary**)dict
|
||||||
|
|
||||||
- (void)updateAttachmentsFromPath:(NSString *)path
|
- (void)updateAttachmentsFromPath:(NSString *)path
|
||||||
{
|
{
|
||||||
|
// FIXME: Still missing
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue