diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2018-12-17 13:13:46 +0100 |
---|---|---|
committer | Michael Stahl <Michael.Stahl@cib.de> | 2018-12-18 17:55:29 +0100 |
commit | 1199902fc9cbf2cf51733f7bc4205d6c32d781d1 (patch) | |
tree | 975bff210ba816020db4d1dfeec2076599422123 | |
parent | 4caef398af256be5f0c2a159129b528ee3702e5c (diff) |
sw_redlinehide_4b: adapt FindAttrImpl()
* rename the only user, some UpdateFields() overload, to UpateOneField()
* restrict it to search for non-formatting hints; the FindAttrsImpl()
should be used for formatting hints instead
Change-Id: I15002610a287fcdcd76777733a277d2ce64904bc
-rw-r--r-- | sw/inc/editsh.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/crsr/findattr.cxx | 73 | ||||
-rw-r--r-- | sw/source/core/edit/edfld.cxx | 8 | ||||
-rw-r--r-- | sw/source/core/inc/pamtyp.hxx | 5 | ||||
-rw-r--r-- | sw/source/ui/fldui/DropDownFieldDialog.cxx | 2 | ||||
-rw-r--r-- | sw/source/ui/fldui/fldedt.cxx | 2 | ||||
-rw-r--r-- | sw/source/ui/fldui/inpdlg.cxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/fldui/fldmgr.cxx | 4 |
8 files changed, 73 insertions, 27 deletions
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index 6dd4c1ca9a9b..fba31cf0e9f0 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -397,7 +397,7 @@ public: void Insert2(SwField const &, const bool bForceExpandHints); - void UpdateFields( SwField & ); ///< One single field. + void UpdateOneField(SwField &); ///< One single field. size_t GetFieldTypeCount(SwFieldIds nResId = SwFieldIds::Unknown) const; SwFieldType* GetFieldType(size_t nField, SwFieldIds nResId = SwFieldIds::Unknown) const; diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx index 30c15b43443c..2fa9c20cb01a 100644 --- a/sw/source/core/crsr/findattr.cxx +++ b/sw/source/core/crsr/findattr.cxx @@ -155,12 +155,11 @@ static void lcl_SetAttrPam( SwPaM& rPam, sal_Int32 nStart, const sal_Int32* pEnd @param rPam ??? @param rCmpItem ??? @param fnMove ??? - @param bValue ??? @return Returns <true> if found, <false> otherwise. */ -static bool lcl_Search( const SwTextNode& rTextNd, SwPaM& rPam, +static bool lcl_SearchAttr( const SwTextNode& rTextNd, SwPaM& rPam, const SfxPoolItem& rCmpItem, - SwMoveFnCollection const & fnMove, bool bValue ) + SwMoveFnCollection const & fnMove) { if ( !rTextNd.HasHints() ) return false; @@ -171,8 +170,7 @@ static bool lcl_Search( const SwTextNode& rTextNd, SwPaM& rPam, sal_Int32 nContentPos = rPam.GetPoint()->nContent.GetIndex(); while( nullptr != ( pTextHt=(*fnMove.fnGetHint)(rTextNd.GetSwpHints(),nPos,nContentPos))) - if( pTextHt->Which() == rCmpItem.Which() && - ( !bValue || CmpAttr( pTextHt->GetAttr(), rCmpItem ))) + if (pTextHt->Which() == rCmpItem.Which()) { lcl_SetAttrPam( rPam, pTextHt->GetStart(), pTextHt->End(), bForward ); return true; @@ -892,12 +890,14 @@ static bool lcl_Search( const SwContentNode& rCNd, const SfxItemSet& rCmpSet, bo namespace sw { bool FindAttrImpl(SwPaM & rSearchPam, - const SfxPoolItem& rAttr, bool bValue, SwMoveFnCollection const & fnMove, - const SwPaM & rRegion, bool bInReadOnly) + const SfxPoolItem& rAttr, SwMoveFnCollection const & fnMove, + const SwPaM & rRegion, bool bInReadOnly, + SwRootFrame const*const pLayout) { // determine which attribute is searched: const sal_uInt16 nWhich = rAttr.Which(); bool bCharAttr = isCHRATR(nWhich) || isTXTATR(nWhich); + assert(isTXTATR(nWhich)); // sw_redlinehide: only works for non-formatting hints such as needed in UpdateFields; use FindAttrsImpl for others std::unique_ptr<SwPaM> pPam(sw::MakeRegion(fnMove, rRegion)); @@ -905,8 +905,6 @@ bool FindAttrImpl(SwPaM & rSearchPam, bool bFirst = true; const bool bSrchForward = &fnMove == &fnMoveForward; SwContentNode * pNode; - const SfxPoolItem* pItem; - SwpFormats aFormatArr; // if at beginning/end then move it out of the node if( bSrchForward @@ -921,27 +919,73 @@ bool FindAttrImpl(SwPaM & rSearchPam, pPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() ); } - while( nullptr != ( pNode = ::GetNode( *pPam, bFirst, fnMove, bInReadOnly ) ) ) + while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout))) { if( bCharAttr ) { if( !pNode->IsTextNode() ) // CharAttr are only in text nodes continue; - if( pNode->GetTextNode()->HasHints() && - lcl_Search( *pNode->GetTextNode(), *pPam, rAttr, fnMove, bValue )) + SwTextFrame const*const pFrame(pLayout + ? static_cast<SwTextFrame const*>(pNode->getLayoutFrame(pLayout)) + : nullptr); + if (pFrame) + { + SwTextNode const* pAttrNode(nullptr); + SwTextAttr const* pAttr(nullptr); + if (bSrchForward) + { + sw::MergedAttrIter iter(*pFrame); + do + { + pAttr = iter.NextAttr(&pAttrNode); + } + while (pAttr + && (pAttrNode->GetIndex() < pPam->GetPoint()->nNode.GetIndex() + || (pAttrNode->GetIndex() == pPam->GetPoint()->nNode.GetIndex() + && pAttr->GetStart() < pPam->GetPoint()->nContent.GetIndex()) + || pAttr->Which() != nWhich)); + } + else + { + sw::MergedAttrIterReverse iter(*pFrame); + do + { + pAttr = iter.PrevAttr(&pAttrNode); + } + while (pAttr + && (pPam->GetPoint()->nNode.GetIndex() < pAttrNode->GetIndex() + || (pPam->GetPoint()->nNode.GetIndex() == pAttrNode->GetIndex() + && pPam->GetPoint()->nContent.GetIndex() <= pAttr->GetStart()) + || pAttr->Which() != nWhich)); + } + if (pAttr) + { + assert(pAttrNode); + pPam->GetPoint()->nNode = *pAttrNode; + lcl_SetAttrPam(*pPam, pAttr->GetStart(), pAttr->End(), bSrchForward); + bFound = true; + break; + } + } + else if (!pLayout && pNode->GetTextNode()->HasHints() && + lcl_SearchAttr(*pNode->GetTextNode(), *pPam, rAttr, fnMove)) + { + bFound = true; + } + if (bFound) { // set to the values of the attribute rSearchPam.SetMark(); *rSearchPam.GetPoint() = *pPam->GetPoint(); *rSearchPam.GetMark() = *pPam->GetMark(); - bFound = true; break; } else if (isTXTATR(nWhich)) continue; } +#if 0 // no hard attribution, so check if node was asked for this attr before if( !pNode->HasSwAttrSet() ) { @@ -952,7 +996,7 @@ bool FindAttrImpl(SwPaM & rSearchPam, } if( SfxItemState::SET == pNode->GetSwAttrSet().GetItemState( nWhich, - true, &pItem ) && ( !bValue || *pItem == rAttr ) ) + true, &pItem )) { // FORWARD: SPoint at the end, GetMark at the beginning of the node // BACKWARD: SPoint at the beginning, GetMark at the end of the node @@ -963,6 +1007,7 @@ bool FindAttrImpl(SwPaM & rSearchPam, bFound = true; break; } +#endif } // if backward search, switch point and mark diff --git a/sw/source/core/edit/edfld.cxx b/sw/source/core/edit/edfld.cxx index da0a15e0199e..3311439fd862 100644 --- a/sw/source/core/edit/edfld.cxx +++ b/sw/source/core/edit/edfld.cxx @@ -206,7 +206,7 @@ static SwTextField* lcl_FindInputField( SwDoc* pDoc, SwField& rField ) return pTField; } -void SwEditShell::UpdateFields( SwField &rField ) +void SwEditShell::UpdateOneField(SwField &rField) { SET_CURR_SHELL( this ); StartAllAction(); @@ -261,9 +261,9 @@ void SwEditShell::UpdateFields( SwField &rField ) // Search for SwTextField ... while( bOkay && pCurStt->nContent != pCurEnd->nContent - && (sw::FindAttrImpl(aPam, aFieldHint, false, fnMoveForward, aCurPam, true) - || sw::FindAttrImpl(aPam, aAnnotationFieldHint, false, fnMoveForward, aCurPam) - || sw::FindAttrImpl(aPam, aInputFieldHint, false, fnMoveForward, aCurPam))) + && (sw::FindAttrImpl(aPam, aFieldHint, fnMoveForward, aCurPam, true, GetLayout()) + || sw::FindAttrImpl(aPam, aAnnotationFieldHint, fnMoveForward, aCurPam, false, GetLayout()) + || sw::FindAttrImpl(aPam, aInputFieldHint, fnMoveForward, aCurPam, false, GetLayout()))) { // if only one PaM has more than one field ... if( aPam.Start()->nContent != pCurStt->nContent ) diff --git a/sw/source/core/inc/pamtyp.hxx b/sw/source/core/inc/pamtyp.hxx index a0ebf2bea708..b51212b23633 100644 --- a/sw/source/core/inc/pamtyp.hxx +++ b/sw/source/core/inc/pamtyp.hxx @@ -97,9 +97,10 @@ namespace sw { SwMoveFnCollection const & fnMove, const SwPaM & rRegion, bool bInReadOnly = false); bool FindAttrImpl(SwPaM & rSearchPam, - const SfxPoolItem& rAttr, bool bValue, + const SfxPoolItem& rAttr, SwMoveFnCollection const & fnMove, - const SwPaM & rPam, bool bInReadOnly = false); + const SwPaM & rPam, bool bInReadOnly, + SwRootFrame const* pLayout); } // namespace sw diff --git a/sw/source/ui/fldui/DropDownFieldDialog.cxx b/sw/source/ui/fldui/DropDownFieldDialog.cxx index 5ccead9f8504..387bccc39490 100644 --- a/sw/source/ui/fldui/DropDownFieldDialog.cxx +++ b/sw/source/ui/fldui/DropDownFieldDialog.cxx @@ -96,7 +96,7 @@ void sw::DropDownFieldDialog::Apply() static_cast<SwDropDownField*>(m_pDropField->CopyField().release())); pCopy->SetPar1(sSelect); - m_rSh.SwEditShell::UpdateFields(*pCopy); + m_rSh.SwEditShell::UpdateOneField(*pCopy); m_rSh.SetUndoNoResetModified(); m_rSh.EndAllAction(); diff --git a/sw/source/ui/fldui/fldedt.cxx b/sw/source/ui/fldui/fldedt.cxx index dfbb9e08183e..8578da18e2d4 100644 --- a/sw/source/ui/fldui/fldedt.cxx +++ b/sw/source/ui/fldui/fldedt.cxx @@ -333,7 +333,7 @@ IMPL_LINK_NOARG(SwFieldEditDlg, AddressHdl, Button*, void) ScopedVclPtr<SfxAbstractDialog> pDlg(rFact.CreateSwAddressAbstractDlg(this, aSet)); if (RET_OK == pDlg->Execute()) { - pSh->UpdateFields( *pCurField ); + pSh->UpdateOneField(*pCurField); } } diff --git a/sw/source/ui/fldui/inpdlg.cxx b/sw/source/ui/fldui/inpdlg.cxx index 361d14a184a8..f2bc3de52fe2 100644 --- a/sw/source/ui/fldui/inpdlg.cxx +++ b/sw/source/ui/fldui/inpdlg.cxx @@ -133,14 +133,14 @@ void SwFieldInputDlg::Apply() else if( aTmp != pInpField->GetPar1() ) { pInpField->SetPar1(aTmp); - rSh.SwEditShell::UpdateFields(*pInpField); + rSh.SwEditShell::UpdateOneField(*pInpField); bModified = true; } } else if( aTmp != pSetField->GetPar2()) { pSetField->SetPar2(aTmp); - rSh.SwEditShell::UpdateFields(*pSetField); + rSh.SwEditShell::UpdateOneField(*pSetField); bModified = true; } diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx index 892fae5561e0..b25e57b13f39 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -1518,7 +1518,7 @@ bool SwFieldMgr::InsertField( if(bTable) { pCurShell->Left(CRSR_SKIP_CHARS, false, 1, false ); - pCurShell->UpdateFields(*pField); + pCurShell->UpdateOneField(*pField); pCurShell->Right(CRSR_SKIP_CHARS, false, 1, false ); } else if( bPageVar ) @@ -1690,7 +1690,7 @@ void SwFieldMgr::UpdateCurField(sal_uInt32 nFormat, } else { // mb: #32157 - pSh->SwEditShell::UpdateFields(*pTmpField); + pSh->SwEditShell::UpdateOneField(*pTmpField); GetCurField(); } |