diff --git a/GM/FrmMain.cpp b/GM/FrmMain.cpp index 5f32a598..ba1d1a19 100644 --- a/GM/FrmMain.cpp +++ b/GM/FrmMain.cpp @@ -122,7 +122,8 @@ static const wxClassInfo *tblBrd[] = { CMainFrame::CMainFrame() : wxDocParentFrameAny(wxDocManager::GetDocumentManager(), nullptr, wxID_ANY, - wxTheApp->GetAppDisplayName()) + wxTheApp->GetAppDisplayName()), + CB::FreezeUntilIdleMixin(static_cast(*this)) { auiManager.SetManagedWindow(this); SetIcon(wxIcon(std::format("#{}", IDR_MAINFRAME))); @@ -653,6 +654,8 @@ void CMainFrame::OnIdle() auiMgrScheduleUpdate = false; auiManager.Update(); } + + CB::FreezeUntilIdleMixin::OnIdle(); } namespace { diff --git a/GM/FrmMain.h b/GM/FrmMain.h index 97d8d747..dff925cd 100644 --- a/GM/FrmMain.h +++ b/GM/FrmMain.h @@ -42,7 +42,8 @@ #include "frmdocktile.h" #endif -class CMainFrame : public wxDocParentFrameAny +class CMainFrame : public wxDocParentFrameAny, + public CB::FreezeUntilIdleMixin { public: CMainFrame(); diff --git a/GShr/CyberBoard.h b/GShr/CyberBoard.h index 1e761ff2..c19a1e57 100644 --- a/GShr/CyberBoard.h +++ b/GShr/CyberBoard.h @@ -2037,6 +2037,9 @@ namespace CB public: virtual wxWindow& GetWindow() = 0; + void OnActivateView(bool activate, + ::wxView *activeView, + ::wxView *deactiveView) override; void OnDraw(wxDC* dc) override; protected: @@ -2070,6 +2073,23 @@ namespace CB { wxWindow* pGetMainWndWx(); inline wxWindow& GetMainWndWx() { return CheckedDeref(pGetMainWndWx()); } + + /* call wxWindow::Freeze() to block repaint until after idle + processing shows/hides palettes */ + class FreezeUntilIdleMixin + { + public: + FreezeUntilIdleMixin(wxWindow& inw); + // avoid compiler preferring copy ctor to above ctor + FreezeUntilIdleMixin(const FreezeUntilIdleMixin&) = delete; + void FreezeUntilIdle(); + protected: + void OnIdle(); + private: + wxWindow& w; + bool scheduleThaw = false; + }; + string GetAppName(); } diff --git a/GShr/LibMfc.cpp b/GShr/LibMfc.cpp index b0205d0b..a21074a2 100644 --- a/GShr/LibMfc.cpp +++ b/GShr/LibMfc.cpp @@ -903,6 +903,22 @@ const std::type_info& CB::GetPublicTypeid(const wxWindow& w) return mfcWnd ? typeid(*mfcWnd) : typeid(w); } +void CB::wxView::OnActivateView(bool activate, + ::wxView *activeView, + ::wxView *deactiveView) +{ + if (activate) + { + wxWindow& mainWnd = GetMainWndWx(); + CB::FreezeUntilIdleMixin* freezer = dynamic_cast(&mainWnd); + if (freezer) + { + freezer->FreezeUntilIdle(); + } + } + ::wxView::OnActivateView(activate, activeView, deactiveView); +} + void CB::wxView::OnDraw(wxDC * dc) { CPP20_TRACE("{}({})\n", __func__, *this); @@ -1012,6 +1028,29 @@ void CB::wxView::FileHistoryRemoveMenu() docMgr.FileHistoryRemoveMenu(&menuFile); } +CB::FreezeUntilIdleMixin::FreezeUntilIdleMixin(wxWindow& inw) : + w(inw) +{ +} + +void CB::FreezeUntilIdleMixin::FreezeUntilIdle() +{ + if (!scheduleThaw) + { + w.Freeze(); + scheduleThaw = true; + } +} + +void CB::FreezeUntilIdleMixin::OnIdle() +{ + if (scheduleThaw) + { + w.Thaw(); + scheduleThaw = false; + } +} + CB::ToolTip::~ToolTip() { Enable(false);