mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 13:10:59 +00:00
Initial changes for NSOutlineView view-based support
This commit is contained in:
parent
d99f82896b
commit
f71ee8641b
4 changed files with 168 additions and 131 deletions
|
@ -1350,6 +1350,14 @@ APPKIT_EXPORT_CLASS
|
|||
clipRect: (NSRect)clipRect
|
||||
inView: (NSView *)view;
|
||||
|
||||
- (void) drawOutlineViewRow: (NSInteger)rowIndex
|
||||
clipRect: (NSRect)clipRect
|
||||
inView: (NSView *)view;
|
||||
|
||||
- (void) drawOutlineCellViewRow: (NSInteger)rowIndex
|
||||
clipRect: (NSRect)clipRect
|
||||
inView: (NSView *)view;
|
||||
|
||||
- (void) drawBoxInClipRect: (NSRect)clipRect
|
||||
boxType: (NSBoxType)boxType
|
||||
borderType: (NSBorderType)borderType
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#import "AppKit/NSImage.h"
|
||||
#import "AppKit/NSMenuView.h"
|
||||
#import "AppKit/NSMenuItemCell.h"
|
||||
#import "AppKit/NSOutlineView.h"
|
||||
#import "AppKit/NSParagraphStyle.h"
|
||||
#import "AppKit/NSPopUpButtonCell.h"
|
||||
#import "AppKit/NSProgressIndicator.h"
|
||||
|
@ -64,6 +65,7 @@
|
|||
#import "AppKit/NSPathCell.h"
|
||||
#import "AppKit/NSPathControl.h"
|
||||
#import "AppKit/NSPathComponentCell.h"
|
||||
|
||||
#import "GNUstepGUI/GSToolbarView.h"
|
||||
#import "GNUstepGUI/GSTitleView.h"
|
||||
|
||||
|
@ -3578,6 +3580,159 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
|
|||
}
|
||||
}
|
||||
|
||||
- (void) drawOutlineViewRow: (NSInteger)rowIndex
|
||||
clipRect: (NSRect)clipRect
|
||||
inView: (NSView *)view
|
||||
{
|
||||
NSOutlineView *outlineView = (NSOutlineView *)view;
|
||||
NSInteger numberOfColumns = [outlineView numberOfColumns];
|
||||
CGFloat *columnOrigins = [outlineView _columnOrigins];
|
||||
NSInteger editedRow = [outlineView editedRow];
|
||||
NSInteger editedColumn = [outlineView editedColumn];
|
||||
NSArray *tableColumns = [outlineView tableColumns];
|
||||
CGFloat indentationPerLevel = [outlineView indentationPerLevel];
|
||||
NSInteger numberOfRows = [outlineView numberOfRows];
|
||||
NSInteger startingColumn;
|
||||
NSInteger endingColumn;
|
||||
NSRect drawingRect;
|
||||
NSCell *imageCell = nil;
|
||||
NSRect imageRect;
|
||||
NSInteger i;
|
||||
CGFloat x_pos;
|
||||
id dataSource = [outlineView dataSource];
|
||||
id delegate = [outlineView delegate];
|
||||
NSTableColumn *outlineTableColumn = [outlineView outlineTableColumn];
|
||||
|
||||
if (dataSource == nil)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Using columnAtPoint: here would make it called twice per row per drawn
|
||||
rect - so we avoid it and do it natively */
|
||||
|
||||
if (rowIndex >= numberOfRows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Determine starting column as fast as possible */
|
||||
x_pos = NSMinX (clipRect);
|
||||
i = 0;
|
||||
while ((i < numberOfColumns) && (x_pos > columnOrigins[i]))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
startingColumn = (i - 1);
|
||||
|
||||
if (startingColumn == -1)
|
||||
startingColumn = 0;
|
||||
|
||||
/* Determine ending column as fast as possible */
|
||||
x_pos = NSMaxX (clipRect);
|
||||
// Nota Bene: we do *not* reset i
|
||||
while ((i < numberOfColumns) && (x_pos > columnOrigins[i]))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
endingColumn = (i - 1);
|
||||
|
||||
if (endingColumn == -1)
|
||||
endingColumn = numberOfColumns - 1;
|
||||
|
||||
/* Draw the row between startingColumn and endingColumn */
|
||||
for (i = startingColumn; i <= endingColumn; i++)
|
||||
{
|
||||
id item = [outlineView itemAtRow: rowIndex];
|
||||
NSTableColumn *tb = [tableColumns objectAtIndex: i];
|
||||
NSCell *cell = [outlineView preparedCellAtColumn: i row: rowIndex];
|
||||
|
||||
[outlineView _willDisplayCell: cell
|
||||
forTableColumn: tb
|
||||
row: rowIndex];
|
||||
if (i == editedColumn && rowIndex == editedRow)
|
||||
{
|
||||
[cell _setInEditing: YES];
|
||||
[cell setShowsFirstResponder: YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
[cell setObjectValue: [dataSource outlineView: outlineView
|
||||
objectValueForTableColumn: tb
|
||||
byItem: item]];
|
||||
}
|
||||
drawingRect = [outlineView frameOfCellAtColumn: i
|
||||
row: rowIndex];
|
||||
|
||||
if (tb == outlineTableColumn)
|
||||
{
|
||||
NSImage *image = nil;
|
||||
NSInteger level = 0;
|
||||
CGFloat indentationFactor = 0.0;
|
||||
|
||||
// display the correct arrow...
|
||||
if ([outlineView isItemExpanded: item])
|
||||
{
|
||||
image = [NSImage imageNamed: @"common_ArrowDownH"];
|
||||
}
|
||||
else
|
||||
{
|
||||
image = [NSImage imageNamed: @"common_ArrowRightH"];
|
||||
}
|
||||
|
||||
if (![outlineView isExpandable: item])
|
||||
{
|
||||
image = [[NSImage alloc] initWithSize: NSMakeSize(14.0,14.0)]; // revisit this.. memory leak
|
||||
}
|
||||
|
||||
level = [outlineView levelForItem: item];
|
||||
indentationFactor = indentationPerLevel * level;
|
||||
imageCell = [[NSCell alloc] initImageCell: image];
|
||||
imageRect = [outlineView frameOfOutlineCellAtRow: rowIndex];
|
||||
|
||||
if ([delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)])
|
||||
{
|
||||
[delegate outlineView: outlineView
|
||||
willDisplayOutlineCell: imageCell
|
||||
forTableColumn: tb
|
||||
item: item];
|
||||
}
|
||||
|
||||
/* Do not indent if the delegate set the image to nil. */
|
||||
if ([imageCell image])
|
||||
{
|
||||
imageRect.size.width = [image size].width;
|
||||
imageRect.size.height = [image size].height;
|
||||
[imageCell drawWithFrame: imageRect inView: outlineView];
|
||||
drawingRect.origin.x
|
||||
+= indentationFactor + imageRect.size.width + 5;
|
||||
drawingRect.size.width
|
||||
-= indentationFactor + imageRect.size.width + 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawingRect.origin.x += indentationFactor;
|
||||
drawingRect.size.width -= indentationFactor;
|
||||
}
|
||||
|
||||
RELEASE(imageCell);
|
||||
}
|
||||
|
||||
[cell drawWithFrame: drawingRect inView: outlineView];
|
||||
if (i == editedColumn && rowIndex == editedRow)
|
||||
{
|
||||
[cell _setInEditing: NO];
|
||||
[cell setShowsFirstResponder: NO];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) drawOutlineCellViewRow: (NSInteger)rowIndex
|
||||
clipRect: (NSRect)clipRect
|
||||
inView: (NSView *)view
|
||||
{
|
||||
}
|
||||
|
||||
- (void) drawBoxInClipRect: (NSRect)clipRect
|
||||
boxType: (NSBoxType)boxType
|
||||
borderType: (NSBorderType)borderType
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
#import "AppKit/NSTextFieldCell.h"
|
||||
#import "AppKit/NSWindow.h"
|
||||
|
||||
#import "GNUstepGUI/GSTheme.h"
|
||||
#import "GSGuiPrivate.h"
|
||||
#include <math.h>
|
||||
|
||||
|
@ -922,137 +923,9 @@ static NSImage *unexpandable = nil;
|
|||
*/
|
||||
- (void) drawRow: (NSInteger)rowIndex clipRect: (NSRect)aRect
|
||||
{
|
||||
NSInteger startingColumn;
|
||||
NSInteger endingColumn;
|
||||
NSRect drawingRect;
|
||||
NSCell *imageCell = nil;
|
||||
NSRect imageRect;
|
||||
NSInteger i;
|
||||
CGFloat x_pos;
|
||||
|
||||
if (_dataSource == nil)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Using columnAtPoint: here would make it called twice per row per drawn
|
||||
rect - so we avoid it and do it natively */
|
||||
|
||||
if (rowIndex >= _numberOfRows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Determine starting column as fast as possible */
|
||||
x_pos = NSMinX (aRect);
|
||||
i = 0;
|
||||
while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i]))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
startingColumn = (i - 1);
|
||||
|
||||
if (startingColumn == -1)
|
||||
startingColumn = 0;
|
||||
|
||||
/* Determine ending column as fast as possible */
|
||||
x_pos = NSMaxX (aRect);
|
||||
// Nota Bene: we do *not* reset i
|
||||
while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i]))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
endingColumn = (i - 1);
|
||||
|
||||
if (endingColumn == -1)
|
||||
endingColumn = _numberOfColumns - 1;
|
||||
|
||||
/* Draw the row between startingColumn and endingColumn */
|
||||
for (i = startingColumn; i <= endingColumn; i++)
|
||||
{
|
||||
id item = [self itemAtRow: rowIndex];
|
||||
NSTableColumn *tb = [_tableColumns objectAtIndex: i];
|
||||
NSCell *cell = [self preparedCellAtColumn: i row: rowIndex];
|
||||
|
||||
[self _willDisplayCell: cell
|
||||
forTableColumn: tb
|
||||
row: rowIndex];
|
||||
if (i == _editedColumn && rowIndex == _editedRow)
|
||||
{
|
||||
[cell _setInEditing: YES];
|
||||
[cell setShowsFirstResponder: YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
[cell setObjectValue: [_dataSource outlineView: self
|
||||
objectValueForTableColumn: tb
|
||||
byItem: item]];
|
||||
}
|
||||
drawingRect = [self frameOfCellAtColumn: i
|
||||
row: rowIndex];
|
||||
|
||||
if (tb == _outlineTableColumn)
|
||||
{
|
||||
NSImage *image = nil;
|
||||
NSInteger level = 0;
|
||||
CGFloat indentationFactor = 0.0;
|
||||
// float originalWidth = drawingRect.size.width;
|
||||
|
||||
// display the correct arrow...
|
||||
if ([self isItemExpanded: item])
|
||||
{
|
||||
image = expanded;
|
||||
}
|
||||
else
|
||||
{
|
||||
image = collapsed;
|
||||
}
|
||||
|
||||
if (![self isExpandable: item])
|
||||
{
|
||||
image = unexpandable;
|
||||
}
|
||||
|
||||
level = [self levelForItem: item];
|
||||
indentationFactor = _indentationPerLevel * level;
|
||||
imageCell = [[NSCell alloc] initImageCell: image];
|
||||
imageRect = [self frameOfOutlineCellAtRow: rowIndex];
|
||||
|
||||
if ([_delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)])
|
||||
{
|
||||
[_delegate outlineView: self
|
||||
willDisplayOutlineCell: imageCell
|
||||
forTableColumn: tb
|
||||
item: item];
|
||||
}
|
||||
|
||||
/* Do not indent if the delegate set the image to nil. */
|
||||
if ([imageCell image])
|
||||
{
|
||||
imageRect.size.width = [image size].width;
|
||||
imageRect.size.height = [image size].height;
|
||||
[imageCell drawWithFrame: imageRect inView: self];
|
||||
drawingRect.origin.x
|
||||
+= indentationFactor + imageRect.size.width + 5;
|
||||
drawingRect.size.width
|
||||
-= indentationFactor + imageRect.size.width + 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawingRect.origin.x += indentationFactor;
|
||||
drawingRect.size.width -= indentationFactor;
|
||||
}
|
||||
|
||||
RELEASE(imageCell);
|
||||
}
|
||||
|
||||
[cell drawWithFrame: drawingRect inView: self];
|
||||
if (i == _editedColumn && rowIndex == _editedRow)
|
||||
{
|
||||
[cell _setInEditing: NO];
|
||||
[cell setShowsFirstResponder: NO];
|
||||
}
|
||||
}
|
||||
[[GSTheme theme] drawOutlineViewRow: rowIndex
|
||||
clipRect: aRect
|
||||
inView: self];
|
||||
}
|
||||
|
||||
- (void) drawRect: (NSRect)aRect
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
#import "AppKit/NSPasteboard.h"
|
||||
#import "AppKit/NSDragging.h"
|
||||
#import "AppKit/NSCustomImageRep.h"
|
||||
|
||||
#import "GNUstepGUI/GSTheme.h"
|
||||
#import "GSBindingHelpers.h"
|
||||
|
||||
|
|
Loading…
Reference in a new issue