xref: /trunk/main/sc/source/filter/xml/xmlstyli.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 #include "xmlstyli.hxx"
29 #include <xmloff/nmspmap.hxx>
30 #include <xmloff/xmlnmspe.hxx>
31 #include <xmloff/xmlimppr.hxx>
32 #include <xmloff/families.hxx>
33 #include <xmloff/xmlnumfi.hxx>
34 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
37 #include <com/sun/star/container/XNameContainer.hpp>
38 #include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
39 #include <com/sun/star/table/BorderLine.hpp>
40 #include <comphelper/extract.hxx>
41 #include <xmloff/xmlprcon.hxx>
42 #include <xmloff/xmluconv.hxx>
43 #include <tools/debug.hxx>
44 #include "XMLTableHeaderFooterContext.hxx"
45 #include "XMLConverter.hxx"
46 #include "XMLTableShapeImportHelper.hxx"
47 #include "sheetdata.hxx"
48 #include "xmlannoi.hxx"
49 #include "textuno.hxx"
50 #include "cellsuno.hxx"
51 
52 #include "docuno.hxx"
53 #include "unonames.hxx"
54 #include "document.hxx"
55 
56 #define XML_LINE_LEFT 0
57 #define XML_LINE_RIGHT 1
58 #define XML_LINE_TOP 2
59 #define XML_LINE_BOTTOM 3
60 
61 #define XML_LINE_TLBR 0
62 #define XML_LINE_BLTR 1
63 
64 using ::rtl::OUString;
65 using namespace ::com::sun::star;
66 using namespace ::com::sun::star::uno;
67 using namespace ::com::sun::star::xml::sax;
68 using namespace ::com::sun::star::style;
69 using namespace ::com::sun::star::frame;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::container;
72 using namespace xmloff::token;
73 //using namespace ::com::sun::star::text;
74 using namespace ::formula;
75 
ScXMLCellImportPropertyMapper(const UniReference<XMLPropertySetMapper> & rMapper,SvXMLImport & rImportP)76 ScXMLCellImportPropertyMapper::ScXMLCellImportPropertyMapper(
77 		const UniReference< XMLPropertySetMapper >& rMapper,
78         SvXMLImport& rImportP) :
79 	SvXMLImportPropertyMapper( rMapper, rImportP )
80 {
81 }
82 
~ScXMLCellImportPropertyMapper()83 ScXMLCellImportPropertyMapper::~ScXMLCellImportPropertyMapper()
84 {
85 }
86 
finished(::std::vector<XMLPropertyState> & rProperties,sal_Int32 nStartIndex,sal_Int32 nEndIndex) const87 void ScXMLCellImportPropertyMapper::finished(::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
88 {
89 	static const sal_Int16 aPaddingCTF[4] = { CTF_SC_LEFTPADDING, CTF_SC_RIGHTPADDING,
90 											CTF_SC_TOPPADDING, CTF_SC_BOTTOMPADDING };
91 	static const sal_Int16 aBorderCTF[4] = { CTF_SC_LEFTBORDER, CTF_SC_RIGHTBORDER,
92 											CTF_SC_TOPBORDER, CTF_SC_BOTTOMBORDER };
93 
94 	SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex);
95 	XMLPropertyState* pAllPaddingProperty(NULL);
96 	XMLPropertyState* pPadding[4] = { NULL, NULL, NULL, NULL };
97 	XMLPropertyState* pNewPadding[4] = { NULL, NULL, NULL, NULL };
98 	XMLPropertyState* pAllBorderProperty = NULL;
99 	XMLPropertyState* pBorders[4] = { NULL, NULL, NULL, NULL };
100 	XMLPropertyState* pNewBorders[4] = { NULL, NULL, NULL, NULL };
101 	XMLPropertyState* pAllBorderWidthProperty = NULL;
102 	XMLPropertyState* pBorderWidths[4] = { NULL, NULL, NULL, NULL };
103     XMLPropertyState* pDiagBorders[2] = { 0 };
104     XMLPropertyState* pOldDiagBorderWidths[2] = { 0 };      // old attribute names without "s"
105     XMLPropertyState* pDiagBorderWidths[2] = { 0 };
106 
107 	::std::vector< XMLPropertyState >::iterator endproperty(rProperties.end());
108 	for (::std::vector< XMLPropertyState >::iterator aIter =  rProperties.begin();
109         aIter != endproperty; ++aIter)
110 	{
111         XMLPropertyState*property = &(*aIter);
112         if (property->mnIndex != -1)
113         {
114 		    sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex);
115 		    switch (nContextID)
116 		    {
117                 case CTF_SC_ALLPADDING                  : pAllPaddingProperty = &*property; break;
118                 case CTF_SC_LEFTPADDING                 : pPadding[XML_LINE_LEFT] = &*property; break;
119                 case CTF_SC_RIGHTPADDING                : pPadding[XML_LINE_RIGHT] = &*property; break;
120                 case CTF_SC_TOPPADDING                  : pPadding[XML_LINE_TOP] = &*property; break;
121                 case CTF_SC_BOTTOMPADDING               : pPadding[XML_LINE_BOTTOM] = &*property; break;
122                 case CTF_SC_ALLBORDER                   : pAllBorderProperty = &*property; break;
123                 case CTF_SC_LEFTBORDER                  : pBorders[XML_LINE_LEFT] = &*property; break;
124                 case CTF_SC_RIGHTBORDER                 : pBorders[XML_LINE_RIGHT] = &*property; break;
125                 case CTF_SC_TOPBORDER                   : pBorders[XML_LINE_TOP] = &*property; break;
126                 case CTF_SC_BOTTOMBORDER                : pBorders[XML_LINE_BOTTOM] = &*property; break;
127                 case CTF_SC_ALLBORDERWIDTH              : pAllBorderWidthProperty = &*property; break;
128                 case CTF_SC_LEFTBORDERWIDTH             : pBorderWidths[XML_LINE_LEFT] = &*property; break;
129                 case CTF_SC_RIGHTBORDERWIDTH            : pBorderWidths[XML_LINE_RIGHT] = &*property; break;
130                 case CTF_SC_TOPBORDERWIDTH              : pBorderWidths[XML_LINE_TOP] = &*property; break;
131                 case CTF_SC_BOTTOMBORDERWIDTH           : pBorderWidths[XML_LINE_BOTTOM] = &*property; break;
132                 case CTF_SC_DIAGONALTLBR                : pDiagBorders[XML_LINE_TLBR] = &*property; break;
133                 case CTF_SC_DIAGONALBLTR                : pDiagBorders[XML_LINE_BLTR] = &*property; break;
134                 case CTF_SC_DIAGONALTLBRWIDTH           : pOldDiagBorderWidths[XML_LINE_TLBR] = &*property; break;
135                 case CTF_SC_DIAGONALTLBRWIDTHS          : pDiagBorderWidths[XML_LINE_TLBR] = &*property; break;
136                 case CTF_SC_DIAGONALBLTRWIDTH           : pOldDiagBorderWidths[XML_LINE_BLTR] = &*property; break;
137                 case CTF_SC_DIAGONALBLTRWIDTHS          : pDiagBorderWidths[XML_LINE_BLTR] = &*property; break;
138 		    }
139         }
140 	}
141 	sal_uInt16 i;
142 
143     // #i27594#; copy Value, but don't insert
144     if (pAllBorderWidthProperty)
145         pAllBorderWidthProperty->mnIndex = -1;
146     if (pAllBorderProperty)
147         pAllBorderProperty->mnIndex = -1;
148     if (pAllPaddingProperty)
149         pAllPaddingProperty->mnIndex = -1;
150 
151     for (i = 0; i < 4; ++i)
152 	{
153 		if (pAllPaddingProperty && !pPadding[i])
154 			pNewPadding[i] = new XMLPropertyState(maPropMapper->FindEntryIndex(aPaddingCTF[i]), pAllPaddingProperty->maValue);
155 		if (pAllBorderProperty && !pBorders[i])
156 		{
157 			pNewBorders[i] = new XMLPropertyState(maPropMapper->FindEntryIndex(aBorderCTF[i]), pAllBorderProperty->maValue);
158 			pBorders[i] = pNewBorders[i];
159 		}
160 		if( !pBorderWidths[i] )
161 			pBorderWidths[i] = pAllBorderWidthProperty;
162 		else
163 			pBorderWidths[i]->mnIndex = -1;
164 		if( pBorders[i] )
165 		{
166 			table::BorderLine aBorderLine;
167 			pBorders[i]->maValue >>= aBorderLine;
168  			if( pBorderWidths[i] )
169 			{
170 				table::BorderLine aBorderLineWidth;
171 				pBorderWidths[i]->maValue >>= aBorderLineWidth;
172 				aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
173 				aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
174 				aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
175 				pBorders[i]->maValue <<= aBorderLine;
176 			}
177 		}
178 	}
179     for( i = 0; i < 2; ++i )
180     {
181         if( pDiagBorders[i] && ( pDiagBorderWidths[i] || pOldDiagBorderWidths[i] ) )
182         {
183             table::BorderLine aBorderLine;
184             pDiagBorders[i]->maValue >>= aBorderLine;
185             table::BorderLine aBorderLineWidth;
186             if (pDiagBorderWidths[i])
187                 pDiagBorderWidths[i]->maValue >>= aBorderLineWidth;     // prefer new attribute
188             else
189                 pOldDiagBorderWidths[i]->maValue >>= aBorderLineWidth;
190             aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
191             aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
192             aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
193             pDiagBorders[i]->maValue <<= aBorderLine;
194             if (pDiagBorderWidths[i])
195                 pDiagBorderWidths[i]->mnIndex = -1;
196             if (pOldDiagBorderWidths[i])
197                 pOldDiagBorderWidths[i]->mnIndex = -1;      // reset mnIndex for old and new attribute if both are present
198         }
199     }
200 
201 	for (i = 0; i < 4; ++i)
202 	{
203 		if (pNewPadding[i])
204 		{
205 			rProperties.push_back(*pNewPadding[i]);
206 			delete pNewPadding[i];
207 		}
208 		if (pNewBorders[i])
209 		{
210 			rProperties.push_back(*pNewBorders[i]);
211 			delete pNewBorders[i];
212 		}
213 	}
214 }
215 
ScXMLRowImportPropertyMapper(const UniReference<XMLPropertySetMapper> & rMapper,SvXMLImport & rImportP)216 ScXMLRowImportPropertyMapper::ScXMLRowImportPropertyMapper(
217 		const UniReference< XMLPropertySetMapper >& rMapper,
218         SvXMLImport& rImportP) :
219 	SvXMLImportPropertyMapper( rMapper, rImportP )
220 {
221 }
222 
~ScXMLRowImportPropertyMapper()223 ScXMLRowImportPropertyMapper::~ScXMLRowImportPropertyMapper()
224 {
225 }
226 
finished(::std::vector<XMLPropertyState> & rProperties,sal_Int32 nStartIndex,sal_Int32 nEndIndex) const227 void ScXMLRowImportPropertyMapper::finished(::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
228 {
229 	SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex);
230 	XMLPropertyState* pHeight(NULL);
231 	XMLPropertyState* pOptimalHeight(NULL);
232 	XMLPropertyState* pPageBreak(NULL);
233 	::std::vector< XMLPropertyState >::iterator endproperty(rProperties.end());
234 	for (::std::vector< XMLPropertyState >::iterator aIter = rProperties.begin();
235         aIter != endproperty; ++aIter)
236 	{
237         XMLPropertyState* property = &(*aIter);
238         if (property->mnIndex != -1)
239         {
240 		    sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex);
241 		    switch (nContextID)
242 		    {
243 			    case CTF_SC_ROWHEIGHT					: pHeight = property; break;
244 			    case CTF_SC_ROWOPTIMALHEIGHT			: pOptimalHeight = property; break;
245 			    case CTF_SC_ROWBREAKBEFORE				: pPageBreak = property; break;
246 		    }
247         }
248 	}
249 	if (pPageBreak)
250 	{
251 		if(!(::cppu::any2bool(pPageBreak->maValue)))
252 			pPageBreak->mnIndex = -1;
253 	}
254 	if (pOptimalHeight)
255 	{
256 		if (::cppu::any2bool(pOptimalHeight->maValue))
257 		{
258 			if (pHeight)
259             {
260                 // set the stored height, but keep "optimal" flag:
261                 // pass the height value as OptimalHeight property (only allowed while loading!)
262                 pOptimalHeight->maValue = pHeight->maValue;
263 				pHeight->mnIndex = -1;
264             }
265             else
266                 pOptimalHeight->mnIndex = -1;
267 		}
268 	}
269 	else if (pHeight)
270 	{
271 		rProperties.push_back(XMLPropertyState(maPropMapper->FindEntryIndex(CTF_SC_ROWOPTIMALHEIGHT), ::cppu::bool2any( sal_False )));
272 	}
273 	// don't access pointers to rProperties elements after push_back!
274 }
275 
276 class ScXMLMapContext : public SvXMLImportContext
277 {
278     rtl::OUString sApplyStyle;
279     rtl::OUString sCondition;
280     rtl::OUString sBaseCell;
281 public:
282 
283 	ScXMLMapContext(
284 			SvXMLImport& rImport, sal_uInt16 nPrfx,
285 			const rtl::OUString& rLName,
286 			const uno::Reference< xml::sax::XAttributeList > & xAttrList );
287 	virtual ~ScXMLMapContext();
288 
GetApplyStyle() const289 	const rtl::OUString& GetApplyStyle() const { return sApplyStyle; }
GetCondition() const290 	const rtl::OUString& GetCondition() const { return sCondition; }
GetBaseCell() const291 	const rtl::OUString& GetBaseCell() const { return sBaseCell; }
292 };
293 
ScXMLMapContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)294 ScXMLMapContext::ScXMLMapContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
295 			const OUString& rLName,	const uno::Reference< xml::sax::XAttributeList > & xAttrList )
296     : SvXMLImportContext( rImport, nPrfx, rLName )
297 {
298 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
299 	for( sal_Int16 i=0; i < nAttrCount; ++i )
300 	{
301 		const OUString& rAttrName(xAttrList->getNameByIndex( i ));
302 		OUString aLocalName;
303 		sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ));
304 		const OUString& rValue(xAttrList->getValueByIndex( i ));
305 
306 		// TODO: use a map here
307 		if( XML_NAMESPACE_STYLE == nPrefix )
308 		{
309 			if( IsXMLToken(aLocalName, XML_CONDITION ) )
310                 sCondition = rValue;
311 			else if( IsXMLToken(aLocalName, XML_APPLY_STYLE_NAME ) )
312 				sApplyStyle = GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TABLE_CELL, rValue);
313 			else if ( IsXMLToken(aLocalName, XML_BASE_CELL_ADDRESS ) )
314 				sBaseCell = rValue;
315 		}
316 	}
317 }
318 
~ScXMLMapContext()319 ScXMLMapContext::~ScXMLMapContext()
320 {
321 }
322 
323 namespace {
324 
325 template< typename Type >
lclAppendProperty(uno::Sequence<beans::PropertyValue> & rProps,const OUString & rPropName,const Type & rValue)326 inline void lclAppendProperty( uno::Sequence< beans::PropertyValue >& rProps, const OUString& rPropName, const Type& rValue )
327 {
328     sal_Int32 nLength = rProps.getLength();
329     rProps.realloc( nLength + 1 );
330     rProps[ nLength ].Name = rPropName;
331     rProps[ nLength ].Value <<= rValue;
332 }
333 
334 } // namespace
335 
SetOperator(uno::Sequence<beans::PropertyValue> & rProps,sheet::ConditionOperator eOp) const336 void XMLTableStyleContext::SetOperator( uno::Sequence< beans::PropertyValue >& rProps, sheet::ConditionOperator eOp ) const
337 {
338     lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_OPERATOR ) ), eOp );
339 }
340 
SetBaseCellAddress(uno::Sequence<beans::PropertyValue> & rProps,const OUString & rBaseCell) const341 void XMLTableStyleContext::SetBaseCellAddress( uno::Sequence< beans::PropertyValue >& rProps, const OUString& rBaseCell ) const
342 {
343     /*  #b4974740# Source position must be set as string, because it may refer
344         to a sheet that hasn't been loaded yet. */
345     lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SOURCESTR ) ), rBaseCell );
346 }
347 
SetStyle(uno::Sequence<beans::PropertyValue> & rProps,const OUString & rApplyStyle) const348 void XMLTableStyleContext::SetStyle( uno::Sequence<beans::PropertyValue>& rProps, const OUString& rApplyStyle ) const
349 {
350     lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_STYLENAME ) ), rApplyStyle );
351 }
352 
SetFormula(uno::Sequence<beans::PropertyValue> & rProps,sal_Int32 nFormulaIdx,const OUString & rFormula,const OUString & rFormulaNmsp,FormulaGrammar::Grammar eGrammar,bool bHasNmsp) const353 void XMLTableStyleContext::SetFormula( uno::Sequence< beans::PropertyValue >& rProps,
354         sal_Int32 nFormulaIdx, const OUString& rFormula, const OUString& rFormulaNmsp,
355         FormulaGrammar::Grammar eGrammar, bool bHasNmsp ) const
356 {
357     OUString aFormula, aFormulaNmsp;
358     FormulaGrammar::Grammar eNewGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
359     if( bHasNmsp )
360     {
361         // the entire attribute contains a namespace: internal namespace not allowed
362         aFormula = rFormula;
363         aFormulaNmsp = rFormulaNmsp;
364         eNewGrammar = eGrammar;
365     }
366     else
367     {
368         // the attribute does not contain a namespace: try to find a namespace of an external grammar
369         GetScImport().ExtractFormulaNamespaceGrammar( aFormula, aFormulaNmsp, eNewGrammar, rFormula, true );
370         if( eNewGrammar != FormulaGrammar::GRAM_EXTERNAL )
371             eNewGrammar = eGrammar;
372     }
373 
374     // add formula, formula namespace, and grammar with appropriate property names
375     sal_Int32 nGrammar = static_cast< sal_Int32 >( eNewGrammar );
376     switch( nFormulaIdx )
377     {
378         case 1:
379             lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULA1 ) ), aFormula );
380             lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULANMSP1 ) ), aFormulaNmsp );
381             lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_GRAMMAR1 ) ), nGrammar );
382         break;
383         case 2:
384             lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULA2 ) ), aFormula );
385             lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FORMULANMSP2 ) ), aFormulaNmsp );
386             lclAppendProperty( rProps, OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_GRAMMAR2 ) ), nGrammar );
387         break;
388         default:
389             OSL_ENSURE( false, "XMLTableStyleContext::SetFormula - invalid formula index" );
390     }
391 }
392 
GetConditionalFormat(uno::Any & aAny,const rtl::OUString & sTempCondition,const rtl::OUString & sApplyStyle,const rtl::OUString & sBaseCell) const393 void XMLTableStyleContext::GetConditionalFormat(uno::Any& aAny,
394 		const rtl::OUString& sTempCondition,
395 		const rtl::OUString& sApplyStyle, const rtl::OUString& sBaseCell) const
396 {
397     if (sTempCondition.getLength() && sApplyStyle.getLength())
398     {
399         uno::Reference<sheet::XSheetConditionalEntries> xConditionalEntries(aAny, uno::UNO_QUERY);
400         if (xConditionalEntries.is())
401         {
402             uno::Sequence<beans::PropertyValue> aProps;
403             if (sBaseCell.getLength())
404                 SetBaseCellAddress(aProps, sBaseCell);
405             SetStyle(aProps, sApplyStyle);
406 
407             // extract leading namespace from condition string
408             OUString aCondition, aConditionNmsp;
409             FormulaGrammar::Grammar eGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
410             GetScImport().ExtractFormulaNamespaceGrammar( aCondition, aConditionNmsp, eGrammar, sTempCondition );
411             bool bHasNmsp = aCondition.getLength() < sTempCondition.getLength();
412 
413             // parse a condition from the attribute string
414             ScXMLConditionParseResult aParseResult;
415             ScXMLConditionHelper::parseCondition( aParseResult, aCondition, 0 );
416 
417             /*  Check the result. A valid value in aParseResult.meToken implies
418                 that the other members of aParseResult are filled with valid
419                 data for that token. */
420             switch( aParseResult.meToken )
421             {
422                 case XML_COND_CELLCONTENT:      // condition is 'cell-content()<operator><expression>'
423                 case XML_COND_ISTRUEFORMULA:    // condition is 'is-true-formula(<expression>)'
424                 case XML_COND_ISBETWEEN:        // condition is 'cell-content-is-between(<expression1>,<expression2>)'
425                 case XML_COND_ISNOTBETWEEN:     // condition is 'cell-content-is-not-between(<expression1>,<expression2>)'
426                     SetOperator( aProps, aParseResult.meOperator );
427                     SetFormula( aProps, 1, aParseResult.maOperand1, aConditionNmsp, eGrammar, bHasNmsp );
428                     SetFormula( aProps, 2, aParseResult.maOperand2, aConditionNmsp, eGrammar, bHasNmsp );
429                 break;
430 
431                 default:;   // unacceptable or unknown condition
432             }
433 
434             xConditionalEntries->addNew( aProps );
435             aAny <<= xConditionalEntries;
436         }
437     }
438 }
439 
SetAttribute(sal_uInt16 nPrefixKey,const OUString & rLocalName,const OUString & rValue)440 void XMLTableStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
441 										const OUString& rLocalName,
442 										const OUString& rValue )
443 {
444 	// TODO: use a map here
445 	if( IsXMLToken(rLocalName, XML_DATA_STYLE_NAME ) )
446 		sDataStyleName = rValue;
447 	else if ( IsXMLToken(rLocalName, XML_MASTER_PAGE_NAME ) )
448 		sPageStyle = rValue;
449 	else
450 		XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
451 }
452 
453 struct ScXMLMapContent
454 {
455     rtl::OUString sCondition;
456     rtl::OUString sApplyStyle;
457     rtl::OUString sBaseCell;
458 };
459 
460 TYPEINIT1( XMLTableStyleContext, XMLPropStyleContext );
461 
XMLTableStyleContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<XAttributeList> & xAttrList,SvXMLStylesContext & rStyles,sal_uInt16 nFamily,sal_Bool bDefaultStyle)462 XMLTableStyleContext::XMLTableStyleContext( ScXMLImport& rImport,
463 		sal_uInt16 nPrfx, const OUString& rLName,
464 		const uno::Reference< XAttributeList > & xAttrList,
465 		SvXMLStylesContext& rStyles, sal_uInt16 nFamily, sal_Bool bDefaultStyle ) :
466 	XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle ),
467 	sDataStyleName(),
468 	sNumberFormat(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberFormat"))),
469 	pStyles(&rStyles),
470 	nNumberFormat(-1),
471     nLastSheet(-1),
472 	bConditionalFormatCreated(sal_False),
473 	bParentSet(sal_False)
474 {
475 }
476 
~XMLTableStyleContext()477 XMLTableStyleContext::~XMLTableStyleContext()
478 {
479 }
480 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<XAttributeList> & xAttrList)481 SvXMLImportContext *XMLTableStyleContext::CreateChildContext(
482 		sal_uInt16 nPrefix,
483 		const OUString& rLocalName,
484 		const uno::Reference< XAttributeList > & xAttrList )
485 {
486 	SvXMLImportContext *pContext(NULL);
487 
488 	if( (XML_NAMESPACE_STYLE == nPrefix) &&
489 		IsXMLToken(rLocalName, XML_MAP ) )
490 	{
491 		pContext = new ScXMLMapContext(GetImport(), nPrefix, rLocalName, xAttrList);
492 
493 		ScXMLMapContent aMap;
494 		aMap.sCondition = ((ScXMLMapContext*)pContext)->GetCondition();
495 		aMap.sApplyStyle = ((ScXMLMapContext*)pContext)->GetApplyStyle();
496 		aMap.sBaseCell = ((ScXMLMapContext*)pContext)->GetBaseCell();
497 		aMaps.push_back(aMap);
498 	}
499 	if (!pContext)
500 		pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
501 														   xAttrList );
502 	return pContext;
503 }
504 
FillPropertySet(const uno::Reference<XPropertySet> & rPropSet)505 void XMLTableStyleContext::FillPropertySet(
506 	const uno::Reference< XPropertySet > & rPropSet )
507 {
508 	if (!IsDefaultStyle())
509 	{
510 		if (GetFamily() == XML_STYLE_FAMILY_TABLE_CELL)
511 		{
512 			if (!bParentSet)
513 			{
514                 AddProperty(CTF_SC_CELLSTYLE, uno::makeAny(GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TABLE_CELL, GetParentName() )));
515 				bParentSet = sal_True;
516 			}
517             sal_Int32 nNumFmt = GetNumberFormat();
518             if (nNumFmt >= 0)
519                 AddProperty(CTF_SC_NUMBERFORMAT, uno::makeAny(nNumFmt));
520 			if (!bConditionalFormatCreated && (aMaps.size() > 0))
521 			{
522 				aConditionalFormat = rPropSet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CONDXML)));
523 				std::vector<ScXMLMapContent>::iterator aItr(aMaps.begin());
524 				std::vector<ScXMLMapContent>::iterator aEndItr(aMaps.end());
525 				while(aItr != aEndItr)
526 				{
527 					//rPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_CONDITIONALFORMAT)),
528 					GetConditionalFormat(aConditionalFormat, aItr->sCondition, aItr->sApplyStyle, aItr->sBaseCell);
529 
530 					++aItr;
531 				}
532 				AddProperty(CTF_SC_IMPORT_MAP, aConditionalFormat);
533 				bConditionalFormatCreated = sal_True;
534 			}
535 		}
536 		else if (GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE)
537 		{
538 			if (sPageStyle.getLength())
539                 AddProperty(CTF_SC_MASTERPAGENAME, uno::makeAny(GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE, sPageStyle )));
540 		}
541 	}
542 	XMLPropStyleContext::FillPropertySet(rPropSet);
543 }
544 
SetDefaults()545 void XMLTableStyleContext::SetDefaults()
546 {
547 	if ((GetFamily() == XML_STYLE_FAMILY_TABLE_CELL) && GetImport().GetModel().is())
548 	{
549 		uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetImport().GetModel(), uno::UNO_QUERY);
550 		if (xMultiServiceFactory.is())
551 		{
552 			uno::Reference <beans::XPropertySet> xProperties(xMultiServiceFactory->createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.Defaults"))), uno::UNO_QUERY);
553 			if (xProperties.is())
554 				FillPropertySet(xProperties);
555 		}
556 	}
557 }
558 
AddProperty(const sal_Int16 nContextID,const uno::Any & rValue)559 void XMLTableStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
560 {
561     XMLPropertyState* property = FindProperty(nContextID);
562     if (property)
563         property->mnIndex = -1; // #i46996# remove old property, so it isn't double
564 	sal_Int32 nIndex(static_cast<XMLTableStylesContext *>(pStyles)->GetIndex(nContextID));
565 	DBG_ASSERT(nIndex != -1, "Property not found in Map");
566 	XMLPropertyState aPropState(nIndex, rValue);
567 	GetProperties().push_back(aPropState); // has to be insertes in a sort order later
568 }
569 
FindProperty(const sal_Int16 nContextID)570 XMLPropertyState* XMLTableStyleContext::FindProperty(const sal_Int16 nContextID)
571 {
572     XMLPropertyState* pRet = NULL;
573 	UniReference < XMLPropertySetMapper > xPrMap;
574 	UniReference < SvXMLImportPropertyMapper > xImpPrMap =
575 		pStyles->GetImportPropertyMapper( GetFamily() );
576 	DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
577 	if( xImpPrMap.is() )
578 		xPrMap = xImpPrMap->getPropertySetMapper();
579 	if( xPrMap.is() )
580 	{
581 	    ::std::vector< XMLPropertyState >::iterator endproperty(GetProperties().end());
582         ::std::vector< XMLPropertyState >::iterator aIter(GetProperties().begin());
583 	    while(!pRet && aIter != endproperty)
584 	    {
585             XMLPropertyState* property = &(*aIter);
586             if (property->mnIndex != -1 && xPrMap->GetEntryContextId(property->mnIndex) == nContextID)
587             {
588                 pRet = property;
589             }
590             else
591                 ++aIter;
592         }
593     }
594     return pRet;
595 }
596 
GetNumberFormat()597 sal_Int32 XMLTableStyleContext::GetNumberFormat()
598 {
599     if (nNumberFormat < 0 && sDataStyleName.getLength())
600     {
601         const SvXMLNumFormatContext* pStyle = static_cast<const SvXMLNumFormatContext*>(
602             pStyles->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, sDataStyleName, sal_True));
603 
604         if (!pStyle)
605         {
606             XMLTableStylesContext* pMyStyles = static_cast<XMLTableStylesContext*>(GetScImport().GetStyles());
607             if (pMyStyles)
608                 pStyle = static_cast<const SvXMLNumFormatContext*>(
609                     pMyStyles->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, sDataStyleName, sal_True));
610             else
611             {
612                 DBG_ERROR("not possible to get style");
613             }
614         }
615         if (pStyle)
616             nNumberFormat = const_cast<SvXMLNumFormatContext*>(pStyle)->GetKey();
617     }
618     return nNumberFormat;
619 }
620 
621 // ----------------------------------------------------------------------------
622 
CreateStyleStyleChildContext(sal_uInt16 nFamily,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)623 SvXMLStyleContext *XMLTableStylesContext::CreateStyleStyleChildContext(
624 		sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
625 		const uno::Reference< xml::sax::XAttributeList > & xAttrList )
626 {
627     SvXMLStyleContext *pStyle;
628     // use own wrapper for text and paragraph, to record style usage
629     if (nFamily == XML_STYLE_FAMILY_TEXT_PARAGRAPH || nFamily == XML_STYLE_FAMILY_TEXT_TEXT)
630         pStyle = new ScCellTextStyleContext( GetImport(), nPrefix, rLocalName,
631                                             xAttrList, *this, nFamily );
632     else
633         pStyle = SvXMLStylesContext::CreateStyleStyleChildContext(
634                     nFamily, nPrefix, rLocalName, xAttrList );
635 
636 	if (!pStyle)
637 	{
638 		switch( nFamily )
639 		{
640 		case XML_STYLE_FAMILY_TABLE_CELL:
641 		case XML_STYLE_FAMILY_TABLE_COLUMN:
642 		case XML_STYLE_FAMILY_TABLE_ROW:
643 		case XML_STYLE_FAMILY_TABLE_TABLE:
644 			pStyle = new XMLTableStyleContext( GetScImport(), nPrefix, rLocalName,
645 			   								xAttrList, *this, nFamily );
646 			break;
647 		}
648 	}
649 
650 	return pStyle;
651 }
652 
CreateDefaultStyleStyleChildContext(sal_uInt16 nFamily,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)653 SvXMLStyleContext *XMLTableStylesContext::CreateDefaultStyleStyleChildContext(
654 		sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
655 		const uno::Reference< xml::sax::XAttributeList > & xAttrList )
656 {
657 	SvXMLStyleContext *pStyle(SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily, nPrefix,
658 															rLocalName,
659 															xAttrList ));
660 	if (!pStyle)
661 	{
662 		switch( nFamily )
663 		{
664 			case XML_STYLE_FAMILY_TABLE_CELL:
665 				pStyle = new XMLTableStyleContext( GetScImport(), nPrefix, rLocalName,
666 											xAttrList, *this, nFamily, sal_True);
667 			break;
668 			case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
669 				pStyle = new XMLGraphicsDefaultStyle( GetScImport(), nPrefix, rLocalName,
670 											xAttrList, *this);
671 			break;
672 		}
673 	}
674 
675 	return pStyle;
676 }
677 
XMLTableStylesContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<XAttributeList> & xAttrList,const sal_Bool bTempAutoStyles)678 XMLTableStylesContext::XMLTableStylesContext( SvXMLImport& rImport,
679 		sal_uInt16 nPrfx ,
680 		const OUString& rLName ,
681 		const uno::Reference< XAttributeList > & xAttrList,
682 		const sal_Bool bTempAutoStyles ) :
683 	SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
684 	sCellStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CellStyle" ) )),
685 	sColumnStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME ))),
686 	sRowStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME ))),
687 	sTableStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME ))),
688 	nNumberFormatIndex(-1),
689 	nConditionalFormatIndex(-1),
690 	nCellStyleIndex(-1),
691 	nMasterPageNameIndex(-1),
692 	bAutoStyles(bTempAutoStyles)
693 {
694 }
695 
~XMLTableStylesContext()696 XMLTableStylesContext::~XMLTableStylesContext()
697 {
698 }
699 
EndElement()700 void XMLTableStylesContext::EndElement()
701 {
702 	SvXMLStylesContext::EndElement();
703 	if (bAutoStyles)
704 		GetImport().GetTextImport()->SetAutoStyles( this );
705 	else
706 		((ScXMLImport&)GetImport()).InsertStyles();
707 }
708 
709 UniReference < SvXMLImportPropertyMapper >
GetImportPropertyMapper(sal_uInt16 nFamily) const710 	XMLTableStylesContext::GetImportPropertyMapper(
711 					sal_uInt16 nFamily ) const
712 {
713 	UniReference < SvXMLImportPropertyMapper > xMapper(SvXMLStylesContext::GetImportPropertyMapper(nFamily));
714 
715 	if (!xMapper.is())
716 	{
717 		switch( nFamily )
718 		{
719 			case XML_STYLE_FAMILY_TABLE_CELL:
720 			{
721 				if( !xCellImpPropMapper.is() )
722 				{
723 					((XMLTableStylesContext *)this)->xCellImpPropMapper =
724 						new ScXMLCellImportPropertyMapper( GetScImport().GetCellStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
725 					xCellImpPropMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(const_cast<SvXMLImport&>(GetImport()), const_cast<XMLFontStylesContext*>(GetScImport().GetFontDecls())));
726 				}
727 				xMapper = xCellImpPropMapper;
728 			}
729 			break;
730 			case XML_STYLE_FAMILY_TABLE_COLUMN:
731 			{
732 				if( !xColumnImpPropMapper.is() )
733 					((XMLTableStylesContext *)this)->xColumnImpPropMapper =
734 						new SvXMLImportPropertyMapper( GetScImport().GetColumnStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
735 				xMapper = xColumnImpPropMapper;
736 			}
737 	 		break;
738 			case XML_STYLE_FAMILY_TABLE_ROW:
739 			{
740 				if( !xRowImpPropMapper.is() )
741 					((XMLTableStylesContext *)this)->xRowImpPropMapper =
742 						new ScXMLRowImportPropertyMapper( GetScImport().GetRowStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
743 				xMapper = xRowImpPropMapper;
744 			}
745 	 		break;
746 			case XML_STYLE_FAMILY_TABLE_TABLE:
747 			{
748 				if( !xTableImpPropMapper.is() )
749 					((XMLTableStylesContext *)this)->xTableImpPropMapper =
750 						new SvXMLImportPropertyMapper( GetScImport().GetTableStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
751 				xMapper = xTableImpPropMapper;
752 			}
753 	 		break;
754 		}
755 	}
756 
757 	return xMapper;
758 }
759 
760 uno::Reference < XNameContainer >
GetStylesContainer(sal_uInt16 nFamily) const761 		XMLTableStylesContext::GetStylesContainer( sal_uInt16 nFamily ) const
762 {
763 	uno::Reference < XNameContainer > xStyles(SvXMLStylesContext::GetStylesContainer(nFamily));
764 	if (!xStyles.is())
765 	{
766 		OUString sName;
767 		switch( nFamily )
768 		{
769 			case XML_STYLE_FAMILY_TABLE_TABLE:
770 			{
771 				if( xTableStyles.is() )
772 					xStyles.set(xTableStyles);
773 				else
774 					sName =
775 						OUString( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "TableStyles" ) ));
776 			}
777 			break;
778 			case XML_STYLE_FAMILY_TABLE_CELL:
779 			{
780 				if( xCellStyles.is() )
781 					xStyles.set(xCellStyles);
782 				else
783 					sName =
784 						OUString( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "CellStyles" ) ));
785 			}
786 			break;
787 			case XML_STYLE_FAMILY_TABLE_COLUMN:
788 			{
789 				if( xColumnStyles.is() )
790 					xStyles.set(xColumnStyles);
791 				else
792 					sName =
793 						OUString( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnStyles" ) ));
794 			}
795 			break;
796 			case XML_STYLE_FAMILY_TABLE_ROW:
797 			{
798 				if( xRowStyles.is() )
799 					xStyles.set(xRowStyles);
800 				else
801 					sName =
802 						OUString( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RowStyles" ) ));
803 			}
804 			break;
805 		}
806 		if( !xStyles.is() && sName.getLength() && GetScImport().GetModel().is() )
807 		{
808 			uno::Reference< XStyleFamiliesSupplier > xFamiliesSupp(
809 											GetScImport().GetModel(), UNO_QUERY );
810 			if (xFamiliesSupp.is())
811 			{
812 				uno::Reference< XNameAccess > xFamilies(xFamiliesSupp->getStyleFamilies());
813 
814                 try
815                 {
816                     xStyles.set(xFamilies->getByName( sName ), uno::UNO_QUERY);
817                 }
818                 catch ( uno::Exception& )
819                 {
820                     // #i97680# Named table/column/row styles aren't supported, getByName will throw an exception.
821                     // For better interoperability, these styles should then be handled as automatic styles.
822                     // For now, NULL is returned (and the style is ignored).
823                 }
824 				switch( nFamily )
825 				{
826 				case XML_STYLE_FAMILY_TABLE_TABLE:
827 					((XMLTableStylesContext *)this)->xTableStyles.set(xStyles);
828 					break;
829 				case XML_STYLE_FAMILY_TABLE_CELL:
830 					((XMLTableStylesContext *)this)->xCellStyles.set(xStyles);
831 					break;
832 				case XML_STYLE_FAMILY_TABLE_COLUMN:
833 					((XMLTableStylesContext *)this)->xColumnStyles.set(xStyles);
834 					break;
835 				case XML_STYLE_FAMILY_TABLE_ROW:
836 					((XMLTableStylesContext *)this)->xRowStyles.set(xStyles);
837 					break;
838 				}
839 			}
840 		}
841 	}
842 
843 	return xStyles;
844 }
845 
GetServiceName(sal_uInt16 nFamily) const846 OUString XMLTableStylesContext::GetServiceName( sal_uInt16 nFamily ) const
847 {
848 	rtl::OUString sServiceName(SvXMLStylesContext::GetServiceName(nFamily));
849 	if (!sServiceName.getLength())
850 	{
851 		switch( nFamily )
852 		{
853 		case XML_STYLE_FAMILY_TABLE_COLUMN:
854 			sServiceName = sColumnStyleServiceName;
855 			break;
856 		case XML_STYLE_FAMILY_TABLE_ROW:
857 			sServiceName = sRowStyleServiceName;
858 			break;
859 		case XML_STYLE_FAMILY_TABLE_CELL:
860 			sServiceName = sCellStyleServiceName;
861 			break;
862 		case XML_STYLE_FAMILY_TABLE_TABLE:
863 			sServiceName = sTableStyleServiceName;
864 			break;
865 		}
866 	}
867 	return sServiceName;
868 }
869 
GetIndex(const sal_Int16 nContextID)870 sal_Int32 XMLTableStylesContext::GetIndex(const sal_Int16 nContextID)
871 {
872 	if (nContextID == CTF_SC_CELLSTYLE)
873 	{
874 		if (nCellStyleIndex == -1)
875 			nCellStyleIndex =
876 				GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
877 		return nCellStyleIndex;
878 	}
879 	else if (nContextID == CTF_SC_NUMBERFORMAT)
880 	{
881 		if (nNumberFormatIndex == -1)
882 			nNumberFormatIndex =
883 				GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
884 		return nNumberFormatIndex;
885 	}
886 	else if (nContextID == CTF_SC_IMPORT_MAP)
887 	{
888 		if (nConditionalFormatIndex == -1)
889 			nConditionalFormatIndex =
890 				GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
891 		return nConditionalFormatIndex;
892 	}
893 	else if (nContextID == CTF_SC_MASTERPAGENAME)
894 	{
895 		if (nMasterPageNameIndex == -1)
896 				nMasterPageNameIndex =
897 				GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_TABLE)->getPropertySetMapper()->FindEntryIndex(nContextID);
898 		return nMasterPageNameIndex;
899 	}
900 	else
901 		return -1;
902 }
903 
904 // ---------------------------------------------------------------------------
905 TYPEINIT1( ScXMLMasterStylesContext, SvXMLStylesContext );
906 
InsertStyleFamily(sal_uInt16) const907 sal_Bool ScXMLMasterStylesContext::InsertStyleFamily( sal_uInt16 ) const
908 {
909 	return sal_True;
910 }
911 
ScXMLMasterStylesContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<XAttributeList> & xAttrList)912 ScXMLMasterStylesContext::ScXMLMasterStylesContext(
913 		SvXMLImport& rImport,
914 		sal_uInt16 nPrfx, const OUString& rLName,
915 		const uno::Reference< XAttributeList > & xAttrList ) :
916 	SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList )
917 {
918 }
919 
~ScXMLMasterStylesContext()920 ScXMLMasterStylesContext::~ScXMLMasterStylesContext()
921 {
922 }
923 
CreateStyleChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<XAttributeList> & xAttrList)924 SvXMLStyleContext *ScXMLMasterStylesContext::CreateStyleChildContext(
925 		sal_uInt16 nPrefix,
926 		const OUString& rLocalName,
927 		const uno::Reference< XAttributeList > & xAttrList )
928 {
929 	SvXMLStyleContext *pContext(0);
930 
931 	if( (XML_NAMESPACE_STYLE == nPrefix) &&
932 		IsXMLToken(rLocalName, XML_MASTER_PAGE) &&
933 	 	InsertStyleFamily( XML_STYLE_FAMILY_MASTER_PAGE ) )
934 		pContext = new ScMasterPageContext(
935 						GetImport(), nPrefix, rLocalName, xAttrList,
936 						!GetImport().GetTextImport()->IsInsertMode() );
937 
938 	// any other style will be ignored here!
939 
940 	return pContext;
941 }
942 
CreateStyleStyleChildContext(sal_uInt16,sal_uInt16,const OUString &,const uno::Reference<XAttributeList> &)943 SvXMLStyleContext *ScXMLMasterStylesContext::CreateStyleStyleChildContext(
944         sal_uInt16 /* nFamily */,
945         sal_uInt16 /* nPrefix */,
946         const OUString& /* rLocalName */,
947 		const uno::Reference< XAttributeList > & /* xAttrList */ )
948 {
949 	return 0;
950 }
951 
EndElement()952 void ScXMLMasterStylesContext::EndElement()
953 {
954 	FinishStyles(sal_True);
955 }
956 
957 TYPEINIT1( ScMasterPageContext, XMLTextMasterPageContext );
958 
ScMasterPageContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<XAttributeList> & xAttrList,sal_Bool bOverwrite)959 ScMasterPageContext::ScMasterPageContext( SvXMLImport& rImport,
960 		sal_uInt16 nPrfx, const OUString& rLName,
961 		const uno::Reference< XAttributeList > & xAttrList,
962 		sal_Bool bOverwrite ) :
963 	XMLTextMasterPageContext( rImport, nPrfx, rLName, xAttrList, bOverwrite ),
964 	bContainsRightHeader(sal_False),
965 	bContainsRightFooter(sal_False)
966 {
967 }
968 
~ScMasterPageContext()969 ScMasterPageContext::~ScMasterPageContext()
970 {
971 }
972 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<XAttributeList> & xAttrList)973 SvXMLImportContext *ScMasterPageContext::CreateChildContext(
974 		sal_uInt16 nPrefix,
975 		const OUString& rLocalName,
976 		const uno::Reference< XAttributeList > & xAttrList )
977 {
978 	return XMLTextMasterPageContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
979 }
980 
CreateHeaderFooterContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,const sal_Bool bFooter,const sal_Bool bLeft)981 SvXMLImportContext *ScMasterPageContext::CreateHeaderFooterContext(
982 			sal_uInt16 nPrefix,
983 			const ::rtl::OUString& rLocalName,
984 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
985 			const sal_Bool bFooter,
986 			const sal_Bool bLeft )
987 {
988 	if (!bLeft)
989 	{
990 		if (bFooter)
991 			bContainsRightFooter = sal_True;
992 		else
993 			bContainsRightHeader = sal_True;
994 	}
995 	if (!xPropSet.is())
996 		xPropSet.set(GetStyle(), UNO_QUERY );
997 	return new XMLTableHeaderFooterContext( GetImport(),
998 												nPrefix, rLocalName,
999 												xAttrList,
1000 												xPropSet,
1001 												bFooter, bLeft );
1002 }
1003 
ClearContent(const rtl::OUString & rContent)1004 void ScMasterPageContext::ClearContent(const rtl::OUString& rContent)
1005 {
1006 	if (!xPropSet.is())
1007 		xPropSet.set(GetStyle(), UNO_QUERY );
1008 
1009     if (xPropSet.is())
1010     {
1011 		uno::Reference < sheet::XHeaderFooterContent > xHeaderFooterContent(xPropSet->getPropertyValue( rContent ), uno::UNO_QUERY);
1012 	    if (xHeaderFooterContent.is())
1013 	    {
1014 		    xHeaderFooterContent->getLeftText()->setString(sEmpty);
1015 		    xHeaderFooterContent->getCenterText()->setString(sEmpty);
1016 		    xHeaderFooterContent->getRightText()->setString(sEmpty);
1017 		    xPropSet->setPropertyValue( rContent, uno::makeAny(xHeaderFooterContent) );
1018 	    }
1019     }
1020 }
1021 
Finish(sal_Bool bOverwrite)1022 void ScMasterPageContext::Finish( sal_Bool bOverwrite )
1023 {
1024 	XMLTextMasterPageContext::Finish(bOverwrite);
1025 	if (!bContainsRightFooter)
1026 		ClearContent(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_PAGE_RIGHTFTRCON)));
1027 	if (!bContainsRightHeader)
1028 		ClearContent(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_PAGE_RIGHTHDRCON)));
1029 }
1030 
1031 // ---------------------------------------------------------------------------
1032 
ScCellTextStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,SvXMLStylesContext & rStyles,sal_uInt16 nFamily,sal_Bool bDefaultStyle)1033 ScCellTextStyleContext::ScCellTextStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
1034             const rtl::OUString& rLName, const uno::Reference<xml::sax::XAttributeList> & xAttrList,
1035             SvXMLStylesContext& rStyles, sal_uInt16 nFamily, sal_Bool bDefaultStyle ) :
1036     XMLTextStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle ),
1037     nLastSheet(-1)
1038 {
1039 }
1040 
~ScCellTextStyleContext()1041 ScCellTextStyleContext::~ScCellTextStyleContext()
1042 {
1043 }
1044 
FillPropertySet(const uno::Reference<beans::XPropertySet> & xPropSet)1045 void ScCellTextStyleContext::FillPropertySet( const uno::Reference<beans::XPropertySet>& xPropSet )
1046 {
1047     XMLTextStyleContext::FillPropertySet( xPropSet );
1048 
1049     ScXMLImport& rXMLImport = GetScImport();
1050 
1051     ScCellTextCursor* pCellImp = ScCellTextCursor::getImplementation( xPropSet );
1052     if (pCellImp)
1053     {
1054         ScAddress aPos = pCellImp->GetCellObj().GetPosition();
1055         if ( static_cast<sal_Int32>(aPos.Tab()) != nLastSheet )
1056         {
1057             ESelection aSel = pCellImp->GetSelection();
1058 
1059             ScSheetSaveData* pSheetData = ScModelObj::getImplementation(GetImport().GetModel())->GetSheetSaveData();
1060             pSheetData->AddTextStyle( GetName(), aPos, aSel );
1061 
1062             nLastSheet = static_cast<sal_Int32>(aPos.Tab());
1063         }
1064     }
1065     else if ( rXMLImport.GetTables().GetCurrentSheet() != nLastSheet )
1066     {
1067         ScDrawTextCursor* pDrawImp = ScDrawTextCursor::getImplementation( xPropSet );
1068         if (pDrawImp)
1069         {
1070             XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
1071             ScXMLAnnotationContext* pAnnotationContext = pTableShapeImport->GetAnnotationContext();
1072             if (pAnnotationContext)
1073             {
1074                 pAnnotationContext->AddContentStyle( GetFamily(), GetName(), pDrawImp->GetSelection() );
1075                 nLastSheet = rXMLImport.GetTables().GetCurrentSheet();
1076             }
1077         }
1078 
1079         // if it's a different shape, BlockSheet is called from XMLTableShapeImportHelper::finishShape
1080         // formatted text in page headers/footers can be ignored
1081     }
1082 }
1083 
1084