Class CPButton

CPObject
    extended byCPResponder
        extended byCPView
            extended byCPControl
                extended byCPButton
Direct Known Subclasses:
CPPopUpButton, NSButton

@implementation CPButton : CPControl

CPButton is a subclass of CPControl that intercepts mouse-down events and sends an action message to a target object when it's clicked or pressed.


Global Variables
CPOffState = 0
        
CPOnState = 1
        
CPMixedState = -1
        

Method Summary
-(id)initWithCoder:(CPCoder)aCoder
          Initializes the button by unarchiving data from aCoder.
-(id)initWithFrame:(CGRect)aFrame
          Initializes the receiver for usage with the specified bounding rectangle.
-(id)NS_initWithCoder:(CPCoder)aCoder
-(BOOL)allowsMixedState
          Returns YES if the button has a 'mixed' state in addition to on and off.
-(CPImage)alternateImage
          Returns the image used when the button is in an alternate state.
-(int)bezelStyle
          Returns the current bezel style.
-(CPControlSize)controlSize
          Returns the button's control size.
-(void)encodeWithCoder:(CPCoder)aCoder
          Archives this button into the provided coder.
-(void)highlight:(BOOL)aFlag
          Highlights the receiver based on aFlag.
-(CPImage)image
          Returns the image that will be drawn on the button.
-(CPCellImagePosition)imagePosition
          Returns the buton's image position.
-(CPImageScaling)imageScaling
          Returns the button's image scaling method.
-(BOOL)isBordered
          Returns YES if the border is bezeled.
-(void)mouseDown:(CPEvent)anEvent
          Called when the user clicks on this button.
-(void)mouseDragged:(CPEvent)anEvent
          Called when the user drags on the button.
-(void)mouseUp:(CPEvent)anEvent
          Called when the user releases the mouse button.
-(void)setAlignment:(CPTextAlignment)anAlignment
          Sets the alignment of the text on the button.
-(void)setAllowsMixedState:(BOOL)aFlag
          Sets whether the button can have a 'mixed' state.
-(void)setAlternateImage:(CPImage)anImage
          Sets the button's image which is used in its alternate state.
-(void)setBezelStyle:(CPBezelStyle)aBezelStyle
          Sets the button's bezel style.
-(void)setBordered:(BOOL)isBordered
          Sets whether the button has a bezeled border.
-(void)setButtonType:(CPButtonType)aButtonType
          Sets how the button highlights and shows its state.
-(void)setControlSize:(CPControlSize)aControlSize
          Sets the button's control size.
-(void)setFont:(CPFont)aFont
          Sets the font that will be used to draw the button text.
-(void)setFrameSize:(CGSize)aSize
          Sets the frame size for the button.
-(void)setImage:(CPImage)anImage
          Sets the image that will be drawn on the button.
-(void)setImagePosition:(CPCellImagePosition)anImagePosition
          Sets the position of the button's image to anImagePosition.
-(void)setImageScaling:(CPImageScaling)anImageScaling
          Sets the button's images scaling method.
-(void)setNextState
          Sets the button to its next state.
-(void)setState:(int)aState
          Sets the button's state to aState.
-(void)setTag:(int)aTag
          Sets button's tag.
-(void)setTextColor:(CPColor)aColor
          Sets the color of the button's text.
-(void)setTitle:(CPString)aTitle
          Sets the button's title.
-(void)sizeToFit
          Compacts the button's frame to fit its contents.
-(int)state
          Returns the button's current state.
-(int)tag
          Returns the button's tag.
-(void)tile
          Lays out the button.
-(CPString)title
          Returns the button's title string.
-(void)viewDidMoveToWindow
          Called when the receiver has been moved to a new CPWindow.

Methods inherited from class CPObject
initialize, alloc, class, instanceMethodForSelector, instancesRespondToSelector, isSubclassOfClass, load, new, setVersion, superclass, version, init, autorelease, awakeAfterUsingCoder, class, classForCoder, classForKeyedArchiver, className, copy, dealloc, description, doesNotRecognizeSelector, forwardInvocation, hash, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableCopy, performSelector, performSelector, performSelector, release, replacementObjectForArchiver, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, retain, self, superclass

Methods inherited from class CPResponder
acceptsFirstResponder, becomeFirstResponder, deleteBackward, doCommandBySelector, insertLineBreak, insertText, interpretKeyEvents, keyDown, keyUp, menu, mouseDown, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseUp, nextResponder, noResponderFor, performKeyEquivalent, resignFirstResponder, scrollWheel, setMenu, setNextResponder, tryToPerform, undoManager

Methods inherited from class CPView
initWithFrame, acceptsFirstMouse, addSubview, addSubview, adjustScroll, alphaValue, autoresizesSubviews, autoresizingMask, autoscroll, backgroundColor, bounds, convertPoint, convertPoint, convertRect, convertRect, convertSize, convertSize, didAddSubview, display, displayIfNeeded, displayIfNeededInRect, displayRect, displayRectIgnoringOpacity, dragImage, dragView, drawRect, enclosingMenuItem, enclosingScrollView, enterFullScreenMode, exitFullScreenModeWithOptions, frame, hitTest, hitTests, isDescendantOf, isFlipped, isHidden, isHiddenOrHasHiddenAncestor, isInFullScreenMode, isOpaque, lockFocus, mouseDown, mouseDownCanMoveWindow, needsDisplay, postsBoundsChangedNotifications, postsFrameChangedNotifications, reflectScrolledClipView, registerForDraggedTypes, registeredDraggedTypes, removeFromSuperview, replaceSubview, resizeSubviewsWithOldSize, resizeWithOldSuperviewSize, scrollClipView, scrollPoint, scrollRectToVisible, scrollRect, setAlphaValue, setAutoresizesSubviews, setAutoresizingMask, setBackgroundColor, setBounds, setBoundsOrigin, setBoundsSize, setFrame, setFrameOrigin, setFrameSize, setHidden, setHitTests, setNeedsDisplay, setNeedsDisplayInRect, setPostsBoundsChangedNotifications, setPostsFrameChangedNotifications, subviews, superview, unlockFocus, unregisterDraggedTypes, viewDidMoveToSuperview, viewDidMoveToWindow, viewWillMoveToSuperview, viewWillMoveToWindow, visibleRect, willRemoveSubview, window

Methods inherited from class CPControl
initWithFrame, action, alignment, backgroundColorForName, floatValue, font, isEnabled, mouseUp, sendAction, setAction, setAlignment, setBackgroundColor, setBackgroundColorWithName, setBackgroundColor, setEnabled, setFloatValue, setFont, setTarget, setTextColor, setTextShadow, target, textColor, textShadow


Method Detail

initWithCoder

-(id)initWithCoder:(CPCoder)aCoder
Initializes the button by unarchiving data from aCoder.
Parameters:
aCoder - the coder containing the archived CPButton.

initWithFrame

-(id)initWithFrame:(CGRect)aFrame
Initializes the receiver for usage with the specified bounding rectangle
Parameters:
aFrame
Returns:
the initialized view

NS_initWithCoder

-(id)NS_initWithCoder:(CPCoder)aCoder
Parameters:
aCoder

allowsMixedState

-(BOOL)allowsMixedState
Returns YES if the button has a 'mixed' state in addition to on and off.

alternateImage

-(CPImage)alternateImage
Returns the image used when the button is in an alternate state.

bezelStyle

-(int)bezelStyle
Returns the current bezel style

controlSize

-(CPControlSize)controlSize
Returns the button's control size.

encodeWithCoder

-(void)encodeWithCoder:(CPCoder)aCoder
Archives this button into the provided coder.
Parameters:
aCoder - the coder to which the button's instance data will be written.

highlight

-(void)highlight:(BOOL)aFlag
Highlights the receiver based on aFlag.
Parameters:
aFlag

image

-(CPImage)image
Returns the image that will be drawn on the button

imagePosition

-(CPCellImagePosition)imagePosition
Returns the buton's image position

imageScaling

-(CPImageScaling)imageScaling
Returns the button's image scaling method

isBordered

-(BOOL)isBordered
Returns YES if the border is bezeled.

mouseDown

-(void)mouseDown:(CPEvent)anEvent
Called when the user clicks on this button.
Parameters:
anEvent - the event with information about the click

mouseDragged

-(void)mouseDragged:(CPEvent)anEvent
Called when the user drags on the button.
Parameters:
anEvent - the event with information about the drag

mouseUp

-(void)mouseUp:(CPEvent)anEvent
Called when the user releases the mouse button
Parameters:
anEvent - the event with information about the mouse release

setAlignment

-(void)setAlignment:(CPTextAlignment)anAlignment
Sets the alignment of the text on the button.
Parameters:
anAlignment - an alignment object

setAllowsMixedState

-(void)setAllowsMixedState:(BOOL)aFlag
Sets whether the button can have a 'mixed' state.
Parameters:
aFlag - specifies whether a 'mixed' state is allowed or not

setAlternateImage

-(void)setAlternateImage:(CPImage)anImage
Sets the button's image which is used in its alternate state.
Parameters:
anImage - the image to be used while the button is in an alternate state

setBezelStyle

-(void)setBezelStyle:(CPBezelStyle)aBezelStyle
Sets the button's bezel style.
Parameters:
aBezelStyle

setBordered

-(void)setBordered:(BOOL)isBordered
Sets whether the button has a bezeled border.
Parameters:
isBordered

setButtonType

-(void)setButtonType:(CPButtonType)aButtonType
Sets how the button highlights and shows its state.
Parameters:
aButtonType - Defines the behavior of the button.

setControlSize

-(void)setControlSize:(CPControlSize)aControlSize
Sets the button's control size.
Parameters:
aControlSize - the button's new control size

setFont

-(void)setFont:(CPFont)aFont
Sets the font that will be used to draw the button text
Parameters:
aFont - the font used to draw the button text

setFrameSize

-(void)setFrameSize:(CGSize)aSize
Sets the frame size for the button.
Parameters:
aSize

setImage

-(void)setImage:(CPImage)anImage
Sets the image that will be drawn on the button.
Parameters:
anImage - the image that will be drawn

setImagePosition

-(void)setImagePosition:(CPCellImagePosition)anImagePosition
Sets the position of the button's image to anImagePosition.
Parameters:
anImagePosition - the position for the button's image

setImageScaling

-(void)setImageScaling:(CPImageScaling)anImageScaling
Sets the button's images scaling method
Parameters:
anImageScaling - the image scaling method

setNextState

-(void)setNextState
Sets the button to its next state.

setState

-(void)setState:(int)aState
Sets the button's state to aState.
Parameters:
aState - Possible states are any of the CPButton globals: CPOffState, CPOnState, CPMixedState

setTag

-(void)setTag:(int)aTag
Sets button's tag.
Parameters:
aTag - the button's new tag

setTextColor

-(void)setTextColor:(CPColor)aColor
Sets the color of the button's text
Parameters:
aColor - the color to use for drawing the button text

setTitle

-(void)setTitle:(CPString)aTitle
Sets the button's title.
Parameters:
aTitle - the new title for the button

sizeToFit

-(void)sizeToFit
Compacts the button's frame to fit its contents.

state

-(int)state
Returns the button's current state

tag

-(int)tag
Returns the button's tag.

tile

-(void)tile
Lays out the button.

title

-(CPString)title
Returns the button's title string

viewDidMoveToWindow

-(void)viewDidMoveToWindow
Called when the receiver has been moved to a new CPWindow.

Created on Sat Sep 13 14:15:43 PDT 2008