Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "namebuff.hxx"
31 : :
32 : : #include <string.h>
33 : :
34 : : #include "rangenam.hxx"
35 : : #include "document.hxx"
36 : : #include "compiler.hxx"
37 : : #include "scextopt.hxx"
38 : :
39 : : #include "root.hxx"
40 : : #include "tokstack.hxx"
41 : : #include "xltools.hxx"
42 : : #include "xiroot.hxx"
43 : :
44 : :
45 : 0 : sal_uInt32 StringHashEntry::MakeHashCode( const String& r )
46 : : {
47 : 0 : register sal_uInt32 n = 0;
48 : 0 : const sal_Unicode* pAkt = r.GetBuffer();
49 : 0 : register sal_Unicode cAkt = *pAkt;
50 : :
51 [ # # ]: 0 : while( cAkt )
52 : : {
53 : 0 : n *= 70;
54 : 0 : n += ( sal_uInt32 ) cAkt;
55 : 0 : pAkt++;
56 : 0 : cAkt = *pAkt;
57 : : }
58 : :
59 : 0 : return n;
60 : : }
61 : :
62 : :
63 : :
64 : :
65 : 55 : NameBuffer::~NameBuffer()
66 : : {
67 : 55 : std::vector<StringHashEntry*>::iterator pIter;
68 [ + - ][ - + ]: 55 : for ( pIter = maHashes.begin(); pIter != maHashes.end(); ++pIter )
69 [ # # ][ # # ]: 0 : delete *pIter;
70 [ - + ]: 110 : }
71 : :
72 : :
73 : : //void NameBuffer::operator <<( const SpString &rNewString )
74 : 0 : void NameBuffer::operator <<( const String &rNewString )
75 : : {
76 : : OSL_ENSURE( maHashes.size() + nBase < 0xFFFF,
77 : : "*NameBuffer::GetLastIndex(): Ich hab' die Nase voll!" );
78 : :
79 [ # # ][ # # ]: 0 : maHashes.push_back( new StringHashEntry( rNewString ) );
80 : 0 : }
81 : :
82 : :
83 : : #if OSL_DEBUG_LEVEL > 0
84 : : sal_uInt16 nShrCnt;
85 : : #endif
86 : :
87 : :
88 : 0 : size_t ShrfmlaBuffer::ScAddressHashFunc::operator() (const ScAddress &addr) const
89 : : {
90 : : // Use something simple, it is just a hash.
91 : 0 : return static_cast< sal_uInt16 >( addr.Row() ) | (static_cast< sal_uInt8 >( addr.Col() ) << 16);
92 : : }
93 : :
94 : : const size_t nBase = 16384; // Range~ und Shared~ Dingens mit jeweils der Haelfte Ids
95 : 55 : ShrfmlaBuffer::ShrfmlaBuffer( RootData* pRD ) :
96 : : ExcRoot( pRD ),
97 [ + - ][ + - ]: 55 : mnCurrIdx (nBase)
98 : : {
99 : : #if OSL_DEBUG_LEVEL > 0
100 : : nShrCnt = 0;
101 : : #endif
102 : 55 : }
103 : :
104 : 55 : ShrfmlaBuffer::~ShrfmlaBuffer()
105 : : {
106 [ - + ]: 110 : }
107 : :
108 : 165 : void ShrfmlaBuffer::Clear()
109 : : {
110 : 165 : index_hash.clear();
111 : : // do not clear index_list, index calculation depends on complete list size...
112 : : // do not change mnCurrIdx
113 : 165 : }
114 : :
115 : 0 : void ShrfmlaBuffer::Store( const ScRange& rRange, const ScTokenArray& rToken )
116 : : {
117 [ # # ]: 0 : String aName( CreateName( rRange.aStart ) );
118 : :
119 : : OSL_ENSURE( mnCurrIdx <= 0xFFFF, "*ShrfmlaBuffer::Store(): Gleich wird mir schlecht...!" );
120 : :
121 [ # # ][ # # ]: 0 : ScRangeData* pData = new ScRangeData( pExcRoot->pIR->GetDocPtr(), aName, rToken, rRange.aStart, RT_SHARED );
[ # # ]
122 : 0 : const ScAddress& rMaxPos = pExcRoot->pIR->GetMaxPos();
123 [ # # ]: 0 : pData->SetMaxCol(rMaxPos.Col());
124 [ # # ]: 0 : pData->SetMaxRow(rMaxPos.Row());
125 : 0 : pData->SetIndex( static_cast< sal_uInt16 >( mnCurrIdx ) );
126 [ # # ][ # # ]: 0 : pExcRoot->pIR->GetNamedRanges().insert( pData );
127 [ # # ]: 0 : index_hash[rRange.aStart] = static_cast< sal_uInt16 >( mnCurrIdx );
128 [ # # ]: 0 : index_list.push_front (rRange);
129 [ # # ]: 0 : ++mnCurrIdx;
130 : 0 : }
131 : :
132 : :
133 : 0 : sal_uInt16 ShrfmlaBuffer::Find( const ScAddress & aAddr ) const
134 : : {
135 [ # # ]: 0 : ShrfmlaHash::const_iterator hash = index_hash.find (aAddr);
136 [ # # ][ # # ]: 0 : if (hash != index_hash.end())
137 [ # # ]: 0 : return hash->second;
138 : :
139 : : // It was not hashed on the top left corner ? do a brute force search
140 : 0 : unsigned int ind = nBase;
141 [ # # ]: 0 : for (ShrfmlaList::const_iterator ptr = index_list.end(); ptr != index_list.begin() ; ind++)
142 [ # # ]: 0 : if ((--ptr)->In (aAddr))
143 : 0 : return static_cast< sal_uInt16 >( ind );
144 : 0 : return static_cast< sal_uInt16 >( mnCurrIdx );
145 : : }
146 : :
147 : :
148 : : #define SHRFMLA_BASENAME "SHARED_FORMULA_"
149 : :
150 : 0 : String ShrfmlaBuffer::CreateName( const ScRange& r )
151 : : {
152 : 0 : String aName( RTL_CONSTASCII_USTRINGPARAM( SHRFMLA_BASENAME ) );
153 [ # # ][ # # ]: 0 : aName += String::CreateFromInt32( r.aStart.Col() );
[ # # ]
154 [ # # ]: 0 : aName.Append( '_' );
155 [ # # ][ # # ]: 0 : aName += String::CreateFromInt32( r.aStart.Row() );
[ # # ]
156 [ # # ]: 0 : aName.Append( '_' );
157 [ # # ][ # # ]: 0 : aName += String::CreateFromInt32( r.aEnd.Col() );
[ # # ]
158 [ # # ]: 0 : aName.Append( '_' );
159 [ # # ][ # # ]: 0 : aName += String::CreateFromInt32( r.aEnd.Row() );
[ # # ]
160 [ # # ]: 0 : aName.Append( '_' );
161 [ # # ][ # # ]: 0 : aName += String::CreateFromInt32( r.aStart.Tab() );
[ # # ]
162 : :
163 : 0 : return aName;
164 : : }
165 : :
166 : 0 : sal_Int16 ExtSheetBuffer::Add( const String& rFPAN, const String& rTN, const sal_Bool bSWB )
167 : : {
168 [ # # ]: 0 : maEntries.push_back( Cont( rFPAN, rTN, bSWB ) );
169 : : // return 1-based index of EXTERNSHEET
170 : 0 : return static_cast< sal_Int16 >( maEntries.size() );
171 : : }
172 : :
173 : :
174 : 0 : sal_Bool ExtSheetBuffer::GetScTabIndex( sal_uInt16 nExcIndex, sal_uInt16& rScIndex )
175 : : {
176 : : OSL_ENSURE( nExcIndex,
177 : : "*ExtSheetBuffer::GetScTabIndex(): Sheet-Index == 0!" );
178 : :
179 [ # # ][ # # ]: 0 : if ( !nExcIndex || nExcIndex > maEntries.size() )
[ # # ]
180 : 0 : return false;
181 : :
182 : 0 : Cont* pCur = &maEntries[ nExcIndex - 1 ];
183 : 0 : sal_uInt16& rTabNum = pCur->nTabNum;
184 : :
185 [ # # ]: 0 : if( rTabNum < 0xFFFD )
186 : : {
187 : 0 : rScIndex = rTabNum;
188 : 0 : return sal_True;
189 : : }
190 : :
191 [ # # ]: 0 : if( rTabNum == 0xFFFF )
192 : : {// neue Tabelle erzeugen
193 : : SCTAB nNewTabNum;
194 [ # # ]: 0 : if( pCur->bSWB )
195 : : {// Tabelle ist im selben Workbook!
196 [ # # ][ # # ]: 0 : if( pExcRoot->pIR->GetDoc().GetTable( pCur->aTab, nNewTabNum ) )
[ # # ]
197 : : {
198 : 0 : rScIndex = rTabNum = static_cast<sal_uInt16>(nNewTabNum);
199 : 0 : return sal_True;
200 : : }
201 : : else
202 : 0 : rTabNum = 0xFFFD;
203 : : }
204 [ # # ][ # # ]: 0 : else if( pExcRoot->pIR->GetDocShell() )
205 : : {// Tabelle ist 'echt' extern
206 [ # # ][ # # ]: 0 : if( pExcRoot->pIR->GetExtDocOptions().GetDocSettings().mnLinkCnt == 0 )
[ # # ]
207 : : {
208 : : String aURL( ScGlobal::GetAbsDocName( pCur->aFile,
209 [ # # ][ # # ]: 0 : pExcRoot->pIR->GetDocShell() ) );
210 [ # # ]: 0 : String aTabName( ScGlobal::GetDocTabName( aURL, pCur->aTab ) );
211 [ # # ][ # # ]: 0 : if( pExcRoot->pIR->GetDoc().LinkExternalTab( nNewTabNum, aTabName, aURL, pCur->aTab ) )
[ # # ][ # # ]
[ # # ]
212 : : {
213 : 0 : rScIndex = rTabNum = static_cast<sal_uInt16>(nNewTabNum);
214 : 0 : return sal_True;
215 : : }
216 : : else
217 [ # # ][ # # ]: 0 : rTabNum = 0xFFFE; // Tabelle einmal nicht angelegt -> wird
[ # # ][ # # ]
218 : : // wohl auch nicht mehr gehen...
219 : : }
220 : : else
221 : 0 : rTabNum = 0xFFFE;
222 : :
223 : : }
224 : : }
225 : :
226 : 0 : return false;
227 : : }
228 : :
229 : :
230 : 0 : sal_Bool ExtSheetBuffer::IsLink( const sal_uInt16 nExcIndex ) const
231 : : {
232 : : OSL_ENSURE( nExcIndex > 0, "*ExtSheetBuffer::IsLink(): Index muss >0 sein!" );
233 : :
234 [ # # ][ # # ]: 0 : if (!nExcIndex || nExcIndex > maEntries.size() )
[ # # ]
235 : 0 : return false;
236 : :
237 : 0 : return maEntries[ nExcIndex -1 ].bLink;
238 : : }
239 : :
240 : :
241 : 0 : sal_Bool ExtSheetBuffer::GetLink( const sal_uInt16 nExcIndex, String& rAppl, String& rDoc ) const
242 : : {
243 : : OSL_ENSURE( nExcIndex > 0, "*ExtSheetBuffer::GetLink(): Index muss >0 sein!" );
244 : :
245 [ # # ][ # # ]: 0 : if (!nExcIndex || nExcIndex > maEntries.size() )
[ # # ]
246 : 0 : return false;
247 : :
248 : 0 : const Cont &rRet = maEntries[ nExcIndex -1 ];
249 : :
250 : 0 : rAppl = rRet.aFile;
251 : 0 : rDoc = rRet.aTab;
252 : :
253 : 0 : return true;
254 : : }
255 : :
256 : :
257 : 165 : void ExtSheetBuffer::Reset( void )
258 : : {
259 : 165 : maEntries.clear();
260 : 165 : }
261 : :
262 : :
263 : :
264 : :
265 : 0 : sal_Bool ExtName::IsDDE( void ) const
266 : : {
267 : 0 : return ( nFlags & 0x0001 ) != 0;
268 : : }
269 : :
270 : :
271 : 0 : sal_Bool ExtName::IsOLE( void ) const
272 : : {
273 : 0 : return ( nFlags & 0x0002 ) != 0;
274 : : }
275 : :
276 : :
277 : 55 : ExtNameBuff::ExtNameBuff( const XclImpRoot& rRoot ) :
278 [ + - ]: 55 : XclImpRoot( rRoot )
279 : : {
280 : 55 : }
281 : :
282 : :
283 : 0 : void ExtNameBuff::AddDDE( const String& rName, sal_Int16 nRefIdx )
284 : : {
285 [ # # ]: 0 : ExtName aNew( rName, 0x0001 );
286 [ # # ][ # # ]: 0 : maExtNames[ nRefIdx ].push_back( aNew );
[ # # ]
287 : 0 : }
288 : :
289 : :
290 : 0 : void ExtNameBuff::AddOLE( const String& rName, sal_Int16 nRefIdx, sal_uInt32 nStorageId )
291 : : {
292 [ # # ]: 0 : ExtName aNew( rName, 0x0002 );
293 : 0 : aNew.nStorageId = nStorageId;
294 [ # # ][ # # ]: 0 : maExtNames[ nRefIdx ].push_back( aNew );
[ # # ]
295 : 0 : }
296 : :
297 : :
298 : 0 : void ExtNameBuff::AddName( const String& rName, sal_Int16 nRefIdx )
299 : : {
300 [ # # ][ # # ]: 0 : ExtName aNew( GetScAddInName( rName ), 0x0004 );
[ # # ]
301 [ # # ][ # # ]: 0 : maExtNames[ nRefIdx ].push_back( aNew );
[ # # ]
302 : 0 : }
303 : :
304 : :
305 : 0 : const ExtName* ExtNameBuff::GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const
306 : : {
307 : : OSL_ENSURE( nNameIdx > 0, "ExtNameBuff::GetNameByIndex() - invalid name index" );
308 [ # # ]: 0 : ExtNameMap::const_iterator aIt = maExtNames.find( nRefIdx );
309 [ # # ][ # # ]: 0 : return ((aIt != maExtNames.end()) && (0 < nNameIdx) && (nNameIdx <= aIt->second.size())) ? &aIt->second[ nNameIdx - 1 ] : 0;
[ # # ][ # # ]
310 : : }
311 : :
312 : :
313 : 0 : void ExtNameBuff::Reset( void )
314 : : {
315 : 0 : maExtNames.clear();
316 : 0 : }
317 : :
318 : :
319 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|