Skip to content

Commit

Permalink
CPAlert informative text support.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljungberg authored and Ross Boucher committed Jun 19, 2010
1 parent b37f5b4 commit 12a49d0
Showing 1 changed file with 49 additions and 8 deletions.
57 changes: 49 additions & 8 deletions AppKit/CPAlert.j
Expand Up @@ -83,6 +83,7 @@ var CPAlertWarningImage,
CPPanel _alertPanel;

CPTextField _messageLabel;
CPTextField _informativeLabel;
CPImageView _alertImageView;

CPAlertStyle _alertStyle;
Expand Down Expand Up @@ -140,8 +141,6 @@ var CPAlertWarningImage,
[_alertPanel setFloatingPanel:YES];
[_alertPanel center];

[_messageLabel setTextColor:(styleMask & CPHUDBackgroundWindowMask) ? [CPColor whiteColor] : [CPColor blackColor]];

var count = [_buttons count];
for(var i=0; i < count; i++)
{
Expand All @@ -156,19 +155,28 @@ var CPAlertWarningImage,

if (!_messageLabel)
{
var bounds = [[_alertPanel contentView] bounds];

_messageLabel = [[CPTextField alloc] initWithFrame:CGRectMake(57.0, 10.0, CGRectGetWidth(bounds) - 73.0, 62.0)];
_messageLabel = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[_messageLabel setFont:[CPFont boldSystemFontOfSize:13.0]];
[_messageLabel setLineBreakMode:CPLineBreakByWordWrapping];
[_messageLabel setAlignment:CPJustifiedTextAlignment];
[_messageLabel setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];

_alertImageView = [[CPImageView alloc] initWithFrame:CGRectMake(15.0, 12.0, 32.0, 32.0)];

_informativeLabel = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[_informativeLabel setFont:[CPFont systemFontOfSize:12.0]];
[_informativeLabel setLineBreakMode:CPLineBreakByWordWrapping];
[_informativeLabel setAlignment:CPJustifiedTextAlignment];
[_informativeLabel setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
}
[_messageLabel setTextColor:(styleMask & CPHUDBackgroundWindowMask) ? [CPColor whiteColor] : [CPColor blackColor]];
[_informativeLabel setTextColor:(styleMask & CPHUDBackgroundWindowMask) ? [CPColor whiteColor] : [CPColor blackColor]];

[[_alertPanel contentView] addSubview:_messageLabel];
[[_alertPanel contentView] addSubview:_alertImageView];
[[_alertPanel contentView] addSubview:_informativeLabel];

[self _layoutMessage];
}

/*!
Expand Down Expand Up @@ -231,22 +239,42 @@ var CPAlertWarningImage,
}

/*!
Set’s the receiver’s message text, or title, to a given text.
Sets the receiver’s message text, or title, to a given text.
@param messageText - Message text for the alert.
*/
- (void)setMessageText:(CPString)messageText
{
[_messageLabel setStringValue:messageText];
[self _layoutMessage];
}

/*!
Return's the receiver's message text body.
/*!
Returns the receiver's message text body.
*/
- (CPString)messageText
{
return [_messageLabel stringValue];
}

/*!
Sets the receiver's informative text, shown below the message text.
@param informativeText - The informative text.
*/
- (void)setInformativeText:(CPString)informativeText
{
[_informativeLabel setStringValue:informativeText];
// No need to call _layoutMessage - only the length of the messageText
// can affect anything there.
}

/*!
Returns the receiver's informative text.
*/
- (CPString)informativeText
{
return [_informativeLabel stringValue];
}

/*!
Adds a button with a given title to the receiver.
Buttons will be added starting from the right hand side of the \c CPAlert panel.
Expand Down Expand Up @@ -281,6 +309,19 @@ var CPAlertWarningImage,
[_buttons addObject:button];
}

- (void)_layoutMessage
{
var bounds = [[_alertPanel contentView] bounds],
width = CGRectGetWidth(bounds) - 73.0,
size = [([_messageLabel stringValue] || " ") sizeWithFont:[_messageLabel currentValueForThemeAttribute:@"font"] inWidth:width],
contentInset = [_messageLabel currentValueForThemeAttribute:@"content-inset"],
height = size.height + contentInset.top + contentInset.bottom;

[_messageLabel setFrame:CGRectMake(57.0, 10.0, width, height)];

[_informativeLabel setFrame:CGRectMake(57.0, 10.0 + height + 6.0, width, CGRectGetHeight(bounds) - height - 50.0)];
}

/*!
Displays the \c CPAlert panel as a modal dialog. The user will not be
able to interact with any other controls until s/he has dismissed the alert
Expand Down

0 comments on commit 12a49d0

Please sign in to comment.