Kaydet (Commit) 5c3cf76f authored tarafından Michael Stahl's avatar Michael Stahl

sw: refactor SwXNumberingRules

... to get some static property getter setter functions.

Change-Id: I3e69c0c01ee7ec2d17edbf06876c17cf4fce3833
üst c1358e5d
...@@ -37,6 +37,7 @@ class SwDoc; ...@@ -37,6 +37,7 @@ class SwDoc;
class SwFmtCol; class SwFmtCol;
class SwDocShell; class SwDocShell;
class SwNumRule; class SwNumRule;
class SwNumFmt;
class SwXFootnoteProperties : public cppu::WeakAggImplHelper2 class SwXFootnoteProperties : public cppu::WeakAggImplHelper2
< <
...@@ -204,6 +205,19 @@ public: ...@@ -204,6 +205,19 @@ public:
static bool isInvalidStyle(const OUString &rName); static bool isInvalidStyle(const OUString &rName);
void Invalidate() {pDocShell = 0;} void Invalidate() {pDocShell = 0;}
OUString GetCreatedNumRuleName() const {return m_sCreatedNumRuleName;} OUString GetCreatedNumRuleName() const {return m_sCreatedNumRuleName;}
static css::uno::Sequence<css::beans::PropertyValue> GetPropertiesForNumFmt(
const SwNumFmt& rFmt, OUString const& rCharFormatName,
OUString const* pHeadingStyleName);
static void SetPropertiesToNumFmt(
SwNumFmt & aFmt,
OUString & rCharStyleName,
OUString *const pBulletFontName,
OUString *const pHeadingStyleName,
OUString *const pParagraphStyleName,
SwDoc *const pDoc, SwDocShell *const pDocShell,
css::uno::Sequence<css::beans::PropertyValue> const& rProperties);
}; };
class SwXChapterNumbering : public SwXNumberingRules class SwXChapterNumbering : public SwXNumberingRules
......
...@@ -1331,7 +1331,58 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetNumberingRuleByIndex( ...@@ -1331,7 +1331,58 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetNumberingRuleByIndex(
const SwNumFmt& rFmt = rNumRule.Get( (sal_uInt16)nIndex ); const SwNumFmt& rFmt = rNumRule.Get( (sal_uInt16)nIndex );
bool bChapterNum = pDocShell != 0; SwCharFmt* pCharFmt = rFmt.GetCharFmt();
OUString CharStyleName;
if (pCharFmt)
CharStyleName = pCharFmt->GetName();
// Whether or not a style is present: the array entry overwrites this string
if (!m_sNewCharStyleNames[nIndex].isEmpty() &&
!SwXNumberingRules::isInvalidStyle(m_sNewCharStyleNames[nIndex]))
{
CharStyleName = m_sNewCharStyleNames[nIndex];
}
OUString aUString;
if (pDocShell) // -> Chapter Numbering
{
// template name
OUString sValue(SW_RES(STR_POOLCOLL_HEADLINE1 + nIndex));
const SwTxtFmtColls* pColls = pDocShell->GetDoc()->GetTxtFmtColls();
const size_t nCount = pColls->size();
for(size_t i = 0; i < nCount; ++i)
{
SwTxtFmtColl &rTxtColl = *pColls->operator[](i);
if(rTxtColl.IsDefault())
continue;
const sal_Int16 nOutLevel = rTxtColl.IsAssignedToListLevelOfOutlineStyle()
? static_cast<sal_Int16>(rTxtColl.GetAssignedOutlineStyleLevel())
: MAXLEVEL;
if ( nOutLevel == nIndex )
{
sValue = rTxtColl.GetName();
break; // the style for the level in question has been found
}
else if( sValue==rTxtColl.GetName() )
{
// if the default for the level is existing, but its
// level is different, then it cannot be the default.
sValue = OUString();
}
}
SwStyleNameMapper::FillProgName(sValue, aUString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true);
}
return GetPropertiesForNumFmt(rFmt, CharStyleName, (pDocShell) ? & aUString : 0);
}
uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt(
const SwNumFmt& rFmt, OUString const& rCharFormatName,
OUString const*const pHeadingStyleName)
{
bool bChapterNum = pHeadingStyleName != 0;
PropValDataArr aPropertyValues; PropValDataArr aPropertyValues;
//fill all properties into the array //fill all properties into the array
...@@ -1358,17 +1409,7 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetNumberingRuleByIndex( ...@@ -1358,17 +1409,7 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetNumberingRuleByIndex(
aPropertyValues.push_back(pData); aPropertyValues.push_back(pData);
//char style name //char style name
SwCharFmt* pCharFmt = rFmt.GetCharFmt(); OUString CharStyleName(rCharFormatName);
OUString CharStyleName;
if(pCharFmt)
CharStyleName = pCharFmt->GetName();
// Whether or not a style is present: the array entry overwrites this string
if (!m_sNewCharStyleNames[nIndex].isEmpty() &&
!SwXNumberingRules::isInvalidStyle(m_sNewCharStyleNames[nIndex]))
{
CharStyleName = m_sNewCharStyleNames[nIndex];
}
aUString = OUString(); aUString = OUString();
SwStyleNameMapper::FillProgName( CharStyleName, aUString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true ); SwStyleNameMapper::FillProgName( CharStyleName, aUString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true );
...@@ -1527,34 +1568,7 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetNumberingRuleByIndex( ...@@ -1527,34 +1568,7 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetNumberingRuleByIndex(
} }
else else
{ {
// template name aUString = *pHeadingStyleName;
OUString sValue(SW_RES(STR_POOLCOLL_HEADLINE1 + nIndex));
const SwTxtFmtColls* pColls = pDocShell->GetDoc()->GetTxtFmtColls();
const size_t nCount = pColls->size();
for(size_t i = 0; i < nCount; ++i)
{
SwTxtFmtColl &rTxtColl = *pColls->operator[](i);
if(rTxtColl.IsDefault())
continue;
const sal_Int16 nOutLevel = rTxtColl.IsAssignedToListLevelOfOutlineStyle()
? static_cast<sal_Int16>(rTxtColl.GetAssignedOutlineStyleLevel())
: MAXLEVEL;
if ( nOutLevel == nIndex )
{
sValue = rTxtColl.GetName();
break; // the style for the level in question has been found
}
else if( sValue==rTxtColl.GetName() )
{
// if the default for the level is existing, but its
// level is different, then it cannot be the default.
sValue = OUString();
}
}
aUString = OUString();
SwStyleNameMapper::FillProgName(sValue, aUString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true);
pData = new PropValData((void*)&aUString, UNO_NAME_HEADING_STYLE_NAME, ::cppu::UnoType<OUString>::get()); pData = new PropValData((void*)&aUString, UNO_NAME_HEADING_STYLE_NAME, ::cppu::UnoType<OUString>::get());
aPropertyValues.push_back(pData); aPropertyValues.push_back(pData);
} }
...@@ -1595,6 +1609,63 @@ void SwXNumberingRules::SetNumberingRuleByIndex( ...@@ -1595,6 +1609,63 @@ void SwXNumberingRules::SetNumberingRuleByIndex(
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
OSL_ENSURE( 0 <= nIndex && nIndex < MAXLEVEL, "index out of range" ); OSL_ENSURE( 0 <= nIndex && nIndex < MAXLEVEL, "index out of range" );
SwNumFmt aFmt(rNumRule.Get( (sal_uInt16)nIndex ));
OUString sHeadingStyleName;
OUString sParagraphStyleName;
SetPropertiesToNumFmt(aFmt, m_sNewCharStyleNames[nIndex],
&m_sNewBulletFontNames[nIndex],
&sHeadingStyleName, &sParagraphStyleName,
pDoc, pDocShell, rProperties);
if (pDoc && !sParagraphStyleName.isEmpty())
{
const SwTxtFmtColls* pColls = pDoc->GetTxtFmtColls();
const size_t nCount = pColls->size();
for (size_t k = 0; k < nCount; ++k)
{
SwTxtFmtColl &rTxtColl = *((*pColls)[k]);
if (rTxtColl.GetName() == sParagraphStyleName)
rTxtColl.SetFmtAttr( SwNumRuleItem( rNumRule.GetName()));
}
}
if (!sHeadingStyleName.isEmpty())
{
assert(pDocShell);
const SwTxtFmtColls* pColls = pDocShell->GetDoc()->GetTxtFmtColls();
const size_t nCount = pColls->size();
for (size_t k = 0; k < nCount; ++k)
{
SwTxtFmtColl &rTxtColl = *((*pColls)[k]);
if (rTxtColl.IsDefault())
continue;
if (rTxtColl.IsAssignedToListLevelOfOutlineStyle() &&
rTxtColl.GetAssignedOutlineStyleLevel() == nIndex &&
rTxtColl.GetName() != sHeadingStyleName)
{
rTxtColl.DeleteAssignmentToListLevelOfOutlineStyle();
}
else if (rTxtColl.GetName() == sHeadingStyleName)
{
rTxtColl.AssignToListLevelOfOutlineStyle( nIndex );
}
}
}
rNumRule.Set(static_cast<sal_uInt16>(nIndex), aFmt);
}
void SwXNumberingRules::SetPropertiesToNumFmt(
SwNumFmt & aFmt,
OUString & rCharStyleName, OUString *const pBulletFontName,
OUString *const pHeadingStyleName,
OUString *const pParagraphStyleName,
SwDoc *const pDoc, SwDocShell *const pDocShell,
const uno::Sequence<beans::PropertyValue>& rProperties)
{
// the order of the names is important! // the order of the names is important!
static const char* aNumPropertyNames[] = static const char* aNumPropertyNames[] =
{ {
...@@ -1665,7 +1736,6 @@ void SwXNumberingRules::SetNumberingRuleByIndex( ...@@ -1665,7 +1736,6 @@ void SwXNumberingRules::SetNumberingRuleByIndex(
aPropertyValues.push_back(pData); aPropertyValues.push_back(pData);
} }
SwNumFmt aFmt(rNumRule.Get( (sal_uInt16)nIndex ));
bool bWrongArg = false; bool bWrongArg = false;
if(!bExcept) if(!bExcept)
{ {
...@@ -1726,7 +1796,7 @@ void SwXNumberingRules::SetNumberingRuleByIndex( ...@@ -1726,7 +1796,7 @@ void SwXNumberingRules::SetNumberingRuleByIndex(
SwStyleNameMapper::FillUIName( uTmp, sCharFmtName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true ); SwStyleNameMapper::FillUIName( uTmp, sCharFmtName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true );
if (sCharFmtName == UNO_NAME_CHARACTER_FORMAT_NONE) if (sCharFmtName == UNO_NAME_CHARACTER_FORMAT_NONE)
{ {
m_sNewCharStyleNames[nIndex] = aInvalidStyle; rCharStyleName = aInvalidStyle;
aFmt.SetCharFmt(0); aFmt.SetCharFmt(0);
} }
else if(pDocShell || pDoc) else if(pDocShell || pDoc)
...@@ -1762,10 +1832,10 @@ void SwXNumberingRules::SetNumberingRuleByIndex( ...@@ -1762,10 +1832,10 @@ void SwXNumberingRules::SetNumberingRuleByIndex(
// #i51842# // #i51842#
// If the character format has been found its name should not be in the // If the character format has been found its name should not be in the
// char style names array // char style names array
m_sNewCharStyleNames[nIndex] = OUString(); rCharStyleName = OUString();
} }
else else
m_sNewCharStyleNames[nIndex] = sCharFmtName; rCharStyleName = sCharFmtName;
} }
break; break;
case 5: //"StartWith", case 5: //"StartWith",
...@@ -1885,20 +1955,13 @@ void SwXNumberingRules::SetNumberingRuleByIndex( ...@@ -1885,20 +1955,13 @@ void SwXNumberingRules::SetNumberingRuleByIndex(
break; break;
case 15: //"ParagraphStyleName" case 15: //"ParagraphStyleName"
{ {
if( pDoc ) if (pParagraphStyleName)
{ {
OUString uTmp; OUString uTmp;
pData->aVal >>= uTmp; pData->aVal >>= uTmp;
OUString sStyleName; OUString sStyleName;
SwStyleNameMapper::FillUIName(uTmp, sStyleName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true ); SwStyleNameMapper::FillUIName(uTmp, sStyleName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true );
const SwTxtFmtColls* pColls = pDoc->GetTxtFmtColls(); *pParagraphStyleName = sStyleName;
const size_t nCount = pColls->size();
for(size_t k = 0; k < nCount; ++k)
{
SwTxtFmtColl &rTxtColl = *((*pColls)[k]);
if ( rTxtColl.GetName() == sStyleName )
rTxtColl.SetFmtAttr( SwNumRuleItem( rNumRule.GetName()));
}
} }
} }
break; break;
...@@ -1948,8 +2011,8 @@ void SwXNumberingRules::SetNumberingRuleByIndex( ...@@ -1948,8 +2011,8 @@ void SwXNumberingRules::SetNumberingRuleByIndex(
vcl::Font aFont(aInfo); vcl::Font aFont(aInfo);
aFmt.SetBulletFont(&aFont); aFmt.SetBulletFont(&aFont);
} }
else else if (pBulletFontName)
m_sNewBulletFontNames[nIndex] = sBulletFontName; *pBulletFontName = sBulletFontName;
} }
break; break;
case 19: //"BulletChar", case 19: //"BulletChar",
...@@ -2047,28 +2110,13 @@ void SwXNumberingRules::SetNumberingRuleByIndex( ...@@ -2047,28 +2110,13 @@ void SwXNumberingRules::SetNumberingRuleByIndex(
break; break;
case 24: //"HeadingStyleName" case 24: //"HeadingStyleName"
{ {
assert( pDocShell ); if (pHeadingStyleName)
{
OUString uTmp; OUString uTmp;
pData->aVal >>= uTmp; pData->aVal >>= uTmp;
OUString sStyleName; OUString sStyleName;
SwStyleNameMapper::FillUIName(uTmp, sStyleName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true ); SwStyleNameMapper::FillUIName(uTmp, sStyleName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true );
const SwTxtFmtColls* pColls = pDocShell->GetDoc()->GetTxtFmtColls(); *pHeadingStyleName = sStyleName;
const size_t nCount = pColls->size();
for(size_t k = 0; k < nCount; ++k)
{
SwTxtFmtColl &rTxtColl = *((*pColls)[k]);
if(rTxtColl.IsDefault())
continue;
if ( rTxtColl.IsAssignedToListLevelOfOutlineStyle() &&
rTxtColl.GetAssignedOutlineStyleLevel() == nIndex &&
rTxtColl.GetName() != sStyleName )
{
rTxtColl.DeleteAssignmentToListLevelOfOutlineStyle();
}
else if ( rTxtColl.GetName() == sStyleName )
{
rTxtColl.AssignToListLevelOfOutlineStyle( nIndex );
}
} }
} }
break; break;
...@@ -2103,13 +2151,14 @@ void SwXNumberingRules::SetNumberingRuleByIndex( ...@@ -2103,13 +2151,14 @@ void SwXNumberingRules::SetNumberingRuleByIndex(
aFmt.SetGraphicBrush( pSetBrush, pSetSize, text::VertOrientation::NONE == eOrient ? 0 : &eOrient ); aFmt.SetGraphicBrush( pSetBrush, pSetSize, text::VertOrientation::NONE == eOrient ? 0 : &eOrient );
} }
} }
if((!bCharStyleNameSet || m_sNewCharStyleNames[nIndex].isEmpty()) && if ((!bCharStyleNameSet || rCharStyleName.isEmpty())
aFmt.GetNumberingType() == NumberingType::BITMAP && !aFmt.GetCharFmt() && aFmt.GetNumberingType() == NumberingType::BITMAP
&& !SwXNumberingRules::isInvalidStyle(m_sNewCharStyleNames[nIndex])) && !aFmt.GetCharFmt()
&& !SwXNumberingRules::isInvalidStyle(rCharStyleName))
{ {
OUString tmp; OUString tmp;
SwStyleNameMapper::FillProgName(RES_POOLCHR_BUL_LEVEL, tmp); SwStyleNameMapper::FillProgName(RES_POOLCHR_BUL_LEVEL, tmp);
m_sNewCharStyleNames[nIndex] = tmp; rCharStyleName = tmp;
} }
delete pSetBrush; delete pSetBrush;
delete pSetSize; delete pSetSize;
...@@ -2123,7 +2172,6 @@ void SwXNumberingRules::SetNumberingRuleByIndex( ...@@ -2123,7 +2172,6 @@ void SwXNumberingRules::SetNumberingRuleByIndex(
throw lang::IllegalArgumentException(); throw lang::IllegalArgumentException();
else if(bExcept) else if(bExcept)
throw uno::RuntimeException(); throw uno::RuntimeException();
rNumRule.Set( (sal_uInt16)nIndex, aFmt );
} }
uno::Reference< XPropertySetInfo > SwXNumberingRules::getPropertySetInfo() uno::Reference< XPropertySetInfo > SwXNumberingRules::getPropertySetInfo()
......
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