1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10*63bba73cSAndrew Rist * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*63bba73cSAndrew Rist * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19*63bba73cSAndrew Rist * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <tools/debug.hxx> 29cdf0e10cSrcweir #ifndef __SGI_STL_SET 30cdf0e10cSrcweir #include <set> 31cdf0e10cSrcweir #endif 32cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 33cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 34cdf0e10cSrcweir #include <xmloff/xmlprcon.hxx> 35cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp> 36cdf0e10cSrcweir #include <com/sun/star/style/XAutoStyleFamily.hpp> 37cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 38cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 39cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp> 40cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertyStates.hpp> 41cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 42cdf0e10cSrcweir #include <xmloff/xmlimp.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #ifndef _XMLOFF_PRSTYLEI_HXX 45cdf0e10cSrcweir #include <xmloff/prstylei.hxx> 46cdf0e10cSrcweir #endif 47cdf0e10cSrcweir #include <xmloff/attrlist.hxx> 48cdf0e10cSrcweir #include "xmloff/xmlerror.hxx" 49cdf0e10cSrcweir 50cdf0e10cSrcweir using ::rtl::OUString; 51cdf0e10cSrcweir using ::rtl::OUStringBuffer; 52cdf0e10cSrcweir 53cdf0e10cSrcweir using namespace ::com::sun::star; 54cdf0e10cSrcweir using namespace ::com::sun::star::uno; 55cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 56cdf0e10cSrcweir using namespace ::com::sun::star::style; 57cdf0e10cSrcweir using namespace ::com::sun::star::container; 58cdf0e10cSrcweir using namespace ::com::sun::star::beans; 59cdf0e10cSrcweir using namespace ::com::sun::star::lang; 60cdf0e10cSrcweir using namespace ::xmloff::token; 61cdf0e10cSrcweir 62cdf0e10cSrcweir 63cdf0e10cSrcweir void XMLPropStyleContext::SetAttribute( sal_uInt16 nPrefixKey, 64cdf0e10cSrcweir const OUString& rLocalName, 65cdf0e10cSrcweir const OUString& rValue ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_FAMILY ) ) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir DBG_ASSERT( GetFamily() == ((SvXMLStylesContext *)&mxStyles)->GetFamily( rValue ), "unexpected style family" ); 70cdf0e10cSrcweir } 71cdf0e10cSrcweir else 72cdf0e10cSrcweir { 73cdf0e10cSrcweir SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue ); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir TYPEINIT1( XMLPropStyleContext, SvXMLStyleContext ); 78cdf0e10cSrcweir 79cdf0e10cSrcweir XMLPropStyleContext::XMLPropStyleContext( SvXMLImport& rImport, 80cdf0e10cSrcweir sal_uInt16 nPrfx, const OUString& rLName, 81cdf0e10cSrcweir const Reference< XAttributeList > & xAttrList, 82cdf0e10cSrcweir SvXMLStylesContext& rStyles, sal_uInt16 nFamily, 83cdf0e10cSrcweir sal_Bool bDefault ) 84cdf0e10cSrcweir : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, nFamily, bDefault ) 85cdf0e10cSrcweir , msIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ) 86cdf0e10cSrcweir , msFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) ) 87cdf0e10cSrcweir , mxStyles( &rStyles ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir XMLPropStyleContext::~XMLPropStyleContext() 92cdf0e10cSrcweir { 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir SvXMLImportContext *XMLPropStyleContext::CreateChildContext( 96cdf0e10cSrcweir sal_uInt16 nPrefix, 97cdf0e10cSrcweir const OUString& rLocalName, 98cdf0e10cSrcweir const Reference< XAttributeList > & xAttrList ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir SvXMLImportContext *pContext = 0; 101cdf0e10cSrcweir 102cdf0e10cSrcweir sal_uInt32 nFamily = 0; 103cdf0e10cSrcweir if( XML_NAMESPACE_STYLE == nPrefix ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) ) 106cdf0e10cSrcweir nFamily = XML_TYPE_PROP_GRAPHIC; 107cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_DRAWING_PAGE_PROPERTIES ) ) 108cdf0e10cSrcweir nFamily = XML_TYPE_PROP_DRAWING_PAGE; 109cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) 110cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TEXT; 111cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) ) 112cdf0e10cSrcweir nFamily = XML_TYPE_PROP_PARAGRAPH; 113cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_RUBY_PROPERTIES ) ) 114cdf0e10cSrcweir nFamily = XML_TYPE_PROP_RUBY; 115cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_SECTION_PROPERTIES ) ) 116cdf0e10cSrcweir nFamily = XML_TYPE_PROP_SECTION; 117cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) ) 118cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TABLE; 119cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_TABLE_COLUMN_PROPERTIES ) ) 120cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TABLE_COLUMN; 121cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) ) 122cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TABLE_ROW; 123cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_TABLE_CELL_PROPERTIES ) ) 124cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TABLE_CELL; 125cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) ) 126cdf0e10cSrcweir nFamily = XML_TYPE_PROP_CHART; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir if( nFamily ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir UniReference < SvXMLImportPropertyMapper > xImpPrMap = 131cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetImportPropertyMapper( 132cdf0e10cSrcweir GetFamily() ); 133cdf0e10cSrcweir if( xImpPrMap.is() ) 134cdf0e10cSrcweir pContext = new SvXMLPropertySetContext( GetImport(), nPrefix, 135cdf0e10cSrcweir rLocalName, xAttrList, 136cdf0e10cSrcweir nFamily, 137cdf0e10cSrcweir maProperties, 138cdf0e10cSrcweir xImpPrMap ); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir if( !pContext ) 142cdf0e10cSrcweir pContext = SvXMLStyleContext::CreateChildContext( nPrefix, rLocalName, 143cdf0e10cSrcweir xAttrList ); 144cdf0e10cSrcweir 145cdf0e10cSrcweir return pContext; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir void XMLPropStyleContext::FillPropertySet( 149cdf0e10cSrcweir const Reference< XPropertySet > & rPropSet ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir UniReference < SvXMLImportPropertyMapper > xImpPrMap = 152cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetImportPropertyMapper( 153cdf0e10cSrcweir GetFamily() ); 154cdf0e10cSrcweir DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" ); 155cdf0e10cSrcweir if( xImpPrMap.is() ) 156cdf0e10cSrcweir xImpPrMap->FillPropertySet( maProperties, rPropSet ); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir void XMLPropStyleContext::SetDefaults() 160cdf0e10cSrcweir { 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir Reference < XStyle > XMLPropStyleContext::Create() 164cdf0e10cSrcweir { 165cdf0e10cSrcweir Reference < XStyle > xNewStyle; 166cdf0e10cSrcweir 167cdf0e10cSrcweir OUString sServiceName( 168cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetServiceName( GetFamily() ) ); 169cdf0e10cSrcweir if( sServiceName.getLength() ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir Reference< XMultiServiceFactory > xFactory( GetImport().GetModel(), 172cdf0e10cSrcweir UNO_QUERY ); 173cdf0e10cSrcweir if( xFactory.is() ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir Reference < XInterface > xIfc = 176cdf0e10cSrcweir xFactory->createInstance( sServiceName ); 177cdf0e10cSrcweir if( xIfc.is() ) 178cdf0e10cSrcweir xNewStyle = Reference < XStyle >( xIfc, UNO_QUERY ); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir return xNewStyle; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir typedef ::std::set < OUString, ::comphelper::UStringLess > PropertyNameSet; 186cdf0e10cSrcweir 187cdf0e10cSrcweir void XMLPropStyleContext::CreateAndInsert( sal_Bool bOverwrite ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir if( ((SvXMLStylesContext *)&mxStyles)->IsAutomaticStyle() 190cdf0e10cSrcweir && ( GetFamily() == XML_STYLE_FAMILY_TEXT_TEXT || GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ) ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir Reference < XAutoStyleFamily > xAutoFamily = 193cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetAutoStyles( GetFamily() ); 194cdf0e10cSrcweir if( !xAutoFamily.is() ) 195cdf0e10cSrcweir return; 196cdf0e10cSrcweir UniReference < SvXMLImportPropertyMapper > xImpPrMap = 197cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetImportPropertyMapper( GetFamily() ); 198cdf0e10cSrcweir DBG_ASSERT( xImpPrMap.is(), "There is no import prop mapper" ); 199cdf0e10cSrcweir if( xImpPrMap.is() ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir Sequence< PropertyValue > aValues; 202cdf0e10cSrcweir xImpPrMap->FillPropertySequence( maProperties, aValues ); 203cdf0e10cSrcweir 204cdf0e10cSrcweir sal_Int32 nLen = aValues.getLength(); 205cdf0e10cSrcweir if( nLen ) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir if( GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir aValues.realloc( nLen + 2 ); 210cdf0e10cSrcweir PropertyValue *pProps = aValues.getArray() + nLen; 211cdf0e10cSrcweir pProps->Name = rtl::OUString::createFromAscii("ParaStyleName"); 212cdf0e10cSrcweir OUString sParent( GetParentName() ); 213cdf0e10cSrcweir if( sParent.getLength() ) 214cdf0e10cSrcweir sParent = GetImport().GetStyleDisplayName( GetFamily(), sParent ); 215cdf0e10cSrcweir else 216cdf0e10cSrcweir sParent = rtl::OUString::createFromAscii("Standard"); 217cdf0e10cSrcweir pProps->Value <<= sParent; 218cdf0e10cSrcweir ++pProps; 219cdf0e10cSrcweir pProps->Name = rtl::OUString::createFromAscii("ParaConditionalStyleName"); 220cdf0e10cSrcweir pProps->Value <<= sParent; 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir Reference < XAutoStyle > xAutoStyle = xAutoFamily->insertStyle( aValues ); 224cdf0e10cSrcweir if( xAutoStyle.is() ) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir Sequence< OUString > aPropNames(1); 227cdf0e10cSrcweir aPropNames[0] = GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ? 228cdf0e10cSrcweir rtl::OUString::createFromAscii("ParaAutoStyleName") : 229cdf0e10cSrcweir rtl::OUString::createFromAscii("CharAutoStyleName"); 230cdf0e10cSrcweir Sequence< Any > aAny = xAutoStyle->getPropertyValues( aPropNames ); 231cdf0e10cSrcweir if( aAny.hasElements() ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir OUString aName; 234cdf0e10cSrcweir aAny[0] >>= aName; 235cdf0e10cSrcweir SetAutoName( aName ); 236cdf0e10cSrcweir } 237cdf0e10cSrcweir } 238cdf0e10cSrcweir } 239cdf0e10cSrcweir } 240cdf0e10cSrcweir } 241cdf0e10cSrcweir else 242cdf0e10cSrcweir { 243cdf0e10cSrcweir const OUString& rName = GetDisplayName(); 244cdf0e10cSrcweir if( 0 == rName.getLength() || IsDefaultStyle() ) 245cdf0e10cSrcweir return; 246cdf0e10cSrcweir 247cdf0e10cSrcweir Reference < XNameContainer > xFamilies = 248cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetStylesContainer( GetFamily() ); 249cdf0e10cSrcweir if( !xFamilies.is() ) 250cdf0e10cSrcweir return; 251cdf0e10cSrcweir 252cdf0e10cSrcweir sal_Bool bNew = sal_False; 253cdf0e10cSrcweir if( xFamilies->hasByName( rName ) ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir Any aAny = xFamilies->getByName( rName ); 256cdf0e10cSrcweir aAny >>= mxStyle; 257cdf0e10cSrcweir } 258cdf0e10cSrcweir else 259cdf0e10cSrcweir { 260cdf0e10cSrcweir mxStyle = Create(); 261cdf0e10cSrcweir if( !mxStyle.is() ) 262cdf0e10cSrcweir return; 263cdf0e10cSrcweir 264cdf0e10cSrcweir Any aAny; 265cdf0e10cSrcweir aAny <<= mxStyle; 266cdf0e10cSrcweir xFamilies->insertByName( rName, aAny ); 267cdf0e10cSrcweir bNew = sal_True; 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir Reference < XPropertySet > xPropSet( mxStyle, UNO_QUERY ); 271cdf0e10cSrcweir Reference< XPropertySetInfo > xPropSetInfo = 272cdf0e10cSrcweir xPropSet->getPropertySetInfo(); 273cdf0e10cSrcweir if( !bNew && xPropSetInfo->hasPropertyByName( msIsPhysical ) ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir Any aAny = xPropSet->getPropertyValue( msIsPhysical ); 276cdf0e10cSrcweir bNew = !*(sal_Bool *)aAny.getValue(); 277cdf0e10cSrcweir } 278cdf0e10cSrcweir SetNew( bNew ); 279cdf0e10cSrcweir if( rName != GetName() ) 280cdf0e10cSrcweir GetImport().AddStyleDisplayName( GetFamily(), GetName(), rName ); 281cdf0e10cSrcweir 282cdf0e10cSrcweir if( bOverwrite || bNew ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY ); 285cdf0e10cSrcweir 286cdf0e10cSrcweir UniReference < XMLPropertySetMapper > xPrMap; 287cdf0e10cSrcweir UniReference < SvXMLImportPropertyMapper > xImpPrMap = 288cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetImportPropertyMapper( 289cdf0e10cSrcweir GetFamily() ); 290cdf0e10cSrcweir DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" ); 291cdf0e10cSrcweir if( xImpPrMap.is() ) 292cdf0e10cSrcweir xPrMap = xImpPrMap->getPropertySetMapper(); 293cdf0e10cSrcweir if( xPrMap.is() ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir Reference < XMultiPropertyStates > xMultiStates( xPropSet, 296cdf0e10cSrcweir UNO_QUERY ); 297cdf0e10cSrcweir if( xMultiStates.is() ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir xMultiStates->setAllPropertiesToDefault(); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir else 302cdf0e10cSrcweir { 303cdf0e10cSrcweir PropertyNameSet aNameSet; 304cdf0e10cSrcweir sal_Int32 nCount = xPrMap->GetEntryCount(); 305cdf0e10cSrcweir sal_Int32 i; 306cdf0e10cSrcweir for( i = 0; i < nCount; i++ ) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir const OUString& rPrName = xPrMap->GetEntryAPIName( i ); 309cdf0e10cSrcweir if( xPropSetInfo->hasPropertyByName( rPrName ) ) 310cdf0e10cSrcweir aNameSet.insert( rPrName ); 311cdf0e10cSrcweir } 312cdf0e10cSrcweir 313cdf0e10cSrcweir nCount = aNameSet.size(); 314cdf0e10cSrcweir Sequence < OUString > aNames( nCount ); 315cdf0e10cSrcweir OUString *pNames = aNames.getArray(); 316cdf0e10cSrcweir PropertyNameSet::iterator aIter = aNameSet.begin(); 317cdf0e10cSrcweir while( aIter != aNameSet.end() ) 318cdf0e10cSrcweir *pNames++ = *aIter++; 319cdf0e10cSrcweir 320cdf0e10cSrcweir Sequence < PropertyState > aStates( 321cdf0e10cSrcweir xPropState->getPropertyStates( aNames ) ); 322cdf0e10cSrcweir const PropertyState *pStates = aStates.getConstArray(); 323cdf0e10cSrcweir pNames = aNames.getArray(); 324cdf0e10cSrcweir 325cdf0e10cSrcweir for( i = 0; i < nCount; i++ ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir if( PropertyState_DIRECT_VALUE == *pStates++ ) 328cdf0e10cSrcweir xPropState->setPropertyToDefault( pNames[i] ); 329cdf0e10cSrcweir } 330cdf0e10cSrcweir } 331cdf0e10cSrcweir } 332cdf0e10cSrcweir 333cdf0e10cSrcweir if (mxStyle.is()) 334cdf0e10cSrcweir mxStyle->setParentStyle(OUString()); 335cdf0e10cSrcweir 336cdf0e10cSrcweir FillPropertySet( xPropSet ); 337cdf0e10cSrcweir } 338cdf0e10cSrcweir else 339cdf0e10cSrcweir { 340cdf0e10cSrcweir SetValid( sal_False ); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir } 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir void XMLPropStyleContext::Finish( sal_Bool bOverwrite ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir if( mxStyle.is() && (IsNew() || bOverwrite) ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir // The families cintaner must exist 350cdf0e10cSrcweir Reference < XNameContainer > xFamilies = 351cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetStylesContainer( GetFamily() ); 352cdf0e10cSrcweir DBG_ASSERT( xFamilies.is(), "Families lost" ); 353cdf0e10cSrcweir if( !xFamilies.is() ) 354cdf0e10cSrcweir return; 355cdf0e10cSrcweir 356cdf0e10cSrcweir // connect parent 357cdf0e10cSrcweir OUString sParent( GetParentName() ); 358cdf0e10cSrcweir if( sParent.getLength() ) 359cdf0e10cSrcweir sParent = GetImport().GetStyleDisplayName( GetFamily(), sParent ); 360cdf0e10cSrcweir if( sParent.getLength() && !xFamilies->hasByName( sParent ) ) 361cdf0e10cSrcweir sParent = OUString(); 362cdf0e10cSrcweir 363cdf0e10cSrcweir if( sParent != mxStyle->getParentStyle() ) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir // this may except if setting the parent style forms a 366cdf0e10cSrcweir // circle in the style depencies; especially if the parent 367cdf0e10cSrcweir // style is the same as the current style 368cdf0e10cSrcweir try 369cdf0e10cSrcweir { 370cdf0e10cSrcweir mxStyle->setParentStyle( sParent ); 371cdf0e10cSrcweir } 372cdf0e10cSrcweir catch( uno::Exception e ) 373cdf0e10cSrcweir { 374cdf0e10cSrcweir // according to the API definition, I would expect a 375cdf0e10cSrcweir // container::NoSuchElementException. But it throws an 376cdf0e10cSrcweir // uno::RuntimeException instead. I catch 377cdf0e10cSrcweir // uno::Exception in order to process both of them. 378cdf0e10cSrcweir 379cdf0e10cSrcweir // We can't set the parent style. For a proper 380cdf0e10cSrcweir // Error-Message, we should pass in the name of the 381cdf0e10cSrcweir // style, as well as the desired parent style. 382cdf0e10cSrcweir Sequence<OUString> aSequence(2); 383cdf0e10cSrcweir 384cdf0e10cSrcweir // getName() throws no non-Runtime exception: 385cdf0e10cSrcweir aSequence[0] = mxStyle->getName(); 386cdf0e10cSrcweir aSequence[1] = sParent; 387cdf0e10cSrcweir 388cdf0e10cSrcweir GetImport().SetError( 389cdf0e10cSrcweir XMLERROR_FLAG_ERROR | XMLERROR_PARENT_STYLE_NOT_ALLOWED, 390cdf0e10cSrcweir aSequence, e.Message, NULL ); 391cdf0e10cSrcweir } 392cdf0e10cSrcweir } 393cdf0e10cSrcweir 394cdf0e10cSrcweir // connect follow 395cdf0e10cSrcweir OUString sFollow( GetFollow() ); 396cdf0e10cSrcweir if( sFollow.getLength() ) 397cdf0e10cSrcweir sFollow = GetImport().GetStyleDisplayName( GetFamily(), sFollow ); 398cdf0e10cSrcweir if( !sFollow.getLength() || !xFamilies->hasByName( sFollow ) ) 399cdf0e10cSrcweir sFollow = mxStyle->getName(); 400cdf0e10cSrcweir 401cdf0e10cSrcweir Reference < XPropertySet > xPropSet( mxStyle, UNO_QUERY ); 402cdf0e10cSrcweir Reference< XPropertySetInfo > xPropSetInfo = 403cdf0e10cSrcweir xPropSet->getPropertySetInfo(); 404cdf0e10cSrcweir if( xPropSetInfo->hasPropertyByName( msFollowStyle ) ) 405cdf0e10cSrcweir { 406cdf0e10cSrcweir Any aAny = xPropSet->getPropertyValue( msFollowStyle ); 407cdf0e10cSrcweir OUString sCurrFollow; 408cdf0e10cSrcweir aAny >>= sCurrFollow; 409cdf0e10cSrcweir if( sCurrFollow != sFollow ) 410cdf0e10cSrcweir { 411cdf0e10cSrcweir aAny <<= sFollow; 412cdf0e10cSrcweir xPropSet->setPropertyValue( msFollowStyle, aAny ); 413cdf0e10cSrcweir } 414cdf0e10cSrcweir } 415cdf0e10cSrcweir } 416cdf0e10cSrcweir } 417cdf0e10cSrcweir 418cdf0e10cSrcweir 419