Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
Define BasicUI::WindowPlacement and subclass for wxWidgets...
Browse files Browse the repository at this point in the history
... 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
  • Loading branch information
Paul-Licameli committed Jul 19, 2021
1 parent 50e8139 commit 2facbe0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libraries/lib-basic-ui/BasicUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Paul Licameli
#include <vector>

namespace BasicUI {
WindowPlacement::~WindowPlacement() = default;

Services::~Services() = default;

static Services *theInstance = nullptr;
Expand Down
14 changes: 14 additions & 0 deletions libraries/lib-basic-ui/BasicUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ namespace BasicUI {

using Action = std::function<void()>;

//! 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
Expand Down
12 changes: 12 additions & 0 deletions src/widgets/wxWidgetsBasicUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Paul Licameli

using namespace BasicUI;

wxWidgetsWindowPlacement::~wxWidgetsWindowPlacement() = default;

wxWidgetsBasicUI::~wxWidgetsBasicUI() = default;

void wxWidgetsBasicUI::DoCallAfter(const Action &action)
Expand All @@ -23,3 +25,13 @@ void wxWidgetsBasicUI::DoYield()
{
wxTheApp->Yield();
}

namespace {
wxWindow *GetParent(const BasicUI::WindowPlacement &placement)
{
if (auto *pPlacement =
dynamic_cast<const wxWidgetsWindowPlacement*>(&placement))
return pPlacement->pWindow;
return nullptr;
}
}
14 changes: 14 additions & 0 deletions src/widgets/wxWidgetsBasicUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2facbe0

Please sign in to comment.