Add defaultButton to CPWindow, set up default key bindings

This commit is contained in:
Ross Boucher committed 2009-04-13 21:22:32 -07:00
1 parent 831bbef9e1
commit 0c63a5aba4
4 files changed
+107 -149

No files matched your search

+16 -143
View File
@@ -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 <code>aState</code>.
@param aState Possible states are any of the CPButton globals:
+8
View File
@@ -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;
+26 -6
View File
@@ -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
{
}
+57
View File
@@ -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)