diff --git a/AppKit/CPAlert.j b/AppKit/CPAlert.j index 8c5f689b4..76b4c64b3 100644 --- a/AppKit/CPAlert.j +++ b/AppKit/CPAlert.j @@ -75,32 +75,33 @@ CPCriticalAlertStyle = 2; representing the first button added to the alert which appears on the right, 1 representing the next button to the left and so on) */ -@implementation CPAlert : CPView +@implementation CPAlert : CPObject { - BOOL _showHelp @accessors(property=showsHelp); - BOOL _showSuppressionButton @accessors(property=showsSuppressionButton); + BOOL _showHelp @accessors(property=showsHelp); + BOOL _showSuppressionButton @accessors(property=showsSuppressionButton); - CPAlertStyle _alertStyle @accessors(property=alertStyle); - CPString _title @accessors(property=title); - CPView _accessoryView @accessors(property=accessoryView); - CPImage _icon @accessors(property=icon); + CPAlertStyle _alertStyle @accessors(property=alertStyle); + CPString _title @accessors(property=title); + CPView _accessoryView @accessors(property=accessoryView); + CPImage _icon @accessors(property=icon); - CPArray _buttons @accessors(property=buttons,readonly); - CPCheckBox _suppressionButton @accessors(property=suppressionButton,readonly); + CPArray _buttons @accessors(property=buttons,readonly); + CPCheckBox _suppressionButton @accessors(property=suppressionButton,readonly); - id _delegate @accessors(property=delegate); - id _modalDelegate; - SEL _didEndSelector; + id _delegate @accessors(property=delegate); + id _modalDelegate; + SEL _didEndSelector; - CPWindow _window @accessors(property=window,readonly); - int _defaultWindowStyle; + _CPAlertThemeView _themeView @accessors(property=themeView, readonly); + CPWindow _window @accessors(property=window,readonly); + int _defaultWindowStyle; - CPImageView _alertImageView; - CPTextField _informativeLabel; - CPTextField _messageLabel; - CPButton _alertHelpButton; + CPImageView _alertImageView; + CPTextField _informativeLabel; + CPTextField _messageLabel; + CPButton _alertHelpButton; - BOOL _needsLayout; + BOOL _needsLayout; } #pragma mark Creating Alerts @@ -164,6 +165,7 @@ CPCriticalAlertStyle = 2; _showHelp = NO; _needsLayout = YES; _defaultWindowStyle = CPTitledWindowMask; + _themeView = [_CPAlertThemeView new]; _messageLabel = [CPTextField labelWithTitle:@"Alert"]; _alertImageView = [[CPImageView alloc] init]; @@ -180,6 +182,11 @@ CPCriticalAlertStyle = 2; #pragma mark Accessors +- (CPTheme)theme +{ + return [_themeView theme]; +} + /*! set the theme to use @@ -197,9 +204,20 @@ CPCriticalAlertStyle = 2; _window = nil; // will be regenerated at next layout _needsLayout = YES; - [super setTheme:aTheme]; + [_themeView setTheme:aTheme]; } +- (void)setValue:(id)aValue forThemeAttribute:(CPString)aName +{ + [_themeView setValue:aValue forThemeAttribute:aName]; +} + +- (void)setValue:(id)aValue forThemeAttribute:(CPString)aName inState:(CPThemeState)aState +{ + [_themeView setValue:aValue forThemeAttribute:aName inState:aState]; +} + + /*! @deprecated */ - (void)setWindowStyle:(int)aStyle @@ -334,16 +352,16 @@ CPCriticalAlertStyle = 2; */ - (void)_layoutMessageView { - var inset = [self currentValueForThemeAttribute:@"content-inset"], + var inset = [_themeView currentValueForThemeAttribute:@"content-inset"], sizeWithFontCorrection = 6.0, messageLabelWidth, messageLabelTextSize; - [_messageLabel setTextColor:[self currentValueForThemeAttribute:@"message-text-color"]]; - [_messageLabel setFont:[self currentValueForThemeAttribute:@"message-text-font"]]; - [_messageLabel setTextShadowColor:[self currentValueForThemeAttribute:@"message-text-shadow-color"]]; - [_messageLabel setTextShadowOffset:[self currentValueForThemeAttribute:@"message-text-shadow-offset"]]; - [_messageLabel setAlignment:[self currentValueForThemeAttribute:@"message-text-alignment"]]; + [_messageLabel setTextColor:[_themeView currentValueForThemeAttribute:@"message-text-color"]]; + [_messageLabel setFont:[_themeView currentValueForThemeAttribute:@"message-text-font"]]; + [_messageLabel setTextShadowColor:[_themeView currentValueForThemeAttribute:@"message-text-shadow-color"]]; + [_messageLabel setTextShadowOffset:[_themeView currentValueForThemeAttribute:@"message-text-shadow-offset"]]; + [_messageLabel setAlignment:[_themeView currentValueForThemeAttribute:@"message-text-alignment"]]; [_messageLabel setLineBreakMode:CPLineBreakByWordWrapping]; messageLabelWidth = CGRectGetWidth([[_window contentView] frame]) - inset.left - inset.right; @@ -357,18 +375,18 @@ CPCriticalAlertStyle = 2; */ - (void)_layoutInformativeView { - var inset = [self currentValueForThemeAttribute:@"content-inset"], - defaultElementsMargin = [self currentValueForThemeAttribute:@"default-elements-margin"], + var inset = [_themeView currentValueForThemeAttribute:@"content-inset"], + defaultElementsMargin = [_themeView currentValueForThemeAttribute:@"default-elements-margin"], sizeWithFontCorrection = 6.0, informativeLabelWidth, informativeLabelOriginY, informativeLabelTextSize; - [_informativeLabel setTextColor:[self currentValueForThemeAttribute:@"informative-text-color"]]; - [_informativeLabel setFont:[self currentValueForThemeAttribute:@"informative-text-font"]]; - [_informativeLabel setTextShadowColor:[self currentValueForThemeAttribute:@"informative-text-shadow-color"]]; - [_informativeLabel setTextShadowOffset:[self currentValueForThemeAttribute:@"informative-text-shadow-offset"]]; - [_informativeLabel setAlignment:[self currentValueForThemeAttribute:@"informative-text-alignment"]]; + [_informativeLabel setTextColor:[_themeView currentValueForThemeAttribute:@"informative-text-color"]]; + [_informativeLabel setFont:[_themeView currentValueForThemeAttribute:@"informative-text-font"]]; + [_informativeLabel setTextShadowColor:[_themeView currentValueForThemeAttribute:@"informative-text-shadow-color"]]; + [_informativeLabel setTextShadowOffset:[_themeView currentValueForThemeAttribute:@"informative-text-shadow-offset"]]; + [_informativeLabel setAlignment:[_themeView currentValueForThemeAttribute:@"informative-text-alignment"]]; [_informativeLabel setLineBreakMode:CPLineBreakByWordWrapping]; informativeLabelWidth = CGRectGetWidth([[_window contentView] frame]) - inset.left - inset.right; @@ -386,8 +404,8 @@ CPCriticalAlertStyle = 2; if (!_accessoryView) return; - var inset = [self currentValueForThemeAttribute:@"content-inset"], - defaultElementsMargin = [self currentValueForThemeAttribute:@"default-elements-margin"], + var inset = [_themeView currentValueForThemeAttribute:@"content-inset"], + defaultElementsMargin = [_themeView currentValueForThemeAttribute:@"default-elements-margin"], accessoryViewWidth = CGRectGetWidth([[_window contentView] frame]) - inset.left - inset.right, accessoryViewOriginY = CGRectGetMaxY([_informativeLabel frame]) + defaultElementsMargin; @@ -403,16 +421,16 @@ CPCriticalAlertStyle = 2; if (!_showSuppressionButton) return; - var inset = [self currentValueForThemeAttribute:@"content-inset"], - suppressionViewXOffset = [self currentValueForThemeAttribute:@"suppression-button-x-offset"], - suppressionViewYOffset = [self currentValueForThemeAttribute:@"suppression-button-y-offset"], - defaultElementsMargin = [self currentValueForThemeAttribute:@"default-elements-margin"], + var inset = [_themeView currentValueForThemeAttribute:@"content-inset"], + suppressionViewXOffset = [_themeView currentValueForThemeAttribute:@"suppression-button-x-offset"], + suppressionViewYOffset = [_themeView currentValueForThemeAttribute:@"suppression-button-y-offset"], + defaultElementsMargin = [_themeView currentValueForThemeAttribute:@"default-elements-margin"], suppressionButtonViewOriginY = CGRectGetMaxY([(_accessoryView || _informativeLabel) frame]) + defaultElementsMargin + suppressionViewYOffset; - [_suppressionButton setTextColor:[self currentValueForThemeAttribute:@"suppression-button-text-color"]]; - [_suppressionButton setFont:[self currentValueForThemeAttribute:@"suppression-button-text-font"]]; - [_suppressionButton setTextShadowColor:[self currentValueForThemeAttribute:@"suppression-button-text-shadow-color"]]; - [_suppressionButton setTextShadowOffset:[self currentValueForThemeAttribute:@"suppression-button-text-shadow-offset"]]; + [_suppressionButton setTextColor:[_themeView currentValueForThemeAttribute:@"suppression-button-text-color"]]; + [_suppressionButton setFont:[_themeView currentValueForThemeAttribute:@"suppression-button-text-font"]]; + [_suppressionButton setTextShadowColor:[_themeView currentValueForThemeAttribute:@"suppression-button-text-shadow-color"]]; + [_suppressionButton setTextShadowOffset:[_themeView currentValueForThemeAttribute:@"suppression-button-text-shadow-offset"]]; [_suppressionButton sizeToFit]; [_suppressionButton setFrameOrigin:CGPointMake(inset.left + suppressionViewXOffset, suppressionButtonViewOriginY)]; @@ -424,12 +442,12 @@ CPCriticalAlertStyle = 2; */ - (CGSize)_layoutButtonsFromView:(CPView)lastView { - var inset = [self currentValueForThemeAttribute:@"content-inset"], - minimumSize = [self currentValueForThemeAttribute:@"size"], - buttonOffset = [self currentValueForThemeAttribute:@"button-offset"], - helpLeftOffset = [self currentValueForThemeAttribute:@"help-image-left-offset"], + var inset = [_themeView currentValueForThemeAttribute:@"content-inset"], + minimumSize = [_themeView currentValueForThemeAttribute:@"size"], + buttonOffset = [_themeView currentValueForThemeAttribute:@"button-offset"], + helpLeftOffset = [_themeView currentValueForThemeAttribute:@"help-image-left-offset"], aRepresentativeButton = [_buttons objectAtIndex:0], - defaultElementsMargin = [self currentValueForThemeAttribute:@"default-elements-margin"], + defaultElementsMargin = [_themeView currentValueForThemeAttribute:@"default-elements-margin"], panelSize = [[_window contentView] frame].size, buttonsOriginY, offsetX; @@ -461,8 +479,8 @@ CPCriticalAlertStyle = 2; if (_showHelp) { - var helpImage = [self currentValueForThemeAttribute:@"help-image"], - helpImagePressed = [self currentValueForThemeAttribute:@"help-image-pressed"], + var helpImage = [_themeView currentValueForThemeAttribute:@"help-image"], + helpImagePressed = [_themeView currentValueForThemeAttribute:@"help-image-pressed"], helpImageSize = helpImage ? [helpImage size] : CGSizeMakeZero(), helpFrame = CGRectMake(helpLeftOffset, buttonsOriginY, helpImageSize.width, helpImageSize.height); @@ -487,7 +505,7 @@ CPCriticalAlertStyle = 2; if (!_window) [self _createWindowWithStyle:nil]; - var iconOffset = [self currentValueForThemeAttribute:@"image-offset"], + var iconOffset = [_themeView currentValueForThemeAttribute:@"image-offset"], theImage = _icon, finalSize; @@ -495,13 +513,13 @@ CPCriticalAlertStyle = 2; switch (_alertStyle) { case CPWarningAlertStyle: - theImage = [self currentValueForThemeAttribute:@"warning-image"]; + theImage = [_themeView currentValueForThemeAttribute:@"warning-image"]; break; case CPInformationalAlertStyle: - theImage = [self currentValueForThemeAttribute:@"information-image"]; + theImage = [_themeView currentValueForThemeAttribute:@"information-image"]; break; case CPCriticalAlertStyle: - theImage = [self currentValueForThemeAttribute:@"error-image"]; + theImage = [_themeView currentValueForThemeAttribute:@"error-image"]; break; } @@ -592,7 +610,7 @@ CPCriticalAlertStyle = 2; - (void)_createWindowWithStyle:(int)forceStyle { var frame = CGRectMakeZero(); - frame.size = [self currentValueForThemeAttribute:@"size"]; + frame.size = [_themeView currentValueForThemeAttribute:@"size"]; _window = [[CPWindow alloc] initWithContentRect:frame styleMask:forceStyle || _defaultWindowStyle]; [_window setLevel:CPStatusWindowLevel]; @@ -633,8 +651,8 @@ CPCriticalAlertStyle = 2; { if ([_window isSheet]) { - [_window orderOut:nil]; [CPApp endSheet:_window returnCode:[aSender tag]]; + [_window orderOut:nil]; } else { @@ -650,17 +668,19 @@ CPCriticalAlertStyle = 2; */ - (void)_alertDidEnd:(CPWindow)aWindow returnCode:(int)returnCode contextInfo:(id)contextInfo { - if ([_delegate respondsToSelector:@selector(alertDidEnd:returnCode:)]) - [_delegate alertDidEnd:self returnCode:returnCode]; - if (_didEndSelector) objj_msgSend(_modalDelegate, _didEndSelector, self, returnCode, contextInfo); _modalDelegate = nil; _didEndSelector = nil; + + if ([_delegate respondsToSelector:@selector(alertDidEnd:returnCode:)]) + [_delegate alertDidEnd:self returnCode:returnCode]; } -#pragma mark Theme Attributes +@end + +@implementation _CPAlertThemeView : CPView + (CPString)defaultThemeClass { diff --git a/AppKit/Themes/Aristo/ThemeDescriptors.j b/AppKit/Themes/Aristo/ThemeDescriptors.j index 4eaa51738..c57c063c8 100755 --- a/AppKit/Themes/Aristo/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo/ThemeDescriptors.j @@ -1832,7 +1832,7 @@ var themedButtonValues = nil, [self registerThemeValues:themedAlertValues forView:alert]; - return alert; + return [alert themeView]; } + (CPStepper)themedStepper @@ -2095,7 +2095,7 @@ var themedButtonValues = nil, [self registerThemeValues:hudSpecificValues forView:alert inherit:themedAlertValues]; - return alert; + return [alert themeView]; } @end