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
29 // INCLUDE ---------------------------------------------------------------
30
31 #include "document.hxx"
32 #include "xmlimprt.hxx"
33 #include "xmlsceni.hxx"
34 #include "docuno.hxx"
35 #include "attrib.hxx"
36 #include "XMLConverter.hxx"
37 #include "rangeutl.hxx"
38
39 #include <xmloff/xmltkmap.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include <xmloff/xmluconv.hxx>
42 #include <xmloff/xmltoken.hxx>
43
44 using namespace com::sun::star;
45 using namespace xmloff::token;
46 using ::rtl::OUString;
47
48 //------------------------------------------------------------------
49
ScXMLTableScenarioContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)50 ScXMLTableScenarioContext::ScXMLTableScenarioContext(
51 ScXMLImport& rImport,
52 sal_uInt16 nPrfx,
53 const OUString& rLName,
54 const uno::Reference< xml::sax::XAttributeList >& xAttrList ):
55 SvXMLImportContext( rImport, nPrfx, rLName ),
56 aBorderColor( COL_BLACK ),
57 bDisplayBorder( sal_True ),
58 bCopyBack( sal_True ),
59 bCopyStyles( sal_True ),
60 bCopyFormulas( sal_True ),
61 bIsActive( sal_False ),
62 bProtected( sal_False )
63 {
64 rImport.LockSolarMutex();
65 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
66 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetTableScenarioAttrTokenMap());
67 for( sal_Int16 i = 0; i < nAttrCount; ++i )
68 {
69 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
70 OUString aLocalName;
71 sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
72 sAttrName, &aLocalName ));
73 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
74
75 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
76 {
77 case XML_TOK_TABLE_SCENARIO_ATTR_DISPLAY_BORDER:
78 {
79 bDisplayBorder = IsXMLToken(sValue, XML_TRUE);
80 }
81 break;
82 case XML_TOK_TABLE_SCENARIO_ATTR_BORDER_COLOR:
83 {
84 SvXMLUnitConverter::convertColor(aBorderColor, sValue);
85 }
86 break;
87 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_BACK:
88 {
89 bCopyBack = IsXMLToken(sValue, XML_TRUE);
90 }
91 break;
92 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_STYLES:
93 {
94 bCopyStyles = IsXMLToken(sValue, XML_TRUE);
95 }
96 break;
97 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_FORMULAS:
98 {
99 bCopyFormulas = IsXMLToken(sValue, XML_TRUE);
100 }
101 break;
102 case XML_TOK_TABLE_SCENARIO_ATTR_IS_ACTIVE:
103 {
104 bIsActive = IsXMLToken(sValue, XML_TRUE);
105 }
106 break;
107 case XML_TOK_TABLE_SCENARIO_ATTR_SCENARIO_RANGES:
108 {
109 ScRangeStringConverter::GetRangeListFromString(
110 aScenarioRanges, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO );
111 }
112 break;
113 case XML_TOK_TABLE_SCENARIO_ATTR_COMMENT:
114 {
115 sComment = sValue;
116 }
117 break;
118 case XML_TOK_TABLE_SCENARIO_ATTR_PROTECTED:
119 {
120 bProtected = IsXMLToken(sValue, XML_TRUE);
121 }
122 break;
123 }
124 }
125 }
126
~ScXMLTableScenarioContext()127 ScXMLTableScenarioContext::~ScXMLTableScenarioContext()
128 {
129 GetScImport().UnlockSolarMutex();
130 }
131
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)132 SvXMLImportContext *ScXMLTableScenarioContext::CreateChildContext(
133 sal_uInt16 nPrefix,
134 const OUString& rLName,
135 const uno::Reference< xml::sax::XAttributeList >& /* xAttrList */ )
136 {
137 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
138 }
139
EndElement()140 void ScXMLTableScenarioContext::EndElement()
141 {
142 SCTAB nCurrTable( sal::static_int_cast<SCTAB>( GetScImport().GetTables().GetCurrentSheet() ) );
143 ScDocument* pDoc(GetScImport().GetDocument());
144 if (pDoc)
145 {
146 pDoc->SetScenario( nCurrTable, sal_True );
147 sal_uInt16 nFlags( 0 );
148 if( bDisplayBorder )
149 nFlags |= SC_SCENARIO_SHOWFRAME;
150 if( bCopyBack )
151 nFlags |= SC_SCENARIO_TWOWAY;
152 if( bCopyStyles )
153 nFlags |= SC_SCENARIO_ATTRIB;
154 if( !bCopyFormulas )
155 nFlags |= SC_SCENARIO_VALUE;
156 if( bProtected )
157 nFlags |= SC_SCENARIO_PROTECT;
158 pDoc->SetScenarioData( nCurrTable, String( sComment ), aBorderColor, nFlags );
159 for( sal_Int32 i = 0; i < static_cast<sal_Int32>(aScenarioRanges.Count()); ++i )
160 {
161 ScRange* pRange(aScenarioRanges.GetObject( i ));
162 if( pRange )
163 pDoc->ApplyFlagsTab( pRange->aStart.Col(), pRange->aStart.Row(),
164 pRange->aEnd.Col(), pRange->aEnd.Row(), nCurrTable, SC_MF_SCENARIO );
165 }
166 pDoc->SetActiveScenario( nCurrTable, bIsActive );
167 }
168 }
169
170