Skip to content

Commit

Permalink
Enable additional button types in CPButton with manual test.
Browse files Browse the repository at this point in the history
  • Loading branch information
thewalkingtoast committed May 1, 2012
1 parent c437537 commit ea0107f
Show file tree
Hide file tree
Showing 9 changed files with 1,373 additions and 820 deletions.
43 changes: 32 additions & 11 deletions AppKit/CPButton.j
Expand Up @@ -55,8 +55,8 @@ CPRadioButton = 4; // Deprecated, use CPRadio instead.
CPMomentaryChangeButton = 5;
CPOnOffButton = 6;
CPMomentaryPushInButton = 7;
CPMomentaryPushButton = 0;
CPMomentaryLight = 7;
CPMomentaryPushButton = 0; // Deprecated, use CPMomentaryLightButton instead.
CPMomentaryLight = 7; // Deprecated, use CPMomentaryPushInButton instead.

CPNoButtonMask = 0;
CPContentsButtonMask = 1;
Expand Down Expand Up @@ -170,6 +170,10 @@ CPButtonImageOffset = 3.0;
{
_controlSize = CPRegularControlSize;

// Set defaults
_highlightsBy = CPChangeBackgroundCellMask;
_showsStateBy = CPNoCellMask;

_keyEquivalent = @"";
_keyEquivalentModifierMask = 0;

Expand Down Expand Up @@ -414,7 +418,7 @@ CPButtonImageOffset = 3.0;
[self setShowsStateBy:CPNoCellMask];
break;

case CPMomentaryChangeButton: [self setHighlightsBy:CPContentsCellMask];
case CPMomentaryChangeButton: [self setHighlightsBy:CPChangeGrayCellMask | CPContentsCellMask];
[self setShowsStateBy:CPNoCellMask];
break;

Expand All @@ -426,7 +430,7 @@ CPButtonImageOffset = 3.0;
[self setShowsStateBy:CPChangeBackgroundCellMask];
break;

case CPToggleButton: [self setHighlightsBy:CPPushInCellMask | CPContentsCellMask];
case CPToggleButton: [self setHighlightsBy:CPPushInCellMask];
[self setShowsStateBy:CPContentsCellMask];
break;

Expand Down Expand Up @@ -494,20 +498,21 @@ CPButtonImageOffset = 3.0;

- (BOOL)startTrackingAt:(CGPoint)aPoint
{
[self highlight:YES];

return [super startTrackingAt:aPoint];
}

- (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
{
[self highlight:NO];
[self invalidateTimers];

[super stopTracking:lastPoint at:aPoint mouseIsUp:mouseIsUp];

if (mouseIsUp && CGRectContainsPoint([self bounds], aPoint))
[self setNextState];

// Keep highlight YES for CPOnState for CPOnOffButton
if (_highlightsBy == CPOnOffButton && [self state] != CPOffState)
mouseIsUp = NO;

[super stopTracking:lastPoint at:aPoint mouseIsUp:mouseIsUp];
}

- (void)invalidateTimers
Expand Down Expand Up @@ -637,11 +642,27 @@ CPButtonImageOffset = 3.0;

var contentView = [self layoutEphemeralSubviewNamed:@"content-view"
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:@"bezel-view"];
relativeToEphemeralSubviewNamed:@"bezel-view"],
displayTitle = _title;

if (_alternateTitle)
{
switch (_highlightsBy)
{
case CPToggleButton:
displayTitle = ([self state] == CPOnState) ? _alternateTitle : _title;
break;
case CPMomentaryChangeButton:
case CPPushOnPushOffButton:
case CPOnOffButton:
displayTitle = ([self hasThemeState:CPThemeStateHighlighted]) ? _alternateTitle : _title;
break;
}
}

if (contentView)
{
[contentView setText:([self hasThemeState:CPThemeStateHighlighted] && _alternateTitle) ? _alternateTitle : _title];
[contentView setText:displayTitle];
[contentView setImage:[self currentValueForThemeAttribute:@"image"]];
[contentView setImageOffset:[self currentValueForThemeAttribute:@"image-offset"]];

Expand Down
5 changes: 4 additions & 1 deletion AppKit/CPControl.j
Expand Up @@ -391,7 +391,10 @@ var CPControlBlackColor = [CPColor blackColor];

- (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
{
[self highlight:NO];
if ( mouseIsUp )
[self highlight:NO];
else
[self highlight:YES];
}

- (void)mouseDown:(CPEvent)anEvent
Expand Down
18 changes: 16 additions & 2 deletions Tests/Manual/CPButtonTest/AppController.j
@@ -1,6 +1,6 @@
/*
* AppController.j
* CPButtonImageTest
* CPButton
*
* Created by Aparajita Fishman on August 31, 2010.
*/
Expand All @@ -16,6 +16,10 @@ CPLogRegister(CPLogConsole);

@outlet CPButton button;
@outlet CPButton imageButton;
@outlet CPButton pushInButton;
@outlet CPButton pushOnOffButton;
@outlet CPButton toggleButton;
@outlet CPButton momentaryChangeButton;
@outlet CPCheckBox checkbox;
@outlet CPCheckBox multiCheckbox;
@outlet CPRadio radio1;
Expand Down Expand Up @@ -57,10 +61,20 @@ CPLogRegister(CPLogConsole);

[[radio1 radioGroup] setTarget:self];
[[radio1 radioGroup] setAction:@selector(radioGroupClicked:)];

[multiCheckbox setState:CPMixedState];

[pushInButton setButtonType:CPMomentaryLightButton];
[pushOnOffButton setButtonType:CPPushOnPushOffButton];
[toggleButton setButtonType:CPToggleButton];
[momentaryChangeButton setButtonType:CPMomentaryChangeButton];

[pushInButton setAlternateTitle:@"Should Not See Me"];
[toggleButton setAlternateTitle:@"Alternate Title For Toggle"];
[momentaryChangeButton setAlternateTitle:@"Changed!"];
}

- (void)setImagePosition:(id)sender
- (IBAction)setImagePosition:(id)sender
{
[self _setImagePosition:[sender indexOfSelectedItem]];
}
Expand Down
10 changes: 4 additions & 6 deletions Tests/Manual/CPButtonTest/Info.plist
Expand Up @@ -2,11 +2,9 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Main cib file base name</key>
<string>MainMenu.cib</string>
<key>CPBundleName</key>
<string>CPButtonImageTest</string>
<key>CPPrincipalClass</key>
<string>CPApplication</string>
<key>Main cib file base name</key>
<string>MainMenu.cib</string>
<key>CPBundleName</key>
<string>CPButton</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Tests/Manual/CPButtonTest/Resources/MainMenu.cib

Large diffs are not rendered by default.

0 comments on commit ea0107f

Please sign in to comment.