Audacity 3.2.0
TrackPanelAx.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 TrackPanelAx.h
6
7 Leland Lucius
8
9**********************************************************************/
10
11#ifndef __AUDACITY_TRACK_PANEL_ACCESSIBILITY__
12#define __AUDACITY_TRACK_PANEL_ACCESSIBILITY__
13
14
15
16#include <functional>
17#include <memory>
18
19#include <wx/setup.h> // for wxUSE_* macros
20
21#if wxUSE_ACCESSIBILITY
22#include "WindowAccessible.h" // to inherit
23#endif
24
25#include "ClientData.h" // to inherit
26#include "Observer.h"
27
28class wxRect;
29class wxWindow;
30
31class AudacityProject;
32class Track;
33class TrackList;
34
35class TrackPanelAx final
36#if wxUSE_ACCESSIBILITY
37 : public WindowAccessible
38#endif
39{
40public:
42 virtual ~ TrackPanelAx();
43
44 using RectangleFinder = std::function< wxRect( Track& ) >;
45 void SetFinder( const RectangleFinder &finder ) { mFinder = finder; }
46
47 // Returns currently focused track or first one if none focused
48 std::shared_ptr<Track> GetFocus();
49
50 // Changes focus to a specified track
51 // Return is the actual focused track, which may be different from
52 // the argument when that is null
53 std::shared_ptr<Track> SetFocus( std::shared_ptr<Track> track = {} );
54
55 // Returns TRUE if passed track has the focus
56 bool IsFocused( const Track *track );
57
58 // Called to signal changes to a track
59 void Updated();
60
61 void MessageForScreenReader(const TranslatableString& message);
62
63#if wxUSE_ACCESSIBILITY
64 // Retrieves the address of an IDispatch interface for the specified child.
65 // All objects must support this property.
66 wxAccStatus GetChild(int childId, wxAccessible** child) override;
67
68 // Gets the number of children.
69 wxAccStatus GetChildCount(int* childCount) override;
70
71 // Gets the default action for this object (0) or > 0 (the action for a child).
72 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
73 // string if there is no action.
74 // The retrieved string describes the action that is performed on an object,
75 // not what the object does as a result. For example, a toolbar button that prints
76 // a document has a default action of "Press" rather than "Prints the current document."
77 wxAccStatus GetDefaultAction(int childId, wxString *actionName) override;
78
79 // Returns the description for this object or a child.
80 wxAccStatus GetDescription(int childId, wxString *description) override;
81
82 // Gets the window with the keyboard focus.
83 // If childId is 0 and child is NULL, no object in
84 // this subhierarchy has the focus.
85 // If this object has the focus, child should be 'this'.
86 wxAccStatus GetFocus(int *childId, wxAccessible **child) override;
87
88 // Returns help text for this object or a child, similar to tooltip text.
89 wxAccStatus GetHelpText(int childId, wxString *helpText) override;
90
91 // Returns the keyboard shortcut for this object or child.
92 // Return e.g. ALT+K
93 wxAccStatus GetKeyboardShortcut(int childId, wxString *shortcut) override;
94
95 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
96 // rect is in screen coordinates.
97 wxAccStatus GetLocation(wxRect& rect, int elementId) override;
98
99 // Gets the name of the specified object.
100 wxAccStatus GetName(int childId, wxString *name) override;
101
102 // Returns a role constant.
103 wxAccStatus GetRole(int childId, wxAccRole *role) override;
104
105 // Gets a variant representing the selected children
106 // of this object.
107 // Acceptable values:
108 // - a null variant (IsNull() returns TRUE)
109 // - a list variant (GetType() == wxT("list"))
110 // - an integer representing the selected child element,
111 // or 0 if this object is selected (GetType() == wxT("long"))
112 // - a "void*" pointer to a wxAccessible child object
113 wxAccStatus GetSelections(wxVariant *selections) override;
114
115 // Returns a state constant.
116 wxAccStatus GetState(int childId, long* state) override;
117
118 // Returns a localized string representing the value for the object
119 // or child.
120 wxAccStatus GetValue(int childId, wxString* strValue) override;
121
122 // Navigates from fromId to toId/toObject
123 wxAccStatus Navigate(wxNavDir navDir, int fromId, int* toId, wxAccessible** toObject) override;
124
125 // Modify focus or selection
126 wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags) override;
127#else
128 wxWindow *GetWindow() const { return mWindow; }
129 void SetWindow( wxWindow *window ) { mWindow = window; }
130#endif
131
132private:
133
135 int TrackNum( const std::shared_ptr<Track> &track );
136 std::shared_ptr<Track> FindTrack( int num );
137
139
140#if !wxUSE_ACCESSIBILITY
141 wxWindow *mWindow{};
142#endif
143
145
146 std::weak_ptr<Track> mFocusedTrack;
148
149 wxString mMessage;
152};
153
155
156class AUDACITY_DLL_API TrackFocus final
157 : public ClientData::Base
158 , public Observer::Publisher<TrackFocusChangeMessage>
159 , public std::enable_shared_from_this<TrackFocus>
160{
161public:
162 static TrackFocus &Get( AudacityProject &project );
163 static const TrackFocus &Get( const AudacityProject &project );
164
165 explicit TrackFocus( AudacityProject &project );
166 ~TrackFocus() override;
167
168 TrackFocus( const TrackFocus & ) PROHIBITED;
169 TrackFocus& operator=( const TrackFocus & ) PROHIBITED;
170
171 // Report the currently focused track, which may be null, otherwise is
172 // a leader track
173 // This function is not const, because it may have a side effect of setting
174 // a focus if none was already set
175 Track *Get();
176
177 // Set the track focus to a given track or to null
178 void Set( Track *pTrack );
179
180 // Not equivalent to pTrack == this->Get(): may return true also for
181 // other channels than the leader
182 // As with Get(), this is not const
183 bool IsFocused( const Track *pTrack );
184
185 void SetAccessible( wxWindow &owner,
186 std::unique_ptr< TrackPanelAx > pAccessible );
187
188 void MessageForScreenReader(const TranslatableString& message);
189
190 void UpdateAccessibility();
191
192private:
193 friend TrackPanelAx; // so it can Publish()
194
196
197#if wxUSE_ACCESSIBILITY
198 TrackPanelAx *mAx{};
199#else
200 std::unique_ptr<TrackPanelAx> mAx;
201#endif
202};
203
204#endif // __AUDACITY_TRACK_PANEL_ACCESSIBILITY__
Utility ClientData::Site to register hooks into a host class that attach client data.
const TranslatableString name
Definition: Distortion.cpp:76
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
TrackFocus & operator=(const TrackFocus &) PROHIBITED
TrackFocus(const TrackFocus &) PROHIBITED
std::unique_ptr< TrackPanelAx > mAx
Definition: TrackPanelAx.h:200
AudacityProject & mProject
Definition: TrackPanelAx.h:195
friend TrackPanelAx
Definition: TrackPanelAx.h:193
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:226
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1339
Helper to TrackPanel to give accessibility.
Definition: TrackPanelAx.h:39
RectangleFinder mFinder
Definition: TrackPanelAx.h:144
TrackPanelAx(AudacityProject &project)
std::weak_ptr< Track > mFocusedTrack
Definition: TrackPanelAx.h:146
void MessageForScreenReader(const TranslatableString &message)
std::shared_ptr< Track > GetFocus()
int mNumFocusedTrack
Definition: TrackPanelAx.h:147
void SetWindow(wxWindow *window)
Definition: TrackPanelAx.h:129
wxWindow * mWindow
Definition: TrackPanelAx.h:141
AudacityProject & mProject
Definition: TrackPanelAx.h:138
void SetFinder(const RectangleFinder &finder)
Definition: TrackPanelAx.h:45
TrackList & GetTracks()
int TrackNum(const std::shared_ptr< Track > &track)
wxString mMessage
Definition: TrackPanelAx.h:149
std::shared_ptr< Track > SetFocus(std::shared_ptr< Track > track={})
bool IsFocused(const Track *track)
std::shared_ptr< Track > FindTrack(int num)
wxWindow * GetWindow() const
Definition: TrackPanelAx.h:128
std::function< wxRect(Track &) > RectangleFinder
Definition: TrackPanelAx.h:44
Holds a msgid for the translation catalog; may also bind format arguments.
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
A convenient default parameter for class template Site.
Definition: ClientData.h:28