Audacity  3.0.3
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 "../BatchCommands.h"
52 #include "ImageManipulation.h"
53 #include "../Menus.h"
54 #include "Prefs.h"
55 #include "Project.h"
56 #include "../UndoManager.h"
57 #include "../widgets/AButton.h"
58 
59 #include "../commands/CommandContext.h"
60 #include "../commands/CommandManager.h"
61 
63 
64 const int BUTTON_WIDTH = 27;
65 const int SEPARATOR_WIDTH = 14;
66 
70 
71 BEGIN_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 
88 void EditToolBar::Create(wxWindow * parent)
89 {
90  ToolBar::Create(parent);
91  UpdatePrefs();
92 }
93 
95 {
96  AddSpacer();
97 }
98 
103  EditToolBar *pBar,
104  teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
105  int id,
106  const TranslatableString &label,
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 // JKC: Unlike ControlToolBar, does not have a focus rect. Shouldn't it?
121 // r->SetFocusRect( r->GetRect().Deflate( 4, 4 ) );
122 
123  pBar->Add( r, 0, wxALIGN_CENTER );
124 
125  return r;
126 }
127 
129 {
130  SetBackgroundColour( theTheme.Colour( clrMedium ) );
132 
133  /* Buttons */
134  // Tooltips slightly more verbose than the menu entries are.
135  AddButton(this, bmpCut, bmpCut, bmpCutDisabled, ETBCutID,
136  XO("Cut selection"));
137  AddButton(this, bmpCopy, bmpCopy, bmpCopyDisabled, ETBCopyID,
138  XO("Copy selection"));
139  AddButton(this, bmpPaste, bmpPaste, bmpPasteDisabled, ETBPasteID,
140  XO("Paste"));
141  AddButton(this, bmpTrim, bmpTrim, bmpTrimDisabled, ETBTrimID,
142  XO("Trim audio outside selection"));
143  AddButton(this, bmpSilence, bmpSilence, bmpSilenceDisabled, ETBSilenceID,
144  XO("Silence audio selection"));
145 
146  AddSeparator();
147 
148  AddButton(this, bmpUndo, bmpUndo, bmpUndoDisabled, ETBUndoID,
149  XO("Undo"));
150  AddButton(this, bmpRedo, bmpRedo, bmpRedoDisabled, ETBRedoID,
151  XO("Redo"));
152 
153  AddSeparator();
154 
155 #ifdef OPTION_SYNC_LOCK_BUTTON
156  AddButton(this, bmpSyncLockTracksUp, bmpSyncLockTracksDown, bmpSyncLockTracksUp, ETBSyncLockID,
157  XO("Sync-Lock Tracks"), true);
158 
159  AddSeparator();
160 #endif
161 
162  // Tooltips match menu entries.
163  // We previously had longer tooltips which were not more clear.
164  AddButton(this, bmpZoomIn, bmpZoomIn, bmpZoomInDisabled, ETBZoomInID,
165  XO("Zoom In"));
166  AddButton(this, bmpZoomOut, bmpZoomOut, bmpZoomOutDisabled, ETBZoomOutID,
167  XO("Zoom Out"));
168  AddButton(this, bmpZoomSel, bmpZoomSel, bmpZoomSelDisabled, ETBZoomSelID,
169  XO("Zoom to Selection"));
170  AddButton(this, bmpZoomFit, bmpZoomFit, bmpZoomFitDisabled, ETBZoomFitID,
171  XO("Fit to Width"));
172 
173 #ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
174  AddButton(this, bmpZoomToggle, bmpZoomToggle, bmpZoomToggleDisabled, ETBZoomToggleID,
175  XO("Zoom Toggle"));
176 #endif
177 
178 
179 
182 #ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
183  mButtons[ETBZoomToggleID]->SetEnabled(false);
184 #endif
185 
188  mButtons[ETBPasteID]->SetEnabled(false);
189 
190 #ifdef OPTION_SYNC_LOCK_BUTTON
191  mButtons[ETBSyncLockID]->PushDown();
192 #endif
193 
194 #if defined(EXPERIMENTAL_EFFECTS_RACK)
195  AddSeparator();
196  AddButton(this, bmpEditEffects, bmpEditEffects, bmpEditEffects, ETBEffectsID,
197  XO("Show Effects Rack"), true);
198 #endif
199 
201 }
202 
204 {
206 
207  // Set label to pull in language change
208  SetLabel(XO("Edit"));
209 
210  // Give base class a chance
212 }
213 
215 {
217 }
218 
220 {
222 }
223 
224 
225 static const struct Entry {
226  int tool;
229 } EditToolbarButtonList[] = {
230  { ETBCutID, wxT("Cut"), XO("Cut") },
231  { ETBCopyID, wxT("Copy"), XO("Copy") },
232  { ETBPasteID, wxT("Paste"), XO("Paste") },
233  { ETBTrimID, wxT("Trim"), XO("Trim audio outside selection") },
234  { ETBSilenceID, wxT("Silence"), XO("Silence audio selection") },
235  { ETBUndoID, wxT("Undo"), XO("Undo") },
236  { ETBRedoID, wxT("Redo"), XO("Redo") },
237 
238 #ifdef OPTION_SYNC_LOCK_BUTTON
239  { ETBSyncLockID, wxT("SyncLock"), XO("Sync-Lock Tracks") },
240 #endif
241 
242  { ETBZoomInID, wxT("ZoomIn"), XO("Zoom In") },
243  { ETBZoomOutID, wxT("ZoomOut"), XO("Zoom Out") },
244 #ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
245  { ETBZoomToggleID, wxT("ZoomToggle"), XO("Zoom Toggle") },
246 #endif
247  { ETBZoomSelID, wxT("ZoomSel"), XO("Fit selection to width") },
248  { ETBZoomFitID, wxT("FitInWindow"), XO("Fit project to width") },
249 
250 #if defined(EXPERIMENTAL_EFFECTS_RACK)
251  { ETBEffectsID, wxT("ShowEffectsRack"), XO("Open Effects Rack") },
252 #endif
253 };
254 
255 
257 {
258  AudacityProject *p;
259  CommandManager* cm = nullptr;
260 
261  if( Action & ETBActEnableDisable ){
262  p = &mProject;
263  cm = &CommandManager::Get( *p );
264 #ifdef OPTION_SYNC_LOCK_BUTTON
265  bool bSyncLockTracks;
266  gPrefs->Read(wxT("/GUI/SyncLockTracks"), &bSyncLockTracks, false);
267 
268  if (bSyncLockTracks)
269  mButtons[ETBSyncLockID]->PushDown();
270  else
271  mButtons[ETBSyncLockID]->PopUp();
272 #endif
273  }
274 
275 
276  for (const auto &entry : EditToolbarButtonList) {
277 #if wxUSE_TOOLTIPS
278  if( Action & ETBActTooltips ){
279  ComponentInterfaceSymbol command{
280  entry.commandName, entry.untranslatedLabel };
282  *mButtons[entry.tool], &command, 1u );
283  }
284 #endif
285  if (cm) {
286  mButtons[entry.tool]->SetEnabled(cm->GetEnabled(entry.commandName));
287  }
288  }
289 }
290 
291 void EditToolBar::OnButton(wxCommandEvent &event)
292 {
293  int id = event.GetId()-first_ETB_ID;
294  // Be sure the pop-up happens even if there are exceptions, except for buttons which toggle.
295  auto cleanup = finally( [&] { mButtons[id]->InteractionOver();});
296 
298  auto &cm = CommandManager::Get( *p );
299 
300  auto flags = MenuManager::Get(*p).GetUpdateFlags();
301  const CommandContext context( *p );
303  EditToolbarButtonList[id].commandName, context, flags, false);
304 
305 #if defined(__WXMAC__)
306  // Bug 2402
307  // LLL: It seems that on the Mac the IDLE events are processed
308  // differently than on Windows/GTK and the AdornedRulerPanel's
309  // OnPaint() method gets called sooner that expected. This is
310  // evident when zooming from this toolbar only. When zooming from
311  // the Menu or from keyboard ommand, the zooming works correctly.
312  wxTheApp->ProcessIdle();
313 #endif
314 }
315 
317  []( AudacityProject &project ){
318  return ToolBar::Holder{ safenew EditToolBar{ project } }; }
319 };
320 
321 #include "ToolManager.h"
322 
323 namespace {
325  /* i18n-hint: Clicking this menu item shows the toolbar for editing */
326  EditBarID, wxT("ShowEditTB"), XXO("&Edit Toolbar")
327 };
328 }
329 
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
EditToolbarButtonList
static const struct Entry EditToolbarButtonList[]
AButton::SetLabel
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:274
teBmps
int teBmps
Definition: ImageManipulation.h:48
ToolManager.h
ETBPasteID
@ ETBPasteID
Definition: EditToolBar.h:31
AButton::InteractionOver
void InteractionOver()
Definition: AButton.h:122
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
AllThemeResources.h
IMPLEMENT_CLASS
IMPLEMENT_CLASS(EditToolBar, ToolBar)
Project.h
AButton
A wxButton with mouse-over behaviour.
Definition: AButton.h:25
ToolBar::mProject
AudacityProject & mProject
Definition: ToolBar.h:235
ToolBar::SetLabel
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:398
AButton::PopUp
void PopUp()
Definition: AButton.cpp:605
first_ETB_ID
const int first_ETB_ID
Definition: EditToolBar.h:63
entry
static ProjectFileIORegistry::WriterEntry entry
Definition: ProjectSettings.cpp:197
EditToolBar::UpdatePrefs
void UpdatePrefs() override
Definition: EditToolBar.cpp:203
XO
#define XO(s)
Definition: Internat.h:31
ThemeBase::ImageSize
wxSize ImageSize(int iIndex)
Definition: Theme.cpp:1224
ToolBar::Holder
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:102
ETBZoomSelID
@ ETBZoomSelID
Definition: EditToolBar.h:53
ETBZoomInID
@ ETBZoomInID
Definition: EditToolBar.h:47
EditToolBar::~EditToolBar
virtual ~EditToolBar()
Definition: EditToolBar.cpp:84
ETBRedoID
@ ETBRedoID
Definition: EditToolBar.h:36
BasicUI::Action
std::function< void()> Action
Definition: BasicUI.h:24
Entry::tool
int tool
Definition: EditToolBar.cpp:226
EditToolBar::Populate
void Populate() override
Definition: EditToolBar.cpp:128
CommandManager::GetEnabled
bool GetEnabled(const CommandID &name)
Definition: CommandManager.cpp:999
AttachedToolBarMenuItem
Definition: ToolManager.h:224
EditToolBar::AddSeparator
void AddSeparator()
Definition: EditToolBar.cpp:94
Entry::commandName
CommandID commandName
Definition: EditToolBar.cpp:227
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
Entry
Definition: EditToolBar.cpp:225
EditToolBar::ForAllButtons
void ForAllButtons(int Action)
Definition: EditToolBar.cpp:256
wxEVT_COMMAND_BUTTON_CLICKED
wxEVT_COMMAND_BUTTON_CLICKED
Definition: AdornedRulerPanel.cpp:494
SEPARATOR_WIDTH
const int SEPARATOR_WIDTH
Definition: EditToolBar.cpp:65
ETBZoomFitID
@ ETBZoomFitID
Definition: EditToolBar.h:54
factory
static RegisteredToolbarFactory factory
Definition: EditToolBar.cpp:316
XXO
#define XXO(s)
Definition: Internat.h:44
AButton::SetEnabled
void SetEnabled(bool state)
Definition: AButton.h:88
ETBZoomOutID
@ ETBZoomOutID
Definition: EditToolBar.h:48
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:34
label
TranslatableString label
Definition: Tags.cpp:756
ToolBar::SetButtonToolTip
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:898
ToolBar::AddSpacer
void AddSpacer(int size=14)
Definition: ToolBar.cpp:736
EditToolBar::RegenerateTooltips
void RegenerateTooltips() override
Definition: EditToolBar.cpp:214
EditToolBar::mButtons
AButton * mButtons[ETBNumButtons]
Definition: EditToolBar.h:101
EditToolBar.h
ToolBar::UpdatePrefs
void UpdatePrefs() override
Definition: ToolBar.cpp:605
AButton::PushDown
void PushDown()
Definition: AButton.cpp:597
EditToolBar::OnButton
void OnButton(wxCommandEvent &event)
Definition: EditToolBar.cpp:291
ToolBar::Create
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:475
ETBSilenceID
@ ETBSilenceID
Definition: EditToolBar.h:33
theTheme
THEME_API Theme theTheme
Definition: Theme.cpp:79
EditToolBar::Create
void Create(wxWindow *parent) override
Definition: EditToolBar.cpp:88
ETBCopyID
@ ETBCopyID
Definition: EditToolBar.h:30
EditToolBar
A ToolBar that has the edit buttons on it.
Definition: EditToolBar.h:71
id
int id
Definition: WaveTrackControls.cpp:577
BUTTON_WIDTH
const int BUTTON_WIDTH
Definition: EditToolBar.cpp:64
RegisteredToolbarFactory
Definition: ToolBar.h:261
EditToolBar::AddButton
static AButton * AddButton(EditToolBar *pBar, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, const TranslatableString &label, bool toggle=false)
Definition: EditToolBar.cpp:102
MacroCommands::HandleTextualCommand
static bool HandleTextualCommand(CommandManager &commandManager, const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
Definition: BatchCommands.cpp:593
TaggedIdentifier< CommandIdTag, false >
ETBCutID
@ ETBCutID
Definition: EditToolBar.h:29
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
EditBarID
@ EditBarID
Definition: ToolBar.h:78
ETBUndoID
@ ETBUndoID
Definition: EditToolBar.h:35
ToolBar::MakeButtonBackgroundsSmall
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:802
ETBActEnableDisable
@ ETBActEnableDisable
Definition: EditToolBar.h:68
MenuManager::Get
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:70
CommandManager
CommandManager implements a system for organizing all user-callable commands.
Definition: CommandManager.h:59
ETBActTooltips
@ ETBActTooltips
Definition: EditToolBar.h:67
ToolBar
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:98
ThemeBase::Colour
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1189
ToolBar::MakeButton
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
ETBTrimID
@ ETBTrimID
Definition: EditToolBar.h:32
Entry::untranslatedLabel
TranslatableString untranslatedLabel
Definition: EditToolBar.cpp:228
Prefs.h
EVT_COMMAND_RANGE
EVT_COMMAND_RANGE(ETBCutID+first_ETB_ID, ETBCutID+first_ETB_ID+ETBNumButtons - 1, wxEVT_COMMAND_BUTTON_CLICKED, EditToolBar::OnButton) EditToolBar
Methods for EditToolBar.
Definition: EditToolBar.cpp:72
CommandManager::Get
static CommandManager & Get(AudacityProject &project)
Definition: CommandManager.cpp:207
safenew
#define safenew
Definition: MemoryX.h:10
EditToolBar::EnableDisableButtons
void EnableDisableButtons() override
Definition: EditToolBar.cpp:219
END_EVENT_TABLE
END_EVENT_TABLE()
anonymous_namespace{EditToolBar.cpp}::sAttachment
AttachedToolBarMenuItem sAttachment
Definition: EditToolBar.cpp:324
MenuManager::GetUpdateFlags
CommandFlag GetUpdateFlags(bool checkActive=false) const
Definition: Menus.cpp:545
ToolBar::Add
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:686
ImageManipulation.h
ETBNumButtons
@ ETBNumButtons
Definition: EditToolBar.h:60