1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "xmlstyli.hxx"
21 #include <xmloff/xmlnamespace.hxx>
22 #include <xmloff/xmlimppr.hxx>
23 #include <xmloff/families.hxx>
24 #include <xmloff/xmlnumfi.hxx>
25 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
28 #include <com/sun/star/table/BorderLine2.hpp>
29 #include <comphelper/extract.hxx>
30 #include <xmloff/xmlprcon.hxx>
31 #include <xmloff/XMLComplexColorContext.hxx>
32 #include "XMLTableHeaderFooterContext.hxx"
33 #include "XMLConverter.hxx"
34 #include "XMLTableShapeImportHelper.hxx"
35 #include <sheetdata.hxx>
36 #include "xmlannoi.hxx"
37 #include <textuno.hxx>
38 #include <cellsuno.hxx>
39 #include "xmlstyle.hxx"
42 #include <unonames.hxx>
43 #include <document.hxx>
44 #include <conditio.hxx>
45 #include <rangelst.hxx>
47 #include <xmloff/xmltypes.hxx>
48 #include <xmloff/contextid.hxx>
49 #include <xmloff/txtprmap.hxx>
51 #define XML_LINE_LEFT 0
52 #define XML_LINE_RIGHT 1
53 #define XML_LINE_TOP 2
54 #define XML_LINE_BOTTOM 3
56 #define XML_LINE_TLBR 0
57 #define XML_LINE_BLTR 1
59 using namespace ::com::sun::star
;
60 using namespace ::com::sun::star::xml::sax
;
61 using namespace ::com::sun::star::style
;
62 using namespace ::com::sun::star::beans
;
63 using namespace ::com::sun::star::container
;
64 using namespace xmloff::token
;
65 using namespace ::formula
;
67 using com::sun::star::uno::UNO_QUERY
;
68 ScXMLCellImportPropertyMapper::ScXMLCellImportPropertyMapper(
69 const rtl::Reference
< XMLPropertySetMapper
>& rMapper
,
70 SvXMLImport
& rImportP
) :
71 SvXMLImportPropertyMapper( rMapper
, rImportP
)
75 ScXMLCellImportPropertyMapper::~ScXMLCellImportPropertyMapper()
79 void ScXMLCellImportPropertyMapper::finished(::std::vector
< XMLPropertyState
>& rProperties
, sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) const
81 static const sal_Int16 aPaddingCTF
[4] = { CTF_SC_LEFTPADDING
, CTF_SC_RIGHTPADDING
,
82 CTF_SC_TOPPADDING
, CTF_SC_BOTTOMPADDING
};
83 static const sal_Int16 aBorderCTF
[4] = { CTF_SC_LEFTBORDER
, CTF_SC_RIGHTBORDER
,
84 CTF_SC_TOPBORDER
, CTF_SC_BOTTOMBORDER
};
86 SvXMLImportPropertyMapper::finished(rProperties
, nStartIndex
, nEndIndex
);
87 XMLPropertyState
* pAllPaddingProperty(nullptr);
88 XMLPropertyState
* pPadding
[4] = { nullptr, nullptr, nullptr, nullptr };
89 XMLPropertyState
* pNewPadding
[4] = { nullptr, nullptr, nullptr, nullptr };
90 XMLPropertyState
* pAllBorderProperty
= nullptr;
91 XMLPropertyState
* pBorders
[4] = { nullptr, nullptr, nullptr, nullptr };
92 XMLPropertyState
* pNewBorders
[4] = { nullptr, nullptr, nullptr, nullptr };
93 XMLPropertyState
* pAllBorderWidthProperty
= nullptr;
94 XMLPropertyState
* pBorderWidths
[4] = { nullptr, nullptr, nullptr, nullptr };
95 XMLPropertyState
* pDiagBorders
[2] = { nullptr };
96 XMLPropertyState
* pOldDiagBorderWidths
[2] = { nullptr }; // old attribute names without "s"
97 XMLPropertyState
* pDiagBorderWidths
[2] = { nullptr };
99 for (auto& rProperty
: rProperties
)
101 XMLPropertyState
*property
= &rProperty
;
102 if (property
->mnIndex
!= -1)
104 sal_Int16 nContextID
= getPropertySetMapper()->GetEntryContextId(property
->mnIndex
);
107 case CTF_SC_ALLPADDING
: pAllPaddingProperty
= property
; break;
108 case CTF_SC_LEFTPADDING
: pPadding
[XML_LINE_LEFT
] = property
; break;
109 case CTF_SC_RIGHTPADDING
: pPadding
[XML_LINE_RIGHT
] = property
; break;
110 case CTF_SC_TOPPADDING
: pPadding
[XML_LINE_TOP
] = property
; break;
111 case CTF_SC_BOTTOMPADDING
: pPadding
[XML_LINE_BOTTOM
] = property
; break;
112 case CTF_SC_ALLBORDER
: pAllBorderProperty
= property
; break;
113 case CTF_SC_LEFTBORDER
: pBorders
[XML_LINE_LEFT
] = property
; break;
114 case CTF_SC_RIGHTBORDER
: pBorders
[XML_LINE_RIGHT
] = property
; break;
115 case CTF_SC_TOPBORDER
: pBorders
[XML_LINE_TOP
] = property
; break;
116 case CTF_SC_BOTTOMBORDER
: pBorders
[XML_LINE_BOTTOM
] = property
; break;
117 case CTF_SC_ALLBORDERWIDTH
: pAllBorderWidthProperty
= property
; break;
118 case CTF_SC_LEFTBORDERWIDTH
: pBorderWidths
[XML_LINE_LEFT
] = property
; break;
119 case CTF_SC_RIGHTBORDERWIDTH
: pBorderWidths
[XML_LINE_RIGHT
] = property
; break;
120 case CTF_SC_TOPBORDERWIDTH
: pBorderWidths
[XML_LINE_TOP
] = property
; break;
121 case CTF_SC_BOTTOMBORDERWIDTH
: pBorderWidths
[XML_LINE_BOTTOM
] = property
; break;
122 case CTF_SC_DIAGONALTLBR
: pDiagBorders
[XML_LINE_TLBR
] = property
; break;
123 case CTF_SC_DIAGONALBLTR
: pDiagBorders
[XML_LINE_BLTR
] = property
; break;
124 case CTF_SC_DIAGONALTLBRWIDTH
: pOldDiagBorderWidths
[XML_LINE_TLBR
] = property
; break;
125 case CTF_SC_DIAGONALTLBRWIDTHS
: pDiagBorderWidths
[XML_LINE_TLBR
] = property
; break;
126 case CTF_SC_DIAGONALBLTRWIDTH
: pOldDiagBorderWidths
[XML_LINE_BLTR
] = property
; break;
127 case CTF_SC_DIAGONALBLTRWIDTHS
: pDiagBorderWidths
[XML_LINE_BLTR
] = property
; break;
133 // #i27594#; copy Value, but don't insert
134 if (pAllBorderWidthProperty
)
135 pAllBorderWidthProperty
->mnIndex
= -1;
136 if (pAllBorderProperty
)
137 pAllBorderProperty
->mnIndex
= -1;
138 if (pAllPaddingProperty
)
139 pAllPaddingProperty
->mnIndex
= -1;
141 for (i
= 0; i
< 4; ++i
)
143 if (pAllPaddingProperty
&& !pPadding
[i
])
144 pNewPadding
[i
] = new XMLPropertyState(maPropMapper
->FindEntryIndex(aPaddingCTF
[i
]), pAllPaddingProperty
->maValue
);
145 if (pAllBorderProperty
&& !pBorders
[i
])
147 pNewBorders
[i
] = new XMLPropertyState(maPropMapper
->FindEntryIndex(aBorderCTF
[i
]), pAllBorderProperty
->maValue
);
148 pBorders
[i
] = pNewBorders
[i
];
150 if( !pBorderWidths
[i
] )
151 pBorderWidths
[i
] = pAllBorderWidthProperty
;
153 pBorderWidths
[i
]->mnIndex
= -1;
156 table::BorderLine2 aBorderLine
;
157 pBorders
[i
]->maValue
>>= aBorderLine
;
158 if( pBorderWidths
[i
] )
160 // Merge style:border-line-width values to fo:border values. Do
161 // not override fo:border line width or line style with an
163 table::BorderLine2 aBorderLineWidth
;
164 pBorderWidths
[i
]->maValue
>>= aBorderLineWidth
;
165 aBorderLine
.OuterLineWidth
= aBorderLineWidth
.OuterLineWidth
;
166 aBorderLine
.InnerLineWidth
= aBorderLineWidth
.InnerLineWidth
;
167 aBorderLine
.LineDistance
= aBorderLineWidth
.LineDistance
;
168 pBorders
[i
]->maValue
<<= aBorderLine
;
172 for( i
= 0; i
< 2; ++i
)
174 if( pDiagBorders
[i
] && ( pDiagBorderWidths
[i
] || pOldDiagBorderWidths
[i
] ) )
176 table::BorderLine2 aBorderLine
;
177 pDiagBorders
[i
]->maValue
>>= aBorderLine
;
178 table::BorderLine2 aBorderLineWidth
;
179 if (pDiagBorderWidths
[i
])
180 pDiagBorderWidths
[i
]->maValue
>>= aBorderLineWidth
; // prefer new attribute
182 pOldDiagBorderWidths
[i
]->maValue
>>= aBorderLineWidth
;
183 aBorderLine
.OuterLineWidth
= aBorderLineWidth
.OuterLineWidth
;
184 aBorderLine
.InnerLineWidth
= aBorderLineWidth
.InnerLineWidth
;
185 aBorderLine
.LineDistance
= aBorderLineWidth
.LineDistance
;
186 pDiagBorders
[i
]->maValue
<<= aBorderLine
;
187 if (pDiagBorderWidths
[i
])
188 pDiagBorderWidths
[i
]->mnIndex
= -1;
189 if (pOldDiagBorderWidths
[i
])
190 pOldDiagBorderWidths
[i
]->mnIndex
= -1; // reset mnIndex for old and new attribute if both are present
194 for (i
= 0; i
< 4; ++i
)
198 rProperties
.push_back(*pNewPadding
[i
]);
199 delete pNewPadding
[i
];
203 rProperties
.push_back(*pNewBorders
[i
]);
204 delete pNewBorders
[i
];
209 ScXMLRowImportPropertyMapper::ScXMLRowImportPropertyMapper(
210 const rtl::Reference
< XMLPropertySetMapper
>& rMapper
,
211 SvXMLImport
& rImportP
) :
212 SvXMLImportPropertyMapper( rMapper
, rImportP
)
216 ScXMLRowImportPropertyMapper::~ScXMLRowImportPropertyMapper()
220 void ScXMLRowImportPropertyMapper::finished(::std::vector
< XMLPropertyState
>& rProperties
, sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) const
222 SvXMLImportPropertyMapper::finished(rProperties
, nStartIndex
, nEndIndex
);
223 XMLPropertyState
* pHeight(nullptr);
224 XMLPropertyState
* pOptimalHeight(nullptr);
225 XMLPropertyState
* pPageBreak(nullptr);
226 for (auto& rProperty
: rProperties
)
228 XMLPropertyState
* property
= &rProperty
;
229 if (property
->mnIndex
!= -1)
231 sal_Int16 nContextID
= getPropertySetMapper()->GetEntryContextId(property
->mnIndex
);
234 case CTF_SC_ROWHEIGHT
: pHeight
= property
; break;
235 case CTF_SC_ROWOPTIMALHEIGHT
: pOptimalHeight
= property
; break;
236 case CTF_SC_ROWBREAKBEFORE
: pPageBreak
= property
; break;
242 if(!(::cppu::any2bool(pPageBreak
->maValue
)))
243 pPageBreak
->mnIndex
= -1;
247 if (::cppu::any2bool(pOptimalHeight
->maValue
))
251 // set the stored height, but keep "optimal" flag:
252 // pass the height value as OptimalHeight property (only allowed while loading!)
253 pOptimalHeight
->maValue
= pHeight
->maValue
;
254 pHeight
->mnIndex
= -1;
257 pOptimalHeight
->mnIndex
= -1;
262 rProperties
.emplace_back(maPropMapper
->FindEntryIndex(CTF_SC_ROWOPTIMALHEIGHT
), css::uno::Any(false));
264 // don't access pointers to rProperties elements after push_back!
269 class XMLTableCellPropsContext
: public SvXMLPropertySetContext
272 XMLTableCellPropsContext(
273 SvXMLImport
& rImport
, sal_Int32 nElement
,
274 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
,
276 ::std::vector
< XMLPropertyState
> &rProps
,
277 const rtl::Reference
< SvXMLImportPropertyMapper
> &rMap
);
279 using SvXMLPropertySetContext::createFastChildContext
;
280 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> createFastChildContext(
282 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
283 ::std::vector
< XMLPropertyState
> &rProperties
,
284 const XMLPropertyState
& rProp
) override
;
289 XMLTableCellPropsContext::XMLTableCellPropsContext(
290 SvXMLImport
& rImport
, sal_Int32 nElement
,
291 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
,
293 ::std::vector
< XMLPropertyState
> &rProps
,
294 const rtl::Reference
< SvXMLImportPropertyMapper
> &rMap
)
295 : SvXMLPropertySetContext( rImport
, nElement
, xAttrList
, nFamily
,
300 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLTableCellPropsContext::createFastChildContext(
302 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
303 ::std::vector
< XMLPropertyState
> &rProperties
,
304 const XMLPropertyState
& rProperty
)
306 switch (mxMapper
->getPropertySetMapper()->GetEntryContextId(rProperty
.mnIndex
))
308 case CTF_COMPLEX_COLOR
:
310 return new XMLPropertyComplexColorContext(GetImport(), nElement
, xAttrList
, rProperty
, rProperties
);
313 case CTF_SC_HYPERLINK
:
316 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
318 if ( aIter
.getToken() == XML_ELEMENT(XLINK
, XML_HREF
) )
319 sURL
= aIter
.toString();
321 XMLOFF_WARN_UNKNOWN("sc", aIter
);
323 if ( !sURL
.isEmpty() )
325 XMLPropertyState
aProp(rProperty
);
326 aProp
.maValue
<<= sURL
;
327 rProperties
.push_back( aProp
);
334 return SvXMLPropertySetContext::createFastChildContext(nElement
, xAttrList
, rProperties
, rProperty
);
339 class ScXMLMapContext
: public SvXMLImportContext
341 OUString msApplyStyle
;
342 OUString msCondition
;
345 ScXMLImport
& GetScImport() { return static_cast<ScXMLImport
&>(GetImport()); }
349 SvXMLImport
& rImport
, sal_Int32 nElement
,
350 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
);
352 ScCondFormatEntry
* CreateConditionEntry();
357 ScXMLMapContext::ScXMLMapContext(SvXMLImport
& rImport
, sal_Int32
/*nElement*/,
358 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
359 : SvXMLImportContext( rImport
)
361 for( auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
) )
363 OUString sValue
= aIter
.toString();
364 switch (aIter
.getToken())
366 case XML_ELEMENT(STYLE
, XML_CONDITION
):
367 msCondition
= sValue
;
369 case XML_ELEMENT(STYLE
, XML_APPLY_STYLE_NAME
):
370 msApplyStyle
= GetImport().GetStyleDisplayName( XmlStyleFamily::TABLE_CELL
, sValue
);
372 case XML_ELEMENT(STYLE
, XML_BASE_CELL_ADDRESS
):
376 XMLOFF_WARN_UNKNOWN("sc", aIter
);
381 ScCondFormatEntry
* ScXMLMapContext::CreateConditionEntry()
383 OUString aCondition
, aConditionNmsp
;
384 FormulaGrammar::Grammar eGrammar
= FormulaGrammar::GRAM_UNSPECIFIED
;
385 GetScImport().ExtractFormulaNamespaceGrammar( aCondition
, aConditionNmsp
, eGrammar
, msCondition
);
386 bool bHasNmsp
= aCondition
.getLength() < msCondition
.getLength();
388 // parse a condition from the attribute string
389 ScXMLConditionParseResult aParseResult
;
390 ScXMLConditionHelper::parseCondition( aParseResult
, aCondition
, 0 );
394 // the attribute does not contain a namespace: try to find a namespace of an external grammar
395 FormulaGrammar::Grammar eNewGrammar
= FormulaGrammar::GRAM_UNSPECIFIED
;
396 GetScImport().ExtractFormulaNamespaceGrammar( aCondition
, aConditionNmsp
, eNewGrammar
, aCondition
, true );
397 if( eNewGrammar
!= FormulaGrammar::GRAM_EXTERNAL
)
398 eGrammar
= eNewGrammar
;
401 ScConditionMode eMode
= ScConditionEntry::GetModeFromApi(aParseResult
.meOperator
);
402 ScDocument
* pDoc
= GetScImport().GetDocument();
405 ScCondFormatEntry
* pEntry
= new ScCondFormatEntry(eMode
, aParseResult
.maOperand1
, aParseResult
.maOperand2
, *pDoc
, ScAddress(), msApplyStyle
,
406 OUString(), OUString(), eGrammar
, eGrammar
);
408 pEntry
->SetSrcString(msBaseCell
);
412 void XMLTableStyleContext::SetAttribute( sal_Int32 nElement
,
413 const OUString
& rValue
)
415 switch(nElement
& TOKEN_MASK
)
417 case XML_DATA_STYLE_NAME
:
418 sDataStyleName
= rValue
;
420 case XML_MASTER_PAGE_NAME
:
424 XMLPropStyleContext::SetAttribute( nElement
, rValue
);
429 XMLTableStyleContext::XMLTableStyleContext( ScXMLImport
& rImport
,
430 XMLTableStylesContext
& rStyles
, XmlStyleFamily nFamily
, bool bDefaultStyle
) :
431 XMLPropStyleContext( rImport
, rStyles
, nFamily
, bDefaultStyle
),
436 mpCondFormat(nullptr),
437 mbDeleteCondFormat(true)
441 XMLTableStyleContext::~XMLTableStyleContext()
443 if(mbDeleteCondFormat
)
447 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLTableStyleContext::createFastChildContext(
449 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
451 css::uno::Reference
< css::xml::sax::XFastContextHandler
> xContext
;
453 if( nElement
== XML_ELEMENT(STYLE
, XML_MAP
) )
456 mpCondFormat
= new ScConditionalFormat( 0, GetScImport().GetDocument() );
457 ScXMLMapContext
* pMapContext
= new ScXMLMapContext(GetImport(), nElement
, xAttrList
);
458 xContext
= pMapContext
;
459 mpCondFormat
->AddEntry(pMapContext
->CreateConditionEntry());
461 else if ( nElement
== XML_ELEMENT(STYLE
, XML_TABLE_CELL_PROPERTIES
) )
463 rtl::Reference
< SvXMLImportPropertyMapper
> xImpPrMap
=
464 GetStyles()->GetImportPropertyMapper(
467 xContext
= new XMLTableCellPropsContext( GetImport(), nElement
,
469 XML_TYPE_PROP_TABLE_CELL
,
475 xContext
= XMLPropStyleContext::createFastChildContext( nElement
, xAttrList
);
479 void XMLTableStyleContext::ApplyCondFormat( const uno::Sequence
<table::CellRangeAddress
>& xCellRanges
)
481 if(!mpCondFormat
|| GetScImport().HasNewCondFormatData())
484 ScRangeList aRangeList
;
485 for(const table::CellRangeAddress
& aAddress
: xCellRanges
)
487 ScRange
aRange( aAddress
.StartColumn
, aAddress
.StartRow
, aAddress
.Sheet
, aAddress
.EndColumn
, aAddress
.EndRow
, aAddress
.Sheet
);
488 aRangeList
.Join( aRange
);
491 ScDocument
* pDoc
= GetScImport().GetDocument();
495 SCTAB nTab
= GetScImport().GetTables().GetCurrentSheet();
496 ScConditionalFormatList
* pFormatList
= pDoc
->GetCondFormList(nTab
);
497 auto itr
= std::find_if(pFormatList
->begin(), pFormatList
->end(),
498 [this](const std::unique_ptr
<ScConditionalFormat
>& rxFormat
) { return rxFormat
->EqualEntries(*mpCondFormat
); });
499 if (itr
!= pFormatList
->end())
501 ScRangeList
& rRangeList
= (*itr
)->GetRangeList();
502 sal_uInt32 nCondId
= (*itr
)->GetKey();
503 size_t n
= aRangeList
.size();
504 for(size_t i
= 0; i
< n
; ++i
)
506 const ScRange
& rRange
= aRangeList
[i
];
507 rRangeList
.Join(rRange
);
510 pDoc
->AddCondFormatData( aRangeList
, nTab
, nCondId
);
514 if(mpCondFormat
&& mbDeleteCondFormat
)
516 sal_uInt32 nIndex
= pDoc
->AddCondFormat(std::unique_ptr
<ScConditionalFormat
>(mpCondFormat
), nTab
);
517 mpCondFormat
->SetKey(nIndex
);
518 mpCondFormat
->SetRange(aRangeList
);
520 pDoc
->AddCondFormatData( aRangeList
, nTab
, nIndex
);
521 mbDeleteCondFormat
= false;
526 void XMLTableStyleContext::FillPropertySet(
527 const uno::Reference
< XPropertySet
> & rPropSet
)
529 if (!IsDefaultStyle())
531 if (GetFamily() == XmlStyleFamily::TABLE_CELL
)
535 AddProperty(CTF_SC_CELLSTYLE
, uno::Any(GetImport().GetStyleDisplayName( XmlStyleFamily::TABLE_CELL
, GetParentName() )));
538 sal_Int32 nNumFmt
= GetNumberFormat();
540 AddProperty(CTF_SC_NUMBERFORMAT
, uno::Any(nNumFmt
));
542 else if (GetFamily() == XmlStyleFamily::TABLE_TABLE
)
544 if (!sPageStyle
.isEmpty())
545 AddProperty(CTF_SC_MASTERPAGENAME
, uno::Any(GetImport().GetStyleDisplayName( XmlStyleFamily::MASTER_PAGE
, sPageStyle
)));
548 XMLPropStyleContext::FillPropertySet(rPropSet
);
551 void XMLTableStyleContext::SetDefaults()
553 if ((GetFamily() == XmlStyleFamily::TABLE_CELL
) && GetScImport().GetScModel())
555 rtl::Reference
<ScModelObj
> xMultiServiceFactory(GetScImport().GetScModel());
556 if (xMultiServiceFactory
.is())
558 uno::Reference
<beans::XPropertySet
> xProperties(xMultiServiceFactory
->createInstance(u
"com.sun.star.sheet.Defaults"_ustr
), uno::UNO_QUERY
);
559 if (xProperties
.is())
560 FillPropertySet(xProperties
);
565 void XMLTableStyleContext::AddProperty(const sal_Int16 nContextID
, const uno::Any
& rValue
)
567 XMLPropertyState
* property
= FindProperty(nContextID
);
569 property
->mnIndex
= -1; // #i46996# remove old property, so it isn't double
570 sal_Int32
nIndex(pStyles
->GetIndex(nContextID
));
571 OSL_ENSURE(nIndex
!= -1, "Property not found in Map");
572 XMLPropertyState
aPropState(nIndex
, rValue
);
573 GetProperties().push_back(aPropState
); // has to be inserted in a sort order later
576 XMLPropertyState
* XMLTableStyleContext::FindProperty(const sal_Int16 nContextID
)
578 XMLPropertyState
* pRet
= nullptr;
579 rtl::Reference
< XMLPropertySetMapper
> xPrMap
;
580 rtl::Reference
< SvXMLImportPropertyMapper
> xImpPrMap
=
581 pStyles
->GetImportPropertyMapper( GetFamily() );
582 OSL_ENSURE( xImpPrMap
.is(), "There is the import prop mapper" );
584 xPrMap
= xImpPrMap
->getPropertySetMapper();
587 auto aIter
= std::find_if(GetProperties().begin(), GetProperties().end(),
588 [&xPrMap
, &nContextID
](const XMLPropertyState
& rProp
) {
589 return rProp
.mnIndex
!= -1 && xPrMap
->GetEntryContextId(rProp
.mnIndex
) == nContextID
;
591 if (aIter
!= GetProperties().end())
597 sal_Int32
XMLTableStyleContext::GetNumberFormat()
599 if (nNumberFormat
< 0 && !sDataStyleName
.isEmpty())
601 const SvXMLNumFormatContext
* pStyle
= static_cast<const SvXMLNumFormatContext
*>(
602 pStyles
->FindStyleChildContext(XmlStyleFamily::DATA_STYLE
, sDataStyleName
, true));
606 XMLTableStylesContext
* pMyStyles
= static_cast<XMLTableStylesContext
*>(GetScImport().GetStyles());
608 pStyle
= static_cast<const SvXMLNumFormatContext
*>(
609 pMyStyles
->FindStyleChildContext(XmlStyleFamily::DATA_STYLE
, sDataStyleName
, true));
612 OSL_FAIL("not possible to get style");
616 nNumberFormat
= const_cast<SvXMLNumFormatContext
*>(pStyle
)->GetKey();
618 return nNumberFormat
;
621 SvXMLStyleContext
*XMLTableStylesContext::CreateStyleStyleChildContext(
622 XmlStyleFamily nFamily
, sal_Int32 nElement
,
623 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
625 SvXMLStyleContext
*pStyle
;
626 // use own wrapper for text and paragraph, to record style usage
627 if (nFamily
== XmlStyleFamily::TEXT_PARAGRAPH
|| nFamily
== XmlStyleFamily::TEXT_TEXT
)
628 pStyle
= new ScCellTextStyleContext( GetImport(),*this, nFamily
);
629 else if (nFamily
== XmlStyleFamily::SD_GRAPHICS_ID
)
630 pStyle
= new ScShapeStyleContext( GetImport(), *this, nFamily
);
632 pStyle
= SvXMLStylesContext::CreateStyleStyleChildContext(
633 nFamily
, nElement
, xAttrList
);
639 case XmlStyleFamily::TABLE_CELL
:
640 case XmlStyleFamily::TABLE_COLUMN
:
641 case XmlStyleFamily::TABLE_ROW
:
642 case XmlStyleFamily::TABLE_TABLE
:
643 pStyle
= new XMLTableStyleContext( GetScImport(), *this, nFamily
);
652 SvXMLStyleContext
*XMLTableStylesContext::CreateDefaultStyleStyleChildContext(
653 XmlStyleFamily nFamily
, sal_Int32 nElement
,
654 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
656 SvXMLStyleContext
*pStyle(SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily
, nElement
,
662 case XmlStyleFamily::TABLE_CELL
:
663 pStyle
= new XMLTableStyleContext( GetScImport(), *this, nFamily
, true);
665 case XmlStyleFamily::SD_GRAPHICS_ID
:
666 pStyle
= new XMLGraphicsDefaultStyle( GetScImport(), *this);
675 constexpr OUStringLiteral
gsCellStyleServiceName(u
"com.sun.star.style.CellStyle");
676 constexpr OUStringLiteral
gsGraphicStyleServiceName(u
"com.sun.star.style.GraphicStyle");
678 XMLTableStylesContext::XMLTableStylesContext( SvXMLImport
& rImport
,
679 const bool bTempAutoStyles
)
680 : SvXMLStylesContext( rImport
)
681 , nNumberFormatIndex(-1)
682 , nConditionalFormatIndex(-1)
683 , nCellStyleIndex(-1)
684 , nMasterPageNameIndex(-1)
685 , bAutoStyles(bTempAutoStyles
)
689 XMLTableStylesContext::~XMLTableStylesContext()
693 void XMLTableStylesContext::endFastElement(sal_Int32
)
696 GetImport().GetTextImport()->SetAutoStyles( this );
698 GetScImport().InsertStyles();
701 rtl::Reference
< SvXMLImportPropertyMapper
>
702 XMLTableStylesContext::GetImportPropertyMapper(
703 XmlStyleFamily nFamily
) const
705 rtl::Reference
< SvXMLImportPropertyMapper
> xMapper(SvXMLStylesContext::GetImportPropertyMapper(nFamily
));
711 case XmlStyleFamily::TABLE_CELL
:
713 if( !xCellImpPropMapper
.is() )
715 const_cast<XMLTableStylesContext
*>(this)->xCellImpPropMapper
=
716 new ScXMLCellImportPropertyMapper( GetScImport().GetCellStylesPropertySetMapper(), const_cast<SvXMLImport
&>(GetImport()) );
717 xCellImpPropMapper
->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(const_cast<SvXMLImport
&>(GetImport())));
719 xMapper
= xCellImpPropMapper
;
722 case XmlStyleFamily::TABLE_COLUMN
:
724 if( !xColumnImpPropMapper
.is() )
725 const_cast<XMLTableStylesContext
*>(this)->xColumnImpPropMapper
=
726 new SvXMLImportPropertyMapper( GetScImport().GetColumnStylesPropertySetMapper(), const_cast<SvXMLImport
&>(GetImport()) );
727 xMapper
= xColumnImpPropMapper
;
730 case XmlStyleFamily::TABLE_ROW
:
732 if( !xRowImpPropMapper
.is() )
733 const_cast<XMLTableStylesContext
*>(this)->xRowImpPropMapper
=
734 new ScXMLRowImportPropertyMapper( GetScImport().GetRowStylesPropertySetMapper(), const_cast<SvXMLImport
&>(GetImport()) );
735 xMapper
= xRowImpPropMapper
;
738 case XmlStyleFamily::TABLE_TABLE
:
740 if( !xTableImpPropMapper
.is() )
741 const_cast<XMLTableStylesContext
*>(this)->xTableImpPropMapper
=
742 new SvXMLImportPropertyMapper( GetScImport().GetTableStylesPropertySetMapper(), const_cast<SvXMLImport
&>(GetImport()) );
743 xMapper
= xTableImpPropMapper
;
753 uno::Reference
< XNameContainer
>
754 XMLTableStylesContext::GetStylesContainer( XmlStyleFamily nFamily
) const
756 uno::Reference
< XNameContainer
> xStyles(SvXMLStylesContext::GetStylesContainer(nFamily
));
762 case XmlStyleFamily::TABLE_TABLE
:
764 if( xTableStyles
.is() )
765 xStyles
.set(xTableStyles
);
767 sName
= "TableStyles";
770 case XmlStyleFamily::TABLE_CELL
:
772 if( xCellStyles
.is() )
773 xStyles
.set(xCellStyles
);
775 sName
= "CellStyles";
778 case XmlStyleFamily::TABLE_COLUMN
:
780 if( xColumnStyles
.is() )
781 xStyles
.set(xColumnStyles
);
783 sName
= "ColumnStyles";
786 case XmlStyleFamily::TABLE_ROW
:
788 if( xRowStyles
.is() )
789 xStyles
.set(xRowStyles
);
794 case XmlStyleFamily::SD_GRAPHICS_ID
:
796 if( xGraphicStyles
.is() )
797 xStyles
.set(xGraphicStyles
);
799 sName
= "GraphicStyles";
804 if( !xStyles
.is() && !sName
.isEmpty() && GetScImport().GetModel().is() )
806 ScModelObj
* xFamiliesSupp( GetScImport().GetScModel() );
807 uno::Reference
< XNameAccess
> xFamilies(xFamiliesSupp
->getStyleFamilies());
811 xStyles
.set(xFamilies
->getByName( sName
), uno::UNO_QUERY
);
813 catch ( uno::Exception
& )
815 // #i97680# Named table/column/row styles aren't supported, getByName will throw an exception.
816 // For better interoperability, these styles should then be handled as automatic styles.
817 // For now, NULL is returned (and the style is ignored).
821 case XmlStyleFamily::TABLE_TABLE
:
822 const_cast<XMLTableStylesContext
*>(this)->xTableStyles
.set(xStyles
);
824 case XmlStyleFamily::TABLE_CELL
:
825 const_cast<XMLTableStylesContext
*>(this)->xCellStyles
.set(xStyles
);
827 case XmlStyleFamily::TABLE_COLUMN
:
828 const_cast<XMLTableStylesContext
*>(this)->xColumnStyles
.set(xStyles
);
830 case XmlStyleFamily::TABLE_ROW
:
831 const_cast<XMLTableStylesContext
*>(this)->xRowStyles
.set(xStyles
);
833 case XmlStyleFamily::SD_GRAPHICS_ID
:
834 const_cast<XMLTableStylesContext
*>(this)->xGraphicStyles
.set(xStyles
);
844 OUString
XMLTableStylesContext::GetServiceName( XmlStyleFamily nFamily
) const
846 OUString
sServiceName(SvXMLStylesContext::GetServiceName(nFamily
));
847 if (sServiceName
.isEmpty())
851 case XmlStyleFamily::TABLE_COLUMN
:
852 sServiceName
= XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME
;
854 case XmlStyleFamily::TABLE_ROW
:
855 sServiceName
= XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME
;
857 case XmlStyleFamily::TABLE_CELL
:
858 sServiceName
= gsCellStyleServiceName
;
860 case XmlStyleFamily::TABLE_TABLE
:
861 sServiceName
= XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME
;
863 case XmlStyleFamily::SD_GRAPHICS_ID
:
864 sServiceName
= gsGraphicStyleServiceName
;
872 sal_Int32
XMLTableStylesContext::GetIndex(const sal_Int16 nContextID
)
874 if (nContextID
== CTF_SC_CELLSTYLE
)
876 if (nCellStyleIndex
== -1)
878 GetImportPropertyMapper(XmlStyleFamily::TABLE_CELL
)->getPropertySetMapper()->FindEntryIndex(nContextID
);
879 return nCellStyleIndex
;
881 else if (nContextID
== CTF_SC_NUMBERFORMAT
)
883 if (nNumberFormatIndex
== -1)
885 GetImportPropertyMapper(XmlStyleFamily::TABLE_CELL
)->getPropertySetMapper()->FindEntryIndex(nContextID
);
886 return nNumberFormatIndex
;
888 else if (nContextID
== CTF_SC_IMPORT_MAP
)
890 if (nConditionalFormatIndex
== -1)
891 nConditionalFormatIndex
=
892 GetImportPropertyMapper(XmlStyleFamily::TABLE_CELL
)->getPropertySetMapper()->FindEntryIndex(nContextID
);
893 return nConditionalFormatIndex
;
895 else if (nContextID
== CTF_SC_MASTERPAGENAME
)
897 if (nMasterPageNameIndex
== -1)
898 nMasterPageNameIndex
=
899 GetImportPropertyMapper(XmlStyleFamily::TABLE_TABLE
)->getPropertySetMapper()->FindEntryIndex(nContextID
);
900 return nMasterPageNameIndex
;
907 bool ScXMLMasterStylesContext::InsertStyleFamily( XmlStyleFamily
) const
912 ScXMLMasterStylesContext::ScXMLMasterStylesContext( SvXMLImport
& rImport
) :
913 SvXMLStylesContext( rImport
)
917 ScXMLMasterStylesContext::~ScXMLMasterStylesContext()
921 SvXMLStyleContext
*ScXMLMasterStylesContext::CreateStyleChildContext(
923 const uno::Reference
< XFastAttributeList
> & xAttrList
)
925 SvXMLStyleContext
*pContext(nullptr);
927 if( nElement
== XML_ELEMENT(STYLE
, XML_MASTER_PAGE
) &&
928 InsertStyleFamily( XmlStyleFamily::MASTER_PAGE
) )
929 pContext
= new ScMasterPageContext(
930 GetImport(), nElement
, xAttrList
,
931 !GetImport().GetTextImport()->IsInsertMode() );
933 // any other style will be ignored here!
938 SvXMLStyleContext
*ScXMLMasterStylesContext::CreateStyleStyleChildContext(
939 XmlStyleFamily
/* nFamily */,
940 sal_Int32
/* nElement */,
941 const uno::Reference
< XFastAttributeList
> & /* xAttrList */ )
946 void ScXMLMasterStylesContext::endFastElement(sal_Int32
)
952 ScMasterPageContext::ScMasterPageContext( SvXMLImport
& rImport
,
954 const uno::Reference
< XFastAttributeList
> & xAttrList
,
956 XMLTextMasterPageContext( rImport
, nElement
, xAttrList
, bOverwrite
),
957 bContainsRightHeader(false),
958 bContainsRightFooter(false)
962 ScMasterPageContext::~ScMasterPageContext()
966 SvXMLImportContext
*ScMasterPageContext::CreateHeaderFooterContext(
968 const css::uno::Reference
< css::xml::sax::XFastAttributeList
> & xAttrList
,
976 bContainsRightFooter
= true;
978 bContainsRightHeader
= true;
981 xPropSet
.set(GetStyle(), UNO_QUERY
);
982 return new XMLTableHeaderFooterContext( GetImport(),
986 bFooter
, bLeft
, bFirst
);
989 void ScMasterPageContext::ClearContent(const OUString
& rContent
)
992 xPropSet
.set(GetStyle(), UNO_QUERY
);
996 uno::Reference
< sheet::XHeaderFooterContent
> xHeaderFooterContent(xPropSet
->getPropertyValue( rContent
), uno::UNO_QUERY
);
997 if (xHeaderFooterContent
.is())
999 xHeaderFooterContent
->getLeftText()->setString(u
""_ustr
);
1000 xHeaderFooterContent
->getCenterText()->setString(u
""_ustr
);
1001 xHeaderFooterContent
->getRightText()->setString(u
""_ustr
);
1002 xPropSet
->setPropertyValue( rContent
, uno::Any(xHeaderFooterContent
) );
1007 void ScMasterPageContext::Finish( bool bOverwrite
)
1009 XMLTextMasterPageContext::Finish(bOverwrite
);
1010 if (!bContainsRightFooter
)
1011 ClearContent(SC_UNO_PAGE_RIGHTFTRCON
);
1012 if (!bContainsRightHeader
)
1013 ClearContent(SC_UNO_PAGE_RIGHTHDRCON
);
1016 ScCellTextStyleContext::ScCellTextStyleContext( SvXMLImport
& rImport
,
1017 SvXMLStylesContext
& rStyles
, XmlStyleFamily nFamily
) :
1018 XMLTextStyleContext( rImport
, rStyles
, nFamily
, false/*bDefaultStyle*/ ),
1023 ScCellTextStyleContext::~ScCellTextStyleContext()
1027 void ScCellTextStyleContext::FillPropertySet( const uno::Reference
<beans::XPropertySet
>& xPropSet
)
1029 XMLTextStyleContext::FillPropertySet( xPropSet
);
1031 ScXMLImport
& rXMLImport
= GetScImport();
1033 ScCellTextCursor
* pCellImp
= comphelper::getFromUnoTunnel
<ScCellTextCursor
>( xPropSet
);
1036 ScAddress aPos
= pCellImp
->GetCellObj().GetPosition();
1037 if ( aPos
.Tab() != nLastSheet
)
1039 ESelection aSel
= pCellImp
->GetSelection();
1041 ScSheetSaveData
* pSheetData
= GetScImport().GetScModel()->GetSheetSaveData();
1042 pSheetData
->AddTextStyle( GetName(), aPos
, aSel
);
1044 nLastSheet
= aPos
.Tab();
1047 else if ( rXMLImport
.GetTables().GetCurrentSheet() != nLastSheet
)
1049 ScDrawTextCursor
* pDrawImp
= comphelper::getFromUnoTunnel
<ScDrawTextCursor
>( xPropSet
);
1052 XMLTableShapeImportHelper
* pTableShapeImport
= static_cast<XMLTableShapeImportHelper
*>(GetScImport().GetShapeImport().get());
1053 ScXMLAnnotationContext
* pAnnotationContext
= pTableShapeImport
->GetAnnotationContext();
1054 if (pAnnotationContext
)
1056 pAnnotationContext
->AddContentStyle( GetFamily(), GetName(), pDrawImp
->GetSelection() );
1057 nLastSheet
= rXMLImport
.GetTables().GetCurrentSheet();
1061 // if it's a different shape, BlockSheet is called from XMLTableShapeImportHelper::finishShape
1062 // formatted text in page headers/footers can be ignored
1066 void ScShapeStyleContext::Finish(bool bOverwrite
)
1068 // set parent styles
1069 XMLPropStyleContext::Finish(bOverwrite
);
1072 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */