BWToolkit / BWTabViewController.h

//  KSTabViewController.h
//  Created by Mike Abdullah on 17/08/2009.
//  Copyright 2009 Karelia Software. All rights reserved.

#import "BWViewController.h"

/*! A neat way to intelligently associate an array of view controllers with the items of an NSTabView.

#ifndef MAC_OS_X_VERSION_10_6
@protocol NSTabViewDelegate <NSObject> @end

@interface BWTabViewController : BWViewController <NSTabViewDelegate, NSCoding>
    NSTabView       *_tabView;
    NSTabViewType   _tabViewType;
    NSMutableArray      *_viewControllers;
    NSMutableArray      *_tabViewItems;
    NSViewController    *_selectedViewController;

#pragma mark Lifecycle

// If you're not loading from a nib, this is handy to specify the most basic tabview property
- (id)initWithTabViewType:(NSTabViewType)type;  // designated initializer
- (id)init; // the default top tabs look

- (void)close;  // sends -close message to any .viewControllers that respond to it

#pragma mark View Properties

@property(nonatomic, retain) IBOutlet NSTabView *tabView;   // separate to -view. Do NOT rely on them being the same.
@property(nonatomic, readonly, getter=isTabViewLoaded) BOOL tabViewLoaded;

#pragma mark Managing the View Controllers

@property(nonatomic, copy, readonly) NSArray *viewControllers;
- (NSUInteger)countOfViewControllers;  // improves efficiency & eases leak hunting

- (void)insertViewController:(NSViewController *)controller atIndex:(NSUInteger)index;
- (void)addViewController:(NSViewController *)controller;
- (void)removeViewController:(NSViewController *)controller;

- (NSViewController *)viewControllerWithIdentifier:(NSString *)identifier;

#pragma mark Managing the Selected Tab

//  Both are KVO-compliant
@property(nonatomic, assign) NSViewController *selectedViewController;
@property(nonatomic) NSUInteger selectedIndex;

//  For subclasses to know when selection is changing without needing KVO. Default implementation does nothing.
- (void)willSelectViewController:(NSViewController *)controller;
- (void)didSelectViewController;

//  NSTabViewDelegate methods that KSTabViewController implements, so be sure to call super if you override them
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem;

#pragma mark Layout

// To answer the question: "If I wanted to display content of x size, what size would I have to make receiver's view?"
// Note the result is in the reciever's view's coordinate system
- (NSSize)viewSizeForContentSize:(NSSize)contentSize;