diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2023-09-01 10:48:52 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2023-09-01 16:13:19 +0200 |
commit | 9a559df3fe2f623ac4eace30cdfeabb3a747c0e9 (patch) | |
tree | 5bd3b68be2895895bf2c853bbbf9401f3e0247b3 | |
parent | 4c2aa7e073d6ab9f063272011d2866addeeed526 (diff) |
tdf#104833 a11y: Don't use VCLXEdit in VCLXAccessibleEdit
Don't rely on the `VCLXWindow` of the control
being a `VCLXEdit`, but use the `Edit` control
directly, as is already done in other methods
of this class.
This is in preparation of using
`VCLXAccessibleEdit` as the a11y class
for `MultiLineEdit` as well, which derives
from `Edit`, but its component interface class,
`VCLXMultiLineEdit` does not derive from `VCLXEdit`.
Already add reporting of the
`AccessibleStateType::MULTI_LINE` state instead of
`AccessibleStateType::SINGLE_LINE` to
`VCLXAccessibleTextComponent::FillAccessibleStateSet`
if the window type is `WindowType::MULTILINEEDIT`.
Add a small helper function,
`VCLXAccessibleEdit::isEditable` to use instead
of `VCLXEdit::isEditable`, which does the same.
Interacting with the single line edit from
the sample dialog in attachment 189287 in tdf#104833
in Accerciser still behaves as expected (and the
text can still be edited when removing the
readonly flag from the control).
Change-Id: I8218db61feb07605f6ea5309f26eebd38312458a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156400
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
-rw-r--r-- | accessibility/inc/standard/vclxaccessibleedit.hxx | 3 | ||||
-rw-r--r-- | accessibility/source/standard/vclxaccessibleedit.cxx | 52 |
2 files changed, 35 insertions, 20 deletions
diff --git a/accessibility/inc/standard/vclxaccessibleedit.hxx b/accessibility/inc/standard/vclxaccessibleedit.hxx index e10e8cecd6ff..b3b6a239b9d7 100644 --- a/accessibility/inc/standard/vclxaccessibleedit.hxx +++ b/accessibility/inc/standard/vclxaccessibleedit.hxx @@ -96,6 +96,9 @@ public: virtual sal_Bool SAL_CALL replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const OUString& sReplacement ) override; virtual sal_Bool SAL_CALL setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const css::uno::Sequence< css::beans::PropertyValue >& aAttributeSet ) override; virtual sal_Bool SAL_CALL setText( const OUString& sText ) override; + +private: + bool isEditable(); }; diff --git a/accessibility/source/standard/vclxaccessibleedit.cxx b/accessibility/source/standard/vclxaccessibleedit.cxx index 96a8d6986cf8..81a1a73c5cae 100644 --- a/accessibility/source/standard/vclxaccessibleedit.cxx +++ b/accessibility/source/standard/vclxaccessibleedit.cxx @@ -108,12 +108,17 @@ void VCLXAccessibleEdit::FillAccessibleStateSet( sal_Int64& rStateSet ) { VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet ); - VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() ); - if ( pVCLXEdit ) + VCLXWindow* pVCLXWindow = GetVCLXWindow(); + if (pVCLXWindow) { rStateSet |= AccessibleStateType::FOCUSABLE; - rStateSet |= AccessibleStateType::SINGLE_LINE; - if ( pVCLXEdit->isEditable() ) + + if (GetWindow() && GetWindow()->GetType() == WindowType::MULTILINEEDIT) + rStateSet |= AccessibleStateType::MULTI_LINE; + else + rStateSet |= AccessibleStateType::SINGLE_LINE; + + if (isEditable()) rStateSet |= AccessibleStateType::EDITABLE; } } @@ -148,13 +153,13 @@ OUString VCLXAccessibleEdit::implGetText() void VCLXAccessibleEdit::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) { - awt::Selection aSelection; - VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() ); - if ( pVCLXEdit ) - aSelection = pVCLXEdit->getSelection(); + Selection aSelection; + VclPtr<Edit> pEdit = GetAs<Edit>(); + if (pEdit) + aSelection = pEdit->GetSelection(); - nStartIndex = aSelection.Min; - nEndIndex = aSelection.Max; + nStartIndex = aSelection.Min(); + nEndIndex = aSelection.Max(); } @@ -415,11 +420,10 @@ sal_Bool VCLXAccessibleEdit::setSelection( sal_Int32 nStartIndex, sal_Int32 nEnd if ( !implIsValidRange( nStartIndex, nEndIndex, sText.getLength() ) ) throw IndexOutOfBoundsException(); - VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() ); VclPtr< Edit > pEdit = GetAs< Edit >(); - if ( pVCLXEdit && pEdit && pEdit->IsEnabled() ) + if (pEdit && pEdit->IsEnabled()) { - pVCLXEdit->setSelection( awt::Selection( nStartIndex, nEndIndex ) ); + pEdit->SetSelection(Selection(nStartIndex, nEndIndex)); bReturn = true; } @@ -551,10 +555,12 @@ sal_Bool VCLXAccessibleEdit::replaceText( sal_Int32 nStartIndex, sal_Int32 nEndI sal_Int32 nMinIndex = std::min( nStartIndex, nEndIndex ); sal_Int32 nMaxIndex = std::max( nStartIndex, nEndIndex ); - VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() ); - if ( pVCLXEdit && pVCLXEdit->isEditable() ) + + if (isEditable()) { - pVCLXEdit->setText( sText.replaceAt( nMinIndex, nMaxIndex - nMinIndex, sReplacement ) ); + VclPtr<Edit> pEdit = GetAs<Edit>(); + assert(pEdit); + pEdit->SetText(sText.replaceAt(nMinIndex, nMaxIndex - nMinIndex, sReplacement)); sal_Int32 nIndex = nMinIndex + sReplacement.getLength(); setSelection( nIndex, nIndex ); bReturn = true; @@ -581,17 +587,23 @@ sal_Bool VCLXAccessibleEdit::setText( const OUString& sText ) bool bReturn = false; - VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() ); - if ( pVCLXEdit && pVCLXEdit->isEditable() ) + if (isEditable()) { - pVCLXEdit->setText( sText ); + VclPtr<Edit> pEdit = GetAs<Edit>(); + assert(pEdit); + pEdit->SetText(sText); sal_Int32 nSize = sText.getLength(); - pVCLXEdit->setSelection( awt::Selection( nSize, nSize ) ); + pEdit->SetSelection(Selection(nSize, nSize) ); bReturn = true; } return bReturn; } +bool VCLXAccessibleEdit::isEditable() +{ + VclPtr<Edit> pEdit = GetAs<Edit>(); + return pEdit && !pEdit->IsReadOnly() && pEdit->IsEnabled(); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |