mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 16:21:56 +00:00
Further improvements to NSOutlineView. GJC
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@12806 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6e7ec538e3
commit
95c7931f6c
2 changed files with 108 additions and 74 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Feb 27 01:03:58 2002 Gregory Casamento <greg_casamento@yahoo.com>
|
||||||
|
|
||||||
|
* Source/NSOutlineView.m implemented indentation and enabled
|
||||||
|
collapsing of items in the outline view.
|
||||||
|
|
||||||
Tue Feb 26 19:08:38 2002 Nicola Pero <nicola@brainstorm.co.uk>
|
Tue Feb 26 19:08:38 2002 Nicola Pero <nicola@brainstorm.co.uk>
|
||||||
|
|
||||||
Patch by Michael Hanni <mhanni@yahoo.com> modified -
|
Patch by Michael Hanni <mhanni@yahoo.com> modified -
|
||||||
|
|
|
@ -50,6 +50,9 @@ static const int current_version = 1;
|
||||||
static NSImage *rightArrow = nil;
|
static NSImage *rightArrow = nil;
|
||||||
static NSImage *downArrow = nil;
|
static NSImage *downArrow = nil;
|
||||||
|
|
||||||
|
// Some necessary things which should not become ivars....
|
||||||
|
static float widest = 0.0;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Forward declarations for functions used by both the NSTableView class
|
// Forward declarations for functions used by both the NSTableView class
|
||||||
// and NSOutlineView.
|
// and NSOutlineView.
|
||||||
|
@ -261,7 +264,7 @@ _selectionChange (NSOutlineView *ov, id delegate, int numberOfRows,
|
||||||
numberOfChildrenOfItem: item];
|
numberOfChildrenOfItem: item];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
NSLog(@"closing: %@");
|
NSLog(@"closing: %@", item);
|
||||||
// close the item...
|
// close the item...
|
||||||
if(item == nil)
|
if(item == nil)
|
||||||
{
|
{
|
||||||
|
@ -274,7 +277,7 @@ _selectionChange (NSOutlineView *ov, id delegate, int numberOfRows,
|
||||||
|
|
||||||
// For the close method it doesn't matter what order they are
|
// For the close method it doesn't matter what order they are
|
||||||
// removed in.
|
// removed in.
|
||||||
for(i=0;i<numchildren;i++)
|
for(i=1;i<=numchildren;i++)
|
||||||
{
|
{
|
||||||
id child = [_dataSource outlineView: self
|
id child = [_dataSource outlineView: self
|
||||||
child: i
|
child: i
|
||||||
|
@ -345,7 +348,7 @@ _selectionChange (NSOutlineView *ov, id delegate, int numberOfRows,
|
||||||
|
|
||||||
if([self isExpandable: item] && [self isItemExpanded: item] && canCollapse)
|
if([self isExpandable: item] && [self isItemExpanded: item] && canCollapse)
|
||||||
{
|
{
|
||||||
NSMutableDictionary *infoDict = [NSDictionary dictionary];
|
NSMutableDictionary *infoDict = [NSMutableDictionary dictionary];
|
||||||
[infoDict setObject: item forKey: @"NSObject"];
|
[infoDict setObject: item forKey: @"NSObject"];
|
||||||
|
|
||||||
// Send out the notification to let observers know that this is about
|
// Send out the notification to let observers know that this is about
|
||||||
|
@ -411,7 +414,6 @@ _selectionChange (NSOutlineView *ov, id delegate, int numberOfRows,
|
||||||
const SEL shouldExpandSelector = @selector(outlineView:shouldExpandItem:);
|
const SEL shouldExpandSelector = @selector(outlineView:shouldExpandItem:);
|
||||||
BOOL canExpand = YES;
|
BOOL canExpand = YES;
|
||||||
|
|
||||||
NSLog(@"HELLO!!!!!!!!");
|
|
||||||
if([_delegate respondsToSelector: shouldExpandSelector])
|
if([_delegate respondsToSelector: shouldExpandSelector])
|
||||||
{
|
{
|
||||||
canExpand = [_delegate outlineView: self shouldExpandItem: item];
|
canExpand = [_delegate outlineView: self shouldExpandItem: item];
|
||||||
|
@ -509,19 +511,55 @@ _selectionChange (NSOutlineView *ov, id delegate, int numberOfRows,
|
||||||
return [_items objectAtIndex: row];
|
return [_items objectAtIndex: row];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)levelForItem: (id)item
|
// Utility function to determine the level of an item.
|
||||||
|
static int _levelForItem(NSOutlineView *outline,
|
||||||
|
id startitem,
|
||||||
|
id searchitem,
|
||||||
|
int level,
|
||||||
|
BOOL *found)
|
||||||
{
|
{
|
||||||
if(item == nil)
|
int num = [[outline dataSource] outlineView: outline
|
||||||
|
numberOfChildrenOfItem: startitem];
|
||||||
|
int i = 0;
|
||||||
|
int finallevel = 0;
|
||||||
|
|
||||||
|
if(*found == YES)
|
||||||
{
|
{
|
||||||
return 0;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if(searchitem == startitem)
|
||||||
|
{
|
||||||
|
*found = YES;
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 1; i <= num; i++)
|
||||||
|
{
|
||||||
|
id anitem = [[outline dataSource] outlineView: outline
|
||||||
|
child: i
|
||||||
|
ofItem: startitem];
|
||||||
|
finallevel = _levelForItem(outline, anitem, searchitem, level + 1, found);
|
||||||
|
}
|
||||||
|
|
||||||
|
return finallevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (int)levelForItem: (id)item
|
||||||
|
{
|
||||||
|
// NSLog(@"Getting level for %@", item);
|
||||||
|
if(item != nil)
|
||||||
|
{
|
||||||
|
BOOL found = NO;
|
||||||
|
return _levelForItem(self, nil, item, -1, &found);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)levelForRow: (int)row
|
- (int)levelForRow: (int)row
|
||||||
{
|
{
|
||||||
return -1;
|
return [self levelForItem: [self itemAtRow: row]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTableColumn *)outlineTableColumn
|
- (NSTableColumn *)outlineTableColumn
|
||||||
|
@ -1293,7 +1331,15 @@ byExtendingSelection: (BOOL)flag
|
||||||
NSLog(@"row which was clicked %d, item %@",
|
NSLog(@"row which was clicked %d, item %@",
|
||||||
_clickedRow,
|
_clickedRow,
|
||||||
[self itemAtRow: _clickedRow]);
|
[self itemAtRow: _clickedRow]);
|
||||||
[self expandItem: [self itemAtRow: _clickedRow]];
|
|
||||||
|
if(![self isItemExpanded: [self itemAtRow: _clickedRow]])
|
||||||
|
{
|
||||||
|
[self expandItem: [self itemAtRow: _clickedRow]];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[self collapseItem: [self itemAtRow: _clickedRow]];
|
||||||
|
}
|
||||||
|
|
||||||
if ((modifiers & (NSShiftKeyMask | NSAlternateKeyMask))
|
if ((modifiers & (NSShiftKeyMask | NSAlternateKeyMask))
|
||||||
&& _allowsMultipleSelection)
|
&& _allowsMultipleSelection)
|
||||||
|
@ -1620,7 +1666,6 @@ byExtendingSelection: (BOOL)flag
|
||||||
/*
|
/*
|
||||||
* Drawing
|
* Drawing
|
||||||
*/
|
*/
|
||||||
|
|
||||||
- (void)drawRow: (int)rowIndex clipRect: (NSRect)aRect
|
- (void)drawRow: (int)rowIndex clipRect: (NSRect)aRect
|
||||||
{
|
{
|
||||||
int startingColumn;
|
int startingColumn;
|
||||||
|
@ -1684,7 +1729,6 @@ byExtendingSelection: (BOOL)flag
|
||||||
item: item];
|
item: item];
|
||||||
}
|
}
|
||||||
|
|
||||||
// item = [self itemAtRow: rowIndex];
|
|
||||||
[cell setObjectValue: [_dataSource outlineView: self
|
[cell setObjectValue: [_dataSource outlineView: self
|
||||||
objectValueForTableColumn: tb
|
objectValueForTableColumn: tb
|
||||||
byItem: item]];
|
byItem: item]];
|
||||||
|
@ -1699,6 +1743,9 @@ byExtendingSelection: (BOOL)flag
|
||||||
if(tb == _outlineTableColumn)
|
if(tb == _outlineTableColumn)
|
||||||
{
|
{
|
||||||
NSImage *arrow = nil;
|
NSImage *arrow = nil;
|
||||||
|
int level = 0;
|
||||||
|
float indentationFactor = 0.0;
|
||||||
|
float originalWidth = drawingRect.size.width;
|
||||||
|
|
||||||
// display the correct arrow...
|
// display the correct arrow...
|
||||||
if([self isItemExpanded: item])
|
if([self isItemExpanded: item])
|
||||||
|
@ -1710,10 +1757,22 @@ byExtendingSelection: (BOOL)flag
|
||||||
arrow = rightArrow;
|
arrow = rightArrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLog(@"outlineColumn: %@", item);
|
level = [self levelForItem: item];
|
||||||
|
// NSLog(@"outlineColumn: %@ level = %d", item, level);
|
||||||
|
indentationFactor = _indentationPerLevel * level;
|
||||||
imageCell = [[NSCell alloc] initImageCell: arrow];
|
imageCell = [[NSCell alloc] initImageCell: arrow];
|
||||||
imageRect.origin.x = drawingRect.origin.x;
|
|
||||||
imageRect.origin.y = drawingRect.origin.y;
|
if(_indentationMarkerFollowsCell)
|
||||||
|
{
|
||||||
|
imageRect.origin.x = drawingRect.origin.x + indentationFactor;
|
||||||
|
imageRect.origin.y = drawingRect.origin.y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
imageRect.origin.x = drawingRect.origin.x;
|
||||||
|
imageRect.origin.y = drawingRect.origin.y;
|
||||||
|
}
|
||||||
|
|
||||||
imageRect.size.width = [arrow size].width;
|
imageRect.size.width = [arrow size].width;
|
||||||
imageRect.size.height = [arrow size].height;
|
imageRect.size.height = [arrow size].height;
|
||||||
|
|
||||||
|
@ -1723,9 +1782,18 @@ byExtendingSelection: (BOOL)flag
|
||||||
[imageCell drawWithFrame: imageRect inView: self];
|
[imageCell drawWithFrame: imageRect inView: self];
|
||||||
}
|
}
|
||||||
|
|
||||||
// reformat drawing rect, so that there is no overlap
|
drawingRect.origin.x += indentationFactor + [arrow size].width + 1;
|
||||||
drawingRect.origin.x += [arrow size].width + 1;
|
drawingRect.size.width -= indentationFactor + [arrow size].width + 1;
|
||||||
drawingRect.size.width -= [arrow size].width + 1;
|
|
||||||
|
if (widest < (drawingRect.origin.x + originalWidth))
|
||||||
|
{
|
||||||
|
widest = (drawingRect.origin.x + originalWidth);
|
||||||
|
NSLog(@"widest = %lf", widest);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSLog(@"Still widest = %lf", widest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[cell drawWithFrame: drawingRect inView: self];
|
[cell drawWithFrame: drawingRect inView: self];
|
||||||
|
@ -1734,69 +1802,30 @@ byExtendingSelection: (BOOL)flag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
- (void) drawRect: (NSRect)aRect
|
||||||
- (void) tile
|
|
||||||
{
|
{
|
||||||
float table_width = 0;
|
int index = 0;
|
||||||
float table_height;
|
|
||||||
|
|
||||||
NSLog(@"In NSOutlineView's tile method *********");
|
for(index = 1;index <= _numberOfRows; index++)
|
||||||
if (_tilingDisabled == YES)
|
|
||||||
{
|
{
|
||||||
NSLog(@"NO TILING!!");
|
NSRect drawingRect;
|
||||||
return;
|
|
||||||
|
NSLog(@"Row = %d",index);
|
||||||
|
drawingRect = [self frameOfCellAtColumn: 1
|
||||||
|
row: index];
|
||||||
|
NSLog(@"Width = %d",drawingRect.size.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_numberOfColumns > 0)
|
[super drawRect: aRect];
|
||||||
|
|
||||||
|
// We need to resize here since all of the columns have been
|
||||||
|
// processed.
|
||||||
|
if(_autoResizesOutlineColumn)
|
||||||
{
|
{
|
||||||
int i;
|
// [_outlineTableColumn setWidth: widest];
|
||||||
float width;
|
widest = 0; // blank this since it was just set into the column..
|
||||||
float offset = 0.0;
|
|
||||||
|
|
||||||
if([_tableColumns objectAtIndex: 0] == _outlineTableColumn)
|
|
||||||
{
|
|
||||||
offset = 10.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
_columnOrigins[0] = _bounds.origin.x; // + offset;
|
|
||||||
width = [[_tableColumns objectAtIndex: 0] width] + offset;
|
|
||||||
table_width += width;
|
|
||||||
|
|
||||||
for (i = 1; i < _numberOfColumns; i++)
|
|
||||||
{
|
|
||||||
id column = [_tableColumns objectAtIndex: i];
|
|
||||||
float coloffset = 0.0;
|
|
||||||
|
|
||||||
// When determining where each column begins, we need to make
|
|
||||||
// sure that the outline column is taken into account
|
|
||||||
if (column == _outlineTableColumn)
|
|
||||||
{
|
|
||||||
coloffset = 10.0; // width of image.
|
|
||||||
}
|
|
||||||
|
|
||||||
_columnOrigins[i] = _columnOrigins[i - 1] + width + coloffset;
|
|
||||||
width = [column width];
|
|
||||||
table_width += width;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// + 1 for the last grid line
|
|
||||||
table_height = (_numberOfRows * _rowHeight) + 1;
|
|
||||||
[self setFrameSize: NSMakeSize (table_width, table_height)];
|
|
||||||
[self setNeedsDisplay: YES];
|
|
||||||
|
|
||||||
if (_headerView != nil)
|
|
||||||
{
|
|
||||||
[_headerView setFrameSize:
|
|
||||||
NSMakeSize (_frame.size.width,
|
|
||||||
[_headerView frame].size.height)];
|
|
||||||
[_cornerView setFrameSize:
|
|
||||||
NSMakeSize ([NSScroller scrollerWidth] + 1,
|
|
||||||
[_headerView frame].size.height)];
|
|
||||||
[_headerView setNeedsDisplay: YES];
|
|
||||||
[_cornerView setNeedsDisplay: YES];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
@end /* implementation of NSOutlineView */
|
@end /* implementation of NSOutlineView */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue