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 
41 wxDEFINE_EVENT(EVT_THEME_CHANGE, wxCommandEvent);
42 
50 };
51 
52 BEGIN_EVENT_TABLE(ThemePrefs, PrefsPanel)
60 
61 ThemePrefs::ThemePrefs(wxWindow * parent, wxWindowID winid)
62 /* i18n-hint: A theme is a consistent visual style across an application's
63  graphical user interface, including choices of colors, and similarity of images
64  such as those on button controls. Audacity can load and save alternative
65  themes. */
66 : PrefsPanel(parent, winid, XO("Theme"))
67 {
68  Populate();
69 }
70 
72 {
73 }
74 
76 {
78 }
79 
81 {
82  return XO("Preferences for Theme");
83 }
84 
86 {
87  return "Theme_Preferences";
88 }
89 
92 {
93  // First any pre-processing for constructing the GUI.
94 
95  //------------------------- Main section --------------------
96  // Now construct the GUI itself.
97  // Use 'eIsCreatingFromPrefs' so that the GUI is
98  // initialised with values from gPrefs.
101  // ----------------------- End of main section --------------
102 }
103 
106 {
107  S.SetBorder(2);
108  S.StartScroller();
109 
110  S.StartStatic(XO("Info"));
111  {
112  S.AddFixedText(
113  XO(
114 "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.\n\n(Only the Transport Toolbar and the colors on the wavetrack are currently affected, even\nthough the image file shows other icons too.)")
115  );
116 
117 #ifdef _DEBUG
118  S.AddFixedText(
119  Verbatim(
120 "This is a debug version of Audacity, with an extra button, 'Output Sourcery'. This will save a\nC version of the image cache that can be compiled in as a default.")
121  );
122 #endif
123 
124  S.AddFixedText(
125  XO(
126 "Saving and loading individual theme files uses a separate file for each image, but is\notherwise the same idea.")
127  );
128  }
129  S.EndStatic();
130 
131  /* i18n-hint: && in here is an escape character to get a single & on screen,
132  * so keep it as is */
133  S.StartStatic( XO("Theme Cache - Images && Color"));
134  {
135  S.StartHorizontalLay(wxALIGN_LEFT);
136  {
137  S.Id(idSaveThemeCache).AddButton(XXO("Save Theme Cache"));
138  S.Id(idLoadThemeCache).AddButton(XXO("Load Theme Cache"));
139 
140  // This next button is only provided in Debug mode.
141  // It is for developers who are compiling Audacity themselves
142  // and who wish to generate a NEW ThemeAsCeeCode.h and compile it in.
143 #ifdef _DEBUG
144  S.Id(idSaveThemeAsCode).AddButton(Verbatim("Output Sourcery"));
145 #endif
146 
147  S.Id(idReadThemeInternal).AddButton(XXO("&Defaults"));
148  }
149  S.EndHorizontalLay();
150  }
151  S.EndStatic();
152 
153  // JKC: 'Ergonomic' details:
154  // Theme components are used much less frequently than
155  // the ImageCache. Yet it's easy to click them 'by mistake'.
156  //
157  // To reduce that risk, we use a separate box to separate them off.
158  // And choose text on the buttons that is shorter, making the
159  // buttons smaller and less tempting to click.
160  S.StartStatic( XO("Individual Theme Files"),1);
161  {
162  S.StartHorizontalLay(wxALIGN_LEFT);
163  {
164  S.Id(idSaveThemeComponents).AddButton( XXO("Save Files"));
165  S.Id(idLoadThemeComponents).AddButton( XXO("Load Files"));
166  }
167  S.EndHorizontalLay();
168  }
169  S.EndStatic();
170  S.EndScroller();
171 
172 }
173 
175 void ThemePrefs::OnLoadThemeComponents(wxCommandEvent & WXUNUSED(event))
176 {
179 }
180 
182 void ThemePrefs::OnSaveThemeComponents(wxCommandEvent & WXUNUSED(event))
183 {
185 }
186 
188 void ThemePrefs::OnLoadThemeCache(wxCommandEvent & WXUNUSED(event))
189 {
192 }
193 
195 void ThemePrefs::OnSaveThemeCache(wxCommandEvent & WXUNUSED(event))
196 {
198  theTheme.WriteImageMap();// bonus - give them the html version.
199 }
200 
202 void ThemePrefs::OnReadThemeInternal(wxCommandEvent & WXUNUSED(event))
203 {
206 }
207 
209 void ThemePrefs::OnSaveThemeAsCode(wxCommandEvent & WXUNUSED(event))
210 {
212  theTheme.WriteImageDefs();// bonus - give them the Defs too.
213 }
214 
216 {
217  AColor::ReInit();
218 
219  wxCommandEvent e{ EVT_THEME_CHANGE };
220  wxTheApp->SafelyProcessEvent( e );
221 }
222 
225 {
226  ShuttleGui S(this, eIsSavingToPrefs);
228 
229  return true;
230 }
231 
232 #ifdef EXPERIMENTAL_THEME_PREFS
233 namespace{
235  [](wxWindow *parent, wxWindowID winid, AudacityProject *)
236  {
237  wxASSERT(parent); // to justify safenew
238  return safenew ThemePrefs(parent, winid);
239  },
240  false,
241  // Register with an explicit ordering hint because this one is
242  // only conditionally compiled
243  { "", { Registry::OrderingHint::After, "Effects" } }
244 };
245 }
246 #endif
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
TranslatableString
Definition: Types.h:290
ThemeBase::SaveComponents
void SaveComponents()
Definition: Theme.cpp:1105
ThemePrefs::OnSaveThemeCache
void OnSaveThemeCache(wxCommandEvent &e)
Save Theme to single png file.
Definition: ThemePrefs.cpp:195
AColor::ReInit
static void ReInit()
Definition: AColor.cpp:446
ThemeBase::CreateImageCache
void CreateImageCache(bool bBinarySave=true)
Definition: Theme.cpp:631
idReadThemeInternal
@ idReadThemeInternal
Definition: ThemePrefs.cpp:48
Theme
Based on ThemeBase, Theme manages image and icon resources.
Definition: Theme.h:164
ThemePrefs::OnLoadThemeCache
void OnLoadThemeCache(wxCommandEvent &e)
Load Theme from single png file.
Definition: ThemePrefs.cpp:188
PrefsPanel::Registration
Definition: PrefsPanel.h:83
XO
#define XO(s)
Definition: Internat.h:32
Registry::OrderingHint::After
@ After
Definition: Registry.h:29
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:91
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:60
idSaveThemeComponents
@ idSaveThemeComponents
Definition: ThemePrefs.cpp:47
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2248
ShuttleGuiBase::EndScroller
void EndScroller()
Definition: ShuttleGui.cpp:964
ThemePrefs::OnSaveThemeAsCode
void OnSaveThemeAsCode(wxCommandEvent &e)
Save Theme as C source code.
Definition: ThemePrefs.cpp:209
ThemePrefs.h
idSaveThemeAsCode
@ idSaveThemeAsCode
Definition: ThemePrefs.cpp:49
XXO
#define XXO(s)
Definition: Internat.h:45
ShuttleGuiBase::StartScroller
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:931
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1170
ThemePrefs::Commit
bool Commit() override
Update the preferences stored on disk.
Definition: ThemePrefs.cpp:224
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1160
ThemeBase::LoadComponents
void LoadComponents(bool bOkIfNotFound=false)
Definition: Theme.cpp:1053
anonymous_namespace{Contrast.cpp}::sAttachment
AttachedItem sAttachment
Definition: Contrast.cpp:696
ShuttleGuiBase::AddFixedText
void AddFixedText(const TranslatableString &Str, bool bCenter=false, int wrapWidth=0)
Definition: ShuttleGui.cpp:433
ThemePrefs::~ThemePrefs
~ThemePrefs(void)
Definition: ThemePrefs.cpp:71
ThemeBase::GetFallbackThemeType
teThemeType GetFallbackThemeType()
Definition: Theme.cpp:889
ThemePrefs::GetDescription
TranslatableString GetDescription() override
Definition: ThemePrefs.cpp:80
ShuttleGuiBase::AddButton
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:353
ThemePrefs::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Create the dialog contents, or exchange data with it.
Definition: ThemePrefs.cpp:105
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:886
eIsSavingToPrefs
@ eIsSavingToPrefs
Definition: ShuttleGui.h:46
ThemeBase::ReadImageCache
bool ReadImageCache(teThemeType type=themeFromFile, bool bOkIfNotFound=false)
Definition: Theme.cpp:921
ThemeBase::WriteImageMap
void WriteImageMap()
Definition: Theme.cpp:796
ThemePrefs::ApplyUpdatedImages
static void ApplyUpdatedImages()
Definition: ThemePrefs.cpp:215
ThemePrefs::OnReadThemeInternal
void OnReadThemeInternal(wxCommandEvent &e)
Read Theme from internal storage.
Definition: ThemePrefs.cpp:202
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:175
idSaveThemeCache
@ idSaveThemeCache
Definition: ThemePrefs.cpp:45
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
Verbatim
TranslatableString Verbatim(wxString str)
Definition: Types.h:573
ThemeBase::SaveThemeAsCode
void SaveThemeAsCode()
Definition: Theme.cpp:1179
eThemePrefsIds
eThemePrefsIds
Definition: ThemePrefs.cpp:43
idLoadThemeComponents
@ idLoadThemeComponents
Definition: ThemePrefs.cpp:46
PrefsPanel
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:50
ThemeBase::WriteImageDefs
void WriteImageDefs()
Writes a series of Macro definitions that can be used in the include file.
Definition: Theme.cpp:849
theTheme
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:201
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:497
eIsCreatingFromPrefs
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:45
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:915
safenew
#define safenew
Definition: MemoryX.h:8
ThemePrefs::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: ThemePrefs.cpp:75
ThemePrefs::OnSaveThemeComponents
void OnSaveThemeComponents(wxCommandEvent &e)
Save Theme to multiple png files.
Definition: ThemePrefs.cpp:182
ThemePrefs::HelpPageName
wxString HelpPageName() override
Definition: ThemePrefs.cpp:85
END_EVENT_TABLE
END_EVENT_TABLE()
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:638
idLoadThemeCache
@ idLoadThemeCache
Definition: ThemePrefs.cpp:44