Audacity  3.0.3
GUIPrefs.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  GUIPrefs.cpp
6 
7  Brian Gunlogson
8  Joshua Haberman
9  Dominic Mazzoni
10  James Crook
11 
12 
13 *******************************************************************//*******************************************************************/
19 
20 
21 #include "GUIPrefs.h"
22 
23 #include <wx/app.h>
24 #include <wx/defs.h>
25 
26 #include "../FileNames.h"
27 #include "Languages.h"
28 #include "../Theme.h"
29 #include "../Prefs.h"
30 #include "../ShuttleGui.h"
31 
32 #include "GUISettings.h"
33 
34 #include "ThemePrefs.h"
35 #include "../AColor.h"
36 #include "../widgets/AudacityMessageBox.h"
37 
38 GUIPrefs::GUIPrefs(wxWindow * parent, wxWindowID winid)
39 /* i18n-hint: refers to Audacity's user interface settings */
40 : PrefsPanel(parent, winid, XC("Interface", "GUI"))
41 {
42  Populate();
43 }
44 
46 {
47 }
48 
50 {
52 }
53 
55 {
56  return XO("Preferences for GUI");
57 }
58 
60 {
61  return "Interface_Preferences";
62 }
63 
65  TranslatableStrings *pChoices,
66  wxArrayStringEx *pCodes,
67  int *pDefaultRangeIndex
68 )
69 {
70  static const auto sCodes = {
71  wxT("36") ,
72  wxT("48") ,
73  wxT("60") ,
74  wxT("72") ,
75  wxT("84") ,
76  wxT("96") ,
77  wxT("120") ,
78  wxT("145") ,
79  };
80  if (pCodes)
81  *pCodes = sCodes;
82 
83  static const std::initializer_list<TranslatableString> sChoices = {
84  XO("-36 dB (shallow range for high-amplitude editing)") ,
85  XO("-48 dB (PCM range of 8 bit samples)") ,
86  XO("-60 dB (PCM range of 10 bit samples)") ,
87  XO("-72 dB (PCM range of 12 bit samples)") ,
88  XO("-84 dB (PCM range of 14 bit samples)") ,
89  XO("-96 dB (PCM range of 16 bit samples)") ,
90  XO("-120 dB (approximate limit of human hearing)") ,
91  XO("-145 dB (PCM range of 24 bit samples)") ,
92  };
93 
94  if (pChoices)
95  *pChoices = sChoices;
96 
97  if (pDefaultRangeIndex)
98  *pDefaultRangeIndex = 2; // 60 == ENV_DB_RANGE
99 }
100 
102 {
103  // First any pre-processing for constructing the GUI.
106 
108 
109 #if 0
110  mLangCodes.insert( mLangCodes.end(), {
111  // only for testing...
112  "kg" ,
113  "ep" ,
114  } );
115 
116  mLangNames.insert( mLangNames.end(), {
117  "Klingon" ,
118  "Esperanto" ,
119  } );
120 #endif
121 
122  //------------------------- Main section --------------------
123  // Now construct the GUI itself.
124  // Use 'eIsCreatingFromPrefs' so that the GUI is
125  // initialised with values from gPrefs.
128  // ----------------------- End of main section --------------
129 }
130 
132  wxT("/GUI/Help"),
133  {
134  ByColumns,
135  { XO("Local") , XO("From Internet") , },
136  { wxT("Local") , wxT("FromInternet") , }
137  },
138  0 // "Local"
139 };
140 
142 {
143  S.SetBorder(2);
144  S.StartScroller();
145 
146  S.StartStatic(XO("Display"));
147  {
148  S.StartMultiColumn(2);
149  {
150 
151  S.TieChoice( XXO("&Language:"),
152  {
153  wxT("/Locale/Language"),
155  }
156  );
157 
158  S.TieChoice( XXO("Location of &Manual:"), GUIManualLocation);
159 
160  S.TieChoice( XXO("Th&eme:"), GUITheme);
161 
162  S.TieChoice( XXO("Meter dB &range:"),
163  {
164  ENV_DB_KEY,
167  }
168  );
169  }
170  S.EndMultiColumn();
171 // S.AddSpace(10);
172 // JKC: This is a silly preference. Kept here as a reminder that we may
173 // later want to have configurable button order.
174 // S.TieCheckBox(XXO("&Ergonomic order of Transport Toolbar buttons"),
175 // wxT("/GUI/ErgonomicTransportButtons"),
176 // true);
177 
178  }
179  S.EndStatic();
180 
181  S.StartStatic(XO("Options"));
182  {
183  // Start wording of options with a verb, if possible.
184  S.TieCheckBox(XXO("Show 'How to Get &Help' at launch"),
185  {wxT("/GUI/ShowSplashScreen"),
186  true});
187  S.TieCheckBox(XXO("Show e&xtra menus"),
188  {wxT("/GUI/ShowExtraMenus"),
189  false});
190 #ifdef EXPERIMENTAL_THEME_PREFS
191  // We do not want to make this option mainstream. It's a
192  // convenience for developers.
193  S.TieCheckBox(XXO("Show alternative &styling (Mac vs PC)"),
194  {wxT("/GUI/ShowMac"),
195  false});
196 #endif
197  S.TieCheckBox(XXO("&Beep on completion of longer activities"),
198  {wxT("/GUI/BeepOnCompletion"),
199  false});
200  S.TieCheckBox(XXO("Re&tain labels if selection snaps to a label"),
201  {wxT("/GUI/RetainLabels"),
202  false});
203  S.TieCheckBox(XXO("B&lend system and Audacity theme"),
204  {wxT("/GUI/BlendThemes"),
205  true});
206 #ifndef __WXMAC__
207  /* i18n-hint: RTL stands for 'Right to Left' */
208  S.TieCheckBox(XXO("Use mostly Left-to-Right layouts in RTL languages"),
209  {"/GUI/RtlWorkaround",
210  true});
211 #endif
212 #ifdef EXPERIMENTAL_CEE_NUMBERS_OPTION
213  S.TieCheckBox(XXO("Never use comma as decimal point"),
214  {wxT("/Locale/CeeNumberFormat"),
215  false});
216 #endif
217  }
218  S.EndStatic();
219 
220  S.StartStatic(XO("Timeline"));
221  {
222  S.TieCheckBox(XXO("Show Timeline Tooltips"),
223  {wxT("/QuickPlay/ToolTips"),
224  true});
225  S.TieCheckBox(XXO("Show Scrub Ruler"),
226  {wxT("/QuickPlay/ScrubbingEnabled"),
227  false});
228  }
229  S.EndStatic();
230 
231  S.EndScroller();
232 }
233 
235 {
236  ShuttleGui S(this, eIsSavingToPrefs);
238 
239  // If language has changed, we want to change it now, not on the next reboot.
240  wxString lang = gPrefs->Read(wxT("/Locale/Language"), wxT(""));
241  wxString usedLang = SetLang(lang);
242  // Bug 1523: Previously didn't check no-language (=System Language)
243  if (!(lang.empty() || lang == L"System") && (lang != usedLang)) {
244  // lang was not usable and is not system language. We got overridden.
245  gPrefs->Write(wxT("/Locale/Language"), usedLang);
246  gPrefs->Flush();
247  }
248 
249  // Reads preference GUITheme
252 
253  return true;
254 }
255 
256 wxString GUIPrefs::SetLang( const wxString & lang )
257 {
258  auto result = Languages::SetLang(FileNames::AudacityPathList(), lang);
259  if (!(lang.empty() || lang == L"System") && result != lang)
261  XO("Language \"%s\" is unknown").Format( lang ) );
262 
263 #ifdef EXPERIMENTAL_CEE_NUMBERS_OPTION
264  bool forceCeeNumbers;
265  gPrefs->Read(wxT("/Locale/CeeNumberFormat"), &forceCeeNumbers, false);
266  if( forceCeeNumbers )
268 #endif
269 
270 #ifdef __WXMAC__
271  wxApp::s_macHelpMenuTitleName = _("&Help");
272 #endif
273 
274  return result;
275 }
276 
278 {
279  static int value = wxNewId();
280  return value;
281 }
282 
284 {
285  static int value = wxNewId();
286  return value;
287 }
288 
289 namespace{
291  [](wxWindow *parent, wxWindowID winid, AudacityProject *)
292  {
293  wxASSERT(parent); // to justify safenew
294  return safenew GUIPrefs(parent, winid);
295  }
296 };
297 }
GUIPrefs::mLangNames
TranslatableStrings mLangNames
Definition: GUIPrefs.h:51
ShowClippingPrefsID
int ShowClippingPrefsID()
Definition: GUIPrefs.cpp:277
GUIPrefs::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: GUIPrefs.cpp:49
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
GUIPrefs::mDefaultRangeIndex
int mDefaultRangeIndex
Definition: GUIPrefs.h:55
GUITheme
ChoiceSetting GUITheme
Definition: Theme.cpp:1310
GUIPrefs::mRangeCodes
wxArrayStringEx mRangeCodes
Definition: GUIPrefs.h:53
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:68
TranslatableStrings
std::vector< TranslatableString > TranslatableStrings
Definition: TranslatableString.h:295
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: AudacityMessageBox.h:20
ShuttleGuiBase::TieCheckBox
wxCheckBox * TieCheckBox(const TranslatableString &Prompt, bool &Var)
Definition: ShuttleGui.cpp:1603
GUIPrefs::~GUIPrefs
~GUIPrefs()
Definition: GUIPrefs.cpp:45
Format
Abstract base class used in importing a file.
GUI_PREFS_PLUGIN_SYMBOL
#define GUI_PREFS_PLUGIN_SYMBOL
Definition: GUIPrefs.h:23
PrefsPanel::Registration
Definition: PrefsPanel.h:84
XO
#define XO(s)
Definition: Internat.h:31
XC
#define XC(s, c)
Definition: Internat.h:37
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1212
FileNames::AudacityPathList
AUDACITY_DLL_API const FilePaths & AudacityPathList()
A list of directories that should be searched for Audacity files (plug-ins, help files,...
ShowTrackNameInWaveformPrefsID
int ShowTrackNameInWaveformPrefsID()
Definition: GUIPrefs.cpp:283
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:61
ShuttleGuiBase::EndScroller
void EndScroller()
Definition: ShuttleGui.cpp:964
ThemePrefs.h
GUIPrefs::SetLang
static wxString SetLang(const wxString &lang)
Definition: GUIPrefs.cpp:256
ChoiceSetting
Definition: Prefs.h:261
XXO
#define XXO(s)
Definition: Internat.h:44
ShuttleGuiBase::StartScroller
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:931
GUIPrefs::GetDescription
TranslatableString GetDescription() override
Definition: GUIPrefs.cpp:54
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1203
Languages.h
wxArrayStringEx::insert
iterator insert(const_iterator pos, std::initializer_list< T > items)
Definition: wxArrayStringEx.h:58
GUIPrefs::GetRangeChoices
static void GetRangeChoices(TranslatableStrings *pChoices, wxArrayStringEx *pCodes, int *pDefaultRangeIndex=nullptr)
Definition: GUIPrefs.cpp:64
GUIPrefs::mRangeChoices
TranslatableStrings mRangeChoices
Definition: GUIPrefs.h:54
ENV_DB_KEY
#define ENV_DB_KEY
Definition: GUISettings.h:15
GUIPrefs
A PrefsPanel for general GUI preferences.
Definition: GUIPrefs.h:26
GUIPrefs::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: GUIPrefs.cpp:141
GUISettings.h
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:886
eIsSavingToPrefs
@ eIsSavingToPrefs
Definition: ShuttleGui.h:47
GUIPrefs::mLangCodes
wxArrayStringEx mLangCodes
Definition: GUIPrefs.h:50
Languages::GetLanguages
void GetLanguages(FilePaths pathList, wxArrayString &langCodes, TranslatableStrings &langNames)
Definition: Languages.cpp:136
ThemePrefs::ApplyUpdatedImages
static void ApplyUpdatedImages()
Definition: ThemePrefs.cpp:215
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:153
GUIPrefs::Populate
void Populate()
Definition: GUIPrefs.cpp:101
GUIManualLocation
ChoiceSetting GUIManualLocation
Definition: GUIPrefs.cpp:131
_
#define _(s)
Definition: Internat.h:75
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
GUIPrefs.h
Internat::SetCeeNumberFormat
static void SetCeeNumberFormat()
Definition: Internat.cpp:122
PrefsPanel
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
theTheme
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:202
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:484
ByColumns
ByColumns_t ByColumns
Definition: Prefs.cpp:374
eIsCreatingFromPrefs
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:46
GUIPrefs::Commit
bool Commit() override
Definition: GUIPrefs.cpp:234
ThemeBase::LoadPreferredTheme
static bool LoadPreferredTheme()
Definition: Theme.cpp:230
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:915
safenew
#define safenew
Definition: MemoryX.h:10
anonymous_namespace{GUIPrefs.cpp}::sAttachment
PrefsPanel::Registration sAttachment
Definition: GUIPrefs.cpp:290
Languages::SetLang
wxString SetLang(const FilePaths &pathList, const wxString &lang)
Definition: Languages.cpp:323
ShuttleGuiBase::TieChoice
wxChoice * TieChoice(const TranslatableString &Prompt, TranslatableString &Selected, const TranslatableStrings &choices)
Definition: ShuttleGui.cpp:1701
GUIPrefs::GUIPrefs
GUIPrefs(wxWindow *parent, wxWindowID winid)
Definition: GUIPrefs.cpp:38
GUIPrefs::HelpPageName
wxString HelpPageName() override
Definition: GUIPrefs.cpp:59
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625