add functions for handling fill style names

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28845 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-10-19 10:34:55 +00:00
parent 1c8cd6a0c4
commit 16ee679c7e
3 changed files with 61 additions and 24 deletions

View file

@ -2,6 +2,7 @@
* Source/GSThemeTools.m: Fix last changes to compile again (variable
declarations not at startof block only work on some compilers).
* Source/GSTheme.m: Functions for working with fill style names.
* Source/NSApplication.m: Fixup to show suppressed icon when app is
deactivated. Fix uninitialisaed variable causing crashes on failing
to use document controller to open an untitled document.

View file

@ -185,6 +185,17 @@ typedef enum {
their area, instead of being repeated */
} GSThemeFillStyle;
/** Function to convert a fill style enumeration value to a string.<br />
* Returns nil on failure.
*/
extern const NSString *
GSThemeStringFromFillStyle(GSThemeFillStyle s);
/** Function to convert a string to a fill style enumeration value.<br />
* Returns -1 on failure.
*/
extern GSThemeFillStyle
GSThemeFillStyleFromString(NSString *s);
/**
* This enumeration provides constants for informing drawing methods

View file

@ -78,6 +78,52 @@ NSString *GSThemeWillActivateNotification
NSString *GSThemeWillDeactivateNotification
= @"GSThemeWillDeactivateNotification";
extern const NSString *
GSThemeStringFromFillStyle(GSThemeFillStyle s)
{
switch (s)
{
case GSThemeFillStyleNone: return @"None";
case GSThemeFillStyleScale: return @"Scale";
case GSThemeFillStyleRepeat: return @"Repeat";
case GSThemeFillStyleCenter: return @"Center";
case GSThemeFillStyleMatrix: return @"Matrix";
case GSThemeFillStyleScaleAll: return @"ScaleAll";
}
return nil;
}
extern GSThemeFillStyle
GSThemeFillStyleFromString(NSString *s)
{
if ([s isEqualToString: @"None"])
{
return GSThemeFillStyleNone;
}
if ([s isEqualToString: @"Scale"])
{
return GSThemeFillStyleScale;
}
if ([s isEqualToString: @"Repeat"])
{
return GSThemeFillStyleRepeat;
}
if ([s isEqualToString: @"Center"])
{
return GSThemeFillStyleCenter;
}
if ([s isEqualToString: @"Matrix"])
{
return GSThemeFillStyleMatrix;
}
if ([s isEqualToString: @"ScaleAll"])
{
return GSThemeFillStyleScaleAll;
}
return -1;
}
@interface NSImage (GSTheme)
+ (NSImage*) _setImage: (NSImage*)image name: (NSString*)name;
@end
@ -823,32 +869,11 @@ typedef struct {
NSString *path;
NSString *file;
NSString *ext;
GSThemeFillStyle style = GSThemeFillStyleNone;
GSThemeFillStyle style;
name = [info objectForKey: @"FillStyle"];
if ([name length] > 0)
{
if ([name isEqualToString: @"Scale"])
{
style = GSThemeFillStyleScale;
}
else if ([name isEqualToString: @"Repeat"])
{
style = GSThemeFillStyleRepeat;
}
else if ([name isEqualToString: @"Center"])
{
style = GSThemeFillStyleCenter;
}
else if ([name isEqualToString: @"Matrix"])
{
style = GSThemeFillStyleMatrix;
}
else if ([name isEqualToString: @"ScaleAll"])
{
style = GSThemeFillStyleScaleAll;
}
}
style = GSThemeFillStyleFromString(name);
if (style < GSThemeFillStyleNone) style = GSThemeFillStyleNone;
x = [[info objectForKey: @"HorizontalDivision"] floatValue];
y = [[info objectForKey: @"VerticalDivision"] floatValue];
file = [info objectForKey: @"FileName"];