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
72namespace
73{
74
75AButton* MakeToolsToolBarButton(wxWindow* parent,
76 wxWindowID id,
78 const wxImage& toolIcon)
79{
80 auto button = safenew AButton(parent, FirstToolID + id);
81 button->SetButtonType(AButton::FrameButton);
82 button->SetButtonToggles(true);
83 button->SetImages(
84 theTheme.Image(bmpRecoloredUpSmall),
85 theTheme.Image(bmpRecoloredUpHiliteSmall),
86 theTheme.Image(bmpRecoloredDownSmall),
87 theTheme.Image(bmpRecoloredHiliteSmall),
88 theTheme.Image(bmpRecoloredUpSmall));
89 button->SetIcon(toolIcon);
90 button->SetFrameMid(3);
91 button->SetLabel(label);
92 button->SetMinSize(wxSize { 25, 25 });
93 button->SetMaxSize(wxSize { 25, 25 });
94 return button;
95}
96
97}
98
100{
101 return wxT("Tools");
102}
103
104//Standard constructor
106: ToolBar(project, XO("Tools"), ID())
107{
108 using namespace ToolCodes;
109
110 //Read the following wxASSERTs as documentating a design decision
111 wxASSERT( selectTool == selectTool - firstTool );
112 wxASSERT( envelopeTool == envelopeTool - firstTool );
113 wxASSERT( drawTool == drawTool - firstTool );
114 wxASSERT( multiTool == multiTool - firstTool );
115 bool multiToolActive = false;
116 gPrefs->Read(wxT("/GUI/ToolBars/Tools/MultiToolActive"), &multiToolActive);
117
118 if (multiToolActive)
120 else
122
125}
126
128{
129 static_assert(
131 "mismatch in number of tools" );
132}
133
135{
136 auto &toolManager = ToolManager::Get( project );
137 return *static_cast<ToolsToolBar*>(toolManager.GetToolBar(ID()));
138}
139
141{
142 return Get( const_cast<AudacityProject&>( project )) ;
143}
144
146{
147
148// JKC:
149// Under Win98 Tooltips appear to be buggy, when you have a lot of
150// tooltip messages flying around. I found that just creating a
151// twelfth tooltip caused Audacity to crash when it tried to show
152// any tooltip.
153//
154// Win98 does NOT recover from this crash - for any application which is
155// using tooltips will also crash thereafter... so you must reboot.
156// Rather weird.
157//
158// Getting windows to process more of its stacked up messages seems
159// to workaround the problem. The problem is not fully understood though
160// (as of April 2003).
161
162 // Vaughan, October 2003: Now we're crashing on Win2K if
163 // "Quit when closing last window" is unchecked, when we come back
164 // through here, on either of the wxSafeYield calls.
165 // James confirms that commenting them out does not cause his original problem
166 // to reappear, so they're commented out now.
167 // wxSafeYield(); //Deal with some queued up messages...
168
169 #if wxUSE_TOOLTIPS
170
171 using namespace ToolCodes;
172
173 static const struct Entry {
174 int tool;
175 CommandID commandName;
176 TranslatableString untranslatedLabel;
177 } table[] = {
178 { selectTool, wxT("SelectTool"), XO("Selection Tool") },
179 { envelopeTool, wxT("EnvelopeTool"), XO("Envelope Tool") },
180 { drawTool, wxT("DrawTool"), XO("Draw Tool") },
181 { multiTool, wxT("MultiTool"), XO("Multi-Tool") },
182 };
183
184 for (const auto &entry : table) {
186 entry.commandName, entry.untranslatedLabel };
188 *mTool[entry.tool], &command, 1u );
189 }
190 #endif
191
192 // wxSafeYield();
193 return;
194}
195
197{
200}
201
203{
204 SetBackgroundColour( theTheme.Colour( clrMedium ) );
206
207 Add(mToolSizer = safenew wxGridSizer(2, 2, toolbarSpacing, toolbarSpacing),
208 0, wxALIGN_CENTRE | wxALL, toolbarSpacing);
209
210 /* Tools */
211 using namespace ToolCodes;
212 mTool[ selectTool ] =
213 MakeToolsToolBarButton(this, selectTool, XO("Selection Tool"), theTheme.Image(bmpIBeam));
214 //MakeTool( this, bmpIBeam, selectTool, XO("Selection Tool") );
216 MakeToolsToolBarButton(this, envelopeTool, XO("Envelope Tool"), theTheme.Image(bmpEnvelope));
217 //MakeTool( this, bmpEnvelope, envelopeTool, XO("Envelope Tool") );
218 mTool[ drawTool ] =
219 MakeToolsToolBarButton(this, drawTool, XO("Draw Tool"), theTheme.Image(bmpDraw));
220 //MakeTool( this, bmpDraw, drawTool, XO("Draw Tool") );
221 mTool[ multiTool ] =
222 MakeToolsToolBarButton(this, multiTool, XO("Multi-Tool"), theTheme.Image(bmpMulti));
223 //MakeTool( this, bmpMulti, multiTool, XO("Multi-Tool") );
228
230
232}
233
234void ToolsToolBar::OnTool(wxCommandEvent & evt)
235{
236 // This will cause callback to OnToolChanged
237 auto iTool = evt.GetId() - ToolCodes::firstTool - FirstToolID;
238 auto pButton = mTool[iTool];
239 if (pButton->IsDown())
241 else
242 // Don't stay up
243 pButton->PushDown();
244}
245
247{
249 return;
252}
253
255{
256 auto &projectSettings = ProjectSettings::Get( mProject );
257 using namespace ToolCodes;
258 mCurrentTool = projectSettings.GetTool() - firstTool;
259 for (int i = 0; i < numTools; i++)
260 if (i == mCurrentTool)
261 mTool[i]->PushDown();
262 else
263 mTool[i]->PopUp();
264
265 gPrefs->Write(wxT("/GUI/ToolBars/Tools/MultiToolActive"),
266 mTool[multiTool]->IsDown());
267 gPrefs->Flush();
268}
269
270void ToolsToolBar::Create(wxWindow * parent)
271{
272 ToolBar::Create(parent);
273 UpdatePrefs();
274}
275
279};
280
281namespace {
283 /* i18n-hint: Clicking this menu item shows a toolbar
284 that has some tools in it */
285 ToolsToolBar::ID(), wxT("ShowToolsTB"), XXO("T&ools Toolbar"),
286};
287}
288
289// Following code injects menu items for changing the current tool
290
291#include "../TrackPanel.h"
292
293// private helper classes and functions
294namespace {
295
298{
299 auto toolbar = &ToolsToolBar::Get( project );
300 if (toolbar) {
303 }
304}
305
306}
307
309namespace {
310
311// Menu handler functions
312
314void OnSelectTool(const CommandContext &context)
315{
317}
318
320void OnEnvelopeTool(const CommandContext &context)
321{
323}
324
325void OnDrawTool(const CommandContext &context)
326{
328}
329
330void OnMultiTool(const CommandContext &context)
331{
333}
334
335void OnPrevTool(const CommandContext &context)
336{
337 auto &project = context.project;
338 auto &trackPanel = TrackPanel::Get( project );
340
341 settings.SetTool(
342 (settings.GetTool() + (ToolCodes::numTools - 1 )) % ToolCodes::numTools);
343 trackPanel.Refresh(false);
344}
345
346void OnNextTool(const CommandContext &context)
347{
348 auto &project = context.project;
349 auto &trackPanel = TrackPanel::Get( project );
351
352 settings.SetTool( (settings.GetTool() + 1) % ToolCodes::numTools );
353 trackPanel.Refresh(false);
354}
355
356using namespace MenuRegistry;
358{
359 static auto menu = std::shared_ptr{
360 Menu( wxT("Tools"), XXO("T&ools"),
361 Command( wxT("SelectTool"), XXO("&Selection Tool"), OnSelectTool,
362 AlwaysEnabledFlag, wxT("F1") ),
363 Command( wxT("EnvelopeTool"), XXO("&Envelope Tool"),
365 Command( wxT("DrawTool"), XXO("&Draw Tool"), OnDrawTool,
366 AlwaysEnabledFlag, wxT("F3") ),
367 Command( wxT("MultiTool"), XXO("&Multi Tool"), OnMultiTool,
368 AlwaysEnabledFlag, wxT("F6") ),
369 Command( wxT("PrevTool"), XXO("&Previous Tool"), OnPrevTool,
370 AlwaysEnabledFlag, wxT("A") ),
371 Command( wxT("NextTool"), XXO("&Next Tool"), OnNextTool,
372 AlwaysEnabledFlag, wxT("D") )
373 ) };
374 return menu;
375}
376
378 wxT("Optional/Extra/Part1")
379};
380}
wxEVT_COMMAND_BUTTON_CLICKED
wxImage(22, 22)
wxT("CloseDown"))
END_EVENT_TABLE()
AttachedItem sAttachment2
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
static ProjectFileIORegistry::AttributeWriterEntry entry
#define safenew
Definition: MemoryX.h:10
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
TranslatableString label
Definition: TagsEditor.cpp:165
const auto project
THEME_API Theme theTheme
Definition: Theme.cpp:82
static constexpr auto toolbarSpacing
Preferred spacing between inner toolbar elements.
Definition: ToolBar.h:57
static RegisteredToolbarFactory factory
IMPLEMENT_CLASS(ToolsToolBar, ToolBar)
EVT_COMMAND_RANGE(ToolCodes::firstTool+FirstToolID, ToolsToolBar::numTools - 1+FirstToolID, wxEVT_COMMAND_BUTTON_CLICKED, ToolsToolBar::OnTool) namespace
Methods for ToolsToolBar.
const int FirstToolID
Definition: ToolsToolBar.h:35
static Settings & settings()
Definition: TrackInfo.cpp:51
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
void PushDown()
Definition: AButton.cpp:664
void PopUp()
Definition: AButton.cpp:672
@ FrameButton
Definition: AButton.h:114
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)
wxImage & Image(int iIndex)
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:73
AudacityProject & mProject
Definition: ToolBar.h:247
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:709
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:819
void UpdatePrefs() override
Definition: ToolBar.cpp:622
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:77
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:934
static ToolManager & Get(AudacityProject &project)
A kind of ToolBar with Tools on it.
Definition: ToolsToolBar.h:37
void UpdatePrefs() override
void RegenerateTooltips() override
void DoToolChanged()
wxGridSizer * mToolSizer
Definition: ToolsToolBar.h:68
static Identifier ID()
AButton * mTool[numTools]
Definition: ToolsToolBar.h:67
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:66
void Refresh(bool eraseBackground=true, const wxRect *rect=(const wxRect *) NULL) override
Definition: TrackPanel.cpp:802
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
Holds a msgid for the translation catalog; may also bind format arguments.
void Redraw()
Definition: Viewport.cpp:753
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:33
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