1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28
29 //___________________________________________________________________
30 #include "XMLDetectiveContext.hxx"
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <xmloff/xmluconv.hxx>
34 #include "convuno.hxx"
35 #include "xmlimprt.hxx"
36 #include "XMLConverter.hxx"
37 #include "rangeutl.hxx"
38
39 #include <algorithm>
40
41 using ::rtl::OUString;
42 using namespace ::com::sun::star;
43 using namespace xmloff::token;
44
45
46 //___________________________________________________________________
47
ScMyImpDetectiveObj()48 ScMyImpDetectiveObj::ScMyImpDetectiveObj() :
49 aSourceRange(),
50 eObjType( SC_DETOBJ_NONE ),
51 bHasError( sal_False )
52 {
53 }
54
55 //___________________________________________________________________
56
operator <(const ScMyImpDetectiveOp & rDetOp) const57 sal_Bool ScMyImpDetectiveOp::operator<(const ScMyImpDetectiveOp& rDetOp) const
58 {
59 return (nIndex < rDetOp.nIndex);
60 }
61
Sort()62 void ScMyImpDetectiveOpArray::Sort()
63 {
64 aDetectiveOpList.sort();
65 }
66
GetFirstOp(ScMyImpDetectiveOp & rDetOp)67 sal_Bool ScMyImpDetectiveOpArray::GetFirstOp( ScMyImpDetectiveOp& rDetOp )
68 {
69 if( aDetectiveOpList.empty() )
70 return sal_False;
71 ScMyImpDetectiveOpList::iterator aItr = aDetectiveOpList.begin();
72 rDetOp = *aItr;
73 aDetectiveOpList.erase( aItr );
74 return sal_True;
75 }
76
77
78 //___________________________________________________________________
79
ScXMLDetectiveContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,ScMyImpDetectiveObjVec * pNewDetectiveObjVec)80 ScXMLDetectiveContext::ScXMLDetectiveContext(
81 ScXMLImport& rImport,
82 sal_uInt16 nPrfx,
83 const OUString& rLName,
84 ScMyImpDetectiveObjVec* pNewDetectiveObjVec ) :
85 SvXMLImportContext( rImport, nPrfx, rLName ),
86 pDetectiveObjVec( pNewDetectiveObjVec )
87 {
88 }
89
~ScXMLDetectiveContext()90 ScXMLDetectiveContext::~ScXMLDetectiveContext()
91 {
92 }
93
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)94 SvXMLImportContext *ScXMLDetectiveContext::CreateChildContext(
95 sal_uInt16 nPrefix,
96 const OUString& rLName,
97 const uno::Reference< xml::sax::XAttributeList>& xAttrList )
98 {
99 SvXMLImportContext* pContext = NULL;
100 const SvXMLTokenMap& rTokenMap = GetScImport().GetDetectiveElemTokenMap();
101
102 switch( rTokenMap.Get( nPrefix, rLName ) )
103 {
104 case XML_TOK_DETECTIVE_ELEM_HIGHLIGHTED:
105 pContext = new ScXMLDetectiveHighlightedContext( GetScImport(), nPrefix, rLName, xAttrList, pDetectiveObjVec );
106 break;
107 case XML_TOK_DETECTIVE_ELEM_OPERATION:
108 pContext = new ScXMLDetectiveOperationContext( GetScImport(), nPrefix, rLName, xAttrList );
109 break;
110 }
111 if( !pContext )
112 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
113
114 return pContext;
115 }
116
EndElement()117 void ScXMLDetectiveContext::EndElement()
118 {
119 }
120
121
122 //___________________________________________________________________
123
ScXMLDetectiveHighlightedContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScMyImpDetectiveObjVec * pNewDetectiveObjVec)124 ScXMLDetectiveHighlightedContext::ScXMLDetectiveHighlightedContext(
125 ScXMLImport& rImport,
126 sal_uInt16 nPrfx,
127 const OUString& rLName,
128 const uno::Reference< xml::sax::XAttributeList >& xAttrList,
129 ScMyImpDetectiveObjVec* pNewDetectiveObjVec ):
130 SvXMLImportContext( rImport, nPrfx, rLName ),
131 pDetectiveObjVec( pNewDetectiveObjVec ),
132 aDetectiveObj(),
133 bValid( sal_False )
134 {
135 if( !xAttrList.is() ) return;
136
137 sal_Int16 nAttrCount = xAttrList->getLength();
138 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDetectiveHighlightedAttrTokenMap();
139
140 for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
141 {
142 const rtl::OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
143 const rtl::OUString& sValue (xAttrList->getValueByIndex( nIndex ));
144 OUString aLocalName;
145 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
146
147 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
148 {
149 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CELL_RANGE:
150 {
151 sal_Int32 nOffset(0);
152 GetScImport().LockSolarMutex();
153 bValid = ScRangeStringConverter::GetRangeFromString( aDetectiveObj.aSourceRange, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
154 GetScImport().UnlockSolarMutex();
155 }
156 break;
157 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_DIRECTION:
158 aDetectiveObj.eObjType = ScXMLConverter::GetDetObjTypeFromString( sValue );
159 break;
160 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CONTAINS_ERROR:
161 aDetectiveObj.bHasError = IsXMLToken(sValue, XML_TRUE);
162 break;
163 case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_MARKED_INVALID:
164 {
165 if (IsXMLToken(sValue, XML_TRUE))
166 aDetectiveObj.eObjType = SC_DETOBJ_CIRCLE;
167 }
168 break;
169 }
170 }
171 }
172
~ScXMLDetectiveHighlightedContext()173 ScXMLDetectiveHighlightedContext::~ScXMLDetectiveHighlightedContext()
174 {
175 }
176
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)177 SvXMLImportContext *ScXMLDetectiveHighlightedContext::CreateChildContext(
178 sal_uInt16 nPrefix,
179 const OUString& rLName,
180 const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
181 {
182 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
183 }
184
EndElement()185 void ScXMLDetectiveHighlightedContext::EndElement()
186 {
187 switch( aDetectiveObj.eObjType )
188 {
189 case SC_DETOBJ_ARROW:
190 case SC_DETOBJ_TOOTHERTAB:
191 break;
192 case SC_DETOBJ_FROMOTHERTAB:
193 case SC_DETOBJ_CIRCLE:
194 bValid = sal_True;
195 break;
196 default:
197 bValid = sal_False;
198 }
199 if( bValid )
200 pDetectiveObjVec->push_back( aDetectiveObj );
201 }
202
203
204 //___________________________________________________________________
205
ScXMLDetectiveOperationContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)206 ScXMLDetectiveOperationContext::ScXMLDetectiveOperationContext(
207 ScXMLImport& rImport,
208 sal_uInt16 nPrfx,
209 const OUString& rLName,
210 const uno::Reference< xml::sax::XAttributeList >& xAttrList ) :
211 SvXMLImportContext( rImport, nPrfx, rLName ),
212 aDetectiveOp(),
213 bHasType( sal_False )
214 {
215 if( !xAttrList.is() ) return;
216
217 sal_Int16 nAttrCount = xAttrList->getLength();
218 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDetectiveOperationAttrTokenMap();
219
220 for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
221 {
222 const rtl::OUString& sAttrName (xAttrList->getNameByIndex( nIndex ));
223 const rtl::OUString& sValue (xAttrList->getValueByIndex( nIndex ));
224 OUString aLocalName;
225 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
226
227 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
228 {
229 case XML_TOK_DETECTIVE_OPERATION_ATTR_NAME:
230 bHasType = ScXMLConverter::GetDetOpTypeFromString( aDetectiveOp.eOpType, sValue );
231 break;
232 case XML_TOK_DETECTIVE_OPERATION_ATTR_INDEX:
233 {
234 sal_Int32 nValue;
235 if( SvXMLUnitConverter::convertNumber( nValue, sValue, 0 ) )
236 aDetectiveOp.nIndex = nValue;
237 }
238 break;
239 }
240 }
241 ScUnoConversion::FillScAddress( aDetectiveOp.aPosition, rImport.GetTables().GetRealCellPos() );
242 }
243
~ScXMLDetectiveOperationContext()244 ScXMLDetectiveOperationContext::~ScXMLDetectiveOperationContext()
245 {
246 }
247
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)248 SvXMLImportContext *ScXMLDetectiveOperationContext::CreateChildContext(
249 sal_uInt16 nPrefix,
250 const OUString& rLName,
251 const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
252 {
253 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
254 }
255
EndElement()256 void ScXMLDetectiveOperationContext::EndElement()
257 {
258 if( bHasType && (aDetectiveOp.nIndex >= 0) )
259 GetScImport().GetDetectiveOpArray()->AddDetectiveOp( aDetectiveOp );
260 }
261
262