xref: /aoo41x/main/sc/source/filter/xml/xmlsceni.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "document.hxx"
32cdf0e10cSrcweir #include "xmlimprt.hxx"
33cdf0e10cSrcweir #include "xmlsceni.hxx"
34cdf0e10cSrcweir #include "docuno.hxx"
35cdf0e10cSrcweir #include "attrib.hxx"
36cdf0e10cSrcweir #include "XMLConverter.hxx"
37cdf0e10cSrcweir #include "rangeutl.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <xmloff/xmltkmap.hxx>
40cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
41cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
42cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace com::sun::star;
45cdf0e10cSrcweir using namespace xmloff::token;
46cdf0e10cSrcweir using ::rtl::OUString;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //------------------------------------------------------------------
49cdf0e10cSrcweir 
ScXMLTableScenarioContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)50cdf0e10cSrcweir ScXMLTableScenarioContext::ScXMLTableScenarioContext(
51cdf0e10cSrcweir 		ScXMLImport& rImport,
52cdf0e10cSrcweir 		sal_uInt16 nPrfx,
53cdf0e10cSrcweir 		const OUString& rLName,
54cdf0e10cSrcweir 		const uno::Reference< xml::sax::XAttributeList >& xAttrList ):
55cdf0e10cSrcweir 	SvXMLImportContext( rImport, nPrfx, rLName ),
56cdf0e10cSrcweir 	aBorderColor( COL_BLACK ),
57cdf0e10cSrcweir 	bDisplayBorder( sal_True ),
58cdf0e10cSrcweir 	bCopyBack( sal_True ),
59cdf0e10cSrcweir 	bCopyStyles( sal_True ),
60cdf0e10cSrcweir 	bCopyFormulas( sal_True ),
61cdf0e10cSrcweir 	bIsActive( sal_False ),
62cdf0e10cSrcweir     bProtected( sal_False )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	rImport.LockSolarMutex();
65cdf0e10cSrcweir 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
66cdf0e10cSrcweir 	const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetTableScenarioAttrTokenMap());
67cdf0e10cSrcweir 	for( sal_Int16 i = 0; i < nAttrCount; ++i )
68cdf0e10cSrcweir 	{
69cdf0e10cSrcweir 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
70cdf0e10cSrcweir 		OUString aLocalName;
71cdf0e10cSrcweir 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
72cdf0e10cSrcweir 											sAttrName, &aLocalName ));
73cdf0e10cSrcweir 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 		switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
76cdf0e10cSrcweir 		{
77cdf0e10cSrcweir 			case XML_TOK_TABLE_SCENARIO_ATTR_DISPLAY_BORDER:
78cdf0e10cSrcweir 			{
79cdf0e10cSrcweir 				bDisplayBorder = IsXMLToken(sValue, XML_TRUE);
80cdf0e10cSrcweir 			}
81cdf0e10cSrcweir 			break;
82cdf0e10cSrcweir 			case XML_TOK_TABLE_SCENARIO_ATTR_BORDER_COLOR:
83cdf0e10cSrcweir 			{
84cdf0e10cSrcweir 				SvXMLUnitConverter::convertColor(aBorderColor, sValue);
85cdf0e10cSrcweir 			}
86cdf0e10cSrcweir 			break;
87cdf0e10cSrcweir 			case XML_TOK_TABLE_SCENARIO_ATTR_COPY_BACK:
88cdf0e10cSrcweir 			{
89cdf0e10cSrcweir 				bCopyBack = IsXMLToken(sValue, XML_TRUE);
90cdf0e10cSrcweir 			}
91cdf0e10cSrcweir 			break;
92cdf0e10cSrcweir 			case XML_TOK_TABLE_SCENARIO_ATTR_COPY_STYLES:
93cdf0e10cSrcweir 			{
94cdf0e10cSrcweir 				bCopyStyles = IsXMLToken(sValue, XML_TRUE);
95cdf0e10cSrcweir 			}
96cdf0e10cSrcweir 			break;
97cdf0e10cSrcweir 			case XML_TOK_TABLE_SCENARIO_ATTR_COPY_FORMULAS:
98cdf0e10cSrcweir 			{
99cdf0e10cSrcweir 				bCopyFormulas = IsXMLToken(sValue, XML_TRUE);
100cdf0e10cSrcweir 			}
101cdf0e10cSrcweir 			break;
102cdf0e10cSrcweir 			case XML_TOK_TABLE_SCENARIO_ATTR_IS_ACTIVE:
103cdf0e10cSrcweir 			{
104cdf0e10cSrcweir 				bIsActive = IsXMLToken(sValue, XML_TRUE);
105cdf0e10cSrcweir 			}
106cdf0e10cSrcweir 			break;
107cdf0e10cSrcweir 			case XML_TOK_TABLE_SCENARIO_ATTR_SCENARIO_RANGES:
108cdf0e10cSrcweir 			{
109cdf0e10cSrcweir 				ScRangeStringConverter::GetRangeListFromString(
110cdf0e10cSrcweir 					aScenarioRanges, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO );
111cdf0e10cSrcweir 			}
112cdf0e10cSrcweir 			break;
113cdf0e10cSrcweir 			case XML_TOK_TABLE_SCENARIO_ATTR_COMMENT:
114cdf0e10cSrcweir 			{
115cdf0e10cSrcweir 				sComment = sValue;
116cdf0e10cSrcweir 			}
117cdf0e10cSrcweir 			break;
118cdf0e10cSrcweir             case XML_TOK_TABLE_SCENARIO_ATTR_PROTECTED:
119cdf0e10cSrcweir             {
120cdf0e10cSrcweir 				bProtected = IsXMLToken(sValue, XML_TRUE);
121cdf0e10cSrcweir             }
122cdf0e10cSrcweir             break;
123cdf0e10cSrcweir 		}
124cdf0e10cSrcweir 	}
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
~ScXMLTableScenarioContext()127cdf0e10cSrcweir ScXMLTableScenarioContext::~ScXMLTableScenarioContext()
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	GetScImport().UnlockSolarMutex();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)132cdf0e10cSrcweir SvXMLImportContext *ScXMLTableScenarioContext::CreateChildContext(
133cdf0e10cSrcweir 		sal_uInt16 nPrefix,
134cdf0e10cSrcweir 		const OUString& rLName,
135cdf0e10cSrcweir         const uno::Reference< xml::sax::XAttributeList >& /* xAttrList */ )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	return new SvXMLImportContext( GetImport(), nPrefix, rLName );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
EndElement()140cdf0e10cSrcweir void ScXMLTableScenarioContext::EndElement()
141cdf0e10cSrcweir {
142cdf0e10cSrcweir     SCTAB nCurrTable( sal::static_int_cast<SCTAB>( GetScImport().GetTables().GetCurrentSheet() ) );
143cdf0e10cSrcweir 	ScDocument*	pDoc(GetScImport().GetDocument());
144cdf0e10cSrcweir 	if (pDoc)
145cdf0e10cSrcweir 	{
146cdf0e10cSrcweir 		pDoc->SetScenario( nCurrTable, sal_True );
147cdf0e10cSrcweir 		sal_uInt16 nFlags( 0 );
148cdf0e10cSrcweir 		if( bDisplayBorder )
149cdf0e10cSrcweir 			nFlags |= SC_SCENARIO_SHOWFRAME;
150cdf0e10cSrcweir 		if( bCopyBack )
151cdf0e10cSrcweir 			nFlags |= SC_SCENARIO_TWOWAY;
152cdf0e10cSrcweir 		if( bCopyStyles )
153cdf0e10cSrcweir 			nFlags |= SC_SCENARIO_ATTRIB;
154cdf0e10cSrcweir 		if( !bCopyFormulas )
155cdf0e10cSrcweir 			nFlags |= SC_SCENARIO_VALUE;
156cdf0e10cSrcweir         if( bProtected )
157cdf0e10cSrcweir             nFlags |= SC_SCENARIO_PROTECT;
158cdf0e10cSrcweir 		pDoc->SetScenarioData( nCurrTable, String( sComment ), aBorderColor, nFlags );
159cdf0e10cSrcweir 		for( sal_Int32 i = 0; i < static_cast<sal_Int32>(aScenarioRanges.Count()); ++i )
160cdf0e10cSrcweir 		{
161cdf0e10cSrcweir 			ScRange* pRange(aScenarioRanges.GetObject( i ));
162cdf0e10cSrcweir 			if( pRange )
163cdf0e10cSrcweir 				pDoc->ApplyFlagsTab( pRange->aStart.Col(), pRange->aStart.Row(),
164cdf0e10cSrcweir 					pRange->aEnd.Col(), pRange->aEnd.Row(), nCurrTable, SC_MF_SCENARIO );
165cdf0e10cSrcweir 		}
166cdf0e10cSrcweir 		pDoc->SetActiveScenario( nCurrTable, bIsActive );
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170