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#ifndef __AUDACITY_TRACK_PANEL_ACCESSIBILITY__
11#define __AUDACITY_TRACK_PANEL_ACCESSIBILITY__
12
13#include "TrackFocus.h" // to inherit
14
15#include <functional>
16
17#include <wx/setup.h> // for wxUSE_* macros
18#include <wx/weakref.h>
19
20#if wxUSE_ACCESSIBILITY
21#include "WindowAccessible.h" // to inherit
22#endif
23
24class Viewport;
25class wxRect;
26class wxWindow;
27
28class TrackPanelAx final
29 : public TrackFocusCallbacks
30#if wxUSE_ACCESSIBILITY
31 , public WindowAccessible
32#endif
33 , public wxTrackable
34{
35public:
36 // Adapts the mismatch of wxWeakPtr and std::weak_ptr
38 Adapter(TrackPanelAx *pAx) : mwAx{ pAx } {}
39
40 ~Adapter() override;
41 void MessageForScreenReader(const TranslatableString& message) override;
42 void BeginChangeFocus() override;
43 void EndChangeFocus(const std::shared_ptr<Track> &track) override;
44 void UpdateAccessibility() override;
45
46 private:
47 const wxWeakRef<TrackPanelAx> mwAx;
48 };
49
50 using RectangleFinder = std::function< wxRect(Track&) >;
51
52 TrackPanelAx(std::weak_ptr<Viewport> wViewport,
53 std::weak_ptr<TrackFocus> wFocus, RectangleFinder finder);
54 ~TrackPanelAx() override;
55
56 // Called to signal changes to a track
57 void Updated();
58
59 void MessageForScreenReader(const TranslatableString& message) override;
60
61#if wxUSE_ACCESSIBILITY
62 // Retrieves the address of an IDispatch interface for the specified child.
63 // All objects must support this property.
64 wxAccStatus GetChild(int childId, wxAccessible** child) override;
65
66 // Gets the number of children.
67 wxAccStatus GetChildCount(int* childCount) override;
68
69 // Gets the default action for this object (0) or > 0 (the action for a child).
70 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
71 // string if there is no action.
72 // The retrieved string describes the action that is performed on an object,
73 // not what the object does as a result. For example, a toolbar button that prints
74 // a document has a default action of "Press" rather than "Prints the current document."
75 wxAccStatus GetDefaultAction(int childId, wxString *actionName) override;
76
77 // Returns the description for this object or a child.
78 wxAccStatus GetDescription(int childId, wxString *description) override;
79
80 // Gets the window with the keyboard focus.
81 // If childId is 0 and child is NULL, no object in
82 // this subhierarchy has the focus.
83 // If this object has the focus, child should be 'this'.
84 wxAccStatus GetFocus(int *childId, wxAccessible **child) override;
85
86 // Returns help text for this object or a child, similar to tooltip text.
87 wxAccStatus GetHelpText(int childId, wxString *helpText) override;
88
89 // Returns the keyboard shortcut for this object or child.
90 // Return e.g. ALT+K
91 wxAccStatus GetKeyboardShortcut(int childId, wxString *shortcut) override;
92
93 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
94 // rect is in screen coordinates.
95 wxAccStatus GetLocation(wxRect& rect, int elementId) override;
96
97 // Gets the name of the specified object.
98 wxAccStatus GetName(int childId, wxString *name) override;
99
100 // Returns a role constant.
101 wxAccStatus GetRole(int childId, wxAccRole *role) override;
102
103 // Gets a variant representing the selected children
104 // of this object.
105 // Acceptable values:
106 // - a null variant (IsNull() returns TRUE)
107 // - a list variant (GetType() == wxT("list"))
108 // - an integer representing the selected child element,
109 // or 0 if this object is selected (GetType() == wxT("long"))
110 // - a "void*" pointer to a wxAccessible child object
111 wxAccStatus GetSelections(wxVariant *selections) override;
112
113 // Returns a state constant.
114 wxAccStatus GetState(int childId, long* state) override;
115
116 // Returns a localized string representing the value for the object
117 // or child.
118 wxAccStatus GetValue(int childId, wxString* strValue) override;
119
120 // Navigates from fromId to toId/toObject
121 wxAccStatus Navigate(wxNavDir navDir, int fromId, int* toId, wxAccessible** toObject) override;
122
123 // Modify focus or selection
124 wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags) override;
125#else
126 wxWindow *GetWindow() const { return mWindow; }
127 void SetWindow( wxWindow *window ) { mWindow = window; }
128#endif
129
130private:
131 void BeginChangeFocus() override;
132 void EndChangeFocus(const std::shared_ptr<Track> &track) override;
133 void UpdateAccessibility() override;
134
135 std::weak_ptr<Viewport> mwViewport;
136 std::weak_ptr<TrackFocus> mwFocus;
137
138#if !wxUSE_ACCESSIBILITY
139 wxWindow *mWindow{};
140#endif
141
143
144 wxString mMessage;
146 bool mTrackName{ true };
147};
148
149#endif // __AUDACITY_TRACK_PANEL_ACCESSIBILITY__
const TranslatableString name
Definition: Distortion.cpp:76
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
Helper to TrackPanel to give accessibility.
Definition: TrackPanelAx.h:34
RectangleFinder mFinder
Definition: TrackPanelAx.h:142
void BeginChangeFocus() override
TrackPanelAx(std::weak_ptr< Viewport > wViewport, std::weak_ptr< TrackFocus > wFocus, RectangleFinder finder)
void SetWindow(wxWindow *window)
Definition: TrackPanelAx.h:127
wxWindow * mWindow
Definition: TrackPanelAx.h:139
std::weak_ptr< Viewport > mwViewport
Definition: TrackPanelAx.h:135
std::function< wxRect(Track &) > RectangleFinder
Definition: TrackPanelAx.h:50
std::weak_ptr< TrackFocus > mwFocus
Definition: TrackPanelAx.h:136
wxString mMessage
Definition: TrackPanelAx.h:144
void UpdateAccessibility() override
wxWindow * GetWindow() const
Definition: TrackPanelAx.h:126
void MessageForScreenReader(const TranslatableString &message) override
void EndChangeFocus(const std::shared_ptr< Track > &track) override
~TrackPanelAx() override
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 ...
A façade hiding platform-specific accessibility API.
Definition: TrackFocus.h:29
void BeginChangeFocus() override
void MessageForScreenReader(const TranslatableString &message) override
const wxWeakRef< TrackPanelAx > mwAx
Definition: TrackPanelAx.h:47
void UpdateAccessibility() override
void EndChangeFocus(const std::shared_ptr< Track > &track) override
Adapter(TrackPanelAx *pAx)
Definition: TrackPanelAx.h:38