Audacity 3.2.0
ToolBarButtons.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/**********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 ToolBarButtons.cpp
7
8 ksoze95
9
10**********************************************************************/
11
12#include <utility>
13#include <wx/app.h>
14
15#include "ToolBarButtons.h"
16
17#include "AllThemeResources.h"
18#include "../widgets/AButton.h"
19#include "Project.h"
20
21#include "CommandContext.h"
22#include "CommandManager.h"
23#include "../commands/CommandDispatch.h"
24
25// flags so 1,2,4,8 etc.
26enum {
29};
30
31ToolBarButtons::ToolBarButtons(ToolBar *const parent, AudacityProject & project, ButtonList buttonList, int size, int firstButtonId)
32 : mParent(parent)
33 , mProject(project)
34 , mFirstButtonId(firstButtonId)
35 , mButtons(size)
36 , mButtonList(std::move(buttonList))
37{
38}
39
40void ToolBarButtons::OnButton(wxCommandEvent & event)
41{
42 int id = event.GetId() - mFirstButtonId;
43
44 // Be sure the pop-up happens even if there are exceptions, except for buttons which toggle.
45 auto cleanup = finally( [&] { mButtons[id]->InteractionOver(); });
46
48 const CommandContext context( mProject );
49
51 mButtonList[id].commandName, context, flags, false );
52
53#if defined(__WXMAC__)
54 // Bug 2402
55 // LLL: It seems that on the Mac the IDLE events are processed
56 // differently than on Windows/GTK and the AdornedRulerPanel's
57 // OnPaint() method gets called sooner that expected. This is
58 // evident when zooming from this toolbar only. When zooming from
59 // the Menu or from keyboard ommand, the zooming works correctly.
60 wxTheApp->ProcessIdle();
61#endif
62}
63
64AButton* ToolBarButtons::CreateButton(teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int thisButtonId, const TranslatableString& label, bool toggle)
65{
66 AButton *&r = mButtons[thisButtonId];
67
69 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
70 eEnabledUp, eEnabledDown, eDisabled,
71 wxWindowID(thisButtonId + mFirstButtonId),
72 wxDefaultPosition,
73 toggle,
74 theTheme.ImageSize( bmpRecoloredUpSmall ));
75
76 r->SetLabel(label);
77
78 return r;
79}
80
81void ToolBarButtons::SetEnabled(int id, bool state)
82{
83 mButtons[id]->SetEnabled(state);
84}
85
87{
88 mCustomEnableDisableButtonsAction = std::move(action);
89}
90
92{
93 mButtons[id]->PopUp();
94}
95
97{
98 mButtons[id]->PushDown();
99}
100
102{
104}
105
107{
109}
110
112{
113 CommandManager* cm = nullptr;
114
117
120 }
121
122 for (const auto &entry : mButtonList) {
123#if wxUSE_TOOLTIPS
124 if ( Action & TBActTooltips ) {
126 entry.commandName, entry.untranslatedLabel };
128 *mButtons[entry.tool], &command, 1u );
129 }
130#endif
131 if (cm) {
132 SetEnabled(entry.tool, cm->GetEnabled(entry.commandName));
133 }
134 }
135}
int teBmps
static ProjectFileIORegistry::AttributeWriterEntry entry
TranslatableString label
Definition: TagsEditor.cpp:165
const auto project
THEME_API Theme theTheme
Definition: Theme.cpp:82
@ TBActEnableDisable
@ TBActTooltips
int id
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
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,...
CommandManager implements a system for organizing all user-callable commands.
bool GetEnabled(const CommandID &name) const
static CommandManager & Get(AudacityProject &project)
CommandFlag GetUpdateFlags(bool quick=false) const
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
wxSize ImageSize(int iIndex)
AudacityProject & mProject
std::vector< AButton * > mButtons
void EnableDisableButtons()
void SetCustomEnableDisableButtonsAction(std::function< void()> action)
void PopUp(int id)
ButtonList mButtonList
std::function< void()> mCustomEnableDisableButtonsAction
void OnButton(wxCommandEvent &event)
void ForAllButtons(int Action)
ToolBarButtons(ToolBar *const parent, AudacityProject &project, ButtonList buttonList, int size, int firstButtonId)
ToolBar * mParent
void SetEnabled(int id, bool state)
void PushDown(int id)
std::vector< Entry > ButtonList
AButton * CreateButton(teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, const TranslatableString &label, bool toggle=false)
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:74
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 SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:970
Holds a msgid for the translation catalog; may also bind format arguments.
std::function< void()> Action
Definition: BasicUI.h:24
AUDACITY_DLL_API bool HandleTextualCommand(const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
STL namespace.