Kaydet (Commit) 0ae13c77 authored tarafından Michael Stahl's avatar Michael Stahl

xmloff,sw: some stylistic cleanup to conditional styles

Change-Id: I1722a0b3d67a7c8740daa5a131d7800319ee2373
üst 2c7ec52b
......@@ -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 );
}
......
......@@ -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",
......
......@@ -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();
}
......
......@@ -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,
......
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