LibreOffice Module sc (master)  1
autonamecache.cxx
Go to the documentation of this file.
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 
21 
22 #include <autonamecache.hxx>
23 #include <dociter.hxx>
24 #include <formulacell.hxx>
25 #include <editutil.hxx>
26 
28  pDoc( pD ),
29  nCurrentTab( 0 ) // doesn't matter - aNames is empty
30 {
31 }
32 
34 {
35 }
36 
37 const ScAutoNameAddresses& ScAutoNameCache::GetNameOccurrences( const OUString& rName, SCTAB nTab )
38 {
39  if ( nTab != nCurrentTab )
40  {
41  // the lists are valid only for one sheet, so they are cleared when another sheet is used
42  aNames.clear();
43  nCurrentTab = nTab;
44  }
45 
46  ScAutoNameHashMap::const_iterator aFound = aNames.find( rName );
47  if ( aFound != aNames.end() )
48  return aFound->second; // already initialized
49 
50  ScAutoNameAddresses& rAddresses = aNames[rName];
51 
53  for (bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
54  {
55  // don't check code length here, always use the stored result
56  // (AutoCalc is disabled during CompileXML)
57  if (aIter.hasString())
58  {
59  OUString aStr;
60  switch (aIter.getType())
61  {
62  case CELLTYPE_STRING:
63  aStr = aIter.getString();
64  break;
65  case CELLTYPE_FORMULA:
66  aStr = aIter.getFormulaCell()->GetString().getString();
67  break;
68  case CELLTYPE_EDIT:
69  {
70  const EditTextObject* p = aIter.getEditText();
71  if (p)
72  aStr = ScEditUtil::GetMultilineString(*p); // string with line separators between paragraphs
73  }
74  break;
75  case CELLTYPE_NONE:
76  case CELLTYPE_VALUE:
77  ; // nothing, prevent compiler warning
78  break;
79  }
80  if ( ScGlobal::GetpTransliteration()->isEqual( aStr, rName ) )
81  {
82  rAddresses.push_back(aIter.GetPos());
83  }
84  }
85  }
86 
87  return rAddresses;
88 }
89 
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SC_DLLPUBLIC::utl::TransliterationWrapper * GetpTransliteration()
Definition: global.cxx:982
ScDocument * pDoc
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:873
std::vector< ScAddress > ScAutoNameAddresses
const ScAutoNameAddresses & GetNameOccurrences(const OUString &rName, SCTAB nTab)
ScAutoNameHashMap aNames
Walk through all cells in an area.
Definition: dociter.hxx:208
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:872
void * p
static OUString GetMultilineString(const EditEngine &rEngine)
Retrieves string with paragraphs delimited by new lines (' ').
Definition: editutil.cxx:105
aStr
ScAutoNameCache(ScDocument *pD)
sal_Int16 SCTAB
Definition: types.hxx:23