1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10*b3f79822SAndrew Rist *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19*b3f79822SAndrew Rist *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir //___________________________________________________________________
30cdf0e10cSrcweir #include "XMLConsolidationContext.hxx"
31cdf0e10cSrcweir #include "document.hxx"
32cdf0e10cSrcweir #include "rangeutl.hxx"
33cdf0e10cSrcweir #include "xmlimprt.hxx"
34cdf0e10cSrcweir #include "XMLConverter.hxx"
35cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
36cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir using ::rtl::OUString;
39cdf0e10cSrcweir using namespace ::com::sun::star;
40cdf0e10cSrcweir using namespace xmloff::token;
41cdf0e10cSrcweir
42cdf0e10cSrcweir
43cdf0e10cSrcweir //___________________________________________________________________
44cdf0e10cSrcweir
ScXMLConsolidationContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)45cdf0e10cSrcweir ScXMLConsolidationContext::ScXMLConsolidationContext(
46cdf0e10cSrcweir ScXMLImport& rImport,
47cdf0e10cSrcweir sal_uInt16 nPrfx,
48cdf0e10cSrcweir const OUString& rLName,
49cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList >& xAttrList ) :
50cdf0e10cSrcweir SvXMLImportContext( rImport, nPrfx, rLName ),
51cdf0e10cSrcweir eFunction( SUBTOTAL_FUNC_NONE ),
52cdf0e10cSrcweir bLinkToSource( sal_False ),
53cdf0e10cSrcweir bTargetAddr(sal_False)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir rImport.LockSolarMutex();
56cdf0e10cSrcweir if( !xAttrList.is() ) return;
57cdf0e10cSrcweir
58cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList->getLength();
59cdf0e10cSrcweir const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetConsolidationAttrTokenMap();
60cdf0e10cSrcweir
61cdf0e10cSrcweir for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir const rtl::OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
64cdf0e10cSrcweir const rtl::OUString& sValue (xAttrList->getValueByIndex( nIndex ));
65cdf0e10cSrcweir OUString aLocalName;
66cdf0e10cSrcweir sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
67cdf0e10cSrcweir
68cdf0e10cSrcweir switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir case XML_TOK_CONSOLIDATION_ATTR_FUNCTION:
71cdf0e10cSrcweir eFunction = ScXMLConverter::GetSubTotalFuncFromString( sValue );
72cdf0e10cSrcweir break;
73cdf0e10cSrcweir case XML_TOK_CONSOLIDATION_ATTR_SOURCE_RANGES:
74cdf0e10cSrcweir sSourceList = sValue;
75cdf0e10cSrcweir break;
76cdf0e10cSrcweir case XML_TOK_CONSOLIDATION_ATTR_TARGET_ADDRESS:
77cdf0e10cSrcweir {
78cdf0e10cSrcweir sal_Int32 nOffset(0);
79cdf0e10cSrcweir bTargetAddr = ScRangeStringConverter::GetAddressFromString(
80cdf0e10cSrcweir aTargetAddr, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
81cdf0e10cSrcweir }
82cdf0e10cSrcweir break;
83cdf0e10cSrcweir case XML_TOK_CONSOLIDATION_ATTR_USE_LABEL:
84cdf0e10cSrcweir sUseLabel = sValue;
85cdf0e10cSrcweir break;
86cdf0e10cSrcweir case XML_TOK_CONSOLIDATION_ATTR_LINK_TO_SOURCE:
87cdf0e10cSrcweir bLinkToSource = IsXMLToken(sValue, XML_TRUE);
88cdf0e10cSrcweir break;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir }
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
~ScXMLConsolidationContext()93cdf0e10cSrcweir ScXMLConsolidationContext::~ScXMLConsolidationContext()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)97cdf0e10cSrcweir SvXMLImportContext *ScXMLConsolidationContext::CreateChildContext(
98cdf0e10cSrcweir sal_uInt16 nPrefix,
99cdf0e10cSrcweir const OUString& rLName,
100cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir return new SvXMLImportContext( GetImport(), nPrefix, rLName );
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
EndElement()105cdf0e10cSrcweir void ScXMLConsolidationContext::EndElement()
106cdf0e10cSrcweir {
107cdf0e10cSrcweir if (bTargetAddr)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir ScConsolidateParam aConsParam;
110cdf0e10cSrcweir aConsParam.nCol = aTargetAddr.Col();
111cdf0e10cSrcweir aConsParam.nRow = aTargetAddr.Row();
112cdf0e10cSrcweir aConsParam.nTab = aTargetAddr.Tab();
113cdf0e10cSrcweir aConsParam.eFunction = eFunction;
114cdf0e10cSrcweir
115cdf0e10cSrcweir sal_Bool bError = sal_False;
116cdf0e10cSrcweir sal_uInt16 nCount = (sal_uInt16) Min( ScRangeStringConverter::GetTokenCount( sSourceList ), (sal_Int32)0xFFFF );
117cdf0e10cSrcweir ScArea** ppAreas = nCount ? new ScArea*[ nCount ] : NULL;
118cdf0e10cSrcweir if( ppAreas )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir sal_Int32 nOffset = 0;
121cdf0e10cSrcweir sal_uInt16 nIndex;
122cdf0e10cSrcweir for( nIndex = 0; nIndex < nCount; ++nIndex )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir ppAreas[ nIndex ] = new ScArea;
125cdf0e10cSrcweir if ( !ScRangeStringConverter::GetAreaFromString(
126cdf0e10cSrcweir *ppAreas[ nIndex ], sSourceList, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ) )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir bError = sal_True; //! handle error
129cdf0e10cSrcweir }
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
132cdf0e10cSrcweir aConsParam.SetAreas( ppAreas, nCount );
133cdf0e10cSrcweir
134cdf0e10cSrcweir // array is copied in SetAreas
135cdf0e10cSrcweir for( nIndex = 0; nIndex < nCount; ++nIndex )
136cdf0e10cSrcweir delete ppAreas[nIndex];
137cdf0e10cSrcweir delete[] ppAreas;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir aConsParam.bByCol = aConsParam.bByRow = sal_False;
141cdf0e10cSrcweir if( IsXMLToken(sUseLabel, XML_COLUMN ) )
142cdf0e10cSrcweir aConsParam.bByCol = sal_True;
143cdf0e10cSrcweir else if( IsXMLToken( sUseLabel, XML_ROW ) )
144cdf0e10cSrcweir aConsParam.bByRow = sal_True;
145cdf0e10cSrcweir else if( IsXMLToken( sUseLabel, XML_BOTH ) )
146cdf0e10cSrcweir aConsParam.bByCol = aConsParam.bByRow = sal_True;
147cdf0e10cSrcweir
148cdf0e10cSrcweir aConsParam.bReferenceData = bLinkToSource;
149cdf0e10cSrcweir
150cdf0e10cSrcweir ScDocument* pDoc = GetScImport().GetDocument();
151cdf0e10cSrcweir if( pDoc )
152cdf0e10cSrcweir pDoc->SetConsolidateDlgData( &aConsParam );
153cdf0e10cSrcweir }
154cdf0e10cSrcweir GetScImport().UnlockSolarMutex();
155cdf0e10cSrcweir }
156cdf0e10cSrcweir
157