fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / xml / XMLDetectiveContext.cxx
blobc01c7cb9643c0a646ba55ce04e25611c3ac68ac1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "XMLDetectiveContext.hxx"
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"
30 #include <algorithm>
32 using namespace ::com::sun::star;
33 using namespace xmloff::token;
35 ScMyImpDetectiveObj::ScMyImpDetectiveObj() :
36 aSourceRange(),
37 eObjType( SC_DETOBJ_NONE ),
38 bHasError( false )
42 bool ScMyImpDetectiveOp::operator<(const ScMyImpDetectiveOp& rDetOp) const
44 return (nIndex < rDetOp.nIndex);
47 void ScMyImpDetectiveOpArray::Sort()
49 aDetectiveOpList.sort();
52 bool ScMyImpDetectiveOpArray::GetFirstOp( ScMyImpDetectiveOp& rDetOp )
54 if( aDetectiveOpList.empty() )
55 return false;
56 ScMyImpDetectiveOpList::iterator aItr = aDetectiveOpList.begin();
57 rDetOp = *aItr;
58 aDetectiveOpList.erase( aItr );
59 return true;
62 ScXMLDetectiveContext::ScXMLDetectiveContext(
63 ScXMLImport& rImport,
64 sal_uInt16 nPrfx,
65 const OUString& rLName,
66 ScMyImpDetectiveObjVec* pNewDetectiveObjVec ) :
67 SvXMLImportContext( rImport, nPrfx, rLName ),
68 pDetectiveObjVec( pNewDetectiveObjVec )
72 ScXMLDetectiveContext::~ScXMLDetectiveContext()
76 SvXMLImportContext *ScXMLDetectiveContext::CreateChildContext(
77 sal_uInt16 nPrefix,
78 const OUString& rLName,
79 const uno::Reference< xml::sax::XAttributeList>& xAttrList )
81 SvXMLImportContext* pContext = NULL;
82 const SvXMLTokenMap& rTokenMap = GetScImport().GetDetectiveElemTokenMap();
84 switch( rTokenMap.Get( nPrefix, rLName ) )
86 case XML_TOK_DETECTIVE_ELEM_HIGHLIGHTED:
87 pContext = new ScXMLDetectiveHighlightedContext( GetScImport(), nPrefix, rLName, xAttrList, pDetectiveObjVec );
88 break;
89 case XML_TOK_DETECTIVE_ELEM_OPERATION:
90 pContext = new ScXMLDetectiveOperationContext( GetScImport(), nPrefix, rLName, xAttrList );
91 break;
93 if( !pContext )
94 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
96 return pContext;
99 void ScXMLDetectiveContext::EndElement()
103 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 bValid( false )
114 if( !xAttrList.is() ) return;
116 sal_Int16 nAttrCount = xAttrList->getLength();
117 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDetectiveHighlightedAttrTokenMap();
119 for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
121 const OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
122 const OUString& sValue (xAttrList->getValueByIndex( nIndex ));
123 OUString aLocalName;
124 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
126 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
128 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CELL_RANGE:
130 sal_Int32 nOffset(0);
131 ScXMLImport::MutexGuard aGuard(GetScImport());
132 bValid = ScRangeStringConverter::GetRangeFromString( aDetectiveObj.aSourceRange, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
134 break;
135 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_DIRECTION:
136 aDetectiveObj.eObjType = ScXMLConverter::GetDetObjTypeFromString( sValue );
137 break;
138 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CONTAINS_ERROR:
139 aDetectiveObj.bHasError = IsXMLToken(sValue, XML_TRUE);
140 break;
141 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_MARKED_INVALID:
143 if (IsXMLToken(sValue, XML_TRUE))
144 aDetectiveObj.eObjType = SC_DETOBJ_CIRCLE;
146 break;
151 ScXMLDetectiveHighlightedContext::~ScXMLDetectiveHighlightedContext()
155 SvXMLImportContext *ScXMLDetectiveHighlightedContext::CreateChildContext(
156 sal_uInt16 nPrefix,
157 const OUString& rLName,
158 const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
160 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
163 void ScXMLDetectiveHighlightedContext::EndElement()
165 switch( aDetectiveObj.eObjType )
167 case SC_DETOBJ_ARROW:
168 case SC_DETOBJ_TOOTHERTAB:
169 break;
170 case SC_DETOBJ_FROMOTHERTAB:
171 case SC_DETOBJ_CIRCLE:
172 bValid = true;
173 break;
174 default:
175 bValid = false;
177 if( bValid )
178 pDetectiveObjVec->push_back( aDetectiveObj );
181 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 bHasType( false )
190 if( !xAttrList.is() ) return;
192 sal_Int16 nAttrCount = xAttrList->getLength();
193 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDetectiveOperationAttrTokenMap();
195 for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
197 const OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
198 const OUString& sValue (xAttrList->getValueByIndex( nIndex ));
199 OUString aLocalName;
200 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
202 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
204 case XML_TOK_DETECTIVE_OPERATION_ATTR_NAME:
205 bHasType = ScXMLConverter::GetDetOpTypeFromString( aDetectiveOp.eOpType, sValue );
206 break;
207 case XML_TOK_DETECTIVE_OPERATION_ATTR_INDEX:
209 sal_Int32 nValue;
210 if (::sax::Converter::convertNumber( nValue, sValue, 0 ))
211 aDetectiveOp.nIndex = nValue;
213 break;
216 aDetectiveOp.aPosition = rImport.GetTables().GetCurrentCellPos();
219 ScXMLDetectiveOperationContext::~ScXMLDetectiveOperationContext()
223 SvXMLImportContext *ScXMLDetectiveOperationContext::CreateChildContext(
224 sal_uInt16 nPrefix,
225 const OUString& rLName,
226 const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
228 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
231 void ScXMLDetectiveOperationContext::EndElement()
233 if( bHasType && (aDetectiveOp.nIndex >= 0) )
234 GetScImport().GetDetectiveOpArray()->AddDetectiveOp( aDetectiveOp );
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */