/src/libreoffice/xmloff/source/style/prstylei.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include <sal/config.h> |
21 | | |
22 | | #include <o3tl/any.hxx> |
23 | | #include <osl/diagnose.h> |
24 | | #include <sal/log.hxx> |
25 | | #include <set> |
26 | | #include <xmloff/xmlnamespace.hxx> |
27 | | #include <xmloff/xmltoken.hxx> |
28 | | #include <com/sun/star/frame/XModel.hpp> |
29 | | #include <com/sun/star/style/XStyle.hpp> |
30 | | #include <com/sun/star/style/XAutoStyleFamily.hpp> |
31 | | #include <com/sun/star/container/XNameContainer.hpp> |
32 | | #include <com/sun/star/beans/XPropertySet.hpp> |
33 | | #include <com/sun/star/beans/XPropertyState.hpp> |
34 | | #include <com/sun/star/beans/XMultiPropertyStates.hpp> |
35 | | #include <com/sun/star/lang/XMultiServiceFactory.hpp> |
36 | | #include <xmloff/xmlimp.hxx> |
37 | | #include <xmloff/prstylei.hxx> |
38 | | #include <xmloff/xmlerror.hxx> |
39 | | #include <xmloff/xmltypes.hxx> |
40 | | #include <xmloff/maptype.hxx> |
41 | | #include <xmloff/xmlimppr.hxx> |
42 | | #include <xmloff/xmlprmap.hxx> |
43 | | #include <comphelper/sequence.hxx> |
44 | | #include <com/sun/star/drawing/FillStyle.hpp> |
45 | | #include "StylePropertiesContext.hxx" |
46 | | |
47 | | using namespace ::com::sun::star; |
48 | | using namespace ::com::sun::star::uno; |
49 | | using namespace ::com::sun::star::xml::sax; |
50 | | using namespace ::com::sun::star::style; |
51 | | using namespace ::com::sun::star::container; |
52 | | using namespace ::com::sun::star::beans; |
53 | | using namespace ::com::sun::star::lang; |
54 | | using namespace ::xmloff::token; |
55 | | using namespace com::sun::star::drawing; |
56 | | |
57 | | void XMLPropStyleContext::SetAttribute( sal_Int32 nElement, |
58 | | const OUString& rValue ) |
59 | 343k | { |
60 | 343k | if( nElement == XML_ELEMENT(STYLE, XML_FAMILY) ) |
61 | 126k | { |
62 | 126k | SAL_WARN_IF( GetFamily() != SvXMLStylesContext::GetFamily( rValue ), "xmloff", "unexpected style family" ); |
63 | 126k | } |
64 | 217k | else |
65 | 217k | { |
66 | 217k | SvXMLStyleContext::SetAttribute( nElement, rValue ); |
67 | 217k | } |
68 | 343k | } |
69 | | |
70 | | |
71 | | namespace |
72 | | { |
73 | | const OldFillStyleDefinitionSet & theStandardSet() |
74 | 0 | { |
75 | 0 | static const OldFillStyleDefinitionSet theSet = []() |
76 | 0 | { |
77 | 0 | OldFillStyleDefinitionSet aSet; |
78 | 0 | aSet.insert(u"BackColorRGB"_ustr); |
79 | 0 | aSet.insert(u"BackTransparent"_ustr); |
80 | 0 | aSet.insert(u"BackColorTransparency"_ustr); |
81 | 0 | aSet.insert(u"BackGraphic"_ustr); |
82 | 0 | aSet.insert(u"BackGraphicFilter"_ustr); |
83 | 0 | aSet.insert(u"BackGraphicLocation"_ustr); |
84 | 0 | aSet.insert(u"BackGraphicTransparency"_ustr); |
85 | 0 | return aSet; |
86 | 0 | }(); |
87 | 0 | return theSet; |
88 | 0 | }; |
89 | | const OldFillStyleDefinitionSet & theHeaderSet() |
90 | 0 | { |
91 | 0 | static const OldFillStyleDefinitionSet theSet = []() |
92 | 0 | { |
93 | 0 | OldFillStyleDefinitionSet aSet; |
94 | 0 | aSet.insert(u"HeaderBackColorRGB"_ustr); |
95 | 0 | aSet.insert(u"HeaderBackTransparent"_ustr); |
96 | 0 | aSet.insert(u"HeaderBackColorTransparency"_ustr); |
97 | 0 | aSet.insert(u"HeaderBackGraphic"_ustr); |
98 | 0 | aSet.insert(u"HeaderBackGraphicFilter"_ustr); |
99 | 0 | aSet.insert(u"HeaderBackGraphicLocation"_ustr); |
100 | 0 | aSet.insert(u"HeaderBackGraphicTransparency"_ustr); |
101 | 0 | return aSet; |
102 | 0 | }(); |
103 | 0 | return theSet; |
104 | 0 | }; |
105 | | const OldFillStyleDefinitionSet & theFooterSet() |
106 | 0 | { |
107 | 0 | static const OldFillStyleDefinitionSet theSet = []() |
108 | 0 | { |
109 | 0 | OldFillStyleDefinitionSet aSet; |
110 | 0 | aSet.insert(u"FooterBackColorRGB"_ustr); |
111 | 0 | aSet.insert(u"FooterBackTransparent"_ustr); |
112 | 0 | aSet.insert(u"FooterBackColorTransparency"_ustr); |
113 | 0 | aSet.insert(u"FooterBackGraphic"_ustr); |
114 | 0 | aSet.insert(u"FooterBackGraphicFilter"_ustr); |
115 | 0 | aSet.insert(u"FooterBackGraphicLocation"_ustr); |
116 | 0 | aSet.insert(u"FooterBackGraphicTransparency"_ustr); |
117 | 0 | return aSet; |
118 | 0 | }(); |
119 | 0 | return theSet; |
120 | 0 | }; |
121 | | const OldFillStyleDefinitionSet & theParaSet() |
122 | 116 | { |
123 | 116 | static const OldFillStyleDefinitionSet theSet = []() |
124 | 116 | { |
125 | 2 | OldFillStyleDefinitionSet aSet; |
126 | | // Caution: here it is *not* 'ParaBackColorRGB' as it should be, but indeed |
127 | | // 'ParaBackColor' is used, see aXMLParaPropMap definition (line 313) |
128 | 2 | aSet.insert(u"ParaBackColor"_ustr); |
129 | 2 | aSet.insert(u"ParaBackTransparent"_ustr); |
130 | 2 | aSet.insert(u"ParaBackGraphicLocation"_ustr); |
131 | 2 | aSet.insert(u"ParaBackGraphicFilter"_ustr); |
132 | 2 | aSet.insert(u"ParaBackGraphic"_ustr); |
133 | | |
134 | | // These are not used in aXMLParaPropMap definition, thus not needed here |
135 | | // aSet.insert("ParaBackColorTransparency"); |
136 | | // aSet.insert("ParaBackGraphicTransparency"); |
137 | 2 | return aSet; |
138 | 2 | }(); |
139 | 116 | return theSet; |
140 | 116 | }; |
141 | | } |
142 | | |
143 | | |
144 | | |
145 | | constexpr OUString gsIsPhysical( u"IsPhysical"_ustr ); |
146 | | constexpr OUString gsFollowStyle( u"FollowStyle"_ustr ); |
147 | | |
148 | | XMLPropStyleContext::XMLPropStyleContext( SvXMLImport& rImport, |
149 | | SvXMLStylesContext& rStyles, XmlStyleFamily nFamily, |
150 | | bool bDefault ) |
151 | 132k | : SvXMLStyleContext( rImport, nFamily, bDefault ) |
152 | 132k | , mxStyles( &rStyles ) |
153 | 132k | { |
154 | 132k | } |
155 | | |
156 | | XMLPropStyleContext::~XMLPropStyleContext() |
157 | 132k | { |
158 | 132k | } |
159 | | |
160 | | const OldFillStyleDefinitionSet& XMLPropStyleContext::getStandardSet() |
161 | 0 | { |
162 | 0 | return theStandardSet(); |
163 | 0 | } |
164 | | |
165 | | const OldFillStyleDefinitionSet& XMLPropStyleContext::getHeaderSet() |
166 | 0 | { |
167 | 0 | return theHeaderSet(); |
168 | 0 | } |
169 | | |
170 | | const OldFillStyleDefinitionSet& XMLPropStyleContext::getFooterSet() |
171 | 0 | { |
172 | 0 | return theFooterSet(); |
173 | 0 | } |
174 | | |
175 | | css::uno::Reference< css::xml::sax::XFastContextHandler > XMLPropStyleContext::createFastChildContext( |
176 | | sal_Int32 nElement, |
177 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
178 | 52.2k | { |
179 | 52.2k | sal_uInt32 nFamily = 0; |
180 | 52.2k | if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) || |
181 | 2.14k | IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT) ) |
182 | 50.3k | { |
183 | 50.3k | sal_Int32 nLocalName = nElement & TOKEN_MASK; |
184 | 50.3k | if( nLocalName == XML_GRAPHIC_PROPERTIES ) |
185 | 307 | nFamily = XML_TYPE_PROP_GRAPHIC; |
186 | 50.0k | else if( nLocalName == XML_DRAWING_PAGE_PROPERTIES ) |
187 | 309 | nFamily = XML_TYPE_PROP_DRAWING_PAGE; |
188 | 49.7k | else if( nLocalName == XML_TEXT_PROPERTIES ) |
189 | 26.7k | nFamily = XML_TYPE_PROP_TEXT; |
190 | 23.0k | else if( nLocalName == XML_PARAGRAPH_PROPERTIES ) |
191 | 3.42k | nFamily = XML_TYPE_PROP_PARAGRAPH; |
192 | 19.5k | else if( nLocalName == XML_RUBY_PROPERTIES ) |
193 | 396 | nFamily = XML_TYPE_PROP_RUBY; |
194 | 19.1k | else if( nLocalName == XML_SECTION_PROPERTIES ) |
195 | 0 | nFamily = XML_TYPE_PROP_SECTION; |
196 | 19.1k | else if( nLocalName == XML_TABLE_PROPERTIES ) |
197 | 1.36k | nFamily = XML_TYPE_PROP_TABLE; |
198 | 17.8k | else if( nLocalName == XML_TABLE_COLUMN_PROPERTIES ) |
199 | 3.56k | nFamily = XML_TYPE_PROP_TABLE_COLUMN; |
200 | 14.2k | else if( nLocalName ==XML_TABLE_ROW_PROPERTIES ) |
201 | 1.82k | nFamily = XML_TYPE_PROP_TABLE_ROW; |
202 | 12.4k | else if( nLocalName == XML_TABLE_CELL_PROPERTIES ) |
203 | 10.8k | nFamily = XML_TYPE_PROP_TABLE_CELL; |
204 | 1.53k | else if( nLocalName == XML_CHART_PROPERTIES ) |
205 | 0 | nFamily = XML_TYPE_PROP_CHART; |
206 | 50.3k | } |
207 | 52.2k | if( nFamily ) |
208 | 48.8k | { |
209 | 48.8k | SvXMLImportPropertyMapper* pImpPrMap = |
210 | 48.8k | mxStyles->GetImportPropertyMapper( GetFamily() ); |
211 | 48.8k | if (pImpPrMap) |
212 | 48.8k | { |
213 | 48.8k | return new StylePropertiesContext(GetImport(), nElement, xAttrList, nFamily, maProperties, pImpPrMap); |
214 | 48.8k | } |
215 | 48.8k | } |
216 | 3.41k | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
217 | 3.41k | return nullptr; |
218 | 3.41k | } |
219 | | |
220 | | void XMLPropStyleContext::FillPropertySet( |
221 | | const Reference< XPropertySet > & rPropSet ) |
222 | 29.1k | { |
223 | 29.1k | SvXMLImportPropertyMapper* pImpPrMap = |
224 | 29.1k | mxStyles->GetImportPropertyMapper( GetFamily() ); |
225 | 29.1k | SAL_WARN_IF( !pImpPrMap, "xmloff", "There is the import prop mapper" ); |
226 | 29.1k | if( pImpPrMap ) |
227 | 29.1k | pImpPrMap->FillPropertySet( maProperties, rPropSet ); |
228 | 29.1k | } |
229 | | |
230 | | void XMLPropStyleContext::SetDefaults() |
231 | 0 | { |
232 | 0 | } |
233 | | |
234 | | Reference < XStyle > XMLPropStyleContext::Create() |
235 | 20.0k | { |
236 | 20.0k | Reference < XStyle > xNewStyle; |
237 | | |
238 | 20.0k | OUString sServiceName = mxStyles->GetServiceName( GetFamily() ); |
239 | 20.0k | if( !sServiceName.isEmpty() ) |
240 | 20.0k | { |
241 | 20.0k | Reference< XMultiServiceFactory > xFactory( GetImport().GetModel(), |
242 | 20.0k | UNO_QUERY ); |
243 | 20.0k | if( xFactory.is() ) |
244 | 20.0k | { |
245 | 20.0k | Reference < XInterface > xIfc = |
246 | 20.0k | xFactory->createInstance( sServiceName ); |
247 | 20.0k | if( xIfc.is() ) |
248 | 20.0k | xNewStyle.set( xIfc, UNO_QUERY ); |
249 | 20.0k | } |
250 | 20.0k | } |
251 | | |
252 | 20.0k | return xNewStyle; |
253 | 20.0k | } |
254 | | |
255 | | void XMLPropStyleContext::CreateAndInsert( bool bOverwrite ) |
256 | 60.1k | { |
257 | 60.1k | SvXMLStylesContext* pSvXMLStylesContext = mxStyles.get(); |
258 | 60.1k | SvXMLImportPropertyMapper* pImpPrMap = pSvXMLStylesContext->GetImportPropertyMapper(GetFamily()); |
259 | 60.1k | OSL_ENSURE(pImpPrMap, "There is no import prop mapper"); |
260 | | |
261 | | // need to filter out old fill definitions when the new ones are used. The new |
262 | | // ones are used when a FillStyle is defined |
263 | 60.1k | const bool bTakeCareOfDrawingLayerFillStyle(pImpPrMap && GetFamily() == XmlStyleFamily::TEXT_PARAGRAPH); |
264 | 60.1k | bool bDrawingLayerFillStylesUsed(false); |
265 | | |
266 | 60.1k | if(bTakeCareOfDrawingLayerFillStyle) |
267 | 33.3k | { |
268 | | // check if new FillStyles are used and if so mark old ones with -1 |
269 | 33.3k | static constexpr OUString s_FillStyle(u"FillStyle"_ustr); |
270 | | |
271 | 33.3k | if(doNewDrawingLayerFillStyleDefinitionsExist(s_FillStyle)) |
272 | 116 | { |
273 | 116 | deactivateOldFillStyleDefinitions(theParaSet()); |
274 | 116 | bDrawingLayerFillStylesUsed = true; |
275 | 116 | } |
276 | 33.3k | } |
277 | | |
278 | 60.1k | if( pSvXMLStylesContext->IsAutomaticStyle() |
279 | 10.6k | && ( GetFamily() == XmlStyleFamily::TEXT_TEXT || GetFamily() == XmlStyleFamily::TEXT_PARAGRAPH ) ) |
280 | 10.6k | { |
281 | | // Need to translate StyleName from temp MapNames to names |
282 | | // used in already imported items (already exist in the pool). This |
283 | | // is required for AutomaticStyles since these do *not* use FillPropertySet |
284 | | // and thus just trigger CheckSpecialContext in XMLTextStyleContext::FillPropertySet |
285 | | // (which may be double action anyways). The mechanism there to use _ContextID_Index_Pair |
286 | | // is not working for AutomaticStyles and is already too late, too (this |
287 | | // method is already called before XMLTextStyleContext::FillPropertySet gets called) |
288 | 10.6k | if(bDrawingLayerFillStylesUsed) |
289 | 116 | { |
290 | 116 | translateNameBasedDrawingLayerFillStyleDefinitionsToStyleDisplayNames(); |
291 | 116 | } |
292 | | |
293 | 10.6k | Reference < XAutoStyleFamily > xAutoFamily = pSvXMLStylesContext->GetAutoStyles( GetFamily() ); |
294 | 10.6k | if( !xAutoFamily.is() ) |
295 | 0 | return; |
296 | 10.6k | if( pImpPrMap ) |
297 | 10.6k | { |
298 | 10.6k | Sequence< PropertyValue > aValues; |
299 | 10.6k | pImpPrMap->FillPropertySequence( maProperties, aValues ); |
300 | | |
301 | 10.6k | sal_Int32 nLen = aValues.getLength(); |
302 | 10.6k | if( nLen ) |
303 | 9.12k | { |
304 | 9.12k | if( GetFamily() == XmlStyleFamily::TEXT_PARAGRAPH ) |
305 | 6.61k | { |
306 | 6.61k | aValues.realloc( nLen + 2 ); |
307 | 6.61k | PropertyValue *pProps = aValues.getArray() + nLen; |
308 | 6.61k | pProps->Name = "ParaStyleName"; |
309 | 6.61k | OUString sParent( GetParentName() ); |
310 | 6.61k | if( !sParent.isEmpty() ) |
311 | 5.50k | { |
312 | 5.50k | sParent = GetImport().GetStyleDisplayName( GetFamily(), sParent ); |
313 | 5.50k | Reference < XNameContainer > xFamilies = pSvXMLStylesContext->GetStylesContainer( GetFamily() ); |
314 | 5.50k | if(xFamilies.is() && xFamilies->hasByName( sParent ) ) |
315 | 4.55k | { |
316 | 4.55k | css::uno::Reference< css::style::XStyle > xStyle; |
317 | 4.55k | Any aAny = xFamilies->getByName( sParent ); |
318 | 4.55k | aAny >>= xStyle; |
319 | 4.55k | sParent = xStyle->getName() ; |
320 | 4.55k | } |
321 | 5.50k | } |
322 | 1.11k | else |
323 | 1.11k | sParent = "Standard"; |
324 | 6.61k | pProps->Value <<= sParent; |
325 | 6.61k | ++pProps; |
326 | 6.61k | pProps->Name = "ParaConditionalStyleName"; |
327 | 6.61k | pProps->Value <<= sParent; |
328 | 6.61k | } |
329 | | |
330 | 9.12k | Reference < XAutoStyle > xAutoStyle = xAutoFamily->insertStyle( aValues ); |
331 | 9.12k | if( xAutoStyle.is() ) |
332 | 9.12k | { |
333 | 9.12k | Sequence< OUString > aPropNames |
334 | 9.12k | { |
335 | 9.12k | (GetFamily() == XmlStyleFamily::TEXT_PARAGRAPH)? |
336 | 6.61k | u"ParaAutoStyleName"_ustr: |
337 | 9.12k | u"CharAutoStyleName"_ustr |
338 | 9.12k | }; |
339 | 9.12k | Sequence< Any > aAny = xAutoStyle->getPropertyValues( aPropNames ); |
340 | 9.12k | if( aAny.hasElements() ) |
341 | 9.12k | { |
342 | 9.12k | SetAutoName(aAny[0]); |
343 | 9.12k | } |
344 | 9.12k | } |
345 | 9.12k | } |
346 | 10.6k | } |
347 | 10.6k | } |
348 | 49.4k | else |
349 | 49.4k | { |
350 | 49.4k | const OUString& rName = GetDisplayName(); |
351 | 49.4k | if( rName.isEmpty() || IsDefaultStyle() ) |
352 | 747 | return; |
353 | | |
354 | 48.7k | Reference < XNameContainer > xFamilies = pSvXMLStylesContext->GetStylesContainer( GetFamily() ); |
355 | 48.7k | if( !xFamilies.is() ) |
356 | 1.34k | { |
357 | 1.34k | SAL_WARN("xmloff", "no styles container for family " << static_cast<int>(GetFamily())); |
358 | 1.34k | return; |
359 | 1.34k | } |
360 | | |
361 | 47.3k | bool bNew = false; |
362 | 47.3k | if( xFamilies->hasByName( rName ) ) |
363 | 27.3k | { |
364 | 27.3k | Any aAny = xFamilies->getByName( rName ); |
365 | 27.3k | aAny >>= mxStyle; |
366 | 27.3k | } |
367 | 20.0k | else |
368 | 20.0k | { |
369 | 20.0k | mxStyle = Create(); |
370 | 20.0k | if( !mxStyle.is() ) |
371 | 0 | return; |
372 | | |
373 | 20.0k | xFamilies->insertByName( rName, Any(mxStyle) ); |
374 | 20.0k | bNew = true; |
375 | 20.0k | } |
376 | | |
377 | | // In Writer, 'SwXTextCellStyle' instances require explicit parent linkage |
378 | 47.3k | if (GetFamily() == XmlStyleFamily::TABLE_CELL) |
379 | 15.6k | mxStyle->setParentStyle(GetParentName()); |
380 | | |
381 | 47.3k | Reference < XPropertySet > xPropSet( mxStyle, UNO_QUERY ); |
382 | 47.3k | Reference< XPropertySetInfo > xPropSetInfo = |
383 | 47.3k | xPropSet->getPropertySetInfo(); |
384 | 47.3k | if( !bNew && xPropSetInfo->hasPropertyByName( gsIsPhysical ) ) |
385 | 18.8k | { |
386 | 18.8k | Any aAny = xPropSet->getPropertyValue( gsIsPhysical ); |
387 | 18.8k | bNew = !*o3tl::doAccess<bool>(aAny); |
388 | 18.8k | } |
389 | 47.3k | SetNew( bNew ); |
390 | 47.3k | if( rName != GetName() ) |
391 | 18.8k | GetImport().AddStyleDisplayName( GetFamily(), GetName(), rName ); |
392 | | |
393 | | |
394 | 47.3k | if( bOverwrite || bNew ) |
395 | 47.3k | { |
396 | 47.3k | rtl::Reference < XMLPropertySetMapper > xPrMap; |
397 | 47.3k | if( pImpPrMap ) |
398 | 47.3k | xPrMap = pImpPrMap->getPropertySetMapper(); |
399 | 47.3k | if( xPrMap.is() ) |
400 | 47.3k | { |
401 | 47.3k | Reference < XMultiPropertyStates > xMultiStates( xPropSet, |
402 | 47.3k | UNO_QUERY ); |
403 | 47.3k | if( xMultiStates.is() ) |
404 | 41.5k | { |
405 | 41.5k | xMultiStates->setAllPropertiesToDefault(); |
406 | 41.5k | } |
407 | 5.85k | else |
408 | 5.85k | { |
409 | 5.85k | std::set < OUString > aNameSet; |
410 | 5.85k | sal_Int32 nCount = xPrMap->GetEntryCount(); |
411 | 5.85k | sal_Int32 i; |
412 | 333k | for( i = 0; i < nCount; i++ ) |
413 | 328k | { |
414 | 328k | const OUString& rPrName = xPrMap->GetEntryAPIName( i ); |
415 | 328k | if( xPropSetInfo->hasPropertyByName( rPrName ) ) |
416 | 322k | aNameSet.insert( rPrName ); |
417 | 328k | } |
418 | 5.85k | Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY ); |
419 | 5.85k | if (xPropState.is()) |
420 | 5.85k | { |
421 | 5.85k | nCount = aNameSet.size(); |
422 | 5.85k | Sequence<OUString> aNames( comphelper::containerToSequence(aNameSet) ); |
423 | 5.85k | Sequence < PropertyState > aStates( xPropState->getPropertyStates(aNames) ); |
424 | 5.85k | const PropertyState *pStates = aStates.getConstArray(); |
425 | 5.85k | OUString* pNames = aNames.getArray(); |
426 | | |
427 | 275k | for( i = 0; i < nCount; i++ ) |
428 | 269k | { |
429 | 269k | if( PropertyState_DIRECT_VALUE == *pStates++ ) |
430 | 10.3k | xPropState->setPropertyToDefault( pNames[i] ); |
431 | 269k | } |
432 | 5.85k | } |
433 | 5.85k | } |
434 | 47.3k | } |
435 | | |
436 | 47.3k | if (mxStyle.is()) |
437 | 47.3k | mxStyle->setParentStyle(OUString()); |
438 | | |
439 | 47.3k | FillPropertySet( xPropSet ); |
440 | 47.3k | } |
441 | 0 | else |
442 | 0 | { |
443 | 0 | SetValid( false ); |
444 | 0 | } |
445 | 47.3k | } |
446 | 60.1k | } |
447 | | |
448 | | void XMLPropStyleContext::Finish( bool bOverwrite ) |
449 | 35.1k | { |
450 | 35.1k | if( !mxStyle.is() || !(IsNew() || bOverwrite) ) |
451 | 4.06k | return; |
452 | | |
453 | | // The families container must exist |
454 | 31.0k | Reference < XNameContainer > xFamilies = mxStyles->GetStylesContainer( GetFamily() ); |
455 | 31.0k | SAL_WARN_IF( !xFamilies.is(), "xmloff", "Families lost" ); |
456 | 31.0k | if( !xFamilies.is() ) |
457 | 0 | return; |
458 | | |
459 | | // connect parent |
460 | 31.0k | OUString sParent( GetParentName() ); |
461 | 31.0k | if( !sParent.isEmpty() ) |
462 | 22.1k | sParent = GetImport().GetStyleDisplayName( GetFamily(), sParent ); |
463 | 31.0k | if( !sParent.isEmpty() && !xFamilies->hasByName( sParent ) ) |
464 | 1.66k | sParent.clear(); |
465 | | |
466 | 31.0k | if( sParent != mxStyle->getParentStyle() ) |
467 | 15.6k | { |
468 | | // this may except if setting the parent style forms a |
469 | | // circle in the style dependencies; especially if the parent |
470 | | // style is the same as the current style |
471 | 15.6k | try |
472 | 15.6k | { |
473 | 15.6k | mxStyle->setParentStyle( sParent ); |
474 | 15.6k | } |
475 | 15.6k | catch(const uno::Exception& e) |
476 | 15.6k | { |
477 | | // according to the API definition, I would expect a |
478 | | // container::NoSuchElementException. But it throws an |
479 | | // uno::RuntimeException instead. I catch |
480 | | // uno::Exception in order to process both of them. |
481 | | |
482 | | // We can't set the parent style. For a proper |
483 | | // Error-Message, we should pass in the name of the |
484 | | // style, as well as the desired parent style. |
485 | | |
486 | | // getName() throws no non-Runtime exception: |
487 | 5 | GetImport().SetError( |
488 | 5 | XMLERROR_FLAG_ERROR | XMLERROR_PARENT_STYLE_NOT_ALLOWED, |
489 | 5 | { mxStyle->getName(), sParent }, e.Message, nullptr ); |
490 | 5 | } |
491 | 15.6k | } |
492 | | |
493 | | // connect follow |
494 | 31.0k | OUString sFollow( GetFollow() ); |
495 | 31.0k | if( !sFollow.isEmpty() ) |
496 | 3.17k | sFollow = GetImport().GetStyleDisplayName( GetFamily(), sFollow ); |
497 | 31.0k | if( sFollow.isEmpty() || !xFamilies->hasByName( sFollow ) ) |
498 | 28.3k | sFollow = mxStyle->getName(); |
499 | | |
500 | 31.0k | Reference < XPropertySet > xPropSet( mxStyle, UNO_QUERY ); |
501 | 31.0k | Reference< XPropertySetInfo > xPropSetInfo = |
502 | 31.0k | xPropSet->getPropertySetInfo(); |
503 | 31.0k | if( xPropSetInfo->hasPropertyByName( gsFollowStyle ) ) |
504 | 15.5k | { |
505 | 15.5k | Any aAny = xPropSet->getPropertyValue( gsFollowStyle ); |
506 | 15.5k | OUString sCurrFollow; |
507 | 15.5k | aAny >>= sCurrFollow; |
508 | 15.5k | if( sCurrFollow != sFollow ) |
509 | 2.64k | { |
510 | 2.64k | xPropSet->setPropertyValue( gsFollowStyle, Any(sFollow) ); |
511 | 2.64k | } |
512 | 15.5k | } |
513 | | |
514 | | // Connect linked style. |
515 | 31.0k | OUString aLinked(GetLinked()); |
516 | 31.0k | if (!aLinked.isEmpty()) |
517 | 0 | { |
518 | 0 | if (GetFamily() == XmlStyleFamily::TEXT_PARAGRAPH) |
519 | 0 | { |
520 | 0 | aLinked = GetImport().GetStyleDisplayName(XmlStyleFamily::TEXT_TEXT, aLinked); |
521 | 0 | } |
522 | 0 | else if (GetFamily() == XmlStyleFamily::TEXT_TEXT) |
523 | 0 | { |
524 | 0 | aLinked = GetImport().GetStyleDisplayName(XmlStyleFamily::TEXT_PARAGRAPH, aLinked); |
525 | 0 | } |
526 | 0 | } |
527 | 31.0k | if (!aLinked.isEmpty() && xPropSetInfo->hasPropertyByName(u"LinkStyle"_ustr)) |
528 | 0 | { |
529 | 0 | uno::Any aAny = xPropSet->getPropertyValue(u"LinkStyle"_ustr); |
530 | 0 | OUString aCurrentLinked; |
531 | 0 | aAny >>= aCurrentLinked; |
532 | 0 | if (aCurrentLinked != aLinked) |
533 | 0 | { |
534 | 0 | xPropSet->setPropertyValue(u"LinkStyle"_ustr, uno::Any(aLinked)); |
535 | 0 | } |
536 | 0 | } |
537 | | |
538 | 31.0k | if ( xPropSetInfo->hasPropertyByName( u"Hidden"_ustr ) ) |
539 | 30.6k | { |
540 | 30.6k | xPropSet->setPropertyValue( u"Hidden"_ustr, uno::Any( IsHidden( ) ) ); |
541 | 30.6k | } |
542 | | |
543 | 31.0k | } |
544 | | |
545 | | bool XMLPropStyleContext::doNewDrawingLayerFillStyleDefinitionsExist( |
546 | | std::u16string_view rFillStyleTag) const |
547 | 43.3k | { |
548 | 43.3k | if(!maProperties.empty() && !rFillStyleTag.empty()) |
549 | 38.2k | { |
550 | | // no & to avoid non-obvious UAF due to the 2nd temp Reference |
551 | 38.2k | const rtl::Reference<XMLPropertySetMapper> rMapper = GetStyles()->GetImportPropertyMapper(GetFamily())->getPropertySetMapper(); |
552 | | |
553 | 38.2k | if(rMapper.is()) |
554 | 38.2k | { |
555 | 38.2k | for(const auto& a : maProperties) |
556 | 488k | { |
557 | 488k | if(a.mnIndex != -1) |
558 | 446k | { |
559 | 446k | const OUString& rPropName = rMapper->GetEntryAPIName(a.mnIndex); |
560 | | |
561 | 446k | if(rPropName == rFillStyleTag) |
562 | 164 | { |
563 | 164 | FillStyle eFillStyle(FillStyle_NONE); |
564 | | |
565 | 164 | if(a.maValue >>= eFillStyle) |
566 | 164 | { |
567 | | // okay, type was good, FillStyle is set |
568 | 164 | } |
569 | 0 | else |
570 | 0 | { |
571 | | // also try an int (see XFillStyleItem::PutValue) |
572 | 0 | sal_Int32 nFillStyle(0); |
573 | |
|
574 | 0 | if(a.maValue >>= nFillStyle) |
575 | 0 | { |
576 | 0 | eFillStyle = static_cast< FillStyle >(nFillStyle); |
577 | 0 | } |
578 | 0 | } |
579 | | |
580 | | // we found the entry, check it |
581 | 164 | return FillStyle_NONE != eFillStyle; |
582 | 164 | } |
583 | 446k | } |
584 | 488k | } |
585 | 38.2k | } |
586 | 38.2k | } |
587 | | |
588 | 43.1k | return false; |
589 | 43.3k | } |
590 | | |
591 | | void XMLPropStyleContext::deactivateOldFillStyleDefinitions( |
592 | | const OldFillStyleDefinitionSet& rHashSetOfTags) |
593 | 116 | { |
594 | 116 | if(rHashSetOfTags.empty() || maProperties.empty()) |
595 | 0 | return; |
596 | | |
597 | 116 | const rtl::Reference< XMLPropertySetMapper >& rMapper = GetStyles()->GetImportPropertyMapper(GetFamily())->getPropertySetMapper(); |
598 | | |
599 | 116 | if(!rMapper.is()) |
600 | 0 | return; |
601 | | |
602 | 116 | for(auto& a : maProperties) |
603 | 4.73k | { |
604 | 4.73k | if(a.mnIndex != -1) |
605 | 4.65k | { |
606 | 4.65k | const OUString& rPropName = rMapper->GetEntryAPIName(a.mnIndex); |
607 | | |
608 | 4.65k | if(rHashSetOfTags.find(rPropName) != rHashSetOfTags.end()) |
609 | 0 | { |
610 | | // mark entry as inactive |
611 | 0 | a.mnIndex = -1; |
612 | 0 | } |
613 | 4.65k | } |
614 | 4.73k | } |
615 | 116 | } |
616 | | |
617 | | void XMLPropStyleContext::translateNameBasedDrawingLayerFillStyleDefinitionsToStyleDisplayNames() |
618 | 116 | { |
619 | 116 | if(maProperties.empty()) |
620 | 0 | return; |
621 | | |
622 | 116 | const rtl::Reference< XMLPropertySetMapper >& rMapper = GetStyles()->GetImportPropertyMapper(GetFamily())->getPropertySetMapper(); |
623 | | |
624 | 116 | if(!rMapper.is()) |
625 | 0 | return; |
626 | | |
627 | 116 | for(auto& a : maProperties) |
628 | 4.73k | { |
629 | 4.73k | if(a.mnIndex != -1) |
630 | 4.65k | { |
631 | 4.65k | const OUString& rPropName = rMapper->GetEntryAPIName(a.mnIndex); |
632 | 4.65k | XmlStyleFamily aStyleFamily(XmlStyleFamily::DATA_STYLE); |
633 | | |
634 | 4.65k | if(rPropName == u"FillGradientName" |
635 | 4.65k | || rPropName == u"FillTransparenceGradientName") |
636 | 0 | { |
637 | 0 | aStyleFamily = XmlStyleFamily::SD_GRADIENT_ID; |
638 | 0 | } |
639 | 4.65k | else if(rPropName == u"FillHatchName") |
640 | 0 | { |
641 | 0 | aStyleFamily = XmlStyleFamily::SD_HATCH_ID; |
642 | 0 | } |
643 | 4.65k | else if(rPropName == u"FillBitmapName") |
644 | 0 | { |
645 | 0 | aStyleFamily = XmlStyleFamily::SD_FILL_IMAGE_ID; |
646 | 0 | } |
647 | | |
648 | 4.65k | if(aStyleFamily != XmlStyleFamily::DATA_STYLE) |
649 | 0 | { |
650 | 0 | OUString sStyleName; |
651 | |
|
652 | 0 | a.maValue >>= sStyleName; |
653 | 0 | sStyleName = GetImport().GetStyleDisplayName( aStyleFamily, sStyleName ); |
654 | 0 | a.maValue <<= sStyleName; |
655 | 0 | } |
656 | 4.65k | } |
657 | 4.73k | } |
658 | 116 | } |
659 | | |
660 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |