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 <unotools/transliterationwrapper.hxx>
21 :
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"
29 :
30 342 : ScAutoNameCache::ScAutoNameCache( ScDocument* pD ) :
31 : pDoc( pD ),
32 342 : nCurrentTab( 0 ) // doesn't matter - aNames is empty
33 : {
34 342 : }
35 :
36 342 : ScAutoNameCache::~ScAutoNameCache()
37 : {
38 342 : }
39 :
40 4 : const ScAutoNameAddresses& ScAutoNameCache::GetNameOccurrences( const OUString& rName, SCTAB nTab )
41 : {
42 4 : if ( nTab != nCurrentTab )
43 : {
44 : // the lists are valid only for one sheet, so they are cleared when another sheet is used
45 2 : aNames.clear();
46 2 : nCurrentTab = nTab;
47 : }
48 :
49 4 : ScAutoNameHashMap::const_iterator aFound = aNames.find( rName );
50 4 : if ( aFound != aNames.end() )
51 0 : return aFound->second; // already initialized
52 :
53 4 : ScAutoNameAddresses& rAddresses = aNames[rName];
54 :
55 4 : ScCellIterator aIter( pDoc, ScRange( 0, 0, nCurrentTab, MAXCOL, MAXROW, nCurrentTab ) );
56 304 : for (bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next())
57 : {
58 : // don't check code length here, always use the stored result
59 : // (AutoCalc is disabled during CompileXML)
60 300 : if (aIter.hasString())
61 : {
62 40 : OUString aStr;
63 40 : switch (aIter.getType())
64 : {
65 : case CELLTYPE_STRING:
66 8 : aStr = aIter.getString();
67 8 : break;
68 : case CELLTYPE_FORMULA:
69 32 : aStr = aIter.getFormulaCell()->GetString().getString();
70 32 : break;
71 : case CELLTYPE_EDIT:
72 : {
73 0 : const EditTextObject* p = aIter.getEditText();
74 0 : if (p)
75 0 : aStr = ScEditUtil::GetMultilineString(*p); // string with line separators between paragraphs
76 : }
77 0 : break;
78 : case CELLTYPE_NONE:
79 : case CELLTYPE_VALUE:
80 : ; // nothing, prevent compiler warning
81 0 : break;
82 : }
83 40 : if ( ScGlobal::GetpTransliteration()->isEqual( aStr, rName ) )
84 : {
85 0 : rAddresses.push_back(aIter.GetPos());
86 40 : }
87 : }
88 : }
89 :
90 4 : return rAddresses;
91 156 : }
92 :
93 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|