Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
SelectionBar Class Referencefinal

(not quite a Toolbar) at foot of screen for setting and viewing the selection range. More...

#include <SelectionBar.h>

Inheritance diagram for SelectionBar:
[legend]
Collaboration diagram for SelectionBar:
[legend]

Public Types

enum class  SelectionMode { StartEnd , StartLength , LengthEnd , LengthCenter }
 
- Public Types inherited from ToolBar
enum  DockID { TopDockID = 1 , BotDockID = 2 }
 Identifies one of the docking areas for toolbars. More...
 
using Holder = wxWindowPtr< ToolBar >
 

Public Member Functions

 SelectionBar (AudacityProject &project)
 
virtual ~SelectionBar ()
 
bool ShownByDefault () const override
 Whether the toolbar should be shown by default. Default implementation returns true. More...
 
DockID DefaultDockID () const override
 Which dock the toolbar defaults into. Default implementation chooses the top dock. More...
 
void Create (wxWindow *parent) override
 
void Populate () override
 
void Repaint (wxDC *WXUNUSED(dc)) override
 
void EnableDisableButtons () override
 
void UpdatePrefs () override
 
void SetTimes (double start, double end)
 
void SetSelectionFormat (const NumericFormatID &format)
 
void RegenerateTooltips () override
 
- Public Member Functions inherited from ToolBar
 ToolBar (AudacityProject &project, const TranslatableString &label, const Identifier &section, bool resizable=false)
 
virtual ~ToolBar ()
 
virtual bool ShownByDefault () const
 Whether the toolbar should be shown by default. Default implementation returns true. More...
 
virtual bool HideAfterReset () const
 Default implementation returns false. More...
 
virtual DockID DefaultDockID () const
 Which dock the toolbar defaults into. Default implementation chooses the top dock. More...
 
bool AcceptsFocus () const override
 
bool AcceptsFocusFromKeyboard () const override
 
virtual void SetToDefaultSize ()
 
virtual void Create (wxWindow *parent)
 
virtual void EnableDisableButtons ()=0
 
virtual void ReCreateButtons ()
 
void UpdatePrefs () override
 
virtual void RegenerateTooltips ()=0
 
int GetIndex () const
 Get a value used for computing cascading positions of undocked bars. More...
 
void SetIndex (int index)
 Set a value used for computing cascading positions of undocked bars. More...
 
TranslatableString GetTitle ()
 
TranslatableString GetLabel ()
 
Identifier GetSection ()
 
ToolDockGetDock ()
 
void SetPreferredNeighbors (Identifier left, Identifier top={})
 
void SetLabel (const TranslatableString &label)
 
virtual void SetDocked (ToolDock *dock, bool pushed)
 
std::pair< Identifier, IdentifierPreferredNeighbors () const noexcept
 Defaults to (NoBarID, NoBarId) More...
 
virtual bool Expose (bool show=true)
 
bool IsResizable () const
 
bool IsVisible () const
 
bool IsDocked () const
 
bool IsPositioned ()
 
void SetVisible (bool bVisible)
 
void SetPositioned ()
 
virtual int GetInitialWidth ()
 Resizable toolbars should implement these. More...
 
virtual int GetMinToolbarWidth ()
 
virtual wxSize GetDockedSize ()
 
wxSize GetSmartDockedSize ()
 
virtual void ResizingDone ()
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
void SetLabel (const TranslatableString &label)
 
void SetName (const TranslatableString &name)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Static Public Member Functions

static Identifier ID ()
 
static SelectionBarGet (AudacityProject &project)
 
static const SelectionBarGet (const AudacityProject &project)
 
- Static Public Member Functions inherited from ToolBar
static AButtonMakeButton (wxWindow *parent, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size)
 
static AButtonMakeButton (ToolBar *parent, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, bool processdownevents, const TranslatableString &label)
 
static void MakeAlternateImages (AButton &button, int idx, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxSize size)
 
static void SetButtonToolTip (AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
 
static void MakeButtonBackgroundsSmall ()
 
static void MakeButtonBackgroundsLarge ()
 

Private Member Functions

AButtonMakeSetupButton ()
 
void AddTitle (const TranslatableString &Title, wxSizer *pSizer)
 
void AddTime (int id, wxSizer *pSizer)
 
void AddSelectionSetupButton (wxSizer *pSizer)
 
void SetSelectionMode (SelectionMode mode)
 
void ValuesToControls ()
 
void OnUpdate (wxCommandEvent &evt)
 
void OnFocus (wxFocusEvent &event)
 
void OnCaptureKey (wxCommandEvent &event)
 
void OnSize (wxSizeEvent &evt)
 
void OnIdle (wxIdleEvent &evt)
 
void ModifySelection (int driver, bool done=false)
 
void SelectionModeUpdated ()
 
void UpdateTimeControlsFormat (const NumericFormatID &format)
 
void FitToTimeControls ()
 
void OnFormatsChanged (struct ProjectNumericFormatsEvent)
 

Private Attributes

double mRate
 
double mStart
 
double mEnd
 
double mLength
 
double mCenter
 
SelectionMode mSelectionMode {}
 
SelectionMode mLastSelectionMode {}
 
std::array< NumericTextCtrl *, 2 > mTimeControls {}
 
AButtonmSetupButton {}
 
Observer::Subscription mFormatChangedToFitValueSubscription [2]
 
wxString mLastValidText
 
const Observer::Subscription mFormatsSubscription
 

Additional Inherited Members

- Protected Member Functions inherited from ToolBar
void SetButton (bool down, AButton *button)
 
wxBoxSizer * GetSizer ()
 
void Add (wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
 
void Add (wxSizer *sizer, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 
void Add (int width, int height, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 
void AddSpacer (int size=14)
 
void AddStretchSpacer (int prop=1)
 
void Detach (wxWindow *window)
 
void Detach (wxSizer *sizer)
 
void Updated ()
 
int GetResizeGrabberWidth ()
 Returns the width in pixels of the resizer element. More...
 
virtual void Populate ()=0
 
virtual void Repaint (wxDC *dc)=0
 
void OnErase (wxEraseEvent &event)
 
void OnPaint (wxPaintEvent &event)
 
void OnMouseEvents (wxMouseEvent &event)
 
- Protected Member Functions inherited from PrefsListener
virtual void UpdateSelectedPrefs (int id)
 
 PrefsListener ()
 
virtual ~PrefsListener ()
 
virtual void UpdatePrefs ()=0
 
- Static Protected Member Functions inherited from ToolBar
static void MakeMacRecoloredImage (teBmps eBmpOut, teBmps eBmpIn)
 
static void MakeMacRecoloredImageSize (teBmps eBmpOut, teBmps eBmpIn, const wxSize &size)
 
static void MakeRecoloredImage (teBmps eBmpOut, teBmps eBmpIn)
 
static void MakeRecoloredImageSize (teBmps eBmpOut, teBmps eBmpIn, const wxSize &size)
 
- Static Protected Member Functions inherited from PrefsListener
static void Broadcast (int id=0)
 Call this static function to notify all PrefsListener objects. More...
 
- Protected Attributes inherited from ToolBar
AudacityProjectmProject
 
TranslatableString mLabel
 
Identifier mSection
 
int mIndex {0}
 

Detailed Description

(not quite a Toolbar) at foot of screen for setting and viewing the selection range.

Definition at line 37 of file SelectionBar.h.

Member Enumeration Documentation

◆ SelectionMode

enum class SelectionBar::SelectionMode
strong
Enumerator
StartEnd 
StartLength 
LengthEnd 
LengthCenter 

Definition at line 40 of file SelectionBar.h.

41 {
42 StartEnd,
43 StartLength,
44 LengthEnd,
45 LengthCenter
46 };

Constructor & Destructor Documentation

◆ SelectionBar()

SelectionBar::SelectionBar ( AudacityProject project)

Definition at line 129 of file SelectionBar.cpp.

130: ToolBar(project, XO("Selection"), ID()),
131 mRate(0.0),
132 mStart(0.0), mEnd(0.0), mLength(0.0), mCenter(0.0),
135{
136 // Make sure we have a valid rate as the NumericTextCtrl()s
137 // created in Populate()
138 // depend on it. Otherwise, division-by-zero floating point exceptions
139 // will occur.
140 // Refer to bug #462 for a scenario where the division-by-zero causes
141 // Audacity to fail.
142 // We expect mRate to be set from the project later.
144
145 // Selection mode of 0 means showing 'start' and 'end' only.
147}
XO("Cut/Copy/Paste")
const auto project
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
static ProjectNumericFormats & Get(AudacityProject &project)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53
double mLength
Definition: SelectionBar.h:98
static Identifier ID()
double mRate
Definition: SelectionBar.h:97
void OnFormatsChanged(struct ProjectNumericFormatsEvent)
double mCenter
Definition: SelectionBar.h:98
SelectionMode mSelectionMode
Definition: SelectionBar.h:100
const Observer::Subscription mFormatsSubscription
Definition: SelectionBar.h:109
double mStart
Definition: SelectionBar.h:98
ToolBar(AudacityProject &project, const TranslatableString &label, const Identifier &section, bool resizable=false)
Definition: ToolBar.cpp:328
SelectionBar::SelectionMode ReadSelectionMode()

References ProjectRate::Get(), ProjectRate::GetRate(), mRate, mSelectionMode, project, and anonymous_namespace{SelectionBar.cpp}::ReadSelectionMode().

Here is the call graph for this function:

◆ ~SelectionBar()

SelectionBar::~SelectionBar ( )
virtual

Definition at line 149 of file SelectionBar.cpp.

150{
151}

Member Function Documentation

◆ AddSelectionSetupButton()

void SelectionBar::AddSelectionSetupButton ( wxSizer *  pSizer)
private

Definition at line 239 of file SelectionBar.cpp.

240{
241 auto setupBtn = MakeSetupButton();
242
243 auto showMenu = [this, setupBtn]()
244 {
245 static const wxString choices[4] = {
246 _("Start and End of Selection"),
247 _("Start and Length of Selection"),
248 _("Length and End of Selection"),
249 _("Length and Center of Selection"),
250 };
251
252 wxMenu menu;
253 int selectionMode {};
254 for (auto& choice : choices)
255 {
256 auto subMenu = menu.AppendRadioItem(wxID_ANY, choice);
257
258 if (static_cast<SelectionMode>(selectionMode) == mSelectionMode)
259 subMenu->Check();
260
261 menu.Bind(
262 wxEVT_MENU,
263 [this, selectionMode](auto& evt)
264 {
265 SetSelectionMode(static_cast<SelectionMode>(selectionMode));
267 },
268 subMenu->GetId());
269
270 ++selectionMode;
271 }
272
273 menu.Bind(wxEVT_MENU_CLOSE, [setupBtn](auto&) { setupBtn->PopUp(); });
274
275 BasicMenu::Handle { &menu }.Popup(wxWidgetsWindowPlacement { setupBtn });
276 };
277
278 setupBtn->Bind(wxEVT_BUTTON, [this, showMenu](auto&) { showMenu(); });
279 pSizer->Add(setupBtn, 0, wxALIGN_RIGHT | wxBOTTOM | wxRIGHT, 5);
280
281 mSetupButton = setupBtn;
282}
#define _(s)
Definition: Internat.h:73
void Popup(const BasicUI::WindowPlacement &window, const Point &pos={})
Display the menu at pos, invoke at most one action, then hide it.
Definition: BasicMenu.cpp:209
void SetSelectionMode(SelectionMode mode)
AButton * mSetupButton
Definition: SelectionBar.h:104
void SelectionModeUpdated()
AButton * MakeSetupButton()
Window placement information for wxWidgetsBasicUI can be constructed from a wxWindow pointer.

References _, MakeSetupButton(), mSelectionMode, mSetupButton, BasicMenu::Handle::Popup(), SelectionModeUpdated(), and SetSelectionMode().

Referenced by Populate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddTime()

void SelectionBar::AddTime ( int  id,
wxSizer *  pSizer 
)
private

Definition at line 213 of file SelectionBar.cpp.

214{
215 auto &formats = ProjectNumericFormats::Get(mProject);
216 auto formatName = formats.GetSelectionFormat();
218 this, id, NumericConverterType_TIME(), formatName, 0.0);
219
220 pCtrl->Bind(
221 wxEVT_TEXT,
222 [this, id](auto& evt) { ModifySelection(id, evt.GetInt() != 0); });
223
224 pSizer->Add(pCtrl, 0, wxALIGN_TOP | wxRIGHT, 5);
225
226 mTimeControls[id] = pCtrl;
227
228 mFormatChangedToFitValueSubscription[id] = pCtrl->Subscribe(
229 [this, id](const auto& msg)
230 {
231 auto altCtrl = mTimeControls[id == 0 ? 1 : 0];
232 if (altCtrl != nullptr)
233 altCtrl->UpdateFormatToFit(msg.value);
234
236 });
237}
#define safenew
Definition: MemoryX.h:9
const NumericConverterType & NumericConverterType_TIME()
int id
static FormatterContext ProjectContext(const AudacityProject &project)
void ModifySelection(int driver, bool done=false)
Observer::Subscription mFormatChangedToFitValueSubscription[2]
Definition: SelectionBar.h:106
void FitToTimeControls()
std::array< NumericTextCtrl *, 2 > mTimeControls
Definition: SelectionBar.h:103
AudacityProject & mProject
Definition: ToolBar.h:248

References FitToTimeControls(), ProjectNumericFormats::Get(), id, mFormatChangedToFitValueSubscription, ModifySelection(), ToolBar::mProject, mTimeControls, NumericConverterType_TIME(), FormatterContext::ProjectContext(), and safenew.

Referenced by Populate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddTitle()

void SelectionBar::AddTitle ( const TranslatableString Title,
wxSizer *  pSizer 
)
private

Definition at line 203 of file SelectionBar.cpp.

204 {
205 const auto translated = Title.Translation();
206 auStaticText * pTitle = safenew auStaticText(this, translated );
207 pTitle->SetBackgroundColour( theTheme.Colour( clrMedium ));
208 pTitle->SetForegroundColour( theTheme.Colour( clrTrackPanelText ) );
209 pSizer->Add( pTitle, 0, wxEXPAND | wxRIGHT, 5 );
210}
THEME_API Theme theTheme
Definition: Theme.cpp:82
wxColour & Colour(int iIndex)
is like wxStaticText, except it can be themed. wxStaticText can't be.
Definition: auStaticText.h:20

References ThemeBase::Colour(), safenew, and theTheme.

Referenced by Populate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create()

void SelectionBar::Create ( wxWindow *  parent)
overridevirtual

Reimplemented from ToolBar.

Definition at line 174 of file SelectionBar.cpp.

175{
176 ToolBar::Create(parent);
177 UpdatePrefs();
178}
void UpdatePrefs() override
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492

References ToolBar::Create(), and UpdatePrefs().

Here is the call graph for this function:

◆ DefaultDockID()

ToolBar::DockID SelectionBar::DefaultDockID ( ) const
overridevirtual

Which dock the toolbar defaults into. Default implementation chooses the top dock.

Reimplemented from ToolBar.

Definition at line 158 of file SelectionBar.cpp.

159{
160 return BotDockID;
161}
@ BotDockID
Definition: ToolBar.h:94

References ToolBar::BotDockID.

◆ EnableDisableButtons()

void SelectionBar::EnableDisableButtons ( )
inlineoverridevirtual

Implements ToolBar.

Definition at line 63 of file SelectionBar.h.

63{};

◆ FitToTimeControls()

void SelectionBar::FitToTimeControls ( )
private

Definition at line 642 of file SelectionBar.cpp.

643{
644 wxSize sz = GetMinSize();
645 sz.SetWidth(10);
646 SetMinSize(sz);
647 Fit();
648 Layout();
649 Updated();
650}
void Updated()
Definition: ToolBar.cpp:684

References ToolBar::Updated().

Referenced by AddTime(), and SelectionModeUpdated().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [1/2]

SelectionBar & SelectionBar::Get ( AudacityProject project)
static

Definition at line 163 of file SelectionBar.cpp.

164{
165 auto &toolManager = ToolManager::Get( project );
166 return *static_cast<SelectionBar*>(toolManager.GetToolBar(ID()));
167}
(not quite a Toolbar) at foot of screen for setting and viewing the selection range.
Definition: SelectionBar.h:37
static ToolManager & Get(AudacityProject &project)

References ToolManager::Get(), ID(), and project.

Referenced by Get(), and ProjectSettings::UpdatePrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [2/2]

const SelectionBar & SelectionBar::Get ( const AudacityProject project)
static

Definition at line 169 of file SelectionBar.cpp.

170{
171 return Get( const_cast<AudacityProject&>( project )) ;
172}
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 SelectionBar & Get(AudacityProject &project)

References Get(), and project.

Here is the call graph for this function:

◆ ID()

Identifier SelectionBar::ID ( )
static

Definition at line 124 of file SelectionBar.cpp.

125{
126 return wxT("Selection");
127}
wxT("CloseDown"))

References wxT().

Referenced by Get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeSetupButton()

AButton * SelectionBar::MakeSetupButton ( )
private

Definition at line 180 of file SelectionBar.cpp.

181{
182 wxImage up = theTheme.Image(bmpRecoloredUpSmall);
183 up.Rescale(20, 20, wxIMAGE_QUALITY_HIGH);
184 wxImage down = theTheme.Image(bmpRecoloredDownSmall);
185 down.Rescale(20, 20, wxIMAGE_QUALITY_HIGH);
186 wxImage hiliteUp = theTheme.Image(bmpRecoloredUpHiliteSmall);
187 hiliteUp.Rescale(20, 20, wxIMAGE_QUALITY_HIGH);
188 wxImage hiliteDown = theTheme.Image(bmpRecoloredHiliteSmall);
189 hiliteDown.Rescale(20, 20, wxIMAGE_QUALITY_HIGH);
190
191 auto btn = safenew AButton(
192 this, wxID_ANY, wxDefaultPosition, wxSize { 20, 20 }, up, hiliteUp, down,
193 hiliteDown, up, false);
194
196 btn->SetIcon(theTheme.Image(bmpCogwheel));
197 btn->SetLabel({});
198 btn->SetName(XO("Selection Toolbar Setup").Translation());
199
200 return btn;
201}
wxImage(22, 22)
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
void SetButtonType(Type type)
Definition: AButton.cpp:147
@ FrameButton
Definition: AButton.h:114
wxImage & Image(int iIndex)

References AButton::FrameButton, ThemeBase::Image(), safenew, AButton::SetButtonType(), theTheme, wxImage(), and XO().

Referenced by AddSelectionSetupButton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ModifySelection()

void SelectionBar::ModifySelection ( int  driver,
bool  done = false 
)
private

Definition at line 362 of file SelectionBar.cpp.

363{
364 // Only update a value if user typed something in.
365 // The reason is the controls may be less accurate than
366 // the values.
367 double start = mStart;
368 double end = mEnd;
369 double center = mCenter;
370 double length = mLength;
371
372 if (driver == 0)
373 {
374 if (
377 start = mTimeControls[0]->GetValue();
378 else if (
381 length = mTimeControls[0]->GetValue();
382 else
383 wxFAIL_MSG("Unexpected selection mode");
384 }
385 else if (driver == 1)
386 {
387 if (
390 end = mTimeControls[1]->GetValue();
392 length = mTimeControls[1]->GetValue();
394 center = mTimeControls[1]->GetValue();
395 else
396 wxFAIL_MSG("Unexpected selection mode");
397 }
398 else
399 {
400 wxFAIL_MSG("Illegal selection driver");
401 }
402
403 switch (mSelectionMode)
404 {
406 if (driver == 0 && end < start)
407 end = start;
408 else if (driver == 1 && start > end)
409 start = end;
410 break;
412 // Nothing can go wrong here
413 end = start + length;
414 break;
416 start = end - length;
417
418 if (start < 0)
419 {
420 // Length is set by user
421 if (driver == 0)
422 end -= start;
423
424 start = 0;
425 }
426 break;
428 start = center - length / 2.0;
429
430 if (start < 0)
431 {
432 // Length is set by user
433 if (driver == 0)
434 center = length / 2.0;
435 else
436 // Center is set by user
437 length = center * 2.0;
438
439 start = 0;
440 }
441
442 end = center + length / 2.0;
443 break;
444 default:
445 break;
446 }
447
448 // Places the start-end markers on the track panel.
450 manager.ModifySelection(start, end, done);
451}
static const AttachedProjectObjects::RegisteredFactory manager
static ProjectSelectionManager & Get(AudacityProject &project)
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References PackedArray::end(), ProjectSelectionManager::Get(), LengthCenter, LengthEnd, manager, mCenter, mEnd, mLength, ToolBar::mProject, mSelectionMode, mStart, mTimeControls, StartEnd, and StartLength.

Referenced by AddTime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnCaptureKey()

void SelectionBar::OnCaptureKey ( wxCommandEvent &  event)
private

Definition at line 604 of file SelectionBar.cpp.

605{
606 wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
607 wxWindow *w = FindFocus();
608 int keyCode = kevent->GetKeyCode();
609
610 // Convert numeric keypad entries.
611 if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9)) {
612 keyCode -= WXK_NUMPAD0 - '0';
613 }
614
615 if (keyCode >= '0' && keyCode <= '9') {
616 return;
617 }
618
619 event.Skip();
620}
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:373

References BasicUI::FindFocus().

Here is the call graph for this function:

◆ OnFocus()

void SelectionBar::OnFocus ( wxFocusEvent &  event)
private

Definition at line 599 of file SelectionBar.cpp.

600{
601 KeyboardCapture::OnFocus( *this, event );
602}
void OnFocus(wxWindow &window, wxFocusEvent &event)
a function useful to implement a focus event handler The window releases the keyboard if the event is...

References KeyboardCapture::OnFocus().

Here is the call graph for this function:

◆ OnFormatsChanged()

void SelectionBar::OnFormatsChanged ( struct ProjectNumericFormatsEvent  evt)
private

Definition at line 588 of file SelectionBar.cpp.

589{
590 auto &formats = ProjectNumericFormats::Get(mProject);
591 switch (evt.type) {
593 return SetSelectionFormat(formats.GetSelectionFormat());
594 default:
595 break;
596 }
597}
void SetSelectionFormat(const NumericFormatID &format)
enum ProjectNumericFormatsEvent::Type type

References ProjectNumericFormatsEvent::ChangedSelectionFormat, ProjectNumericFormats::Get(), ToolBar::mProject, SetSelectionFormat(), and ProjectNumericFormatsEvent::type.

Here is the call graph for this function:

◆ OnIdle()

void SelectionBar::OnIdle ( wxIdleEvent &  evt)
private

Definition at line 496 of file SelectionBar.cpp.

497{
498 evt.Skip();
499 const auto& selectedRegion = ViewInfo::Get(mProject).selectedRegion;
500
501 SetTimes(selectedRegion.t0(), selectedRegion.t1());
502}
void SetTimes(double start, double end)
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235

References ViewInfo::Get(), ToolBar::mProject, ViewInfo::selectedRegion, and SetTimes().

Here is the call graph for this function:

◆ OnSize()

void SelectionBar::OnSize ( wxSizeEvent &  evt)
private

Definition at line 353 of file SelectionBar.cpp.

354{
355 Refresh( true );
356
357 evt.Skip();
358}

◆ OnUpdate()

void SelectionBar::OnUpdate ( wxCommandEvent &  evt)
private

Definition at line 454 of file SelectionBar.cpp.

455{
456 evt.Skip(false);
457
458 wxWindow *w = FindFocus();
459
460 auto focusedCtrlIt =
461 std::find(mTimeControls.begin(), mTimeControls.end(), w);
462
463 const auto focusedCtrlIdx =
464 focusedCtrlIt != mTimeControls.end() ?
465 std::distance(mTimeControls.begin(), focusedCtrlIt) :
466 -1;
467
468 auto format = evt.GetString();
469
470 // Save format name before recreating the controls so they resize properly
471 if (mTimeControls.front())
472 {
473 auto &formats = ProjectNumericFormats::Get(mProject);
474 formats.SetSelectionFormat(format);
475 // Then my Subscription is called
476 }
477
478 // ReCreateButtons() will get rid of our sizers and controls
479 // so reset pointers first.
480 std::fill(mTimeControls.begin(), mTimeControls.end(), nullptr);
481
483
485
487
488 if (focusedCtrlIdx >= 0 && mTimeControls[focusedCtrlIdx])
489 mTimeControls[focusedCtrlIdx]->SetFocus();
490
492
493 Updated();
494}
void RegenerateTooltips() override
void UpdateTimeControlsFormat(const NumericFormatID &format)
void ValuesToControls()
virtual void ReCreateButtons()
Definition: ToolBar.cpp:533

References BasicUI::FindFocus(), anonymous_namespace{ExportPCM.cpp}::format, ProjectNumericFormats::Get(), ToolBar::mProject, mTimeControls, ToolBar::ReCreateButtons(), RegenerateTooltips(), ToolBar::Updated(), UpdateTimeControlsFormat(), and ValuesToControls().

Referenced by SetSelectionFormat(), and UpdatePrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Populate()

void SelectionBar::Populate ( )
overridevirtual

Implements ToolBar.

Definition at line 284 of file SelectionBar.cpp.

285{
286 SetBackgroundColour( theTheme.Colour( clrMedium ) );
287
288 mTimeControls[0] = mTimeControls[1] = {};
289
290 // Outer sizer has space top and left.
291 // Inner sizers have space on right only.
292 // This choice makes for a nice border and internal spacing and places clear responsibility
293 // on each sizer as to what spacings it creates.
294 wxFlexGridSizer *mainSizer = safenew wxFlexGridSizer(2, 1, 1);
295 Add(mainSizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5);
296
297 AddTitle(XO("Selection"), mainSizer);
298 AddTime(0, mainSizer);
299 AddSelectionSetupButton(mainSizer);
300 AddTime(1, mainSizer);
301
302 mSetupButton->MoveBeforeInTabOrder(mTimeControls[0]);
303
304 // Update the selection mode before the layout
306 mainSizer->Layout();
308 Layout();
309
310 CallAfter([this]{
311 auto &formats = ProjectNumericFormats::Get(mProject);
312 SetSelectionFormat(formats.GetSelectionFormat());
313 });
314
315}
void AddTitle(const TranslatableString &Title, wxSizer *pSizer)
void AddSelectionSetupButton(wxSizer *pSizer)
void AddTime(int id, wxSizer *pSizer)
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:709
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:208

References ToolBar::Add(), AddSelectionSetupButton(), AddTime(), AddTitle(), BasicUI::CallAfter(), ThemeBase::Colour(), ProjectNumericFormats::Get(), ToolBar::mProject, mSelectionMode, mSetupButton, mTimeControls, RegenerateTooltips(), safenew, SetSelectionFormat(), SetSelectionMode(), theTheme, and XO().

Here is the call graph for this function:

◆ RegenerateTooltips()

void SelectionBar::RegenerateTooltips ( )
overridevirtual

Implements ToolBar.

Definition at line 349 of file SelectionBar.cpp.

350{
351}

Referenced by OnUpdate(), Populate(), and UpdatePrefs().

Here is the caller graph for this function:

◆ Repaint()

void SelectionBar::Repaint ( wxDC *  WXUNUSEDdc)
inlineoverride

Definition at line 62 of file SelectionBar.h.

62{};

◆ SelectionModeUpdated()

void SelectionBar::SelectionModeUpdated ( )
private

Definition at line 504 of file SelectionBar.cpp.

505{
506 // We just changed the mode. Remember it.
508
510}
void UpdateSelectionMode(SelectionBar::SelectionMode selectionMode)

References FitToTimeControls(), mSelectionMode, and anonymous_namespace{SelectionBar.cpp}::UpdateSelectionMode().

Referenced by AddSelectionSetupButton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetSelectionFormat()

void SelectionBar::SetSelectionFormat ( const NumericFormatID format)

Definition at line 573 of file SelectionBar.cpp.

574{
575 if (mTimeControls.front() == nullptr)
576 return;
577
578 const bool changed = mTimeControls.front()->SetFormatName(format);
579
580 // Test first whether changed, to avoid infinite recursion from OnUpdate
581 if ( changed ) {
582 wxCommandEvent e;
583 e.SetString(format.GET());
584 OnUpdate(e);
585 }
586}
void OnUpdate(wxCommandEvent &evt)

References anonymous_namespace{ExportPCM.cpp}::format, mTimeControls, and OnUpdate().

Referenced by OnFormatsChanged(), and Populate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetSelectionMode()

void SelectionBar::SetSelectionMode ( SelectionMode  mode)
private

Definition at line 515 of file SelectionBar.cpp.

516{
517 mSelectionMode = mode;
518
519 // Update names and WindowIds for the screen readers
520 auto& modeName = ModeNames[static_cast<size_t>(mode)];
521
522 if (mTimeControls[0]) {
523 mTimeControls[0]->SetName(modeName.first);
524 mTimeControls[0]->SetId(WindowIDs.at(modeName.first));
525 }
526
527 if (mTimeControls[1]) {
528 mTimeControls[1]->SetName(modeName.second);
529 mTimeControls[1]->SetId(WindowIDs.at(modeName.second));
530 }
531
532 UpdateTimeControlsFormat(mTimeControls[0]->GetFormatName());
533
535}
std::pair< const TranslatableString &, const TranslatableString & > ModeNames[]
std::unordered_map< TranslatableString, wxWindowID > WindowIDs

References anonymous_namespace{SelectionBar.cpp}::ModeNames, mSelectionMode, mTimeControls, UpdateTimeControlsFormat(), ValuesToControls(), and anonymous_namespace{SelectionBar.cpp}::WindowIDs.

Referenced by AddSelectionSetupButton(), and Populate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetTimes()

void SelectionBar::SetTimes ( double  start,
double  end 
)

Definition at line 558 of file SelectionBar.cpp.

559{
560 if ( start != mStart || end != mEnd
562 ) {
563 mStart = start;
564 mEnd = end;
565 mLength = end-start;
566 mCenter = (end+start)/2.0;
568
570 }
571}
SelectionMode mLastSelectionMode
Definition: SelectionBar.h:101

References PackedArray::end(), mCenter, mEnd, mLastSelectionMode, mLength, mSelectionMode, mStart, and ValuesToControls().

Referenced by OnIdle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShownByDefault()

bool SelectionBar::ShownByDefault ( ) const
overridevirtual

Whether the toolbar should be shown by default. Default implementation returns true.

Reimplemented from ToolBar.

Definition at line 153 of file SelectionBar.cpp.

154{
155 return true;
156}

◆ UpdatePrefs()

void SelectionBar::UpdatePrefs ( )
overridevirtual

Implements PrefsListener.

Definition at line 317 of file SelectionBar.cpp.

318{
319 // The project rate is no longer driven from here.
320 // When preferences change, the Project learns about it too.
321 // If necessary we can drive the SelectionBar mRate via the Project
322 // calling our SetRate().
323 // As of 13-Sep-2018, changes to the sample rate pref will only affect
324 // creation of new projects, not the sample rate in existing ones.
325
326 // This will only change the selection mode during a "Reset Configuration"
327 // action since the read value will be the same during a normal preferences
328 // update.
330
331 // This will only change the time format during a "Reset Configuration"
332 // action since the read value will be the same during a normal preferences
333 // update.
334 wxCommandEvent e;
338 gPrefs->Read(wxT("/SelectionFormat"), wxT(""))).Internal());
339 OnUpdate(e);
340
341 // Set label to pull in language change
342 SetLabel(XO("Selection"));
343
345 // Give base class a chance
347}
@ Internal
Indicates internal failure from Audacity.
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:408
void UpdatePrefs() override
Definition: ToolBar.cpp:622
virtual bool Read(const wxString &key, bool *value) const =0
NUMERIC_FORMATS_API NumericFormatSymbol Lookup(const FormatterContext &context, const NumericConverterType &type, const NumericFormatID &formatIdentifier)
Looks up the format, returns Default for the type if the format is not registered.

References gPrefs, Internal, NumericConverterFormats::Lookup(), ToolBar::mProject, mSelectionMode, NumericConverterType_TIME(), OnUpdate(), FormatterContext::ProjectContext(), audacity::BasicSettings::Read(), anonymous_namespace{SelectionBar.cpp}::ReadSelectionMode(), RegenerateTooltips(), ToolBar::SetLabel(), ToolBar::UpdatePrefs(), wxT(), and XO().

Referenced by Create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateTimeControlsFormat()

void SelectionBar::UpdateTimeControlsFormat ( const NumericFormatID format)
private

Definition at line 622 of file SelectionBar.cpp.

623{
624 for (size_t controlIndex = 0; controlIndex < mTimeControls.size();
625 ++controlIndex)
626 {
627 auto ctrl = mTimeControls[controlIndex];
628
629 if (ctrl == nullptr)
630 continue;
631
632 const auto type =
633 TimeConverterType[static_cast<size_t>(mSelectionMode)][controlIndex];
634
635 ctrl->SetTypeAndFormatName(
636 type, type != NumericConverterType_DURATION() ?
637 format :
639 }
640}
const NumericConverterType & NumericConverterType_DURATION()
NUMERIC_FORMATS_API NumericFormatID GetBestDurationFormat(const NumericFormatID &timeFormat)
Return the best duration format for the given time format. Currently is an identity function.
const NumericConverterType TimeConverterType[][2]

References anonymous_namespace{ExportPCM.cpp}::format, NumericConverterFormats::GetBestDurationFormat(), mSelectionMode, mTimeControls, NumericConverterType_DURATION(), and anonymous_namespace{SelectionBar.cpp}::TimeConverterType.

Referenced by OnUpdate(), and SetSelectionMode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ValuesToControls()

void SelectionBar::ValuesToControls ( )
private

Definition at line 537 of file SelectionBar.cpp.

538{
539 const double valuePairs[4][2] = {
540 { mStart, mEnd },
541 { mStart, mLength },
542 { mLength, mEnd },
543 { mLength, mCenter } };
544
545 const auto value = valuePairs[static_cast<size_t>(mSelectionMode)];
546
547 size_t i = 0;
548 for (auto ctrl : mTimeControls)
549 {
550 if (ctrl != nullptr)
551 ctrl->SetValue(value[i]);
552
553 i++;
554 }
555}

References mCenter, mEnd, mLength, mSelectionMode, mStart, and mTimeControls.

Referenced by OnUpdate(), SetSelectionMode(), and SetTimes().

Here is the caller graph for this function:

Member Data Documentation

◆ mCenter

double SelectionBar::mCenter
private

Definition at line 98 of file SelectionBar.h.

Referenced by ModifySelection(), SetTimes(), and ValuesToControls().

◆ mEnd

double SelectionBar::mEnd
private

Definition at line 98 of file SelectionBar.h.

Referenced by ModifySelection(), SetTimes(), and ValuesToControls().

◆ mFormatChangedToFitValueSubscription

Observer::Subscription SelectionBar::mFormatChangedToFitValueSubscription[2]
private

Definition at line 106 of file SelectionBar.h.

Referenced by AddTime().

◆ mFormatsSubscription

const Observer::Subscription SelectionBar::mFormatsSubscription
private

Definition at line 109 of file SelectionBar.h.

◆ mLastSelectionMode

SelectionMode SelectionBar::mLastSelectionMode {}
private

Definition at line 101 of file SelectionBar.h.

Referenced by SetTimes().

◆ mLastValidText

wxString SelectionBar::mLastValidText
private

Definition at line 108 of file SelectionBar.h.

◆ mLength

double SelectionBar::mLength
private

Definition at line 98 of file SelectionBar.h.

Referenced by ModifySelection(), SetTimes(), and ValuesToControls().

◆ mRate

double SelectionBar::mRate
private

Definition at line 97 of file SelectionBar.h.

Referenced by SelectionBar().

◆ mSelectionMode

SelectionMode SelectionBar::mSelectionMode {}
private

◆ mSetupButton

AButton* SelectionBar::mSetupButton {}
private

Definition at line 104 of file SelectionBar.h.

Referenced by AddSelectionSetupButton(), and Populate().

◆ mStart

double SelectionBar::mStart
private

Definition at line 98 of file SelectionBar.h.

Referenced by ModifySelection(), SetTimes(), and ValuesToControls().

◆ mTimeControls

std::array<NumericTextCtrl*, 2> SelectionBar::mTimeControls {}
private

The documentation for this class was generated from the following files: