mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-02 08:39:46 +02:00
Facade class for basic UI, injection of a wxWidgets implementation...
... but none of the methods is defined yet. The intention is to inject dependencies on wxWidgets (or other) toolkit so that lower-level files have less build dependency on wxCore classes or on the event loop.
This commit is contained in:
parent
2133e42938
commit
d20cf01255
@ -8,6 +8,7 @@ set( LIBRARIES
|
||||
lib-utility
|
||||
lib-uuid
|
||||
lib-components
|
||||
lib-basic-ui
|
||||
)
|
||||
|
||||
if ( ${_OPT}has_networking )
|
||||
|
25
libraries/lib-basic-ui/BasicUI.cpp
Normal file
25
libraries/lib-basic-ui/BasicUI.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
/*!********************************************************************
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
@file BasicUI.cpp
|
||||
|
||||
Paul Licameli
|
||||
|
||||
**********************************************************************/
|
||||
#include "BasicUI.h"
|
||||
|
||||
namespace BasicUI {
|
||||
Services::~Services() = default;
|
||||
|
||||
static Services *theInstance = nullptr;
|
||||
|
||||
Services *Get() { return theInstance; }
|
||||
|
||||
Services *Install(Services *pInstance)
|
||||
{
|
||||
auto result = theInstance;
|
||||
theInstance = pInstance;
|
||||
return result;
|
||||
}
|
||||
}
|
47
libraries/lib-basic-ui/BasicUI.h
Normal file
47
libraries/lib-basic-ui/BasicUI.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*!********************************************************************
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
@file BasicUI.h
|
||||
@brief Toolkit-neutral facade for basic user interface services
|
||||
|
||||
Paul Licameli
|
||||
|
||||
**********************************************************************/
|
||||
#ifndef __AUDACITY_BASIC_UI__
|
||||
#define __AUDACITY_BASIC_UI__
|
||||
|
||||
namespace BasicUI {
|
||||
|
||||
//! @name Types used in the Services interface
|
||||
//! @{
|
||||
|
||||
//! @}
|
||||
|
||||
//! Abstract class defines a few user interface services, not mentioning particular toolkits
|
||||
/*! The intention is that the application supplies a concrete implementation at
|
||||
startup. Most code will not use this class directly, but call the inline
|
||||
functions that follow. */
|
||||
class BASIC_UI_API Services {
|
||||
public:
|
||||
virtual ~Services();
|
||||
};
|
||||
|
||||
//! Fetch the global instance, or nullptr if none is yet installed
|
||||
BASIC_UI_API Services *Get();
|
||||
|
||||
//! Install an implementation; return the previously installed instance
|
||||
BASIC_UI_API Services *Install(Services *pInstance);
|
||||
|
||||
/*! @name Functions that invoke global Services
|
||||
These dispatch to the global Services, if supplied. If none was supplied,
|
||||
they are mostly no-ops, with exceptions as noted. All should be called on
|
||||
the main thread only, except as noted.
|
||||
*/
|
||||
//! @{
|
||||
|
||||
//! @}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
23
libraries/lib-basic-ui/CMakeLists.txt
Normal file
23
libraries/lib-basic-ui/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
#[[
|
||||
This library defines a facade interface, BasicUI::Services, for a few basic
|
||||
interactions with the user, such as showing simple dialog boxes, and for
|
||||
enqueuing actions to the event loop, and yielding to to the event dispatcher.
|
||||
|
||||
The interface makes no mention of classes in wxWidgets. Using this library
|
||||
instead of making direct use of wxWidgets enlarges the parts of the program
|
||||
that are toolkit neutral.
|
||||
|
||||
There is a global pointer to an instance of Services, and the main program is
|
||||
expected, at startup, to create a static instance of a subclass of Services and
|
||||
set the pointer. If it does not, then calls to the non-member functions in
|
||||
namespace BasicUI are no-ops.
|
||||
]]#
|
||||
|
||||
set( SOURCES
|
||||
BasicUI.cpp
|
||||
BasicUI.h
|
||||
)
|
||||
audacity_library( lib-basic-ui "${SOURCES}"
|
||||
""
|
||||
"" ""
|
||||
)
|
@ -112,6 +112,7 @@ It handles initialization and termination by subclassing wxApp.
|
||||
#include "widgets/FileConfig.h"
|
||||
#include "widgets/FileHistory.h"
|
||||
#include "update/UpdateManager.h"
|
||||
#include "widgets/wxWidgetsBasicUI.h"
|
||||
|
||||
#ifdef HAS_NETWORKING
|
||||
#include "NetworkManager.h"
|
||||
@ -1057,6 +1058,12 @@ bool AudacityApp::OnInit()
|
||||
// Ensure we have an event loop during initialization
|
||||
wxEventLoopGuarantor eventLoop;
|
||||
|
||||
// Inject basic GUI services behind the facade
|
||||
{
|
||||
static wxWidgetsBasicUI uiServices;
|
||||
(void)BasicUI::Install(&uiServices);
|
||||
}
|
||||
|
||||
// Fire up SQLite
|
||||
if ( !ProjectFileIO::InitializeSQL() )
|
||||
this->CallAfter([]{
|
||||
|
@ -986,6 +986,8 @@ list( APPEND SOURCES
|
||||
widgets/wxPanelWrapper.cpp
|
||||
widgets/wxPanelWrapper.h
|
||||
widgets/wxTextCtrlWrapper.h
|
||||
widgets/wxWidgetsBasicUI.cpp
|
||||
widgets/wxWidgetsBasicUI.h
|
||||
|
||||
# XML handling
|
||||
xml/XMLFileReader.cpp
|
||||
|
12
src/widgets/wxWidgetsBasicUI.cpp
Normal file
12
src/widgets/wxWidgetsBasicUI.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
/*!********************************************************************
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
@file wxWidgetsBasicUI.cpp
|
||||
|
||||
Paul Licameli
|
||||
|
||||
**********************************************************************/
|
||||
#include "wxWidgetsBasicUI.h"
|
||||
|
||||
wxWidgetsBasicUI::~wxWidgetsBasicUI() = default;
|
23
src/widgets/wxWidgetsBasicUI.h
Normal file
23
src/widgets/wxWidgetsBasicUI.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*!********************************************************************
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
@file wxWidgetsBasicUI.h
|
||||
@brief Implementation of BasicUI using wxWidgets
|
||||
|
||||
Paul Licameli
|
||||
|
||||
**********************************************************************/
|
||||
#ifndef __WXWIDGETS_BASIC_UI__
|
||||
#define __WXWIDGETS_BASIC_UI__
|
||||
|
||||
#include "BasicUI.h"
|
||||
|
||||
//! 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 {
|
||||
public:
|
||||
~wxWidgetsBasicUI() override;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user