Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <tools/stream.hxx>
21 : : #include "svl/brdcst.hxx"
22 : :
23 : : #include <basic/sbx.hxx>
24 : : #include "sbxres.hxx"
25 : : #include "sbxconv.hxx"
26 : : #include <math.h>
27 : : #include <ctype.h>
28 : :
29 : : #include "com/sun/star/uno/XInterface.hpp"
30 : : using namespace com::sun::star::uno;
31 : :
32 : : ///////////////////////////// SbxVariable //////////////////////////////
33 : :
34 [ + + ][ - + ]: 194750 : TYPEINIT1(SbxVariable,SbxValue)
35 [ + - ][ # # ]: 99656 : TYPEINIT1(SbxHint,SfxSimpleHint)
36 : :
37 : : #ifdef DBG_UTIL
38 : : static sal_uIntPtr nVar = 0;
39 : : #endif
40 : :
41 : : ///////////////////////////// SbxVariableImpl ////////////////////////////
42 : :
43 : 0 : class SbxVariableImpl
44 : : {
45 : : friend class SbxVariable;
46 : : String m_aDeclareClassName;
47 : : Reference< XInterface > m_xComListener;
48 : : StarBASIC* m_pComListenerParentBasic;
49 : :
50 : 0 : SbxVariableImpl( void )
51 : 0 : : m_pComListenerParentBasic( NULL )
52 : 0 : {}
53 : 0 : SbxVariableImpl( const SbxVariableImpl& r )
54 : : : m_aDeclareClassName( r.m_aDeclareClassName )
55 : : , m_xComListener( r.m_xComListener )
56 : 0 : , m_pComListenerParentBasic( r.m_pComListenerParentBasic )
57 : : {
58 : 0 : }
59 : : };
60 : :
61 : :
62 : : ///////////////////////////// Constructors //////////////////////////////
63 : :
64 [ + - ][ + - ]: 4318 : SbxVariable::SbxVariable() : SbxValue()
[ # # ][ # # ]
65 : : {
66 : 4318 : mpSbxVariableImpl = NULL;
67 : 4318 : pCst = NULL;
68 : 4318 : pParent = NULL;
69 : 4318 : nUserData = 0;
70 : 4318 : nHash = 0;
71 : : #ifdef DBG_UTIL
72 : : DbgOutf( "SbxVariable::Ctor %lx=%ld", (void*)this, ++nVar );
73 : : #endif
74 : 4318 : }
75 : :
76 : : void registerComListenerVariableForBasic( SbxVariable* pVar, StarBASIC* pBasic );
77 : :
78 : 5495 : SbxVariable::SbxVariable( const SbxVariable& r )
79 [ + - ][ + - ]: 5495 : : SvRefBase( r ), SbxValue( r ), mpPar( r.mpPar ), pInfo( r.pInfo )
[ + - ][ + - ]
80 : : {
81 : 5495 : mpSbxVariableImpl = NULL;
82 [ - + - + ]: 5495 : if( r.mpSbxVariableImpl != NULL )
83 : : {
84 [ # # ][ # # ]: 0 : mpSbxVariableImpl = new SbxVariableImpl( *r.mpSbxVariableImpl );
[ # # ][ # # ]
85 : : #ifndef DISABLE_SCRIPTING
86 [ # # ][ # # ]: 0 : if( mpSbxVariableImpl->m_xComListener.is() )
87 [ # # ][ # # ]: 0 : registerComListenerVariableForBasic( this, mpSbxVariableImpl->m_pComListenerParentBasic );
88 : : #endif
89 : : }
90 : 5495 : pCst = NULL;
91 [ + - ][ + - ]: 5495 : if( r.CanRead() )
92 : : {
93 : 5495 : pParent = r.pParent;
94 : 5495 : nUserData = r.nUserData;
95 [ + - ][ + - ]: 5495 : maName = r.maName;
96 : 5495 : nHash = r.nHash;
97 : : }
98 : : else
99 : : {
100 : 0 : pParent = NULL;
101 : 0 : nUserData = 0;
102 : 0 : nHash = 0;
103 : : }
104 : : #ifdef DBG_UTIL
105 : : static sal_Char const aCellsStr[] = "Cells";
106 : : if ( maName.EqualsAscii( aCellsStr ) )
107 : : maName.AssignAscii( aCellsStr, sizeof( aCellsStr )-1 );
108 : : DbgOutf( "SbxVariable::Ctor %lx=%ld", (void*)this, ++nVar );
109 : : #endif
110 : 5495 : }
111 : :
112 [ + - ][ + - ]: 35355 : SbxVariable::SbxVariable( SbxDataType t, void* p ) : SbxValue( t, p )
[ + - ][ + - ]
113 : : {
114 : 35355 : mpSbxVariableImpl = NULL;
115 : 35355 : pCst = NULL;
116 : 35355 : pParent = NULL;
117 : 35355 : nUserData = 0;
118 : 35355 : nHash = 0;
119 : : #ifdef DBG_UTIL
120 : : DbgOutf( "SbxVariable::Ctor %lx=%ld", (void*)this, ++nVar );
121 : : #endif
122 : 35355 : }
123 : :
124 : : void removeDimAsNewRecoverItem( SbxVariable* pVar );
125 : :
126 [ + - ][ + - ]: 52610 : SbxVariable::~SbxVariable()
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
127 : : {
128 : : #ifdef DBG_UTIL
129 : : rtl::OString aBStr(rtl::OUStringToOString(maName, RTL_TEXTENCODING_ASCII_US));
130 : : DbgOutf( "SbxVariable::Dtor %lx (%s)", (void*)this, aBStr.getStr() );
131 : : static sal_Char const aCellsStr[] = "Cells";
132 : : if ( maName.EqualsAscii( aCellsStr ) )
133 : : maName.AssignAscii( aCellsStr, sizeof( aCellsStr )-1 );
134 : : #endif
135 : : #ifndef DISABLE_SCRIPTING
136 [ - + ][ - + ]: 43539 : if( IsSet( SBX_DIM_AS_NEW ))
137 [ # # ][ # # ]: 0 : removeDimAsNewRecoverItem( this );
138 : : #endif
139 [ - + ][ # # ]: 43539 : delete mpSbxVariableImpl;
[ - + ][ # # ]
140 [ + + ][ + - ]: 43539 : delete pCst;
[ + + ][ + - ]
141 [ + - ][ - + ]: 61681 : }
[ # # ][ - + ]
[ - + ][ # # ]
142 : :
143 : : ////////////////////////////// Broadcasting //////////////////////////////
144 : :
145 : 60188 : SfxBroadcaster& SbxVariable::GetBroadcaster()
146 : : {
147 [ + + ]: 60188 : if( !pCst )
148 [ + - ]: 30712 : pCst = new SfxBroadcaster;
149 : 60188 : return *pCst;
150 : : }
151 : :
152 : 4547 : SbxArray* SbxVariable::GetParameters() const
153 : : {
154 : 4547 : return mpPar;
155 : : }
156 : :
157 : 25247 : SbxObject* SbxVariable::GetParent()
158 : : {
159 : 25247 : return pParent;
160 : : }
161 : :
162 : : // Perhaps some day one could cut the parameter 0.
163 : : // then the copying will be dropped ...
164 : :
165 : 100546 : void SbxVariable::Broadcast( sal_uIntPtr nHintId )
166 : : {
167 [ + + ][ + + ]: 100546 : if( pCst && !IsSet( SBX_NO_BROADCAST ) )
[ + + ]
168 : : {
169 : : // Because the method could be called from outside, check the
170 : : // rights here again
171 [ + + ]: 23839 : if( nHintId & SBX_HINT_DATAWANTED )
172 [ - + ]: 22830 : if( !CanRead() )
173 : 0 : return;
174 [ + + ]: 23839 : if( nHintId & SBX_HINT_DATACHANGED )
175 [ - + ]: 1009 : if( !CanWrite() )
176 : 0 : return;
177 : : // Avoid further broadcasting
178 : 23839 : SfxBroadcaster* pSave = pCst;
179 : 23839 : pCst = NULL;
180 : 23839 : sal_uInt16 nSaveFlags = GetFlags();
181 : 23839 : SetFlag( SBX_READWRITE );
182 [ + + ]: 23839 : if( mpPar.Is() )
183 : : // Register this as element 0, but don't change over the parent!
184 : 1468 : mpPar->GetRef( 0 ) = this;
185 [ + - ]: 23839 : pSave->Broadcast( SbxHint( nHintId, this ) );
186 [ - + ]: 23839 : delete pCst; // who knows already, onto which thoughts someone comes?
187 : 23839 : pCst = pSave;
188 : 100546 : SetFlags( nSaveFlags );
189 : : }
190 : : }
191 : :
192 : 0 : SbxInfo* SbxVariable::GetInfo()
193 : : {
194 [ # # ]: 0 : if( !pInfo )
195 : : {
196 : 0 : Broadcast( SBX_HINT_INFOWANTED );
197 [ # # ]: 0 : if( pInfo.Is() )
198 : 0 : SetModified( sal_True );
199 : : }
200 : 0 : return pInfo;
201 : : }
202 : :
203 : 219 : void SbxVariable::SetInfo( SbxInfo* p )
204 : : {
205 : 219 : pInfo = p;
206 : 219 : }
207 : :
208 : 20653 : void SbxVariable::SetParameters( SbxArray* p )
209 : : {
210 : 20653 : mpPar = p;
211 : 20653 : }
212 : :
213 : :
214 : : /////////////////////////// Name of the variables ///////////////////////////
215 : :
216 : 35206 : void SbxVariable::SetName( const XubString& rName )
217 : : {
218 : 35206 : maName = rName;
219 : 35206 : nHash = MakeHashCode( rName );
220 : 35206 : }
221 : :
222 : 133101 : const XubString& SbxVariable::GetName( SbxNameType t ) const
223 : : {
224 : : static char cSuffixes[] = " %&!#@ $";
225 [ + - ]: 133101 : if( t == SbxNAME_NONE )
226 : 133101 : return maName;
227 : : // Request parameter-information (not for objects)
228 [ # # ]: 0 : ((SbxVariable*)this)->GetInfo();
229 : : // Append nothing, if it is a simple property (no empty brackets)
230 [ # # # # ]: 0 : if( !pInfo
[ # # ][ # # ]
231 [ # # ]: 0 : || ( pInfo->aParams.empty() && GetClass() == SbxCLASS_PROPERTY ) )
232 : 0 : return maName;
233 : 0 : xub_Unicode cType = ' ';
234 [ # # ]: 0 : XubString aTmp( maName );
235 : : // short type? Then fetch it, posible this is 0.
236 [ # # ]: 0 : SbxDataType et = GetType();
237 [ # # ]: 0 : if( t == SbxNAME_SHORT_TYPES )
238 : : {
239 [ # # ]: 0 : if( et <= SbxSTRING )
240 : 0 : cType = cSuffixes[ et ];
241 [ # # ]: 0 : if( cType != ' ' )
242 [ # # ]: 0 : aTmp += cType;
243 : : }
244 [ # # ]: 0 : aTmp += '(';
245 [ # # ][ # # ]: 0 : for(SbxParams::const_iterator i = pInfo->aParams.begin(); i != pInfo->aParams.end(); ++i)
[ # # ][ # # ]
[ # # ][ # # ]
246 : : {
247 [ # # ]: 0 : int nt = i->eType & 0x0FFF;
248 [ # # ][ # # ]: 0 : if( i != pInfo->aParams.begin() )
[ # # ]
249 [ # # ]: 0 : aTmp += ',';
250 [ # # ][ # # ]: 0 : if( i->nFlags & SBX_OPTIONAL )
251 [ # # ][ # # ]: 0 : aTmp += String( SbxRes( STRING_OPTIONAL ) );
[ # # ][ # # ]
252 [ # # ][ # # ]: 0 : if( i->eType & SbxBYREF )
253 [ # # ][ # # ]: 0 : aTmp += String( SbxRes( STRING_BYREF ) );
[ # # ][ # # ]
254 [ # # ][ # # ]: 0 : aTmp += i->aName;
255 : 0 : cType = ' ';
256 : : // short type? Then fetch it, posible this is 0.
257 [ # # ]: 0 : if( t == SbxNAME_SHORT_TYPES )
258 : : {
259 [ # # ]: 0 : if( nt <= SbxSTRING )
260 : 0 : cType = cSuffixes[ nt ];
261 : : }
262 [ # # ]: 0 : if( cType != ' ' )
263 : : {
264 [ # # ]: 0 : aTmp += cType;
265 [ # # ][ # # ]: 0 : if( i->eType & SbxARRAY )
266 [ # # ]: 0 : aTmp.AppendAscii( "()" );
267 : : }
268 : : else
269 : : {
270 [ # # ][ # # ]: 0 : if( i->eType & SbxARRAY )
271 [ # # ]: 0 : aTmp.AppendAscii( "()" );
272 : : // long type?
273 [ # # ]: 0 : if( t != SbxNAME_SHORT )
274 : : {
275 [ # # ][ # # ]: 0 : aTmp += String( SbxRes( STRING_AS ) );
[ # # ][ # # ]
276 [ # # ]: 0 : if( nt < 32 )
277 : : aTmp += String( SbxRes(
278 [ # # ][ # # ]: 0 : sal::static_int_cast< sal_uInt16 >( STRING_TYPES + nt ) ) );
[ # # ][ # # ]
279 : : else
280 [ # # ][ # # ]: 0 : aTmp += String( SbxRes( STRING_ANY ) );
[ # # ][ # # ]
281 : : }
282 : : }
283 : : }
284 [ # # ]: 0 : aTmp += ')';
285 : : // Long type? Then fetch it
286 [ # # ][ # # ]: 0 : if( t == SbxNAME_LONG_TYPES && et != SbxEMPTY )
287 : : {
288 [ # # ][ # # ]: 0 : aTmp += String( SbxRes( STRING_AS ) );
[ # # ][ # # ]
289 [ # # ]: 0 : if( et < 32 )
290 : : aTmp += String( SbxRes(
291 [ # # ][ # # ]: 0 : sal::static_int_cast< sal_uInt16 >( STRING_TYPES + et ) ) );
[ # # ][ # # ]
292 : : else
293 [ # # ][ # # ]: 0 : aTmp += String( SbxRes( STRING_ANY ) );
[ # # ][ # # ]
294 : : }
295 [ # # ]: 0 : ((SbxVariable*) this)->aToolString = aTmp;
296 [ # # ]: 133101 : return aToolString;
297 : : }
298 : :
299 : : // Create a simple hashcode: the first six characters were evaluated.
300 : :
301 : 360805 : sal_uInt16 SbxVariable::MakeHashCode( const XubString& rName )
302 : : {
303 : 360805 : sal_uInt16 n = 0;
304 : 360805 : sal_uInt16 nLen = rName.Len();
305 [ + + ]: 360805 : if( nLen > 6 )
306 : 259184 : nLen = 6;
307 : 360805 : const xub_Unicode* p = rName.GetBuffer();
308 [ + + ]: 2404726 : while( nLen-- )
309 : : {
310 : 2043921 : sal_uInt8 c = (sal_uInt8)*p;
311 : 2043921 : p++;
312 : : // If we have a commen sigen break!!
313 [ - + ]: 2043921 : if( c >= 0x80 )
314 : 0 : return 0;
315 : 2043921 : n = sal::static_int_cast< sal_uInt16 >( ( n << 3 ) + toupper( c ) );
316 : : }
317 : 360805 : return n;
318 : : }
319 : :
320 : : ////////////////////////////// Operators ////////////////////////////////
321 : :
322 : 3291 : SbxVariable& SbxVariable::operator=( const SbxVariable& r )
323 : : {
324 : 3291 : SbxValue::operator=( r );
325 [ - + ]: 3291 : delete mpSbxVariableImpl;
326 [ - + ]: 3291 : if( r.mpSbxVariableImpl != NULL )
327 : : {
328 [ # # ]: 0 : mpSbxVariableImpl = new SbxVariableImpl( *r.mpSbxVariableImpl );
329 : : #ifndef DISABLE_SCRIPTING
330 [ # # ]: 0 : if( mpSbxVariableImpl->m_xComListener.is() )
331 : 0 : registerComListenerVariableForBasic( this, mpSbxVariableImpl->m_pComListenerParentBasic );
332 : : #endif
333 : : }
334 : : else
335 : 3291 : mpSbxVariableImpl = NULL;
336 : 3291 : return *this;
337 : : }
338 : :
339 : : //////////////////////////////// Conversion ////////////////////////////////
340 : :
341 : 112706 : SbxDataType SbxVariable::GetType() const
342 : : {
343 [ + + ]: 112706 : if( aData.eType == SbxOBJECT )
344 [ + + ]: 6037 : return aData.pObj ? aData.pObj->GetType() : SbxOBJECT;
345 [ - + ]: 106669 : else if( aData.eType == SbxVARIANT )
346 [ # # ]: 0 : return aData.pObj ? aData.pObj->GetType() : SbxVARIANT;
347 : : else
348 : 112706 : return aData.eType;
349 : : }
350 : :
351 : 10 : SbxClassType SbxVariable::GetClass() const
352 : : {
353 : 10 : return SbxCLASS_VARIABLE;
354 : : }
355 : :
356 : 61200 : void SbxVariable::SetModified( sal_Bool b )
357 : : {
358 [ + + ]: 61200 : if( IsSet( SBX_NO_MODIFY ) )
359 : 61200 : return;
360 : 57623 : SbxBase::SetModified( b );
361 [ + - ][ + + ]: 57623 : if( pParent && pParent != this ) //??? HotFix: Recursion out here MM
362 : 4831 : pParent->SetModified( b );
363 : : }
364 : :
365 : 45267 : void SbxVariable::SetParent( SbxObject* p )
366 : : {
367 : : #ifdef DBG_UTIL
368 : : // Will the parent of a SbxObject be set?
369 : : if ( p && ISA(SbxObject) )
370 : : {
371 : : // then this had to be a child of the new parent
372 : : bool bFound = false;
373 : : SbxArray *pChildren = p->GetObjects();
374 : : if ( pChildren )
375 : : {
376 : : for ( sal_uInt16 nIdx = 0; !bFound && nIdx < pChildren->Count(); ++nIdx )
377 : : bFound = ( this == pChildren->Get(nIdx) );
378 : : }
379 : : if ( !bFound )
380 : : {
381 : : String aMsg = rtl::OUString("dangling: [");
382 : : aMsg += GetName();
383 : : aMsg.AppendAscii( "].SetParent([" );
384 : : aMsg += p->GetName();
385 : : aMsg.AppendAscii( "])" );
386 : : rtl::OString aBStr(rtl::OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US));
387 : : DbgOut( aBStr.getStr(), DBG_OUT_WARNING, __FILE__, __LINE__);
388 : : }
389 : : }
390 : : #endif
391 : :
392 : 45267 : pParent = p;
393 : 45267 : }
394 : :
395 : 0 : SbxVariableImpl* SbxVariable::getImpl( void )
396 : : {
397 [ # # ]: 0 : if( mpSbxVariableImpl == NULL )
398 [ # # ]: 0 : mpSbxVariableImpl = new SbxVariableImpl();
399 : 0 : return mpSbxVariableImpl;
400 : : }
401 : :
402 : 0 : const String& SbxVariable::GetDeclareClassName( void )
403 : : {
404 : 0 : SbxVariableImpl* pImpl = getImpl();
405 : 0 : return pImpl->m_aDeclareClassName;
406 : : }
407 : :
408 : 0 : void SbxVariable::SetDeclareClassName( const String& rDeclareClassName )
409 : : {
410 : 0 : SbxVariableImpl* pImpl = getImpl();
411 : 0 : pImpl->m_aDeclareClassName = rDeclareClassName;
412 : 0 : }
413 : :
414 : 0 : void SbxVariable::SetComListener( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xComListener,
415 : : StarBASIC* pParentBasic )
416 : : {
417 : 0 : SbxVariableImpl* pImpl = getImpl();
418 : 0 : pImpl->m_xComListener = xComListener;
419 : 0 : pImpl->m_pComListenerParentBasic = pParentBasic;
420 : : #ifndef DISABLE_SCRIPTING
421 : 0 : registerComListenerVariableForBasic( this, pParentBasic );
422 : : #endif
423 : 0 : }
424 : :
425 : 0 : void SbxVariable::ClearComListener( void )
426 : : {
427 : 0 : SbxVariableImpl* pImpl = getImpl();
428 : 0 : pImpl->m_xComListener.clear();
429 : 0 : }
430 : :
431 : :
432 : : ////////////////////////////// Loading/Saving /////////////////////////////
433 : :
434 : 0 : sal_Bool SbxVariable::LoadData( SvStream& rStrm, sal_uInt16 nVer )
435 : : {
436 : : sal_uInt16 nType;
437 : : sal_uInt8 cMark;
438 [ # # ]: 0 : rStrm >> cMark;
439 [ # # ]: 0 : if( cMark == 0xFF )
440 : : {
441 [ # # ][ # # ]: 0 : if( !SbxValue::LoadData( rStrm, nVer ) )
442 : 0 : return sal_False;
443 : : maName = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rStrm,
444 [ # # ][ # # ]: 0 : RTL_TEXTENCODING_ASCII_US);
445 : : sal_uInt32 nTemp;
446 [ # # ]: 0 : rStrm >> nTemp;
447 : 0 : nUserData = nTemp;
448 : : }
449 : : else
450 : : {
451 [ # # ]: 0 : rStrm.SeekRel( -1L );
452 [ # # ]: 0 : rStrm >> nType;
453 : : maName = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rStrm,
454 [ # # ][ # # ]: 0 : RTL_TEXTENCODING_ASCII_US);
455 : : sal_uInt32 nTemp;
456 [ # # ]: 0 : rStrm >> nTemp;
457 : 0 : nUserData = nTemp;
458 : : // correction: old methods have instead of SbxNULL now SbxEMPTY
459 [ # # ][ # # ]: 0 : if( nType == SbxNULL && GetClass() == SbxCLASS_METHOD )
[ # # ][ # # ]
460 : 0 : nType = SbxEMPTY;
461 : 0 : SbxValues aTmp;
462 [ # # ]: 0 : String aTmpString;
463 : 0 : ::rtl::OUString aVal;
464 : 0 : aTmp.eType = aData.eType = (SbxDataType) nType;
465 : 0 : aTmp.pOUString = &aVal;
466 [ # # # # : 0 : switch( nType )
# # # ]
467 : : {
468 : : case SbxBOOL:
469 : : case SbxERROR:
470 : : case SbxINTEGER:
471 [ # # ]: 0 : rStrm >> aTmp.nInteger; break;
472 : : case SbxLONG:
473 [ # # ]: 0 : rStrm >> aTmp.nLong; break;
474 : : case SbxSINGLE:
475 : : {
476 : : // Floats as ASCII
477 : : aTmpString = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(
478 [ # # ][ # # ]: 0 : rStrm, RTL_TEXTENCODING_ASCII_US);
479 : : double d;
480 : : SbxDataType t;
481 [ # # ][ # # ]: 0 : if( ImpScan( aTmpString, d, t, NULL ) != SbxERR_OK || t == SbxDOUBLE )
[ # # ][ # # ]
[ # # # # ]
[ # # ]
482 : : {
483 : 0 : aTmp.nSingle = 0;
484 : 0 : return sal_False;
485 : : }
486 : 0 : aTmp.nSingle = (float) d;
487 : : break;
488 : : }
489 : : case SbxDATE:
490 : : case SbxDOUBLE:
491 : : {
492 : : // Floats as ASCII
493 : : aTmpString = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rStrm,
494 [ # # ][ # # ]: 0 : RTL_TEXTENCODING_ASCII_US);
495 : : SbxDataType t;
496 [ # # ][ # # ]: 0 : if( ImpScan( aTmpString, aTmp.nDouble, t, NULL ) != SbxERR_OK )
[ # # ]
497 : : {
498 : 0 : aTmp.nDouble = 0;
499 : 0 : return sal_False;
500 : : }
501 : : break;
502 : : }
503 : : case SbxSTRING:
504 : : aVal = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rStrm,
505 [ # # ]: 0 : RTL_TEXTENCODING_ASCII_US);
506 : 0 : break;
507 : : case SbxEMPTY:
508 : : case SbxNULL:
509 : 0 : break;
510 : : default:
511 : 0 : aData.eType = SbxNULL;
512 : : DBG_ASSERT( !this, "Nicht unterstuetzer Datentyp geladen" );
513 : 0 : return sal_False;
514 : : }
515 : : // putt value
516 [ # # ][ # # ]: 0 : if( nType != SbxNULL && nType != SbxEMPTY && !Put( aTmp ) )
[ # # ][ # # ]
[ # # ]
517 [ # # ][ # # ]: 0 : return sal_False;
[ # # ]
518 : : }
519 [ # # ]: 0 : rStrm >> cMark;
520 : : // cMark is also a version number!
521 : : // 1: initial version
522 : : // 2: with nUserData
523 [ # # ]: 0 : if( cMark )
524 : : {
525 [ # # ]: 0 : if( cMark > 2 )
526 : 0 : return sal_False;
527 [ # # ][ # # ]: 0 : pInfo = new SbxInfo;
[ # # ]
528 [ # # ]: 0 : pInfo->LoadData( rStrm, (sal_uInt16) cMark );
529 : : }
530 : : // Load private data only, if it is a SbxVariable
531 [ # # ][ # # ]: 0 : if( GetClass() == SbxCLASS_VARIABLE && !LoadPrivateData( rStrm, nVer ) )
[ # # ][ # # ]
[ # # ]
532 : 0 : return sal_False;
533 [ # # ]: 0 : ((SbxVariable*) this)->Broadcast( SBX_HINT_DATACHANGED );
534 [ # # ]: 0 : nHash = MakeHashCode( maName );
535 [ # # ]: 0 : SetModified( sal_True );
536 : 0 : return sal_True;
537 : : }
538 : :
539 : 0 : sal_Bool SbxVariable::StoreData( SvStream& rStrm ) const
540 : : {
541 : 0 : rStrm << (sal_uInt8) 0xFF; // Marker
542 : : sal_Bool bValStore;
543 [ # # ]: 0 : if( this->IsA( TYPE(SbxMethod) ) )
544 : : {
545 : : // #50200 Avoid that objects , which during the runtime
546 : : // as return-value are saved in the method as a value were saved
547 : 0 : SbxVariable* pThis = (SbxVariable*)this;
548 : 0 : sal_uInt16 nSaveFlags = GetFlags();
549 : 0 : pThis->SetFlag( SBX_WRITE );
550 : 0 : pThis->SbxValue::Clear();
551 : 0 : pThis->SetFlags( nSaveFlags );
552 : :
553 : : // So that the method will not be executed in any case!
554 : : // CAST, to avoid const!
555 : 0 : pThis->SetFlag( SBX_NO_BROADCAST );
556 : 0 : bValStore = SbxValue::StoreData( rStrm );
557 : 0 : pThis->ResetFlag( SBX_NO_BROADCAST );
558 : : }
559 : : else
560 : 0 : bValStore = SbxValue::StoreData( rStrm );
561 [ # # ]: 0 : if( !bValStore )
562 : 0 : return sal_False;
563 : : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rStrm, maName,
564 [ # # ]: 0 : RTL_TEXTENCODING_ASCII_US);
565 : 0 : rStrm << (sal_uInt32)nUserData;
566 [ # # ]: 0 : if( pInfo.Is() )
567 : : {
568 : 0 : rStrm << (sal_uInt8) 2; // Version 2: with UserData!
569 : 0 : pInfo->StoreData( rStrm );
570 : : }
571 : : else
572 : 0 : rStrm << (sal_uInt8) 0;
573 : : // Save private data only, if it is a SbxVariable
574 [ # # ]: 0 : if( GetClass() == SbxCLASS_VARIABLE )
575 : 0 : return StorePrivateData( rStrm );
576 : : else
577 : 0 : return sal_True;
578 : : }
579 : :
580 : : ////////////////////////////// SbxInfo ///////////////////////////////////
581 : :
582 [ + - ][ + - ]: 34 : SbxInfo::SbxInfo() : aHelpFile(), nHelpId( 0 ), aParams()
[ + - ]
583 : 34 : {}
584 : :
585 : 219 : SbxInfo::SbxInfo( const String& r, sal_uInt32 n )
586 [ + - ][ + - ]: 219 : : aHelpFile( r ), nHelpId( n ), aParams()
[ + - ]
587 : 219 : {}
588 : :
589 : : ////////////////////////////// SbxAlias //////////////////////////////////
590 : :
591 : 0 : SbxAlias::SbxAlias( const SbxAlias& r )
592 : : : SvRefBase( r ), SbxVariable( r ),
593 [ # # ][ # # ]: 0 : SfxListener( r ), xAlias( r.xAlias )
[ # # ][ # # ]
594 : 0 : {}
595 : :
596 : 0 : SbxAlias& SbxAlias::operator=( const SbxAlias& r )
597 : : {
598 : 0 : xAlias = r.xAlias;
599 : 0 : return *this;
600 : : }
601 : :
602 [ # # ][ # # ]: 0 : SbxAlias::~SbxAlias()
[ # # ][ # # ]
[ # # ][ # # ]
603 : : {
604 [ # # ][ # # ]: 0 : if( xAlias.Is() )
605 [ # # ][ # # ]: 0 : EndListening( xAlias->GetBroadcaster() );
[ # # ][ # # ]
606 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ][ # # ]
607 : :
608 : 0 : void SbxAlias::Broadcast( sal_uIntPtr nHt )
609 : : {
610 [ # # ]: 0 : if( xAlias.Is() )
611 : : {
612 : 0 : xAlias->SetParameters( GetParameters() );
613 [ # # ]: 0 : if( nHt == SBX_HINT_DATAWANTED )
614 : 0 : SbxVariable::operator=( *xAlias );
615 [ # # ][ # # ]: 0 : else if( nHt == SBX_HINT_DATACHANGED || nHt == SBX_HINT_CONVERTED )
616 : 0 : *xAlias = *this;
617 [ # # ]: 0 : else if( nHt == SBX_HINT_INFOWANTED )
618 : : {
619 : 0 : xAlias->Broadcast( nHt );
620 : 0 : pInfo = xAlias->GetInfo();
621 : : }
622 : : }
623 : 0 : }
624 : :
625 : 0 : void SbxAlias::SFX_NOTIFY( SfxBroadcaster&, const TypeId&,
626 : : const SfxHint& rHint, const TypeId& )
627 : : {
628 [ # # ][ # # ]: 0 : const SbxHint* p = PTR_CAST(SbxHint,&rHint);
629 [ # # ][ # # ]: 0 : if( p && p->GetId() == SBX_HINT_DYING )
[ # # ]
630 : : {
631 : 0 : xAlias.Clear();
632 : : // delete the alias?
633 [ # # ]: 0 : if( pParent )
634 : 0 : pParent->Remove( this );
635 : : }
636 : 0 : }
637 : :
638 : 0 : void SbxVariable::Dump( SvStream& rStrm, sal_Bool bFill )
639 : : {
640 [ # # ][ # # ]: 0 : rtl::OString aBNameStr(rtl::OUStringToOString(GetName( SbxNAME_SHORT_TYPES ), RTL_TEXTENCODING_ASCII_US));
[ # # ]
641 [ # # ]: 0 : rStrm << "Variable( "
642 [ # # ][ # # ]: 0 : << rtl::OString::valueOf(reinterpret_cast<sal_Int64>(this)).getStr() << "=="
643 [ # # ]: 0 : << aBNameStr.getStr();
644 [ # # ][ # # ]: 0 : rtl::OString aBParentNameStr(rtl::OUStringToOString(GetParent()->GetName(), RTL_TEXTENCODING_ASCII_US));
[ # # ][ # # ]
645 [ # # ][ # # ]: 0 : if ( GetParent() )
646 [ # # ][ # # ]: 0 : rStrm << " in parent '" << aBParentNameStr.getStr() << "'";
[ # # ]
647 : : else
648 [ # # ]: 0 : rStrm << " no parent";
649 [ # # ]: 0 : rStrm << " ) ";
650 : :
651 : : // output also the object at object-vars
652 [ # # # # : 0 : if ( GetValues_Impl().eType == SbxOBJECT &&
# # ][ # # ]
[ # # ]
653 : 0 : GetValues_Impl().pObj &&
654 : 0 : GetValues_Impl().pObj != this &&
655 [ # # ]: 0 : GetValues_Impl().pObj != GetParent() )
656 : : {
657 [ # # ]: 0 : rStrm << " contains ";
658 [ # # ]: 0 : ((SbxObject*) GetValues_Impl().pObj)->Dump( rStrm, bFill );
659 : : }
660 : : else
661 [ # # ]: 0 : rStrm << endl;
662 : 0 : }
663 : :
664 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|