1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/xmlnmspe.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() :
34 eObjType( SC_DETOBJ_NONE
),
39 bool ScMyImpDetectiveOp::operator<(const ScMyImpDetectiveOp
& rDetOp
) const
41 return (nIndex
< rDetOp
.nIndex
);
44 void ScMyImpDetectiveOpArray::Sort()
46 aDetectiveOpList
.sort();
49 bool ScMyImpDetectiveOpArray::GetFirstOp( ScMyImpDetectiveOp
& rDetOp
)
51 if( aDetectiveOpList
.empty() )
53 ScMyImpDetectiveOpList::iterator aItr
= aDetectiveOpList
.begin();
55 aDetectiveOpList
.erase( aItr
);
59 ScXMLDetectiveContext::ScXMLDetectiveContext(
61 ScMyImpDetectiveObjVec
* pNewDetectiveObjVec
) :
62 ScXMLImportContext( rImport
),
63 pDetectiveObjVec( pNewDetectiveObjVec
)
67 ScXMLDetectiveContext::~ScXMLDetectiveContext()
71 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDetectiveContext::createFastChildContext(
72 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
74 SvXMLImportContext
* pContext
= nullptr;
75 sax_fastparser::FastAttributeList
*pAttribList
=
76 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
80 case XML_ELEMENT( TABLE
, XML_HIGHLIGHTED_RANGE
):
81 pContext
= new ScXMLDetectiveHighlightedContext( GetScImport(), pAttribList
, pDetectiveObjVec
);
83 case XML_ELEMENT( TABLE
, XML_OPERATION
):
84 pContext
= new ScXMLDetectiveOperationContext( GetScImport(), pAttribList
);
88 pContext
= new SvXMLImportContext( GetImport() );
93 ScXMLDetectiveHighlightedContext::ScXMLDetectiveHighlightedContext(
95 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
96 ScMyImpDetectiveObjVec
* pNewDetectiveObjVec
):
97 ScXMLImportContext( rImport
),
98 pDetectiveObjVec( pNewDetectiveObjVec
),
102 if ( rAttrList
.is() )
104 for (auto &aIter
: *rAttrList
)
106 switch (aIter
.getToken())
108 case XML_ELEMENT( TABLE
, XML_CELL_RANGE_ADDRESS
):
110 sal_Int32
nOffset(0);
111 ScXMLImport::MutexGuard
aGuard(GetScImport());
112 bValid
= ScRangeStringConverter::GetRangeFromString( aDetectiveObj
.aSourceRange
, aIter
.toString(), GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO
, nOffset
);
115 case XML_ELEMENT( TABLE
, XML_DIRECTION
):
116 aDetectiveObj
.eObjType
= ScXMLConverter::GetDetObjTypeFromString( aIter
.toString() );
118 case XML_ELEMENT( TABLE
, XML_CONTAINS_ERROR
):
119 aDetectiveObj
.bHasError
= IsXMLToken(aIter
, XML_TRUE
);
121 case XML_ELEMENT( TABLE
, XML_MARKED_INVALID
):
123 if (IsXMLToken(aIter
, XML_TRUE
))
124 aDetectiveObj
.eObjType
= SC_DETOBJ_CIRCLE
;
132 ScXMLDetectiveHighlightedContext::~ScXMLDetectiveHighlightedContext()
136 void SAL_CALL
ScXMLDetectiveHighlightedContext::endFastElement( sal_Int32
/*nElement*/ )
138 switch( aDetectiveObj
.eObjType
)
140 case SC_DETOBJ_ARROW
:
141 case SC_DETOBJ_TOOTHERTAB
:
143 case SC_DETOBJ_FROMOTHERTAB
:
144 case SC_DETOBJ_CIRCLE
:
151 pDetectiveObjVec
->push_back( aDetectiveObj
);
154 ScXMLDetectiveOperationContext::ScXMLDetectiveOperationContext(
155 ScXMLImport
& rImport
,
156 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
) :
157 ScXMLImportContext( rImport
),
161 if ( rAttrList
.is() )
163 for (auto &aIter
: *rAttrList
)
165 switch (aIter
.getToken())
167 case XML_ELEMENT( TABLE
, XML_NAME
):
168 bHasType
= ScXMLConverter::GetDetOpTypeFromString( aDetectiveOp
.eOpType
, aIter
.toString() );
170 case XML_ELEMENT( TABLE
, XML_INDEX
):
173 if (::sax::Converter::convertNumber( nValue
, aIter
.toString(), 0 ))
174 aDetectiveOp
.nIndex
= nValue
;
180 aDetectiveOp
.aPosition
= rImport
.GetTables().GetCurrentCellPos();
183 ScXMLDetectiveOperationContext::~ScXMLDetectiveOperationContext()
187 void SAL_CALL
ScXMLDetectiveOperationContext::endFastElement( sal_Int32
/*nElement*/ )
189 if( bHasType
&& (aDetectiveOp
.nIndex
>= 0) )
190 GetScImport().GetDetectiveOpArray()->AddDetectiveOp( aDetectiveOp
);
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */