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 <formulacell.hxx>
25 #include <editutil.hxx>
27 ScAutoNameCache::ScAutoNameCache( ScDocument
& rD
) :
29 nCurrentTab( 0 ) // doesn't matter - aNames is empty
33 ScAutoNameCache::~ScAutoNameCache()
37 const ScAutoNameAddresses
& ScAutoNameCache::GetNameOccurrences( const OUString
& rName
, SCTAB nTab
)
39 if ( nTab
!= nCurrentTab
)
41 // the lists are valid only for one sheet, so they are cleared when another sheet is used
46 ScAutoNameHashMap::const_iterator aFound
= aNames
.find( rName
);
47 if ( aFound
!= aNames
.end() )
48 return aFound
->second
; // already initialized
50 ScAutoNameAddresses
& rAddresses
= aNames
[rName
];
52 ScCellIterator
aIter( rDoc
, ScRange( 0, 0, nCurrentTab
, rDoc
.MaxCol(), rDoc
.MaxRow(), nCurrentTab
) );
53 for (bool bHasCell
= aIter
.first(); bHasCell
; bHasCell
= aIter
.next())
55 // don't check code length here, always use the stored result
56 // (AutoCalc is disabled during CompileXML)
57 if (aIter
.hasString())
60 switch (aIter
.getType())
63 aStr
= aIter
.getString();
65 case CELLTYPE_FORMULA
:
66 aStr
= aIter
.getFormulaCell()->GetString().getString();
70 const EditTextObject
* p
= aIter
.getEditText();
72 aStr
= ScEditUtil::GetMultilineString(*p
); // string with line separators between paragraphs
77 ; // nothing, prevent compiler warning
80 if ( ScGlobal::GetTransliteration().isEqual( aStr
, rName
) )
82 rAddresses
.push_back(aIter
.GetPos());
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */