Audacity 3.2.0
ProjectStatus.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5ProjectStatus.h
6
7Paul Licameli
8
9**********************************************************************/
10
11#ifndef __AUDACITY_PROJECT_STATUS__
12#define __AUDACITY_PROJECT_STATUS__
13#endif
14
15#include <utility>
16#include <unordered_map>
17#include <vector>
18#include "ClientData.h" // to inherit
19#include "Prefs.h"
20#include "Observer.h"
21#include "Registry.h"
22
23class AudacityProject;
24class wxWindow;
25
27
34
36class PROJECT_API StatusBarFieldItem /* not final */
38{
39public:
40 explicit StatusBarFieldItem(StatusBarField identifier);
41 virtual ~StatusBarFieldItem();
42
49 virtual int GetDefaultWidth(const AudacityProject& project) const = 0;
50
58 virtual void OnSize(AudacityProject& project);
59
61 virtual void SetText(AudacityProject& project, const TranslatableString& msg) = 0;
64
66 virtual bool IsVisible(const AudacityProject& project) const = 0;
67
68protected:
70 void DispatchFieldChanged(const AudacityProject& project);
71};
72
73struct PROJECT_API StatusBarFieldRegistryTraits final
75{
77};
78
80
82struct PROJECT_API ProjectStatusFieldsRegistry final
83{
87 static void Visit(const StatusBarFieldRegistryVisitor& visitor);
89 static std::size_t Count(const AudacityProject* project);
91 static StatusBarFieldItem* Get(const StatusBarField& identifier);
93 static int GetFieldIndex(
94 const AudacityProject& project, const StatusBarField& identifier);
96 static void OnSize(AudacityProject& project);
97
99 Subscribe(std::function<void(const AudacityProject&, const StatusBarField&)>
100 handler);
101};
102
105
106class PROJECT_API ProjectStatus final
107 : public ClientData::Base
108 , public PrefsListener
109 , public Observer::Publisher<StatusBarField>
110{
111public:
113 static const ProjectStatus &Get( const AudacityProject &project );
114
116 ProjectStatus( const ProjectStatus & ) = delete;
117 ProjectStatus &operator= ( const ProjectStatus & ) = delete;
118 ~ProjectStatus() override;
119
120 // Type of a function to report translatable strings, and also report an extra
121 // margin, to request that the corresponding field of the status bar should
122 // be wide enough to contain any of those strings plus the margin.
123 using StatusWidthResult = std::pair< std::vector<TranslatableString>, unsigned >;
124 using StatusWidthFunction = std::function<
126 >;
127 using StatusWidthFunctions = std::vector< StatusWidthFunction >;
128
129 // Typically a static instance of this struct is used.
131 {
132 explicit
134 };
135
136 static const StatusWidthFunctions &GetStatusWidthFunctions();
137
139 void Set(const TranslatableString &msg,
141
142 // PrefsListener implementation
143 void UpdatePrefs() override;
144
145private:
147 static struct DefaultFieldsRegistrator final
148 {
150 } sDefaultFieldsRegistrator;
151
153 std::unordered_map<StatusBarField, TranslatableString> mCurrentStatus;
155};
Utility ClientData::Site to register hooks into a host class that attach client data.
#define field(n, t)
Definition: ImportAUP.cpp:165
PROJECT_API StatusBarField StateStatusBarField()
ID of the first field in the status bar. This filed is used to display playback state.
PROJECT_API StatusBarField MainStatusBarField()
ID of the second field in the status bar. This field is expandable.
PROJECT_API StatusBarField RateStatusBarField()
ID of the third field in the status bar. This field is used to display the current rate.
const auto project
static void OnSize(wxSizeEvent &evt)
Definition: VSTEditor.cpp:224
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
A listener notified of changes in preferences.
Definition: Prefs.h:652
Observer::Subscription mFieldChangedSubscription
~ProjectStatus() override
std::unordered_map< StatusBarField, TranslatableString > mCurrentStatus
std::pair< std::vector< TranslatableString >, unsigned > StatusWidthResult
ProjectStatus(const ProjectStatus &)=delete
std::function< StatusWidthResult(const AudacityProject &, StatusBarField) > StatusWidthFunction
std::vector< StatusWidthFunction > StatusWidthFunctions
AudacityProject & mProject
Generates classes whose instances register items at construction.
Definition: Registry.h:388
Abstract base class for status bar fields.
Definition: ProjectStatus.h:38
virtual int GetDefaultWidth(const AudacityProject &project) const =0
virtual void SetText(AudacityProject &project, const TranslatableString &msg)=0
Sets the current text of the field.
virtual TranslatableString GetText(const AudacityProject &project) const =0
Retrieves the current text of the field.
virtual bool IsVisible(const AudacityProject &project) const =0
Returns true if the field is visible in the status bar of the given project.
Holds a msgid for the translation catalog; may also bind format arguments.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
size_t Count(const Ptr< Type, BaseDeleter > &p)
Find out how many elements were allocated with a Ptr.
Definition: PackedArray.h:143
void Visit(const Visitors &visitors, const GroupItem< RegistryTraits > *pTopItem, const GroupItem< RegistryTraits > *pRegistry={}, typename RegistryTraits::ComputedItemContextType &computedItemContext=RegistryTraits::ComputedItemContextType::Instance)
Definition: Registry.h:609
A convenient default parameter for class template Site.
Definition: ClientData.h:29
Registry of status bar fields.
Definition: ProjectStatus.h:83
Has variadic and range constructors that check types.
Definition: Registry.h:292
Common abstract base class for items that are not groups.
Definition: Registry.h:224
Primary template for a list of arbitrary types.
Definition: TypeList.h:61