Audacity 3.2.0
PrefsPanel.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 PrefsPanel.h
6
7 Joshua Haberman
8
9*******************************************************************//*******************************************************************/
26
27#ifndef __AUDACITY_PREFS_PANEL__
28#define __AUDACITY_PREFS_PANEL__
29
30#include <functional>
31#include "wxPanelWrapper.h" // to inherit
32#include "ComponentInterface.h"
33#include "Registry.h"
34
35/* A few constants for an attempt at semi-uniformity */
36#define PREFS_FONT_SIZE 8
37
38#define BUILTIN_PREFS_PANEL_PREFIX wxT("Built-in PrefsPanel: ")
39
40/* these are spacing guidelines: ie. radio buttons should have a 5 pixel
41 * border on each side */
42#define RADIO_BUTTON_BORDER 5
43#define TOP_LEVEL_BORDER 5
44#define GENERIC_CONTROL_BORDER 5
45
46class AudacityProject;
47class ShuttleGui;
48
49class AUDACITY_DLL_API PrefsPanel /* not final */
51{
52 struct PrefsItem;
53
54 public:
55 // An array of PrefsNode specifies the tree of pages in pre-order traversal.
56 struct PrefsNode {
57 using Factory =
58 std::function< PrefsPanel * (
59 wxWindow *parent, wxWindowID winid, AudacityProject *) >;
61 size_t nChildren{ 0 };
62 bool expanded{ false };
63 mutable bool enabled{ true };
64
65 PrefsNode(const Factory &factory_,
66 unsigned nChildren_ = 0,
67 bool expanded_ = true)
68 : factory(factory_), nChildren(nChildren_), expanded(expanded_)
69 {}
70 };
71
72 using Factories = std::vector<PrefsPanel::PrefsNode>;
73 static Factories &DefaultFactories();
74
75 // \brief Type alias for factories such as GUIPrefsFactory that produce a
76 // PrefsPanel, used by the Preferences dialog in a treebook.
77 // The project pointer may be null. Usually it's not needed because
78 // preferences are global. But sometimes you need a project, such as to
79 // preview the preference changes for spectrograms.
80 using Factory =
81 std::function< PrefsPanel * (
82 wxWindow *parent, wxWindowID winid, AudacityProject *) >;
83
84 // Typically you make a static object of this type in the .cpp file that
85 // also implements the PrefsPanel subclass.
86 struct AUDACITY_DLL_API Registration final
87 : Registry::RegisteredItem<PrefsItem>
88 {
89 Registration( const wxString &name, const Factory &factory,
90 bool expanded = true,
91 const Registry::Placement &placement = { wxEmptyString, {} });
92 };
93
94 PrefsPanel(wxWindow * parent,
95 wxWindowID winid, const TranslatableString &title)
96 : wxPanelWrapper(parent, winid)
97 {
98 SetLabel(title); // Provide visual label
99 SetName(title); // Provide audible label
100 }
101
102 virtual ~PrefsPanel();
103
104 // NEW virtuals
105 virtual void Preview() {} // Make tentative changes
106 virtual bool Commit() = 0; // used to be called "Apply"
107
108
109 virtual PluginPath GetPath() const override;
110 virtual VendorSymbol GetVendor() const override;
111 virtual wxString GetVersion() const override;
112
113 //virtual ComponentInterfaceSymbol GetSymbol();
114 //virtual wxString GetDescription();
115
116
117 // If it returns True, the Preview button is added below the panel
118 // Default returns false
119 virtual bool ShowsPreviewButton();
120 virtual void PopulateOrExchange( ShuttleGui & WXUNUSED(S) ){};
121
123
124 virtual ManualPageID HelpPageName();
125
126 virtual void Cancel();
127
128 private:
131 };
132 struct AUDACITY_DLL_API PrefsItem final
133 : Registry::GroupItem<Traits> {
135 bool expanded{ false };
136
138
139 PrefsItem(const wxString &name,
140 const PrefsPanel::Factory &factory, bool expanded);
141
142 struct Visitor;
143 };
144};
145
146#endif
const TranslatableString name
Definition: Distortion.cpp:76
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
static const auto title
#define S(N)
Definition: ToChars.cpp:64
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
ComponentInterface provides name / vendor / version functions to identify plugins....
virtual wxString GetVersion() const =0
virtual PluginPath GetPath() const =0
virtual VendorSymbol GetVendor() const =0
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
PrefsPanel(wxWindow *parent, wxWindowID winid, const TranslatableString &title)
Definition: PrefsPanel.h:94
std::function< PrefsPanel *(wxWindow *parent, wxWindowID winid, AudacityProject *) > Factory
Definition: PrefsPanel.h:82
virtual bool Commit()=0
virtual void Preview()
Definition: PrefsPanel.h:105
virtual void PopulateOrExchange(ShuttleGui &WXUNUSED(S))
Definition: PrefsPanel.h:120
std::vector< PrefsPanel::PrefsNode > Factories
Definition: PrefsPanel.h:72
Generates classes whose instances register items at construction.
Definition: Registry.h:388
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:630
Holds a msgid for the translation catalog; may also bind format arguments.
void SetLabel(const TranslatableString &label)
static RegisteredToolbarFactory factory
PrefsPanel::Factory factory
Definition: PrefsPanel.h:134
PrefsNode(const Factory &factory_, unsigned nChildren_=0, bool expanded_=true)
Definition: PrefsPanel.h:65
std::function< PrefsPanel *(wxWindow *parent, wxWindowID winid, AudacityProject *) > Factory
Definition: PrefsPanel.h:59
Has variadic and range constructors that check types.
Definition: Registry.h:292
Primary template for a list of arbitrary types.
Definition: TypeList.h:61