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 37 of file TrackPanelAx.h.

Member Typedef Documentation

◆ RectangleFinder

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

Definition at line 46 of file TrackPanelAx.h.

Constructor & Destructor Documentation

◆ TrackPanelAx()

TrackPanelAx::TrackPanelAx ( AudacityProject project)

Definition at line 41 of file TrackPanelAx.cpp.

42 :
43#if wxUSE_ACCESSIBILITY
44 WindowAccessible( nullptr ) // window pointer must be set after construction
45 ,
46#endif
47 mProject{ project }
48{
49 mTrackName = true;
50 mMessageCount = 0;
52}
int mNumFocusedTrack
Definition: TrackPanelAx.h:149
AudacityProject & mProject
Definition: TrackPanelAx.h:140
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 54 of file TrackPanelAx.cpp.

55{
56}

Member Function Documentation

◆ FindTrack()

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

Definition at line 193 of file TrackPanelAx.cpp.

194{
195 int ndx = 0;
196
197 for ( auto t : GetTracks().Leaders() )
198 {
199 ndx++;
200 if( ndx == num )
201 return t->SharedPointer();
202 }
203
204 return {};
205}
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 67 of file TrackPanelAx.cpp.

68{
69 auto focusedTrack = mFocusedTrack.lock();
70 if( !focusedTrack ) {
71 if (mNumFocusedTrack >=1) {
72 // This prevents the focus from being unnecessarily set to track 1
73 // when effects are applied. (Applying an effect can change
74 // the pointers of the selected tracks.)
75 focusedTrack = FindTrack(mNumFocusedTrack);
76 }
77 if (!focusedTrack) {
78 focusedTrack =
79 Track::SharedPointer( *GetTracks().Any().first );
80 // only call SetFocus if the focus has changed to avoid
81 // unnecessary focus events
82 if (focusedTrack)
83 focusedTrack = SetFocus();
84 }
85 }
86
87 if( !TrackNum( focusedTrack ) )
88 {
89 mFocusedTrack.reset();
90 return {};
91 }
92
93 return( focusedTrack );
94}
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:290
std::weak_ptr< Track > mFocusedTrack
Definition: TrackPanelAx.h:148
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 58 of file TrackPanelAx.cpp.

59{
60 return TrackList::Get( mProject );
61}
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:468

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 130 of file TrackPanelAx.h.

130{ return mWindow; }
wxWindow * mWindow
Definition: TrackPanelAx.h:143

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 158 of file TrackPanelAx.cpp.

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

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 227 of file TrackPanelAx.cpp.

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

References 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 47 of file TrackPanelAx.h.

47{ mFinder = finder; }
RectangleFinder mFinder
Definition: TrackPanelAx.h:146

References mFinder.

◆ SetFocus()

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

Definition at line 97 of file TrackPanelAx.cpp.

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

References PackedArray::begin(), BasicUI::CallAfter(), 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 131 of file TrackPanelAx.h.

131{ mWindow = window; }

References mWindow.

◆ TrackNum()

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

Definition at line 175 of file TrackPanelAx.cpp.

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

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 207 of file TrackPanelAx.cpp.

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

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 146 of file TrackPanelAx.h.

Referenced by SetFinder().

◆ mFocusedTrack

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

Definition at line 148 of file TrackPanelAx.h.

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

◆ mMessage

wxString TrackPanelAx::mMessage
private

Definition at line 151 of file TrackPanelAx.h.

Referenced by MessageForScreenReader().

◆ mMessageCount

int TrackPanelAx::mMessageCount
private

Definition at line 153 of file TrackPanelAx.h.

Referenced by MessageForScreenReader(), and TrackPanelAx().

◆ mNumFocusedTrack

int TrackPanelAx::mNumFocusedTrack
private

Definition at line 149 of file TrackPanelAx.h.

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

◆ mProject

AudacityProject& TrackPanelAx::mProject
private

Definition at line 140 of file TrackPanelAx.h.

Referenced by GetTracks(), and SetFocus().

◆ mTrackName

bool TrackPanelAx::mTrackName
private

Definition at line 152 of file TrackPanelAx.h.

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

◆ mWindow

wxWindow* TrackPanelAx::mWindow {}
private

Definition at line 143 of file TrackPanelAx.h.

Referenced by GetWindow(), and SetWindow().


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