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 "XMLDetectiveContext.hxx"
23 :
24 : #include <sax/tools/converter.hxx>
25 : #include <xmloff/nmspmap.hxx>
26 : #include <xmloff/xmltoken.hxx>
27 : #include "convuno.hxx"
28 : #include "xmlimprt.hxx"
29 : #include "XMLConverter.hxx"
30 : #include "rangeutl.hxx"
31 :
32 : #include <algorithm>
33 :
34 : using namespace ::com::sun::star;
35 : using namespace xmloff::token;
36 :
37 :
38 0 : ScMyImpDetectiveObj::ScMyImpDetectiveObj() :
39 : aSourceRange(),
40 : eObjType( SC_DETOBJ_NONE ),
41 0 : bHasError( false )
42 : {
43 0 : }
44 :
45 0 : bool ScMyImpDetectiveOp::operator<(const ScMyImpDetectiveOp& rDetOp) const
46 : {
47 0 : return (nIndex < rDetOp.nIndex);
48 : }
49 :
50 107 : void ScMyImpDetectiveOpArray::Sort()
51 : {
52 107 : aDetectiveOpList.sort();
53 107 : }
54 :
55 107 : bool ScMyImpDetectiveOpArray::GetFirstOp( ScMyImpDetectiveOp& rDetOp )
56 : {
57 107 : if( aDetectiveOpList.empty() )
58 107 : return false;
59 0 : ScMyImpDetectiveOpList::iterator aItr = aDetectiveOpList.begin();
60 0 : rDetOp = *aItr;
61 0 : aDetectiveOpList.erase( aItr );
62 0 : return true;
63 : }
64 :
65 :
66 0 : ScXMLDetectiveContext::ScXMLDetectiveContext(
67 : ScXMLImport& rImport,
68 : sal_uInt16 nPrfx,
69 : const OUString& rLName,
70 : ScMyImpDetectiveObjVec* pNewDetectiveObjVec ) :
71 : SvXMLImportContext( rImport, nPrfx, rLName ),
72 0 : pDetectiveObjVec( pNewDetectiveObjVec )
73 : {
74 0 : }
75 :
76 0 : ScXMLDetectiveContext::~ScXMLDetectiveContext()
77 : {
78 0 : }
79 :
80 0 : SvXMLImportContext *ScXMLDetectiveContext::CreateChildContext(
81 : sal_uInt16 nPrefix,
82 : const OUString& rLName,
83 : const uno::Reference< xml::sax::XAttributeList>& xAttrList )
84 : {
85 0 : SvXMLImportContext* pContext = NULL;
86 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDetectiveElemTokenMap();
87 :
88 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
89 : {
90 : case XML_TOK_DETECTIVE_ELEM_HIGHLIGHTED:
91 0 : pContext = new ScXMLDetectiveHighlightedContext( GetScImport(), nPrefix, rLName, xAttrList, pDetectiveObjVec );
92 0 : break;
93 : case XML_TOK_DETECTIVE_ELEM_OPERATION:
94 0 : pContext = new ScXMLDetectiveOperationContext( GetScImport(), nPrefix, rLName, xAttrList );
95 0 : break;
96 : }
97 0 : if( !pContext )
98 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
99 :
100 0 : return pContext;
101 : }
102 :
103 0 : void ScXMLDetectiveContext::EndElement()
104 : {
105 0 : }
106 :
107 :
108 0 : ScXMLDetectiveHighlightedContext::ScXMLDetectiveHighlightedContext(
109 : ScXMLImport& rImport,
110 : sal_uInt16 nPrfx,
111 : const OUString& rLName,
112 : const uno::Reference< xml::sax::XAttributeList >& xAttrList,
113 : ScMyImpDetectiveObjVec* pNewDetectiveObjVec ):
114 : SvXMLImportContext( rImport, nPrfx, rLName ),
115 : pDetectiveObjVec( pNewDetectiveObjVec ),
116 : aDetectiveObj(),
117 0 : bValid( false )
118 : {
119 0 : if( !xAttrList.is() ) return;
120 :
121 0 : sal_Int16 nAttrCount = xAttrList->getLength();
122 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDetectiveHighlightedAttrTokenMap();
123 :
124 0 : for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
125 : {
126 0 : const OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
127 0 : const OUString& sValue (xAttrList->getValueByIndex( nIndex ));
128 0 : OUString aLocalName;
129 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
130 :
131 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
132 : {
133 : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CELL_RANGE:
134 : {
135 0 : sal_Int32 nOffset(0);
136 0 : ScXMLImport::MutexGuard aGuard(GetScImport());
137 0 : bValid = ScRangeStringConverter::GetRangeFromString( aDetectiveObj.aSourceRange, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
138 : }
139 0 : break;
140 : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_DIRECTION:
141 0 : aDetectiveObj.eObjType = ScXMLConverter::GetDetObjTypeFromString( sValue );
142 0 : break;
143 : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CONTAINS_ERROR:
144 0 : aDetectiveObj.bHasError = IsXMLToken(sValue, XML_TRUE);
145 0 : break;
146 : case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_MARKED_INVALID:
147 : {
148 0 : if (IsXMLToken(sValue, XML_TRUE))
149 0 : aDetectiveObj.eObjType = SC_DETOBJ_CIRCLE;
150 : }
151 0 : break;
152 : }
153 0 : }
154 : }
155 :
156 0 : ScXMLDetectiveHighlightedContext::~ScXMLDetectiveHighlightedContext()
157 : {
158 0 : }
159 :
160 0 : SvXMLImportContext *ScXMLDetectiveHighlightedContext::CreateChildContext(
161 : sal_uInt16 nPrefix,
162 : const OUString& rLName,
163 : const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
164 : {
165 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );
166 : }
167 :
168 0 : void ScXMLDetectiveHighlightedContext::EndElement()
169 : {
170 0 : switch( aDetectiveObj.eObjType )
171 : {
172 : case SC_DETOBJ_ARROW:
173 : case SC_DETOBJ_TOOTHERTAB:
174 0 : break;
175 : case SC_DETOBJ_FROMOTHERTAB:
176 : case SC_DETOBJ_CIRCLE:
177 0 : bValid = true;
178 0 : break;
179 : default:
180 0 : bValid = false;
181 : }
182 0 : if( bValid )
183 0 : pDetectiveObjVec->push_back( aDetectiveObj );
184 0 : }
185 :
186 :
187 0 : ScXMLDetectiveOperationContext::ScXMLDetectiveOperationContext(
188 : ScXMLImport& rImport,
189 : sal_uInt16 nPrfx,
190 : const OUString& rLName,
191 : const uno::Reference< xml::sax::XAttributeList >& xAttrList ) :
192 : SvXMLImportContext( rImport, nPrfx, rLName ),
193 : aDetectiveOp(),
194 0 : bHasType( false )
195 : {
196 0 : if( !xAttrList.is() ) return;
197 :
198 0 : sal_Int16 nAttrCount = xAttrList->getLength();
199 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDetectiveOperationAttrTokenMap();
200 :
201 0 : for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
202 : {
203 0 : const OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
204 0 : const OUString& sValue (xAttrList->getValueByIndex( nIndex ));
205 0 : OUString aLocalName;
206 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
207 :
208 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
209 : {
210 : case XML_TOK_DETECTIVE_OPERATION_ATTR_NAME:
211 0 : bHasType = ScXMLConverter::GetDetOpTypeFromString( aDetectiveOp.eOpType, sValue );
212 0 : break;
213 : case XML_TOK_DETECTIVE_OPERATION_ATTR_INDEX:
214 : {
215 : sal_Int32 nValue;
216 0 : if (::sax::Converter::convertNumber( nValue, sValue, 0 ))
217 0 : aDetectiveOp.nIndex = nValue;
218 : }
219 0 : break;
220 : }
221 0 : }
222 0 : aDetectiveOp.aPosition = rImport.GetTables().GetCurrentCellPos();
223 : }
224 :
225 0 : ScXMLDetectiveOperationContext::~ScXMLDetectiveOperationContext()
226 : {
227 0 : }
228 :
229 0 : SvXMLImportContext *ScXMLDetectiveOperationContext::CreateChildContext(
230 : sal_uInt16 nPrefix,
231 : const OUString& rLName,
232 : const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
233 : {
234 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLName );
235 : }
236 :
237 0 : void ScXMLDetectiveOperationContext::EndElement()
238 : {
239 0 : if( bHasType && (aDetectiveOp.nIndex >= 0) )
240 0 : GetScImport().GetDetectiveOpArray()->AddDetectiveOp( aDetectiveOp );
241 0 : }
242 :
243 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|