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