diff options
author | Steve Yin <steve_y@apache.org> | 2013-11-26 14:25:22 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-11-26 15:27:17 +0000 |
commit | c23ab5eaed57cc3fb5860e26c591c73c5b22687b (patch) | |
tree | 7a918b328e80763fa334f59c789cff399f207541 /editeng/source/accessibility/AccessibleStaticTextBase.cxx | |
parent | -Werror,-Wunused-private-field (diff) | |
download | core-c23ab5eaed57cc3fb5860e26c591c73c5b22687b.tar.gz core-c23ab5eaed57cc3fb5860e26c591c73c5b22687b.zip |
Integrate branch of IAccessible2
WaE: Reorder initializations to prevent compiler warnings.
(cherry picked from commit c05431aa92fa2c7c7258418a6ecd651b5c26d982)
WaE: unname unused variable to prevent compiler warnings.
(cherry picked from commit 2259256a390c4b6f83cfb5dbe4a65df5032aee47)
Conflicts:
editeng/source/accessibility/AccessibleEditableTextPara.cxx
ad61537527a74670af266feb9e4d26d2d654daf7
66044902b8d94fc15d4c30270e6cc419fb7d3565
Change-Id: I3ec9798f2c7d854824722c0cf44b62128b4f4cb4
Diffstat (limited to 'editeng/source/accessibility/AccessibleStaticTextBase.cxx')
-rw-r--r-- | editeng/source/accessibility/AccessibleStaticTextBase.cxx | 155 |
1 files changed, 144 insertions, 11 deletions
diff --git a/editeng/source/accessibility/AccessibleStaticTextBase.cxx b/editeng/source/accessibility/AccessibleStaticTextBase.cxx index c7a3c9b2f346..890bc5480241 100644 --- a/editeng/source/accessibility/AccessibleStaticTextBase.cxx +++ b/editeng/source/accessibility/AccessibleStaticTextBase.cxx @@ -77,7 +77,7 @@ namespace accessibility return ( lhs.Name == rhs.Name && lhs.Value == rhs.Value ); } }; - + sal_Unicode cNewLine(0x0a); //------------------------------------------------------------------------ // // Static Helper @@ -114,7 +114,7 @@ namespace accessibility */ class AccessibleStaticTextBase_Impl { - + friend class AccessibleStaticTextBase; public: // receive pointer to our frontend class and view window @@ -188,6 +188,7 @@ namespace accessibility sal_Int32 nEndPara, sal_Int32 nEndIndex ); Rectangle GetParagraphBoundingBox() const; + sal_Bool RemoveLineBreakCount( sal_Int32& rIndex ); private: @@ -368,8 +369,7 @@ namespace accessibility { nCurrCount = GetParagraph( nCurrPara ).getCharacterCount(); nCurrIndex += nCurrCount; - - if( nCurrIndex > nFlatIndex ) + if( nCurrIndex >= nFlatIndex ) { // check overflow DBG_ASSERT(nCurrPara >= 0 && nCurrPara <= SAL_MAX_INT32 && @@ -459,7 +459,57 @@ namespace accessibility } return aRect; } + //the input argument is the index(including "\n" ) in the string. + //the function will calculate the actual index(not including "\n") in the string. + //and return true if the index is just at a "\n" + sal_Bool AccessibleStaticTextBase_Impl::RemoveLineBreakCount( sal_Int32& rIndex ) + { + // get the total char number inside the cell. + sal_Int32 i, nCount, nParas; + for( i=0, nCount=0, nParas=GetParagraphCount(); i<nParas; ++i ) + nCount += GetParagraph(i).getCharacterCount(); + nCount = nCount + (nParas-1); + if( nCount == 0 && rIndex == 0) return sal_False; + + sal_Int32 nCurrPara, nCurrCount; + sal_Int32 nLineBreakPos = 0, nLineBreakCount = 0; + sal_Int32 nParaCount = GetParagraphCount(); + for ( nCurrCount = 0, nCurrPara = 0; nCurrPara < nParaCount; nCurrPara++ ) + { + nCurrCount += GetParagraph( nCurrPara ).getCharacterCount(); + nLineBreakPos = nCurrCount++; + if ( rIndex == nLineBreakPos ) + { + rIndex -= (++nLineBreakCount);//(++nLineBreakCount); + if ( rIndex < 0) + { + rIndex = 0; + } + //if the index is at the last position of the last paragraph + //there is no "\n" , so we should increase rIndex by 1 and return false. + if ( (nCurrPara+1) == nParaCount ) + { + rIndex++; + return sal_False; + } + else + { + return sal_True; + } + } + else if ( rIndex < nLineBreakPos ) + { + rIndex -= nLineBreakCount; + return sal_False; + } + else + { + nLineBreakCount++; + } + } + return sal_False; + } //------------------------------------------------------------------------ // // AccessibleStaticTextBase implementation @@ -653,6 +703,9 @@ namespace accessibility { SolarMutexGuard aGuard; + //get the actual index without "\n" + mpImpl->RemoveLineBreakCount( nIndex ); + EPosition aPos( mpImpl->Index2Internal(nIndex) ); return mpImpl->GetParagraph( aPos.nPara ).getCharacterAttributes( aPos.nIndex, aRequestedAttributes ); @@ -683,7 +736,8 @@ namespace accessibility sal_Int32 i, nCount, nParas; for( i=0, nCount=0, nParas=mpImpl->GetParagraphCount(); i<nParas; ++i ) nCount += mpImpl->GetParagraph(i).getCharacterCount(); - + //count on the number of "\n" which equals number of paragraphs decrease 1. + nCount = nCount + (nParas-1); return nCount; } @@ -786,37 +840,88 @@ namespace accessibility if( nStartIndex > nEndIndex ) ::std::swap(nStartIndex, nEndIndex); - + //if startindex equals endindex we will get nothing. So return an empty string directly. + if ( nStartIndex == nEndIndex ) + { + return OUString(); + } + sal_Bool bStart = mpImpl->RemoveLineBreakCount( nStartIndex ); + //if the start index is just at a "\n", we need to begin from the next char + if ( bStart ) + { + nStartIndex++; + } + //we need to find out whether the previous position of the current endindex is at "\n" or not + //if yes we need to mark it and add "\n" at the end of the result + sal_Int32 nTemp = nEndIndex - 1; + sal_Bool bEnd = mpImpl->RemoveLineBreakCount( nTemp ); + sal_Bool bTemp = mpImpl->RemoveLineBreakCount( nEndIndex ); + //if the below condition is true it indicates an empty paragraph with just a "\n" + //so we need to set one "\n" flag to avoid duplication. + if ( bStart && bEnd && ( nStartIndex == nEndIndex) ) + { + bEnd = sal_False; + } + //if the current endindex is at a "\n", we need to increase endindex by 1 to make sure + //the char before "\n" is included. Because string returned by this function will not include + //the char at the endindex. + if ( bTemp ) + { + nEndIndex++; + } + OUString aRes; EPosition aStartIndex( mpImpl->Range2Internal(nStartIndex) ); EPosition aEndIndex( mpImpl->Range2Internal(nEndIndex) ); // #102170# Special case: start and end paragraph are identical if( aStartIndex.nPara == aEndIndex.nPara ) { - return mpImpl->GetParagraph( aStartIndex.nPara ).getTextRange( aStartIndex.nIndex, aEndIndex.nIndex ); + //we don't return the string directly now for that we have to do some further process for "\n" + aRes = mpImpl->GetParagraph( aStartIndex.nPara ).getTextRange( aStartIndex.nIndex, aEndIndex.nIndex ); } else { sal_Int32 i( aStartIndex.nPara ); - OUString aRes( mpImpl->GetParagraph(i).getTextRange( aStartIndex.nIndex, - mpImpl->GetParagraph(i).getCharacterCount()-1) ); + aRes = mpImpl->GetParagraph(i).getTextRange( aStartIndex.nIndex, + mpImpl->GetParagraph(i).getCharacterCount()/*-1*/); ++i; // paragraphs inbetween are fully included for( ; i<aEndIndex.nPara; ++i ) + { + aRes += OUString(cNewLine); aRes += mpImpl->GetParagraph(i).getText(); + } if( i<=aEndIndex.nPara ) + { + //if the below condition is mathed it means the endindex is at mid of the last paragraph + //we need to add a "\n" before we add the last part of the string. + if ( !bEnd && aEndIndex.nIndex ) + { + aRes += OUString(cNewLine); + } aRes += mpImpl->GetParagraph(i).getTextRange( 0, aEndIndex.nIndex ); - - return aRes; + } } + //According the the flag we marked before, we have to add "\n" at the beginning + //or at the end of the result string. + if ( bStart ) + { + aRes = OUString(cNewLine) + aRes; + } + if ( bEnd ) + { + aRes += OUString(cNewLine); + } + return aRes; } ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleStaticTextBase::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) { SolarMutexGuard aGuard; + sal_Bool bLineBreak = mpImpl->RemoveLineBreakCount( nIndex ); EPosition aPos( mpImpl->Range2Internal(nIndex) ); ::com::sun::star::accessibility::TextSegment aResult; @@ -836,6 +941,17 @@ namespace accessibility aResult.SegmentStart = mpImpl->Internal2Index( EPosition( aPos.nPara, 0 ) ); aResult.SegmentEnd = aResult.SegmentStart + aResult.SegmentText.getLength(); } + else if ( AccessibleTextType::ATTRIBUTE_RUN == aTextType ) + { + SvxAccessibleTextAdapter& rTextForwarder = mpImpl->GetParagraph( aPos.nIndex ).GetTextForwarder(); + sal_uInt16 nStartIndex, nEndIndex; + if ( rTextForwarder.GetAttributeRun( nStartIndex, nEndIndex, aPos.nPara, aPos.nIndex, sal_True ) ) + { + aResult.SegmentText = getTextRange( nStartIndex, nEndIndex ); + aResult.SegmentStart = nStartIndex; + aResult.SegmentEnd = nEndIndex; + } + } else { // No special handling required, forward to wrapped class @@ -843,6 +959,10 @@ namespace accessibility // #112814# Adapt the start index with the paragraph offset mpImpl->CorrectTextSegment( aResult, aPos.nPara ); + if ( bLineBreak ) + { + aResult.SegmentText = OUString(cNewLine); + } } return aResult; @@ -852,6 +972,8 @@ namespace accessibility { SolarMutexGuard aGuard; + sal_Int32 nOldIdx = nIndex; + sal_Bool bLineBreak = mpImpl->RemoveLineBreakCount( nIndex ); EPosition aPos( mpImpl->Range2Internal(nIndex) ); ::com::sun::star::accessibility::TextSegment aResult; @@ -883,6 +1005,10 @@ namespace accessibility // #112814# Adapt the start index with the paragraph offset mpImpl->CorrectTextSegment( aResult, aPos.nPara ); + if ( bLineBreak && (nOldIdx-1) >= 0) + { + aResult = getTextAtIndex( nOldIdx-1, aTextType ); + } } return aResult; @@ -892,6 +1018,9 @@ namespace accessibility { SolarMutexGuard aGuard; + sal_Int32 nTemp = nIndex+1; + sal_Bool bLineBreak = mpImpl->RemoveLineBreakCount( nTemp ); + mpImpl->RemoveLineBreakCount( nIndex ); EPosition aPos( mpImpl->Range2Internal(nIndex) ); ::com::sun::star::accessibility::TextSegment aResult; @@ -917,6 +1046,10 @@ namespace accessibility // #112814# Adapt the start index with the paragraph offset mpImpl->CorrectTextSegment( aResult, aPos.nPara ); + if ( bLineBreak ) + { + aResult.SegmentText = OUString(cNewLine) + aResult.SegmentText; + } } return aResult; |