Update ooo320-m1
[ooovba.git] / sc / source / core / data / autonamecache.cxx
blob329e7f46997b0eb374970da65a254df9ad575a7d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: autonamecache.cxx,v $
10 * $Revision: 1.4.128.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include <unotools/transliterationwrapper.hxx>
40 #include "autonamecache.hxx"
41 #include "dociter.hxx"
42 #include "cell.hxx"
43 #include "queryparam.hxx"
45 // -----------------------------------------------------------------------
47 ScAutoNameCache::ScAutoNameCache( ScDocument* pD ) :
48 pDoc( pD ),
49 nCurrentTab( 0 ) // doesn't matter - aNames is empty
53 ScAutoNameCache::~ScAutoNameCache()
57 const ScAutoNameAddresses& ScAutoNameCache::GetNameOccurences( const String& rName, SCTAB nTab )
59 if ( nTab != nCurrentTab )
61 // the lists are valid only for one sheet, so they are cleared when another sheet is used
62 aNames.clear();
63 nCurrentTab = nTab;
66 ScAutoNameHashMap::const_iterator aFound = aNames.find( rName );
67 if ( aFound != aNames.end() )
68 return aFound->second; // already initialized
70 ScAutoNameAddresses& rAddresses = aNames[rName];
72 ScCellIterator aIter( pDoc, ScRange( 0, 0, nCurrentTab, MAXCOL, MAXROW, nCurrentTab ) );
73 for ( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() )
75 // don't check code length here, always use the stored result
76 // (AutoCalc is disabled during CompileXML)
78 if ( pCell->HasStringData() )
80 String aStr;
81 CellType eType = pCell->GetCellType();
82 switch ( eType )
84 case CELLTYPE_STRING:
85 ((ScStringCell*)pCell)->GetString( aStr );
86 break;
87 case CELLTYPE_FORMULA:
88 ((ScFormulaCell*)pCell)->GetString( aStr );
89 break;
90 case CELLTYPE_EDIT:
91 ((ScEditCell*)pCell)->GetString( aStr );
92 break;
93 case CELLTYPE_NONE:
94 case CELLTYPE_VALUE:
95 case CELLTYPE_NOTE:
96 case CELLTYPE_SYMBOLS:
97 #ifdef DBG_UTIL
98 case CELLTYPE_DESTROYED:
99 #endif
100 ; // nothing, prevent compiler warning
101 break;
103 if ( ScGlobal::GetpTransliteration()->isEqual( aStr, rName ) )
105 rAddresses.push_back( ScAddress( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() ) );
110 return rAddresses;