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