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
|
/* -*- 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 <tools/shl.hxx>
#include <tools/stream.hxx>
#include <basic/sbx.hxx>
#include <basic/sbxfac.hxx>
#include <basic/sbxbase.hxx>
#include <rtl/instance.hxx>
#include <rtl/ustring.hxx>
#include <boost/foreach.hpp>
// AppData-Structure for SBX:
TYPEINIT0(SbxBase)
namespace
{
class theSbxAppData : public rtl::Static<SbxAppData, theSbxAppData> {};
}
SbxAppData& GetSbxData_Impl()
{
return theSbxAppData::get();
}
SbxAppData::~SbxAppData()
{
delete pBasicFormater;
}
//////////////////////////////// SbxBase /////////////////////////////////
DBG_NAME(SbxBase);
SbxBase::SbxBase()
{
DBG_CTOR( SbxBase, 0 );
nFlags = SBX_READWRITE;
}
SbxBase::SbxBase( const SbxBase& r )
: SvRefBase( r )
{
DBG_CTOR( SbxBase, 0 );
nFlags = r.nFlags;
}
SbxBase::~SbxBase()
{
DBG_DTOR(SbxBase,0);
}
SbxBase& SbxBase::operator=( const SbxBase& r )
{
DBG_CHKTHIS( SbxBase, 0 );
nFlags = r.nFlags;
return *this;
}
SbxDataType SbxBase::GetType() const
{
DBG_CHKTHIS( SbxBase, 0 );
return SbxEMPTY;
}
SbxClassType SbxBase::GetClass() const
{
DBG_CHKTHIS( SbxBase, 0 );
return SbxCLASS_DONTCARE;
}
void SbxBase::Clear()
{
DBG_CHKTHIS( SbxBase, 0 );
}
sal_Bool SbxBase::IsFixed() const
{
DBG_CHKTHIS( SbxBase, 0 );
return IsSet( SBX_FIXED );
}
void SbxBase::SetModified( sal_Bool b )
{
DBG_CHKTHIS( SbxBase, 0 );
if( IsSet( SBX_NO_MODIFY ) )
return;
if( b )
SetFlag( SBX_MODIFIED );
else
ResetFlag( SBX_MODIFIED );
}
SbxError SbxBase::GetError()
{
return GetSbxData_Impl().eSbxError;
}
void SbxBase::SetError( SbxError e )
{
SbxAppData& r = GetSbxData_Impl();
if( e && r.eSbxError == SbxERR_OK )
r.eSbxError = e;
}
sal_Bool SbxBase::IsError()
{
return sal_Bool( GetSbxData_Impl().eSbxError != SbxERR_OK );
}
void SbxBase::ResetError()
{
GetSbxData_Impl().eSbxError = SbxERR_OK;
}
void SbxBase::AddFactory( SbxFactory* pFac )
{
SbxAppData& r = GetSbxData_Impl();
// From 1996-03-06: take the HandleLast-Flag into account
sal_uInt16 nPos = r.aFacs.size(); // Insert position
if( !pFac->IsHandleLast() ) // Only if not self HandleLast
{
// Rank new factory in front of factories with HandleLast
while( nPos > 0 &&
r.aFacs[ nPos-1 ].IsHandleLast() )
nPos--;
}
r.aFacs.insert( r.aFacs.begin() + nPos, pFac );
}
void SbxBase::RemoveFactory( SbxFactory* pFac )
{
SbxAppData& r = GetSbxData_Impl();
for(SbxFacs::iterator it = r.aFacs.begin(); it != r.aFacs.end(); ++it)
{
if( &(*it) == pFac )
{
r.aFacs.release( it ).release(); break;
}
}
}
SbxBase* SbxBase::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
{
// #91626: Hack to skip old Basic dialogs
// Problem: There does not exist a factory any more,
// so we have to create a dummy SbxVariable instead
if( nSbxId == 0x65 ) // Dialog Id
return new SbxVariable;
OUString aEmptyStr;
if( nCreator == SBXCR_SBX )
switch( nSbxId )
{
case SBXID_VALUE: return new SbxValue;
case SBXID_VARIABLE: return new SbxVariable;
case SBXID_ARRAY: return new SbxArray;
case SBXID_DIMARRAY: return new SbxDimArray;
case SBXID_OBJECT: return new SbxObject( aEmptyStr );
case SBXID_COLLECTION: return new SbxCollection( aEmptyStr );
case SBXID_FIXCOLLECTION:
return new SbxStdCollection( aEmptyStr, aEmptyStr );
case SBXID_METHOD: return new SbxMethod( aEmptyStr, SbxEMPTY );
case SBXID_PROPERTY: return new SbxProperty( aEmptyStr, SbxEMPTY );
}
// Unknown type: go over the factories!
SbxAppData& r = GetSbxData_Impl();
SbxBase* pNew = NULL;
BOOST_FOREACH(SbxFactory& rFac, r.aFacs)
{
pNew = rFac.Create( nSbxId, nCreator );
if( pNew )
break;
}
SAL_WARN_IF(!pNew, "basic", "No factory for SBX ID " << nSbxId);
return pNew;
}
SbxObject* SbxBase::CreateObject( const OUString& rClass )
{
SbxAppData& r = GetSbxData_Impl();
SbxObject* pNew = NULL;
BOOST_FOREACH(SbxFactory& rFac, r.aFacs)
{
pNew = rFac.CreateObject( rClass );
if( pNew )
break;
}
SAL_WARN_IF(!pNew, "basic", "No factory for object class " << rClass);
return pNew;
}
SbxBase* SbxBase::Load( SvStream& rStrm )
{
sal_uInt16 nSbxId, nFlags, nVer;
sal_uInt32 nCreator, nSize;
rStrm >> nCreator >> nSbxId >> nFlags >> nVer;
// Correcting a foolishness of mine:
if( nFlags & SBX_RESERVED )
nFlags = ( nFlags & ~SBX_RESERVED ) | SBX_GBLSEARCH;
sal_uIntPtr nOldPos = rStrm.Tell();
rStrm >> nSize;
SbxBase* p = Create( nSbxId, nCreator );
if( p )
{
p->nFlags = nFlags;
if( p->LoadData( rStrm, nVer ) )
{
sal_uIntPtr nNewPos = rStrm.Tell();
nOldPos += nSize;
DBG_ASSERT( nOldPos >= nNewPos, "SBX: Too much data loaded" );
if( nOldPos != nNewPos )
rStrm.Seek( nOldPos );
if( !p->LoadCompleted() )
{
// Deleting of the object
SbxBaseRef aRef( p );
p = NULL;
}
}
else
{
rStrm.SetError( SVSTREAM_FILEFORMAT_ERROR );
// Deleting of the object
SbxBaseRef aRef( p );
p = NULL;
}
}
else
rStrm.SetError( SVSTREAM_FILEFORMAT_ERROR );
return p;
}
// Skip the Sbx-Object inside the stream
void SbxBase::Skip( SvStream& rStrm )
{
sal_uInt16 nSbxId, nFlags, nVer;
sal_uInt32 nCreator, nSize;
rStrm >> nCreator >> nSbxId >> nFlags >> nVer;
sal_uIntPtr nStartPos = rStrm.Tell();
rStrm >> nSize;
rStrm.Seek( nStartPos + nSize );
}
sal_Bool SbxBase::Store( SvStream& rStrm )
{
DBG_CHKTHIS( SbxBase, 0 );
if( !( nFlags & SBX_DONTSTORE ) )
{
rStrm << (sal_uInt32) GetCreator()
<< (sal_uInt16) GetSbxId()
<< (sal_uInt16) GetFlags()
<< (sal_uInt16) GetVersion();
sal_uIntPtr nOldPos = rStrm.Tell();
rStrm << (sal_uInt32) 0L;
sal_Bool bRes = StoreData( rStrm );
sal_uIntPtr nNewPos = rStrm.Tell();
rStrm.Seek( nOldPos );
rStrm << (sal_uInt32) ( nNewPos - nOldPos );
rStrm.Seek( nNewPos );
if( rStrm.GetError() != SVSTREAM_OK )
bRes = sal_False;
if( bRes )
bRes = StoreCompleted();
return bRes;
}
else
return sal_True;
}
sal_Bool SbxBase::LoadData( SvStream&, sal_uInt16 )
{
DBG_CHKTHIS( SbxBase, 0 );
return sal_False;
}
sal_Bool SbxBase::StoreData( SvStream& ) const
{
DBG_CHKTHIS( SbxBase, 0 );
return sal_False;
}
sal_Bool SbxBase::LoadPrivateData( SvStream&, sal_uInt16 )
{
DBG_CHKTHIS( SbxBase, 0 );
return sal_True;
}
sal_Bool SbxBase::StorePrivateData( SvStream& ) const
{
DBG_CHKTHIS( SbxBase, 0 );
return sal_True;
}
sal_Bool SbxBase::LoadCompleted()
{
DBG_CHKTHIS( SbxBase, 0 );
return sal_True;
}
sal_Bool SbxBase::StoreCompleted()
{
DBG_CHKTHIS( SbxBase, 0 );
return sal_True;
}
//////////////////////////////// SbxFactory ////////////////////////////////
SbxFactory::~SbxFactory()
{
}
SbxBase* SbxFactory::Create( sal_uInt16, sal_uInt32 )
{
return NULL;
}
SbxObject* SbxFactory::CreateObject( const OUString& )
{
return NULL;
}
///////////////////////////////// SbxInfo //////////////////////////////////
SbxInfo::~SbxInfo()
{}
void SbxInfo::AddParam(const OUString& rName, SbxDataType eType, sal_uInt16 nFlags)
{
aParams.push_back(new SbxParamInfo(rName, eType, nFlags));
}
const SbxParamInfo* SbxInfo::GetParam( sal_uInt16 n ) const
{
if( n < 1 || n > aParams.size() )
return NULL;
else
return &(aParams[n - 1]);
}
sal_Bool SbxInfo::LoadData( SvStream& rStrm, sal_uInt16 nVer )
{
aParams.clear();
sal_uInt16 nParam;
aComment = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rStrm,
RTL_TEXTENCODING_ASCII_US);
aHelpFile = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rStrm,
RTL_TEXTENCODING_ASCII_US);
rStrm >> nHelpId >> nParam;
while( nParam-- )
{
sal_uInt16 nType, nFlags;
sal_uInt32 nUserData = 0;
OUString aName = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rStrm,
RTL_TEXTENCODING_ASCII_US);
rStrm >> nType >> nFlags;
if( nVer > 1 )
rStrm >> nUserData;
AddParam( aName, (SbxDataType) nType, nFlags );
SbxParamInfo& p(aParams.back());
p.nUserData = nUserData;
}
return sal_True;
}
sal_Bool SbxInfo::StoreData( SvStream& rStrm ) const
{
write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rStrm, aComment,
RTL_TEXTENCODING_ASCII_US );
write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rStrm, aHelpFile,
RTL_TEXTENCODING_ASCII_US);
rStrm << nHelpId << static_cast<sal_uInt16>(aParams.size());
for(SbxParams::const_iterator i = aParams.begin(); i != aParams.end(); ++i)
{
write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rStrm, i->aName,
RTL_TEXTENCODING_ASCII_US);
rStrm << (sal_uInt16) i->eType
<< (sal_uInt16) i->nFlags
<< (sal_uInt32) i->nUserData;
}
return sal_True;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|