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 rDoc( rD ),
29 nCurrentTab( 0 ) // doesn't matter - aNames is empty
30{
31}
32
34{
35}
36
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;
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::GetTransliteration().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: */
std::vector< ScAddress > ScAutoNameAddresses
ScAutoNameHashMap aNames
const ScAutoNameAddresses & GetNameOccurrences(const OUString &rName, SCTAB nTab)
ScDocument & rDoc
ScAutoNameCache(ScDocument &pD)
Walk through all cells in an area.
Definition: dociter.hxx:206
CellType getType() const
Definition: dociter.hxx:233
const EditTextObject * getEditText() const
Definition: dociter.hxx:235
ScFormulaCell * getFormulaCell()
Definition: dociter.hxx:236
bool hasString() const
Definition: dociter.cxx:994
const ScAddress & GetPos() const
Definition: dociter.hxx:231
OUString getString() const
Definition: dociter.cxx:968
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:892
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
static OUString GetMultilineString(const EditEngine &rEngine)
Retrieves string with paragraphs delimited by new lines (' ').
Definition: editutil.cxx:109
const svl::SharedString & GetString()
static SC_DLLPUBLIC ::utl::TransliterationWrapper & GetTransliteration()
Definition: global.cxx:1026
const OUString & getString() const
@ CELLTYPE_EDIT
Definition: global.hxx:277
@ CELLTYPE_STRING
Definition: global.hxx:275
@ CELLTYPE_FORMULA
Definition: global.hxx:276
@ CELLTYPE_NONE
Definition: global.hxx:273
@ CELLTYPE_VALUE
Definition: global.hxx:274
void * p
aStr
sal_Int16 SCTAB
Definition: types.hxx:22