Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSToolbar.h |
Related sample code |
NSToolbar and NSToolbarItem
provide the mechanism for a titled window to display a toolbar just below its title bar, as shown below:
– displayMode
– setDisplayMode:
– showsBaselineSeparator
– setShowsBaselineSeparator:
– allowsUserCustomization
– setAllowsUserCustomization:
– identifier
– items
– visibleItems
– sizeMode
– setSizeMode:
– insertItemWithItemIdentifier:atIndex:
– removeItemAtIndex:
– toolbarWillAddItem:
delegate method
– toolbarDidRemoveItem:
delegate method
– setSelectedItemIdentifier:
– selectedItemIdentifier
– autosavesConfiguration
– setAutosavesConfiguration:
– configurationDictionary
– setConfigurationFromDictionary:
– toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:
delegate method
– toolbarAllowedItemIdentifiers:
delegate method
– toolbarDefaultItemIdentifiers:
delegate method
– toolbarSelectableItemIdentifiers:
delegate method
– validateVisibleItems
Returns a Boolean value that indicates whether users are allowed to modify the toolbar.
- (BOOL)allowsUserCustomization
YES
if users are allowed to modify the toolbar, NO
otherwise. The default is NO
.
If the value is NO
, then the Customize Toolbar… menu item is disabled and other modification is disabled. This attribute does not affect the user’s ability to show or hide the toolbar.
NSToolbar.h
Returns a Boolean value that indicates whether the receiver autosaves its configuration.
- (BOOL)autosavesConfiguration
YES
if the receiver autosaves its configuration, otherwise NO
. The default is NO
.
When autosaving is enabled, the receiver will automatically write the toolbar settings to user defaults if the toolbar configuration changes. The toolbar's configuration is identified in user defaults by the toolbar identifier. If there are multiple toolbars active with the same identifier, they all share the same configuration.
NSToolbar.h
Returns the receiver’s configuration as a dictionary.
- (NSDictionary *)configurationDictionary
A dictionary containing configuration information for the toolbar.
Contains displayMode
, isVisible
, and a list of the item identifiers currently in the toolbar.
Do not depend on any details of the normal contents of a configuration dictionary.
NSToolbar.h
Returns a Boolean value that indicates whether the receiver’s customization palette is running (in use).
- (BOOL)customizationPaletteIsRunning
YES
if the receiver's customization palette is running, otherwise NO
.
NSToolbar.h
Returns the receiver’s delegate.
- (id)delegate
The receiver's delegate.
Every toolbar must have a delegate, which must implement the required delegate methods.
NSToolbar.h
Returns the receiver’s display mode.
- (NSToolbarDisplayMode)displayMode
The receiver's display mode.
NSToolbar.h
Returns the receiver’s identifier.
- (NSString *)identifier
The receiver's identifier, a string used by the class to identify the kind of toolbar.
Within the application all toolbars with the same identifier are synchronized to maintain the same state, including for example, the display mode and item order. The identifier is used as the autosave name for toolbars that save their configuration.
– setAutosavesConfiguration:
NSToolbar.h
Initializes a newly allocated toolbar with the specified identifier.
- (id)initWithIdentifier:(NSString *)identifier
A string used by the class to identify the kind of the toolbar.
The initialized toolbar object.
identifier is never seen by users and should not be localized. See identifier
for important information.
NSToolbar.h
Inserts the specified item at the specified index.
- (void)insertItemWithItemIdentifier:(NSString *)itemIdentifier atIndex:(NSInteger)index
The identifier of the item to insert.
The index at which to insert the item.
If the toolbar needs a new instance, it will get it from toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:
. Typically, you should not call this method; you should let the user reconfigure the toolbar. See identifier
for important information.
NSToolbar.h
Returns a Boolean value that indicates whether the receiver is visible.
- (BOOL)isVisible
YES
if the receiver is visible, otherwise NO
.
NSToolbar.h
Returns the receiver's current items, in order.
- (NSArray *)items
An array of the items in the toolbar.
NSToolbar.h
Removes the specified item.
- (void)removeItemAtIndex:(NSInteger)index
The index of the item to remove.
Typically, you should not call this method; you should let the user reconfigure the toolbar. See identifier
for important information.
NSToolbar.h
Runs the receiver’s customization palette.
- (void)runCustomizationPalette:(id)sender
The control sending the message.
NSToolbar.h
Returns the identifier of the receiver’s currently selected item, or nil
if there is no selection.
- (NSString *)selectedItemIdentifier
The identifier of the receiver’s currently selected item, or nil
if there is no selection.
NSToolbar.h
Sets whether users are allowed to modify the toolbar.
- (void)setAllowsUserCustomization:(BOOL)allowsCustomization
YES
to allow users to modify the toolbar, NO
otherwise.
This value can be changed at any time. For instance, you may not want users to be able to customize the toolbar while some event is being processed. This attribute does not affect the user’s ability to show or hide the toolbar.
If you set the toolbar to allow customization, be sure to also set the toolbar to autosave its configuration so the user’s changes persist.
NSToolbar.h
Sets whether the receiver autosaves its configuration.
- (void)setAutosavesConfiguration:(BOOL)flag
YES
to indicate that the receiver should autosave its configuration, NO
otherwise.
Customizable toolbars should generally supporting autosaving. If you need to customize the saving behavior, you can use the configurationDictionary
to access the settings that should be saved.
NSToolbar.h
Sets the receiver’s configuration using configDict.
- (void)setConfigurationFromDictionary:(NSDictionary *)configDict
A dictionary with the toolbar's configuration information. If you want to provide a custom dictionary, you should first get the receiver's current configuration dictionary, then create a modified copy, rather than trying to construct one yourself.
This method immediately affects toolbars with the same identifier in all windows of your application.
Do not depend on any details of the normal contents of a configuration dictionary.
NSToolbar.h
Sets the receiver’s delegate.
- (void)setDelegate:(id)delegate
The new delegate object.
Every toolbar must have a delegate, which must implement the required delegate methods.
NSToolbar.h
Sets the receiver’s display mode.
- (void)setDisplayMode:(NSToolbarDisplayMode)displayMode
The new display mode.
NSToolbar.h
Sets the receiver's selected item to the specified toolbar item.
- (void)setSelectedItemIdentifier:(NSString *)itemIdentifier
The identifier of the item to select. itemIdentifier may be any identifier returned by toolbarSelectableItemIdentifiers:
, even if it is not currently in the toolbar.
Typically, a toolbar will manage the selection of items automatically. This method can be used to select identifiers of custom view items, or to force a selection change. See toolbarSelectableItemIdentifiers:
for more details. If itemIdentifier is not recognized by the receiver, the current selected item identifier does not change.
NSToolbar.h
Sets whether the toolbar shows the separator between the toolbar and the main window contents.
- (void)setShowsBaselineSeparator:(BOOL)flag
YES
if the toolbar should show the separator between the toolbar and the main window contents, otherwise NO
.
NSToolbar.h
Sets the receiver’s size mode.
- (void)setSizeMode:(NSToolbarSizeMode)sizeMode
The new size mode.
If there is no icon of the given size for a toolbar item, the toolbar item creates one by scaling an icon of another size.
NSToolbar.h
Sets whether the receiver is visible or hidden.
- (void)setVisible:(BOOL)shown
YES
to indicate the receiver should be made visible, NO
to indicate it should be hidden.
NSToolbar.h
Returns a Boolean value that indicates whether the toolbar shows the separator between the toolbar and the main window contents.
- (BOOL)showsBaselineSeparator
YES
if the toolbar shows the separator between the toolbar and the main window contents, otherwise NO
. The default is YES
.
NSToolbar.h
Returns the receiver’s size mode.
- (NSToolbarSizeMode)sizeMode
The receiver's size mode.
NSToolbar.h
Called on window updates to validate the visible items.
- (void)validateVisibleItems
You typically use this method by overriding it in a subclass. The default implementation of this method iterates through the list of visible items, sending each a validate
message. Override it and call super
if you want to know when this method is called.
This method forces a validation of the entire visible set of items, so typically you should not invoke it directly. Instead, if necessary you should validate on a per item basis only those items that have auto-validation disabled (see validate
and Validating Toolbar Items)—you generally do this for performance reasons if your validation code is slow.
NSToolbar.h
Returns the receiver’s currently visible items.
- (NSArray *)visibleItems
An array of the toolbar's visible items.
Items in the overflow menu are not considered visible.
NSToolbar.h
Sent to request a new toolbar item; returns a toolbar item of the identified kind for the specified toolbar.
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
The toolbar for which the item is being requested.
The identifier for the requested item.
YES
if the item will be immediately inserted into the toolbar. If flag is NO
the toolbar item is being requested for display in the toolbar customization sheet and should always be enabled or provide some other canonical representation. If you ignore this parameter the same toolbar item will be used in the toolbar and in the customization sheet.
The toolbar item for the specified toolbar and identifier. Return nil
to indicate that the identified kind of toolbar item is not supported. When an item is requested again, you may return the same NSToolbarItem
object returned earlier or a different instance.
Implement this method to create new toolbar item instances. This method is called lazily on behalf of a toolbar instance, which must be the sole owner of the toolbar item. A toolbar may ask again for a kind of toolbar item already supplied to it, in which case this method may return the same toolbar item it returned before or a different one. If your delegate services multiple toolbars, each attached to a different window, it is best to return a different item for each toolbar—an NSToolbarItem
object can only be in one toolbar at a time.
If the item is a custom view item, the NSView
object must be fully formed when the item is returned. Do not assume that the returned item is going to be added as an active item in the toolbar, as it could be that it will be used only in the customization palette. (The customization palette makes a copy of the returned item.)
Implementation of this method is required.
NSToolbar.h
Sent to discover the allowed item identifiers for a toolbar.
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
The toolbar whose allowed item identifiers are to be returned.
An array of toolbar item identifiers for toolbar, specifying the contents and the order of the items in the configuration palette.
Every allowed item must be explicitly listed, even the standard ones. The identifiers returned should include all of those returned by toolbarDefaultItemIdentifiers:
.
Implementation of this method is required.
NSToolbar.h
Sent to discover the default item identifiers for a toolbar.
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
The toolbar whose default item identifiers are to be returned.
An array of toolbar item identifiers for toolbar, specifying the contents and the order of the items in the default toolbar configuration.
During initialization of toolbar, this method is called only if a toolbar configuration for the identifier of toolbar is not found in the user preferences. This method is called during initialization of the toolbar customization palette.
Implementation of this method is required.
NSToolbar.h
Sent just after an item has been removed from a toolbar.
- (void)toolbarDidRemoveItem:(NSNotification *)notification
The notification object sent to observers of NSToolbarDidRemoveItemNotification.
This method allows you to remove information related to the item that may have been cached.
Implementation of this method is optional.
NSToolbar.h
Sent to discover the selectable item identifiers for a toolbar.
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
The toolbar whose selectable item identifiers are to be returned.
An array of item identifiers that should indicate selection in the specified toolbar.
Toolbars that need to indicate item selection should return an array containing the identifiers of the selectable toolbar items.
If implemented, toolbar will display the currently selected item with a visual highlight. Clicking on an item whose identifier is selectable will automatically update the toolbar's selected item identifier, when possible. Clicking an item whose identifier is not selectable will not update the toolbar's selected item identifier.
Implementation of this method is optional.
NSToolbar.h
Sent just before a new item is added to a toolbar.
- (void)toolbarWillAddItem:(NSNotification *)notification
The notification object sent to observers of NSToolbarWillAddItemNotification.
If you need to cache a reference to a toolbar item or need to set up some initial state before a toolbar item is added, this is where to do it.
Implementation of this method is optional.
NSToolbar.h
These constants specify toolbar display modes and are used by displayMode
and setDisplayMode:
.
typedef enum { NSToolbarDisplayModeDefault, NSToolbarDisplayModeIconAndLabel, NSToolbarDisplayModeIconOnly, NSToolbarDisplayModeLabelOnly } NSToolbarDisplayMode;
NSToolbarDisplayModeDefault
The default display mode.
Available in Mac OS X v10.0 and later.
Declared in NSToolbar.h
.
NSToolbarDisplayModeIconAndLabel
The toolbar will display icons and labels.
Available in Mac OS X v10.0 and later.
Declared in NSToolbar.h
.
NSToolbarDisplayModeIconOnly
The toolbar will display only icons.
Available in Mac OS X v10.0 and later.
Declared in NSToolbar.h
.
NSToolbarDisplayModeLabelOnly
The toolbar will display only labels.
Available in Mac OS X v10.0 and later.
Declared in NSToolbar.h
.
NSToolbar.h
These constants specify toolbar display modes and are used by sizeMode
and setSizeMode:
.
typedef enum { NSToolbarSizeModeDefault, NSToolbarSizeModeRegular, NSToolbarSizeModeSmall } NSToolbarSizeMode;
NSToolbarSizeModeDefault
The toolbar uses the system-defined default size, which is NSToolbarSizeModeRegular
.
Available in Mac OS X v10.2 and later.
Declared in NSToolbar.h
.
NSToolbarSizeModeRegular
The toolbar uses regular-sized controls and 32 by 32 pixel icons.
Available in Mac OS X v10.2 and later.
Declared in NSToolbar.h
.
NSToolbarSizeModeSmall
The toolbar uses small-sized controls and 24 by 24 pixel icons.
Available in Mac OS X v10.2 and later.
Declared in NSToolbar.h
.
NSToolbar.h
Posted after an item is removed from a toolbar. The notification item is the NSToolbar
object that had an item removed from it. The userInfo dictionary contains the following information:
Key |
Value |
---|---|
|
The |
NSToolbar.h
Posted before a new item is added to the toolbar. The notification item is the NSToolbar
object having an item added to it. The userInfo dictionary contains the following information:
Key |
Value |
---|---|
|
The |
NSToolbar.h
© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-10-15)