summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/source/filter/xml/xmlfmt.cxx40
-rw-r--r--sw/source/uibase/chrdlg/ccoll.cxx2
-rw-r--r--xmloff/source/style/prstylecond.cxx21
-rw-r--r--xmloff/source/style/styleexp.cxx17
4 files changed, 42 insertions, 38 deletions
diff --git a/sw/source/filter/xml/xmlfmt.cxx b/sw/source/filter/xml/xmlfmt.cxx
index 8f60091126c1..904a102722b1 100644
--- a/sw/source/filter/xml/xmlfmt.cxx
+++ b/sw/source/filter/xml/xmlfmt.cxx
@@ -311,36 +311,40 @@ SwXMLTextStyleContext_Impl::Finish( bool bOverwrite )
if( pConditions && XML_STYLE_FAMILY_TEXT_PARAGRAPH == GetFamily() && xNewStyle.is() )
{
- CommandStruct const *aCommands = SwCondCollItem::GetCmds();
+ CommandStruct const*const pCommands = SwCondCollItem::GetCmds();
Reference< XPropertySet > xPropSet( xNewStyle, UNO_QUERY );
uno::Sequence< beans::NamedValue > aSeq( pConditions->size() );
- std::vector<rtl::Reference<SwXMLConditionContext_Impl>>::size_type i;
- unsigned j;
-
- for( i = 0; i < pConditions->size(); ++i )
+ for (std::vector<rtl::Reference<SwXMLConditionContext_Impl>>::size_type i = 0;
+ i < pConditions->size(); ++i)
{
- if( (*pConditions)[i]->IsValid() )
- {
- Master_CollCondition nCond = (*pConditions)[i]->getCondition();
- sal_uInt32 nSubCond = (*pConditions)[i]->getSubCondition();
+ assert((*pConditions)[i]->IsValid()); // checked before inserting
+ Master_CollCondition nCond = (*pConditions)[i]->getCondition();
+ sal_uInt32 nSubCond = (*pConditions)[i]->getSubCondition();
- for( j = 0; j < COND_COMMAND_COUNT; ++j )
+ for (size_t j = 0; j < COND_COMMAND_COUNT; ++j)
+ {
+ if (pCommands[j].nCnd == nCond &&
+ pCommands[j].nSubCond == nSubCond)
{
- if( aCommands[j].nCnd == nCond &&
- aCommands[j].nSubCond == nSubCond )
- {
- aSeq[i].Name = GetCommandContextByIndex( j );
- aSeq[i].Value <<= GetImport().GetStyleDisplayName( GetFamily(), (*pConditions)[i]->getApplyStyle() );
- break;
- }
+ aSeq[i].Name = GetCommandContextByIndex( j );
+ aSeq[i].Value <<= GetImport().GetStyleDisplayName(
+ GetFamily(), (*pConditions)[i]->getApplyStyle() );
+ break;
}
}
}
- xPropSet->setPropertyValue( UNO_NAME_PARA_STYLE_CONDITIONS, uno::makeAny( aSeq ) );
+ try
+ {
+ xPropSet->setPropertyValue(UNO_NAME_PARA_STYLE_CONDITIONS, uno::makeAny(aSeq));
+ }
+ catch (uno::Exception const& e)
+ {
+ SAL_WARN("sw.xml", "exception when setting ParaStyleConditions: " << e.Message);
+ }
}
XMLTextStyleContext::Finish( bOverwrite );
}
diff --git a/sw/source/uibase/chrdlg/ccoll.cxx b/sw/source/uibase/chrdlg/ccoll.cxx
index d4b617b12d9b..58f77f5770db 100644
--- a/sw/source/uibase/chrdlg/ccoll.cxx
+++ b/sw/source/uibase/chrdlg/ccoll.cxx
@@ -41,6 +41,8 @@
//!! order of entries has to be the same as in
//!! CommandStruct SwCondCollItem::aCmds[]
+// note: also keep this in sync with the list of conditions in xmloff/source/style/prstylecond.cxx
+
const char * const aCommandContext[COND_COMMAND_COUNT] =
{
"TableHeader",
diff --git a/xmloff/source/style/prstylecond.cxx b/xmloff/source/style/prstylecond.cxx
index 4568c6bc88b2..63b7e3ace250 100644
--- a/xmloff/source/style/prstylecond.cxx
+++ b/xmloff/source/style/prstylecond.cxx
@@ -23,12 +23,14 @@
using namespace ::xmloff::token;
-static struct ConditionMap
+// note: keep this in sync with the list of conditions in sw/source/uibase/chrdlg/ccoll.cxx
+
+static const struct ConditionMap
{
char const* aInternal;
XMLTokenEnum nExternal;
int aValue;
-} aConditionMap[] =
+} g_ConditionMap[] =
{
{ "TableHeader", XML_TABLE_HEADER, -1 },
{ "Table", XML_TABLE, -1 },
@@ -60,27 +62,24 @@ static struct ConditionMap
{ "NumberingLevel10", XML_LIST_LEVEL, 10 }
};
-#define CONDITION_COUNT (sizeof(aConditionMap) / sizeof(aConditionMap[0]))
-
OUString GetParaStyleCondExternal( OUString const &internal)
{
- unsigned i;
-
- for(i = 0; i < CONDITION_COUNT; ++i)
+ for (size_t i = 0; i < SAL_N_ELEMENTS(g_ConditionMap); ++i)
{
- if(internal.compareToAscii( aConditionMap[i].aInternal ) == 0)
+ if (internal.compareToAscii( g_ConditionMap[i].aInternal ) == 0)
{
- OUString aResult( GetXMLToken( aConditionMap[i].nExternal ) );
+ OUString aResult( GetXMLToken( g_ConditionMap[i].nExternal ) );
aResult += "()";
- if( aConditionMap[i].aValue != -1 )
+ if (g_ConditionMap[i].aValue != -1)
{
aResult += "=";
- aResult += OUString::number( aConditionMap[i].aValue );
+ aResult += OUString::number( g_ConditionMap[i].aValue );
}
return aResult;
}
}
+ assert(!"GetParaStyleCondExternal: model has unknown style condition");
return OUString();
}
diff --git a/xmloff/source/style/styleexp.cxx b/xmloff/source/style/styleexp.cxx
index bd8588a1928a..4795aa32b19f 100644
--- a/xmloff/source/style/styleexp.cxx
+++ b/xmloff/source/style/styleexp.cxx
@@ -80,30 +80,29 @@ void XMLStyleExport::exportStyleAttributes( const Reference< XStyle >& )
void XMLStyleExport::exportStyleContent( const Reference< XStyle >& rStyle )
{
Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
+ assert(xPropSet.is());
try
{
uno::Any aProperty = xPropSet->getPropertyValue( "ParaStyleConditions" );
uno::Sequence< beans::NamedValue > aSeq;
- int i;
aProperty >>= aSeq;
- for(i = 0; i < aSeq.getLength(); ++i)
+ for (sal_Int32 i = 0; i < aSeq.getLength(); ++i)
{
- beans::NamedValue const& aNamedCond = aSeq[i];
+ beans::NamedValue const& rNamedCond = aSeq[i];
OUString aStyleName;
- if ( aNamedCond.Value >>= aStyleName )
+ if (rNamedCond.Value >>= aStyleName)
{
- if ( aStyleName.getLength() > 0 )
+ if (!aStyleName.isEmpty())
{
- OUString aExternal = GetParaStyleCondExternal( aNamedCond.Name );
+ OUString aExternal = GetParaStyleCondExternal(rNamedCond.Name);
- if (aExternal.getLength() > 0)
+ if (!aExternal.isEmpty())
{
- bool bEncoded;
-
+ bool bEncoded;
GetExport().AddAttribute( XML_NAMESPACE_STYLE,
XML_CONDITION,