Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "document.hxx"
21 : #include "xmlimprt.hxx"
22 : #include "xmlsceni.hxx"
23 : #include "docuno.hxx"
24 : #include "attrib.hxx"
25 : #include "XMLConverter.hxx"
26 : #include "rangeutl.hxx"
27 :
28 : #include <xmloff/xmltkmap.hxx>
29 : #include <xmloff/nmspmap.hxx>
30 : #include <xmloff/xmltoken.hxx>
31 :
32 : #include <sax/tools/converter.hxx>
33 :
34 : using namespace com::sun::star;
35 : using namespace xmloff::token;
36 :
37 0 : ScXMLTableScenarioContext::ScXMLTableScenarioContext(
38 : ScXMLImport& rImport,
39 : sal_uInt16 nPrfx,
40 : const OUString& rLName,
41 : const uno::Reference< xml::sax::XAttributeList >& xAttrList ):
42 : SvXMLImportContext( rImport, nPrfx, rLName ),
43 : aBorderColor( COL_BLACK ),
44 : bDisplayBorder( true ),
45 : bCopyBack( true ),
46 : bCopyStyles( true ),
47 : bCopyFormulas( true ),
48 : bIsActive( false ),
49 0 : bProtected( false )
50 : {
51 0 : rImport.LockSolarMutex();
52 0 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
53 0 : const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetTableScenarioAttrTokenMap());
54 0 : for( sal_Int16 i = 0; i < nAttrCount; ++i )
55 : {
56 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
57 0 : OUString aLocalName;
58 0 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
59 0 : sAttrName, &aLocalName ));
60 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
61 :
62 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
63 : {
64 : case XML_TOK_TABLE_SCENARIO_ATTR_DISPLAY_BORDER:
65 : {
66 0 : bDisplayBorder = IsXMLToken(sValue, XML_TRUE);
67 : }
68 0 : break;
69 : case XML_TOK_TABLE_SCENARIO_ATTR_BORDER_COLOR:
70 : {
71 0 : sal_Int32 nColor(0);
72 0 : ::sax::Converter::convertColor(nColor, sValue);
73 0 : aBorderColor.SetColor(nColor);
74 : }
75 0 : break;
76 : case XML_TOK_TABLE_SCENARIO_ATTR_COPY_BACK:
77 : {
78 0 : bCopyBack = IsXMLToken(sValue, XML_TRUE);
79 : }
80 0 : break;
81 : case XML_TOK_TABLE_SCENARIO_ATTR_COPY_STYLES:
82 : {
83 0 : bCopyStyles = IsXMLToken(sValue, XML_TRUE);
84 : }
85 0 : break;
86 : case XML_TOK_TABLE_SCENARIO_ATTR_COPY_FORMULAS:
87 : {
88 0 : bCopyFormulas = IsXMLToken(sValue, XML_TRUE);
89 : }
90 0 : break;
91 : case XML_TOK_TABLE_SCENARIO_ATTR_IS_ACTIVE:
92 : {
93 0 : bIsActive = IsXMLToken(sValue, XML_TRUE);
94 : }
95 0 : break;
96 : case XML_TOK_TABLE_SCENARIO_ATTR_SCENARIO_RANGES:
97 : {
98 : ScRangeStringConverter::GetRangeListFromString(
99 0 : aScenarioRanges, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO );
100 : }
101 0 : break;
102 : case XML_TOK_TABLE_SCENARIO_ATTR_COMMENT:
103 : {
104 0 : sComment = sValue;
105 : }
106 0 : break;
107 : case XML_TOK_TABLE_SCENARIO_ATTR_PROTECTED:
108 : {
109 0 : bProtected = IsXMLToken(sValue, XML_TRUE);
110 : }
111 0 : break;
112 : }
113 0 : }
114 0 : }
115 :
116 0 : ScXMLTableScenarioContext::~ScXMLTableScenarioContext()
117 : {
118 0 : GetScImport().UnlockSolarMutex();
119 0 : }
120 :
121 0 : SvXMLImportContext *ScXMLTableScenarioContext::CreateChildContext(
122 : sal_uInt16 nPrefix,
123 : const OUString& rLName,
124 : const uno::Reference< xml::sax::XAttributeList >& /* xAttrList */ )
125 : {
126 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );
127 : }
128 :
129 0 : void ScXMLTableScenarioContext::EndElement()
130 : {
131 0 : SCTAB nCurrTable( GetScImport().GetTables().GetCurrentSheet() );
132 0 : ScDocument* pDoc(GetScImport().GetDocument());
133 0 : if (pDoc)
134 : {
135 0 : pDoc->SetScenario( nCurrTable, true );
136 0 : sal_uInt16 nFlags( 0 );
137 0 : if( bDisplayBorder )
138 0 : nFlags |= SC_SCENARIO_SHOWFRAME;
139 0 : if( bCopyBack )
140 0 : nFlags |= SC_SCENARIO_TWOWAY;
141 0 : if( bCopyStyles )
142 0 : nFlags |= SC_SCENARIO_ATTRIB;
143 0 : if( !bCopyFormulas )
144 0 : nFlags |= SC_SCENARIO_VALUE;
145 0 : if( bProtected )
146 0 : nFlags |= SC_SCENARIO_PROTECT;
147 0 : pDoc->SetScenarioData( nCurrTable, OUString( sComment ), aBorderColor, nFlags );
148 0 : for( size_t i = 0; i < aScenarioRanges.size(); ++i )
149 : {
150 0 : ScRange* pRange(aScenarioRanges[ i ]);
151 0 : if( pRange )
152 0 : pDoc->ApplyFlagsTab( pRange->aStart.Col(), pRange->aStart.Row(),
153 0 : pRange->aEnd.Col(), pRange->aEnd.Row(), nCurrTable, SC_MF_SCENARIO );
154 : }
155 0 : pDoc->SetActiveScenario( nCurrTable, bIsActive );
156 : }
157 228 : }
158 :
159 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|