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

Helper to TrackPanel to give accessibility. More...

#include <TrackPanelAx.h>

Collaboration diagram for TrackPanelAx:
[legend]

Public Types

using RectangleFinder = std::function< wxRect(Track &) >
 

Public Member Functions

 TrackPanelAx (AudacityProject &project)
 
virtual ~TrackPanelAx ()
 
void SetFinder (const RectangleFinder &finder)
 
std::shared_ptr< TrackGetFocus ()
 
std::shared_ptr< TrackSetFocus (std::shared_ptr< Track > track={})
 
bool IsFocused (const Track *track)
 
void Updated ()
 
void MessageForScreenReader (const TranslatableString &message)
 
wxWindow * GetWindow () const
 
void SetWindow (wxWindow *window)
 

Private Member Functions

TrackListGetTracks ()
 
int TrackNum (const std::shared_ptr< Track > &track)
 
std::shared_ptr< TrackFindTrack (int num)
 

Private Attributes

AudacityProjectmProject
 
wxWindow * mWindow {}
 
RectangleFinder mFinder
 
std::weak_ptr< TrackmFocusedTrack
 
int mNumFocusedTrack
 
wxString mMessage
 
bool mTrackName
 
int mMessageCount
 

Detailed Description

Helper to TrackPanel to give accessibility.

Definition at line 35 of file TrackPanelAx.h.

Member Typedef Documentation

◆ RectangleFinder

using TrackPanelAx::RectangleFinder = std::function< wxRect( Track& ) >

Definition at line 44 of file TrackPanelAx.h.

Constructor & Destructor Documentation

◆ TrackPanelAx()

TrackPanelAx::TrackPanelAx ( AudacityProject project)

Definition at line 38 of file TrackPanelAx.cpp.

39 :
40#if wxUSE_ACCESSIBILITY
41 WindowAccessible( nullptr ) // window pointer must be set after construction
42 ,
43#endif
44 mProject{ project }
45{
46 mTrackName = true;
47 mMessageCount = 0;
49}
int mNumFocusedTrack
Definition: TrackPanelAx.h:147
AudacityProject & mProject
Definition: TrackPanelAx.h:138
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...

References mMessageCount, mNumFocusedTrack, and mTrackName.

◆ ~TrackPanelAx()

TrackPanelAx::~TrackPanelAx ( )
virtual

Definition at line 51 of file TrackPanelAx.cpp.

52{
53}

Member Function Documentation

◆ FindTrack()

std::shared_ptr< Track > TrackPanelAx::FindTrack ( int  num)
private

Definition at line 190 of file TrackPanelAx.cpp.

191{
192 int ndx = 0;
193
194 for ( auto t : GetTracks().Leaders() )
195 {
196 ndx++;
197 if( ndx == num )
198 return t->SharedPointer();
199 }
200
201 return {};
202}
TrackList & GetTracks()

References GetTracks().

Referenced by GetFocus().

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

◆ GetFocus()

std::shared_ptr< Track > TrackPanelAx::GetFocus ( )

Definition at line 64 of file TrackPanelAx.cpp.

65{
66 auto focusedTrack = mFocusedTrack.lock();
67 if( !focusedTrack ) {
68 if (mNumFocusedTrack >=1) {
69 // This prevents the focus from being unnecessarily set to track 1
70 // when effects are applied. (Applying an effect can change
71 // the pointers of the selected tracks.)
72 focusedTrack = FindTrack(mNumFocusedTrack);
73 }
74 if (!focusedTrack) {
75 focusedTrack =
76 Track::SharedPointer( *GetTracks().Any().first );
77 // only call SetFocus if the focus has changed to avoid
78 // unnecessary focus events
79 if (focusedTrack)
80 focusedTrack = SetFocus();
81 }
82 }
83
84 if( !TrackNum( focusedTrack ) )
85 {
86 mFocusedTrack.reset();
87 return {};
88 }
89
90 return( focusedTrack );
91}
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:224
std::weak_ptr< Track > mFocusedTrack
Definition: TrackPanelAx.h:146
int TrackNum(const std::shared_ptr< Track > &track)
std::shared_ptr< Track > SetFocus(std::shared_ptr< Track > track={})
std::shared_ptr< Track > FindTrack(int num)

References FindTrack(), GetTracks(), mFocusedTrack, mNumFocusedTrack, SetFocus(), Track::SharedPointer(), and TrackNum().

Referenced by MessageForScreenReader(), and Updated().

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

◆ GetTracks()

TrackList & TrackPanelAx::GetTracks ( )
private

Definition at line 55 of file TrackPanelAx.cpp.

56{
57 return TrackList::Get( mProject );
58}
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:360

References TrackList::Get(), and mProject.

Referenced by FindTrack(), GetFocus(), IsFocused(), SetFocus(), and TrackNum().

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

◆ GetWindow()

wxWindow * TrackPanelAx::GetWindow ( ) const
inline

Definition at line 128 of file TrackPanelAx.h.

128{ return mWindow; }
wxWindow * mWindow
Definition: TrackPanelAx.h:141

References mWindow.

Referenced by MessageForScreenReader(), SetFocus(), and Updated().

Here is the caller graph for this function:

◆ IsFocused()

bool TrackPanelAx::IsFocused ( const Track track)

Definition at line 155 of file TrackPanelAx.cpp.

156{
157 auto focusedTrack = mFocusedTrack.lock();
158 if( !focusedTrack )
159 focusedTrack = SetFocus();
160
161 // Remap track pointer if there are outstanding pending updates
162 auto origTrack =
163 GetTracks().FindById( track->GetId() );
164 if (origTrack)
165 track = origTrack;
166
167 return focusedTrack
168 ? TrackList::Channels(focusedTrack.get()).contains(track)
169 : !track;
170}
TrackId GetId() const
Definition: Track.h:214
Track * FindById(TrackId id)
Definition: Track.cpp:569
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1406

References TrackList::Channels(), TrackList::FindById(), Track::GetId(), GetTracks(), mFocusedTrack, and SetFocus().

Here is the call graph for this function:

◆ MessageForScreenReader()

void TrackPanelAx::MessageForScreenReader ( const TranslatableString message)

Definition at line 224 of file TrackPanelAx.cpp.

225{
226#if wxUSE_ACCESSIBILITY
228 {
229 auto t = GetFocus();
230 int childId = t ? TrackNum(t) : 0;
231
232 mMessage = message.Translation();
233
234 // append \a alternatively, so that the string is never the same as the previous string.
235 // This ensures that screen readers read it.
236 if (mMessageCount % 2 == 0)
237 mMessage.Append('\a');
239
240 mTrackName = false;
241 NotifyEvent(wxACC_EVENT_OBJECT_NAMECHANGE,
242 GetWindow(),
243 wxOBJID_CLIENT,
244 childId);
245 }
246
247#endif
248}
std::shared_ptr< Track > GetFocus()
wxString mMessage
Definition: TrackPanelAx.h:149
wxWindow * GetWindow() const
Definition: TrackPanelAx.h:128
wxString Translation() const
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:343

References BasicUI::FindFocus(), GetFocus(), GetWindow(), mMessage, mMessageCount, mTrackName, TrackNum(), and TranslatableString::Translation().

Here is the call graph for this function:

◆ SetFinder()

void TrackPanelAx::SetFinder ( const RectangleFinder finder)
inline

Definition at line 45 of file TrackPanelAx.h.

45{ mFinder = finder; }
RectangleFinder mFinder
Definition: TrackPanelAx.h:144

References mFinder.

◆ SetFocus()

std::shared_ptr< Track > TrackPanelAx::SetFocus ( std::shared_ptr< Track track = {})

Definition at line 94 of file TrackPanelAx.cpp.

95{
96 mTrackName = true;
97
98#if wxUSE_ACCESSIBILITY
99
100 auto focusedTrack = mFocusedTrack.lock();
101 if( focusedTrack && !focusedTrack->GetSelected() )
102 {
103 NotifyEvent( wxACC_EVENT_OBJECT_SELECTIONREMOVE,
104 GetWindow(),
105 wxOBJID_CLIENT,
106 TrackNum( focusedTrack ) );
107 }
108#endif
109
110 if( !track )
111 track = Track::SharedPointer( *GetTracks().Any().begin() );
112
113 if ( mFocusedTrack.lock() != track ) {
114 mFocusedTrack = track;
115 BasicUI::CallAfter([wFocus = TrackFocus::Get(mProject).weak_from_this()]{
116 if (auto pFocus = wFocus.lock())
117 pFocus->Publish({});
118 });
119 }
120 mNumFocusedTrack = TrackNum(track);
121
122#if wxUSE_ACCESSIBILITY
123 if( track )
124 {
126 {
127 NotifyEvent( wxACC_EVENT_OBJECT_FOCUS,
128 GetWindow(),
129 wxOBJID_CLIENT,
131 }
132
133 if( track->GetSelected() )
134 {
135 NotifyEvent( wxACC_EVENT_OBJECT_SELECTION,
136 GetWindow(),
137 wxOBJID_CLIENT,
139 }
140 }
141 else
142 {
143 NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
144 GetWindow(),
145 wxOBJID_CLIENT,
146 wxACC_SELF);
147 }
148
149#endif
150
151 return track;
152}
Track * Get()
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:208
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150

References PackedArray::begin(), BasicUI::CallAfter(), BasicUI::FindFocus(), TrackFocus::Get(), GetTracks(), GetWindow(), mFocusedTrack, mNumFocusedTrack, mProject, mTrackName, Track::SharedPointer(), and TrackNum().

Referenced by GetFocus(), and IsFocused().

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

◆ SetWindow()

void TrackPanelAx::SetWindow ( wxWindow *  window)
inline

Definition at line 129 of file TrackPanelAx.h.

129{ mWindow = window; }

References mWindow.

◆ TrackNum()

int TrackPanelAx::TrackNum ( const std::shared_ptr< Track > &  track)
private

Definition at line 172 of file TrackPanelAx.cpp.

173{
174 // Find 1-based position of the target in the visible tracks, or 0 if not
175 // found
176 int ndx = 0;
177
178 for ( auto t : GetTracks().Leaders() )
179 {
180 ndx++;
181 if( t == target.get() )
182 {
183 return ndx;
184 }
185 }
186
187 return 0;
188}

References GetTracks().

Referenced by GetFocus(), MessageForScreenReader(), SetFocus(), and Updated().

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

◆ Updated()

void TrackPanelAx::Updated ( )

Definition at line 204 of file TrackPanelAx.cpp.

205{
206#if wxUSE_ACCESSIBILITY
207 auto t = GetFocus();
208 mTrackName = true;
209
210 // The object_focus event is only needed by Window-Eyes
211 // and can be removed when we cease to support this screen reader.
212 NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
213 GetWindow(),
214 wxOBJID_CLIENT,
215 TrackNum(t));
216
217 NotifyEvent(wxACC_EVENT_OBJECT_NAMECHANGE,
218 GetWindow(),
219 wxOBJID_CLIENT,
220 TrackNum(t));
221#endif
222}

References GetFocus(), GetWindow(), mTrackName, and TrackNum().

Here is the call graph for this function:

Member Data Documentation

◆ mFinder

RectangleFinder TrackPanelAx::mFinder
private

Definition at line 144 of file TrackPanelAx.h.

Referenced by SetFinder().

◆ mFocusedTrack

std::weak_ptr<Track> TrackPanelAx::mFocusedTrack
private

Definition at line 146 of file TrackPanelAx.h.

Referenced by GetFocus(), IsFocused(), and SetFocus().

◆ mMessage

wxString TrackPanelAx::mMessage
private

Definition at line 149 of file TrackPanelAx.h.

Referenced by MessageForScreenReader().

◆ mMessageCount

int TrackPanelAx::mMessageCount
private

Definition at line 151 of file TrackPanelAx.h.

Referenced by MessageForScreenReader(), and TrackPanelAx().

◆ mNumFocusedTrack

int TrackPanelAx::mNumFocusedTrack
private

Definition at line 147 of file TrackPanelAx.h.

Referenced by GetFocus(), SetFocus(), and TrackPanelAx().

◆ mProject

AudacityProject& TrackPanelAx::mProject
private

Definition at line 138 of file TrackPanelAx.h.

Referenced by GetTracks(), and SetFocus().

◆ mTrackName

bool TrackPanelAx::mTrackName
private

Definition at line 150 of file TrackPanelAx.h.

Referenced by MessageForScreenReader(), SetFocus(), TrackPanelAx(), and Updated().

◆ mWindow

wxWindow* TrackPanelAx::mWindow {}
private

Definition at line 141 of file TrackPanelAx.h.

Referenced by GetWindow(), and SetWindow().


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