Kaydet (Commit) 1199902f authored tarafından Michael Stahl's avatar Michael Stahl

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
üst 4caef398
...@@ -397,7 +397,7 @@ public: ...@@ -397,7 +397,7 @@ public:
void Insert2(SwField const &, const bool bForceExpandHints); 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; size_t GetFieldTypeCount(SwFieldIds nResId = SwFieldIds::Unknown) const;
SwFieldType* GetFieldType(size_t nField, SwFieldIds nResId = SwFieldIds::Unknown) const; SwFieldType* GetFieldType(size_t nField, SwFieldIds nResId = SwFieldIds::Unknown) const;
......
...@@ -155,12 +155,11 @@ static void lcl_SetAttrPam( SwPaM& rPam, sal_Int32 nStart, const sal_Int32* pEnd ...@@ -155,12 +155,11 @@ static void lcl_SetAttrPam( SwPaM& rPam, sal_Int32 nStart, const sal_Int32* pEnd
@param rPam ??? @param rPam ???
@param rCmpItem ??? @param rCmpItem ???
@param fnMove ??? @param fnMove ???
@param bValue ???
@return Returns <true> if found, <false> otherwise. @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, const SfxPoolItem& rCmpItem,
SwMoveFnCollection const & fnMove, bool bValue ) SwMoveFnCollection const & fnMove)
{ {
if ( !rTextNd.HasHints() ) if ( !rTextNd.HasHints() )
return false; return false;
...@@ -171,8 +170,7 @@ static bool lcl_Search( const SwTextNode& rTextNd, SwPaM& rPam, ...@@ -171,8 +170,7 @@ static bool lcl_Search( const SwTextNode& rTextNd, SwPaM& rPam,
sal_Int32 nContentPos = rPam.GetPoint()->nContent.GetIndex(); sal_Int32 nContentPos = rPam.GetPoint()->nContent.GetIndex();
while( nullptr != ( pTextHt=(*fnMove.fnGetHint)(rTextNd.GetSwpHints(),nPos,nContentPos))) while( nullptr != ( pTextHt=(*fnMove.fnGetHint)(rTextNd.GetSwpHints(),nPos,nContentPos)))
if( pTextHt->Which() == rCmpItem.Which() && if (pTextHt->Which() == rCmpItem.Which())
( !bValue || CmpAttr( pTextHt->GetAttr(), rCmpItem )))
{ {
lcl_SetAttrPam( rPam, pTextHt->GetStart(), pTextHt->End(), bForward ); lcl_SetAttrPam( rPam, pTextHt->GetStart(), pTextHt->End(), bForward );
return true; return true;
...@@ -892,12 +890,14 @@ static bool lcl_Search( const SwContentNode& rCNd, const SfxItemSet& rCmpSet, bo ...@@ -892,12 +890,14 @@ static bool lcl_Search( const SwContentNode& rCNd, const SfxItemSet& rCmpSet, bo
namespace sw { namespace sw {
bool FindAttrImpl(SwPaM & rSearchPam, bool FindAttrImpl(SwPaM & rSearchPam,
const SfxPoolItem& rAttr, bool bValue, SwMoveFnCollection const & fnMove, const SfxPoolItem& rAttr, SwMoveFnCollection const & fnMove,
const SwPaM & rRegion, bool bInReadOnly) const SwPaM & rRegion, bool bInReadOnly,
SwRootFrame const*const pLayout)
{ {
// determine which attribute is searched: // determine which attribute is searched:
const sal_uInt16 nWhich = rAttr.Which(); const sal_uInt16 nWhich = rAttr.Which();
bool bCharAttr = isCHRATR(nWhich) || isTXTATR(nWhich); 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)); std::unique_ptr<SwPaM> pPam(sw::MakeRegion(fnMove, rRegion));
...@@ -905,8 +905,6 @@ bool FindAttrImpl(SwPaM & rSearchPam, ...@@ -905,8 +905,6 @@ bool FindAttrImpl(SwPaM & rSearchPam,
bool bFirst = true; bool bFirst = true;
const bool bSrchForward = &fnMove == &fnMoveForward; const bool bSrchForward = &fnMove == &fnMoveForward;
SwContentNode * pNode; SwContentNode * pNode;
const SfxPoolItem* pItem;
SwpFormats aFormatArr;
// if at beginning/end then move it out of the node // if at beginning/end then move it out of the node
if( bSrchForward if( bSrchForward
...@@ -921,27 +919,73 @@ bool FindAttrImpl(SwPaM & rSearchPam, ...@@ -921,27 +919,73 @@ bool FindAttrImpl(SwPaM & rSearchPam,
pPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() ); 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( bCharAttr )
{ {
if( !pNode->IsTextNode() ) // CharAttr are only in text nodes if( !pNode->IsTextNode() ) // CharAttr are only in text nodes
continue; continue;
if( pNode->GetTextNode()->HasHints() && SwTextFrame const*const pFrame(pLayout
lcl_Search( *pNode->GetTextNode(), *pPam, rAttr, fnMove, bValue )) ? 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 // set to the values of the attribute
rSearchPam.SetMark(); rSearchPam.SetMark();
*rSearchPam.GetPoint() = *pPam->GetPoint(); *rSearchPam.GetPoint() = *pPam->GetPoint();
*rSearchPam.GetMark() = *pPam->GetMark(); *rSearchPam.GetMark() = *pPam->GetMark();
bFound = true;
break; break;
} }
else if (isTXTATR(nWhich)) else if (isTXTATR(nWhich))
continue; continue;
} }
#if 0
// no hard attribution, so check if node was asked for this attr before // no hard attribution, so check if node was asked for this attr before
if( !pNode->HasSwAttrSet() ) if( !pNode->HasSwAttrSet() )
{ {
...@@ -952,7 +996,7 @@ bool FindAttrImpl(SwPaM & rSearchPam, ...@@ -952,7 +996,7 @@ bool FindAttrImpl(SwPaM & rSearchPam,
} }
if( SfxItemState::SET == pNode->GetSwAttrSet().GetItemState( nWhich, 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 // FORWARD: SPoint at the end, GetMark at the beginning of the node
// BACKWARD: SPoint at the beginning, GetMark at the end of the node // BACKWARD: SPoint at the beginning, GetMark at the end of the node
...@@ -963,6 +1007,7 @@ bool FindAttrImpl(SwPaM & rSearchPam, ...@@ -963,6 +1007,7 @@ bool FindAttrImpl(SwPaM & rSearchPam,
bFound = true; bFound = true;
break; break;
} }
#endif
} }
// if backward search, switch point and mark // if backward search, switch point and mark
......
...@@ -206,7 +206,7 @@ static SwTextField* lcl_FindInputField( SwDoc* pDoc, SwField& rField ) ...@@ -206,7 +206,7 @@ static SwTextField* lcl_FindInputField( SwDoc* pDoc, SwField& rField )
return pTField; return pTField;
} }
void SwEditShell::UpdateFields( SwField &rField ) void SwEditShell::UpdateOneField(SwField &rField)
{ {
SET_CURR_SHELL( this ); SET_CURR_SHELL( this );
StartAllAction(); StartAllAction();
...@@ -261,9 +261,9 @@ void SwEditShell::UpdateFields( SwField &rField ) ...@@ -261,9 +261,9 @@ void SwEditShell::UpdateFields( SwField &rField )
// Search for SwTextField ... // Search for SwTextField ...
while( bOkay while( bOkay
&& pCurStt->nContent != pCurEnd->nContent && pCurStt->nContent != pCurEnd->nContent
&& (sw::FindAttrImpl(aPam, aFieldHint, false, fnMoveForward, aCurPam, true) && (sw::FindAttrImpl(aPam, aFieldHint, fnMoveForward, aCurPam, true, GetLayout())
|| sw::FindAttrImpl(aPam, aAnnotationFieldHint, false, fnMoveForward, aCurPam) || sw::FindAttrImpl(aPam, aAnnotationFieldHint, fnMoveForward, aCurPam, false, GetLayout())
|| sw::FindAttrImpl(aPam, aInputFieldHint, false, fnMoveForward, aCurPam))) || sw::FindAttrImpl(aPam, aInputFieldHint, fnMoveForward, aCurPam, false, GetLayout())))
{ {
// if only one PaM has more than one field ... // if only one PaM has more than one field ...
if( aPam.Start()->nContent != pCurStt->nContent ) if( aPam.Start()->nContent != pCurStt->nContent )
......
...@@ -97,9 +97,10 @@ namespace sw { ...@@ -97,9 +97,10 @@ namespace sw {
SwMoveFnCollection const & fnMove, SwMoveFnCollection const & fnMove,
const SwPaM & rRegion, bool bInReadOnly = false); const SwPaM & rRegion, bool bInReadOnly = false);
bool FindAttrImpl(SwPaM & rSearchPam, bool FindAttrImpl(SwPaM & rSearchPam,
const SfxPoolItem& rAttr, bool bValue, const SfxPoolItem& rAttr,
SwMoveFnCollection const & fnMove, SwMoveFnCollection const & fnMove,
const SwPaM & rPam, bool bInReadOnly = false); const SwPaM & rPam, bool bInReadOnly,
SwRootFrame const* pLayout);
} // namespace sw } // namespace sw
......
...@@ -96,7 +96,7 @@ void sw::DropDownFieldDialog::Apply() ...@@ -96,7 +96,7 @@ void sw::DropDownFieldDialog::Apply()
static_cast<SwDropDownField*>(m_pDropField->CopyField().release())); static_cast<SwDropDownField*>(m_pDropField->CopyField().release()));
pCopy->SetPar1(sSelect); pCopy->SetPar1(sSelect);
m_rSh.SwEditShell::UpdateFields(*pCopy); m_rSh.SwEditShell::UpdateOneField(*pCopy);
m_rSh.SetUndoNoResetModified(); m_rSh.SetUndoNoResetModified();
m_rSh.EndAllAction(); m_rSh.EndAllAction();
......
...@@ -333,7 +333,7 @@ IMPL_LINK_NOARG(SwFieldEditDlg, AddressHdl, Button*, void) ...@@ -333,7 +333,7 @@ IMPL_LINK_NOARG(SwFieldEditDlg, AddressHdl, Button*, void)
ScopedVclPtr<SfxAbstractDialog> pDlg(rFact.CreateSwAddressAbstractDlg(this, aSet)); ScopedVclPtr<SfxAbstractDialog> pDlg(rFact.CreateSwAddressAbstractDlg(this, aSet));
if (RET_OK == pDlg->Execute()) if (RET_OK == pDlg->Execute())
{ {
pSh->UpdateFields( *pCurField ); pSh->UpdateOneField(*pCurField);
} }
} }
......
...@@ -133,14 +133,14 @@ void SwFieldInputDlg::Apply() ...@@ -133,14 +133,14 @@ void SwFieldInputDlg::Apply()
else if( aTmp != pInpField->GetPar1() ) else if( aTmp != pInpField->GetPar1() )
{ {
pInpField->SetPar1(aTmp); pInpField->SetPar1(aTmp);
rSh.SwEditShell::UpdateFields(*pInpField); rSh.SwEditShell::UpdateOneField(*pInpField);
bModified = true; bModified = true;
} }
} }
else if( aTmp != pSetField->GetPar2()) else if( aTmp != pSetField->GetPar2())
{ {
pSetField->SetPar2(aTmp); pSetField->SetPar2(aTmp);
rSh.SwEditShell::UpdateFields(*pSetField); rSh.SwEditShell::UpdateOneField(*pSetField);
bModified = true; bModified = true;
} }
......
...@@ -1518,7 +1518,7 @@ bool SwFieldMgr::InsertField( ...@@ -1518,7 +1518,7 @@ bool SwFieldMgr::InsertField(
if(bTable) if(bTable)
{ {
pCurShell->Left(CRSR_SKIP_CHARS, false, 1, false ); pCurShell->Left(CRSR_SKIP_CHARS, false, 1, false );
pCurShell->UpdateFields(*pField); pCurShell->UpdateOneField(*pField);
pCurShell->Right(CRSR_SKIP_CHARS, false, 1, false ); pCurShell->Right(CRSR_SKIP_CHARS, false, 1, false );
} }
else if( bPageVar ) else if( bPageVar )
...@@ -1690,7 +1690,7 @@ void SwFieldMgr::UpdateCurField(sal_uInt32 nFormat, ...@@ -1690,7 +1690,7 @@ void SwFieldMgr::UpdateCurField(sal_uInt32 nFormat,
} }
else { else {
// mb: #32157 // mb: #32157
pSh->SwEditShell::UpdateFields(*pTmpField); pSh->SwEditShell::UpdateOneField(*pTmpField);
GetCurField(); GetCurField();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment