mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +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
6e11db13e3
commit
2085dd62a2
3 changed files with 153 additions and 20 deletions
18
ChangeLog
18
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>
|
||||
|
||||
* Headers/gnustep/base/NSString.h:
|
||||
|
@ -17,9 +23,9 @@
|
|||
|
||||
* Tools/gsdoc-0_6_6.dtd: added prjref element which enable explicit
|
||||
links between projects
|
||||
* Tools/gsdoc.m: handle prjref
|
||||
remove extensions from files in gsdocrefs
|
||||
(one day we'll generate other formats :-)
|
||||
* Tools/gsdoc.m: handle prjref
|
||||
remove extensions from files in gsdocrefs
|
||||
(one day we'll generate other formats :-)
|
||||
|
||||
2000-08-23 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
|
@ -68,6 +74,12 @@
|
|||
added index generation
|
||||
* 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>
|
||||
|
||||
* Headers/gnustep/base/all.h: Moved to Old as obsolete file.
|
||||
|
|
|
@ -34,7 +34,10 @@
|
|||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSGeometry.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 NSScannerClass = 0;
|
||||
static SEL scanFloatSel = @selector(scanFloat:);
|
||||
|
@ -44,6 +47,36 @@ static BOOL (*scanFloatImp)(NSScanner*, SEL, float*);
|
|||
static BOOL (*scanStringImp)(NSScanner*, SEL, NSString*, 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
|
||||
setupCache()
|
||||
{
|
||||
|
@ -57,6 +90,13 @@ setupCache()
|
|||
[NSScannerClass instanceMethodForSelector: scanStringSel];
|
||||
scannerImp = (id (*)(Class, SEL, NSString*))
|
||||
[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... **/
|
||||
|
||||
NSString *
|
||||
NSString*
|
||||
NSStringFromPoint(NSPoint aPoint)
|
||||
{
|
||||
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)
|
||||
{
|
||||
setupCache();
|
||||
return [NSStringClass stringWithFormat: @"{x=%f; y=%f; width=%f; height=%f}",
|
||||
aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height];
|
||||
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];
|
||||
}
|
||||
|
||||
NSString *
|
||||
NSString*
|
||||
NSStringFromSize(NSSize aSize)
|
||||
{
|
||||
setupCache();
|
||||
return [NSStringClass stringWithFormat: @"{width=%f; height=%f}",
|
||||
aSize.width, aSize.height];
|
||||
if (MacOSX == YES)
|
||||
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;
|
||||
NSPoint point;
|
||||
|
@ -233,12 +289,29 @@ NSPoint NSPointFromString(NSString* string)
|
|||
&& (*scanStringImp)(scanner, scanStringSel, @"=", NULL)
|
||||
&& (*scanFloatImp)(scanner, scanFloatSel, &point.y)
|
||||
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
||||
return point;
|
||||
{
|
||||
return point;
|
||||
}
|
||||
else
|
||||
return NSMakePoint(0, 0);
|
||||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSSize NSSizeFromString(NSString* string)
|
||||
NSSize
|
||||
NSSizeFromString(NSString* string)
|
||||
{
|
||||
NSScanner *scanner;
|
||||
NSSize size;
|
||||
|
@ -254,12 +327,29 @@ NSSize NSSizeFromString(NSString* string)
|
|||
&& (*scanStringImp)(scanner, scanStringSel, @"=", NULL)
|
||||
&& (*scanFloatImp)(scanner, scanFloatSel, &size.height)
|
||||
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
||||
return size;
|
||||
{
|
||||
return size;
|
||||
}
|
||||
else
|
||||
return NSMakeSize(0, 0);
|
||||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSRect NSRectFromString(NSString* string)
|
||||
NSRect
|
||||
NSRectFromString(NSString* string)
|
||||
{
|
||||
NSScanner *scanner;
|
||||
NSRect rect;
|
||||
|
@ -286,8 +376,35 @@ NSRect NSRectFromString(NSString* string)
|
|||
&& (*scanStringImp)(scanner, scanStringSel, @"=", NULL)
|
||||
&& (*scanFloatImp)(scanner, scanFloatSel, &rect.size.height)
|
||||
&& (*scanStringImp)(scanner, scanStringSel, @"}", NULL))
|
||||
return rect;
|
||||
{
|
||||
return rect;
|
||||
}
|
||||
else
|
||||
return NSMakeRect(0, 0, 0, 0);
|
||||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ print_string(NSString* s)
|
|||
}
|
||||
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSGeometry.h>
|
||||
|
||||
|
||||
int main()
|
||||
|
@ -25,6 +26,9 @@ int main()
|
|||
|
||||
print_string(s);
|
||||
|
||||
s2 = NSStringFromPoint(NSMakePoint(1.374, 5.100));
|
||||
print_string(s2);
|
||||
|
||||
s2 = [s copy];
|
||||
print_string(s2);
|
||||
s3 = [s2 mutableCopy];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue