Inherits from | |
Conforms to | |
Declared in | PSMTabBarControl.h |
PSMTabBarControl provides a user interface for the management of tabbed views that has an appearance similar to Apple's Safari web browser.
Internally, PSMTabBarControl uses a custom cell class and supporting style objects to implement its user interface.
Currently, this object supports "Aqua" and "Metal" tab styles to present an appearance consistent with the rest of your application. Numerous configuration options exist to customize behavior, as outlined below. PSMTabBarControl instances require a few specific connections with other application objects to perform properly at runtime:
A PSMTabBarControl instance should occupy the width of the window, and should be precisely 22 pixels in height. It should be resizable in width, but not height. It can be placed at the top or botton of the window (or anywhere in between, if desired).
Outside of configuring it, your application should have little interaction with this class. The presented tabs will change in conjunction with changes your application makes in the NSTabView being controlled.
PSMTabBarControl becomes even more powerful if your application design matches an expected pattern: the control attempts to bind a number of tab attributes to the NSTabViewItem's identifier object if possible. These visible attributes include a progress indicator, an icon, and an object counter. Additionally, the control binds each tab's title to the label of the represented NSTabViewItem.
Taking advantage of these features requires no glue code on your part, but it does require providing a particular object graph. Here's the basics...
The demo application included with this project illustrates a very quick way to accomplish these goals. If this pattern is followed, PSMTabBarControl will take care of the rest.
– setTabView:
Specifies the instance of NSTabView to be controlled.
– tabView
Returns the instance of NSTabView being controlled.
– setPartnerView:
Specifies a view that will resize to compensate for control size changes in response to hide and show messages.
– partnerView
Returns the instance of a view that will resize to compensate for control size changes in response to hide and show messages.
– setDelegate:
Specifies an object that will receive delegate messages as passed through from the NSTabView instance.
– delegate:
Returns the specified delegate object.
– canCloseOnlyTab
Returns YES if the user is allowed to close a tab when it is the only tab left, NO otherwise.
– setCanCloseOnlyTab:
Controls whether the receiver will present a close button for a single tab in a tab bar.
– styleName
Returns the name of the current drawing style. "Aqua", "Metal", and "Unified" are the currently supported options.
– setStyleNamed:
Specifies the style in which the tabs and control are drawn. "Aqua", "Metal", and "Unified" are the currently supported options.
– hideForSingleTab
Returns YES if the control will hide if there is only one tab left, NO otherwise.
– setHideForSingleTab:
Controls whether the receiver will hide when the user closes all but a single tab in a tab bar.
– showAddTabButton
Returns YES if the control will display a small "add tab" button at the rightmost end of the tabs, NO otherwise.
– setShowAddTabButton:
Controls whether the receiver will will display a small "add tab" button at the rightmost end of the tabs.
– cellMinWidth
Returns the minimum width (in pixels) that a tab will be allowed to occupy.
– setCellMinWidth:
Specifies the maximum width (in pixels) that a tab will be allowed to occupy.
– cellMaxWidth
Returns the maximum width (in pixels) that a tab will be allowed to occupy.
– setCellMaxWidth:
Specifies the maximum width (in pixels) that a tab will be allowed to occupy.
– cellOptimumWidth
Returns the default width (in pixels) that a tab will be allowed to occupy when tabs are drawn with uniform size.
– setCellMaxWidth:
Specifies the default width (in pixels) that a tab will be allowed to occupy when tabs are drawn with uniform size.
– sizeCellsToFit
Returns YES if the control will make the tabs sized to fit the content of the tab, NO otherwise.
– setSizeCellsToFit:
Controls whether the receiver will make the tabs sized to fit the content of the tab.
– allowsDragBetweenWindows
Returns YES if the control allows a user to drag a tab to another instance of this control, NO otherwise.
– setAllowsDragBetweenWindows:
Controls whether the receiver will allow a user to drag a tab to another instance of this control.
– addTabButton
Returns an instance of an NSButton subclass that is used to present the "add tab" button. If "showAddTabButton" is YES, developers must use this method to access the button and specify a target and action for the button.
– overflowPopUpButton
Returns an instance of an NSPopUpButton subclass that is used to present the overflow menu (which shows when there are more tabs than can fit across the control).
– representedTabViewItems
Returns an array of the NSTabViewItems represented by the tabs in the control. Useful if you want to archive the order of the tabs between runs of your program.
– hideTabBar:animate:
If desired, obejcts can tell the tab bar to hide (reduce in size to a single pixel line spanning the window) or show, and optionally whether to animate this effect or not.
Returns an instance of an NSButton subclass that is used to present the "add tab" button. If "showAddTabButton" is YES, developers must use this method to access the button and specify a target and action for the button.
- (PSMRolloverButton *)addTabButton;
If you have configured the control to show the add tab button, you must use this method to access the button and set the target and action for it. Example:
[[tabBar addTabButton] setTarget:self];
[[tabBar addTabButton] setAction:@selector(addNewTab:)];
Returns YES
if the control allows a user to drag a tab to another instance of this control, NO otherwise.
- (BOOL)allowsDragBetweenWindows
The default is YES
.
Returns YES
if the receiver has been configured to allow users to close a single remaining tab.
- (BOOL)canCloseOnlyTab
The default is NO
.
Returns the maximum width (in pixels) that a tab will be allowed to occupy.
- (int)cellMaxWidth
The cellMaxWidth value applies to both uniformly sized tabs, and tabs that are sized to fit. No tab will be drawn wider than the specified value.
Returns the minimum width (in pixels) that a tab will be allowed to occupy.
- (int)cellMinWidth
The cellMinWidth value applies only to uniformly sized tabs. No tab will be drawn smaller than the specified value. Size-to-fit tabs ignore this value, and are made just small enough to fit their content.
Returns the width (in pixels) that a tab will be made to occupy if the tabs are uniformly sized.
- (int)cellOptimumWidth
The cellOptimumWidth value applies only to uniformly sized tabs. All tabs will be drawn at the specified value. Size-to-fit tabs ignore this value, and are made just small enough to fit their content.
Returns the object that will be sent passed-through NSTabView delegate messages.
- (id)delegate
Returns YES
if the receiver has been configured to hide if there is a single remaining tab.
- (BOOL)hideForSingleTab
The default is NO
.
If desired, obejcts can tell the tab bar to hide (reduce in size to a single pixel line spanning the window) or show, and optionally whether to animate this effect or not.
- (void)hideTabBar:(BOOL)hide animate:(BOOL)animate
If hide is YES
the control will shrink to a single pixel line spanning the window; otherwise the control will expand to its normal appearance. If animate is YES
, the shrinking and expanding will happen in a visible animation; otherwise the transition will be instant. There is no effect if the control is already in the specified state.
Returns an instance of an NSPopUpButton subclass that is used to present the overflow menu.
- (PSMOverflowPopUpButton *)overflowPopUpButton;
This method could be used to modify the button or menu if desired.
Returns the object that will be resized to compensate for the changing size of the control during hide/show behavior.
- (id)partnerView
If a partnerView has not been specified, the window will be resized during hide/show.
Returns an array of NSTabViewItems, ordered according to the display order of the tabs in the control.
- (NSMutableArray *)representedTabViewItems;
This method could be used archive the order of the tabs between application runs. When the user reorders tabs via drag and drop, the represented NSTabView does not change order.
If set to YES
, the receiver is configured to allow users to drag a tab to an instance of PSMTabBarControl in another window.
- (void)setAllowsDragBetweenWindows:(BOOL)value
The default is YES
.
If set to YES
, the receiver is configured to allow users to close a single remaining tab.
- (void)setCanCloseOnlyTab:(BOOL)value
The default is NO
.
Specifies the maximum width (in pixels) that a tab will be allowed to occupy.
- (void)setCellMaxWidth:(int)value
No tab will be drawn any wider than the specified value.
Specifies the minimum width (in pixels) that a tab will be allowed to occupy.
- (void)setCellMinWidth:(int)value
No tab will be drawn any smaller than the specified value. This value is ignored when drawing in size-to-fit; tabs are made just small enough to fit their content.
Specifies the width (in pixels) that a tab will occupy when tabs are uniformly sized.
- (void)setCellOptimumWidth:(int)value
This value is ignored when drawing in size-to-fit; tabs are made just small enough to fit their content.
Specifies an object that will receive delegate messages as passed through from the NSTabView instance.
- (void)setDelegate:(id)object
If set to YES
, the receiver is configured to hide when there is a single remaining tab.
- (void)setHideForSingleTab:(BOOL)value
The default is NO
.
Specifies a view that will resize to compensate for control size changes in response to hide and show messages.
- (void)setPartnerView:(id)view
if nil, the control will resize the window in response to hide/show messages.
Specifies the style in which the tabs and control are drawn.
- (void)setStyleNamed:(NSString *)name
"Aqua" and "Metal" are the currently supported options.
Controls whether the receiver will will display a small "add tab" button at the rightmost end of the tabs.
- (void)setShowAddTabButton:(BOOL)value
Default is NO
.
Controls whether the receiver will make the tabs sized to fit the content of the tab.
- (void)setSizeCellsToFit:(BOOL)value
Default is NO
.
Specifies the instance of NSTabView to be controlled.
- (void)setTabView:(NSTabView *)view
This class will not function properly without this outlet being set.
Returns YES if the control will make the tabs sized to fit the content of the tab, NO otherwise.
The default is NO
.
Returns the name of the current drawing style.
- (NSString *)styleName
"Aqua" and "Metal" are the currently supported options.
Returns the instance of NSTabView being controlled.
- (NSTabView *)tabView
This class will not function properly if this object is nil.
You application controller can keep track of activity from the tab view and the user via the following delegate methods.
Sent when a user clicks the close button on a tab.
- (BOOL)tabView:(NSTabView *)tabView shouldCloseTabViewItem:(NSTabViewItem *)tabViewItem
If you return NO
, the tab will not be closed. Please make sure to alert the user as to why with a sheet or dialog.
Sent when tab is about to be closed.
- (void)tabView:(NSTabView *)tabView willCloseTabViewItem:(NSTabViewItem *)tabViewItem
This presents you with an opportunity to clean up the application objects/events/sessions represented by the tab.
Sent after a tab has been closed.
- (void)tabView:(NSTabView *)tabView didCloseTabViewItem:(NSTabViewItem *)tabViewItem
This presents you with an opportunity to clean up the application objects/events/sessions represented by the tab. Don't go trying to modify the tabViewItem - it is about to be released, and has already been removed from the tabView!
Informs the delegate that tabView has selected tabViewItem.
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
Invoked just before tabViewItem in tabView is selected.
- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem
The delegate can return NO
to prevent selection of specific tabs.
Informs the delegate that tabView is about to select tabViewItem.
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem
Informs the delegate that the number of tab view items in tabView has changed.
- (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)tabView