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