libs-gui/Source/NSStoryboardSegue.m

212 lines
5.7 KiB
Mathematica
Raw Normal View History

2020-01-20 20:58:19 +00:00
/* Implementation of class NSStoryboardSegue
2020-07-06 13:50:55 +00:00
Copyright (C) 2020 Free Software Foundation, Inc.
2023-10-01 11:47:05 +00:00
2020-01-20 20:58:19 +00:00
By: Gregory Casamento
Date: Mon Jan 20 15:57:31 EST 2020
This file is part of the GNUstep Library.
2023-10-01 11:47:05 +00:00
2020-01-20 20:58:19 +00:00
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
2023-10-01 11:47:05 +00:00
2020-01-20 20:58:19 +00:00
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
2023-10-01 11:47:05 +00:00
2020-01-20 20:58:19 +00:00
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/
2020-07-02 17:24:48 +00:00
#import <Foundation/NSString.h>
#import <Foundation/NSGeometry.h>
2020-07-02 20:39:40 +00:00
#import "AppKit/NSStoryboardSegue.h"
2020-07-02 20:39:40 +00:00
#import "AppKit/NSWindowController.h"
#import "AppKit/NSViewController.h"
2020-07-21 11:51:43 +00:00
#import "AppKit/NSSplitViewController.h"
2020-07-22 06:19:35 +00:00
#import "AppKit/NSSplitViewItem.h"
#import "AppKit/NSSplitView.h"
#import "AppKit/NSTabViewController.h"
#import "AppKit/NSTabViewItem.h"
#import "AppKit/NSTabView.h"
2020-07-02 20:39:40 +00:00
#import "AppKit/NSWindow.h"
#import "AppKit/NSApplication.h"
2020-07-21 11:51:43 +00:00
#import "AppKit/NSView.h"
#import "AppKit/NSPopover.h"
2020-01-20 20:58:19 +00:00
@implementation NSStoryboardSegue
- (id) sourceController
{
return _sourceController;
}
- (id) destinationController
{
return _destinationController;
}
- (NSStoryboardSegueIdentifier)identifier
{
return _identifier;
}
2020-07-02 17:24:48 +00:00
- (void) _setHandler: (GSStoryboardSeguePerformHandler)handler
{
ASSIGN(_handler, handler);
}
- (void) _setDestinationController: (id)controller
{
_destinationController = controller;
}
- (void) _setSourceController: (id)controller
{
_sourceController = controller;
}
2023-10-01 11:47:05 +00:00
+ (instancetype) segueWithIdentifier: (NSStoryboardSegueIdentifier)identifier
source: (id)sourceController
destination: (id)destinationController
performHandler: (GSStoryboardSeguePerformHandler)performHandler
{
NSStoryboardSegue *segue = [[NSStoryboardSegue alloc] initWithIdentifier: identifier
2023-10-01 11:47:05 +00:00
source: sourceController
destination: destinationController];
AUTORELEASE(segue);
2020-07-02 17:24:48 +00:00
[segue _setHandler: performHandler];
return segue;
}
2023-10-01 11:47:05 +00:00
- (instancetype) initWithIdentifier: (NSStoryboardSegueIdentifier)identifier
source: (id)sourceController
destination: (id)destinationController
{
self = [super init];
if (self != nil)
{
ASSIGN(_sourceController, sourceController);
ASSIGN(_destinationController, destinationController);
ASSIGN(_identifier, identifier);
}
return self;
}
2020-07-02 17:24:48 +00:00
- (void) dealloc
{
RELEASE(_sourceController);
RELEASE(_destinationController);
RELEASE(_identifier);
RELEASE(_kind);
RELEASE(_relationship);
RELEASE(_handler);
[super dealloc];
}
2020-07-06 03:06:53 +00:00
- (void) perform
{
2020-07-02 20:39:40 +00:00
// Perform segue based on it's kind...
2020-07-02 17:24:48 +00:00
if ([_kind isEqualToString: @"relationship"])
{
if ([_relationship isEqualToString: @"window.shadowedContentViewController"])
2023-10-01 11:47:05 +00:00
{
NSWindow *w = [_sourceController window];
NSView *v = [_destinationController view];
[w setContentView: v];
[w setTitle: [_destinationController title]];
[_sourceController showWindow: self];
}
2020-07-21 11:51:43 +00:00
else if ([_relationship isEqualToString: @"splitItems"])
2023-10-01 11:47:05 +00:00
{
NSView *v = [_destinationController view];
NSSplitViewController *svc = (NSSplitViewController *)_sourceController;
[[svc splitView] addSubview: v];
NSUInteger idx = [[[svc splitView] subviews] count] - 1;
NSSplitViewItem *item = [[svc splitViewItems] objectAtIndex: idx];
[item setViewController: _destinationController];
}
else if ([_relationship isEqualToString: @"tabItems"])
2023-10-01 11:47:05 +00:00
{
NSTabViewController *tvc = (NSTabViewController *)_sourceController;
NSTabViewItem *item = [NSTabViewItem tabViewItemWithViewController: _destinationController];
[tvc addTabViewItem: item];
}
2020-07-02 17:24:48 +00:00
}
else if ([_kind isEqualToString: @"modal"])
{
NSWindow *w = nil;
if ([_destinationController isKindOfClass: [NSWindowController class]])
2023-10-01 11:47:05 +00:00
{
w = [_destinationController window];
}
else
2023-10-01 11:47:05 +00:00
{
w = [NSWindow windowWithContentViewController: _destinationController];
[w setTitle: [_destinationController title]];
}
RETAIN(w);
2020-07-04 19:14:48 +00:00
[w center];
[NSApp runModalForWindow: w];
2020-07-02 17:24:48 +00:00
}
else if ([_kind isEqualToString: @"show"])
{
if ([_destinationController isKindOfClass: [NSWindowController class]])
2023-10-01 11:47:05 +00:00
{
[_destinationController showWindow: _sourceController];
}
else
2023-10-01 11:47:05 +00:00
{
NSWindow *w = [NSWindow windowWithContentViewController: _destinationController];
[w setTitle: [_destinationController title]];
[w center];
[w orderFrontRegardless];
RETAIN(w);
}
2020-07-02 20:39:40 +00:00
}
else if ([_kind isEqualToString: @"popover"])
{
2023-10-01 10:56:53 +00:00
if (_popover == nil)
{
NSPopover *po = [[NSPopover alloc] init];
NSRect rect = [_popoverAnchorView frame];
_popover = po; // weak... since we manually release...
[po setBehavior: _popoverBehavior];
[po setContentViewController: _destinationController];
[po showRelativeToRect: rect
ofView: _popoverAnchorView
preferredEdge: _preferredEdge];
}
else
{
if ([_popover behavior] == NSPopoverBehaviorTransient)
{
2023-10-01 11:47:05 +00:00
[_destinationController dismissController: nil];
2023-10-01 10:56:53 +00:00
[_popover close];
RELEASE(_popover);
_popover = nil;
}
}
}
else if ([_kind isEqualToString: @"sheet"])
{
}
else if ([_kind isEqualToString: @"custom"])
{
}
2020-07-02 20:39:40 +00:00
if (_handler != nil)
{
CALL_BLOCK_NO_ARGS(_handler);
2020-07-02 17:24:48 +00:00
}
}
2020-01-20 20:58:19 +00:00
@end