tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / filter / xml / XMLDetectiveContext.cxx
blobb6e3af33ad9d21b39f9860dd1b3611bccc4aa46e
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/xmltoken.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include "xmlimprt.hxx"
26 #include "XMLConverter.hxx"
27 #include <rangeutl.hxx>
29 using namespace ::com::sun::star;
30 using namespace xmloff::token;
32 ScMyImpDetectiveObj::ScMyImpDetectiveObj() :
33 eObjType( SC_DETOBJ_NONE ),
34 bHasError( false )
38 bool ScMyImpDetectiveOp::operator<(const ScMyImpDetectiveOp& rDetOp) const
40 return (nIndex < rDetOp.nIndex);
43 void ScMyImpDetectiveOpArray::Sort()
45 aDetectiveOpList.sort();
48 bool ScMyImpDetectiveOpArray::GetFirstOp( ScMyImpDetectiveOp& rDetOp )
50 if( aDetectiveOpList.empty() )
51 return false;
52 ScMyImpDetectiveOpList::iterator aItr = aDetectiveOpList.begin();
53 rDetOp = *aItr;
54 aDetectiveOpList.erase( aItr );
55 return true;
58 ScXMLDetectiveContext::ScXMLDetectiveContext(
59 ScXMLImport& rImport,
60 ScMyImpDetectiveObjVec* pNewDetectiveObjVec ) :
61 ScXMLImportContext( rImport ),
62 pDetectiveObjVec( pNewDetectiveObjVec )
66 ScXMLDetectiveContext::~ScXMLDetectiveContext()
70 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDetectiveContext::createFastChildContext(
71 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
73 SvXMLImportContext* pContext = nullptr;
74 sax_fastparser::FastAttributeList *pAttribList =
75 &sax_fastparser::castToFastAttributeList( xAttrList );
77 switch (nElement)
79 case XML_ELEMENT( TABLE, XML_HIGHLIGHTED_RANGE ):
80 pContext = new ScXMLDetectiveHighlightedContext( GetScImport(), pAttribList, pDetectiveObjVec );
81 break;
82 case XML_ELEMENT( TABLE, XML_OPERATION ):
83 pContext = new ScXMLDetectiveOperationContext( GetScImport(), pAttribList );
84 break;
87 return pContext;
90 ScXMLDetectiveHighlightedContext::ScXMLDetectiveHighlightedContext(
91 ScXMLImport& rImport,
92 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
93 ScMyImpDetectiveObjVec* pNewDetectiveObjVec ):
94 ScXMLImportContext( rImport ),
95 pDetectiveObjVec( pNewDetectiveObjVec ),
96 bValid( false )
98 if ( !rAttrList.is() )
99 return;
101 for (auto &aIter : *rAttrList)
103 switch (aIter.getToken())
105 case XML_ELEMENT( TABLE, XML_CELL_RANGE_ADDRESS ):
107 sal_Int32 nOffset(0);
108 ScXMLImport::MutexGuard aGuard(GetScImport());
109 ScDocument* pDoc = GetScImport().GetDocument();
110 assert(pDoc);
111 bValid = ScRangeStringConverter::GetRangeFromString( aDetectiveObj.aSourceRange, aIter.toString(), *pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset );
113 break;
114 case XML_ELEMENT( TABLE, XML_DIRECTION ):
115 aDetectiveObj.eObjType = ScXMLConverter::GetDetObjTypeFromString( aIter.toString() );
116 break;
117 case XML_ELEMENT( TABLE, XML_CONTAINS_ERROR ):
118 aDetectiveObj.bHasError = IsXMLToken(aIter, XML_TRUE);
119 break;
120 case XML_ELEMENT( TABLE, XML_MARKED_INVALID ):
122 if (IsXMLToken(aIter, XML_TRUE))
123 aDetectiveObj.eObjType = SC_DETOBJ_CIRCLE;
125 break;
130 ScXMLDetectiveHighlightedContext::~ScXMLDetectiveHighlightedContext()
134 void SAL_CALL ScXMLDetectiveHighlightedContext::endFastElement( sal_Int32 /*nElement*/ )
136 switch( aDetectiveObj.eObjType )
138 case SC_DETOBJ_ARROW:
139 case SC_DETOBJ_TOOTHERTAB:
140 break;
141 case SC_DETOBJ_FROMOTHERTAB:
142 case SC_DETOBJ_CIRCLE:
143 bValid = true;
144 break;
145 default:
146 bValid = false;
148 if( bValid )
149 pDetectiveObjVec->push_back( aDetectiveObj );
152 ScXMLDetectiveOperationContext::ScXMLDetectiveOperationContext(
153 ScXMLImport& rImport,
154 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
155 ScXMLImportContext( rImport ),
156 bHasType( false )
158 if ( rAttrList.is() )
160 for (auto &aIter : *rAttrList)
162 switch (aIter.getToken())
164 case XML_ELEMENT( TABLE, XML_NAME ):
165 bHasType = ScXMLConverter::GetDetOpTypeFromString( aDetectiveOp.eOpType, aIter.toString() );
166 break;
167 case XML_ELEMENT( TABLE, XML_INDEX ):
169 sal_Int32 nValue;
170 if (::sax::Converter::convertNumber( nValue, aIter.toView(), 0 ))
171 aDetectiveOp.nIndex = nValue;
173 break;
177 aDetectiveOp.aPosition = rImport.GetTables().GetCurrentCellPos();
180 ScXMLDetectiveOperationContext::~ScXMLDetectiveOperationContext()
184 void SAL_CALL ScXMLDetectiveOperationContext::endFastElement( sal_Int32 /*nElement*/ )
186 if( bHasType && (aDetectiveOp.nIndex >= 0) )
187 GetScImport().GetDetectiveOpArray()->AddDetectiveOp( aDetectiveOp );
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */