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