1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
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(
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
));
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
);
89 case XML_TOK_TABLE_SCENARIO_ATTR_BORDER_COLOR
:
91 SvXMLUnitConverter::convertColor(aBorderColor
, sValue
);
94 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_BACK
:
96 bCopyBack
= IsXMLToken(sValue
, XML_TRUE
);
99 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_STYLES
:
101 bCopyStyles
= IsXMLToken(sValue
, XML_TRUE
);
104 case XML_TOK_TABLE_SCENARIO_ATTR_COPY_FORMULAS
:
106 bCopyFormulas
= IsXMLToken(sValue
, XML_TRUE
);
109 case XML_TOK_TABLE_SCENARIO_ATTR_IS_ACTIVE
:
111 bIsActive
= IsXMLToken(sValue
, XML_TRUE
);
114 case XML_TOK_TABLE_SCENARIO_ATTR_SCENARIO_RANGES
:
116 ScRangeStringConverter::GetRangeListFromString(
117 aScenarioRanges
, sValue
, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO
);
120 case XML_TOK_TABLE_SCENARIO_ATTR_COMMENT
:
125 case XML_TOK_TABLE_SCENARIO_ATTR_PROTECTED
:
127 bProtected
= IsXMLToken(sValue
, XML_TRUE
);
134 ScXMLTableScenarioContext::~ScXMLTableScenarioContext()
136 GetScImport().UnlockSolarMutex();
139 SvXMLImportContext
*ScXMLTableScenarioContext::CreateChildContext(
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());
153 pDoc
->SetScenario( nCurrTable
, TRUE
);
156 nFlags
|= SC_SCENARIO_SHOWFRAME
;
158 nFlags
|= SC_SCENARIO_TWOWAY
;
160 nFlags
|= SC_SCENARIO_ATTRIB
;
162 nFlags
|= SC_SCENARIO_VALUE
;
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
));
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
);