2006-09-22 11:53:40 +00:00
|
|
|
/** <title>GSTheme</title>
|
2004-01-19 04:22:47 +00:00
|
|
|
|
|
|
|
<abstract>Useful/configurable drawing functions</abstract>
|
|
|
|
|
|
|
|
Copyright (C) 2004 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Adam Fedor <fedor@gnu.org>
|
|
|
|
Date: Jan 2004
|
|
|
|
|
|
|
|
This file is part of the GNU Objective C User interface library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2004-01-19 04:22:47 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:01:49 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2007-10-29 21:16:17 +00:00
|
|
|
|
2004-01-19 04:22:47 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-29 21:16:17 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
2004-01-19 04:22:47 +00:00
|
|
|
|
2008-12-29 10:28:59 +00:00
|
|
|
#import "Foundation/NSBundle.h"
|
|
|
|
#import "Foundation/NSDictionary.h"
|
|
|
|
#import "Foundation/NSFileManager.h"
|
2009-01-05 06:51:59 +00:00
|
|
|
#import "Foundation/NSMapTable.h"
|
2008-12-29 10:28:59 +00:00
|
|
|
#import "Foundation/NSNotification.h"
|
|
|
|
#import "Foundation/NSNull.h"
|
|
|
|
#import "Foundation/NSPathUtilities.h"
|
|
|
|
#import "Foundation/NSSet.h"
|
|
|
|
#import "Foundation/NSUserDefaults.h"
|
|
|
|
#import "GNUstepGUI/GSTheme.h"
|
|
|
|
#import "AppKit/NSApplication.h"
|
|
|
|
#import "AppKit/NSButton.h"
|
|
|
|
#import "AppKit/NSColor.h"
|
|
|
|
#import "AppKit/NSColorList.h"
|
|
|
|
#import "AppKit/NSGraphics.h"
|
|
|
|
#import "AppKit/NSImage.h"
|
|
|
|
#import "AppKit/NSImageView.h"
|
|
|
|
#import "AppKit/NSMatrix.h"
|
|
|
|
#import "AppKit/NSMenu.h"
|
|
|
|
#import "AppKit/NSPanel.h"
|
|
|
|
#import "AppKit/NSScrollView.h"
|
|
|
|
#import "AppKit/NSTextContainer.h"
|
|
|
|
#import "AppKit/NSTextField.h"
|
|
|
|
#import "AppKit/NSTextView.h"
|
|
|
|
#import "AppKit/NSScrollView.h"
|
|
|
|
#import "AppKit/NSView.h"
|
|
|
|
#import "AppKit/NSWindow.h"
|
|
|
|
#import "AppKit/NSBezierPath.h"
|
|
|
|
#import "AppKit/PSOperators.h"
|
|
|
|
#import "GSThemePrivate.h"
|
2006-10-02 05:09:48 +00:00
|
|
|
|
2009-01-05 09:43:25 +00:00
|
|
|
// Scroller part names
|
|
|
|
NSString *GSScrollerDownArrow = @"GSScrollerDownArrow";
|
|
|
|
NSString *GSScrollerHorizontalKnob = @"GSScrollerHorizontalKnob";
|
|
|
|
NSString *GSScrollerHorizontalSlot = @"GSScrollerHorizontalSlot";
|
|
|
|
NSString *GSScrollerLeftArrow = @"GSScrollerLeftArrow";
|
|
|
|
NSString *GSScrollerRightArrow = @"GSScrollerRightArrow";
|
|
|
|
NSString *GSScrollerUpArrow = @"GSScrollerUpArrow";
|
|
|
|
NSString *GSScrollerVerticalKnob = @"GSScrollerVerticalKnob";
|
|
|
|
NSString *GSScrollerVerticalSlot = @"GSScrollerVerticalSlot";
|
2006-10-02 05:09:48 +00:00
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
NSString *GSThemeDidActivateNotification
|
|
|
|
= @"GSThemeDidActivateNotification";
|
|
|
|
NSString *GSThemeDidDeactivateNotification
|
|
|
|
= @"GSThemeDidDeactivateNotification";
|
2008-12-29 11:49:42 +00:00
|
|
|
NSString *GSThemeWillActivateNotification
|
|
|
|
= @"GSThemeWillActivateNotification";
|
|
|
|
NSString *GSThemeWillDeactivateNotification
|
|
|
|
= @"GSThemeWillDeactivateNotification";
|
2006-09-22 11:23:03 +00:00
|
|
|
|
2009-01-06 05:08:58 +00:00
|
|
|
@interface GSTheme (Private)
|
|
|
|
- (void) _revokeOwnerships;
|
|
|
|
@end
|
|
|
|
|
2006-09-22 11:53:40 +00:00
|
|
|
@implementation GSTheme
|
2004-01-19 04:22:47 +00:00
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
static GSTheme *defaultTheme = nil;
|
|
|
|
static NSString *currentThemeName = nil;
|
|
|
|
static GSTheme *theTheme = nil;
|
2006-09-22 11:23:03 +00:00
|
|
|
static NSMutableDictionary *themes = nil;
|
|
|
|
static NSNull *null = nil;
|
2009-01-05 06:51:59 +00:00
|
|
|
static NSMapTable *names = 0;
|
2005-11-23 05:43:21 +00:00
|
|
|
|
2009-01-02 10:12:25 +00:00
|
|
|
typedef struct {
|
|
|
|
NSBundle *bundle;
|
|
|
|
NSColorList *colors;
|
|
|
|
NSMutableDictionary *images;
|
2009-01-05 09:43:25 +00:00
|
|
|
NSMutableDictionary *normalTiles;
|
|
|
|
NSMutableDictionary *highlightedTiles;
|
|
|
|
NSMutableDictionary *selectedTiles;
|
2009-01-06 05:08:58 +00:00
|
|
|
NSMutableSet *owned;
|
2009-01-02 10:12:25 +00:00
|
|
|
NSImage *icon;
|
|
|
|
NSString *name;
|
|
|
|
} internal;
|
|
|
|
|
2009-01-05 09:43:25 +00:00
|
|
|
#define _internal ((internal*)_reserved)
|
|
|
|
#define _bundle _internal->bundle
|
|
|
|
#define _colors _internal->colors
|
|
|
|
#define _images _internal->images
|
|
|
|
#define _normalTiles _internal->normalTiles
|
|
|
|
#define _highlightedTiles _internal->highlightedTiles
|
|
|
|
#define _selectedTiles _internal->selectedTiles
|
2009-01-06 05:08:58 +00:00
|
|
|
#define _owned _internal->owned
|
2009-01-05 09:43:25 +00:00
|
|
|
#define _icon _internal->icon
|
|
|
|
#define _name _internal->name
|
2009-01-02 10:12:25 +00:00
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
+ (void) defaultsDidChange: (NSNotification*)n
|
|
|
|
{
|
|
|
|
NSUserDefaults *defs;
|
|
|
|
NSString *name;
|
2005-11-02 13:55:27 +00:00
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
defs = [NSUserDefaults standardUserDefaults];
|
|
|
|
name = [defs stringForKey: @"GSTheme"];
|
2006-10-02 05:09:48 +00:00
|
|
|
if (name != currentThemeName && [name isEqual: currentThemeName] == NO)
|
2006-09-22 11:23:03 +00:00
|
|
|
{
|
2006-10-02 05:09:48 +00:00
|
|
|
[self setTheme: [self loadThemeNamed: name]];
|
|
|
|
ASSIGN(currentThemeName, name); // Don't try to load again.
|
2006-09-22 11:23:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) initialize
|
2005-11-02 13:55:27 +00:00
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
if (themes == nil)
|
2005-11-02 13:55:27 +00:00
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
themes = [NSMutableDictionary new];
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver: self
|
|
|
|
selector: @selector(defaultsDidChange:)
|
|
|
|
name: NSUserDefaultsDidChangeNotification
|
|
|
|
object: nil];
|
|
|
|
null = RETAIN([NSNull null]);
|
2009-01-02 10:12:25 +00:00
|
|
|
defaultTheme = [[self alloc] initWithBundle: nil];
|
2006-09-22 11:23:03 +00:00
|
|
|
ASSIGN(theTheme, defaultTheme);
|
2009-01-02 10:12:25 +00:00
|
|
|
ASSIGN(currentThemeName, [defaultTheme name]);
|
2009-01-05 06:51:59 +00:00
|
|
|
names = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
|
|
|
|
NSIntMapValueCallBacks, 0);
|
2005-11-02 13:55:27 +00:00
|
|
|
}
|
2006-10-02 05:09:48 +00:00
|
|
|
/* Establish the theme specified by the user defaults (if any);
|
|
|
|
*/
|
|
|
|
[self defaultsDidChange: nil];
|
2005-11-02 13:55:27 +00:00
|
|
|
}
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
+ (GSTheme*) loadThemeNamed: (NSString*)aName
|
2005-11-02 13:55:27 +00:00
|
|
|
{
|
2006-10-02 05:09:48 +00:00
|
|
|
NSBundle *bundle;
|
|
|
|
Class cls;
|
2006-09-22 11:53:40 +00:00
|
|
|
GSTheme *instance;
|
2006-10-02 05:09:48 +00:00
|
|
|
NSString *theme;
|
2006-09-22 11:23:03 +00:00
|
|
|
|
|
|
|
if ([aName length] == 0)
|
|
|
|
{
|
2006-10-02 05:09:48 +00:00
|
|
|
return defaultTheme;
|
2006-09-22 11:23:03 +00:00
|
|
|
}
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
if ([aName isAbsolutePath] == YES)
|
2006-09-22 11:23:03 +00:00
|
|
|
{
|
|
|
|
theme = aName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-10-02 05:09:48 +00:00
|
|
|
aName = [aName lastPathComponent];
|
|
|
|
|
|
|
|
/* Ensure that the theme name has the 'theme' extension.
|
|
|
|
*/
|
|
|
|
if ([[aName pathExtension] isEqualToString: @"theme"] == YES)
|
|
|
|
{
|
|
|
|
theme = aName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
theme = [aName stringByAppendingPathExtension: @"theme"];
|
|
|
|
}
|
|
|
|
if ([theme isEqualToString: @"GNUstep.theme"] == YES)
|
|
|
|
{
|
|
|
|
return defaultTheme;
|
|
|
|
}
|
2006-09-22 11:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bundle = [themes objectForKey: theme];
|
|
|
|
if (bundle == nil)
|
|
|
|
{
|
|
|
|
NSString *path;
|
|
|
|
NSFileManager *mgr = [NSFileManager defaultManager];
|
2006-10-02 05:09:48 +00:00
|
|
|
BOOL isDir;
|
2006-09-22 11:23:03 +00:00
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
/* A theme may be either an absolute path or a filename to be located
|
|
|
|
* in the Themes subdirectory of one of the standard Library directories.
|
|
|
|
*/
|
|
|
|
if ([theme isAbsolutePath] == YES)
|
|
|
|
{
|
|
|
|
if ([mgr fileExistsAtPath: theme isDirectory: &isDir] == YES
|
|
|
|
&& isDir == YES)
|
|
|
|
{
|
|
|
|
path = theme;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
|
|
|
enumerator = [NSSearchPathForDirectoriesInDomains
|
|
|
|
(NSAllLibrariesDirectory, NSAllDomainsMask, YES) objectEnumerator];
|
|
|
|
while ((path = [enumerator nextObject]) != nil)
|
2006-09-22 11:23:03 +00:00
|
|
|
{
|
2006-10-02 05:09:48 +00:00
|
|
|
path = [path stringByAppendingPathComponent: @"Themes"];
|
|
|
|
path = [path stringByAppendingPathComponent: theme];
|
|
|
|
if ([mgr fileExistsAtPath: path isDirectory: &isDir])
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2006-09-22 11:23:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path == nil)
|
|
|
|
{
|
|
|
|
NSLog (@"No theme named '%@' found", aName);
|
2006-10-02 05:09:48 +00:00
|
|
|
return nil;
|
2006-09-22 11:23:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bundle = [NSBundle bundleWithPath: path];
|
|
|
|
[themes setObject: bundle forKey: theme];
|
|
|
|
[bundle load]; // Ensure code is loaded.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cls = [bundle principalClass];
|
|
|
|
if (cls == 0)
|
|
|
|
{
|
|
|
|
cls = self;
|
|
|
|
}
|
|
|
|
instance = [[cls alloc] initWithBundle: bundle];
|
2006-10-02 05:09:48 +00:00
|
|
|
return AUTORELEASE(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) orderFrontSharedThemePanel: (id)sender
|
|
|
|
{
|
|
|
|
GSThemePanel *panel;
|
|
|
|
|
|
|
|
panel = [GSThemePanel sharedThemePanel];
|
|
|
|
[panel update: self];
|
|
|
|
[panel center];
|
|
|
|
[panel orderFront: self];
|
2005-11-02 13:55:27 +00:00
|
|
|
}
|
|
|
|
|
2006-09-22 11:53:40 +00:00
|
|
|
+ (void) setTheme: (GSTheme*)theme
|
2005-11-23 05:43:21 +00:00
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
if (theme == nil)
|
|
|
|
{
|
|
|
|
theme = defaultTheme;
|
|
|
|
}
|
|
|
|
if (theme != theTheme)
|
|
|
|
{
|
|
|
|
[theTheme deactivate];
|
|
|
|
ASSIGN (theTheme, theme);
|
|
|
|
[theTheme activate];
|
|
|
|
}
|
2006-10-02 05:09:48 +00:00
|
|
|
ASSIGN(currentThemeName, [theTheme name]);
|
2005-11-23 05:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-09-22 11:53:40 +00:00
|
|
|
+ (GSTheme*) theme
|
2005-11-23 05:43:21 +00:00
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
return theTheme;
|
2005-11-23 05:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
- (void) activate
|
2005-11-23 05:43:21 +00:00
|
|
|
{
|
2006-10-02 05:09:48 +00:00
|
|
|
NSUserDefaults *defs;
|
|
|
|
NSMutableArray *searchList;
|
2006-09-22 11:23:03 +00:00
|
|
|
NSArray *imagePaths;
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
NSString *imagePath;
|
2006-10-02 05:09:48 +00:00
|
|
|
NSArray *imageTypes;
|
|
|
|
NSDictionary *infoDict;
|
|
|
|
NSWindow *window;
|
2006-09-22 11:23:03 +00:00
|
|
|
|
2008-12-29 12:05:35 +00:00
|
|
|
/* Get rid of any cached colors list so that we regenerate it when needed
|
|
|
|
*/
|
|
|
|
[_colors release];
|
|
|
|
_colors = nil;
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
/*
|
|
|
|
* We step through all the bundle image resources and load them in
|
|
|
|
* to memory, setting their names so that they are visible to
|
|
|
|
* [NSImage+imageNamed:] and storing them in our local array.
|
|
|
|
*/
|
2006-10-02 05:09:48 +00:00
|
|
|
imageTypes = [NSImage imageFileTypes];
|
2006-09-22 11:23:03 +00:00
|
|
|
imagePaths = [_bundle pathsForResourcesOfType: nil
|
|
|
|
inDirectory: @"ThemeImages"];
|
|
|
|
enumerator = [imagePaths objectEnumerator];
|
|
|
|
while ((imagePath = [enumerator nextObject]) != nil)
|
|
|
|
{
|
2006-10-02 05:09:48 +00:00
|
|
|
NSString *ext = [imagePath pathExtension];
|
2006-09-22 11:23:03 +00:00
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
if (ext != nil && [imageTypes containsObject: ext] == YES)
|
|
|
|
{
|
|
|
|
NSImage *image;
|
2006-12-27 11:35:48 +00:00
|
|
|
NSString *imageName;
|
2006-10-02 05:09:48 +00:00
|
|
|
|
2006-12-27 11:35:48 +00:00
|
|
|
imageName = [imagePath lastPathComponent];
|
|
|
|
imageName = [imageName stringByDeletingPathExtension];
|
|
|
|
|
|
|
|
image = [_images objectForKey: imageName];
|
|
|
|
if (image == nil)
|
2006-10-02 05:09:48 +00:00
|
|
|
{
|
2006-12-27 11:35:48 +00:00
|
|
|
image = [[NSImage alloc] initWithContentsOfFile: imagePath];
|
|
|
|
if (image != nil)
|
|
|
|
{
|
|
|
|
[_images setObject: image forKey: imageName];
|
|
|
|
RELEASE(image);
|
|
|
|
}
|
|
|
|
}
|
2006-10-02 05:09:48 +00:00
|
|
|
|
2006-12-27 11:35:48 +00:00
|
|
|
/* We try to ensure that our new image can be found by name.
|
|
|
|
*/
|
|
|
|
if (image != nil && [[image name] isEqualToString: imageName] == NO)
|
|
|
|
{
|
|
|
|
if ([image setName: imageName] == NO)
|
|
|
|
{
|
|
|
|
NSImage *old;
|
|
|
|
|
|
|
|
/* Couldn't set image name ... presumably already
|
|
|
|
* in use ... so we remove the name from the old
|
|
|
|
* image and try again.
|
|
|
|
*/
|
|
|
|
old = [NSImage imageNamed: imageName];
|
|
|
|
[old setName: nil];
|
|
|
|
[image setName: imageName];
|
|
|
|
}
|
2006-10-02 05:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-10-15 08:34:47 +00:00
|
|
|
* We could cache tile info here, but it's probably better for the
|
2009-01-05 09:43:25 +00:00
|
|
|
* tilesNamed:state:cache: method to do it lazily.
|
2006-10-02 05:09:48 +00:00
|
|
|
*/
|
2006-09-22 11:23:03 +00:00
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
/*
|
|
|
|
* Use the GSThemeDomain key in the info dictionary of the theme to
|
|
|
|
* set a defaults domain which will establish user defaults values
|
|
|
|
* but will not override any defaults set explicitly by the user.
|
|
|
|
* NB. For subclasses, the theme info dictionary may not be the same
|
|
|
|
* as that of the bundle, so we don't use the bundle method directly.
|
|
|
|
*/
|
|
|
|
infoDict = [self infoDictionary];
|
|
|
|
defs = [NSUserDefaults standardUserDefaults];
|
|
|
|
searchList = [[defs searchList] mutableCopy];
|
|
|
|
if ([[infoDict objectForKey: @"GSThemeDomain"] isKindOfClass:
|
|
|
|
[NSDictionary class]] == YES)
|
|
|
|
{
|
|
|
|
[defs removeVolatileDomainForName: @"GSThemeDomain"];
|
|
|
|
[defs setVolatileDomain: [infoDict objectForKey: @"GSThemeDomain"]
|
|
|
|
forName: @"GSThemeDomain"];
|
|
|
|
if ([searchList containsObject: @"GSThemeDomain"] == NO)
|
|
|
|
{
|
|
|
|
unsigned index;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Higher priority than GSConfigDomain and NSRegistrationDomain,
|
|
|
|
* but lower than NSGlobalDomain, NSArgumentDomain, and others
|
|
|
|
* set by the user to be application specific.
|
|
|
|
*/
|
|
|
|
index = [searchList indexOfObject: GSConfigDomain];
|
|
|
|
if (index == NSNotFound)
|
|
|
|
{
|
|
|
|
index = [searchList indexOfObject: NSRegistrationDomain];
|
|
|
|
if (index == NSNotFound)
|
|
|
|
{
|
|
|
|
index = [searchList count];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[searchList insertObject: @"GSThemeDomain" atIndex: index];
|
|
|
|
[defs setSearchList: searchList];
|
2006-09-22 11:23:03 +00:00
|
|
|
}
|
|
|
|
}
|
2006-10-02 05:09:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[searchList removeObject: @"GSThemeDomain"];
|
|
|
|
[defs removeVolatileDomainForName: @"GSThemeDomain"];
|
|
|
|
}
|
|
|
|
RELEASE(searchList);
|
2006-09-22 11:23:03 +00:00
|
|
|
|
2008-12-29 11:49:42 +00:00
|
|
|
/*
|
|
|
|
* Tell all other classes that new theme information is about to be present.
|
|
|
|
*/
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
postNotificationName: GSThemeWillActivateNotification
|
|
|
|
object: self
|
|
|
|
userInfo: nil];
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
/*
|
|
|
|
* Tell all other classes that new theme information is present.
|
|
|
|
*/
|
2006-09-22 11:23:03 +00:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
2008-12-29 11:49:42 +00:00
|
|
|
postNotificationName: GSThemeDidActivateNotification
|
|
|
|
object: self
|
|
|
|
userInfo: nil];
|
2006-10-02 05:09:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset main menu to change between styles if necessary
|
|
|
|
*/
|
|
|
|
[[NSApp mainMenu] setMain: YES];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark all windows as needing redisplaying to thos the new theme.
|
|
|
|
*/
|
|
|
|
enumerator = [[NSApp windows] objectEnumerator];
|
|
|
|
while ((window = [enumerator nextObject]) != nil)
|
|
|
|
{
|
|
|
|
[[[window contentView] superview] setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*) authors
|
|
|
|
{
|
|
|
|
return [[self infoDictionary] objectForKey: @"GSThemeAuthors"];
|
2005-11-23 05:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
- (NSBundle*) bundle
|
2005-11-23 05:43:21 +00:00
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
return _bundle;
|
2005-11-23 05:43:21 +00:00
|
|
|
}
|
|
|
|
|
2008-12-29 11:52:36 +00:00
|
|
|
- (NSColorList*) colors
|
|
|
|
{
|
2008-12-29 12:05:35 +00:00
|
|
|
if (_colors == nil)
|
|
|
|
{
|
|
|
|
NSString *colorsPath;
|
|
|
|
|
|
|
|
colorsPath = [_bundle pathForResource: @"ThemeColors" ofType: @"clr"];
|
|
|
|
if (colorsPath == nil)
|
|
|
|
{
|
|
|
|
_colors = [null retain];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_colors = [[NSColorList alloc] initWithName: @"System"
|
|
|
|
fromFile: colorsPath];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((id)_colors == (id)null)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
2008-12-29 11:52:36 +00:00
|
|
|
return _colors;
|
|
|
|
}
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
- (void) deactivate
|
2005-11-23 05:43:21 +00:00
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
NSEnumerator *enumerator;
|
|
|
|
NSImage *image;
|
|
|
|
|
2008-12-29 11:49:42 +00:00
|
|
|
/* Tell everything that we will become inactive.
|
|
|
|
*/
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
postNotificationName: GSThemeWillDeactivateNotification
|
|
|
|
object: self
|
|
|
|
userInfo: nil];
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
/*
|
|
|
|
* Remove all cached bundle images from both NSImage's name dictionary
|
2006-12-27 11:35:48 +00:00
|
|
|
* and our cache dictionary, so that we can be sure we reload afresh
|
|
|
|
* when re-activated (in case the images on disk changed ... eg by a
|
|
|
|
* theme editor modifying the theme).
|
2006-09-22 11:23:03 +00:00
|
|
|
*/
|
|
|
|
enumerator = [_images objectEnumerator];
|
|
|
|
while ((image = [enumerator nextObject]) != nil)
|
|
|
|
{
|
|
|
|
[image setName: nil];
|
|
|
|
}
|
|
|
|
[_images removeAllObjects];
|
|
|
|
|
2009-01-06 05:08:58 +00:00
|
|
|
[self _revokeOwnerships];
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
/* Tell everything that we have become inactive.
|
|
|
|
*/
|
2006-09-22 11:23:03 +00:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
2008-12-29 11:49:42 +00:00
|
|
|
postNotificationName: GSThemeDidDeactivateNotification
|
|
|
|
object: self
|
|
|
|
userInfo: nil];
|
2005-11-23 05:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
- (void) dealloc
|
2005-11-23 05:43:21 +00:00
|
|
|
{
|
2009-01-02 10:12:25 +00:00
|
|
|
if (_reserved != 0)
|
|
|
|
{
|
|
|
|
RELEASE(_bundle);
|
|
|
|
RELEASE(_colors);
|
|
|
|
RELEASE(_images);
|
2009-01-05 09:43:25 +00:00
|
|
|
RELEASE(_normalTiles);
|
|
|
|
RELEASE(_highlightedTiles);
|
|
|
|
RELEASE(_selectedTiles);
|
2009-01-02 10:12:25 +00:00
|
|
|
RELEASE(_icon);
|
2009-01-06 05:08:58 +00:00
|
|
|
[self _revokeOwnerships];
|
|
|
|
RELEASE(_owned);
|
2009-01-02 10:12:25 +00:00
|
|
|
NSZoneFree ([self zone], _reserved);
|
|
|
|
}
|
2006-09-22 11:23:03 +00:00
|
|
|
[super dealloc];
|
2005-11-23 05:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
- (NSImage*) icon
|
|
|
|
{
|
|
|
|
if (_icon == nil)
|
|
|
|
{
|
|
|
|
NSString *path;
|
|
|
|
|
|
|
|
path = [[self infoDictionary] objectForKey: @"GSThemeIcon"];
|
|
|
|
if (path != nil)
|
|
|
|
{
|
|
|
|
NSString *ext = [path pathExtension];
|
|
|
|
|
|
|
|
path = [path stringByDeletingPathExtension];
|
|
|
|
path = [_bundle pathForResource: path ofType: ext];
|
|
|
|
if (path != nil)
|
|
|
|
{
|
|
|
|
_icon = [[NSImage alloc] initWithContentsOfFile: path];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_icon == nil)
|
|
|
|
{
|
|
|
|
_icon = RETAIN([NSImage imageNamed: @"GNUstep"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _icon;
|
|
|
|
}
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
- (id) initWithBundle: (NSBundle*)bundle
|
2005-11-23 05:43:21 +00:00
|
|
|
{
|
2009-01-02 10:12:25 +00:00
|
|
|
_reserved = NSZoneCalloc ([self zone], 1, sizeof(internal));
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
ASSIGN(_bundle, bundle);
|
2006-12-27 11:35:48 +00:00
|
|
|
_images = [NSMutableDictionary new];
|
2009-01-05 09:43:25 +00:00
|
|
|
_normalTiles = [NSMutableDictionary new];
|
|
|
|
_highlightedTiles = [NSMutableDictionary new];
|
|
|
|
_selectedTiles = [NSMutableDictionary new];
|
2009-01-06 05:08:58 +00:00
|
|
|
_owned = [NSMutableSet new];
|
|
|
|
|
2009-01-02 10:12:25 +00:00
|
|
|
ASSIGN(_name,
|
|
|
|
[[[_bundle bundlePath] lastPathComponent] stringByDeletingPathExtension]);
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
return self;
|
2005-11-23 05:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
- (NSDictionary*) infoDictionary
|
|
|
|
{
|
|
|
|
return [_bundle infoDictionary];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) name
|
|
|
|
{
|
|
|
|
if (self == defaultTheme)
|
|
|
|
{
|
2009-01-02 10:12:25 +00:00
|
|
|
_name = @"GNUstep";
|
2006-10-02 05:09:48 +00:00
|
|
|
}
|
2009-01-01 08:30:19 +00:00
|
|
|
return _name;
|
|
|
|
}
|
|
|
|
|
2009-01-05 06:51:59 +00:00
|
|
|
- (NSString*) nameForElement: (id)anObject
|
|
|
|
{
|
|
|
|
NSString *name = (NSString*)NSMapGet(names, (void*)anObject);
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2009-01-01 08:30:19 +00:00
|
|
|
- (void) setName: (NSString*)aString
|
|
|
|
{
|
|
|
|
if (self != defaultTheme)
|
|
|
|
{
|
|
|
|
ASSIGNCOPY(_name, aString);
|
|
|
|
}
|
2006-10-02 05:09:48 +00:00
|
|
|
}
|
|
|
|
|
2009-01-06 05:08:58 +00:00
|
|
|
- (void) setName: (NSString*)aString
|
|
|
|
forElement: (id)anObject
|
|
|
|
temporary: (BOOL)takeOwnership
|
2009-01-05 06:51:59 +00:00
|
|
|
{
|
|
|
|
if (aString == nil)
|
|
|
|
{
|
2009-01-05 09:43:25 +00:00
|
|
|
if (anObject == nil)
|
|
|
|
{
|
|
|
|
/* Ignore this ... it's most likely a partially initialised
|
|
|
|
* control being deallocated and removing the name for a
|
|
|
|
* subsidiary item which was never allocated in the first place.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
2009-01-05 06:51:59 +00:00
|
|
|
NSMapRemove(names, (void*)anObject);
|
2009-01-06 05:08:58 +00:00
|
|
|
[_owned removeObject: anObject];
|
2009-01-05 06:51:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-05 09:43:25 +00:00
|
|
|
if (anObject == nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"[%@-%@] nil object supplied",
|
|
|
|
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
|
|
|
}
|
2009-01-05 06:51:59 +00:00
|
|
|
NSMapInsert(names, (void*)anObject, (void*)aString);
|
2009-01-06 05:08:58 +00:00
|
|
|
if (takeOwnership == YES)
|
|
|
|
{
|
|
|
|
[_owned addObject: anObject];
|
|
|
|
}
|
2009-01-05 06:51:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
- (NSWindow*) themeInspector
|
|
|
|
{
|
|
|
|
return [GSThemeInspector sharedThemeInspector];
|
|
|
|
}
|
|
|
|
|
2009-01-05 09:43:25 +00:00
|
|
|
- (GSDrawTiles*) tilesNamed: (NSString*)aName
|
|
|
|
state: (GSThemeControlState)elementState
|
|
|
|
cache: (BOOL)useCache
|
2005-11-23 05:43:21 +00:00
|
|
|
{
|
2009-01-05 09:43:25 +00:00
|
|
|
GSDrawTiles *tiles;
|
|
|
|
NSMutableDictionary *cache;
|
|
|
|
|
|
|
|
switch (elementState)
|
|
|
|
{
|
|
|
|
case GSThemeNormalState:
|
|
|
|
cache = _normalTiles;
|
|
|
|
break;
|
|
|
|
case GSThemeHighlightedState:
|
|
|
|
cache = _highlightedTiles;
|
|
|
|
break;
|
|
|
|
case GSThemeSelectedState:
|
|
|
|
cache = _selectedTiles;
|
|
|
|
break;
|
|
|
|
}
|
2006-09-22 11:23:03 +00:00
|
|
|
|
2009-01-05 09:43:25 +00:00
|
|
|
tiles = (useCache == YES) ? [cache objectForKey: aName] : nil;
|
2006-09-22 11:23:03 +00:00
|
|
|
if (tiles == nil)
|
|
|
|
{
|
2006-10-02 05:09:48 +00:00
|
|
|
NSDictionary *info;
|
|
|
|
NSImage *image;
|
2009-01-05 09:43:25 +00:00
|
|
|
NSString *fullName;
|
|
|
|
|
|
|
|
switch (elementState)
|
|
|
|
{
|
|
|
|
case GSThemeNormalState:
|
|
|
|
fullName = aName;
|
|
|
|
break;
|
|
|
|
case GSThemeHighlightedState:
|
|
|
|
fullName = [aName stringByAppendingString: @"Highlighted"];
|
|
|
|
break;
|
|
|
|
case GSThemeSelectedState:
|
|
|
|
fullName = [aName stringByAppendingString: @"Selected"];
|
|
|
|
break;
|
|
|
|
}
|
2006-10-02 05:09:48 +00:00
|
|
|
|
|
|
|
/* The GSThemeTiles entry in the info dictionary should be a
|
|
|
|
* dictionary containing information about each set of tiles.
|
|
|
|
* Keys are:
|
|
|
|
* FileName Name of the file in the ThemeTiles directory
|
|
|
|
* HorizontalDivision Where to divide the image into columns.
|
|
|
|
* VerticalDivision Where to divide the image into rows.
|
|
|
|
*/
|
|
|
|
info = [self infoDictionary];
|
2009-01-05 09:43:25 +00:00
|
|
|
info = [[info objectForKey: @"GSThemeTiles"] objectForKey: fullName];
|
2006-10-02 05:09:48 +00:00
|
|
|
if ([info isKindOfClass: [NSDictionary class]] == YES)
|
|
|
|
{
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
NSString *path;
|
|
|
|
NSString *file;
|
|
|
|
NSString *ext;
|
|
|
|
|
|
|
|
x = [[info objectForKey: @"HorizontalDivision"] floatValue];
|
|
|
|
y = [[info objectForKey: @"VerticalDivision"] floatValue];
|
|
|
|
file = [info objectForKey: @"FileName"];
|
|
|
|
ext = [file pathExtension];
|
|
|
|
file = [file stringByDeletingPathExtension];
|
|
|
|
path = [_bundle pathForResource: file
|
|
|
|
ofType: ext
|
|
|
|
inDirectory: @"ThemeTiles"];
|
|
|
|
if (path == nil)
|
|
|
|
{
|
|
|
|
NSLog(@"File %@.%@ not found in ThemeTiles", file, ext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
image = [[NSImage alloc] initWithContentsOfFile: path];
|
|
|
|
if (image != nil)
|
|
|
|
{
|
|
|
|
tiles = [[GSDrawTiles alloc] initWithImage: image
|
|
|
|
horizontal: x
|
|
|
|
vertical: y];
|
|
|
|
RELEASE(image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSArray *imageTypes;
|
|
|
|
NSString *imagePath;
|
|
|
|
unsigned count;
|
|
|
|
|
|
|
|
imageTypes = [NSImage imageFileTypes];
|
2008-12-16 19:31:50 +00:00
|
|
|
for (count = 0; count < [imageTypes count]; count++)
|
2006-10-02 05:09:48 +00:00
|
|
|
{
|
|
|
|
NSString *ext = [imageTypes objectAtIndex: count];
|
|
|
|
|
2009-01-05 09:43:25 +00:00
|
|
|
imagePath = [_bundle pathForResource: fullName
|
2006-10-02 05:09:48 +00:00
|
|
|
ofType: ext
|
|
|
|
inDirectory: @"ThemeTiles"];
|
|
|
|
if (imagePath != nil)
|
|
|
|
{
|
|
|
|
image = [[NSImage alloc] initWithContentsOfFile: imagePath];
|
|
|
|
if (image != nil)
|
|
|
|
{
|
|
|
|
tiles = [[GSDrawTiles alloc] initWithImage: image];
|
|
|
|
RELEASE(image);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-09-22 11:23:03 +00:00
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
if (tiles == nil)
|
2006-09-22 11:23:03 +00:00
|
|
|
{
|
2009-01-05 09:43:25 +00:00
|
|
|
[cache setObject: null forKey: aName];
|
2006-09-22 11:23:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-05 09:43:25 +00:00
|
|
|
[cache setObject: tiles forKey: aName];
|
2006-10-15 18:27:35 +00:00
|
|
|
RELEASE(tiles);
|
2006-09-22 11:23:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tiles == (id)null)
|
|
|
|
{
|
|
|
|
tiles = nil;
|
|
|
|
}
|
|
|
|
return tiles;
|
2005-11-23 05:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
@end
|
2006-10-02 05:09:48 +00:00
|
|
|
|
2009-01-06 05:08:58 +00:00
|
|
|
@implementation GSTheme (Private)
|
|
|
|
/* Remove all temporarily named objects from our registry, releasing them.
|
|
|
|
*/
|
|
|
|
- (void) _revokeOwnerships
|
|
|
|
{
|
|
|
|
id o;
|
|
|
|
|
|
|
|
while ((o = [_owned anyObject]) != nil)
|
|
|
|
{
|
|
|
|
[self setName: nil forElement: o temporary: YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|