Audacity  3.0.3
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 "../widgets/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 
46 class AudacityProject;
47 class ShuttleGui;
48 
49 class AUDACITY_DLL_API PrefsPanel /* not final */
51 {
52  public:
53  // An array of PrefsNode specifies the tree of pages in pre-order traversal.
54  struct PrefsNode {
55  using Factory =
56  std::function< PrefsPanel * (
57  wxWindow *parent, wxWindowID winid, AudacityProject *) >;
59  size_t nChildren{ 0 };
60  bool expanded{ false };
61 
62  PrefsNode(const Factory &factory_,
63  unsigned nChildren_ = 0,
64  bool expanded_ = true)
65  : factory(factory_), nChildren(nChildren_), expanded(expanded_)
66  {}
67  };
68 
69  using Factories = std::vector<PrefsPanel::PrefsNode>;
70  static Factories &DefaultFactories();
71 
72  // \brief Type alias for factories such as GUIPrefsFactory that produce a
73  // PrefsPanel, used by the Preferences dialog in a treebook.
74  // The project pointer may be null. Usually it's not needed because
75  // preferences are global. But sometimes you need a project, such as to
76  // preview the preference changes for spectrograms.
77  using Factory =
78  std::function< PrefsPanel * (
79  wxWindow *parent, wxWindowID winid, AudacityProject *) >;
80 
81  // Typically you make a static object of this type in the .cpp file that
82  // also implements the PrefsPanel subclass.
83  struct AUDACITY_DLL_API Registration final
84  {
85  Registration( const wxString &name, const Factory &factory,
86  bool expanded = true,
87  const Registry::Placement &placement = { wxEmptyString, {} });
88  };
89 
90  PrefsPanel(wxWindow * parent,
91  wxWindowID winid, const TranslatableString &title)
92  : wxPanelWrapper(parent, winid)
93  {
94  SetLabel(title); // Provide visual label
95  SetName(title); // Provide audible label
96  }
97 
98  virtual ~PrefsPanel();
99 
100  // NEW virtuals
101  virtual void Preview() {} // Make tentative changes
102  virtual bool Commit() = 0; // used to be called "Apply"
103 
104 
105  virtual PluginPath GetPath();
106  virtual VendorSymbol GetVendor();
107  virtual wxString GetVersion();
108 
109  //virtual ComponentInterfaceSymbol GetSymbol();
110  //virtual wxString GetDescription();
111 
112 
113  // If it returns True, the Preview button is added below the panel
114  // Default returns false
115  virtual bool ShowsPreviewButton();
116  virtual void PopulateOrExchange( ShuttleGui & WXUNUSED(S) ){};
117 
119 
120  virtual ManualPageID HelpPageName();
121 
122  virtual void Cancel();
123 };
124 
125 #endif
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
wxPanelWrapper
Definition: wxPanelWrapper.h:41
PluginPath
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
PrefsPanel::PopulateOrExchange
virtual void PopulateOrExchange(ShuttleGui &WXUNUSED(S))
Definition: PrefsPanel.h:116
PrefsPanel::Registration
Definition: PrefsPanel.h:84
PrefsPanel::Factory
std::function< PrefsPanel *(wxWindow *parent, wxWindowID winid, AudacityProject *) > Factory
Definition: PrefsPanel.h:79
Registry::Placement
Definition: Registry.h:219
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
PrefsPanel::Preview
virtual void Preview()
Definition: PrefsPanel.h:101
PrefsPanel::Commit
virtual bool Commit()=0
ComponentInterface.h
PrefsPanel::PrefsNode
Definition: PrefsPanel.h:54
factory
static RegisteredToolbarFactory factory
Definition: ControlToolBar.cpp:806
name
const TranslatableString name
Definition: Distortion.cpp:98
title
static const auto title
Definition: UpdateNoticeDialog.cpp:23
PrefsPanel::PrefsNode::Factory
std::function< PrefsPanel *(wxWindow *parent, wxWindowID winid, AudacityProject *) > Factory
Definition: PrefsPanel.h:57
PrefsPanel::PrefsNode::PrefsNode
PrefsNode(const Factory &factory_, unsigned nChildren_=0, bool expanded_=true)
Definition: PrefsPanel.h:62
TaggedIdentifier< ManualPageIDTag >
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:113
ComponentInterface
ComponentInterface provides name / vendor / version functions to identify plugins....
Definition: ComponentInterface.h:62
PrefsPanel::PrefsNode::factory
Factory factory
Definition: PrefsPanel.h:58
PrefsPanel
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
PrefsPanel::Factories
std::vector< PrefsPanel::PrefsNode > Factories
Definition: PrefsPanel.h:69
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
PrefsPanel::PrefsPanel
PrefsPanel(wxWindow *parent, wxWindowID winid, const TranslatableString &title)
Definition: PrefsPanel.h:90