From 6f4e4e75ee12649bff509fa26108faa28373c1af Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Thu, 16 Nov 2023 15:34:06 -0800 Subject: [PATCH] Mac: Fix Tree/GridView header tooltips when setting the background color --- lib/monomac | 2 +- src/Eto.Mac/Forms/Controls/GridHandler.cs | 89 ++++++++--------------- 2 files changed, 32 insertions(+), 59 deletions(-) diff --git a/lib/monomac b/lib/monomac index b3a93a8d6..86f4bad5f 160000 --- a/lib/monomac +++ b/lib/monomac @@ -1 +1 @@ -Subproject commit b3a93a8d6a9fb9ffcccd44345300b40c9ae96d85 +Subproject commit 86f4bad5f285cb5a601e7aa6b3b897d2e96f9b64 diff --git a/src/Eto.Mac/Forms/Controls/GridHandler.cs b/src/Eto.Mac/Forms/Controls/GridHandler.cs index f1311678f..87294d36f 100644 --- a/src/Eto.Mac/Forms/Controls/GridHandler.cs +++ b/src/Eto.Mac/Forms/Controls/GridHandler.cs @@ -71,57 +71,23 @@ public override void MouseDown(NSEvent theEvent) } } - class EtoTableHeaderViewWithBackground : EtoTableHeaderView + class EtoBackgroundView : NSView { + [Export("backgroundColor")] public NSColor BackgroundColor { get; set; } + + public EtoBackgroundView() + { + } + + public EtoBackgroundView(NativeHandle handle) : base(handle) + { + } public override void DrawRect(CGRect dirtyRect) { - if (BackgroundColor == null) - { - base.DrawRect(dirtyRect); - return; - } - - // gotta draw header cells manually to get a custom background color without tinting... - var bounds = Bounds; BackgroundColor.SetFill(); - NSBezierPath.FillRect(bounds); - - NSBezierPath path; - nfloat? position = null; - var dividerSize = ConvertSizeToBacking(new CGSize(1, 1)); - var spacing = TableView.IntercellSpacing.Width; - var columns = TableView.TableColumns(); - for (int i = 0; i < columns.Length; i++) - { - var cellFrame = GetHeaderRect(i); - var col = columns[i]; - var cell = col.HeaderCell; - if (col.Hidden || cell == null) - continue; - cell.DrawWithFrame(cellFrame, this); - if (position == null) - { - // draw separator up to first column - NSColor.Separator.Set(); - path = new NSBezierPath(); - path.MoveTo(new CGPoint(bounds.X, bounds.Bottom)); - path.LineTo(new CGPoint(cellFrame.X, bounds.Bottom)); - path.LineWidth = dividerSize.Height; - path.Stroke(); - path.Dispose(); - } - position = cellFrame.Right; - } - // draw separator from last column - NSColor.Separator.Set(); - path = new NSBezierPath(); - path.MoveTo(new CGPoint(position ?? bounds.X, bounds.Bottom)); - path.LineTo(new CGPoint(bounds.Right, bounds.Bottom)); - path.LineWidth = dividerSize.Height; - path.Stroke(); - path.Dispose(); + NSBezierPath.FillRect(Bounds); } } @@ -530,10 +496,7 @@ public bool ShowHeader { if (value && Control.HeaderView == null) { - if (HasBackgroundColor && !UseNSBoxBackgroundColor) - headerView = new EtoTableHeaderViewWithBackground { Handler = this, BackgroundColor = BackgroundColor.ToNSUI(), Menu = ContextMenu.ToNS() }; - else - headerView = new EtoTableHeaderView { Handler = this, Menu = ContextMenu.ToNS() }; + headerView = new EtoTableHeaderView { Handler = this, Menu = ContextMenu.ToNS() }; Control.HeaderView = headerView; } else if (!value && Control.HeaderView != null) @@ -975,17 +938,27 @@ protected override void SetBackgroundColor(Color? color) Control.BackgroundColor = bg; if (!UseNSBoxBackgroundColor) { - var currentHeader = Control.HeaderView; - if (currentHeader is EtoTableHeaderViewWithBackground backgroundHeaderView) - { - backgroundHeaderView.BackgroundColor = bg; - backgroundHeaderView.SetNeedsDisplay(); - } - else if (currentHeader != null) + var clip = ScrollView.Subviews.OfType().FirstOrDefault(r => r.DocumentView == headerView); + var banner = clip?.Subviews.FirstOrDefault(r => r.Class.Name == "NSBannerView"); + var effectView = banner?.Subviews.OfType().FirstOrDefault(); + if (effectView == null || banner == null) + return; + + // inject a view above the effectView with our desired background color + var backgroundView = banner.Subviews.OfType().FirstOrDefault(); + if (backgroundView == null) { - headerView = new EtoTableHeaderViewWithBackground { Handler = this, BackgroundColor = bg, Menu = ContextMenu.ToNS() }; - Control.HeaderView = headerView; + backgroundView = new EtoBackgroundView + { + Frame = banner.Bounds, + AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable, + TranslatesAutoresizingMaskIntoConstraints = true + }; + banner.AddSubview(backgroundView, NSWindowOrderingMode.Above, effectView); } + + backgroundView.BackgroundColor = bg; + backgroundView.SetNeedsDisplay(); } }