From cfe0eaa7f22f0758539ffd674551356a5627a716 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 16 Oct 2016 23:48:27 +0200 Subject: [PATCH] Create wxAccessible object on demand in wxDVC Create wxAccessible objects only in response to calls to GetOrCreateAccessible() to save resources. --- include/wx/dataview.h | 4 +++ include/wx/generic/dataview.h | 4 +++ src/common/datavcmn.cpp | 11 ++++--- src/generic/datavgen.cpp | 60 ++++++++++++++++++++++++----------- 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index e74764cf52..0d8ccd766a 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -1386,6 +1386,10 @@ public: void OnCollapsed( wxDataViewEvent &event ); void OnSize( wxSizeEvent &event ); +#if wxUSE_ACCESSIBILITY + virtual wxAccessible* CreateAccessible() wxOVERRIDE; +#endif // wxUSE_ACCESSIBILITY + private: wxDECLARE_EVENT_TABLE(); wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl); diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 8bf816228d..b1e5ee7700 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -329,6 +329,10 @@ public: // utility functions not part of the API virtual void OnInternalIdle() wxOVERRIDE; +#if wxUSE_ACCESSIBILITY + virtual wxAccessible* CreateAccessible() wxOVERRIDE; +#endif // wxUSE_ACCESSIBILITY + private: virtual wxDataViewItem DoGetCurrentItem() const wxOVERRIDE; virtual void DoSetCurrentItem(const wxDataViewItem& item) wxOVERRIDE; diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 3e1c681785..ff22ecc3d7 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -2570,10 +2570,6 @@ bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id, 0 // not resizable ); -#if wxUSE_ACCESSIBILITY - SetAccessible(new wxDataViewTreeCtrlAccessible(this)); -#endif // wxUSE_ACCESSIBILITY - return true; } @@ -2743,6 +2739,13 @@ void wxDataViewTreeCtrl::OnSize( wxSizeEvent &event ) event.Skip( true ); } +#if wxUSE_ACCESSIBILITY +wxAccessible* wxDataViewTreeCtrl::CreateAccessible() +{ + return new wxDataViewTreeCtrlAccessible(this); +} +#endif // wxUSE_ACCESSIBILITY + #if wxUSE_ACCESSIBILITY //----------------------------------------------------------------------------- // wxDataViewTreeCtrlAccessible diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 596fdc64d0..0ef2c38ae6 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -241,12 +241,6 @@ public: wxDataViewHeaderWindow(wxDataViewCtrl *parent) : wxHeaderCtrl(parent) { -#if wxUSE_ACCESSIBILITY - // Under MSW wxHeadrCtrl is a native control - // so we just need to pass all requests - // to the accessibility framework. - SetAccessible(new wxAccessible(this)); -#endif // wxUSE_ACCESSIBILITY } wxDataViewCtrl *GetOwner() const @@ -276,6 +270,16 @@ public: } } +#if wxUSE_ACCESSIBILITY + virtual wxAccessible* CreateAccessible() wxOVERRIDE + { + // Under MSW wxHeadrCtrl is a native control + // so we just need to pass all requests + // to the accessibility framework. + return new wxAccessible(this); + } +#endif // wxUSE_ACCESSIBILITY + protected: // implement/override wxHeaderCtrl functions by forwarding them to the main // control @@ -4668,10 +4672,6 @@ bool wxDataViewCtrl::Create(wxWindow *parent, m_clientArea = new wxDataViewMainWindow( this, wxID_ANY ); -#if wxUSE_ACCESSIBILITY - SetAccessible(new wxDataViewCtrlAccessible(this)); -#endif // wxUSE_ACCESSIBILITY - // We use the cursor keys for moving the selection, not scrolling, so call // this method to ensure wxScrollHelperEvtHandler doesn't catch all // keyboard events forwarded to us from wxListMainWindow. @@ -5495,7 +5495,12 @@ void wxDataViewCtrl::DoEnableSystemTheme(bool enable, wxWindow* window) Base::DoEnableSystemTheme(enable, m_headerArea); } -#endif // !wxUSE_GENERICDATAVIEWCTRL +#if wxUSE_ACCESSIBILITY +wxAccessible* wxDataViewCtrl::CreateAccessible() +{ + return new wxDataViewCtrlAccessible(this); +} +#endif // wxUSE_ACCESSIBILITY #if wxUSE_ACCESSIBILITY //----------------------------------------------------------------------------- @@ -6236,15 +6241,31 @@ wxAccStatus wxDataViewCtrlAccessible::GetFocus(int* childId, wxAccessible** chil *childId = row+1; *child = NULL; } - else if ( dvWnd->HasFocus() ) - { - *childId = wxACC_SELF; - *child = this; - } else { - *childId = 0; - *child = NULL; + // First check if header is focused because header control + // handles accesibility requestes on its own. + wxHeaderCtrl* dvHdr = dvCtrl->GenericGetHeader(); + if ( dvHdr ) + { + if ( dvHdr->HasFocus() ) + { + *childId = wxACC_SELF; + *child = dvHdr->GetOrCreateAccessible(); + return wxACC_OK; + } + } + + if ( dvWnd->HasFocus() ) + { + *childId = wxACC_SELF; + *child = this; + } + else + { + *childId = 0; + *child = NULL; + } } return wxACC_OK; @@ -6289,7 +6310,8 @@ wxAccStatus wxDataViewCtrlAccessible::GetSelections(wxVariant* selections) return wxACC_OK; } - #endif // wxUSE_ACCESSIBILITY +#endif // !wxUSE_GENERICDATAVIEWCTRL + #endif // wxUSE_DATAVIEWCTRL