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