mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-28 01:12:03 +00:00
AppKit: Stop theme state overriding table background; set source-list background
- Remove CPTableView theme-state overrides of background colour - Take default background from theme background-color in current state, else controlBackgroundColor - Apply default background in layout; treat nil colour as default background - Archive only table view's own background colour through CPView -_archivedBackgroundColor - Set _sourceListBackgroundColor with source-list highlight style, as in AppKit - Give Aristo3 table view background A3CPColorTableRow in place of white - Add tests for own, theme, default, source-list and decoded backgrounds
This commit is contained in:
1 parent
cf035ac182
commit
b4070c19e0
4 files changed
+277
-9
No files matched your search
+59
-6
@@ -357,6 +357,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
|
||||
|
||||
BOOL _usesAlternatingRowBackgroundColors;
|
||||
CPArray _alternatingRowBackgroundColors;
|
||||
BOOL _usesDefaultBackgroundColor;
|
||||
|
||||
unsigned _selectionHighlightStyle;
|
||||
CPColor _unfocusedSelectionHighlightColor;
|
||||
@@ -487,6 +488,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
|
||||
|
||||
//Setting Display Attributes
|
||||
_selectionHighlightStyle = CPTableViewSelectionHighlightStyleRegular;
|
||||
[self setBackgroundColor:nil];
|
||||
|
||||
[self setUsesAlternatingRowBackgroundColors:NO];
|
||||
[self setAlternatingRowBackgroundColors:[self valueForThemeAttribute:@"alternating-row-colors"]];
|
||||
@@ -586,16 +588,56 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
|
||||
[self _initSubclass];
|
||||
}
|
||||
|
||||
- (void)setThemeState:(CPThemeState)aState
|
||||
/*!
|
||||
Sets the background colour of the table view. A \c nil colour gives the default
|
||||
background: the theme's background colour in the table view's current state, else
|
||||
\c +[CPColor controlBackgroundColor], as in AppKit. For a transparent table view, set
|
||||
\c +[CPColor clearColor].
|
||||
@param aColor the background colour, or \c nil for the default background
|
||||
*/
|
||||
- (void)setBackgroundColor:(CPColor)aColor
|
||||
{
|
||||
[super setThemeState:aState];
|
||||
[self setBackgroundColor:[self hasThemeState:CPThemeStateHUD] ? [CPColor clearColor] : [CPColor whiteColor]];
|
||||
if (aColor === [CPNull null])
|
||||
aColor = nil;
|
||||
|
||||
_usesDefaultBackgroundColor = !aColor;
|
||||
|
||||
[super setBackgroundColor:aColor || [self _defaultBackgroundColor]];
|
||||
}
|
||||
|
||||
- (void)unsetThemeState:(CPThemeState)aState
|
||||
/*
|
||||
Returns the default background: the theme's background colour in the receiver's current
|
||||
state, else the control background colour, AppKit's default.
|
||||
*/
|
||||
- (CPColor)_defaultBackgroundColor
|
||||
{
|
||||
[super unsetThemeState:aState];
|
||||
[self setBackgroundColor:[self hasThemeState:CPThemeStateHUD] ? [CPColor clearColor] : [CPColor whiteColor]];
|
||||
return [self currentValueForThemeAttribute:@"background-color"] || [CPColor controlBackgroundColor];
|
||||
}
|
||||
|
||||
/*
|
||||
Applies the default background again when the receiver has no background colour of its
|
||||
own.
|
||||
|
||||
The table view set a white background, or a clear one in the HUD state, at each change of
|
||||
theme state, over the colour that the application had set. A change of appearance, key
|
||||
window or first responder is a change of theme state, so no colour of the application,
|
||||
the theme or AppKit could show. A change of theme state now marks the table view for
|
||||
layout, as for every view, and the layout applies the default only to a table view
|
||||
without a colour of its own.
|
||||
*/
|
||||
- (void)_updateDefaultBackgroundColor
|
||||
{
|
||||
if (_usesDefaultBackgroundColor)
|
||||
[super setBackgroundColor:[self _defaultBackgroundColor]];
|
||||
}
|
||||
|
||||
/*
|
||||
The receiver archives only a background colour of its own, so that a decoded copy takes
|
||||
the default background from its theme again.
|
||||
*/
|
||||
- (CPColor)_archivedBackgroundColor
|
||||
{
|
||||
return _usesDefaultBackgroundColor ? nil : [super _archivedBackgroundColor];
|
||||
}
|
||||
|
||||
- (void)_initSubclass
|
||||
@@ -1080,6 +1122,8 @@ NOT YET IMPLEMENTED
|
||||
/*!
|
||||
Sets the selection highlight style to an enumerated value.
|
||||
This value can also affect the way the tableview draws feedback when the user is dragging.
|
||||
As in AppKit, the source-list style also sets the background colour to the source-list
|
||||
background colour. A background colour set after the style replaces it.
|
||||
|
||||
Valid values are:
|
||||
<pre>
|
||||
@@ -1092,8 +1136,16 @@ NOT YET IMPLEMENTED
|
||||
{
|
||||
_selectionHighlightStyle = aSelectionHighlightStyle;
|
||||
|
||||
/*
|
||||
The source-list style changed only the dragging feedback style. The table view kept
|
||||
its background, so a source list had the background of a plain table, and the
|
||||
System catalog's source-list background colour had no reader.
|
||||
*/
|
||||
if (aSelectionHighlightStyle === CPTableViewSelectionHighlightStyleSourceList)
|
||||
{
|
||||
_destinationDragStyle = CPTableViewDraggingDestinationFeedbackStyleSourceList;
|
||||
[self setBackgroundColor:[CPColor colorWithCatalogName:@"System" colorName:@"_sourceListBackgroundColor"]];
|
||||
}
|
||||
else
|
||||
_destinationDragStyle = CPTableViewDraggingDestinationFeedbackStyleRegular;
|
||||
|
||||
@@ -4512,6 +4564,7 @@ Your delegate can implement this method to avoid subclassing the tableview to ad
|
||||
*/
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[self _updateDefaultBackgroundColor];
|
||||
[self load];
|
||||
}
|
||||
|
||||
|
||||
+14
-2
@@ -4280,8 +4280,10 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
|
||||
if (!_autoresizesSubviews)
|
||||
[aCoder encodeBool:_autoresizesSubviews forKey:CPViewAutoresizesSubviewsKey];
|
||||
|
||||
if (_backgroundColor != nil)
|
||||
[aCoder encodeObject:_backgroundColor forKey:CPViewBackgroundColorKey];
|
||||
var archivedBackgroundColor = [self _archivedBackgroundColor];
|
||||
|
||||
if (archivedBackgroundColor != nil)
|
||||
[aCoder encodeObject:archivedBackgroundColor forKey:CPViewBackgroundColorKey];
|
||||
|
||||
if (_hitTests !== YES)
|
||||
[aCoder encodeBool:_hitTests forKey:CPViewHitTestsKey];
|
||||
@@ -4320,6 +4322,16 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
|
||||
[aCoder encodeObject:_trackingAreas forKey:CPViewTrackingAreasKey];
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the background colour that the receiver archives: its background colour. A
|
||||
subclass that gives a default background when it has no colour of its own returns nil
|
||||
for the default, so that a decoded copy takes the default again.
|
||||
*/
|
||||
- (CPColor)_archivedBackgroundColor
|
||||
{
|
||||
return _backgroundColor;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
var _CPViewFullScreenModeStateMake = function(aView)
|
||||
|
||||
@@ -7312,7 +7312,13 @@ function A3MaskIcon(aMaskImage, aColor)
|
||||
[@"image-generic-file", imageGenericFile],
|
||||
[@"default-row-height", 17.0],
|
||||
[@"header-view-height", 22],
|
||||
[@"background-color", [CPColor whiteColor]],
|
||||
|
||||
/*
|
||||
The default background of a table view without a colour of its own. The value was
|
||||
white, which does not follow the appearance, and no code read it. It is now the
|
||||
table row colour, the control background colour.
|
||||
*/
|
||||
[@"background-color", A3CPColorTableRow],
|
||||
|
||||
// HUD Images mapping
|
||||
[@"sort-image", sortImageHUD, CPThemeStateHUD],
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* CPTableViewBackgroundTest.j
|
||||
* AppKit
|
||||
*
|
||||
* Created by David Richardson on 2026-11-12.
|
||||
* Copyright David Richardson 2026.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import <AppKit/AppKit.j>
|
||||
|
||||
/*
|
||||
A table view's background is the application's colour when it has one. Without one, it
|
||||
is the theme's background colour in the table view's current state, else the control
|
||||
background colour, AppKit's default. The source-list style sets the source-list
|
||||
background, as in AppKit.
|
||||
*/
|
||||
@implementation CPTableViewBackgroundTest : OJTestCase
|
||||
{
|
||||
CPWindow theWindow;
|
||||
CPTableView tableView;
|
||||
}
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
// This will init the global var CPApp which are used internally in the AppKit
|
||||
[[CPApplication alloc] init];
|
||||
|
||||
theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 400.0, 400.0) styleMask:CPWindowNotSizable];
|
||||
tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 200.0)];
|
||||
|
||||
[tableView addTableColumn:[[CPTableColumn alloc] initWithIdentifier:@"Column"]];
|
||||
[[theWindow contentView] addSubview:tableView];
|
||||
}
|
||||
|
||||
/*
|
||||
Returns a theme that gives a table view aColor as its background colour, and aHUDColor
|
||||
in the HUD state. A nil colour gives no value.
|
||||
*/
|
||||
- (CPTheme)themeWithBackgroundColor:(CPColor)aColor HUDBackgroundColor:(CPColor)aHUDColor
|
||||
{
|
||||
var template = [[CPTableView alloc] initWithFrame:CGRectMakeZero()],
|
||||
theme = [[CPTheme alloc] initWithName:@"CPTableViewBackgroundTestTheme"];
|
||||
|
||||
if (aColor)
|
||||
[template setValue:aColor forThemeAttribute:@"background-color"];
|
||||
|
||||
if (aHUDColor)
|
||||
[template setValue:aHUDColor forThemeAttribute:@"background-color" inState:CPThemeStateHUD];
|
||||
|
||||
[theme takeThemeFromObject:template];
|
||||
|
||||
return theme;
|
||||
}
|
||||
|
||||
/*
|
||||
Gives aTableView aTheme and lays it out, as the display cycle does after a change of
|
||||
theme.
|
||||
*/
|
||||
- (void)setTheme:(CPTheme)aTheme ofTableView:(CPTableView)aTableView
|
||||
{
|
||||
[aTableView setTheme:aTheme];
|
||||
[aTableView layoutIfNeeded];
|
||||
}
|
||||
|
||||
- (void)testWithoutAColourOfItsOwnATableViewTakesTheThemeBackground
|
||||
{
|
||||
var red = [CPColor redColor];
|
||||
|
||||
[self setTheme:[self themeWithBackgroundColor:red HUDBackgroundColor:nil] ofTableView:tableView];
|
||||
|
||||
[self assert:red same:[tableView backgroundColor]];
|
||||
}
|
||||
|
||||
- (void)testWithoutAThemeBackgroundATableViewTakesTheControlBackgroundColor
|
||||
{
|
||||
[self setTheme:[self themeWithBackgroundColor:nil HUDBackgroundColor:nil] ofTableView:tableView];
|
||||
|
||||
[self assert:[CPColor controlBackgroundColor] same:[tableView backgroundColor]];
|
||||
}
|
||||
|
||||
- (void)testTheThemeBackgroundFollowsTheThemeState
|
||||
{
|
||||
var red = [CPColor redColor],
|
||||
blue = [CPColor blueColor];
|
||||
|
||||
[self setTheme:[self themeWithBackgroundColor:red HUDBackgroundColor:blue] ofTableView:tableView];
|
||||
|
||||
[tableView setThemeState:CPThemeStateHUD];
|
||||
[tableView layoutIfNeeded];
|
||||
[self assert:blue same:[tableView backgroundColor] message:@"HUD state"];
|
||||
|
||||
[tableView unsetThemeState:CPThemeStateHUD];
|
||||
[tableView layoutIfNeeded];
|
||||
[self assert:red same:[tableView backgroundColor] message:@"normal state"];
|
||||
}
|
||||
|
||||
- (void)testAColourOfItsOwnStaysInEachThemeState
|
||||
{
|
||||
var green = [CPColor greenColor];
|
||||
|
||||
[self setTheme:[self themeWithBackgroundColor:[CPColor redColor] HUDBackgroundColor:[CPColor blueColor]] ofTableView:tableView];
|
||||
[tableView setBackgroundColor:green];
|
||||
|
||||
[tableView setThemeState:CPThemeStateHUD];
|
||||
[tableView layoutIfNeeded];
|
||||
[self assert:green same:[tableView backgroundColor] message:@"HUD state"];
|
||||
|
||||
[tableView setThemeState:CPThemeStateKeyWindow];
|
||||
[tableView layoutIfNeeded];
|
||||
[self assert:green same:[tableView backgroundColor] message:@"key window state"];
|
||||
|
||||
[tableView unsetThemeState:CPThemeStateHUD];
|
||||
[tableView unsetThemeState:CPThemeStateKeyWindow];
|
||||
[tableView layoutIfNeeded];
|
||||
[self assert:green same:[tableView backgroundColor] message:@"normal state"];
|
||||
}
|
||||
|
||||
- (void)testANilColourGivesTheDefaultBackgroundAgain
|
||||
{
|
||||
var red = [CPColor redColor],
|
||||
blue = [CPColor blueColor];
|
||||
|
||||
[self setTheme:[self themeWithBackgroundColor:red HUDBackgroundColor:blue] ofTableView:tableView];
|
||||
[tableView setBackgroundColor:[CPColor greenColor]];
|
||||
[tableView setBackgroundColor:nil];
|
||||
|
||||
[self assert:red same:[tableView backgroundColor] message:@"normal state"];
|
||||
|
||||
[tableView setThemeState:CPThemeStateHUD];
|
||||
[tableView layoutIfNeeded];
|
||||
[self assert:blue same:[tableView backgroundColor] message:@"HUD state"];
|
||||
}
|
||||
|
||||
- (void)testTheSourceListStyleSetsTheSourceListBackground
|
||||
{
|
||||
var sourceListColor = [CPColor colorWithCatalogName:@"System" colorName:@"_sourceListBackgroundColor"];
|
||||
|
||||
[self setTheme:[self themeWithBackgroundColor:[CPColor redColor] HUDBackgroundColor:[CPColor blueColor]] ofTableView:tableView];
|
||||
[tableView setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleSourceList];
|
||||
|
||||
[self assert:sourceListColor same:[tableView backgroundColor] message:@"normal state"];
|
||||
|
||||
[tableView setThemeState:CPThemeStateHUD];
|
||||
[tableView layoutIfNeeded];
|
||||
[self assert:sourceListColor same:[tableView backgroundColor] message:@"HUD state"];
|
||||
}
|
||||
|
||||
- (void)testAColourSetAfterTheSourceListStyleReplacesTheSourceListBackground
|
||||
{
|
||||
var green = [CPColor greenColor];
|
||||
|
||||
[tableView setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleSourceList];
|
||||
[tableView setBackgroundColor:green];
|
||||
|
||||
[self assert:green same:[tableView backgroundColor]];
|
||||
}
|
||||
|
||||
- (void)testADecodedTableViewTakesTheDefaultBackgroundFromItsTheme
|
||||
{
|
||||
var yellow = [CPColor yellowColor];
|
||||
|
||||
[self setTheme:[self themeWithBackgroundColor:[CPColor redColor] HUDBackgroundColor:nil] ofTableView:tableView];
|
||||
|
||||
var decoded = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:tableView]];
|
||||
|
||||
[self setTheme:[self themeWithBackgroundColor:yellow HUDBackgroundColor:nil] ofTableView:decoded];
|
||||
|
||||
[self assert:yellow equals:[decoded backgroundColor]];
|
||||
}
|
||||
|
||||
- (void)testADecodedTableViewKeepsItsOwnColour
|
||||
{
|
||||
[self setTheme:[self themeWithBackgroundColor:[CPColor redColor] HUDBackgroundColor:nil] ofTableView:tableView];
|
||||
[tableView setBackgroundColor:[CPColor greenColor]];
|
||||
|
||||
var decoded = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:tableView]];
|
||||
|
||||
[self setTheme:[self themeWithBackgroundColor:[CPColor yellowColor] HUDBackgroundColor:nil] ofTableView:decoded];
|
||||
|
||||
[self assert:[CPColor greenColor] equals:[decoded backgroundColor]];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user