1999-12-08 15:04:57 +00:00
|
|
|
|
/* GormInspectorsManager.m
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Author: Richard Frith-Macdonald <richard@brainstrom.co.uk>
|
|
|
|
|
* Date: 1999
|
|
|
|
|
*
|
|
|
|
|
* This file is part of GNUstep.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "GormPrivate.h"
|
|
|
|
|
|
|
|
|
|
@implementation NSObject (IBInspectorClassNames)
|
|
|
|
|
- (NSString*) inspectorClassName
|
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
return @"GormObjectInspector";
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
- (NSString*) connectInspectorClassName
|
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
return @"GormObjectInspector";
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
- (NSString*) sizeInspectorClassName
|
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
return @"GormObjectInspector";
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
- (NSString*) helpInspectorClassName
|
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
return @"GormObjectInspector";
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
- (NSString*) classInspectorClassName
|
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
return @"GormObjectInspector";
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The GormEmptyInspector is a placeholder for an empty selection.
|
|
|
|
|
*/
|
|
|
|
|
@interface GormEmptyInspector : IBInspector
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation GormEmptyInspector
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
RELEASE(window);
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
self = [super init];
|
|
|
|
|
if (self != nil)
|
|
|
|
|
{
|
|
|
|
|
NSView *contents;
|
|
|
|
|
NSButton *button;
|
|
|
|
|
|
|
|
|
|
window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, 272, 360)
|
|
|
|
|
styleMask: NSBorderlessWindowMask
|
|
|
|
|
backing: NSBackingStoreRetained
|
|
|
|
|
defer: NO];
|
|
|
|
|
contents = [window contentView];
|
|
|
|
|
button = [[NSButton alloc] initWithFrame: [contents bounds]];
|
|
|
|
|
[button setAutoresizingMask:
|
|
|
|
|
NSViewHeightSizable | NSViewWidthSizable];
|
|
|
|
|
[button setStringValue: @"Empty Selection"];
|
|
|
|
|
[button setBordered: NO];
|
|
|
|
|
[contents addSubview: button];
|
|
|
|
|
RELEASE(button);
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The GormObjectInspector is a placeholder for any object without a
|
|
|
|
|
* suitable inspector.
|
|
|
|
|
*/
|
|
|
|
|
@interface GormObjectInspector : IBInspector
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation GormObjectInspector
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
RELEASE(window);
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
self = [super init];
|
|
|
|
|
if (self != nil)
|
|
|
|
|
{
|
|
|
|
|
NSView *contents;
|
|
|
|
|
NSButton *button;
|
|
|
|
|
|
|
|
|
|
window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, 272, 360)
|
|
|
|
|
styleMask: NSBorderlessWindowMask
|
|
|
|
|
backing: NSBackingStoreRetained
|
|
|
|
|
defer: NO];
|
|
|
|
|
contents = [window contentView];
|
|
|
|
|
button = [[NSButton alloc] initWithFrame: [contents bounds]];
|
|
|
|
|
[button setAutoresizingMask:
|
|
|
|
|
NSViewHeightSizable | NSViewWidthSizable];
|
|
|
|
|
[button setStringValue: @"Unknown object"];
|
|
|
|
|
[button setBordered: NO];
|
|
|
|
|
[contents addSubview: button];
|
|
|
|
|
RELEASE(button);
|
|
|
|
|
}
|
|
|
|
|
return self;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
1999-12-08 15:19:11 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
1999-12-08 15:19:11 +00:00
|
|
|
|
/*
|
|
|
|
|
* The GormMultipleInspector is a placeholder for a multiple selection.
|
|
|
|
|
*/
|
|
|
|
|
@interface GormMultipleInspector : IBInspector
|
1999-12-08 15:04:57 +00:00
|
|
|
|
@end
|
|
|
|
|
|
1999-12-08 15:19:11 +00:00
|
|
|
|
@implementation GormMultipleInspector
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
RELEASE(window);
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
self = [super init];
|
|
|
|
|
if (self != nil)
|
|
|
|
|
{
|
|
|
|
|
NSView *contents;
|
|
|
|
|
NSButton *button;
|
|
|
|
|
|
|
|
|
|
window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, 272, 360)
|
|
|
|
|
styleMask: NSBorderlessWindowMask
|
|
|
|
|
backing: NSBackingStoreRetained
|
|
|
|
|
defer: NO];
|
|
|
|
|
contents = [window contentView];
|
|
|
|
|
button = [[NSButton alloc] initWithFrame: [contents bounds]];
|
|
|
|
|
[button setAutoresizingMask:
|
|
|
|
|
NSViewHeightSizable | NSViewWidthSizable];
|
|
|
|
|
[button setStringValue: @"Multiple Selection"];
|
|
|
|
|
[button setBordered: NO];
|
|
|
|
|
[contents addSubview: button];
|
|
|
|
|
RELEASE(button);
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
@implementation GormInspectorsManager
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
1999-12-08 15:19:11 +00:00
|
|
|
|
RELEASE(emptyInspector);
|
|
|
|
|
RELEASE(multipleInspector);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
RELEASE(panel);
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
NSCell *cell;
|
|
|
|
|
NSRect contentRect = {{0, 0}, {272, 420}};
|
|
|
|
|
NSRect selectionRect = {{0, 378}, {272, 52}};
|
1999-12-08 15:19:11 +00:00
|
|
|
|
NSRect dividerRect = {{0, 361}, {272, 2}};
|
1999-12-08 15:04:57 +00:00
|
|
|
|
NSRect inspectorRect = {{0, 0}, {272, 360}};
|
|
|
|
|
unsigned int style = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask;
|
|
|
|
|
|
|
|
|
|
panel = [[NSPanel alloc] initWithContentRect: contentRect
|
|
|
|
|
styleMask: style
|
|
|
|
|
backing: NSBackingStoreRetained
|
|
|
|
|
defer: NO];
|
1999-12-08 15:19:11 +00:00
|
|
|
|
divider = [[NSBox alloc] initWithFrame: dividerRect];
|
|
|
|
|
[divider setBorderType: NSLineBorder];
|
|
|
|
|
[divider setTitlePosition: NSNoTitle];
|
|
|
|
|
[divider setAutoresizingMask: NSViewWidthSizable|NSViewMinYMargin];
|
|
|
|
|
[[panel contentView] addSubview: divider];
|
|
|
|
|
RELEASE(divider);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
|
|
[panel setTitle: @"Inspector"];
|
|
|
|
|
[panel setMinSize: [panel frame].size];
|
|
|
|
|
|
|
|
|
|
selectionView = [[NSMatrix alloc] initWithFrame: selectionRect
|
|
|
|
|
mode: NSRadioModeMatrix
|
|
|
|
|
cellClass: [NSCell class]
|
|
|
|
|
numberOfRows: 1
|
|
|
|
|
numberOfColumns: 4];
|
|
|
|
|
[selectionView setTarget: self];
|
|
|
|
|
[selectionView setAction: @selector(setCurrentInspector:)];
|
|
|
|
|
[selectionView setCellSize: NSMakeSize(52,52)];
|
|
|
|
|
[selectionView setIntercellSpacing: NSMakeSize(0,0)];
|
|
|
|
|
[selectionView setAutoresizingMask: NSViewWidthSizable|NSViewMinYMargin];
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 0];
|
|
|
|
|
[cell setStringValue: @"Attr"];
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 1];
|
|
|
|
|
[cell setStringValue: @"Size"];
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 2];
|
|
|
|
|
[cell setStringValue: @"Conn"];
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 3];
|
|
|
|
|
[cell setStringValue: @"Help"];
|
|
|
|
|
[[panel contentView] addSubview: selectionView];
|
|
|
|
|
RELEASE(selectionView);
|
|
|
|
|
|
|
|
|
|
inspectorView = [[NSView alloc] initWithFrame: inspectorRect];
|
|
|
|
|
[inspectorView setAutoresizingMask:
|
|
|
|
|
NSViewHeightSizable | NSViewWidthSizable];
|
|
|
|
|
[[panel contentView] addSubview: inspectorView];
|
|
|
|
|
RELEASE(inspectorView);
|
|
|
|
|
|
|
|
|
|
[panel setFrameUsingName: @"Inspector"];
|
|
|
|
|
[panel setFrameAutosaveName: @"Inspector"];
|
|
|
|
|
|
|
|
|
|
current = -1;
|
|
|
|
|
|
1999-12-08 15:19:11 +00:00
|
|
|
|
emptyInspector = [GormEmptyInspector new];
|
|
|
|
|
multipleInspector = [GormMultipleInspector new];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
|
|
[self setCurrentInspector: 0];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSPanel*) panel
|
|
|
|
|
{
|
|
|
|
|
return panel;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:19:11 +00:00
|
|
|
|
- (void) updateSelection
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
|
|
|
|
[self setCurrentInspector: self];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setCurrentInspector: (id)anObj
|
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
NSArray *selection = [[(id<IB>)NSApp selectionOwner] selection];
|
|
|
|
|
unsigned count = [selection count];
|
|
|
|
|
id obj = [selection lastObject];
|
|
|
|
|
NSView *newView = nil;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
|
|
if (anObj != self)
|
|
|
|
|
{
|
|
|
|
|
current = [anObj selectedColumn];
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:19:11 +00:00
|
|
|
|
/*
|
|
|
|
|
* Set panel title for the type of object being inspected.
|
|
|
|
|
*/
|
|
|
|
|
if (obj == nil)
|
|
|
|
|
{
|
|
|
|
|
[panel setTitle: @"Inspector"];
|
|
|
|
|
}
|
|
|
|
|
else
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
[panel setTitle: [NSString stringWithFormat: @"%@ Inspector",
|
|
|
|
|
NSStringFromClass([obj class])]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return the inspector view to its original window and release the old
|
|
|
|
|
* inspector.
|
|
|
|
|
*/
|
|
|
|
|
[[inspector window] setContentView: [[inspectorView subviews] lastObject]];
|
|
|
|
|
DESTROY(inspector);
|
|
|
|
|
|
|
|
|
|
if (count == 0 || count > 1)
|
|
|
|
|
{
|
|
|
|
|
inspector = RETAIN(emptyInspector);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
else if (count > 1)
|
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
inspector = RETAIN(multipleInspector);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSString *name;
|
|
|
|
|
Class c;
|
|
|
|
|
|
|
|
|
|
switch (current)
|
|
|
|
|
{
|
|
|
|
|
case 0: name = [obj inspectorClassName]; break;
|
|
|
|
|
case 1: name = [obj connectInspectorClassName]; break;
|
|
|
|
|
case 2: name = [obj sizeInspectorClassName]; break;
|
|
|
|
|
case 3: name = [obj helpInspectorClassName]; break;
|
|
|
|
|
default: name = [obj classInspectorClassName]; break;
|
|
|
|
|
}
|
|
|
|
|
c = NSClassFromString(name);
|
1999-12-08 15:19:11 +00:00
|
|
|
|
inspector = [c new];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:19:11 +00:00
|
|
|
|
newView = [[inspector window] contentView];
|
|
|
|
|
if (newView != nil)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
NSView *outer = [panel contentView];
|
|
|
|
|
NSRect rect = [outer bounds];
|
|
|
|
|
|
|
|
|
|
if (buttonView != nil)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
[buttonView removeFromSuperview];
|
|
|
|
|
buttonView = nil;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
1999-12-08 15:19:11 +00:00
|
|
|
|
|
|
|
|
|
rect.size.height = [divider frame].origin.y;
|
|
|
|
|
if ([inspector wantsButtons] == YES)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
NSRect buttonsRect;
|
|
|
|
|
NSRect bRect = NSMakeRect(0, 0, 60, 20);
|
|
|
|
|
NSButton *ok;
|
|
|
|
|
NSButton *revert;
|
|
|
|
|
|
|
|
|
|
buttonsRect = rect;
|
|
|
|
|
buttonsRect.size.height = 40;
|
|
|
|
|
rect.origin.y += 40;
|
|
|
|
|
rect.size.height -= 40;
|
|
|
|
|
|
|
|
|
|
buttonView = [[NSView alloc] initWithFrame: buttonsRect];
|
|
|
|
|
[buttonView setAutoresizingMask:
|
|
|
|
|
NSViewHeightSizable | NSViewWidthSizable];
|
|
|
|
|
[outer addSubview: buttonView];
|
|
|
|
|
RELEASE(buttonView);
|
|
|
|
|
|
|
|
|
|
ok = [inspector okButton];
|
|
|
|
|
if (ok == nil)
|
|
|
|
|
{
|
|
|
|
|
ok = AUTORELEASE([[NSButton alloc] initWithFrame: bRect]);
|
|
|
|
|
[ok setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin];
|
|
|
|
|
[ok setTitle: @"Ok"];
|
|
|
|
|
[ok setAction: @selector(ok:)];
|
|
|
|
|
[ok setTarget: inspector];
|
|
|
|
|
}
|
|
|
|
|
revert = [inspector revertButton];
|
|
|
|
|
if (revert == nil)
|
|
|
|
|
{
|
|
|
|
|
revert = AUTORELEASE([[NSButton alloc] initWithFrame: bRect]);
|
|
|
|
|
[revert setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin];
|
|
|
|
|
[revert setTitle: @"Revert"];
|
|
|
|
|
[revert setAction: @selector(revert:)];
|
|
|
|
|
[revert setTarget: inspector];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bRect = [ok frame];
|
|
|
|
|
bRect.origin.y = 10;
|
|
|
|
|
bRect.origin.x = buttonsRect.size.width - 10 - bRect.size.width;
|
|
|
|
|
[ok setFrame: bRect];
|
|
|
|
|
|
|
|
|
|
bRect = [revert frame];
|
|
|
|
|
bRect.origin.y = 10;
|
|
|
|
|
bRect.origin.x = 10;
|
|
|
|
|
[revert setFrame: bRect];
|
|
|
|
|
|
|
|
|
|
[buttonView addSubview: ok];
|
|
|
|
|
[buttonView addSubview: revert];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
[buttonView removeFromSuperview];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
1999-12-08 15:19:11 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Make the inspector view the correct size for the viewable panel,
|
|
|
|
|
* and set the frame size for the new contents before adding them.
|
|
|
|
|
*/
|
|
|
|
|
[inspectorView setFrame: rect];
|
|
|
|
|
rect.origin = NSZeroPoint;
|
|
|
|
|
[newView setFrame: rect];
|
|
|
|
|
[inspectorView addSubview: newView];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|