mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 13:10:59 +00:00
Consolidate and refactor the cellview methods in the theme drawing code, so that there is no repeated code
This commit is contained in:
parent
8e2df65156
commit
f787edfcfb
4 changed files with 161 additions and 210 deletions
|
@ -1346,18 +1346,14 @@ APPKIT_EXPORT_CLASS
|
|||
clipRect: (NSRect)clipRect
|
||||
inView: (NSView *)view;
|
||||
|
||||
- (void) drawTableCellViewRow: (NSInteger)rowIndex
|
||||
clipRect: (NSRect)clipRect
|
||||
inView: (NSView *)view;
|
||||
- (void) drawCellViewRow: (NSInteger)rowIndex
|
||||
clipRect: (NSRect)clipRect
|
||||
inView: (id)v;
|
||||
|
||||
- (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
|
||||
|
|
|
@ -3309,7 +3309,8 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
|
|||
NSInteger numberOfColumns = [tableView numberOfColumns];
|
||||
NSIndexSet *selectedRows = [tableView selectedRowIndexes];
|
||||
NSIndexSet *selectedColumns = [tableView selectedColumnIndexes];
|
||||
NSColor *backgroundColor = [tableView backgroundColor];
|
||||
|
||||
// NSColor *backgroundColor = [tableView backgroundColor];
|
||||
|
||||
// Set the fill color
|
||||
{
|
||||
|
@ -3494,25 +3495,48 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
|
|||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) drawTableCellViewRow: (NSInteger)rowIndex
|
||||
clipRect: (NSRect)clipRect
|
||||
inView: (NSView *)view
|
||||
|
||||
- (void) drawCellViewRow: (NSInteger)rowIndex
|
||||
clipRect: (NSRect)clipRect
|
||||
inView: (id)v
|
||||
{
|
||||
NSTableView *tableView = (NSTableView *)view;
|
||||
NSInteger numberOfColumns = [tableView numberOfColumns];
|
||||
CGFloat *columnOrigins = [tableView _columnOrigins];
|
||||
NSArray *tableColumns = [tableView tableColumns];
|
||||
NSInteger numberOfColumns = [v numberOfColumns];
|
||||
CGFloat *columnOrigins = [v _columnOrigins];
|
||||
NSArray *tableColumns = [v tableColumns];
|
||||
CGFloat indentationPerLevel = 0.0;
|
||||
NSInteger numberOfRows = [v numberOfRows];
|
||||
NSInteger startingColumn;
|
||||
NSInteger endingColumn;
|
||||
NSInteger i;
|
||||
CGFloat x_pos;
|
||||
id<NSTableViewDelegate> delegate = [tableView delegate];
|
||||
BOOL hasMethod = [delegate respondsToSelector: @selector(tableView:viewForTableColumn:row:)];
|
||||
|
||||
/* Using columnAtPoint: here would make it called twice per row per drawn
|
||||
rect - so we avoid it and do it natively */
|
||||
id dataSource = [v dataSource];
|
||||
id delegate = [v delegate];
|
||||
BOOL hasMethod = NO;
|
||||
NSTableColumn *outlineTableColumn = nil;
|
||||
|
||||
// If we have no data source, there is nothing to do...
|
||||
if (dataSource == nil)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If the rowIndex is greater than the numberOfRows, done...
|
||||
if (rowIndex >= numberOfRows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check the delegate method...
|
||||
if ([v isKindOfClass: [NSOutlineView class]])
|
||||
{
|
||||
outlineTableColumn = [v outlineTableColumn];
|
||||
hasMethod = [delegate respondsToSelector: @selector(outlineView:viewForTableColumn:row:)];
|
||||
}
|
||||
else if ([v isKindOfClass: [NSTableView class]])
|
||||
{
|
||||
hasMethod = [delegate respondsToSelector: @selector(tableView:viewForTableColumn:row:)];
|
||||
}
|
||||
|
||||
/* Determine starting column as fast as possible */
|
||||
x_pos = NSMinX (clipRect);
|
||||
i = 0;
|
||||
|
@ -3539,43 +3563,124 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
|
|||
/* Draw the row between startingColumn and endingColumn */
|
||||
for (i = startingColumn; i <= endingColumn; i++)
|
||||
{
|
||||
NSRect drawingRect = [tableView
|
||||
frameOfCellAtColumn: i
|
||||
row: rowIndex];
|
||||
NSTableColumn *tb = nil;
|
||||
NSRect drawingRect = [v frameOfCellAtColumn: i
|
||||
row: rowIndex];
|
||||
NSTableColumn *tb = [tableColumns objectAtIndex: i];
|
||||
NSIndexPath *path = [NSIndexPath indexPathForItem: i
|
||||
inSection: rowIndex];
|
||||
NSMapTable *paths = [tableView _renderedViewPaths];
|
||||
NSMapTable *views = [tableView _pathsToViews];
|
||||
NSMapTable *paths = [v _renderedViewPaths];
|
||||
NSMapTable *views = [v _pathsToViews];
|
||||
NSView *view = [paths objectForKey: path];
|
||||
|
||||
// If the view has been stored use it, if not
|
||||
// then grab it.
|
||||
if (view == nil)
|
||||
{
|
||||
tb = [tableColumns objectAtIndex: i];
|
||||
if (hasMethod)
|
||||
{
|
||||
view = [delegate tableView: tableView
|
||||
viewForTableColumn: tb
|
||||
row: rowIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSArray *protoCellViews = [tb _prototypeCellViews];
|
||||
|
||||
// it seems there is always one prototype...
|
||||
if ([protoCellViews count] > 0)
|
||||
{
|
||||
view = [protoCellViews objectAtIndex: 0];
|
||||
view = [view copy]; // instantiate the prototype...
|
||||
}
|
||||
}
|
||||
|
||||
// Store the object...
|
||||
[paths setObject: view forKey: path];
|
||||
[views setObject: path forKey: view];
|
||||
[tableView addSubview: view];
|
||||
if ([v isKindOfClass: [NSOutlineView class]])
|
||||
{
|
||||
id item = [v itemAtRow: rowIndex];
|
||||
|
||||
if (tb == outlineTableColumn)
|
||||
{
|
||||
NSImage *image = nil;
|
||||
NSInteger level = 0;
|
||||
CGFloat indentationFactor = 0.0;
|
||||
NSImageView *imageView = nil;
|
||||
NSRect imageRect = NSZeroRect;
|
||||
|
||||
// display the correct arrow...
|
||||
if ([v isItemExpanded: item])
|
||||
{
|
||||
image = [NSImage imageNamed: @"common_ArrowDownH"];
|
||||
}
|
||||
else
|
||||
{
|
||||
image = [NSImage imageNamed: @"common_ArrowRightH"];
|
||||
}
|
||||
|
||||
if (![v isExpandable: item])
|
||||
{
|
||||
image = [[NSImage alloc] initWithSize: NSMakeSize(14.0,14.0)]; // revisit this.. memory leak
|
||||
}
|
||||
|
||||
level = [v levelForItem: item];
|
||||
indentationFactor = indentationPerLevel * level;
|
||||
imageView = [[NSImageView alloc] init];
|
||||
imageRect = [v frameOfOutlineCellAtRow: rowIndex];
|
||||
|
||||
/* Do not indent if the delegate set the image to nil. */
|
||||
if ([imageView image])
|
||||
{
|
||||
imageRect.size.width = [image size].width;
|
||||
imageRect.size.height = [image size].height;
|
||||
|
||||
// Place the image...
|
||||
[imageView setFrame: imageRect];
|
||||
[v addSubview: imageView];
|
||||
|
||||
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(imageView);
|
||||
}
|
||||
|
||||
if (view == nil)
|
||||
{
|
||||
if (hasMethod)
|
||||
{
|
||||
view = [delegate outlineView: v
|
||||
viewForTableColumn: tb
|
||||
item: item];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSArray *protoCellViews = [tb _prototypeCellViews];
|
||||
|
||||
// it seems there is always one prototype...
|
||||
if ([protoCellViews count] > 0)
|
||||
{
|
||||
view = [protoCellViews objectAtIndex: 0];
|
||||
view = [view copy]; // instantiate the prototype...
|
||||
}
|
||||
}
|
||||
|
||||
[paths setObject: view forKey: path];
|
||||
[v addSubview: view];
|
||||
}
|
||||
}
|
||||
else if ([v isKindOfClass: [NSTableView class]])
|
||||
{
|
||||
// If the view has been stored use it, if not
|
||||
// then grab it.
|
||||
if (view == nil)
|
||||
{
|
||||
if (hasMethod)
|
||||
{
|
||||
view = [delegate tableView: v
|
||||
viewForTableColumn: tb
|
||||
row: rowIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSArray *protoCellViews = [tb _prototypeCellViews];
|
||||
|
||||
// it seems there is always one prototype...
|
||||
if ([protoCellViews count] > 0)
|
||||
{
|
||||
view = [protoCellViews objectAtIndex: 0];
|
||||
view = [view copy]; // instantiate the prototype...
|
||||
}
|
||||
}
|
||||
|
||||
// Store the object...
|
||||
[paths setObject: view forKey: path];
|
||||
[views setObject: path forKey: view];
|
||||
[v addSubview: view];
|
||||
}
|
||||
}
|
||||
|
||||
// Place the view...
|
||||
|
@ -3730,156 +3835,6 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
|
|||
}
|
||||
}
|
||||
|
||||
- (void) drawOutlineCellViewRow: (NSInteger)rowIndex
|
||||
clipRect: (NSRect)clipRect
|
||||
inView: (NSView *)view
|
||||
{
|
||||
NSOutlineView *outlineView = (NSOutlineView *)view;
|
||||
NSInteger numberOfColumns = [outlineView numberOfColumns];
|
||||
CGFloat *columnOrigins = [outlineView _columnOrigins];
|
||||
NSArray *tableColumns = [outlineView tableColumns];
|
||||
CGFloat indentationPerLevel = [outlineView indentationPerLevel];
|
||||
NSInteger numberOfRows = [outlineView numberOfRows];
|
||||
NSInteger startingColumn;
|
||||
NSInteger endingColumn;
|
||||
NSInteger i;
|
||||
CGFloat x_pos;
|
||||
id dataSource = [outlineView dataSource];
|
||||
id delegate = [outlineView delegate];
|
||||
NSTableColumn *outlineTableColumn = [outlineView outlineTableColumn];
|
||||
BOOL hasMethod = [delegate respondsToSelector: @selector(outlineView:viewForTableColumn:row:)];
|
||||
|
||||
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);
|
||||
|
||||
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++)
|
||||
{
|
||||
NSRect drawingRect = [outlineView
|
||||
frameOfCellAtColumn: i
|
||||
row: rowIndex];
|
||||
id item = [outlineView itemAtRow: rowIndex];
|
||||
NSTableColumn *tb = [tableColumns objectAtIndex: i];
|
||||
NSIndexPath *path = [NSIndexPath indexPathForItem: i
|
||||
inSection: rowIndex];
|
||||
NSMapTable *paths = [outlineView _renderedViewPaths];
|
||||
NSView *view = [paths objectForKey: path];
|
||||
|
||||
if (tb == outlineTableColumn)
|
||||
{
|
||||
NSImage *image = nil;
|
||||
NSInteger level = 0;
|
||||
CGFloat indentationFactor = 0.0;
|
||||
NSImageView *imageView = nil;
|
||||
NSRect imageRect = NSZeroRect;
|
||||
|
||||
// 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;
|
||||
imageView = [[NSImageView alloc] init];
|
||||
imageRect = [outlineView frameOfOutlineCellAtRow: rowIndex];
|
||||
|
||||
/* Do not indent if the delegate set the image to nil. */
|
||||
if ([imageView image])
|
||||
{
|
||||
imageRect.size.width = [image size].width;
|
||||
imageRect.size.height = [image size].height;
|
||||
|
||||
// Place the image...
|
||||
[imageView setFrame: imageRect];
|
||||
[outlineView addSubview: imageView];
|
||||
|
||||
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(imageView);
|
||||
}
|
||||
|
||||
if (view == nil)
|
||||
{
|
||||
if (hasMethod)
|
||||
{
|
||||
view = [delegate outlineView: outlineView
|
||||
viewForTableColumn: tb
|
||||
item: item];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSArray *protoCellViews = [tb _prototypeCellViews];
|
||||
|
||||
// it seems there is always one prototype...
|
||||
if ([protoCellViews count] > 0)
|
||||
{
|
||||
view = [protoCellViews objectAtIndex: 0];
|
||||
view = [view copy]; // instantiate the prototype...
|
||||
}
|
||||
}
|
||||
|
||||
[paths setObject: view forKey: path];
|
||||
[outlineView addSubview: view];
|
||||
}
|
||||
|
||||
// Place the view...
|
||||
[view setFrame: drawingRect];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) drawBoxInClipRect: (NSRect)clipRect
|
||||
boxType: (NSBoxType)boxType
|
||||
borderType: (NSBorderType)borderType
|
||||
|
|
|
@ -925,9 +925,9 @@ static NSImage *unexpandable = nil;
|
|||
{
|
||||
if (_viewBased)
|
||||
{
|
||||
[[GSTheme theme] drawOutlineCellViewRow: rowIndex
|
||||
clipRect: aRect
|
||||
inView: self];
|
||||
[[GSTheme theme] drawCellViewRow: rowIndex
|
||||
clipRect: aRect
|
||||
inView: self];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -5056,9 +5056,9 @@ This method is deprecated, use -columnIndexesInRect:. */
|
|||
{
|
||||
if (_viewBased)
|
||||
{
|
||||
[[GSTheme theme] drawTableCellViewRow: rowIndex
|
||||
clipRect: clipRect
|
||||
inView: self];
|
||||
[[GSTheme theme] drawCellViewRow: rowIndex
|
||||
clipRect: clipRect
|
||||
inView: self];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue