Audacity 3.2.0
ToolsToolBar.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ToolsToolBar.cpp
6
7 Dominic Mazzoni
8 Shane T. Mueller
9 Leland Lucius
10
11 See ToolsToolBar.h for details
12
13*******************************************************************//*******************************************************************/
31
32
33
34#include "ToolsToolBar.h"
35#include "ToolManager.h"
36
37// For compilers that support precompilation, includes "wx/wx.h".
38#include <wx/wxprec.h>
39
40#include <wx/setup.h> // for wxUSE_* macros
41
42#ifndef WX_PRECOMP
43#include <wx/defs.h>
44#include <wx/sizer.h>
45#endif
46#include <wx/tooltip.h>
47
48#include "Prefs.h"
49#include "AllThemeResources.h"
50#include "ImageManipulation.h"
51#include "Project.h"
52#include "../ProjectSettings.h"
53#include "../tracks/ui/Scrubbing.h"
54#include "Viewport.h"
55
56#include "../widgets/AButton.h"
57
58
60
64
65BEGIN_EVENT_TABLE(ToolsToolBar, ToolBar)
69 ToolsToolBar::OnTool)
71
73{
74 return wxT("Tools");
75}
76
77//Standard constructor
79: ToolBar(project, XO("Tools"), ID())
80{
81 using namespace ToolCodes;
82
83 //Read the following wxASSERTs as documentating a design decision
84 wxASSERT( selectTool == selectTool - firstTool );
85 wxASSERT( envelopeTool == envelopeTool - firstTool );
86 wxASSERT( drawTool == drawTool - firstTool );
87 wxASSERT( multiTool == multiTool - firstTool );
88 bool multiToolActive = false;
89 gPrefs->Read(wxT("/GUI/ToolBars/Tools/MultiToolActive"), &multiToolActive);
90
91 if (multiToolActive)
93 else
95
98}
99
101{
102 static_assert(
104 "mismatch in number of tools" );
105}
106
108{
109 auto &toolManager = ToolManager::Get( project );
110 return *static_cast<ToolsToolBar*>(toolManager.GetToolBar(ID()));
111}
112
114{
115 return Get( const_cast<AudacityProject&>( project )) ;
116}
117
119{
120
121// JKC:
122// Under Win98 Tooltips appear to be buggy, when you have a lot of
123// tooltip messages flying around. I found that just creating a
124// twelfth tooltip caused Audacity to crash when it tried to show
125// any tooltip.
126//
127// Win98 does NOT recover from this crash - for any application which is
128// using tooltips will also crash thereafter... so you must reboot.
129// Rather weird.
130//
131// Getting windows to process more of its stacked up messages seems
132// to workaround the problem. The problem is not fully understood though
133// (as of April 2003).
134
135 // Vaughan, October 2003: Now we're crashing on Win2K if
136 // "Quit when closing last window" is unchecked, when we come back
137 // through here, on either of the wxSafeYield calls.
138 // James confirms that commenting them out does not cause his original problem
139 // to reappear, so they're commented out now.
140 // wxSafeYield(); //Deal with some queued up messages...
141
142 #if wxUSE_TOOLTIPS
143
144 using namespace ToolCodes;
145
146 static const struct Entry {
147 int tool;
148 CommandID commandName;
149 TranslatableString untranslatedLabel;
150 } table[] = {
151 { selectTool, wxT("SelectTool"), XO("Selection Tool") },
152 { envelopeTool, wxT("EnvelopeTool"), XO("Envelope Tool") },
153 { drawTool, wxT("DrawTool"), XO("Draw Tool") },
154 { multiTool, wxT("MultiTool"), XO("Multi-Tool") },
155 };
156
157 for (const auto &entry : table) {
159 entry.commandName, entry.untranslatedLabel };
161 *mTool[entry.tool], &command, 1u );
162 }
163 #endif
164
165 // wxSafeYield();
166 return;
167}
168
170{
173}
174
176 ToolsToolBar *pBar, teBmps eTool,
177 int id, const TranslatableString &label)
178{
179 AButton *button = ToolBar::MakeButton(pBar,
180 bmpRecoloredUpSmall,
181 bmpRecoloredDownSmall,
182 bmpRecoloredUpHiliteSmall,
183 bmpRecoloredDownSmall, // Not bmpRecoloredHiliteSmall as down is inactive.
184 eTool, eTool, eTool,
185 wxWindowID(id + FirstToolID),
186 wxDefaultPosition, true,
187 theTheme.ImageSize( bmpRecoloredUpSmall ));
188 button->SetLabel( label );
189 pBar->mToolSizer->Add( button );
190 return button;
191}
192
193
195{
196 SetBackgroundColour( theTheme.Colour( clrMedium ) );
198
199 Add(mToolSizer = safenew wxGridSizer(2, 2, 1, 1));
200
201 /* Tools */
202 using namespace ToolCodes;
203 mTool[ selectTool ] = MakeTool( this, bmpIBeam, selectTool, XO("Selection Tool") );
204 mTool[ envelopeTool ] = MakeTool( this, bmpEnvelope, envelopeTool, XO("Envelope Tool") );
205 mTool[ drawTool ] = MakeTool( this, bmpDraw, drawTool, XO("Draw Tool") );
206 mTool[ multiTool ] = MakeTool( this, bmpMulti, multiTool, XO("Multi-Tool") );
207
209
211}
212
213void ToolsToolBar::OnTool(wxCommandEvent & evt)
214{
215 // This will cause callback to OnToolChanged
216 auto iTool = evt.GetId() - ToolCodes::firstTool - FirstToolID;
217 auto pButton = mTool[iTool];
218 if (pButton->IsDown())
220 else
221 // Don't stay up
222 pButton->PushDown();
223}
224
226{
228 return;
231}
232
234{
235 auto &projectSettings = ProjectSettings::Get( mProject );
236 using namespace ToolCodes;
237 mCurrentTool = projectSettings.GetTool() - firstTool;
238 for (int i = 0; i < numTools; i++)
239 if (i == mCurrentTool)
240 mTool[i]->PushDown();
241 else
242 mTool[i]->PopUp();
243
244 gPrefs->Write(wxT("/GUI/ToolBars/Tools/MultiToolActive"),
245 mTool[multiTool]->IsDown());
246 gPrefs->Flush();
247}
248
249void ToolsToolBar::Create(wxWindow * parent)
250{
251 ToolBar::Create(parent);
252 UpdatePrefs();
253}
254
258};
259
260namespace {
262 /* i18n-hint: Clicking this menu item shows a toolbar
263 that has some tools in it */
264 ToolsToolBar::ID(), wxT("ShowToolsTB"), XXO("T&ools Toolbar"),
265};
266}
267
268// Following code injects menu items for changing the current tool
269
270#include "../TrackPanel.h"
271
272// private helper classes and functions
273namespace {
274
277{
278 auto toolbar = &ToolsToolBar::Get( project );
279 if (toolbar) {
282 }
283}
284
285}
286
288namespace {
289
290// Menu handler functions
291
293void OnSelectTool(const CommandContext &context)
294{
296}
297
299void OnEnvelopeTool(const CommandContext &context)
300{
302}
303
304void OnDrawTool(const CommandContext &context)
305{
307}
308
309void OnMultiTool(const CommandContext &context)
310{
312}
313
314void OnPrevTool(const CommandContext &context)
315{
316 auto &project = context.project;
317 auto &trackPanel = TrackPanel::Get( project );
319
320 settings.SetTool(
321 (settings.GetTool() + (ToolCodes::numTools - 1 )) % ToolCodes::numTools);
322 trackPanel.Refresh(false);
323}
324
325void OnNextTool(const CommandContext &context)
326{
327 auto &project = context.project;
328 auto &trackPanel = TrackPanel::Get( project );
330
331 settings.SetTool( (settings.GetTool() + 1) % ToolCodes::numTools );
332 trackPanel.Refresh(false);
333}
334
335using namespace MenuRegistry;
337{
338 static auto menu = std::shared_ptr{
339 Menu( wxT("Tools"), XXO("T&ools"),
340 Command( wxT("SelectTool"), XXO("&Selection Tool"), OnSelectTool,
341 AlwaysEnabledFlag, wxT("F1") ),
342 Command( wxT("EnvelopeTool"), XXO("&Envelope Tool"),
344 Command( wxT("DrawTool"), XXO("&Draw Tool"), OnDrawTool,
345 AlwaysEnabledFlag, wxT("F3") ),
346 Command( wxT("MultiTool"), XXO("&Multi Tool"), OnMultiTool,
347 AlwaysEnabledFlag, wxT("F6") ),
348 Command( wxT("PrevTool"), XXO("&Previous Tool"), OnPrevTool,
349 AlwaysEnabledFlag, wxT("A") ),
350 Command( wxT("NextTool"), XXO("&Next Tool"), OnNextTool,
351 AlwaysEnabledFlag, wxT("D") )
352 ) };
353 return menu;
354}
355
357 wxT("Optional/Extra/Part1")
358};
359}
wxEVT_COMMAND_BUTTON_CLICKED
wxT("CloseDown"))
END_EVENT_TABLE()
AttachedItem sAttachment2
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
int teBmps
static ProjectFileIORegistry::AttributeWriterEntry entry
#define safenew
Definition: MemoryX.h:9
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
TranslatableString label
Definition: TagsEditor.cpp:165
const auto project
THEME_API Theme theTheme
Definition: Theme.cpp:82
EVT_COMMAND_RANGE(ToolCodes::firstTool+FirstToolID, ToolsToolBar::numTools - 1+FirstToolID, wxEVT_COMMAND_BUTTON_CLICKED, ToolsToolBar::OnTool) Identifier ToolsToolBar
Methods for ToolsToolBar.
static RegisteredToolbarFactory factory
IMPLEMENT_CLASS(ToolsToolBar, ToolBar)
const int FirstToolID
Definition: ToolsToolBar.h:35
static Settings & settings()
Definition: TrackInfo.cpp:69
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
void PushDown()
Definition: AButton.cpp:577
void PopUp()
Definition: AButton.cpp:585
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:189
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
void SetTool(int tool)
static ProjectSettings & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Definition: Registry.h:388
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:74
AudacityProject & mProject
Definition: ToolBar.h:248
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:709
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:875
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:837
void UpdatePrefs() override
Definition: ToolBar.cpp:622
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:78
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:970
static ToolManager & Get(AudacityProject &project)
A kind of ToolBar with Tools on it.
Definition: ToolsToolBar.h:37
void UpdatePrefs() override
static AButton * MakeTool(ToolsToolBar *pBar, teBmps eTool, int id, const TranslatableString &label)
void RegenerateTooltips() override
static Identifier ID()
void DoToolChanged()
wxGridSizer * mToolSizer
Definition: ToolsToolBar.h:69
AButton * mTool[numTools]
Definition: ToolsToolBar.h:68
ToolsToolBar(AudacityProject &project)
void Create(wxWindow *parent) override
void OnTool(wxCommandEvent &evt)
static ToolsToolBar & Get(AudacityProject &project)
void Populate() override
virtual ~ToolsToolBar()
void OnToolChanged(ProjectSettingsEvent)
Observer::Subscription mSubscription
Definition: ToolsToolBar.h:67
void Refresh(bool eraseBackground=true, const wxRect *rect=(const wxRect *) NULL) override
Definition: TrackPanel.cpp:801
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:233
Holds a msgid for the translation catalog; may also bind format arguments.
void Redraw()
Definition: Viewport.cpp:748
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:32
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0
virtual bool Read(const wxString &key, bool *value) const =0
constexpr auto Command
Definition: MenuRegistry.h:456
constexpr auto Menu
Items will appear in a main toolbar menu or in a sub-menu.
Definition: MenuRegistry.h:445
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:175
AttachedToolBarMenuItem sAttachment
void OnNextTool(const CommandContext &context)
void OnPrevTool(const CommandContext &context)
void OnMultiTool(const CommandContext &context)
void OnSelectTool(const CommandContext &context)
Handler to set the select tool active.
void OnEnvelopeTool(const CommandContext &context)
Handler to set the Envelope tool active.
void SetTool(AudacityProject &project, int tool)
Called by handlers that set tools.
void OnDrawTool(const CommandContext &context)
enum ProjectSettingsEvent::Type type