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
1063bba73cSAndrew Rist *
1163bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1263bba73cSAndrew Rist *
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.
1963bba73cSAndrew Rist *
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
44*56b35d86SArmin Le Grand //UUUU
45*56b35d86SArmin Le Grand #include <com/sun/star/drawing/FillStyle.hpp>
46*56b35d86SArmin 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
59*56b35d86SArmin Le Grand //UUUU
60*56b35d86SArmin 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
78*56b35d86SArmin Le Grand
79*56b35d86SArmin Le Grand //UUUU
80*56b35d86SArmin Le Grand OldFillStyleDefinitionSet XMLPropStyleContext::maStandardSet;
81*56b35d86SArmin Le Grand OldFillStyleDefinitionSet XMLPropStyleContext::maHeaderSet;
82*56b35d86SArmin Le Grand OldFillStyleDefinitionSet XMLPropStyleContext::maFooterSet;
83*56b35d86SArmin Le Grand OldFillStyleDefinitionSet XMLPropStyleContext::maParaSet;
84*56b35d86SArmin Le Grand
XMLPropStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<XAttributeList> & xAttrList,SvXMLStylesContext & rStyles,sal_uInt16 nFamily,sal_Bool bDefault)85*56b35d86SArmin Le Grand XMLPropStyleContext::XMLPropStyleContext(
86*56b35d86SArmin Le Grand SvXMLImport& rImport,
87*56b35d86SArmin Le Grand sal_uInt16 nPrfx,
88*56b35d86SArmin Le Grand const OUString& rLName,
89*56b35d86SArmin Le Grand const Reference< XAttributeList > & xAttrList,
90*56b35d86SArmin Le Grand SvXMLStylesContext& rStyles,
91*56b35d86SArmin Le Grand sal_uInt16 nFamily,
92*56b35d86SArmin Le Grand sal_Bool bDefault)
93*56b35d86SArmin Le Grand : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList, nFamily, bDefault),
94*56b35d86SArmin Le Grand msIsPhysical(RTL_CONSTASCII_USTRINGPARAM("IsPhysical")),
95*56b35d86SArmin Le Grand msFollowStyle(RTL_CONSTASCII_USTRINGPARAM("FollowStyle")),
96*56b35d86SArmin Le Grand mxStyles(&rStyles)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
~XMLPropStyleContext()100cdf0e10cSrcweir XMLPropStyleContext::~XMLPropStyleContext()
101cdf0e10cSrcweir {
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
getStandardSet()104*56b35d86SArmin Le Grand const OldFillStyleDefinitionSet& XMLPropStyleContext::getStandardSet()
105*56b35d86SArmin Le Grand {
106*56b35d86SArmin Le Grand if(maStandardSet.empty())
107*56b35d86SArmin Le Grand {
108*56b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackColorRGB")));
109*56b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackTransparent")));
110*56b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackColorTransparency")));
111*56b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackGraphicURL")));
112*56b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackGraphicFilter")));
113*56b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackGraphicLocation")));
114*56b35d86SArmin Le Grand maStandardSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BackGraphicTransparency")));
115*56b35d86SArmin Le Grand }
116*56b35d86SArmin Le Grand
117*56b35d86SArmin Le Grand return maStandardSet;
118*56b35d86SArmin Le Grand }
119*56b35d86SArmin Le Grand
getHeaderSet()120*56b35d86SArmin Le Grand const OldFillStyleDefinitionSet& XMLPropStyleContext::getHeaderSet()
121*56b35d86SArmin Le Grand {
122*56b35d86SArmin Le Grand if(maHeaderSet.empty())
123*56b35d86SArmin Le Grand {
124*56b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackColorRGB")));
125*56b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackTransparent")));
126*56b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackColorTransparency")));
127*56b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackGraphicURL")));
128*56b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackGraphicFilter")));
129*56b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackGraphicLocation")));
130*56b35d86SArmin Le Grand maHeaderSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderBackGraphicTransparency")));
131*56b35d86SArmin Le Grand }
132*56b35d86SArmin Le Grand
133*56b35d86SArmin Le Grand return maHeaderSet;
134*56b35d86SArmin Le Grand }
135*56b35d86SArmin Le Grand
getFooterSet()136*56b35d86SArmin Le Grand const OldFillStyleDefinitionSet& XMLPropStyleContext::getFooterSet()
137*56b35d86SArmin Le Grand {
138*56b35d86SArmin Le Grand if(maFooterSet.empty())
139*56b35d86SArmin Le Grand {
140*56b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackColorRGB")));
141*56b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackTransparent")));
142*56b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackColorTransparency")));
143*56b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackGraphicURL")));
144*56b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackGraphicFilter")));
145*56b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackGraphicLocation")));
146*56b35d86SArmin Le Grand maFooterSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FooterBackGraphicTransparency")));
147*56b35d86SArmin Le Grand }
148*56b35d86SArmin Le Grand
149*56b35d86SArmin Le Grand return maFooterSet;
150*56b35d86SArmin Le Grand }
151*56b35d86SArmin Le Grand
getParaSet()152*56b35d86SArmin Le Grand const OldFillStyleDefinitionSet& XMLPropStyleContext::getParaSet()
153*56b35d86SArmin Le Grand {
154*56b35d86SArmin Le Grand if(maParaSet.empty())
155*56b35d86SArmin Le Grand {
156*56b35d86SArmin Le Grand // Caution: here it is *not* 'ParaBackColorRGB' as it should be, but indeed
157*56b35d86SArmin Le Grand // 'ParaBackColor' is used, see aXMLParaPropMap definition (line 313)
158*56b35d86SArmin Le Grand maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackColor")));
159*56b35d86SArmin Le Grand maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackTransparent")));
160*56b35d86SArmin Le Grand maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackGraphicLocation")));
161*56b35d86SArmin Le Grand maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackGraphicFilter")));
162*56b35d86SArmin Le Grand maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackGraphicURL")));
163*56b35d86SArmin Le Grand
164*56b35d86SArmin Le Grand // These are not used in aXMLParaPropMap definition, thus not needed here
165*56b35d86SArmin Le Grand // maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackColorTransparency")));
166*56b35d86SArmin Le Grand // maParaSet.insert(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackGraphicTransparency")));
167*56b35d86SArmin Le Grand }
168*56b35d86SArmin Le Grand
169*56b35d86SArmin Le Grand return maParaSet;
170*56b35d86SArmin Le Grand }
171*56b35d86SArmin 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 {
266*56b35d86SArmin Le Grand SvXMLStylesContext* pSvXMLStylesContext = static_cast< SvXMLStylesContext* >(&mxStyles);
267*56b35d86SArmin Le Grand UniReference < SvXMLImportPropertyMapper > xImpPrMap = pSvXMLStylesContext->GetImportPropertyMapper(GetFamily());
268*56b35d86SArmin Le Grand OSL_ENSURE(xImpPrMap.is(), "There is no import prop mapper");
269*56b35d86SArmin Le Grand
270*56b35d86SArmin Le Grand //UUUU need to filter out old fill definitions when the new ones are used. The new
271*56b35d86SArmin Le Grand // ones are used when a FillStyle is defined
272*56b35d86SArmin Le Grand const bool bTakeCareOfDrawingLayerFillStyle(xImpPrMap.is() && GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH);
273*56b35d86SArmin Le Grand bool bDrawingLayerFillStylesUsed(false);
274*56b35d86SArmin Le Grand
275*56b35d86SArmin Le Grand if(bTakeCareOfDrawingLayerFillStyle)
276*56b35d86SArmin Le Grand {
277*56b35d86SArmin Le Grand // check if new FillStyles are used and if so mark old ones with -1
278*56b35d86SArmin Le Grand static ::rtl::OUString s_FillStyle(RTL_CONSTASCII_USTRINGPARAM("FillStyle"));
279*56b35d86SArmin Le Grand
280*56b35d86SArmin Le Grand if(doNewDrawingLayerFillStyleDefinitionsExist(s_FillStyle))
281*56b35d86SArmin Le Grand {
282*56b35d86SArmin Le Grand deactivateOldFillStyleDefinitions(getParaSet());
283*56b35d86SArmin Le Grand bDrawingLayerFillStylesUsed = true;
284*56b35d86SArmin Le Grand }
285*56b35d86SArmin Le Grand }
286*56b35d86SArmin Le Grand
287*56b35d86SArmin Le Grand if( pSvXMLStylesContext->IsAutomaticStyle()
288cdf0e10cSrcweir && ( GetFamily() == XML_STYLE_FAMILY_TEXT_TEXT || GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ) )
289cdf0e10cSrcweir {
290*56b35d86SArmin Le Grand //UUUU Need to translate StyleName from temp MapNames to names
291*56b35d86SArmin Le Grand // used in already imported items (already exist in the pool). This
292*56b35d86SArmin Le Grand // is required for AutomaticStyles since these do *not* use FillPropertySet
293*56b35d86SArmin Le Grand // and thus just trigger CheckSpecialContext in XMLTextStyleContext::FillPropertySet
294*56b35d86SArmin Le Grand // (which may be double action anyways). The mechanism there to use _ContextID_Index_Pair
295*56b35d86SArmin Le Grand // is not working for AutomaticStyles and is already too late, too (this
296*56b35d86SArmin Le Grand // method is already called before XMLTextStyleContext::FillPropertySet gets called)
297*56b35d86SArmin Le Grand if(bDrawingLayerFillStylesUsed)
298*56b35d86SArmin Le Grand {
299*56b35d86SArmin Le Grand translateNameBasedDrawingLayerFillStyleDefinitionsToStyleDisplayNames();
300*56b35d86SArmin Le Grand }
301*56b35d86SArmin Le Grand
302*56b35d86SArmin 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 );
309*56b35d86SArmin Le Grand
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
353*56b35d86SArmin 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 {
450cdf0e10cSrcweir // The families cintaner 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
467cdf0e10cSrcweir // circle in the style depencies; 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
520*56b35d86SArmin Le Grand //UUUU
doNewDrawingLayerFillStyleDefinitionsExist(const OUString & rFillStyleTag) const521*56b35d86SArmin Le Grand bool XMLPropStyleContext::doNewDrawingLayerFillStyleDefinitionsExist(
522*56b35d86SArmin Le Grand const OUString& rFillStyleTag) const
523*56b35d86SArmin Le Grand {
524*56b35d86SArmin Le Grand if(maProperties.size() && rFillStyleTag.getLength())
525*56b35d86SArmin Le Grand {
526*56b35d86SArmin Le Grand const UniReference< XMLPropertySetMapper >& rMapper = GetStyles()->GetImportPropertyMapper(GetFamily())->getPropertySetMapper();
527*56b35d86SArmin Le Grand
528*56b35d86SArmin Le Grand if(rMapper.is())
529*56b35d86SArmin Le Grand {
530*56b35d86SArmin Le Grand for(::std::vector< XMLPropertyState >::const_iterator a = maProperties.begin(); a != maProperties.end(); a++)
531*56b35d86SArmin Le Grand {
532*56b35d86SArmin Le Grand if(a->mnIndex != -1)
533*56b35d86SArmin Le Grand {
534*56b35d86SArmin Le Grand const OUString& rPropName = rMapper->GetEntryAPIName(a->mnIndex);
535*56b35d86SArmin Le Grand
536*56b35d86SArmin Le Grand if(rPropName == rFillStyleTag)
537*56b35d86SArmin Le Grand {
538*56b35d86SArmin Le Grand FillStyle eFillStyle(FillStyle_NONE);
539*56b35d86SArmin Le Grand
540*56b35d86SArmin Le Grand if(a->maValue >>= eFillStyle)
541*56b35d86SArmin Le Grand {
542*56b35d86SArmin Le Grand // okay, type was good, FillStyle is set
543*56b35d86SArmin Le Grand }
544*56b35d86SArmin Le Grand else
545*56b35d86SArmin Le Grand {
546*56b35d86SArmin Le Grand // also try an int (see XFillStyleItem::PutValue)
547*56b35d86SArmin Le Grand sal_Int32 nFillStyle(0);
548*56b35d86SArmin Le Grand
549*56b35d86SArmin Le Grand if(a->maValue >>= nFillStyle)
550*56b35d86SArmin Le Grand {
551*56b35d86SArmin Le Grand eFillStyle = static_cast< FillStyle >(nFillStyle);
552*56b35d86SArmin Le Grand }
553*56b35d86SArmin Le Grand }
554*56b35d86SArmin Le Grand
555*56b35d86SArmin Le Grand // we found the entry, check it
556*56b35d86SArmin Le Grand return FillStyle_NONE != eFillStyle;
557*56b35d86SArmin Le Grand }
558*56b35d86SArmin Le Grand }
559*56b35d86SArmin Le Grand }
560*56b35d86SArmin Le Grand }
561*56b35d86SArmin Le Grand }
562*56b35d86SArmin Le Grand
563*56b35d86SArmin Le Grand return false;
564*56b35d86SArmin Le Grand }
565*56b35d86SArmin Le Grand
566*56b35d86SArmin Le Grand //UUUU
deactivateOldFillStyleDefinitions(const OldFillStyleDefinitionSet & rHashSetOfTags)567*56b35d86SArmin Le Grand bool XMLPropStyleContext::deactivateOldFillStyleDefinitions(
568*56b35d86SArmin Le Grand const OldFillStyleDefinitionSet& rHashSetOfTags)
569*56b35d86SArmin Le Grand {
570*56b35d86SArmin Le Grand bool bRetval(false);
571*56b35d86SArmin Le Grand
572*56b35d86SArmin Le Grand if(!rHashSetOfTags.empty() && maProperties.size())
573*56b35d86SArmin Le Grand {
574*56b35d86SArmin Le Grand const UniReference< XMLPropertySetMapper >& rMapper = GetStyles()->GetImportPropertyMapper(GetFamily())->getPropertySetMapper();
575*56b35d86SArmin Le Grand
576*56b35d86SArmin Le Grand if(rMapper.is())
577*56b35d86SArmin Le Grand {
578*56b35d86SArmin Le Grand for(::std::vector< XMLPropertyState >::iterator a = maProperties.begin(); a != maProperties.end(); a++)
579*56b35d86SArmin Le Grand {
580*56b35d86SArmin Le Grand if(a->mnIndex != -1)
581*56b35d86SArmin Le Grand {
582*56b35d86SArmin Le Grand const OUString& rPropName = rMapper->GetEntryAPIName(a->mnIndex);
583*56b35d86SArmin Le Grand
584*56b35d86SArmin Le Grand if(rHashSetOfTags.find(rPropName) != rHashSetOfTags.end())
585*56b35d86SArmin Le Grand {
586*56b35d86SArmin Le Grand // mark entry as inactive
587*56b35d86SArmin Le Grand a->mnIndex = -1;
588*56b35d86SArmin Le Grand bRetval = true;
589*56b35d86SArmin Le Grand }
590*56b35d86SArmin Le Grand }
591*56b35d86SArmin Le Grand }
592*56b35d86SArmin Le Grand }
593*56b35d86SArmin Le Grand }
594*56b35d86SArmin Le Grand
595*56b35d86SArmin Le Grand return bRetval;
596*56b35d86SArmin Le Grand }
597*56b35d86SArmin Le Grand
598*56b35d86SArmin Le Grand //UUUU
translateNameBasedDrawingLayerFillStyleDefinitionsToStyleDisplayNames()599*56b35d86SArmin Le Grand bool XMLPropStyleContext::translateNameBasedDrawingLayerFillStyleDefinitionsToStyleDisplayNames()
600*56b35d86SArmin Le Grand {
601*56b35d86SArmin Le Grand bool bRetval(false);
602*56b35d86SArmin Le Grand
603*56b35d86SArmin Le Grand if(maProperties.size())
604*56b35d86SArmin Le Grand {
605*56b35d86SArmin Le Grand const UniReference< XMLPropertySetMapper >& rMapper = GetStyles()->GetImportPropertyMapper(GetFamily())->getPropertySetMapper();
606*56b35d86SArmin Le Grand
607*56b35d86SArmin Le Grand if(rMapper.is())
608*56b35d86SArmin Le Grand {
609*56b35d86SArmin Le Grand static OUString s_FillGradientName(RTL_CONSTASCII_USTRINGPARAM("FillGradientName"));
610*56b35d86SArmin Le Grand static OUString s_FillHatchName(RTL_CONSTASCII_USTRINGPARAM("FillHatchName"));
611*56b35d86SArmin Le Grand static OUString s_FillBitmapName(RTL_CONSTASCII_USTRINGPARAM("FillBitmapName"));
612*56b35d86SArmin Le Grand static OUString s_FillTransparenceGradientName(RTL_CONSTASCII_USTRINGPARAM("FillTransparenceGradientName"));
613*56b35d86SArmin Le Grand
614*56b35d86SArmin Le Grand for(::std::vector< XMLPropertyState >::iterator a = maProperties.begin(); a != maProperties.end(); a++)
615*56b35d86SArmin Le Grand {
616*56b35d86SArmin Le Grand if(a->mnIndex != -1)
617*56b35d86SArmin Le Grand {
618*56b35d86SArmin Le Grand const OUString& rPropName = rMapper->GetEntryAPIName(a->mnIndex);
619*56b35d86SArmin Le Grand sal_uInt16 aStyleFamily(0);
620*56b35d86SArmin Le Grand
621*56b35d86SArmin Le Grand if(rPropName == s_FillGradientName || rPropName == s_FillTransparenceGradientName)
622*56b35d86SArmin Le Grand {
623*56b35d86SArmin Le Grand aStyleFamily = XML_STYLE_FAMILY_SD_GRADIENT_ID;
624*56b35d86SArmin Le Grand }
625*56b35d86SArmin Le Grand else if(rPropName == s_FillHatchName)
626*56b35d86SArmin Le Grand {
627*56b35d86SArmin Le Grand aStyleFamily = XML_STYLE_FAMILY_SD_HATCH_ID;
628*56b35d86SArmin Le Grand }
629*56b35d86SArmin Le Grand else if(rPropName == s_FillBitmapName)
630*56b35d86SArmin Le Grand {
631*56b35d86SArmin Le Grand aStyleFamily = XML_STYLE_FAMILY_SD_FILL_IMAGE_ID;
632*56b35d86SArmin Le Grand }
633*56b35d86SArmin Le Grand
634*56b35d86SArmin Le Grand if(aStyleFamily)
635*56b35d86SArmin Le Grand {
636*56b35d86SArmin Le Grand OUString sStyleName;
637*56b35d86SArmin Le Grand
638*56b35d86SArmin Le Grand a->maValue >>= sStyleName;
639*56b35d86SArmin Le Grand sStyleName = GetImport().GetStyleDisplayName( aStyleFamily, sStyleName );
640*56b35d86SArmin Le Grand a->maValue <<= sStyleName;
641*56b35d86SArmin Le Grand bRetval = true;
642*56b35d86SArmin Le Grand }
643*56b35d86SArmin Le Grand }
644*56b35d86SArmin Le Grand }
645*56b35d86SArmin Le Grand }
646*56b35d86SArmin Le Grand }
647*56b35d86SArmin Le Grand
648*56b35d86SArmin Le Grand return bRetval;
649*56b35d86SArmin Le Grand }
650*56b35d86SArmin Le Grand
651*56b35d86SArmin Le Grand //eof
652