From 1cec1b06371724279c8a2a4db14899693c6a5d6f Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Fri, 15 Nov 2013 17:48:57 -0800 Subject: [PATCH] NEW: CPTableView drop view now supports theming Previously, the style of the blueish view that shows up on CPTableView when user is about to drop something on it was hard coded. This patch adds the following theme attributes in CPTableView // theme of the drop view for CPDragOperationOn on a non selected row dropview-on-background-color dropview-on-border-color dropview-on-border-width dropview-on-border-radius // theme of the drop view for CPDragOperationOn on a selected row dropview-on-selected-background-color dropview-on-selected-border-color dropview-on-selected-border-width dropview-on-selected-border-radius // theme of the drop view for CPDragOperationAbove on a non selected row dropview-above-border-color dropview-above-border-width // theme of the drop view for CPDragOperationAbove on a selected row dropview-above-selected-border-color dropview-above-selected-border-width Aristo and Aristo2 have been updated, and use the same old hardcoded values. --- AppKit/CPTableView.j | 70 +++++++++++++++--------- AppKit/Themes/Aristo/ThemeDescriptors.j | 35 +++++++++--- AppKit/Themes/Aristo2/ThemeDescriptors.j | 34 +++++++++--- 3 files changed, 96 insertions(+), 43 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index f19e4d259..74c8ced3d 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -299,6 +299,18 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; @"selection-radius": [CPNull null], @"image-generic-file": [CPNull null], @"default-row-height": 25.0, + @"dropview-on-background-color": [CPNull null], + @"dropview-on-border-color": [CPNull null], + @"dropview-on-border-width": [CPNull null], + @"dropview-on-border-radius": [CPNull null], + @"dropview-on-selected-background-color": [CPNull null], + @"dropview-on-selected-border-color": [CPNull null], + @"dropview-on-selected-border-width": [CPNull null], + @"dropview-on-selected-border-radius": [CPNull null], + @"dropview-above-border-color": [CPNull null], + @"dropview-above-border-width": [CPNull null], + @"dropview-above-selected-border-color": [CPNull null], + @"dropview-above-selected-border-width": [CPNull null] }; } @@ -5975,13 +5987,19 @@ var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey", if (tableView._destinationDragStyle === CPTableViewDraggingDestinationFeedbackStyleNone || isBlinking) return; - var context = [[CPGraphicsContext currentContext] graphicsPort]; - - CGContextSetStrokeColor(context, [CPColor colorWithHexString:@"4886ca"]); - CGContextSetLineWidth(context, 3); + var context = [[CPGraphicsContext currentContext] graphicsPort], + borderRadius, + borderColor, + borderWidth, + backgroundColor; if (currentRow === -1) { + borderColor = [tableView valueForThemeAttribute:@"dropview-on-border-color"]; + borderWidth = [tableView valueForThemeAttribute:@"dropview-on-border-width"]; + + CGContextSetStrokeColor(context, borderColor); + CGContextSetLineWidth(context, borderWidth); CGContextStrokeRect(context, [self bounds]); } @@ -5993,16 +6011,23 @@ var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey", if ([selectedRows containsIndex:currentRow]) { - CGContextSetLineWidth(context, 2); - CGContextSetStrokeColor(context, [CPColor whiteColor]); + borderRadius = [tableView valueForThemeAttribute:@"dropview-on-selected-border-radius"]; + borderColor = [tableView valueForThemeAttribute:@"dropview-on-selected-border-color"]; + borderWidth = [tableView valueForThemeAttribute:@"dropview-on-selected-border-width"]; + backgroundColor = [tableView valueForThemeAttribute:@"dropview-on-selected-background-color"]; } else { - CGContextSetFillColor(context, [CPColor colorWithRed:72 / 255 green:134 / 255 blue:202 / 255 alpha:0.25]); - CGContextFillRoundedRectangleInRect(context, newRect, 8, YES, YES, YES, YES); + borderRadius = [tableView valueForThemeAttribute:@"dropview-on-border-radius"]; + borderColor = [tableView valueForThemeAttribute:@"dropview-on-border-color"]; + borderWidth = [tableView valueForThemeAttribute:@"dropview-on-border-width"]; + backgroundColor = [tableView valueForThemeAttribute:@"dropview-on-background-color"]; } - CGContextStrokeRoundedRectangleInRect(context, newRect, 8, YES, YES, YES, YES); + CGContextSetStrokeColor(context, borderColor); + CGContextSetLineWidth(context, borderWidth); + CGContextSetFillColor(context, backgroundColor); + CGContextStrokeRoundedRectangleInRect(context, newRect, borderRadius, YES, YES, YES, YES); } else if (dropOperation === CPTableViewDropAbove) @@ -6014,28 +6039,23 @@ var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey", if ([selectedRows containsIndex:currentRow - 1] || [selectedRows containsIndex:currentRow]) { - CGContextSetStrokeColor(context, [CPColor whiteColor]); - CGContextSetLineWidth(context, 4); - //draw the circle thing - CGContextStrokeEllipseInRect(context, CGRectMake(aRect.origin.x + 4, aRect.origin.y + 4, 8, 8)); - //then draw the line - CGContextBeginPath(context); - CGContextMoveToPoint(context, 10, aRect.origin.y + 8); - CGContextAddLineToPoint(context, aRect.size.width - aRect.origin.y - 8, aRect.origin.y + 8); - CGContextStrokePath(context); - - CGContextSetStrokeColor(context, [CPColor colorWithHexString:@"4886ca"]); - CGContextSetLineWidth(context, 3); + borderColor = [tableView valueForThemeAttribute:@"dropview-above-selected-border-color"]; + borderWidth = [tableView valueForThemeAttribute:@"dropview-above-selected-border-width"]; + } + else + { + borderColor = [tableView valueForThemeAttribute:@"dropview-above-border-color"]; + borderWidth = [tableView valueForThemeAttribute:@"dropview-above-border-width"]; } - //draw the circle thing - CGContextStrokeEllipseInRect(context, CGRectMake(aRect.origin.x + 4, aRect.origin.y + 4, 8, 8)); - //then draw the line + CGContextSetStrokeColor(context, borderColor); + CGContextSetLineWidth(context, borderWidth); + CGContextStrokeEllipseInRect(context, CGRectMake(aRect.origin.x + 4, aRect.origin.y + 4, 8, 8)); // circle + CGContextBeginPath(context); CGContextMoveToPoint(context, 10, aRect.origin.y + 8); CGContextAddLineToPoint(context, aRect.size.width - aRect.origin.y - 8, aRect.origin.y + 8); CGContextStrokePath(context); - //CGContextStrokeLineSegments(context, [aRect.origin.x + 8, aRect.origin.y + 8, 300 , aRect.origin.y + 8]); } } diff --git a/AppKit/Themes/Aristo/ThemeDescriptors.j b/AppKit/Themes/Aristo/ThemeDescriptors.j index b35286a16..c37ed8181 100755 --- a/AppKit/Themes/Aristo/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo/ThemeDescriptors.j @@ -2082,15 +2082,32 @@ var themedButtonValues = nil, themedTableViewValues = [ - [@"alternating-row-colors", alternatingRowColors], - [@"grid-color", gridColor], - [@"highlighted-grid-color", [CPColor whiteColor]], - [@"selection-color", selectionColor], - [@"sourcelist-selection-color", sourceListSelectionColor], - [@"sort-image", sortImage], - [@"sort-image-reversed", sortImageReversed], - [@"image-generic-file", imageGenericFile], - [@"default-row-height", 23.0], + [@"alternating-row-colors", alternatingRowColors], + [@"grid-color", gridColor], + [@"highlighted-grid-color", [CPColor whiteColor]], + [@"selection-color", selectionColor], + [@"sourcelist-selection-color", sourceListSelectionColor], + [@"sort-image", sortImage], + [@"sort-image-reversed", sortImageReversed], + [@"image-generic-file", imageGenericFile], + [@"default-row-height", 23.0], + + [@"dropview-on-background-color", [CPColor colorWithRed:72 / 255 green:134 / 255 blue:202 / 255 alpha:0.25]], + [@"dropview-on-border-color", [CPColor colorWithHexString:@"4886ca"]], + [@"dropview-on-border-width", 3.0], + [@"dropview-on-border-radius", 8.0], + + [@"dropview-on-selected-background-color", [CPColor clearColor]], + [@"dropview-on-selected-border-color", [CPColor whiteColor]], + [@"dropview-on-selected-border-width", 2.0], + [@"dropview-on-selected-border-radius", 8.0], + + [@"dropview-above-border-color", [CPColor colorWithHexString:@"4886ca"]], + [@"dropview-above-border-width", 3.0], + + [@"dropview-above-selected-border-color", [CPColor colorWithHexString:@"8BB6F0"]], + [@"dropview-above-selected-border-width", 2.0], + ]; [self registerThemeValues:themedTableViewValues forView:tableview]; diff --git a/AppKit/Themes/Aristo2/ThemeDescriptors.j b/AppKit/Themes/Aristo2/ThemeDescriptors.j index 1dcd57c6f..4b4bbf13b 100644 --- a/AppKit/Themes/Aristo2/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo2/ThemeDescriptors.j @@ -1557,15 +1557,31 @@ var themedButtonValues = nil, themedTableViewValues = [ - [@"alternating-row-colors", alternatingRowColors], - [@"grid-color", gridColor], - [@"highlighted-grid-color", [CPColor whiteColor]], - [@"selection-color", selectionColor], - [@"sourcelist-selection-color", sourceListSelectionColor], - [@"sort-image", sortImage], - [@"sort-image-reversed", sortImageReversed], - [@"image-generic-file", imageGenericFile], - [@"default-row-height", 25.0] + [@"alternating-row-colors", alternatingRowColors], + [@"grid-color", gridColor], + [@"highlighted-grid-color", [CPColor whiteColor]], + [@"selection-color", selectionColor], + [@"sourcelist-selection-color", sourceListSelectionColor], + [@"sort-image", sortImage], + [@"sort-image-reversed", sortImageReversed], + [@"image-generic-file", imageGenericFile], + [@"default-row-height", 25.0], + + [@"dropview-on-background-color", [CPColor colorWithRed:72 / 255 green:134 / 255 blue:202 / 255 alpha:0.25]], + [@"dropview-on-border-color", [CPColor colorWithHexString:@"4886ca"]], + [@"dropview-on-border-width", 3.0], + [@"dropview-on-border-radius", 8.0], + + [@"dropview-on-selected-background-color", [CPColor clearColor]], + [@"dropview-on-selected-border-color", [CPColor whiteColor]], + [@"dropview-on-selected-border-width", 2.0], + [@"dropview-on-selected-border-radius", 8.0], + + [@"dropview-above-border-color", [CPColor colorWithHexString:@"4886ca"]], + [@"dropview-above-border-width", 3.0], + + [@"dropview-above-selected-border-color", [CPColor colorWithHexString:@"8BB6F0"]], + [@"dropview-above-selected-border-width", 2.0], ]; [tableview setUsesAlternatingRowBackgroundColors:YES];