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