Audacity 3.2.0
ShareAudioToolbar.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 ShareAudioToolbar.cpp
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#include "ShareAudioToolbar.h"
12
13#include <wx/sizer.h>
14#include <wx/stattext.h>
15
16#include <algorithm>
17
18#if wxUSE_TOOLTIPS
19#include <wx/tooltip.h>
20#endif
21
22#include "AColor.h"
23#include "AudioIOBase.h"
24#include "AllThemeResources.h"
25#include "Prefs.h"
26#include "ProjectWindow.h"
27#include "Theme.h"
28#include "PlayableTrack.h"
29
32#include "widgets/AButton.h"
33
35
36namespace audacity::cloud
37{
39{
40 return wxT("Share Audio");
41}
42
44 : ToolBar(project, XO("Share Audio"), ID())
45{
46}
47
49{
50}
51
53{
54 auto& toolManager = ToolManager::Get(project);
55 return *static_cast<ShareAudioToolbar*>(
56 toolManager.GetToolBar(ID()));
57}
58
60{
61 return Get(const_cast<AudacityProject&>(project));
62}
63
64void ShareAudioToolbar::Create(wxWindow* parent)
65{
66 ToolBar::Create(parent);
67
68 // Simulate a size event to set initial meter placement/size
69 wxSizeEvent event(GetSize(), GetId());
70 event.SetEventObject(this);
71 GetEventHandler()->ProcessEvent(event);
72}
73
75{
76#if wxUSE_TOOLTIPS
77 for (long iWinID = ID_SHARE_AUDIO_BUTTON; iWinID < BUTTON_COUNT; iWinID++)
78 {
79 auto pCtrl = static_cast<AButton*>(this->FindWindow(iWinID));
81 switch (iWinID)
82 {
84 name = ID();
85 break;
86 }
87
88 std::vector<ComponentInterfaceSymbol> commands(
89 1u, { name, Verbatim(pCtrl->GetLabel()) });
90
92 mProject, *pCtrl, commands.data(), commands.size());
93 }
94#endif
95}
96
98{
100 SetBackgroundColour(theTheme.Colour(clrMedium));
102
103#if wxUSE_TOOLTIPS
105 wxToolTip::Enable(true);
106 wxToolTip::SetDelay(1000);
107#endif
108
109 // Set default order and mode
111}
112
114{
115#ifndef USE_AQUA_THEME
116 const auto s = mSizer->GetSize();
117 const auto p = mSizer->GetPosition();
118
119 wxRect bevelRect(p.x, p.y, s.GetWidth() - 1, s.GetHeight() - 1);
120 AColor::Bevel(*dc, true, bevelRect);
121#endif
122}
123
125{
126 auto gAudioIO = AudioIOBase::Get();
127
128 const bool audioStreamActive = gAudioIO &&
129 gAudioIO->IsStreamActive() && !gAudioIO->IsMonitoring();
130
131 bool hasAudio = false;
132
133 for (const auto& track : TrackList::Get(mProject).Any<PlayableTrack>())
134 {
135 if (track->GetStartTime() != track->GetEndTime())
136 {
137 hasAudio = true;
138 break;
139 }
140 }
141
142 mShareAudioButton->SetEnabled(hasAudio && !audioStreamActive);
143}
144
146{
147 // ToolBar::ReCreateButtons() will get rid of its sizer and
148 // since we've attached our sizer to it, ours will get deleted too
149 // so clean ours up first.
150 DestroySizer();
151
153
155
157}
158
160{
162 //i18n-hint: Share audio button text, keep as short as possible
163 mShareAudioButton->SetLabel(XO("Share Audio"));
166 theTheme.Image(bmpRecoloredUpSmall),
167 theTheme.Image(bmpRecoloredUpHiliteSmall),
168 theTheme.Image(bmpRecoloredDownSmall),
169 theTheme.Image(bmpRecoloredHiliteSmall),
170 theTheme.Image(bmpRecoloredUpSmall));
171 mShareAudioButton->SetIcon(theTheme.Image(bmpShareAudio));
172 mShareAudioButton->SetForegroundColour(theTheme.Colour(clrTrackPanelText));
173
174 mShareAudioButton->Bind(
175 wxEVT_BUTTON,
176 [this](auto)
177 {
179 dlg.ShowModal();
180
182 });
183}
184
186{
187 // (Re)allocate the button sizer
188 DestroySizer();
189
190 Add((mSizer = safenew wxBoxSizer(wxHORIZONTAL)), 1, wxEXPAND);
191 mSizer->Add(mShareAudioButton, 1, wxEXPAND);
192
193 // Layout the sizer
194 mSizer->Layout();
195
196 // Layout the toolbar
197 Layout();
198
199 const auto height = 2 * toolbarSingle;
200 SetMinSize({ std::max(76, GetSizer()->GetMinSize().GetWidth()), height });
201 SetMaxSize({ -1, height });
202}
203
205{
206 if (mSizer == nullptr)
207 return;
208
209 Detach(mSizer);
210
211 std::unique_ptr<wxSizer> { mSizer }; // DELETE it
212 mSizer = nullptr;
213}
214
218};
219
220namespace
221{
223 /* i18n-hint: Clicking this menu item shows the toolbar
224 that opens Share Audio dialog */
225 ShareAudioToolbar::ID(), wxT("ShareAudioTB"), XXO("&Share Audio Toolbar")
226};
227}
228
229} // namespace audacity::cloud
wxT("CloseDown"))
const TranslatableString name
Definition: Distortion.cpp:76
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
Extends Track with notions of mute and solo setting.
IMPLEMENT_CLASS(audacity::cloud::ShareAudioToolbar, ToolBar)
const auto project
THEME_API Theme theTheme
Definition: Theme.cpp:82
#define toolbarSingle
Definition: ToolBar.h:59
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
void SetButtonType(Type type)
Definition: AButton.cpp:147
void SetImages(const wxImage &up, const wxImage &over, const wxImage &down, const wxImage &overDown, const wxImage &dis)
Definition: AButton.cpp:205
void PopUp()
Definition: AButton.cpp:585
@ FrameButton
Definition: AButton.h:114
void SetEnabled(bool state)
Definition: AButton.h:182
void SetIcon(const wxImage &icon)
Definition: AButton.cpp:226
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:189
static void Bevel(wxDC &dc, bool up, const wxRect &r)
Definition: AColor.cpp:264
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static AudioIOBase * Get()
Definition: AudioIOBase.cpp:94
size_t size() const
How many attachment pointers are in the Site.
Definition: ClientData.h:260
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
static ProjectWindow & Get(AudacityProject &project)
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:74
AudacityProject & mProject
Definition: ToolBar.h:248
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:709
virtual void ReCreateButtons()
Definition: ToolBar.cpp:533
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:837
wxBoxSizer * GetSizer()
Definition: ToolBar.cpp:701
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492
void Detach(wxWindow *window)
Definition: ToolBar.cpp:775
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:78
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:970
static ToolManager & Get(AudacityProject &project)
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
ShareAudioToolbar(AudacityProject &project)
void Create(wxWindow *parent) override
static ShareAudioToolbar & Get(AudacityProject &project)
static RegisteredToolbarFactory factory