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 <basic/sbx.hxx>
22 : #include "sbxres.hxx"
23 : #include <svl/brdcst.hxx>
24 :
25 106504 : TYPEINIT1(SbxMethod,SbxVariable)
26 68849 : TYPEINIT1(SbxProperty,SbxVariable)
27 73885 : TYPEINIT2(SbxObject,SbxVariable,SfxListener)
28 :
29 143 : static OUString pNameProp; // Name-Property
30 143 : static OUString pParentProp; // Parent-Property
31 :
32 : static sal_uInt16 nNameHash = 0, nParentHash = 0;
33 :
34 :
35 :
36 9276 : SbxObject::SbxObject( const OUString& rClass )
37 9276 : : SbxVariable( SbxOBJECT ), aClassName( rClass )
38 : {
39 9276 : aData.pObj = this;
40 9276 : if( !nNameHash )
41 : {
42 67 : pNameProp = OUString::createFromAscii(GetSbxRes( STRING_NAMEPROP ));
43 67 : pParentProp = OUString::createFromAscii(GetSbxRes( STRING_PARENTPROP ));
44 67 : nNameHash = MakeHashCode( pNameProp );
45 67 : nParentHash = MakeHashCode( pParentProp );
46 : }
47 9276 : SbxObject::Clear();
48 9276 : SbxObject::SetName( rClass );
49 9276 : }
50 :
51 0 : SbxObject::SbxObject( const SbxObject& rObj )
52 0 : : SvRefBase( rObj ), SbxVariable( rObj.GetType() ),
53 0 : SfxListener( rObj )
54 : {
55 0 : *this = rObj;
56 0 : }
57 :
58 0 : SbxObject& SbxObject::operator=( const SbxObject& r )
59 : {
60 0 : if( &r != this )
61 : {
62 0 : SbxVariable::operator=( r );
63 0 : aClassName = r.aClassName;
64 0 : pMethods = new SbxArray;
65 0 : pProps = new SbxArray;
66 0 : pObjs = new SbxArray( SbxOBJECT );
67 : // The arrays were copied, the content taken over
68 0 : *pMethods = *r.pMethods;
69 0 : *pProps = *r.pProps;
70 0 : *pObjs = *r.pObjs;
71 : // Because the variables were taken over, this is OK
72 0 : pDfltProp = r.pDfltProp;
73 0 : SetName( r.GetName() );
74 0 : SetFlags( r.GetFlags() );
75 0 : SetModified( sal_True );
76 : }
77 0 : return *this;
78 : }
79 :
80 18474 : static void CheckParentsOnDelete( SbxObject* pObj, SbxArray* p )
81 : {
82 26184 : for( sal_uInt16 i = 0; i < p->Count(); i++ )
83 : {
84 7710 : SbxVariableRef& rRef = p->GetRef( i );
85 7710 : if( rRef->IsBroadcaster() )
86 : {
87 7710 : pObj->EndListening( rRef->GetBroadcaster(), sal_True );
88 : }
89 : // Did the element have more then one reference and still a Listener?
90 7710 : if( rRef->GetRefCount() > 1 )
91 : {
92 248 : rRef->SetParent( NULL );
93 : DBG_ASSERT( !rRef->IsBroadcaster() || rRef->GetBroadcaster().GetListenerCount(), "Object element with dangling parent" );
94 : }
95 : }
96 18474 : }
97 :
98 13352 : SbxObject::~SbxObject()
99 : {
100 6158 : CheckParentsOnDelete( this, pProps );
101 6158 : CheckParentsOnDelete( this, pMethods );
102 6158 : CheckParentsOnDelete( this, pObjs );
103 :
104 : // avoid handling in ~SbxVariable as SBX_DIM_AS_NEW == SBX_GBLSEARCH
105 6158 : ResetFlag( SBX_DIM_AS_NEW );
106 7194 : }
107 :
108 13404 : SbxDataType SbxObject::GetType() const
109 : {
110 13404 : return SbxOBJECT;
111 : }
112 :
113 36605 : SbxClassType SbxObject::GetClass() const
114 : {
115 36605 : return SbxCLASS_OBJECT;
116 : }
117 :
118 9276 : void SbxObject::Clear()
119 : {
120 9276 : pMethods = new SbxArray;
121 9276 : pProps = new SbxArray;
122 9276 : pObjs = new SbxArray( SbxOBJECT );
123 : SbxVariable* p;
124 9276 : p = Make( pNameProp, SbxCLASS_PROPERTY, SbxSTRING );
125 9276 : p->SetFlag( SBX_DONTSTORE );
126 9276 : p = Make( pParentProp, SbxCLASS_PROPERTY, SbxOBJECT );
127 9276 : p->ResetFlag( SBX_WRITE );
128 9276 : p->SetFlag( SBX_DONTSTORE );
129 9276 : pDfltProp = NULL;
130 9276 : SetModified( sal_False );
131 9276 : }
132 :
133 21949 : void SbxObject::SFX_NOTIFY( SfxBroadcaster&, const TypeId&,
134 : const SfxHint& rHint, const TypeId& )
135 : {
136 21949 : const SbxHint* p = PTR_CAST(SbxHint,&rHint);
137 21949 : if( p )
138 : {
139 21949 : sal_uIntPtr nId = p->GetId();
140 21949 : bool bRead = ( nId == SBX_HINT_DATAWANTED );
141 21949 : bool bWrite = ( nId == SBX_HINT_DATACHANGED );
142 21949 : SbxVariable* pVar = p->GetVar();
143 21949 : if( bRead || bWrite )
144 : {
145 21868 : OUString aVarName( pVar->GetName() );
146 21868 : sal_uInt16 nHash_ = MakeHashCode( aVarName );
147 21868 : if( nHash_ == nNameHash && aVarName.equalsIgnoreAsciiCase( pNameProp ) )
148 : {
149 0 : if( bRead )
150 : {
151 0 : pVar->PutString( GetName() );
152 : }
153 : else
154 : {
155 0 : SetName( pVar->GetOUString() );
156 : }
157 : }
158 21868 : else if( nHash_ == nParentHash && aVarName.equalsIgnoreAsciiCase( pParentProp ) )
159 : {
160 0 : SbxObject* p_ = GetParent();
161 0 : if( !p_ )
162 : {
163 0 : p_ = this;
164 : }
165 0 : pVar->PutObject( p_ );
166 21868 : }
167 : }
168 : }
169 21949 : }
170 :
171 148 : sal_Bool SbxObject::IsClass( const OUString& rName ) const
172 : {
173 148 : return sal_Bool( aClassName.equalsIgnoreAsciiCase( rName ) );
174 : }
175 :
176 0 : SbxVariable* SbxObject::FindUserData( sal_uInt32 nData )
177 : {
178 0 : if( !GetAll( SbxCLASS_DONTCARE ) )
179 : {
180 0 : return NULL;
181 : }
182 0 : SbxVariable* pRes = pMethods->FindUserData( nData );
183 0 : if( !pRes )
184 : {
185 0 : pRes = pProps->FindUserData( nData );
186 : }
187 0 : if( !pRes )
188 : {
189 0 : pRes = pObjs->FindUserData( nData );
190 : }
191 : // Search in the parents?
192 0 : if( !pRes && IsSet( SBX_GBLSEARCH ) )
193 : {
194 0 : SbxObject* pCur = this;
195 0 : while( !pRes && pCur->pParent )
196 : {
197 : // I myself was already searched through!
198 0 : sal_uInt16 nOwn = pCur->GetFlags();
199 0 : pCur->ResetFlag( SBX_EXTSEARCH );
200 : // I search already global!
201 0 : sal_uInt16 nPar = pCur->pParent->GetFlags();
202 0 : pCur->pParent->ResetFlag( SBX_GBLSEARCH );
203 0 : pRes = pCur->pParent->FindUserData( nData );
204 0 : pCur->SetFlags( nOwn );
205 0 : pCur->pParent->SetFlags( nPar );
206 0 : pCur = pCur->pParent;
207 : }
208 : }
209 0 : return pRes;
210 : }
211 :
212 107291 : SbxVariable* SbxObject::Find( const OUString& rName, SbxClassType t )
213 : {
214 : #ifdef DBG_UTIL
215 : static sal_uInt16 nLvl = 0;
216 : static const char* pCls[] = { "DontCare","Array","Value","Variable","Method","Property","Object" };
217 : OString aNameStr1(OUStringToOString(rName, RTL_TEXTENCODING_ASCII_US));
218 : OString aNameStr2(OUStringToOString(SbxVariable::GetName(), RTL_TEXTENCODING_ASCII_US));
219 : DbgOutf( "SBX: Search %.*s %s %s in %s",
220 : nLvl++, " ",
221 : ( t >= SbxCLASS_DONTCARE && t <= SbxCLASS_OBJECT )
222 : ? pCls[ t-1 ] : "Unknown class", aNameStr1.getStr(), aNameStr2.getStr() );
223 : #endif
224 :
225 107291 : if( !GetAll( t ) )
226 : {
227 0 : return NULL;
228 : }
229 107291 : SbxVariable* pRes = NULL;
230 107291 : pObjs->SetFlag( SBX_EXTSEARCH );
231 107291 : if( t == SbxCLASS_DONTCARE )
232 : {
233 63805 : pRes = pMethods->Find( rName, SbxCLASS_METHOD );
234 63805 : if( !pRes )
235 : {
236 61490 : pRes = pProps->Find( rName, SbxCLASS_PROPERTY );
237 : }
238 63805 : if( !pRes )
239 : {
240 42146 : pRes = pObjs->Find( rName, t );
241 : }
242 : }
243 : else
244 : {
245 43486 : SbxArray* pArray = NULL;
246 43486 : switch( t )
247 : {
248 : case SbxCLASS_VARIABLE:
249 4976 : case SbxCLASS_PROPERTY: pArray = pProps; break;
250 907 : case SbxCLASS_METHOD: pArray = pMethods; break;
251 37603 : case SbxCLASS_OBJECT: pArray = pObjs; break;
252 0 : default: DBG_ASSERT( !this, "Invalid SBX-Class" ); break;
253 : }
254 43486 : if( pArray )
255 : {
256 43486 : pRes = pArray->Find( rName, t );
257 : }
258 : }
259 : // ExtendedsSearch in the Object-Array?
260 : // For objects and DontCare is the array of objects already
261 : // searched through
262 107291 : if( !pRes && ( t == SbxCLASS_METHOD || t == SbxCLASS_PROPERTY ) )
263 4856 : pRes = pObjs->Find( rName, t );
264 : // Search in the parents?
265 107291 : if( !pRes && IsSet( SBX_GBLSEARCH ) )
266 : {
267 9248 : SbxObject* pCur = this;
268 28640 : while( !pRes && pCur->pParent )
269 : {
270 : // I myself was already searched through!
271 10144 : sal_uInt16 nOwn = pCur->GetFlags();
272 10144 : pCur->ResetFlag( SBX_EXTSEARCH );
273 : // I search already global!
274 10144 : sal_uInt16 nPar = pCur->pParent->GetFlags();
275 10144 : pCur->pParent->ResetFlag( SBX_GBLSEARCH );
276 10144 : pRes = pCur->pParent->Find( rName, t );
277 10144 : pCur->SetFlags( nOwn );
278 10144 : pCur->pParent->SetFlags( nPar );
279 10144 : pCur = pCur->pParent;
280 : }
281 : }
282 : #ifdef DBG_UTIL
283 : nLvl--;
284 : if( pRes )
285 : {
286 : OString aNameStr3(OUStringToOString(rName, RTL_TEXTENCODING_ASCII_US));
287 : OString aNameStr4(OUStringToOString(SbxVariable::GetName(), RTL_TEXTENCODING_ASCII_US));
288 : DbgOutf( "SBX: Found %.*s %s in %s",
289 : nLvl, " ", aNameStr3.getStr(), aNameStr4.getStr() );
290 : }
291 : #endif
292 107291 : return pRes;
293 : }
294 :
295 : // Abbreviated version: The parent-string will be searched through
296 : // The whole thing recursive, because Call() might be overloaded
297 : // Qualified names are allowed
298 :
299 18 : sal_Bool SbxObject::Call( const OUString& rName, SbxArray* pParam )
300 : {
301 18 : SbxVariable* pMeth = FindQualified( rName, SbxCLASS_DONTCARE);
302 18 : if( pMeth && pMeth->ISA(SbxMethod) )
303 : {
304 : // FindQualified() might have been stroked!
305 18 : if( pParam )
306 : {
307 18 : pMeth->SetParameters( pParam );
308 : }
309 18 : pMeth->Broadcast( SBX_HINT_DATAWANTED );
310 18 : pMeth->SetParameters( NULL );
311 18 : return sal_True;
312 : }
313 0 : SetError( SbxERR_NO_METHOD );
314 0 : return sal_False;
315 : }
316 :
317 100 : SbxProperty* SbxObject::GetDfltProperty()
318 : {
319 100 : if ( !pDfltProp && !aDfltPropName.isEmpty() )
320 : {
321 88 : pDfltProp = (SbxProperty*) Find( aDfltPropName, SbxCLASS_PROPERTY );
322 88 : if( !pDfltProp )
323 : {
324 0 : pDfltProp = (SbxProperty*) Make( aDfltPropName, SbxCLASS_PROPERTY, SbxVARIANT );
325 : }
326 : }
327 100 : return pDfltProp;
328 : }
329 1213 : void SbxObject::SetDfltProperty( const OUString& rName )
330 : {
331 1213 : if ( rName != aDfltPropName )
332 : {
333 1213 : pDfltProp = NULL;
334 : }
335 1213 : aDfltPropName = rName;
336 1213 : SetModified( sal_True );
337 1213 : }
338 :
339 : // Search of a already available variable. If she was located,
340 : // the index will be set, elsewise will be delivered the Count of the Array.
341 : // In any case it will be delivered the correct Array.
342 :
343 18423 : SbxArray* SbxObject::FindVar( SbxVariable* pVar, sal_uInt16& nArrayIdx )
344 : {
345 18423 : SbxArray* pArray = NULL;
346 18423 : if( pVar ) switch( pVar->GetClass() )
347 : {
348 : case SbxCLASS_VARIABLE:
349 13534 : case SbxCLASS_PROPERTY: pArray = pProps; break;
350 0 : case SbxCLASS_METHOD: pArray = pMethods; break;
351 4889 : case SbxCLASS_OBJECT: pArray = pObjs; break;
352 0 : default: DBG_ASSERT( !this, "Invalid SBX-Class" ); break;
353 : }
354 18423 : if( pArray )
355 : {
356 18423 : nArrayIdx = pArray->Count();
357 : // Is the variable per name available?
358 18423 : pArray->ResetFlag( SBX_EXTSEARCH );
359 18423 : SbxVariable* pOld = pArray->Find( pVar->GetName(), pVar->GetClass() );
360 18423 : if( pOld )
361 : {
362 31801 : for( sal_uInt16 i = 0; i < pArray->Count(); i++ )
363 : {
364 31801 : SbxVariableRef& rRef = pArray->GetRef( i );
365 31801 : if( (SbxVariable*) rRef == pOld )
366 : {
367 15678 : nArrayIdx = i; break;
368 : }
369 : }
370 : }
371 : }
372 18423 : return pArray;
373 : }
374 :
375 : // If a new object will be established, this object will be indexed,
376 : // if an object of this name exists already.
377 :
378 23799 : SbxVariable* SbxObject::Make( const OUString& rName, SbxClassType ct, SbxDataType dt )
379 : {
380 : // Is the object already available?
381 23799 : SbxArray* pArray = NULL;
382 23799 : switch( ct )
383 : {
384 : case SbxCLASS_VARIABLE:
385 18741 : case SbxCLASS_PROPERTY: pArray = pProps; break;
386 5058 : case SbxCLASS_METHOD: pArray = pMethods; break;
387 0 : case SbxCLASS_OBJECT: pArray = pObjs; break;
388 0 : default: DBG_ASSERT( !this, "Invalid SBX-Class" ); break;
389 : }
390 23799 : if( !pArray )
391 : {
392 0 : return NULL;
393 : }
394 : // Collections may contain objects of the same name
395 23799 : if( !( ct == SbxCLASS_OBJECT && ISA(SbxCollection) ) )
396 : {
397 23799 : SbxVariable* pRes = pArray->Find( rName, ct );
398 23799 : if( pRes )
399 : {
400 0 : return pRes;
401 : }
402 : }
403 23799 : SbxVariable* pVar = NULL;
404 23799 : switch( ct )
405 : {
406 : case SbxCLASS_VARIABLE:
407 : case SbxCLASS_PROPERTY:
408 18741 : pVar = new SbxProperty( rName, dt );
409 18741 : break;
410 : case SbxCLASS_METHOD:
411 5058 : pVar = new SbxMethod( rName, dt );
412 5058 : break;
413 : case SbxCLASS_OBJECT:
414 0 : pVar = CreateObject( rName );
415 0 : break;
416 : default:
417 0 : break;
418 : }
419 23799 : pVar->SetParent( this );
420 23799 : pArray->Put( pVar, pArray->Count() );
421 23799 : SetModified( sal_True );
422 : // The object listen always
423 23799 : StartListening( pVar->GetBroadcaster(), sal_True );
424 23799 : Broadcast( SBX_HINT_OBJECTCHANGED );
425 23799 : return pVar;
426 : }
427 :
428 0 : SbxObject* SbxObject::MakeObject( const OUString& rName, const OUString& rClass )
429 : {
430 : // Is the object already available?
431 0 : if( !ISA(SbxCollection) )
432 : {
433 0 : SbxVariable* pRes = pObjs->Find( rName, SbxCLASS_OBJECT );
434 0 : if( pRes )
435 : {
436 0 : return PTR_CAST(SbxObject,pRes);
437 : }
438 : }
439 0 : SbxObject* pVar = CreateObject( rClass );
440 0 : if( pVar )
441 : {
442 0 : pVar->SetName( rName );
443 0 : pVar->SetParent( this );
444 0 : pObjs->Put( pVar, pObjs->Count() );
445 0 : SetModified( sal_True );
446 : // The object listen always
447 0 : StartListening( pVar->GetBroadcaster(), sal_True );
448 0 : Broadcast( SBX_HINT_OBJECTCHANGED );
449 : }
450 0 : return pVar;
451 : }
452 :
453 4727 : void SbxObject::Insert( SbxVariable* pVar )
454 : {
455 : sal_uInt16 nIdx;
456 4727 : SbxArray* pArray = FindVar( pVar, nIdx );
457 4727 : if( pArray )
458 : {
459 : // Into with it. But you should pay attention at the Pointer!
460 4727 : if( nIdx < pArray->Count() )
461 : {
462 : // Then this element exists already
463 : // There are objects of the same name allowed at collections
464 2144 : if( pArray == pObjs && ISA(SbxCollection) )
465 : {
466 0 : nIdx = pArray->Count();
467 : }
468 : else
469 : {
470 2144 : SbxVariable* pOld = pArray->Get( nIdx );
471 : // already inside: overwrite
472 2144 : if( pOld == pVar )
473 : {
474 0 : return;
475 : }
476 2144 : EndListening( pOld->GetBroadcaster(), sal_True );
477 2144 : if( pVar->GetClass() == SbxCLASS_PROPERTY )
478 : {
479 0 : if( pOld == pDfltProp )
480 : {
481 0 : pDfltProp = (SbxProperty*) pVar;
482 : }
483 : }
484 : }
485 : }
486 4727 : StartListening( pVar->GetBroadcaster(), sal_True );
487 4727 : pArray->Put( pVar, nIdx );
488 4727 : if( pVar->GetParent() != this )
489 : {
490 4441 : pVar->SetParent( this );
491 : }
492 4727 : SetModified( sal_True );
493 4727 : Broadcast( SBX_HINT_OBJECTCHANGED );
494 : #ifdef DBG_UTIL
495 : static const char* pCls[] =
496 : { "DontCare","Array","Value","Variable","Method","Property","Object" };
497 : OUString aVarName( pVar->GetName() );
498 : if ( aVarName.isEmpty() && pVar->ISA(SbxObject) )
499 : {
500 : aVarName = PTR_CAST(SbxObject,pVar)->GetClassName();
501 : }
502 : OString aNameStr1(OUStringToOString(aVarName, RTL_TEXTENCODING_ASCII_US));
503 : OString aNameStr2(OUStringToOString(SbxVariable::GetName(), RTL_TEXTENCODING_ASCII_US));
504 : DbgOutf( "SBX: Insert %s %s in %s",
505 : ( pVar->GetClass() >= SbxCLASS_DONTCARE &&
506 : pVar->GetClass() <= SbxCLASS_OBJECT )
507 : ? pCls[ pVar->GetClass()-1 ] : "Unknown class", aNameStr1.getStr(), aNameStr2.getStr() );
508 : #endif
509 : }
510 : }
511 :
512 : // Optimisation, Insertion without checking about
513 : // double entry and without broadcasts, will only be used in SO2/auto.cxx
514 2245 : void SbxObject::QuickInsert( SbxVariable* pVar )
515 : {
516 2245 : SbxArray* pArray = NULL;
517 2245 : if( pVar )
518 : {
519 2245 : switch( pVar->GetClass() )
520 : {
521 : case SbxCLASS_VARIABLE:
522 1254 : case SbxCLASS_PROPERTY: pArray = pProps; break;
523 991 : case SbxCLASS_METHOD: pArray = pMethods; break;
524 0 : case SbxCLASS_OBJECT: pArray = pObjs; break;
525 0 : default: DBG_ASSERT( !this, "Invalid SBX-Class" ); break;
526 : }
527 : }
528 2245 : if( pArray )
529 : {
530 2245 : StartListening( pVar->GetBroadcaster(), sal_True );
531 2245 : pArray->Put( pVar, pArray->Count() );
532 2245 : if( pVar->GetParent() != this )
533 : {
534 2245 : pVar->SetParent( this );
535 : }
536 2245 : SetModified( sal_True );
537 : #ifdef DBG_UTIL
538 : static const char* pCls[] =
539 : { "DontCare","Array","Value","Variable","Method","Property","Object" };
540 : OUString aVarName( pVar->GetName() );
541 : if ( aVarName.isEmpty() && pVar->ISA(SbxObject) )
542 : {
543 : aVarName = PTR_CAST(SbxObject,pVar)->GetClassName();
544 : }
545 : OString aNameStr1(OUStringToOString(aVarName, RTL_TEXTENCODING_ASCII_US));
546 : OString aNameStr2(OUStringToOString(SbxVariable::GetName(), RTL_TEXTENCODING_ASCII_US));
547 : DbgOutf( "SBX: Insert %s %s in %s",
548 : ( pVar->GetClass() >= SbxCLASS_DONTCARE &&
549 : pVar->GetClass() <= SbxCLASS_OBJECT )
550 : ? pCls[ pVar->GetClass()-1 ] : "Unknown class", aNameStr1.getStr(), aNameStr2.getStr() );
551 : #endif
552 : }
553 2245 : }
554 :
555 13534 : void SbxObject::Remove( const OUString& rName, SbxClassType t )
556 : {
557 13534 : Remove( SbxObject::Find( rName, t ) );
558 13534 : }
559 :
560 13696 : void SbxObject::Remove( SbxVariable* pVar )
561 : {
562 : sal_uInt16 nIdx;
563 13696 : SbxArray* pArray = FindVar( pVar, nIdx );
564 13696 : if( pArray && nIdx < pArray->Count() )
565 : {
566 : #ifdef DBG_UTIL
567 : OUString aVarName( pVar->GetName() );
568 : if ( aVarName.isEmpty() && pVar->ISA(SbxObject) )
569 : {
570 : aVarName = PTR_CAST(SbxObject,pVar)->GetClassName();
571 : }
572 : OString aNameStr1(OUStringToOString(aVarName, RTL_TEXTENCODING_ASCII_US));
573 : OString aNameStr2(OUStringToOString(SbxVariable::GetName(), RTL_TEXTENCODING_ASCII_US));
574 : DbgOutf( "SBX: Remove %s in %s",
575 : aNameStr1.getStr(), aNameStr2.getStr() );
576 : #endif
577 13534 : SbxVariableRef pVar_ = pArray->Get( nIdx );
578 13534 : if( pVar_->IsBroadcaster() )
579 : {
580 13534 : EndListening( pVar_->GetBroadcaster(), sal_True );
581 : }
582 13534 : if( (SbxVariable*) pVar_ == pDfltProp )
583 : {
584 0 : pDfltProp = NULL;
585 : }
586 13534 : pArray->Remove( nIdx );
587 13534 : if( pVar_->GetParent() == this )
588 : {
589 13534 : pVar_->SetParent( NULL );
590 : }
591 13534 : SetModified( sal_True );
592 13534 : Broadcast( SBX_HINT_OBJECTCHANGED );
593 : }
594 13696 : }
595 :
596 0 : static sal_Bool LoadArray( SvStream& rStrm, SbxObject* pThis, SbxArray* pArray )
597 : {
598 0 : SbxArrayRef p = (SbxArray*) SbxBase::Load( rStrm );
599 0 : if( !p.Is() )
600 : {
601 0 : return sal_False;
602 : }
603 0 : for( sal_uInt16 i = 0; i < p->Count(); i++ )
604 : {
605 0 : SbxVariableRef& r = p->GetRef( i );
606 0 : SbxVariable* pVar = r;
607 0 : if( pVar )
608 : {
609 0 : pVar->SetParent( pThis );
610 0 : pThis->StartListening( pVar->GetBroadcaster(), sal_True );
611 : }
612 : }
613 0 : pArray->Merge( p );
614 0 : return sal_True;
615 : }
616 :
617 : // The load of an object is additive!
618 :
619 0 : sal_Bool SbxObject::LoadData( SvStream& rStrm, sal_uInt16 nVer )
620 : {
621 : // Help for the read in of old objects: just TRUE back,
622 : // LoadPrivateData() had to set the default status up
623 0 : if( !nVer )
624 : {
625 0 : return sal_True;
626 : }
627 0 : pDfltProp = NULL;
628 0 : if( !SbxVariable::LoadData( rStrm, nVer ) )
629 : {
630 0 : return sal_False;
631 : }
632 : // If it contains no alien object, insert ourselves
633 0 : if( aData.eType == SbxOBJECT && !aData.pObj )
634 : {
635 0 : aData.pObj = this;
636 : }
637 : sal_uInt32 nSize;
638 0 : OUString aDfltProp;
639 0 : aClassName = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rStrm, RTL_TEXTENCODING_ASCII_US);
640 0 : aDfltProp = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rStrm, RTL_TEXTENCODING_ASCII_US);
641 0 : sal_uIntPtr nPos = rStrm.Tell();
642 0 : rStrm >> nSize;
643 0 : if( !LoadPrivateData( rStrm, nVer ) )
644 : {
645 0 : return sal_False;
646 : }
647 0 : sal_uIntPtr nNewPos = rStrm.Tell();
648 0 : nPos += nSize;
649 : DBG_ASSERT( nPos >= nNewPos, "SBX: Loaded too much data" );
650 0 : if( nPos != nNewPos )
651 : {
652 0 : rStrm.Seek( nPos );
653 : }
654 0 : if( !LoadArray( rStrm, this, pMethods ) ||
655 0 : !LoadArray( rStrm, this, pProps ) ||
656 0 : !LoadArray( rStrm, this, pObjs ) )
657 : {
658 0 : return sal_False;
659 : }
660 : // Set properties
661 0 : if( !aDfltProp.isEmpty() )
662 : {
663 0 : pDfltProp = (SbxProperty*) pProps->Find( aDfltProp, SbxCLASS_PROPERTY );
664 : }
665 0 : SetModified( sal_False );
666 0 : return sal_True;
667 : }
668 :
669 0 : sal_Bool SbxObject::StoreData( SvStream& rStrm ) const
670 : {
671 0 : if( !SbxVariable::StoreData( rStrm ) )
672 : {
673 0 : return sal_False;
674 : }
675 0 : OUString aDfltProp;
676 0 : if( pDfltProp )
677 : {
678 0 : aDfltProp = pDfltProp->GetName();
679 : }
680 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rStrm, aClassName, RTL_TEXTENCODING_ASCII_US);
681 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rStrm, aDfltProp, RTL_TEXTENCODING_ASCII_US);
682 0 : sal_uIntPtr nPos = rStrm.Tell();
683 0 : rStrm << (sal_uInt32) 0L;
684 0 : if( !StorePrivateData( rStrm ) )
685 : {
686 0 : return sal_False;
687 : }
688 0 : sal_uIntPtr nNew = rStrm.Tell();
689 0 : rStrm.Seek( nPos );
690 0 : rStrm << (sal_uInt32) ( nNew - nPos );
691 0 : rStrm.Seek( nNew );
692 0 : if( !pMethods->Store( rStrm ) )
693 : {
694 0 : return sal_False;
695 : }
696 0 : if( !pProps->Store( rStrm ) )
697 : {
698 0 : return sal_False;
699 : }
700 0 : if( !pObjs->Store( rStrm ) )
701 : {
702 0 : return sal_False;
703 : }
704 0 : ((SbxObject*) this)->SetModified( sal_False );
705 0 : return sal_True;
706 : }
707 :
708 0 : OUString SbxObject::GenerateSource( const OUString &rLinePrefix,
709 : const SbxObject* )
710 : {
711 : // Collect the properties in a String
712 0 : OUString aSource;
713 0 : SbxArrayRef xProps( GetProperties() );
714 0 : bool bLineFeed = false;
715 0 : for ( sal_uInt16 nProp = 0; nProp < xProps->Count(); ++nProp )
716 : {
717 0 : SbxPropertyRef xProp = (SbxProperty*) xProps->Get(nProp);
718 0 : OUString aPropName( xProp->GetName() );
719 0 : if ( xProp->CanWrite() &&
720 0 : !( xProp->GetHashCode() == nNameHash &&
721 0 : aPropName.equalsIgnoreAsciiCase(pNameProp)))
722 : {
723 : // Insert a break except in front of the first property
724 0 : if ( bLineFeed )
725 : {
726 0 : aSource += "\n";
727 : }
728 : else
729 : {
730 0 : bLineFeed = true;
731 : }
732 0 : aSource += rLinePrefix;
733 0 : aSource += ".";
734 0 : aSource += aPropName;
735 0 : aSource += " = ";
736 :
737 : // Display the property value textual
738 0 : switch ( xProp->GetType() )
739 : {
740 : case SbxEMPTY:
741 : case SbxNULL:
742 : // no value
743 0 : break;
744 :
745 : case SbxSTRING:
746 : // Strings in quotation mark
747 0 : aSource += "\"";
748 0 : aSource += xProp->GetOUString();
749 0 : aSource += "\"";
750 0 : break;
751 :
752 : default:
753 : // miscellaneous, such as e.g.numerary directly
754 0 : aSource += xProp->GetOUString();
755 0 : break;
756 : }
757 : }
758 0 : }
759 0 : return aSource;
760 : }
761 :
762 0 : static sal_Bool CollectAttrs( const SbxBase* p, OUString& rRes )
763 : {
764 0 : OUString aAttrs;
765 0 : if( p->IsHidden() )
766 : {
767 0 : aAttrs = "Hidden";
768 : }
769 0 : if( p->IsSet( SBX_EXTSEARCH ) )
770 : {
771 0 : if( !aAttrs.isEmpty() )
772 : {
773 0 : aAttrs += ",";
774 : }
775 0 : aAttrs += "ExtSearch";
776 : }
777 0 : if( !p->IsVisible() )
778 : {
779 0 : if( !aAttrs.isEmpty() )
780 : {
781 0 : aAttrs += ",";
782 : }
783 0 : aAttrs += "Invisible";
784 : }
785 0 : if( p->IsSet( SBX_DONTSTORE ) )
786 : {
787 0 : if( !aAttrs.isEmpty() )
788 : {
789 0 : aAttrs += ",";
790 : }
791 0 : aAttrs += "DontStore";
792 : }
793 0 : if( !aAttrs.isEmpty() )
794 : {
795 0 : rRes = " (";
796 0 : rRes += aAttrs;
797 0 : rRes += ")";
798 0 : return sal_True;
799 : }
800 : else
801 : {
802 0 : rRes = "";
803 0 : return sal_False;
804 0 : }
805 : }
806 :
807 0 : void SbxObject::Dump( SvStream& rStrm, sal_Bool bFill )
808 : {
809 : // Shifting
810 : static sal_uInt16 nLevel = 0;
811 0 : if ( nLevel > 10 )
812 : {
813 0 : rStrm << "<too deep>" << endl;
814 0 : return;
815 : }
816 0 : ++nLevel;
817 0 : OUString aIndent("");
818 0 : for ( sal_uInt16 n = 1; n < nLevel; ++n )
819 : {
820 0 : aIndent += " ";
821 : }
822 : // if necessary complete the object
823 0 : if ( bFill )
824 : {
825 0 : GetAll( SbxCLASS_DONTCARE );
826 : }
827 : // Output the data of the object itself
828 0 : OString aNameStr(OUStringToOString(GetName(), RTL_TEXTENCODING_ASCII_US));
829 0 : OString aClassNameStr(OUStringToOString(aClassName, RTL_TEXTENCODING_ASCII_US));
830 0 : rStrm << "Object( "
831 0 : << OString::valueOf(reinterpret_cast<sal_Int64>(this)).getStr()<< "=='"
832 0 : << ( aNameStr.isEmpty() ? "<unnamed>" : aNameStr.getStr() ) << "', "
833 0 : << "of class '" << aClassNameStr.getStr() << "', "
834 0 : << "counts "
835 0 : << OString::number(GetRefCount()).getStr()
836 0 : << " refs, ";
837 0 : if ( GetParent() )
838 : {
839 0 : OString aParentNameStr(OUStringToOString(GetName(), RTL_TEXTENCODING_ASCII_US));
840 0 : rStrm << "in parent "
841 0 : << OString::valueOf(reinterpret_cast<sal_Int64>(GetParent())).getStr()
842 0 : << "=='" << ( aParentNameStr.isEmpty() ? "<unnamed>" : aParentNameStr.getStr() ) << "'";
843 : }
844 : else
845 : {
846 0 : rStrm << "no parent ";
847 : }
848 0 : rStrm << " )" << endl;
849 0 : OString aIndentNameStr(OUStringToOString(aIndent, RTL_TEXTENCODING_ASCII_US));
850 0 : rStrm << aIndentNameStr.getStr() << "{" << endl;
851 :
852 : // Flags
853 0 : OUString aAttrs;
854 0 : if( CollectAttrs( this, aAttrs ) )
855 : {
856 0 : OString aAttrStr(OUStringToOString(aAttrs, RTL_TEXTENCODING_ASCII_US));
857 0 : rStrm << aIndentNameStr.getStr() << "- Flags: " << aAttrStr.getStr() << endl;
858 : }
859 :
860 : // Methods
861 0 : rStrm << aIndentNameStr.getStr() << "- Methods:" << endl;
862 0 : for( sal_uInt16 i = 0; i < pMethods->Count(); i++ )
863 : {
864 0 : SbxVariableRef& r = pMethods->GetRef( i );
865 0 : SbxVariable* pVar = r;
866 0 : if( pVar )
867 : {
868 0 : OUString aLine( aIndent );
869 0 : aLine += " - ";
870 0 : aLine += pVar->GetName( SbxNAME_SHORT_TYPES );
871 0 : OUString aAttrs2;
872 0 : if( CollectAttrs( pVar, aAttrs2 ) )
873 : {
874 0 : aLine += aAttrs2;
875 : }
876 0 : if( !pVar->IsA( TYPE(SbxMethod) ) )
877 : {
878 0 : aLine += " !! Not a Method !!";
879 : }
880 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rStrm, aLine, RTL_TEXTENCODING_ASCII_US);
881 :
882 : // Output also the object at object-methods
883 0 : if ( pVar->GetValues_Impl().eType == SbxOBJECT &&
884 0 : pVar->GetValues_Impl().pObj &&
885 0 : pVar->GetValues_Impl().pObj != this &&
886 0 : pVar->GetValues_Impl().pObj != GetParent() )
887 : {
888 0 : rStrm << " contains ";
889 0 : ((SbxObject*) pVar->GetValues_Impl().pObj)->Dump( rStrm, bFill );
890 : }
891 : else
892 : {
893 0 : rStrm << endl;
894 0 : }
895 : }
896 : }
897 :
898 : // Properties
899 0 : rStrm << aIndentNameStr.getStr() << "- Properties:" << endl;
900 : {
901 0 : for( sal_uInt16 i = 0; i < pProps->Count(); i++ )
902 : {
903 0 : SbxVariableRef& r = pProps->GetRef( i );
904 0 : SbxVariable* pVar = r;
905 0 : if( pVar )
906 : {
907 0 : OUString aLine( aIndent );
908 0 : aLine += " - ";
909 0 : aLine += pVar->GetName( SbxNAME_SHORT_TYPES );
910 0 : OUString aAttrs3;
911 0 : if( CollectAttrs( pVar, aAttrs3 ) )
912 : {
913 0 : aLine += aAttrs3;
914 : }
915 0 : if( !pVar->IsA( TYPE(SbxProperty) ) )
916 : {
917 0 : aLine += " !! Not a Property !!";
918 : }
919 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rStrm, aLine, RTL_TEXTENCODING_ASCII_US);
920 :
921 : // output also the object at object properties
922 0 : if ( pVar->GetValues_Impl().eType == SbxOBJECT &&
923 0 : pVar->GetValues_Impl().pObj &&
924 0 : pVar->GetValues_Impl().pObj != this &&
925 0 : pVar->GetValues_Impl().pObj != GetParent() )
926 : {
927 0 : rStrm << " contains ";
928 0 : ((SbxObject*) pVar->GetValues_Impl().pObj)->Dump( rStrm, bFill );
929 : }
930 : else
931 : {
932 0 : rStrm << endl;
933 0 : }
934 : }
935 : }
936 : }
937 :
938 : // Objects
939 0 : rStrm << aIndentNameStr.getStr() << "- Objects:" << endl;
940 : {
941 0 : for( sal_uInt16 i = 0; i < pObjs->Count(); i++ )
942 : {
943 0 : SbxVariableRef& r = pObjs->GetRef( i );
944 0 : SbxVariable* pVar = r;
945 0 : if ( pVar )
946 : {
947 0 : rStrm << aIndentNameStr.getStr() << " - Sub";
948 0 : if ( pVar->ISA(SbxObject) )
949 : {
950 0 : ((SbxObject*) pVar)->Dump( rStrm, bFill );
951 : }
952 0 : else if ( pVar->ISA(SbxVariable) )
953 : {
954 0 : ((SbxVariable*) pVar)->Dump( rStrm, bFill );
955 : }
956 : }
957 : }
958 : }
959 :
960 0 : rStrm << aIndentNameStr.getStr() << "}" << endl << endl;
961 0 : --nLevel;
962 : }
963 :
964 6477 : SbxMethod::SbxMethod( const OUString& r, SbxDataType t )
965 6477 : : SbxVariable( t )
966 : {
967 6477 : SetName( r );
968 6477 : }
969 :
970 5401 : SbxMethod::SbxMethod( const SbxMethod& r )
971 5401 : : SvRefBase( r ), SbxVariable( r )
972 : {
973 5401 : }
974 :
975 20404 : SbxMethod::~SbxMethod()
976 : {
977 20404 : }
978 :
979 7801 : SbxClassType SbxMethod::GetClass() const
980 : {
981 7801 : return SbxCLASS_METHOD;
982 : }
983 :
984 20107 : SbxProperty::SbxProperty( const OUString& r, SbxDataType t )
985 20107 : : SbxVariable( t )
986 : {
987 20107 : SetName( r );
988 20107 : }
989 :
990 50300 : SbxProperty::~SbxProperty()
991 : {
992 50300 : }
993 :
994 63024 : SbxClassType SbxProperty::GetClass() const
995 : {
996 63024 : return SbxCLASS_PROPERTY;
997 429 : }
998 :
999 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|