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 "document.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlsceni.hxx"
25 #include "XMLConverter.hxx"
26 #include "rangeutl.hxx"
28 #include <xmloff/xmltkmap.hxx>
29 #include <xmloff/nmspmap.hxx>
30 #include <xmloff/xmltoken.hxx>
32 #include <sax/tools/converter.hxx>
34 using namespace com::sun::star
;
35 using namespace xmloff::token
;
37 ScXMLTableScenarioContext::ScXMLTableScenarioContext(
40 const OUString
& rLName
,
41 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
):
42 SvXMLImportContext( rImport
, nPrfx
, rLName
),
43 aBorderColor( COL_BLACK
),
44 bDisplayBorder( true ),
47 bCopyFormulas( true ),
51 rImport
.LockSolarMutex();
52 sal_Int16
nAttrCount(xAttrList
.is() ? xAttrList
->getLength() : 0);
53 const SvXMLTokenMap
& rAttrTokenMap(GetScImport().GetTableScenarioAttrTokenMap());
54 for( sal_Int16 i
= 0; i
< nAttrCount
; ++i
)
56 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
58 sal_uInt16
nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
59 sAttrName
, &aLocalName
));
60 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
62 switch( rAttrTokenMap
.Get( nPrefix
, aLocalName
) )
64 case XML_TOK_TABLE_SCENARIO_ATTR_DISPLAY_BORDER
:
66 bDisplayBorder
= IsXMLToken(sValue
, XML_TRUE
);
69 case XML_TOK_TABLE_SCENARIO_ATTR_BORDER_COLOR
:
72 ::sax::Converter::convertColor(nColor
, sValue
);
73 aBorderColor
.SetColor(nColor
);
76 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_BACK
:
78 bCopyBack
= IsXMLToken(sValue
, XML_TRUE
);
81 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_STYLES
:
83 bCopyStyles
= IsXMLToken(sValue
, XML_TRUE
);
86 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_FORMULAS
:
88 bCopyFormulas
= IsXMLToken(sValue
, XML_TRUE
);
91 case XML_TOK_TABLE_SCENARIO_ATTR_IS_ACTIVE
:
93 bIsActive
= IsXMLToken(sValue
, XML_TRUE
);
96 case XML_TOK_TABLE_SCENARIO_ATTR_SCENARIO_RANGES
:
98 ScRangeStringConverter::GetRangeListFromString(
99 aScenarioRanges
, sValue
, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO
);
102 case XML_TOK_TABLE_SCENARIO_ATTR_COMMENT
:
107 case XML_TOK_TABLE_SCENARIO_ATTR_PROTECTED
:
109 bProtected
= IsXMLToken(sValue
, XML_TRUE
);
116 ScXMLTableScenarioContext::~ScXMLTableScenarioContext()
118 GetScImport().UnlockSolarMutex();
121 SvXMLImportContext
*ScXMLTableScenarioContext::CreateChildContext(
123 const OUString
& rLName
,
124 const uno::Reference
< xml::sax::XAttributeList
>& /* xAttrList */ )
126 return new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
129 void ScXMLTableScenarioContext::EndElement()
131 SCTAB
nCurrTable( GetScImport().GetTables().GetCurrentSheet() );
132 ScDocument
* pDoc(GetScImport().GetDocument());
135 pDoc
->SetScenario( nCurrTable
, true );
136 sal_uInt16
nFlags( 0 );
138 nFlags
|= SC_SCENARIO_SHOWFRAME
;
140 nFlags
|= SC_SCENARIO_TWOWAY
;
142 nFlags
|= SC_SCENARIO_ATTRIB
;
144 nFlags
|= SC_SCENARIO_VALUE
;
146 nFlags
|= SC_SCENARIO_PROTECT
;
147 pDoc
->SetScenarioData( nCurrTable
, OUString( sComment
), aBorderColor
, nFlags
);
148 for( size_t i
= 0; i
< aScenarioRanges
.size(); ++i
)
150 ScRange
* pRange(aScenarioRanges
[ i
]);
152 pDoc
->ApplyFlagsTab( pRange
->aStart
.Col(), pRange
->aStart
.Row(),
153 pRange
->aEnd
.Col(), pRange
->aEnd
.Row(), nCurrTable
, SC_MF_SCENARIO
);
155 pDoc
->SetActiveScenario( nCurrTable
, bIsActive
);
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */