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/event.h>
45#include <wx/intl.h>
46#include <wx/sizer.h>
47#endif
48#include <wx/tooltip.h>
49
50#include "Prefs.h"
51#include "AllThemeResources.h"
52#include "ImageManipulation.h"
53#include "Project.h"
54#include "../ProjectSettings.h"
55#include "../ProjectWindow.h"
56#include "../tracks/ui/Scrubbing.h"
57
58#include "../widgets/AButton.h"
59
60
62
66
67BEGIN_EVENT_TABLE(ToolsToolBar, ToolBar)
71 ToolsToolBar::OnTool)
73
74//Standard constructor
76: ToolBar(project, ToolsBarID, XO("Tools"), wxT("Tools"))
77{
78 using namespace ToolCodes;
79
80 //Read the following wxASSERTs as documentating a design decision
81 wxASSERT( selectTool == selectTool - firstTool );
82 wxASSERT( envelopeTool == envelopeTool - firstTool );
83 wxASSERT( drawTool == drawTool - firstTool );
84 wxASSERT( multiTool == multiTool - firstTool );
85 bool multiToolActive = false;
86 gPrefs->Read(wxT("/GUI/ToolBars/Tools/MultiToolActive"), &multiToolActive);
87
88 if (multiToolActive)
89 mCurrentTool = multiTool;
90 else
91 mCurrentTool = selectTool;
92
93 project.Bind(EVT_PROJECT_SETTINGS_CHANGE,
95}
96
98{
99 static_assert(
101 "mismatch in number of tools" );
102}
103
105{
106 auto &toolManager = ToolManager::Get( project );
107 return *static_cast<ToolsToolBar*>( toolManager.GetToolBar(ToolsBarID) );
108}
109
111{
112 return Get( const_cast<AudacityProject&>( project )) ;
113}
114
116{
117
118// JKC:
119// Under Win98 Tooltips appear to be buggy, when you have a lot of
120// tooltip messages flying around. I found that just creating a
121// twelfth tooltip caused Audacity to crash when it tried to show
122// any tooltip.
123//
124// Win98 does NOT recover from this crash - for any application which is
125// using tooltips will also crash thereafter... so you must reboot.
126// Rather weird.
127//
128// Getting windows to process more of its stacked up messages seems
129// to workaround the problem. The problem is not fully understood though
130// (as of April 2003).
131
132 // Vaughan, October 2003: Now we're crashing on Win2K if
133 // "Quit when closing last window" is unchecked, when we come back
134 // through here, on either of the wxSafeYield calls.
135 // James confirms that commenting them out does not cause his original problem
136 // to reappear, so they're commented out now.
137 // wxSafeYield(); //Deal with some queued up messages...
138
139 #if wxUSE_TOOLTIPS
140
141 using namespace ToolCodes;
142
143 static const struct Entry {
144 int tool;
145 CommandID commandName;
146 TranslatableString untranslatedLabel;
147 } table[] = {
148 { selectTool, wxT("SelectTool"), XO("Selection Tool") },
149 { envelopeTool, wxT("EnvelopeTool"), XO("Envelope Tool") },
150 { drawTool, wxT("DrawTool"), XO("Draw Tool") },
151 { multiTool, wxT("MultiTool"), XO("Multi-Tool") },
152 };
153
154 for (const auto &entry : table) {
156 entry.commandName, entry.untranslatedLabel };
158 *mTool[entry.tool], &command, 1u );
159 }
160 #endif
161
162 // wxSafeYield();
163 return;
164}
165
167{
170}
171
173 ToolsToolBar *pBar, teBmps eTool,
174 int id, const TranslatableString &label)
175{
176 AButton *button = ToolBar::MakeButton(pBar,
177 bmpRecoloredUpSmall,
178 bmpRecoloredDownSmall,
179 bmpRecoloredUpHiliteSmall,
180 bmpRecoloredDownSmall, // Not bmpRecoloredHiliteSmall as down is inactive.
181 eTool, eTool, eTool,
182 wxWindowID(id + FirstToolID),
183 wxDefaultPosition, true,
184 theTheme.ImageSize( bmpRecoloredUpSmall ));
185 button->SetLabel( label );
186 pBar->mToolSizer->Add( button );
187 return button;
188}
189
190
192{
193 SetBackgroundColour( theTheme.Colour( clrMedium ) );
195
196 Add(mToolSizer = safenew wxGridSizer(2, 2, 1, 1));
197
198 /* Tools */
199 using namespace ToolCodes;
200 mTool[ selectTool ] = MakeTool( this, bmpIBeam, selectTool, XO("Selection Tool") );
201 mTool[ envelopeTool ] = MakeTool( this, bmpEnvelope, envelopeTool, XO("Envelope Tool") );
202 mTool[ drawTool ] = MakeTool( this, bmpDraw, drawTool, XO("Draw Tool") );
203 mTool[ multiTool ] = MakeTool( this, bmpMulti, multiTool, XO("Multi-Tool") );
204
206
208}
209
210void ToolsToolBar::OnTool(wxCommandEvent & evt)
211{
212 // This will cause callback to OnToolChanged
213 auto iTool = evt.GetId() - ToolCodes::firstTool - FirstToolID;
214 auto pButton = mTool[iTool];
215 if (pButton->IsDown())
217 else
218 // Don't stay up
219 pButton->PushDown();
220}
221
222void ToolsToolBar::OnToolChanged(wxCommandEvent &evt)
223{
224 evt.Skip(); // Let other listeners hear the event too
225 if (evt.GetInt() != ProjectSettings::ChangedTool)
226 return;
229}
230
232{
233 auto &projectSettings = ProjectSettings::Get( mProject );
234 using namespace ToolCodes;
235 mCurrentTool = projectSettings.GetTool() - firstTool;
236 for (int i = 0; i < numTools; i++)
237 if (i == mCurrentTool)
238 mTool[i]->PushDown();
239 else
240 mTool[i]->PopUp();
241
242 gPrefs->Write(wxT("/GUI/ToolBars/Tools/MultiToolActive"),
243 mTool[multiTool]->IsDown());
244 gPrefs->Flush();
245}
246
247void ToolsToolBar::Create(wxWindow * parent)
248{
249 ToolBar::Create(parent);
250 UpdatePrefs();
251}
252
254 []( AudacityProject &project ){
255 return ToolBar::Holder{ safenew ToolsToolBar{ project } }; }
256};
257
258namespace {
260 /* i18n-hint: Clicking this menu item shows a toolbar
261 that has some tools in it */
262 ToolsBarID, wxT("ShowToolsTB"), XXO("T&ools Toolbar"),
263};
264}
265
266// Following code injects menu items for changing the current tool
267
268#include "../TrackPanel.h"
269
270// private helper classes and functions
271namespace {
272
274void SetTool(AudacityProject &project, int tool)
275{
276 auto toolbar = &ToolsToolBar::Get( project );
277 if (toolbar) {
278 ProjectSettings::Get(project).SetTool(tool);
279 TrackPanel::Get( project ).Refresh(false);
280 }
281}
282
283}
284
286namespace ToolActions {
287
288// exported helper functions
289// none
290
291// Menu handler functions
292
295void OnSelectTool(const CommandContext &context)
296{
298}
299
301void OnEnvelopeTool(const CommandContext &context)
302{
304}
305
306void OnDrawTool(const CommandContext &context)
307{
309}
310
311void OnMultiTool(const CommandContext &context)
312{
314}
315
316void OnPrevTool(const CommandContext &context)
317{
318 auto &project = context.project;
319 auto &trackPanel = TrackPanel::Get( project );
320 auto &settings = ProjectSettings::Get( project );
321
322 settings.SetTool(
323 (settings.GetTool() + (ToolCodes::numTools - 1 )) % ToolCodes::numTools);
324 trackPanel.Refresh(false);
325}
326
327void OnNextTool(const CommandContext &context)
328{
329 auto &project = context.project;
330 auto &trackPanel = TrackPanel::Get( project );
331 auto &settings = ProjectSettings::Get( project );
332
333 settings.SetTool( (settings.GetTool() + 1) % ToolCodes::numTools );
334 trackPanel.Refresh(false);
335}
336
337}; // struct Handler
338
340 // Handler is not stateful. Doesn't need a factory registered with
341 // AudacityProject.
342 static ToolActions::Handler instance;
343 return instance;
344};
345
346#define FN(X) (& ToolActions::Handler :: X)
347
348using namespace MenuTable;
350{
351 static BaseItemSharedPtr menu{
353 Menu( wxT("Tools"), XXO("T&ools"),
354 Command( wxT("SelectTool"), XXO("&Selection Tool"), FN(OnSelectTool),
355 AlwaysEnabledFlag, wxT("F1") ),
356 Command( wxT("EnvelopeTool"), XXO("&Envelope Tool"),
357 FN(OnEnvelopeTool), AlwaysEnabledFlag, wxT("F2") ),
358 Command( wxT("DrawTool"), XXO("&Draw Tool"), FN(OnDrawTool),
359 AlwaysEnabledFlag, wxT("F3") ),
360 Command( wxT("MultiTool"), XXO("&Multi Tool"), FN(OnMultiTool),
361 AlwaysEnabledFlag, wxT("F6") ),
362 Command( wxT("PrevTool"), XXO("&Previous Tool"), FN(OnPrevTool),
363 AlwaysEnabledFlag, wxT("A") ),
364 Command( wxT("NextTool"), XXO("&Next Tool"), FN(OnNextTool),
365 AlwaysEnabledFlag, wxT("D") )
366 ) ) };
367 return menu;
368}
369
370#undef FN
371
373 wxT("Optional/Extra/Part1"),
375};
376}
wxEVT_COMMAND_BUTTON_CLICKED
END_EVENT_TABLE()
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:35
wxEvtHandler CommandHandlerObject
int teBmps
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define safenew
Definition: MemoryX.h:10
FileConfig * gPrefs
Definition: Prefs.cpp:71
static ProjectFileIORegistry::AttributeWriterEntry entry
TranslatableString label
Definition: TagsEditor.cpp:163
THEME_API Theme theTheme
Definition: Theme.cpp:82
@ ToolsBarID
Definition: ToolBar.h:73
EVT_COMMAND_RANGE(ToolCodes::firstTool+FirstToolID, ToolsToolBar::numTools - 1+FirstToolID, wxEVT_COMMAND_BUTTON_CLICKED, ToolsToolBar::OnTool) ToolsToolBar
Methods for ToolsToolBar.
static RegisteredToolbarFactory factory
#define FN(X)
IMPLEMENT_CLASS(ToolsToolBar, ToolBar)
const int FirstToolID
Definition: ToolsToolBar.h:33
static Settings & settings()
Definition: TrackInfo.cpp:87
A wxButton with mouse-over behaviour.
Definition: AButton.h:25
void PushDown()
Definition: AButton.cpp:597
void PopUp()
Definition: AButton.cpp:605
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:274
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
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,...
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
void SetTool(int tool)
static ProjectSettings & Get(AudacityProject &project)
static ProjectWindow & Get(AudacityProject &project)
void RedrawProject(const bool bForceWaveTracks=false)
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:98
AudacityProject & mProject
Definition: ToolBar.h:235
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:686
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:840
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:802
void UpdatePrefs() override
Definition: ToolBar.cpp:605
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:475
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:102
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:898
static ToolManager & Get(AudacityProject &project)
A kind of ToolBar with Tools on it.
Definition: ToolsToolBar.h:35
void UpdatePrefs() override
static AButton * MakeTool(ToolsToolBar *pBar, teBmps eTool, int id, const TranslatableString &label)
void RegenerateTooltips() override
void DoToolChanged()
void OnToolChanged(wxCommandEvent &evt)
wxGridSizer * mToolSizer
Definition: ToolsToolBar.h:64
AButton * mTool[numTools]
Definition: ToolsToolBar.h:63
void Create(wxWindow *parent) override
void OnTool(wxCommandEvent &evt)
static ToolsToolBar & Get(AudacityProject &project)
void Populate() override
virtual ~ToolsToolBar()
void Refresh(bool eraseBackground=true, const wxRect *rect=(const wxRect *) NULL) override
Definition: TrackPanel.cpp:781
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:227
Holds a msgid for the translation catalog; may also bind format arguments.
std::unique_ptr< MenuItem > Menu(const Identifier &internalName, const TranslatableString &title, Args &&... args)
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
std::shared_ptr< BaseItem > BaseItemSharedPtr
Definition: Registry.h:72
Namespace for functions for View Toolbar menu.
AttachedItem sAttachment2
static CommandHandlerObject & findCommandHandler(AudacityProject &)
BaseItemSharedPtr ExtraToolsMenu()
AttachedToolBarMenuItem sAttachment
void SetTool(AudacityProject &project, int tool)
Called by handlers that set tools.
void OnSelectTool(const CommandContext &context)
Handler to set the select tool active.
void OnDrawTool(const CommandContext &context)
void OnNextTool(const CommandContext &context)
void OnPrevTool(const CommandContext &context)
void OnMultiTool(const CommandContext &context)
void OnEnvelopeTool(const CommandContext &context)
Handler to set the Envelope tool active.