[TOC] [Prev] [Next]

NSTabView

Inherits From:
NSView : NSResponder : NSObject

Conforms To:
NSCoding (NSResponder)
NSObject (NSObject)

Declared In:
AppKit/NSTabView.h

Class Description

Note: The NSTabView class and its supporting class NSTabViewItem are under development. If you want to use these classes, you will have to instantiate them programmatically because Interface Builder does not yet include support for them.

An NSTabView provides a convenient mechanism for presenting information in a multi-page format. The view is distinguished by a row of tabs that give the visual appearance of folder tabs, as shown in the figure below. The user selects the desired page by clicking the appropriate tab or using the arrow keys to move between pages. Each page displays a view hierarchy provided by your application.

An NSTabView can support a multi-page format without visible tabs. For example, instead of tabs, you might use a pop-up menu or radio buttons, similar to those shown in the illustration, to let the user select from several view pages. When a tab view is drawn with tabs (the default), the border must be bezeled. When a tab view is drawn without tabs, the view can have a bezeled border, a lined border, or no border.

An NSTabView keeps a zero-based array of NSTabViewItems, one per tab in the view. A tab view item provides access to a tab's color, state, label text, initial first responder, and associated view.Your application can supply each tab view item with an optional identifier object to customize tab handling. For more information, see the documentation for NSTabViewItem.Tab label text defaults to the default font and font size used for standard interface items, such as button labels and menu items. When you invoke setFont: to change the tab view's font, tab height and width is adjusted automatically to accommodate a new font size. If the view allows truncating, tab labels are truncated as needed.

Delegate Messages

NSTabView defines delegate messages to allow the delegate to control or react to changes in selection and changes in the number of tabs:

tabViewDidChangeNumberOfTabViewItems: informs the delegate that the number of tab view items in tabView has changed.

tabView:didSelectTabViewItem: informs the delegate that the specified tab view item has been selected.

tabView:shouldSelectTabViewItem: informs the delegate that the specified tab view item is about to be selected. The delegate can return NO to prevent the selection.

tabView:willSelectTabViewItem: informs the delegate that the specified tab view item will be selected. The delegate can perform tasks related to the selection, but cannot prevent it.


Method Types

Adding and removing tabs
- addTabViewItem:
- insertTabViewItem: atIndex:
- removeTabViewItem:
Accessing tabs
- indexOfTabViewItem:
- indexOfTabViewItemWithIdentifier:
- numberOfTabViewItems
- tabViewItemAtIndex:
- tabViewItems
Selecting a tab
- selectFirstTabViewItem:
- selectLastTabViewItem:
- selectNextTabViewItem:
- selectPreviousTabViewItem:
- selectedTabViewItem
- selectTabViewItemAtIndex:
- takeSelectedTabViewItemFromSender:
Modifying the font
- font
- setFont:
Modifying the tab type
- setTabViewType:
- tabViewType
Manipulating the background
- drawsBackground
- setDrawsBackground:
Determining the size
- minimumSize
- contentRect
Truncating tab labels
- allowsTruncatedLabels
- setAllowsTruncatedLabels:
Assigning a delegate
- setDelegate:
- delegate
Event handling
- tabViewItemAtPoint:

Instance Methods


addTabViewItem:

- (void)addTabViewItem:(NSTabViewItem *)tabViewItem

Adds the tab item specified by tabViewItem. The item is added at the end of the array of tab items, so that the new tab appears on the right side of the view. If the delegate supports it, invokes the delegate's tabViewDidChangeNumberOfTabViewItems: method.

See also: - insertTabViewItem:atIndex:, - numberOfTabViewItems, - removeTabViewItem:, - tabViewItemAtIndex:, - tabViewItems


allowsTruncatedLabels

- (BOOL)allowsTruncatedLabels

Returns YES if the tab view allows truncating for labels that don't fit on a tab. The default is NO. When truncating is allowed, the tab view inserts an ellipsis, if necessary, to fit a label in the tab.

See also: - setAllowsTruncatedLabels:


contentRect

- (NSRect)contentRect

Returns the rectangle describing the content area of a tab view. This area does not include the space required for the tab view's tabs or borders (if any).


delegate

- (id)delegate

Returns the tab view's delegate.

See also: - setDelegate:


drawsBackground

- (BOOL) drawsBackground

Returns YES if the tab view draws a background color when the tab view type is NSNoTabsNoBorder. If the tab view uses bezeled edges or a line border, the appropriate background color for that border is used.

See also: - setTabViewType:, - setDrawsBackground:


font

- (NSFont *)font

Returns the font for tab label text.

See also: - setFont:


indexOfTabViewItem:

- (int)indexOfTabViewItem:(NSTabViewItem *)tabViewItem

Returns the index of the item that matches tabViewItem, or NSNotFound if the item is not found. A tab view keeps an array containing one tab view item for each tab in the view-this is the array that is searched. The returned index is base 0.

See also: - indexOfTabViewItemWithIdentifier:, - insertTabViewItem:atIndex:, - numberOfTabViewItems, - tabViewItemAtIndex:


indexOfTabViewItemWithIdentifier:

- (int)indexOfTabViewItemWithIdentifier:(id)identifier

Returns the index of the item that matches identifier, or NSNotFound if the item is not found. A tab view keeps an array containing one tab view item for each tab in the view-this is the array that is searched. The returned index is base 0.

See also: - indexOfTabViewItem:, - insertTabViewItem:atIndex:, - numberOfTabViewItems, - tabViewItemAtIndex:


insertTabViewItem:atIndex:

- (void)insertTabViewItem:(NSTabViewItem *)tabViewItem
atIndex:(int)index

Inserts tabViewItem into the tab view's array of tab view items at index. The index parameter is base 0. If there is a delegate and the delegate supports it, sends the delegate the tabViewDidChangeNumberOfTabViewItems: message.

See also: - indexOfTabViewItem:, - indexOfTabViewItemWithIdentifier:, - numberOfTabViewItems, - tabViewItemAtIndex:


minimumSize

- (NSSize)minimumSize

Returns the minimum size necessary for the view to display tabs in a useful way. You can use the value returned by this method to limit how much a user can resize a tab view.

See also: - setTabViewType:


numberOfTabViewItems

- (int)numberOfTabViewItems

Returns the number of items in the tab view's array of tab view items. Because there is one item in the array for each tab in the view, this is equivalent to the number of tabs in the view.

See also: - indexOfTabViewItem:, - tabViewItems


removeTabViewItem:

- (void)removeTabViewItem:(NSTabViewItem *)tabViewItem

Removes the item specified by tabViewItem from the tab view's array of tab view items. If there is a delegate and the delegate supports it, sends the delegate the tabViewDidChangeNumberOfTabViewItems: message.

See also: - addTabViewItem:, - insertTabViewItem:atIndex:, - tabViewItems


selectFirstTabViewItem:

- (void)selectFirstTabViewItem:(id)sender

Selects the first tab view item. The sender parameter is ignored.

See also: - selectTabViewItem:


selectLastTabViewItem:

- (void)selectLastTabViewItem:(id)sender

Selects the last tab view item. The sender parameter is ignored.

See also: - selectTabViewItem:


selectNextTabViewItem:

- (void)selectNextTabViewItem:(id)sender

Selects the next tab view item in the sequence. If the currently visible item is the last item in the sequence, this method does nothing and the last page remains displayed. The sender parameter is ignored.

See also: - selectTabViewItem:


selectPreviousTabViewItem:

- (void)selectPreviousTabViewItem:(id)sender

Selects the previous tab view item in the sequence. If the currently visible item is the first item in the sequence, this method does nothing and the first page remains displayed. The sender parameter is ignored.

See also: - selectTabViewItem:


selectedTabViewItem

- (NSTabViewItem *)selectedTabViewItem

Returns the tab view item for the currently-selected tab, or nil if no item is selected. If there is a delegate and the delegate supports it, sends the delegate the shouldSelectTabViewItem: message.

See also: - selectTabViewItemAtIndex:


selectTabViewItem:

- (void)selectTabViewItem:(NSTabViewItem *)tabViewItem

Selects the tab view item specified by tabViewItem. If there is a delegate and the delegate supports it, sends the delegate the shouldSelectTabViewItem: message.

See also: - insertTabViewItem:atIndex:, - selectedTabViewItem


selectTabViewItemAtIndex:

- (void)selectTabViewItemAtIndex:(int)index

Selects the tab view item specified by index. The index parameter is base 0.

See also: - insertTabViewItem:atIndex:, - selectedTabViewItem


setAllowsTruncatedLabels:

- (void)setAllowsTruncatedLabels:(BOOL)allowTruncatedLabels

Returns YES if the tab view allows truncating for names that don't fit on a tab.

See also: - allowsTruncatedLabels:


setDelegate:

- (void)setDelegate:(id)anObject

Sets the tab view's delegate to anObject.

See also: - delegate


setDrawsBackground:

- (void)setDrawsBackground:(BOOL)flag

Sets whether a background is drawn when the view type is NSNoTabsNoBorder. If the tab view has a bezeled border or a line border the appropriate background for that border is used.

See also: - setTabViewType:, - drawsBackground


setFont:

- (void)setFont:(NSFont *)font

Sets the font for tab label text to font. Tab height is adjusted automatically to accommodate a new font size. If the view allows truncating, tab labels are truncated as needed.

See also: - allowsTruncatedLabels:, - font, - setAllowsTruncatedLabels:


setTabViewType:

- (void)setTabViewType:(NSTabViewType)tabViewType

Sets the tab type to tabViewType. The available types are:

Tab Type Description
NSTopTabsBezelBorder The view includes tabs and has a bezeled border (the default)
NSNoTabsBezelBorder The view does not include tabs and has a bezeled border
NSNoTabsLineBorder The view does not include tabs and has a lined border
NSNoTabsNoBorder The view does not include tabs and has no border

See also: - tabViewType


tabViewItemAtIndex:

- (NSTabViewItem *)tabViewItemAtIndex:(int)index

Returns the tab view item at index in the tab view's array of items. The index parameter is base 0.

See also: - indexOfTabViewItem:, - insertTabViewItem:atIndex:, - tabViewItems


tabViewItemAtPoint:

- (NSTabViewItem *)tabViewItemAtPoint:(NSPoint)point

Returns the tab view item identified by point. You can use this method to find a tab view item based on a user's mouse click.


tabViewItems

- (NSArray *)tabViewItems

Returns the tab view's array of tab view items. A tab view keeps an array containing one tab view item for each tab in the view. The array is base 0.

See also: - numberOfTabViewItems, - tabViewItemAtIndex:


tabViewType

- (NSTabViewType)tabViewType

Returns the tab type for the tab view. The available types are described with the setTabViewType: method.


takeSelectedTabViewItemFromSender:

- (void)takeSelectedTabViewItemFromSender:(id)sender

If sender responds to the indexOfSelectedItem method, this method invokes that method and selects the tab view item at the specified index. If sender does not respond to indexOfSelectedItem but is an instance of NSMatrix, this method uses the index of the matrix' currently selected cell.

The location of the selected cell is a zero-based number, obtained by counting the number of cells up to and including the selected cell. Cells are counted from left to right and from top to bottom. For example in a 5 by 5 matrix, if the selected cell is three rows down in column five (location [2,4] in the matrix), the corresponding index would be 14.


Methods Implemented By the Delegate

tabViewDidChangeNumberOfTabViewItems:

- (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)tabView

Informs the delegate that the number of tab view items in tabView has changed.

See also: - numberOfTabViewItems (NSTabView class)


tabView:didSelectTabViewItem:

- (void)tabView:(NSTabView *)tabView
shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem

Informs the delegate that tabView has selected tabViewItem.


tabView:shouldSelectTabViewItem:

- ((BOOL)tabView:(NSTabView *)tabView
shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem

Invoked just before tabViewItem in tabView is selected. The delegate can return NO to prevent selection of specific tabs.


tabView:willSelectTabViewItem:

- (void)tabView:(NSTabView *)tabView
willSelectTabViewItem:(NSTabViewItem *)tabViewItem

Informs the delegate that tabView is about to select tabViewItem.



[TOC] [Prev] [Next]

Copyright © 1997, Apple Computer, Inc. All rights reserved.