1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/xmlnamespace.hxx>
28 using namespace ::com::sun::star
;
29 using namespace xmloff::token
;
31 ScXMLConsolidationContext::ScXMLConsolidationContext(
33 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
) :
34 ScXMLImportContext( rImport
),
35 eFunction( SUBTOTAL_FUNC_NONE
),
36 bLinkToSource( false ),
39 rImport
.LockSolarMutex();
40 if ( !rAttrList
.is() )
43 for (auto &aIter
: *rAttrList
)
45 switch (aIter
.getToken())
47 case XML_ELEMENT( TABLE
, XML_FUNCTION
):
48 eFunction
= ScXMLConverter::GetSubTotalFuncFromString( aIter
.toString() );
50 case XML_ELEMENT( TABLE
, XML_SOURCE_CELL_RANGE_ADDRESSES
):
51 sSourceList
= aIter
.toString();
53 case XML_ELEMENT( TABLE
, XML_TARGET_CELL_ADDRESS
):
56 ScDocument
* pDoc
= GetScImport().GetDocument();
58 bTargetAddr
= ScRangeStringConverter::GetAddressFromString(
59 aTargetAddr
, aIter
.toString(), *pDoc
, ::formula::FormulaGrammar::CONV_OOO
, nOffset
);
62 case XML_ELEMENT( TABLE
, XML_USE_LABEL
):
63 sUseLabel
= aIter
.toString();
65 case XML_ELEMENT( TABLE
, XML_LINK_TO_SOURCE_DATA
):
66 bLinkToSource
= IsXMLToken( aIter
, XML_TRUE
);
72 ScXMLConsolidationContext::~ScXMLConsolidationContext()
74 GetScImport().UnlockSolarMutex();
77 void SAL_CALL
ScXMLConsolidationContext::endFastElement( sal_Int32
/*nElement*/ )
82 std::unique_ptr
<ScConsolidateParam
> pConsParam(new ScConsolidateParam
);
83 pConsParam
->nCol
= aTargetAddr
.Col();
84 pConsParam
->nRow
= aTargetAddr
.Row();
85 pConsParam
->nTab
= aTargetAddr
.Tab();
86 pConsParam
->eFunction
= eFunction
;
88 sal_uInt16 nCount
= static_cast<sal_uInt16
>(std::min( ScRangeStringConverter::GetTokenCount( sSourceList
), sal_Int32(0xFFFF) ));
91 std::unique_ptr
<ScArea
[]> ppAreas(new ScArea
[ nCount
]);
92 sal_Int32 nOffset
= 0;
94 ScDocument
* pDoc
= GetScImport().GetDocument();
96 for( nIndex
= 0; nIndex
< nCount
; ++nIndex
)
98 if ( !ScRangeStringConverter::GetAreaFromString(
99 ppAreas
[ nIndex
], sSourceList
, *pDoc
, ::formula::FormulaGrammar::CONV_OOO
, nOffset
) )
105 pConsParam
->SetAreas( std::move(ppAreas
), nCount
);
108 pConsParam
->bByCol
= pConsParam
->bByRow
= false;
109 if( IsXMLToken(sUseLabel
, XML_COLUMN
) )
110 pConsParam
->bByCol
= true;
111 else if( IsXMLToken( sUseLabel
, XML_ROW
) )
112 pConsParam
->bByRow
= true;
113 else if( IsXMLToken( sUseLabel
, XML_BOTH
) )
114 pConsParam
->bByCol
= pConsParam
->bByRow
= true;
116 pConsParam
->bReferenceData
= bLinkToSource
;
118 ScDocument
* pDoc
= GetScImport().GetDocument();
120 pDoc
->SetConsolidateDlgData( std::move(pConsParam
) );
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */