Update ooo320-m1
[ooovba.git] / sc / source / filter / xml / xmlsceni.cxx
blob55e9969a2873228693772f0c7beebbe36d61b9d9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlsceni.cxx,v $
10 * $Revision: 1.15.134.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include "document.hxx"
39 #include "xmlimprt.hxx"
40 #include "xmlsceni.hxx"
41 #include "docuno.hxx"
42 #include "attrib.hxx"
43 #include "XMLConverter.hxx"
44 #include "rangeutl.hxx"
46 #include <xmloff/xmltkmap.hxx>
47 #include <xmloff/nmspmap.hxx>
48 #include <xmloff/xmluconv.hxx>
49 #include <xmloff/xmltoken.hxx>
51 using namespace com::sun::star;
52 using namespace xmloff::token;
53 using ::rtl::OUString;
55 //------------------------------------------------------------------
57 ScXMLTableScenarioContext::ScXMLTableScenarioContext(
58 ScXMLImport& rImport,
59 USHORT nPrfx,
60 const OUString& rLName,
61 const uno::Reference< xml::sax::XAttributeList >& xAttrList ):
62 SvXMLImportContext( rImport, nPrfx, rLName ),
63 aBorderColor( COL_BLACK ),
64 bDisplayBorder( sal_True ),
65 bCopyBack( sal_True ),
66 bCopyStyles( sal_True ),
67 bCopyFormulas( sal_True ),
68 bIsActive( sal_False ),
69 bProtected( sal_False )
71 rImport.LockSolarMutex();
72 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
73 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetTableScenarioAttrTokenMap());
74 for( sal_Int16 i = 0; i < nAttrCount; ++i )
76 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
77 OUString aLocalName;
78 USHORT nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
79 sAttrName, &aLocalName ));
80 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
82 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
84 case XML_TOK_TABLE_SCENARIO_ATTR_DISPLAY_BORDER:
86 bDisplayBorder = IsXMLToken(sValue, XML_TRUE);
88 break;
89 case XML_TOK_TABLE_SCENARIO_ATTR_BORDER_COLOR:
91 SvXMLUnitConverter::convertColor(aBorderColor, sValue);
93 break;
94 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_BACK:
96 bCopyBack = IsXMLToken(sValue, XML_TRUE);
98 break;
99 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_STYLES:
101 bCopyStyles = IsXMLToken(sValue, XML_TRUE);
103 break;
104 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_FORMULAS:
106 bCopyFormulas = IsXMLToken(sValue, XML_TRUE);
108 break;
109 case XML_TOK_TABLE_SCENARIO_ATTR_IS_ACTIVE:
111 bIsActive = IsXMLToken(sValue, XML_TRUE);
113 break;
114 case XML_TOK_TABLE_SCENARIO_ATTR_SCENARIO_RANGES:
116 ScRangeStringConverter::GetRangeListFromString(
117 aScenarioRanges, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO );
119 break;
120 case XML_TOK_TABLE_SCENARIO_ATTR_COMMENT:
122 sComment = sValue;
124 break;
125 case XML_TOK_TABLE_SCENARIO_ATTR_PROTECTED:
127 bProtected = IsXMLToken(sValue, XML_TRUE);
129 break;
134 ScXMLTableScenarioContext::~ScXMLTableScenarioContext()
136 GetScImport().UnlockSolarMutex();
139 SvXMLImportContext *ScXMLTableScenarioContext::CreateChildContext(
140 USHORT nPrefix,
141 const OUString& rLName,
142 const uno::Reference< xml::sax::XAttributeList >& /* xAttrList */ )
144 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
147 void ScXMLTableScenarioContext::EndElement()
149 SCTAB nCurrTable( sal::static_int_cast<SCTAB>( GetScImport().GetTables().GetCurrentSheet() ) );
150 ScDocument* pDoc(GetScImport().GetDocument());
151 if (pDoc)
153 pDoc->SetScenario( nCurrTable, TRUE );
154 USHORT nFlags( 0 );
155 if( bDisplayBorder )
156 nFlags |= SC_SCENARIO_SHOWFRAME;
157 if( bCopyBack )
158 nFlags |= SC_SCENARIO_TWOWAY;
159 if( bCopyStyles )
160 nFlags |= SC_SCENARIO_ATTRIB;
161 if( !bCopyFormulas )
162 nFlags |= SC_SCENARIO_VALUE;
163 if( bProtected )
164 nFlags |= SC_SCENARIO_PROTECT;
165 pDoc->SetScenarioData( nCurrTable, String( sComment ), aBorderColor, nFlags );
166 for( sal_Int32 i = 0; i < static_cast<sal_Int32>(aScenarioRanges.Count()); ++i )
168 ScRange* pRange(aScenarioRanges.GetObject( i ));
169 if( pRange )
170 pDoc->ApplyFlagsTab( pRange->aStart.Col(), pRange->aStart.Row(),
171 pRange->aEnd.Col(), pRange->aEnd.Row(), nCurrTable, SC_MF_SCENARIO );
173 pDoc->SetActiveScenario( nCurrTable, bIsActive );