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 "cell.hxx"
25 : #include "queryparam.hxx"
26 :
27 : // -----------------------------------------------------------------------
28 :
29 33 : ScAutoNameCache::ScAutoNameCache( ScDocument* pD ) :
30 : pDoc( pD ),
31 33 : nCurrentTab( 0 ) // doesn't matter - aNames is empty
32 : {
33 33 : }
34 :
35 33 : ScAutoNameCache::~ScAutoNameCache()
36 : {
37 33 : }
38 :
39 4 : const ScAutoNameAddresses& ScAutoNameCache::GetNameOccurrences( const String& rName, SCTAB nTab )
40 : {
41 4 : if ( nTab != nCurrentTab )
42 : {
43 : // the lists are valid only for one sheet, so they are cleared when another sheet is used
44 2 : aNames.clear();
45 2 : nCurrentTab = nTab;
46 : }
47 :
48 4 : ScAutoNameHashMap::const_iterator aFound = aNames.find( rName );
49 4 : if ( aFound != aNames.end() )
50 0 : return aFound->second; // already initialized
51 :
52 4 : ScAutoNameAddresses& rAddresses = aNames[rName];
53 :
54 4 : ScCellIterator aIter( pDoc, ScRange( 0, 0, nCurrentTab, MAXCOL, MAXROW, nCurrentTab ) );
55 288 : for ( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() )
56 : {
57 : // don't check code length here, always use the stored result
58 : // (AutoCalc is disabled during CompileXML)
59 :
60 284 : if ( pCell->HasStringData() )
61 : {
62 32 : String aStr;
63 32 : CellType eType = pCell->GetCellType();
64 32 : switch ( eType )
65 : {
66 : case CELLTYPE_STRING:
67 0 : aStr = ((ScStringCell*)pCell)->GetString();
68 0 : break;
69 : case CELLTYPE_FORMULA:
70 32 : aStr = ((ScFormulaCell*)pCell)->GetString();
71 32 : break;
72 : case CELLTYPE_EDIT:
73 0 : aStr = ((ScEditCell*)pCell)->GetString();
74 0 : break;
75 : case CELLTYPE_NONE:
76 : case CELLTYPE_VALUE:
77 : case CELLTYPE_NOTE:
78 : case CELLTYPE_SYMBOLS:
79 : #if OSL_DEBUG_LEVEL > 0
80 : case CELLTYPE_DESTROYED:
81 : #endif
82 : ; // nothing, prevent compiler warning
83 0 : break;
84 : }
85 32 : if ( ScGlobal::GetpTransliteration()->isEqual( aStr, rName ) )
86 : {
87 0 : rAddresses.push_back( ScAddress( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() ) );
88 32 : }
89 : }
90 : }
91 :
92 4 : return rAddresses;
93 : }
94 :
95 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|