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
62 Track *Get();
63
65
68 void Set(Track *pTrack, bool focusPanel = false);
69
70 void MessageForScreenReader(const TranslatableString& message);
71
73 void UpdateAccessibility();
74
75 // Returns currently focused track, never changing it
76 std::shared_ptr<Track> PeekFocus() const;
77
78 int TrackNum(const std::shared_ptr<Track> &track) const;
79
80 int NumFocusedTrack() const { return mNumFocusedTrack; }
81
82 // Returns currently focused track or first one if none focused
83 std::shared_ptr<Track> GetFocus();
84
85 const TrackList &GetTracks() const;
86
87 std::shared_ptr<Track> FindTrack(int num) const;
88
89 // Changes focus to a specified track
90 // Return is the actual focused track, which may be different from
91 // the argument when that is null
92 std::shared_ptr<Track> SetFocus(std::shared_ptr<Track> track = {},
93 bool focusPanel = false);
94
95private:
96 TrackList &GetTracks();
97
99 std::unique_ptr<TrackFocusCallbacks> mpCallbacks;
100 std::weak_ptr<Track> mFocusedTrack;
101 int mNumFocusedTrack{ 0 };
102};
103
104#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:100
std::unique_ptr< TrackFocusCallbacks > mpCallbacks
Definition: TrackFocus.h:99
TrackFocus & operator=(const TrackFocus &)=delete
int NumFocusedTrack() const
Definition: TrackFocus.h:80
AudacityProject & mProject
Definition: TrackFocus.h:98
TrackFocus(const TrackFocus &)=delete
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:850
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:392
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
std::shared_ptr< Track > FindTrack(TrackPanelCell *pCell)
Definition: TrackPanel.cpp:538
A convenient default parameter for class template Site.
Definition: ClientData.h:29
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