Copyright ã1994 by NeXT Computer, Inc.  All Rights Reserved.

NSButton

Inherits From:	NSControl : NSView : NSResponder : NSObject

Conforms To:	NSCoding (NSResponder)
NSObject (NSObject)

Declared In:	AppKit/NSButton.h 

Class Description

NSButton is a subclass of NSControl that intercepts mouse-down events and sends an action message to a target object when it's clicked or pressed. By virtue of its NSButtonCell, NSButton is a two-state NSControlÐit's either ªoffº or ªonºÐand it displays its state depending on the configuration of the NSButtonCell. NSButton acquires other attributes of NSButtonCell. The state is used as the value, so NSControl methods like setIntValue: actually set the state (the methods setState: and state are provided as a more conceptually accurate way of setting and getting the state). The NSButton can send its action continuously and display highlighting in several different ways. What's more, an NSButton can have a key equivalent that's eligible for triggering whenever the NSButton's NSPanel or NSWindow is the key window.

NSButton and NSMatrix both provide a control view, which is needed to display an NSButtonCell object. However, while NSMatrix requires you to access the NSButtonCells directly, most of NSButton's methods are ªcoversº for identically declared methods in NSButtonCell. (In other words, the implementation of the NSButton method invokes the corresponding NSButtonCell method for you, allowing you to be unconcerned with the NSButtonCell's existence.) The only NSButtonCell methods that don't have covers relate to the font used to display the key equivalent, and to specific methods for highlighting or showing the NSButton's state (these last are usually set together with NSButton's setType: method).

Creating a Subclass of NSButton

Override the designated initializer (NSView's initWithFrame: method) if you create a subclass of NSButton that performs its own initialization. If you want to use a custom NSButtonCell subclass with your subclass of NSButton, you have to override the setCellClass: method, as described in ªCreating New NSControlsº in the NSControl class specification.

See the NSButtonCell class specification for more on NSButton's behavior.

 Initializing the NSButton Factory 

+ (Class)cellClass	Returns the subclass of NSButtonCell used by NSButton.

+ (void)setCellClass:(Class)classId	Sets the subclass of NSButtonCell used by NSButton.

Setting the Button Type 

- (void)setType:(int)aType	Sets how the NSButton highlights and shows its state.

Setting the State 

- (void)setState:(int)value	Sets the NSButton's state to value (0 or 1).

- (int)state	Returns the NSButton's current state (0 or 1).

Setting the Repeat Interval 

- (void)getPeriodicDelay:(float *)delay	Gets repeat parameters for continuous buttons.
interval:(float *)interval

- (void)setPeriodicDelay:(float)delay	Sets repeat parameters for continuous buttons.
interval:(float)interval

Setting the Titles 

- (NSString *)alternateTitle	Returns the button's alternate title.

- (void)setAlternateTitle:(NSString *)aString	Makes aString the button's alternate title.

- (void)setTitle:(NSString *)aString	Makes aString the button's title.

- (NSString *)title	Returns the button's title.

Setting the Images 

- (NSImage *)alternateImage	Returns the button's alternate image.

- (NSImage *)image	Returns the button's image.

- (NSCellImagePosition)imagePosition	Returns the position of the button's image.

- (void)setAlternateImage:(NSImage *)anImage	Makes anImage the alternate image.

- (void)setImage:(NSImage *)anImage	Makes anImage the button's icon.

- (void)setImagePosition:(NSCellImagePosition)aPosition
	Sets the position of the button's image to aPosition.

Modifying Graphic Attributes 

- (BOOL)isBordered	Returns whether the button has a bezeled border.

- (BOOL)isTransparent	Returns whether the button is transparent.

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

- (void)setTransparent:(BOOL)flag	Sets whether the button is transparent.

Displaying 

- (void)highlight:(BOOL)flag	Highlights (or unhighlights) the button according to flag.

Setting the Key Equivalent 

	

- (NSString *)keyEquivalent	Returns the button's key equivalent.

- (unsigned int)keyEquivalentModifierMask	Returns the mask indicating the possible modifier keys for button's key equivalent. 

- (void)setKeyEquivalent:(NSString *)aKeyEquivalent
	Makes aKeyEquivalent the button's key equivalent.

- (void)setKeyEquivalentModifierMask:(unsigned int)mask	
	Sets the mask that determines the possible modifier keys for button's key equivalent. 

Handling Events and Action Messages 

- (void)performClick:(id)sender	Simulates the user's clicking the button.

- (BOOL)performKeyEquivalent:(NSEvent *)anEvent
	Simulates a mouse click, if the key in anEvent is right.