mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
First cut at working tabView controller
This commit is contained in:
parent
3071502cba
commit
0add17530a
6 changed files with 196 additions and 1 deletions
|
@ -50,7 +50,6 @@ typedef NSUInteger NSTabViewControllerTabStyle;
|
|||
NSTabViewControllerTabStyle _tabStyle;
|
||||
NSViewControllerTransitionOptions _transitionOptions;
|
||||
BOOL _canPropagateSelectedChildViewControllerTitle;
|
||||
NSMutableArray *_tabViewItems;
|
||||
}
|
||||
|
||||
- (NSTabViewControllerTabStyle) tabStyle;
|
||||
|
|
|
@ -41,6 +41,7 @@ typedef enum {
|
|||
@class NSColor;
|
||||
@class NSTabView;
|
||||
@class NSView;
|
||||
@class NSViewController;
|
||||
|
||||
@interface NSTabViewItem : NSObject <NSCoding>
|
||||
{
|
||||
|
@ -53,7 +54,9 @@ typedef enum {
|
|||
NSTabView *_tabview;
|
||||
NSRect _rect; // cached
|
||||
NSString *_toolTip;
|
||||
NSViewController *_viewController;
|
||||
}
|
||||
|
||||
- (id) initWithIdentifier:(id)identifier;
|
||||
|
||||
- (void)setIdentifier:(id)identifier;
|
||||
|
@ -78,6 +81,13 @@ typedef enum {
|
|||
- (void)drawLabel:(BOOL)shouldTruncateLabel
|
||||
inRect:(NSRect)tabRect;
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST)
|
||||
- (NSViewController *) viewController;
|
||||
- (void) setViewController: (NSViewController *)vc;
|
||||
|
||||
+ (instancetype) tabViewItemWithViewController: (NSViewController *)vc;
|
||||
#endif
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
|
||||
- (NSString *)toolTip;
|
||||
- (void)setToolTip:(NSString *)newToolTip;
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
- (void) setSplitView: (NSSplitView *)splitView
|
||||
{
|
||||
[self setView: splitView];
|
||||
[splitView setDelegate: self];
|
||||
}
|
||||
|
||||
- (NSSplitViewItem *) splitViewItemForViewController: (NSViewController *)vc
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#import "AppKit/NSSplitViewController.h"
|
||||
#import "AppKit/NSSplitViewItem.h"
|
||||
#import "AppKit/NSSplitView.h"
|
||||
#import "AppKit/NSTabViewController.h"
|
||||
#import "AppKit/NSTabViewItem.h"
|
||||
#import "AppKit/NSTabView.h"
|
||||
#import "AppKit/NSWindow.h"
|
||||
#import "AppKit/NSApplication.h"
|
||||
#import "AppKit/NSView.h"
|
||||
|
@ -130,6 +133,12 @@
|
|||
NSSplitViewItem *item = [[svc splitViewItems] objectAtIndex: idx];
|
||||
[item setViewController: _destinationController];
|
||||
}
|
||||
else if ([_relationship isEqualToString: @"tabItems"])
|
||||
{
|
||||
NSTabViewController *tvc = (NSTabViewController *)_sourceController;
|
||||
NSTabViewItem *item = [NSTabViewItem tabViewItemWithViewController: _destinationController];
|
||||
[tvc addTabViewItem: item];
|
||||
}
|
||||
}
|
||||
else if ([_kind isEqualToString: @"modal"])
|
||||
{
|
||||
|
|
|
@ -22,9 +22,166 @@
|
|||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSArray.h>
|
||||
|
||||
#import "AppKit/NSTabViewController.h"
|
||||
#import "AppKit/NSTabViewItem.h"
|
||||
#import "AppKit/NSTabView.h"
|
||||
|
||||
#import "GSFastEnumeration.h"
|
||||
|
||||
@implementation NSTabViewController
|
||||
- (NSTabViewControllerTabStyle) tabStyle
|
||||
{
|
||||
return _tabStyle;
|
||||
}
|
||||
|
||||
- (void) setTabStyle: (NSTabViewControllerTabStyle)ts
|
||||
{
|
||||
_tabStyle = ts;
|
||||
}
|
||||
|
||||
- (NSTabView *) tabView
|
||||
{
|
||||
return (NSTabView *)[self view];
|
||||
}
|
||||
|
||||
- (void) setTabView: (NSTabView *)tv
|
||||
{
|
||||
[self setView: tv];
|
||||
[tv setDelegate: self];
|
||||
}
|
||||
|
||||
- (NSViewControllerTransitionOptions) transitionOptions
|
||||
{
|
||||
return _transitionOptions;
|
||||
}
|
||||
|
||||
- (void) setTransitionOptions: (NSViewControllerTransitionOptions)options
|
||||
{
|
||||
_transitionOptions = options;
|
||||
}
|
||||
|
||||
- (BOOL) canPropagateSelectedChildViewControllerTitle
|
||||
{
|
||||
return _canPropagateSelectedChildViewControllerTitle;
|
||||
}
|
||||
|
||||
- (void) setCanPropagateSelectedChildViewControllerTitle: (BOOL)flag
|
||||
{
|
||||
_canPropagateSelectedChildViewControllerTitle = flag;
|
||||
}
|
||||
|
||||
// Managing tabViewItems...
|
||||
- (NSArray *) tabViewItems
|
||||
{
|
||||
return [[self tabView] tabViewItems];
|
||||
}
|
||||
|
||||
- (void) setTabViewItems: (NSArray *)items
|
||||
{
|
||||
FOR_IN(NSTabViewItem*, item, items)
|
||||
[[self tabView] addTabViewItem: item];
|
||||
END_FOR_IN(items);
|
||||
}
|
||||
|
||||
- (NSTabViewItem *) tabViewItemForViewController: (NSViewController *)controller
|
||||
{
|
||||
NSArray *tabViewItems = [[self tabView] tabViewItems];
|
||||
FOR_IN(NSTabViewItem*, tvi, tabViewItems)
|
||||
if ([tvi viewController] == controller)
|
||||
{
|
||||
return tvi;
|
||||
}
|
||||
END_FOR_IN(tabViewItems);
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) addTabViewItem: (NSTabViewItem *)item
|
||||
{
|
||||
[[self tabView] addTabViewItem: item];
|
||||
}
|
||||
|
||||
- (void) insertTabViewItem: (NSTabViewItem *)item
|
||||
atIndex: (NSInteger)index
|
||||
{
|
||||
[[self tabView] insertTabViewItem: item atIndex: index];
|
||||
}
|
||||
|
||||
- (void) removeTabViewItem: (NSTabViewItem *)item
|
||||
{
|
||||
[[self tabView] removeTabViewItem: item];
|
||||
}
|
||||
|
||||
- (NSInteger) selectedTabViewItemIndex
|
||||
{
|
||||
return [[self tabView] indexOfTabViewItem: [[self tabView] selectedTabViewItem]];
|
||||
}
|
||||
|
||||
- (void) setSelectedTabViewItemIndex: (NSInteger)idx
|
||||
{
|
||||
[[self tabView] selectTabViewItemAtIndex: idx];
|
||||
}
|
||||
|
||||
// Responding to tabview actions...
|
||||
- (BOOL)tabView:(NSTabView *)tabView
|
||||
shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)tabView:(NSTabView *)tabView
|
||||
willSelectTabViewItem:(NSTabViewItem *)tabViewItem
|
||||
{
|
||||
// not implemented
|
||||
}
|
||||
|
||||
- (void)tabView:(NSTabView *)tabView
|
||||
didSelectTabViewItem:(NSTabViewItem *)tabViewItem
|
||||
{
|
||||
// not implemented
|
||||
}
|
||||
|
||||
// Responding to toolbar actions...
|
||||
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
|
||||
itemForItemIdentifier:(NSToolbarItemIdentifier)itemIdentifier
|
||||
willBeInsertedIntoToolbar:(BOOL)flag
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
|
||||
{
|
||||
return [NSArray array];
|
||||
}
|
||||
|
||||
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
|
||||
{
|
||||
return [NSArray array];
|
||||
}
|
||||
|
||||
// NSCoding
|
||||
- (instancetype) initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
self = [super initWithCoder: coder];
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
if ([coder containsValueForKey: @"NSTabView"])
|
||||
{
|
||||
NSTabView *tv = [coder decodeObjectForKey: @"NSTabView"];
|
||||
[self setTabView: tv];
|
||||
}
|
||||
if ([coder containsValueForKey: @"NSTabViewItems"])
|
||||
{
|
||||
NSArray *items = [coder decodeObjectForKey: @"NSTabViewItems"];
|
||||
[self setTabViewItems: items];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)coder
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#import "AppKit/NSTabView.h"
|
||||
#import "AppKit/NSTabViewItem.h"
|
||||
#import "AppKit/PSOperators.h"
|
||||
#import "AppKit/NSViewController.h"
|
||||
|
||||
@implementation NSTabViewItem
|
||||
|
||||
|
@ -72,6 +73,24 @@
|
|||
NSStringFromClass([self class]), _label, _ident];
|
||||
}
|
||||
|
||||
- (NSViewController *) viewController
|
||||
{
|
||||
return _viewController;
|
||||
}
|
||||
|
||||
- (void) setViewController: (NSViewController *)vc
|
||||
{
|
||||
_viewController = vc; // weak
|
||||
[self setView: [vc view]];
|
||||
}
|
||||
|
||||
+ (instancetype) tabViewItemWithViewController: (NSViewController *)vc
|
||||
{
|
||||
NSTabViewItem *item = [[NSTabViewItem alloc] init];
|
||||
[item setViewController: vc];
|
||||
return item;
|
||||
}
|
||||
|
||||
// Set identifier.
|
||||
|
||||
- (void) setIdentifier: (id)identifier
|
||||
|
|
Loading…
Reference in a new issue