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 :
21 :
22 : #include "XMLConsolidationContext.hxx"
23 : #include "document.hxx"
24 : #include "rangeutl.hxx"
25 : #include "xmlimprt.hxx"
26 : #include "XMLConverter.hxx"
27 : #include <xmloff/nmspmap.hxx>
28 : #include <xmloff/xmltoken.hxx>
29 :
30 : using namespace ::com::sun::star;
31 : using namespace xmloff::token;
32 :
33 :
34 0 : ScXMLConsolidationContext::ScXMLConsolidationContext(
35 : ScXMLImport& rImport,
36 : sal_uInt16 nPrfx,
37 : const OUString& rLName,
38 : const uno::Reference< xml::sax::XAttributeList >& xAttrList ) :
39 : SvXMLImportContext( rImport, nPrfx, rLName ),
40 : eFunction( SUBTOTAL_FUNC_NONE ),
41 : bLinkToSource( false ),
42 0 : bTargetAddr(false)
43 : {
44 0 : ScXMLImport::MutexGuard aGuard(GetScImport());
45 0 : if( !xAttrList.is() ) return;
46 :
47 0 : sal_Int16 nAttrCount = xAttrList->getLength();
48 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetConsolidationAttrTokenMap();
49 :
50 0 : for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
51 : {
52 0 : const OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
53 0 : const OUString& sValue (xAttrList->getValueByIndex( nIndex ));
54 0 : OUString aLocalName;
55 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
56 :
57 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
58 : {
59 : case XML_TOK_CONSOLIDATION_ATTR_FUNCTION:
60 0 : eFunction = ScXMLConverter::GetSubTotalFuncFromString( sValue );
61 0 : break;
62 : case XML_TOK_CONSOLIDATION_ATTR_SOURCE_RANGES:
63 0 : sSourceList = sValue;
64 0 : break;
65 : case XML_TOK_CONSOLIDATION_ATTR_TARGET_ADDRESS:
66 : {
67 0 : sal_Int32 nOffset(0);
68 : bTargetAddr = ScRangeStringConverter::GetAddressFromString(
69 0 : aTargetAddr, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
70 : }
71 0 : break;
72 : case XML_TOK_CONSOLIDATION_ATTR_USE_LABEL:
73 0 : sUseLabel = sValue;
74 0 : break;
75 : case XML_TOK_CONSOLIDATION_ATTR_LINK_TO_SOURCE:
76 0 : bLinkToSource = IsXMLToken(sValue, XML_TRUE);
77 0 : break;
78 : }
79 0 : }
80 : }
81 :
82 0 : ScXMLConsolidationContext::~ScXMLConsolidationContext()
83 : {
84 0 : }
85 :
86 0 : SvXMLImportContext *ScXMLConsolidationContext::CreateChildContext(
87 : sal_uInt16 nPrefix,
88 : const OUString& rLName,
89 : const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
90 : {
91 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );
92 : }
93 :
94 0 : void ScXMLConsolidationContext::EndElement()
95 : {
96 0 : if (bTargetAddr)
97 : {
98 0 : ScConsolidateParam aConsParam;
99 0 : aConsParam.nCol = aTargetAddr.Col();
100 0 : aConsParam.nRow = aTargetAddr.Row();
101 0 : aConsParam.nTab = aTargetAddr.Tab();
102 0 : aConsParam.eFunction = eFunction;
103 :
104 0 : sal_uInt16 nCount = (sal_uInt16) std::min( ScRangeStringConverter::GetTokenCount( sSourceList ), (sal_Int32)0xFFFF );
105 0 : ScArea** ppAreas = nCount ? new ScArea*[ nCount ] : NULL;
106 0 : if( ppAreas )
107 : {
108 0 : sal_Int32 nOffset = 0;
109 : sal_uInt16 nIndex;
110 0 : for( nIndex = 0; nIndex < nCount; ++nIndex )
111 : {
112 0 : ppAreas[ nIndex ] = new ScArea;
113 0 : if ( !ScRangeStringConverter::GetAreaFromString(
114 0 : *ppAreas[ nIndex ], sSourceList, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ) )
115 : {
116 : //! handle error
117 : }
118 : }
119 :
120 0 : aConsParam.SetAreas( ppAreas, nCount );
121 :
122 : // array is copied in SetAreas
123 0 : for( nIndex = 0; nIndex < nCount; ++nIndex )
124 0 : delete ppAreas[nIndex];
125 0 : delete[] ppAreas;
126 : }
127 :
128 0 : aConsParam.bByCol = aConsParam.bByRow = false;
129 0 : if( IsXMLToken(sUseLabel, XML_COLUMN ) )
130 0 : aConsParam.bByCol = true;
131 0 : else if( IsXMLToken( sUseLabel, XML_ROW ) )
132 0 : aConsParam.bByRow = true;
133 0 : else if( IsXMLToken( sUseLabel, XML_BOTH ) )
134 0 : aConsParam.bByCol = aConsParam.bByRow = true;
135 :
136 0 : aConsParam.bReferenceData = bLinkToSource;
137 :
138 0 : ScDocument* pDoc = GetScImport().GetDocument();
139 0 : if( pDoc )
140 0 : pDoc->SetConsolidateDlgData( &aConsParam );
141 : }
142 0 : GetScImport().UnlockSolarMutex();
143 0 : }
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|