1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28
29 // INCLUDE ---------------------------------------------------------------
30
31 #include <unotools/transliterationwrapper.hxx>
32
33 #include "autonamecache.hxx"
34 #include "dociter.hxx"
35 #include "cell.hxx"
36 #include "queryparam.hxx"
37
38 // -----------------------------------------------------------------------
39
ScAutoNameCache(ScDocument * pD)40 ScAutoNameCache::ScAutoNameCache( ScDocument* pD ) :
41 pDoc( pD ),
42 nCurrentTab( 0 ) // doesn't matter - aNames is empty
43 {
44 }
45
~ScAutoNameCache()46 ScAutoNameCache::~ScAutoNameCache()
47 {
48 }
49
GetNameOccurences(const String & rName,SCTAB nTab)50 const ScAutoNameAddresses& ScAutoNameCache::GetNameOccurences( const String& rName, SCTAB nTab )
51 {
52 if ( nTab != nCurrentTab )
53 {
54 // the lists are valid only for one sheet, so they are cleared when another sheet is used
55 aNames.clear();
56 nCurrentTab = nTab;
57 }
58
59 ScAutoNameHashMap::const_iterator aFound = aNames.find( rName );
60 if ( aFound != aNames.end() )
61 return aFound->second; // already initialized
62
63 ScAutoNameAddresses& rAddresses = aNames[rName];
64
65 ScCellIterator aIter( pDoc, ScRange( 0, 0, nCurrentTab, MAXCOL, MAXROW, nCurrentTab ) );
66 for ( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() )
67 {
68 // don't check code length here, always use the stored result
69 // (AutoCalc is disabled during CompileXML)
70
71 if ( pCell->HasStringData() )
72 {
73 String aStr;
74 CellType eType = pCell->GetCellType();
75 switch ( eType )
76 {
77 case CELLTYPE_STRING:
78 ((ScStringCell*)pCell)->GetString( aStr );
79 break;
80 case CELLTYPE_FORMULA:
81 ((ScFormulaCell*)pCell)->GetString( aStr );
82 break;
83 case CELLTYPE_EDIT:
84 ((ScEditCell*)pCell)->GetString( aStr );
85 break;
86 case CELLTYPE_NONE:
87 case CELLTYPE_VALUE:
88 case CELLTYPE_NOTE:
89 case CELLTYPE_SYMBOLS:
90 #ifdef DBG_UTIL
91 case CELLTYPE_DESTROYED:
92 #endif
93 ; // nothing, prevent compiler warning
94 break;
95 }
96 if ( ScGlobal::GetpTransliteration()->isEqual( aStr, rName ) )
97 {
98 rAddresses.push_back( ScAddress( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() ) );
99 }
100 }
101 }
102
103 return rAddresses;
104 }
105
106