mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-20 05:29:23 +00:00
AppKit: Add AppKit image names to CPImage
Add AppKit's NSImage names to CPImage. Resolve each system image on use against current theme and drawing appearance, so image follows theme switch and appearance. * CPAppearance.j: Add _CPThemeAttributeValueForAppearance() to return theme value for closest appearance, in best-match order, then value for every appearance. * CPColor.j: Resolve catalog colours through _CPThemeAttributeValueForAppearance(). * CPImage.j: - Add constant for each AppKit NSImageName except Touch Bar names, with CP in place of NS; keep string of CPImageNameColorPanel for existing cibs. - Add theme class image with one attribute per system image; derive attribute name from image name in kebab case (CPAddTemplate gives add-template). - Load theme attributes in each initialiser, as CPColor and CPFont do. - Add _CPSystemImage; share one instance per name, resolve image on each use, forward CPImage and subclass methods to resolved image, and repost its load notification. - Fall back from +imageNamed: to system image; take default colour panel images from AppKit resources. - Archive system image by name; decode name to shared instance. * _CPObject+Theme.j: Replace CPResponder.j import with forward declaration; break import cycle through CPCursor.j and CPImage.j. * CGContext.j: Take image element from -image in CGContextDrawImage, so system images draw. * _CPCibCustomResource.j: Resolve built-in image names to system images; remove button bar image map and its CPButtonBar and CPTheme dependencies; keep nil for CPMenuCheckmark and CPMenuMixedState. * NSCustomResource.j: Map each IB built-in image name with matching system image by prefix; alias NSColorPanel and NSToolbarShowColors to CPImageNameColorPanel; raise for unsupported names. * Aristo and Aristo2 ThemeDescriptors.j: Give add, remove and action template images as CPImage theme values; share button bar images between CPButtonBar and CPImage through ButtonBarImage functions; exclude themedImage from showcase. * Aristo3 ThemeDescriptors.j: Add A3MaskIcon() for SVG mask icons and replace inline button bar icon definitions with it; give add, remove and action template images as CPImage theme values; exclude themedImage from showcase. * CPImageNamedTest.j: Add tests for names, shared instances, defaults, theme values per appearance, theme switch, CSS and subclass forwarding, load notification, size override, archiving and cib resources.
This commit is contained in:
1 parent
ded1ac267f
commit
dd8ead0d84
11 files changed
+1063
-193
No files matched your search
@@ -151,6 +151,33 @@ function _CPThemeStateForAppearanceName(aName)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the value that the theme attribute anAttribute holds for anAppearance: the value for
|
||||
the closest appearance, in the order of -bestMatchFromAppearancesWithNames:; then the value
|
||||
for every appearance; or nil when anAttribute holds neither. System colours and system
|
||||
images take their theme values this way.
|
||||
*/
|
||||
function _CPThemeAttributeValueForAppearance(anAttribute, anAppearance)
|
||||
{
|
||||
var values = [anAttribute values];
|
||||
|
||||
if (!values)
|
||||
return nil;
|
||||
|
||||
var matchingNames = _CPAppearanceMatchingNames([anAppearance name]);
|
||||
|
||||
for (var i = 0, count = matchingNames.length; i < count; i++)
|
||||
{
|
||||
var state = _CPThemeStateForAppearanceName(matchingNames[i]),
|
||||
value = state ? [values objectForKey:String(state)] : nil;
|
||||
|
||||
if (value)
|
||||
return value;
|
||||
}
|
||||
|
||||
return [values objectForKey:String(CPThemeStateNormal)];
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
@ingroup appkit
|
||||
|
||||
+6
-23
@@ -170,34 +170,17 @@ function _CPThemeAttributeForSystemColorName(aName)
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the value of the system colour aName for anAppearance. The current theme's value
|
||||
for the closest appearance comes first, in the order of
|
||||
-[CPAppearance bestMatchFromAppearancesWithNames:]; then the theme's value for every
|
||||
appearance; then the value in _CPSystemColorDefaults.
|
||||
Returns the value of the system colour aName for anAppearance: the current theme's value for
|
||||
anAppearance (see _CPThemeAttributeValueForAppearance), then the value in
|
||||
_CPSystemColorDefaults.
|
||||
*/
|
||||
function _CPSystemColorValue(aName, anAppearance)
|
||||
{
|
||||
var attribute = [[CPTheme defaultTheme] attributeWithName:_CPThemeAttributeForSystemColorName(aName) forClass:[CPColor defaultThemeClass]],
|
||||
values = [attribute values];
|
||||
themeValue = _CPThemeAttributeValueForAppearance(attribute, anAppearance);
|
||||
|
||||
if (values)
|
||||
{
|
||||
var matchingNames = _CPAppearanceMatchingNames([anAppearance name]);
|
||||
|
||||
for (var i = 0, count = matchingNames.length; i < count; i++)
|
||||
{
|
||||
var state = _CPThemeStateForAppearanceName(matchingNames[i]),
|
||||
value = state ? [values objectForKey:String(state)] : nil;
|
||||
|
||||
if (value)
|
||||
return value;
|
||||
}
|
||||
|
||||
var normalValue = [values objectForKey:String(CPThemeStateNormal)];
|
||||
|
||||
if (normalValue)
|
||||
return normalValue;
|
||||
}
|
||||
if (themeValue)
|
||||
return themeValue;
|
||||
|
||||
var defaultValue = _CPSystemColorDefaultValues[aName];
|
||||
|
||||
|
||||
+501
-18
@@ -29,11 +29,15 @@
|
||||
@import <Foundation/CPKeyedArchiver.j>
|
||||
@import <Foundation/CPKeyedUnarchiver.j>
|
||||
|
||||
@import "_CPObject+Theme.j"
|
||||
@import "CGGeometry.j"
|
||||
@import "CPAppearance.j"
|
||||
@import "CPCompatibility.j"
|
||||
@import "CPGraphicsContext.j"
|
||||
@import "CPTheme.j"
|
||||
|
||||
@class CPColor
|
||||
@class _CPSystemImage
|
||||
@global document
|
||||
|
||||
@protocol CPImageDelegate <CPObject>
|
||||
@@ -59,16 +63,154 @@ CPImageLoadStatusReadError = 6;
|
||||
|
||||
CPImageDidLoadNotification = @"CPImageDidLoadNotification";
|
||||
|
||||
// Image Names
|
||||
CPImageNameColorPanel = @"CPImageNameColorPanel";
|
||||
CPImageNameColorPanelHighlighted = @"CPImageNameColorPanelHighlighted";
|
||||
/*
|
||||
System image names. Each constant has the name of an AppKit NSImageName constant with CP in
|
||||
place of NS, and AppKit's string with CP in place of NS, so that nib2cib maps an image name
|
||||
in a XIB by replacing the prefix. CPImageNameColorPanel keeps the string that it had before
|
||||
Cappuccino took AppKit's names, because existing cibs hold that string; nib2cib maps
|
||||
NSColorPanel to it. CPImageNameColorPanelHighlighted is Cappuccino's own name, for the
|
||||
highlighted image of the Colors toolbar item. AppKit's Touch Bar names are absent, because
|
||||
Cappuccino has no touch bar.
|
||||
*/
|
||||
CPImageNameActionTemplate = @"CPActionTemplate";
|
||||
CPImageNameAddTemplate = @"CPAddTemplate";
|
||||
CPImageNameAdvanced = @"CPAdvanced";
|
||||
CPImageNameApplicationIcon = @"CPApplicationIcon";
|
||||
CPImageNameBluetoothTemplate = @"CPBluetoothTemplate";
|
||||
CPImageNameBonjour = @"CPBonjour";
|
||||
CPImageNameBookmarksTemplate = @"CPBookmarksTemplate";
|
||||
CPImageNameCaution = @"CPCaution";
|
||||
CPImageNameColumnViewTemplate = @"CPColumnViewTemplate";
|
||||
CPImageNameComputer = @"CPComputer";
|
||||
CPImageNameDotMac = @"CPDotMac";
|
||||
CPImageNameEnterFullScreenTemplate = @"CPEnterFullScreenTemplate";
|
||||
CPImageNameEveryone = @"CPEveryone";
|
||||
CPImageNameExitFullScreenTemplate = @"CPExitFullScreenTemplate";
|
||||
CPImageNameFlowViewTemplate = @"CPFlowViewTemplate";
|
||||
CPImageNameFolder = @"CPFolder";
|
||||
CPImageNameFolderBurnable = @"CPFolderBurnable";
|
||||
CPImageNameFolderSmart = @"CPFolderSmart";
|
||||
CPImageNameFollowLinkFreestandingTemplate = @"CPFollowLinkFreestandingTemplate";
|
||||
CPImageNameFontPanel = @"CPFontPanel";
|
||||
CPImageNameGoBackTemplate = @"CPGoBackTemplate";
|
||||
CPImageNameGoForwardTemplate = @"CPGoForwardTemplate";
|
||||
CPImageNameGoLeftTemplate = @"CPGoLeftTemplate";
|
||||
CPImageNameGoRightTemplate = @"CPGoRightTemplate";
|
||||
CPImageNameHomeTemplate = @"CPHomeTemplate";
|
||||
CPImageNameIChatTheaterTemplate = @"CPIChatTheaterTemplate";
|
||||
CPImageNameIconViewTemplate = @"CPIconViewTemplate";
|
||||
CPImageNameInfo = @"CPInfo";
|
||||
CPImageNameInvalidDataFreestandingTemplate = @"CPInvalidDataFreestandingTemplate";
|
||||
CPImageNameLeftFacingTriangleTemplate = @"CPLeftFacingTriangleTemplate";
|
||||
CPImageNameListViewTemplate = @"CPListViewTemplate";
|
||||
CPImageNameLockLockedTemplate = @"CPLockLockedTemplate";
|
||||
CPImageNameLockUnlockedTemplate = @"CPLockUnlockedTemplate";
|
||||
CPImageNameMenuMixedStateTemplate = @"CPMenuMixedStateTemplate";
|
||||
CPImageNameMenuOnStateTemplate = @"CPMenuOnStateTemplate";
|
||||
CPImageNameMobileMe = @"CPMobileMe";
|
||||
CPImageNameMultipleDocuments = @"CPMultipleDocuments";
|
||||
CPImageNameNetwork = @"CPNetwork";
|
||||
CPImageNamePathTemplate = @"CPPathTemplate";
|
||||
CPImageNamePreferencesGeneral = @"CPPreferencesGeneral";
|
||||
CPImageNameQuickLookTemplate = @"CPQuickLookTemplate";
|
||||
CPImageNameRefreshFreestandingTemplate = @"CPRefreshFreestandingTemplate";
|
||||
CPImageNameRefreshTemplate = @"CPRefreshTemplate";
|
||||
CPImageNameRemoveTemplate = @"CPRemoveTemplate";
|
||||
CPImageNameRevealFreestandingTemplate = @"CPRevealFreestandingTemplate";
|
||||
CPImageNameRightFacingTriangleTemplate = @"CPRightFacingTriangleTemplate";
|
||||
CPImageNameShareTemplate = @"CPShareTemplate";
|
||||
CPImageNameSlideshowTemplate = @"CPSlideshowTemplate";
|
||||
CPImageNameSmartBadgeTemplate = @"CPSmartBadgeTemplate";
|
||||
CPImageNameStatusAvailable = @"CPStatusAvailable";
|
||||
CPImageNameStatusNone = @"CPStatusNone";
|
||||
CPImageNameStatusPartiallyAvailable = @"CPStatusPartiallyAvailable";
|
||||
CPImageNameStatusUnavailable = @"CPStatusUnavailable";
|
||||
CPImageNameStopProgressFreestandingTemplate = @"CPStopProgressFreestandingTemplate";
|
||||
CPImageNameStopProgressTemplate = @"CPStopProgressTemplate";
|
||||
CPImageNameTrashEmpty = @"CPTrashEmpty";
|
||||
CPImageNameTrashFull = @"CPTrashFull";
|
||||
CPImageNameUser = @"CPUser";
|
||||
CPImageNameUserAccounts = @"CPUserAccounts";
|
||||
CPImageNameUserGroup = @"CPUserGroup";
|
||||
CPImageNameUserGuest = @"CPUserGuest";
|
||||
CPImageNameColorPanel = @"CPImageNameColorPanel";
|
||||
CPImageNameColorPanelHighlighted = @"CPImageNameColorPanelHighlighted";
|
||||
|
||||
var imagesForNames = { },
|
||||
AppKitImageForNames = { },
|
||||
ImageDescriptionFormat = "%s {\n filename: \"%s\",\n size: { width:%f, height:%f }\n}";
|
||||
ImageDescriptionFormat = "%s {\n filename: \"%s\",\n size: { width:%f, height:%f }\n}",
|
||||
CPImageSystemImageNameKey = @"CPImageSystemImageNameKey",
|
||||
|
||||
AppKitImageForNames[CPImageNameColorPanel] = CGSizeMake(26.0, 29.0);
|
||||
AppKitImageForNames[CPImageNameColorPanelHighlighted] = CGSizeMake(26.0, 29.0);
|
||||
/*
|
||||
The system image names, each with its default image: the AppKit resource that holds the
|
||||
image, with its size, or null when only a theme gives the image.
|
||||
*/
|
||||
_CPSystemImageDefaults = {
|
||||
"CPActionTemplate": null,
|
||||
"CPAddTemplate": null,
|
||||
"CPAdvanced": null,
|
||||
"CPApplicationIcon": null,
|
||||
"CPBluetoothTemplate": null,
|
||||
"CPBonjour": null,
|
||||
"CPBookmarksTemplate": null,
|
||||
"CPCaution": null,
|
||||
"CPColumnViewTemplate": null,
|
||||
"CPComputer": null,
|
||||
"CPDotMac": null,
|
||||
"CPEnterFullScreenTemplate": null,
|
||||
"CPEveryone": null,
|
||||
"CPExitFullScreenTemplate": null,
|
||||
"CPFlowViewTemplate": null,
|
||||
"CPFolder": null,
|
||||
"CPFolderBurnable": null,
|
||||
"CPFolderSmart": null,
|
||||
"CPFollowLinkFreestandingTemplate": null,
|
||||
"CPFontPanel": null,
|
||||
"CPGoBackTemplate": null,
|
||||
"CPGoForwardTemplate": null,
|
||||
"CPGoLeftTemplate": null,
|
||||
"CPGoRightTemplate": null,
|
||||
"CPHomeTemplate": null,
|
||||
"CPIChatTheaterTemplate": null,
|
||||
"CPIconViewTemplate": null,
|
||||
"CPInfo": null,
|
||||
"CPInvalidDataFreestandingTemplate": null,
|
||||
"CPLeftFacingTriangleTemplate": null,
|
||||
"CPListViewTemplate": null,
|
||||
"CPLockLockedTemplate": null,
|
||||
"CPLockUnlockedTemplate": null,
|
||||
"CPMenuMixedStateTemplate": null,
|
||||
"CPMenuOnStateTemplate": null,
|
||||
"CPMobileMe": null,
|
||||
"CPMultipleDocuments": null,
|
||||
"CPNetwork": null,
|
||||
"CPPathTemplate": null,
|
||||
"CPPreferencesGeneral": null,
|
||||
"CPQuickLookTemplate": null,
|
||||
"CPRefreshFreestandingTemplate": null,
|
||||
"CPRefreshTemplate": null,
|
||||
"CPRemoveTemplate": null,
|
||||
"CPRevealFreestandingTemplate": null,
|
||||
"CPRightFacingTriangleTemplate": null,
|
||||
"CPShareTemplate": null,
|
||||
"CPSlideshowTemplate": null,
|
||||
"CPSmartBadgeTemplate": null,
|
||||
"CPStatusAvailable": null,
|
||||
"CPStatusNone": null,
|
||||
"CPStatusPartiallyAvailable": null,
|
||||
"CPStatusUnavailable": null,
|
||||
"CPStopProgressFreestandingTemplate": null,
|
||||
"CPStopProgressTemplate": null,
|
||||
"CPTrashEmpty": null,
|
||||
"CPTrashFull": null,
|
||||
"CPUser": null,
|
||||
"CPUserAccounts": null,
|
||||
"CPUserGroup": null,
|
||||
"CPUserGuest": null,
|
||||
"CPImageNameColorPanel": ["CPImage/CPImageNameColorPanel.png", 26.0, 29.0],
|
||||
"CPImageNameColorPanelHighlighted": ["CPImage/CPImageNameColorPanelHighlighted.png", 26.0, 29.0]
|
||||
},
|
||||
_CPSystemImages = {},
|
||||
_CPSystemImageDefaultValues = {};
|
||||
|
||||
/*!
|
||||
Returns a resource image with a relative path and size
|
||||
@@ -113,6 +255,52 @@ function CPAppKitImage(aFilename, aSize)
|
||||
return CPImageInBundle(aFilename, aSize, [CPBundle bundleForClass:[CPView class]]);
|
||||
}
|
||||
|
||||
/// @cond IGNORE
|
||||
|
||||
/*
|
||||
Returns YES when aName is the name of a system image.
|
||||
*/
|
||||
function _CPImageIsSystemImageName(aName)
|
||||
{
|
||||
return _CPSystemImageDefaults.hasOwnProperty(aName);
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the theme attribute of CPImage that holds a theme's values for the system image
|
||||
aName: the name without CP, in lower case with words joined by hyphens (CPAddTemplate is
|
||||
"add-template"). Cappuccino's own names also drop ImageName (CPImageNameColorPanel is
|
||||
"color-panel").
|
||||
*/
|
||||
function _CPThemeAttributeForSystemImageName(aName)
|
||||
{
|
||||
return aName.replace(/^CP(ImageName)?/, "").replace(/([A-Z])/g, "-$1").toLowerCase().substring(1);
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the image for the system image aName in anAppearance: the current theme's value for
|
||||
anAppearance (see _CPThemeAttributeValueForAppearance), then the default image in
|
||||
_CPSystemImageDefaults, or nil when the system image has no default.
|
||||
*/
|
||||
function _CPSystemImageValue(aName, anAppearance)
|
||||
{
|
||||
var attribute = [[CPTheme defaultTheme] attributeWithName:_CPThemeAttributeForSystemImageName(aName) forClass:[CPImage defaultThemeClass]],
|
||||
themeValue = _CPThemeAttributeValueForAppearance(attribute, anAppearance);
|
||||
|
||||
if (themeValue)
|
||||
return themeValue;
|
||||
|
||||
if (!_CPSystemImageDefaultValues.hasOwnProperty(aName))
|
||||
{
|
||||
var resource = _CPSystemImageDefaults[aName];
|
||||
|
||||
_CPSystemImageDefaultValues[aName] = resource ? CPAppKitImage(resource[0], CGSizeMake(resource[1], resource[2])) : nil;
|
||||
}
|
||||
|
||||
return _CPSystemImageDefaultValues[aName];
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
|
||||
/*!
|
||||
@ingroup appkit
|
||||
@class CPImage
|
||||
@@ -134,7 +322,7 @@ function CPAppKitImage(aFilename, aSize)
|
||||
Called when the image loading was aborted.
|
||||
@param image the image that was aborted
|
||||
*/
|
||||
@implementation CPImage : CPObject
|
||||
@implementation CPImage : CPObject <CPTheme>
|
||||
{
|
||||
CGSize _size;
|
||||
CPString _filename;
|
||||
@@ -147,6 +335,28 @@ function CPAppKitImage(aFilename, aSize)
|
||||
Image _image;
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
// MARK: Theming
|
||||
|
||||
+ (CPString)defaultThemeClass
|
||||
{
|
||||
return "image";
|
||||
}
|
||||
|
||||
/*
|
||||
CPImage has one theme attribute for each system image, which holds the theme's values for
|
||||
that image (see _CPSystemImageValue).
|
||||
*/
|
||||
+ (CPDictionary)themeAttributes
|
||||
{
|
||||
var attributes = @{};
|
||||
|
||||
for (var imageName in _CPSystemImageDefaults)
|
||||
[attributes setObject:[CPNull null] forKey:_CPThemeAttributeForSystemImageName(imageName)];
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
return [self initByReferencingFile:@"" size:CGSizeMake(-1, -1)];
|
||||
@@ -174,11 +384,26 @@ function CPAppKitImage(aFilename, aSize)
|
||||
_size = CGSizeMakeCopy(aSize);
|
||||
_filename = aFilename;
|
||||
_loadStatus = CPImageLoadStatusInitialized;
|
||||
|
||||
[self _initTheming];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
Setting a theme value on a CPImage raised "CPImage does not contain theme attribute", because
|
||||
an object that is not a view loads its theme attributes only when its initialiser asks for
|
||||
them. A theme records its system images on a CPImage (see +themeAttributes), so each CPImage
|
||||
initialiser loads them, as the initialisers of CPColor and CPFont do.
|
||||
*/
|
||||
- (void)_initTheming
|
||||
{
|
||||
_theme = [CPTheme defaultTheme];
|
||||
_themeState = CPThemeStateNormal;
|
||||
[self _loadThemeAttributes];
|
||||
}
|
||||
|
||||
/*!
|
||||
Initializes the image. Loads the specified image into memory.
|
||||
@param aFilename the image to load
|
||||
@@ -281,6 +506,15 @@ function CPAppKitImage(aFilename, aSize)
|
||||
return CGSizeMakeCopy(_size);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the image with the name \c aName: an image registered under that name with
|
||||
-setName:, or else the system image of that name, such as CPImageNameAddTemplate. A system
|
||||
image takes its picture from the current theme and the drawing appearance each time it is
|
||||
used, so it follows a theme switch. +imageNamed: returns one shared instance for each
|
||||
system image.
|
||||
@param aName the name of the image
|
||||
@return the image, or \c nil when no image has that name
|
||||
*/
|
||||
+ (id)imageNamed:(CPString)aName
|
||||
{
|
||||
var image = imagesForNames[aName];
|
||||
@@ -288,21 +522,24 @@ function CPAppKitImage(aFilename, aSize)
|
||||
if (image)
|
||||
return image;
|
||||
|
||||
var imageOrSize = AppKitImageForNames[aName];
|
||||
return [self _systemImageNamed:aName];
|
||||
}
|
||||
|
||||
if (!imageOrSize)
|
||||
/*
|
||||
Returns the shared system image with the name aName, or nil when aName is not a system
|
||||
image name.
|
||||
*/
|
||||
+ (CPImage)_systemImageNamed:(CPString)aName
|
||||
{
|
||||
if (!_CPImageIsSystemImageName(aName))
|
||||
return nil;
|
||||
|
||||
if (!imageOrSize.isa)
|
||||
{
|
||||
imageOrSize = CPAppKitImage("CPImage/" + aName + ".png", imageOrSize);
|
||||
var image = _CPSystemImages[aName];
|
||||
|
||||
[imageOrSize setName:aName];
|
||||
if (!image)
|
||||
image = _CPSystemImages[aName] = [[_CPSystemImage alloc] _initWithSystemImageName:aName];
|
||||
|
||||
AppKitImageForNames[aName] = imageOrSize;
|
||||
}
|
||||
|
||||
return imageOrSize;
|
||||
return image;
|
||||
}
|
||||
|
||||
- (BOOL)setName:(CPString)aName
|
||||
@@ -607,6 +844,8 @@ function CPAppKitImage(aFilename, aSize)
|
||||
|
||||
if (self)
|
||||
{
|
||||
[self _initTheming];
|
||||
|
||||
_size = CGSizeMakeCopy(aSize);
|
||||
_filename = @"CSS image";
|
||||
_loadStatus = CPImageLoadStatusCompleted;
|
||||
@@ -749,6 +988,9 @@ var CPImageCSSDictionaryKey = @"CPImageCSSDictionaryKey",
|
||||
*/
|
||||
- (id)initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
if ([aCoder containsValueForKey:CPImageSystemImageNameKey])
|
||||
return [CPImage _systemImageNamed:[aCoder decodeObjectForKey:CPImageSystemImageNameKey]];
|
||||
|
||||
if ([aCoder containsValueForKey:CPImageCSSDictionaryKey])
|
||||
return [self initWithCSSDictionary:[aCoder decodeObjectForKey:CPImageCSSDictionaryKey] beforeDictionary:[aCoder decodeObjectForKey:CPImageCSSBeforeDictionaryKey] afterDictionary:[aCoder decodeObjectForKey:CPImageCSSAfterDictionaryKey] size:[aCoder decodeSizeForKey:@"CPSize"]];
|
||||
else
|
||||
@@ -1126,3 +1368,244 @@ var CPNinePartImageImageSlicesKey = @"CPNinePartImageImageSlicesKey";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// MARK: -
|
||||
|
||||
/*
|
||||
A system image keeps its name and resolves to an image each time it is used: the current
|
||||
theme's image for the drawing appearance, or the default image (see _CPSystemImageValue). So
|
||||
it follows a theme switch and the appearance in which a view draws. Each CPImage method
|
||||
forwards to the resolved image; the methods of CPImage subclasses forward through
|
||||
-forwardingTargetForSelector:. When there is no image, a system image is an empty, loaded
|
||||
image of size zero.
|
||||
*/
|
||||
@implementation _CPSystemImage : CPImage
|
||||
{
|
||||
CPString _systemImageName;
|
||||
CGSize _sizeOverride;
|
||||
CPImage _observedImage;
|
||||
}
|
||||
|
||||
- (id)_initWithSystemImageName:(CPString)aName
|
||||
{
|
||||
self = [super initByReferencingFile:@"" size:CGSizeMakeZero()];
|
||||
|
||||
if (self)
|
||||
_systemImageName = aName;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CPImage)_resolvedImage
|
||||
{
|
||||
return _CPSystemImageValue(_systemImageName, [CPAppearance currentDrawingAppearance]);
|
||||
}
|
||||
|
||||
// MARK: Name
|
||||
|
||||
- (CPString)name
|
||||
{
|
||||
return _systemImageName;
|
||||
}
|
||||
|
||||
/*
|
||||
The name of a system image is fixed.
|
||||
*/
|
||||
- (BOOL)setName:(CPString)aName
|
||||
{
|
||||
return aName === _systemImageName;
|
||||
}
|
||||
|
||||
// MARK: Forwarding
|
||||
|
||||
- (CPString)filename
|
||||
{
|
||||
var resolvedImage = [self _resolvedImage];
|
||||
|
||||
return resolvedImage ? [resolvedImage filename] : @"";
|
||||
}
|
||||
|
||||
- (CPData)data
|
||||
{
|
||||
return [[self _resolvedImage] data];
|
||||
}
|
||||
|
||||
/*
|
||||
A size set with -setSize: replaces the size of the resolved image, as for any shared named
|
||||
image.
|
||||
*/
|
||||
- (void)setSize:(CGSize)aSize
|
||||
{
|
||||
_sizeOverride = CGSizeMakeCopy(aSize);
|
||||
}
|
||||
|
||||
- (CGSize)size
|
||||
{
|
||||
if (_sizeOverride)
|
||||
return CGSizeMakeCopy(_sizeOverride);
|
||||
|
||||
var resolvedImage = [self _resolvedImage];
|
||||
|
||||
return resolvedImage ? [resolvedImage size] : CGSizeMakeZero();
|
||||
}
|
||||
|
||||
- (Image)image
|
||||
{
|
||||
return [[self _resolvedImage] image];
|
||||
}
|
||||
|
||||
- (unsigned)loadStatus
|
||||
{
|
||||
var resolvedImage = [self _resolvedImage];
|
||||
|
||||
if (!resolvedImage)
|
||||
return CPImageLoadStatusCompleted;
|
||||
|
||||
[self _observeImage:resolvedImage];
|
||||
|
||||
return [resolvedImage loadStatus];
|
||||
}
|
||||
|
||||
- (void)load
|
||||
{
|
||||
var resolvedImage = [self _resolvedImage];
|
||||
|
||||
[self _observeImage:resolvedImage];
|
||||
[resolvedImage load];
|
||||
}
|
||||
|
||||
- (BOOL)isSingleImage
|
||||
{
|
||||
var resolvedImage = [self _resolvedImage];
|
||||
|
||||
return resolvedImage ? [resolvedImage isSingleImage] : YES;
|
||||
}
|
||||
|
||||
- (BOOL)isThreePartImage
|
||||
{
|
||||
return !![[self _resolvedImage] isThreePartImage];
|
||||
}
|
||||
|
||||
- (BOOL)isNinePartImage
|
||||
{
|
||||
return !![[self _resolvedImage] isNinePartImage];
|
||||
}
|
||||
|
||||
- (BOOL)isMaterialIconImage
|
||||
{
|
||||
return !![[self _resolvedImage] isMaterialIconImage];
|
||||
}
|
||||
|
||||
- (BOOL)isCSSBased
|
||||
{
|
||||
return !![[self _resolvedImage] isCSSBased];
|
||||
}
|
||||
|
||||
- (BOOL)hasCSSDictionary
|
||||
{
|
||||
return !![[self _resolvedImage] hasCSSDictionary];
|
||||
}
|
||||
|
||||
- (BOOL)hasCSSBeforeDictionary
|
||||
{
|
||||
return !![[self _resolvedImage] hasCSSBeforeDictionary];
|
||||
}
|
||||
|
||||
- (BOOL)hasCSSAfterDictionary
|
||||
{
|
||||
return !![[self _resolvedImage] hasCSSAfterDictionary];
|
||||
}
|
||||
|
||||
- (CPDictionary)cssDictionary
|
||||
{
|
||||
return [[self _resolvedImage] cssDictionary];
|
||||
}
|
||||
|
||||
- (CPDictionary)cssBeforeDictionary
|
||||
{
|
||||
return [[self _resolvedImage] cssBeforeDictionary];
|
||||
}
|
||||
|
||||
- (CPDictionary)cssAfterDictionary
|
||||
{
|
||||
return [[self _resolvedImage] cssAfterDictionary];
|
||||
}
|
||||
|
||||
- (DOMElement)applyCSSImageForView:(CPView)aView onDOMElement:(DOMElement)aDOMElement styleNode:(DOMElement)aStyleNode previousState:(CPArrayRef)aPreviousStateRef
|
||||
{
|
||||
return [[self _resolvedImage] applyCSSImageForView:aView onDOMElement:aDOMElement styleNode:aStyleNode previousState:aPreviousStateRef];
|
||||
}
|
||||
|
||||
- (BOOL)_shouldBeResized
|
||||
{
|
||||
return !![[self _resolvedImage] _shouldBeResized];
|
||||
}
|
||||
|
||||
- (void)drawAtPoint:(CGPoint)point fromRect:(CPRect)fromRect operation:(CGBlendMode)op fraction:(float)delta
|
||||
{
|
||||
[[self _resolvedImage] drawAtPoint:point fromRect:fromRect operation:op fraction:delta];
|
||||
}
|
||||
|
||||
- (BOOL)respondsToSelector:(SEL)aSelector
|
||||
{
|
||||
return [super respondsToSelector:aSelector] || [[self _resolvedImage] respondsToSelector:aSelector];
|
||||
}
|
||||
|
||||
- (id)forwardingTargetForSelector:(SEL)aSelector
|
||||
{
|
||||
var resolvedImage = [self _resolvedImage];
|
||||
|
||||
return [resolvedImage respondsToSelector:aSelector] ? resolvedImage : [super forwardingTargetForSelector:aSelector];
|
||||
}
|
||||
|
||||
- (CPString)description
|
||||
{
|
||||
return [CPString stringWithFormat:@"System image %@: %@", _systemImageName, [[self _resolvedImage] description]];
|
||||
}
|
||||
|
||||
// MARK: Loading
|
||||
|
||||
/*
|
||||
A view that finds the image not yet loaded waits for CPImageDidLoadNotification from the
|
||||
system image, so the system image posts it when the resolved image loads.
|
||||
*/
|
||||
- (void)_observeImage:(CPImage)anImage
|
||||
{
|
||||
if (!anImage || anImage === _observedImage || [anImage loadStatus] === CPImageLoadStatusCompleted)
|
||||
return;
|
||||
|
||||
var center = [CPNotificationCenter defaultCenter];
|
||||
|
||||
if (_observedImage)
|
||||
[center removeObserver:self name:CPImageDidLoadNotification object:_observedImage];
|
||||
|
||||
_observedImage = anImage;
|
||||
|
||||
[center addObserver:self selector:@selector(_observedImageDidLoad:) name:CPImageDidLoadNotification object:anImage];
|
||||
}
|
||||
|
||||
- (void)_observedImageDidLoad:(CPNotification)aNotification
|
||||
{
|
||||
[[CPNotificationCenter defaultCenter] removeObserver:self name:CPImageDidLoadNotification object:_observedImage];
|
||||
|
||||
_observedImage = nil;
|
||||
|
||||
[self _imageDidLoad];
|
||||
}
|
||||
|
||||
// MARK: Coding
|
||||
|
||||
- (Class)classForKeyedArchiver
|
||||
{
|
||||
return [CPImage class];
|
||||
}
|
||||
|
||||
/*
|
||||
A system image is archived by its name, so that it decodes to the shared system image.
|
||||
*/
|
||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
[aCoder encodeObject:_systemImageName forKey:CPImageSystemImageNameKey];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -28,16 +28,12 @@
|
||||
|
||||
@import "CPCompatibility.j"
|
||||
@import "CPImage.j"
|
||||
@import "CPTheme.j"
|
||||
|
||||
@class CPButtonBar
|
||||
@class CPView
|
||||
|
||||
var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey",
|
||||
_CPCibCustomResourceResourceNameKey = @"_CPCibCustomResourceResourceNameKey",
|
||||
_CPCibCustomResourcePropertiesKey = @"_CPCibCustomResourcePropertiesKey",
|
||||
|
||||
_CPCibCustomResourceTemplateImageMap = nil;
|
||||
_CPCibCustomResourcePropertiesKey = @"_CPCibCustomResourcePropertiesKey";
|
||||
|
||||
|
||||
@implementation _CPCibCustomResource : CPObject
|
||||
@@ -48,19 +44,6 @@ var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey",
|
||||
CPBundle _bundle;
|
||||
}
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
if (self !== [_CPCibCustomResource class])
|
||||
return;
|
||||
|
||||
_CPCibCustomResourceTemplateImageMap = @{
|
||||
"CPAddTemplate": "button-image-plus",
|
||||
"CPRemoveTemplate": "button-image-minus",
|
||||
"CPActionTemplate": "button-image-action",
|
||||
"CPMenuCheckmark": [CPNull null],
|
||||
"CPMenuMixedState": [CPNull null]
|
||||
};
|
||||
}
|
||||
+ (id)imageResourceWithName:(CPString)aResourceName size:(CGSize)aSize
|
||||
{
|
||||
return [[self alloc] initWithClassName:@"CPImage" resourceName:aResourceName properties:@{ @"size": aSize }];
|
||||
@@ -127,18 +110,20 @@ var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey",
|
||||
return [CPImage imageWithMaterialIconNamed:iconName size:CGSizeMake(16,16)];
|
||||
}
|
||||
|
||||
var templateImage = [_CPCibCustomResourceTemplateImageMap objectForKey:_resourceName];
|
||||
|
||||
// Default checkmarks are handled by the theme so just let it be nil
|
||||
if (templateImage !== [CPNull null])
|
||||
{
|
||||
if (templateImage)
|
||||
return [[CPTheme defaultTheme] valueForAttributeWithName:templateImage forClass:[CPButtonBar class]];
|
||||
else
|
||||
return [self imageFromCoder:aCoder];
|
||||
}
|
||||
else
|
||||
/*
|
||||
nib2cib writes CPMenuCheckmark and CPMenuMixedState for the default state images
|
||||
of a menu item (NSMenuCheckmark and NSMenuMixedState in the XIB). The menu item
|
||||
theme draws the default state images, so these names give nil.
|
||||
*/
|
||||
if (_resourceName === @"CPMenuCheckmark" || _resourceName === @"CPMenuMixedState")
|
||||
return nil;
|
||||
|
||||
var systemImage = [CPImage _systemImageNamed:_resourceName];
|
||||
|
||||
if (systemImage)
|
||||
return systemImage;
|
||||
|
||||
return [self imageFromCoder:aCoder];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
||||
@@ -1332,7 +1332,12 @@ CGContextConcatCTM = function(aContext, anAffineTransform)
|
||||
|
||||
function CGContextDrawImage(aContext, aRect, anImage)
|
||||
{
|
||||
aContext.drawImage(anImage._image, CGRectGetMinX(aRect), CGRectGetMinY(aRect), CGRectGetWidth(aRect), CGRectGetHeight(aRect));
|
||||
/*
|
||||
The image element comes from -image, not from the _image instance variable. A system
|
||||
image (_CPSystemImage) has no element of its own, so _image drew nothing for it; -image
|
||||
returns the element of the image that the system image resolves to.
|
||||
*/
|
||||
aContext.drawImage([anImage image], CGRectGetMinX(aRect), CGRectGetMinY(aRect), CGRectGetWidth(aRect), CGRectGetHeight(aRect));
|
||||
aContext.hasPath = NO;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,25 @@ var themedButtonValues = nil,
|
||||
themedIndeterminateProgressIndicator = nil,
|
||||
themedWindowViewValues = nil;
|
||||
|
||||
/*
|
||||
The images of the button bar's buttons. The theme also gives them as its add, remove and
|
||||
action system images (see +themedImage).
|
||||
*/
|
||||
function ButtonBarImagePlus()
|
||||
{
|
||||
return PatternImage("buttonbar-image-plus.png", 11.0, 12.0);
|
||||
}
|
||||
|
||||
function ButtonBarImageMinus()
|
||||
{
|
||||
return PatternImage("buttonbar-image-minus.png", 11.0, 4.0);
|
||||
}
|
||||
|
||||
function ButtonBarImageAction()
|
||||
{
|
||||
return PatternImage("buttonbar-image-action.png", 22.0, 14.0);
|
||||
}
|
||||
|
||||
/*
|
||||
HOW TO ADD OR MODIFY THEMED ELEMENTS
|
||||
|
||||
@@ -381,7 +400,8 @@ var themedButtonValues = nil,
|
||||
"themedRuleEditor",
|
||||
"themedTableDataView",
|
||||
"themedCornerview",
|
||||
"themedTokenFieldTokenCloseButton"];
|
||||
"themedTokenFieldTokenCloseButton",
|
||||
"themedImage"];
|
||||
}
|
||||
|
||||
+ (CPColor)themedColor
|
||||
@@ -401,6 +421,25 @@ var themedButtonValues = nil,
|
||||
return color;
|
||||
}
|
||||
|
||||
/*
|
||||
The system images that this theme gives (see +[CPImage imageNamed:]): the images of the
|
||||
button bar's buttons.
|
||||
*/
|
||||
+ (CPImage)themedImage
|
||||
{
|
||||
var image = [[CPImage alloc] init],
|
||||
themedImageValues =
|
||||
[
|
||||
[@"add-template", ButtonBarImagePlus()],
|
||||
[@"remove-template", ButtonBarImageMinus()],
|
||||
[@"action-template", ButtonBarImageAction()]
|
||||
];
|
||||
|
||||
[self registerThemeValues:themedImageValues forObject:image];
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
+ (CPButton)makeButton
|
||||
{
|
||||
return [[CPButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 60.0, 24.0)];
|
||||
@@ -2512,9 +2551,9 @@ var themedButtonValues = nil,
|
||||
],
|
||||
PatternIsHorizontal),
|
||||
|
||||
buttonImagePlus = PatternImage("buttonbar-image-plus.png", 11.0, 12.0),
|
||||
buttonImageMinus = PatternImage("buttonbar-image-minus.png", 11.0, 4.0),
|
||||
buttonImageAction = PatternImage("buttonbar-image-action.png", 22.0, 14.0),
|
||||
buttonImagePlus = ButtonBarImagePlus(),
|
||||
buttonImageMinus = ButtonBarImageMinus(),
|
||||
buttonImageAction = ButtonBarImageAction(),
|
||||
|
||||
themedButtonBarValues =
|
||||
[
|
||||
|
||||
@@ -77,6 +77,25 @@ var themedButtonValues = nil,
|
||||
|
||||
placeholderColor = regularDisabledTextColor;
|
||||
|
||||
/*
|
||||
The images of the button bar's buttons. The theme also gives them as its add, remove and
|
||||
action system images (see +themedImage).
|
||||
*/
|
||||
function ButtonBarImagePlus()
|
||||
{
|
||||
return PatternImage("buttonbar-image-plus.png", 11.0, 12.0);
|
||||
}
|
||||
|
||||
function ButtonBarImageMinus()
|
||||
{
|
||||
return PatternImage("buttonbar-image-minus.png", 11.0, 4.0);
|
||||
}
|
||||
|
||||
function ButtonBarImageAction()
|
||||
{
|
||||
return PatternImage("buttonbar-image-action.png", 22.0, 14.0);
|
||||
}
|
||||
|
||||
@implementation Aristo2ThemeDescriptor : BKThemeDescriptor
|
||||
|
||||
+ (CPString)themeName
|
||||
@@ -98,7 +117,8 @@ var themedButtonValues = nil,
|
||||
"themedTableDataView",
|
||||
"themedCornerview",
|
||||
"themedTokenFieldTokenCloseButton",
|
||||
"themedColor"];
|
||||
"themedColor",
|
||||
"themedImage"];
|
||||
}
|
||||
|
||||
+ (CPColor)themedColor
|
||||
@@ -117,6 +137,25 @@ var themedButtonValues = nil,
|
||||
return color;
|
||||
}
|
||||
|
||||
/*
|
||||
The system images that this theme gives (see +[CPImage imageNamed:]): the images of the
|
||||
button bar's buttons.
|
||||
*/
|
||||
+ (CPImage)themedImage
|
||||
{
|
||||
var image = [[CPImage alloc] init],
|
||||
themedImageValues =
|
||||
[
|
||||
[@"add-template", ButtonBarImagePlus()],
|
||||
[@"remove-template", ButtonBarImageMinus()],
|
||||
[@"action-template", ButtonBarImageAction()]
|
||||
];
|
||||
|
||||
[self registerThemeValues:themedImageValues forObject:image];
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
+ (CPButton)makeButton
|
||||
{
|
||||
return [[CPButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 60.0, 25)];
|
||||
@@ -1985,9 +2024,9 @@ var themedButtonValues = nil,
|
||||
orientation: PatternIsHorizontal
|
||||
}),
|
||||
|
||||
buttonImagePlus = PatternImage("buttonbar-image-plus.png", 11.0, 12.0),
|
||||
buttonImageMinus = PatternImage("buttonbar-image-minus.png", 11.0, 4.0),
|
||||
buttonImageAction = PatternImage("buttonbar-image-action.png", 22.0, 14.0),
|
||||
buttonImagePlus = ButtonBarImagePlus(),
|
||||
buttonImageMinus = ButtonBarImageMinus(),
|
||||
buttonImageAction = ButtonBarImageAction(),
|
||||
|
||||
themedButtonBarValues =
|
||||
[
|
||||
|
||||
@@ -113,6 +113,26 @@ var themedButtonValues = nil,
|
||||
|
||||
placeholderColor = regularDisabledTextColor;
|
||||
|
||||
/*
|
||||
Returns an icon of 16 by 16 points that fills the shape of the mask image aMaskImage (a CSS
|
||||
url) with the colour aColor (a CSS colour).
|
||||
*/
|
||||
function A3MaskIcon(aMaskImage, aColor)
|
||||
{
|
||||
return [CPImage imageWithCSSDictionary:@{
|
||||
"-webkit-mask-image": aMaskImage,
|
||||
"mask-image": aMaskImage,
|
||||
"background-color": aColor,
|
||||
"-webkit-mask-size": "contain",
|
||||
"mask-size": "contain",
|
||||
"-webkit-mask-repeat": "no-repeat",
|
||||
"mask-repeat": "no-repeat",
|
||||
"-webkit-mask-position": "center",
|
||||
"mask-position": "center"
|
||||
}
|
||||
size:CGSizeMake(16,16)];
|
||||
}
|
||||
|
||||
@implementation Aristo3ThemeDescriptor : BKThemeDescriptor
|
||||
|
||||
+ (CPString)themeName
|
||||
@@ -136,6 +156,7 @@ var themedButtonValues = nil,
|
||||
"themedCornerview",
|
||||
"themedTokenFieldTokenCloseButton",
|
||||
"themedColor",
|
||||
"themedImage",
|
||||
"themedView",
|
||||
"themedFont"
|
||||
];
|
||||
@@ -232,6 +253,25 @@ var themedButtonValues = nil,
|
||||
return color;
|
||||
}
|
||||
|
||||
/*
|
||||
The system images that this theme gives (see +[CPImage imageNamed:]): the icons of the
|
||||
button bar's buttons.
|
||||
*/
|
||||
+ (CPImage)themedImage
|
||||
{
|
||||
var image = [[CPImage alloc] init],
|
||||
themedImageValues =
|
||||
[
|
||||
[@"add-template", A3MaskIcon(svgPlus, A3ColorActiveText)],
|
||||
[@"remove-template", A3MaskIcon(svgMinus, A3ColorActiveText)],
|
||||
[@"action-template", A3MaskIcon(svgGear, A3ColorActiveText)]
|
||||
];
|
||||
|
||||
[self registerThemeValues:themedImageValues forObject:image];
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
+ (CPButton)makeButton
|
||||
{
|
||||
return [[CPButton alloc] initWithFrame:CGRectMake(0, 0, 100, 21)];
|
||||
@@ -6723,111 +6763,16 @@ var themedButtonValues = nil,
|
||||
}],
|
||||
|
||||
// --- ICONS (Standard) ---
|
||||
plusIcon = [CPImage imageWithCSSDictionary:@{
|
||||
"-webkit-mask-image": svgPlus,
|
||||
"mask-image": svgPlus,
|
||||
"background-color": A3ColorActiveText,
|
||||
"-webkit-mask-size": "contain",
|
||||
"mask-size": "contain",
|
||||
"-webkit-mask-repeat": "no-repeat",
|
||||
"mask-repeat": "no-repeat",
|
||||
"-webkit-mask-position": "center",
|
||||
"mask-position": "center"
|
||||
}
|
||||
size:CGSizeMake(16,16)],
|
||||
|
||||
minusIcon = [CPImage imageWithCSSDictionary:@{
|
||||
"-webkit-mask-image": svgMinus,
|
||||
"mask-image": svgMinus,
|
||||
"background-color": A3ColorActiveText,
|
||||
"-webkit-mask-size": "contain",
|
||||
"mask-size": "contain",
|
||||
"-webkit-mask-repeat": "no-repeat",
|
||||
"mask-repeat": "no-repeat",
|
||||
"-webkit-mask-position": "center",
|
||||
"mask-position": "center"
|
||||
}
|
||||
size:CGSizeMake(16,16)],
|
||||
|
||||
actionIcon = [CPImage imageWithCSSDictionary:@{
|
||||
"-webkit-mask-image": svgGear,
|
||||
"mask-image": svgGear,
|
||||
"background-color": A3ColorActiveText,
|
||||
"-webkit-mask-size": "contain",
|
||||
"mask-size": "contain",
|
||||
"-webkit-mask-repeat": "no-repeat",
|
||||
"mask-repeat": "no-repeat",
|
||||
"-webkit-mask-position": "center",
|
||||
"mask-position": "center"
|
||||
}
|
||||
size:CGSizeMake(16,16)],
|
||||
|
||||
actionIconHighlighted = [CPImage imageWithCSSDictionary:@{
|
||||
"-webkit-mask-image": svgGear2,
|
||||
"mask-image": svgGear2,
|
||||
"background-color": A3ColorActiveText,
|
||||
"-webkit-mask-size": "contain",
|
||||
"mask-size": "contain",
|
||||
"-webkit-mask-repeat": "no-repeat",
|
||||
"mask-repeat": "no-repeat",
|
||||
"-webkit-mask-position": "center",
|
||||
"mask-position": "center"
|
||||
}
|
||||
size:CGSizeMake(16,16)],
|
||||
plusIcon = A3MaskIcon(svgPlus, A3ColorActiveText),
|
||||
minusIcon = A3MaskIcon(svgMinus, A3ColorActiveText),
|
||||
actionIcon = A3MaskIcon(svgGear, A3ColorActiveText),
|
||||
actionIconHighlighted = A3MaskIcon(svgGear2, A3ColorActiveText),
|
||||
|
||||
// --- HUD ICONS (White) ---
|
||||
plusIconHUD = [CPImage imageWithCSSDictionary:@{
|
||||
"-webkit-mask-image": svgPlus,
|
||||
"mask-image": svgPlus,
|
||||
"background-color": @"#FFFFFF",
|
||||
"-webkit-mask-size": "contain",
|
||||
"mask-size": "contain",
|
||||
"-webkit-mask-repeat": "no-repeat",
|
||||
"mask-repeat": "no-repeat",
|
||||
"-webkit-mask-position": "center",
|
||||
"mask-position": "center"
|
||||
}
|
||||
size:CGSizeMake(16,16)],
|
||||
|
||||
minusIconHUD = [CPImage imageWithCSSDictionary:@{
|
||||
"-webkit-mask-image": svgMinus,
|
||||
"mask-image": svgMinus,
|
||||
"background-color": @"#FFFFFF",
|
||||
"-webkit-mask-size": "contain",
|
||||
"mask-size": "contain",
|
||||
"-webkit-mask-repeat": "no-repeat",
|
||||
"mask-repeat": "no-repeat",
|
||||
"-webkit-mask-position": "center",
|
||||
"mask-position": "center"
|
||||
}
|
||||
size:CGSizeMake(16,16)],
|
||||
|
||||
actionIconHUD = [CPImage imageWithCSSDictionary:@{
|
||||
"-webkit-mask-image": svgGear,
|
||||
"mask-image": svgGear,
|
||||
"background-color": @"#FFFFFF",
|
||||
"-webkit-mask-size": "contain",
|
||||
"mask-size": "contain",
|
||||
"-webkit-mask-repeat": "no-repeat",
|
||||
"mask-repeat": "no-repeat",
|
||||
"-webkit-mask-position": "center",
|
||||
"mask-position": "center"
|
||||
}
|
||||
size:CGSizeMake(16,16)],
|
||||
|
||||
actionIconHighlightedHUD = [CPImage imageWithCSSDictionary:@{
|
||||
"-webkit-mask-image": svgGear2,
|
||||
"mask-image": svgGear2,
|
||||
"background-color": @"#FFFFFF",
|
||||
"-webkit-mask-size": "contain",
|
||||
"mask-size": "contain",
|
||||
"-webkit-mask-repeat": "no-repeat",
|
||||
"mask-repeat": "no-repeat",
|
||||
"-webkit-mask-position": "center",
|
||||
"mask-position": "center"
|
||||
}
|
||||
size:CGSizeMake(16,16)],
|
||||
|
||||
plusIconHUD = A3MaskIcon(svgPlus, @"#FFFFFF"),
|
||||
minusIconHUD = A3MaskIcon(svgMinus, @"#FFFFFF"),
|
||||
actionIconHUD = A3MaskIcon(svgGear, @"#FFFFFF"),
|
||||
actionIconHighlightedHUD = A3MaskIcon(svgGear2, @"#FFFFFF"),
|
||||
|
||||
themedButtonBarValues =
|
||||
[
|
||||
|
||||
@@ -20,10 +20,18 @@
|
||||
*/
|
||||
|
||||
@import <Foundation/Foundation.j>
|
||||
@import "CPResponder.j"
|
||||
|
||||
@import "CPTheme.j"
|
||||
|
||||
/*
|
||||
The build failed with "Cannot find protocol declaration for 'CPTheme'" in CPImage.j. This file
|
||||
imported CPResponder.j, which imports CPCursor.j and through it CPImage.j. CPImage adopts the
|
||||
CPTheme protocol and uses the theming instance variables, which this file declares. When the
|
||||
compiler reached this file first, it compiled CPImage before they existed. This file uses
|
||||
CPResponder only at run time, so a forward declaration replaces the import.
|
||||
*/
|
||||
@class CPResponder
|
||||
|
||||
var CPViewThemeClassKey = @"CPViewThemeClassKey",
|
||||
CPViewThemeStateKey = @"CPViewThemeStateKey";
|
||||
|
||||
|
||||
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
* CPImageNamedTest.j
|
||||
* AppKit
|
||||
*
|
||||
* Created by David Richardson on 2026-11-09.
|
||||
* Copyright David Richardson 2026.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import <AppKit/CPImage.j>
|
||||
@import <AppKit/CPAppearance.j>
|
||||
@import <AppKit/CPTheme.j>
|
||||
@import <AppKit/_CPCibCustomResource.j>
|
||||
|
||||
/*
|
||||
Each system image constant and AppKit's string for it, from AppKit's NSImageName constants
|
||||
on macOS 27 without the Touch Bar names.
|
||||
*/
|
||||
var CPImageNamedTestAppKitNames = [
|
||||
[CPImageNameActionTemplate, @"NSActionTemplate"],
|
||||
[CPImageNameAddTemplate, @"NSAddTemplate"],
|
||||
[CPImageNameAdvanced, @"NSAdvanced"],
|
||||
[CPImageNameApplicationIcon, @"NSApplicationIcon"],
|
||||
[CPImageNameBluetoothTemplate, @"NSBluetoothTemplate"],
|
||||
[CPImageNameBonjour, @"NSBonjour"],
|
||||
[CPImageNameBookmarksTemplate, @"NSBookmarksTemplate"],
|
||||
[CPImageNameCaution, @"NSCaution"],
|
||||
[CPImageNameColorPanel, @"NSColorPanel"],
|
||||
[CPImageNameColumnViewTemplate, @"NSColumnViewTemplate"],
|
||||
[CPImageNameComputer, @"NSComputer"],
|
||||
[CPImageNameDotMac, @"NSDotMac"],
|
||||
[CPImageNameEnterFullScreenTemplate, @"NSEnterFullScreenTemplate"],
|
||||
[CPImageNameEveryone, @"NSEveryone"],
|
||||
[CPImageNameExitFullScreenTemplate, @"NSExitFullScreenTemplate"],
|
||||
[CPImageNameFlowViewTemplate, @"NSFlowViewTemplate"],
|
||||
[CPImageNameFolder, @"NSFolder"],
|
||||
[CPImageNameFolderBurnable, @"NSFolderBurnable"],
|
||||
[CPImageNameFolderSmart, @"NSFolderSmart"],
|
||||
[CPImageNameFollowLinkFreestandingTemplate, @"NSFollowLinkFreestandingTemplate"],
|
||||
[CPImageNameFontPanel, @"NSFontPanel"],
|
||||
[CPImageNameGoBackTemplate, @"NSGoBackTemplate"],
|
||||
[CPImageNameGoForwardTemplate, @"NSGoForwardTemplate"],
|
||||
[CPImageNameGoLeftTemplate, @"NSGoLeftTemplate"],
|
||||
[CPImageNameGoRightTemplate, @"NSGoRightTemplate"],
|
||||
[CPImageNameHomeTemplate, @"NSHomeTemplate"],
|
||||
[CPImageNameIChatTheaterTemplate, @"NSIChatTheaterTemplate"],
|
||||
[CPImageNameIconViewTemplate, @"NSIconViewTemplate"],
|
||||
[CPImageNameInfo, @"NSInfo"],
|
||||
[CPImageNameInvalidDataFreestandingTemplate, @"NSInvalidDataFreestandingTemplate"],
|
||||
[CPImageNameLeftFacingTriangleTemplate, @"NSLeftFacingTriangleTemplate"],
|
||||
[CPImageNameListViewTemplate, @"NSListViewTemplate"],
|
||||
[CPImageNameLockLockedTemplate, @"NSLockLockedTemplate"],
|
||||
[CPImageNameLockUnlockedTemplate, @"NSLockUnlockedTemplate"],
|
||||
[CPImageNameMenuMixedStateTemplate, @"NSMenuMixedStateTemplate"],
|
||||
[CPImageNameMenuOnStateTemplate, @"NSMenuOnStateTemplate"],
|
||||
[CPImageNameMobileMe, @"NSMobileMe"],
|
||||
[CPImageNameMultipleDocuments, @"NSMultipleDocuments"],
|
||||
[CPImageNameNetwork, @"NSNetwork"],
|
||||
[CPImageNamePathTemplate, @"NSPathTemplate"],
|
||||
[CPImageNamePreferencesGeneral, @"NSPreferencesGeneral"],
|
||||
[CPImageNameQuickLookTemplate, @"NSQuickLookTemplate"],
|
||||
[CPImageNameRefreshFreestandingTemplate, @"NSRefreshFreestandingTemplate"],
|
||||
[CPImageNameRefreshTemplate, @"NSRefreshTemplate"],
|
||||
[CPImageNameRemoveTemplate, @"NSRemoveTemplate"],
|
||||
[CPImageNameRevealFreestandingTemplate, @"NSRevealFreestandingTemplate"],
|
||||
[CPImageNameRightFacingTriangleTemplate, @"NSRightFacingTriangleTemplate"],
|
||||
[CPImageNameShareTemplate, @"NSShareTemplate"],
|
||||
[CPImageNameSlideshowTemplate, @"NSSlideshowTemplate"],
|
||||
[CPImageNameSmartBadgeTemplate, @"NSSmartBadgeTemplate"],
|
||||
[CPImageNameStatusAvailable, @"NSStatusAvailable"],
|
||||
[CPImageNameStatusNone, @"NSStatusNone"],
|
||||
[CPImageNameStatusPartiallyAvailable, @"NSStatusPartiallyAvailable"],
|
||||
[CPImageNameStatusUnavailable, @"NSStatusUnavailable"],
|
||||
[CPImageNameStopProgressFreestandingTemplate, @"NSStopProgressFreestandingTemplate"],
|
||||
[CPImageNameStopProgressTemplate, @"NSStopProgressTemplate"],
|
||||
[CPImageNameTrashEmpty, @"NSTrashEmpty"],
|
||||
[CPImageNameTrashFull, @"NSTrashFull"],
|
||||
[CPImageNameUser, @"NSUser"],
|
||||
[CPImageNameUserAccounts, @"NSUserAccounts"],
|
||||
[CPImageNameUserGroup, @"NSUserGroup"],
|
||||
[CPImageNameUserGuest, @"NSUserGuest"],
|
||||
];
|
||||
|
||||
/*
|
||||
A coder that the cib loader accepts for resolving a custom resource.
|
||||
*/
|
||||
@implementation CPImageNamedTestCoder : CPObject
|
||||
|
||||
- (CPBundle)bundle
|
||||
{
|
||||
return [CPBundle mainBundle];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPImageNamedTest : OJTestCase
|
||||
{
|
||||
CPTheme _previousTheme;
|
||||
}
|
||||
|
||||
/*
|
||||
Each test starts with a theme that gives no images, so that a system image takes its
|
||||
default unless the test sets another theme.
|
||||
*/
|
||||
- (void)setUp
|
||||
{
|
||||
_previousTheme = [CPTheme defaultTheme];
|
||||
[CPTheme setDefaultTheme:[[CPTheme alloc] initWithName:@"CPImageNamedTestEmpty"]];
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
[CPTheme setDefaultTheme:_previousTheme];
|
||||
[CPAppearance setCurrentAppearance:nil];
|
||||
[CPImage imageNamed:CPImageNameAddTemplate]._sizeOverride = nil;
|
||||
}
|
||||
|
||||
/*
|
||||
A theme that gives the add image for every appearance, for DarkAqua and for high-contrast
|
||||
DarkAqua.
|
||||
*/
|
||||
- (CPTheme)themeWithAddImages
|
||||
{
|
||||
var theme = [[CPTheme alloc] initWithName:@"CPImageNamedTestAddImages"],
|
||||
template = [[CPImage alloc] init];
|
||||
|
||||
[template setValue:[[CPImage alloc] initByReferencingFile:@"normal.png" size:CGSizeMake(10, 10)] forThemeAttribute:@"add-template"];
|
||||
[template setValue:[[CPImage alloc] initByReferencingFile:@"dark.png" size:CGSizeMake(10, 10)] forThemeAttribute:@"add-template" inState:CPThemeStateAppearanceDarkAqua];
|
||||
[template setValue:[[CPImage alloc] initByReferencingFile:@"hc-dark.png" size:CGSizeMake(10, 10)] forThemeAttribute:@"add-template" inState:CPThemeStateAppearanceAccessibilityHighContrastDarkAqua];
|
||||
[theme takeThemeFromObject:template];
|
||||
|
||||
return theme;
|
||||
}
|
||||
|
||||
- (CPTheme)themeWithAddImage:(CPImage)anImage
|
||||
{
|
||||
var theme = [[CPTheme alloc] initWithName:@"CPImageNamedTestAddImage"],
|
||||
template = [[CPImage alloc] init];
|
||||
|
||||
[template setValue:anImage forThemeAttribute:@"add-template"];
|
||||
[theme takeThemeFromObject:template];
|
||||
|
||||
return theme;
|
||||
}
|
||||
|
||||
- (CPString)addImageFilenameIn:(CPString)anAppearanceName
|
||||
{
|
||||
var filename = nil;
|
||||
|
||||
[[CPAppearance appearanceNamed:anAppearanceName] performAsCurrentDrawingAppearance:function()
|
||||
{
|
||||
filename = [[CPImage imageNamed:CPImageNameAddTemplate] filename];
|
||||
}];
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
// MARK: Names
|
||||
|
||||
- (void)testNamesUseAppKitStringsWithTheCPPrefix
|
||||
{
|
||||
CPImageNamedTestAppKitNames.forEach(function(aPair)
|
||||
{
|
||||
if (aPair[1] === @"NSColorPanel")
|
||||
[self assert:@"CPImageNameColorPanel" equals:aPair[0]];
|
||||
else
|
||||
[self assert:aPair[1].replace(/^NS/, "CP") equals:aPair[0]];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)testEachSystemImageNameGivesItsSharedImage
|
||||
{
|
||||
CPImageNamedTestAppKitNames.concat([[CPImageNameColorPanelHighlighted]]).forEach(function(aPair)
|
||||
{
|
||||
var image = [CPImage imageNamed:aPair[0]];
|
||||
|
||||
[self assertNotNull:image message:aPair[0]];
|
||||
[self assert:image same:[CPImage imageNamed:aPair[0]]];
|
||||
[self assert:aPair[0] equals:[image name]];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)testAnUnknownNameGivesNil
|
||||
{
|
||||
[self assertNull:[CPImage imageNamed:@"CPImageNamedTestNoSuchImage"]];
|
||||
}
|
||||
|
||||
// MARK: Defaults
|
||||
|
||||
- (void)testWithoutAThemeValueASystemImageIsEmpty
|
||||
{
|
||||
var image = [CPImage imageNamed:CPImageNameAddTemplate];
|
||||
|
||||
[self assert:@"" equals:[image filename]];
|
||||
[self assertTrue:CGSizeEqualToSize(CGSizeMakeZero(), [image size])];
|
||||
[self assert:CPImageLoadStatusCompleted equals:[image loadStatus]];
|
||||
[self assertFalse:[image isCSSBased]];
|
||||
}
|
||||
|
||||
- (void)testTheColorPanelImagesKeepTheirAppKitResources
|
||||
{
|
||||
[self assertTrue:[[[CPImage imageNamed:CPImageNameColorPanel] filename] hasSuffix:@"CPImage/CPImageNameColorPanel.png"]];
|
||||
[self assertTrue:CGSizeEqualToSize(CGSizeMake(26, 29), [[CPImage imageNamed:CPImageNameColorPanel] size])];
|
||||
[self assertTrue:[[[CPImage imageNamed:CPImageNameColorPanelHighlighted] filename] hasSuffix:@"CPImage/CPImageNameColorPanelHighlighted.png"]];
|
||||
}
|
||||
|
||||
// MARK: Theme values
|
||||
|
||||
- (void)testAThemeValueGivesTheImage
|
||||
{
|
||||
[CPTheme setDefaultTheme:[self themeWithAddImages]];
|
||||
|
||||
[self assert:@"normal.png" equals:[self addImageFilenameIn:CPAppearanceNameAqua]];
|
||||
[self assertTrue:CGSizeEqualToSize(CGSizeMake(10, 10), [[CPImage imageNamed:CPImageNameAddTemplate] size])];
|
||||
}
|
||||
|
||||
- (void)testTheThemeValueForTheDrawingAppearanceWins
|
||||
{
|
||||
[CPTheme setDefaultTheme:[self themeWithAddImages]];
|
||||
|
||||
[self assert:@"dark.png" equals:[self addImageFilenameIn:CPAppearanceNameDarkAqua]];
|
||||
[self assert:@"dark.png" equals:[self addImageFilenameIn:CPAppearanceNameVibrantDark]];
|
||||
[self assert:@"hc-dark.png" equals:[self addImageFilenameIn:CPAppearanceNameAccessibilityHighContrastDarkAqua]];
|
||||
[self assert:@"normal.png" equals:[self addImageFilenameIn:CPAppearanceNameAccessibilityHighContrastAqua]];
|
||||
}
|
||||
|
||||
- (void)testASystemImageFollowsAThemeChange
|
||||
{
|
||||
var image = [CPImage imageNamed:CPImageNameAddTemplate];
|
||||
|
||||
[self assert:@"" equals:[image filename]];
|
||||
|
||||
[CPTheme setDefaultTheme:[self themeWithAddImages]];
|
||||
|
||||
[self assert:@"normal.png" equals:[image filename]];
|
||||
}
|
||||
|
||||
// MARK: Forwarding
|
||||
|
||||
- (void)testASystemImageForwardsACSSImage
|
||||
{
|
||||
var cssDictionary = @{ @"background-color": @"red" };
|
||||
|
||||
[CPTheme setDefaultTheme:[self themeWithAddImage:[CPImage imageWithCSSDictionary:cssDictionary size:CGSizeMake(16, 16)]]];
|
||||
|
||||
var image = [CPImage imageNamed:CPImageNameAddTemplate];
|
||||
|
||||
[self assertTrue:[image isCSSBased]];
|
||||
[self assertTrue:[image hasCSSDictionary]];
|
||||
[self assert:cssDictionary same:[image cssDictionary]];
|
||||
}
|
||||
|
||||
- (void)testASystemImageForwardsTheMethodsOfImageSubclasses
|
||||
{
|
||||
var slices = [[[CPImage alloc] initByReferencingFile:@"left.png" size:CGSizeMake(2, 10)],
|
||||
[[CPImage alloc] initByReferencingFile:@"center.png" size:CGSizeMake(1, 10)],
|
||||
[[CPImage alloc] initByReferencingFile:@"right.png" size:CGSizeMake(2, 10)]];
|
||||
|
||||
[CPTheme setDefaultTheme:[self themeWithAddImage:[[CPThreePartImage alloc] initWithImageSlices:slices isVertical:NO]]];
|
||||
|
||||
var image = [CPImage imageNamed:CPImageNameAddTemplate];
|
||||
|
||||
[self assertTrue:[image isThreePartImage]];
|
||||
[self assertTrue:[image respondsToSelector:@selector(imageSlices)]];
|
||||
[self assert:slices equals:[image imageSlices]];
|
||||
}
|
||||
|
||||
- (void)testASystemImagePostsItsLoadNotificationWhenTheResolvedImageLoads
|
||||
{
|
||||
var resolvedImage = [[CPImage alloc] initByReferencingFile:@"later.png" size:CGSizeMake(10, 10)],
|
||||
image = [CPImage imageNamed:CPImageNameAddTemplate],
|
||||
postedObjects = [];
|
||||
|
||||
[CPTheme setDefaultTheme:[self themeWithAddImage:resolvedImage]];
|
||||
|
||||
var observer = [[CPNotificationCenter defaultCenter] addObserverForName:CPImageDidLoadNotification object:image queue:nil usingBlock:function(aNotification)
|
||||
{
|
||||
postedObjects.push([aNotification object]);
|
||||
}];
|
||||
|
||||
[self assert:CPImageLoadStatusInitialized equals:[image loadStatus]];
|
||||
|
||||
[resolvedImage _imageDidLoad];
|
||||
|
||||
[[CPNotificationCenter defaultCenter] removeObserver:observer];
|
||||
|
||||
[self assert:[image] equals:postedObjects];
|
||||
[self assert:CPImageLoadStatusCompleted equals:[image loadStatus]];
|
||||
}
|
||||
|
||||
- (void)testASizeSetOnASystemImageReplacesTheResolvedSize
|
||||
{
|
||||
var image = [CPImage imageNamed:CPImageNameAddTemplate];
|
||||
|
||||
[CPTheme setDefaultTheme:[self themeWithAddImages]];
|
||||
[image setSize:CGSizeMake(20, 20)];
|
||||
|
||||
[self assertTrue:CGSizeEqualToSize(CGSizeMake(20, 20), [image size])];
|
||||
}
|
||||
|
||||
// MARK: Archiving and cibs
|
||||
|
||||
- (void)testASystemImageIsArchivedByName
|
||||
{
|
||||
var image = [CPImage imageNamed:CPImageNameAddTemplate];
|
||||
|
||||
[self assert:image same:[CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:image]]];
|
||||
}
|
||||
|
||||
- (void)testACibResourceWithASystemImageNameGivesTheSystemImage
|
||||
{
|
||||
var coder = [[CPImageNamedTestCoder alloc] init],
|
||||
addResource = [_CPCibCustomResource imageResourceWithName:@"CPAddTemplate" size:CGSizeMake(11, 12)],
|
||||
checkmarkResource = [_CPCibCustomResource imageResourceWithName:@"CPMenuCheckmark" size:CGSizeMake(11, 12)];
|
||||
|
||||
[self assert:[CPImage imageNamed:CPImageNameAddTemplate] same:[addResource awakeAfterUsingCoder:coder]];
|
||||
[self assertNull:[checkmarkResource awakeAfterUsingCoder:coder]];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -47,15 +47,35 @@ function imagesize(path) {
|
||||
var FILE = require("file"),
|
||||
imageSize = require("cappuccino/imagesize").imagesize
|
||||
*/
|
||||
var supportedTemplateImages = {
|
||||
"NSAddTemplate": "CPAddTemplate",
|
||||
"NSRemoveTemplate": "CPRemoveTemplate",
|
||||
"NSActionTemplate": "CPActionTemplate",
|
||||
"NSToolbarShowColors": "CPImageNameColorPanel",
|
||||
/*
|
||||
IB names a built-in image by its AppKit name. nib2cib maps it to the name with CP in place of
|
||||
NS when CPImage has a system image of that name (see +[CPImage imageNamed:]). These IB names
|
||||
map otherwise: NSColorPanel and NSToolbarShowColors (the image of the Colors toolbar item)
|
||||
map to CPImageNameColorPanel, which keeps its earlier string; NSMenuCheckmark and
|
||||
NSMenuMixedState (the default state images of a menu item) map to names that the cib loader
|
||||
resolves to nil, so that the menu item theme draws them.
|
||||
*/
|
||||
var builtInImageAliases = {
|
||||
"NSColorPanel": CPImageNameColorPanel,
|
||||
"NSToolbarShowColors": CPImageNameColorPanel,
|
||||
"NSMenuCheckmark": "CPMenuCheckmark",
|
||||
"NSMenuMixedState": "CPMenuMixedState"
|
||||
};
|
||||
|
||||
/*
|
||||
Returns the CP name for the built-in image that IB names aName, or nil when Cappuccino has no
|
||||
such image.
|
||||
*/
|
||||
function CPNameForBuiltInImage(aName)
|
||||
{
|
||||
if (builtInImageAliases.hasOwnProperty(aName))
|
||||
return builtInImageAliases[aName];
|
||||
|
||||
var name = "CP" + aName.substring(2);
|
||||
|
||||
return _CPImageIsSystemImageName(name) ? name : nil;
|
||||
}
|
||||
|
||||
@implementation _CPCibCustomResource (NSCoding)
|
||||
|
||||
- (id)NS_initWithCoder:(CPCoder)aCoder
|
||||
@@ -75,11 +95,14 @@ var supportedTemplateImages = {
|
||||
return nil;
|
||||
else if (/^NS[A-Z][A-Za-z]+$/.test(_resourceName))
|
||||
{
|
||||
if (supportedTemplateImages[_resourceName])
|
||||
{
|
||||
// Defer resolving this path until runtime.
|
||||
_resourceName = supportedTemplateImages[_resourceName];
|
||||
}
|
||||
var builtInImageName = CPNameForBuiltInImage(_resourceName);
|
||||
|
||||
/*
|
||||
The cib keeps the name, and the cib loader resolves it to the system image at
|
||||
run time.
|
||||
*/
|
||||
if (builtInImageName)
|
||||
_resourceName = builtInImageName;
|
||||
else
|
||||
[CPException raise:Nib2CibException format:@"The built in image “%@” is not supported.", _resourceName];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user