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/nmspmap.hxx>
22 #include <xmloff/xmlnmspe.hxx>
23 #include <xmloff/xmlimppr.hxx>
24 #include <xmloff/families.hxx>
25 #include <xmloff/xmlnumfi.hxx>
26 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
29 #include <com/sun/star/container/XNameContainer.hpp>
30 #include <com/sun/star/table/BorderLine2.hpp>
31 #include <comphelper/extract.hxx>
32 #include <xmloff/xmlprcon.hxx>
33 #include <xmloff/xmluconv.hxx>
34 #include "XMLTableHeaderFooterContext.hxx"
35 #include "XMLConverter.hxx"
36 #include "XMLTableShapeImportHelper.hxx"
37 #include "sheetdata.hxx"
38 #include "xmlannoi.hxx"
39 #include "textuno.hxx"
40 #include "cellsuno.hxx"
43 #include "unonames.hxx"
44 #include "document.hxx"
45 #include "conditio.hxx"
46 #include <svl/intitem.hxx>
47 #include "rangelst.hxx"
48 #include "rangeutl.hxx"
49 #include "docfunc.hxx"
50 #include "markdata.hxx"
51 #include "docpool.hxx"
52 #include "scitems.hxx"
53 #include "patattr.hxx"
55 #define XML_LINE_LEFT 0
56 #define XML_LINE_RIGHT 1
57 #define XML_LINE_TOP 2
58 #define XML_LINE_BOTTOM 3
60 #define XML_LINE_TLBR 0
61 #define XML_LINE_BLTR 1
63 using namespace ::com::sun::star
;
64 using namespace ::com::sun::star::xml::sax
;
65 using namespace ::com::sun::star::style
;
66 using namespace ::com::sun::star::frame
;
67 using namespace ::com::sun::star::beans
;
68 using namespace ::com::sun::star::container
;
69 using namespace xmloff::token
;
70 using namespace ::formula
;
72 using com::sun::star::uno::Reference
;
73 using com::sun::star::uno::UNO_QUERY
;
75 ScXMLCellImportPropertyMapper::ScXMLCellImportPropertyMapper(
76 const rtl::Reference
< XMLPropertySetMapper
>& rMapper
,
77 SvXMLImport
& rImportP
) :
78 SvXMLImportPropertyMapper( rMapper
, rImportP
)
82 ScXMLCellImportPropertyMapper::~ScXMLCellImportPropertyMapper()
86 void ScXMLCellImportPropertyMapper::finished(::std::vector
< XMLPropertyState
>& rProperties
, sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) const
88 static const sal_Int16 aPaddingCTF
[4] = { CTF_SC_LEFTPADDING
, CTF_SC_RIGHTPADDING
,
89 CTF_SC_TOPPADDING
, CTF_SC_BOTTOMPADDING
};
90 static const sal_Int16 aBorderCTF
[4] = { CTF_SC_LEFTBORDER
, CTF_SC_RIGHTBORDER
,
91 CTF_SC_TOPBORDER
, CTF_SC_BOTTOMBORDER
};
93 SvXMLImportPropertyMapper::finished(rProperties
, nStartIndex
, nEndIndex
);
94 XMLPropertyState
* pAllPaddingProperty(NULL
);
95 XMLPropertyState
* pPadding
[4] = { NULL
, NULL
, NULL
, NULL
};
96 XMLPropertyState
* pNewPadding
[4] = { NULL
, NULL
, NULL
, NULL
};
97 XMLPropertyState
* pAllBorderProperty
= NULL
;
98 XMLPropertyState
* pBorders
[4] = { NULL
, NULL
, NULL
, NULL
};
99 XMLPropertyState
* pNewBorders
[4] = { NULL
, NULL
, NULL
, NULL
};
100 XMLPropertyState
* pAllBorderWidthProperty
= NULL
;
101 XMLPropertyState
* pBorderWidths
[4] = { NULL
, NULL
, NULL
, NULL
};
102 XMLPropertyState
* pDiagBorders
[2] = { 0 };
103 XMLPropertyState
* pOldDiagBorderWidths
[2] = { 0 }; // old attribute names without "s"
104 XMLPropertyState
* pDiagBorderWidths
[2] = { 0 };
106 ::std::vector
< XMLPropertyState
>::iterator
endproperty(rProperties
.end());
107 for (::std::vector
< XMLPropertyState
>::iterator aIter
= rProperties
.begin();
108 aIter
!= endproperty
; ++aIter
)
110 XMLPropertyState
*property
= &(*aIter
);
111 if (property
->mnIndex
!= -1)
113 sal_Int16 nContextID
= getPropertySetMapper()->GetEntryContextId(property
->mnIndex
);
116 case CTF_SC_ALLPADDING
: pAllPaddingProperty
= property
; break;
117 case CTF_SC_LEFTPADDING
: pPadding
[XML_LINE_LEFT
] = property
; break;
118 case CTF_SC_RIGHTPADDING
: pPadding
[XML_LINE_RIGHT
] = property
; break;
119 case CTF_SC_TOPPADDING
: pPadding
[XML_LINE_TOP
] = property
; break;
120 case CTF_SC_BOTTOMPADDING
: pPadding
[XML_LINE_BOTTOM
] = property
; break;
121 case CTF_SC_ALLBORDER
: pAllBorderProperty
= property
; break;
122 case CTF_SC_LEFTBORDER
: pBorders
[XML_LINE_LEFT
] = property
; break;
123 case CTF_SC_RIGHTBORDER
: pBorders
[XML_LINE_RIGHT
] = property
; break;
124 case CTF_SC_TOPBORDER
: pBorders
[XML_LINE_TOP
] = property
; break;
125 case CTF_SC_BOTTOMBORDER
: pBorders
[XML_LINE_BOTTOM
] = property
; break;
126 case CTF_SC_ALLBORDERWIDTH
: pAllBorderWidthProperty
= property
; break;
127 case CTF_SC_LEFTBORDERWIDTH
: pBorderWidths
[XML_LINE_LEFT
] = property
; break;
128 case CTF_SC_RIGHTBORDERWIDTH
: pBorderWidths
[XML_LINE_RIGHT
] = property
; break;
129 case CTF_SC_TOPBORDERWIDTH
: pBorderWidths
[XML_LINE_TOP
] = property
; break;
130 case CTF_SC_BOTTOMBORDERWIDTH
: pBorderWidths
[XML_LINE_BOTTOM
] = property
; break;
131 case CTF_SC_DIAGONALTLBR
: pDiagBorders
[XML_LINE_TLBR
] = property
; break;
132 case CTF_SC_DIAGONALBLTR
: pDiagBorders
[XML_LINE_BLTR
] = property
; break;
133 case CTF_SC_DIAGONALTLBRWIDTH
: pOldDiagBorderWidths
[XML_LINE_TLBR
] = property
; break;
134 case CTF_SC_DIAGONALTLBRWIDTHS
: pDiagBorderWidths
[XML_LINE_TLBR
] = property
; break;
135 case CTF_SC_DIAGONALBLTRWIDTH
: pOldDiagBorderWidths
[XML_LINE_BLTR
] = property
; break;
136 case CTF_SC_DIAGONALBLTRWIDTHS
: pDiagBorderWidths
[XML_LINE_BLTR
] = property
; break;
142 // #i27594#; copy Value, but don't insert
143 if (pAllBorderWidthProperty
)
144 pAllBorderWidthProperty
->mnIndex
= -1;
145 if (pAllBorderProperty
)
146 pAllBorderProperty
->mnIndex
= -1;
147 if (pAllPaddingProperty
)
148 pAllPaddingProperty
->mnIndex
= -1;
150 for (i
= 0; i
< 4; ++i
)
152 if (pAllPaddingProperty
&& !pPadding
[i
])
153 pNewPadding
[i
] = new XMLPropertyState(maPropMapper
->FindEntryIndex(aPaddingCTF
[i
]), pAllPaddingProperty
->maValue
);
154 if (pAllBorderProperty
&& !pBorders
[i
])
156 pNewBorders
[i
] = new XMLPropertyState(maPropMapper
->FindEntryIndex(aBorderCTF
[i
]), pAllBorderProperty
->maValue
);
157 pBorders
[i
] = pNewBorders
[i
];
159 if( !pBorderWidths
[i
] )
160 pBorderWidths
[i
] = pAllBorderWidthProperty
;
162 pBorderWidths
[i
]->mnIndex
= -1;
165 table::BorderLine2 aBorderLine
;
166 pBorders
[i
]->maValue
>>= aBorderLine
;
167 if( pBorderWidths
[i
] )
169 // Merge style:border-line-width values to fo:border values. Do
170 // not override fo:border line width or line style with an
172 table::BorderLine2 aBorderLineWidth
;
173 pBorderWidths
[i
]->maValue
>>= aBorderLineWidth
;
174 aBorderLine
.OuterLineWidth
= aBorderLineWidth
.OuterLineWidth
;
175 aBorderLine
.InnerLineWidth
= aBorderLineWidth
.InnerLineWidth
;
176 aBorderLine
.LineDistance
= aBorderLineWidth
.LineDistance
;
177 pBorders
[i
]->maValue
<<= aBorderLine
;
181 for( i
= 0; i
< 2; ++i
)
183 if( pDiagBorders
[i
] && ( pDiagBorderWidths
[i
] || pOldDiagBorderWidths
[i
] ) )
185 table::BorderLine2 aBorderLine
;
186 pDiagBorders
[i
]->maValue
>>= aBorderLine
;
187 table::BorderLine2 aBorderLineWidth
;
188 if (pDiagBorderWidths
[i
])
189 pDiagBorderWidths
[i
]->maValue
>>= aBorderLineWidth
; // prefer new attribute
191 pOldDiagBorderWidths
[i
]->maValue
>>= aBorderLineWidth
;
192 aBorderLine
.OuterLineWidth
= aBorderLineWidth
.OuterLineWidth
;
193 aBorderLine
.InnerLineWidth
= aBorderLineWidth
.InnerLineWidth
;
194 aBorderLine
.LineDistance
= aBorderLineWidth
.LineDistance
;
195 pDiagBorders
[i
]->maValue
<<= aBorderLine
;
196 if (pDiagBorderWidths
[i
])
197 pDiagBorderWidths
[i
]->mnIndex
= -1;
198 if (pOldDiagBorderWidths
[i
])
199 pOldDiagBorderWidths
[i
]->mnIndex
= -1; // reset mnIndex for old and new attribute if both are present
203 for (i
= 0; i
< 4; ++i
)
207 rProperties
.push_back(*pNewPadding
[i
]);
208 delete pNewPadding
[i
];
212 rProperties
.push_back(*pNewBorders
[i
]);
213 delete pNewBorders
[i
];
218 ScXMLRowImportPropertyMapper::ScXMLRowImportPropertyMapper(
219 const rtl::Reference
< XMLPropertySetMapper
>& rMapper
,
220 SvXMLImport
& rImportP
) :
221 SvXMLImportPropertyMapper( rMapper
, rImportP
)
225 ScXMLRowImportPropertyMapper::~ScXMLRowImportPropertyMapper()
229 void ScXMLRowImportPropertyMapper::finished(::std::vector
< XMLPropertyState
>& rProperties
, sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) const
231 SvXMLImportPropertyMapper::finished(rProperties
, nStartIndex
, nEndIndex
);
232 XMLPropertyState
* pHeight(NULL
);
233 XMLPropertyState
* pOptimalHeight(NULL
);
234 XMLPropertyState
* pPageBreak(NULL
);
235 ::std::vector
< XMLPropertyState
>::iterator
endproperty(rProperties
.end());
236 for (::std::vector
< XMLPropertyState
>::iterator aIter
= rProperties
.begin();
237 aIter
!= endproperty
; ++aIter
)
239 XMLPropertyState
* property
= &(*aIter
);
240 if (property
->mnIndex
!= -1)
242 sal_Int16 nContextID
= getPropertySetMapper()->GetEntryContextId(property
->mnIndex
);
245 case CTF_SC_ROWHEIGHT
: pHeight
= property
; break;
246 case CTF_SC_ROWOPTIMALHEIGHT
: pOptimalHeight
= property
; break;
247 case CTF_SC_ROWBREAKBEFORE
: pPageBreak
= property
; break;
253 if(!(::cppu::any2bool(pPageBreak
->maValue
)))
254 pPageBreak
->mnIndex
= -1;
258 if (::cppu::any2bool(pOptimalHeight
->maValue
))
262 // set the stored height, but keep "optimal" flag:
263 // pass the height value as OptimalHeight property (only allowed while loading!)
264 pOptimalHeight
->maValue
= pHeight
->maValue
;
265 pHeight
->mnIndex
= -1;
268 pOptimalHeight
->mnIndex
= -1;
273 rProperties
.push_back(XMLPropertyState(maPropMapper
->FindEntryIndex(CTF_SC_ROWOPTIMALHEIGHT
), css::uno::Any(false)));
275 // don't access pointers to rProperties elements after push_back!
278 class XMLTableCellPropsContext
: public SvXMLPropertySetContext
280 using SvXMLPropertySetContext::CreateChildContext
;
282 XMLTableCellPropsContext(
283 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
284 const OUString
& rLName
,
285 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
287 ::std::vector
< XMLPropertyState
> &rProps
,
288 const rtl::Reference
< SvXMLImportPropertyMapper
> &rMap
);
290 virtual SvXMLImportContext
*CreateChildContext( sal_uInt16 nPrefix
,
291 const OUString
& rLocalName
,
292 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
293 ::std::vector
< XMLPropertyState
> &rProperties
,
294 const XMLPropertyState
& rProp
) SAL_OVERRIDE
;
297 XMLTableCellPropsContext::XMLTableCellPropsContext(
298 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
299 const OUString
& rLName
,
300 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
302 ::std::vector
< XMLPropertyState
> &rProps
,
303 const rtl::Reference
< SvXMLImportPropertyMapper
> &rMap
)
304 : SvXMLPropertySetContext( rImport
, nPrfx
, rLName
, xAttrList
, nFamily
,
309 SvXMLImportContext
* XMLTableCellPropsContext::CreateChildContext( sal_uInt16 nPrefix
,
310 const OUString
& rLocalName
,
311 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
312 ::std::vector
< XMLPropertyState
> &rProperties
,
313 const XMLPropertyState
& rProp
)
315 // no need for a custom context or indeed a SvXMLTokenMap to grab just the
316 // single attribute ( href ) that we are interested in.
317 // still though, we will check namesspaces etc.
318 if ( ( XML_NAMESPACE_STYLE
== nPrefix
) &&
319 IsXMLToken(rLocalName
, XML_HYPERLINK
) )
322 for ( int i
=0; i
<xAttrList
->getLength(); ++i
)
325 OUString sName
= xAttrList
->getNameByIndex(i
);
326 sal_uInt16 nPrfx
= GetImport().GetNamespaceMap().GetKeyByAttrName( sName
,
328 if ( nPrfx
== XML_NAMESPACE_XLINK
)
330 if ( IsXMLToken( aLocalName
, XML_HREF
) )
332 sURL
= xAttrList
->getValueByIndex(i
);
337 if ( !sURL
.isEmpty() )
339 XMLPropertyState
aProp( rProp
);
340 aProp
.maValue
<<= sURL
;
341 rProperties
.push_back( aProp
);
344 return SvXMLPropertySetContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
, rProperties
, rProp
);
347 class ScXMLMapContext
: public SvXMLImportContext
349 OUString msApplyStyle
;
350 OUString msCondition
;
353 ScXMLImport
& GetScImport() { return static_cast<ScXMLImport
&>(GetImport()); }
357 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
358 const OUString
& rLName
,
359 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
360 virtual ~ScXMLMapContext();
362 ScCondFormatEntry
* CreateConditionEntry();
365 ScXMLMapContext::ScXMLMapContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
366 const OUString
& rLName
, const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
367 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
369 sal_Int16
nAttrCount(xAttrList
.is() ? xAttrList
->getLength() : 0);
370 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
372 const OUString
& rAttrName(xAttrList
->getNameByIndex( i
));
374 sal_uInt16
nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLocalName
));
375 const OUString
& rValue(xAttrList
->getValueByIndex( i
));
377 // TODO: use a map here
378 if( XML_NAMESPACE_STYLE
== nPrefix
)
380 if( IsXMLToken(aLocalName
, XML_CONDITION
) )
381 msCondition
= rValue
;
382 else if( IsXMLToken(aLocalName
, XML_APPLY_STYLE_NAME
) )
383 msApplyStyle
= GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TABLE_CELL
, rValue
);
384 else if ( IsXMLToken(aLocalName
, XML_BASE_CELL_ADDRESS
) )
390 ScCondFormatEntry
* ScXMLMapContext::CreateConditionEntry()
392 OUString aCondition
, aConditionNmsp
;
393 FormulaGrammar::Grammar eGrammar
= FormulaGrammar::GRAM_UNSPECIFIED
;
394 GetScImport().ExtractFormulaNamespaceGrammar( aCondition
, aConditionNmsp
, eGrammar
, msCondition
);
395 bool bHasNmsp
= aCondition
.getLength() < msCondition
.getLength();
397 // parse a condition from the attribute string
398 ScXMLConditionParseResult aParseResult
;
399 ScXMLConditionHelper::parseCondition( aParseResult
, aCondition
, 0 );
403 // the attribute does not contain a namespace: try to find a namespace of an external grammar
404 FormulaGrammar::Grammar eNewGrammar
= FormulaGrammar::GRAM_UNSPECIFIED
;
405 GetScImport().ExtractFormulaNamespaceGrammar( aCondition
, aConditionNmsp
, eNewGrammar
, aCondition
, true );
406 if( eNewGrammar
!= FormulaGrammar::GRAM_EXTERNAL
)
407 eGrammar
= eNewGrammar
;
410 ScConditionMode eMode
= ScConditionEntry::GetModeFromApi(aParseResult
.meOperator
);
411 OUString aNmsp1
, aNmsp2
;
412 ScDocument
* pDoc
= GetScImport().GetDocument();
414 ScCondFormatEntry
* pEntry
= new ScCondFormatEntry(eMode
, aParseResult
.maOperand1
, aParseResult
.maOperand2
, pDoc
, ScAddress(), msApplyStyle
,
415 aNmsp1
, aNmsp2
, eGrammar
, eGrammar
);
417 pEntry
->SetSrcString(msBaseCell
);
421 ScXMLMapContext::~ScXMLMapContext()
425 void XMLTableStyleContext::SetAttribute( sal_uInt16 nPrefixKey
,
426 const OUString
& rLocalName
,
427 const OUString
& rValue
)
429 // TODO: use a map here
430 if( IsXMLToken(rLocalName
, XML_DATA_STYLE_NAME
) )
431 sDataStyleName
= rValue
;
432 else if ( IsXMLToken(rLocalName
, XML_MASTER_PAGE_NAME
) )
435 XMLPropStyleContext::SetAttribute( nPrefixKey
, rLocalName
, rValue
);
438 TYPEINIT1( XMLTableStyleContext
, XMLPropStyleContext
);
440 XMLTableStyleContext::XMLTableStyleContext( ScXMLImport
& rImport
,
441 sal_uInt16 nPrfx
, const OUString
& rLName
,
442 const uno::Reference
< XAttributeList
> & xAttrList
,
443 SvXMLStylesContext
& rStyles
, sal_uInt16 nFamily
, bool bDefaultStyle
) :
444 XMLPropStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, rStyles
, nFamily
, bDefaultStyle
),
451 mbDeleteCondFormat(true)
455 XMLTableStyleContext::~XMLTableStyleContext()
457 if(mbDeleteCondFormat
)
461 SvXMLImportContext
*XMLTableStyleContext::CreateChildContext(
463 const OUString
& rLocalName
,
464 const uno::Reference
< XAttributeList
> & xAttrList
)
466 SvXMLImportContext
*pContext(NULL
);
468 if( (XML_NAMESPACE_STYLE
== nPrefix
) &&
469 IsXMLToken(rLocalName
, XML_MAP
) )
472 mpCondFormat
= new ScConditionalFormat( 0, GetScImport().GetDocument() );
473 ScXMLMapContext
* pMapContext
= new ScXMLMapContext(GetImport(), nPrefix
, rLocalName
, xAttrList
);
474 pContext
= pMapContext
;
475 mpCondFormat
->AddEntry(pMapContext
->CreateConditionEntry());
477 else if ( ( XML_NAMESPACE_STYLE
== nPrefix
) &&
478 IsXMLToken(rLocalName
, XML_TABLE_CELL_PROPERTIES
) )
480 rtl::Reference
< SvXMLImportPropertyMapper
> xImpPrMap
=
481 GetStyles()->GetImportPropertyMapper(
484 pContext
= new XMLTableCellPropsContext( GetImport(), nPrefix
,
485 rLocalName
, xAttrList
,
486 XML_TYPE_PROP_TABLE_CELL
,
492 pContext
= XMLPropStyleContext::CreateChildContext( nPrefix
, rLocalName
,
497 void XMLTableStyleContext::ApplyCondFormat( const uno::Sequence
<table::CellRangeAddress
>& xCellRanges
)
499 if(!mpCondFormat
|| GetScImport().HasNewCondFormatData())
502 ScRangeList aRangeList
;
503 sal_Int32 nRanges
= xCellRanges
.getLength();
504 for(sal_Int32 i
= 0; i
< nRanges
; ++i
)
506 table::CellRangeAddress aAddress
= xCellRanges
[i
];
507 ScRange
aRange( aAddress
.StartColumn
, aAddress
.StartRow
, aAddress
.Sheet
, aAddress
.EndColumn
, aAddress
.EndRow
, aAddress
.Sheet
);
508 aRangeList
.Join( aRange
, false );
511 ScDocument
* pDoc
= GetScImport().GetDocument();
512 SCTAB nTab
= GetScImport().GetTables().GetCurrentSheet();
513 ScConditionalFormatList
* pFormatList
= pDoc
->GetCondFormList(nTab
);
514 for(ScConditionalFormatList::iterator itr
= pFormatList
->begin(), itrEnd
= pFormatList
->end();
515 itr
!= itrEnd
; ++itr
)
517 if(itr
->EqualEntries(*mpCondFormat
))
519 ScRangeList
& rRangeList
= itr
->GetRangeList();
520 sal_uInt32 nCondId
= itr
->GetKey();
521 size_t n
= aRangeList
.size();
522 for(size_t i
= 0; i
< n
; ++i
)
524 const ScRange
* pRange
= aRangeList
[i
];
525 rRangeList
.Join(*pRange
);
528 pDoc
->AddCondFormatData( aRangeList
, nTab
, nCondId
);
533 if(mpCondFormat
&& mbDeleteCondFormat
)
535 sal_uLong nIndex
= pDoc
->AddCondFormat(mpCondFormat
, nTab
);
536 mpCondFormat
->SetKey(nIndex
);
537 mpCondFormat
->SetRange(aRangeList
);
539 pDoc
->AddCondFormatData( aRangeList
, nTab
, nIndex
);
540 mbDeleteCondFormat
= false;
545 void XMLTableStyleContext::FillPropertySet(
546 const uno::Reference
< XPropertySet
> & rPropSet
)
548 if (!IsDefaultStyle())
550 if (GetFamily() == XML_STYLE_FAMILY_TABLE_CELL
)
554 AddProperty(CTF_SC_CELLSTYLE
, uno::makeAny(GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TABLE_CELL
, GetParentName() )));
557 sal_Int32 nNumFmt
= GetNumberFormat();
559 AddProperty(CTF_SC_NUMBERFORMAT
, uno::makeAny(nNumFmt
));
561 else if (GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE
)
563 if (!sPageStyle
.isEmpty())
564 AddProperty(CTF_SC_MASTERPAGENAME
, uno::makeAny(GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE
, sPageStyle
)));
567 XMLPropStyleContext::FillPropertySet(rPropSet
);
570 void XMLTableStyleContext::SetDefaults()
572 if ((GetFamily() == XML_STYLE_FAMILY_TABLE_CELL
) && GetImport().GetModel().is())
574 uno::Reference
<lang::XMultiServiceFactory
> xMultiServiceFactory(GetImport().GetModel(), uno::UNO_QUERY
);
575 if (xMultiServiceFactory
.is())
577 uno::Reference
<beans::XPropertySet
> xProperties(xMultiServiceFactory
->createInstance("com.sun.star.sheet.Defaults"), uno::UNO_QUERY
);
578 if (xProperties
.is())
579 FillPropertySet(xProperties
);
584 void XMLTableStyleContext::AddProperty(const sal_Int16 nContextID
, const uno::Any
& rValue
)
586 XMLPropertyState
* property
= FindProperty(nContextID
);
588 property
->mnIndex
= -1; // #i46996# remove old property, so it isn't double
589 sal_Int32
nIndex(static_cast<XMLTableStylesContext
*>(pStyles
)->GetIndex(nContextID
));
590 OSL_ENSURE(nIndex
!= -1, "Property not found in Map");
591 XMLPropertyState
aPropState(nIndex
, rValue
);
592 GetProperties().push_back(aPropState
); // has to be insertes in a sort order later
595 XMLPropertyState
* XMLTableStyleContext::FindProperty(const sal_Int16 nContextID
)
597 XMLPropertyState
* pRet
= NULL
;
598 rtl::Reference
< XMLPropertySetMapper
> xPrMap
;
599 rtl::Reference
< SvXMLImportPropertyMapper
> xImpPrMap
=
600 pStyles
->GetImportPropertyMapper( GetFamily() );
601 OSL_ENSURE( xImpPrMap
.is(), "There is the import prop mapper" );
603 xPrMap
= xImpPrMap
->getPropertySetMapper();
606 ::std::vector
< XMLPropertyState
>::iterator
endproperty(GetProperties().end());
607 ::std::vector
< XMLPropertyState
>::iterator
aIter(GetProperties().begin());
608 while(!pRet
&& aIter
!= endproperty
)
610 XMLPropertyState
* property
= &(*aIter
);
611 if (property
->mnIndex
!= -1 && xPrMap
->GetEntryContextId(property
->mnIndex
) == nContextID
)
622 sal_Int32
XMLTableStyleContext::GetNumberFormat()
624 if (nNumberFormat
< 0 && !sDataStyleName
.isEmpty())
626 const SvXMLNumFormatContext
* pStyle
= static_cast<const SvXMLNumFormatContext
*>(
627 pStyles
->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE
, sDataStyleName
, true));
631 XMLTableStylesContext
* pMyStyles
= static_cast<XMLTableStylesContext
*>(GetScImport().GetStyles());
633 pStyle
= static_cast<const SvXMLNumFormatContext
*>(
634 pMyStyles
->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE
, sDataStyleName
, true));
637 OSL_FAIL("not possible to get style");
641 nNumberFormat
= const_cast<SvXMLNumFormatContext
*>(pStyle
)->GetKey();
643 return nNumberFormat
;
646 SvXMLStyleContext
*XMLTableStylesContext::CreateStyleStyleChildContext(
647 sal_uInt16 nFamily
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
648 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
650 SvXMLStyleContext
*pStyle
;
651 // use own wrapper for text and paragraph, to record style usage
652 if (nFamily
== XML_STYLE_FAMILY_TEXT_PARAGRAPH
|| nFamily
== XML_STYLE_FAMILY_TEXT_TEXT
)
653 pStyle
= new ScCellTextStyleContext( GetImport(), nPrefix
, rLocalName
,
654 xAttrList
, *this, nFamily
);
656 pStyle
= SvXMLStylesContext::CreateStyleStyleChildContext(
657 nFamily
, nPrefix
, rLocalName
, xAttrList
);
663 case XML_STYLE_FAMILY_TABLE_CELL
:
664 case XML_STYLE_FAMILY_TABLE_COLUMN
:
665 case XML_STYLE_FAMILY_TABLE_ROW
:
666 case XML_STYLE_FAMILY_TABLE_TABLE
:
667 pStyle
= new XMLTableStyleContext( GetScImport(), nPrefix
, rLocalName
,
668 xAttrList
, *this, nFamily
);
676 SvXMLStyleContext
*XMLTableStylesContext::CreateDefaultStyleStyleChildContext(
677 sal_uInt16 nFamily
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
678 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
680 SvXMLStyleContext
*pStyle(SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily
, nPrefix
,
687 case XML_STYLE_FAMILY_TABLE_CELL
:
688 pStyle
= new XMLTableStyleContext( GetScImport(), nPrefix
, rLocalName
,
689 xAttrList
, *this, nFamily
, true);
691 case XML_STYLE_FAMILY_SD_GRAPHICS_ID
:
692 pStyle
= new XMLGraphicsDefaultStyle( GetScImport(), nPrefix
, rLocalName
,
701 XMLTableStylesContext::XMLTableStylesContext( SvXMLImport
& rImport
,
703 const OUString
& rLName
,
704 const uno::Reference
< XAttributeList
> & xAttrList
,
705 const bool bTempAutoStyles
) :
706 SvXMLStylesContext( rImport
, nPrfx
, rLName
, xAttrList
),
707 sCellStyleServiceName( OUString( "com.sun.star.style.CellStyle" )),
708 sColumnStyleServiceName( OUString( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME
)),
709 sRowStyleServiceName( OUString( XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME
)),
710 sTableStyleServiceName( OUString( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME
)),
711 nNumberFormatIndex(-1),
712 nConditionalFormatIndex(-1),
714 nMasterPageNameIndex(-1),
715 bAutoStyles(bTempAutoStyles
)
719 XMLTableStylesContext::~XMLTableStylesContext()
723 void XMLTableStylesContext::EndElement()
725 SvXMLStylesContext::EndElement();
727 GetImport().GetTextImport()->SetAutoStyles( this );
729 GetScImport().InsertStyles();
732 rtl::Reference
< SvXMLImportPropertyMapper
>
733 XMLTableStylesContext::GetImportPropertyMapper(
734 sal_uInt16 nFamily
) const
736 rtl::Reference
< SvXMLImportPropertyMapper
> xMapper(SvXMLStylesContext::GetImportPropertyMapper(nFamily
));
742 case XML_STYLE_FAMILY_TABLE_CELL
:
744 if( !xCellImpPropMapper
.is() )
746 const_cast<XMLTableStylesContext
*>(this)->xCellImpPropMapper
=
747 new ScXMLCellImportPropertyMapper( GetScImport().GetCellStylesPropertySetMapper(), const_cast<SvXMLImport
&>(GetImport()) );
748 xCellImpPropMapper
->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(const_cast<SvXMLImport
&>(GetImport())));
750 xMapper
= xCellImpPropMapper
;
753 case XML_STYLE_FAMILY_TABLE_COLUMN
:
755 if( !xColumnImpPropMapper
.is() )
756 const_cast<XMLTableStylesContext
*>(this)->xColumnImpPropMapper
=
757 new SvXMLImportPropertyMapper( GetScImport().GetColumnStylesPropertySetMapper(), const_cast<SvXMLImport
&>(GetImport()) );
758 xMapper
= xColumnImpPropMapper
;
761 case XML_STYLE_FAMILY_TABLE_ROW
:
763 if( !xRowImpPropMapper
.is() )
764 const_cast<XMLTableStylesContext
*>(this)->xRowImpPropMapper
=
765 new ScXMLRowImportPropertyMapper( GetScImport().GetRowStylesPropertySetMapper(), const_cast<SvXMLImport
&>(GetImport()) );
766 xMapper
= xRowImpPropMapper
;
769 case XML_STYLE_FAMILY_TABLE_TABLE
:
771 if( !xTableImpPropMapper
.is() )
772 const_cast<XMLTableStylesContext
*>(this)->xTableImpPropMapper
=
773 new SvXMLImportPropertyMapper( GetScImport().GetTableStylesPropertySetMapper(), const_cast<SvXMLImport
&>(GetImport()) );
774 xMapper
= xTableImpPropMapper
;
783 uno::Reference
< XNameContainer
>
784 XMLTableStylesContext::GetStylesContainer( sal_uInt16 nFamily
) const
786 uno::Reference
< XNameContainer
> xStyles(SvXMLStylesContext::GetStylesContainer(nFamily
));
792 case XML_STYLE_FAMILY_TABLE_TABLE
:
794 if( xTableStyles
.is() )
795 xStyles
.set(xTableStyles
);
798 OUString( OUString( "TableStyles" ));
801 case XML_STYLE_FAMILY_TABLE_CELL
:
803 if( xCellStyles
.is() )
804 xStyles
.set(xCellStyles
);
807 OUString( OUString( "CellStyles" ));
810 case XML_STYLE_FAMILY_TABLE_COLUMN
:
812 if( xColumnStyles
.is() )
813 xStyles
.set(xColumnStyles
);
816 OUString( OUString( "ColumnStyles" ));
819 case XML_STYLE_FAMILY_TABLE_ROW
:
821 if( xRowStyles
.is() )
822 xStyles
.set(xRowStyles
);
825 OUString( OUString( "RowStyles" ));
829 if( !xStyles
.is() && !sName
.isEmpty() && GetScImport().GetModel().is() )
831 uno::Reference
< XStyleFamiliesSupplier
> xFamiliesSupp(
832 GetScImport().GetModel(), UNO_QUERY
);
833 if (xFamiliesSupp
.is())
835 uno::Reference
< XNameAccess
> xFamilies(xFamiliesSupp
->getStyleFamilies());
839 xStyles
.set(xFamilies
->getByName( sName
), uno::UNO_QUERY
);
841 catch ( uno::Exception
& )
843 // #i97680# Named table/column/row styles aren't supported, getByName will throw an exception.
844 // For better interoperability, these styles should then be handled as automatic styles.
845 // For now, NULL is returned (and the style is ignored).
849 case XML_STYLE_FAMILY_TABLE_TABLE
:
850 const_cast<XMLTableStylesContext
*>(this)->xTableStyles
.set(xStyles
);
852 case XML_STYLE_FAMILY_TABLE_CELL
:
853 const_cast<XMLTableStylesContext
*>(this)->xCellStyles
.set(xStyles
);
855 case XML_STYLE_FAMILY_TABLE_COLUMN
:
856 const_cast<XMLTableStylesContext
*>(this)->xColumnStyles
.set(xStyles
);
858 case XML_STYLE_FAMILY_TABLE_ROW
:
859 const_cast<XMLTableStylesContext
*>(this)->xRowStyles
.set(xStyles
);
869 OUString
XMLTableStylesContext::GetServiceName( sal_uInt16 nFamily
) const
871 OUString
sServiceName(SvXMLStylesContext::GetServiceName(nFamily
));
872 if (sServiceName
.isEmpty())
876 case XML_STYLE_FAMILY_TABLE_COLUMN
:
877 sServiceName
= sColumnStyleServiceName
;
879 case XML_STYLE_FAMILY_TABLE_ROW
:
880 sServiceName
= sRowStyleServiceName
;
882 case XML_STYLE_FAMILY_TABLE_CELL
:
883 sServiceName
= sCellStyleServiceName
;
885 case XML_STYLE_FAMILY_TABLE_TABLE
:
886 sServiceName
= sTableStyleServiceName
;
893 sal_Int32
XMLTableStylesContext::GetIndex(const sal_Int16 nContextID
)
895 if (nContextID
== CTF_SC_CELLSTYLE
)
897 if (nCellStyleIndex
== -1)
899 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL
)->getPropertySetMapper()->FindEntryIndex(nContextID
);
900 return nCellStyleIndex
;
902 else if (nContextID
== CTF_SC_NUMBERFORMAT
)
904 if (nNumberFormatIndex
== -1)
906 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL
)->getPropertySetMapper()->FindEntryIndex(nContextID
);
907 return nNumberFormatIndex
;
909 else if (nContextID
== CTF_SC_IMPORT_MAP
)
911 if (nConditionalFormatIndex
== -1)
912 nConditionalFormatIndex
=
913 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL
)->getPropertySetMapper()->FindEntryIndex(nContextID
);
914 return nConditionalFormatIndex
;
916 else if (nContextID
== CTF_SC_MASTERPAGENAME
)
918 if (nMasterPageNameIndex
== -1)
919 nMasterPageNameIndex
=
920 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_TABLE
)->getPropertySetMapper()->FindEntryIndex(nContextID
);
921 return nMasterPageNameIndex
;
927 TYPEINIT1( ScXMLMasterStylesContext
, SvXMLStylesContext
);
929 bool ScXMLMasterStylesContext::InsertStyleFamily( sal_uInt16
) const
934 ScXMLMasterStylesContext::ScXMLMasterStylesContext(
935 SvXMLImport
& rImport
,
936 sal_uInt16 nPrfx
, const OUString
& rLName
,
937 const uno::Reference
< XAttributeList
> & xAttrList
) :
938 SvXMLStylesContext( rImport
, nPrfx
, rLName
, xAttrList
)
942 ScXMLMasterStylesContext::~ScXMLMasterStylesContext()
946 SvXMLStyleContext
*ScXMLMasterStylesContext::CreateStyleChildContext(
948 const OUString
& rLocalName
,
949 const uno::Reference
< XAttributeList
> & xAttrList
)
951 SvXMLStyleContext
*pContext(0);
953 if( (XML_NAMESPACE_STYLE
== nPrefix
) &&
954 IsXMLToken(rLocalName
, XML_MASTER_PAGE
) &&
955 InsertStyleFamily( XML_STYLE_FAMILY_MASTER_PAGE
) )
956 pContext
= new ScMasterPageContext(
957 GetImport(), nPrefix
, rLocalName
, xAttrList
,
958 !GetImport().GetTextImport()->IsInsertMode() );
960 // any other style will be ignored here!
965 SvXMLStyleContext
*ScXMLMasterStylesContext::CreateStyleStyleChildContext(
966 sal_uInt16
/* nFamily */,
967 sal_uInt16
/* nPrefix */,
968 const OUString
& /* rLocalName */,
969 const uno::Reference
< XAttributeList
> & /* xAttrList */ )
974 void ScXMLMasterStylesContext::EndElement()
979 TYPEINIT1( ScMasterPageContext
, XMLTextMasterPageContext
);
981 ScMasterPageContext::ScMasterPageContext( SvXMLImport
& rImport
,
982 sal_uInt16 nPrfx
, const OUString
& rLName
,
983 const uno::Reference
< XAttributeList
> & xAttrList
,
985 XMLTextMasterPageContext( rImport
, nPrfx
, rLName
, xAttrList
, bOverwrite
),
986 bContainsRightHeader(false),
987 bContainsRightFooter(false)
991 ScMasterPageContext::~ScMasterPageContext()
995 SvXMLImportContext
*ScMasterPageContext::CreateChildContext(
997 const OUString
& rLocalName
,
998 const uno::Reference
< XAttributeList
> & xAttrList
)
1000 return XMLTextMasterPageContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
1003 SvXMLImportContext
*ScMasterPageContext::CreateHeaderFooterContext(
1005 const OUString
& rLocalName
,
1006 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
> & xAttrList
,
1009 const bool /*bFirst*/ )
1014 bContainsRightFooter
= true;
1016 bContainsRightHeader
= true;
1019 xPropSet
.set(GetStyle(), UNO_QUERY
);
1020 return new XMLTableHeaderFooterContext( GetImport(),
1021 nPrefix
, rLocalName
,
1027 void ScMasterPageContext::ClearContent(const OUString
& rContent
)
1030 xPropSet
.set(GetStyle(), UNO_QUERY
);
1034 uno::Reference
< sheet::XHeaderFooterContent
> xHeaderFooterContent(xPropSet
->getPropertyValue( rContent
), uno::UNO_QUERY
);
1035 if (xHeaderFooterContent
.is())
1037 xHeaderFooterContent
->getLeftText()->setString(sEmpty
);
1038 xHeaderFooterContent
->getCenterText()->setString(sEmpty
);
1039 xHeaderFooterContent
->getRightText()->setString(sEmpty
);
1040 xPropSet
->setPropertyValue( rContent
, uno::makeAny(xHeaderFooterContent
) );
1045 void ScMasterPageContext::Finish( bool bOverwrite
)
1047 XMLTextMasterPageContext::Finish(bOverwrite
);
1048 if (!bContainsRightFooter
)
1049 ClearContent(OUString(SC_UNO_PAGE_RIGHTFTRCON
));
1050 if (!bContainsRightHeader
)
1051 ClearContent(OUString(SC_UNO_PAGE_RIGHTHDRCON
));
1054 ScCellTextStyleContext::ScCellTextStyleContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
1055 const OUString
& rLName
, const uno::Reference
<xml::sax::XAttributeList
> & xAttrList
,
1056 SvXMLStylesContext
& rStyles
, sal_uInt16 nFamily
, bool bDefaultStyle
) :
1057 XMLTextStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, rStyles
, nFamily
, bDefaultStyle
),
1062 ScCellTextStyleContext::~ScCellTextStyleContext()
1066 void ScCellTextStyleContext::FillPropertySet( const uno::Reference
<beans::XPropertySet
>& xPropSet
)
1068 XMLTextStyleContext::FillPropertySet( xPropSet
);
1070 ScXMLImport
& rXMLImport
= GetScImport();
1072 ScCellTextCursor
* pCellImp
= ScCellTextCursor::getImplementation( xPropSet
);
1075 ScAddress aPos
= pCellImp
->GetCellObj().GetPosition();
1076 if ( aPos
.Tab() != nLastSheet
)
1078 ESelection aSel
= pCellImp
->GetSelection();
1080 ScSheetSaveData
* pSheetData
= ScModelObj::getImplementation(GetImport().GetModel())->GetSheetSaveData();
1081 pSheetData
->AddTextStyle( GetName(), aPos
, aSel
);
1083 nLastSheet
= aPos
.Tab();
1086 else if ( rXMLImport
.GetTables().GetCurrentSheet() != nLastSheet
)
1088 ScDrawTextCursor
* pDrawImp
= ScDrawTextCursor::getImplementation( xPropSet
);
1091 XMLTableShapeImportHelper
* pTableShapeImport
= static_cast<XMLTableShapeImportHelper
*>(GetScImport().GetShapeImport().get());
1092 ScXMLAnnotationContext
* pAnnotationContext
= pTableShapeImport
->GetAnnotationContext();
1093 if (pAnnotationContext
)
1095 pAnnotationContext
->AddContentStyle( GetFamily(), GetName(), pDrawImp
->GetSelection() );
1096 nLastSheet
= rXMLImport
.GetTables().GetCurrentSheet();
1100 // if it's a different shape, BlockSheet is called from XMLTableShapeImportHelper::finishShape
1101 // formatted text in page headers/footers can be ignored
1105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */