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 <unotools/transliterationwrapper.hxx>
22 #include "autonamecache.hxx"
23 #include "dociter.hxx"
24 #include "queryparam.hxx"
25 #include "formulacell.hxx"
26 #include "cellvalue.hxx"
27 #include "editutil.hxx"
28 #include "document.hxx"
30 ScAutoNameCache::ScAutoNameCache( ScDocument
* pD
) :
32 nCurrentTab( 0 ) // doesn't matter - aNames is empty
36 ScAutoNameCache::~ScAutoNameCache()
40 const ScAutoNameAddresses
& ScAutoNameCache::GetNameOccurrences( const OUString
& rName
, SCTAB nTab
)
42 if ( nTab
!= nCurrentTab
)
44 // the lists are valid only for one sheet, so they are cleared when another sheet is used
49 ScAutoNameHashMap::const_iterator aFound
= aNames
.find( rName
);
50 if ( aFound
!= aNames
.end() )
51 return aFound
->second
; // already initialized
53 ScAutoNameAddresses
& rAddresses
= aNames
[rName
];
55 ScCellIterator
aIter( pDoc
, ScRange( 0, 0, nCurrentTab
, MAXCOL
, MAXROW
, nCurrentTab
) );
56 for (bool bHasCell
= aIter
.first(); bHasCell
; bHasCell
= aIter
.next())
58 // don't check code length here, always use the stored result
59 // (AutoCalc is disabled during CompileXML)
60 if (aIter
.hasString())
63 switch (aIter
.getType())
66 aStr
= aIter
.getString();
68 case CELLTYPE_FORMULA
:
69 aStr
= aIter
.getFormulaCell()->GetString().getString();
73 const EditTextObject
* p
= aIter
.getEditText();
75 aStr
= ScEditUtil::GetMultilineString(*p
); // string with line separators between paragraphs
80 ; // nothing, prevent compiler warning
83 if ( ScGlobal::GetpTransliteration()->isEqual( aStr
, rName
) )
85 rAddresses
.push_back(aIter
.GetPos());
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */