mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-24 06:28:54 +00:00
Make system color list creation more robust; recover from broken System.clr files. Fix locale issue in +colorFromString:.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17375 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
77fa3e8966
commit
e2118a6a32
2 changed files with 38 additions and 10 deletions
|
@ -1,3 +1,11 @@
|
|||
2003-07-27 17:53 Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
* Source/NSColor.m (+colorFromString:): Use NSScanner instead of
|
||||
sscanf to avoid problems on non-c locales.
|
||||
|
||||
(initSystemColors): Make the creation of the system color list
|
||||
more robust. If entries are missing, add them.
|
||||
|
||||
2003-07-26 18:50 Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
* Source/NSView.m, Source/NSWindow.m: Make drawing debug logging
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSScanner.h>
|
||||
|
||||
#include "AppKit/NSColor.h"
|
||||
#include "AppKit/NSColorList.h"
|
||||
|
@ -162,7 +163,7 @@ static NSMutableDictionary *colorStrings = nil;
|
|||
static NSMutableDictionary *systemDict = nil;
|
||||
|
||||
static
|
||||
void initSystemColors()
|
||||
void initSystemColors(void)
|
||||
{
|
||||
NSString *white;
|
||||
NSString *lightGray;
|
||||
|
@ -219,25 +220,39 @@ void initSystemColors()
|
|||
|
||||
systemColors = [NSColorList colorListNamed: @"System"];
|
||||
if (systemColors == nil)
|
||||
{
|
||||
systemColors = [[NSColorList alloc] initWithName: @"System"];
|
||||
}
|
||||
|
||||
{
|
||||
NSEnumerator *e;
|
||||
NSString *r;
|
||||
BOOL changed = NO;
|
||||
|
||||
// Set up default system colors
|
||||
systemColors = [[NSColorList alloc] initWithName: @"System"];
|
||||
|
||||
e = [colorStrings keyEnumerator];
|
||||
|
||||
while ((r = (NSString *)[e nextObject]))
|
||||
{
|
||||
NSString *cs = [colorStrings objectForKey: r];
|
||||
NSColor *c = [NSColorClass colorFromString: cs];
|
||||
NSString *cs;
|
||||
NSColor *c;
|
||||
|
||||
if (c != nil)
|
||||
[systemColors setColor: c forKey: r];
|
||||
if ([systemColors colorWithKey: r])
|
||||
continue;
|
||||
|
||||
cs = [colorStrings objectForKey: r];
|
||||
c = [NSColorClass colorFromString: cs];
|
||||
|
||||
NSCAssert1(c, @"couldn't get default system color %@", r);
|
||||
|
||||
[systemColors setColor: c forKey: r];
|
||||
|
||||
changed = YES;
|
||||
}
|
||||
|
||||
[systemColors writeToFile: nil];
|
||||
|
||||
if (changed)
|
||||
[systemColors writeToFile: nil];
|
||||
}
|
||||
|
||||
systemDict = [NSMutableDictionary new];
|
||||
|
@ -1245,16 +1260,21 @@ systemColorWithName(NSString *name)
|
|||
}
|
||||
else if (str != nil)
|
||||
{
|
||||
const char *ptr = [str cString];
|
||||
float r, g, b;
|
||||
NSScanner *scanner = [[NSScanner alloc] initWithString: str];
|
||||
|
||||
if (sscanf(ptr, "%f %f %f", &r, &g, &b) == 3)
|
||||
if ([scanner scanFloat: &r] &&
|
||||
[scanner scanFloat: &g] &&
|
||||
[scanner scanFloat: &b] &&
|
||||
[scanner isAtEnd])
|
||||
{
|
||||
return [self colorWithCalibratedRed: r
|
||||
green: g
|
||||
blue: b
|
||||
alpha: 1.0];
|
||||
}
|
||||
|
||||
DESTROY(scanner);
|
||||
}
|
||||
|
||||
return nil;
|
||||
|
|
Loading…
Reference in a new issue