diff --git a/AppKit/CPButton.j b/AppKit/CPButton.j index b3aa3e845..a2f0982c6 100644 --- a/AppKit/CPButton.j +++ b/AppKit/CPButton.j @@ -32,184 +32,53 @@ CPScaleProportionally = 0; CPScaleToFit = 1; CPScaleNone = 2; -/* - @global - @group CPCellImagePosition -*/ + +/* @group CPCellImagePosition */ + CPNoImage = 0; -/* - @global - @group CPCellImagePosition -*/ CPImageOnly = 1; -/* - @global - @group CPCellImagePosition -*/ CPImageLeft = 2; -/* - @global - @group CPCellImagePosition -*/ CPImageRight = 3; -/* - @global - @group CPCellImagePosition -*/ CPImageBelow = 4; -/* - @global - @group CPCellImagePosition -*/ CPImageAbove = 5; -/* - @global - @group CPCellImagePosition -*/ CPImageOverlaps = 6; -/* - @global - @class CPButton -*/ + +/* @group CPButtonState */ + CPOnState = 1; -/* - @global - @class CPButton -*/ CPOffState = 0; -/* - @global - @class CPButton -*/ CPMixedState = -1; -/* - @global - @group CPBezelStyle -*/ +/* @group CPBezelStyle */ + CPRoundedBezelStyle = 1; -/* - @global - @group CPBezelStyle -*/ CPRegularSquareBezelStyle = 2; -/* - @global - @group CPBezelStyle -*/ CPThickSquareBezelStyle = 3; -/* - @global - @group CPBezelStyle -*/ CPThickerSquareBezelStyle = 4; -/* - @global - @group CPBezelStyle -*/ CPDisclosureBezelStyle = 5; -/* - @global - @group CPBezelStyle -*/ CPShadowlessSquareBezelStyle = 6; -/* - @global - @group CPBezelStyle -*/ CPCircularBezelStyle = 7; -/* - @global - @group CPBezelStyle -*/ CPTexturedSquareBezelStyle = 8; -/* - @global - @group CPBezelStyle -*/ CPHelpButtonBezelStyle = 9; -/* - @global - @group CPBezelStyle -*/ CPSmallSquareBezelStyle = 10; -/* - @global - @group CPBezelStyle -*/ CPTexturedRoundedBezelStyle = 11; -/* - @global - @group CPBezelStyle -*/ CPRoundRectBezelStyle = 12; -/* - @global - @group CPBezelStyle -*/ CPRecessedBezelStyle = 13; -/* - @global - @group CPBezelStyle -*/ CPRoundedDisclosureBezelStyle = 14; -/* - @global - @group CPBezelStyle -*/ CPHUDBezelStyle = -1; -/* - @global - @group CPButtonType -*/ +/* @group CPButtonType */ CPMomentaryLightButton = 0; -/* - @global - @group CPButtonType -*/ CPPushOnPushOffButton = 1; -/* - @global - @group CPButtonType -*/ CPToggleButton = 2; -/* - @global - @group CPButtonType -*/ CPSwitchButton = 3; -/* - @global - @group CPButtonType -*/ CPRadioButton = 4; -/* - @global - @group CPButtonType -*/ CPMomentaryChangeButton = 5; -/* - @global - @group CPButtonType -*/ CPOnOffButton = 6; -/* - @global - @group CPButtonType -*/ CPMomentaryPushInButton = 7; -/* - @global - @group CPButtonType -*/ CPMomentaryPushButton = 0; -/* - @global - @group CPButtonType -*/ CPMomentaryLight = 7; @@ -302,14 +171,18 @@ var _CPButtonClassName = nil, /*! Sets the button to its next state. */ -- (void)setNextState +- (int)nextState { if (_state == CPOffState) - _state = CPOnState; + return CPOnState; else - _state = (_state >= CPOnState && _allowsMixedState) ? CPMixedState : CPOffState; + return (_state >= CPOnState && _allowsMixedState) ? CPMixedState : CPOffState; } +- (void)setNextState +{ + [self setState:[self nextState]]; +} /*! Sets the button's state to aState. @param aState Possible states are any of the CPButton globals: diff --git a/AppKit/CPControl.j b/AppKit/CPControl.j index a06ba9ba3..058071110 100644 --- a/AppKit/CPControl.j +++ b/AppKit/CPControl.j @@ -282,6 +282,14 @@ var CPControlBlackColor = [CPColor blackColor]; _previousTrackingLocation = currentLocation; } +- (void)performClick:(id)sender +{ + [self highlight:YES]; + [self setState:[self nextState]]; + [self sendAction:[self action] to:[self target]]; + [self highlight:NO]; +} + - (unsigned)mouseDownFlags { return _trackingMouseDownFlags; diff --git a/AppKit/CPResponder.j b/AppKit/CPResponder.j index c85432ef1..abed24b70 100644 --- a/AppKit/CPResponder.j +++ b/AppKit/CPResponder.j @@ -24,10 +24,12 @@ CPDeleteKeyCode = 8; -CPUpArrowKeyCode = 63232; -CPDownArrowKeyCode = 63233; -CPLeftArrowKeyCode = 63234; -CPRightArrowKeyCode = 63235; +CPReturnKeyCode = 13; +CPEscapeKeyCode = 27; +CPLeftArrowKeyCode = 37; +CPUpArrowKeyCode = 38; +CPRightArrowKeyCode = 39; +CPDownArrowKeyCode = 40; /*! @class CPResponder @@ -109,9 +111,13 @@ CPRightArrowKeyCode = 63235; break; case CPDeleteKeyCode: [self deleteBackward:self]; break; - case 3: - case 13: [self insertLineBreak:self]; + case CPReturnKeyCode: + case 3: [self insertLineBreak:self]; break; + + case CPEscapeKeyCode: [self cancel:self]; + break; + default: [self insertText:[event characters]]; } } @@ -220,6 +226,20 @@ CPRightArrowKeyCode = 63235; @param aSender the object requesting this */ - (void)insertLineBreak:(id)aSender +{ + [self insertNewline:aSender]; +} + +/*! + Insert a line break at the caret position or selection. + @param aSender the object requesting this +*/ +- (void)insertNewline:(id)aSender +{ + [self insertNewline:aSender]; +} + +- (void)cancel:(id)sender { } diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index c4c6dd6b7..0c0ab534c 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -276,6 +276,9 @@ var CPWindowSaveImage = nil, CPArray _registeredDraggedTypesArray; CPCountedSet _inclusiveRegisteredDraggedTypes; + CPButton _defaultButton; + BOOL _defaultButtonEnabled; + // Bridge Support #if PLATFORM(DOM) DOMElement _DOMElement; @@ -401,6 +404,8 @@ CPTexturedBackgroundWindowMask if (aStyleMask & CPBorderlessBridgeWindowMask) [self setFullBridge:YES]; + + _defaultButtonEnabled = YES; } return self; @@ -1692,6 +1697,58 @@ CPTexturedBackgroundWindowMask return NO; } +- (void)keyDown:(CPEvent)event +{ + if (![self performKeyEquivalent:event]) + [self interpretKeyEvents:[event]]; +} + +- (void)insertNewline:(id)sender +{ + if (_defaultButton && _defaultButtonEnabled) + [_defaultButton performClick:nil]; +} + +- (void)setDefaultButtonCell:(CPButton)aButton +{ + [self setDefaultButton:aButton]; +} + +- (CPButton)defaultButtonCell +{ + return [self defaultButton]; +} + +- (void)setDefaultButton:(CPButton)aButton +{ + _defaultButton = aButton; +} + +- (CPButton)defaultButton +{ + return _defaultButton; +} + +- (void)enableKeyEquivalentForDefaultButton +{ + _defaultButtonEnabled = YES; +} + +- (void)enableKeyEquivalentForDefaultButtonCell +{ + [self enableKeyEquivalentForDefaultButton]; +} + +- (void)disableKeyEquivalentForDefaultButton +{ + _defaultButtonEnabled = NO; +} + +- (void)disableKeyEquivalentForDefaultButtonCell +{ + [self disableKeyEquivalentForDefaultButton]; +} + @end @implementation CPWindow (MenuBar)