Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxGrid: implement basic accessibility / screen reader support #24368

Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/wx/generic/grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class wxGridRowOperations;
class wxGridColumnOperations;
class wxGridDirectionOperations;

#if wxUSE_ACCESSIBILITY
class WXDLLIMPEXP_FWD_CORE wxGridAccessible;
class WXDLLIMPEXP_FWD_CORE wxGridCellAccessible;
#endif // wxUSE_ACCESSIBILITY


// ----------------------------------------------------------------------------
// macros
Expand Down Expand Up @@ -2411,6 +2416,13 @@ class WXDLLIMPEXP_CORE wxGrid : public wxScrolledCanvas
// implementation only
void CancelMouseCapture();

#if wxUSE_ACCESSIBILITY
virtual wxAccessible* CreateAccessible() override;
virtual bool Show(bool show) override;
virtual void SetName(const wxString &name) override;
virtual bool Reparent(wxWindowBase *newParent) override;
#endif // wxUSE_ACCESSIBILITY

protected:
virtual wxSize DoGetBestSize() const override;
virtual void DoEnable(bool enable) override;
Expand Down Expand Up @@ -2769,6 +2781,11 @@ class WXDLLIMPEXP_CORE wxGrid : public wxScrolledCanvas
friend class wxGridHeaderColumn;
friend class wxGridHeaderCtrl;

#if wxUSE_ACCESSIBILITY
friend class wxGridAccessible;
friend class wxGridCellAccessible;
#endif // wxUSE_ACCESSIBILITY

private:
// This is called from both Create() and OnDPIChanged() to (re)initialize
// the values in pixels, which depend on the current DPI.
Expand Down Expand Up @@ -3467,5 +3484,6 @@ extern const int wxEVT_GRID_CHANGE_SEL_LABEL;

#endif


#endif // wxUSE_GRID
#endif // _WX_GENERIC_GRID_H_
60 changes: 60 additions & 0 deletions include/wx/generic/private/grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -1282,5 +1282,65 @@ TryGetValueAsDate(wxDateTime& result,

} // namespace wxGridPrivate


#if wxUSE_ACCESSIBILITY
//-----------------------------------------------------------------------------
// accessibility support for whole grid and per cell
//-----------------------------------------------------------------------------

class WXDLLIMPEXP_CORE wxGridAccessible : public wxWindowAccessible
{
public:
explicit wxGridAccessible(wxGrid* win);
virtual ~wxGridAccessible();

virtual wxAccStatus HitTest(const wxPoint& pt, int* childId,
wxAccessible** childObject) override;

virtual wxAccStatus GetLocation(wxRect& rect, int elementId) override;
virtual wxAccStatus GetName(int childId, wxString* name) override;
virtual wxAccStatus GetChildCount(int* childCount) override;
virtual wxAccStatus GetChild(int childId, wxAccessible** child) override;
virtual wxAccStatus GetRole(int childId, wxAccRole* role) override;
virtual wxAccStatus GetState(int childId, long* state) override;
virtual wxAccStatus GetValue(int childId, wxString* strValue) override;
virtual wxAccStatus GetFocus(int* childId, wxAccessible** child) override;

private:
std::unique_ptr<wxGridCellAccessible> m_gridCellAccessible;
};

class WXDLLIMPEXP_CORE wxGridCellAccessible : public wxAccessible
{
public:
wxGridCellAccessible(wxGrid* win, int childId);

virtual wxAccStatus HitTest(const wxPoint& pt, int* childId,
wxAccessible** childObject) override;

virtual wxAccStatus GetLocation(wxRect& rect, int elementId) override;
virtual wxAccStatus GetName(int childId, wxString* name) override;
virtual wxAccStatus GetChildCount(int* childCount) override;
virtual wxAccStatus GetChild(int childId, wxAccessible** child) override;
virtual wxAccStatus GetParent(wxAccessible** parent) override;
virtual wxAccStatus GetRole(int childId, wxAccRole* role) override;
virtual wxAccStatus GetState(int childId, long* state) override;
virtual wxAccStatus GetValue(int childId, wxString* strValue) override;
virtual wxAccStatus GetFocus(int* childId, wxAccessible** child) override;

private:
const int m_childId;
// row and / or col can be -1 for column or row header
const wxGridCellCoords m_coords;

bool m_isSameRow = false;
bool m_isSameCol = false;

friend class wxGridAccessible;
void DoGetLocation(wxGrid* grid, wxRect& rect);
};

#endif // wxUSE_ACCESSIBILITY

#endif // wxUSE_GRID
#endif // _WX_GENERIC_GRID_PRIVATE_H_