From 847a9c2b987b3c2e6c714bbf926dc49aba2243d8 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sun, 8 Feb 2026 19:30:06 +0100 Subject: [PATCH] new: column-selection --- AppKit/CPTableView.j | 51 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 3b02ec8da..f97428a92 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -424,6 +424,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; BOOL _draggedColumnIsSelected; BOOL _needsDifferedTableColumnRemove; CPArray _differedColumnDataToRemove; + CPArray _selectedColumnBackgroundViews; Function _BlockDeselectView; Function _BlockSelectView; @@ -593,6 +594,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; - (void)_initSubclass { + _selectedColumnBackgroundViews = []; + _BlockDeselectView = function(view, row, column) { [view unsetThemeState:CPThemeStateSelectedDataView]; @@ -612,6 +615,47 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; }; } +- (void)_updateSelectedColumnBackgrounds +{ + // 1. Remove existing column background views + [_selectedColumnBackgroundViews makeObjectsPerformSelector:@selector(removeFromSuperview)]; + [_selectedColumnBackgroundViews removeAllObjects]; + + // 2. If no highlighting style, stop here + if ([self selectionHighlightStyle] === CPTableViewSelectionHighlightStyleNone) + return; + + var color = [self selectionHighlightColor], + bounds = [self bounds]; + + // 3. Create a view for each selected column index + [_selectedColumnIndexes enumerateIndexesUsingBlock:function(idx, stop) + { + var rect = [self rectOfColumn:idx]; + + // Ensure the highlight spans the full height of the table + rect.size.height = MAX(CGRectGetHeight(bounds), [self frame].size.height); + + var view = [[CPView alloc] initWithFrame:rect]; + [view setBackgroundColor:color]; + [view setHitTests:NO]; + + // Add to the table view at the bottom of the stack + [self addSubview:view positioned:CPWindowBelow relativeTo:nil]; + [_selectedColumnBackgroundViews addObject:view]; + }]; + + // 4. Z-Order Correction: + // _CPTableRowViews (alternating row colors) are also added "Below nil". + // To ensure the Column selection appears ON TOP of the row alternating colors, + // we must push the currently visible row views to the very back. + for (var rowIndex in _visibleRowViews) + { + if (_visibleRowViews.hasOwnProperty(rowIndex)) + [self addSubview:_visibleRowViews[rowIndex] positioned:CPWindowBelow relativeTo:nil]; + } +} + /*! @anchor setdatasource Sets the receiver's data source to a given object. @@ -1464,8 +1508,7 @@ NOT YET IMPLEMENTED _selectedColumnIndexes = [columns copy]; [self _updateHighlightWithOldColumns:previousSelectedIndexes newColumns:_selectedColumnIndexes]; - // No more setNeedsDisplay for drawing - // [self setNeedsDisplay:YES]; + [self _updateSelectedColumnBackgrounds]; if (_headerView) [_headerView setNeedsDisplay:YES]; @@ -2651,9 +2694,9 @@ NOT YET IMPLEMENTED [self setFrameSize:CGSizeMake(width, height)]; + [self _updateSelectedColumnBackgrounds]; + [self setNeedsLayout]; - // No more display needed for layout - // [self setNeedsDisplay:YES]; }