diff options
author | Steve Yin <steve_y@apache.org> | 2013-11-29 13:03:27 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-12-02 10:25:33 +0000 |
commit | 76c549eb01dcb7b5bf28a271ce00e386f3d388ba (patch) | |
tree | bb09874a25b3b29c52556228abdf4aafb9ca6515 /sw/source/core/access/accdoc.cxx | |
parent | 84972949a3501003b0b6ad98f07f1b4ab83f3ca1 (diff) |
Integrate branch of IAccessible2
Conflicts:
everything
Change-Id: I9619634ee1e60d449025c006803da29c1e9d14b3
Diffstat (limited to 'sw/source/core/access/accdoc.cxx')
-rw-r--r-- | sw/source/core/access/accdoc.cxx | 510 |
1 files changed, 499 insertions, 11 deletions
diff --git a/sw/source/core/access/accdoc.cxx b/sw/source/core/access/accdoc.cxx index 5fb1e5fcdb74..74036086e1ea 100644 --- a/sw/source/core/access/accdoc.cxx +++ b/sw/source/core/access/accdoc.cxx @@ -36,6 +36,29 @@ #include "access.hrc" #include <pagefrm.hxx> +#include <editeng/brushitem.hxx> +#include <swatrset.hxx> +#include <frmatr.hxx> +#include "unostyle.hxx" +#include "viewsh.hxx" +#include "docsh.hxx" +#include <crsrsh.hxx> +#include "fesh.hxx" +#include <fmtclds.hxx> +#include <flyfrm.hxx> +#include <colfrm.hxx> +#include <txtfrm.hxx> +#include <sectfrm.hxx> +#include <section.hxx> +#include <svx/unoapi.hxx> +#include <swmodule.hxx> +#include <svtools/colorcfg.hxx> + +#include <fmtanchr.hxx> +#include <viewimp.hxx> +#include <dview.hxx> +#include <dcontact.hxx> +#include <svx/svdmark.hxx> const sal_Char sServiceName[] = "com.sun.star.text.AccessibleTextDocumentView"; const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleDocumentView"; @@ -160,8 +183,15 @@ sal_Int32 SAL_CALL SwAccessibleDocumentBase::getAccessibleIndexInParent (void) for( sal_Int32 i=0; i < nCount; i++ ) { - if( xAcc->getAccessibleChild( i ) == xThis ) - return i; + try + { + if( xAcc->getAccessibleChild( i ) == xThis ) + return i; + } + catch(::com::sun::star::lang::IndexOutOfBoundsException e) + { + return -1L; + } } return -1L; } @@ -172,20 +202,58 @@ OUString SAL_CALL SwAccessibleDocumentBase::getAccessibleDescription (void) return GetResource( STR_ACCESS_DOC_DESC ); } +OUString SAL_CALL SwAccessibleDocumentBase::getAccessibleName (void) + throw (::com::sun::star::uno::RuntimeException) +{ + OUString sAccName = GetResource( STR_ACCESS_DOC_WORDPROCESSING ); + SwDoc *pDoc = GetShell()->GetDoc(); + if ( pDoc ) + { + OUString sFileName = pDoc->getDocAccTitle(); + if ( sFileName.isEmpty() ) + { + SwDocShell* pDocSh = pDoc->GetDocShell(); + if ( pDocSh ) + { + sFileName = pDocSh->GetTitle( SFX_TITLE_APINAME ); + } + } + OUString sReadOnly; + if(pDoc->getDocReadOnly()) + { + sReadOnly = GetResource( STR_ACCESS_DOC_WORDPROCESSING_READONLY ); + } + + if ( !sFileName.isEmpty() ) + { + sAccName = sFileName + sReadOnly + " - " + sAccName; + } + } + + return sAccName; +} + awt::Rectangle SAL_CALL SwAccessibleDocumentBase::getBounds() throw (uno::RuntimeException) { - SolarMutexGuard aGuard; + try + { + SolarMutexGuard aGuard; - Window *pWin = GetWindow(); + Window *pWin = GetWindow(); - CHECK_FOR_WINDOW( XAccessibleComponent, pWin ) + CHECK_FOR_WINDOW( XAccessibleComponent, pWin ) - Rectangle aPixBounds( pWin->GetWindowExtentsRelative( pWin->GetAccessibleParentWindow() ) ); - awt::Rectangle aBox( aPixBounds.Left(), aPixBounds.Top(), - aPixBounds.GetWidth(), aPixBounds.GetHeight() ); + Rectangle aPixBounds( pWin->GetWindowExtentsRelative( pWin->GetAccessibleParentWindow() ) ); + awt::Rectangle aBox( aPixBounds.Left(), aPixBounds.Top(), + aPixBounds.GetWidth(), aPixBounds.GetHeight() ); - return aBox; + return aBox; + } + catch(::com::sun::star::lang::IndexOutOfBoundsException e) + { + return awt::Rectangle(); + } } awt::Point SAL_CALL SwAccessibleDocumentBase::getLocation() @@ -280,6 +348,7 @@ void SwAccessibleDocument::GetStates( // MULTISELECTABLE rStateSet.AddState( AccessibleStateType::MULTI_SELECTABLE ); + rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS ); } SwAccessibleDocument::SwAccessibleDocument ( SwAccessibleMap* pInitMap ) : @@ -398,6 +467,22 @@ uno::Any SwAccessibleDocument::queryInterface( uno::Reference<XAccessibleSelection> aSelect = this; aRet <<= aSelect; } + //Add XEventListener interface support. + else if ( (rType == ::getCppuType((uno::Reference<com::sun::star::document::XEventListener> *)NULL)) ) + { + uno::Reference<com::sun::star::document::XEventListener> aSelect = this; + aRet <<= aSelect; + } + else if ( rType == ::getCppuType((uno::Reference<XAccessibleExtendedAttributes> *)NULL) ) + { + uno::Reference<XAccessibleExtendedAttributes> aAttribute = this; + aRet <<= aAttribute; + } + else if(rType == ::getCppuType((uno::Reference<XAccessibleGetAccFlowTo> *)NULL) ) + { + uno::Reference<XAccessibleGetAccFlowTo> AccFlowTo = this; + aRet <<= AccFlowTo; + } else aRet = SwAccessibleContext::queryInterface( rType ); return aRet; @@ -410,11 +495,14 @@ uno::Sequence< uno::Type > SAL_CALL SwAccessibleDocument::getTypes() uno::Sequence< uno::Type > aTypes( SwAccessibleDocumentBase::getTypes() ); sal_Int32 nIndex = aTypes.getLength(); - aTypes.realloc( nIndex + 1 ); + //Reset types memory alloc + //aTypes.realloc( nIndex + 1 ); + aTypes.realloc( nIndex + 2 ); uno::Type* pTypes = aTypes.getArray(); pTypes[nIndex] = ::getCppuType( static_cast< uno::Reference< XAccessibleSelection > * >( 0 ) ); - + //Add XEventListener interface support. + pTypes[nIndex + 1 ] = ::getCppuType( static_cast< uno::Reference< com::sun::star::document::XEventListener > * >( 0 ) ); return aTypes; } @@ -482,4 +570,404 @@ void SwAccessibleDocument::deselectAccessibleChild( maSelectionHelper.deselectAccessibleChild( nChildIndex ); } +//Implement XEventListener interfaces +void SAL_CALL SwAccessibleDocument::notifyEvent( const ::com::sun::star::document::EventObject& Event ) + throw (::com::sun::star::uno::RuntimeException) +{ + if ( Event.EventName.equalsAscii( "FirstPageShows" ) ) + { + FireStateChangedEvent( AccessibleStateType::FOCUSED,sal_True ); + } + else if ( Event.EventName.equalsAscii( "LoadFinished" ) ) + { + // IA2 CWS. MT: OFFSCREEN == !SHOWING, should stay consistent + // FireStateChangedEvent( AccessibleStateType::OFFSCREEN,sal_True ); + // MT: LoadFinished => Why not SHOWING == TRUE? + FireStateChangedEvent( AccessibleStateType::SHOWING,sal_False ); + } + else if ( Event.EventName.equalsAscii( "FormatFinished" ) ) + { + FireStateChangedEvent( AccessibleStateType::BUSY,sal_False ); + // FireStateChangedEvent( AccessibleStateType::OFFSCREEN,sal_False ); + FireStateChangedEvent( AccessibleStateType::SHOWING,sal_True ); + } + else + { + isIfAsynLoad = sal_False; + } +} + +void SAL_CALL SwAccessibleDocument::disposing( const ::com::sun::star::lang::EventObject& ) + throw (::com::sun::star::uno::RuntimeException) +{ +} + +uno::Any SAL_CALL SwAccessibleDocument::getExtendedAttributes() + throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) +{ + uno::Any anyAtrribute; + SwDoc *pDoc = GetShell()->GetDoc(); + + if (!pDoc) + return anyAtrribute; + SwCrsrShell* pCrsrShell = GetCrsrShell(); + if( !pCrsrShell ) + return anyAtrribute; + + SwFEShell* pFEShell = pCrsrShell->ISA( SwFEShell ) + ? static_cast<SwFEShell*>( pCrsrShell ) + : 0; + OUString sAttrName; + OUString sValue; + sal_uInt16 nPage, nLogPage; + OUString sDisplay; + + if( pFEShell ) + { + pFEShell->GetPageNumber(-1,sal_True,nPage,nLogPage,sDisplay); + sAttrName = "page-name:"; + + + sValue = sAttrName + sDisplay ; + sAttrName = ";page-number:"; + sValue += sAttrName; + sValue += OUString::number( nPage ) ; + sAttrName = ";total-pages:"; + sValue += sAttrName; + sValue += OUString::number( pCrsrShell->GetPageCnt() ) ; + sValue += ";"; + + + sAttrName = "line-number:"; + + + + SwCntntFrm* pCurrFrm = pCrsrShell->GetCurrFrm(); + SwPageFrm* pCurrPage=((SwFrm*)pCurrFrm)->FindPageFrm(); + sal_uLong nLineNum = 0; + SwTxtFrm* pTxtFrm = NULL; + SwTxtFrm* pCurrTxtFrm = NULL; + pTxtFrm = static_cast< SwTxtFrm* >(static_cast< SwPageFrm* > (pCurrPage)->ContainsCntnt()); + if (pCurrFrm->IsInFly())//such as, graphic,chart + { + SwFlyFrm *pFlyFrm = pCurrFrm->FindFlyFrm(); + const SwFmtAnchor& rAnchor = pFlyFrm->GetFmt()->GetAnchor(); + RndStdIds eAnchorId = rAnchor.GetAnchorId(); + if(eAnchorId == FLY_AS_CHAR) + { + const SwFrm *pSwFrm = pFlyFrm->GetAnchorFrm(); + if(pSwFrm->IsTxtFrm()) + pCurrTxtFrm = ((SwTxtFrm*)(pSwFrm)); + } + } + else + pCurrTxtFrm = static_cast< SwTxtFrm* >(pCurrFrm); + //check whether the text frame where the Graph/OLE/Frame anchored is in the Header/Footer + SwFrm* pFrm = pCurrTxtFrm; + while ( pFrm && !pFrm->IsHeaderFrm() && !pFrm->IsFooterFrm() ) + pFrm = pFrm->GetUpper(); + if ( pFrm ) + pCurrTxtFrm = NULL; + //check shape + if(pCrsrShell->Imp()->GetDrawView()) + { + const SdrMarkList &rMrkList = pCrsrShell->Imp()->GetDrawView()->GetMarkedObjectList(); + for ( sal_uInt16 i = 0; i < rMrkList.GetMarkCount(); ++i ) + { + SdrObject *pObj = rMrkList.GetMark(i)->GetMarkedSdrObj(); + SwFrmFmt* pFmt = ((SwDrawContact*)pObj->GetUserCall())->GetFmt(); + const SwFmtAnchor& rAnchor = pFmt->GetAnchor(); + if( FLY_AS_CHAR != rAnchor.GetAnchorId() ) + pCurrTxtFrm = NULL; + } + } + //calculate line number + if (pCurrTxtFrm && pTxtFrm) + { + if (!(pCurrTxtFrm->IsInTab() || pCurrTxtFrm->IsInFtn())) + { + while( pTxtFrm != pCurrTxtFrm ) + { + //check header/footer + pFrm = pTxtFrm; + while ( pFrm && !pFrm->IsHeaderFrm() && !pFrm->IsFooterFrm() ) + pFrm = pFrm->GetUpper(); + if ( pFrm ) + { + pTxtFrm = static_cast< SwTxtFrm*>(pTxtFrm->GetNextCntntFrm()); + continue; + } + if (!(pTxtFrm->IsInTab() || pTxtFrm->IsInFtn() || pTxtFrm->IsInFly())) + nLineNum += pTxtFrm->GetThisLines(); + pTxtFrm = static_cast< SwTxtFrm* >(pTxtFrm ->GetNextCntntFrm()); + } + SwPaM* pCaret = pCrsrShell->GetCrsr(); + if (!pCurrTxtFrm->IsEmpty() && pCaret) + { + sal_uInt16 nActPos = 0; + if (pCurrTxtFrm->IsTxtFrm()) + { + const SwPosition* pPoint = NULL; + if(pCurrTxtFrm->IsInFly()) + { + SwFlyFrm *pFlyFrm = pCurrTxtFrm->FindFlyFrm(); + const SwFmtAnchor& rAnchor = pFlyFrm->GetFmt()->GetAnchor(); + pPoint= rAnchor.GetCntntAnchor(); + } + else + pPoint = pCaret->GetPoint(); + nActPos = pPoint->nContent.GetIndex(); + nLineNum += pCurrTxtFrm->GetLineCount( nActPos ); + } + else//graphic, form, shape, etc. + { + SwPosition* pPoint = pCaret->GetPoint(); + Point aPt = pCrsrShell->_GetCrsr()->GetPtPos(); + if( pCrsrShell->GetLayout()->GetCrsrOfst( pPoint, aPt/*,* &eTmpState*/ ) ) + { + nActPos = pPoint->nContent.GetIndex(); + nLineNum += pCurrTxtFrm->GetLineCount( nActPos ); + } + } + } + else + ++nLineNum; + } + } + + sValue += sAttrName; + sValue += OUString::number( nLineNum ) ; + + sValue += ";"; + + + SwFrm* pCurrCol=((SwFrm*)pCurrFrm)->FindColFrm(); + + sAttrName = "column-number:"; + sValue += sAttrName; + + sal_uInt16 nCurrCol = 1; + if(pCurrCol!=NULL) + { + //SwLayoutFrm* pParent = pCurrCol->GetUpper(); + SwFrm* pCurrPageCol=((SwFrm*)pCurrFrm)->FindColFrm(); + while(pCurrPageCol && pCurrPageCol->GetUpper() && pCurrPageCol->GetUpper()->IsPageFrm()) + { + pCurrPageCol = pCurrPageCol->GetUpper(); + } + + SwLayoutFrm* pParent = (SwLayoutFrm*)(pCurrPageCol->GetUpper()); + + if(pParent!=NULL) + { + SwFrm* pCol = pParent->Lower(); + while(pCol&&(pCol!=pCurrPageCol)) + { + pCol = pCol->GetNext(); + nCurrCol +=1; + } + } + } + sValue += OUString::number( nCurrCol ) ; + sValue += ";"; + + sAttrName = "total-columns:"; + + const SwFmtCol &rFmtCol=pCurrPage->GetAttrSet()->GetCol(); + sal_uInt16 nColCount=rFmtCol.GetNumCols(); + nColCount = nColCount>0?nColCount:1; + sValue += sAttrName; + sValue += OUString::number( nColCount ) ; + + sValue += ";"; + + if(pCurrFrm!=NULL) + { + SwSectionFrm* pCurrSctFrm=((SwFrm*)pCurrFrm)->FindSctFrm(); + if(pCurrSctFrm!=NULL && pCurrSctFrm->GetSection()!=NULL ) + { + sAttrName = "section-name:"; + + sValue += sAttrName; + OUString sectionName = pCurrSctFrm->GetSection()->GetSectionName(); + + sectionName = sectionName.replaceFirst( "\\" , "\\\\" ); + sectionName = sectionName.replaceFirst( "=" , "\\=" ); + sectionName = sectionName.replaceFirst( ";" , "\\;" ); + sectionName = sectionName.replaceFirst( "," , "\\," ); + sectionName = sectionName.replaceFirst( ":" , "\\:" ); + + sValue += sectionName; + + sValue += ";"; + + //section-columns-number + { + sAttrName = "section-columns-number:"; + + nCurrCol = 1; + + if(pCurrCol!=NULL) + { + SwLayoutFrm* pParent = pCurrCol->GetUpper(); + if(pParent!=NULL) + { + SwFrm* pCol = pParent->Lower(); + while(pCol&&(pCol!=pCurrCol)) + { + pCol = pCol->GetNext(); + nCurrCol +=1; + } + } + } + sValue += sAttrName; + sValue += OUString::number( nCurrCol ) ; + sValue += ";"; + } + + //section-total-columns + { + sAttrName = "section-total-columns:"; + const SwFmtCol &rFmtSctCol=pCurrSctFrm->GetAttrSet()->GetCol(); + sal_uInt16 nSctColCount=rFmtSctCol.GetNumCols(); + nSctColCount = nSctColCount>0?nSctColCount:1; + sValue += sAttrName; + sValue += OUString::number( nSctColCount ) ; + + sValue += ";"; + } + } + } + anyAtrribute <<= sValue; + } + return anyAtrribute; +} + +sal_Int32 SAL_CALL SwAccessibleDocument::getBackground() + throw (::com::sun::star::uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return SW_MOD()->GetColorConfig().GetColorValue( ::svtools::DOCCOLOR ).nColor; +} + +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > + SAL_CALL SwAccessibleDocument::get_AccFlowTo(const ::com::sun::star::uno::Any& rAny, sal_Int32 nType) + throw ( ::com::sun::star::uno::RuntimeException ) +{ + const sal_Int32 FORSPELLCHECKFLOWTO = 1; + const sal_Int32 FORFINDREPLACEFLOWTO = 2; + SwAccessibleMap* pAccMap = GetMap(); + if ( !pAccMap ) + { + return uno::Sequence< uno::Any >(); + } + + if ( nType == FORSPELLCHECKFLOWTO ) + { + uno::Reference< ::com::sun::star::drawing::XShape > xShape; + rAny >>= xShape; + if( xShape.is() ) + { + SdrObject* pObj = GetSdrObjectFromXShape(xShape); + if( pObj ) + { + uno::Reference<XAccessible> xAcc = pAccMap->GetContext(pObj, this, sal_False); + uno::Reference < XAccessibleSelection > xAccSelection( xAcc, uno::UNO_QUERY ); + if ( xAccSelection.is() ) + { + try + { + if ( xAccSelection->getSelectedAccessibleChildCount() ) + { + uno::Reference < XAccessible > xSel = xAccSelection->getSelectedAccessibleChild( 0 ); + if ( xSel.is() ) + { + uno::Reference < XAccessibleContext > xSelContext( xSel->getAccessibleContext() ); + if ( xSelContext.is() ) + { + //if in sw we find the selected paragraph here + if ( xSelContext->getAccessibleRole() == AccessibleRole::PARAGRAPH ) + { + uno::Sequence<uno::Any> aRet( 1 ); + aRet[0] = uno::makeAny( xSel ); + return aRet; + } + } + } + } + } + catch ( const com::sun::star::lang::IndexOutOfBoundsException& ) + { + return uno::Sequence< uno::Any >(); + } + //end of try...catch + } + } + } + else + { + uno::Reference< XAccessible > xAcc = pAccMap->GetCursorContext(); + SwAccessibleContext *pAccImpl = static_cast< SwAccessibleContext *>( xAcc.get() ); + if ( pAccImpl && pAccImpl->getAccessibleRole() == AccessibleRole::PARAGRAPH ) + { + uno::Sequence< uno::Any > aRet(1); + aRet[0] = uno::makeAny( xAcc ); + return aRet; + } + } + } + else if ( nType == FORFINDREPLACEFLOWTO ) + { + SwCrsrShell* pCrsrShell = GetCrsrShell(); + if ( pCrsrShell ) + { + SwPaM *_pStartCrsr = pCrsrShell->GetCrsr(), *__pStartCrsr = _pStartCrsr; + SwCntntNode* pPrevNode = NULL; + std::vector<SwFrm*> vFrmList; + do + { + if ( _pStartCrsr && _pStartCrsr->HasMark() ) + { + SwCntntNode* pCntntNode = _pStartCrsr->GetCntntNode(); + if ( pCntntNode == pPrevNode ) + { + continue; + } + SwFrm* pFrm = pCntntNode ? pCntntNode->getLayoutFrm( pCrsrShell->GetLayout() ) : NULL; + if ( pFrm ) + { + vFrmList.push_back( pFrm ); + } + + pPrevNode = pCntntNode; + } + } + + while( _pStartCrsr && ( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) != __pStartCrsr) ); + + if ( vFrmList.size() ) + { + uno::Sequence< uno::Any > aRet(vFrmList.size()); + std::vector<SwFrm*>::iterator aIter = vFrmList.begin(); + for ( sal_Int32 nIndex = 0; aIter != vFrmList.end(); aIter++, nIndex++ ) + { + uno::Reference< XAccessible > xAcc = pAccMap->GetContext(*aIter, sal_False); + if ( xAcc.is() ) + { + SwAccessibleContext *pAccImpl = static_cast< SwAccessibleContext *>( xAcc.get() ); + if ( pAccImpl && pAccImpl->getAccessibleRole() == AccessibleRole::PARAGRAPH ) + { + aRet[nIndex] = uno::makeAny( xAcc ); + } + } + } + + return aRet; + } + } + } + + return uno::Sequence< uno::Any >(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |