Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSToolbarItem.h |
Related sample code |
Each item in an NSToolbar is an instance of NSToolbarItem.
– itemIdentifier
– toolbar
– label
– setLabel:
– paletteLabel
– setPaletteLabel:
– toolTip
– setToolTip:
– menuFormRepresentation
– setMenuFormRepresentation:
– tag
– setTag:
– target
– setTarget:
– action
– setAction:
– isEnabled
– setEnabled:
– image
– setImage:
– view
– setView:
– minSize
– setMinSize:
– maxSize
– setMaxSize:
Returns the receiver’s action.
- (SEL)action
The receiver’s action.
For custom view items, this method sends action
to the view if it responds and returns the result.
NSToolbarItem.h
Returns a Boolean value that indicates whether the receiver can be represented in the toolbar at more than one position.
- (BOOL)allowsDuplicatesInToolbar
YES
to allow dragging the receiver into the toolbar at more than one position, otherwise NO
.
You use this method by overriding it in a subclass to always return YES
; typically, you wouldn’t call it. By default, if an item with the same identifier is already in the toolbar, dragging it in again will effectively move it to the new position.
NSToolbarItem.h
Returns a Boolean value that indicates whether the receiver is automatically validated by the toolbar.
- (BOOL)autovalidates
YES
if the receiver is automatically validated by the toolbar, otherwise NO
.
NSToolbarItem.h
Returns the image of the receiver.
- (NSImage *)image
The image of the receiver.
For an image item this method returns the result of the most recent setImage:
. For view items, this method calls image
on the view if it responds and returns the result.
NSToolbarItem.h
Initialize the receiver with a given identifier.
- (id)initWithItemIdentifier:(NSString *)itemIdentifier
The identifier for the receiver. itemIdentifier is never seen by users and should not be localized.
The identifier is used by the toolbar and its delegate to identify the kind of the toolbar item.
NSToolbarItem.h
Returns a Boolean value that indicates whether the receiver is enabled.
- (BOOL)isEnabled
YES
if the receiver is enabled, otherwise NO
.
For a view item, this method calls isEnabled
on the view if it responds and returns the result.
NSToolbarItem.h
Returns the receiver’s identifier.
- (NSString *)itemIdentifier
The receiver’s identifier, which was provided in the initializer.
NSToolbarItem.h
Returns the receiver’s label.
- (NSString *)label
The receiver’s label, which normally appears in the toolbar and in the overflow menu.
For a discussion on labels, see “Setting a Toolbar Item’s Representation”.
NSToolbarItem.h
Returns the receiver’s maximum size.
- (NSSize)maxSize
The receiver’s maximum size.
See “Setting a Toolbar Item’s Size” for a discussion on item sizes.
NSToolbarItem.h
Returns the receiver’s menu form representation.
- (NSMenuItem *)menuFormRepresentation
The receiver’s menu form representation.
By default, this method returns nil
, even though there is a default menu form representation.
For a discussion on menu forms, see “Setting a Toolbar Item’s Representation”.
NSToolbarItem.h
Returns the receiver’s minimum size.
- (NSSize)minSize
The receiver’s minimum size.
See “Setting a Toolbar Item’s Size” for a discussion on item sizes.
NSToolbarItem.h
Returns the label that appears when the receiver is in the customization palette.
- (NSString *)paletteLabel
The label that appears when the receiver is in the customization palette.
An item must have a palette label if the customization palette is to be used, and for most items it is reasonable to set paletteLabel
to be the same value as label
. One reason for paletteLabel
to be different from label
would be if it’s more descriptive; another might be if there is no label
.
NSToolbarItem.h
Sets the receiver’s action.
- (void)setAction:(SEL)action
The action for the receiver.
For a custom view item, this method calls setAction:
on the view if it responds.
See Action Messages for additional information on action messages.
NSToolbarItem.h
Sets the receiver’s auto validation flag.
- (void)setAutovalidates:(BOOL)resistance
YES
to set the receiver to be automatically validated by the toolbar, otherwise NO
.
By default NSToolbar
automatically invokes the receiver’s validate method on a regular basis. If your validate method is time consuming, you can disable auto validation on a per toolbar item basis.
NSToolbarItem.h
Sets the receiver’s enabled flag.
- (void)setEnabled:(BOOL)enabled
YES
to enable the receiver, otherwise NO
.
For a custom view item, this method calls setEnabled:
on the view if it responds.
NSToolbarItem.h
Sets the image for the receiver or of the view.
- (void)setImage:(NSImage *)image
The image for the receiver, or of the view if it has already been set for the receiver.
For a custom view item (one whose view has already been set), this method calls setImage:
on the view if it responds. If image contains multiple representations, NSToolbarItem
chooses the most appropriately sized representation when displaying.
NSToolbarItem.h
Sets the receiver’s label that appears in the toolbar.
- (void)setLabel:(NSString *)label
The receiver’s label that appears in the toolbar. The length of the label should be appropriate and not too long. The label may be empty.
The implication is that the toolbar will draw the label for the receiver, and a redraw is triggered by this method. The toolbar is in charge of the label area. For a discussion on labels, see “Setting a Toolbar Item’s Representation”.
NSToolbarItem.h
Sets the receiver’s maximum size to a given size.
- (void)setMaxSize:(NSSize)size
The maximum size for the receiver.
See “Setting a Toolbar Item’s Size” for a discussion on item sizes.
NSToolbarItem.h
Sets the receiver’s menu form.
- (void)setMenuFormRepresentation:(NSMenuItem *)menuItem
The menu form for the receiver.
For a discussion on menu forms see “Setting a Toolbar Item’s Representation”.
NSToolbarItem.h
Sets the receiver’s minimum size to a given size.
- (void)setMinSize:(NSSize)size
The minimum size for the receiver.
See “Setting a Toolbar Item’s Size” for a discussion on item sizes.
NSToolbarItem.h
Sets the receiver’s label that appears when it is in the customization palette.
- (void)setPaletteLabel:(NSString *)paletteLabel
The label that appears when the receiver is in the customization palette.
An item must have a palette label if the customization palette is to be used, and for most items it is reasonable to set paletteLabel
to be the same value as label
. One reason for paletteLabel
to be different from label
would be if it’s more descriptive; another might be if there is no label
.
NSToolbarItem.h
Sets the receiver’s tag.
- (void)setTag:(NSInteger)tag
The tag for the receiver.
You can use the tag for your own custom purpose.
NSToolbarItem.h
Sets the receiver’s target.
- (void)setTarget:(id)target
The target for the receiver.
If target is nil
, the toolbar will call action
on the first responder that implements it (see About the Responder Chain).
– target
– setAction:
– validateToolbarItem:
(NSToolbarValidation
)NSToolbarItem.h
Sets the tooltip to be used when the receiver is displayed in the toolbar.
- (void)setToolTip:(NSString *)toolTip
A string representing the tooltip to be used when the receiver is displayed in the toolbar.
NSToolbarItem.h
Use this method to make the receiver into a view item.
- (void)setView:(NSView *)view
The view for the receiver. The view and all of its contents must conform to the NSCoding
protocol if the toolbar supports customization.
Note that many of the set/get methods are implemented by calls forwarded to view, if it responds to it.
NSToolbarItem.h
Sets the receiver’s visibility priority.
- (void)setVisibilityPriority:(NSInteger)visibilityPriority
The visibility priority for the receiver. The values for visibilityPriority are described in Item Priority
.
NSToolbarItem.h
Returns the receiver’s tag.
- (NSInteger)tag
The receiver’s tag.
You can use the tag for your own custom purpose.
NSToolbarItem.h
Returns the receiver’s target.
- (id)target
The receiver’s target.
NSToolbarItem.h
Returns the toolbar that is using the receiver.
- (NSToolbar *)toolbar
The toolbar that is using the receiver.
NSToolbarItem.h
Returns the tooltip used when the receiver is displayed in the toolbar.
- (NSString *)toolTip
The tooltip used when the receiver is displayed in the toolbar.
NSToolbarItem.h
This method is called by the receiver’s toolbar during validation.
- (void)validate
You may invoke this method directly if you have disabled automatic validation for an item—typically you do this for performance reasons if your validation code is slow. For further discussion, see “Validating Toolbar Items”.
NSToolbarItem.h
Returns the receiver’s view.
- (NSView *)view
The receiver’s view.
Note that many of the set/get methods are implemented by calls forwarded to the NSView
object referenced by this attribute, if the object responds to it.
NSToolbarItem.h
Returns the receiver’s visibility priority.
- (NSInteger)visibilityPriority
The receiver’s visibility priority. Possible values are described in Item Priority
.
NSToolbarItem.h
NSToolbarItem
defines the following standard toolbar item identifiers.
NSString *NSToolbarSeparatorItemIdentifier; NSString *NSToolbarSpaceItemIdentifier; NSString *NSToolbarFlexibleSpaceItemIdentifier; NSString *NSToolbarShowColorsItemIdentifier; NSString *NSToolbarShowFontsItemIdentifier; NSString *NSToolbarCustomizeToolbarItemIdentifier; NSString *NSToolbarPrintItemIdentifier;
NSToolbarSeparatorItemIdentifier
The Separator item.
Available in Mac OS X v10.0 and later.
Declared in NSToolbarItem.h
.
NSToolbarSpaceItemIdentifier
The Space item.
Available in Mac OS X v10.0 and later.
Declared in NSToolbarItem.h
.
NSToolbarFlexibleSpaceItemIdentifier
The Flexible Space item.
Available in Mac OS X v10.0 and later.
Declared in NSToolbarItem.h
.
NSToolbarShowColorsItemIdentifier
The Colors item. Shows the color panel.
Available in Mac OS X v10.0 and later.
Declared in NSToolbarItem.h
.
NSToolbarShowFontsItemIdentifier
The Fonts item. Shows the font panel.
Available in Mac OS X v10.0 and later.
Declared in NSToolbarItem.h
.
NSToolbarCustomizeToolbarItemIdentifier
The Customize item. Shows the customization palette.
Available in Mac OS X v10.0 and later.
Declared in NSToolbarItem.h
.
NSToolbarPrintItemIdentifier
The Print item. Sends printDocument:
to firstResponder
, but you can change this in toolbarWillAddItem:
if you need to do so.
Available in Mac OS X v10.0 and later.
Declared in NSToolbarItem.h
.
The following figure illustrates the items in the order in which they are described above.
NSToolbarItem.h
When a toolbar does not have enough space to fit all its items, it must push some items into the overflow menu. These values allow you to suggest a priority for a toolbar item.
enum { NSToolbarItemVisibilityPriorityStandard = 0, NSToolbarItemVisibilityPriorityLow = -1000, NSToolbarItemVisibilityPriorityHigh = 1000, NSToolbarItemVisibilityPriorityUser = 2000 };
NSToolbarItemVisibilityPriorityStandard
The default visibility priority.
Available in Mac OS X v10.4 and later.
Declared in NSToolbarItem.h
.
NSToolbarItemVisibilityPriorityLow
Items with this priority will be the first items to be pushed to the overflow menu.
Available in Mac OS X v10.4 and later.
Declared in NSToolbarItem.h
.
NSToolbarItemVisibilityPriorityHigh
Items with this priority are less inclined to be pushed to the overflow menu.
Available in Mac OS X v10.4 and later.
Declared in NSToolbarItem.h
.
NSToolbarItemVisibilityPriorityUser
Items with this priority are the last to be pushed to the overflow menu. Only the user should set items to this priority.
Available in Mac OS X v10.4 and later.
Declared in NSToolbarItem.h
.
To suggest that an item always remain visible, give it a value greater than NSToolbarItemVisibilityPriorityStandard
, but less than NSToolbarItemVisibilityPriorityUser
. In configurable toolbars, users can control the priority of an item and the priority is autosaved by the NSToolbar. These values are used by the setVisibilityPriority:
and visibilityPriority
methods:
NSToolbarItem.h
© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-06-28)