mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-01 09:02:01 +00:00
Added macOS-X compatibility stuff.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7440 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0e8e5eaf14
commit
8c4c1d434a
3 changed files with 153 additions and 20 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,9 @@
|
||||||
|
2000-09-07 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSGeometry.m: Add code to parse MacOS-X format strings.
|
||||||
|
Also produce MacOS-X format strings if the GSMacOSXCompatibleGeometry
|
||||||
|
or GSMacOSXCompatible default is YES (the former overrides the latter).
|
||||||
|
|
||||||
2000-09-01 Fred Kiefer <FredKiefer@gmx.de>
|
2000-09-01 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Headers/gnustep/base/NSString.h:
|
* Headers/gnustep/base/NSString.h:
|
||||||
|
@ -68,6 +74,12 @@
|
||||||
added index generation
|
added index generation
|
||||||
* Tools/gsdoc.gsdoc: added parameters documentation
|
* Tools/gsdoc.gsdoc: added parameters documentation
|
||||||
|
|
||||||
|
2000-08-13 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Documentation/gsdoc/NSString.gsdoc: add documentation for replacing
|
||||||
|
strings within the reciever.
|
||||||
|
* Documentation/gsdoc/NSMutableString.gsdoc: ditto
|
||||||
|
|
||||||
2000-08-08 Richard Frith-Macdonald <rfm@gnu.org>
|
2000-08-08 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Headers/gnustep/base/all.h: Moved to Old as obsolete file.
|
* Headers/gnustep/base/all.h: Moved to Old as obsolete file.
|
||||||
|
|
|
@ -34,7 +34,10 @@
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSGeometry.h>
|
#include <Foundation/NSGeometry.h>
|
||||||
#include <Foundation/NSScanner.h>
|
#include <Foundation/NSScanner.h>
|
||||||
|
#include <Foundation/NSNotification.h>
|
||||||
|
#include <Foundation/NSUserDefaults.h>
|
||||||
|
|
||||||
|
static BOOL MacOSX = NO; // Compatibility mode
|
||||||
static Class NSStringClass = 0;
|
static Class NSStringClass = 0;
|
||||||
static Class NSScannerClass = 0;
|
static Class NSScannerClass = 0;
|
||||||
static SEL scanFloatSel = @selector(scanFloat:);
|
static SEL scanFloatSel = @selector(scanFloat:);
|
||||||
|
@ -44,6 +47,36 @@ static BOOL (*scanFloatImp)(NSScanner*, SEL, float*);
|
||||||
static BOOL (*scanStringImp)(NSScanner*, SEL, NSString*, NSString**);
|
static BOOL (*scanStringImp)(NSScanner*, SEL, NSString*, NSString**);
|
||||||
static id (*scannerImp)(Class, SEL, NSString*);
|
static id (*scannerImp)(Class, SEL, NSString*);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A trivial class to monitor user defaults to see how we should be
|
||||||
|
* producing strings describing geometry structures.
|
||||||
|
*/
|
||||||
|
@interface GSGeometryDefaultObserver : NSObject
|
||||||
|
+ (void) defaultsChanged: (NSNotification*)aNotification;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation GSGeometryDefaultObserver
|
||||||
|
+ (void) defaultsChanged: (NSNotification*)aNotification
|
||||||
|
{
|
||||||
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
id def;
|
||||||
|
|
||||||
|
def = [defaults objectForKey: @"GSMacOSXCompatibleGeometry"];
|
||||||
|
if (def == nil)
|
||||||
|
{
|
||||||
|
def = [defaults objectForKey: @"GSMacOSXCompatible"];
|
||||||
|
}
|
||||||
|
if (def != nil && [def isKindOfClass: NSStringClass] == YES)
|
||||||
|
{
|
||||||
|
MacOSX = [def boolValue];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MacOSX = NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
setupCache()
|
setupCache()
|
||||||
{
|
{
|
||||||
|
@ -57,6 +90,13 @@ setupCache()
|
||||||
[NSScannerClass instanceMethodForSelector: scanStringSel];
|
[NSScannerClass instanceMethodForSelector: scanStringSel];
|
||||||
scannerImp = (id (*)(Class, SEL, NSString*))
|
scannerImp = (id (*)(Class, SEL, NSString*))
|
||||||
[NSScannerClass methodForSelector: scannerSel];
|
[NSScannerClass methodForSelector: scannerSel];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
addObserver: [GSGeometryDefaultObserver class]
|
||||||
|
selector: @selector(defaultsChanged:)
|
||||||
|
name: NSUserDefaultsDidChangeNotification
|
||||||
|
object: nil];
|
||||||
|
[[GSGeometryDefaultObserver class] defaultsChanged: nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,30 +234,46 @@ NSDivideRect(NSRect aRect,
|
||||||
|
|
||||||
/** Get a String Representation... **/
|
/** Get a String Representation... **/
|
||||||
|
|
||||||
NSString *
|
NSString*
|
||||||
NSStringFromPoint(NSPoint aPoint)
|
NSStringFromPoint(NSPoint aPoint)
|
||||||
{
|
{
|
||||||
setupCache();
|
setupCache();
|
||||||
return [NSStringClass stringWithFormat: @"{x=%f; y=%f}", aPoint.x, aPoint.y];
|
if (MacOSX == YES)
|
||||||
|
return [NSStringClass stringWithFormat:
|
||||||
|
@"{%g, %g}", aPoint.x, aPoint.y];
|
||||||
|
else
|
||||||
|
return [NSStringClass stringWithFormat:
|
||||||
|
@"{x=%g; y=%g}", aPoint.x, aPoint.y];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString *
|
NSString*
|
||||||
NSStringFromRect(NSRect aRect)
|
NSStringFromRect(NSRect aRect)
|
||||||
{
|
{
|
||||||
setupCache();
|
setupCache();
|
||||||
return [NSStringClass stringWithFormat: @"{x=%f; y=%f; width=%f; height=%f}",
|
if (MacOSX == YES)
|
||||||
|
return [NSStringClass stringWithFormat:
|
||||||
|
@"{{%g, %g}, {%g, %g}}",
|
||||||
|
aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height];
|
||||||
|
else
|
||||||
|
return [NSStringClass stringWithFormat:
|
||||||
|
@"{x=%g; y=%g; width=%g; height=%g}",
|
||||||
aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height];
|
aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString *
|
NSString*
|
||||||
NSStringFromSize(NSSize aSize)
|
NSStringFromSize(NSSize aSize)
|
||||||
{
|
{
|
||||||
setupCache();
|
setupCache();
|
||||||
return [NSStringClass stringWithFormat: @"{width=%f; height=%f}",
|
if (MacOSX == YES)
|
||||||
aSize.width, aSize.height];
|
return [NSStringClass stringWithFormat:
|
||||||
|
@"{%g, %g}", aSize.width, aSize.height];
|
||||||
|
else
|
||||||
|
return [NSStringClass stringWithFormat:
|
||||||
|
@"{width=%g; height=%g}", aSize.width, aSize.height];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSPoint NSPointFromString(NSString* string)
|
NSPoint
|
||||||
|
NSPointFromString(NSString* string)
|
||||||
{
|
{
|
||||||
NSScanner *scanner;
|
NSScanner *scanner;
|
||||||
NSPoint point;
|
NSPoint point;
|
||||||
|
@ -233,12 +289,29 @@ NSPoint NSPointFromString(NSString* string)
|
||||||
&& (*scanStringImp)(scanner, scanStringSel, @"=", NULL)
|
&& (*scanStringImp)(scanner, scanStringSel, @"=", NULL)
|
||||||
&& (*scanFloatImp)(scanner, scanFloatSel, &point.y)
|
&& (*scanFloatImp)(scanner, scanFloatSel, &point.y)
|
||||||
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
||||||
|
{
|
||||||
return point;
|
return point;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
[scanner setScanLocation: 0];
|
||||||
|
if ((*scanStringImp)(scanner, scanStringSel, @"{", NULL)
|
||||||
|
&& (*scanFloatImp)(scanner, scanFloatSel, &point.x)
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @",", NULL)
|
||||||
|
&& (*scanFloatImp)(scanner, scanFloatSel, &point.y)
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
||||||
|
{
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return NSMakePoint(0, 0);
|
return NSMakePoint(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSSize NSSizeFromString(NSString* string)
|
NSSize
|
||||||
|
NSSizeFromString(NSString* string)
|
||||||
{
|
{
|
||||||
NSScanner *scanner;
|
NSScanner *scanner;
|
||||||
NSSize size;
|
NSSize size;
|
||||||
|
@ -254,12 +327,29 @@ NSSize NSSizeFromString(NSString* string)
|
||||||
&& (*scanStringImp)(scanner, scanStringSel, @"=", NULL)
|
&& (*scanStringImp)(scanner, scanStringSel, @"=", NULL)
|
||||||
&& (*scanFloatImp)(scanner, scanFloatSel, &size.height)
|
&& (*scanFloatImp)(scanner, scanFloatSel, &size.height)
|
||||||
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
||||||
|
{
|
||||||
return size;
|
return size;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
[scanner setScanLocation: 0];
|
||||||
|
if ((*scanStringImp)(scanner, scanStringSel, @"{", NULL)
|
||||||
|
&& (*scanFloatImp)(scanner, scanFloatSel, &size.width)
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @",", NULL)
|
||||||
|
&& (*scanFloatImp)(scanner, scanFloatSel, &size.height)
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
||||||
|
{
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return NSMakeSize(0, 0);
|
return NSMakeSize(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSRect NSRectFromString(NSString* string)
|
NSRect
|
||||||
|
NSRectFromString(NSString* string)
|
||||||
{
|
{
|
||||||
NSScanner *scanner;
|
NSScanner *scanner;
|
||||||
NSRect rect;
|
NSRect rect;
|
||||||
|
@ -286,8 +376,35 @@ NSRect NSRectFromString(NSString* string)
|
||||||
&& (*scanStringImp)(scanner, scanStringSel, @"=", NULL)
|
&& (*scanStringImp)(scanner, scanStringSel, @"=", NULL)
|
||||||
&& (*scanFloatImp)(scanner, scanFloatSel, &rect.size.height)
|
&& (*scanFloatImp)(scanner, scanFloatSel, &rect.size.height)
|
||||||
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
||||||
|
{
|
||||||
return rect;
|
return rect;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
[scanner setScanLocation: 0];
|
||||||
|
if ((*scanStringImp)(scanner, scanStringSel, @"{", NULL)
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @"{", NULL)
|
||||||
|
&& (*scanFloatImp)(scanner, scanFloatSel, &rect.origin.x)
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @",", NULL)
|
||||||
|
|
||||||
|
&& (*scanFloatImp)(scanner, scanFloatSel, &rect.origin.y)
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL)
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @",", NULL)
|
||||||
|
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @"{", NULL)
|
||||||
|
&& (*scanFloatImp)(scanner, scanFloatSel, &rect.size.width)
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @",", NULL)
|
||||||
|
|
||||||
|
&& (*scanFloatImp)(scanner, scanFloatSel, &rect.size.height)
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL)
|
||||||
|
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
||||||
|
{
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return NSMakeRect(0, 0, 0, 0);
|
return NSMakeRect(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ print_string(NSString* s)
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
|
#include <Foundation/NSGeometry.h>
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
@ -25,6 +26,9 @@ int main()
|
||||||
|
|
||||||
print_string(s);
|
print_string(s);
|
||||||
|
|
||||||
|
s2 = NSStringFromPoint(NSMakePoint(1.374, 5.100));
|
||||||
|
print_string(s2);
|
||||||
|
|
||||||
s2 = [s copy];
|
s2 = [s copy];
|
||||||
print_string(s2);
|
print_string(s2);
|
||||||
s3 = [s2 mutableCopy];
|
s3 = [s2 mutableCopy];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue