From 4302c6b8ba32882141b7fca79db6201c67589f45 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Tue, 17 Sep 2019 01:04:29 +0700 Subject: [PATCH] Fix showing the popup menu in wxHeaderCtrl under Mac wxOSX asserts if a menu item with id of 0 is created, so use 1-based IDs to avoid this. Using an explicit constant for the base instead of using 0 implicitly also arguably makes the code more clear. Closes https://github.com/wxWidgets/wxWidgets/pull/1555 --- src/common/headerctrlcmn.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/common/headerctrlcmn.cpp b/src/common/headerctrlcmn.cpp index 2f5eeff7a7..7ef5adc6f0 100644 --- a/src/common/headerctrlcmn.cpp +++ b/src/common/headerctrlcmn.cpp @@ -40,6 +40,7 @@ namespace // ---------------------------------------------------------------------------- const unsigned int wxNO_COLUMN = static_cast(-1); +const unsigned int wxID_COLUMNS_BASE = 1; // ---------------------------------------------------------------------------- // wxHeaderColumnsRearrangeDialog: dialog for customizing our columns @@ -284,7 +285,7 @@ void wxHeaderCtrlBase::AddColumnsItems(wxMenu& menu, int idColumnsBase) const wxHeaderColumn& col = GetColumn(n); menu.AppendCheckItem(idColumnsBase + n, col.GetTitle()); if ( col.IsShown() ) - menu.Check(n, true); + menu.Check(idColumnsBase + n, true); } } @@ -295,15 +296,15 @@ bool wxHeaderCtrlBase::ShowColumnsMenu(const wxPoint& pt, const wxString& title) if ( !title.empty() ) menu.SetTitle(title); - AddColumnsItems(menu); + AddColumnsItems(menu, wxID_COLUMNS_BASE); // ... and an extra one to show the customization dialog if the user is // allowed to reorder the columns too - const unsigned count = GetColumnCount(); + const unsigned idCustomize = GetColumnCount() + wxID_COLUMNS_BASE; if ( HasFlag(wxHD_ALLOW_REORDER) ) { menu.AppendSeparator(); - menu.Append(count, _("&Customize...")); + menu.Append(idCustomize, _("&Customize...")); } // do show the menu and get the user selection @@ -311,13 +312,14 @@ bool wxHeaderCtrlBase::ShowColumnsMenu(const wxPoint& pt, const wxString& title) if ( rc == wxID_NONE ) return false; - if ( static_cast(rc) == count ) + if ( static_cast(rc) == idCustomize ) { return ShowCustomizeDialog(); } else // a column selected from the menu { - UpdateColumnVisibility(rc, !GetColumn(rc).IsShown()); + const int columnIndex = rc - wxID_COLUMNS_BASE; + UpdateColumnVisibility(columnIndex, !GetColumn(columnIndex).IsShown()); } return true;