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/nmspmap.hxx>
24 #include <xmloff/xmltoken.hxx>
25 #include "convuno.hxx"
26 #include "xmlimprt.hxx"
27 #include "XMLConverter.hxx"
28 #include "rangeutl.hxx"
32 using namespace ::com::sun::star
;
33 using namespace xmloff::token
;
35 ScMyImpDetectiveObj::ScMyImpDetectiveObj() :
37 eObjType( SC_DETOBJ_NONE
),
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() )
56 ScMyImpDetectiveOpList::iterator aItr
= aDetectiveOpList
.begin();
58 aDetectiveOpList
.erase( aItr
);
62 ScXMLDetectiveContext::ScXMLDetectiveContext(
65 const OUString
& rLName
,
66 ScMyImpDetectiveObjVec
* pNewDetectiveObjVec
) :
67 SvXMLImportContext( rImport
, nPrfx
, rLName
),
68 pDetectiveObjVec( pNewDetectiveObjVec
)
72 ScXMLDetectiveContext::~ScXMLDetectiveContext()
76 SvXMLImportContext
*ScXMLDetectiveContext::CreateChildContext(
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
);
89 case XML_TOK_DETECTIVE_ELEM_OPERATION
:
90 pContext
= new ScXMLDetectiveOperationContext( GetScImport(), nPrefix
, rLName
, xAttrList
);
94 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
99 void ScXMLDetectiveContext::EndElement()
103 ScXMLDetectiveHighlightedContext::ScXMLDetectiveHighlightedContext(
104 ScXMLImport
& rImport
,
106 const OUString
& rLName
,
107 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
108 ScMyImpDetectiveObjVec
* pNewDetectiveObjVec
):
109 SvXMLImportContext( rImport
, nPrfx
, rLName
),
110 pDetectiveObjVec( pNewDetectiveObjVec
),
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
));
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
);
135 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_DIRECTION
:
136 aDetectiveObj
.eObjType
= ScXMLConverter::GetDetObjTypeFromString( sValue
);
138 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CONTAINS_ERROR
:
139 aDetectiveObj
.bHasError
= IsXMLToken(sValue
, XML_TRUE
);
141 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_MARKED_INVALID
:
143 if (IsXMLToken(sValue
, XML_TRUE
))
144 aDetectiveObj
.eObjType
= SC_DETOBJ_CIRCLE
;
151 ScXMLDetectiveHighlightedContext::~ScXMLDetectiveHighlightedContext()
155 SvXMLImportContext
*ScXMLDetectiveHighlightedContext::CreateChildContext(
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
:
170 case SC_DETOBJ_FROMOTHERTAB
:
171 case SC_DETOBJ_CIRCLE
:
178 pDetectiveObjVec
->push_back( aDetectiveObj
);
181 ScXMLDetectiveOperationContext::ScXMLDetectiveOperationContext(
182 ScXMLImport
& rImport
,
184 const OUString
& rLName
,
185 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
) :
186 SvXMLImportContext( rImport
, nPrfx
, rLName
),
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
));
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
);
207 case XML_TOK_DETECTIVE_OPERATION_ATTR_INDEX
:
210 if (::sax::Converter::convertNumber( nValue
, sValue
, 0 ))
211 aDetectiveOp
.nIndex
= nValue
;
216 aDetectiveOp
.aPosition
= rImport
.GetTables().GetCurrentCellPos();
219 ScXMLDetectiveOperationContext::~ScXMLDetectiveOperationContext()
223 SvXMLImportContext
*ScXMLDetectiveOperationContext::CreateChildContext(
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: */