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/nmspmap.hxx>
26 #include <xmloff/xmltoken.hxx>
28 using namespace ::com::sun::star
;
29 using namespace xmloff::token
;
31 ScXMLConsolidationContext::ScXMLConsolidationContext(
34 const OUString
& rLName
,
35 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
) :
36 SvXMLImportContext( rImport
, nPrfx
, rLName
),
37 eFunction( SUBTOTAL_FUNC_NONE
),
38 bLinkToSource( false ),
41 rImport
.LockSolarMutex();
42 if( !xAttrList
.is() ) return;
44 sal_Int16 nAttrCount
= xAttrList
->getLength();
45 const SvXMLTokenMap
& rAttrTokenMap
= GetScImport().GetConsolidationAttrTokenMap();
47 for( sal_Int16 nIndex
= 0; nIndex
< nAttrCount
; ++nIndex
)
49 const OUString
& sAttrName (xAttrList
->getNameByIndex( nIndex
));
50 const OUString
& sValue (xAttrList
->getValueByIndex( nIndex
));
52 sal_uInt16 nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
54 switch( rAttrTokenMap
.Get( nPrefix
, aLocalName
) )
56 case XML_TOK_CONSOLIDATION_ATTR_FUNCTION
:
57 eFunction
= ScXMLConverter::GetSubTotalFuncFromString( sValue
);
59 case XML_TOK_CONSOLIDATION_ATTR_SOURCE_RANGES
:
62 case XML_TOK_CONSOLIDATION_ATTR_TARGET_ADDRESS
:
65 bTargetAddr
= ScRangeStringConverter::GetAddressFromString(
66 aTargetAddr
, sValue
, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO
, nOffset
);
69 case XML_TOK_CONSOLIDATION_ATTR_USE_LABEL
:
72 case XML_TOK_CONSOLIDATION_ATTR_LINK_TO_SOURCE
:
73 bLinkToSource
= IsXMLToken(sValue
, XML_TRUE
);
79 ScXMLConsolidationContext::~ScXMLConsolidationContext()
81 GetScImport().UnlockSolarMutex();
84 SvXMLImportContext
*ScXMLConsolidationContext::CreateChildContext(
86 const OUString
& rLName
,
87 const uno::Reference
< xml::sax::XAttributeList
>& /* xAttrList */ )
89 return new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
92 void ScXMLConsolidationContext::EndElement()
96 ScConsolidateParam aConsParam
;
97 aConsParam
.nCol
= aTargetAddr
.Col();
98 aConsParam
.nRow
= aTargetAddr
.Row();
99 aConsParam
.nTab
= aTargetAddr
.Tab();
100 aConsParam
.eFunction
= eFunction
;
102 sal_uInt16 nCount
= (sal_uInt16
) std::min( ScRangeStringConverter::GetTokenCount( sSourceList
), (sal_Int32
)0xFFFF );
103 ScArea
** ppAreas
= nCount
? new ScArea
*[ nCount
] : NULL
;
106 sal_Int32 nOffset
= 0;
108 for( nIndex
= 0; nIndex
< nCount
; ++nIndex
)
110 ppAreas
[ nIndex
] = new ScArea
;
111 if ( !ScRangeStringConverter::GetAreaFromString(
112 *ppAreas
[ nIndex
], sSourceList
, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO
, nOffset
) )
118 aConsParam
.SetAreas( ppAreas
, nCount
);
120 // array is copied in SetAreas
121 for( nIndex
= 0; nIndex
< nCount
; ++nIndex
)
122 delete ppAreas
[nIndex
];
126 aConsParam
.bByCol
= aConsParam
.bByRow
= false;
127 if( IsXMLToken(sUseLabel
, XML_COLUMN
) )
128 aConsParam
.bByCol
= true;
129 else if( IsXMLToken( sUseLabel
, XML_ROW
) )
130 aConsParam
.bByRow
= true;
131 else if( IsXMLToken( sUseLabel
, XML_BOTH
) )
132 aConsParam
.bByCol
= aConsParam
.bByRow
= true;
134 aConsParam
.bReferenceData
= bLinkToSource
;
136 ScDocument
* pDoc
= GetScImport().GetDocument();
138 pDoc
->SetConsolidateDlgData( &aConsParam
);
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */