163bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
363bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
463bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
563bba73cSAndrew Rist * distributed with this work for additional information
663bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
763bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
863bba73cSAndrew Rist * "License"); you may not use this file except in compliance
963bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
1163bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
1363bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
1463bba73cSAndrew Rist * software distributed under the License is distributed on an
1563bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1663bba73cSAndrew Rist * KIND, either express or implied. See the License for the
1763bba73cSAndrew Rist * specific language governing permissions and limitations
1863bba73cSAndrew Rist * under the License.
19cdf0e10cSrcweir *
2063bba73cSAndrew Rist *************************************************************/
2163bba73cSAndrew Rist
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
24cdf0e10cSrcweir
25cdf0e10cSrcweir #include <tools/debug.hxx>
26cdf0e10cSrcweir #ifndef __SGI_STL_SET
27cdf0e10cSrcweir #include <set>
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
30cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
31cdf0e10cSrcweir #include <xmloff/xmlprcon.hxx>
32cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp>
33cdf0e10cSrcweir #include <com/sun/star/style/XAutoStyleFamily.hpp>
34cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
35cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
36cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp>
37cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertyStates.hpp>
38cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
40cdf0e10cSrcweir #include <xmloff/prstylei.hxx>
41cdf0e10cSrcweir #include <xmloff/attrlist.hxx>
42cdf0e10cSrcweir #include "xmloff/xmlerror.hxx"
43cdf0e10cSrcweir
4456b35d86SArmin Le Grand //UUUU
4556b35d86SArmin Le Grand #include <com/sun/star/drawing/FillStyle.hpp>
4656b35d86SArmin Le Grand
47cdf0e10cSrcweir using ::rtl::OUString;
48cdf0e10cSrcweir using ::rtl::OUStringBuffer;
49cdf0e10cSrcweir
50cdf0e10cSrcweir using namespace ::com::sun::star;
51cdf0e10cSrcweir using namespace ::com::sun::star::uno;
52cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
53cdf0e10cSrcweir using namespace ::com::sun::star::style;
54cdf0e10cSrcweir using namespace ::com::sun::star::container;
55cdf0e10cSrcweir using namespace ::com::sun::star::beans;
56cdf0e10cSrcweir using namespace ::com::sun::star::lang;
57cdf0e10cSrcweir using namespace ::xmloff::token;
58cdf0e10cSrcweir
5956b35d86SArmin Le Grand //UUUU
6056b35d86SArmin Le Grand using namespace com::sun::star::drawing;
61cdf0e10cSrcweir
SetAttribute(sal_uInt16 nPrefixKey,const OUString & rLocalName,const OUString & rValue)62cdf0e10cSrcweir void XMLPropStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
63cdf0e10cSrcweir const OUString& rLocalName,
64cdf0e10cSrcweir const OUString& rValue )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_FAMILY ) )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir DBG_ASSERT( GetFamily() == ((SvXMLStylesContext *)&mxStyles)->GetFamily( rValue ), "unexpected style family" );
69cdf0e10cSrcweir }
70cdf0e10cSrcweir else
71cdf0e10cSrcweir {
72cdf0e10cSrcweir SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
73cdf0e10cSrcweir }
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
76cdf0e10cSrcweir TYPEINIT1( XMLPropStyleContext, SvXMLStyleContext );
77cdf0e10cSrcweir
7856b35d86SArmin Le Grand
7956b35d86SArmin Le Grand //UUUU
8056b35d86SArmin Le Grand OldFillStyleDefinitionSet XMLPropStyleContext::maStandardSet;
8156b35d86SArmin Le Grand OldFillStyleDefinitionSet XMLPropStyleContext::maHeaderSet;
8256b35d86SArmin Le Grand OldFillStyleDefinitionSet XMLPropStyleContext::maFooterSet;
8356b35d86SArmin Le Grand OldFillStyleDefinitionSet XMLPropStyleContext::maParaSet;
8456b35d86SArmin Le Grand
XMLPropStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<XAttributeList> & xAttrList,SvXMLStylesContext & rStyles,sal_uInt16 nFamily,sal_Bool bDefault)8556b35d86SArmin Le Grand XMLPropStyleContext::XMLPropStyleContext(
8656b35d86SArmin Le Grand SvXMLImport& rImport,
8756b35d86SArmin Le Grand sal_uInt16 nPrfx,
8856b35d86SArmin Le Grand const OUString& rLName,
89cdf0e10cSrcweir const Reference< XAttributeList > & xAttrList,
9056b35d86SArmin Le Grand SvXMLStylesContext& rStyles,
9156b35d86SArmin Le Grand sal_uInt16 nFamily,
92cdf0e10cSrcweir sal_Bool bDefault)
9356b35d86SArmin Le Grand : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList, nFamily, bDefault),
9456b35d86SArmin Le Grand msIsPhysical(RTL_CONSTASCII_USTRINGPARAM("IsPhysical")),
9556b35d86SArmin Le Grand msFollowStyle(RTL_CONSTASCII_USTRINGPARAM("FollowStyle")),
9656b35d86SArmin Le Grand mxStyles(&rStyles)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
~XMLPropStyleContext()100cdf0e10cSrcweir XMLPropStyleContext::~XMLPropStyleContext()
101cdf0e10cSrcweir {
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
getStandardSet()10456b35d86SArmin Le Grand const OldFillStyleDefinitionSet& XMLPropStyleContext::getStandardSet()
10556b35d86SArmin Le Grand {
10656b35d86SArmin Le Grand if(maStandardSet.empty())
10756b35d86SArmin Le Grand {
10856b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackColorRGB")));
10956b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackTransparent")));
11056b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackColorTransparency")));
11156b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackGraphicURL")));
11256b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackGraphicFilter")));
11356b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackGraphicLocation")));
11456b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackGraphicTransparency")));
11556b35d86SArmin Le Grand }
11656b35d86SArmin Le Grand
11756b35d86SArmin Le Grand return maStandardSet;
11856b35d86SArmin Le Grand }
11956b35d86SArmin Le Grand
getHeaderSet()12056b35d86SArmin Le Grand const OldFillStyleDefinitionSet& XMLPropStyleContext::getHeaderSet()
12156b35d86SArmin Le Grand {
12256b35d86SArmin Le Grand if(maHeaderSet.empty())
12356b35d86SArmin Le Grand {
12456b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackColorRGB")));
12556b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackTransparent")));
12656b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackColorTransparency")));
12756b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackGraphicURL")));
12856b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackGraphicFilter")));
12956b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackGraphicLocation")));
13056b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackGraphicTransparency")));
13156b35d86SArmin Le Grand }
13256b35d86SArmin Le Grand
13356b35d86SArmin Le Grand return maHeaderSet;
13456b35d86SArmin Le Grand }
13556b35d86SArmin Le Grand
getFooterSet()13656b35d86SArmin Le Grand const OldFillStyleDefinitionSet& XMLPropStyleContext::getFooterSet()
13756b35d86SArmin Le Grand {
13856b35d86SArmin Le Grand if(maFooterSet.empty())
13956b35d86SArmin Le Grand {
14056b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackColorRGB")));
14156b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackTransparent")));
14256b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackColorTransparency")));
14356b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackGraphicURL")));
14456b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackGraphicFilter")));
14556b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackGraphicLocation")));
14656b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackGraphicTransparency")));
14756b35d86SArmin Le Grand }
14856b35d86SArmin Le Grand
14956b35d86SArmin Le Grand return maFooterSet;
15056b35d86SArmin Le Grand }
15156b35d86SArmin Le Grand
getParaSet()15256b35d86SArmin Le Grand const OldFillStyleDefinitionSet& XMLPropStyleContext::getParaSet()
15356b35d86SArmin Le Grand {
15456b35d86SArmin Le Grand if(maParaSet.empty())
15556b35d86SArmin Le Grand {
15656b35d86SArmin Le Grand // Caution: here it is *not* 'ParaBackColorRGB' as it should be, but indeed
15756b35d86SArmin Le Grand // 'ParaBackColor' is used, see aXMLParaPropMap definition (line 313)
15856b35d86SArmin Le Grand maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackColor")));
15956b35d86SArmin Le Grand maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackTransparent")));
16056b35d86SArmin Le Grand maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackGraphicLocation")));
16156b35d86SArmin Le Grand maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackGraphicFilter")));
16256b35d86SArmin Le Grand maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackGraphicURL")));
16356b35d86SArmin Le Grand
16456b35d86SArmin Le Grand // These are not used in aXMLParaPropMap definition, thus not needed here
16556b35d86SArmin Le Grand // maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackColorTransparency")));
16656b35d86SArmin Le Grand // maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackGraphicTransparency")));
16756b35d86SArmin Le Grand }
16856b35d86SArmin Le Grand
16956b35d86SArmin Le Grand return maParaSet;
17056b35d86SArmin Le Grand }
17156b35d86SArmin Le Grand
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)172cdf0e10cSrcweir SvXMLImportContext *XMLPropStyleContext::CreateChildContext(
173cdf0e10cSrcweir sal_uInt16 nPrefix,
174cdf0e10cSrcweir const OUString& rLocalName,
175cdf0e10cSrcweir const Reference< XAttributeList > & xAttrList )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir SvXMLImportContext *pContext = 0;
178cdf0e10cSrcweir
179cdf0e10cSrcweir sal_uInt32 nFamily = 0;
180cdf0e10cSrcweir if( XML_NAMESPACE_STYLE == nPrefix )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
183cdf0e10cSrcweir nFamily = XML_TYPE_PROP_GRAPHIC;
184cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_DRAWING_PAGE_PROPERTIES ) )
185cdf0e10cSrcweir nFamily = XML_TYPE_PROP_DRAWING_PAGE;
186cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
187cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TEXT;
188cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
189cdf0e10cSrcweir nFamily = XML_TYPE_PROP_PARAGRAPH;
190cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_RUBY_PROPERTIES ) )
191cdf0e10cSrcweir nFamily = XML_TYPE_PROP_RUBY;
192cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_SECTION_PROPERTIES ) )
193cdf0e10cSrcweir nFamily = XML_TYPE_PROP_SECTION;
194cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) )
195cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TABLE;
196cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_TABLE_COLUMN_PROPERTIES ) )
197cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TABLE_COLUMN;
198cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) )
199cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TABLE_ROW;
200cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_TABLE_CELL_PROPERTIES ) )
201cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TABLE_CELL;
202cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
203cdf0e10cSrcweir nFamily = XML_TYPE_PROP_CHART;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir if( nFamily )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir UniReference < SvXMLImportPropertyMapper > xImpPrMap =
208cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetImportPropertyMapper(
209cdf0e10cSrcweir GetFamily() );
210cdf0e10cSrcweir if( xImpPrMap.is() )
211cdf0e10cSrcweir pContext = new SvXMLPropertySetContext( GetImport(), nPrefix,
212cdf0e10cSrcweir rLocalName, xAttrList,
213cdf0e10cSrcweir nFamily,
214cdf0e10cSrcweir maProperties,
215cdf0e10cSrcweir xImpPrMap );
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir if( !pContext )
219cdf0e10cSrcweir pContext = SvXMLStyleContext::CreateChildContext( nPrefix, rLocalName,
220cdf0e10cSrcweir xAttrList );
221cdf0e10cSrcweir
222cdf0e10cSrcweir return pContext;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir
FillPropertySet(const Reference<XPropertySet> & rPropSet)225cdf0e10cSrcweir void XMLPropStyleContext::FillPropertySet(
226cdf0e10cSrcweir const Reference< XPropertySet > & rPropSet )
227cdf0e10cSrcweir {
228cdf0e10cSrcweir UniReference < SvXMLImportPropertyMapper > xImpPrMap =
229cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetImportPropertyMapper(
230cdf0e10cSrcweir GetFamily() );
231cdf0e10cSrcweir DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
232cdf0e10cSrcweir if( xImpPrMap.is() )
233cdf0e10cSrcweir xImpPrMap->FillPropertySet( maProperties, rPropSet );
234cdf0e10cSrcweir }
235cdf0e10cSrcweir
SetDefaults()236cdf0e10cSrcweir void XMLPropStyleContext::SetDefaults()
237cdf0e10cSrcweir {
238cdf0e10cSrcweir }
239cdf0e10cSrcweir
Create()240cdf0e10cSrcweir Reference < XStyle > XMLPropStyleContext::Create()
241cdf0e10cSrcweir {
242cdf0e10cSrcweir Reference < XStyle > xNewStyle;
243cdf0e10cSrcweir
244cdf0e10cSrcweir OUString sServiceName(
245cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetServiceName( GetFamily() ) );
246cdf0e10cSrcweir if( sServiceName.getLength() )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir Reference< XMultiServiceFactory > xFactory( GetImport().GetModel(),
249cdf0e10cSrcweir UNO_QUERY );
250cdf0e10cSrcweir if( xFactory.is() )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir Reference < XInterface > xIfc =
253cdf0e10cSrcweir xFactory->createInstance( sServiceName );
254cdf0e10cSrcweir if( xIfc.is() )
255cdf0e10cSrcweir xNewStyle = Reference < XStyle >( xIfc, UNO_QUERY );
256cdf0e10cSrcweir }
257cdf0e10cSrcweir }
258cdf0e10cSrcweir
259cdf0e10cSrcweir return xNewStyle;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir
262cdf0e10cSrcweir typedef ::std::set < OUString, ::comphelper::UStringLess > PropertyNameSet;
263cdf0e10cSrcweir
CreateAndInsert(sal_Bool bOverwrite)264cdf0e10cSrcweir void XMLPropStyleContext::CreateAndInsert( sal_Bool bOverwrite )
265cdf0e10cSrcweir {
26656b35d86SArmin Le Grand SvXMLStylesContext* pSvXMLStylesContext = static_cast< SvXMLStylesContext* >(&mxStyles);
26756b35d86SArmin Le Grand UniReference < SvXMLImportPropertyMapper > xImpPrMap = pSvXMLStylesContext->GetImportPropertyMapper(GetFamily());
26856b35d86SArmin Le Grand OSL_ENSURE(xImpPrMap.is(), "There is no import prop mapper");
26956b35d86SArmin Le Grand
27056b35d86SArmin Le Grand //UUUU need to filter out old fill definitions when the new ones are used. The new
27156b35d86SArmin Le Grand // ones are used when a FillStyle is defined
27256b35d86SArmin Le Grand const bool bTakeCareOfDrawingLayerFillStyle(xImpPrMap.is() && GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH);
27356b35d86SArmin Le Grand bool bDrawingLayerFillStylesUsed(false);
27456b35d86SArmin Le Grand
27556b35d86SArmin Le Grand if(bTakeCareOfDrawingLayerFillStyle)
27656b35d86SArmin Le Grand {
27756b35d86SArmin Le Grand // check if new FillStyles are used and if so mark old ones with -1
27856b35d86SArmin Le Grand static ::rtl::OUString s_FillStyle(RTL_CONSTASCII_USTRINGPARAM("FillStyle"));
27956b35d86SArmin Le Grand
28056b35d86SArmin Le Grand if(doNewDrawingLayerFillStyleDefinitionsExist(s_FillStyle))
28156b35d86SArmin Le Grand {
28256b35d86SArmin Le Grand deactivateOldFillStyleDefinitions(getParaSet());
28356b35d86SArmin Le Grand bDrawingLayerFillStylesUsed = true;
28456b35d86SArmin Le Grand }
28556b35d86SArmin Le Grand }
28656b35d86SArmin Le Grand
28756b35d86SArmin Le Grand if( pSvXMLStylesContext->IsAutomaticStyle()
288cdf0e10cSrcweir && ( GetFamily() == XML_STYLE_FAMILY_TEXT_TEXT || GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ) )
289cdf0e10cSrcweir {
29056b35d86SArmin Le Grand //UUUU Need to translate StyleName from temp MapNames to names
29156b35d86SArmin Le Grand // used in already imported items (already exist in the pool). This
29256b35d86SArmin Le Grand // is required for AutomaticStyles since these do *not* use FillPropertySet
29356b35d86SArmin Le Grand // and thus just trigger CheckSpecialContext in XMLTextStyleContext::FillPropertySet
29456b35d86SArmin Le Grand // (which may be double action anyways). The mechanism there to use _ContextID_Index_Pair
29556b35d86SArmin Le Grand // is not working for AutomaticStyles and is already too late, too (this
29656b35d86SArmin Le Grand // method is already called before XMLTextStyleContext::FillPropertySet gets called)
29756b35d86SArmin Le Grand if(bDrawingLayerFillStylesUsed)
29856b35d86SArmin Le Grand {
29956b35d86SArmin Le Grand translateNameBasedDrawingLayerFillStyleDefinitionsToStyleDisplayNames();
30056b35d86SArmin Le Grand }
30156b35d86SArmin Le Grand
30256b35d86SArmin Le Grand Reference < XAutoStyleFamily > xAutoFamily = pSvXMLStylesContext->GetAutoStyles( GetFamily() );
303cdf0e10cSrcweir if( !xAutoFamily.is() )
304cdf0e10cSrcweir return;
305cdf0e10cSrcweir if( xImpPrMap.is() )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir Sequence< PropertyValue > aValues;
308cdf0e10cSrcweir xImpPrMap->FillPropertySequence( maProperties, aValues );
309cdf0e10cSrcweir
310cdf0e10cSrcweir sal_Int32 nLen = aValues.getLength();
311cdf0e10cSrcweir if( nLen )
312cdf0e10cSrcweir {
313cdf0e10cSrcweir if( GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH )
314cdf0e10cSrcweir {
315cdf0e10cSrcweir aValues.realloc( nLen + 2 );
316cdf0e10cSrcweir PropertyValue *pProps = aValues.getArray() + nLen;
317cdf0e10cSrcweir pProps->Name = rtl::OUString::createFromAscii("ParaStyleName");
318cdf0e10cSrcweir OUString sParent( GetParentName() );
319cdf0e10cSrcweir if( sParent.getLength() )
320cdf0e10cSrcweir sParent = GetImport().GetStyleDisplayName( GetFamily(), sParent );
321cdf0e10cSrcweir else
322cdf0e10cSrcweir sParent = rtl::OUString::createFromAscii("Standard");
323cdf0e10cSrcweir pProps->Value <<= sParent;
324cdf0e10cSrcweir ++pProps;
325cdf0e10cSrcweir pProps->Name = rtl::OUString::createFromAscii("ParaConditionalStyleName");
326cdf0e10cSrcweir pProps->Value <<= sParent;
327cdf0e10cSrcweir }
328cdf0e10cSrcweir
329cdf0e10cSrcweir Reference < XAutoStyle > xAutoStyle = xAutoFamily->insertStyle( aValues );
330cdf0e10cSrcweir if( xAutoStyle.is() )
331cdf0e10cSrcweir {
332cdf0e10cSrcweir Sequence< OUString > aPropNames(1);
333cdf0e10cSrcweir aPropNames[0] = GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ?
334cdf0e10cSrcweir rtl::OUString::createFromAscii("ParaAutoStyleName") :
335cdf0e10cSrcweir rtl::OUString::createFromAscii("CharAutoStyleName");
336cdf0e10cSrcweir Sequence< Any > aAny = xAutoStyle->getPropertyValues( aPropNames );
337cdf0e10cSrcweir if( aAny.hasElements() )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir OUString aName;
340cdf0e10cSrcweir aAny[0] >>= aName;
341cdf0e10cSrcweir SetAutoName( aName );
342cdf0e10cSrcweir }
343cdf0e10cSrcweir }
344cdf0e10cSrcweir }
345cdf0e10cSrcweir }
346cdf0e10cSrcweir }
347cdf0e10cSrcweir else
348cdf0e10cSrcweir {
349cdf0e10cSrcweir const OUString& rName = GetDisplayName();
350cdf0e10cSrcweir if( 0 == rName.getLength() || IsDefaultStyle() )
351cdf0e10cSrcweir return;
352cdf0e10cSrcweir
35356b35d86SArmin Le Grand Reference < XNameContainer > xFamilies = pSvXMLStylesContext->GetStylesContainer( GetFamily() );
354cdf0e10cSrcweir if( !xFamilies.is() )
355cdf0e10cSrcweir return;
356cdf0e10cSrcweir
357cdf0e10cSrcweir sal_Bool bNew = sal_False;
358cdf0e10cSrcweir if( xFamilies->hasByName( rName ) )
359cdf0e10cSrcweir {
360cdf0e10cSrcweir Any aAny = xFamilies->getByName( rName );
361cdf0e10cSrcweir aAny >>= mxStyle;
362cdf0e10cSrcweir }
363cdf0e10cSrcweir else
364cdf0e10cSrcweir {
365cdf0e10cSrcweir mxStyle = Create();
366cdf0e10cSrcweir if( !mxStyle.is() )
367cdf0e10cSrcweir return;
368cdf0e10cSrcweir
369cdf0e10cSrcweir Any aAny;
370cdf0e10cSrcweir aAny <<= mxStyle;
371cdf0e10cSrcweir xFamilies->insertByName( rName, aAny );
372cdf0e10cSrcweir bNew = sal_True;
373cdf0e10cSrcweir }
374cdf0e10cSrcweir
375cdf0e10cSrcweir Reference < XPropertySet > xPropSet( mxStyle, UNO_QUERY );
376cdf0e10cSrcweir Reference< XPropertySetInfo > xPropSetInfo =
377cdf0e10cSrcweir xPropSet->getPropertySetInfo();
378cdf0e10cSrcweir if( !bNew && xPropSetInfo->hasPropertyByName( msIsPhysical ) )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir Any aAny = xPropSet->getPropertyValue( msIsPhysical );
381cdf0e10cSrcweir bNew = !*(sal_Bool *)aAny.getValue();
382cdf0e10cSrcweir }
383cdf0e10cSrcweir SetNew( bNew );
384cdf0e10cSrcweir if( rName != GetName() )
385cdf0e10cSrcweir GetImport().AddStyleDisplayName( GetFamily(), GetName(), rName );
386cdf0e10cSrcweir
387cdf0e10cSrcweir if( bOverwrite || bNew )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY );
390cdf0e10cSrcweir
391cdf0e10cSrcweir UniReference < XMLPropertySetMapper > xPrMap;
392cdf0e10cSrcweir if( xImpPrMap.is() )
393cdf0e10cSrcweir xPrMap = xImpPrMap->getPropertySetMapper();
394cdf0e10cSrcweir if( xPrMap.is() )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir Reference < XMultiPropertyStates > xMultiStates( xPropSet,
397cdf0e10cSrcweir UNO_QUERY );
398cdf0e10cSrcweir if( xMultiStates.is() )
399cdf0e10cSrcweir {
400cdf0e10cSrcweir xMultiStates->setAllPropertiesToDefault();
401cdf0e10cSrcweir }
402cdf0e10cSrcweir else
403cdf0e10cSrcweir {
404cdf0e10cSrcweir PropertyNameSet aNameSet;
405cdf0e10cSrcweir sal_Int32 nCount = xPrMap->GetEntryCount();
406cdf0e10cSrcweir sal_Int32 i;
407cdf0e10cSrcweir for( i = 0; i < nCount; i++ )
408cdf0e10cSrcweir {
409cdf0e10cSrcweir const OUString& rPrName = xPrMap->GetEntryAPIName( i );
410cdf0e10cSrcweir if( xPropSetInfo->hasPropertyByName( rPrName ) )
411cdf0e10cSrcweir aNameSet.insert( rPrName );
412cdf0e10cSrcweir }
413cdf0e10cSrcweir
414cdf0e10cSrcweir nCount = aNameSet.size();
415cdf0e10cSrcweir Sequence < OUString > aNames( nCount );
416cdf0e10cSrcweir OUString *pNames = aNames.getArray();
417cdf0e10cSrcweir PropertyNameSet::iterator aIter = aNameSet.begin();
418cdf0e10cSrcweir while( aIter != aNameSet.end() )
419cdf0e10cSrcweir *pNames++ = *aIter++;
420cdf0e10cSrcweir
421cdf0e10cSrcweir Sequence < PropertyState > aStates(
422cdf0e10cSrcweir xPropState->getPropertyStates( aNames ) );
423cdf0e10cSrcweir const PropertyState *pStates = aStates.getConstArray();
424cdf0e10cSrcweir pNames = aNames.getArray();
425cdf0e10cSrcweir
426cdf0e10cSrcweir for( i = 0; i < nCount; i++ )
427cdf0e10cSrcweir {
428cdf0e10cSrcweir if( PropertyState_DIRECT_VALUE == *pStates++ )
429cdf0e10cSrcweir xPropState->setPropertyToDefault( pNames[i] );
430cdf0e10cSrcweir }
431cdf0e10cSrcweir }
432cdf0e10cSrcweir }
433cdf0e10cSrcweir
434cdf0e10cSrcweir if (mxStyle.is())
435cdf0e10cSrcweir mxStyle->setParentStyle(OUString());
436cdf0e10cSrcweir
437cdf0e10cSrcweir FillPropertySet( xPropSet );
438cdf0e10cSrcweir }
439cdf0e10cSrcweir else
440cdf0e10cSrcweir {
441cdf0e10cSrcweir SetValid( sal_False );
442cdf0e10cSrcweir }
443cdf0e10cSrcweir }
444cdf0e10cSrcweir }
445cdf0e10cSrcweir
Finish(sal_Bool bOverwrite)446cdf0e10cSrcweir void XMLPropStyleContext::Finish( sal_Bool bOverwrite )
447cdf0e10cSrcweir {
448cdf0e10cSrcweir if( mxStyle.is() && (IsNew() || bOverwrite) )
449cdf0e10cSrcweir {
450dcaf07f7SJohn Bampton // The families container must exist
451cdf0e10cSrcweir Reference < XNameContainer > xFamilies =
452cdf0e10cSrcweir ((SvXMLStylesContext *)&mxStyles)->GetStylesContainer( GetFamily() );
453cdf0e10cSrcweir DBG_ASSERT( xFamilies.is(), "Families lost" );
454cdf0e10cSrcweir if( !xFamilies.is() )
455cdf0e10cSrcweir return;
456cdf0e10cSrcweir
457cdf0e10cSrcweir // connect parent
458cdf0e10cSrcweir OUString sParent( GetParentName() );
459cdf0e10cSrcweir if( sParent.getLength() )
460cdf0e10cSrcweir sParent = GetImport().GetStyleDisplayName( GetFamily(), sParent );
461cdf0e10cSrcweir if( sParent.getLength() && !xFamilies->hasByName( sParent ) )
462cdf0e10cSrcweir sParent = OUString();
463cdf0e10cSrcweir
464cdf0e10cSrcweir if( sParent != mxStyle->getParentStyle() )
465cdf0e10cSrcweir {
466cdf0e10cSrcweir // this may except if setting the parent style forms a
467*7ddf0362SJohn Bampton // circle in the style dependencies; especially if the parent
468cdf0e10cSrcweir // style is the same as the current style
469cdf0e10cSrcweir try
470cdf0e10cSrcweir {
471cdf0e10cSrcweir mxStyle->setParentStyle( sParent );
472cdf0e10cSrcweir }
473cdf0e10cSrcweir catch( uno::Exception e )
474cdf0e10cSrcweir {
475cdf0e10cSrcweir // according to the API definition, I would expect a
476cdf0e10cSrcweir // container::NoSuchElementException. But it throws an
477cdf0e10cSrcweir // uno::RuntimeException instead. I catch
478cdf0e10cSrcweir // uno::Exception in order to process both of them.
479cdf0e10cSrcweir
480cdf0e10cSrcweir // We can't set the parent style. For a proper
481cdf0e10cSrcweir // Error-Message, we should pass in the name of the
482cdf0e10cSrcweir // style, as well as the desired parent style.
483cdf0e10cSrcweir Sequence<OUString> aSequence(2);
484cdf0e10cSrcweir
485cdf0e10cSrcweir // getName() throws no non-Runtime exception:
486cdf0e10cSrcweir aSequence[0] = mxStyle->getName();
487cdf0e10cSrcweir aSequence[1] = sParent;
488cdf0e10cSrcweir
489cdf0e10cSrcweir GetImport().SetError(
490cdf0e10cSrcweir XMLERROR_FLAG_ERROR | XMLERROR_PARENT_STYLE_NOT_ALLOWED,
491cdf0e10cSrcweir aSequence, e.Message, NULL );
492cdf0e10cSrcweir }
493cdf0e10cSrcweir }
494cdf0e10cSrcweir
495cdf0e10cSrcweir // connect follow
496cdf0e10cSrcweir OUString sFollow( GetFollow() );
497cdf0e10cSrcweir if( sFollow.getLength() )
498cdf0e10cSrcweir sFollow = GetImport().GetStyleDisplayName( GetFamily(), sFollow );
499cdf0e10cSrcweir if( !sFollow.getLength() || !xFamilies->hasByName( sFollow ) )
500cdf0e10cSrcweir sFollow = mxStyle->getName();
501cdf0e10cSrcweir
502cdf0e10cSrcweir Reference < XPropertySet > xPropSet( mxStyle, UNO_QUERY );
503cdf0e10cSrcweir Reference< XPropertySetInfo > xPropSetInfo =
504cdf0e10cSrcweir xPropSet->getPropertySetInfo();
505cdf0e10cSrcweir if( xPropSetInfo->hasPropertyByName( msFollowStyle ) )
506cdf0e10cSrcweir {
507cdf0e10cSrcweir Any aAny = xPropSet->getPropertyValue( msFollowStyle );
508cdf0e10cSrcweir OUString sCurrFollow;
509cdf0e10cSrcweir aAny >>= sCurrFollow;
510cdf0e10cSrcweir if( sCurrFollow != sFollow )
511cdf0e10cSrcweir {
512cdf0e10cSrcweir aAny <<= sFollow;
513cdf0e10cSrcweir xPropSet->setPropertyValue( msFollowStyle, aAny );
514cdf0e10cSrcweir }
515cdf0e10cSrcweir }
516cdf0e10cSrcweir }
517cdf0e10cSrcweir }
518cdf0e10cSrcweir
519cdf0e10cSrcweir
52056b35d86SArmin Le Grand //UUUU
doNewDrawingLayerFillStyleDefinitionsExist(const OUString & rFillStyleTag) const52156b35d86SArmin Le Grand bool XMLPropStyleContext::doNewDrawingLayerFillStyleDefinitionsExist(
52256b35d86SArmin Le Grand const OUString& rFillStyleTag) const
52356b35d86SArmin Le Grand {
52456b35d86SArmin Le Grand if(maProperties.size() && rFillStyleTag.getLength())
52556b35d86SArmin Le Grand {
52656b35d86SArmin Le Grand const UniReference< XMLPropertySetMapper >& rMapper = GetStyles()->GetImportPropertyMapper(GetFamily())->getPropertySetMapper();
52756b35d86SArmin Le Grand
52856b35d86SArmin Le Grand if(rMapper.is())
52956b35d86SArmin Le Grand {
53056b35d86SArmin Le Grand for(::std::vector< XMLPropertyState >::const_iterator a = maProperties.begin(); a != maProperties.end(); a++)
53156b35d86SArmin Le Grand {
53256b35d86SArmin Le Grand if(a->mnIndex != -1)
53356b35d86SArmin Le Grand {
53456b35d86SArmin Le Grand const OUString& rPropName = rMapper->GetEntryAPIName(a->mnIndex);
53556b35d86SArmin Le Grand
53656b35d86SArmin Le Grand if(rPropName == rFillStyleTag)
53756b35d86SArmin Le Grand {
53856b35d86SArmin Le Grand FillStyle eFillStyle(FillStyle_NONE);
53956b35d86SArmin Le Grand
54056b35d86SArmin Le Grand if(a->maValue >>= eFillStyle)
54156b35d86SArmin Le Grand {
54256b35d86SArmin Le Grand // okay, type was good, FillStyle is set
54356b35d86SArmin Le Grand }
54456b35d86SArmin Le Grand else
54556b35d86SArmin Le Grand {
54656b35d86SArmin Le Grand // also try an int (see XFillStyleItem::PutValue)
54756b35d86SArmin Le Grand sal_Int32 nFillStyle(0);
54856b35d86SArmin Le Grand
54956b35d86SArmin Le Grand if(a->maValue >>= nFillStyle)
55056b35d86SArmin Le Grand {
55156b35d86SArmin Le Grand eFillStyle = static_cast< FillStyle >(nFillStyle);
55256b35d86SArmin Le Grand }
55356b35d86SArmin Le Grand }
55456b35d86SArmin Le Grand
55556b35d86SArmin Le Grand // we found the entry, check it
55656b35d86SArmin Le Grand return FillStyle_NONE != eFillStyle;
55756b35d86SArmin Le Grand }
55856b35d86SArmin Le Grand }
55956b35d86SArmin Le Grand }
56056b35d86SArmin Le Grand }
56156b35d86SArmin Le Grand }
56256b35d86SArmin Le Grand
56356b35d86SArmin Le Grand return false;
56456b35d86SArmin Le Grand }
56556b35d86SArmin Le Grand
56656b35d86SArmin Le Grand //UUUU
deactivateOldFillStyleDefinitions(const OldFillStyleDefinitionSet & rHashSetOfTags)56756b35d86SArmin Le Grand bool XMLPropStyleContext::deactivateOldFillStyleDefinitions(
56856b35d86SArmin Le Grand const OldFillStyleDefinitionSet& rHashSetOfTags)
56956b35d86SArmin Le Grand {
57056b35d86SArmin Le Grand bool bRetval(false);
57156b35d86SArmin Le Grand
57256b35d86SArmin Le Grand if(!rHashSetOfTags.empty() && maProperties.size())
57356b35d86SArmin Le Grand {
57456b35d86SArmin Le Grand const UniReference< XMLPropertySetMapper >& rMapper = GetStyles()->GetImportPropertyMapper(GetFamily())->getPropertySetMapper();
57556b35d86SArmin Le Grand
57656b35d86SArmin Le Grand if(rMapper.is())
57756b35d86SArmin Le Grand {
57856b35d86SArmin Le Grand for(::std::vector< XMLPropertyState >::iterator a = maProperties.begin(); a != maProperties.end(); a++)
57956b35d86SArmin Le Grand {
58056b35d86SArmin Le Grand if(a->mnIndex != -1)
58156b35d86SArmin Le Grand {
58256b35d86SArmin Le Grand const OUString& rPropName = rMapper->GetEntryAPIName(a->mnIndex);
58356b35d86SArmin Le Grand
58456b35d86SArmin Le Grand if(rHashSetOfTags.find(rPropName) != rHashSetOfTags.end())
58556b35d86SArmin Le Grand {
58656b35d86SArmin Le Grand // mark entry as inactive
58756b35d86SArmin Le Grand a->mnIndex = -1;
58856b35d86SArmin Le Grand bRetval = true;
58956b35d86SArmin Le Grand }
59056b35d86SArmin Le Grand }
59156b35d86SArmin Le Grand }
59256b35d86SArmin Le Grand }
59356b35d86SArmin Le Grand }
59456b35d86SArmin Le Grand
59556b35d86SArmin Le Grand return bRetval;
59656b35d86SArmin Le Grand }
59756b35d86SArmin Le Grand
59856b35d86SArmin Le Grand //UUUU
translateNameBasedDrawingLayerFillStyleDefinitionsToStyleDisplayNames()59956b35d86SArmin Le Grand bool XMLPropStyleContext::translateNameBasedDrawingLayerFillStyleDefinitionsToStyleDisplayNames()
60056b35d86SArmin Le Grand {
60156b35d86SArmin Le Grand bool bRetval(false);
60256b35d86SArmin Le Grand
60356b35d86SArmin Le Grand if(maProperties.size())
60456b35d86SArmin Le Grand {
60556b35d86SArmin Le Grand const UniReference< XMLPropertySetMapper >& rMapper = GetStyles()->GetImportPropertyMapper(GetFamily())->getPropertySetMapper();
60656b35d86SArmin Le Grand
60756b35d86SArmin Le Grand if(rMapper.is())
60856b35d86SArmin Le Grand {
60956b35d86SArmin Le Grand static OUString s_FillGradientName(RTL_CONSTASCII_USTRINGPARAM("FillGradientName"));
61056b35d86SArmin Le Grand static OUString s_FillHatchName(RTL_CONSTASCII_USTRINGPARAM("FillHatchName"));
61156b35d86SArmin Le Grand static OUString s_FillBitmapName(RTL_CONSTASCII_USTRINGPARAM("FillBitmapName"));
61256b35d86SArmin Le Grand static OUString s_FillTransparenceGradientName(RTL_CONSTASCII_USTRINGPARAM("FillTransparenceGradientName"));
61356b35d86SArmin Le Grand
61456b35d86SArmin Le Grand for(::std::vector< XMLPropertyState >::iterator a = maProperties.begin(); a != maProperties.end(); a++)
61556b35d86SArmin Le Grand {
61656b35d86SArmin Le Grand if(a->mnIndex != -1)
61756b35d86SArmin Le Grand {
61856b35d86SArmin Le Grand const OUString& rPropName = rMapper->GetEntryAPIName(a->mnIndex);
61956b35d86SArmin Le Grand sal_uInt16 aStyleFamily(0);
62056b35d86SArmin Le Grand
62156b35d86SArmin Le Grand if(rPropName == s_FillGradientName || rPropName == s_FillTransparenceGradientName)
62256b35d86SArmin Le Grand {
62356b35d86SArmin Le Grand aStyleFamily = XML_STYLE_FAMILY_SD_GRADIENT_ID;
62456b35d86SArmin Le Grand }
62556b35d86SArmin Le Grand else if(rPropName == s_FillHatchName)
62656b35d86SArmin Le Grand {
62756b35d86SArmin Le Grand aStyleFamily = XML_STYLE_FAMILY_SD_HATCH_ID;
62856b35d86SArmin Le Grand }
62956b35d86SArmin Le Grand else if(rPropName == s_FillBitmapName)
63056b35d86SArmin Le Grand {
63156b35d86SArmin Le Grand aStyleFamily = XML_STYLE_FAMILY_SD_FILL_IMAGE_ID;
63256b35d86SArmin Le Grand }
63356b35d86SArmin Le Grand
63456b35d86SArmin Le Grand if(aStyleFamily)
63556b35d86SArmin Le Grand {
63656b35d86SArmin Le Grand OUString sStyleName;
63756b35d86SArmin Le Grand
63856b35d86SArmin Le Grand a->maValue >>= sStyleName;
63956b35d86SArmin Le Grand sStyleName = GetImport().GetStyleDisplayName( aStyleFamily, sStyleName );
64056b35d86SArmin Le Grand a->maValue <<= sStyleName;
64156b35d86SArmin Le Grand bRetval = true;
64256b35d86SArmin Le Grand }
64356b35d86SArmin Le Grand }
64456b35d86SArmin Le Grand }
64556b35d86SArmin Le Grand }
64656b35d86SArmin Le Grand }
64756b35d86SArmin Le Grand
64856b35d86SArmin Le Grand return bRetval;
64956b35d86SArmin Le Grand }
65056b35d86SArmin Le Grand
65156b35d86SArmin Le Grand //eof
652