* Headers/AppKit/NSOutlineView.h,

* Source/NSOutlineView.m: Add -parentForItem: and -frameOfOutlineCellAtRow:. 
Use the later in -drawRow:clipRect:.
Change methods to use NSInteger and CGFloat.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30514 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2010-05-31 22:18:45 +00:00
parent e225579e41
commit 57cc668254
3 changed files with 107 additions and 56 deletions

View file

@ -1,3 +1,10 @@
2010-06-01 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSOutlineView.h,
* Source/NSOutlineView.m: Add -parentForItem: and
-frameOfOutlineCellAtRow:. Use the later in -drawRow:clipRect:.
Change methods to use NSInteger and CGFloat.
2010-05-31 Wolfgang Lux <wolfgang.lux@gmail.com> 2010-05-31 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSWindow.m (-dealloc): Avoid a race with some lame window * Source/NSWindow.m (-dealloc): Avoid a race with some lame window
@ -13,9 +20,10 @@
Implement support for document types with a wild card extension. Implement support for document types with a wild card extension.
2010-05-31 David Wetzel <dave@turbocat.de> 2010-05-31 David Wetzel <dave@turbocat.de>
* Source/NSViewController.m
* Headers/AppKit/NSViewController.h * Source/NSViewController.m
New files fixes #29822 * Headers/AppKit/NSViewController.h
New files fixes #29822
2010-05-31 Wolfgang Lux <wolfgang.lux@gmail.com> 2010-05-31 Wolfgang Lux <wolfgang.lux@gmail.com>

View file

@ -47,7 +47,7 @@
BOOL _autoResizesOutlineColumn; BOOL _autoResizesOutlineColumn;
BOOL _indentationMarkerFollowsCell; BOOL _indentationMarkerFollowsCell;
BOOL _autosaveExpandedItems; BOOL _autosaveExpandedItems;
float _indentationPerLevel; CGFloat _indentationPerLevel;
NSTableColumn *_outlineTableColumn; NSTableColumn *_outlineTableColumn;
} }
@ -58,25 +58,30 @@
- (void) collapseItem: (id)item collapseChildren: (BOOL)collapseChildren; - (void) collapseItem: (id)item collapseChildren: (BOOL)collapseChildren;
- (void) expandItem: (id)item; - (void) expandItem: (id)item;
- (void) expandItem: (id)item expandChildren: (BOOL)expandChildren; - (void) expandItem: (id)item expandChildren: (BOOL)expandChildren;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
- (NSRect) frameOfOutlineCellAtRow: (NSInteger)row;
#endif
- (BOOL) indentationMarkerFollowsCell; - (BOOL) indentationMarkerFollowsCell;
- (float) indentationPerLevel; - (CGFloat) indentationPerLevel;
- (BOOL) isExpandable: (id)item; - (BOOL) isExpandable: (id)item;
- (BOOL) isItemExpanded: (id)item; - (BOOL) isItemExpanded: (id)item;
- (id) itemAtRow: (int)row; - (id) itemAtRow: (NSInteger)row;
- (int) levelForItem: (id)item; - (NSInteger) levelForItem: (id)item;
- (int) levelForRow: (int)row; - (NSInteger) levelForRow: (NSInteger)row;
- (NSTableColumn *) outlineTableColumn; - (NSTableColumn *) outlineTableColumn;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
- (id) parentForItem: (id)item;
#endif
- (void) reloadItem: (id)item; - (void) reloadItem: (id)item;
- (void) reloadItem: (id)item reloadChildren: (BOOL)reloadChildren; - (void) reloadItem: (id)item reloadChildren: (BOOL)reloadChildren;
- (int) rowForItem: (id)item; - (NSInteger) rowForItem: (id)item;
- (void) setAutoresizesOutlineColumn: (BOOL)resize; - (void) setAutoresizesOutlineColumn: (BOOL)resize;
- (void) setAutosaveExpandedItems: (BOOL)flag; - (void) setAutosaveExpandedItems: (BOOL)flag;
- (void) setDropItem: (id)item dropChildIndex: (int)childIndex; - (void) setDropItem: (id)item dropChildIndex: (NSInteger)childIndex;
- (void) setIndentationMarkerFollowsCell: (BOOL)followsCell; - (void) setIndentationMarkerFollowsCell: (BOOL)followsCell;
- (void) setIndentationPerLevel: (float)newIndentLevel; - (void) setIndentationPerLevel: (CGFloat)newIndentLevel;
- (void) setOutlineTableColumn: (NSTableColumn *)outlineTableColumn; - (void) setOutlineTableColumn: (NSTableColumn *)outlineTableColumn;
- (BOOL) shouldCollapseAutoExpandedItemsForDeposited: (BOOL)deposited; - (BOOL) shouldCollapseAutoExpandedItemsForDeposited: (BOOL)deposited;
@end /* interface of NSOutlineView */ @end /* interface of NSOutlineView */
/** /**

View file

@ -367,6 +367,24 @@ static NSImage *unexpandable = nil;
} }
} }
- (NSRect) frameOfOutlineCellAtRow: (NSInteger)row
{
NSRect frameRect;
if (![self isExpandable: [self itemAtRow: row]])
return NSZeroRect;
frameRect = [self frameOfCellAtColumn: 0
row: row];
if (_indentationMarkerFollowsCell)
{
frameRect.origin.x += _indentationPerLevel * [self levelForRow: row];
}
return frameRect;
}
/** /**
* Returns whether or not the indentation marker or "knob" is indented * Returns whether or not the indentation marker or "knob" is indented
* along with the content inside the cell. * along with the content inside the cell.
@ -380,7 +398,7 @@ static NSImage *unexpandable = nil;
* Returns the amount of indentation, in points, for each level * Returns the amount of indentation, in points, for each level
* of the tree represented by the outline view. * of the tree represented by the outline view.
*/ */
- (float) indentationPerLevel - (CGFloat) indentationPerLevel
{ {
return _indentationPerLevel; return _indentationPerLevel;
} }
@ -418,7 +436,7 @@ static NSImage *unexpandable = nil;
* Returns the item at a given row. If no item exists for the given row, * Returns the item at a given row. If no item exists for the given row,
* returns nil. * returns nil.
*/ */
- (id) itemAtRow: (int)row - (id) itemAtRow: (NSInteger)row
{ {
if ((row >= [_items count]) || (row < 0)) if ((row >= [_items count]) || (row < 0))
{ {
@ -430,12 +448,12 @@ static NSImage *unexpandable = nil;
/** /**
* Returns the level for a given item. * Returns the level for a given item.
*/ */
- (int) levelForItem: (id)item - (NSInteger) levelForItem: (id)item
{ {
if (item != nil) if (item != nil)
{ {
id object = NSMapGet(_levelOfItems, item); id object = NSMapGet(_levelOfItems, item);
return [object intValue]; return [object integerValue];
} }
return -1; return -1;
@ -444,7 +462,7 @@ static NSImage *unexpandable = nil;
/** /**
* Returns the level for the given row. * Returns the level for the given row.
*/ */
- (int) levelForRow: (int)row - (NSInteger) levelForRow: (NSInteger)row
{ {
return [self levelForItem: [self itemAtRow: row]]; return [self levelForItem: [self itemAtRow: row]];
} }
@ -457,6 +475,29 @@ static NSImage *unexpandable = nil;
return _outlineTableColumn; return _outlineTableColumn;
} }
/**
* Returns the parent of the given item or nil
*/
- (id) parentForItem: (id)item
{
NSArray *allKeys = NSAllMapTableKeys(_itemDict);
NSEnumerator *en = [allKeys objectEnumerator];
NSInteger index;
id parent;
while ((parent = [en nextObject]))
{
NSMutableArray *childArray = NSMapGet(_itemDict, parent);
if ((index = [childArray indexOfObject: item]) != NSNotFound)
{
return (parent == [NSNull null]) ? (id)nil : (id)parent;
}
}
return nil;
}
/** /**
* Causes an item to be reloaded. This is the equivalent of calling * Causes an item to be reloaded. This is the equivalent of calling
* [NSOutlineView-reloadItem:reloadChildren:] with reloadChildren set to NO. * [NSOutlineView-reloadItem:reloadChildren:] with reloadChildren set to NO.
@ -473,7 +514,7 @@ static NSImage *unexpandable = nil;
*/ */
- (void) reloadItem: (id)item reloadChildren: (BOOL)reloadChildren - (void) reloadItem: (id)item reloadChildren: (BOOL)reloadChildren
{ {
int index; NSInteger index;
id parent; id parent;
BOOL expanded; BOOL expanded;
id dsobj = nil; id dsobj = nil;
@ -490,7 +531,7 @@ static NSImage *unexpandable = nil;
if ((index = [childArray indexOfObject: object]) != NSNotFound) if ((index = [childArray indexOfObject: object]) != NSNotFound)
{ {
parent = (parent == [NSNull null]) ? (id)nil : (id)parent; parent = (parent == [NSNull null]) ? (id)nil : (id)parent;
dsobj = [_dataSource outlineView: self dsobj = [_dataSource outlineView: self
child: index child: index
ofItem: parent]; ofItem: parent];
@ -524,9 +565,9 @@ static NSImage *unexpandable = nil;
* Returns the corresponding row in the outline view for the given item. * Returns the corresponding row in the outline view for the given item.
* Returns -1 if item is nil or not found. * Returns -1 if item is nil or not found.
*/ */
- (int) rowForItem: (id)item - (NSInteger) rowForItem: (id)item
{ {
int row; NSInteger row;
if (item == nil) if (item == nil)
return -1; return -1;
@ -599,7 +640,7 @@ static NSImage *unexpandable = nil;
/** /**
* Sets the amount, in points, that each level is to be indented by. * Sets the amount, in points, that each level is to be indented by.
*/ */
- (void)setIndentationPerLevel: (float)newIndentLevel - (void)setIndentationPerLevel: (CGFloat)newIndentLevel
{ {
_indentationPerLevel = newIndentLevel; _indentationPerLevel = newIndentLevel;
} }
@ -717,6 +758,7 @@ static NSImage *unexpandable = nil;
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];
if ([aCoder allowsKeyedCoding] == NO) if ([aCoder allowsKeyedCoding] == NO)
{ {
float indentation = _indentationPerLevel;
[aCoder encodeValueOfObjCType: @encode(BOOL) [aCoder encodeValueOfObjCType: @encode(BOOL)
at: &_autoResizesOutlineColumn]; at: &_autoResizesOutlineColumn];
[aCoder encodeValueOfObjCType: @encode(BOOL) [aCoder encodeValueOfObjCType: @encode(BOOL)
@ -724,7 +766,7 @@ static NSImage *unexpandable = nil;
[aCoder encodeValueOfObjCType: @encode(BOOL) [aCoder encodeValueOfObjCType: @encode(BOOL)
at: &_autosaveExpandedItems]; at: &_autosaveExpandedItems];
[aCoder encodeValueOfObjCType: @encode(float) [aCoder encodeValueOfObjCType: @encode(float)
at: &_indentationPerLevel]; at: &indentation];
[aCoder encodeConditionalObject: _outlineTableColumn]; [aCoder encodeConditionalObject: _outlineTableColumn];
} }
} }
@ -748,6 +790,7 @@ static NSImage *unexpandable = nil;
} }
else else
{ {
float indentation;
// overrides outline defaults with archived values // overrides outline defaults with archived values
[aDecoder decodeValueOfObjCType: @encode(BOOL) [aDecoder decodeValueOfObjCType: @encode(BOOL)
at: &_autoResizesOutlineColumn]; at: &_autoResizesOutlineColumn];
@ -756,7 +799,8 @@ static NSImage *unexpandable = nil;
[aDecoder decodeValueOfObjCType: @encode(BOOL) [aDecoder decodeValueOfObjCType: @encode(BOOL)
at: &_autosaveExpandedItems]; at: &_autosaveExpandedItems];
[aDecoder decodeValueOfObjCType: @encode(float) [aDecoder decodeValueOfObjCType: @encode(float)
at: &_indentationPerLevel]; at: &indentation];
_indentationPerLevel = indentation;
_outlineTableColumn = [aDecoder decodeObject]; _outlineTableColumn = [aDecoder decodeObject];
} }
return self; return self;
@ -887,8 +931,8 @@ static NSImage *unexpandable = nil;
if (tb == _outlineTableColumn) if (tb == _outlineTableColumn)
{ {
NSImage *image = nil; NSImage *image = nil;
int level = 0; NSInteger level = 0;
float indentationFactor = 0.0; CGFloat indentationFactor = 0.0;
// float originalWidth = drawingRect.size.width; // float originalWidth = drawingRect.size.width;
// display the correct arrow... // display the correct arrow...
@ -909,17 +953,7 @@ static NSImage *unexpandable = nil;
level = [self levelForItem: item]; level = [self levelForItem: item];
indentationFactor = _indentationPerLevel * level; indentationFactor = _indentationPerLevel * level;
imageCell = [[NSCell alloc] initImageCell: image]; imageCell = [[NSCell alloc] initImageCell: image];
imageRect = [self frameOfOutlineCellAtRow: rowIndex];
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;
}
if ([_delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)]) if ([_delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)])
{ {
@ -978,7 +1012,7 @@ static NSImage *unexpandable = nil;
} }
- (void) setDropItem: (id)item - (void) setDropItem: (id)item
dropChildIndex: (int)childIndex dropChildIndex: (NSInteger)childIndex
{ {
if (item != nil && [_items indexOfObject: item] == NSNotFound) if (item != nil && [_items indexOfObject: item] == NSNotFound)
@ -1018,7 +1052,9 @@ static NSImage *unexpandable = nil;
} }
// TODO: Move the part that starts at 'Compute the indicator rect area' to GSTheme // TODO: Move the part that starts at 'Compute the indicator rect area' to GSTheme
- (void) drawDropAboveIndicatorWithDropItem: (id)currentDropItem atRow: (int)row childDropIndex: (int)currentDropIndex - (void) drawDropAboveIndicatorWithDropItem: (id)currentDropItem
atRow: (int)row
childDropIndex: (int)currentDropIndex
{ {
int level = 0; int level = 0;
NSBezierPath *path = nil; NSBezierPath *path = nil;
@ -1136,10 +1172,12 @@ static NSImage *unexpandable = nil;
/* Returns the row whose item is the parent that owns the child at the given row. /* Returns the row whose item is the parent that owns the child at the given row.
Also returns the child index relative to this parent. */ Also returns the child index relative to this parent. */
- (int) parentRowForRow: (int)row atLevel: (int)level andReturnChildIndex: (int *)childIndex - (NSInteger) _parentRowForRow: (NSInteger)row
atLevel: (NSInteger)level
andReturnChildIndex: (NSInteger *)childIndex
{ {
int i; NSInteger i;
int lvl; NSInteger lvl;
*childIndex = 0; *childIndex = 0;
@ -1173,29 +1211,29 @@ Also returns the child index relative to this parent. */
* The insertion row is identical to the hovered row, except when p is in * The insertion row is identical to the hovered row, except when p is in
* the hovered row bottom part (the last quarter). * the hovered row bottom part (the last quarter).
*/ */
int row; NSInteger row;
/* A row can be divided into 4 vertically stacked portions. /* A row can be divided into 4 vertically stacked portions.
* We call each portion a quarter. * We call each portion a quarter.
* verticalQuarterPosition is the number of quarters that exists between the * verticalQuarterPosition is the number of quarters that exists between the
* top left origin (NSOutlineView is flipped) and the hovered row (precisely * top left origin (NSOutlineView is flipped) and the hovered row (precisely
* up to the quarter occupied by the pointer in this row). * up to the quarter occupied by the pointer in this row).
*/ */
int verticalQuarterPosition; NSInteger verticalQuarterPosition;
/* An indentation unit can be divided into 2 portions (left and right). /* An indentation unit can be divided into 2 portions (left and right).
* We call each portion a half. * We call each portion a half.
* We use it to compute the insertion level. */ * We use it to compute the insertion level. */
int horizontalHalfPosition; NSInteger horizontalHalfPosition;
/* The quarter (0, 1, 2 or 3) occupied by the pointer within the hovered row /* The quarter (0, 1, 2 or 3) occupied by the pointer within the hovered row
* (not in the insertion row). */ * (not in the insertion row). */
int positionInRow; NSInteger positionInRow;
/* The previous row level (the row before the insertion row) */ /* The previous row level (the row before the insertion row) */
int levelBefore; NSInteger levelBefore;
/* The next row level (the row after the insertion row) */ /* The next row level (the row after the insertion row) */
int levelAfter; NSInteger levelAfter;
/* The insertion level that may vary with the horizontal pointer position, /* The insertion level that may vary with the horizontal pointer position,
* when the pointer is between two rows and the bottom row is a parent. * when the pointer is between two rows and the bottom row is a parent.
*/ */
int level; NSInteger level;
NSDragOperation dragOperation = [sender draggingSourceOperationMask]; NSDragOperation dragOperation = [sender draggingSourceOperationMask];
ASSIGN(lastDragUpdate, [NSDate date]); ASSIGN(lastDragUpdate, [NSDate date]);
@ -1243,9 +1281,9 @@ Also returns the child index relative to this parent. */
if ((lastVerticalQuarterPosition != verticalQuarterPosition) if ((lastVerticalQuarterPosition != verticalQuarterPosition)
|| (lastHorizontalHalfPosition != horizontalHalfPosition)) || (lastHorizontalHalfPosition != horizontalHalfPosition))
{ {
int minInsertionLevel = levelAfter; NSInteger minInsertionLevel = levelAfter;
int maxInsertionLevel = levelBefore; NSInteger maxInsertionLevel = levelBefore;
int pointerInsertionLevel = rint((float)horizontalHalfPosition / 2.); NSInteger pointerInsertionLevel = rint((float)horizontalHalfPosition / 2.);
/* Save positions to avoid executing this code when the general /* Save positions to avoid executing this code when the general
* position of the mouse is unchanged. * position of the mouse is unchanged.
@ -1302,10 +1340,10 @@ Also returns the child index relative to this parent. */
} }
else /* Drop above */ else /* Drop above */
{ {
int childIndex = 0; NSInteger childIndex = 0;
int parentRow = [self parentRowForRow: row NSInteger parentRow = [self _parentRowForRow: row
atLevel: level atLevel: level
andReturnChildIndex: &childIndex]; andReturnChildIndex: &childIndex];
//NSLog(@"found %d (proposed childIndex = %d)", parentRow, childIndex); //NSLog(@"found %d (proposed childIndex = %d)", parentRow, childIndex);