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
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
2006-09-22 11:23:03 +00:00
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
Boston, MA 02111 USA.
|
2004-01-19 04:22:47 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
#include "Foundation/NSBundle.h"
|
|
|
|
|
#include "Foundation/NSDictionary.h"
|
|
|
|
|
#include "Foundation/NSFileManager.h"
|
|
|
|
|
#include "Foundation/NSNotification.h"
|
|
|
|
|
#include "Foundation/NSNull.h"
|
|
|
|
|
#include "Foundation/NSPathUtilities.h"
|
2006-10-02 16:30:52 +00:00
|
|
|
|
#include "Foundation/NSSet.h"
|
2006-09-22 11:23:03 +00:00
|
|
|
|
#include "Foundation/NSUserDefaults.h"
|
2006-09-22 11:53:40 +00:00
|
|
|
|
#include "GNUstepGUI/GSTheme.h"
|
2006-10-02 05:09:48 +00:00
|
|
|
|
#include "AppKit/NSApplication.h"
|
|
|
|
|
#include "AppKit/NSButton.h"
|
2004-01-19 04:22:47 +00:00
|
|
|
|
#include "AppKit/NSColor.h"
|
2006-09-22 11:23:03 +00:00
|
|
|
|
#include "AppKit/NSColorList.h"
|
2004-01-19 04:22:47 +00:00
|
|
|
|
#include "AppKit/NSGraphics.h"
|
2006-09-22 11:23:03 +00:00
|
|
|
|
#include "AppKit/NSImage.h"
|
2006-10-12 17:14:26 +00:00
|
|
|
|
#include "AppKit/NSImageView.h"
|
2006-10-02 05:09:48 +00:00
|
|
|
|
#include "AppKit/NSMatrix.h"
|
|
|
|
|
#include "AppKit/NSMenu.h"
|
|
|
|
|
#include "AppKit/NSPanel.h"
|
|
|
|
|
#include "AppKit/NSScrollView.h"
|
2006-10-12 17:14:26 +00:00
|
|
|
|
#include "AppKit/NSTextContainer.h"
|
2006-10-02 05:09:48 +00:00
|
|
|
|
#include "AppKit/NSTextField.h"
|
2006-10-12 17:14:26 +00:00
|
|
|
|
#include "AppKit/NSTextView.h"
|
|
|
|
|
#include "AppKit/NSScrollView.h"
|
2004-02-13 18:27:34 +00:00
|
|
|
|
#include "AppKit/NSView.h"
|
2006-10-02 05:09:48 +00:00
|
|
|
|
#include "AppKit/NSWindow.h"
|
2006-09-22 11:23:03 +00:00
|
|
|
|
#include "AppKit/NSBezierPath.h"
|
2004-01-19 04:22:47 +00:00
|
|
|
|
#include "AppKit/PSOperators.h"
|
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <float.h>
|
|
|
|
|
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSString *GSThemeDidActivateNotification
|
|
|
|
|
= @"GSThemeDidActivateNotification";
|
|
|
|
|
NSString *GSThemeDidDeactivateNotification
|
|
|
|
|
= @"GSThemeDidDeactivateNotification";
|
|
|
|
|
|
|
|
|
|
/** These are the nine types of tile used to draw a rectangular object.
|
|
|
|
|
*/
|
|
|
|
|
typedef enum {
|
|
|
|
|
TileTL = 0, /** Top left corner */
|
|
|
|
|
TileTM = 1, /** Top middle section */
|
|
|
|
|
TileTR = 2, /** Top right corner */
|
|
|
|
|
TileCL = 3, /** Centerj left corner */
|
|
|
|
|
TileCM = 4, /** Centerj middle section */
|
|
|
|
|
TileCR = 5, /** Centerj right corner */
|
|
|
|
|
TileBL = 6, /** Bottom left corner */
|
|
|
|
|
TileBM = 7, /** Bottom middle section */
|
|
|
|
|
TileBR = 8 /** Bottom right corner */
|
2006-09-22 11:53:40 +00:00
|
|
|
|
} GSThemeTileOffset;
|
2006-09-22 11:23:03 +00:00
|
|
|
|
|
|
|
|
|
/** This is a trivial class to hold the nine tiles needed to draw a rectangle
|
|
|
|
|
*/
|
|
|
|
|
@interface GSDrawTiles : NSObject
|
|
|
|
|
{
|
|
|
|
|
@public
|
|
|
|
|
NSImage *images[9]; /** The tile images */
|
|
|
|
|
NSRect rects[9]; /** The rectangles to use when drawing */
|
|
|
|
|
}
|
|
|
|
|
- (id) initWithImage: (NSImage*)image;
|
2006-10-02 05:09:48 +00:00
|
|
|
|
- (id) initWithImage: (NSImage*)image horizontal: (float)x vertical: (float)y;
|
2006-09-22 11:23:03 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
2004-01-19 04:22:47 +00:00
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
|
/** This is the panel used to select and inspect themes.
|
2006-09-22 11:23:03 +00:00
|
|
|
|
*/
|
2006-10-02 05:09:48 +00:00
|
|
|
|
@interface GSThemePanel : NSPanel
|
2006-09-22 11:23:03 +00:00
|
|
|
|
{
|
2006-10-02 05:09:48 +00:00
|
|
|
|
NSMatrix *matrix; // Not retained.
|
|
|
|
|
NSScrollView *sideView; // Not retained.
|
|
|
|
|
NSView *bottomView; // Not retained.
|
|
|
|
|
}
|
2006-09-22 11:23:03 +00:00
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
|
/** Return the shared panel.
|
|
|
|
|
*/
|
|
|
|
|
+ (GSThemePanel*) sharedThemePanel;
|
|
|
|
|
|
|
|
|
|
/** Update current theme to the one clicked on in the matrix.
|
|
|
|
|
*/
|
|
|
|
|
- (void) changeSelection: (id)sender;
|
|
|
|
|
|
|
|
|
|
/** Handle notifications
|
|
|
|
|
*/
|
|
|
|
|
- (void) notified: (NSNotification*)n;
|
|
|
|
|
|
|
|
|
|
/** Toggle whether the current theme is the default theme.
|
|
|
|
|
*/
|
|
|
|
|
- (void) setDefault: (id)sender;
|
|
|
|
|
|
|
|
|
|
/** Update list of available themes.
|
|
|
|
|
*/
|
|
|
|
|
- (void) update: (id)sender;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** This is the window used to inspect themes.
|
|
|
|
|
*/
|
|
|
|
|
@interface GSThemeInspector : NSWindow
|
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
}
|
2006-10-02 05:09:48 +00:00
|
|
|
|
|
|
|
|
|
/** Return the shared panel.
|
|
|
|
|
*/
|
|
|
|
|
+ (GSThemeInspector*) sharedThemeInspector;
|
|
|
|
|
|
|
|
|
|
/** Update to show current theme.
|
|
|
|
|
*/
|
|
|
|
|
- (void) update: (id)sender;
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
@end
|
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** This category defines private methods for internal use by GSTheme
|
|
|
|
|
*/
|
2006-09-22 11:53:40 +00:00
|
|
|
|
@interface GSTheme (internal)
|
2006-09-22 11:23:03 +00:00
|
|
|
|
/**
|
|
|
|
|
* Called whenever user defaults are changed ... this checks for the
|
|
|
|
|
* GSTheme user default and ensures that the specified theme is the
|
|
|
|
|
* current active theme.
|
|
|
|
|
*/
|
|
|
|
|
+ (void) defaultsDidChange: (NSNotification*)n;
|
|
|
|
|
|
|
|
|
|
/**
|
2006-10-02 05:09:48 +00:00
|
|
|
|
* Called to load specified theme.<br />
|
|
|
|
|
* If aName is nil or an empty string or 'GNUstep',
|
|
|
|
|
* this returns the default theme.<br />
|
|
|
|
|
* If the named is a full path specification, this uses that path.<br />
|
|
|
|
|
* Otherwise this method searches the standard locations.<br />
|
|
|
|
|
* Returns nil on failure.
|
2006-09-22 11:23:03 +00:00
|
|
|
|
*/
|
2006-10-02 05:09:48 +00:00
|
|
|
|
+ (GSTheme*) loadThemeNamed: (NSString*)aName;
|
2006-09-22 11:23:03 +00:00
|
|
|
|
@end
|
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
|
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;
|
2005-11-23 05:43:21 +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];
|
|
|
|
|
}
|
|
|
|
|
if (null == nil)
|
|
|
|
|
{
|
|
|
|
|
null = RETAIN([NSNull null]);
|
|
|
|
|
}
|
|
|
|
|
if (defaultTheme == nil)
|
|
|
|
|
{
|
|
|
|
|
NSBundle *aBundle = [NSBundle bundleForClass: self];
|
|
|
|
|
|
|
|
|
|
defaultTheme = [[self alloc] initWithBundle: aBundle];
|
|
|
|
|
ASSIGN(theTheme, defaultTheme);
|
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;
|
|
|
|
|
NSMutableDictionary *userInfo;
|
|
|
|
|
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;
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSString *colorsPath;
|
2006-10-02 05:09:48 +00:00
|
|
|
|
NSDictionary *infoDict;
|
|
|
|
|
NSWindow *window;
|
2006-09-22 11:23:03 +00:00
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
|
userInfo = [NSMutableDictionary dictionary];
|
2006-09-22 11:23:03 +00:00
|
|
|
|
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
|
|
|
|
|
* [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;
|
|
|
|
|
|
|
|
|
|
image = [[NSImage alloc] initWithContentsOfFile: imagePath];
|
|
|
|
|
if (image != nil)
|
|
|
|
|
{
|
|
|
|
|
NSString *imageName;
|
|
|
|
|
|
|
|
|
|
imageName = [imagePath lastPathComponent];
|
|
|
|
|
imageName = [imageName stringByDeletingPathExtension];
|
|
|
|
|
[_images addObject: image];
|
|
|
|
|
[image setName: imageName];
|
|
|
|
|
RELEASE(image);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2006-10-15 08:34:47 +00:00
|
|
|
|
* We could cache tile info here, but it's probably better for the
|
|
|
|
|
* tilesNamed: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
|
|
|
|
|
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]
|
|
|
|
|
postNotificationName: GSThemeDidActivateNotification
|
|
|
|
|
object: self
|
|
|
|
|
userInfo: userInfo];
|
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
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Remove all cached bundle images from both NSImage's name dictionary
|
|
|
|
|
* and our cache array.
|
|
|
|
|
*/
|
|
|
|
|
enumerator = [_images objectEnumerator];
|
|
|
|
|
while ((image = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
[image setName: nil];
|
|
|
|
|
}
|
|
|
|
|
[_images removeAllObjects];
|
|
|
|
|
|
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]
|
|
|
|
|
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
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
RELEASE(_bundle);
|
|
|
|
|
RELEASE(_images);
|
|
|
|
|
RELEASE(_tiles);
|
2006-10-02 05:09:48 +00:00
|
|
|
|
RELEASE(_icon);
|
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
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
ASSIGN(_bundle, bundle);
|
|
|
|
|
_images = [NSMutableArray new];
|
|
|
|
|
_tiles = [NSMutableDictionary new];
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
return @"GNUstep";
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
[[[_bundle bundlePath] lastPathComponent] stringByDeletingPathExtension];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSWindow*) themeInspector
|
|
|
|
|
{
|
|
|
|
|
return [GSThemeInspector sharedThemeInspector];
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-15 08:34:47 +00:00
|
|
|
|
- (GSDrawTiles*) tilesNamed: (NSString*)aName cache: (BOOL)useCache
|
2005-11-23 05:43:21 +00:00
|
|
|
|
{
|
2006-10-15 08:34:47 +00:00
|
|
|
|
GSDrawTiles *tiles;
|
2006-09-22 11:23:03 +00:00
|
|
|
|
|
2006-10-15 08:34:47 +00:00
|
|
|
|
tiles = (useCache == YES) ? [_tiles 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;
|
|
|
|
|
|
|
|
|
|
/* 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];
|
|
|
|
|
info = [[info objectForKey: @"GSThemeTiles"] objectForKey: aName];
|
|
|
|
|
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];
|
|
|
|
|
for (count = 0; image == nil && count < [imageTypes count]; count++)
|
|
|
|
|
{
|
|
|
|
|
NSString *ext = [imageTypes objectAtIndex: count];
|
|
|
|
|
|
|
|
|
|
imagePath = [_bundle pathForResource: aName
|
|
|
|
|
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
|
|
|
|
{
|
2006-10-02 05:09:48 +00:00
|
|
|
|
[_tiles setObject: null forKey: aName];
|
2006-09-22 11:23:03 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-10-02 05:09:48 +00:00
|
|
|
|
[_tiles 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-09-22 11:53:40 +00:00
|
|
|
|
@implementation GSTheme (Drawing)
|
2006-09-22 11:23:03 +00:00
|
|
|
|
|
|
|
|
|
- (NSRect) drawButton: (NSRect) frame
|
|
|
|
|
in: (NSButtonCell*) cell
|
|
|
|
|
view: (NSView*) view
|
|
|
|
|
style: (int) style
|
|
|
|
|
state: (int) state
|
2005-11-23 05:43:21 +00:00
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
/* computes the interior frame rect */
|
|
|
|
|
|
|
|
|
|
NSRect interiorFrame = [cell drawingRectForBounds: frame];
|
|
|
|
|
|
|
|
|
|
/* Draw the button background */
|
|
|
|
|
|
|
|
|
|
if (state == 0) /* default state, unpressed */
|
|
|
|
|
{
|
|
|
|
|
[[NSColor controlBackgroundColor] set];
|
|
|
|
|
NSRectFill(frame);
|
2006-09-22 11:53:40 +00:00
|
|
|
|
[self drawButton: frame withClip: NSZeroRect];
|
2006-09-22 11:23:03 +00:00
|
|
|
|
}
|
|
|
|
|
else if (state == 1) /* highlighted state */
|
|
|
|
|
{
|
|
|
|
|
[[NSColor selectedControlColor] set];
|
|
|
|
|
NSRectFill(frame);
|
2006-09-22 11:53:40 +00:00
|
|
|
|
[self drawGrayBezel: frame withClip: NSZeroRect];
|
2006-09-22 11:23:03 +00:00
|
|
|
|
}
|
|
|
|
|
else if (state == 2) /* pushed state */
|
|
|
|
|
{
|
|
|
|
|
[[NSColor selectedControlColor] set];
|
|
|
|
|
NSRectFill(frame);
|
2006-09-22 11:53:40 +00:00
|
|
|
|
[self drawGrayBezel: frame withClip: NSZeroRect];
|
2006-09-22 11:23:03 +00:00
|
|
|
|
interiorFrame
|
|
|
|
|
= NSOffsetRect(interiorFrame, 1.0, [view isFlipped] ? 1.0 : -1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* returns the interior frame rect */
|
|
|
|
|
|
|
|
|
|
return interiorFrame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) drawFocusFrame: (NSRect) frame view: (NSView*) view
|
|
|
|
|
{
|
|
|
|
|
NSDottedFrameRect(frame);
|
2005-11-23 05:43:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
- (void) drawWindowBackground: (NSRect) frame view: (NSView*) view
|
|
|
|
|
{
|
|
|
|
|
NSColor *c;
|
2005-11-23 05:43:21 +00:00
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
c = [[view window] backgroundColor];
|
|
|
|
|
[c set];
|
|
|
|
|
NSRectFill (frame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-22 11:53:40 +00:00
|
|
|
|
@implementation GSTheme (MidLevelDrawing)
|
2006-09-22 11:23:03 +00:00
|
|
|
|
|
|
|
|
|
- (NSRect) drawButton: (NSRect)border withClip: (NSRect)clip
|
2004-01-19 04:22:47 +00:00
|
|
|
|
{
|
|
|
|
|
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge,
|
|
|
|
|
NSMinXEdge, NSMaxYEdge,
|
|
|
|
|
NSMaxXEdge, NSMinYEdge};
|
|
|
|
|
NSRectEdge dn_sides[] = {NSMaxXEdge, NSMaxYEdge,
|
2004-02-08 20:33:07 +00:00
|
|
|
|
NSMinXEdge, NSMinYEdge,
|
|
|
|
|
NSMaxXEdge, NSMaxYEdge};
|
|
|
|
|
// These names are role names not the actual colours
|
|
|
|
|
NSColor *black = [NSColor controlDarkShadowColor];
|
|
|
|
|
NSColor *dark = [NSColor controlShadowColor];
|
|
|
|
|
NSColor *white = [NSColor controlLightHighlightColor];
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSColor *colors[] = {black, black, white, white, dark, dark};
|
2004-02-08 20:33:07 +00:00
|
|
|
|
|
2004-01-19 04:22:47 +00:00
|
|
|
|
if ([[NSView focusView] isFlipped] == YES)
|
|
|
|
|
{
|
2004-05-31 19:24:10 +00:00
|
|
|
|
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 6);
|
2004-01-19 04:22:47 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-05-31 19:24:10 +00:00
|
|
|
|
return NSDrawColorTiledRects(border, clip, up_sides, colors, 6);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
- (NSRect) drawDarkBezel: (NSRect)border withClip: (NSRect)clip
|
2004-01-19 04:22:47 +00:00
|
|
|
|
{
|
|
|
|
|
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge,
|
|
|
|
|
NSMinXEdge, NSMaxYEdge, NSMaxXEdge, NSMinYEdge};
|
|
|
|
|
NSRectEdge dn_sides[] = {NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge,
|
|
|
|
|
NSMinXEdge, NSMinYEdge, NSMaxXEdge, NSMaxYEdge};
|
2004-02-08 20:33:07 +00:00
|
|
|
|
// These names are role names not the actual colours
|
|
|
|
|
NSColor *black = [NSColor controlDarkShadowColor];
|
|
|
|
|
NSColor *dark = [NSColor controlShadowColor];
|
|
|
|
|
NSColor *light = [NSColor controlColor];
|
|
|
|
|
NSColor *white = [NSColor controlLightHighlightColor];
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSColor *colors[] = {white, white, dark, dark, black, black, light, light};
|
2004-05-31 19:24:10 +00:00
|
|
|
|
NSRect rect;
|
|
|
|
|
|
2004-01-19 04:22:47 +00:00
|
|
|
|
if ([[NSView focusView] isFlipped] == YES)
|
|
|
|
|
{
|
2004-05-31 19:24:10 +00:00
|
|
|
|
rect = NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
|
2004-01-19 04:22:47 +00:00
|
|
|
|
|
2004-02-08 20:33:07 +00:00
|
|
|
|
[dark set];
|
2004-01-19 04:22:47 +00:00
|
|
|
|
PSrectfill(NSMinX(border) + 1., NSMinY(border) - 2., 1., 1.);
|
|
|
|
|
PSrectfill(NSMaxX(border) - 2., NSMaxY(border) + 1., 1., 1.);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-05-31 19:24:10 +00:00
|
|
|
|
rect = NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
|
2004-01-19 04:22:47 +00:00
|
|
|
|
|
2004-02-08 20:33:07 +00:00
|
|
|
|
[dark set];
|
2004-01-19 04:22:47 +00:00
|
|
|
|
PSrectfill(NSMinX(border) + 1., NSMinY(border) + 1., 1., 1.);
|
|
|
|
|
PSrectfill(NSMaxX(border) - 2., NSMaxY(border) - 2., 1., 1.);
|
|
|
|
|
}
|
2004-05-31 19:24:10 +00:00
|
|
|
|
return rect;
|
2004-01-19 04:22:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
- (NSRect) drawDarkButton: (NSRect)border withClip: (NSRect)clip
|
2004-01-19 04:22:47 +00:00
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge,
|
|
|
|
|
NSMinXEdge, NSMaxYEdge};
|
|
|
|
|
NSRectEdge dn_sides[] = {NSMaxXEdge, NSMaxYEdge,
|
|
|
|
|
NSMinXEdge, NSMinYEdge};
|
2004-02-08 20:33:07 +00:00
|
|
|
|
// These names are role names not the actual colours
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSColor *black = [NSColor controlDarkShadowColor];
|
|
|
|
|
NSColor *white = [NSColor controlHighlightColor];
|
|
|
|
|
NSColor *colors[] = {black, black, white, white};
|
2004-02-08 20:33:07 +00:00
|
|
|
|
|
|
|
|
|
if ([[NSView focusView] isFlipped] == YES)
|
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 4);
|
2004-02-08 20:33:07 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
return NSDrawColorTiledRects(border, clip, up_sides, colors, 4);
|
2004-02-08 20:33:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
- (NSRect) drawFramePhoto: (NSRect)border withClip: (NSRect)clip
|
2004-02-08 20:33:07 +00:00
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge,
|
|
|
|
|
NSMinXEdge, NSMaxYEdge,
|
|
|
|
|
NSMaxXEdge, NSMinYEdge};
|
|
|
|
|
NSRectEdge dn_sides[] = {NSMaxXEdge, NSMaxYEdge,
|
|
|
|
|
NSMinXEdge, NSMinYEdge,
|
|
|
|
|
NSMaxXEdge, NSMaxYEdge};
|
2004-02-08 20:33:07 +00:00
|
|
|
|
// These names are role names not the actual colours
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSColor *black = [NSColor controlDarkShadowColor];
|
|
|
|
|
NSColor *dark = [NSColor controlShadowColor];
|
|
|
|
|
NSColor *colors[] = {dark, dark, dark, dark,
|
|
|
|
|
black,black};
|
|
|
|
|
|
|
|
|
|
if ([[NSView focusView] isFlipped] == YES)
|
|
|
|
|
{
|
|
|
|
|
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 6);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NSDrawColorTiledRects(border, clip, up_sides, colors, 6);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSRect) drawGradientBorder: (NSGradientType)gradientType
|
|
|
|
|
inRect: (NSRect)border
|
|
|
|
|
withClip: (NSRect)clip
|
|
|
|
|
{
|
|
|
|
|
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge,
|
|
|
|
|
NSMinXEdge, NSMaxYEdge};
|
|
|
|
|
NSRectEdge dn_sides[] = {NSMaxXEdge, NSMaxYEdge,
|
|
|
|
|
NSMinXEdge, NSMinYEdge};
|
|
|
|
|
NSColor *black = [NSColor controlDarkShadowColor];
|
2004-02-08 20:33:07 +00:00
|
|
|
|
NSColor *dark = [NSColor controlShadowColor];
|
|
|
|
|
NSColor *light = [NSColor controlColor];
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSColor **colors;
|
|
|
|
|
NSColor *concaveWeak[] = {dark, dark, light, light};
|
|
|
|
|
NSColor *concaveStrong[] = {black, black, light, light};
|
|
|
|
|
NSColor *convexWeak[] = {light, light, dark, dark};
|
|
|
|
|
NSColor *convexStrong[] = {light, light, black, black};
|
|
|
|
|
NSRect rect;
|
|
|
|
|
|
|
|
|
|
switch (gradientType)
|
|
|
|
|
{
|
|
|
|
|
case NSGradientConcaveWeak:
|
|
|
|
|
colors = concaveWeak;
|
|
|
|
|
break;
|
|
|
|
|
case NSGradientConcaveStrong:
|
|
|
|
|
colors = concaveStrong;
|
|
|
|
|
break;
|
|
|
|
|
case NSGradientConvexWeak:
|
|
|
|
|
colors = convexWeak;
|
|
|
|
|
break;
|
|
|
|
|
case NSGradientConvexStrong:
|
|
|
|
|
colors = convexStrong;
|
|
|
|
|
break;
|
|
|
|
|
case NSGradientNone:
|
|
|
|
|
default:
|
|
|
|
|
return border;
|
|
|
|
|
}
|
2004-01-19 04:22:47 +00:00
|
|
|
|
|
|
|
|
|
if ([[NSView focusView] isFlipped] == YES)
|
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
rect = NSDrawColorTiledRects(border, clip, dn_sides, colors, 4);
|
2004-01-19 04:22:47 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
rect = NSDrawColorTiledRects(border, clip, up_sides, colors, 4);
|
2004-01-19 04:22:47 +00:00
|
|
|
|
}
|
2006-09-22 11:23:03 +00:00
|
|
|
|
|
|
|
|
|
return rect;
|
2004-01-19 04:22:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
- (NSRect) drawGrayBezel: (NSRect)border withClip: (NSRect)clip
|
2004-02-08 20:33:07 +00:00
|
|
|
|
{
|
|
|
|
|
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge,
|
|
|
|
|
NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge};
|
|
|
|
|
NSRectEdge dn_sides[] = {NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge,
|
|
|
|
|
NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge};
|
|
|
|
|
// These names are role names not the actual colours
|
|
|
|
|
NSColor *black = [NSColor controlDarkShadowColor];
|
|
|
|
|
NSColor *dark = [NSColor controlShadowColor];
|
|
|
|
|
NSColor *light = [NSColor controlColor];
|
|
|
|
|
NSColor *white = [NSColor controlLightHighlightColor];
|
|
|
|
|
NSColor *colors[] = {white, white, dark, dark,
|
|
|
|
|
light, light, black, black};
|
2004-05-31 19:24:10 +00:00
|
|
|
|
NSRect rect;
|
2004-02-08 20:33:07 +00:00
|
|
|
|
|
|
|
|
|
if ([[NSView focusView] isFlipped] == YES)
|
|
|
|
|
{
|
2004-05-31 19:24:10 +00:00
|
|
|
|
rect = NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
|
2004-02-08 20:33:07 +00:00
|
|
|
|
[dark set];
|
|
|
|
|
PSrectfill(NSMinX(border) + 1., NSMaxY(border) - 2., 1., 1.);
|
|
|
|
|
PSrectfill(NSMaxX(border) - 2., NSMinY(border) + 1., 1., 1.);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-05-31 19:24:10 +00:00
|
|
|
|
rect = NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
|
2004-02-08 20:33:07 +00:00
|
|
|
|
[dark set];
|
|
|
|
|
PSrectfill(NSMinX(border) + 1., NSMinY(border) + 1., 1., 1.);
|
|
|
|
|
PSrectfill(NSMaxX(border) - 2., NSMaxY(border) - 2., 1., 1.);
|
|
|
|
|
}
|
2004-05-31 19:24:10 +00:00
|
|
|
|
return rect;
|
2004-02-08 20:33:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
- (NSRect) drawGroove: (NSRect)border withClip: (NSRect)clip
|
2004-01-19 04:22:47 +00:00
|
|
|
|
{
|
|
|
|
|
// go clockwise from the top twice -- makes the groove come out right
|
|
|
|
|
NSRectEdge up_sides[] = {NSMaxYEdge, NSMaxXEdge, NSMinYEdge, NSMinXEdge,
|
|
|
|
|
NSMaxYEdge, NSMaxXEdge, NSMinYEdge, NSMinXEdge};
|
|
|
|
|
NSRectEdge dn_sides[] = {NSMinYEdge, NSMaxXEdge, NSMaxYEdge, NSMinXEdge,
|
|
|
|
|
NSMinYEdge, NSMaxXEdge, NSMaxYEdge, NSMinXEdge};
|
2004-02-08 20:33:07 +00:00
|
|
|
|
// These names are role names not the actual colours
|
|
|
|
|
NSColor *dark = [NSColor controlShadowColor];
|
|
|
|
|
NSColor *white = [NSColor controlLightHighlightColor];
|
|
|
|
|
NSColor *colors[] = {dark, white, white, dark,
|
|
|
|
|
white, dark, dark, white};
|
2004-01-19 04:22:47 +00:00
|
|
|
|
|
|
|
|
|
if ([[NSView focusView] isFlipped] == YES)
|
|
|
|
|
{
|
2004-05-31 19:24:10 +00:00
|
|
|
|
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
|
2004-01-19 04:22:47 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-05-31 19:24:10 +00:00
|
|
|
|
return NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
|
2004-01-19 04:22:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
- (NSRect) drawLightBezel: (NSRect)border withClip: (NSRect)clip
|
2004-01-19 04:22:47 +00:00
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge,
|
|
|
|
|
NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge};
|
|
|
|
|
NSRectEdge dn_sides[] = {NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge,
|
|
|
|
|
NSMaxXEdge, NSMaxYEdge, NSMinXEdge, NSMinYEdge};
|
2004-02-08 20:33:07 +00:00
|
|
|
|
// These names are role names not the actual colours
|
|
|
|
|
NSColor *dark = [NSColor controlShadowColor];
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSColor *light = [NSColor controlColor];
|
|
|
|
|
NSColor *white = [NSColor controlLightHighlightColor];
|
|
|
|
|
NSColor *colors[] = {white, white, dark, dark,
|
|
|
|
|
light, light, dark, dark};
|
2004-01-19 04:22:47 +00:00
|
|
|
|
|
|
|
|
|
if ([[NSView focusView] isFlipped] == YES)
|
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
|
2004-01-19 04:22:47 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
return NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
|
2004-01-19 04:22:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
- (NSRect) drawWhiteBezel: (NSRect)border withClip: (NSRect)clip
|
2004-02-13 18:27:34 +00:00
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSRectEdge up_sides[] = {NSMaxYEdge, NSMaxXEdge, NSMinYEdge, NSMinXEdge,
|
|
|
|
|
NSMaxYEdge, NSMaxXEdge, NSMinYEdge, NSMinXEdge};
|
|
|
|
|
NSRectEdge dn_sides[] = {NSMinYEdge, NSMaxXEdge, NSMaxYEdge, NSMinXEdge,
|
|
|
|
|
NSMinYEdge, NSMaxXEdge, NSMaxYEdge, NSMinXEdge};
|
|
|
|
|
// These names are role names not the actual colours
|
2004-02-13 18:27:34 +00:00
|
|
|
|
NSColor *dark = [NSColor controlShadowColor];
|
|
|
|
|
NSColor *light = [NSColor controlColor];
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSColor *white = [NSColor controlLightHighlightColor];
|
|
|
|
|
NSColor *colors[] = {dark, white, white, dark,
|
|
|
|
|
dark, light, light, dark};
|
|
|
|
|
|
|
|
|
|
if ([[NSView focusView] isFlipped] == YES)
|
|
|
|
|
{
|
|
|
|
|
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-22 11:53:40 +00:00
|
|
|
|
@implementation GSTheme (LowLevelDrawing)
|
2006-09-22 11:23:03 +00:00
|
|
|
|
|
|
|
|
|
- (void) fillHorizontalRect: (NSRect)rect
|
|
|
|
|
withImage: (NSImage*)image
|
|
|
|
|
fromRect: (NSRect)source
|
|
|
|
|
flipped: (BOOL)flipped
|
|
|
|
|
{
|
|
|
|
|
NSGraphicsContext *ctxt = GSCurrentContext();
|
|
|
|
|
NSBezierPath *path;
|
|
|
|
|
unsigned repetitions;
|
|
|
|
|
unsigned count;
|
|
|
|
|
float y;
|
|
|
|
|
|
|
|
|
|
DPSgsave (ctxt);
|
|
|
|
|
path = [NSBezierPath bezierPathWithRect: rect];
|
|
|
|
|
[path addClip];
|
|
|
|
|
repetitions = (rect.size.width / source.size.width) + 1;
|
|
|
|
|
y = rect.origin.y;
|
|
|
|
|
|
|
|
|
|
if (flipped) y = rect.origin.y + rect.size.height;
|
2004-02-13 18:27:34 +00:00
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
for (count = 0; count < repetitions; count++)
|
2004-02-13 18:27:34 +00:00
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
NSPoint p = NSMakePoint (rect.origin.x + count * source.size.width, y);
|
|
|
|
|
|
|
|
|
|
[image compositeToPoint: p
|
|
|
|
|
fromRect: source
|
|
|
|
|
operation: NSCompositeSourceOver];
|
2004-02-13 18:27:34 +00:00
|
|
|
|
}
|
2006-09-22 11:23:03 +00:00
|
|
|
|
DPSgrestore (ctxt);
|
|
|
|
|
}
|
2004-02-13 18:27:34 +00:00
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
- (void) fillRect: (NSRect)rect
|
|
|
|
|
withRepeatedImage: (NSImage*)image
|
|
|
|
|
fromRect: (NSRect)source
|
|
|
|
|
center: (BOOL)center
|
|
|
|
|
{
|
|
|
|
|
NSGraphicsContext *ctxt = GSCurrentContext ();
|
|
|
|
|
NSBezierPath *path;
|
|
|
|
|
NSSize size;
|
|
|
|
|
unsigned xrepetitions;
|
|
|
|
|
unsigned yrepetitions;
|
|
|
|
|
unsigned x;
|
|
|
|
|
unsigned y;
|
|
|
|
|
|
|
|
|
|
DPSgsave (ctxt);
|
|
|
|
|
path = [NSBezierPath bezierPathWithRect: rect];
|
|
|
|
|
[path addClip];
|
|
|
|
|
size = [image size];
|
|
|
|
|
xrepetitions = (rect.size.width / size.width) + 1;
|
|
|
|
|
yrepetitions = (rect.size.height / size.height) + 1;
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < xrepetitions; x++)
|
2004-02-13 18:27:34 +00:00
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
for (y = 0; y < yrepetitions; y++)
|
|
|
|
|
{
|
|
|
|
|
NSPoint p;
|
|
|
|
|
|
|
|
|
|
p = NSMakePoint (rect.origin.x + x * size.width,
|
|
|
|
|
rect.origin.y + y * size.height);
|
|
|
|
|
[image compositeToPoint: p
|
|
|
|
|
fromRect: source
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DPSgrestore (ctxt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) fillRect: (NSRect)rect
|
|
|
|
|
withTiles: (GSDrawTiles*)tiles
|
|
|
|
|
background: (NSColor*)color
|
2006-09-22 11:53:40 +00:00
|
|
|
|
fillStyle: (GSThemeFillStyle)style
|
2006-09-22 11:23:03 +00:00
|
|
|
|
{
|
|
|
|
|
NSGraphicsContext *ctxt = GSCurrentContext();
|
|
|
|
|
NSSize tls = tiles->rects[TileTL].size;
|
|
|
|
|
NSSize tms = tiles->rects[TileTM].size;
|
|
|
|
|
NSSize trs = tiles->rects[TileTR].size;
|
|
|
|
|
NSSize cls = tiles->rects[TileCL].size;
|
|
|
|
|
NSSize crs = tiles->rects[TileCR].size;
|
|
|
|
|
NSSize bls = tiles->rects[TileBL].size;
|
|
|
|
|
NSSize bms = tiles->rects[TileBM].size;
|
|
|
|
|
NSSize brs = tiles->rects[TileBR].size;
|
|
|
|
|
NSRect inFill;
|
|
|
|
|
BOOL flipped = [[ctxt focusView] isFlipped];
|
|
|
|
|
|
|
|
|
|
if (color == nil)
|
|
|
|
|
{
|
|
|
|
|
[[NSColor redColor] set];
|
2004-02-13 18:27:34 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
[color set];
|
|
|
|
|
}
|
|
|
|
|
NSRectFill(rect);
|
|
|
|
|
|
2006-10-15 08:34:47 +00:00
|
|
|
|
if (style == GSThemeFillStyleMatrix)
|
|
|
|
|
{
|
|
|
|
|
NSRect grid;
|
|
|
|
|
float x;
|
|
|
|
|
float y;
|
|
|
|
|
|
|
|
|
|
if (tiles->images[TileTM] == nil)
|
|
|
|
|
{
|
|
|
|
|
grid.size.width = (tiles->rects[TileTL].size.width
|
|
|
|
|
+ tiles->rects[TileTR].size.width
|
|
|
|
|
+ 9);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
grid.size.width = (tiles->rects[TileTL].size.width
|
|
|
|
|
+ tiles->rects[TileTM].size.width
|
|
|
|
|
+ tiles->rects[TileTR].size.width
|
|
|
|
|
+ 12);
|
|
|
|
|
}
|
|
|
|
|
grid.origin.x = rect.origin.x + (rect.size.width - grid.size.width) / 2;
|
|
|
|
|
x = grid.origin.x;
|
|
|
|
|
if (flipped)
|
|
|
|
|
{
|
|
|
|
|
grid.origin.y
|
|
|
|
|
= NSMaxY(rect) - (rect.size.height - grid.size.height) / 2;
|
|
|
|
|
y = NSMaxY(grid);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
grid.origin.y
|
|
|
|
|
= rect.origin.y + (rect.size.height - grid.size.height) / 2;
|
|
|
|
|
y = grid.origin.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Draw bottom row
|
|
|
|
|
*/
|
|
|
|
|
if (flipped)
|
|
|
|
|
{
|
|
|
|
|
y -= (tiles->rects[TileBL].size.height + 3);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
y += 3;
|
|
|
|
|
}
|
2006-10-15 18:27:35 +00:00
|
|
|
|
[tiles->images[TileBL] compositeToPoint: NSMakePoint(x, y)
|
|
|
|
|
fromRect: tiles->rects[TileBL]
|
2006-10-15 08:34:47 +00:00
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
x += tiles->rects[TileBL].size.width + 3;
|
|
|
|
|
if (tiles->images[TileBM] != nil)
|
|
|
|
|
{
|
2006-10-15 18:27:35 +00:00
|
|
|
|
[tiles->images[TileBM] compositeToPoint: NSMakePoint(x, y)
|
|
|
|
|
fromRect: tiles->rects[TileBM]
|
2006-10-15 08:34:47 +00:00
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
x += tiles->rects[TileBM].size.width + 3;
|
|
|
|
|
}
|
2006-10-15 18:27:35 +00:00
|
|
|
|
[tiles->images[TileBR] compositeToPoint: NSMakePoint(x, y)
|
|
|
|
|
fromRect: tiles->rects[TileBR]
|
2006-10-15 08:34:47 +00:00
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
if (!flipped)
|
|
|
|
|
{
|
|
|
|
|
y += tiles->rects[TileBL].size.height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tiles->images[TileCL] != nil)
|
|
|
|
|
{
|
|
|
|
|
/* Draw middle row
|
|
|
|
|
*/
|
|
|
|
|
x = grid.origin.x;
|
|
|
|
|
if (flipped)
|
|
|
|
|
{
|
|
|
|
|
y -= (tiles->rects[TileCL].size.height + 3);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
y += 3;
|
|
|
|
|
}
|
2006-10-15 18:27:35 +00:00
|
|
|
|
[tiles->images[TileCL] compositeToPoint: NSMakePoint(x, y)
|
|
|
|
|
fromRect: tiles->rects[TileCL]
|
2006-10-15 08:34:47 +00:00
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
x += tiles->rects[TileCL].size.width + 3;
|
|
|
|
|
if (tiles->images[TileCM] != nil)
|
|
|
|
|
{
|
2006-10-15 18:27:35 +00:00
|
|
|
|
[tiles->images[TileCM] compositeToPoint: NSMakePoint(x, y)
|
|
|
|
|
fromRect: tiles->rects[TileCM]
|
2006-10-15 08:34:47 +00:00
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
x += tiles->rects[TileCM].size.width + 3;
|
|
|
|
|
}
|
2006-10-15 18:27:35 +00:00
|
|
|
|
[tiles->images[TileCR] compositeToPoint: NSMakePoint(x, y)
|
|
|
|
|
fromRect: tiles->rects[TileCR]
|
2006-10-15 08:34:47 +00:00
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
if (!flipped)
|
|
|
|
|
{
|
|
|
|
|
y += tiles->rects[TileCL].size.height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Draw top row
|
|
|
|
|
*/
|
|
|
|
|
x = grid.origin.x;
|
|
|
|
|
if (flipped)
|
|
|
|
|
{
|
|
|
|
|
y -= (tiles->rects[TileTL].size.height + 3);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
y += 3;
|
|
|
|
|
}
|
2006-10-15 18:27:35 +00:00
|
|
|
|
[tiles->images[TileTL] compositeToPoint: NSMakePoint(x, y)
|
|
|
|
|
fromRect: tiles->rects[TileTL]
|
2006-10-15 08:34:47 +00:00
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
x += tiles->rects[TileTL].size.width + 3;
|
|
|
|
|
if (tiles->images[TileTM] != nil)
|
|
|
|
|
{
|
2006-10-15 18:27:35 +00:00
|
|
|
|
[tiles->images[TileTM] compositeToPoint: NSMakePoint(x, y)
|
|
|
|
|
fromRect: tiles->rects[TileTM]
|
2006-10-15 08:34:47 +00:00
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
x += tiles->rects[TileTM].size.width + 3;
|
|
|
|
|
}
|
2006-10-15 18:27:35 +00:00
|
|
|
|
[tiles->images[TileTR] compositeToPoint: NSMakePoint(x, y)
|
|
|
|
|
fromRect: tiles->rects[TileTR]
|
2006-10-15 08:34:47 +00:00
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
}
|
|
|
|
|
else if (flipped)
|
2006-09-22 11:23:03 +00:00
|
|
|
|
{
|
|
|
|
|
[self fillHorizontalRect:
|
|
|
|
|
NSMakeRect (rect.origin.x + bls.width,
|
|
|
|
|
rect.origin.y + rect.size.height - bms.height,
|
|
|
|
|
rect.size.width - bls.width - brs.width,
|
|
|
|
|
bms.height)
|
|
|
|
|
withImage: tiles->images[TileBM]
|
|
|
|
|
fromRect: tiles->rects[TileBM]
|
|
|
|
|
flipped: YES];
|
|
|
|
|
[self fillHorizontalRect:
|
|
|
|
|
NSMakeRect (rect.origin.x + tls.width,
|
|
|
|
|
rect.origin.y,
|
|
|
|
|
rect.size.width - tls.width - trs.width,
|
|
|
|
|
tms.height)
|
|
|
|
|
withImage: tiles->images[TileTM]
|
|
|
|
|
fromRect: tiles->rects[TileTM]
|
|
|
|
|
flipped: YES];
|
|
|
|
|
[self fillVerticalRect:
|
|
|
|
|
NSMakeRect (rect.origin.x,
|
|
|
|
|
rect.origin.y + bls.height,
|
|
|
|
|
cls.width,
|
|
|
|
|
rect.size.height - bls.height - tls.height)
|
|
|
|
|
withImage: tiles->images[TileCL]
|
|
|
|
|
fromRect: tiles->rects[TileCL]
|
|
|
|
|
flipped: NO];
|
|
|
|
|
[self fillVerticalRect:
|
|
|
|
|
NSMakeRect (rect.origin.x + rect.size.width - crs.width,
|
|
|
|
|
rect.origin.y + brs.height,
|
|
|
|
|
crs.width,
|
|
|
|
|
rect.size.height - brs.height - trs.height)
|
|
|
|
|
withImage: tiles->images[TileCR]
|
|
|
|
|
fromRect: tiles->rects[TileCR]
|
|
|
|
|
flipped: NO];
|
|
|
|
|
|
|
|
|
|
[tiles->images[TileTL] compositeToPoint:
|
|
|
|
|
NSMakePoint (rect.origin.x,
|
|
|
|
|
rect.origin.y)
|
|
|
|
|
fromRect: tiles->rects[TileTL]
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
[tiles->images[TileTR] compositeToPoint:
|
|
|
|
|
NSMakePoint (rect.origin.x + rect.size.width - tls.width,
|
|
|
|
|
rect.origin.y)
|
|
|
|
|
fromRect: tiles->rects[TileTR]
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
[tiles->images[TileBL] compositeToPoint:
|
|
|
|
|
NSMakePoint (rect.origin.x,
|
|
|
|
|
rect.origin.y + rect.size.height - tls.height)
|
|
|
|
|
fromRect: tiles->rects[TileBL]
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
[tiles->images[TileBR] compositeToPoint:
|
|
|
|
|
NSMakePoint (rect.origin.x + rect.size.width - brs.width,
|
|
|
|
|
rect.origin.y + rect.size.height - tls.height)
|
|
|
|
|
fromRect: tiles->rects[TileBR]
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
|
|
|
|
|
inFill = NSMakeRect (rect.origin.x +cls.width,
|
2006-10-15 08:34:47 +00:00
|
|
|
|
rect.origin.y + bms.height,
|
2006-09-22 11:23:03 +00:00
|
|
|
|
rect.size.width - cls.width - crs.width,
|
|
|
|
|
rect.size.height - bms.height - tms.height);
|
2006-10-15 08:34:47 +00:00
|
|
|
|
if (style == GSThemeFillStyleCenter)
|
2006-09-22 11:23:03 +00:00
|
|
|
|
{
|
|
|
|
|
[self fillRect: inFill
|
|
|
|
|
withRepeatedImage: tiles->images[TileCM]
|
|
|
|
|
fromRect: tiles->rects[TileCM]
|
|
|
|
|
center: NO];
|
|
|
|
|
}
|
2006-10-15 08:34:47 +00:00
|
|
|
|
else if (style == GSThemeFillStyleRepeat)
|
2006-09-22 11:23:03 +00:00
|
|
|
|
{
|
|
|
|
|
[self fillRect: inFill
|
|
|
|
|
withRepeatedImage: tiles->images[TileCM]
|
|
|
|
|
fromRect: tiles->rects[TileCM]
|
|
|
|
|
center: NO];
|
|
|
|
|
}
|
2006-10-15 08:34:47 +00:00
|
|
|
|
else if (style == GSThemeFillStyleScale)
|
|
|
|
|
{
|
2006-09-22 11:23:03 +00:00
|
|
|
|
[tiles->images[TileCM] setScalesWhenResized: YES];
|
|
|
|
|
[tiles->images[TileCM] setSize: inFill.size];
|
|
|
|
|
[tiles->images[TileCM] compositeToPoint: inFill.origin
|
|
|
|
|
fromRect: tiles->rects[TileCM]
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[self fillHorizontalRect:
|
|
|
|
|
NSMakeRect(
|
|
|
|
|
rect.origin.x + tls.width,
|
|
|
|
|
rect.origin.y + rect.size.height - tms.height,
|
|
|
|
|
rect.size.width - bls.width - brs.width,
|
|
|
|
|
tms.height)
|
|
|
|
|
withImage: tiles->images[TileTM]
|
|
|
|
|
fromRect: tiles->rects[TileTM]
|
|
|
|
|
flipped: NO];
|
|
|
|
|
[self fillHorizontalRect:
|
|
|
|
|
NSMakeRect(
|
|
|
|
|
rect.origin.x + bls.width,
|
|
|
|
|
rect.origin.y,
|
|
|
|
|
rect.size.width - bls.width - brs.width,
|
|
|
|
|
bms.height)
|
|
|
|
|
withImage: tiles->images[TileBM]
|
|
|
|
|
fromRect: tiles->rects[TileBM]
|
|
|
|
|
flipped: NO];
|
|
|
|
|
[self fillVerticalRect:
|
|
|
|
|
NSMakeRect(
|
|
|
|
|
rect.origin.x,
|
|
|
|
|
rect.origin.y + bls.height,
|
|
|
|
|
cls.width,
|
|
|
|
|
rect.size.height - tls.height - bls.height)
|
|
|
|
|
withImage: tiles->images[TileCL]
|
|
|
|
|
fromRect: tiles->rects[TileCL]
|
|
|
|
|
flipped: NO];
|
|
|
|
|
[self fillVerticalRect:
|
|
|
|
|
NSMakeRect(
|
|
|
|
|
rect.origin.x + rect.size.width - crs.width,
|
|
|
|
|
rect.origin.y + brs.height,
|
|
|
|
|
crs.width,
|
|
|
|
|
rect.size.height - trs.height - brs.height)
|
|
|
|
|
withImage: tiles->images[TileCR]
|
|
|
|
|
fromRect: tiles->rects[TileCR]
|
|
|
|
|
flipped: NO];
|
|
|
|
|
|
|
|
|
|
[tiles->images[TileTL] compositeToPoint:
|
|
|
|
|
NSMakePoint (
|
|
|
|
|
rect.origin.x,
|
|
|
|
|
rect.origin.y + rect.size.height - tls.height)
|
|
|
|
|
fromRect: tiles->rects[TileTL]
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
[tiles->images[TileTR] compositeToPoint:
|
|
|
|
|
NSMakePoint(
|
|
|
|
|
rect.origin.x + rect.size.width - trs.width,
|
|
|
|
|
rect.origin.y + rect.size.height - trs.height)
|
|
|
|
|
fromRect: tiles->rects[TileTR]
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
[tiles->images[TileBL] compositeToPoint:
|
|
|
|
|
NSMakePoint(
|
|
|
|
|
rect.origin.x,
|
|
|
|
|
rect.origin.y)
|
|
|
|
|
fromRect: tiles->rects[TileBL]
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
[tiles->images[TileBR] compositeToPoint:
|
|
|
|
|
NSMakePoint(
|
|
|
|
|
rect.origin.x + rect.size.width - brs.width,
|
|
|
|
|
rect.origin.y)
|
|
|
|
|
fromRect: tiles->rects[TileBR]
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
|
|
|
|
|
inFill = NSMakeRect (rect.origin.x +cls.width,
|
2006-10-15 08:34:47 +00:00
|
|
|
|
rect.origin.y + bms.height,
|
2006-09-22 11:23:03 +00:00
|
|
|
|
rect.size.width - cls.width - crs.width,
|
|
|
|
|
rect.size.height - bms.height - tms.height);
|
|
|
|
|
|
2006-10-15 08:34:47 +00:00
|
|
|
|
if (style == GSThemeFillStyleCenter)
|
2006-09-22 11:23:03 +00:00
|
|
|
|
{
|
|
|
|
|
[self fillRect: inFill
|
|
|
|
|
withRepeatedImage: tiles->images[TileCM]
|
|
|
|
|
fromRect: tiles->rects[TileCM]
|
|
|
|
|
center: NO];
|
|
|
|
|
}
|
2006-10-15 08:34:47 +00:00
|
|
|
|
else if (style == GSThemeFillStyleRepeat)
|
2006-09-22 11:23:03 +00:00
|
|
|
|
{
|
|
|
|
|
[self fillRect: inFill
|
|
|
|
|
withRepeatedImage: tiles->images[TileCM]
|
|
|
|
|
fromRect: tiles->rects[TileCM]
|
|
|
|
|
center: YES];
|
|
|
|
|
}
|
2006-10-15 08:34:47 +00:00
|
|
|
|
else if (style == GSThemeFillStyleScale)
|
2006-09-22 11:23:03 +00:00
|
|
|
|
{
|
|
|
|
|
[tiles->images[TileCM] setScalesWhenResized: YES];
|
|
|
|
|
[tiles->images[TileCM] setSize: inFill.size];
|
|
|
|
|
[tiles->images[TileCM] compositeToPoint: inFill.origin
|
|
|
|
|
fromRect: tiles->rects[TileCM]
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
}
|
2004-02-13 18:27:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 11:23:03 +00:00
|
|
|
|
- (void) fillVerticalRect: (NSRect)rect
|
|
|
|
|
withImage: (NSImage*)image
|
|
|
|
|
fromRect: (NSRect)source
|
|
|
|
|
flipped: (BOOL)flipped
|
|
|
|
|
{
|
|
|
|
|
NSGraphicsContext *ctxt = GSCurrentContext();
|
|
|
|
|
NSBezierPath *path;
|
|
|
|
|
unsigned repetitions;
|
|
|
|
|
unsigned count;
|
|
|
|
|
NSPoint p;
|
|
|
|
|
|
|
|
|
|
DPSgsave (ctxt);
|
|
|
|
|
path = [NSBezierPath bezierPathWithRect: rect];
|
|
|
|
|
[path addClip];
|
|
|
|
|
repetitions = (rect.size.height / source.size.height) + 1;
|
|
|
|
|
|
|
|
|
|
if (flipped)
|
|
|
|
|
{
|
|
|
|
|
for (count = 0; count < repetitions; count++)
|
|
|
|
|
{
|
|
|
|
|
p = NSMakePoint (rect.origin.x,
|
|
|
|
|
rect.origin.y + rect.size.height - count * source.size.height);
|
|
|
|
|
[image compositeToPoint: p
|
|
|
|
|
fromRect: source
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (count = 0; count < repetitions; count++)
|
|
|
|
|
{
|
|
|
|
|
p = NSMakePoint (rect.origin.x,
|
|
|
|
|
rect.origin.y + count * source.size.height);
|
|
|
|
|
[image compositeToPoint: p
|
|
|
|
|
fromRect: source
|
|
|
|
|
operation: NSCompositeSourceOver];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DPSgrestore (ctxt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation GSDrawTiles
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
|
{
|
|
|
|
|
RELEASE(images[i]);
|
|
|
|
|
}
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Simple initialiser, assume the single image is split into nine equal tiles.
|
|
|
|
|
* If the image size is not divisible by three, the corners are made equal
|
|
|
|
|
* in size and the central parts slightly smaller.
|
|
|
|
|
*/
|
|
|
|
|
- (id) initWithImage: (NSImage*)image
|
|
|
|
|
{
|
|
|
|
|
NSSize s = [image size];
|
|
|
|
|
|
|
|
|
|
return [self initWithImage: image
|
|
|
|
|
horizontal: s.width / 3.0
|
|
|
|
|
vertical: s.height / 3.0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithImage: (NSImage*)image horizontal: (float)x vertical: (float)y
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
NSSize s = [image size];
|
|
|
|
|
|
|
|
|
|
x = floor(x);
|
|
|
|
|
y = floor(y);
|
|
|
|
|
|
|
|
|
|
rects[TileTL] = NSMakeRect(0.0, s.height - y, x, y);
|
|
|
|
|
rects[TileTM] = NSMakeRect(x, s.height - y, s.width - 2.0 * x, y);
|
|
|
|
|
rects[TileTR] = NSMakeRect(s.width - x, s.height - y, x, y);
|
|
|
|
|
rects[TileCL] = NSMakeRect(0.0, y, x, s.height - 2.0 * y);
|
|
|
|
|
rects[TileCM] = NSMakeRect(x, y, s.width - 2.0 * x, s.height - 2.0 * y);
|
|
|
|
|
rects[TileCR] = NSMakeRect(s.width - x, y, x, s.height - 2.0 * y);
|
|
|
|
|
rects[TileBL] = NSMakeRect(0.0, 0.0, x, y);
|
|
|
|
|
rects[TileBM] = NSMakeRect(x, 0.0, s.width - 2.0 * x, y);
|
|
|
|
|
rects[TileBR] = NSMakeRect(s.width - x, 0.0, x, y);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
|
{
|
|
|
|
|
if (rects[i].origin.x < 0.0 || rects[i].origin.y < 0.0
|
|
|
|
|
|| rects[i].size.width <= 0.0 || rects[i].size.height <= 0.0)
|
|
|
|
|
{
|
|
|
|
|
images[i] = nil;
|
|
|
|
|
rects[i] = NSZeroRect;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
images[i] = RETAIN(image);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation GSThemePanel
|
|
|
|
|
|
|
|
|
|
static GSThemePanel *sharedPanel = nil;
|
|
|
|
|
|
|
|
|
|
+ (GSThemePanel*) sharedThemePanel
|
|
|
|
|
{
|
|
|
|
|
if (sharedPanel == nil)
|
|
|
|
|
{
|
|
|
|
|
sharedPanel = [self new];
|
|
|
|
|
}
|
|
|
|
|
return sharedPanel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
NSRect winFrame;
|
|
|
|
|
NSRect sideFrame;
|
|
|
|
|
NSRect bottomFrame;
|
|
|
|
|
NSRect frame;
|
|
|
|
|
NSView *container;
|
|
|
|
|
NSButtonCell *proto;
|
|
|
|
|
|
|
|
|
|
winFrame = NSMakeRect(0, 0, 367, 420);
|
|
|
|
|
sideFrame = NSMakeRect(0, 0, 95, 420);
|
|
|
|
|
bottomFrame = NSMakeRect(95, 0, 272, 32);
|
|
|
|
|
|
|
|
|
|
self = [super initWithContentRect: winFrame
|
|
|
|
|
styleMask: (NSTitledWindowMask | NSClosableWindowMask
|
|
|
|
|
| NSMiniaturizableWindowMask | NSResizableWindowMask)
|
|
|
|
|
backing: NSBackingStoreBuffered
|
|
|
|
|
defer: NO];
|
|
|
|
|
|
|
|
|
|
[self setReleasedWhenClosed: NO];
|
|
|
|
|
container = [self contentView];
|
|
|
|
|
sideView = [[NSScrollView alloc] initWithFrame: sideFrame];
|
|
|
|
|
[sideView setHasHorizontalScroller: NO];
|
|
|
|
|
[sideView setHasVerticalScroller: YES];
|
|
|
|
|
[sideView setBorderType: NSBezelBorder];
|
|
|
|
|
[sideView setAutoresizingMask: (NSViewHeightSizable | NSViewMaxXMargin)];
|
|
|
|
|
[container addSubview: sideView];
|
|
|
|
|
RELEASE(sideView);
|
|
|
|
|
|
|
|
|
|
proto = [[NSButtonCell alloc] init];
|
|
|
|
|
[proto setBordered: NO];
|
|
|
|
|
[proto setAlignment: NSCenterTextAlignment];
|
|
|
|
|
[proto setImagePosition: NSImageAbove];
|
|
|
|
|
[proto setSelectable: NO];
|
|
|
|
|
[proto setEditable: NO];
|
|
|
|
|
[matrix setPrototype: proto];
|
|
|
|
|
|
|
|
|
|
frame = [sideView frame];
|
|
|
|
|
frame.origin = NSZeroPoint;
|
|
|
|
|
matrix = [[NSMatrix alloc] initWithFrame: frame
|
|
|
|
|
mode: NSRadioModeMatrix
|
|
|
|
|
prototype: proto
|
|
|
|
|
numberOfRows: 1
|
|
|
|
|
numberOfColumns: 1];
|
|
|
|
|
RELEASE(proto);
|
|
|
|
|
[matrix setAutosizesCells: NO];
|
|
|
|
|
[matrix setCellSize: NSMakeSize(72,72)];
|
|
|
|
|
[matrix setIntercellSpacing: NSMakeSize(8,8)];
|
|
|
|
|
[matrix setAutoresizingMask: NSViewNotSizable];
|
|
|
|
|
[matrix setMode: NSRadioModeMatrix];
|
|
|
|
|
[matrix setAction: @selector(changeSelection:)];
|
|
|
|
|
[matrix setTarget: self];
|
|
|
|
|
|
|
|
|
|
[sideView setDocumentView: matrix];
|
|
|
|
|
RELEASE(matrix);
|
|
|
|
|
|
|
|
|
|
bottomView = [[NSView alloc] initWithFrame: bottomFrame];
|
|
|
|
|
[bottomView setAutoresizingMask: (NSViewWidthSizable | NSViewMaxYMargin)];
|
|
|
|
|
[container addSubview: bottomView];
|
|
|
|
|
RELEASE(bottomView);
|
|
|
|
|
|
|
|
|
|
[self setTitle: @"Themes"];
|
|
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
|
addObserver: self
|
|
|
|
|
selector: @selector(notified:)
|
|
|
|
|
name: GSThemeDidActivateNotification
|
|
|
|
|
object: nil];
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
|
addObserver: self
|
|
|
|
|
selector: @selector(notified:)
|
|
|
|
|
name: GSThemeDidDeactivateNotification
|
|
|
|
|
object: nil];
|
|
|
|
|
|
|
|
|
|
/* Fake a notification to set the initial value for the inspector.
|
|
|
|
|
*/
|
|
|
|
|
[self notified:
|
|
|
|
|
[NSNotification notificationWithName: GSThemeDidActivateNotification
|
|
|
|
|
object: [GSTheme theme]
|
|
|
|
|
userInfo: nil]];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) changeSelection: (id)sender
|
|
|
|
|
{
|
|
|
|
|
NSButtonCell *cell = [sender selectedCell];
|
|
|
|
|
NSString *name = [cell title];
|
|
|
|
|
|
|
|
|
|
[GSTheme setTheme: [GSTheme loadThemeNamed: name]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) notified: (NSNotification*)n
|
|
|
|
|
{
|
|
|
|
|
NSView *cView;
|
|
|
|
|
GSThemeInspector *inspector;
|
|
|
|
|
|
|
|
|
|
inspector = (GSThemeInspector*)[[n object] themeInspector];
|
|
|
|
|
cView = [self contentView];
|
|
|
|
|
|
|
|
|
|
if ([[n name] isEqualToString: GSThemeDidActivateNotification] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSView *iView;
|
|
|
|
|
NSRect frame;
|
|
|
|
|
NSButton *button;
|
|
|
|
|
NSString *dName;
|
|
|
|
|
|
|
|
|
|
/* Ask the inspector to ensure that it is up to date.
|
|
|
|
|
*/
|
|
|
|
|
[inspector update: self];
|
|
|
|
|
|
|
|
|
|
/* Move the inspector view into our window.
|
|
|
|
|
*/
|
|
|
|
|
iView = RETAIN([inspector contentView]);
|
|
|
|
|
[inspector setContentView: nil];
|
|
|
|
|
[cView addSubview: iView];
|
|
|
|
|
RELEASE(iView);
|
|
|
|
|
|
|
|
|
|
/* Set inspector view to fill the frame to the right of our
|
|
|
|
|
* scrollview and above the bottom view
|
|
|
|
|
*/
|
|
|
|
|
frame.origin.x = [sideView frame].size.width;
|
|
|
|
|
frame.origin.y = [bottomView frame].size.height;
|
|
|
|
|
frame.size = [cView frame].size;
|
|
|
|
|
frame.size.width -= [sideView frame].size.width;
|
|
|
|
|
frame.size.height -= [bottomView frame].size.height;
|
|
|
|
|
[iView setFrame: frame];
|
|
|
|
|
|
|
|
|
|
button = [[bottomView subviews] lastObject];
|
|
|
|
|
if (button == nil)
|
|
|
|
|
{
|
|
|
|
|
button = [NSButton new];
|
|
|
|
|
[button setTarget: self];
|
|
|
|
|
[button setAction: @selector(setDefault:)];
|
|
|
|
|
[bottomView addSubview: button];
|
|
|
|
|
RELEASE(button);
|
|
|
|
|
}
|
|
|
|
|
dName = [[NSUserDefaults standardUserDefaults] stringForKey: @"GSTheme"];
|
|
|
|
|
if ([[[n object] name] isEqual: dName] == YES)
|
|
|
|
|
{
|
|
|
|
|
[button setTitle: @"Revert default theme"];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[button setTitle: @"Make this the default theme"];
|
|
|
|
|
}
|
|
|
|
|
[button sizeToFit];
|
|
|
|
|
frame = [button frame];
|
|
|
|
|
frame.origin.x = ([bottomView frame].size.width - frame.size.width) / 2;
|
|
|
|
|
frame.origin.y = ([bottomView frame].size.height - frame.size.height) / 2;
|
|
|
|
|
[button setFrame: frame];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Restore the inspector content view.
|
|
|
|
|
*/
|
|
|
|
|
[inspector setContentView: [[cView subviews] lastObject]];
|
|
|
|
|
}
|
|
|
|
|
[cView setNeedsDisplay: YES];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setDefault: (id)sender
|
|
|
|
|
{
|
|
|
|
|
NSButton *button = (NSButton*)sender;
|
|
|
|
|
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
NSString *cName;
|
|
|
|
|
NSString *dName;
|
|
|
|
|
NSRect frame;
|
|
|
|
|
|
|
|
|
|
dName = [defs stringForKey: @"GSTheme"];
|
|
|
|
|
cName = [[GSTheme theme] name];
|
|
|
|
|
|
|
|
|
|
if ([cName isEqual: dName] == YES)
|
|
|
|
|
{
|
|
|
|
|
[defs removeObjectForKey: @"GSTheme"];
|
|
|
|
|
[button setTitle: @"Make this the default theme"];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[defs setObject: cName forKey: @"GSTheme"];
|
|
|
|
|
[button setTitle: @"Revert default theme"];
|
|
|
|
|
}
|
|
|
|
|
[defs synchronize];
|
|
|
|
|
[button sizeToFit];
|
|
|
|
|
frame = [button frame];
|
|
|
|
|
frame.origin.x = ([bottomView frame].size.width - frame.size.width) / 2;
|
|
|
|
|
frame.origin.y = ([bottomView frame].size.height - frame.size.height) / 2;
|
|
|
|
|
[button setFrame: frame];
|
|
|
|
|
[bottomView setNeedsDisplay: YES];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) update: (id)sender
|
|
|
|
|
{
|
|
|
|
|
NSArray *array;
|
2006-10-02 16:30:52 +00:00
|
|
|
|
|
|
|
|
|
/* Avoid [NSMutableSet set] that confuses GCC 3.3.3. It seems to confuse
|
|
|
|
|
* this static +(id)set method with the instance -(void)set, so it would
|
|
|
|
|
* refuse to compile saying
|
|
|
|
|
* GSTheme.m:1565: error: void value not ignored as it ought to be
|
|
|
|
|
*/
|
|
|
|
|
NSMutableSet *set = AUTORELEASE([NSMutableSet new]);
|
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
|
NSString *selected = RETAIN([[matrix selectedCell] title]);
|
|
|
|
|
unsigned existing = [[matrix cells] count];
|
|
|
|
|
NSFileManager *mgr = [NSFileManager defaultManager];
|
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
NSString *path;
|
|
|
|
|
NSString *name;
|
|
|
|
|
NSButtonCell *cell;
|
|
|
|
|
unsigned count = 0;
|
|
|
|
|
|
|
|
|
|
/* Ensure the first cell contains the default theme.
|
|
|
|
|
*/
|
|
|
|
|
cell = [matrix cellAtRow: count++ column: 0];
|
|
|
|
|
[cell setImage: [defaultTheme icon]];
|
|
|
|
|
[cell setTitle: [defaultTheme name]];
|
|
|
|
|
|
|
|
|
|
/* Go through all the themes in the standard locations and find their names.
|
|
|
|
|
*/
|
|
|
|
|
enumerator = [NSSearchPathForDirectoriesInDomains
|
|
|
|
|
(NSAllLibrariesDirectory, NSAllDomainsMask, YES) objectEnumerator];
|
|
|
|
|
while ((path = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *files;
|
|
|
|
|
NSString *file;
|
|
|
|
|
|
|
|
|
|
path = [path stringByAppendingPathComponent: @"Themes"];
|
|
|
|
|
files = [[mgr directoryContentsAtPath: path] objectEnumerator];
|
|
|
|
|
while ((file = [files nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
NSString *ext = [file pathExtension];
|
|
|
|
|
|
|
|
|
|
name = [file stringByDeletingPathExtension];
|
|
|
|
|
if ([ext isEqualToString: @"theme"] == YES
|
|
|
|
|
&& [name isEqualToString: @"GNUstep"] == NO)
|
|
|
|
|
{
|
|
|
|
|
[set addObject: name];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sort theme names alphabetically, and add each theme to the matrix.
|
|
|
|
|
*/
|
|
|
|
|
array = [[set allObjects] sortedArrayUsingSelector:
|
|
|
|
|
@selector(caseInsensitiveCompare:)];
|
|
|
|
|
enumerator = [array objectEnumerator];
|
|
|
|
|
while ((name = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
GSTheme *loaded;
|
|
|
|
|
|
|
|
|
|
loaded = [GSTheme loadThemeNamed: name];
|
|
|
|
|
if (loaded != nil)
|
|
|
|
|
{
|
|
|
|
|
if (count >= existing)
|
|
|
|
|
{
|
|
|
|
|
[matrix addRow];
|
|
|
|
|
existing++;
|
|
|
|
|
}
|
|
|
|
|
cell = [matrix cellAtRow: count column: 0];
|
|
|
|
|
[cell setImage: [loaded icon]];
|
|
|
|
|
[cell setTitle: [loaded name]];
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Empty any unused cells.
|
|
|
|
|
*/
|
|
|
|
|
while (count < existing)
|
|
|
|
|
{
|
|
|
|
|
cell = [matrix cellAtRow: count column: 0];
|
|
|
|
|
[cell setImage: nil];
|
|
|
|
|
[cell setTitle: @""];
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Restore the selected cell.
|
|
|
|
|
*/
|
|
|
|
|
array = [matrix cells];
|
|
|
|
|
count = [array count];
|
|
|
|
|
while (count-- > 0)
|
|
|
|
|
{
|
|
|
|
|
cell = [matrix cellAtRow: count column: 0];
|
|
|
|
|
if ([[cell title] isEqual: selected])
|
|
|
|
|
{
|
|
|
|
|
[matrix selectCellAtRow: count column: 0];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RELEASE(selected);
|
|
|
|
|
[matrix sizeToCells];
|
|
|
|
|
[matrix setNeedsDisplay: YES];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static NSTextField *
|
|
|
|
|
new_label (NSString *value)
|
|
|
|
|
{
|
|
|
|
|
NSTextField *t;
|
|
|
|
|
|
|
|
|
|
t = AUTORELEASE([NSTextField new]);
|
|
|
|
|
[t setStringValue: value];
|
|
|
|
|
[t setDrawsBackground: NO];
|
|
|
|
|
[t setEditable: NO];
|
|
|
|
|
[t setSelectable: NO];
|
|
|
|
|
[t setBezeled: NO];
|
|
|
|
|
[t setBordered: NO];
|
|
|
|
|
[t setAlignment: NSLeftTextAlignment];
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implemented in GSInfoPanel.m
|
|
|
|
|
* An object that displays a list of left-aligned strings (used for the authors)
|
|
|
|
|
*/
|
|
|
|
|
@interface _GSLabelListView: NSView
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
/* After initialization, its size is the size it needs, just move it
|
|
|
|
|
where we want it to show */
|
|
|
|
|
- (id) initWithStringArray: (NSArray *)array
|
|
|
|
|
font: (NSFont *)font;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation GSThemeInspector
|
|
|
|
|
|
|
|
|
|
static GSThemeInspector *sharedInspector = nil;
|
|
|
|
|
|
|
|
|
|
+ (GSThemeInspector*) sharedThemeInspector
|
|
|
|
|
{
|
|
|
|
|
if (sharedInspector == nil)
|
|
|
|
|
{
|
|
|
|
|
sharedInspector = [self new];
|
|
|
|
|
}
|
|
|
|
|
return sharedInspector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
NSRect frame;
|
|
|
|
|
NSView *content;
|
|
|
|
|
|
|
|
|
|
frame.size = NSMakeSize(272,388);
|
|
|
|
|
frame.origin = NSZeroPoint;
|
|
|
|
|
self = [super initWithContentRect: frame
|
|
|
|
|
styleMask: (NSTitledWindowMask | NSClosableWindowMask
|
|
|
|
|
| NSMiniaturizableWindowMask | NSResizableWindowMask)
|
|
|
|
|
backing: NSBackingStoreBuffered
|
|
|
|
|
defer: NO];
|
|
|
|
|
|
|
|
|
|
[self setReleasedWhenClosed: NO];
|
|
|
|
|
content = [self contentView];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) update: (id)sender
|
|
|
|
|
{
|
|
|
|
|
GSTheme *theme = [GSTheme theme];
|
2006-10-12 17:14:26 +00:00
|
|
|
|
NSString *details;
|
2006-10-02 05:09:48 +00:00
|
|
|
|
NSArray *authors;
|
|
|
|
|
NSView *content = [self contentView];
|
|
|
|
|
NSRect cFrame = [content frame];
|
|
|
|
|
NSView *view;
|
2006-10-12 17:14:26 +00:00
|
|
|
|
NSImageView *iv;
|
2006-10-02 05:09:48 +00:00
|
|
|
|
NSTextField *tf;
|
|
|
|
|
NSRect nameFrame;
|
|
|
|
|
NSRect frame;
|
|
|
|
|
|
|
|
|
|
while ((view = [[content subviews] lastObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
[view removeFromSuperview];
|
|
|
|
|
}
|
2006-10-12 17:14:26 +00:00
|
|
|
|
frame = NSMakeRect(cFrame.size.width - 58, cFrame.size.height - 58, 48, 48);
|
|
|
|
|
iv = [[NSImageView alloc] initWithFrame: frame];
|
|
|
|
|
[iv setImage: [[GSTheme theme] icon]];
|
|
|
|
|
[content addSubview: iv];
|
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
|
tf = new_label([theme name]);
|
|
|
|
|
[tf setFont: [NSFont boldSystemFontOfSize: 32]];
|
|
|
|
|
[tf sizeToFit];
|
|
|
|
|
nameFrame = [tf frame];
|
2006-10-12 17:14:26 +00:00
|
|
|
|
nameFrame.origin.x
|
|
|
|
|
= (cFrame.size.width - frame.size.width - nameFrame.size.width) / 2;
|
2006-10-02 05:09:48 +00:00
|
|
|
|
nameFrame.origin.y = cFrame.size.height - nameFrame.size.height - 25;
|
|
|
|
|
[tf setFrame: nameFrame];
|
|
|
|
|
[content addSubview: tf];
|
|
|
|
|
|
|
|
|
|
authors = [[theme infoDictionary] objectForKey: @"GSThemeAuthors"];
|
|
|
|
|
if ([authors count] > 0)
|
|
|
|
|
{
|
|
|
|
|
view = [[_GSLabelListView alloc] initWithStringArray: authors
|
|
|
|
|
font: [NSFont systemFontOfSize: 14]];
|
|
|
|
|
frame = [view frame];
|
|
|
|
|
frame.origin.x = (cFrame.size.width - frame.size.width) / 2;
|
|
|
|
|
frame.origin.y = nameFrame.origin.y - frame.size.height - 25;
|
|
|
|
|
[view setFrame: frame];
|
|
|
|
|
[content addSubview: view];
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-12 17:14:26 +00:00
|
|
|
|
details = [[theme infoDictionary] objectForKey: @"GSThemeDetails"];
|
|
|
|
|
if ([details length] > 0)
|
|
|
|
|
{
|
|
|
|
|
NSScrollView *s;
|
|
|
|
|
NSTextView *v;
|
|
|
|
|
NSRect r;
|
|
|
|
|
|
|
|
|
|
r = NSMakeRect(10, 10, cFrame.size.width - 20, frame.origin.y - 20);
|
|
|
|
|
s = [[NSScrollView alloc] initWithFrame: r];
|
|
|
|
|
[s setHasHorizontalScroller: NO];
|
|
|
|
|
[s setHasVerticalScroller: YES];
|
|
|
|
|
[s setBorderType: NSBezelBorder];
|
|
|
|
|
[s setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
|
|
|
|
|
[content addSubview: s];
|
|
|
|
|
RELEASE(s);
|
|
|
|
|
|
|
|
|
|
r = [[s documentView] frame];
|
|
|
|
|
v = [[NSTextView alloc] initWithFrame: r];
|
|
|
|
|
[v setBackgroundColor: [self backgroundColor]];
|
|
|
|
|
[v setHorizontallyResizable: YES];
|
|
|
|
|
[v setVerticallyResizable: YES];
|
|
|
|
|
[v setEditable: NO];
|
|
|
|
|
[v setRichText: YES];
|
|
|
|
|
[v setMinSize: NSMakeSize (0, 0)];
|
|
|
|
|
[v setMaxSize: NSMakeSize (1E7, 1E7)];
|
|
|
|
|
[v setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
|
|
|
|
|
[[v textContainer] setContainerSize:
|
|
|
|
|
NSMakeSize (r.size.width, 1e7)];
|
|
|
|
|
[[v textContainer] setWidthTracksTextView: YES];
|
|
|
|
|
[v setString: details];
|
|
|
|
|
[s setDocumentView: v];
|
|
|
|
|
RELEASE(v);
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-02 05:09:48 +00:00
|
|
|
|
[content setNeedsDisplay: YES];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|