From c5fec4c0299c0d9f071ee80adcf2858373b51d54 Mon Sep 17 00:00:00 2001 From: gcasa Date: Sun, 3 Mar 2002 05:58:51 +0000 Subject: [PATCH] Made modifications to NSOutlineView to make it usable. Added an image to mark unexpandable items. GJC git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@12959 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 10 +++ Images/GNUmakefile | 1 + Images/common_outlineUnexpandable.tiff | Bin 0 -> 980 bytes Source/NSOutlineView.m | 106 +++++++++++++++---------- 4 files changed, 75 insertions(+), 42 deletions(-) create mode 100644 Images/common_outlineUnexpandable.tiff diff --git a/ChangeLog b/ChangeLog index e5f4ac2bc..66991c49c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2002-03-03 Gregory Casamento + + * Images/common_outlineUnexpandable.tiff added. + * Images/GNUmakefile modified to install images + * Source/NSOutlineView.m modified to use new images. + Also made several fixes which should now make NSOutlineView + usable. The graphics used are consistent with the look of + the outline view in the OPENSTEP Interface Builder classes + tab. + 2002-03-02 Gregory Casamento * Images/common_outlineExpanded.tiff added. diff --git a/Images/GNUmakefile b/Images/GNUmakefile index 3b2fd34dd..7d2abae91 100644 --- a/Images/GNUmakefile +++ b/Images/GNUmakefile @@ -97,6 +97,7 @@ common_copyCursor.tiff \ common_linkCursor.tiff \ common_outlineCollapsed.tiff \ common_outlineExpanded.tiff \ +common_outlineUnexpandable.tiff \ GNUstep.tiff \ GNUstepMenuImage.tiff \ nsmapping.strings \ diff --git a/Images/common_outlineUnexpandable.tiff b/Images/common_outlineUnexpandable.tiff new file mode 100644 index 0000000000000000000000000000000000000000..3fb4752ced9d11360e7bb441072bef7289f0e41d GIT binary patch literal 980 zcmY*XOH3M36dh0+HBv=GiG}z{j8=`64KZp$n$*7w39%Yi4L_?!p^8mvOf>4oblH_I z+%=7{T^JS$Zg4^T(F8RbKZ)4lCx9Xdj0iLHrgv~Kcqeb}xo_^d@4P#=rKKGE&BdNs zK|w+B>gsCn=;(-cyWRBp`8j=Xa6r$`&)aizbH&e+A*imdmanX=IQRDUh)^g*-re01 z9*>9E+}w;>t=90^*qB)$5ELhPRaI58g@px2Fc_pFkqCw3IOT9SNbu%=!+|A*`}{GR%|6gZ8jZ$qV`JmfIhmQ6+3V};F3=SN&6H3m zL}IbH5;*wm>@0q9aY0;OUXm7z1>f1(IosdgKLhiEj=h5^X=#a?oSdXuTU)7;k`e^}-2y#%HV;`@SxpLs0GZ+UrDB`}jgu0`e26(om?*NO~{2x&CHHR11 zV}m+k7XJY(NviXP#f%1J(msS(8vAGrgM$YBN5hwqfj+(NgI@Rbvr4a3sRwj#NBVkt du%=<%C&Tb);d_-)HK@~%7#MOhEasAN{~t__Wb*(3 literal 0 HcmV?d00001 diff --git a/Source/NSOutlineView.m b/Source/NSOutlineView.m index 3a90cb2db..a9c13474d 100644 --- a/Source/NSOutlineView.m +++ b/Source/NSOutlineView.m @@ -49,6 +49,7 @@ static const int current_version = 1; // Cache the arrow images... static NSImage *collapsed = nil; static NSImage *expanded = nil; +static NSImage *unexpandable = nil; // Some necessary things which should not become ivars.... static float widest = 0.0; @@ -223,7 +224,7 @@ _selectionChange (NSOutlineView *ov, id delegate, int numberOfRows, nc = [NSNotificationCenter defaultCenter]; collapsed = [NSImage imageNamed: @"common_outlineCollapsed.tiff"]; expanded = [NSImage imageNamed: @"common_outlineExpanded.tiff"]; - // NSLog(@"%@ %@",rightArrow, downArrow); + unexpandable = [NSImage imageNamed: @"common_outlineUnexpandable.tiff"]; } } @@ -258,13 +259,43 @@ _selectionChange (NSOutlineView *ov, id delegate, int numberOfRows, return _autosaveExpandedItems; } -- (void)_closeItem: (id)item +// Collect all of the items under a given element. +static void _collectItems(NSOutlineView *outline, + id startitem, + NSMutableArray *allChildren) { - int numchildren = [_dataSource outlineView: self - numberOfChildrenOfItem: item]; + int num = [[outline dataSource] outlineView: outline + numberOfChildrenOfItem: startitem]; int i = 0; - NSLog(@"closing: %@", item); + for(i = 1; i <= num; i++) + { + id anitem = [[outline dataSource] outlineView: outline + child: i + ofItem: startitem]; + + // Only collect the children if the item is expanded + if([outline isItemExpanded: startitem]) + { + [allChildren addObject: anitem]; + } + + _collectItems(outline, anitem, allChildren); + } +} + +- (void)_closeItem: (id)item +{ + int numchildren = 0; + int i = 0; + NSMutableArray *removeAll = [NSMutableArray array]; + + // [_dataSource outlineView: self + // numberOfChildrenOfItem: item]; + + _collectItems(self, item, removeAll); + numchildren = [removeAll count]; + // close the item... if(item == nil) { @@ -277,12 +308,10 @@ _selectionChange (NSOutlineView *ov, id delegate, int numberOfRows, // For the close method it doesn't matter what order they are // removed in. - for(i=1;i<=numchildren;i++) + + for(i=0; i < numchildren; i++) { - id child = [_dataSource outlineView: self - child: i - ofItem: item]; - NSLog(@"child = %@",child); + id child = [removeAll objectAtIndex: i]; [_items removeObject: child]; } } @@ -294,7 +323,6 @@ _selectionChange (NSOutlineView *ov, id delegate, int numberOfRows, int i = 0; int insertionPoint = 0; - NSLog(@"opening: %@", item); // open the item... if(item == nil) { @@ -315,19 +343,30 @@ _selectionChange (NSOutlineView *ov, id delegate, int numberOfRows, insertionPoint++; } - // [self setNeedsDisplayInRect: [self rectOfRow: [self rowForItem: item]]]; [self setNeedsDisplay: YES]; - NSLog(@"Insertion point = %d",insertionPoint); for(i=numchildren; i > 0; i--) { id child = [_dataSource outlineView: self child: i ofItem: item]; - NSLog(@"In here...."); - NSLog(@"child = %@",child); + + // Add all of the children... + if([self isItemExpanded: child]) + { + NSMutableArray *insertAll = [NSMutableArray array]; + int i = 0, numitems = 0; + + _collectItems(self, child, insertAll); + numitems = [insertAll count]; + for(i = numitems-1; i >= 0; i--) + { + [_items insertObject: [insertAll objectAtIndex: i] + atIndex: insertionPoint]; + } + } + + // Add the parent [_items insertObject: child atIndex: insertionPoint]; - // [self setNeedsDisplayInRect: [self rectOfRow: [self rowForItem: child]]]; - NSLog(@"_items = %@",_items); } } @@ -507,7 +546,6 @@ _selectionChange (NSOutlineView *ov, id delegate, int numberOfRows, - (id)itemAtRow: (int)row { - NSLog(@"itemAtRow %d",row); return [_items objectAtIndex: row]; } @@ -540,6 +578,7 @@ static int _levelForItem(NSOutlineView *outline, child: i ofItem: startitem]; finallevel = _levelForItem(outline, anitem, searchitem, level + 1, found); + if(*found) break; } return finallevel; @@ -547,7 +586,6 @@ static int _levelForItem(NSOutlineView *outline, - (int)levelForItem: (id)item { - // NSLog(@"Getting level for %@", item); if(item != nil) { BOOL found = NO; @@ -620,7 +658,6 @@ static int _levelForItem(NSOutlineView *outline, - (void) noteNumberOfRowsChanged { _numberOfRows = [_items count]; - NSLog(@"_numberOfRows = %d", _numberOfRows); /* If we are selecting rows, we have to check that we have no selected rows below the new end of the table */ @@ -1290,8 +1327,6 @@ byExtendingSelection: (BOOL)flag _clickedRow = [self rowAtPoint: location]; _clickedColumn = [self columnAtPoint: location]; - NSLog(@"location (%f,%f)",location.x,location.y); - // Selection if (clickCount == 1) { @@ -1328,10 +1363,6 @@ byExtendingSelection: (BOOL)flag { BOOL newSelection; - NSLog(@"row which was clicked %d, item %@", - _clickedRow, - [self itemAtRow: _clickedRow]); - if(![self isItemExpanded: [self itemAtRow: _clickedRow]]) { [self expandItem: [self itemAtRow: _clickedRow]]; @@ -1678,7 +1709,6 @@ byExtendingSelection: (BOOL)flag int i; float x_pos; - NSLog(@"In the drawing code..."); if (_dataSource == nil) { return; @@ -1734,11 +1764,6 @@ byExtendingSelection: (BOOL)flag byItem: item]]; drawingRect = [self frameOfCellAtColumn: i row: rowIndex]; - NSLog(@"Drawing rect (%f, %f, %f, %f)", - drawingRect.origin.x, - drawingRect.origin.y, - drawingRect.size.width, - drawingRect.size.height); if(tb == _outlineTableColumn) { @@ -1757,8 +1782,12 @@ byExtendingSelection: (BOOL)flag image = collapsed; } + if(![self isExpandable: item]) + { + image = unexpandable; + } + level = [self levelForItem: item]; - // NSLog(@"outlineColumn: %@ level = %d", item, level); indentationFactor = _indentationPerLevel * level; imageCell = [[NSCell alloc] initImageCell: image]; @@ -1776,11 +1805,7 @@ byExtendingSelection: (BOOL)flag imageRect.size.width = [image size].width; imageRect.size.height = [image size].height; - // Draw the arrow if the item is expandable.. - if([self isExpandable: item]) - { - [imageCell drawWithFrame: imageRect inView: self]; - } + [imageCell drawWithFrame: imageRect inView: self]; drawingRect.origin.x += indentationFactor + [image size].width + 1; drawingRect.size.width -= indentationFactor + [image size].width + 1; @@ -1788,11 +1813,10 @@ byExtendingSelection: (BOOL)flag if (widest < (drawingRect.origin.x + originalWidth)) { widest = (drawingRect.origin.x + originalWidth); - NSLog(@"widest = %lf", widest); } else { - NSLog(@"Still widest = %lf", widest); + // NSLog(@"Still widest = %lf", widest); } } @@ -1810,10 +1834,8 @@ byExtendingSelection: (BOOL)flag { NSRect drawingRect; - NSLog(@"Row = %d",index); drawingRect = [self frameOfCellAtColumn: 1 row: index]; - NSLog(@"Width = %d",drawingRect.size.width); } [super drawRect: aRect];