Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / xml / XMLConsolidationContext.cxx
blob71dafb482636fe6a587d3b52fb6dcf4fb64c02d9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "XMLConsolidationContext.hxx"
21 #include <document.hxx>
22 #include <rangeutl.hxx>
23 #include "xmlimprt.hxx"
24 #include "XMLConverter.hxx"
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlnmspe.hxx>
28 using namespace ::com::sun::star;
29 using namespace xmloff::token;
31 ScXMLConsolidationContext::ScXMLConsolidationContext(
32 ScXMLImport& rImport,
33 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
34 ScXMLImportContext( rImport ),
35 eFunction( SUBTOTAL_FUNC_NONE ),
36 bLinkToSource( false ),
37 bTargetAddr(false)
39 rImport.LockSolarMutex();
40 if ( rAttrList.is() )
42 for (auto &aIter : *rAttrList)
44 switch (aIter.getToken())
46 case XML_ELEMENT( TABLE, XML_FUNCTION ):
47 eFunction = ScXMLConverter::GetSubTotalFuncFromString( aIter.toString() );
48 break;
49 case XML_ELEMENT( TABLE, XML_SOURCE_CELL_RANGE_ADDRESSES ):
50 sSourceList = aIter.toString();
51 break;
52 case XML_ELEMENT( TABLE, XML_TARGET_CELL_ADDRESS ):
54 sal_Int32 nOffset(0);
55 bTargetAddr = ScRangeStringConverter::GetAddressFromString(
56 aTargetAddr, aIter.toString(), GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
58 break;
59 case XML_ELEMENT( TABLE, XML_USE_LABEL ):
60 sUseLabel = aIter.toString();
61 break;
62 case XML_ELEMENT( TABLE, XML_LINK_TO_SOURCE_DATA ):
63 bLinkToSource = IsXMLToken( aIter, XML_TRUE );
64 break;
70 ScXMLConsolidationContext::~ScXMLConsolidationContext()
72 GetScImport().UnlockSolarMutex();
75 void SAL_CALL ScXMLConsolidationContext::endFastElement( sal_Int32 /*nElement*/ )
77 if (bTargetAddr)
79 std::unique_ptr<ScConsolidateParam> pConsParam(new ScConsolidateParam);
80 pConsParam->nCol = aTargetAddr.Col();
81 pConsParam->nRow = aTargetAddr.Row();
82 pConsParam->nTab = aTargetAddr.Tab();
83 pConsParam->eFunction = eFunction;
85 sal_uInt16 nCount = static_cast<sal_uInt16>(std::min( ScRangeStringConverter::GetTokenCount( sSourceList ), sal_Int32(0xFFFF) ));
86 if( nCount )
88 std::unique_ptr<ScArea[]> ppAreas(new ScArea[ nCount ]);
89 sal_Int32 nOffset = 0;
90 sal_uInt16 nIndex;
91 for( nIndex = 0; nIndex < nCount; ++nIndex )
93 if ( !ScRangeStringConverter::GetAreaFromString(
94 ppAreas[ nIndex ], sSourceList, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ) )
96 //! handle error
100 pConsParam->SetAreas( std::move(ppAreas), nCount );
103 pConsParam->bByCol = pConsParam->bByRow = false;
104 if( IsXMLToken(sUseLabel, XML_COLUMN ) )
105 pConsParam->bByCol = true;
106 else if( IsXMLToken( sUseLabel, XML_ROW ) )
107 pConsParam->bByRow = true;
108 else if( IsXMLToken( sUseLabel, XML_BOTH ) )
109 pConsParam->bByCol = pConsParam->bByRow = true;
111 pConsParam->bReferenceData = bLinkToSource;
113 ScDocument* pDoc = GetScImport().GetDocument();
114 if( pDoc )
115 pDoc->SetConsolidateDlgData( std::move(pConsParam) );
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */