Audacity  3.0.3
ThemePrefs.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ThemePrefs.cpp
6 
7  James Crook
8 
9  Audacity is free software.
10  This file is licensed under the wxWidgets license, see License.txt
11 
12 ********************************************************************//********************************************************************/
30 
31 
32 #include "ThemePrefs.h"
33 
34 #include <wx/app.h>
35 #include <wx/wxprec.h>
36 #include "Prefs.h"
37 #include "Theme.h"
38 #include "../ShuttleGui.h"
39 #include "AColor.h"
40 #include "BasicUI.h"
41 
42 wxDEFINE_EVENT(EVT_THEME_CHANGE, wxCommandEvent);
43 
51 };
52 
53 BEGIN_EVENT_TABLE(ThemePrefs, PrefsPanel)
61 
62 static bool ConfirmSave()
63 {
64  if (!GUIBlendThemes.Read())
65  return true;
66 
67  using namespace BasicUI;
68  const auto message = Verbatim(
69 "\"Blend system and Audacity theme\" in Interface Preferences was on.\n"
70 "This may cause images to to be re-saved with slight changes of color."
71  );
72 
73  return MessageBoxResult::Cancel != ShowMessageBox(message,
75 }
76 
77 ThemePrefs::ThemePrefs(wxWindow * parent, wxWindowID winid)
78 /* i18n-hint: A theme is a consistent visual style across an application's
79  graphical user interface, including choices of colors, and similarity of images
80  such as those on button controls. Audacity can load and save alternative
81  themes. */
82 : PrefsPanel(parent, winid, XO("Theme"))
83 {
84  Populate();
85 }
86 
88 {
89 }
90 
92 {
94 }
95 
97 {
98  return XO("Preferences for Theme");
99 }
100 
102 {
103  return "Theme_Preferences";
104 }
105 
108 {
109  // First any pre-processing for constructing the GUI.
110 
111  //------------------------- Main section --------------------
112  // Now construct the GUI itself.
113  // Use 'eIsCreatingFromPrefs' so that the GUI is
114  // initialised with values from gPrefs.
117  // ----------------------- End of main section --------------
118 }
119 
122 {
123  S.SetBorder(2);
124  S.StartScroller();
125 
126  S.StartStatic(XO("Info"));
127  {
128  S.AddFixedText(
129  XO(
130 "Themability is an experimental feature.\n\nTo try it out, click \"Save Theme Cache\" then find and modify the images and colors in\nImageCacheVxx.png using an image editor such as the Gimp.\n\nClick \"Load Theme Cache\" to load the changed images and colors back into Audacity.")
131  );
132 
133 #ifdef _DEBUG
134  S.AddFixedText(
135  Verbatim(
136 "This is a debug version of Audacity, with an extra button, 'Output Sourcery'. This will save\nC versions of the image caches that can be compiled in as defaults.")
137  );
138 #endif
139 
140  S.AddFixedText(
141  XO(
142 "Saving and loading individual theme files uses a separate file for each image, but is\notherwise the same idea.")
143  );
144  }
145  S.EndStatic();
146 
147  /* i18n-hint: && in here is an escape character to get a single & on screen,
148  * so keep it as is */
149  S.StartStatic( XO("Theme Cache - Images && Color"));
150  {
151  S.StartHorizontalLay(wxALIGN_LEFT);
152  {
153  S.Id(idSaveThemeCache).AddButton(XXO("Save Theme Cache"));
154  S.Id(idLoadThemeCache).AddButton(XXO("Load Theme Cache"));
155 
156  // This next button is only provided in Debug mode.
157  // It is for developers who are compiling Audacity themselves
158  // and who wish to generate NEW *ThemeAsCeeCode.h and compile them in.
159 #ifdef _DEBUG
160  S.Id(idSaveThemeAsCode).AddButton(Verbatim("Output Sourcery"));
161 #endif
162 
163  S.Id(idReadThemeInternal).AddButton(XXO("&Defaults"));
164  }
165  S.EndHorizontalLay();
166  }
167  S.EndStatic();
168 
169  // JKC: 'Ergonomic' details:
170  // Theme components are used much less frequently than
171  // the ImageCache. Yet it's easy to click them 'by mistake'.
172  //
173  // To reduce that risk, we use a separate box to separate them off.
174  // And choose text on the buttons that is shorter, making the
175  // buttons smaller and less tempting to click.
176  S.StartStatic( XO("Individual Theme Files"),1);
177  {
178  S.StartHorizontalLay(wxALIGN_LEFT);
179  {
180  S.Id(idSaveThemeComponents).AddButton( XXO("Save Files"));
181  S.Id(idLoadThemeComponents).AddButton( XXO("Load Files"));
182  }
183  S.EndHorizontalLay();
184  }
185  S.EndStatic();
186  S.EndScroller();
187 
188 }
189 
191 void ThemePrefs::OnLoadThemeComponents(wxCommandEvent & WXUNUSED(event))
192 {
193  wxBusyCursor busy;
196 }
197 
199 void ThemePrefs::OnSaveThemeComponents(wxCommandEvent & WXUNUSED(event))
200 {
201  if (!ConfirmSave())
202  return;
203  wxBusyCursor busy;
205 }
206 
208 void ThemePrefs::OnLoadThemeCache(wxCommandEvent & WXUNUSED(event))
209 {
210  wxBusyCursor busy;
211  theTheme.SwitchTheme({});
213 }
214 
216 void ThemePrefs::OnSaveThemeCache(wxCommandEvent & WXUNUSED(event))
217 {
218  if (!ConfirmSave())
219  return;
220  wxBusyCursor busy;
222  theTheme.WriteImageMap();// bonus - give them the html version.
223 }
224 
226 void ThemePrefs::OnReadThemeInternal(wxCommandEvent & WXUNUSED(event))
227 {
228  wxBusyCursor busy;
231 }
232 
234 void ThemePrefs::OnSaveThemeAsCode(wxCommandEvent & WXUNUSED(event))
235 {
236  if (!ConfirmSave())
237  return;
238  wxBusyCursor busy;
240  theTheme.WriteImageDefs();// bonus - give them the Defs too.
241 }
242 
244 {
245  AColor::ReInit();
246 
247  wxCommandEvent e{ EVT_THEME_CHANGE };
248  wxTheApp->SafelyProcessEvent( e );
249 }
250 
253 {
254  ShuttleGui S(this, eIsSavingToPrefs);
256 
260  return true;
261 }
262 
264 {
268 }
269 
270 #ifdef EXPERIMENTAL_THEME_PREFS
271 namespace{
273  [](wxWindow *parent, wxWindowID winid, AudacityProject *)
274  {
275  wxASSERT(parent); // to justify safenew
276  return safenew ThemePrefs(parent, winid);
277  },
278  false,
279  // Register with an explicit ordering hint because this one is
280  // only conditionally compiled
281  { "", { Registry::OrderingHint::After, "Effects" } }
282 };
283 }
284 #endif
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
ThemePrefs::Cancel
void Cancel() override
Definition: ThemePrefs.cpp:263
BasicUI::MessageBoxOptions
Definition: BasicUI.h:91
ThemePrefs::HelpPageName
ManualPageID HelpPageName() override
If not empty string, the Help button is added below the panel.
Definition: ThemePrefs.cpp:101
ThemePrefs::OnSaveThemeCache
void OnSaveThemeCache(wxCommandEvent &e)
Save Themes, each to a single png file.
Definition: ThemePrefs.cpp:216
AColor::ReInit
static void ReInit()
Definition: AColor.cpp:435
idReadThemeInternal
@ idReadThemeInternal
Definition: ThemePrefs.cpp:49
BasicUI::ShowMessageBox
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:248
ThemePrefs::OnLoadThemeCache
void OnLoadThemeCache(wxCommandEvent &e)
Load Theme from single png file.
Definition: ThemePrefs.cpp:208
PrefsPanel::Registration
Definition: PrefsPanel.h:84
XO
#define XO(s)
Definition: Internat.h:31
ThemePrefs::ThemePrefs
ThemePrefs(wxWindow *parent, wxWindowID winid)
Definition: ThemePrefs.cpp:77
Registry::OrderingHint::After
@ After
Definition: Registry.h:29
BasicUI::MessageBoxOptions::CancelButton
MessageBoxOptions && CancelButton() &&
Definition: BasicUI.h:111
THEME_PREFS_PLUGIN_SYMBOL
#define THEME_PREFS_PLUGIN_SYMBOL
Definition: ThemePrefs.h:28
ThemePrefs::Populate
void Populate()
Creates the dialog and its contents.
Definition: ThemePrefs.cpp:107
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
idSaveThemeComponents
@ idSaveThemeComponents
Definition: ThemePrefs.cpp:48
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2274
BasicUI::Icon::Warning
@ Warning
Setting::Read
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:128
ThemeBase::SwitchTheme
void SwitchTheme(teThemeType Theme)
Definition: Theme.cpp:201
ShuttleGuiBase::EndScroller
void EndScroller()
Definition: ShuttleGui.cpp:971
ThemePrefs::OnSaveThemeAsCode
void OnSaveThemeAsCode(wxCommandEvent &e)
Save Theme as C source code.
Definition: ThemePrefs.cpp:234
ThemePrefs.h
idSaveThemeAsCode
@ idSaveThemeAsCode
Definition: ThemePrefs.cpp:50
XXO
#define XXO(s)
Definition: Internat.h:44
ShuttleGuiBase::StartScroller
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:938
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1177
ThemePrefs::Commit
bool Commit() override
Update the preferences stored on disk.
Definition: ThemePrefs.cpp:252
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1167
BasicUI::MessageBoxResult::Cancel
@ Cancel
anonymous_namespace{Contrast.cpp}::sAttachment
AttachedItem sAttachment
Definition: Contrast.cpp:697
ShuttleGuiBase::AddFixedText
void AddFixedText(const TranslatableString &Str, bool bCenter=false, int wrapWidth=0)
Definition: ShuttleGui.cpp:440
ThemeBase::DeleteUnusedThemes
void DeleteUnusedThemes()
Definition: Theme.cpp:1178
Theme.h
ThemePrefs::~ThemePrefs
~ThemePrefs(void)
Definition: ThemePrefs.cpp:87
ThemeBase::GetFallbackThemeType
teThemeType GetFallbackThemeType()
Definition: Theme.cpp:864
ThemePrefs::GetDescription
TranslatableString GetDescription() override
Definition: ThemePrefs.cpp:96
theTheme
THEME_API Theme theTheme
Definition: Theme.cpp:79
ShuttleGuiBase::AddButton
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:360
BasicUI.h
Toolkit-neutral facade for basic user interface services.
ThemePrefs::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Create the dialog contents, or exchange data with it.
Definition: ThemePrefs.cpp:121
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:893
eIsSavingToPrefs
@ eIsSavingToPrefs
Definition: ShuttleGui.h:48
ThemeBase::WriteImageMap
void WriteImageMap()
Definition: Theme.cpp:760
ThemeBase::LoadThemeComponents
void LoadThemeComponents(bool bOkIfNotFound=false)
Definition: Theme.cpp:1008
ThemePrefs::ApplyUpdatedImages
static void ApplyUpdatedImages()
Definition: ThemePrefs.cpp:243
BasicUI
Definition: Export.h:39
ThemePrefs::OnReadThemeInternal
void OnReadThemeInternal(wxCommandEvent &e)
Read Theme from internal storage.
Definition: ThemePrefs.cpp:226
TaggedIdentifier< ManualPageIDTag >
ThemePrefs
A PrefsPanel that configures dynamic loading of Theme icons and colours.
Definition: ThemePrefs.h:31
wxDEFINE_EVENT
wxDEFINE_EVENT(EVT_THEME_CHANGE, wxCommandEvent)
ThemePrefs::OnLoadThemeComponents
void OnLoadThemeComponents(wxCommandEvent &e)
Load Theme from multiple png files.
Definition: ThemePrefs.cpp:191
idSaveThemeCache
@ idSaveThemeCache
Definition: ThemePrefs.cpp:46
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
Verbatim
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
Definition: TranslatableString.h:321
ThemeBase::SaveThemeAsCode
void SaveThemeAsCode()
Definition: Theme.cpp:1156
ThemeBase::SaveThemeComponents
void SaveThemeComponents()
Definition: Theme.cpp:1069
eThemePrefsIds
eThemePrefsIds
Definition: ThemePrefs.cpp:44
GUIBlendThemes
BoolSetting GUIBlendThemes
Definition: Theme.cpp:1303
idLoadThemeComponents
@ idLoadThemeComponents
Definition: ThemePrefs.cpp:47
PrefsPanel
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
ThemeBase::WriteImageDefs
void WriteImageDefs()
Writes a series of Macro definitions that can be used in the include file.
Definition: Theme.cpp:822
Prefs.h
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
eIsCreatingFromPrefs
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:47
ThemeBase::LoadPreferredTheme
static bool LoadPreferredTheme()
Definition: Theme.cpp:147
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:922
safenew
#define safenew
Definition: MemoryX.h:10
ThemeBase::CreateImageCache
void CreateImageCache()
Definition: Theme.cpp:587
ThemePrefs::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: ThemePrefs.cpp:91
AColor.h
ThemePrefs::OnSaveThemeComponents
void OnSaveThemeComponents(wxCommandEvent &e)
Save Theme to multiple png files.
Definition: ThemePrefs.cpp:199
END_EVENT_TABLE
END_EVENT_TABLE()
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
ConfirmSave
static bool ConfirmSave()
Definition: ThemePrefs.cpp:62
idLoadThemeCache
@ idLoadThemeCache
Definition: ThemePrefs.cpp:45