Audacity 3.2.0
TrackFocus.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 TrackFocus.h
6
7 Leland Lucius
8
9 Paul Licameli split from TrackPanelAx.h
10
11**********************************************************************/
12#ifndef __AUDACITY_TRACK_FOCUS__
13#define __AUDACITY_TRACK_FOCUS__
14
15#include <memory>
16
17#include "ClientData.h" // to inherit
18#include "Observer.h"
19
20class AudacityProject;
21class Track;
22class TrackList;
23
25 bool focusPanel = false;
26};
27
29struct TRACK_SELECTION_API TrackFocusCallbacks {
31
32 virtual void MessageForScreenReader(const TranslatableString& message) = 0;
33 virtual void BeginChangeFocus() = 0;
34 virtual void EndChangeFocus(const std::shared_ptr<Track> &track) = 0;
35 virtual void UpdateAccessibility() = 0;
36};
37
38class TRACK_SELECTION_API TrackFocus final
39 : public ClientData::Base
40 , public Observer::Publisher<TrackFocusChangeMessage>
41 , public std::enable_shared_from_this<TrackFocus>
42{
43public:
45 static const TrackFocus &Get(const AudacityProject &project);
46
48 ~TrackFocus() final;
49
50 TrackFocus(const TrackFocus &) = delete;
51 TrackFocus& operator=(const TrackFocus &) = delete;
52
53 void SetCallbacks(std::unique_ptr<TrackFocusCallbacks> pCallbacks);
54
63 Track *Get();
64
66
69 void Set(Track *pTrack, bool focusPanel = false);
70
71 void MessageForScreenReader(const TranslatableString& message);
72
74 void UpdateAccessibility();
75
76 // Returns currently focused track, never changing it
77 std::shared_ptr<Track> PeekFocus() const;
78
79 int TrackNum(const std::shared_ptr<Track> &track) const;
80
81 int NumFocusedTrack() const { return mNumFocusedTrack; }
82
83 // Returns currently focused track or first one if none focused
84 std::shared_ptr<Track> GetFocus();
85
86 const TrackList &GetTracks() const;
87
88 std::shared_ptr<Track> FindTrack(int num) const;
89
90 // Changes focus to a specified track
91 // Return is the actual focused track, which may be different from
92 // the argument when that is null
93 std::shared_ptr<Track> SetFocus(std::shared_ptr<Track> track = {},
94 bool focusPanel = false);
95
96private:
97 TrackList &GetTracks();
98
100 std::unique_ptr<TrackFocusCallbacks> mpCallbacks;
101 std::weak_ptr<Track> mFocusedTrack;
102 int mNumFocusedTrack{ 0 };
103};
104
105#endif // __AUDACITY_TRACK_FOCUS__
Utility ClientData::Site to register hooks into a host class that attach client data.
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
std::weak_ptr< Track > mFocusedTrack
Definition: TrackFocus.h:101
std::unique_ptr< TrackFocusCallbacks > mpCallbacks
Definition: TrackFocus.h:100
TrackFocus & operator=(const TrackFocus &)=delete
int NumFocusedTrack() const
Definition: TrackFocus.h:81
AudacityProject & mProject
Definition: TrackFocus.h:99
TrackFocus(const TrackFocus &)=delete
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:993
Holds a msgid for the translation catalog; may also bind format arguments.
void SetFocus(const WindowPlacement &focus)
Set the window that accepts keyboard input.
Definition: BasicUI.h:382
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
std::shared_ptr< Track > FindTrack(TrackPanelCell *pCell)
Definition: TrackPanel.cpp:537
A convenient default parameter for class template Site.
Definition: ClientData.h:28
A fa├žade hiding platform-specific accessibility API.
Definition: TrackFocus.h:29
virtual void EndChangeFocus(const std::shared_ptr< Track > &track)=0
virtual void BeginChangeFocus()=0
virtual void UpdateAccessibility()=0
virtual void MessageForScreenReader(const TranslatableString &message)=0
virtual ~TrackFocusCallbacks()
bool focusPanel
whether to focus the window that shows tracks
Definition: TrackFocus.h:25