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 auto& button = mButtons[thisButtonId];// ;
67 button = safenew AButton(mParent, thisButtonId + mFirstButtonId);
68 button->SetButtonType(AButton::FrameButton);
69 button->SetButtonToggles(toggle);
70 button->SetImages(
71 theTheme.Image(bmpRecoloredUpSmall),
72 theTheme.Image(bmpRecoloredUpHiliteSmall),
73 theTheme.Image(bmpRecoloredDownSmall),
74 theTheme.Image(bmpRecoloredHiliteSmall),
75 theTheme.Image(bmpRecoloredUpSmall));
76 button->SetIcons(theTheme.Image(eEnabledUp), theTheme.Image(eEnabledDown), theTheme.Image(eDisabled));
77 button->SetFrameMid(3);
78 button->SetLabel(label);
79 button->SetMinSize(wxSize { 25, 25 });
80 button->SetMaxSize(wxSize { 25, 25 });
81 return button;
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
#define safenew
Definition: MemoryX.h:10
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
@ 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,...
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,...
wxImage & Image(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:73
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:934
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.