Audacity  2.2.2
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 *******************************************************************//*******************************************************************/
32 
33 
34 #include "../Audacity.h"
35 #include "EditToolBar.h"
36 
37 // For compilers that support precompilation, includes "wx/wx.h".
38 #include <wx/wxprec.h>
39 
40 #ifndef WX_PRECOMP
41 #include <wx/event.h>
42 #include <wx/image.h>
43 #include <wx/intl.h>
44 #include <wx/sizer.h>
45 #include <wx/tooltip.h>
46 #endif
47 
48 #include "../AllThemeResources.h"
49 #include "../AudioIO.h"
50 #include "../ImageManipulation.h"
51 #include "../Internat.h"
52 #include "../Prefs.h"
53 #include "../Project.h"
54 #include "../Theme.h"
55 #include "../Track.h"
56 #include "../UndoManager.h"
57 #include "../widgets/AButton.h"
58 
59 #include "../Experimental.h"
60 
62 
63 const int BUTTON_WIDTH = 27;
64 const int SEPARATOR_WIDTH = 14;
65 
69 
70 BEGIN_EVENT_TABLE( EditToolBar, ToolBar )
72  ETBCutID + ETBNumButtons - 1,
73  wxEVT_COMMAND_BUTTON_CLICKED,
74  EditToolBar::OnButton )
76 
77 //Standard contructor
79 : ToolBar(EditBarID, _("Edit"), wxT("Edit"))
80 {
81 }
82 
84 {
85 }
86 
87 void EditToolBar::Create(wxWindow * parent)
88 {
89  ToolBar::Create(parent);
90 }
91 
93 {
94  AddSpacer();
95 }
96 
101  EditToolBar *pBar,
102  teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
103  int id,
104  const wxChar *label,
105  bool toggle)
106 {
107  AButton *&r = pBar->mButtons[id];
108 
109  r = ToolBar::MakeButton(pBar,
110  bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
111  eEnabledUp, eEnabledDown, eDisabled,
112  wxWindowID(id),
113  wxDefaultPosition,
114  toggle,
115  theTheme.ImageSize( bmpRecoloredUpSmall ));
116 
117  r->SetLabel(label);
118 // JKC: Unlike ControlToolBar, does not have a focus rect. Shouldn't it?
119 // r->SetFocusRect( r->GetRect().Deflate( 4, 4 ) );
120 
121  pBar->Add( r, 0, wxALIGN_CENTER );
122 
123  return r;
124 }
125 
127 {
128  SetBackgroundColour( theTheme.Colour( clrMedium ) );
130 
131  /* Buttons */
132  // Tooltips slightly more verbose than the menu entries are.
133  AddButton(this, bmpCut, bmpCut, bmpCutDisabled, ETBCutID,
134  _("Cut selection"));
135  AddButton(this, bmpCopy, bmpCopy, bmpCopyDisabled, ETBCopyID,
136  _("Copy selection"));
137  AddButton(this, bmpPaste, bmpPaste, bmpPasteDisabled, ETBPasteID,
138  _("Paste"));
139  AddButton(this, bmpTrim, bmpTrim, bmpTrimDisabled, ETBTrimID,
140  _("Trim audio outside selection"));
141  AddButton(this, bmpSilence, bmpSilence, bmpSilenceDisabled, ETBSilenceID,
142  _("Silence audio selection"));
143 
144  AddSeparator();
145 
146  AddButton(this, bmpUndo, bmpUndo, bmpUndoDisabled, ETBUndoID,
147  _("Undo"));
148  AddButton(this, bmpRedo, bmpRedo, bmpRedoDisabled, ETBRedoID,
149  _("Redo"));
150 
151  AddSeparator();
152 
153 #ifdef OPTION_SYNC_LOCK_BUTTON
154  AddButton(this, bmpSyncLockTracksUp, bmpSyncLockTracksDown, bmpSyncLockTracksUp, ETBSyncLockID,
155  _("Sync-Lock Tracks"), true);
156 
157  AddSeparator();
158 #endif
159 
160  // Tooltips match menu entries.
161  // We previously had longer tooltips which were not more clear.
162  AddButton(this, bmpZoomIn, bmpZoomIn, bmpZoomInDisabled, ETBZoomInID,
163  _("Zoom In"));
164  AddButton(this, bmpZoomOut, bmpZoomOut, bmpZoomOutDisabled, ETBZoomOutID,
165  _("Zoom Out"));
166  AddButton(this, bmpZoomSel, bmpZoomSel, bmpZoomSelDisabled, ETBZoomSelID,
167  _("Zoom to Selection"));
168  AddButton(this, bmpZoomFit, bmpZoomFit, bmpZoomFitDisabled, ETBZoomFitID,
169  _("Fit to Width"));
170 
171 #ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
172  AddButton(this, bmpZoomToggle, bmpZoomToggle, bmpZoomToggleDisabled, ETBZoomToggleID,
173  _("Zoom Toggle"));
174 #endif
175 
176 
177 
180 #ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
182 #endif
183 
186  mButtons[ETBPasteID]->SetEnabled(false);
187 
188 #ifdef OPTION_SYNC_LOCK_BUTTON
189  mButtons[ETBSyncLockID]->PushDown();
190 #endif
191 
192 #if defined(EXPERIMENTAL_EFFECTS_RACK)
193  AddSeparator();
194  AddButton(this, bmpEditEffects, bmpEditEffects, bmpEditEffects, ETBEffectsID,
195  _("Show Effects Rack"), true);
196 #endif
197 
199 }
200 
202 {
204 
205  // Set label to pull in language change
206  SetLabel(_("Edit"));
207 
208  // Give base class a chance
210 }
211 
213 {
215 }
216 
218 {
220 }
221 
222 
223 static const struct Entry {
224  int tool;
225  wxString commandName;
227 } EditToolbarButtonList[] = {
228  { ETBCutID, wxT("Cut"), XO("Cut") },
229  { ETBCopyID, wxT("Copy"), XO("Copy") },
230  { ETBPasteID, wxT("Paste"), XO("Paste") },
231  { ETBTrimID, wxT("Trim"), XO("Trim audio outside selection") },
232  { ETBSilenceID, wxT("Silence"), XO("Silence audio selection") },
233  { ETBUndoID, wxT("Undo"), XO("Undo") },
234  { ETBRedoID, wxT("Redo"), XO("Redo") },
235 
236 #ifdef OPTION_SYNC_LOCK_BUTTON
237  { ETBSyncLockID, wxT("SyncLock"), XO("Sync-Lock Tracks") },
238 #endif
239 
240  { ETBZoomInID, wxT("ZoomIn"), XO("Zoom In") },
241  { ETBZoomOutID, wxT("ZoomOut"), XO("Zoom Out") },
242 #ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
243  { ETBZoomToggleID, wxT("ZoomToggle"), XO("Zoom Toggle") },
244 #endif
245  { ETBZoomSelID, wxT("ZoomSel"), XO("Fit selection to width") },
246  { ETBZoomFitID, wxT("FitInWindow"), XO("Fit project to width") },
247 
248 #if defined(EXPERIMENTAL_EFFECTS_RACK)
249  { ETBEffectsID, wxT("ShowEffectsRack"), XO("Open Effects Rack") },
250 #endif
251 };
252 
253 
255 {
256  AudacityProject *p;
257  CommandManager* cm = nullptr;
258 
259  if( Action & ETBActEnableDisable ){
260  p = GetActiveProject();
261  if (!p) return;
262  cm = p->GetCommandManager();
263  if (!cm) return;
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  LocalizedCommandNameVector commands( 1u,
280  { wxGetTranslation(entry.untranslatedLabel), entry.commandName }
281  );
282  ToolBar::SetButtonToolTip(*mButtons[entry.tool], commands);
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();
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  if (!p) return;
300  if (!cm) return;
301 
302  auto flags = p->GetUpdateFlags();
303  cm->HandleTextualCommand(EditToolbarButtonList[id].commandName, flags, NoFlagsSpecifed);
304 }
305 
306 
void InteractionOver()
Definition: AButton.h:131
bool GetEnabled(const wxString &name)
void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:732
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
virtual void UpdatePrefs()
Definition: ToolBar.cpp:540
void PopUp()
Definition: AButton.cpp:525
const int BUTTON_WIDTH
Definition: EditToolBar.cpp:63
void UpdatePrefs() override
static AButton * AddButton(EditToolBar *pBar, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, const wxChar *label, bool toggle=false)
static void SetButtonToolTip(AButton &button, const LocalizedCommandNameVector &commands)
Definition: ToolBar.cpp:828
A ToolBar that has the edit buttons on it.
Definition: EditToolBar.h:71
wxString label
Definition: Tags.cpp:727
void EnableDisableButtons() override
#define XO(s)
Definition: Internat.h:30
void Create(wxWindow *parent) override
Definition: EditToolBar.cpp:87
int teBmps
Definition: Theme.h:28
wxSize ImageSize(int iIndex)
Definition: Theme.cpp:1240
CommandManager * GetCommandManager()
Definition: Project.h:328
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:770
const int SEPARATOR_WIDTH
Definition: EditToolBar.cpp:64
void AddSpacer(int size=14)
Definition: ToolBar.cpp:666
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
IMPLEMENT_CLASS(EditToolBar, ToolBar)
void AddSeparator()
Definition: EditToolBar.cpp:92
bool HandleTextualCommand(const wxString &Str, CommandFlag flags, CommandMask mask)
void Populate() override
int tool
void SetEnabled(bool state)
Definition: AButton.h:97
std::vector< LocalizedCommandName > LocalizedCommandNameVector
Definition: ToolBar.h:160
CommandManager implements a system for organizing all user-callable commands.
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:616
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:443
wxString untranslatedLabel
void OnButton(wxCommandEvent &event)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
void ForAllButtons(int Action)
AButton * mButtons[ETBNumButtons]
Definition: EditToolBar.h:101
wxString commandName
void SetLabel(const wxString &label)
Definition: ToolBar.cpp:379
EVT_COMMAND_RANGE(ETBCutID, ETBCutID+ETBNumButtons-1, wxEVT_COMMAND_BUTTON_CLICKED, EditToolBar::OnButton) EditToolBar
Methods for EditToolBar.
Definition: EditToolBar.cpp:71
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
void RegenerateTooltips() override
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1208
void PushDown()
Definition: AButton.cpp:517
END_EVENT_TABLE()
virtual ~EditToolBar()
Definition: EditToolBar.cpp:83
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed...
Definition: ToolBar.h:87
static const struct Entry EditToolbarButtonList[]
CommandFlag GetUpdateFlags(bool checkActive=false)
Definition: Menus.cpp:2034
A wxButton with mouse-over behaviour.
Definition: AButton.h:27