mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-17 04:00:42 +00:00
Added API for changing tableview selection color and source list gradient.
This commit is contained in:
1 parent
6a34329765
commit
79e8b6e242
2 files changed
+109
-18
No files matched your search
+62
-17
@@ -74,6 +74,10 @@ CPTableViewDraggingDestinationFeedbackStyleSourceList = 1;
|
||||
CPTableViewDropOn = 0;
|
||||
CPTableViewDropAbove = 1;
|
||||
|
||||
CPSourceListGradient = "CPSourceListGradient";
|
||||
CPSourceListTopLineColor = "CPSourceListTopLineColor";
|
||||
CPSourceListBottomLineColor = "CPSourceListBottomLineColor";
|
||||
|
||||
// TODO: add docs
|
||||
|
||||
CPTableViewSelectionHighlightStyleNone = -1;
|
||||
@@ -169,6 +173,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
|
||||
|
||||
unsigned _selectionHighlightStyle;
|
||||
CPTableColumn _currentHighlightedTableColumn;
|
||||
CPColor _selectionHighlightColor;
|
||||
unsigned _gridStyleMask;
|
||||
CPColor _gridColor;
|
||||
|
||||
@@ -288,6 +293,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
|
||||
if (!_alternatingRowBackgroundColors)
|
||||
_alternatingRowBackgroundColors = [[CPColor whiteColor], [CPColor colorWithHexString:@"e4e7ff"]];
|
||||
|
||||
_selectionHighlightColor = [CPColor colorWithHexString:@"5f83b9"];
|
||||
|
||||
_tableColumnRanges = [];
|
||||
_dirtyTableColumnRangeIndex = 0;
|
||||
_numberOfHiddenColumns = 0;
|
||||
@@ -579,15 +586,67 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
|
||||
//early return for IE.
|
||||
if (aSelectionHighlightStyle == CPTableViewSelectionHighlightStyleSourceList && !CPFeatureIsCompatible(CPHTMLCanvasFeature))
|
||||
return;
|
||||
|
||||
|
||||
_selectionHighlightStyle = aSelectionHighlightStyle;
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
|
||||
if (aSelectionHighlightStyle === CPTableViewSelectionHighlightStyleSourceList)
|
||||
_destinationDragStyle = CPTableViewDraggingDestinationFeedbackStyleSourceList;
|
||||
else
|
||||
_destinationDragStyle = CPTableViewDraggingDestinationFeedbackStyleRegular;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the highlight color for a row or column selection
|
||||
@param aColor a CPColor
|
||||
*/
|
||||
- (void)setSelectionHighlightColor:(CPColor)aColor
|
||||
{
|
||||
if (aColor === _selectionHighlightColor)
|
||||
return;
|
||||
|
||||
_selectionHighlightColor = aColor;
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the highlight color for a row or column selection.
|
||||
*/
|
||||
- (CPColor)selectionHighlightColor
|
||||
{
|
||||
return _selectionHighlightColor;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the highlight gradient for a row or column selection
|
||||
This is specific to the
|
||||
@param aDictionary a CPDictionary expects three keys to be set:
|
||||
CPSourceListGradient which is a CGGradient
|
||||
CPSourceListTopLineColor which is a CPColor
|
||||
CPSourceListBottomLineColor which is a CPColor
|
||||
*/
|
||||
- (void)setSelectionGradientColors:(CPDictionary)aDictionary
|
||||
{
|
||||
if ([aDictionary valueForKey:"CPSourceListGradient"] === _sourceListActiveGradient && [aDictionary valueForKey:"CPSourceListTopLineColor"] === _sourceListActiveTopLineColor && [aDictionary valueForKey:"CPSourceListBottomLineColor"] === _sourceListActiveBottomLineColor)
|
||||
return;
|
||||
|
||||
_sourceListActiveGradient = [aDictionary valueForKey:CPSourceListGradient];
|
||||
_sourceListActiveTopLineColor = [aDictionary valueForKey:CPSourceListTopLineColor]
|
||||
_sourceListActiveBottomLineColor = [aDictionary valueForKey:CPSourceListBottomLineColor];
|
||||
[self setNeedsDisplay:YES]
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns a dictionary of containing the keys:
|
||||
CPSourceListGradient
|
||||
CPSourceListTopLineColor
|
||||
CPSourceListBottomLineColor
|
||||
*/
|
||||
- (CPDictionary)selectionGradientColors
|
||||
{
|
||||
return [CPDictionary dictionaryWithObjects:[_sourceListActiveGradient, _sourceListActiveTopLineColor, _sourceListActiveBottomLineColor] forKeys:[CPSourceListGradient, CPSourceListTopLineColor, CPSourceListBottomLineColor]];
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the grid color in the non highlighted state.
|
||||
@param aColor a CPColor
|
||||
@@ -2568,7 +2627,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
|
||||
|
||||
if (!drawGradient)
|
||||
{
|
||||
[[CPColor selectionColor] setFill];
|
||||
[_selectionHighlightColor setFill];
|
||||
CGContextFillPath(context);
|
||||
}
|
||||
|
||||
@@ -3401,20 +3460,6 @@ var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey",
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPColor (tableview)
|
||||
|
||||
+ (CPColor)selectionColor
|
||||
{
|
||||
return [CPColor colorWithHexString:@"5f83b9"];
|
||||
}
|
||||
|
||||
+ (CPColor)selectionColorSourceView
|
||||
{
|
||||
return [CPColor colorWithPatternImage:[[CPImage alloc] initByReferencingFile:@"Resources/tableviewselection.png" size:CGSizeMake(6,22)]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPIndexSet (tableview)
|
||||
|
||||
- (void)removeMatches:otherSet
|
||||
|
||||
@@ -19,7 +19,7 @@ tableTestDragType = @"CPTableViewTestDragType";
|
||||
dataSet2 = [],
|
||||
dataSet3 = [];
|
||||
|
||||
for(var i = 1; i < 100; i++)
|
||||
for(var i = 1; i < 10; i++)
|
||||
{
|
||||
dataSet1[i - 1] = [CPNumber numberWithInt:i];
|
||||
dataSet2[i - 1] = [CPNumber numberWithInt:i+10];
|
||||
@@ -41,6 +41,7 @@ tableTestDragType = @"CPTableViewTestDragType";
|
||||
[tableView registerForDraggedTypes:[CPArray arrayWithObject:tableTestDragType]];
|
||||
[tableView setColumnAutoresizingStyle:CPTableViewLastColumnOnlyAutoresizingStyle];
|
||||
[tableView setDelegate:self];
|
||||
[tableView setSelectionHighlightColor:[CPColor redColor]];
|
||||
[tableView setDataSource:self];
|
||||
|
||||
|
||||
@@ -81,6 +82,46 @@ tableTestDragType = @"CPTableViewTestDragType";
|
||||
[theWindow orderFront:self];
|
||||
[self newWindow];
|
||||
[self sourceList];
|
||||
|
||||
var button = [[CPButton alloc] initWithFrame:CGRectMake(10,10,100, 24)];
|
||||
[button setTitle:@"Remove Row"];
|
||||
[button setTarget:self];
|
||||
[button setAction:@selector(removeRow:)];
|
||||
[contentView addSubview:button];
|
||||
|
||||
var button = [[CPButton alloc] initWithFrame:CGRectMake(10,40,100, 24)];
|
||||
[button setTitle:@"Add Row"];
|
||||
[button setTarget:self];
|
||||
[button setAction:@selector(addRow:)];
|
||||
[contentView addSubview:button];
|
||||
|
||||
var sourceListActiveGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), [255.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),
|
||||
sourceListActiveTopLineColor = [CPColor colorWithCalibratedRed:(255.0/255.0) green:(123.0/255.0) blue:(218.0/255.0) alpha:1.0],
|
||||
sourceListActiveBottomLineColor = [CPColor colorWithCalibratedRed:(255.0/255.0) green:(92.0/255.0) blue:(207.0/255.0) alpha:1.0];
|
||||
[tableView setSelectionGradientColors:[CPDictionary dictionaryWithObjects:[sourceListActiveGradient, sourceListActiveTopLineColor, sourceListActiveBottomLineColor] forKeys:[CPSourceListGradient, CPSourceListTopLineColor, CPSourceListBottomLineColor]]];
|
||||
|
||||
var button = [[CPButton alloc] initWithFrame:CGRectMake(10,70,100, 24)];
|
||||
[button setTitle:@"Switch Highlight"];
|
||||
[button setTarget:self];
|
||||
[button setAction:@selector(switchSelectionHighlightType:)];
|
||||
[contentView addSubview:button];
|
||||
}
|
||||
|
||||
- (void)switchSelectionHighlightType:(id)sender
|
||||
{
|
||||
[tableView setSelectionHighlightStyle: ABS([tableView selectionHighlightStyle] - 1)];
|
||||
}
|
||||
|
||||
- (void)removeRow:(id)sender
|
||||
{
|
||||
[dataSet1 removeObjectAtIndex:0];
|
||||
[tableView reloadData];
|
||||
}
|
||||
|
||||
- (void)addRow:(id)sender
|
||||
{
|
||||
[dataSet1 addObject:[dataSet1 count] || 0];
|
||||
[tableView reloadData];
|
||||
}
|
||||
|
||||
- (void)newWindow
|
||||
@@ -167,6 +208,11 @@ tableTestDragType = @"CPTableViewTestDragType";
|
||||
[tableView3 setRowHeight:32.0];
|
||||
[scrollView3 setDocumentView:tableView3];
|
||||
[scrollView3 setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
|
||||
var sourceListActiveGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), [255.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),
|
||||
sourceListActiveTopLineColor = [CPColor colorWithCalibratedRed:(255.0/255.0) green:(123.0/255.0) blue:(218.0/255.0) alpha:1.0],
|
||||
sourceListActiveBottomLineColor = [CPColor colorWithCalibratedRed:(255.0/255.0) green:(92.0/255.0) blue:(207.0/255.0) alpha:1.0];
|
||||
[tableView3 setSelectionGradientColors:[CPDictionary dictionaryWithObjects:[sourceListActiveGradient, sourceListActiveTopLineColor, sourceListActiveBottomLineColor] forKeys:[CPSourceListGradient, CPSourceListTopLineColor, CPSourceListBottomLineColor]]];
|
||||
|
||||
[[window3 contentView] addSubview:scrollView3];
|
||||
|
||||
|
||||
Reference in new issue
Block a user