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 #include "../commands/CommandContext.h"
61 
63 
64 const int BUTTON_WIDTH = 27;
65 const int SEPARATOR_WIDTH = 14;
66 
70 
71 BEGIN_EVENT_TABLE( EditToolBar, ToolBar )
73  ETBCutID+first_ETB_ID + ETBNumButtons - 1,
74  wxEVT_COMMAND_BUTTON_CLICKED,
75  EditToolBar::OnButton )
77 
78 //Standard contructor
80 : ToolBar(EditBarID, _("Edit"), wxT("Edit"))
81 {
82 }
83 
85 {
86 }
87 
88 void EditToolBar::Create(wxWindow * parent)
89 {
90  ToolBar::Create(parent);
91 }
92 
94 {
95  AddSpacer();
96 }
97 
102  EditToolBar *pBar,
103  teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
104  int id,
105  const wxChar *label,
106  bool toggle)
107 {
108  AButton *&r = pBar->mButtons[id];
109 
110  r = ToolBar::MakeButton(pBar,
111  bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
112  eEnabledUp, eEnabledDown, eDisabled,
113  wxWindowID(id+first_ETB_ID),
114  wxDefaultPosition,
115  toggle,
116  theTheme.ImageSize( bmpRecoloredUpSmall ));
117 
118  r->SetLabel(label);
119 // JKC: Unlike ControlToolBar, does not have a focus rect. Shouldn't it?
120 // r->SetFocusRect( r->GetRect().Deflate( 4, 4 ) );
121 
122  pBar->Add( r, 0, wxALIGN_CENTER );
123 
124  return r;
125 }
126 
128 {
129  SetBackgroundColour( theTheme.Colour( clrMedium ) );
131 
132  /* Buttons */
133  // Tooltips slightly more verbose than the menu entries are.
134  AddButton(this, bmpCut, bmpCut, bmpCutDisabled, ETBCutID,
135  _("Cut selection"));
136  AddButton(this, bmpCopy, bmpCopy, bmpCopyDisabled, ETBCopyID,
137  _("Copy selection"));
138  AddButton(this, bmpPaste, bmpPaste, bmpPasteDisabled, ETBPasteID,
139  _("Paste"));
140  AddButton(this, bmpTrim, bmpTrim, bmpTrimDisabled, ETBTrimID,
141  _("Trim audio outside selection"));
142  AddButton(this, bmpSilence, bmpSilence, bmpSilenceDisabled, ETBSilenceID,
143  _("Silence audio selection"));
144 
145  AddSeparator();
146 
147  AddButton(this, bmpUndo, bmpUndo, bmpUndoDisabled, ETBUndoID,
148  _("Undo"));
149  AddButton(this, bmpRedo, bmpRedo, bmpRedoDisabled, ETBRedoID,
150  _("Redo"));
151 
152  AddSeparator();
153 
154 #ifdef OPTION_SYNC_LOCK_BUTTON
155  AddButton(this, bmpSyncLockTracksUp, bmpSyncLockTracksDown, bmpSyncLockTracksUp, ETBSyncLockID,
156  _("Sync-Lock Tracks"), true);
157 
158  AddSeparator();
159 #endif
160 
161  // Tooltips match menu entries.
162  // We previously had longer tooltips which were not more clear.
163  AddButton(this, bmpZoomIn, bmpZoomIn, bmpZoomInDisabled, ETBZoomInID,
164  _("Zoom In"));
165  AddButton(this, bmpZoomOut, bmpZoomOut, bmpZoomOutDisabled, ETBZoomOutID,
166  _("Zoom Out"));
167  AddButton(this, bmpZoomSel, bmpZoomSel, bmpZoomSelDisabled, ETBZoomSelID,
168  _("Zoom to Selection"));
169  AddButton(this, bmpZoomFit, bmpZoomFit, bmpZoomFitDisabled, ETBZoomFitID,
170  _("Fit to Width"));
171 
172 #ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
173  AddButton(this, bmpZoomToggle, bmpZoomToggle, bmpZoomToggleDisabled, ETBZoomToggleID,
174  _("Zoom Toggle"));
175 #endif
176 
177 
178 
181 #ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
183 #endif
184 
187  mButtons[ETBPasteID]->SetEnabled(false);
188 
189 #ifdef OPTION_SYNC_LOCK_BUTTON
190  mButtons[ETBSyncLockID]->PushDown();
191 #endif
192 
193 #if defined(EXPERIMENTAL_EFFECTS_RACK)
194  AddSeparator();
195  AddButton(this, bmpEditEffects, bmpEditEffects, bmpEditEffects, ETBEffectsID,
196  _("Show Effects Rack"), true);
197 #endif
198 
200 }
201 
203 {
205 
206  // Set label to pull in language change
207  SetLabel(_("Edit"));
208 
209  // Give base class a chance
211 }
212 
214 {
216 }
217 
219 {
221 }
222 
223 
224 static const struct Entry {
225  int tool;
226  wxString commandName;
228 } EditToolbarButtonList[] = {
229  { ETBCutID, wxT("Cut"), XO("Cut") },
230  { ETBCopyID, wxT("Copy"), XO("Copy") },
231  { ETBPasteID, wxT("Paste"), XO("Paste") },
232  { ETBTrimID, wxT("Trim"), XO("Trim audio outside selection") },
233  { ETBSilenceID, wxT("Silence"), XO("Silence audio selection") },
234  { ETBUndoID, wxT("Undo"), XO("Undo") },
235  { ETBRedoID, wxT("Redo"), XO("Redo") },
236 
237 #ifdef OPTION_SYNC_LOCK_BUTTON
238  { ETBSyncLockID, wxT("SyncLock"), XO("Sync-Lock Tracks") },
239 #endif
240 
241  { ETBZoomInID, wxT("ZoomIn"), XO("Zoom In") },
242  { ETBZoomOutID, wxT("ZoomOut"), XO("Zoom Out") },
243 #ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
244  { ETBZoomToggleID, wxT("ZoomToggle"), XO("Zoom Toggle") },
245 #endif
246  { ETBZoomSelID, wxT("ZoomSel"), XO("Fit selection to width") },
247  { ETBZoomFitID, wxT("FitInWindow"), XO("Fit project to width") },
248 
249 #if defined(EXPERIMENTAL_EFFECTS_RACK)
250  { ETBEffectsID, wxT("ShowEffectsRack"), XO("Open Effects Rack") },
251 #endif
252 };
253 
254 
256 {
257  AudacityProject *p;
258  CommandManager* cm = nullptr;
259 
260  if( Action & ETBActEnableDisable ){
261  p = GetActiveProject();
262  if (!p) return;
263  cm = p->GetCommandManager();
264  if (!cm) return;
265 #ifdef OPTION_SYNC_LOCK_BUTTON
266  bool bSyncLockTracks;
267  gPrefs->Read(wxT("/GUI/SyncLockTracks"), &bSyncLockTracks, false);
268 
269  if (bSyncLockTracks)
270  mButtons[ETBSyncLockID]->PushDown();
271  else
272  mButtons[ETBSyncLockID]->PopUp();
273 #endif
274  }
275 
276 
277  for (const auto &entry : EditToolbarButtonList) {
278 #if wxUSE_TOOLTIPS
279  if( Action & ETBActTooltips ){
280  TranslatedInternalString command{
281  entry.commandName, wxGetTranslation(entry.untranslatedLabel) };
282  ToolBar::SetButtonToolTip( *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  if (!p) return;
300  if (!cm) return;
301 
302  auto flags = p->GetUpdateFlags();
303  const CommandContext context( *GetActiveProject() );
304  cm->HandleTextualCommand(EditToolbarButtonList[id].commandName, context, flags, NoFlagsSpecifed);
305 }
306 
307 
void InteractionOver()
Definition: AButton.h:132
bool GetEnabled(const wxString &name)
void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:727
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
virtual void UpdatePrefs()
Definition: ToolBar.cpp:535
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:374
void PopUp()
Definition: AButton.cpp:525
const int BUTTON_WIDTH
Definition: EditToolBar.cpp:64
void UpdatePrefs() override
static AButton * AddButton(EditToolBar *pBar, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, const wxChar *label, bool toggle=false)
A ToolBar that has the edit buttons on it.
Definition: EditToolBar.h:73
wxString label
Definition: Tags.cpp:727
bool HandleTextualCommand(const wxString &Str, const CommandContext &context, CommandFlag flags, CommandMask mask)
void EnableDisableButtons() override
#define XO(s)
Definition: Internat.h:33
void Create(wxWindow *parent) override
Definition: EditToolBar.cpp:88
int teBmps
Definition: Theme.h:28
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
wxSize ImageSize(int iIndex)
Definition: Theme.cpp:1257
CommandManager * GetCommandManager()
Definition: Project.h:346
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:765
const int SEPARATOR_WIDTH
Definition: EditToolBar.cpp:65
void AddSpacer(int size=14)
Definition: ToolBar.cpp:661
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
IMPLEMENT_CLASS(EditToolBar, ToolBar)
void AddSeparator()
Definition: EditToolBar.cpp:93
void Populate() override
int tool
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
void SetEnabled(bool state)
Definition: AButton.h:98
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:611
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:438
wxString untranslatedLabel
void OnButton(wxCommandEvent &event)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void ForAllButtons(int Action)
AButton * mButtons[ETBNumButtons]
Definition: EditToolBar.h:103
wxString commandName
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
void RegenerateTooltips() override
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
void PushDown()
Definition: AButton.cpp:517
END_EVENT_TABLE()
static void SetButtonToolTip(AButton &button, const TranslatedInternalString commands[], size_t nCommands)
Definition: ToolBar.cpp:823
const int first_ETB_ID
Definition: EditToolBar.h:65
virtual ~EditToolBar()
Definition: EditToolBar.cpp:84
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:2174
A wxButton with mouse-over behaviour.
Definition: AButton.h:28