update dev300-m57
[ooovba.git] / sc / source / core / data / autonamecache.cxx
blobc51efb6c5591dd59e2e086db2a60e8897aef9863
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"
44 // -----------------------------------------------------------------------
46 ScAutoNameCache::ScAutoNameCache( ScDocument* pD ) :
47 pDoc( pD ),
48 nCurrentTab( 0 ) // doesn't matter - aNames is empty
52 ScAutoNameCache::~ScAutoNameCache()
56 const ScAutoNameAddresses& ScAutoNameCache::GetNameOccurences( const String& rName, SCTAB nTab )
58 if ( nTab != nCurrentTab )
60 // the lists are valid only for one sheet, so they are cleared when another sheet is used
61 aNames.clear();
62 nCurrentTab = nTab;
65 ScAutoNameHashMap::const_iterator aFound = aNames.find( rName );
66 if ( aFound != aNames.end() )
67 return aFound->second; // already initialized
69 ScAutoNameAddresses& rAddresses = aNames[rName];
71 ScCellIterator aIter( pDoc, ScRange( 0, 0, nCurrentTab, MAXCOL, MAXROW, nCurrentTab ) );
72 for ( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() )
74 // don't check code length here, always use the stored result
75 // (AutoCalc is disabled during CompileXML)
77 if ( pCell->HasStringData() )
79 String aStr;
80 CellType eType = pCell->GetCellType();
81 switch ( eType )
83 case CELLTYPE_STRING:
84 ((ScStringCell*)pCell)->GetString( aStr );
85 break;
86 case CELLTYPE_FORMULA:
87 ((ScFormulaCell*)pCell)->GetString( aStr );
88 break;
89 case CELLTYPE_EDIT:
90 ((ScEditCell*)pCell)->GetString( aStr );
91 break;
92 case CELLTYPE_NONE:
93 case CELLTYPE_VALUE:
94 case CELLTYPE_NOTE:
95 case CELLTYPE_SYMBOLS:
96 #ifdef DBG_UTIL
97 case CELLTYPE_DESTROYED:
98 #endif
99 ; // nothing, prevent compiler warning
100 break;
102 if ( ScGlobal::pTransliteration->isEqual( aStr, rName ) )
104 rAddresses.push_back( ScAddress( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() ) );
109 return rAddresses;