From af63d0b288a785e39be548a1b1c3a5889888e54f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rivaille Date: Tue, 26 Mar 2002 17:15:26 +0000 Subject: [PATCH] GormDocument.m Palettes/3Containers/GNUmakefile Palettes/3Containers/main.m Palettes/3Containers/inspectors.m Palettes/3Containers/GormNSTableView.m Palettes/3Containers/GormNSTableView.h git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@13242 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 16 ++++ GormDocument.m | 9 +- Palettes/3Containers/GNUmakefile | 5 +- Palettes/3Containers/GormNSTableView.h | 31 ++++++ Palettes/3Containers/GormNSTableView.m | 125 +++++++++++++++++++++++++ Palettes/3Containers/inspectors.m | 39 +++++++- Palettes/3Containers/main.m | 40 +++----- 7 files changed, 229 insertions(+), 36 deletions(-) create mode 100644 Palettes/3Containers/GormNSTableView.h create mode 100644 Palettes/3Containers/GormNSTableView.m diff --git a/ChangeLog b/ChangeLog index 6d04d0f5..1ce4a3f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2002-03-26 Pierre-Yves Rivaille + + * GormDocument.m ([GormDocument -init]): + Call setWidth instead of setMinWidth for non-resizable column. + Call sizeToFit on classesView. + * GormDocument.m ([GormDocument -{load, save}Document]): + Add support for GormNSTableView. + * Palettes/3Containers/GNUMakefile + * Palettes/3Containers/main.m + * Palettes/3Containers/GormNSTableView.m + * Palettes/3Containers/GormNSTableView.h + * Palettes/3Containers/inspectors.m + GormNSTableView replaces NSTableView when editing interface. + GormNSTableView features a dummy dataSource during editing and + testing. + 2002-03-24 Gregory John Casamento * GormDocument.m: Minor cleanup of debug statements. diff --git a/GormDocument.m b/GormDocument.m index 7feaab6d..ca506686 100644 --- a/GormDocument.m +++ b/GormDocument.m @@ -1187,18 +1187,20 @@ static NSImage *classesImage = nil; tableColumn = [[NSTableColumn alloc] initWithIdentifier: @"outlets"]; [[tableColumn headerCell] setStringValue: @"O"]; - [tableColumn setMinWidth: 25]; + [tableColumn setWidth: 25]; [tableColumn setResizable: NO]; [classesView addTableColumn: tableColumn]; RELEASE(tableColumn); tableColumn = [[NSTableColumn alloc] initWithIdentifier: @"actions"]; [[tableColumn headerCell] setStringValue: @"A"]; - [tableColumn setMinWidth: 25]; + [tableColumn setWidth: 25]; [tableColumn setResizable: NO]; [classesView addTableColumn: tableColumn]; RELEASE(tableColumn); + [classesView sizeToFit]; + // expand all of the items in the classesView... [classesView expandItem: @"NSObject"]; @@ -1328,6 +1330,7 @@ static NSImage *classesImage = nil; [u decodeClassName: @"GSCustomView" asClassName: @"GormCustomView"]; [u decodeClassName: @"NSWindow" asClassName: @"GormNSWindow"]; [u decodeClassName: @"NSBrowser" asClassName: @"GormNSBrowser"]; + [u decodeClassName: @"NSTableView" asClassName: @"GormNSTableView"]; c = [u decodeObject]; if (c == nil || [c isKindOfClass: [GSNibContainer class]] == NO) @@ -1873,6 +1876,8 @@ static NSImage *classesImage = nil; intoClassName: @"NSWindow"]; [archiver encodeClassName: @"GormNSBrowser" intoClassName: @"NSBrowser"]; + [archiver encodeClassName: @"GormNSTableView" + intoClassName: @"NSTableView"]; [archiver encodeRootObject: self]; archiveResult = [archiverData writeToFile: documentPath atomically: YES]; //archiveResult = [NSArchiver archiveRootObject: self toFile: documentPath]; diff --git a/Palettes/3Containers/GNUmakefile b/Palettes/3Containers/GNUmakefile index 39104f91..76300ac3 100644 --- a/Palettes/3Containers/GNUmakefile +++ b/Palettes/3Containers/GNUmakefile @@ -25,8 +25,9 @@ include $(GNUSTEP_MAKEFILES)/common.make PALETTE_NAME = 3Containers 3Containers_PALETTE_ICON = ContainersPalette -3Containers_OBJC_FILES = main.m inspectors.m GormNSBrowser.m -3Containers_HEADER_FILES = GormNSBrowser.m +3Containers_OBJC_FILES = main.m inspectors.m GormNSBrowser.m \ + GormNSTableView.m +3Containers_HEADER_FILES = GormNSBrowser.h GormNSTableView.h 3Containers_PRINCIPAL_CLASS = ContainersPalette 3Containers_RESOURCE_FILES = ContainersPalette.tiff \ GormBrowserInspector.gorm \ diff --git a/Palettes/3Containers/GormNSTableView.h b/Palettes/3Containers/GormNSTableView.h new file mode 100644 index 00000000..27f14910 --- /dev/null +++ b/Palettes/3Containers/GormNSTableView.h @@ -0,0 +1,31 @@ +/* GormNSTableView.h + + Copyright (C) 2001 Free Software Foundation, Inc. + + Author: Pierre-Yves Rivaille + Date: 2001 + + 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. +*/ + +#import + +@interface GormNSTableView : NSTableView +{ + id _gormDataSource; +} +@end diff --git a/Palettes/3Containers/GormNSTableView.m b/Palettes/3Containers/GormNSTableView.m new file mode 100644 index 00000000..28612bae --- /dev/null +++ b/Palettes/3Containers/GormNSTableView.m @@ -0,0 +1,125 @@ +/* GormNSTableView.m + + Copyright (C) 2001 Free Software Foundation, Inc. + + Author: Pierre-Yves Rivaille + Date: 2001 + + 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. +*/ + +#import "GormNSTableView.h" + +/* --------------------------------------------------------------- + * NSTableView dataSource +*/ +@interface NSTableViewDataSource: NSObject +{ +} +- (int) numberOfRowsInTableView: (NSTableView *)tv; +- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex; + +@end + +static NSString* value1[] = +{@"zero", + @"un", + @"deux", + @"trois", + @"quatre", + @"cinq", + @"six", + @"sept", + @"huit", + @"neuf"}; + +static NSString* value2[] = +{@"zero", + @"one", + @"two", + @"three", + @"four", + @"five", + @"six", + @"seven", + @"eight", + @"nine"}; + +@implementation NSTableViewDataSource + +- (int) numberOfRowsInTableView: (NSTableView *)tv +{ + return 10; +} +- (id)tableView:(NSTableView *)aTableView +objectValueForTableColumn:(NSTableColumn *)aTableColumn + row:(int)rowIndex +{ + if ([[aTableColumn identifier] isEqualToString: @"column1"]) + { + return value1[rowIndex]; + } + return value2[rowIndex]; +} + +@end + +static id _sharedDataSource = nil; + +@implementation GormNSTableView ++ (id) sharedDataSource +{ + if (_sharedDataSource == nil) + { + _sharedDataSource = [[NSTableViewDataSource alloc] init]; + } + return _sharedDataSource; +} + +- (id) initWithFrame: (NSRect) aRect +{ + self = [super initWithFrame: aRect]; + [super setDataSource: [GormNSTableView sharedDataSource]]; + _gormDataSource = nil; + return self; +} + +- (void)setDataSource: (id)anObject +{ + _gormDataSource = anObject; +} + +- (id)dataSource +{ + return _gormDataSource; +} + +- (void)encodeWithCoder: (NSCoder*) aCoder +{ + _dataSource = _gormDataSource; + [super encodeWithCoder: aCoder]; + _dataSource = _sharedDataSource; +} + +- (id) initWithCoder: (NSCoder*) aCoder +{ + self = [super initWithCoder: aCoder]; + [super setDataSource: [GormNSTableView sharedDataSource]]; + return self; +} + +@end diff --git a/Palettes/3Containers/inspectors.m b/Palettes/3Containers/inspectors.m index 2e07c3c6..58b58e03 100644 --- a/Palettes/3Containers/inspectors.m +++ b/Palettes/3Containers/inspectors.m @@ -83,7 +83,7 @@ - (void) _getValuesFromObject: anObject { - + if (anObject != object) { return; @@ -135,6 +135,30 @@ @end +@interface GormViewSizeInspector : IBInspector +{ + NSButton *top; + NSButton *bottom; + NSButton *left; + NSButton *right; + NSButton *width; + NSButton *height; + NSForm *sizeForm; +} +@end + +@interface GormTableViewSizeInspector : GormViewSizeInspector +@end +@implementation GormTableViewSizeInspector +- (void) setObject: (id)anObject +{ + id scrollView; + scrollView = [anObject enclosingScrollView]; + + [super setObject: scrollView]; +} +@end + /*---------------------------------------------------------------------------- * NSTableView (possibly embedded in a Scroll view) */ @@ -145,6 +169,11 @@ return @"GormTableViewAttributesInspector"; } +- (NSString*) sizeInspectorClassName +{ + return @"GormTableViewSizeInspector"; +} + @end @interface GormTableViewAttributesInspector : IBInspector @@ -218,6 +247,8 @@ { [object setTag:[[tagField cellAtIndex:0] intValue]]; } + + [scrollView setNeedsDisplay: YES]; } - (void) _getValuesFromObject: anObject @@ -225,7 +256,9 @@ BOOL isScrollView; id scrollView; - scrollView = [[object superview] superview]; + scrollView = //[[object superview] superview]; + [object enclosingScrollView]; + isScrollView = [ scrollView isKindOfClass: [NSScrollView class]]; if (anObject != object) @@ -249,7 +282,7 @@ [horizontalScrollerSwitch setEnabled: YES]; [horizontalScrollerSwitch setState: - ([scrollView hasVerticalScroller]) ? NSOnState : NSOffState]; + ([scrollView hasHorizontalScroller]) ? NSOnState : NSOffState]; [borderMatrix setEnabled: YES]; [borderMatrix selectCellWithTag: [scrollView borderType]]; diff --git a/Palettes/3Containers/main.m b/Palettes/3Containers/main.m index 1836d221..651fe846 100644 --- a/Palettes/3Containers/main.m +++ b/Palettes/3Containers/main.m @@ -25,30 +25,10 @@ #include #include "../../Gorm.h" #include "GormNSBrowser.h" +#include "GormNSTableView.h" +#include - -/* --------------------------------------------------------------- - * NSTableView data source -*/ - -@interface NSTableViewDataSource: NSObject -{ -} -@end - -@implementation NSTableViewDataSource -- (int)numberOfRowsInTableView:(NSTableView *)aTableView -{ - return 3; -} -- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex -{ - return [NSString stringWithFormat:@"%d",rowIndex]; -} - -@end - /* --------------------------------------------------------------- * Containers Palette Display */ @@ -113,31 +93,33 @@ //[v setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable]; contentSize = [v contentSize]; - tv = [[NSTableView alloc] initWithFrame: + tv = [[GormNSTableView alloc] initWithFrame: NSMakeRect(0,0,contentSize.width, contentSize.height)]; // [tv setDataSource: [[NSTableViewDataSource alloc] init]]; - [tv setAutoresizesAllColumnsToFit: YES]; + // [tv setAutoresizesAllColumnsToFit: YES]; [v setDocumentView: tv]; RELEASE(tv); - tc = [[NSTableColumn alloc] initWithIdentifier: @"table"]; + tc = [[NSTableColumn alloc] initWithIdentifier: @"column1"]; [[tc headerCell] setStringValue: @" "]; - [tc setWidth: contentSize.width/2]; + [tc setWidth: floor(contentSize.width/2)]; + [tc setMinWidth: 20]; [tc setResizable: YES]; [tc setEditable: YES]; [tv addTableColumn: tc]; RELEASE(tc); - tc = [[NSTableColumn alloc] initWithIdentifier: @"view"]; + tc = [[NSTableColumn alloc] initWithIdentifier: @"column2"]; [[tc headerCell] setStringValue: @" "]; - [tc setMinWidth: contentSize.width/2]; + [tc setWidth: ceil(contentSize.width/2)]; + [tc setMinWidth: 20]; [tc setResizable: YES]; [tc setEditable: YES]; [tv addTableColumn: tc]; RELEASE(tc); [tv setFrame: NSMakeRect(0,0,contentSize.width, contentSize.height)]; - [v setDocumentView: tv]; + // [v setDocumentView: tv]; [contents addSubview: v]; RELEASE(tv); RELEASE(v);