mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 06:10:48 +00:00
Some theme integration work
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@23585 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1e779eacaf
commit
c7ab1a2a90
14 changed files with 1550 additions and 432 deletions
|
@ -19,7 +19,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA
|
||||
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
# Boston, MA 02111 USA
|
||||
#
|
||||
|
||||
MAKEFILE_NAME = DocMakefile
|
||||
|
@ -147,6 +148,7 @@ NSWorkspace.h
|
|||
|
||||
AUTOGSDOC_HEADERS_GUIADD = \
|
||||
GSDisplayServer.h \
|
||||
GSDrawFunctions.h \
|
||||
GSFusedSilica.h \
|
||||
GSTable.h \
|
||||
GSHbox.h \
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -195,6 +195,7 @@
|
|||
|
||||
- (void) drawRect: (NSRect)rect
|
||||
{
|
||||
GSDrawFunctions *theme = [GSDrawFunctions theme];
|
||||
NSRect workRect = [self bounds];
|
||||
NSSize titleSize;
|
||||
NSRectEdge top_left[] = {NSMinXEdge, NSMaxYEdge};
|
||||
|
@ -213,7 +214,7 @@
|
|||
|
||||
// Rectangle 2
|
||||
// Draw the title box's button.
|
||||
[GSDrawFunctions drawButton: workRect :workRect];
|
||||
[theme drawButton: workRect withClip: workRect];
|
||||
|
||||
// Overdraw white top and left lines with light gray lines for window title
|
||||
workRect.origin.y += 1;
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "AppKit/NSColor.h"
|
||||
#include "AppKit/NSWindow.h"
|
||||
#include "GNUstepGUI/GSDisplayServer.h"
|
||||
#include "GNUstepGUI/GSDrawFunctions.h"
|
||||
|
||||
|
||||
struct NSWindow_struct
|
||||
|
@ -215,12 +216,9 @@ struct NSWindow_struct
|
|||
|
||||
- (void) drawRect: (NSRect)rect
|
||||
{
|
||||
NSColor *c = [_window backgroundColor];
|
||||
|
||||
if (NSIntersectsRect(rect, contentRect))
|
||||
{
|
||||
[c set];
|
||||
NSRectFill(contentRect);
|
||||
[[GSDrawFunctions theme] drawWindowBackground: contentRect view: self];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -836,6 +836,9 @@ typedef struct _GSButtonCellFlags
|
|||
|
||||
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||
{
|
||||
unsigned mask;
|
||||
int buttonState = 0;
|
||||
|
||||
// Save last view drawn to
|
||||
if (_control_view != controlView)
|
||||
_control_view = controlView;
|
||||
|
@ -848,22 +851,59 @@ typedef struct _GSButtonCellFlags
|
|||
if (NSIsEmptyRect(cellFrame))
|
||||
return;
|
||||
|
||||
// draw the border if needed
|
||||
if ((_cell.is_bordered) &&
|
||||
(!_shows_border_only_while_mouse_inside || _mouse_inside))
|
||||
// set the mask
|
||||
if (_cell.is_highlighted)
|
||||
{
|
||||
// FIXME Should check the bezel and gradient style
|
||||
if (_cell.is_highlighted && (_highlightsByMask & NSPushInCellMask))
|
||||
mask = _highlightsByMask;
|
||||
if (_cell.state)
|
||||
{
|
||||
[GSDrawFunctions drawGrayBezel: cellFrame : NSZeroRect];
|
||||
}
|
||||
else
|
||||
mask &= ~_showAltStateMask;
|
||||
}
|
||||
}
|
||||
else if (_cell.state)
|
||||
mask = _showAltStateMask;
|
||||
else
|
||||
mask = NSNoCellMask;
|
||||
|
||||
/* Draw the cell's background color.
|
||||
We draw when there is a border or when highlightsByMask
|
||||
is NSChangeBackgroundCellMask or NSChangeGrayCellMask,
|
||||
as required by our nextstep-like look and feel. */
|
||||
if (_cell.is_bordered
|
||||
|| (_highlightsByMask & NSChangeBackgroundCellMask)
|
||||
|| (_highlightsByMask & NSChangeGrayCellMask))
|
||||
{
|
||||
/* Determine the background color. */
|
||||
if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
||||
{
|
||||
[GSDrawFunctions drawButton: cellFrame : NSZeroRect];
|
||||
buttonState = 1; /* highlighted state */
|
||||
}
|
||||
}
|
||||
|
||||
/* Pushed in buttons contents are displaced to the bottom right 1px. */
|
||||
if (_cell.is_bordered && (mask & NSPushInCellMask))
|
||||
{
|
||||
buttonState = 2; // pushed button
|
||||
}
|
||||
|
||||
// draw the border if needed
|
||||
if ((_cell.is_bordered)
|
||||
&& (!_shows_border_only_while_mouse_inside || _mouse_inside))
|
||||
{
|
||||
cellFrame = [[GSDrawFunctions theme]
|
||||
drawButton: cellFrame in: self view: controlView
|
||||
style: _bezel_style
|
||||
state: buttonState];
|
||||
}
|
||||
|
||||
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
||||
|
||||
// Draw first responder
|
||||
if (_cell.shows_first_responder
|
||||
&& [[controlView window] firstResponder] == controlView)
|
||||
{
|
||||
[[GSDrawFunctions theme] drawFocusFrame: cellFrame view: controlView];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) drawGradientWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
|
||||
|
@ -884,47 +924,47 @@ typedef struct _GSButtonCellFlags
|
|||
|
||||
switch (_gradient_type)
|
||||
{
|
||||
case NSGradientNone:
|
||||
return;
|
||||
break;
|
||||
case NSGradientNone:
|
||||
return;
|
||||
break;
|
||||
|
||||
case NSGradientConcaveWeak:
|
||||
[gray getHue: &h saturation: &s brightness: &v alpha: &a];
|
||||
start_white = [lightGray brightnessComponent];
|
||||
end_white = [gray brightnessComponent];
|
||||
break;
|
||||
|
||||
case NSGradientConvexWeak:
|
||||
[darkGray getHue: &h saturation: &s brightness: &v alpha: &a];
|
||||
start_white = [gray brightnessComponent];
|
||||
end_white = [lightGray brightnessComponent];
|
||||
break;
|
||||
|
||||
case NSGradientConcaveStrong:
|
||||
[lightGray getHue: &h saturation: &s brightness: &v alpha: &a];
|
||||
start_white = [lightGray brightnessComponent];
|
||||
end_white = [darkGray brightnessComponent];
|
||||
break;
|
||||
|
||||
case NSGradientConvexStrong:
|
||||
[darkGray getHue: &h saturation: &s brightness: &v alpha: &a];
|
||||
start_white = [darkGray brightnessComponent];
|
||||
end_white = [lightGray brightnessComponent];
|
||||
break;
|
||||
case NSGradientConcaveWeak:
|
||||
[gray getHue: &h saturation: &s brightness: &v alpha: &a];
|
||||
start_white = [lightGray brightnessComponent];
|
||||
end_white = [gray brightnessComponent];
|
||||
break;
|
||||
|
||||
case NSGradientConvexWeak:
|
||||
[darkGray getHue: &h saturation: &s brightness: &v alpha: &a];
|
||||
start_white = [gray brightnessComponent];
|
||||
end_white = [lightGray brightnessComponent];
|
||||
break;
|
||||
|
||||
case NSGradientConcaveStrong:
|
||||
[lightGray getHue: &h saturation: &s brightness: &v alpha: &a];
|
||||
start_white = [lightGray brightnessComponent];
|
||||
end_white = [darkGray brightnessComponent];
|
||||
break;
|
||||
|
||||
case NSGradientConvexStrong:
|
||||
[darkGray getHue: &h saturation: &s brightness: &v alpha: &a];
|
||||
start_white = [darkGray brightnessComponent];
|
||||
end_white = [lightGray brightnessComponent];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
white = start_white;
|
||||
white_step = fabs(start_white - end_white)/
|
||||
(cellFrame.size.width + cellFrame.size.height);
|
||||
white_step = fabs(start_white - end_white)
|
||||
/ (cellFrame.size.width + cellFrame.size.height);
|
||||
|
||||
// Start from top left
|
||||
p1 = NSMakePoint(cellFrame.origin.x,
|
||||
cellFrame.size.height + cellFrame.origin.y);
|
||||
p1 = NSMakePoint(cellFrame.origin.x,
|
||||
cellFrame.size.height + cellFrame.origin.y);
|
||||
p2 = NSMakePoint(cellFrame.origin.x,
|
||||
cellFrame.size.height + cellFrame.origin.y);
|
||||
cellFrame.size.height + cellFrame.origin.y);
|
||||
|
||||
// Move by Y
|
||||
while (p1.y > cellFrame.origin.y)
|
||||
|
@ -974,7 +1014,6 @@ typedef struct _GSButtonCellFlags
|
|||
NSRect titleRect;
|
||||
NSSize imageSize = {0, 0};
|
||||
NSSize titleSize = {0, 0};
|
||||
NSColor *backgroundColor = nil;
|
||||
BOOL flippedView = [controlView isFlipped];
|
||||
NSCellImagePosition ipos = _cell.image_position;
|
||||
|
||||
|
@ -998,38 +1037,6 @@ typedef struct _GSButtonCellFlags
|
|||
else
|
||||
mask = NSNoCellMask;
|
||||
|
||||
/* Pushed in buttons contents are displaced to the bottom right 1px. */
|
||||
if (_cell.is_bordered && (mask & NSPushInCellMask))
|
||||
{
|
||||
cellFrame = NSOffsetRect(cellFrame, 1., flippedView ? 1. : -1.);
|
||||
}
|
||||
|
||||
/* Draw the cell's background color.
|
||||
We draw when there is a border or when highlightsByMask
|
||||
is NSChangeBackgroundCellMask or NSChangeGrayCellMask,
|
||||
as required by our nextstep-like look and feel. */
|
||||
if (_cell.is_bordered
|
||||
|| (_highlightsByMask & NSChangeBackgroundCellMask)
|
||||
|| (_highlightsByMask & NSChangeGrayCellMask))
|
||||
{
|
||||
/* Determine the background color. */
|
||||
if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
||||
{
|
||||
backgroundColor = [NSColor selectedControlColor];
|
||||
}
|
||||
else if (_cell.is_bordered)
|
||||
{
|
||||
backgroundColor = [NSColor controlBackgroundColor];
|
||||
}
|
||||
|
||||
if (backgroundColor != nil)
|
||||
{
|
||||
[backgroundColor set];
|
||||
NSRectFill (cellFrame);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine the image and the title that will be
|
||||
* displayed. If the NSContentsCellMask is set the
|
||||
|
@ -1195,7 +1202,8 @@ typedef struct _GSButtonCellFlags
|
|||
imageRect.origin.x = cellFrame.origin.x;
|
||||
imageRect.origin.y = cellFrame.origin.y;
|
||||
imageRect.size.width = cellFrame.size.width;
|
||||
imageRect.size.height = titleRect.origin.y - GSCellTextImageYDist - imageRect.origin.y;
|
||||
imageRect.size.height
|
||||
= titleRect.origin.y - GSCellTextImageYDist - imageRect.origin.y;
|
||||
|
||||
if (_cell.is_bordered || _cell.is_bezeled)
|
||||
{
|
||||
|
@ -1229,7 +1237,9 @@ typedef struct _GSButtonCellFlags
|
|||
// Draw image
|
||||
if (imageToDisplay != nil)
|
||||
{
|
||||
[self _drawImage: imageToDisplay inFrame: imageRect isFlipped: flippedView];
|
||||
[self _drawImage: imageToDisplay
|
||||
inFrame: imageRect
|
||||
isFlipped: flippedView];
|
||||
}
|
||||
|
||||
// Draw title
|
||||
|
@ -1237,13 +1247,6 @@ typedef struct _GSButtonCellFlags
|
|||
{
|
||||
[self _drawAttributedText: titleToDisplay inFrame: titleRect];
|
||||
}
|
||||
|
||||
// Draw first responder
|
||||
if (_cell.shows_first_responder
|
||||
&& [[controlView window] firstResponder] == controlView)
|
||||
{
|
||||
NSDottedFrameRect(cellFrame);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSSize) cellSize
|
||||
|
|
|
@ -45,9 +45,19 @@
|
|||
#include "AppKit/NSImage.h"
|
||||
#include "AppKit/NSGraphics.h"
|
||||
#include "AppKit/PSOperators.h"
|
||||
#include "GNUstepGUI/GSDrawFunctions.h"
|
||||
|
||||
static Class NSColorClass;
|
||||
|
||||
/* This interface must be provided in NSColorList to let us manage
|
||||
* system colors.
|
||||
*/
|
||||
@interface NSColorList (GNUstepPrivate)
|
||||
+ (void) _setDefaultSystemColorList: (NSColorList*)aList;
|
||||
+ (void) _setThemeSystemColorList: (NSColorList*)aList;
|
||||
@end
|
||||
|
||||
|
||||
@interface GSNamedColor : NSColor
|
||||
{
|
||||
NSString *_catalog_name;
|
||||
|
@ -153,12 +163,14 @@ static Class NSColorClass;
|
|||
|
||||
+ (NSColor*) colorFromString: (NSString*)string;
|
||||
+ (void) defaultsDidChange: (NSNotification*)notification;
|
||||
+ (void) themeDidActivate: (NSNotification*)notification;
|
||||
|
||||
@end
|
||||
|
||||
// Class variables
|
||||
static BOOL gnustep_gui_ignores_alpha = YES;
|
||||
static NSColorList *systemColors = nil;
|
||||
static NSColorList *defaultSystemColors = nil;
|
||||
static NSMutableDictionary *colorStrings = nil;
|
||||
static NSMutableDictionary *systemDict = nil;
|
||||
|
||||
|
@ -224,9 +236,11 @@ void initSystemColors(void)
|
|||
nil];
|
||||
|
||||
systemColors = [NSColorList colorListNamed: @"System"];
|
||||
defaultSystemColors = [[NSColorList alloc] initWithName: @"System"];
|
||||
[NSColorList _setDefaultSystemColorList: defaultSystemColors];
|
||||
if (systemColors == nil)
|
||||
{
|
||||
systemColors = [[NSColorList alloc] initWithName: @"System"];
|
||||
ASSIGN(systemColors, defaultSystemColors);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -240,24 +254,24 @@ void initSystemColors(void)
|
|||
|
||||
while ((key = (NSString *)[enumerator nextObject]))
|
||||
{
|
||||
NSString *aColorString;
|
||||
NSColor *color;
|
||||
|
||||
if ([systemColors colorWithKey: key])
|
||||
continue;
|
||||
if ((color = [systemColors colorWithKey: key]) == nil)
|
||||
{
|
||||
NSString *aColorString;
|
||||
|
||||
aColorString = [colorStrings objectForKey: key];
|
||||
color = [NSColorClass colorFromString: aColorString];
|
||||
aColorString = [colorStrings objectForKey: key];
|
||||
color = [NSColorClass colorFromString: aColorString];
|
||||
|
||||
NSCAssert1(color, @"couldn't get default system color %@", key);
|
||||
|
||||
[systemColors setColor: color forKey: key];
|
||||
|
||||
changed = YES;
|
||||
NSCAssert1(color, @"couldn't get default system color %@", key);
|
||||
[systemColors setColor: color forKey: key];
|
||||
changed = YES;
|
||||
}
|
||||
if (defaultSystemColors != systemColors)
|
||||
{
|
||||
[defaultSystemColors setColor: color forKey: key];
|
||||
}
|
||||
}
|
||||
|
||||
if (changed)
|
||||
[systemColors writeToFile: nil];
|
||||
}
|
||||
|
||||
systemDict = [NSMutableDictionary new];
|
||||
|
@ -309,6 +323,12 @@ systemColorWithName(NSString *name)
|
|||
selector: @selector(defaultsDidChange:)
|
||||
name: NSUserDefaultsDidChangeNotification
|
||||
object: nil];
|
||||
// watch for themes which may provide new system color lists
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
selector: @selector(themeDidActivate:)
|
||||
name: GSThemeDidActivateNotification
|
||||
object: nil];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1636,6 +1656,35 @@ systemColorWithName(NSString *name)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle activation of a new theme ... look for a 'System' color list
|
||||
* in the theme bundle and use it instead of the default system color
|
||||
* list if it is present.
|
||||
*/
|
||||
+ (void) themeDidActivate: (NSNotification*)notification
|
||||
{
|
||||
NSDictionary *userInfo = [notification userInfo];
|
||||
NSColorList *list = [userInfo objectForKey: @"Colors"];
|
||||
|
||||
if (list == nil)
|
||||
{
|
||||
list = defaultSystemColors;
|
||||
}
|
||||
NSAssert([[list name] isEqual: @"System"], NSInvalidArgumentException);
|
||||
[NSColorList _setThemeSystemColorList: list];
|
||||
|
||||
/* We always update the system dictionary and send a notification, since
|
||||
* the theme may have gicen us a pre-existing color list, but have changed
|
||||
* one or more of the colors in it.
|
||||
*/
|
||||
list = [NSColorList colorListNamed: @"System"];
|
||||
ASSIGN(systemColors, list);
|
||||
[systemDict removeAllObjects];
|
||||
NSLog(@"Theme activation with control background %@", [self controlBackgroundColor]);
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: NSSystemColorsDidChangeNotification object: nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "config.h"
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSNotificationQueue.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
|
@ -43,82 +44,51 @@
|
|||
#include "AppKit/NSColor.h"
|
||||
#include "AppKit/AppKitExceptions.h"
|
||||
|
||||
// The list of available color lists is created only once -- this has
|
||||
// a drawback, that you need to restart your program to get the color
|
||||
// lists read again.
|
||||
static NSMutableArray *_gnustep_available_color_lists = nil;
|
||||
static NSLock *_gnustep_color_list_lock = nil;
|
||||
// The list of available color lists is cached and re-loaded only
|
||||
// after a time.
|
||||
static NSMutableArray *_availableColorLists = nil;
|
||||
static NSLock *_colorListLock = nil;
|
||||
|
||||
static NSColorList *defaultSystemColorList = nil;
|
||||
static NSColorList *themeColorList = nil;
|
||||
|
||||
@interface NSColorList (GNUstepPrivate)
|
||||
|
||||
/* Loads the available color lists from standard directories.<br />
|
||||
* If called with a nil argument, this will check to see if the
|
||||
* lists have already been loaded, and only load if they haven't been.
|
||||
*/
|
||||
+ (void) _loadAvailableColorLists: (NSNotification*)aNotification;
|
||||
|
||||
/* Set the default system color list ... to be used if no system color
|
||||
* list has been loaded from file. This should always be the last of
|
||||
* the array of available color lists even though it has noit been
|
||||
* written to file.
|
||||
*/
|
||||
+ (void) _setDefaultSystemColorList: (NSColorList*)aList;
|
||||
|
||||
/* Set the theme system color list ... if this is not nil, it is placed
|
||||
* at the start of the array of available lists and is used as the system
|
||||
* color list.
|
||||
*/
|
||||
+ (void) _setThemeSystemColorList: (NSColorList*)aList;
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSColorList
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
+ (void)initialize
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSColorList class])
|
||||
{
|
||||
[self setVersion: 2];
|
||||
_colorListLock = [NSRecursiveLock new];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Private Method which loads the color lists.
|
||||
* Invoke if _gnustep_available_color_lists == nil
|
||||
* before any operation with that object or its lock.
|
||||
*
|
||||
* The aim is to defer reading the available color lists
|
||||
* till we really need to, so that only programs which really use
|
||||
* this feature get the overhead.
|
||||
*/
|
||||
+ (void) _loadAvailableColorLists
|
||||
{
|
||||
NSString *dir;
|
||||
NSString *file;
|
||||
NSEnumerator *e;
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSDirectoryEnumerator *de;
|
||||
NSColorList *newList;
|
||||
|
||||
// Create the global array of color lists
|
||||
_gnustep_available_color_lists = [[NSMutableArray alloc] init];
|
||||
|
||||
/*
|
||||
* Load color lists found in standard paths into the array
|
||||
* FIXME: Check exactly where in the directory tree we should scan.
|
||||
*/
|
||||
e = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
|
||||
NSAllDomainsMask, YES) objectEnumerator];
|
||||
|
||||
while ((dir = (NSString *)[e nextObject]))
|
||||
{
|
||||
BOOL flag;
|
||||
|
||||
dir = [dir stringByAppendingPathComponent: @"Colors"];
|
||||
if (![fm fileExistsAtPath: dir isDirectory: &flag] || !flag)
|
||||
{
|
||||
// Only process existing directories
|
||||
continue;
|
||||
}
|
||||
|
||||
de = [fm enumeratorAtPath: dir];
|
||||
while ((file = [de nextObject]))
|
||||
{
|
||||
if ([[file pathExtension] isEqualToString: @"clr"])
|
||||
{
|
||||
NSString *name = [file stringByDeletingPathExtension];
|
||||
newList = [[NSColorList alloc] initWithName: name
|
||||
fromFile: [dir stringByAppendingPathComponent: file]];
|
||||
[_gnustep_available_color_lists addObject: newList];
|
||||
RELEASE(newList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// And create its access lock
|
||||
_gnustep_color_list_lock = [[NSLock alloc] init];
|
||||
}
|
||||
|
||||
/*
|
||||
* Getting All Color Lists
|
||||
*/
|
||||
|
@ -126,15 +96,11 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
{
|
||||
NSArray *a;
|
||||
|
||||
if (_gnustep_available_color_lists == nil)
|
||||
[NSColorList _loadAvailableColorLists];
|
||||
|
||||
// Serialize access to color list
|
||||
[_gnustep_color_list_lock lock];
|
||||
|
||||
a = [NSArray arrayWithArray: _gnustep_available_color_lists];
|
||||
|
||||
[_gnustep_color_list_lock unlock];
|
||||
[_colorListLock lock];
|
||||
[NSColorList _loadAvailableColorLists: nil];
|
||||
a = [NSArray arrayWithArray: _availableColorLists];
|
||||
[_colorListLock unlock];
|
||||
|
||||
return a;
|
||||
}
|
||||
|
@ -146,31 +112,25 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
{
|
||||
NSColorList *r;
|
||||
NSEnumerator *e;
|
||||
BOOL found = NO;
|
||||
|
||||
if (_gnustep_available_color_lists == nil)
|
||||
[NSColorList _loadAvailableColorLists];
|
||||
|
||||
// Serialize access to color list
|
||||
[_gnustep_color_list_lock lock];
|
||||
[_colorListLock lock];
|
||||
|
||||
e = [_gnustep_available_color_lists objectEnumerator];
|
||||
[NSColorList _loadAvailableColorLists: nil];
|
||||
e = [_availableColorLists objectEnumerator];
|
||||
|
||||
while ((r = (NSColorList *)[e nextObject]))
|
||||
while ((r = (NSColorList *)[e nextObject]) != nil)
|
||||
{
|
||||
if ([[r name] isEqualToString: name])
|
||||
{
|
||||
found = YES;
|
||||
RETAIN(r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[_gnustep_color_list_lock unlock];
|
||||
[_colorListLock unlock];
|
||||
|
||||
if (found)
|
||||
return r;
|
||||
else
|
||||
return nil;
|
||||
return AUTORELEASE(r);
|
||||
}
|
||||
|
||||
|
||||
|
@ -371,6 +331,8 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
key: (NSString *)key
|
||||
atIndex: (unsigned)location
|
||||
{
|
||||
NSNotification *n;
|
||||
|
||||
if (_is_editable == NO)
|
||||
[NSException raise: NSColorListNotEditableException
|
||||
format: @"Color list cannot be edited\n"];
|
||||
|
@ -379,13 +341,20 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
[_orderedColorKeys removeObject: key];
|
||||
[_orderedColorKeys insertObject: key atIndex: location];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: NSColorListChangedNotification
|
||||
object: self];
|
||||
n = [NSNotification notificationWithName: NSColorListChangedNotification
|
||||
object: self
|
||||
userInfo: nil];
|
||||
[[NSNotificationQueue defaultQueue]
|
||||
enqueueNotification: n
|
||||
postingStyle: NSPostASAP
|
||||
coalesceMask: NSNotificationCoalescingOnSender
|
||||
forModes: nil];
|
||||
}
|
||||
|
||||
- (void) removeColorWithKey: (NSString *)key
|
||||
{
|
||||
NSNotification *n;
|
||||
|
||||
if (_is_editable == NO)
|
||||
[NSException raise: NSColorListNotEditableException
|
||||
format: @"Color list cannot be edited\n"];
|
||||
|
@ -393,14 +362,21 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
[_colorDictionary removeObjectForKey: key];
|
||||
[_orderedColorKeys removeObject: key];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: NSColorListChangedNotification
|
||||
object: self];
|
||||
n = [NSNotification notificationWithName: NSColorListChangedNotification
|
||||
object: self
|
||||
userInfo: nil];
|
||||
[[NSNotificationQueue defaultQueue]
|
||||
enqueueNotification: n
|
||||
postingStyle: NSPostASAP
|
||||
coalesceMask: NSNotificationCoalescingOnSender
|
||||
forModes: nil];
|
||||
}
|
||||
|
||||
- (void) setColor: (NSColor *)aColor
|
||||
forKey: (NSString *)key
|
||||
{
|
||||
NSNotification *n;
|
||||
|
||||
if (_is_editable == NO)
|
||||
[NSException raise: NSColorListNotEditableException
|
||||
format: @"Color list cannot be edited\n"];
|
||||
|
@ -410,9 +386,14 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
if ([_orderedColorKeys containsObject: key] == NO)
|
||||
[_orderedColorKeys addObject: key];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: NSColorListChangedNotification
|
||||
object: self];
|
||||
n = [NSNotification notificationWithName: NSColorListChangedNotification
|
||||
object: self
|
||||
userInfo: nil];
|
||||
[[NSNotificationQueue defaultQueue]
|
||||
enqueueNotification: n
|
||||
postingStyle: NSPostASAP
|
||||
coalesceMask: NSNotificationCoalescingOnSender
|
||||
forModes: nil];
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -438,8 +419,7 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
* We need to initialize before saving, to avoid the new file being
|
||||
* counted as a different list thus making us appear twice
|
||||
*/
|
||||
if (_gnustep_available_color_lists == nil)
|
||||
[NSColorList _loadAvailableColorLists];
|
||||
[NSColorList _loadAvailableColorLists: nil];
|
||||
|
||||
if (path == nil || ([fm fileExistsAtPath: path isDirectory: &isDir] == NO))
|
||||
{
|
||||
|
@ -513,10 +493,10 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
|
||||
if (success && path_is_standard)
|
||||
{
|
||||
[_gnustep_color_list_lock lock];
|
||||
if ([_gnustep_available_color_lists containsObject: self] == NO)
|
||||
[_gnustep_available_color_lists addObject: self];
|
||||
[_gnustep_color_list_lock unlock];
|
||||
[_colorListLock lock];
|
||||
if ([_availableColorLists containsObject: self] == NO)
|
||||
[_availableColorLists addObject: self];
|
||||
[_colorListLock unlock];
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -532,12 +512,9 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
handler: nil];
|
||||
|
||||
// Remove the color list from the global list of colors
|
||||
if (_gnustep_available_color_lists == nil)
|
||||
[NSColorList _loadAvailableColorLists];
|
||||
|
||||
[_gnustep_color_list_lock lock];
|
||||
[_gnustep_available_color_lists removeObject: self];
|
||||
[_gnustep_color_list_lock unlock];
|
||||
[_colorListLock lock];
|
||||
[_availableColorLists removeObject: self];
|
||||
[_colorListLock unlock];
|
||||
|
||||
// Reset file name
|
||||
_fullFileName = nil;
|
||||
|
@ -562,3 +539,117 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
|
||||
@end
|
||||
|
||||
@implementation NSColorList (GNUstepPrivate)
|
||||
|
||||
+ (void) _loadAvailableColorLists: (NSNotification*)aNotification
|
||||
{
|
||||
[_colorListLock lock];
|
||||
/* FIXME ... we should ensure that we get housekeeping notifications */
|
||||
if (_availableColorLists != nil && aNotification == nil)
|
||||
{
|
||||
// Nothing to do ... already loaded
|
||||
[_colorListLock unlock];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *dir;
|
||||
NSString *file;
|
||||
NSEnumerator *e;
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSDirectoryEnumerator *de;
|
||||
NSColorList *newList;
|
||||
|
||||
if (_availableColorLists == nil)
|
||||
{
|
||||
// Create the global array of color lists
|
||||
_availableColorLists = [[NSMutableArray alloc] init];
|
||||
}
|
||||
else
|
||||
{
|
||||
[_availableColorLists removeAllObjects];
|
||||
}
|
||||
|
||||
/*
|
||||
* Keep any pre-loaded system color list.
|
||||
*/
|
||||
if (themeColorList != nil)
|
||||
{
|
||||
[_availableColorLists addObject: themeColorList];
|
||||
}
|
||||
|
||||
/*
|
||||
* Load color lists found in standard paths into the array
|
||||
* FIXME: Check exactly where in the directory tree we should scan.
|
||||
*/
|
||||
e = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
|
||||
NSAllDomainsMask, YES) objectEnumerator];
|
||||
|
||||
while ((dir = (NSString *)[e nextObject]))
|
||||
{
|
||||
BOOL flag;
|
||||
|
||||
dir = [dir stringByAppendingPathComponent: @"Colors"];
|
||||
if (![fm fileExistsAtPath: dir isDirectory: &flag] || !flag)
|
||||
{
|
||||
// Only process existing directories
|
||||
continue;
|
||||
}
|
||||
|
||||
de = [fm enumeratorAtPath: dir];
|
||||
while ((file = [de nextObject]))
|
||||
{
|
||||
if ([[file pathExtension] isEqualToString: @"clr"])
|
||||
{
|
||||
NSString *name;
|
||||
|
||||
name = [file stringByDeletingPathExtension];
|
||||
newList = [[NSColorList alloc] initWithName: name
|
||||
fromFile: [dir stringByAppendingPathComponent: file]];
|
||||
[_availableColorLists addObject: newList];
|
||||
RELEASE(newList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultSystemColorList != nil)
|
||||
{
|
||||
[_availableColorLists addObject: defaultSystemColorList];
|
||||
}
|
||||
[_colorListLock unlock];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void) _setDefaultSystemColorList: (NSColorList*)aList
|
||||
{
|
||||
[_colorListLock lock];
|
||||
if (defaultSystemColorList != aList)
|
||||
{
|
||||
if (defaultSystemColorList != nil
|
||||
&& [_availableColorLists lastObject] == defaultSystemColorList)
|
||||
{
|
||||
[_availableColorLists removeLastObject];
|
||||
}
|
||||
ASSIGN(defaultSystemColorList, aList);
|
||||
[_availableColorLists addObject: aList];
|
||||
}
|
||||
[_colorListLock unlock];
|
||||
}
|
||||
|
||||
+ (void) _setThemeSystemColorList: (NSColorList*)aList
|
||||
{
|
||||
[_colorListLock lock];
|
||||
if (themeColorList != aList)
|
||||
{
|
||||
if (themeColorList != nil && [_availableColorLists count] > 0
|
||||
&& [_availableColorLists objectAtIndex: 0] == themeColorList)
|
||||
{
|
||||
[_availableColorLists removeObjectAtIndex: 0];
|
||||
}
|
||||
ASSIGN(themeColorList, aList);
|
||||
[_availableColorLists insertObject: aList atIndex: 0];
|
||||
}
|
||||
[_colorListLock unlock];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -365,6 +365,7 @@
|
|||
- (void) drawRect: (NSRect)rect
|
||||
{
|
||||
NSGraphicsContext *ctxt = GSCurrentContext();
|
||||
GSDrawFunctions *theme = [GSDrawFunctions theme];
|
||||
int howMany = [_items count];
|
||||
int i;
|
||||
NSRect previousRect = NSMakeRect(0, 0, 0, 0);
|
||||
|
@ -378,18 +379,18 @@
|
|||
default:
|
||||
case NSTopTabsBezelBorder:
|
||||
aRect.size.height -= 16;
|
||||
[GSDrawFunctions drawButton: aRect : NSZeroRect];
|
||||
[theme drawButton: aRect withClip: NSZeroRect];
|
||||
break;
|
||||
|
||||
case NSBottomTabsBezelBorder:
|
||||
aRect.size.height -= 16;
|
||||
aRect.origin.y += 16;
|
||||
[GSDrawFunctions drawButton: aRect : rect];
|
||||
[theme drawButton: aRect withClip: rect];
|
||||
aRect.origin.y -= 16;
|
||||
break;
|
||||
|
||||
case NSNoTabsBezelBorder:
|
||||
[GSDrawFunctions drawButton: aRect : rect];
|
||||
[theme drawButton: aRect withClip: rect];
|
||||
break;
|
||||
|
||||
case NSNoTabsLineBorder:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue