From 2facbe0d535733a4011a394f77ccdfba3d6a0c61 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 6 Jun 2021 08:15:35 -0400 Subject: [PATCH] Define BasicUI::WindowPlacement and subclass for wxWidgets... ... An elaborate way to hold a wxWindow* as parent of a window, but avoiding mention of wxWindow* in the member functions of BasicUI::Services, to be defined next --- libraries/lib-basic-ui/BasicUI.cpp | 2 ++ libraries/lib-basic-ui/BasicUI.h | 14 ++++++++++++++ src/widgets/wxWidgetsBasicUI.cpp | 12 ++++++++++++ src/widgets/wxWidgetsBasicUI.h | 14 ++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/libraries/lib-basic-ui/BasicUI.cpp b/libraries/lib-basic-ui/BasicUI.cpp index bd5ab3db27..aa5fe38900 100644 --- a/libraries/lib-basic-ui/BasicUI.cpp +++ b/libraries/lib-basic-ui/BasicUI.cpp @@ -13,6 +13,8 @@ Paul Licameli #include namespace BasicUI { +WindowPlacement::~WindowPlacement() = default; + Services::~Services() = default; static Services *theInstance = nullptr; diff --git a/libraries/lib-basic-ui/BasicUI.h b/libraries/lib-basic-ui/BasicUI.h index ff1ac2a284..26802d0e6d 100644 --- a/libraries/lib-basic-ui/BasicUI.h +++ b/libraries/lib-basic-ui/BasicUI.h @@ -20,6 +20,20 @@ namespace BasicUI { using Action = std::function; +//! Subclasses may hold information such as a parent window pointer for a dialog. +/*! The default-constructed empty value of this base class must be accepted by overrides of methods of + Services */ +class BASIC_UI_API WindowPlacement { +public: + WindowPlacement() = default; + + //! Don't slice + WindowPlacement( const WindowPlacement& ) PROHIBITED; + //! Don't slice + WindowPlacement &operator=( const WindowPlacement& ) PROHIBITED; + virtual ~WindowPlacement(); +}; + //! @} //! Abstract class defines a few user interface services, not mentioning particular toolkits diff --git a/src/widgets/wxWidgetsBasicUI.cpp b/src/widgets/wxWidgetsBasicUI.cpp index 25c9384d3d..3eb6cc0387 100644 --- a/src/widgets/wxWidgetsBasicUI.cpp +++ b/src/widgets/wxWidgetsBasicUI.cpp @@ -12,6 +12,8 @@ Paul Licameli using namespace BasicUI; +wxWidgetsWindowPlacement::~wxWidgetsWindowPlacement() = default; + wxWidgetsBasicUI::~wxWidgetsBasicUI() = default; void wxWidgetsBasicUI::DoCallAfter(const Action &action) @@ -23,3 +25,13 @@ void wxWidgetsBasicUI::DoYield() { wxTheApp->Yield(); } + +namespace { +wxWindow *GetParent(const BasicUI::WindowPlacement &placement) +{ + if (auto *pPlacement = + dynamic_cast(&placement)) + return pPlacement->pWindow; + return nullptr; +} +} diff --git a/src/widgets/wxWidgetsBasicUI.h b/src/widgets/wxWidgetsBasicUI.h index d203a045eb..9973110b7f 100644 --- a/src/widgets/wxWidgetsBasicUI.h +++ b/src/widgets/wxWidgetsBasicUI.h @@ -13,6 +13,20 @@ Paul Licameli #include "BasicUI.h" +class wxWindow; + +//! Window placement information for wxWidgetsBasicUI can be constructed from a wxWindow pointer +struct AUDACITY_DLL_API wxWidgetsWindowPlacement final +: BasicUI::WindowPlacement { + wxWidgetsWindowPlacement() = default; + explicit wxWidgetsWindowPlacement( wxWindow *pWindow ) + : pWindow{ pWindow } + {} + + ~wxWidgetsWindowPlacement() override; + wxWindow *pWindow{}; +}; + //! An implementation of BasicUI::Services in terms of the wxWidgets toolkit /*! This is a singleton that doesn't need AUDACITY_DLL_API visibility */ class wxWidgetsBasicUI final : public BasicUI::Services {