Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "formulaiter.hxx"
21 :
22 : #include "formulacell.hxx"
23 : #include "tokenarray.hxx"
24 : #include <formula/token.hxx>
25 :
26 : using namespace formula;
27 :
28 4127 : ScDetectiveRefIter::ScDetectiveRefIter( ScFormulaCell* pCell )
29 : {
30 4127 : pCode = pCell->GetCode();
31 4127 : pCode->Reset();
32 4127 : aPos = pCell->aPos;
33 4127 : }
34 :
35 3209 : static bool lcl_ScDetectiveRefIter_SkipRef( formula::FormulaToken* p, const ScAddress& rPos )
36 : {
37 3209 : ScSingleRefData& rRef1 = *p->GetSingleRef();
38 3209 : ScAddress aAbs1 = rRef1.toAbs(rPos);
39 3209 : if (!ValidAddress(aAbs1))
40 288 : return true;
41 2921 : if ( p->GetType() == svDoubleRef || p->GetType() == svExternalDoubleRef )
42 : {
43 1255 : ScSingleRefData& rRef2 = p->GetDoubleRef()->Ref2;
44 1255 : ScAddress aAbs2 = rRef2.toAbs(rPos);
45 1255 : if (!ValidAddress(aAbs2))
46 0 : return true;
47 : }
48 2921 : return false;
49 : }
50 :
51 7036 : bool ScDetectiveRefIter::GetNextRef( ScRange& rRange )
52 : {
53 7036 : bool bRet = false;
54 7036 : formula::FormulaToken* p = GetNextRefToken();
55 7036 : if( p )
56 : {
57 2913 : SingleDoubleRefProvider aProv( *p );
58 2913 : rRange.aStart = aProv.Ref1.toAbs(aPos);
59 2913 : rRange.aEnd = aProv.Ref2.toAbs(aPos);
60 2913 : bRet = true;
61 : }
62 :
63 7036 : return bRet;
64 : }
65 :
66 7048 : formula::FormulaToken* ScDetectiveRefIter::GetNextRefToken()
67 : {
68 7048 : formula::FormulaToken* p = pCode->GetNextReferenceRPN();
69 14384 : while (p && lcl_ScDetectiveRefIter_SkipRef(p, aPos))
70 : {
71 288 : p = pCode->GetNextReferenceRPN();
72 : }
73 7048 : return p;
74 156 : }
75 :
76 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|