Skip to content

Commit

Permalink
Merge pull request #2319 from cwensley/curtis/mac-listbox-dark-to-lig…
Browse files Browse the repository at this point in the history
…ht-switch

Mac: Fix errors with ListBox when switching from light to dark mode
  • Loading branch information
cwensley authored Sep 24, 2022
2 parents e647a6a + 9fc1875 commit 009d2e6
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/Eto.Mac/Forms/Controls/ListBoxHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ public class EtoDataSource : NSTableViewDataSource

public override NSObject GetObjectValue(NSTableView tableView, NSTableColumn tableColumn, nint row)
{
var w = Handler.Widget;
var item = Handler.collection.ElementAt((int)row);
var h = Handler;
if (h == null)
return null;
var w = h.Widget;
var item = h.collection.ElementAt((int)row);
return new MacImageData
{
Text = new NSString(Convert.ToString(w.ItemTextBinding.GetValue(item))),
Expand All @@ -80,7 +83,10 @@ public override NSObject GetObjectValue(NSTableView tableView, NSTableColumn tab

public override nint GetRowCount(NSTableView tableView)
{
return Handler.collection.Collection == null ? 0 : Handler.collection.Collection.Count();
var h = Handler;
if (h == null)
return 0;
return h.collection.Collection == null ? 0 : h.collection.Collection.Count();
}
}

Expand All @@ -97,12 +103,18 @@ public override bool ShouldSelectRow(NSTableView tableView, nint row)

public override void SelectionDidChange(NSNotification notification)
{
Handler.Callback.OnSelectedIndexChanged(Handler.Widget, EventArgs.Empty);
var h = Handler;
if (h == null)
return;
h.Callback.OnSelectedIndexChanged(h.Widget, EventArgs.Empty);
}

public override nfloat GetRowHeight(NSTableView tableView, nint row)
{
return Handler.Control.GetCell(0, row).CellSize.Height;
var h = Handler;
if (h == null)
return tableView.RowHeight;
return h.Control.GetCell(0, row).CellSize.Height;
}
}

Expand All @@ -118,8 +130,9 @@ public ListBoxHandler Handler

public override NSMenu MenuForEvent(NSEvent theEvent)
{
if (Handler.ContextMenu != null)
return Handler.ContextMenu.ControlObject as NSMenu;
var h = Handler;
if (h?.ContextMenu != null)
return h.ContextMenu.ControlObject as NSMenu;
return base.MenuForEvent(theEvent);
}

Expand Down

0 comments on commit 009d2e6

Please sign in to comment.