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 :
38 0 : ScXMLTableScenarioContext::ScXMLTableScenarioContext(
39 : ScXMLImport& rImport,
40 : sal_uInt16 nPrfx,
41 : const OUString& rLName,
42 : const uno::Reference< xml::sax::XAttributeList >& xAttrList ):
43 : SvXMLImportContext( rImport, nPrfx, rLName ),
44 : aBorderColor( COL_BLACK ),
45 : bDisplayBorder( true ),
46 : bCopyBack( true ),
47 : bCopyStyles( true ),
48 : bCopyFormulas( true ),
49 : bIsActive( false ),
50 0 : bProtected( false )
51 : {
52 0 : rImport.LockSolarMutex();
53 0 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
54 0 : const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetTableScenarioAttrTokenMap());
55 0 : for( sal_Int16 i = 0; i < nAttrCount; ++i )
56 : {
57 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
58 0 : OUString aLocalName;
59 0 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
60 0 : sAttrName, &aLocalName ));
61 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
62 :
63 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
64 : {
65 : case XML_TOK_TABLE_SCENARIO_ATTR_DISPLAY_BORDER:
66 : {
67 0 : bDisplayBorder = IsXMLToken(sValue, XML_TRUE);
68 : }
69 0 : break;
70 : case XML_TOK_TABLE_SCENARIO_ATTR_BORDER_COLOR:
71 : {
72 0 : sal_Int32 nColor(0);
73 0 : ::sax::Converter::convertColor(nColor, sValue);
74 0 : aBorderColor.SetColor(nColor);
75 : }
76 0 : break;
77 : case XML_TOK_TABLE_SCENARIO_ATTR_COPY_BACK:
78 : {
79 0 : bCopyBack = IsXMLToken(sValue, XML_TRUE);
80 : }
81 0 : break;
82 : case XML_TOK_TABLE_SCENARIO_ATTR_COPY_STYLES:
83 : {
84 0 : bCopyStyles = IsXMLToken(sValue, XML_TRUE);
85 : }
86 0 : break;
87 : case XML_TOK_TABLE_SCENARIO_ATTR_COPY_FORMULAS:
88 : {
89 0 : bCopyFormulas = IsXMLToken(sValue, XML_TRUE);
90 : }
91 0 : break;
92 : case XML_TOK_TABLE_SCENARIO_ATTR_IS_ACTIVE:
93 : {
94 0 : bIsActive = IsXMLToken(sValue, XML_TRUE);
95 : }
96 0 : break;
97 : case XML_TOK_TABLE_SCENARIO_ATTR_SCENARIO_RANGES:
98 : {
99 : ScRangeStringConverter::GetRangeListFromString(
100 0 : aScenarioRanges, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO );
101 : }
102 0 : break;
103 : case XML_TOK_TABLE_SCENARIO_ATTR_COMMENT:
104 : {
105 0 : sComment = sValue;
106 : }
107 0 : break;
108 : case XML_TOK_TABLE_SCENARIO_ATTR_PROTECTED:
109 : {
110 0 : bProtected = IsXMLToken(sValue, XML_TRUE);
111 : }
112 0 : break;
113 : }
114 0 : }
115 0 : }
116 :
117 0 : ScXMLTableScenarioContext::~ScXMLTableScenarioContext()
118 : {
119 0 : GetScImport().UnlockSolarMutex();
120 0 : }
121 :
122 0 : SvXMLImportContext *ScXMLTableScenarioContext::CreateChildContext(
123 : sal_uInt16 nPrefix,
124 : const OUString& rLName,
125 : const uno::Reference< xml::sax::XAttributeList >& /* xAttrList */ )
126 : {
127 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );
128 : }
129 :
130 0 : void ScXMLTableScenarioContext::EndElement()
131 : {
132 0 : SCTAB nCurrTable( GetScImport().GetTables().GetCurrentSheet() );
133 0 : ScDocument* pDoc(GetScImport().GetDocument());
134 0 : if (pDoc)
135 : {
136 0 : pDoc->SetScenario( nCurrTable, true );
137 0 : sal_uInt16 nFlags( 0 );
138 0 : if( bDisplayBorder )
139 0 : nFlags |= SC_SCENARIO_SHOWFRAME;
140 0 : if( bCopyBack )
141 0 : nFlags |= SC_SCENARIO_TWOWAY;
142 0 : if( bCopyStyles )
143 0 : nFlags |= SC_SCENARIO_ATTRIB;
144 0 : if( !bCopyFormulas )
145 0 : nFlags |= SC_SCENARIO_VALUE;
146 0 : if( bProtected )
147 0 : nFlags |= SC_SCENARIO_PROTECT;
148 0 : pDoc->SetScenarioData( nCurrTable, OUString( sComment ), aBorderColor, nFlags );
149 0 : for( size_t i = 0; i < aScenarioRanges.size(); ++i )
150 : {
151 0 : ScRange* pRange(aScenarioRanges[ i ]);
152 0 : if( pRange )
153 0 : pDoc->ApplyFlagsTab( pRange->aStart.Col(), pRange->aStart.Row(),
154 0 : pRange->aEnd.Col(), pRange->aEnd.Row(), nCurrTable, SC_MF_SCENARIO );
155 : }
156 0 : pDoc->SetActiveScenario( nCurrTable, bIsActive );
157 : }
158 0 : }
159 :
160 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|