forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditToolBar.cpp
More file actions
328 lines (259 loc) · 9.29 KB
/
Copy pathEditToolBar.cpp
File metadata and controls
328 lines (259 loc) · 9.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/**********************************************************************
Audacity: A Digital Audio Editor
EditToolBar.cpp
Dominic Mazzoni
Shane T. Mueller
Leland Lucius
See EditToolBar.h for details
*******************************************************************//*!
\class EditToolBar
\brief A ToolBar that has the edit buttons on it.
This class, which is a child of Toolbar, creates the
window containing interfaces to commonly-used edit
functions that are otherwise only available through
menus. The window can be embedded within a normal project
window, or within a ToolBarFrame.
All of the controls in this window were custom-written for
Audacity - they are not native controls on any platform -
however, it is intended that the images could be easily
replaced to allow "skinning" or just customization to
match the look and feel of each platform.
*//*******************************************************************/
#include "../Audacity.h"
#include "EditToolBar.h"
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#include <wx/setup.h> // for wxUSE_* macros
#ifndef WX_PRECOMP
#include <wx/event.h>
#include <wx/image.h>
#include <wx/intl.h>
#include <wx/sizer.h>
#include <wx/tooltip.h>
#endif
#include "../AllThemeResources.h"
#include "../BatchCommands.h"
#include "../ImageManipulation.h"
#include "../Menus.h"
#include "../Prefs.h"
#include "../Project.h"
#include "../UndoManager.h"
#include "../widgets/AButton.h"
#include "../commands/CommandContext.h"
#include "../commands/CommandManager.h"
IMPLEMENT_CLASS(EditToolBar, ToolBar);
const int BUTTON_WIDTH = 27;
const int SEPARATOR_WIDTH = 14;
////////////////////////////////////////////////////////////
/// Methods for EditToolBar
////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE( EditToolBar, ToolBar )
EVT_COMMAND_RANGE( ETBCutID+first_ETB_ID,
ETBCutID+first_ETB_ID + ETBNumButtons - 1,
wxEVT_COMMAND_BUTTON_CLICKED,
EditToolBar::OnButton )
END_EVENT_TABLE()
//Standard constructor
EditToolBar::EditToolBar( AudacityProject &project )
: ToolBar(project, EditBarID, XO("Edit"), wxT("Edit"))
{
}
EditToolBar::~EditToolBar()
{
}
void EditToolBar::Create(wxWindow * parent)
{
ToolBar::Create(parent);
UpdatePrefs();
}
void EditToolBar::AddSeparator()
{
AddSpacer();
}
/// This is a convenience function that allows for button creation in
/// MakeButtons() with fewer arguments
/// Very similar to code in ControlToolBar...
AButton *EditToolBar::AddButton(
EditToolBar *pBar,
teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
int id,
const TranslatableString &label,
bool toggle)
{
AButton *&r = pBar->mButtons[id];
r = ToolBar::MakeButton(pBar,
bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
eEnabledUp, eEnabledDown, eDisabled,
wxWindowID(id+first_ETB_ID),
wxDefaultPosition,
toggle,
theTheme.ImageSize( bmpRecoloredUpSmall ));
r->SetLabel(label);
// JKC: Unlike ControlToolBar, does not have a focus rect. Shouldn't it?
// r->SetFocusRect( r->GetRect().Deflate( 4, 4 ) );
pBar->Add( r, 0, wxALIGN_CENTER );
return r;
}
void EditToolBar::Populate()
{
SetBackgroundColour( theTheme.Colour( clrMedium ) );
MakeButtonBackgroundsSmall();
/* Buttons */
// Tooltips slightly more verbose than the menu entries are.
AddButton(this, bmpCut, bmpCut, bmpCutDisabled, ETBCutID,
XO("Cut selection"));
AddButton(this, bmpCopy, bmpCopy, bmpCopyDisabled, ETBCopyID,
XO("Copy selection"));
AddButton(this, bmpPaste, bmpPaste, bmpPasteDisabled, ETBPasteID,
XO("Paste"));
AddButton(this, bmpTrim, bmpTrim, bmpTrimDisabled, ETBTrimID,
XO("Trim audio outside selection"));
AddButton(this, bmpSilence, bmpSilence, bmpSilenceDisabled, ETBSilenceID,
XO("Silence audio selection"));
AddSeparator();
AddButton(this, bmpUndo, bmpUndo, bmpUndoDisabled, ETBUndoID,
XO("Undo"));
AddButton(this, bmpRedo, bmpRedo, bmpRedoDisabled, ETBRedoID,
XO("Redo"));
AddSeparator();
#ifdef OPTION_SYNC_LOCK_BUTTON
AddButton(this, bmpSyncLockTracksUp, bmpSyncLockTracksDown, bmpSyncLockTracksUp, ETBSyncLockID,
XO("Sync-Lock Tracks"), true);
AddSeparator();
#endif
// Tooltips match menu entries.
// We previously had longer tooltips which were not more clear.
AddButton(this, bmpZoomIn, bmpZoomIn, bmpZoomInDisabled, ETBZoomInID,
XO("Zoom In"));
AddButton(this, bmpZoomOut, bmpZoomOut, bmpZoomOutDisabled, ETBZoomOutID,
XO("Zoom Out"));
AddButton(this, bmpZoomSel, bmpZoomSel, bmpZoomSelDisabled, ETBZoomSelID,
XO("Zoom to Selection"));
AddButton(this, bmpZoomFit, bmpZoomFit, bmpZoomFitDisabled, ETBZoomFitID,
XO("Fit to Width"));
#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
AddButton(this, bmpZoomToggle, bmpZoomToggle, bmpZoomToggleDisabled, ETBZoomToggleID,
XO("Zoom Toggle"));
#endif
mButtons[ETBZoomInID]->SetEnabled(false);
mButtons[ETBZoomOutID]->SetEnabled(false);
#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
mButtons[ETBZoomToggleID]->SetEnabled(false);
#endif
mButtons[ETBZoomSelID]->SetEnabled(false);
mButtons[ETBZoomFitID]->SetEnabled(false);
mButtons[ETBPasteID]->SetEnabled(false);
#ifdef OPTION_SYNC_LOCK_BUTTON
mButtons[ETBSyncLockID]->PushDown();
#endif
#if defined(EXPERIMENTAL_EFFECTS_RACK)
AddSeparator();
AddButton(this, bmpEditEffects, bmpEditEffects, bmpEditEffects, ETBEffectsID,
XO("Show Effects Rack"), true);
#endif
RegenerateTooltips();
}
void EditToolBar::UpdatePrefs()
{
RegenerateTooltips();
// Set label to pull in language change
SetLabel(XO("Edit"));
// Give base class a chance
ToolBar::UpdatePrefs();
}
void EditToolBar::RegenerateTooltips()
{
ForAllButtons( ETBActTooltips );
}
void EditToolBar::EnableDisableButtons()
{
ForAllButtons( ETBActEnableDisable );
}
static const struct Entry {
int tool;
CommandID commandName;
TranslatableString untranslatedLabel;
} EditToolbarButtonList[] = {
{ ETBCutID, wxT("Cut"), XO("Cut") },
{ ETBCopyID, wxT("Copy"), XO("Copy") },
{ ETBPasteID, wxT("Paste"), XO("Paste") },
{ ETBTrimID, wxT("Trim"), XO("Trim audio outside selection") },
{ ETBSilenceID, wxT("Silence"), XO("Silence audio selection") },
{ ETBUndoID, wxT("Undo"), XO("Undo") },
{ ETBRedoID, wxT("Redo"), XO("Redo") },
#ifdef OPTION_SYNC_LOCK_BUTTON
{ ETBSyncLockID, wxT("SyncLock"), XO("Sync-Lock Tracks") },
#endif
{ ETBZoomInID, wxT("ZoomIn"), XO("Zoom In") },
{ ETBZoomOutID, wxT("ZoomOut"), XO("Zoom Out") },
#ifdef EXPERIMENTAL_ZOOM_TOGGLE_BUTTON
{ ETBZoomToggleID, wxT("ZoomToggle"), XO("Zoom Toggle") },
#endif
{ ETBZoomSelID, wxT("ZoomSel"), XO("Fit selection to width") },
{ ETBZoomFitID, wxT("FitInWindow"), XO("Fit project to width") },
#if defined(EXPERIMENTAL_EFFECTS_RACK)
{ ETBEffectsID, wxT("ShowEffectsRack"), XO("Open Effects Rack") },
#endif
};
void EditToolBar::ForAllButtons(int Action)
{
AudacityProject *p;
CommandManager* cm = nullptr;
if( Action & ETBActEnableDisable ){
p = &mProject;
cm = &CommandManager::Get( *p );
#ifdef OPTION_SYNC_LOCK_BUTTON
bool bSyncLockTracks;
gPrefs->Read(wxT("/GUI/SyncLockTracks"), &bSyncLockTracks, false);
if (bSyncLockTracks)
mButtons[ETBSyncLockID]->PushDown();
else
mButtons[ETBSyncLockID]->PopUp();
#endif
}
for (const auto &entry : EditToolbarButtonList) {
#if wxUSE_TOOLTIPS
if( Action & ETBActTooltips ){
ComponentInterfaceSymbol command{
entry.commandName, entry.untranslatedLabel };
ToolBar::SetButtonToolTip( mProject,
*mButtons[entry.tool], &command, 1u );
}
#endif
if (cm) {
mButtons[entry.tool]->SetEnabled(cm->GetEnabled(entry.commandName));
}
}
}
void EditToolBar::OnButton(wxCommandEvent &event)
{
int id = event.GetId()-first_ETB_ID;
// Be sure the pop-up happens even if there are exceptions, except for buttons which toggle.
auto cleanup = finally( [&] { mButtons[id]->InteractionOver();});
AudacityProject *p = &mProject;
auto &cm = CommandManager::Get( *p );
auto flags = MenuManager::Get(*p).GetUpdateFlags();
const CommandContext context( *p );
MacroCommands::HandleTextualCommand( cm,
EditToolbarButtonList[id].commandName, context, flags, false);
#if defined(__WXMAC__)
// Bug 2402
// LLL: It seems that on the Mac the IDLE events are processed
// differently than on Windows/GTK and the AdornedRulerPanel's
// OnPaint() method gets called sooner that expected. This is
// evident when zooming from this toolbar only. When zooming from
// the Menu or from keyboard ommand, the zooming works correctly.
wxTheApp->ProcessIdle();
#endif
}
static RegisteredToolbarFactory factory{ EditBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{ safenew EditToolBar{ project } }; }
};
#include "ToolManager.h"
namespace {
AttachedToolBarMenuItem sAttachment{
/* i18n-hint: Clicking this menu item shows the toolbar for editing */
EditBarID, wxT("ShowEditTB"), XXO("&Edit Toolbar")
};
}