Kaydet (Commit) 2f5e266e authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski Kaydeden (comit) Caolán McNamara

Refactor NumRule handling in CopyImpl

The bug fix for i#86492 added a lot of duplicated code. This moves
the code into their own functions and uses macros to make the
resulting code even more readable.

Change-Id: Ifa0ece26f3152f1f8d8c65173b459e8c14c5b43a
Reviewed-on: https://gerrit.libreoffice.org/10968Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst d8e976e3
......@@ -3987,6 +3987,69 @@ SwFlyFrmFmt* DocumentContentOperationsManager::_InsNoTxtNode( const SwPosition&
return pFmt;
}
#define NUMRULE_STATE \
SfxItemState aNumRuleState = SFX_ITEM_UNKNOWN; \
SwNumRuleItem aNumRuleItem; \
SfxItemState aListIdState = SFX_ITEM_UNKNOWN; \
SfxStringItem aListIdItem( RES_PARATR_LIST_ID, OUString() ); \
#define PUSH_NUMRULE_STATE \
lcl_PushNumruleState( aNumRuleState, aNumRuleItem, aListIdState, aListIdItem, pDestTxtNd );
#define POP_NUMRULE_STATE \
lcl_PopNumruleState( aNumRuleState, aNumRuleItem, aListIdState, aListIdItem, pDestTxtNd, rPam );
static void lcl_PushNumruleState( SfxItemState &aNumRuleState, SwNumRuleItem &aNumRuleItem,
SfxItemState &aListIdState, SfxStringItem &aListIdItem,
const SwTxtNode *pDestTxtNd )
{
// Safe numrule item at destination.
// #i86492# - Safe also <ListId> item of destination.
const SfxItemSet * pAttrSet = pDestTxtNd->GetpSwAttrSet();
if (pAttrSet != NULL)
{
const SfxPoolItem * pItem = NULL;
aNumRuleState = pAttrSet->GetItemState(RES_PARATR_NUMRULE, false, &pItem);
if (SFX_ITEM_SET == aNumRuleState)
aNumRuleItem = *((SwNumRuleItem *) pItem);
aListIdState =
pAttrSet->GetItemState(RES_PARATR_LIST_ID, false, &pItem);
if (SFX_ITEM_SET == aListIdState)
{
aListIdItem.SetValue( static_cast<const SfxStringItem*>(pItem)->GetValue() );
}
}
}
static void lcl_PopNumruleState( int aNumRuleState, const SwNumRuleItem &aNumRuleItem,
int aListIdState, const SfxStringItem &aListIdItem,
SwTxtNode *pDestTxtNd, const SwPaM& rPam )
{
/* If only a part of one paragraph is copied
restore the numrule at the destination. */
// #i86492# - restore also <ListId> item
if ( !lcl_MarksWholeNode(rPam) )
{
if (SFX_ITEM_SET == aNumRuleState)
{
pDestTxtNd->SetAttr(aNumRuleItem);
}
else
{
pDestTxtNd->ResetAttr(RES_PARATR_NUMRULE);
}
if (SFX_ITEM_SET == aListIdState)
{
pDestTxtNd->SetAttr(aListIdItem);
}
else
{
pDestTxtNd->ResetAttr(RES_PARATR_LIST_ID);
}
}
}
bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
const bool bMakeNewFrms, const bool bCopyAll,
SwPaM *const pCpyRange ) const
......@@ -4150,28 +4213,10 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
}
}
// Safe numrule item at destination.
// #i86492# - Safe also <ListId> item of destination.
SfxItemState aNumRuleState = SFX_ITEM_UNKNOWN;
SwNumRuleItem aNumRuleItem;
SfxItemState aListIdState = SFX_ITEM_UNKNOWN;
SfxStringItem aListIdItem( RES_PARATR_LIST_ID, OUString() );
NUMRULE_STATE
if( bCopyCollFmt && bOneNode )
{
const SfxItemSet * pAttrSet = pDestTxtNd->GetpSwAttrSet();
if (pAttrSet != NULL)
{
const SfxPoolItem * pItem = NULL;
aNumRuleState = pAttrSet->GetItemState(RES_PARATR_NUMRULE, false, &pItem);
if (SFX_ITEM_SET == aNumRuleState)
aNumRuleItem = *((SwNumRuleItem *) pItem);
aListIdState =
pAttrSet->GetItemState(RES_PARATR_LIST_ID, false, &pItem);
if (SFX_ITEM_SET == aListIdState)
{
aListIdItem.SetValue( static_cast<const SfxStringItem*>(pItem)->GetValue() );
}
}
PUSH_NUMRULE_STATE
}
if( !bCopyOk )
......@@ -4191,29 +4236,7 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
if( bCopyCollFmt )
{
pSttTxtNd->CopyCollFmt( *pDestTxtNd );
/* If only a part of one paragraph is copied
restore the numrule at the destination. */
// #i86492# - restore also <ListId> item
if ( !lcl_MarksWholeNode(rPam) )
{
if (SFX_ITEM_SET == aNumRuleState)
{
pDestTxtNd->SetAttr(aNumRuleItem);
}
else
{
pDestTxtNd->ResetAttr(RES_PARATR_NUMRULE);
}
if (SFX_ITEM_SET == aListIdState)
{
pDestTxtNd->SetAttr(aListIdItem);
}
else
{
pDestTxtNd->ResetAttr(RES_PARATR_LIST_ID);
}
}
POP_NUMRULE_STATE
}
break;
......@@ -4295,31 +4318,14 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
bStartIsTxtNode = true;
}
// Save numrule at destination
// #i86492# - Safe also <ListId> item of destination.
SfxItemState aNumRuleState = SFX_ITEM_UNKNOWN;
SwNumRuleItem aNumRuleItem;
SfxItemState aListIdState = SFX_ITEM_UNKNOWN;
SfxStringItem aListIdItem( RES_PARATR_LIST_ID, OUString() );
{
const SfxItemSet* pAttrSet = pDestTxtNd->GetpSwAttrSet();
if (pAttrSet != NULL)
{
const SfxPoolItem * pItem = NULL;
aNumRuleState =
pAttrSet->GetItemState(RES_PARATR_NUMRULE, false, &pItem);
if (SFX_ITEM_SET == aNumRuleState)
aNumRuleItem = *((SwNumRuleItem *) pItem);
const bool bEmptyDestNd = pDestTxtNd->GetTxt().isEmpty();
aListIdState =
pAttrSet->GetItemState(RES_PARATR_LIST_ID, false, &pItem);
if (SFX_ITEM_SET == aListIdState)
aListIdItem.SetValue( static_cast<const SfxStringItem*>(pItem)->GetValue() );
}
NUMRULE_STATE
if( bCopyCollFmt && ( bOneNode || bEmptyDestNd ))
{
PUSH_NUMRULE_STATE
}
const bool bEmptyDestNd = pDestTxtNd->GetTxt().isEmpty();
pEndTxtNd->CopyText( pDestTxtNd, aDestIdx, SwIndex( pEndTxtNd ),
pEnd->nContent.GetIndex() );
......@@ -4327,31 +4333,9 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
if( bCopyCollFmt && ( bOneNode || bEmptyDestNd ))
{
pEndTxtNd->CopyCollFmt( *pDestTxtNd );
if ( bOneNode )
{
/* If only a part of one paragraph is copied
restore the numrule at the destination. */
// #i86492# - restore also <ListId> item
if ( !lcl_MarksWholeNode(rPam) )
{
if (SFX_ITEM_SET == aNumRuleState)
{
pDestTxtNd->SetAttr(aNumRuleItem);
}
else
{
pDestTxtNd->ResetAttr(RES_PARATR_NUMRULE);
}
if (SFX_ITEM_SET == aListIdState)
{
pDestTxtNd->SetAttr(aListIdItem);
}
else
{
pDestTxtNd->ResetAttr(RES_PARATR_LIST_ID);
}
}
POP_NUMRULE_STATE
}
}
}
......
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