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
67
68BEGIN_EVENT_TABLE( EditToolBar, ToolBar )
72 EditToolBar::OnButton )
74
75//Standard constructor
77: ToolBar(project, EditBarID, XO("Edit"), wxT("Edit"))
78{
79}
80
82{
83}
84
85void EditToolBar::Create(wxWindow * parent)
86{
87 ToolBar::Create(parent);
89}
90
92{
93 mToolSizer->AddSpacer(0);
94}
95
100 EditToolBar *pBar,
101 teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
102 int id,
104 bool toggle)
105{
106 AButton *&r = pBar->mButtons[id];
107
108 r = ToolBar::MakeButton(pBar,
109 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
110 eEnabledUp, eEnabledDown, eDisabled,
111 wxWindowID(id+first_ETB_ID),
112 wxDefaultPosition,
113 toggle,
114 theTheme.ImageSize( bmpRecoloredUpSmall ));
115
116 r->SetLabel(label);
117 pBar->mToolSizer->Add(r);
118
119 return r;
120}
121
123{
124 SetBackgroundColour( theTheme.Colour( clrMedium ) );
126
127 Add(mToolSizer = safenew wxGridSizer(2, 5, 1, 1));
128
129 /* Buttons */
130 // Tooltips match menu entries.
131 // We previously had longer tooltips which were not more clear.
132 AddButton(this, bmpZoomIn, bmpZoomIn, bmpZoomInDisabled, ETBZoomInID,
133 XO("Zoom In"));
134 AddButton(this, bmpZoomOut, bmpZoomOut, bmpZoomOutDisabled, ETBZoomOutID,
135 XO("Zoom Out"));
136 AddButton(this, bmpZoomSel, bmpZoomSel, bmpZoomSelDisabled, ETBZoomSelID,
137 XO("Zoom to Selection"));
138 AddButton(this, bmpZoomFit, bmpZoomFit, bmpZoomFitDisabled, ETBZoomFitID,
139 XO("Fit to Width"));
140
141#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
142 AddButton(this, bmpZoomToggle, bmpZoomToggle, bmpZoomToggleDisabled, ETBZoomToggleID,
143 XO("Zoom Toggle"));
144#endif
145
146 // Tooltips slightly more verbose than the menu entries are.
147 AddButton(this, bmpTrim, bmpTrim, bmpTrimDisabled, ETBTrimID,
148 XO("Trim audio outside selection"));
149 AddButton(this, bmpSilence, bmpSilence, bmpSilenceDisabled, ETBSilenceID,
150 XO("Silence audio selection"));
151
152#ifdef OPTION_SYNC_LOCK_BUTTON
153 AddButton(this, bmpSyncLockTracksUp, bmpSyncLockTracksDown, bmpSyncLockTracksUp, ETBSyncLockID,
154 XO("Sync-Lock Tracks"), true);
155#else
156 AddSeparator();
157#endif
158
159 AddButton(this, bmpUndo, bmpUndo, bmpUndoDisabled, ETBUndoID,
160 XO("Undo"));
161 AddButton(this, bmpRedo, bmpRedo, bmpRedoDisabled, ETBRedoID,
162 XO("Redo"));
163
166#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
167 mButtons[ETBZoomToggleID]->SetEnabled(false);
168#endif
169
172
173#ifdef OPTION_SYNC_LOCK_BUTTON
174 mButtons[ETBSyncLockID]->PushDown();
175#endif
176
178}
179
181{
183
184 // Set label to pull in language change
185 SetLabel(XO("Edit"));
186
187 // Give base class a chance
189}
190
192{
194}
195
197{
199}
200
201
202static const struct Entry {
203 int tool;
207 { ETBZoomInID, wxT("ZoomIn"), XO("Zoom In") },
208 { ETBZoomOutID, wxT("ZoomOut"), XO("Zoom Out") },
209#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
210 { ETBZoomToggleID, wxT("ZoomToggle"), XO("Zoom Toggle") },
211#endif
212 { ETBZoomSelID, wxT("ZoomSel"), XO("Fit selection to width") },
213 { ETBZoomFitID, wxT("FitInWindow"), XO("Fit project to width") },
214
215 { ETBTrimID, wxT("Trim"), XO("Trim audio outside selection") },
216 { ETBSilenceID, wxT("Silence"), XO("Silence audio selection") },
217#ifdef OPTION_SYNC_LOCK_BUTTON
218 { ETBSyncLockID, wxT("SyncLock"), XO("Sync-Lock Tracks") },
219#endif
220 { ETBUndoID, wxT("Undo"), XO("Undo") },
221 { ETBRedoID, wxT("Redo"), XO("Redo") },
223
224
226{
228 CommandManager* cm = nullptr;
229
231 p = &mProject;
232 cm = &CommandManager::Get( *p );
233#ifdef OPTION_SYNC_LOCK_BUTTON
234 bool bSyncLockTracks;
235 gPrefs->Read(wxT("/GUI/SyncLockTracks"), &bSyncLockTracks, false);
236
237 if (bSyncLockTracks)
238 mButtons[ETBSyncLockID]->PushDown();
239 else
240 mButtons[ETBSyncLockID]->PopUp();
241#endif
242 }
243
244
245 for (const auto &entry : EditToolbarButtonList) {
246#if wxUSE_TOOLTIPS
247 if( Action & ETBActTooltips ){
249 entry.commandName, entry.untranslatedLabel };
251 *mButtons[entry.tool], &command, 1u );
252 }
253#endif
254 if (cm) {
255 mButtons[entry.tool]->SetEnabled(cm->GetEnabled(entry.commandName));
256 }
257 }
258}
259
260void EditToolBar::OnButton(wxCommandEvent &event)
261{
262 int id = event.GetId()-first_ETB_ID;
263 // Be sure the pop-up happens even if there are exceptions, except for buttons which toggle.
264 auto cleanup = finally( [&] { mButtons[id]->InteractionOver();});
265
267 auto &cm = CommandManager::Get( *p );
268
269 auto flags = MenuManager::Get(*p).GetUpdateFlags();
270 const CommandContext context( *p );
272 EditToolbarButtonList[id].commandName, context, flags, false);
273
274#if defined(__WXMAC__)
275 // Bug 2402
276 // LLL: It seems that on the Mac the IDLE events are processed
277 // differently than on Windows/GTK and the AdornedRulerPanel's
278 // OnPaint() method gets called sooner that expected. This is
279 // evident when zooming from this toolbar only. When zooming from
280 // the Menu or from keyboard ommand, the zooming works correctly.
281 wxTheApp->ProcessIdle();
282#endif
283}
284
286 []( AudacityProject &project ){
287 return ToolBar::Holder{ safenew EditToolBar{ project } }; }
288};
289
290#include "ToolManager.h"
291
292namespace {
294 /* i18n-hint: Clicking this menu item shows the toolbar for editing */
295 EditBarID, wxT("ShowEditTB"), XXO("&Edit Toolbar")
296};
297}
298
wxEVT_COMMAND_BUTTON_CLICKED
wxT("CloseDown"))
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:69
static RegisteredToolbarFactory factory
IMPLEMENT_CLASS(EditToolBar, ToolBar)
const int first_ETB_ID
Definition: EditToolBar.h:57
@ ETBActTooltips
Definition: EditToolBar.h:61
@ ETBActEnableDisable
Definition: EditToolBar.h:62
@ 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
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:77
int id
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
void PushDown()
Definition: AButton.cpp:580
void InteractionOver()
Definition: AButton.h:218
void PopUp()
Definition: AButton.cpp:588
void SetEnabled(bool state)
Definition: AButton.h:182
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:192
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)
Definition: EditToolBar.cpp:99
void Create(wxWindow *parent) override
Definition: EditToolBar.cpp:85
wxGridSizer * mToolSizer
Definition: EditToolBar.h:97
AButton * mButtons[ETBNumButtons]
Definition: EditToolBar.h:95
void RegenerateTooltips() override
void Populate() override
void AddSeparator()
Definition: EditToolBar.cpp:91
void ForAllButtons(int Action)
void OnButton(wxCommandEvent &event)
virtual ~EditToolBar()
Definition: EditToolBar.cpp:81
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:101
AudacityProject & mProject
Definition: ToolBar.h:251
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:695
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:861
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:407
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:823
void UpdatePrefs() override
Definition: ToolBar.cpp:614
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:484
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:105
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:956
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