Changes to make system colors easier to manage

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27449 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2008-12-29 11:49:42 +00:00
parent 539faec0d3
commit f0a1421d50
5 changed files with 79 additions and 34 deletions

View file

@ -4,13 +4,19 @@
control how application help is displayed.
* Documentation/GuiUser/DefaultsSummary.gsdoc: Document the new
user default.
* Source/GSTheme.m: Move stuff out into separate files.
* Headers/Additions/GNUstepGUI/GSTheme.h: New notifications and
method to obtain system colors.
* Source/GSTheme.m: Move stuff out into separate files. Add new
notifications for activation/deactivations. Implement new method
to provide system colors, making it easy for subclasses to replace
the standard mechanism for dealing with colors.
* Source/GSThemeInspector.m: The inspector for viewing a theme.
* Source/GSThemePanel.m: The panel for viewing/selecting themes.
* Source/GSThemeTools.m: Low level drawing tools.
* Source/GSThemeDrawing.m: Methods for drawing control.
* Source/GSThemePrivate.h: Internal API
* Source/GNUmakefile: Changes to build new theme files.
* Source/NSColor.m: Use new API for obtaining color list.
2008-12-28 Fred Kiefer <FredKiefer@gmx.de>

View file

@ -145,6 +145,7 @@
@class NSArray;
@class NSBundle;
@class NSColor;
@class NSColorList;
@class NSDictionary;
@class NSImage;
@class GSDrawTiles;
@ -176,14 +177,34 @@ typedef enum {
GSThemeSelectedState, /** A control which is selected */
} GSThemeControlState;
/** Notification sent when a theme has just become active.
/** Notification sent when a theme has just become active.<br />
* The notification is posted by the -activate method.<br />
* This is primarily for internal use by AppKit controls which
* need to readjust how they are displayed when a new theme is in use.
*/
APPKIT_EXPORT NSString *GSThemeDidActivateNotification;
/** Notification sent when a theme has become inactive.
/** Notification sent when a theme has just become inactive.<br />
* The notification is posted by the -deactivate method.<br />
* This is primarily for use by subclasses of GSTheme which need to perform
* additional cleanup when the theme stops being used.
*/
APPKIT_EXPORT NSString *GSThemeDidDeactivateNotification;
/** Notification sent when a theme is about to become active.<br />
* The notification is posted by the -activate method.<br />
* This is primarily for use by subclasses of GSTheme which need to perform
* additional setup before the theme starts being used by the AppKit controls.
*/
APPKIT_EXPORT NSString *GSThemeWillActivateNotification;
/** Notification sent when a theme is about to become inactive.<br />
* The notification is posted by the -deactivate method.<br />
* This allows code to make preparatory changes before the current theme
* is deactivated.
*/
APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
/**
<p><em>This interface is <strong>HIGHLY</strong> unstable
@ -226,6 +247,7 @@ APPKIT_EXPORT NSString *GSThemeDidDeactivateNotification;
{
@private
NSBundle *_bundle;
NSColorList *_colors;
NSMutableDictionary *_images;
NSMutableDictionary *_tiles;
NSImage *_icon;
@ -261,10 +283,9 @@ APPKIT_EXPORT NSString *GSThemeDidDeactivateNotification;
* <p>The base implementation handles setup and caching of the system
* color list, standard image information, tiling information,
* and user defaults.<br />
* It then sends a GSThemeDidActivateNotification to allow other
* parts of the GUI library to update themselves from the new theme.<br />
* If the theme sets an alternative system color list, the notification
* userInfo dictionary will contain that list keyed on <em>Colors</em>.
* It then sends a GSThemeWillActivateNotification and a
* GSThemeDidActivateNotification to allow other
* parts of the GUI library to update themselves from the new theme.
* </p>
* <p>Finally, this method marks all windows in the application as needing
* update ... so they will draw themselves with the new theme information.
@ -282,6 +303,13 @@ APPKIT_EXPORT NSString *GSThemeDidDeactivateNotification;
*/
- (NSBundle*) bundle;
/**
* Returns the system color list defined by the receiver.<br />
* The default implementation returns the color list provided in the
* theme bundle (if any) or the default system color list.
*/
- (NSColorList*) colors;
/**
* <p>This method is called automatically when the receiver is stopped from
* being the currently active theme by the use of the +setTheme: method

View file

@ -61,6 +61,10 @@ NSString *GSThemeDidActivateNotification
= @"GSThemeDidActivateNotification";
NSString *GSThemeDidDeactivateNotification
= @"GSThemeDidDeactivateNotification";
NSString *GSThemeWillActivateNotification
= @"GSThemeWillActivateNotification";
NSString *GSThemeWillDeactivateNotification
= @"GSThemeWillDeactivateNotification";
@implementation GSTheme
@ -237,31 +241,14 @@ static NSNull *null = nil;
- (void) activate
{
NSUserDefaults *defs;
NSMutableDictionary *userInfo;
NSMutableArray *searchList;
NSArray *imagePaths;
NSEnumerator *enumerator;
NSString *imagePath;
NSArray *imageTypes;
NSString *colorsPath;
NSDictionary *infoDict;
NSWindow *window;
userInfo = [NSMutableDictionary dictionary];
colorsPath = [_bundle pathForResource: @"ThemeColors" ofType: @"clr"];
if (colorsPath != nil)
{
NSColorList *list = nil;
list = [[NSColorList alloc] initWithName: @"System"
fromFile: colorsPath];
if (list != nil)
{
[userInfo setObject: list forKey: @"Colors"];
RELEASE(list);
}
}
/*
* We step through all the bundle image resources and load them in
* to memory, setting their names so that they are visible to
@ -364,13 +351,21 @@ static NSNull *null = nil;
}
RELEASE(searchList);
/*
* Tell all other classes that new theme information is about to be present.
*/
[[NSNotificationCenter defaultCenter]
postNotificationName: GSThemeWillActivateNotification
object: self
userInfo: nil];
/*
* Tell all other classes that new theme information is present.
*/
[[NSNotificationCenter defaultCenter]
postNotificationName: GSThemeDidActivateNotification
object: self
userInfo: userInfo];
postNotificationName: GSThemeDidActivateNotification
object: self
userInfo: nil];
/*
* Reset main menu to change between styles if necessary
@ -402,6 +397,13 @@ static NSNull *null = nil;
NSEnumerator *enumerator;
NSImage *image;
/* Tell everything that we will become inactive.
*/
[[NSNotificationCenter defaultCenter]
postNotificationName: GSThemeWillDeactivateNotification
object: self
userInfo: nil];
/*
* Remove all cached bundle images from both NSImage's name dictionary
* and our cache dictionary, so that we can be sure we reload afresh
@ -418,14 +420,15 @@ static NSNull *null = nil;
/* Tell everything that we have become inactive.
*/
[[NSNotificationCenter defaultCenter]
postNotificationName: GSThemeDidDeactivateNotification
object: self
userInfo: nil];
postNotificationName: GSThemeDidDeactivateNotification
object: self
userInfo: nil];
}
- (void) dealloc
{
RELEASE(_bundle);
RELEASE(_colors);
RELEASE(_images);
RELEASE(_tiles);
RELEASE(_icon);
@ -460,9 +463,17 @@ static NSNull *null = nil;
- (id) initWithBundle: (NSBundle*)bundle
{
NSString *colorsPath;
ASSIGN(_bundle, bundle);
_images = [NSMutableDictionary new];
_tiles = [NSMutableDictionary new];
colorsPath = [_bundle pathForResource: @"ThemeColors" ofType: @"clr"];
if (colorsPath != nil)
{
_colors = [[NSColorList alloc] initWithName: @"System"
fromFile: colorsPath];
}
return self;
}

View file

@ -140,7 +140,7 @@
}
}
#if 0
#if 1
- (NSRect) drawGradientBorder: (NSGradientType)gradientType
inRect: (NSRect)border
withClip: (NSRect)clip

View file

@ -1762,8 +1762,8 @@ systemColorWithName(NSString *name)
*/
+ (void) themeDidActivate: (NSNotification*)notification
{
NSDictionary *userInfo = [notification userInfo];
NSColorList *list = [userInfo objectForKey: @"Colors"];
GSTheme *theme = [notification object];
NSColorList *list = [theme colors];
if (list == nil)
{
@ -1773,7 +1773,7 @@ systemColorWithName(NSString *name)
[NSColorList _setThemeSystemColorList: list];
/* We always update the system dictionary and send a notification, since
* the theme may have gicen us a pre-existing color list, but have changed
* the theme may have given us a pre-existing color list, but have changed
* one or more of the colors in it.
*/
list = [NSColorList colorListNamed: @"System"];