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/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
),
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() )
52 ScMyImpDetectiveOpList::iterator aItr
= aDetectiveOpList
.begin();
54 aDetectiveOpList
.erase( aItr
);
58 ScXMLDetectiveContext::ScXMLDetectiveContext(
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
);
79 case XML_ELEMENT( TABLE
, XML_HIGHLIGHTED_RANGE
):
80 pContext
= new ScXMLDetectiveHighlightedContext( GetScImport(), pAttribList
, pDetectiveObjVec
);
82 case XML_ELEMENT( TABLE
, XML_OPERATION
):
83 pContext
= new ScXMLDetectiveOperationContext( GetScImport(), pAttribList
);
90 ScXMLDetectiveHighlightedContext::ScXMLDetectiveHighlightedContext(
92 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
93 ScMyImpDetectiveObjVec
* pNewDetectiveObjVec
):
94 ScXMLImportContext( rImport
),
95 pDetectiveObjVec( pNewDetectiveObjVec
),
98 if ( !rAttrList
.is() )
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();
111 bValid
= ScRangeStringConverter::GetRangeFromString( aDetectiveObj
.aSourceRange
, aIter
.toString(), *pDoc
, ::formula::FormulaGrammar::CONV_OOO
, nOffset
);
114 case XML_ELEMENT( TABLE
, XML_DIRECTION
):
115 aDetectiveObj
.eObjType
= ScXMLConverter::GetDetObjTypeFromString( aIter
.toString() );
117 case XML_ELEMENT( TABLE
, XML_CONTAINS_ERROR
):
118 aDetectiveObj
.bHasError
= IsXMLToken(aIter
, XML_TRUE
);
120 case XML_ELEMENT( TABLE
, XML_MARKED_INVALID
):
122 if (IsXMLToken(aIter
, XML_TRUE
))
123 aDetectiveObj
.eObjType
= SC_DETOBJ_CIRCLE
;
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
:
141 case SC_DETOBJ_FROMOTHERTAB
:
142 case SC_DETOBJ_CIRCLE
:
149 pDetectiveObjVec
->push_back( aDetectiveObj
);
152 ScXMLDetectiveOperationContext::ScXMLDetectiveOperationContext(
153 ScXMLImport
& rImport
,
154 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
) :
155 ScXMLImportContext( rImport
),
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() );
167 case XML_ELEMENT( TABLE
, XML_INDEX
):
170 if (::sax::Converter::convertNumber( nValue
, aIter
.toView(), 0 ))
171 aDetectiveOp
.nIndex
= nValue
;
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: */