Audacity 3.2.0
EditToolBar.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 EditToolBar.cpp
6
7 Dominic Mazzoni
8 Shane T. Mueller
9 Leland Lucius
10
11 See EditToolBar.h for details
12
13*******************************************************************//*******************************************************************/
31
32
33
34#include "EditToolBar.h"
35
36// For compilers that support precompilation, includes "wx/wx.h".
37#include <wx/wxprec.h>
38
39#include <wx/setup.h> // for wxUSE_* macros
40
41#ifndef WX_PRECOMP
42#include <wx/app.h>
43#include <wx/event.h>
44#include <wx/image.h>
45#include <wx/intl.h>
46#include <wx/sizer.h>
47#include <wx/tooltip.h>
48#endif
49
50#include "AllThemeResources.h"
51#include "ImageManipulation.h"
52#include "../Menus.h"
53#include "Prefs.h"
54#include "Project.h"
55#include "UndoManager.h"
56#include "../widgets/AButton.h"
57
58#include "../commands/CommandContext.h"
59#include "../commands/CommandManager.h"
60#include "../commands/CommandDispatch.h"
61
63
64const int BUTTON_WIDTH = 27;
65const int SEPARATOR_WIDTH = 14;
66
70
71BEGIN_EVENT_TABLE( EditToolBar, ToolBar )
75 EditToolBar::OnButton )
77
78//Standard constructor
80: ToolBar(project, EditBarID, XO("Edit"), wxT("Edit"))
81{
82}
83
85{
86}
87
88void EditToolBar::Create(wxWindow * parent)
89{
90 ToolBar::Create(parent);
92}
93
95{
96 mToolSizer->AddSpacer(0);
97}
98
103 EditToolBar *pBar,
104 teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
105 int id,
107 bool toggle)
108{
109 AButton *&r = pBar->mButtons[id];
110
111 r = ToolBar::MakeButton(pBar,
112 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
113 eEnabledUp, eEnabledDown, eDisabled,
114 wxWindowID(id+first_ETB_ID),
115 wxDefaultPosition,
116 toggle,
117 theTheme.ImageSize( bmpRecoloredUpSmall ));
118
119 r->SetLabel(label);
120 pBar->mToolSizer->Add(r);
121
122 return r;
123}
124
126{
127 SetBackgroundColour( theTheme.Colour( clrMedium ) );
129
130 Add(mToolSizer = safenew wxGridSizer(2, 5, 1, 1));
131
132 /* Buttons */
133 // Tooltips match menu entries.
134 // We previously had longer tooltips which were not more clear.
135 AddButton(this, bmpZoomIn, bmpZoomIn, bmpZoomInDisabled, ETBZoomInID,
136 XO("Zoom In"));
137 AddButton(this, bmpZoomOut, bmpZoomOut, bmpZoomOutDisabled, ETBZoomOutID,
138 XO("Zoom Out"));
139 AddButton(this, bmpZoomSel, bmpZoomSel, bmpZoomSelDisabled, ETBZoomSelID,
140 XO("Zoom to Selection"));
141 AddButton(this, bmpZoomFit, bmpZoomFit, bmpZoomFitDisabled, ETBZoomFitID,
142 XO("Fit to Width"));
143
144#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
145 AddButton(this, bmpZoomToggle, bmpZoomToggle, bmpZoomToggleDisabled, ETBZoomToggleID,
146 XO("Zoom Toggle"));
147#endif
148
149 // Tooltips slightly more verbose than the menu entries are.
150 AddButton(this, bmpTrim, bmpTrim, bmpTrimDisabled, ETBTrimID,
151 XO("Trim audio outside selection"));
152 AddButton(this, bmpSilence, bmpSilence, bmpSilenceDisabled, ETBSilenceID,
153 XO("Silence audio selection"));
154
155#ifdef OPTION_SYNC_LOCK_BUTTON
156 AddButton(this, bmpSyncLockTracksUp, bmpSyncLockTracksDown, bmpSyncLockTracksUp, ETBSyncLockID,
157 XO("Sync-Lock Tracks"), true);
158#else
159 AddSeparator();
160#endif
161
162 AddButton(this, bmpUndo, bmpUndo, bmpUndoDisabled, ETBUndoID,
163 XO("Undo"));
164 AddButton(this, bmpRedo, bmpRedo, bmpRedoDisabled, ETBRedoID,
165 XO("Redo"));
166
169#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
170 mButtons[ETBZoomToggleID]->SetEnabled(false);
171#endif
172
175
176#ifdef OPTION_SYNC_LOCK_BUTTON
177 mButtons[ETBSyncLockID]->PushDown();
178#endif
179
181}
182
184{
186
187 // Set label to pull in language change
188 SetLabel(XO("Edit"));
189
190 // Give base class a chance
192}
193
195{
197}
198
200{
202}
203
204
205static const struct Entry {
206 int tool;
210 { ETBZoomInID, wxT("ZoomIn"), XO("Zoom In") },
211 { ETBZoomOutID, wxT("ZoomOut"), XO("Zoom Out") },
212#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
213 { ETBZoomToggleID, wxT("ZoomToggle"), XO("Zoom Toggle") },
214#endif
215 { ETBZoomSelID, wxT("ZoomSel"), XO("Fit selection to width") },
216 { ETBZoomFitID, wxT("FitInWindow"), XO("Fit project to width") },
217
218 { ETBTrimID, wxT("Trim"), XO("Trim audio outside selection") },
219 { ETBSilenceID, wxT("Silence"), XO("Silence audio selection") },
220#ifdef OPTION_SYNC_LOCK_BUTTON
221 { ETBSyncLockID, wxT("SyncLock"), XO("Sync-Lock Tracks") },
222#endif
223 { ETBUndoID, wxT("Undo"), XO("Undo") },
224 { ETBRedoID, wxT("Redo"), XO("Redo") },
226
227
229{
231 CommandManager* cm = nullptr;
232
234 p = &mProject;
235 cm = &CommandManager::Get( *p );
236#ifdef OPTION_SYNC_LOCK_BUTTON
237 bool bSyncLockTracks;
238 gPrefs->Read(wxT("/GUI/SyncLockTracks"), &bSyncLockTracks, false);
239
240 if (bSyncLockTracks)
241 mButtons[ETBSyncLockID]->PushDown();
242 else
243 mButtons[ETBSyncLockID]->PopUp();
244#endif
245 }
246
247
248 for (const auto &entry : EditToolbarButtonList) {
249#if wxUSE_TOOLTIPS
250 if( Action & ETBActTooltips ){
252 entry.commandName, entry.untranslatedLabel };
254 *mButtons[entry.tool], &command, 1u );
255 }
256#endif
257 if (cm) {
258 mButtons[entry.tool]->SetEnabled(cm->GetEnabled(entry.commandName));
259 }
260 }
261}
262
263void EditToolBar::OnButton(wxCommandEvent &event)
264{
265 int id = event.GetId()-first_ETB_ID;
266 // Be sure the pop-up happens even if there are exceptions, except for buttons which toggle.
267 auto cleanup = finally( [&] { mButtons[id]->InteractionOver();});
268
270 auto &cm = CommandManager::Get( *p );
271
272 auto flags = MenuManager::Get(*p).GetUpdateFlags();
273 const CommandContext context( *p );
275 EditToolbarButtonList[id].commandName, context, flags, false);
276
277#if defined(__WXMAC__)
278 // Bug 2402
279 // LLL: It seems that on the Mac the IDLE events are processed
280 // differently than on Windows/GTK and the AdornedRulerPanel's
281 // OnPaint() method gets called sooner that expected. This is
282 // evident when zooming from this toolbar only. When zooming from
283 // the Menu or from keyboard ommand, the zooming works correctly.
284 wxTheApp->ProcessIdle();
285#endif
286}
287
289 []( AudacityProject &project ){
290 return ToolBar::Holder{ safenew EditToolBar{ project } }; }
291};
292
293#include "ToolManager.h"
294
295namespace {
297 /* i18n-hint: Clicking this menu item shows the toolbar for editing */
298 EditBarID, wxT("ShowEditTB"), XXO("&Edit Toolbar")
299};
300}
301
wxEVT_COMMAND_BUTTON_CLICKED
END_EVENT_TABLE()
bool HandleTextualCommand(CommandManager &commandManager, const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
static const struct Entry EditToolbarButtonList[]
EVT_COMMAND_RANGE(ETBZoomInID+first_ETB_ID, ETBZoomInID+first_ETB_ID+ETBNumButtons - 1, wxEVT_COMMAND_BUTTON_CLICKED, EditToolBar::OnButton) EditToolBar
Methods for EditToolBar.
Definition: EditToolBar.cpp:72
static RegisteredToolbarFactory factory
const int BUTTON_WIDTH
Definition: EditToolBar.cpp:64
const int SEPARATOR_WIDTH
Definition: EditToolBar.cpp:65
IMPLEMENT_CLASS(EditToolBar, ToolBar)
const int first_ETB_ID
Definition: EditToolBar.h:57
@ ETBZoomInID
Definition: EditToolBar.h:30
@ ETBRedoID
Definition: EditToolBar.h:52
@ ETBNumButtons
Definition: EditToolBar.h:54
@ ETBZoomSelID
Definition: EditToolBar.h:36
@ ETBUndoID
Definition: EditToolBar.h:51
@ ETBZoomOutID
Definition: EditToolBar.h:31
@ ETBTrimID
Definition: EditToolBar.h:39
@ ETBSilenceID
Definition: EditToolBar.h:40
@ ETBZoomFitID
Definition: EditToolBar.h:37
@ ETBActTooltips
Definition: EditToolBar.h:61
@ ETBActEnableDisable
Definition: EditToolBar.h:62
int teBmps
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define safenew
Definition: MemoryX.h:10
FileConfig * gPrefs
Definition: Prefs.cpp:71
static ProjectFileIORegistry::AttributeWriterEntry entry
TranslatableString label
Definition: TagsEditor.cpp:163
THEME_API Theme theTheme
Definition: Theme.cpp:82
@ EditBarID
Definition: ToolBar.h:78
int id
A wxButton with mouse-over behaviour.
Definition: AButton.h:25
void PushDown()
Definition: AButton.cpp:597
void InteractionOver()
Definition: AButton.h:122
void PopUp()
Definition: AButton.cpp:605
void SetEnabled(bool state)
Definition: AButton.h:88
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:274
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
CommandManager implements a system for organizing all user-callable commands.
static CommandManager & Get(AudacityProject &project)
bool GetEnabled(const CommandID &name)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
A ToolBar that has the edit buttons on it.
Definition: EditToolBar.h:65
void EnableDisableButtons() override
void UpdatePrefs() override
static AButton * AddButton(EditToolBar *pBar, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, const TranslatableString &label, bool toggle=false)
void Create(wxWindow *parent) override
Definition: EditToolBar.cpp:88
wxGridSizer * mToolSizer
Definition: EditToolBar.h:97
AButton * mButtons[ETBNumButtons]
Definition: EditToolBar.h:95
void RegenerateTooltips() override
void Populate() override
void AddSeparator()
Definition: EditToolBar.cpp:94
void ForAllButtons(int Action)
void OnButton(wxCommandEvent &event)
virtual ~EditToolBar()
Definition: EditToolBar.cpp:84
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:71
CommandFlag GetUpdateFlags(bool checkActive=false) const
Definition: Menus.cpp:553
wxColour & Colour(int iIndex)
wxSize ImageSize(int iIndex)
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:98
AudacityProject & mProject
Definition: ToolBar.h:235
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:686
static AButton * MakeButton(wxWindow *parent, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size)
Definition: ToolBar.cpp:840
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:398
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:802
void UpdatePrefs() override
Definition: ToolBar.cpp:605
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:475
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:102
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:898
Holds a msgid for the translation catalog; may also bind format arguments.
std::function< void()> Action
Definition: BasicUI.h:24
AttachedToolBarMenuItem sAttachment
CommandID commandName
int tool
TranslatableString untranslatedLabel