28#include <rtl/ustrbuf.hxx>
32#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
33#include <com/sun/star/uno/Reference.hxx>
34#include <com/sun/star/awt/Point.hpp>
35#include <com/sun/star/awt/Rectangle.hpp>
36#include <com/sun/star/accessibility/AccessibleTextType.hpp>
66 class PropertyValueEqualFunctor
71 explicit PropertyValueEqualFunctor(
const beans::PropertyValue& rPValue)
74 bool operator() (
const beans::PropertyValue& rhs )
const
89 sal_Int32 nEndPara, sal_Int32 nEndIndex )
95 "AccessibleStaticTextBase_Impl::MakeSelection: index value overflow");
97 return ESelection(nStartPara, nStartIndex, nEndPara, nEndIndex);
120 void SetEditSource( std::unique_ptr< SvxEditSource > && pEditSource );
132 AccessibleEditableTextPara&
GetParagraph( sal_Int32 nPara )
const;
152 bool SetSelection( sal_Int32 nStartPara, sal_Int32 nStartIndex,
153 sal_Int32 nEndPara, sal_Int32 nEndIndex );
154 bool CopyText( sal_Int32 nStartPara, sal_Int32 nStartIndex,
155 sal_Int32 nEndPara, sal_Int32 nEndIndex );
181 mxTextParagraph( new AccessibleEditableTextPara(nullptr) )
218 throw lang::DisposedException (
"object has been already disposed",
mxThis );
240 for(sal_Int32
i=0;
i<nEEIndex.
nPara; ++
i)
250 return aRes + nEEIndex.
nIndex;
257 if( aTextSegment.SegmentStart != -1 &&
258 aTextSegment.SegmentEnd != -1 )
261 sal_Int32 nOffset(0);
263 for(
i=0;
i<nPara; ++
i)
266 aTextSegment.SegmentStart += nOffset;
267 aTextSegment.SegmentEnd += nOffset;
275 throw lang::IndexOutOfBoundsException(
"AccessibleStaticTextBase_Impl::Index2Internal: character index out of bounds",
279 sal_Int32 nCurrPara, nCurrIndex, nParas, nCurrCount;
280 for( nCurrPara=0, nParas=
GetParagraphCount(), nCurrCount=0, nCurrIndex=0; nCurrPara<nParas; ++nCurrPara )
282 nCurrCount =
GetParagraph( nCurrPara ).getCharacterCount();
283 nCurrIndex += nCurrCount;
284 if( nCurrIndex >= nFlatIndex )
288 nFlatIndex - nCurrIndex + nCurrCount >= 0,
289 "AccessibleStaticTextBase_Impl::Index2Internal: index value overflow");
291 return EPosition(nCurrPara, nFlatIndex - nCurrIndex + nCurrCount);
296 if( bExclusive && nCurrIndex == nFlatIndex )
300 nFlatIndex - nCurrIndex + nCurrCount >= 0,
301 "AccessibleStaticTextBase_Impl::Index2Internal: index value overflow");
303 return EPosition(nCurrPara-1, nFlatIndex - nCurrIndex + nCurrCount);
307 throw lang::IndexOutOfBoundsException(
"AccessibleStaticTextBase_Impl::Index2Internal: character index out of bounds",
312 sal_Int32 nEndPara, sal_Int32 nEndIndex )
323 catch(
const uno::RuntimeException& )
330 sal_Int32 nEndPara, sal_Int32 nEndIndex )
347 aRetVal = rCacheVF.
Copy();
352 catch(
const uno::RuntimeException& )
382 if(
nCount == 0 && rIndex == 0)
return false;
385 sal_Int32 nCurrPara, nCurrCount;
386 sal_Int32 nLineBreakPos = 0, nLineBreakCount = 0;
388 for ( nCurrCount = 0, nCurrPara = 0; nCurrPara < nParaCount; nCurrPara++ )
390 nCurrCount +=
GetParagraph( nCurrPara ).getCharacterCount();
391 nLineBreakPos = nCurrCount++;
392 if ( rIndex == nLineBreakPos )
394 rIndex -= (++nLineBreakCount);
401 if ( (nCurrPara+1) == nParaCount )
411 else if ( rIndex < nLineBreakPos )
413 rIndex -= nLineBreakCount;
444 mpImpl->SetEditSource( std::move(pEditSource) );
449 mpImpl->SetEventSource( rInterface );
458 mpImpl->SetOffset( rPoint );
477 return uno::Reference< XAccessible >();
483 return uno::Reference< XAccessible >();
491 sal_Int32
i,
nPos, nParas;
492 for(
i=0,
nPos=-1, nParas=
mpImpl->GetParagraphCount();
i<nParas; ++
i )
494 if( (
nPos=
mpImpl->GetParagraph(
i).getCaretPosition()) != -1 )
524 return mpImpl->GetParagraph( aPos.
nPara ).getCharacterAttributes( aPos.
nIndex, aRequestedAttributes );
536 AccessibleEditableTextPara& rPara =
mpImpl->GetParagraph( aPos.
nPara );
537 awt::Rectangle aParaBounds( rPara.getBounds() );
538 awt::Rectangle aBounds( rPara.getCharacterBounds( aPos.
nIndex ) );
539 aBounds.X += aParaBounds.X;
540 aBounds.Y += aParaBounds.Y;
550 for(
i=0,
nCount=0, nParas=
mpImpl->GetParagraphCount();
i<nParas; ++
i )
561 const sal_Int32 nParas(
mpImpl->GetParagraphCount() );
564 for(
i=0;
i<nParas; ++
i )
570 AccessibleEditableTextPara& rPara =
mpImpl->GetParagraph(
i );
571 awt::Rectangle aParaBounds( rPara.getBounds() );
572 awt::Point aPoint( rPoint );
573 aPoint.X -= aParaBounds.X;
574 aPoint.Y -= aParaBounds.Y;
577 if ( (
nIndex = rPara.getIndexAtPoint( aPoint ) ) != -1 )
592 if( nStart < 0 || nEnd < 0 )
602 sal_Int32
i,
nPos, nParas;
603 for(
i=0,
nPos=-1, nParas=
mpImpl->GetParagraphCount();
i<nParas; ++
i )
605 if( (
nPos=
mpImpl->GetParagraph(
i).getSelectionStart()) != -1 )
616 sal_Int32
i,
nPos, nParas;
617 for(
i=0,
nPos=-1, nParas=
mpImpl->GetParagraphCount();
i<nParas; ++
i )
619 if( (
nPos=
mpImpl->GetParagraph(
i).getSelectionEnd()) != -1 )
643 for(
i=0, nParas=
mpImpl->GetParagraphCount();
i<nParas; ++
i )
644 aRes.append(
mpImpl->GetParagraph(
i).getText());
646 return aRes.makeStringAndClear();
653 if( nStartIndex > nEndIndex )
654 std::swap(nStartIndex, nEndIndex);
656 if ( nStartIndex == nEndIndex )
660 bool bStart =
mpImpl->RemoveLineBreakCount( nStartIndex );
668 sal_Int32 nTemp = nEndIndex - 1;
669 bool bEnd =
mpImpl->RemoveLineBreakCount( nTemp );
670 bool bTemp =
mpImpl->RemoveLineBreakCount( nEndIndex );
673 if ( bStart && bEnd && ( nStartIndex == nEndIndex) )
696 sal_Int32
i( aStartIndex.
nPara );
697 aRes =
mpImpl->GetParagraph(
i).getTextRange( aStartIndex.
nIndex,
698 mpImpl->GetParagraph(
i).getCharacterCount());
702 for( ;
i<aEndIndex.
nPara; ++
i )
704 aRes.append(OUStringChar(
cNewLine) +
mpImpl->GetParagraph(
i).getText());
711 if ( !bEnd && aEndIndex.
nIndex )
715 aRes.append(
mpImpl->GetParagraph(
i).getTextRange( 0, aEndIndex.
nIndex ));
722 aRes.insert(0, OUStringChar(
cNewLine));
726 aRes.append(OUStringChar(
cNewLine));
728 return aRes.makeStringAndClear();
735 bool bLineBreak =
mpImpl->RemoveLineBreakCount(
nIndex );
738 css::accessibility::TextSegment aResult;
740 if( AccessibleTextType::PARAGRAPH == aTextType )
749 aResult.SegmentText =
mpImpl->GetParagraph( aPos.
nPara ).getText();
753 aResult.SegmentEnd = aResult.SegmentStart + aResult.SegmentText.getLength();
755 else if ( AccessibleTextType::ATTRIBUTE_RUN == aTextType )
758 sal_Int32 nStartIndex, nEndIndex;
761 aResult.SegmentText =
getTextRange( nStartIndex, nEndIndex );
762 aResult.SegmentStart = nStartIndex;
763 aResult.SegmentEnd = nEndIndex;
769 aResult =
mpImpl->GetParagraph( aPos.
nPara ).getTextAtIndex( aPos.
nIndex, aTextType );
775 aResult.SegmentText = OUString(
cNewLine);
786 sal_Int32 nOldIdx =
nIndex;
787 bool bLineBreak =
mpImpl->RemoveLineBreakCount(
nIndex );
790 css::accessibility::TextSegment aResult;
792 if( AccessibleTextType::PARAGRAPH == aTextType )
797 aResult.SegmentText =
mpImpl->GetParagraph( aPos.
nPara ).getText();
802 else if( aPos.
nPara > 0 )
804 aResult.SegmentText =
mpImpl->GetParagraph( aPos.
nPara - 1 ).getText();
810 aResult.SegmentEnd = aResult.SegmentStart + aResult.SegmentText.getLength();
815 aResult =
mpImpl->GetParagraph( aPos.
nPara ).getTextBeforeIndex( aPos.
nIndex, aTextType );
819 if ( bLineBreak && (nOldIdx-1) >= 0)
832 sal_Int32 nTemp =
nIndex+1;
833 bool bLineBreak =
mpImpl->RemoveLineBreakCount( nTemp );
837 css::accessibility::TextSegment aResult;
839 if( AccessibleTextType::PARAGRAPH == aTextType )
846 aResult.SegmentText =
mpImpl->GetParagraph( aPos.
nPara + 1 ).getText();
850 aResult.SegmentEnd = aResult.SegmentStart + aResult.SegmentText.getLength();
856 aResult =
mpImpl->GetParagraph( aPos.
nPara ).getTextBehindIndex( aPos.
nIndex, aTextType );
862 aResult.SegmentText = OUStringChar(
cNewLine) + aResult.SegmentText;
873 if( nStartIndex > nEndIndex )
874 std::swap(nStartIndex, nEndIndex);
896 comphelper::sequenceToContainer<PropertyValueVector>(
mpImpl->GetParagraph( 0 ).getDefaultAttributes( RequestedAttributes )) );
898 const sal_Int32 nParaCount =
mpImpl->GetParagraphCount();
899 for ( sal_Int32 nPara = 1; nPara < nParaCount; ++nPara )
901 uno::Sequence< beans::PropertyValue >
aSeq =
mpImpl->GetParagraph( nPara ).getDefaultAttributes( RequestedAttributes );
904 for (
const auto& rDefAttr : aDefAttrVec )
906 const beans::PropertyValue* pItr =
aSeq.getConstArray();
907 const beans::PropertyValue* pEnd = pItr +
aSeq.getLength();
908 const beans::PropertyValue* pFind = std::find_if( pItr, pEnd, PropertyValueEqualFunctor(rDefAttr) );
911 aIntersectionVec.push_back( *pFind );
915 aDefAttrVec.swap( aIntersectionVec );
917 if ( aDefAttrVec.empty() )
934 AccessibleEditableTextPara& rPara =
mpImpl->GetParagraph( aPos.
nPara );
935 uno::Sequence< beans::PropertyValue > aDefAttrSeq = rPara.getDefaultAttributes( RequestedAttributes );
936 uno::Sequence< beans::PropertyValue > aRunAttrSeq = rPara.getRunAttributes( aPos.
nIndex, RequestedAttributes );
937 uno::Sequence< beans::PropertyValue > aIntersectionSeq =
getDefaultAttributes( RequestedAttributes );
940 const beans::PropertyValue* pDefAttr = aDefAttrSeq.getConstArray();
941 const sal_Int32
nLength = aDefAttrSeq.getLength();
944 const beans::PropertyValue* pItr = aIntersectionSeq.getConstArray();
945 const beans::PropertyValue* pEnd = pItr + aIntersectionSeq.getLength();
946 bool bNone = std::none_of( pItr, pEnd, PropertyValueEqualFunctor( pDefAttr[
i] ) );
947 if ( bNone && pDefAttr[
i].
Handle != 0)
949 aDiffVec.push_back( pDefAttr[
i] );
958 return mpImpl->GetParagraphBoundingBox();
const beans::PropertyValue & m_rPValue
virtual bool GetAttributeRun(sal_Int32 &nStartIndex, sal_Int32 &nEndIndex, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell=false) const override
Query range of similar attributes.
Encapsulates EditView and OutlinerView for the purpose of unified EditEngine/Outliner access.
virtual bool Copy()=0
Copy current selection to clipboard.
virtual bool SetSelection(const ESelection &rSelection)=0
Set selection in view.
virtual bool GetSelection(ESelection &rSelection) const =0
Query current selection.
AccessibleStaticTextBase_Impl.
tools::Rectangle GetParagraphBoundingBox() const
uno::Reference< XAccessible > mxThis
void SetEditSource(std::unique_ptr< SvxEditSource > &&pEditSource)
EPosition Index2Internal(sal_Int32 nFlatIndex) const
AccessibleStaticTextBase_Impl()
void SetOffset(const Point &)
rtl::Reference< AccessibleEditableTextPara > mxTextParagraph
void SetEventSource(const uno::Reference< XAccessible > &rInterface)
bool CopyText(sal_Int32 nStartPara, sal_Int32 nStartIndex, sal_Int32 nEndPara, sal_Int32 nEndIndex)
sal_Int32 GetParagraphCount() const
EPosition ImpCalcInternal(sal_Int32 nFlatIndex, bool bExclusive) const
bool SetSelection(sal_Int32 nStartPara, sal_Int32 nStartIndex, sal_Int32 nEndPara, sal_Int32 nEndIndex)
AccessibleEditableTextPara & GetParagraph(sal_Int32 nPara) const
SvxEditSourceAdapter maEditSource
void CorrectTextSegment(TextSegment &aTextSegment, int nPara) const
EPosition Range2Internal(sal_Int32 nFlatIndex) const
sal_Int32 Internal2Index(EPosition nEEIndex) const
bool RemoveLineBreakCount(sal_Int32 &rIndex)
Helper class for objects containing EditEngine/Outliner text.
virtual sal_Unicode SAL_CALL getCharacter(sal_Int32 nIndex) override
virtual sal_Int32 SAL_CALL getIndexAtPoint(const css::awt::Point &aPoint) override
AccessibleStaticTextBase(::std::unique_ptr< SvxEditSource > &&pEditSource)
Create accessible text object for given edit source.
void SetOffset(const Point &rPoint)
Set offset of EditEngine from parent.
virtual OUString SAL_CALL getSelectedText() override
virtual ~AccessibleStaticTextBase()
virtual css::awt::Rectangle SAL_CALL getCharacterBounds(sal_Int32 nIndex) override
virtual sal_Bool SAL_CALL scrollSubstringTo(sal_Int32 nStartIndex, sal_Int32 nEndIndex, css::accessibility::AccessibleScrollType aScrollType) override
virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine)
virtual OUString SAL_CALL getTextRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual sal_Bool SAL_CALL setSelection(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
This will only work with a functional SvxEditViewForwarder, i.e. an EditEngine/Outliner in edit mode.
virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine)
const std::unique_ptr< AccessibleStaticTextBase_Impl > mpImpl
@dyn
virtual sal_Int64 SAL_CALL getAccessibleChildCount()
virtual sal_Int32 SAL_CALL getSelectionStart() override
void Dispose()
Drop all references and enter disposed state.
virtual sal_Int32 SAL_CALL getCharacterCount() override
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getRunAttributes(sal_Int32 Index, const css::uno::Sequence< OUString > &RequestedAttributes) override
virtual sal_Int32 SAL_CALL getSelectionEnd() override
virtual sal_Int32 SAL_CALL getCaretPosition() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint)
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getDefaultAttributes(const css::uno::Sequence< OUString > &RequestedAttributes) override
virtual sal_Bool SAL_CALL setCaretPosition(sal_Int32 nIndex) override
void SetEditSource(::std::unique_ptr< SvxEditSource > &&pEditSource)
Set the current edit source.
virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine)
virtual OUString SAL_CALL getText() override
void SetEventSource(const css::uno::Reference< css::accessibility::XAccessible > &rInterface)
Set the event source.
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes(sal_Int32 nIndex, const css::uno::Sequence< OUString > &aRequestedAttributes) override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i)
virtual sal_Bool SAL_CALL copyText(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
This will only work with a functional SvxEditViewForwarder, i.e. an EditEngine/Outliner in edit mode.
tools::Rectangle GetParagraphBoundingBox() const
#define DBG_ASSERT(sCon, aError)
#define DBG_TESTSOLARMUTEX()
Sequence< sal_Int8 > aSeq
static ESelection MakeSelection(sal_Int32 nStartPara, sal_Int32 nStartIndex, sal_Int32 nEndPara, sal_Int32 nEndIndex)
sal_Unicode const cNewLine(0x0a)
std::vector< beans::PropertyValue > PropertyValueVector
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)