From 811968716c6a3c2aaaa764d216dfd17866bee80a Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 2 Apr 2020 13:50:58 +0100 Subject: [PATCH] Add OSX layout hack to PAGED_DIALOG for preferences. --- common/widgets/paged_dialog.cpp | 32 +++++++++++++++++++++++++++++++- include/widgets/paged_dialog.h | 3 +++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/common/widgets/paged_dialog.cpp b/common/widgets/paged_dialog.cpp index 3b3c0e15c1..2a07264eb0 100644 --- a/common/widgets/paged_dialog.cpp +++ b/common/widgets/paged_dialog.cpp @@ -78,6 +78,8 @@ PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, if( m_auxiliaryButton ) m_auxiliaryButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PAGED_DIALOG::OnAuxiliaryAction ), nullptr, this ); + + m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED, wxBookCtrlEventHandler( PAGED_DIALOG::OnPageChange ), NULL, this ); Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( PAGED_DIALOG::OnUpdateUI ), nullptr, this ); } @@ -98,7 +100,10 @@ void PAGED_DIALOG::finishInitialization() m_treebook->Fit(); m_treebook->Layout(); - FinishDialogSettings(); + for( int i = 0; i < m_treebook->GetPageCount(); ++i ) + m_macHack.push_back( true ); + + FinishDialogSettings(); } @@ -133,6 +138,9 @@ PAGED_DIALOG::~PAGED_DIALOG() if( m_auxiliaryButton ) m_auxiliaryButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PAGED_DIALOG::OnAuxiliaryAction ), nullptr, this ); + + m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED, wxBookCtrlEventHandler( PAGED_DIALOG::OnPageChange ), NULL, this ); + Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( PAGED_DIALOG::OnUpdateUI ), nullptr, this ); } @@ -266,3 +274,25 @@ void PAGED_DIALOG::OnUpdateUI( wxUpdateUIEvent& event ) } } } + + +void PAGED_DIALOG::OnPageChange( wxBookCtrlEvent& event ) +{ +#ifdef __WXMAC__ + // Work around an OSX bug where the wxGrid children don't get placed correctly until + // the first resize event + int page = event.GetSelection(); + + if( page + 1 <= m_macHack.size() && m_macHack[ page ] ) + { + wxSize pageSize = m_treebook->GetPage( page )->GetSize(); + pageSize.x -= 3; + pageSize.y += 2; + + m_treebook->GetPage( page )->SetSize( pageSize ); + m_macHack[ page ] = false; + } +#endif +} + + diff --git a/include/widgets/paged_dialog.h b/include/widgets/paged_dialog.h index 516590eac5..25cc94ac6a 100644 --- a/include/widgets/paged_dialog.h +++ b/include/widgets/paged_dialog.h @@ -35,6 +35,8 @@ private: int m_errorRow; // the row if m_errorCtrl is a grid int m_errorCol; // the column if m_errorCtrl is a grid + std::vector m_macHack; + public: PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, const wxString& aAuxiliaryAction = wxEmptyString ); @@ -55,6 +57,7 @@ protected: virtual void OnAuxiliaryAction( wxCommandEvent& event ) { event.Skip(); } void OnUpdateUI( wxUpdateUIEvent& event ); + void OnPageChange( wxBookCtrlEvent& event ); wxTreebook* m_treebook; wxButton* m_auxiliaryButton;