1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <sal/log.hxx>
#include <iomanip>
#include <tools/debug.hxx>
#include <tools/stream.hxx>
#include <basic/sbx.hxx>
#include <basic/sberrors.hxx>
#include <basic/sbxmeth.hxx>
#include <sbxprop.hxx>
#include <svl/SfxBroadcaster.hxx>
#include "sbxres.hxx"
static OUString pNameProp; // Name-Property
static OUString pParentProp; // Parent-Property
static sal_uInt16 nNameHash = 0, nParentHash = 0;
SbxObject::SbxObject( const OUString& rClass )
: SbxVariable( SbxOBJECT ), aClassName( rClass )
{
aData.pObj = this;
if( !nNameHash )
{
pNameProp = GetSbxRes( StringId::NameProp );
pParentProp = GetSbxRes( StringId::ParentProp );
nNameHash = MakeHashCode( pNameProp );
nParentHash = MakeHashCode( pParentProp );
}
SbxObject::Clear();
SbxObject::SetName( rClass );
}
SbxObject::SbxObject( const SbxObject& rObj )
: SvRefBase( rObj ), SbxVariable( rObj.GetType() ),
SfxListener( rObj )
{
*this = rObj;
}
SbxObject& SbxObject::operator=( const SbxObject& r )
{
if( &r != this )
{
SbxVariable::operator=( r );
aClassName = r.aClassName;
pMethods = new SbxArray;
pProps = new SbxArray;
pObjs = new SbxArray( SbxOBJECT );
// The arrays were copied, the content taken over
*pMethods = *r.pMethods;
*pProps = *r.pProps;
*pObjs = *r.pObjs;
// Because the variables were taken over, this is OK
pDfltProp = r.pDfltProp;
SetName( r.GetName() );
SetFlags( r.GetFlags() );
SetModified( true );
}
return *this;
}
static void CheckParentsOnDelete( SbxObject* pObj, SbxArray* p )
{
for( sal_uInt32 i = 0; i < p->Count32(); i++ )
{
SbxVariableRef& rRef = p->GetRef32( i );
if( rRef->IsBroadcaster() )
{
pObj->EndListening( rRef->GetBroadcaster(), true );
}
// does the element have more than one reference and still a Listener?
if( rRef->GetRefCount() > 1 )
{
rRef->SetParent( nullptr );
SAL_INFO_IF(rRef->IsBroadcaster() && rRef->GetBroadcaster().GetListenerCount(), "basic.sbx", "Object element with dangling parent");
}
}
}
SbxObject::~SbxObject()
{
CheckParentsOnDelete( this, pProps.get() );
CheckParentsOnDelete( this, pMethods.get() );
CheckParentsOnDelete( this, pObjs.get() );
// avoid handling in ~SbxVariable as SbxFlagBits::DimAsNew == SbxFlagBits::GlobalSearch
ResetFlag( SbxFlagBits::DimAsNew );
}
SbxDataType SbxObject::GetType() const
{
return SbxOBJECT;
}
SbxClassType SbxObject::GetClass() const
{
return SbxClassType::Object;
}
void SbxObject::Clear()
{
pMethods = new SbxArray;
pProps = new SbxArray;
pObjs = new SbxArray( SbxOBJECT );
SbxVariable* p;
p = Make( pNameProp, SbxClassType::Property, SbxSTRING );
p->SetFlag( SbxFlagBits::DontStore );
p = Make( pParentProp, SbxClassType::Property, SbxOBJECT );
p->ResetFlag( SbxFlagBits::Write );
p->SetFlag( SbxFlagBits::DontStore );
pDfltProp = nullptr;
SetModified( false );
}
void SbxObject::Notify( SfxBroadcaster&, const SfxHint& rHint )
{
const SbxHint* p = dynamic_cast<const SbxHint*>(&rHint);
if( !p )
return;
const SfxHintId nId = p->GetId();
bool bRead = ( nId == SfxHintId::BasicDataWanted );
bool bWrite = ( nId == SfxHintId::BasicDataChanged );
SbxVariable* pVar = p->GetVar();
if( !(bRead || bWrite) )
return;
OUString aVarName( pVar->GetName() );
sal_uInt16 nHash_ = MakeHashCode( aVarName );
if( nHash_ == nNameHash && aVarName.equalsIgnoreAsciiCase( pNameProp ) )
{
if( bRead )
{
pVar->PutString( GetName() );
}
else
{
SetName( pVar->GetOUString() );
}
}
else if( nHash_ == nParentHash && aVarName.equalsIgnoreAsciiCase( pParentProp ) )
{
SbxObject* p_ = GetParent();
if( !p_ )
{
p_ = this;
}
pVar->PutObject( p_ );
}
}
bool SbxObject::IsClass( const OUString& rName ) const
{
return aClassName.equalsIgnoreAsciiCase( rName );
}
SbxVariable* SbxObject::Find( const OUString& rName, SbxClassType t )
{
#ifdef DBG_UTIL
static int nLvl = 1;
static const char* pCls[] = { "DontCare","Array","Value","Variable","Method","Property","Object" };
SAL_INFO(
"basic.sbx",
"search" << std::setw(nLvl) << " "
<< (t >= SbxClassType::DontCare && t <= SbxClassType::Object
? pCls[static_cast<int>(t) - 1] : "Unknown class")
<< " " << rName << " in " << SbxVariable::GetName());
++nLvl;
#endif
SbxVariable* pRes = nullptr;
pObjs->SetFlag( SbxFlagBits::ExtSearch );
if( t == SbxClassType::DontCare )
{
pRes = pMethods->Find( rName, SbxClassType::Method );
if( !pRes )
{
pRes = pProps->Find( rName, SbxClassType::Property );
}
if( !pRes )
{
pRes = pObjs->Find( rName, t );
}
}
else
{
SbxArray* pArray = nullptr;
switch( t )
{
case SbxClassType::Variable:
case SbxClassType::Property: pArray = pProps.get(); break;
case SbxClassType::Method: pArray = pMethods.get(); break;
case SbxClassType::Object: pArray = pObjs.get(); break;
default: SAL_WARN( "basic.sbx", "Invalid SBX-Class" ); break;
}
if( pArray )
{
pRes = pArray->Find( rName, t );
}
}
// Extended Search in the Object-Array?
// For objects and DontCare the array of objects has already been searched
if( !pRes && ( t == SbxClassType::Method || t == SbxClassType::Property ) )
pRes = pObjs->Find( rName, t );
// Search in the parents?
if( !pRes && IsSet( SbxFlagBits::GlobalSearch ) )
{
SbxObject* pCur = this;
while( !pRes && pCur->pParent )
{
// I myself was already searched!
SbxFlagBits nOwn = pCur->GetFlags();
pCur->ResetFlag( SbxFlagBits::ExtSearch );
// I search already global!
SbxFlagBits nPar = pCur->pParent->GetFlags();
pCur->pParent->ResetFlag( SbxFlagBits::GlobalSearch );
pRes = pCur->pParent->Find( rName, t );
pCur->SetFlags( nOwn );
pCur->pParent->SetFlags( nPar );
pCur = pCur->pParent;
}
}
#ifdef DBG_UTIL
--nLvl;
SAL_INFO_IF(
pRes, "basic.sbx",
"found" << std::setw(nLvl) << " " << rName << " in "
<< SbxVariable::GetName());
#endif
return pRes;
}
// Abbreviated version: The parent-string will be searched
// The whole thing recursive, because Call() might be overridden
// Qualified names are allowed
bool SbxObject::Call( const OUString& rName, SbxArray* pParam )
{
SbxVariable* pMeth = FindQualified( rName, SbxClassType::DontCare);
if( dynamic_cast<const SbxMethod*>( pMeth) )
{
// FindQualified() might have struck already!
if( pParam )
{
pMeth->SetParameters( pParam );
}
pMeth->Broadcast( SfxHintId::BasicDataWanted );
pMeth->SetParameters( nullptr );
return true;
}
SetError( ERRCODE_BASIC_NO_METHOD );
return false;
}
SbxProperty* SbxObject::GetDfltProperty()
{
if ( !pDfltProp && !aDfltPropName.isEmpty() )
{
pDfltProp = static_cast<SbxProperty*>( Find( aDfltPropName, SbxClassType::Property ) );
if( !pDfltProp )
{
pDfltProp = static_cast<SbxProperty*>( Make( aDfltPropName, SbxClassType::Property, SbxVARIANT ) );
}
}
return pDfltProp;
}
void SbxObject::SetDfltProperty( const OUString& rName )
{
if ( rName != aDfltPropName )
{
pDfltProp = nullptr;
}
aDfltPropName = rName;
SetModified( true );
}
// Search of an already available variable. If it was located,
// the index will be set, otherwise the Count of the Array will be returned.
// In any case the correct Array will be returned.
SbxArray* SbxObject::FindVar( SbxVariable const * pVar, sal_uInt32& nArrayIdx )
{
SbxArray* pArray = nullptr;
if( pVar )
{
switch( pVar->GetClass() )
{
case SbxClassType::Variable:
case SbxClassType::Property: pArray = pProps.get(); break;
case SbxClassType::Method: pArray = pMethods.get(); break;
case SbxClassType::Object: pArray = pObjs.get(); break;
default: SAL_WARN( "basic.sbx", "Invalid SBX-Class" ); break;
}
}
if( pArray )
{
nArrayIdx = pArray->Count32();
// Is the variable per name available?
pArray->ResetFlag( SbxFlagBits::ExtSearch );
SbxVariable* pOld = pArray->Find( pVar->GetName(), pVar->GetClass() );
if( pOld )
{
for( sal_uInt32 i = 0; i < pArray->Count32(); i++ )
{
SbxVariableRef& rRef = pArray->GetRef32( i );
if( rRef.get() == pOld )
{
nArrayIdx = i; break;
}
}
}
}
return pArray;
}
// If a new object will be established, this object will be indexed,
// if an object of this name exists already.
SbxVariable* SbxObject::Make( const OUString& rName, SbxClassType ct, SbxDataType dt, bool bIsRuntimeFunction )
{
// Is the object already available?
SbxArray* pArray = nullptr;
switch( ct )
{
case SbxClassType::Variable:
case SbxClassType::Property: pArray = pProps.get(); break;
case SbxClassType::Method: pArray = pMethods.get(); break;
case SbxClassType::Object: pArray = pObjs.get(); break;
default: SAL_WARN( "basic.sbx", "Invalid SBX-Class" ); break;
}
if( !pArray )
{
return nullptr;
}
// Collections may contain objects of the same name
if( !( ct == SbxClassType::Object && dynamic_cast<const SbxCollection*>( this ) != nullptr ) )
{
SbxVariable* pRes = pArray->Find( rName, ct );
if( pRes )
{
return pRes;
}
}
SbxVariable* pVar = nullptr;
switch( ct )
{
case SbxClassType::Variable:
case SbxClassType::Property:
pVar = new SbxProperty( rName, dt );
break;
case SbxClassType::Method:
pVar = new SbxMethod( rName, dt, bIsRuntimeFunction );
break;
case SbxClassType::Object:
pVar = CreateObject( rName );
break;
default:
break;
}
pVar->SetParent( this );
pArray->Put32( pVar, pArray->Count32() );
SetModified( true );
// The object listen always
StartListening(pVar->GetBroadcaster(), DuplicateHandling::Prevent);
return pVar;
}
void SbxObject::Insert( SbxVariable* pVar )
{
sal_uInt32 nIdx;
SbxArray* pArray = FindVar( pVar, nIdx );
if( !pArray )
return;
// Into with it. But you should pay attention at the Pointer!
if( nIdx < pArray->Count32() )
{
// Then this element exists already
// There are objects of the same name allowed at collections
if( pArray == pObjs.get() && dynamic_cast<const SbxCollection*>( this ) != nullptr )
{
nIdx = pArray->Count32();
}
else
{
SbxVariable* pOld = pArray->Get32( nIdx );
// already inside: overwrite
if( pOld == pVar )
{
return;
}
EndListening( pOld->GetBroadcaster(), true );
if( pVar->GetClass() == SbxClassType::Property )
{
if( pOld == pDfltProp )
{
pDfltProp = static_cast<SbxProperty*>(pVar);
}
}
}
}
StartListening(pVar->GetBroadcaster(), DuplicateHandling::Prevent);
pArray->Put32( pVar, nIdx );
if( pVar->GetParent() != this )
{
pVar->SetParent( this );
}
SetModified( true );
#ifdef DBG_UTIL
static const char* pCls[] =
{ "DontCare","Array","Value","Variable","Method","Property","Object" };
OUString aVarName( pVar->GetName() );
if (const SbxObject *pSbxObj = aVarName.isEmpty() ? dynamic_cast<const SbxObject*>(pVar) : nullptr)
{
aVarName = pSbxObj->GetClassName();
}
SAL_INFO(
"basic.sbx",
"insert "
<< ((pVar->GetClass() >= SbxClassType::DontCare
&& pVar->GetClass() <= SbxClassType::Object)
? pCls[static_cast<int>(pVar->GetClass()) - 1] : "Unknown class")
<< " " << aVarName << " in " << SbxVariable::GetName());
#endif
}
// Optimisation, Insertion without checking about
// double entry and without broadcasts, will only be used in SO2/auto.cxx
void SbxObject::QuickInsert( SbxVariable* pVar )
{
SbxArray* pArray = nullptr;
if( pVar )
{
switch( pVar->GetClass() )
{
case SbxClassType::Variable:
case SbxClassType::Property: pArray = pProps.get(); break;
case SbxClassType::Method: pArray = pMethods.get(); break;
case SbxClassType::Object: pArray = pObjs.get(); break;
default: SAL_WARN( "basic.sbx", "Invalid SBX-Class" ); break;
}
}
if( !pArray )
return;
StartListening(pVar->GetBroadcaster(), DuplicateHandling::Prevent);
pArray->Put32( pVar, pArray->Count32() );
if( pVar->GetParent() != this )
{
pVar->SetParent( this );
}
SetModified( true );
#ifdef DBG_UTIL
static const char* pCls[] =
{ "DontCare","Array","Value","Variable","Method","Property","Object" };
OUString aVarName( pVar->GetName() );
if (const SbxObject *pSbxObj = aVarName.isEmpty() ? dynamic_cast<const SbxObject*>(pVar) : nullptr)
{
aVarName = pSbxObj->GetClassName();
}
SAL_INFO(
"basic.sbx",
"insert "
<< ((pVar->GetClass() >= SbxClassType::DontCare
&& pVar->GetClass() <= SbxClassType::Object)
? pCls[static_cast<int>(pVar->GetClass()) - 1] : "Unknown class")
<< " " << aVarName << " in " << SbxVariable::GetName());
#endif
}
void SbxObject::Remove( const OUString& rName, SbxClassType t )
{
Remove( SbxObject::Find( rName, t ) );
}
void SbxObject::Remove( SbxVariable* pVar )
{
sal_uInt32 nIdx;
SbxArray* pArray = FindVar( pVar, nIdx );
if( !(pArray && nIdx < pArray->Count32()) )
return;
#ifdef DBG_UTIL
OUString aVarName( pVar->GetName() );
if (const SbxObject *pSbxObj = aVarName.isEmpty() ? dynamic_cast<const SbxObject*>(pVar) : nullptr)
{
aVarName = pSbxObj->GetClassName();
}
SAL_INFO(
"basic.sbx",
"remove " << aVarName << " in " << SbxVariable::GetName());
#endif
SbxVariableRef pVar_ = pArray->Get32( nIdx );
if( pVar_->IsBroadcaster() )
{
EndListening( pVar_->GetBroadcaster(), true );
}
if( pVar_.get() == pDfltProp )
{
pDfltProp = nullptr;
}
pArray->Remove( nIdx );
if( pVar_->GetParent() == this )
{
pVar_->SetParent( nullptr );
}
SetModified( true );
}
static bool LoadArray( SvStream& rStrm, SbxObject* pThis, SbxArray* pArray )
{
SbxArrayRef p = static_cast<SbxArray*>( SbxBase::Load( rStrm ) );
if( !p.is() )
{
return false;
}
for( sal_uInt32 i = 0; i < p->Count32(); i++ )
{
SbxVariableRef& r = p->GetRef32( i );
SbxVariable* pVar = r.get();
if( pVar )
{
pVar->SetParent( pThis );
pThis->StartListening(pVar->GetBroadcaster(), DuplicateHandling::Prevent);
}
}
pArray->Merge( p.get() );
return true;
}
// The load of an object is additive!
bool SbxObject::LoadData( SvStream& rStrm, sal_uInt16 nVer )
{
// Help for the read in of old objects: just return TRUE,
// LoadPrivateData() has to set the default status up
if( !nVer )
{
return true;
}
pDfltProp = nullptr;
if( !SbxVariable::LoadData( rStrm, nVer ) )
{
return false;
}
// If it contains no alien object, insert ourselves
if( aData.eType == SbxOBJECT && !aData.pObj )
{
aData.pObj = this;
}
sal_uInt32 nSize;
OUString aDfltProp;
aClassName = read_uInt16_lenPrefixed_uInt8s_ToOUString(rStrm, RTL_TEXTENCODING_ASCII_US);
aDfltProp = read_uInt16_lenPrefixed_uInt8s_ToOUString(rStrm, RTL_TEXTENCODING_ASCII_US);
sal_uInt64 nPos = rStrm.Tell();
rStrm.ReadUInt32( nSize );
sal_uInt64 const nNewPos = rStrm.Tell();
nPos += nSize;
DBG_ASSERT( nPos >= nNewPos, "SBX: Loaded too much data" );
if( nPos != nNewPos )
{
rStrm.Seek( nPos );
}
if( !LoadArray( rStrm, this, pMethods.get() ) ||
!LoadArray( rStrm, this, pProps.get() ) ||
!LoadArray( rStrm, this, pObjs.get() ) )
{
return false;
}
// Set properties
if( !aDfltProp.isEmpty() )
{
pDfltProp = static_cast<SbxProperty*>( pProps->Find( aDfltProp, SbxClassType::Property ) );
}
SetModified( false );
return true;
}
bool SbxObject::StoreData( SvStream& rStrm ) const
{
if( !SbxVariable::StoreData( rStrm ) )
{
return false;
}
OUString aDfltProp;
if( pDfltProp )
{
aDfltProp = pDfltProp->GetName();
}
write_uInt16_lenPrefixed_uInt8s_FromOUString(rStrm, aClassName, RTL_TEXTENCODING_ASCII_US);
write_uInt16_lenPrefixed_uInt8s_FromOUString(rStrm, aDfltProp, RTL_TEXTENCODING_ASCII_US);
sal_uInt64 const nPos = rStrm.Tell();
rStrm.WriteUInt32( 0 );
sal_uInt64 const nNew = rStrm.Tell();
rStrm.Seek( nPos );
rStrm.WriteUInt32( nNew - nPos );
rStrm.Seek( nNew );
if( !pMethods->Store( rStrm ) )
{
return false;
}
if( !pProps->Store( rStrm ) )
{
return false;
}
if( !pObjs->Store( rStrm ) )
{
return false;
}
const_cast<SbxObject*>(this)->SetModified( false );
return true;
}
static bool CollectAttrs( const SbxBase* p, OUString& rRes )
{
OUString aAttrs;
if( p->IsHidden() )
{
aAttrs = "Hidden";
}
if( p->IsSet( SbxFlagBits::ExtSearch ) )
{
if( !aAttrs.isEmpty() )
{
aAttrs += ",";
}
aAttrs += "ExtSearch";
}
if( !p->IsVisible() )
{
if( !aAttrs.isEmpty() )
{
aAttrs += ",";
}
aAttrs += "Invisible";
}
if( p->IsSet( SbxFlagBits::DontStore ) )
{
if( !aAttrs.isEmpty() )
{
aAttrs += ",";
}
aAttrs += "DontStore";
}
if( !aAttrs.isEmpty() )
{
rRes = " (" + aAttrs + ")";
return true;
}
else
{
rRes.clear();
return false;
}
}
void SbxObject::Dump( SvStream& rStrm, bool bFill )
{
// Shifting
static sal_uInt16 nLevel = 0;
if ( nLevel > 10 )
{
rStrm.WriteCharPtr( "<too deep>" ) << endl;
return;
}
++nLevel;
OUString aIndent("");
for ( sal_uInt16 n = 1; n < nLevel; ++n )
{
aIndent += " ";
}
// Output the data of the object itself
OString aNameStr(OUStringToOString(GetName(), RTL_TEXTENCODING_ASCII_US));
OString aClassNameStr(OUStringToOString(aClassName, RTL_TEXTENCODING_ASCII_US));
rStrm.WriteCharPtr( "Object( " )
.WriteOString( OString::number(reinterpret_cast<sal_Int64>(this)) ).WriteCharPtr( "=='" )
.WriteCharPtr( aNameStr.isEmpty() ? "<unnamed>" : aNameStr.getStr() ).WriteCharPtr( "', " )
.WriteCharPtr( "of class '" ).WriteOString( aClassNameStr ).WriteCharPtr( "', " )
.WriteCharPtr( "counts " )
.WriteOString( OString::number(GetRefCount()) )
.WriteCharPtr( " refs, " );
if ( GetParent() )
{
OString aParentNameStr(OUStringToOString(GetName(), RTL_TEXTENCODING_ASCII_US));
rStrm.WriteCharPtr( "in parent " )
.WriteOString( OString::number(reinterpret_cast<sal_Int64>(GetParent())) )
.WriteCharPtr( "=='" ).WriteCharPtr( aParentNameStr.isEmpty() ? "<unnamed>" : aParentNameStr.getStr() ).WriteCharPtr( "'" );
}
else
{
rStrm.WriteCharPtr( "no parent " );
}
rStrm.WriteCharPtr( " )" ) << endl;
OString aIndentNameStr(OUStringToOString(aIndent, RTL_TEXTENCODING_ASCII_US));
rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "{" ) << endl;
// Flags
OUString aAttrs;
if( CollectAttrs( this, aAttrs ) )
{
OString aAttrStr(OUStringToOString(aAttrs, RTL_TEXTENCODING_ASCII_US));
rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "- Flags: " ).WriteOString( aAttrStr ) << endl;
}
// Methods
rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "- Methods:" ) << endl;
for( sal_uInt32 i = 0; i < pMethods->Count32(); i++ )
{
SbxVariableRef& r = pMethods->GetRef32( i );
SbxVariable* pVar = r.get();
if( pVar )
{
OUString aLine = aIndent + " - " + pVar->GetName( SbxNameType::ShortTypes );
OUString aAttrs2;
if( CollectAttrs( pVar, aAttrs2 ) )
{
aLine += aAttrs2;
}
if( dynamic_cast<const SbxMethod *>(pVar) == nullptr )
{
aLine += " !! Not a Method !!";
}
write_uInt16_lenPrefixed_uInt8s_FromOUString(rStrm, aLine, RTL_TEXTENCODING_ASCII_US);
// Output also the object at object-methods
if ( pVar->GetValues_Impl().eType == SbxOBJECT &&
pVar->GetValues_Impl().pObj &&
pVar->GetValues_Impl().pObj != this &&
pVar->GetValues_Impl().pObj != GetParent() )
{
rStrm.WriteCharPtr( " contains " );
static_cast<SbxObject*>(pVar->GetValues_Impl().pObj)->Dump( rStrm, bFill );
}
else
{
rStrm << endl;
}
}
}
// Properties
rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "- Properties:" ) << endl;
{
for( sal_uInt32 i = 0; i < pProps->Count32(); i++ )
{
SbxVariableRef& r = pProps->GetRef32( i );
SbxVariable* pVar = r.get();
if( pVar )
{
OUString aLine = aIndent + " - " + pVar->GetName( SbxNameType::ShortTypes );
OUString aAttrs3;
if( CollectAttrs( pVar, aAttrs3 ) )
{
aLine += aAttrs3;
}
if( dynamic_cast<const SbxProperty *>(pVar) == nullptr )
{
aLine += " !! Not a Property !!";
}
write_uInt16_lenPrefixed_uInt8s_FromOUString(rStrm, aLine, RTL_TEXTENCODING_ASCII_US);
// output also the object at object properties
if ( pVar->GetValues_Impl().eType == SbxOBJECT &&
pVar->GetValues_Impl().pObj &&
pVar->GetValues_Impl().pObj != this &&
pVar->GetValues_Impl().pObj != GetParent() )
{
rStrm.WriteCharPtr( " contains " );
static_cast<SbxObject*>(pVar->GetValues_Impl().pObj)->Dump( rStrm, bFill );
}
else
{
rStrm << endl;
}
}
}
}
// Objects
rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "- Objects:" ) << endl;
{
for( sal_uInt32 i = 0; i < pObjs->Count32(); i++ )
{
SbxVariableRef& r = pObjs->GetRef32( i );
SbxVariable* pVar = r.get();
if ( pVar )
{
rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( " - Sub" );
if (SbxObject *pSbxObj = dynamic_cast<SbxObject*>(pVar))
{
pSbxObj->Dump(rStrm, bFill);
}
else
{
pVar->Dump(rStrm, bFill);
}
}
}
}
rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "}" ) << endl << endl;
--nLevel;
}
SbxMethod::SbxMethod( const OUString& r, SbxDataType t, bool bIsRuntimeFunction )
: SbxVariable(t)
, mbIsRuntimeFunction(bIsRuntimeFunction)
, mbRuntimeFunctionReturnType(t)
{
SetName(r);
}
SbxMethod::SbxMethod( const SbxMethod& r )
: SvRefBase(r)
, SbxVariable(r)
, mbIsRuntimeFunction(r.IsRuntimeFunction())
, mbRuntimeFunctionReturnType(r.GetRuntimeFunctionReturnType())
{
}
SbxMethod::~SbxMethod()
{
}
SbxClassType SbxMethod::GetClass() const
{
return SbxClassType::Method;
}
SbxProperty::SbxProperty( const OUString& r, SbxDataType t )
: SbxVariable( t )
{
SetName( r );
}
SbxProperty::~SbxProperty()
{
}
SbxClassType SbxProperty::GetClass() const
{
return SbxClassType::Property;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|