1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-07 15:49:42 +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.

Original commit: d20cf012556a819e68515d86bb66a2c047007539

Signed-off-by: Panagiotis Vasilopoulos <hello@alwayslivid.com>
This commit is contained in:
Paul Licameli 2021-02-07 21:17:45 -05:00 committed by Panagiotis Vasilopoulos
parent 6daf0a29b7
commit 2d0394796e
No known key found for this signature in database
GPG Key ID: 9E541BDE43B99F44
8 changed files with 1066 additions and 171 deletions

View File

@ -7,6 +7,7 @@ set( LIBRARIES
lib-strings
lib-utility
lib-components
lib-basic-ui
)
foreach( LIBRARY ${LIBRARIES} )

View 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;
}
}

View 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

View 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}"
""
"" ""
)

View File

@ -110,6 +110,7 @@ It handles initialization and termination by subclassing wxApp.
#include "tracks/ui/Scrubbing.h"
#include "widgets/FileConfig.h"
#include "widgets/FileHistory.h"
#include "widgets/wxWidgetsBasicUI.h"
#ifdef EXPERIMENTAL_EASY_CHANGE_KEY_BINDINGS
#include "prefs/KeyConfigPrefs.h"
@ -975,17 +976,22 @@ bool AudacityApp::OnInit() {
// Ensure we have an event loop during initialization
wxEventLoopGuarantor eventLoop;
// Fire up SQLite
if (!ProjectFileIO::InitializeSQL())
this->CallAfter([] {
::AudacityMessageBox(
XO("SQLite library failed to initialize. Audacity cannot continue."));
QuitAudacity(true);
});
// Inject basic GUI services behind the facade
{
static wxWidgetsBasicUI uiServices;
(void)BasicUI::Install(&uiServices);
}
// Fire up SQLite
if ( !ProjectFileIO::InitializeSQL() )
this->CallAfter([]{
::AudacityMessageBox(
XO("SQLite library failed to initialize. Audacity cannot continue.") );
QuitAudacity( true );
});
// cause initialization of wxWidgets' global logger target
(void)AudacityLogger::Get();
// cause initialization of wxWidgets' global logger target
(void)AudacityLogger::Get();
#if defined(__WXMAC__)
// Disable window animation

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
/*!********************************************************************
Audacity: A Digital Audio Editor
@file wxWidgetsBasicUI.cpp
Paul Licameli
**********************************************************************/
#include "wxWidgetsBasicUI.h"
wxWidgetsBasicUI::~wxWidgetsBasicUI() = default;

View 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