TableView theming

This commit is contained in:
Randall Luecke committed 2010-07-22 00:21:02 -05:00
1 parent 85f3691432
commit cffbf86351
9 files changed
+174 -69

No files matched your search

+3 -12
View File
@@ -78,18 +78,7 @@ CPTableColumnUserResizingMask = 1 << 1;
var header = [[_CPTableColumnHeaderView alloc] initWithFrame:CGRectMakeZero()];
[self setHeaderView:header];
var textDataView = [CPTextField new];
[textDataView setValue:[CPColor colorWithRed:51.0 / 255.0 green:51.0 / 255.0 blue:51.0 / 255.0 alpha:1.0]
forThemeAttribute:"text-color"];
[textDataView setValue:[CPColor whiteColor] forThemeAttribute:@"text-color" inState:CPThemeStateSelectedDataView];
[textDataView setLineBreakMode:CPLineBreakByTruncatingTail];
[textDataView setValue:[CPFont boldSystemFontOfSize:12.0] forThemeAttribute:@"font" inState:CPThemeStateSelectedDataView];
[textDataView setValue:CPCenterVerticalTextAlignment forThemeAttribute:@"vertical-alignment"];
[textDataView setValue:CGInsetMake(0.0, 0.0, 0.0, 5.0) forThemeAttribute:@"content-inset"];
[self setDataView:textDataView];
[self setDataView:[CPTextField new]];
}
return self;
@@ -259,6 +248,8 @@ CPTableColumnUserResizingMask = 1 << 1;
if (_dataView)
_dataViewData[[_dataView UID]] = nil;
[aView setThemeState:CPThemeStateTableDataView];
_dataView = aView;
_dataViewData[[aView UID]] = [CPKeyedArchiver archivedDataWithRootObject:aView];
}
+30 -5
View File
@@ -33,13 +33,13 @@
+ (CPString)themeClass
{
return @"tableHeader";
return @"columnHeader";
}
+ (id)themeAttributes
{
return [CPDictionary dictionaryWithObjects:[[CPNull null], CGInsetMakeZero(), [CPNull null], [CPNull null], [CPNull null], CGSizeMakeZero()]
forKeys:[@"background-color", @"text-inset", @"text-color", @"text-font", @"text-shadow-color", @"text-shadow-offset"]];
return [CPDictionary dictionaryWithObjects:[[CPNull null], [CPNull null], CGInsetMakeZero(), [CPNull null], [CPNull null], [CPNull null], CGSizeMakeZero()]
forKeys:[@"background-color", @"text-alignment", @"text-inset", @"text-color", @"text-font", @"text-shadow-color", @"text-shadow-offset"]];
}
- (void)initWithFrame:(CGRect)frame
@@ -76,6 +76,7 @@
[_textField setFont:[self currentValueForThemeAttribute:@"text-font"]];
[_textField setTextShadowColor:[self currentValueForThemeAttribute:@"text-shadow-color"]];
[_textField setTextShadowOffset:[self currentValueForThemeAttribute:@"text-shadow-offset"]];
[_textField setAlignment:[self currentValueForThemeAttribute:@"text-alignment"]];
}
- (void)setStringValue:(CPString)string
@@ -158,12 +159,24 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
BOOL _isResizing;
BOOL _isDragging;
BOOL _isTrackingColumn;
BOOL _drawsColumnLines;
float _columnOldWidth;
CPTableView _tableView @accessors(property=tableView);
}
+ (CPString)themeClass
{
return @"tableHeaderRow";
}
+ (id)themeAttributes
{
return [CPDictionary dictionaryWithObjects:[[CPNull null]]
forKeys:[@"background-color"]];
}
- (void)_init
{
_mouseDownLocation = CPPointMakeZero();
@@ -177,7 +190,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
_columnOldWidth = 0.0;
[self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 23.0))]];
[self setBackgroundColor:[self currentValueForThemeAttribute:@"background-color"]];
}
- (id)initWithFrame:(CGRect)aFrame
@@ -206,6 +219,16 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
return headerRect;
}
- (void)setDrawsColumnLines:(BOOL)aFlag
{
_drawsColumnLines = aFlag;
}
- (BOOL)drawsColumnLines
{
return _drawsColumnLines;
}
- (CGRect)_cursorRectForColumn:(int)column
{
if (column == -1 || !([_tableView._tableColumns[column] resizingMask] & CPTableColumnUserResizingMask))
@@ -582,11 +605,13 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
if([headerView superview] != self)
[self addSubview:headerView];
}
[self setBackgroundColor:[self currentValueForThemeAttribute:@"background-color"]];
}
- (void)drawRect:(CGRect)aRect
{
if (!_tableView)
if (!_tableView || ![self drawsColumnLines])
return;
var context = [[CPGraphicsContext currentContext] graphicsPort],
+42 -43
View File
@@ -165,6 +165,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
BOOL _allowsEmptySelection;
CPArray _sortDescriptors;
//Setting Display Attributes
CGSize _intercellSpacing;
float _rowHeight;
@@ -174,9 +175,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
unsigned _selectionHighlightStyle;
CPTableColumn _currentHighlightedTableColumn;
CPColor _selectionHighlightColor;
unsigned _gridStyleMask;
CPColor _gridColor;
unsigned _numberOfRows;
@@ -215,12 +214,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
BOOL _disableAutomaticResizing @accessors(property=disableAutomaticResizing);
BOOL _lastColumnShouldSnap;
CPGradient _sourceListActiveGradient;
CPColor _sourceListActiveTopLineColor;
CPColor _sourceListActiveBottomLineColor;
int _draggedColumnIndex;
CPArray _differedColumnDataToRemove;
CPArray _differedColumnDataToRemove;
/*
CPGradient _sourceListInactiveGradient;
@@ -229,6 +224,17 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
*/
}
+ (CPString)themeClass
{
return @"tableview";
}
+ (id)themeAttributes
{
return [CPDictionary dictionaryWithObjects:[[CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null]]
forKeys:["alternating-row-colors", "grid-color", "highlighted-grid-color", "selection-color", "sourcelist-selection-color", "sort-image", "sort-image-reversed"]];
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
@@ -588,17 +594,14 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
- (void)setAlternatingRowBackgroundColors:(CPArray)alternatingRowBackgroundColors
{
if ([_alternatingRowBackgroundColors isEqual:alternatingRowBackgroundColors])
return;
_alternatingRowBackgroundColors = alternatingRowBackgroundColors;
[self setValue:alternatingRowBackgroundColors forThemeAttribute:"alternating-row-colors"];
[self setNeedsDisplay:YES];
}
- (CPArray)alternatingRowBackgroundColors
{
return _alternatingRowBackgroundColors;
return [self currentValueForThemeAttribute:@"alternating-row-colors"];
}
- (unsigned)selectionHighlightStyle
@@ -627,10 +630,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
*/
- (void)setSelectionHighlightColor:(CPColor)aColor
{
if (aColor === _selectionHighlightColor)
return;
[self setValue:aColor forThemeAttribute:"selection-color"];
_selectionHighlightColor = aColor;
[self setNeedsDisplay:YES];
}
@@ -639,7 +640,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
*/
- (CPColor)selectionHighlightColor
{
return _selectionHighlightColor;
return [self currentValueForThemeAttribute:@"selection-color"];
}
/*!
@@ -652,12 +653,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
*/
- (void)setSelectionGradientColors:(CPDictionary)aDictionary
{
if ([aDictionary valueForKey:"CPSourceListGradient"] === _sourceListActiveGradient && [aDictionary valueForKey:"CPSourceListTopLineColor"] === _sourceListActiveTopLineColor && [aDictionary valueForKey:"CPSourceListBottomLineColor"] === _sourceListActiveBottomLineColor)
return;
[self setValue:aDictionary forThemeAttribute:"sourcelist-selection-color"];
_sourceListActiveGradient = [aDictionary valueForKey:CPSourceListGradient];
_sourceListActiveTopLineColor = [aDictionary valueForKey:CPSourceListTopLineColor];
_sourceListActiveBottomLineColor = [aDictionary valueForKey:CPSourceListBottomLineColor];
[self setNeedsDisplay:YES];
}
@@ -669,7 +666,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
*/
- (CPDictionary)selectionGradientColors
{
return [CPDictionary dictionaryWithObjects:[_sourceListActiveGradient, _sourceListActiveTopLineColor, _sourceListActiveBottomLineColor] forKeys:[CPSourceListGradient, CPSourceListTopLineColor, CPSourceListBottomLineColor]];
return [self currentValueForThemeAttribute:@"sourcelist-selection-color"];
}
/*!
@@ -678,17 +675,14 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
*/
- (void)setGridColor:(CPColor)aColor
{
if (_gridColor === aColor)
return;
_gridColor = aColor;
[self setValue:aColor forThemeAttribute:"grid-color"];
[self setNeedsDisplay:YES];
}
- (CPColor)gridColor
{
return _gridColor;
return [self currentValueForThemeAttribute:@"grid-color"];;
}
/*!
@@ -1914,7 +1908,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
[newSortDescriptors insertObject:newMainSortDescriptor atIndex:0];
// Update indicator image & highlighted column before
var image = [newMainSortDescriptor ascending] ? [CPTableView _defaultTableHeaderSortImage] : [CPTableView _defaultTableHeaderReverseSortImage];
var image = [newMainSortDescriptor ascending] ? [self _tableHeaderSortImage] : [self _tableHeaderReverseSortImage];
[self setIndicatorImage:nil inTableColumn:_currentHighlightedTableColumn];
[self setIndicatorImage:image inTableColumn:tableColumn];
@@ -1929,14 +1923,14 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
[[aTableColumn headerView] _setIndicatorImage:anImage];
}
+ (CPImage)_defaultTableHeaderSortImage
- (CPImage)_tableHeaderSortImage
{
return CPAppKitImage("tableview-headerview-ascending.png", CGSizeMake(9.0, 8.0));
return [self currentValueForThemeAttribute:"sort-image"];
}
+ (CPImage)_defaultTableHeaderReverseSortImage
- (CPImage)_tableHeaderReverseSortImage
{
return CPAppKitImage("tableview-headerview-descending.png", CGSizeMake(9.0, 8.0));
return [self currentValueForThemeAttribute:"sort-image-reversed"];
}
//Highlightable Column Headers
@@ -2636,7 +2630,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
}
CGContextClosePath(context);
CGContextSetStrokeColor(context, _gridColor);
CGContextSetStrokeColor(context, [self gridColor]);
CGContextStrokePath(context);
}
@@ -2679,6 +2673,12 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
deltaHeight = 0.5 * (_gridStyleMask & CPTableViewSolidHorizontalGridLineMask);
CGContextBeginPath(context);
var gradientCache = [self selectionGradientColors],
topLineColor = [gradientCache objectForKey:CPSourceListTopLineColor],
bottomLineColor = [gradientCache objectForKey:CPSourceListBottomLineColor],
gradientColor = [gradientCache objectForKey:CPSourceListGradient];
while (count--)
{
var rowRect = CGRectIntersection(objj_msgSend(self, rectSelector, indexes[count]), aRect);
@@ -2691,21 +2691,21 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
maxX = _CGRectGetMaxX(rowRect),
maxY = _CGRectGetMaxY(rowRect) - deltaHeight;
CGContextDrawLinearGradient(context, _sourceListActiveGradient, rowRect.origin, CGPointMake(minX, maxY), 0);
CGContextDrawLinearGradient(context, gradientColor, rowRect.origin, CGPointMake(minX, maxY), 0);
CGContextClosePath(context);
CGContextBeginPath(context);
CGContextMoveToPoint(context, minX, minY);
CGContextAddLineToPoint(context, maxX, minY);
CGContextClosePath(context);
CGContextSetStrokeColor(context, _sourceListActiveTopLineColor);
CGContextSetStrokeColor(context, topLineColor);
CGContextStrokePath(context);
CGContextBeginPath(context);
CGContextMoveToPoint(context, minX, maxY);
CGContextAddLineToPoint(context, maxX, maxY - 1);
CGContextClosePath(context);
CGContextSetStrokeColor(context, _sourceListActiveBottomLineColor);
CGContextSetStrokeColor(context, bottomLineColor);
CGContextStrokePath(context);
}
}
@@ -2714,7 +2714,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
if (!drawGradient)
{
[_selectionHighlightColor setFill];
[[self selectionHighlightColor] setFill];
CGContextFillPath(context);
}
@@ -2757,7 +2757,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
}
CGContextClosePath(context);
CGContextSetStrokeColor(context, [CPColor colorWithHexString:@"e5e5e5"]);
CGContextSetStrokeColor(context, [self currentValueForThemeAttribute:"highlighted-grid-color"]);
CGContextStrokePath(context);
}
@@ -3537,12 +3537,11 @@ var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey",
_intercellSpacing = [aCoder decodeSizeForKey:CPTableViewIntercellSpacingKey] || _CGSizeMake(0.0, 0.0);
_gridColor = [aCoder decodeObjectForKey:CPTableViewGridColorKey] || [CPColor grayColor];
[self setGridColor:[aCoder decodeObjectForKey:CPTableViewGridColorKey] || [CPColor grayColor]];
_gridStyleMask = [aCoder decodeIntForKey:CPTableViewGridStyleMaskKey] || CPTableViewGridNone;
_usesAlternatingRowBackgroundColors = [aCoder decodeObjectForKey:CPTableViewUsesAlternatingBackgroundKey];
_alternatingRowBackgroundColors =
[[CPColor whiteColor], [CPColor colorWithRed:245.0 / 255.0 green:249.0 / 255.0 blue:252.0 / 255.0 alpha:1.0]];
[self setAlternatingRowBackgroundColors:[aCoder decodeObjectForKey:CPTableViewAlternatingRowColorsKey]];
_headerView = [aCoder decodeObjectForKey:CPTableViewHeaderViewKey];
_cornerView = [aCoder decodeObjectForKey:CPTableViewCornerViewKey];
@@ -3576,11 +3575,11 @@ var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey",
[aCoder encodeObject:_tableColumns forKey:CPTableViewTableColumnsKey];
[aCoder encodeObject:_gridColor forKey:CPTableViewGridColorKey];
[aCoder encodeObject:[self gridColor] forKey:CPTableViewGridColorKey];
[aCoder encodeInt:_gridStyleMask forKey:CPTableViewGridStyleMaskKey];
[aCoder encodeBool:_usesAlternatingRowBackgroundColors forKey:CPTableViewUsesAlternatingBackgroundKey];
[aCoder encodeObject:_alternatingRowBackgroundColors forKey:CPTableViewAlternatingRowColorsKey]
[aCoder encodeObject:[self alternatingRowBackgroundColors] forKey:CPTableViewAlternatingRowColorsKey]
[aCoder encodeObject:_cornerView forKey:CPTableViewCornerViewKey];
[aCoder encodeObject:_headerView forKey:CPTableViewHeaderViewKey];
+2 -1
View File
@@ -242,7 +242,8 @@ CPThemeStateNormal = CPThemeStates["normal"] = 0;
CPThemeStateDisabled = CPThemeState("disabled");
CPThemeStateHighlighted = CPThemeState("highlighted");
CPThemeStateSelected = CPThemeState("selected");
CPThemeStateSelectedDataView = CPThemeState("selectedDataView");
CPThemeStateTableDataView = CPThemeState("tableDataView");
CPThemeStateSelectedDataView = CPThemeStateSelectedTableDataView = CPThemeState("selectedTableDataView");
CPThemeStateBezeled = CPThemeState("bezeled");
CPThemeStateBordered = CPThemeState("bordered");
CPThemeStateEditable = CPThemeState("editable");
+3
View File
@@ -1364,6 +1364,9 @@ var CPViewFlags = { },
if (_backgroundColor == aColor)
return;
if (aColor == [CPNull null])
aColor = nil;
_backgroundColor = aColor;
#if PLATFORM(DOM)
+72 -1
View File
@@ -356,6 +356,16 @@
[textfield setStringValue:""];
[textfield setEditable:YES];
// tableview dataview stuff
[textfield setValue:[CPColor colorWithRed:51.0 / 255.0 green:51.0 / 255.0 blue:51.0 / 255.0 alpha:1.0] forThemeAttribute:"text-color" inState:CPThemeStateTableDataView];
[textfield setValue:CPLineBreakByTruncatingTail forThemeAttribute:@"line-break-mode" inState:CPThemeStateTableDataView|CPThemeStateTableDataView];
[textfield setValue:CPCenterVerticalTextAlignment forThemeAttribute:@"vertical-alignment" inState:CPThemeStateTableDataView|CPThemeStateTableDataView];
[textfield setValue:CGInsetMake(0.0, 0.0, 0.0, 5.0) forThemeAttribute:@"content-inset" inState:CPThemeStateTableDataView|CPThemeStateTableDataView];
[textfield setValue:[CPColor whiteColor] forThemeAttribute:@"text-color" inState:CPThemeStateTableDataView|CPThemeStateSelectedTableDataView];
[textfield setValue:[CPFont boldSystemFontOfSize:12.0] forThemeAttribute:@"font" inState:CPThemeStateTableDataView|CPThemeStateSelectedTableDataView];
return textfield;
}
@@ -773,7 +783,7 @@
return buttonBar;
}
+ (_CPTableColumnHeaderView)themedTableHeader
+ (_CPTableColumnHeaderView)themedColumnHeader
{
var header = [[_CPTableColumnHeaderView alloc] initWithFrame:CGRectMake(0,0,50,24)],
highlightedPressed = [CPColor colorWithPatternImage:[_CPCibCustomResource imageResourceWithName:"tableview-headerview-highlighted-pressed.png" size:CGSizeMake(1.0, 23.0)]],
@@ -790,6 +800,7 @@
[header setValue:[CPFont boldSystemFontOfSize:12.0] forThemeAttribute:@"text-font"];
[header setValue:[CPColor whiteColor] forThemeAttribute:@"text-shadow-color"];
[header setValue:CGSizeMake(0,1) forThemeAttribute:@"text-shadow-offset"];
[header setValue:CPLeftTextAlignment forThemeAttribute:@"text-alignment"];
[header setValue:pressed forThemeAttribute:@"background-color" inState:CPThemeStateHighlighted];
[header setValue:highlighted forThemeAttribute:@"background-color" inState:CPThemeStateSelected];
@@ -798,6 +809,66 @@
return header;
}
+ (CPTableHeaderView)themedTableHeaderRow
{
var header = [[CPTableHeaderView alloc] initWithFrame:CGRectMake(0,0,50,24)],
normal = [CPColor colorWithPatternImage:[_CPCibCustomResource imageResourceWithName:"tableview-headerview.png" size:CGSizeMake(1.0, 23.0)]];
[header setValue:normal forThemeAttribute:@"background-color"];
return header;
}
+ (_CPCornerView)themedCornerview
{
var corner = [[_CPCornerView alloc] initWithFrame:CGRectMake(0,0,25, 23)],
normal = [CPColor colorWithPatternImage:[_CPCibCustomResource imageResourceWithName:"tableview-headerview.png" size:CGSizeMake(1.0, 23.0)]];
[corner setValue:normal forThemeAttribute:"background-color"];
return corner;
}
+ (CPTableView)themedTableView
{
// This is a bit more complicated than the rest because we actually set theme values for several different (table related) controls in this method
var tableview = [[CPTableView alloc] initWithFrame:CGRectMake(0,0,200,200)];
// Now theme the tableview
var sortImage = [_CPCibCustomResource imageResourceWithName:"tableview-headerview-ascending.png" size:CGSizeMake(9.0, 8.0)],
sortImageReversed = [_CPCibCustomResource imageResourceWithName:"tableview-headerview-descending.png" size:CGSizeMake(9.0, 8.0)],
alternatingRowColors = [[CPColor whiteColor], [CPColor colorWithHexString:@"e4e7ff"]],
gridColor = [CPColor colorWithHexString:@"dce0e2"],
selectionColor = [CPColor colorWithHexString:@"5f83b9"],
sourceListSelectionColor = [CPDictionary dictionaryWithObjects: [ CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), [89.0/255.0, 153.0/255.0, 209.0/255.0,1.0, 33.0/255.0, 94.0/255.0, 208.0/255.0,1.0], [0,1], 2),
[CPColor colorWithCalibratedRed:(61.0/255.0) green:(123.0/255.0) blue:(218.0/255.0) alpha:1.0],
[CPColor colorWithCalibratedRed:(31.0/255.0) green:(92.0/255.0) blue:(207.0/255.0) alpha:1.0]
]
forKeys: [CPSourceListGradient, CPSourceListTopLineColor, CPSourceListBottomLineColor]];
[tableview setValue:alternatingRowColors forThemeAttribute:"alternating-row-colors"];
[tableview setValue:gridColor forThemeAttribute:"grid-color"];
[tableview setValue:[CPColor whiteColor] forThemeAttribute:"highlighted-grid-color"];
[tableview setValue:selectionColor forThemeAttribute:"selection-color"];
[tableview setValue:sourceListSelectionColor forThemeAttribute:"sourcelist-selection-color"];
[tableview setValue:sortImage forThemeAttribute:"sort-image"];
[tableview setValue:sortImageReversed forThemeAttribute:"sort-image-reversed"];
return tableview;
}
+ (CPTextField)themedTableDataView
{
var view = [self themedStandardTextField];
[view setBezeled:NO];
[view setEditable:NO];
[view setThemeState:CPThemeStateTableDataView];
return view;
}
@end
@implementation AristoHUDThemeDescriptor : BKThemeDescriptor
+22 -7
View File
@@ -1,21 +1,36 @@
@import "CPView.j"
@implementation _CPCornerView : CPView
{
}
+ (CPString)themeClass
{
return @"cornerview";
}
+ (id)themeAttributes
{
return [CPDictionary dictionaryWithObjects:[[CPNull null]]
forKeys:[@"background-color"]];
}
- (void)layoutSubviews
{
[self setBackgroundColor:[self currentValueForThemeAttribute:@"background-color"]];
}
- (void)_init
{
[self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 23.0))]];
[self setBackgroundColor:[self currentValueForThemeAttribute:@"background-color"]];
}
- (id)initWithFrame:(CGRect)aFrame
{
if (self = [super initWithFrame:aFrame])
{
self = [super initWithFrame:aFrame]
if (self)
[self _init];
}
return self;
}
@@ -23,9 +38,9 @@
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
{
if (self)
[self _init];
}
return self;
}