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#if wxUSE_TOOLTIPS
17#include <wx/tooltip.h>
18#endif
19
20#include "AColor.h"
21#include "AudioIOBase.h"
22#include "AllThemeResources.h"
23#include "Prefs.h"
24#include "ProjectWindow.h"
25#include "Theme.h"
26#include "Track.h"
27
30#include "widgets/AButton.h"
31
33
34namespace cloud
35{
37 : ToolBar(project, ShareAudioBarID, XO("Share Audio"), wxT("Share Audio"))
38{
39}
40
42{
43}
44
46{
47 auto& toolManager = ToolManager::Get(project);
48 return *static_cast<ShareAudioToolbar*>(
49 toolManager.GetToolBar(ShareAudioBarID));
50}
51
53{
54 return Get(const_cast<AudacityProject&>(project));
55}
56
57void ShareAudioToolbar::Create(wxWindow* parent)
58{
59 ToolBar::Create(parent);
60
61 // Simulate a size event to set initial meter placement/size
62 wxSizeEvent event(GetSize(), GetId());
63 event.SetEventObject(this);
64 GetEventHandler()->ProcessEvent(event);
65}
66
68{
69#if wxUSE_TOOLTIPS
70 for (long iWinID = ID_SHARE_AUDIO_BUTTON; iWinID < BUTTON_COUNT; iWinID++)
71 {
72 auto pCtrl = static_cast<AButton*>(this->FindWindow(iWinID));
74 switch (iWinID)
75 {
77 name = wxT("Share Audio");
78 break;
79 }
80
81 std::vector<ComponentInterfaceSymbol> commands(
82 1u, { name, Verbatim(pCtrl->GetLabel()) });
83
85 mProject, *pCtrl, commands.data(), commands.size());
86 }
87#endif
88}
89
91{
93 SetBackgroundColour(theTheme.Colour(clrMedium));
95
96#if wxUSE_TOOLTIPS
98 wxToolTip::Enable(true);
99 wxToolTip::SetDelay(1000);
100#endif
101
102 // Set default order and mode
104}
105
107{
108#ifndef USE_AQUA_THEME
109 const auto s = mSizer->GetSize();
110 const auto p = mSizer->GetPosition();
111
112 wxRect bevelRect(p.x, p.y, s.GetWidth() - 1, s.GetHeight() - 1);
113 AColor::Bevel(*dc, true, bevelRect);
114#endif
115}
116
118{
119 auto gAudioIO = AudioIOBase::Get();
120
121 const bool audioStreamActive = gAudioIO &&
122 gAudioIO->IsStreamActive() && !gAudioIO->IsMonitoring();
123
124 bool hasAudio = false;
125
126 for (const auto& track : TrackList::Get(mProject).Leaders<PlayableTrack>())
127 {
128 if (track->GetStartTime() != track->GetEndTime())
129 {
130 hasAudio = true;
131 break;
132 }
133 }
134
135 mShareAudioButton->SetEnabled(hasAudio && !audioStreamActive);
136}
137
139{
140 // ToolBar::ReCreateButtons() will get rid of its sizer and
141 // since we've attached our sizer to it, ours will get deleted too
142 // so clean ours up first.
143 DestroySizer();
144
146
148
150}
151
153{
155 //i18n-hint: Share audio button text, keep as short as possible
156 mShareAudioButton->SetLabel(XO("Share Audio"));
159 theTheme.Image(bmpRecoloredUpSmall),
160 theTheme.Image(bmpRecoloredUpHiliteSmall),
161 theTheme.Image(bmpRecoloredDownSmall),
162 theTheme.Image(bmpRecoloredHiliteSmall),
163 theTheme.Image(bmpRecoloredUpSmall));
164 mShareAudioButton->SetIcon(theTheme.Image(bmpShareAudio));
165 mShareAudioButton->SetForegroundColour(theTheme.Colour(clrTrackPanelText));
166
167 mShareAudioButton->Bind(
168 wxEVT_BUTTON,
169 [this](auto)
170 {
172 dlg.ShowModal();
173
175 });
176}
177
179{
180 // (Re)allocate the button sizer
181 DestroySizer();
182
183 Add((mSizer = safenew wxBoxSizer(wxHORIZONTAL)), 1, wxEXPAND);
184 mSizer->Add(mShareAudioButton, 1, wxEXPAND);
185
186 // Layout the sizer
187 mSizer->Layout();
188
189 // Layout the toolbar
190 Layout();
191
192 const auto height = 2 * toolbarSingle;
193 const wxSize size(GetSizer()->GetMinSize().GetWidth(), height);
194 SetMinSize(size);
195 SetMaxSize(size);
196}
197
199{
200 if (mSizer == nullptr)
201 return;
202
203 Detach(mSizer);
204
205 std::unique_ptr<wxSizer> { mSizer }; // DELETE it
206 mSizer = nullptr;
207}
208
210 ShareAudioBarID, [](AudacityProject& project)
211 { return ToolBar::Holder { safenew ShareAudioToolbar { project } }; }
212};
213
214namespace
215{
217 /* i18n-hint: Clicking this menu item shows the toolbar
218 that opens Share Audio dialog */
219 ShareAudioBarID, wxT("ShareAudioTB"), XXO("&Share Audio Toolbar")
220};
221}
222
223} // namespace cloud
wxT("CloseDown"))
const TranslatableString name
Definition: Distortion.cpp:82
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define safenew
Definition: MemoryX.h:10
IMPLEMENT_CLASS(cloud::ShareAudioToolbar, ToolBar)
THEME_API Theme theTheme
Definition: Theme.cpp:82
#define toolbarSingle
Definition: ToolBar.h:59
declares abstract base class Track, TrackList, and iterators over TrackList
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:150
void SetImages(const wxImage &up, const wxImage &over, const wxImage &down, const wxImage &overDown, const wxImage &dis)
Definition: AButton.cpp:208
void PopUp()
Definition: AButton.cpp:588
@ FrameButton
Definition: AButton.h:114
void SetEnabled(bool state)
Definition: AButton.h:182
void SetIcon(const wxImage &icon)
Definition: AButton.cpp:229
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:192
static void Bevel(wxDC &dc, bool up, const wxRect &r)
Definition: AColor.cpp:266
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
static AudioIOBase * Get()
Definition: AudioIOBase.cpp:91
size_t size() const
How many attachment pointers are in the Site.
Definition: ClientData.h:251
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:101
AudacityProject & mProject
Definition: ToolBar.h:251
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:695
virtual void ReCreateButtons()
Definition: ToolBar.cpp:525
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:823
wxBoxSizer * GetSizer()
Definition: ToolBar.cpp:687
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:484
void Detach(wxWindow *window)
Definition: ToolBar.cpp:761
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:105
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:956
static ToolManager & Get(AudacityProject &project)
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
static ShareAudioToolbar & Get(AudacityProject &project)
void Create(wxWindow *parent) override
void Repaint(wxDC *dc) override
void EnableDisableButtons() override
ShareAudioToolbar(AudacityProject &project)
void RegenerateTooltips() override
static RegisteredToolbarFactory factory