@@ -71,57 +71,23 @@ public override void MouseDown(NSEvent theEvent)
71
71
}
72
72
}
73
73
74
- class EtoTableHeaderViewWithBackground : EtoTableHeaderView
74
+ class EtoBackgroundView : NSView
75
75
{
76
+ [ Export ( "backgroundColor" ) ]
76
77
public NSColor BackgroundColor { get ; set ; }
78
+
79
+ public EtoBackgroundView ( )
80
+ {
81
+ }
82
+
83
+ public EtoBackgroundView ( NativeHandle handle ) : base ( handle )
84
+ {
85
+ }
77
86
78
87
public override void DrawRect ( CGRect dirtyRect )
79
88
{
80
- if ( BackgroundColor == null )
81
- {
82
- base . DrawRect ( dirtyRect ) ;
83
- return ;
84
- }
85
-
86
- // gotta draw header cells manually to get a custom background color without tinting...
87
- var bounds = Bounds ;
88
89
BackgroundColor . SetFill ( ) ;
89
- NSBezierPath . FillRect ( bounds ) ;
90
-
91
- NSBezierPath path ;
92
- nfloat ? position = null ;
93
- var dividerSize = ConvertSizeToBacking ( new CGSize ( 1 , 1 ) ) ;
94
- var spacing = TableView . IntercellSpacing . Width ;
95
- var columns = TableView . TableColumns ( ) ;
96
- for ( int i = 0 ; i < columns . Length ; i ++ )
97
- {
98
- var cellFrame = GetHeaderRect ( i ) ;
99
- var col = columns [ i ] ;
100
- var cell = col . HeaderCell ;
101
- if ( col . Hidden || cell == null )
102
- continue ;
103
- cell . DrawWithFrame ( cellFrame , this ) ;
104
- if ( position == null )
105
- {
106
- // draw separator up to first column
107
- NSColor . Separator . Set ( ) ;
108
- path = new NSBezierPath ( ) ;
109
- path . MoveTo ( new CGPoint ( bounds . X , bounds . Bottom ) ) ;
110
- path . LineTo ( new CGPoint ( cellFrame . X , bounds . Bottom ) ) ;
111
- path . LineWidth = dividerSize . Height ;
112
- path . Stroke ( ) ;
113
- path . Dispose ( ) ;
114
- }
115
- position = cellFrame . Right ;
116
- }
117
- // draw separator from last column
118
- NSColor . Separator . Set ( ) ;
119
- path = new NSBezierPath ( ) ;
120
- path . MoveTo ( new CGPoint ( position ?? bounds . X , bounds . Bottom ) ) ;
121
- path . LineTo ( new CGPoint ( bounds . Right , bounds . Bottom ) ) ;
122
- path . LineWidth = dividerSize . Height ;
123
- path . Stroke ( ) ;
124
- path . Dispose ( ) ;
90
+ NSBezierPath . FillRect ( Bounds ) ;
125
91
}
126
92
}
127
93
@@ -530,10 +496,7 @@ public bool ShowHeader
530
496
{
531
497
if ( value && Control . HeaderView == null )
532
498
{
533
- if ( HasBackgroundColor && ! UseNSBoxBackgroundColor )
534
- headerView = new EtoTableHeaderViewWithBackground { Handler = this , BackgroundColor = BackgroundColor . ToNSUI ( ) , Menu = ContextMenu . ToNS ( ) } ;
535
- else
536
- headerView = new EtoTableHeaderView { Handler = this , Menu = ContextMenu . ToNS ( ) } ;
499
+ headerView = new EtoTableHeaderView { Handler = this , Menu = ContextMenu . ToNS ( ) } ;
537
500
Control . HeaderView = headerView ;
538
501
}
539
502
else if ( ! value && Control . HeaderView != null )
@@ -975,17 +938,27 @@ protected override void SetBackgroundColor(Color? color)
975
938
Control . BackgroundColor = bg ;
976
939
if ( ! UseNSBoxBackgroundColor )
977
940
{
978
- var currentHeader = Control . HeaderView ;
979
- if ( currentHeader is EtoTableHeaderViewWithBackground backgroundHeaderView )
980
- {
981
- backgroundHeaderView . BackgroundColor = bg ;
982
- backgroundHeaderView . SetNeedsDisplay ( ) ;
983
- }
984
- else if ( currentHeader != null )
941
+ var clip = ScrollView . Subviews . OfType < NSClipView > ( ) . FirstOrDefault ( r => r . DocumentView == headerView ) ;
942
+ var banner = clip ? . Subviews . FirstOrDefault ( r => r . Class . Name == "NSBannerView" ) ;
943
+ var effectView = banner ? . Subviews . OfType < NSVisualEffectView > ( ) . FirstOrDefault ( ) ;
944
+ if ( effectView == null || banner == null )
945
+ return ;
946
+
947
+ // inject a view above the effectView with our desired background color
948
+ var backgroundView = banner . Subviews . OfType < EtoBackgroundView > ( ) . FirstOrDefault ( ) ;
949
+ if ( backgroundView == null )
985
950
{
986
- headerView = new EtoTableHeaderViewWithBackground { Handler = this , BackgroundColor = bg , Menu = ContextMenu . ToNS ( ) } ;
987
- Control . HeaderView = headerView ;
951
+ backgroundView = new EtoBackgroundView
952
+ {
953
+ Frame = banner . Bounds ,
954
+ AutoresizingMask = NSViewResizingMask . WidthSizable | NSViewResizingMask . HeightSizable ,
955
+ TranslatesAutoresizingMaskIntoConstraints = true
956
+ } ;
957
+ banner . AddSubview ( backgroundView , NSWindowOrderingMode . Above , effectView ) ;
988
958
}
959
+
960
+ backgroundView . BackgroundColor = bg ;
961
+ backgroundView . SetNeedsDisplay ( ) ;
989
962
}
990
963
}
991
964
0 commit comments