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 "../Menus.h"
20#include "Project.h"
21
22#include "../commands/CommandContext.h"
23#include "../commands/CommandManager.h"
24#include "../commands/CommandDispatch.h"
25
26// flags so 1,2,4,8 etc.
27enum {
30};
31
32ToolBarButtons::ToolBarButtons(ToolBar *const parent, AudacityProject & project, ButtonList buttonList, int size, int firstButtonId)
33 : mParent(parent)
34 , mProject(project)
35 , mFirstButtonId(firstButtonId)
36 , mButtons(size)
37 , mButtonList(std::move(buttonList))
38{
39}
40
41void ToolBarButtons::OnButton(wxCommandEvent & event)
42{
43 int id = event.GetId() - mFirstButtonId;
44
45 // Be sure the pop-up happens even if there are exceptions, except for buttons which toggle.
46 auto cleanup = finally( [&] { mButtons[id]->InteractionOver(); });
47
48 auto &cm = CommandManager::Get( mProject );
49
51 const CommandContext context( mProject );
52
54 mButtonList[id].commandName, context, flags, false );
55
56#if defined(__WXMAC__)
57 // Bug 2402
58 // LLL: It seems that on the Mac the IDLE events are processed
59 // differently than on Windows/GTK and the AdornedRulerPanel's
60 // OnPaint() method gets called sooner that expected. This is
61 // evident when zooming from this toolbar only. When zooming from
62 // the Menu or from keyboard ommand, the zooming works correctly.
63 wxTheApp->ProcessIdle();
64#endif
65}
66
67AButton* ToolBarButtons::CreateButton(teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int thisButtonId, const TranslatableString& label, bool toggle)
68{
69 AButton *&r = mButtons[thisButtonId];
70
72 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
73 eEnabledUp, eEnabledDown, eDisabled,
74 wxWindowID(thisButtonId + mFirstButtonId),
75 wxDefaultPosition,
76 toggle,
77 theTheme.ImageSize( bmpRecoloredUpSmall ));
78
79 r->SetLabel(label);
80
81 return r;
82}
83
84void ToolBarButtons::SetEnabled(int id, bool state)
85{
86 mButtons[id]->SetEnabled(state);
87}
88
90{
91 mCustomEnableDisableButtonsAction = std::move(action);
92}
93
95{
96 mButtons[id]->PopUp();
97}
98
100{
101 mButtons[id]->PushDown();
102}
103
105{
107}
108
110{
112}
113
115{
116 CommandManager* cm = nullptr;
117
120
123 }
124
125 for (const auto &entry : mButtonList) {
126#if wxUSE_TOOLTIPS
127 if ( Action & TBActTooltips ) {
129 entry.commandName, entry.untranslatedLabel };
131 *mButtons[entry.tool], &command, 1u );
132 }
133#endif
134 if (cm) {
135 SetEnabled(entry.tool, cm->GetEnabled(entry.commandName));
136 }
137 }
138}
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.
static CommandManager & Get(AudacityProject &project)
bool GetEnabled(const CommandID &name)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:69
CommandFlag GetUpdateFlags(bool checkActive=false) const
Definition: Menus.cpp:528
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(CommandManager &commandManager, const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
STL namespace.