Update ooo320-m1
[ooovba.git] / sc / source / filter / xml / xmlstyli.cxx
blob0542dd78b5103e96251f50c437816b3f6052ae18
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlstyli.cxx,v $
10 * $Revision: 1.63 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 #include "xmlstyli.hxx"
36 #include <xmloff/nmspmap.hxx>
37 #include <xmloff/xmlnmspe.hxx>
38 #include <xmloff/xmlimppr.hxx>
39 #include <xmloff/families.hxx>
40 #include <xmloff/xmlnumfi.hxx>
41 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
42 #include <xmloff/xmltoken.hxx>
43 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
44 #include <com/sun/star/container/XNameContainer.hpp>
45 #include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
46 #include <com/sun/star/table/BorderLine.hpp>
47 #include <comphelper/extract.hxx>
48 #include <xmloff/xmlprcon.hxx>
49 #include <xmloff/xmluconv.hxx>
50 #include <tools/debug.hxx>
51 #include "XMLTableHeaderFooterContext.hxx"
52 #include "XMLConverter.hxx"
53 #include "XMLTableShapeImportHelper.hxx"
54 #include "sheetdata.hxx"
55 #include "xmlannoi.hxx"
56 #include "textuno.hxx"
57 #include "cellsuno.hxx"
59 #include "docuno.hxx"
60 #include "unonames.hxx"
61 #include "document.hxx"
63 #define XML_LINE_LEFT 0
64 #define XML_LINE_RIGHT 1
65 #define XML_LINE_TOP 2
66 #define XML_LINE_BOTTOM 3
68 #define XML_LINE_TLBR 0
69 #define XML_LINE_BLTR 1
71 using ::rtl::OUString;
72 using namespace ::com::sun::star;
73 using namespace ::com::sun::star::uno;
74 using namespace ::com::sun::star::xml::sax;
75 using namespace ::com::sun::star::style;
76 using namespace ::com::sun::star::frame;
77 using namespace ::com::sun::star::beans;
78 using namespace ::com::sun::star::container;
79 using namespace xmloff::token;
80 //using namespace ::com::sun::star::text;
81 using namespace ::formula;
83 ScXMLCellImportPropertyMapper::ScXMLCellImportPropertyMapper(
84 const UniReference< XMLPropertySetMapper >& rMapper,
85 SvXMLImport& rImportP) :
86 SvXMLImportPropertyMapper( rMapper, rImportP )
90 ScXMLCellImportPropertyMapper::~ScXMLCellImportPropertyMapper()
94 void ScXMLCellImportPropertyMapper::finished(::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
96 static const sal_Int16 aPaddingCTF[4] = { CTF_SC_LEFTPADDING, CTF_SC_RIGHTPADDING,
97 CTF_SC_TOPPADDING, CTF_SC_BOTTOMPADDING };
98 static const sal_Int16 aBorderCTF[4] = { CTF_SC_LEFTBORDER, CTF_SC_RIGHTBORDER,
99 CTF_SC_TOPBORDER, CTF_SC_BOTTOMBORDER };
101 SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex);
102 XMLPropertyState* pAllPaddingProperty(NULL);
103 XMLPropertyState* pPadding[4] = { NULL, NULL, NULL, NULL };
104 XMLPropertyState* pNewPadding[4] = { NULL, NULL, NULL, NULL };
105 XMLPropertyState* pAllBorderProperty = NULL;
106 XMLPropertyState* pBorders[4] = { NULL, NULL, NULL, NULL };
107 XMLPropertyState* pNewBorders[4] = { NULL, NULL, NULL, NULL };
108 XMLPropertyState* pAllBorderWidthProperty = NULL;
109 XMLPropertyState* pBorderWidths[4] = { NULL, NULL, NULL, NULL };
110 XMLPropertyState* pDiagBorders[2] = { 0 };
111 XMLPropertyState* pDiagBorderWidths[2] = { 0 };
113 ::std::vector< XMLPropertyState >::iterator endproperty(rProperties.end());
114 for (::std::vector< XMLPropertyState >::iterator aIter = rProperties.begin();
115 aIter != endproperty; ++aIter)
117 XMLPropertyState*property = &(*aIter);
118 if (property->mnIndex != -1)
120 sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex);
121 switch (nContextID)
123 case CTF_SC_ALLPADDING : pAllPaddingProperty = &*property; break;
124 case CTF_SC_LEFTPADDING : pPadding[XML_LINE_LEFT] = &*property; break;
125 case CTF_SC_RIGHTPADDING : pPadding[XML_LINE_RIGHT] = &*property; break;
126 case CTF_SC_TOPPADDING : pPadding[XML_LINE_TOP] = &*property; break;
127 case CTF_SC_BOTTOMPADDING : pPadding[XML_LINE_BOTTOM] = &*property; break;
128 case CTF_SC_ALLBORDER : pAllBorderProperty = &*property; break;
129 case CTF_SC_LEFTBORDER : pBorders[XML_LINE_LEFT] = &*property; break;
130 case CTF_SC_RIGHTBORDER : pBorders[XML_LINE_RIGHT] = &*property; break;
131 case CTF_SC_TOPBORDER : pBorders[XML_LINE_TOP] = &*property; break;
132 case CTF_SC_BOTTOMBORDER : pBorders[XML_LINE_BOTTOM] = &*property; break;
133 case CTF_SC_ALLBORDERWIDTH : pAllBorderWidthProperty = &*property; break;
134 case CTF_SC_LEFTBORDERWIDTH : pBorderWidths[XML_LINE_LEFT] = &*property; break;
135 case CTF_SC_RIGHTBORDERWIDTH : pBorderWidths[XML_LINE_RIGHT] = &*property; break;
136 case CTF_SC_TOPBORDERWIDTH : pBorderWidths[XML_LINE_TOP] = &*property; break;
137 case CTF_SC_BOTTOMBORDERWIDTH : pBorderWidths[XML_LINE_BOTTOM] = &*property; break;
138 case CTF_SC_DIAGONALTLBR : pDiagBorders[XML_LINE_TLBR] = &*property; break;
139 case CTF_SC_DIAGONALBLTR : pDiagBorders[XML_LINE_BLTR] = &*property; break;
140 case CTF_SC_DIAGONALTLBRWIDTH : pDiagBorderWidths[XML_LINE_TLBR] = &*property; break;
141 case CTF_SC_DIAGONALBLTRWIDTH : pDiagBorderWidths[XML_LINE_BLTR] = &*property; break;
145 sal_uInt16 i;
147 // #i27594#; copy Value, but don't insert
148 if (pAllBorderWidthProperty)
149 pAllBorderWidthProperty->mnIndex = -1;
150 if (pAllBorderProperty)
151 pAllBorderProperty->mnIndex = -1;
152 if (pAllPaddingProperty)
153 pAllPaddingProperty->mnIndex = -1;
155 for (i = 0; i < 4; ++i)
157 if (pAllPaddingProperty && !pPadding[i])
158 pNewPadding[i] = new XMLPropertyState(maPropMapper->FindEntryIndex(aPaddingCTF[i]), pAllPaddingProperty->maValue);
159 if (pAllBorderProperty && !pBorders[i])
161 pNewBorders[i] = new XMLPropertyState(maPropMapper->FindEntryIndex(aBorderCTF[i]), pAllBorderProperty->maValue);
162 pBorders[i] = pNewBorders[i];
164 if( !pBorderWidths[i] )
165 pBorderWidths[i] = pAllBorderWidthProperty;
166 else
167 pBorderWidths[i]->mnIndex = -1;
168 if( pBorders[i] )
170 table::BorderLine aBorderLine;
171 pBorders[i]->maValue >>= aBorderLine;
172 if( pBorderWidths[i] )
174 table::BorderLine aBorderLineWidth;
175 pBorderWidths[i]->maValue >>= aBorderLineWidth;
176 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
177 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
178 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
179 pBorders[i]->maValue <<= aBorderLine;
183 for( i = 0; i < 2; ++i )
185 if( pDiagBorders[i] && pDiagBorderWidths[i] )
187 table::BorderLine aBorderLine;
188 pDiagBorders[i]->maValue >>= aBorderLine;
189 table::BorderLine aBorderLineWidth;
190 pDiagBorderWidths[i]->maValue >>= aBorderLineWidth;
191 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
192 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
193 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
194 pDiagBorders[i]->maValue <<= aBorderLine;
195 pDiagBorderWidths[i]->mnIndex = -1;
199 for (i = 0; i < 4; ++i)
201 if (pNewPadding[i])
203 rProperties.push_back(*pNewPadding[i]);
204 delete pNewPadding[i];
206 if (pNewBorders[i])
208 rProperties.push_back(*pNewBorders[i]);
209 delete pNewBorders[i];
214 ScXMLRowImportPropertyMapper::ScXMLRowImportPropertyMapper(
215 const UniReference< XMLPropertySetMapper >& rMapper,
216 SvXMLImport& rImportP) :
217 SvXMLImportPropertyMapper( rMapper, rImportP )
221 ScXMLRowImportPropertyMapper::~ScXMLRowImportPropertyMapper()
225 void ScXMLRowImportPropertyMapper::finished(::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
227 SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex);
228 XMLPropertyState* pHeight(NULL);
229 XMLPropertyState* pOptimalHeight(NULL);
230 XMLPropertyState* pPageBreak(NULL);
231 ::std::vector< XMLPropertyState >::iterator endproperty(rProperties.end());
232 for (::std::vector< XMLPropertyState >::iterator aIter = rProperties.begin();
233 aIter != endproperty; ++aIter)
235 XMLPropertyState* property = &(*aIter);
236 if (property->mnIndex != -1)
238 sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex);
239 switch (nContextID)
241 case CTF_SC_ROWHEIGHT : pHeight = property; break;
242 case CTF_SC_ROWOPTIMALHEIGHT : pOptimalHeight = property; break;
243 case CTF_SC_ROWBREAKBEFORE : pPageBreak = property; break;
247 if (pPageBreak)
249 if(!(::cppu::any2bool(pPageBreak->maValue)))
250 pPageBreak->mnIndex = -1;
252 if (pOptimalHeight)
254 if (::cppu::any2bool(pOptimalHeight->maValue))
256 if (pHeight)
258 // set the stored height, but keep "optimal" flag:
259 // pass the height value as OptimalHeight property (only allowed while loading!)
260 pOptimalHeight->maValue = pHeight->maValue;
261 pHeight->mnIndex = -1;
263 else
264 pOptimalHeight->mnIndex = -1;
267 else if (pHeight)
269 rProperties.push_back(XMLPropertyState(maPropMapper->FindEntryIndex(CTF_SC_ROWOPTIMALHEIGHT), ::cppu::bool2any( sal_False )));
271 // don't access pointers to rProperties elements after push_back!
274 class ScXMLMapContext : public SvXMLImportContext
276 rtl::OUString sApplyStyle;
277 rtl::OUString sCondition;
278 rtl::OUString sBaseCell;
279 public:
281 ScXMLMapContext(
282 SvXMLImport& rImport, sal_uInt16 nPrfx,
283 const rtl::OUString& rLName,
284 const uno::Reference< xml::sax::XAttributeList > & xAttrList );
285 virtual ~ScXMLMapContext();
287 const rtl::OUString& GetApplyStyle() const { return sApplyStyle; }
288 const rtl::OUString& GetCondition() const { return sCondition; }
289 const rtl::OUString& GetBaseCell() const { return sBaseCell; }
292 ScXMLMapContext::ScXMLMapContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
293 const OUString& rLName, const uno::Reference< xml::sax::XAttributeList > & xAttrList )
294 : SvXMLImportContext( rImport, nPrfx, rLName )
296 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
297 for( sal_Int16 i=0; i < nAttrCount; ++i )
299 const OUString& rAttrName(xAttrList->getNameByIndex( i ));
300 OUString aLocalName;
301 sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ));
302 const OUString& rValue(xAttrList->getValueByIndex( i ));
304 // TODO: use a map here
305 if( XML_NAMESPACE_STYLE == nPrefix )
307 if( IsXMLToken(aLocalName, XML_CONDITION ) )
308 sCondition = rValue;
309 else if( IsXMLToken(aLocalName, XML_APPLY_STYLE_NAME ) )
310 sApplyStyle = GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TABLE_CELL, rValue);
311 else if ( IsXMLToken(aLocalName, XML_BASE_CELL_ADDRESS ) )
312 sBaseCell = rValue;
317 ScXMLMapContext::~ScXMLMapContext()
321 namespace {
323 template< typename Type >
324 inline void lclAppendProperty( uno::Sequence< beans::PropertyValue >& rProps, const OUString& rPropName, const Type& rValue )
326 sal_Int32 nLength = rProps.getLength();
327 rProps.realloc( nLength + 1 );
328 rProps[ nLength ].Name = rPropName;
329 rProps[ nLength ].Value <<= rValue;
332 } // namespace
334 void XMLTableStyleContext::SetOperator( uno::Sequence< beans::PropertyValue >& rProps, sheet::ConditionOperator eOp ) const
336 lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_OPERATOR ) ), eOp );
339 void XMLTableStyleContext::SetBaseCellAddress( uno::Sequence< beans::PropertyValue >& rProps, const OUString& rBaseCell ) const
341 /* #b4974740# Source position must be set as string, because it may refer
342 to a sheet that hasn't been loaded yet. */
343 lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SOURCESTR ) ), rBaseCell );
346 void XMLTableStyleContext::SetStyle( uno::Sequence<beans::PropertyValue>& rProps, const OUString& rApplyStyle ) const
348 lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_STYLENAME ) ), rApplyStyle );
351 void XMLTableStyleContext::SetFormula( uno::Sequence< beans::PropertyValue >& rProps,
352 sal_Int32 nFormulaIdx, const OUString& rFormula, const OUString& rFormulaNmsp,
353 FormulaGrammar::Grammar eGrammar, bool bHasNmsp ) const
355 OUString aFormula, aFormulaNmsp;
356 FormulaGrammar::Grammar eNewGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
357 if( bHasNmsp )
359 // the entire attribute contains a namespace: internal namespace not allowed
360 aFormula = rFormula;
361 aFormulaNmsp = rFormulaNmsp;
362 eNewGrammar = eGrammar;
364 else
366 // the attribute does not contain a namespace: try to find a namespace of an external grammar
367 GetScImport().ExtractFormulaNamespaceGrammar( aFormula, aFormulaNmsp, eNewGrammar, rFormula, true );
368 if( eNewGrammar != FormulaGrammar::GRAM_EXTERNAL )
369 eNewGrammar = eGrammar;
372 // add formula, formula namespace, and grammar with appropriate property names
373 sal_Int32 nGrammar = static_cast< sal_Int32 >( eNewGrammar );
374 switch( nFormulaIdx )
376 case 1:
377 lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULA1 ) ), aFormula );
378 lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULANMSP1 ) ), aFormulaNmsp );
379 lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_GRAMMAR1 ) ), nGrammar );
380 break;
381 case 2:
382 lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULA2 ) ), aFormula );
383 lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULANMSP2 ) ), aFormulaNmsp );
384 lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_GRAMMAR2 ) ), nGrammar );
385 break;
386 default:
387 OSL_ENSURE( false, "XMLTableStyleContext::SetFormula - invalid formula index" );
391 void XMLTableStyleContext::GetConditionalFormat(uno::Any& aAny,
392 const rtl::OUString& sTempCondition,
393 const rtl::OUString& sApplyStyle, const rtl::OUString& sBaseCell) const
395 if (sTempCondition.getLength() && sApplyStyle.getLength())
397 uno::Reference<sheet::XSheetConditionalEntries> xConditionalEntries(aAny, uno::UNO_QUERY);
398 if (xConditionalEntries.is())
400 uno::Sequence<beans::PropertyValue> aProps;
401 if (sBaseCell.getLength())
402 SetBaseCellAddress(aProps, sBaseCell);
403 SetStyle(aProps, sApplyStyle);
405 // extract leading namespace from condition string
406 OUString aCondition, aConditionNmsp;
407 FormulaGrammar::Grammar eGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
408 GetScImport().ExtractFormulaNamespaceGrammar( aCondition, aConditionNmsp, eGrammar, sTempCondition );
409 bool bHasNmsp = aCondition.getLength() < sTempCondition.getLength();
411 // parse a condition from the attribute string
412 ScXMLConditionParseResult aParseResult;
413 ScXMLConditionHelper::parseCondition( aParseResult, aCondition, 0 );
415 /* Check the result. A valid value in aParseResult.meToken implies
416 that the other members of aParseResult are filled with valid
417 data for that token. */
418 switch( aParseResult.meToken )
420 case XML_COND_CELLCONTENT: // condition is 'cell-content()<operator><expression>'
421 case XML_COND_ISTRUEFORMULA: // condition is 'is-true-formula(<expression>)'
422 case XML_COND_ISBETWEEN: // condition is 'cell-content-is-between(<expression1>,<expression2>)'
423 case XML_COND_ISNOTBETWEEN: // condition is 'cell-content-is-not-between(<expression1>,<expression2>)'
424 SetOperator( aProps, aParseResult.meOperator );
425 SetFormula( aProps, 1, aParseResult.maOperand1, aConditionNmsp, eGrammar, bHasNmsp );
426 SetFormula( aProps, 2, aParseResult.maOperand2, aConditionNmsp, eGrammar, bHasNmsp );
427 break;
429 default:; // unacceptable or unknown condition
432 xConditionalEntries->addNew( aProps );
433 aAny <<= xConditionalEntries;
438 void XMLTableStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
439 const OUString& rLocalName,
440 const OUString& rValue )
442 // TODO: use a map here
443 if( IsXMLToken(rLocalName, XML_DATA_STYLE_NAME ) )
444 sDataStyleName = rValue;
445 else if ( IsXMLToken(rLocalName, XML_MASTER_PAGE_NAME ) )
446 sPageStyle = rValue;
447 else
448 XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
451 struct ScXMLMapContent
453 rtl::OUString sCondition;
454 rtl::OUString sApplyStyle;
455 rtl::OUString sBaseCell;
458 TYPEINIT1( XMLTableStyleContext, XMLPropStyleContext );
460 XMLTableStyleContext::XMLTableStyleContext( ScXMLImport& rImport,
461 sal_uInt16 nPrfx, const OUString& rLName,
462 const uno::Reference< XAttributeList > & xAttrList,
463 SvXMLStylesContext& rStyles, sal_uInt16 nFamily, sal_Bool bDefaultStyle ) :
464 XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle ),
465 sDataStyleName(),
466 sNumberFormat(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberFormat"))),
467 pStyles(&rStyles),
468 nNumberFormat(-1),
469 nLastSheet(-1),
470 bConditionalFormatCreated(sal_False),
471 bParentSet(sal_False)
475 XMLTableStyleContext::~XMLTableStyleContext()
479 SvXMLImportContext *XMLTableStyleContext::CreateChildContext(
480 sal_uInt16 nPrefix,
481 const OUString& rLocalName,
482 const uno::Reference< XAttributeList > & xAttrList )
484 SvXMLImportContext *pContext(NULL);
486 if( (XML_NAMESPACE_STYLE == nPrefix) &&
487 IsXMLToken(rLocalName, XML_MAP ) )
489 pContext = new ScXMLMapContext(GetImport(), nPrefix, rLocalName, xAttrList);
491 ScXMLMapContent aMap;
492 aMap.sCondition = ((ScXMLMapContext*)pContext)->GetCondition();
493 aMap.sApplyStyle = ((ScXMLMapContext*)pContext)->GetApplyStyle();
494 aMap.sBaseCell = ((ScXMLMapContext*)pContext)->GetBaseCell();
495 aMaps.push_back(aMap);
497 if (!pContext)
498 pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
499 xAttrList );
500 return pContext;
503 void XMLTableStyleContext::FillPropertySet(
504 const uno::Reference< XPropertySet > & rPropSet )
506 if (!IsDefaultStyle())
508 if (GetFamily() == XML_STYLE_FAMILY_TABLE_CELL)
510 if (!bParentSet)
512 AddProperty(CTF_SC_CELLSTYLE, uno::makeAny(GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TABLE_CELL, GetParentName() )));
513 bParentSet = sal_True;
515 sal_Int32 nNumFmt = GetNumberFormat();
516 if (nNumFmt >= 0)
517 AddProperty(CTF_SC_NUMBERFORMAT, uno::makeAny(nNumFmt));
518 if (!bConditionalFormatCreated && (aMaps.size() > 0))
520 aConditionalFormat = rPropSet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CONDXML)));
521 std::vector<ScXMLMapContent>::iterator aItr(aMaps.begin());
522 std::vector<ScXMLMapContent>::iterator aEndItr(aMaps.end());
523 while(aItr != aEndItr)
525 //rPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_CONDITIONALFORMAT)),
526 GetConditionalFormat(aConditionalFormat, aItr->sCondition, aItr->sApplyStyle, aItr->sBaseCell);
528 ++aItr;
530 AddProperty(CTF_SC_IMPORT_MAP, aConditionalFormat);
531 bConditionalFormatCreated = sal_True;
534 else if (GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE)
536 if (sPageStyle.getLength())
537 AddProperty(CTF_SC_MASTERPAGENAME, uno::makeAny(GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE, sPageStyle )));
540 XMLPropStyleContext::FillPropertySet(rPropSet);
543 void XMLTableStyleContext::SetDefaults()
545 if ((GetFamily() == XML_STYLE_FAMILY_TABLE_CELL) && GetImport().GetModel().is())
547 uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetImport().GetModel(), uno::UNO_QUERY);
548 if (xMultiServiceFactory.is())
550 uno::Reference <beans::XPropertySet> xProperties(xMultiServiceFactory->createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.Defaults"))), uno::UNO_QUERY);
551 if (xProperties.is())
552 FillPropertySet(xProperties);
557 void XMLTableStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
559 XMLPropertyState* property = FindProperty(nContextID);
560 if (property)
561 property->mnIndex = -1; // #i46996# remove old property, so it isn't double
562 sal_Int32 nIndex(static_cast<XMLTableStylesContext *>(pStyles)->GetIndex(nContextID));
563 DBG_ASSERT(nIndex != -1, "Property not found in Map");
564 XMLPropertyState aPropState(nIndex, rValue);
565 GetProperties().push_back(aPropState); // has to be insertes in a sort order later
568 XMLPropertyState* XMLTableStyleContext::FindProperty(const sal_Int16 nContextID)
570 XMLPropertyState* pRet = NULL;
571 UniReference < XMLPropertySetMapper > xPrMap;
572 UniReference < SvXMLImportPropertyMapper > xImpPrMap =
573 pStyles->GetImportPropertyMapper( GetFamily() );
574 DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
575 if( xImpPrMap.is() )
576 xPrMap = xImpPrMap->getPropertySetMapper();
577 if( xPrMap.is() )
579 ::std::vector< XMLPropertyState >::iterator endproperty(GetProperties().end());
580 ::std::vector< XMLPropertyState >::iterator aIter(GetProperties().begin());
581 while(!pRet && aIter != endproperty)
583 XMLPropertyState* property = &(*aIter);
584 if (property->mnIndex != -1 && xPrMap->GetEntryContextId(property->mnIndex) == nContextID)
586 pRet = property;
588 else
589 ++aIter;
592 return pRet;
595 sal_Int32 XMLTableStyleContext::GetNumberFormat()
597 if (nNumberFormat < 0 && sDataStyleName.getLength())
599 const SvXMLNumFormatContext* pStyle = static_cast<const SvXMLNumFormatContext*>(
600 pStyles->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, sDataStyleName, sal_True));
602 if (!pStyle)
604 XMLTableStylesContext* pMyStyles = static_cast<XMLTableStylesContext*>(GetScImport().GetStyles());
605 if (pMyStyles)
606 pStyle = static_cast<const SvXMLNumFormatContext*>(
607 pMyStyles->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, sDataStyleName, sal_True));
608 else
610 DBG_ERROR("not possible to get style");
613 if (pStyle)
614 nNumberFormat = const_cast<SvXMLNumFormatContext*>(pStyle)->GetKey();
616 return nNumberFormat;
619 // ----------------------------------------------------------------------------
621 SvXMLStyleContext *XMLTableStylesContext::CreateStyleStyleChildContext(
622 sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
623 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
625 SvXMLStyleContext *pStyle;
626 // use own wrapper for text and paragraph, to record style usage
627 if (nFamily == XML_STYLE_FAMILY_TEXT_PARAGRAPH || nFamily == XML_STYLE_FAMILY_TEXT_TEXT)
628 pStyle = new ScCellTextStyleContext( GetImport(), nPrefix, rLocalName,
629 xAttrList, *this, nFamily );
630 else
631 pStyle = SvXMLStylesContext::CreateStyleStyleChildContext(
632 nFamily, nPrefix, rLocalName, xAttrList );
634 if (!pStyle)
636 switch( nFamily )
638 case XML_STYLE_FAMILY_TABLE_CELL:
639 case XML_STYLE_FAMILY_TABLE_COLUMN:
640 case XML_STYLE_FAMILY_TABLE_ROW:
641 case XML_STYLE_FAMILY_TABLE_TABLE:
642 pStyle = new XMLTableStyleContext( GetScImport(), nPrefix, rLocalName,
643 xAttrList, *this, nFamily );
644 break;
648 return pStyle;
651 SvXMLStyleContext *XMLTableStylesContext::CreateDefaultStyleStyleChildContext(
652 sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
653 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
655 SvXMLStyleContext *pStyle(SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily, nPrefix,
656 rLocalName,
657 xAttrList ));
658 if (!pStyle)
660 switch( nFamily )
662 case XML_STYLE_FAMILY_TABLE_CELL:
663 pStyle = new XMLTableStyleContext( GetScImport(), nPrefix, rLocalName,
664 xAttrList, *this, nFamily, sal_True);
665 break;
666 case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
667 pStyle = new XMLGraphicsDefaultStyle( GetScImport(), nPrefix, rLocalName,
668 xAttrList, *this);
669 break;
673 return pStyle;
676 XMLTableStylesContext::XMLTableStylesContext( SvXMLImport& rImport,
677 sal_uInt16 nPrfx ,
678 const OUString& rLName ,
679 const uno::Reference< XAttributeList > & xAttrList,
680 const sal_Bool bTempAutoStyles ) :
681 SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
682 sCellStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CellStyle" ) )),
683 sColumnStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME ))),
684 sRowStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME ))),
685 sTableStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME ))),
686 nNumberFormatIndex(-1),
687 nConditionalFormatIndex(-1),
688 nCellStyleIndex(-1),
689 nMasterPageNameIndex(-1),
690 bAutoStyles(bTempAutoStyles)
694 XMLTableStylesContext::~XMLTableStylesContext()
698 void XMLTableStylesContext::EndElement()
700 SvXMLStylesContext::EndElement();
701 if (bAutoStyles)
702 GetImport().GetTextImport()->SetAutoStyles( this );
703 else
704 ((ScXMLImport&)GetImport()).InsertStyles();
707 UniReference < SvXMLImportPropertyMapper >
708 XMLTableStylesContext::GetImportPropertyMapper(
709 sal_uInt16 nFamily ) const
711 UniReference < SvXMLImportPropertyMapper > xMapper(SvXMLStylesContext::GetImportPropertyMapper(nFamily));
713 if (!xMapper.is())
715 switch( nFamily )
717 case XML_STYLE_FAMILY_TABLE_CELL:
719 if( !xCellImpPropMapper.is() )
721 ((XMLTableStylesContext *)this)->xCellImpPropMapper =
722 new ScXMLCellImportPropertyMapper( GetScImport().GetCellStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
723 xCellImpPropMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(const_cast<SvXMLImport&>(GetImport()), const_cast<XMLFontStylesContext*>(GetScImport().GetFontDecls())));
725 xMapper = xCellImpPropMapper;
727 break;
728 case XML_STYLE_FAMILY_TABLE_COLUMN:
730 if( !xColumnImpPropMapper.is() )
731 ((XMLTableStylesContext *)this)->xColumnImpPropMapper =
732 new SvXMLImportPropertyMapper( GetScImport().GetColumnStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
733 xMapper = xColumnImpPropMapper;
735 break;
736 case XML_STYLE_FAMILY_TABLE_ROW:
738 if( !xRowImpPropMapper.is() )
739 ((XMLTableStylesContext *)this)->xRowImpPropMapper =
740 new ScXMLRowImportPropertyMapper( GetScImport().GetRowStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
741 xMapper = xRowImpPropMapper;
743 break;
744 case XML_STYLE_FAMILY_TABLE_TABLE:
746 if( !xTableImpPropMapper.is() )
747 ((XMLTableStylesContext *)this)->xTableImpPropMapper =
748 new SvXMLImportPropertyMapper( GetScImport().GetTableStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
749 xMapper = xTableImpPropMapper;
751 break;
755 return xMapper;
758 uno::Reference < XNameContainer >
759 XMLTableStylesContext::GetStylesContainer( sal_uInt16 nFamily ) const
761 uno::Reference < XNameContainer > xStyles(SvXMLStylesContext::GetStylesContainer(nFamily));
762 if (!xStyles.is())
764 OUString sName;
765 switch( nFamily )
767 case XML_STYLE_FAMILY_TABLE_TABLE:
769 if( xTableStyles.is() )
770 xStyles.set(xTableStyles);
771 else
772 sName =
773 OUString( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "TableStyles" ) ));
775 break;
776 case XML_STYLE_FAMILY_TABLE_CELL:
778 if( xCellStyles.is() )
779 xStyles.set(xCellStyles);
780 else
781 sName =
782 OUString( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "CellStyles" ) ));
784 break;
785 case XML_STYLE_FAMILY_TABLE_COLUMN:
787 if( xColumnStyles.is() )
788 xStyles.set(xColumnStyles);
789 else
790 sName =
791 OUString( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnStyles" ) ));
793 break;
794 case XML_STYLE_FAMILY_TABLE_ROW:
796 if( xRowStyles.is() )
797 xStyles.set(xRowStyles);
798 else
799 sName =
800 OUString( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RowStyles" ) ));
802 break;
804 if( !xStyles.is() && sName.getLength() && GetScImport().GetModel().is() )
806 uno::Reference< XStyleFamiliesSupplier > xFamiliesSupp(
807 GetScImport().GetModel(), UNO_QUERY );
808 if (xFamiliesSupp.is())
810 uno::Reference< XNameAccess > xFamilies(xFamiliesSupp->getStyleFamilies());
814 xStyles.set(xFamilies->getByName( sName ), uno::UNO_QUERY);
816 catch ( uno::Exception& )
818 // #i97680# Named table/column/row styles aren't supported, getByName will throw an exception.
819 // For better interoperability, these styles should then be handled as automatic styles.
820 // For now, NULL is returned (and the style is ignored).
822 switch( nFamily )
824 case XML_STYLE_FAMILY_TABLE_TABLE:
825 ((XMLTableStylesContext *)this)->xTableStyles.set(xStyles);
826 break;
827 case XML_STYLE_FAMILY_TABLE_CELL:
828 ((XMLTableStylesContext *)this)->xCellStyles.set(xStyles);
829 break;
830 case XML_STYLE_FAMILY_TABLE_COLUMN:
831 ((XMLTableStylesContext *)this)->xColumnStyles.set(xStyles);
832 break;
833 case XML_STYLE_FAMILY_TABLE_ROW:
834 ((XMLTableStylesContext *)this)->xRowStyles.set(xStyles);
835 break;
841 return xStyles;
844 OUString XMLTableStylesContext::GetServiceName( sal_uInt16 nFamily ) const
846 rtl::OUString sServiceName(SvXMLStylesContext::GetServiceName(nFamily));
847 if (!sServiceName.getLength())
849 switch( nFamily )
851 case XML_STYLE_FAMILY_TABLE_COLUMN:
852 sServiceName = sColumnStyleServiceName;
853 break;
854 case XML_STYLE_FAMILY_TABLE_ROW:
855 sServiceName = sRowStyleServiceName;
856 break;
857 case XML_STYLE_FAMILY_TABLE_CELL:
858 sServiceName = sCellStyleServiceName;
859 break;
860 case XML_STYLE_FAMILY_TABLE_TABLE:
861 sServiceName = sTableStyleServiceName;
862 break;
865 return sServiceName;
868 sal_Int32 XMLTableStylesContext::GetIndex(const sal_Int16 nContextID)
870 if (nContextID == CTF_SC_CELLSTYLE)
872 if (nCellStyleIndex == -1)
873 nCellStyleIndex =
874 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
875 return nCellStyleIndex;
877 else if (nContextID == CTF_SC_NUMBERFORMAT)
879 if (nNumberFormatIndex == -1)
880 nNumberFormatIndex =
881 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
882 return nNumberFormatIndex;
884 else if (nContextID == CTF_SC_IMPORT_MAP)
886 if (nConditionalFormatIndex == -1)
887 nConditionalFormatIndex =
888 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
889 return nConditionalFormatIndex;
891 else if (nContextID == CTF_SC_MASTERPAGENAME)
893 if (nMasterPageNameIndex == -1)
894 nMasterPageNameIndex =
895 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_TABLE)->getPropertySetMapper()->FindEntryIndex(nContextID);
896 return nMasterPageNameIndex;
898 else
899 return -1;
902 // ---------------------------------------------------------------------------
903 TYPEINIT1( ScXMLMasterStylesContext, SvXMLStylesContext );
905 sal_Bool ScXMLMasterStylesContext::InsertStyleFamily( sal_uInt16 ) const
907 return sal_True;
910 ScXMLMasterStylesContext::ScXMLMasterStylesContext(
911 SvXMLImport& rImport,
912 sal_uInt16 nPrfx, const OUString& rLName,
913 const uno::Reference< XAttributeList > & xAttrList ) :
914 SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList )
918 ScXMLMasterStylesContext::~ScXMLMasterStylesContext()
922 SvXMLStyleContext *ScXMLMasterStylesContext::CreateStyleChildContext(
923 sal_uInt16 nPrefix,
924 const OUString& rLocalName,
925 const uno::Reference< XAttributeList > & xAttrList )
927 SvXMLStyleContext *pContext(0);
929 if( (XML_NAMESPACE_STYLE == nPrefix) &&
930 IsXMLToken(rLocalName, XML_MASTER_PAGE) &&
931 InsertStyleFamily( XML_STYLE_FAMILY_MASTER_PAGE ) )
932 pContext = new ScMasterPageContext(
933 GetImport(), nPrefix, rLocalName, xAttrList,
934 !GetImport().GetTextImport()->IsInsertMode() );
936 // any other style will be ignored here!
938 return pContext;
941 SvXMLStyleContext *ScXMLMasterStylesContext::CreateStyleStyleChildContext(
942 sal_uInt16 /* nFamily */,
943 sal_uInt16 /* nPrefix */,
944 const OUString& /* rLocalName */,
945 const uno::Reference< XAttributeList > & /* xAttrList */ )
947 return 0;
950 void ScXMLMasterStylesContext::EndElement()
952 FinishStyles(sal_True);
955 TYPEINIT1( ScMasterPageContext, XMLTextMasterPageContext );
957 ScMasterPageContext::ScMasterPageContext( SvXMLImport& rImport,
958 sal_uInt16 nPrfx, const OUString& rLName,
959 const uno::Reference< XAttributeList > & xAttrList,
960 sal_Bool bOverwrite ) :
961 XMLTextMasterPageContext( rImport, nPrfx, rLName, xAttrList, bOverwrite ),
962 bContainsRightHeader(sal_False),
963 bContainsRightFooter(sal_False)
967 ScMasterPageContext::~ScMasterPageContext()
971 SvXMLImportContext *ScMasterPageContext::CreateChildContext(
972 sal_uInt16 nPrefix,
973 const OUString& rLocalName,
974 const uno::Reference< XAttributeList > & xAttrList )
976 return XMLTextMasterPageContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
979 SvXMLImportContext *ScMasterPageContext::CreateHeaderFooterContext(
980 sal_uInt16 nPrefix,
981 const ::rtl::OUString& rLocalName,
982 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
983 const sal_Bool bFooter,
984 const sal_Bool bLeft )
986 if (!bLeft)
988 if (bFooter)
989 bContainsRightFooter = sal_True;
990 else
991 bContainsRightHeader = sal_True;
993 if (!xPropSet.is())
994 xPropSet.set(GetStyle(), UNO_QUERY );
995 return new XMLTableHeaderFooterContext( GetImport(),
996 nPrefix, rLocalName,
997 xAttrList,
998 xPropSet,
999 bFooter, bLeft );
1002 void ScMasterPageContext::ClearContent(const rtl::OUString& rContent)
1004 if (!xPropSet.is())
1005 xPropSet.set(GetStyle(), UNO_QUERY );
1007 if (xPropSet.is())
1009 uno::Reference < sheet::XHeaderFooterContent > xHeaderFooterContent(xPropSet->getPropertyValue( rContent ), uno::UNO_QUERY);
1010 if (xHeaderFooterContent.is())
1012 xHeaderFooterContent->getLeftText()->setString(sEmpty);
1013 xHeaderFooterContent->getCenterText()->setString(sEmpty);
1014 xHeaderFooterContent->getRightText()->setString(sEmpty);
1015 xPropSet->setPropertyValue( rContent, uno::makeAny(xHeaderFooterContent) );
1020 void ScMasterPageContext::Finish( sal_Bool bOverwrite )
1022 XMLTextMasterPageContext::Finish(bOverwrite);
1023 if (!bContainsRightFooter)
1024 ClearContent(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_PAGE_RIGHTFTRCON)));
1025 if (!bContainsRightHeader)
1026 ClearContent(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_PAGE_RIGHTHDRCON)));
1029 // ---------------------------------------------------------------------------
1031 ScCellTextStyleContext::ScCellTextStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
1032 const rtl::OUString& rLName, const uno::Reference<xml::sax::XAttributeList> & xAttrList,
1033 SvXMLStylesContext& rStyles, sal_uInt16 nFamily, sal_Bool bDefaultStyle ) :
1034 XMLTextStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle ),
1035 nLastSheet(-1)
1039 ScCellTextStyleContext::~ScCellTextStyleContext()
1043 void ScCellTextStyleContext::FillPropertySet( const uno::Reference<beans::XPropertySet>& xPropSet )
1045 XMLTextStyleContext::FillPropertySet( xPropSet );
1047 ScXMLImport& rXMLImport = GetScImport();
1049 ScCellTextCursor* pCellImp = ScCellTextCursor::getImplementation( xPropSet );
1050 if (pCellImp)
1052 ScAddress aPos = pCellImp->GetCellObj().GetPosition();
1053 if ( static_cast<sal_Int32>(aPos.Tab()) != nLastSheet )
1055 ESelection aSel = pCellImp->GetSelection();
1057 ScSheetSaveData* pSheetData = ScModelObj::getImplementation(GetImport().GetModel())->GetSheetSaveData();
1058 pSheetData->AddTextStyle( GetName(), aPos, aSel );
1060 nLastSheet = static_cast<sal_Int32>(aPos.Tab());
1063 else if ( rXMLImport.GetTables().GetCurrentSheet() != nLastSheet )
1065 ScDrawTextCursor* pDrawImp = ScDrawTextCursor::getImplementation( xPropSet );
1066 if (pDrawImp)
1068 XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
1069 ScXMLAnnotationContext* pAnnotationContext = pTableShapeImport->GetAnnotationContext();
1070 if (pAnnotationContext)
1072 pAnnotationContext->AddContentStyle( GetFamily(), GetName(), pDrawImp->GetSelection() );
1073 nLastSheet = rXMLImport.GetTables().GetCurrentSheet();
1077 // if it's a different shape, BlockSheet is called from XMLTableShapeImportHelper::finishShape
1078 // formatted text in page headers/footers can be ignored