1*e1f63238SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*e1f63238SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*e1f63238SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*e1f63238SAndrew Rist * distributed with this work for additional information
6*e1f63238SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*e1f63238SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*e1f63238SAndrew Rist * "License"); you may not use this file except in compliance
9*e1f63238SAndrew Rist * with the License. You may obtain a copy of the License at
10*e1f63238SAndrew Rist *
11*e1f63238SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*e1f63238SAndrew Rist *
13*e1f63238SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*e1f63238SAndrew Rist * software distributed under the License is distributed on an
15*e1f63238SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e1f63238SAndrew Rist * KIND, either express or implied. See the License for the
17*e1f63238SAndrew Rist * specific language governing permissions and limitations
18*e1f63238SAndrew Rist * under the License.
19*e1f63238SAndrew Rist *
20*e1f63238SAndrew Rist *************************************************************/
21*e1f63238SAndrew Rist
22*e1f63238SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_basic.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "sb.hxx"
30cdf0e10cSrcweir #include <tools/rcid.h>
31cdf0e10cSrcweir #include <tools/config.hxx>
32cdf0e10cSrcweir #include <tools/stream.hxx>
33cdf0e10cSrcweir #ifndef __RSC //autogen
34cdf0e10cSrcweir #include <tools/errinf.hxx>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include <basic/sbx.hxx>
37cdf0e10cSrcweir #include <tools/list.hxx>
38cdf0e10cSrcweir #include <tools/shl.hxx>
39cdf0e10cSrcweir #include <tools/rc.hxx>
40cdf0e10cSrcweir #include <vcl/svapp.hxx>
41cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
42cdf0e10cSrcweir #include "sbunoobj.hxx"
43cdf0e10cSrcweir #include "sbjsmeth.hxx"
44cdf0e10cSrcweir #include "sbjsmod.hxx"
45cdf0e10cSrcweir #include "sbintern.hxx"
46cdf0e10cSrcweir #include "disas.hxx"
47cdf0e10cSrcweir #include "runtime.hxx"
48cdf0e10cSrcweir #include <basic/sbuno.hxx>
49cdf0e10cSrcweir #include <basic/sbobjmod.hxx>
50cdf0e10cSrcweir #include "stdobj.hxx"
51cdf0e10cSrcweir #include "filefmt.hxx"
52cdf0e10cSrcweir #include "sb.hrc"
53cdf0e10cSrcweir #include <basrid.hxx>
54cdf0e10cSrcweir #include <vos/mutex.hxx>
55cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
56cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
57cdf0e10cSrcweir #include <com/sun/star/util/XCloseBroadcaster.hpp>
58cdf0e10cSrcweir #include <com/sun/star/util/XCloseListener.hpp>
59cdf0e10cSrcweir #include "errobject.hxx"
60cdf0e10cSrcweir #include <map>
61cdf0e10cSrcweir #include <hash_map>
62cdf0e10cSrcweir
63cdf0e10cSrcweir #include <com/sun/star/script/ModuleType.hpp>
64cdf0e10cSrcweir #include <com/sun/star/script/ModuleInfo.hpp>
65cdf0e10cSrcweir using namespace ::com::sun::star::script;
66cdf0e10cSrcweir
67cdf0e10cSrcweir // #pragma SW_SEGMENT_CLASS( SBASIC, SBASIC_CODE )
68cdf0e10cSrcweir
69cdf0e10cSrcweir SV_IMPL_VARARR(SbTextPortions,SbTextPortion)
70cdf0e10cSrcweir
71cdf0e10cSrcweir TYPEINIT1(StarBASIC,SbxObject)
72cdf0e10cSrcweir
73cdf0e10cSrcweir #define RTLNAME "@SBRTL"
74cdf0e10cSrcweir // i#i68894#
75cdf0e10cSrcweir using namespace ::com::sun::star;
76cdf0e10cSrcweir using com::sun::star::uno::Reference;
77cdf0e10cSrcweir using com::sun::star::uno::Any;
78cdf0e10cSrcweir using com::sun::star::uno::UNO_QUERY;
79cdf0e10cSrcweir using com::sun::star::lang::XMultiServiceFactory;
80cdf0e10cSrcweir
81cdf0e10cSrcweir const static String aThisComponent( RTL_CONSTASCII_USTRINGPARAM("ThisComponent") );
82cdf0e10cSrcweir const static String aVBAHook( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobals" ) );
83cdf0e10cSrcweir
84cdf0e10cSrcweir // ============================================================================
85cdf0e10cSrcweir
86cdf0e10cSrcweir class DocBasicItem : public ::cppu::WeakImplHelper1< util::XCloseListener >
87cdf0e10cSrcweir {
88cdf0e10cSrcweir public:
89cdf0e10cSrcweir explicit DocBasicItem( StarBASIC& rDocBasic );
90cdf0e10cSrcweir virtual ~DocBasicItem();
91cdf0e10cSrcweir
getClassModules() const92cdf0e10cSrcweir inline const SbxObjectRef& getClassModules() const { return mxClassModules; }
isDocClosed() const93cdf0e10cSrcweir inline bool isDocClosed() const { return mbDocClosed; }
94cdf0e10cSrcweir
95cdf0e10cSrcweir void clearDependingVarsOnDelete( StarBASIC& rDeletedBasic );
96cdf0e10cSrcweir
97cdf0e10cSrcweir void startListening();
98cdf0e10cSrcweir void stopListening();
99cdf0e10cSrcweir
100cdf0e10cSrcweir virtual void SAL_CALL queryClosing( const lang::EventObject& rSource, sal_Bool bGetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException);
101cdf0e10cSrcweir virtual void SAL_CALL notifyClosing( const lang::EventObject& rSource ) throw (uno::RuntimeException);
102cdf0e10cSrcweir virtual void SAL_CALL disposing( const lang::EventObject& rSource ) throw (uno::RuntimeException);
103cdf0e10cSrcweir
104cdf0e10cSrcweir private:
105cdf0e10cSrcweir StarBASIC& mrDocBasic;
106cdf0e10cSrcweir SbxObjectRef mxClassModules;
107cdf0e10cSrcweir bool mbDocClosed;
108cdf0e10cSrcweir bool mbDisposed;
109cdf0e10cSrcweir };
110cdf0e10cSrcweir
111cdf0e10cSrcweir // ----------------------------------------------------------------------------
112cdf0e10cSrcweir
DocBasicItem(StarBASIC & rDocBasic)113cdf0e10cSrcweir DocBasicItem::DocBasicItem( StarBASIC& rDocBasic ) :
114cdf0e10cSrcweir mrDocBasic( rDocBasic ),
115cdf0e10cSrcweir mxClassModules( new SbxObject( String() ) ),
116cdf0e10cSrcweir mbDocClosed( false ),
117cdf0e10cSrcweir mbDisposed( false )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
~DocBasicItem()121cdf0e10cSrcweir DocBasicItem::~DocBasicItem()
122cdf0e10cSrcweir {
123cdf0e10cSrcweir stopListening();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir
clearDependingVarsOnDelete(StarBASIC & rDeletedBasic)126cdf0e10cSrcweir void DocBasicItem::clearDependingVarsOnDelete( StarBASIC& rDeletedBasic )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir mrDocBasic.implClearDependingVarsOnDelete( &rDeletedBasic );
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
startListening()131cdf0e10cSrcweir void DocBasicItem::startListening()
132cdf0e10cSrcweir {
133cdf0e10cSrcweir Any aThisComp;
134cdf0e10cSrcweir mrDocBasic.GetUNOConstant( "ThisComponent", aThisComp );
135cdf0e10cSrcweir Reference< util::XCloseBroadcaster > xCloseBC( aThisComp, UNO_QUERY );
136cdf0e10cSrcweir mbDisposed = !xCloseBC.is();
137cdf0e10cSrcweir if( xCloseBC.is() )
138cdf0e10cSrcweir try { xCloseBC->addCloseListener( this ); } catch( uno::Exception& ) {}
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
stopListening()141cdf0e10cSrcweir void DocBasicItem::stopListening()
142cdf0e10cSrcweir {
143cdf0e10cSrcweir if( mbDisposed ) return;
144cdf0e10cSrcweir mbDisposed = true;
145cdf0e10cSrcweir Any aThisComp;
146cdf0e10cSrcweir mrDocBasic.GetUNOConstant( "ThisComponent", aThisComp );
147cdf0e10cSrcweir Reference< util::XCloseBroadcaster > xCloseBC( aThisComp, UNO_QUERY );
148cdf0e10cSrcweir if( xCloseBC.is() )
149cdf0e10cSrcweir try { xCloseBC->removeCloseListener( this ); } catch( uno::Exception& ) {}
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
queryClosing(const lang::EventObject &,sal_Bool)152cdf0e10cSrcweir void SAL_CALL DocBasicItem::queryClosing( const lang::EventObject& /*rSource*/, sal_Bool /*bGetsOwnership*/ ) throw (util::CloseVetoException, uno::RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
notifyClosing(const lang::EventObject &)156cdf0e10cSrcweir void SAL_CALL DocBasicItem::notifyClosing( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException)
157cdf0e10cSrcweir {
158cdf0e10cSrcweir stopListening();
159cdf0e10cSrcweir mbDocClosed = true;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
disposing(const lang::EventObject &)162cdf0e10cSrcweir void SAL_CALL DocBasicItem::disposing( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir stopListening();
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir // ----------------------------------------------------------------------------
168cdf0e10cSrcweir
169cdf0e10cSrcweir namespace {
170cdf0e10cSrcweir
171cdf0e10cSrcweir typedef ::rtl::Reference< DocBasicItem > DocBasicItemRef;
172cdf0e10cSrcweir typedef std::map< const StarBASIC*, DocBasicItemRef > DocBasicItemMap;
173cdf0e10cSrcweir static DocBasicItemMap GaDocBasicItems;
174cdf0e10cSrcweir
lclFindDocBasicItem(const StarBASIC * pDocBasic)175cdf0e10cSrcweir const DocBasicItem* lclFindDocBasicItem( const StarBASIC* pDocBasic )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir DocBasicItemMap::iterator it = GaDocBasicItems.find( pDocBasic );
178cdf0e10cSrcweir return (it != GaDocBasicItems.end()) ? it->second.get() : 0;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
lclInsertDocBasicItem(StarBASIC & rDocBasic)181cdf0e10cSrcweir void lclInsertDocBasicItem( StarBASIC& rDocBasic )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir DocBasicItemRef& rxDocBasicItem = GaDocBasicItems[ &rDocBasic ];
184cdf0e10cSrcweir rxDocBasicItem.set( new DocBasicItem( rDocBasic ) );
185cdf0e10cSrcweir rxDocBasicItem->startListening();
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
lclRemoveDocBasicItem(StarBASIC & rDocBasic)188cdf0e10cSrcweir void lclRemoveDocBasicItem( StarBASIC& rDocBasic )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir DocBasicItemMap::iterator it = GaDocBasicItems.find( &rDocBasic );
191cdf0e10cSrcweir if( it != GaDocBasicItems.end() )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir it->second->stopListening();
194cdf0e10cSrcweir GaDocBasicItems.erase( it );
195cdf0e10cSrcweir }
196cdf0e10cSrcweir DocBasicItemMap::iterator it_end = GaDocBasicItems.end();
197cdf0e10cSrcweir for( it = GaDocBasicItems.begin(); it != it_end; ++it )
198cdf0e10cSrcweir it->second->clearDependingVarsOnDelete( rDocBasic );
199cdf0e10cSrcweir }
200cdf0e10cSrcweir
lclGetDocBasicForModule(SbModule * pModule)201cdf0e10cSrcweir StarBASIC* lclGetDocBasicForModule( SbModule* pModule )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir StarBASIC* pRetBasic = NULL;
204cdf0e10cSrcweir SbxObject* pCurParent = pModule;
205cdf0e10cSrcweir while( pCurParent->GetParent() != NULL )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir pCurParent = pCurParent->GetParent();
208cdf0e10cSrcweir StarBASIC* pDocBasic = PTR_CAST( StarBASIC, pCurParent );
209cdf0e10cSrcweir if( pDocBasic != NULL && pDocBasic->IsDocBasic() )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir pRetBasic = pDocBasic;
212cdf0e10cSrcweir break;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir }
215cdf0e10cSrcweir return pRetBasic;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir } // namespace
219cdf0e10cSrcweir
220cdf0e10cSrcweir // ============================================================================
221cdf0e10cSrcweir
getVBAGlobals()222cdf0e10cSrcweir SbxObject* StarBASIC::getVBAGlobals( )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir if ( !pVBAGlobals )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir Any aThisDoc;
227cdf0e10cSrcweir if ( GetUNOConstant("ThisComponent", aThisDoc) )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir Reference< XMultiServiceFactory > xDocFac( aThisDoc, UNO_QUERY );
230cdf0e10cSrcweir if ( xDocFac.is() )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir try
233cdf0e10cSrcweir {
234cdf0e10cSrcweir xDocFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals" ) ) );
235cdf0e10cSrcweir }
236cdf0e10cSrcweir catch( Exception& )
237cdf0e10cSrcweir {
238cdf0e10cSrcweir // Ignore
239cdf0e10cSrcweir }
240cdf0e10cSrcweir }
241cdf0e10cSrcweir }
242cdf0e10cSrcweir pVBAGlobals = (SbUnoObject*)Find( aVBAHook , SbxCLASS_DONTCARE );
243cdf0e10cSrcweir }
244cdf0e10cSrcweir return pVBAGlobals;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
247cdf0e10cSrcweir // i#i68894#
VBAFind(const String & rName,SbxClassType t)248cdf0e10cSrcweir SbxVariable* StarBASIC::VBAFind( const String& rName, SbxClassType t )
249cdf0e10cSrcweir {
250cdf0e10cSrcweir if( rName == aThisComponent )
251cdf0e10cSrcweir return NULL;
252cdf0e10cSrcweir // rename to init globals
253cdf0e10cSrcweir if ( getVBAGlobals( ) )
254cdf0e10cSrcweir return pVBAGlobals->Find( rName, t );
255cdf0e10cSrcweir return NULL;
256cdf0e10cSrcweir
257cdf0e10cSrcweir }
258cdf0e10cSrcweir // Create array for conversion SFX <-> VB error code
259cdf0e10cSrcweir struct SFX_VB_ErrorItem
260cdf0e10cSrcweir {
261cdf0e10cSrcweir sal_uInt16 nErrorVB;
262cdf0e10cSrcweir SbError nErrorSFX;
263cdf0e10cSrcweir };
264cdf0e10cSrcweir
265cdf0e10cSrcweir const SFX_VB_ErrorItem __FAR_DATA SFX_VB_ErrorTab[] =
266cdf0e10cSrcweir {
267cdf0e10cSrcweir { 1, SbERR_BASIC_EXCEPTION }, // #87844 Map exception to error code 1
268cdf0e10cSrcweir { 2, SbERR_SYNTAX },
269cdf0e10cSrcweir { 3, SbERR_NO_GOSUB },
270cdf0e10cSrcweir { 4, SbERR_REDO_FROM_START },
271cdf0e10cSrcweir { 5, SbERR_BAD_ARGUMENT },
272cdf0e10cSrcweir { 6, SbERR_MATH_OVERFLOW },
273cdf0e10cSrcweir { 7, SbERR_NO_MEMORY },
274cdf0e10cSrcweir { 8, SbERR_ALREADY_DIM },
275cdf0e10cSrcweir { 9, SbERR_OUT_OF_RANGE },
276cdf0e10cSrcweir { 10, SbERR_DUPLICATE_DEF },
277cdf0e10cSrcweir { 11, SbERR_ZERODIV },
278cdf0e10cSrcweir { 12, SbERR_VAR_UNDEFINED },
279cdf0e10cSrcweir { 13, SbERR_CONVERSION },
280cdf0e10cSrcweir { 14, SbERR_BAD_PARAMETER },
281cdf0e10cSrcweir { 18, SbERR_USER_ABORT },
282cdf0e10cSrcweir { 20, SbERR_BAD_RESUME },
283cdf0e10cSrcweir { 28, SbERR_STACK_OVERFLOW },
284cdf0e10cSrcweir { 35, SbERR_PROC_UNDEFINED },
285cdf0e10cSrcweir { 48, SbERR_BAD_DLL_LOAD },
286cdf0e10cSrcweir { 49, SbERR_BAD_DLL_CALL },
287cdf0e10cSrcweir { 51, SbERR_INTERNAL_ERROR },
288cdf0e10cSrcweir { 52, SbERR_BAD_CHANNEL },
289cdf0e10cSrcweir { 53, SbERR_FILE_NOT_FOUND },
290cdf0e10cSrcweir { 54, SbERR_BAD_FILE_MODE },
291cdf0e10cSrcweir { 55, SbERR_FILE_ALREADY_OPEN },
292cdf0e10cSrcweir { 57, SbERR_IO_ERROR },
293cdf0e10cSrcweir { 58, SbERR_FILE_EXISTS },
294cdf0e10cSrcweir { 59, SbERR_BAD_RECORD_LENGTH },
295cdf0e10cSrcweir { 61, SbERR_DISK_FULL },
296cdf0e10cSrcweir { 62, SbERR_READ_PAST_EOF },
297cdf0e10cSrcweir { 63, SbERR_BAD_RECORD_NUMBER },
298cdf0e10cSrcweir { 67, SbERR_TOO_MANY_FILES },
299cdf0e10cSrcweir { 68, SbERR_NO_DEVICE },
300cdf0e10cSrcweir { 70, SbERR_ACCESS_DENIED },
301cdf0e10cSrcweir { 71, SbERR_NOT_READY },
302cdf0e10cSrcweir { 73, SbERR_NOT_IMPLEMENTED },
303cdf0e10cSrcweir { 74, SbERR_DIFFERENT_DRIVE },
304cdf0e10cSrcweir { 75, SbERR_ACCESS_ERROR },
305cdf0e10cSrcweir { 76, SbERR_PATH_NOT_FOUND },
306cdf0e10cSrcweir { 91, SbERR_NO_OBJECT },
307cdf0e10cSrcweir { 93, SbERR_BAD_PATTERN },
308cdf0e10cSrcweir { 94, SBERR_IS_NULL },
309cdf0e10cSrcweir { 250, SbERR_DDE_ERROR },
310cdf0e10cSrcweir { 280, SbERR_DDE_WAITINGACK },
311cdf0e10cSrcweir { 281, SbERR_DDE_OUTOFCHANNELS },
312cdf0e10cSrcweir { 282, SbERR_DDE_NO_RESPONSE },
313cdf0e10cSrcweir { 283, SbERR_DDE_MULT_RESPONSES },
314cdf0e10cSrcweir { 284, SbERR_DDE_CHANNEL_LOCKED },
315cdf0e10cSrcweir { 285, SbERR_DDE_NOTPROCESSED },
316cdf0e10cSrcweir { 286, SbERR_DDE_TIMEOUT },
317cdf0e10cSrcweir { 287, SbERR_DDE_USER_INTERRUPT },
318cdf0e10cSrcweir { 288, SbERR_DDE_BUSY },
319cdf0e10cSrcweir { 289, SbERR_DDE_NO_DATA },
320cdf0e10cSrcweir { 290, SbERR_DDE_WRONG_DATA_FORMAT },
321cdf0e10cSrcweir { 291, SbERR_DDE_PARTNER_QUIT },
322cdf0e10cSrcweir { 292, SbERR_DDE_CONV_CLOSED },
323cdf0e10cSrcweir { 293, SbERR_DDE_NO_CHANNEL },
324cdf0e10cSrcweir { 294, SbERR_DDE_INVALID_LINK },
325cdf0e10cSrcweir { 295, SbERR_DDE_QUEUE_OVERFLOW },
326cdf0e10cSrcweir { 296, SbERR_DDE_LINK_ALREADY_EST },
327cdf0e10cSrcweir { 297, SbERR_DDE_LINK_INV_TOPIC },
328cdf0e10cSrcweir { 298, SbERR_DDE_DLL_NOT_FOUND },
329cdf0e10cSrcweir { 323, SbERR_CANNOT_LOAD },
330cdf0e10cSrcweir { 341, SbERR_BAD_INDEX },
331cdf0e10cSrcweir { 366, SbERR_NO_ACTIVE_OBJECT },
332cdf0e10cSrcweir { 380, SbERR_BAD_PROP_VALUE },
333cdf0e10cSrcweir { 382, SbERR_PROP_READONLY },
334cdf0e10cSrcweir { 394, SbERR_PROP_WRITEONLY },
335cdf0e10cSrcweir { 420, SbERR_INVALID_OBJECT },
336cdf0e10cSrcweir { 423, SbERR_NO_METHOD },
337cdf0e10cSrcweir { 424, SbERR_NEEDS_OBJECT },
338cdf0e10cSrcweir { 425, SbERR_INVALID_USAGE_OBJECT },
339cdf0e10cSrcweir { 430, SbERR_NO_OLE },
340cdf0e10cSrcweir { 438, SbERR_BAD_METHOD },
341cdf0e10cSrcweir { 440, SbERR_OLE_ERROR },
342cdf0e10cSrcweir { 445, SbERR_BAD_ACTION },
343cdf0e10cSrcweir { 446, SbERR_NO_NAMED_ARGS },
344cdf0e10cSrcweir { 447, SbERR_BAD_LOCALE },
345cdf0e10cSrcweir { 448, SbERR_NAMED_NOT_FOUND },
346cdf0e10cSrcweir { 449, SbERR_NOT_OPTIONAL },
347cdf0e10cSrcweir { 450, SbERR_WRONG_ARGS },
348cdf0e10cSrcweir { 451, SbERR_NOT_A_COLL },
349cdf0e10cSrcweir { 452, SbERR_BAD_ORDINAL },
350cdf0e10cSrcweir { 453, SbERR_DLLPROC_NOT_FOUND },
351cdf0e10cSrcweir { 460, SbERR_BAD_CLIPBD_FORMAT },
352cdf0e10cSrcweir { 951, SbERR_UNEXPECTED },
353cdf0e10cSrcweir { 952, SbERR_EXPECTED },
354cdf0e10cSrcweir { 953, SbERR_SYMBOL_EXPECTED },
355cdf0e10cSrcweir { 954, SbERR_VAR_EXPECTED },
356cdf0e10cSrcweir { 955, SbERR_LABEL_EXPECTED },
357cdf0e10cSrcweir { 956, SbERR_LVALUE_EXPECTED },
358cdf0e10cSrcweir { 957, SbERR_VAR_DEFINED },
359cdf0e10cSrcweir { 958, SbERR_PROC_DEFINED },
360cdf0e10cSrcweir { 959, SbERR_LABEL_DEFINED },
361cdf0e10cSrcweir { 960, SbERR_UNDEF_VAR },
362cdf0e10cSrcweir { 961, SbERR_UNDEF_ARRAY },
363cdf0e10cSrcweir { 962, SbERR_UNDEF_PROC },
364cdf0e10cSrcweir { 963, SbERR_UNDEF_LABEL },
365cdf0e10cSrcweir { 964, SbERR_UNDEF_TYPE },
366cdf0e10cSrcweir { 965, SbERR_BAD_EXIT },
367cdf0e10cSrcweir { 966, SbERR_BAD_BLOCK },
368cdf0e10cSrcweir { 967, SbERR_BAD_BRACKETS },
369cdf0e10cSrcweir { 968, SbERR_BAD_DECLARATION },
370cdf0e10cSrcweir { 969, SbERR_BAD_PARAMETERS },
371cdf0e10cSrcweir { 970, SbERR_BAD_CHAR_IN_NUMBER },
372cdf0e10cSrcweir { 971, SbERR_MUST_HAVE_DIMS },
373cdf0e10cSrcweir { 972, SbERR_NO_IF },
374cdf0e10cSrcweir { 973, SbERR_NOT_IN_SUBR },
375cdf0e10cSrcweir { 974, SbERR_NOT_IN_MAIN },
376cdf0e10cSrcweir { 975, SbERR_WRONG_DIMS },
377cdf0e10cSrcweir { 976, SbERR_BAD_OPTION },
378cdf0e10cSrcweir { 977, SbERR_CONSTANT_REDECLARED },
379cdf0e10cSrcweir { 978, SbERR_PROG_TOO_LARGE },
380cdf0e10cSrcweir { 979, SbERR_NO_STRINGS_ARRAYS },
381cdf0e10cSrcweir { 1000, SbERR_PROPERTY_NOT_FOUND },
382cdf0e10cSrcweir { 1001, SbERR_METHOD_NOT_FOUND },
383cdf0e10cSrcweir { 1002, SbERR_ARG_MISSING },
384cdf0e10cSrcweir { 1003, SbERR_BAD_NUMBER_OF_ARGS },
385cdf0e10cSrcweir { 1004, SbERR_METHOD_FAILED },
386cdf0e10cSrcweir { 1005, SbERR_SETPROP_FAILED },
387cdf0e10cSrcweir { 1006, SbERR_GETPROP_FAILED },
388cdf0e10cSrcweir { 1007, SbERR_BASIC_COMPAT },
389cdf0e10cSrcweir { 0xFFFF, 0xFFFFFFFFL } // End mark
390cdf0e10cSrcweir };
391cdf0e10cSrcweir
392cdf0e10cSrcweir // The StarBASIC factory is a hack. When a SbModule is created, its pointer
393cdf0e10cSrcweir // is saved and given to the following SbProperties/SbMethods. This restores
394cdf0e10cSrcweir // the Modul-relationshop. But it works only when a modul is loaded.
395cdf0e10cSrcweir // Can cause troubles with separately loaded properties!
396cdf0e10cSrcweir
Create(sal_uInt16 nSbxId,sal_uInt32 nCreator)397cdf0e10cSrcweir SbxBase* SbiFactory::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir if( nCreator == SBXCR_SBX )
400cdf0e10cSrcweir {
401cdf0e10cSrcweir String aEmpty;
402cdf0e10cSrcweir switch( nSbxId )
403cdf0e10cSrcweir {
404cdf0e10cSrcweir case SBXID_BASIC:
405cdf0e10cSrcweir return new StarBASIC( NULL );
406cdf0e10cSrcweir case SBXID_BASICMOD:
407cdf0e10cSrcweir return new SbModule( aEmpty );
408cdf0e10cSrcweir case SBXID_BASICPROP:
409cdf0e10cSrcweir return new SbProperty( aEmpty, SbxVARIANT, NULL );
410cdf0e10cSrcweir case SBXID_BASICMETHOD:
411cdf0e10cSrcweir return new SbMethod( aEmpty, SbxVARIANT, NULL );
412cdf0e10cSrcweir case SBXID_JSCRIPTMOD:
413cdf0e10cSrcweir return new SbJScriptModule( aEmpty );
414cdf0e10cSrcweir case SBXID_JSCRIPTMETH:
415cdf0e10cSrcweir return new SbJScriptMethod( aEmpty, SbxVARIANT, NULL );
416cdf0e10cSrcweir }
417cdf0e10cSrcweir }
418cdf0e10cSrcweir return NULL;
419cdf0e10cSrcweir }
420cdf0e10cSrcweir
CreateObject(const String & rClass)421cdf0e10cSrcweir SbxObject* SbiFactory::CreateObject( const String& rClass )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir if( rClass.EqualsIgnoreCaseAscii( "StarBASIC" ) )
424cdf0e10cSrcweir return new StarBASIC( NULL );
425cdf0e10cSrcweir else
426cdf0e10cSrcweir if( rClass.EqualsIgnoreCaseAscii( "StarBASICModule" ) )
427cdf0e10cSrcweir {
428cdf0e10cSrcweir String aEmpty;
429cdf0e10cSrcweir return new SbModule( aEmpty );
430cdf0e10cSrcweir }
431cdf0e10cSrcweir else
432cdf0e10cSrcweir if( rClass.EqualsIgnoreCaseAscii( "Collection" ) )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir String aCollectionName( RTL_CONSTASCII_USTRINGPARAM("Collection") );
435cdf0e10cSrcweir return new BasicCollection( aCollectionName );
436cdf0e10cSrcweir }
437cdf0e10cSrcweir else
438cdf0e10cSrcweir if( rClass.EqualsIgnoreCaseAscii( "FileSystemObject" ) )
439cdf0e10cSrcweir {
440cdf0e10cSrcweir try
441cdf0e10cSrcweir {
442cdf0e10cSrcweir Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW );
443cdf0e10cSrcweir ::rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.FileSystemObject" ) );
444cdf0e10cSrcweir Reference< XInterface > xInterface( xFactory->createInstance( aServiceName ), UNO_SET_THROW );
445cdf0e10cSrcweir return new SbUnoObject( aServiceName, uno::makeAny( xInterface ) );
446cdf0e10cSrcweir }
447cdf0e10cSrcweir catch( Exception& )
448cdf0e10cSrcweir {}
449cdf0e10cSrcweir }
450cdf0e10cSrcweir
451cdf0e10cSrcweir return NULL;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir
454cdf0e10cSrcweir
455cdf0e10cSrcweir // Factory class to create OLE objects
456cdf0e10cSrcweir class SbOLEFactory : public SbxFactory
457cdf0e10cSrcweir {
458cdf0e10cSrcweir public:
459cdf0e10cSrcweir virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX );
460cdf0e10cSrcweir virtual SbxObject* CreateObject( const String& );
461cdf0e10cSrcweir };
462cdf0e10cSrcweir
Create(sal_uInt16,sal_uInt32)463cdf0e10cSrcweir SbxBase* SbOLEFactory::Create( sal_uInt16, sal_uInt32 )
464cdf0e10cSrcweir {
465cdf0e10cSrcweir // Not supported
466cdf0e10cSrcweir return NULL;
467cdf0e10cSrcweir }
468cdf0e10cSrcweir
469cdf0e10cSrcweir SbUnoObject* createOLEObject_Impl( const String& aType ); // sbunoobj.cxx
470cdf0e10cSrcweir
CreateObject(const String & rClassName)471cdf0e10cSrcweir SbxObject* SbOLEFactory::CreateObject( const String& rClassName )
472cdf0e10cSrcweir {
473cdf0e10cSrcweir SbxObject* pRet = createOLEObject_Impl( rClassName );
474cdf0e10cSrcweir return pRet;
475cdf0e10cSrcweir }
476cdf0e10cSrcweir
477cdf0e10cSrcweir
478cdf0e10cSrcweir //========================================================================
479cdf0e10cSrcweir // SbFormFactory, show user forms by: dim as new <user form name>
480cdf0e10cSrcweir
481cdf0e10cSrcweir class SbFormFactory : public SbxFactory
482cdf0e10cSrcweir {
483cdf0e10cSrcweir public:
484cdf0e10cSrcweir virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX );
485cdf0e10cSrcweir virtual SbxObject* CreateObject( const String& );
486cdf0e10cSrcweir };
487cdf0e10cSrcweir
Create(sal_uInt16,sal_uInt32)488cdf0e10cSrcweir SbxBase* SbFormFactory::Create( sal_uInt16, sal_uInt32 )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir // Not supported
491cdf0e10cSrcweir return NULL;
492cdf0e10cSrcweir }
493cdf0e10cSrcweir
CreateObject(const String & rClassName)494cdf0e10cSrcweir SbxObject* SbFormFactory::CreateObject( const String& rClassName )
495cdf0e10cSrcweir {
496cdf0e10cSrcweir if( SbModule* pMod = pMOD )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir if( SbxVariable* pVar = pMod->Find( rClassName, SbxCLASS_OBJECT ) )
499cdf0e10cSrcweir {
500cdf0e10cSrcweir if( SbUserFormModule* pFormModule = PTR_CAST( SbUserFormModule, pVar->GetObject() ) )
501cdf0e10cSrcweir {
502cdf0e10cSrcweir bool bInitState = pFormModule->getInitState();
503cdf0e10cSrcweir if( bInitState )
504cdf0e10cSrcweir {
505cdf0e10cSrcweir // Not the first instantiate, reset
506cdf0e10cSrcweir bool bTriggerTerminateEvent = false;
507cdf0e10cSrcweir pFormModule->ResetApiObj( bTriggerTerminateEvent );
508cdf0e10cSrcweir pFormModule->setInitState( false );
509cdf0e10cSrcweir }
510cdf0e10cSrcweir else
511cdf0e10cSrcweir {
512cdf0e10cSrcweir pFormModule->Load();
513cdf0e10cSrcweir }
514cdf0e10cSrcweir return pFormModule->CreateInstance();
515cdf0e10cSrcweir }
516cdf0e10cSrcweir }
517cdf0e10cSrcweir }
518cdf0e10cSrcweir return 0;
519cdf0e10cSrcweir }
520cdf0e10cSrcweir
521cdf0e10cSrcweir
522cdf0e10cSrcweir //========================================================================
523cdf0e10cSrcweir // SbTypeFactory
524cdf0e10cSrcweir
cloneTypeObjectImpl(const SbxObject & rTypeObj)525cdf0e10cSrcweir SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj )
526cdf0e10cSrcweir {
527cdf0e10cSrcweir SbxObject* pRet = new SbxObject( rTypeObj );
528cdf0e10cSrcweir pRet->PutObject( pRet );
529cdf0e10cSrcweir
530cdf0e10cSrcweir // Copy the properties, not only the reference to them
531cdf0e10cSrcweir SbxArray* pProps = pRet->GetProperties();
532cdf0e10cSrcweir sal_uInt32 nCount = pProps->Count32();
533cdf0e10cSrcweir for( sal_uInt32 i = 0 ; i < nCount ; i++ )
534cdf0e10cSrcweir {
535cdf0e10cSrcweir SbxVariable* pVar = pProps->Get32( i );
536cdf0e10cSrcweir SbxProperty* pProp = PTR_CAST( SbxProperty, pVar );
537cdf0e10cSrcweir if( pProp )
538cdf0e10cSrcweir {
539cdf0e10cSrcweir SbxProperty* pNewProp = new SbxProperty( *pProp );
540cdf0e10cSrcweir SbxDataType eVarType = pVar->GetType();
541cdf0e10cSrcweir if( eVarType & SbxARRAY )
542cdf0e10cSrcweir {
543cdf0e10cSrcweir SbxBase* pParObj = pVar->GetObject();
544cdf0e10cSrcweir SbxDimArray* pSource = PTR_CAST(SbxDimArray,pParObj);
545cdf0e10cSrcweir SbxDimArray* pDest = new SbxDimArray( pVar->GetType() );
546cdf0e10cSrcweir sal_Int32 lb = 0;
547cdf0e10cSrcweir sal_Int32 ub = 0;
548cdf0e10cSrcweir
549cdf0e10cSrcweir pDest->setHasFixedSize( pSource->hasFixedSize() );
550cdf0e10cSrcweir if ( pSource->GetDims() && pSource->hasFixedSize() )
551cdf0e10cSrcweir {
552cdf0e10cSrcweir for ( sal_Int32 j = 1 ; j <= pSource->GetDims(); ++j )
553cdf0e10cSrcweir {
554cdf0e10cSrcweir pSource->GetDim32( (sal_Int32)j, lb, ub );
555cdf0e10cSrcweir pDest->AddDim32( lb, ub );
556cdf0e10cSrcweir }
557cdf0e10cSrcweir }
558cdf0e10cSrcweir else
559cdf0e10cSrcweir pDest->unoAddDim( 0, -1 ); // variant array
560cdf0e10cSrcweir
561cdf0e10cSrcweir sal_uInt16 nSavFlags = pVar->GetFlags();
562cdf0e10cSrcweir pNewProp->ResetFlag( SBX_FIXED );
563cdf0e10cSrcweir // need to reset the FIXED flag
564cdf0e10cSrcweir // when calling PutObject ( because the type will not match Object )
565cdf0e10cSrcweir pNewProp->PutObject( pDest );
566cdf0e10cSrcweir pNewProp->SetFlags( nSavFlags );
567cdf0e10cSrcweir }
568cdf0e10cSrcweir if( eVarType == SbxOBJECT )
569cdf0e10cSrcweir {
570cdf0e10cSrcweir SbxBase* pObjBase = pVar->GetObject();
571cdf0e10cSrcweir SbxObject* pSrcObj = PTR_CAST(SbxObject,pObjBase);
572cdf0e10cSrcweir SbxObject* pDestObj = NULL;
573cdf0e10cSrcweir if( pSrcObj != NULL )
574cdf0e10cSrcweir pDestObj = cloneTypeObjectImpl( *pSrcObj );
575cdf0e10cSrcweir pNewProp->PutObject( pDestObj );
576cdf0e10cSrcweir }
577cdf0e10cSrcweir pProps->PutDirect( pNewProp, i );
578cdf0e10cSrcweir }
579cdf0e10cSrcweir }
580cdf0e10cSrcweir return pRet;
581cdf0e10cSrcweir }
582cdf0e10cSrcweir
583cdf0e10cSrcweir // Factory class to create user defined objects (type command)
584cdf0e10cSrcweir class SbTypeFactory : public SbxFactory
585cdf0e10cSrcweir {
586cdf0e10cSrcweir public:
587cdf0e10cSrcweir virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX );
588cdf0e10cSrcweir virtual SbxObject* CreateObject( const String& );
589cdf0e10cSrcweir };
590cdf0e10cSrcweir
Create(sal_uInt16,sal_uInt32)591cdf0e10cSrcweir SbxBase* SbTypeFactory::Create( sal_uInt16, sal_uInt32 )
592cdf0e10cSrcweir {
593cdf0e10cSrcweir // Not supported
594cdf0e10cSrcweir return NULL;
595cdf0e10cSrcweir }
596cdf0e10cSrcweir
CreateObject(const String & rClassName)597cdf0e10cSrcweir SbxObject* SbTypeFactory::CreateObject( const String& rClassName )
598cdf0e10cSrcweir {
599cdf0e10cSrcweir SbxObject* pRet = NULL;
600cdf0e10cSrcweir SbModule* pMod = pMOD;
601cdf0e10cSrcweir if( pMod )
602cdf0e10cSrcweir {
603cdf0e10cSrcweir const SbxObject* pObj = pMod->FindType( rClassName );
604cdf0e10cSrcweir if( pObj )
605cdf0e10cSrcweir pRet = cloneTypeObjectImpl( *pObj );
606cdf0e10cSrcweir }
607cdf0e10cSrcweir return pRet;
608cdf0e10cSrcweir }
609cdf0e10cSrcweir
createUserTypeImpl(const String & rClassName)610cdf0e10cSrcweir SbxObject* createUserTypeImpl( const String& rClassName )
611cdf0e10cSrcweir {
612cdf0e10cSrcweir SbxObject* pRetObj = pTYPEFAC->CreateObject( rClassName );
613cdf0e10cSrcweir return pRetObj;
614cdf0e10cSrcweir }
615cdf0e10cSrcweir
616cdf0e10cSrcweir
TYPEINIT1(SbClassModuleObject,SbModule)617cdf0e10cSrcweir TYPEINIT1(SbClassModuleObject,SbModule)
618cdf0e10cSrcweir
619cdf0e10cSrcweir SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
620cdf0e10cSrcweir : SbModule( pClassModule->GetName() )
621cdf0e10cSrcweir , mpClassModule( pClassModule )
622cdf0e10cSrcweir , mbInitializeEventDone( false )
623cdf0e10cSrcweir {
624cdf0e10cSrcweir aOUSource = pClassModule->aOUSource;
625cdf0e10cSrcweir aComment = pClassModule->aComment;
626cdf0e10cSrcweir pImage = pClassModule->pImage;
627cdf0e10cSrcweir pBreaks = pClassModule->pBreaks;
628cdf0e10cSrcweir
629cdf0e10cSrcweir SetClassName( pClassModule->GetName() );
630cdf0e10cSrcweir
631cdf0e10cSrcweir // Allow search only internally
632cdf0e10cSrcweir ResetFlag( SBX_GBLSEARCH );
633cdf0e10cSrcweir
634cdf0e10cSrcweir // Copy the methods from original class module
635cdf0e10cSrcweir SbxArray* pClassMethods = pClassModule->GetMethods();
636cdf0e10cSrcweir sal_uInt32 nMethodCount = pClassMethods->Count32();
637cdf0e10cSrcweir sal_uInt32 i;
638cdf0e10cSrcweir for( i = 0 ; i < nMethodCount ; i++ )
639cdf0e10cSrcweir {
640cdf0e10cSrcweir SbxVariable* pVar = pClassMethods->Get32( i );
641cdf0e10cSrcweir
642cdf0e10cSrcweir // Exclude SbIfaceMapperMethod to copy them in a second step
643cdf0e10cSrcweir SbIfaceMapperMethod* pIfaceMethod = PTR_CAST( SbIfaceMapperMethod, pVar );
644cdf0e10cSrcweir if( !pIfaceMethod )
645cdf0e10cSrcweir {
646cdf0e10cSrcweir SbMethod* pMethod = PTR_CAST(SbMethod, pVar );
647cdf0e10cSrcweir if( pMethod )
648cdf0e10cSrcweir {
649cdf0e10cSrcweir sal_uInt16 nFlags_ = pMethod->GetFlags();
650cdf0e10cSrcweir pMethod->SetFlag( SBX_NO_BROADCAST );
651cdf0e10cSrcweir SbMethod* pNewMethod = new SbMethod( *pMethod );
652cdf0e10cSrcweir pNewMethod->ResetFlag( SBX_NO_BROADCAST );
653cdf0e10cSrcweir pMethod->SetFlags( nFlags_ );
654cdf0e10cSrcweir pNewMethod->pMod = this;
655cdf0e10cSrcweir pNewMethod->SetParent( this );
656cdf0e10cSrcweir pMethods->PutDirect( pNewMethod, i );
657cdf0e10cSrcweir StartListening( pNewMethod->GetBroadcaster(), sal_True );
658cdf0e10cSrcweir }
659cdf0e10cSrcweir }
660cdf0e10cSrcweir }
661cdf0e10cSrcweir
662cdf0e10cSrcweir // Copy SbIfaceMapperMethod in a second step to ensure that
663cdf0e10cSrcweir // the corresponding base methods have already been copied
664cdf0e10cSrcweir for( i = 0 ; i < nMethodCount ; i++ )
665cdf0e10cSrcweir {
666cdf0e10cSrcweir SbxVariable* pVar = pClassMethods->Get32( i );
667cdf0e10cSrcweir
668cdf0e10cSrcweir SbIfaceMapperMethod* pIfaceMethod = PTR_CAST( SbIfaceMapperMethod, pVar );
669cdf0e10cSrcweir if( pIfaceMethod )
670cdf0e10cSrcweir {
671cdf0e10cSrcweir SbMethod* pImplMethod = pIfaceMethod->getImplMethod();
672cdf0e10cSrcweir if( !pImplMethod )
673cdf0e10cSrcweir {
674cdf0e10cSrcweir DBG_ERROR( "No ImplMethod" );
675cdf0e10cSrcweir continue;
676cdf0e10cSrcweir }
677cdf0e10cSrcweir
678cdf0e10cSrcweir // Search for own copy of ImplMethod
679cdf0e10cSrcweir String aImplMethodName = pImplMethod->GetName();
680cdf0e10cSrcweir SbxVariable* p = pMethods->Find( aImplMethodName, SbxCLASS_METHOD );
681cdf0e10cSrcweir SbMethod* pImplMethodCopy = p ? PTR_CAST(SbMethod,p) : NULL;
682cdf0e10cSrcweir if( !pImplMethodCopy )
683cdf0e10cSrcweir {
684cdf0e10cSrcweir DBG_ERROR( "Found no ImplMethod copy" );
685cdf0e10cSrcweir continue;
686cdf0e10cSrcweir }
687cdf0e10cSrcweir SbIfaceMapperMethod* pNewIfaceMethod =
688cdf0e10cSrcweir new SbIfaceMapperMethod( pIfaceMethod->GetName(), pImplMethodCopy );
689cdf0e10cSrcweir pMethods->PutDirect( pNewIfaceMethod, i );
690cdf0e10cSrcweir }
691cdf0e10cSrcweir }
692cdf0e10cSrcweir
693cdf0e10cSrcweir // Copy the properties from original class module
694cdf0e10cSrcweir SbxArray* pClassProps = pClassModule->GetProperties();
695cdf0e10cSrcweir sal_uInt32 nPropertyCount = pClassProps->Count32();
696cdf0e10cSrcweir for( i = 0 ; i < nPropertyCount ; i++ )
697cdf0e10cSrcweir {
698cdf0e10cSrcweir SbxVariable* pVar = pClassProps->Get32( i );
699cdf0e10cSrcweir SbProcedureProperty* pProcedureProp = PTR_CAST( SbProcedureProperty, pVar );
700cdf0e10cSrcweir if( pProcedureProp )
701cdf0e10cSrcweir {
702cdf0e10cSrcweir sal_uInt16 nFlags_ = pProcedureProp->GetFlags();
703cdf0e10cSrcweir pProcedureProp->SetFlag( SBX_NO_BROADCAST );
704cdf0e10cSrcweir SbProcedureProperty* pNewProp = new SbProcedureProperty
705cdf0e10cSrcweir ( pProcedureProp->GetName(), pProcedureProp->GetType() );
706cdf0e10cSrcweir // ( pProcedureProp->GetName(), pProcedureProp->GetType(), this );
707cdf0e10cSrcweir pNewProp->SetFlags( nFlags_ ); // Copy flags
708cdf0e10cSrcweir pNewProp->ResetFlag( SBX_NO_BROADCAST ); // except the Broadcast if it was set
709cdf0e10cSrcweir pProcedureProp->SetFlags( nFlags_ );
710cdf0e10cSrcweir pProps->PutDirect( pNewProp, i );
711cdf0e10cSrcweir StartListening( pNewProp->GetBroadcaster(), sal_True );
712cdf0e10cSrcweir }
713cdf0e10cSrcweir else
714cdf0e10cSrcweir {
715cdf0e10cSrcweir SbxProperty* pProp = PTR_CAST( SbxProperty, pVar );
716cdf0e10cSrcweir if( pProp )
717cdf0e10cSrcweir {
718cdf0e10cSrcweir sal_uInt16 nFlags_ = pProp->GetFlags();
719cdf0e10cSrcweir pProp->SetFlag( SBX_NO_BROADCAST );
720cdf0e10cSrcweir SbxProperty* pNewProp = new SbxProperty( *pProp );
721cdf0e10cSrcweir
722cdf0e10cSrcweir // Special handling for modules instances and collections, they need
723cdf0e10cSrcweir // to be instantiated, otherwise all refer to the same base object
724cdf0e10cSrcweir SbxDataType eVarType = pProp->GetType();
725cdf0e10cSrcweir if( eVarType == SbxOBJECT )
726cdf0e10cSrcweir {
727cdf0e10cSrcweir SbxBase* pObjBase = pProp->GetObject();
728cdf0e10cSrcweir SbxObject* pObj = PTR_CAST(SbxObject,pObjBase);
729cdf0e10cSrcweir if( pObj != NULL )
730cdf0e10cSrcweir {
731cdf0e10cSrcweir String aObjClass = pObj->GetClassName();
732cdf0e10cSrcweir
733cdf0e10cSrcweir SbClassModuleObject* pClassModuleObj = PTR_CAST(SbClassModuleObject,pObjBase);
734cdf0e10cSrcweir if( pClassModuleObj != NULL )
735cdf0e10cSrcweir {
736cdf0e10cSrcweir SbModule* pLclClassModule = pClassModuleObj->getClassModule();
737cdf0e10cSrcweir SbClassModuleObject* pNewObj = new SbClassModuleObject( pLclClassModule );
738cdf0e10cSrcweir pNewObj->SetName( pProp->GetName() );
739cdf0e10cSrcweir pNewObj->SetParent( pLclClassModule->pParent );
740cdf0e10cSrcweir pNewProp->PutObject( pNewObj );
741cdf0e10cSrcweir }
742cdf0e10cSrcweir else if( aObjClass.EqualsIgnoreCaseAscii( "Collection" ) )
743cdf0e10cSrcweir {
744cdf0e10cSrcweir String aCollectionName( RTL_CONSTASCII_USTRINGPARAM("Collection") );
745cdf0e10cSrcweir BasicCollection* pNewCollection = new BasicCollection( aCollectionName );
746cdf0e10cSrcweir pNewCollection->SetName( pProp->GetName() );
747cdf0e10cSrcweir pNewCollection->SetParent( pClassModule->pParent );
748cdf0e10cSrcweir pNewProp->PutObject( pNewCollection );
749cdf0e10cSrcweir }
750cdf0e10cSrcweir }
751cdf0e10cSrcweir }
752cdf0e10cSrcweir
753cdf0e10cSrcweir pNewProp->ResetFlag( SBX_NO_BROADCAST );
754cdf0e10cSrcweir pNewProp->SetParent( this );
755cdf0e10cSrcweir pProps->PutDirect( pNewProp, i );
756cdf0e10cSrcweir pProp->SetFlags( nFlags_ );
757cdf0e10cSrcweir }
758cdf0e10cSrcweir }
759cdf0e10cSrcweir }
760cdf0e10cSrcweir SetModuleType( ModuleType::CLASS );
761cdf0e10cSrcweir mbVBACompat = pClassModule->mbVBACompat;
762cdf0e10cSrcweir }
763cdf0e10cSrcweir
~SbClassModuleObject()764cdf0e10cSrcweir SbClassModuleObject::~SbClassModuleObject()
765cdf0e10cSrcweir {
766cdf0e10cSrcweir // do not trigger termination event when document is already closed
767cdf0e10cSrcweir if( StarBASIC::IsRunning() )
768cdf0e10cSrcweir if( StarBASIC* pDocBasic = lclGetDocBasicForModule( this ) )
769cdf0e10cSrcweir if( const DocBasicItem* pDocBasicItem = lclFindDocBasicItem( pDocBasic ) )
770cdf0e10cSrcweir if( !pDocBasicItem->isDocClosed() )
771cdf0e10cSrcweir triggerTerminateEvent();
772cdf0e10cSrcweir
773cdf0e10cSrcweir // Must be deleted by base class dtor because this data
774cdf0e10cSrcweir // is not owned by the SbClassModuleObject object
775cdf0e10cSrcweir pImage = NULL;
776cdf0e10cSrcweir pBreaks = NULL;
777cdf0e10cSrcweir }
778cdf0e10cSrcweir
SFX_NOTIFY(SfxBroadcaster & rBC,const TypeId & rBCType,const SfxHint & rHint,const TypeId & rHintType)779cdf0e10cSrcweir void SbClassModuleObject::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
780cdf0e10cSrcweir const SfxHint& rHint, const TypeId& rHintType )
781cdf0e10cSrcweir {
782cdf0e10cSrcweir handleProcedureProperties( rBC, rHint );
783cdf0e10cSrcweir }
784cdf0e10cSrcweir
Find(const XubString & rName,SbxClassType t)785cdf0e10cSrcweir SbxVariable* SbClassModuleObject::Find( const XubString& rName, SbxClassType t )
786cdf0e10cSrcweir {
787cdf0e10cSrcweir SbxVariable* pRes = SbxObject::Find( rName, t );
788cdf0e10cSrcweir if( pRes )
789cdf0e10cSrcweir {
790cdf0e10cSrcweir triggerInitializeEvent();
791cdf0e10cSrcweir
792cdf0e10cSrcweir SbIfaceMapperMethod* pIfaceMapperMethod = PTR_CAST(SbIfaceMapperMethod,pRes);
793cdf0e10cSrcweir if( pIfaceMapperMethod )
794cdf0e10cSrcweir {
795cdf0e10cSrcweir pRes = pIfaceMapperMethod->getImplMethod();
796cdf0e10cSrcweir pRes->SetFlag( SBX_EXTFOUND );
797cdf0e10cSrcweir }
798cdf0e10cSrcweir }
799cdf0e10cSrcweir return pRes;
800cdf0e10cSrcweir }
801cdf0e10cSrcweir
triggerInitializeEvent(void)802cdf0e10cSrcweir void SbClassModuleObject::triggerInitializeEvent( void )
803cdf0e10cSrcweir {
804cdf0e10cSrcweir static String aInitMethodName( RTL_CONSTASCII_USTRINGPARAM("Class_Initialize") );
805cdf0e10cSrcweir
806cdf0e10cSrcweir if( mbInitializeEventDone )
807cdf0e10cSrcweir return;
808cdf0e10cSrcweir
809cdf0e10cSrcweir mbInitializeEventDone = true;
810cdf0e10cSrcweir
811cdf0e10cSrcweir // Search method
812cdf0e10cSrcweir SbxVariable* pMeth = SbxObject::Find( aInitMethodName, SbxCLASS_METHOD );
813cdf0e10cSrcweir if( pMeth )
814cdf0e10cSrcweir {
815cdf0e10cSrcweir SbxValues aVals;
816cdf0e10cSrcweir pMeth->Get( aVals );
817cdf0e10cSrcweir }
818cdf0e10cSrcweir }
819cdf0e10cSrcweir
triggerTerminateEvent(void)820cdf0e10cSrcweir void SbClassModuleObject::triggerTerminateEvent( void )
821cdf0e10cSrcweir {
822cdf0e10cSrcweir static String aTermMethodName( RTL_CONSTASCII_USTRINGPARAM("Class_Terminate") );
823cdf0e10cSrcweir
824cdf0e10cSrcweir if( !mbInitializeEventDone || GetSbData()->bRunInit )
825cdf0e10cSrcweir return;
826cdf0e10cSrcweir
827cdf0e10cSrcweir // Search method
828cdf0e10cSrcweir SbxVariable* pMeth = SbxObject::Find( aTermMethodName, SbxCLASS_METHOD );
829cdf0e10cSrcweir if( pMeth )
830cdf0e10cSrcweir {
831cdf0e10cSrcweir SbxValues aVals;
832cdf0e10cSrcweir pMeth->Get( aVals );
833cdf0e10cSrcweir }
834cdf0e10cSrcweir }
835cdf0e10cSrcweir
836cdf0e10cSrcweir
SbClassData(void)837cdf0e10cSrcweir SbClassData::SbClassData( void )
838cdf0e10cSrcweir {
839cdf0e10cSrcweir mxIfaces = new SbxArray();
840cdf0e10cSrcweir }
841cdf0e10cSrcweir
clear(void)842cdf0e10cSrcweir void SbClassData::clear( void )
843cdf0e10cSrcweir {
844cdf0e10cSrcweir mxIfaces->Clear();
845cdf0e10cSrcweir maRequiredTypes.clear();
846cdf0e10cSrcweir }
847cdf0e10cSrcweir
SbClassFactory(void)848cdf0e10cSrcweir SbClassFactory::SbClassFactory( void )
849cdf0e10cSrcweir {
850cdf0e10cSrcweir String aDummyName;
851cdf0e10cSrcweir xClassModules = new SbxObject( aDummyName );
852cdf0e10cSrcweir }
853cdf0e10cSrcweir
~SbClassFactory()854cdf0e10cSrcweir SbClassFactory::~SbClassFactory()
855cdf0e10cSrcweir {}
856cdf0e10cSrcweir
AddClassModule(SbModule * pClassModule)857cdf0e10cSrcweir void SbClassFactory::AddClassModule( SbModule* pClassModule )
858cdf0e10cSrcweir {
859cdf0e10cSrcweir SbxObjectRef xToUseClassModules = xClassModules;
860cdf0e10cSrcweir
861cdf0e10cSrcweir if( StarBASIC* pDocBasic = lclGetDocBasicForModule( pClassModule ) )
862cdf0e10cSrcweir if( const DocBasicItem* pDocBasicItem = lclFindDocBasicItem( pDocBasic ) )
863cdf0e10cSrcweir xToUseClassModules = pDocBasicItem->getClassModules();
864cdf0e10cSrcweir
865cdf0e10cSrcweir SbxObject* pParent = pClassModule->GetParent();
866cdf0e10cSrcweir xToUseClassModules->Insert( pClassModule );
867cdf0e10cSrcweir pClassModule->SetParent( pParent );
868cdf0e10cSrcweir }
869cdf0e10cSrcweir
RemoveClassModule(SbModule * pClassModule)870cdf0e10cSrcweir void SbClassFactory::RemoveClassModule( SbModule* pClassModule )
871cdf0e10cSrcweir {
872cdf0e10cSrcweir xClassModules->Remove( pClassModule );
873cdf0e10cSrcweir }
874cdf0e10cSrcweir
Create(sal_uInt16,sal_uInt32)875cdf0e10cSrcweir SbxBase* SbClassFactory::Create( sal_uInt16, sal_uInt32 )
876cdf0e10cSrcweir {
877cdf0e10cSrcweir // Not supported
878cdf0e10cSrcweir return NULL;
879cdf0e10cSrcweir }
880cdf0e10cSrcweir
CreateObject(const String & rClassName)881cdf0e10cSrcweir SbxObject* SbClassFactory::CreateObject( const String& rClassName )
882cdf0e10cSrcweir {
883cdf0e10cSrcweir SbxObjectRef xToUseClassModules = xClassModules;
884cdf0e10cSrcweir
885cdf0e10cSrcweir if( SbModule* pMod = pMOD )
886cdf0e10cSrcweir if( StarBASIC* pDocBasic = lclGetDocBasicForModule( pMod ) )
887cdf0e10cSrcweir if( const DocBasicItem* pDocBasicItem = lclFindDocBasicItem( pDocBasic ) )
888cdf0e10cSrcweir xToUseClassModules = pDocBasicItem->getClassModules();
889cdf0e10cSrcweir
890cdf0e10cSrcweir SbxVariable* pVar = xToUseClassModules->Find( rClassName, SbxCLASS_OBJECT );
891cdf0e10cSrcweir SbxObject* pRet = NULL;
892cdf0e10cSrcweir if( pVar )
893cdf0e10cSrcweir {
894cdf0e10cSrcweir SbModule* pVarMod = (SbModule*)pVar;
895cdf0e10cSrcweir pRet = new SbClassModuleObject( pVarMod );
896cdf0e10cSrcweir }
897cdf0e10cSrcweir return pRet;
898cdf0e10cSrcweir }
899cdf0e10cSrcweir
FindClass(const String & rClassName)900cdf0e10cSrcweir SbModule* SbClassFactory::FindClass( const String& rClassName )
901cdf0e10cSrcweir {
902cdf0e10cSrcweir SbxVariable* pVar = xClassModules->Find( rClassName, SbxCLASS_DONTCARE );
903cdf0e10cSrcweir SbModule* pMod = pVar ? (SbModule*)pVar : NULL;
904cdf0e10cSrcweir return pMod;
905cdf0e10cSrcweir }
906cdf0e10cSrcweir
StarBASIC(StarBASIC * p,sal_Bool bIsDocBasic)907cdf0e10cSrcweir StarBASIC::StarBASIC( StarBASIC* p, sal_Bool bIsDocBasic )
908cdf0e10cSrcweir : SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASIC") ) ), bDocBasic( bIsDocBasic )
909cdf0e10cSrcweir {
910cdf0e10cSrcweir SetParent( p );
911cdf0e10cSrcweir pLibInfo = NULL;
912cdf0e10cSrcweir bNoRtl = bBreak = sal_False;
913cdf0e10cSrcweir bVBAEnabled = sal_False;
914cdf0e10cSrcweir pModules = new SbxArray;
915cdf0e10cSrcweir
916cdf0e10cSrcweir if( !GetSbData()->nInst++ )
917cdf0e10cSrcweir {
918cdf0e10cSrcweir pSBFAC = new SbiFactory;
919cdf0e10cSrcweir AddFactory( pSBFAC );
920cdf0e10cSrcweir pTYPEFAC = new SbTypeFactory;
921cdf0e10cSrcweir AddFactory( pTYPEFAC );
922cdf0e10cSrcweir pCLASSFAC = new SbClassFactory;
923cdf0e10cSrcweir AddFactory( pCLASSFAC );
924cdf0e10cSrcweir pOLEFAC = new SbOLEFactory;
925cdf0e10cSrcweir AddFactory( pOLEFAC );
926cdf0e10cSrcweir pFORMFAC = new SbFormFactory;
927cdf0e10cSrcweir AddFactory( pFORMFAC );
928cdf0e10cSrcweir pUNOFAC = new SbUnoFactory;
929cdf0e10cSrcweir AddFactory( pUNOFAC );
930cdf0e10cSrcweir }
931cdf0e10cSrcweir pRtl = new SbiStdObject( String( RTL_CONSTASCII_USTRINGPARAM(RTLNAME) ), this );
932cdf0e10cSrcweir // Search via StarBasic is always global
933cdf0e10cSrcweir SetFlag( SBX_GBLSEARCH );
934cdf0e10cSrcweir pVBAGlobals = NULL;
935cdf0e10cSrcweir bQuit = sal_False;
936cdf0e10cSrcweir
937cdf0e10cSrcweir if( bDocBasic )
938cdf0e10cSrcweir lclInsertDocBasicItem( *this );
939cdf0e10cSrcweir }
940cdf0e10cSrcweir
941cdf0e10cSrcweir // #51727 Override SetModified so that the modified state
942cdf0e10cSrcweir // is not given to the parent
SetModified(sal_Bool b)943cdf0e10cSrcweir void StarBASIC::SetModified( sal_Bool b )
944cdf0e10cSrcweir {
945cdf0e10cSrcweir SbxBase::SetModified( b );
946cdf0e10cSrcweir }
947cdf0e10cSrcweir
948cdf0e10cSrcweir extern void lcl_closeTraceFile();
949cdf0e10cSrcweir
~StarBASIC()950cdf0e10cSrcweir StarBASIC::~StarBASIC()
951cdf0e10cSrcweir {
952cdf0e10cSrcweir #ifdef DBG_TRACE_BASIC
953cdf0e10cSrcweir lcl_closeTraceFile();
954cdf0e10cSrcweir #endif
955cdf0e10cSrcweir
956cdf0e10cSrcweir // Needs to be first action as it can trigger events
957cdf0e10cSrcweir disposeComVariablesForBasic( this );
958cdf0e10cSrcweir
959cdf0e10cSrcweir if( !--GetSbData()->nInst )
960cdf0e10cSrcweir {
961cdf0e10cSrcweir RemoveFactory( pSBFAC );
962cdf0e10cSrcweir delete pSBFAC; pSBFAC = NULL;
963cdf0e10cSrcweir RemoveFactory( pUNOFAC );
964cdf0e10cSrcweir delete pUNOFAC; pUNOFAC = NULL;
965cdf0e10cSrcweir RemoveFactory( pTYPEFAC );
966cdf0e10cSrcweir delete pTYPEFAC; pTYPEFAC = NULL;
967cdf0e10cSrcweir RemoveFactory( pCLASSFAC );
968cdf0e10cSrcweir delete pCLASSFAC; pCLASSFAC = NULL;
969cdf0e10cSrcweir RemoveFactory( pOLEFAC );
970cdf0e10cSrcweir delete pOLEFAC; pOLEFAC = NULL;
971cdf0e10cSrcweir RemoveFactory( pFORMFAC );
972cdf0e10cSrcweir delete pFORMFAC; pFORMFAC = NULL;
973cdf0e10cSrcweir
974cdf0e10cSrcweir #ifdef DBG_UTIL
975cdf0e10cSrcweir // There is no need to clean SbiData at program end,
976cdf0e10cSrcweir // but we dislike MLK's at Purify
977cdf0e10cSrcweir // TODO: Where else???
978cdf0e10cSrcweir SbiGlobals** pp = (SbiGlobals**) ::GetAppData( SHL_SBC );
979cdf0e10cSrcweir SbiGlobals* p = *pp;
980cdf0e10cSrcweir if( p )
981cdf0e10cSrcweir {
982cdf0e10cSrcweir delete p;
983cdf0e10cSrcweir *pp = 0;
984cdf0e10cSrcweir }
985cdf0e10cSrcweir #endif
986cdf0e10cSrcweir }
987cdf0e10cSrcweir else if( bDocBasic )
988cdf0e10cSrcweir {
989cdf0e10cSrcweir SbxError eOld = SbxBase::GetError();
990cdf0e10cSrcweir
991cdf0e10cSrcweir lclRemoveDocBasicItem( *this );
992cdf0e10cSrcweir
993cdf0e10cSrcweir SbxBase::ResetError();
994cdf0e10cSrcweir if( eOld != SbxERR_OK )
995cdf0e10cSrcweir SbxBase::SetError( eOld );
996cdf0e10cSrcweir }
997cdf0e10cSrcweir
998cdf0e10cSrcweir // #100326 Set Parent NULL in registered listeners
999cdf0e10cSrcweir if( xUnoListeners.Is() )
1000cdf0e10cSrcweir {
1001cdf0e10cSrcweir sal_uInt16 uCount = xUnoListeners->Count();
1002cdf0e10cSrcweir for( sal_uInt16 i = 0 ; i < uCount ; i++ )
1003cdf0e10cSrcweir {
1004cdf0e10cSrcweir SbxVariable* pListenerObj = xUnoListeners->Get( i );
1005cdf0e10cSrcweir pListenerObj->SetParent( NULL );
1006cdf0e10cSrcweir }
1007cdf0e10cSrcweir xUnoListeners = NULL;
1008cdf0e10cSrcweir }
1009cdf0e10cSrcweir
1010cdf0e10cSrcweir clearUnoMethodsForBasic( this );
1011cdf0e10cSrcweir }
1012cdf0e10cSrcweir
1013cdf0e10cSrcweir // Override new() operator, so that everyone can create a new instance
operator new(size_t n)1014cdf0e10cSrcweir void* StarBASIC::operator new( size_t n )
1015cdf0e10cSrcweir {
1016cdf0e10cSrcweir if( n < sizeof( StarBASIC ) )
1017cdf0e10cSrcweir {
1018cdf0e10cSrcweir // DBG_ASSERT( sal_False, "Warnung: inkompatibler BASIC-Stand!" );
1019cdf0e10cSrcweir n = sizeof( StarBASIC );
1020cdf0e10cSrcweir }
1021cdf0e10cSrcweir return ::operator new( n );
1022cdf0e10cSrcweir }
1023cdf0e10cSrcweir
operator delete(void * p)1024cdf0e10cSrcweir void StarBASIC::operator delete( void* p )
1025cdf0e10cSrcweir {
1026cdf0e10cSrcweir ::operator delete( p );
1027cdf0e10cSrcweir }
1028cdf0e10cSrcweir
implClearDependingVarsOnDelete(StarBASIC * pDeletedBasic)1029cdf0e10cSrcweir void StarBASIC::implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic )
1030cdf0e10cSrcweir {
1031cdf0e10cSrcweir if( this != pDeletedBasic )
1032cdf0e10cSrcweir {
1033cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
1034cdf0e10cSrcweir {
1035cdf0e10cSrcweir SbModule* p = (SbModule*)pModules->Get( i );
1036cdf0e10cSrcweir p->ClearVarsDependingOnDeletedBasic( pDeletedBasic );
1037cdf0e10cSrcweir }
1038cdf0e10cSrcweir }
1039cdf0e10cSrcweir
1040cdf0e10cSrcweir for( sal_uInt16 nObj = 0; nObj < pObjs->Count(); nObj++ )
1041cdf0e10cSrcweir {
1042cdf0e10cSrcweir SbxVariable* pVar = pObjs->Get( nObj );
1043cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST(StarBASIC,pVar);
1044cdf0e10cSrcweir if( pBasic && pBasic != pDeletedBasic )
1045cdf0e10cSrcweir pBasic->implClearDependingVarsOnDelete( pDeletedBasic );
1046cdf0e10cSrcweir }
1047cdf0e10cSrcweir }
1048cdf0e10cSrcweir
1049cdf0e10cSrcweir
1050cdf0e10cSrcweir /**************************************************************************
1051cdf0e10cSrcweir *
1052cdf0e10cSrcweir * Creation/Managment of modules
1053cdf0e10cSrcweir *
1054cdf0e10cSrcweir **************************************************************************/
1055cdf0e10cSrcweir
MakeModule(const String & rName,const String & rSrc)1056cdf0e10cSrcweir SbModule* StarBASIC::MakeModule( const String& rName, const String& rSrc )
1057cdf0e10cSrcweir {
1058cdf0e10cSrcweir return MakeModule32( rName, rSrc );
1059cdf0e10cSrcweir }
1060cdf0e10cSrcweir
MakeModule32(const String & rName,const::rtl::OUString & rSrc)1061cdf0e10cSrcweir SbModule* StarBASIC::MakeModule32( const String& rName, const ::rtl::OUString& rSrc )
1062cdf0e10cSrcweir {
1063cdf0e10cSrcweir ModuleInfo mInfo;
1064cdf0e10cSrcweir mInfo.ModuleType = ModuleType::NORMAL;
1065cdf0e10cSrcweir return MakeModule32( rName, mInfo, rSrc );
1066cdf0e10cSrcweir }
MakeModule32(const String & rName,const ModuleInfo & mInfo,const rtl::OUString & rSrc)1067cdf0e10cSrcweir SbModule* StarBASIC::MakeModule32( const String& rName, const ModuleInfo& mInfo, const rtl::OUString& rSrc )
1068cdf0e10cSrcweir {
1069cdf0e10cSrcweir
1070cdf0e10cSrcweir OSL_TRACE("create module %s type mInfo %d", rtl::OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ).getStr(), mInfo.ModuleType );
1071cdf0e10cSrcweir SbModule* p = NULL;
1072cdf0e10cSrcweir switch ( mInfo.ModuleType )
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir case ModuleType::DOCUMENT:
1075cdf0e10cSrcweir // In theory we should be able to create Object modules
1076cdf0e10cSrcweir // in ordinary basic ( in vba mode thought these are create
1077cdf0e10cSrcweir // by the application/basic and not by the user )
1078cdf0e10cSrcweir p = new SbObjModule( rName, mInfo, isVBAEnabled() );
1079cdf0e10cSrcweir break;
1080cdf0e10cSrcweir case ModuleType::CLASS:
1081cdf0e10cSrcweir p = new SbModule( rName, isVBAEnabled() );
1082cdf0e10cSrcweir p->SetModuleType( ModuleType::CLASS );
1083cdf0e10cSrcweir break;
1084cdf0e10cSrcweir case ModuleType::FORM:
1085cdf0e10cSrcweir p = new SbUserFormModule( rName, mInfo, isVBAEnabled() );
1086cdf0e10cSrcweir break;
1087cdf0e10cSrcweir default:
1088cdf0e10cSrcweir p = new SbModule( rName, isVBAEnabled() );
1089cdf0e10cSrcweir
1090cdf0e10cSrcweir }
1091cdf0e10cSrcweir p->SetSource32( rSrc );
1092cdf0e10cSrcweir p->SetParent( this );
1093cdf0e10cSrcweir pModules->Insert( p, pModules->Count() );
1094cdf0e10cSrcweir SetModified( sal_True );
1095cdf0e10cSrcweir return p;
1096cdf0e10cSrcweir }
1097cdf0e10cSrcweir
Insert(SbxVariable * pVar)1098cdf0e10cSrcweir void StarBASIC::Insert( SbxVariable* pVar )
1099cdf0e10cSrcweir {
1100cdf0e10cSrcweir if( pVar->IsA( TYPE(SbModule) ) )
1101cdf0e10cSrcweir {
1102cdf0e10cSrcweir pModules->Insert( pVar, pModules->Count() );
1103cdf0e10cSrcweir pVar->SetParent( this );
1104cdf0e10cSrcweir StartListening( pVar->GetBroadcaster(), sal_True );
1105cdf0e10cSrcweir }
1106cdf0e10cSrcweir else
1107cdf0e10cSrcweir {
1108cdf0e10cSrcweir sal_Bool bWasModified = IsModified();
1109cdf0e10cSrcweir SbxObject::Insert( pVar );
1110cdf0e10cSrcweir if( !bWasModified && pVar->IsSet( SBX_DONTSTORE ) )
1111cdf0e10cSrcweir SetModified( sal_False );
1112cdf0e10cSrcweir }
1113cdf0e10cSrcweir }
1114cdf0e10cSrcweir
Remove(SbxVariable * pVar)1115cdf0e10cSrcweir void StarBASIC::Remove( SbxVariable* pVar )
1116cdf0e10cSrcweir {
1117cdf0e10cSrcweir if( pVar->IsA( TYPE(SbModule) ) )
1118cdf0e10cSrcweir {
1119cdf0e10cSrcweir // #87540 Can be last reference!
1120cdf0e10cSrcweir SbxVariableRef xVar = pVar;
1121cdf0e10cSrcweir pModules->Remove( pVar );
1122cdf0e10cSrcweir pVar->SetParent( 0 );
1123cdf0e10cSrcweir EndListening( pVar->GetBroadcaster() );
1124cdf0e10cSrcweir }
1125cdf0e10cSrcweir else
1126cdf0e10cSrcweir SbxObject::Remove( pVar );
1127cdf0e10cSrcweir }
1128cdf0e10cSrcweir
Compile(SbModule * pMod)1129cdf0e10cSrcweir sal_Bool StarBASIC::Compile( SbModule* pMod )
1130cdf0e10cSrcweir {
1131cdf0e10cSrcweir return pMod ? pMod->Compile() : sal_False;
1132cdf0e10cSrcweir }
1133cdf0e10cSrcweir
Disassemble(SbModule * pMod,String & rText)1134cdf0e10cSrcweir sal_Bool StarBASIC::Disassemble( SbModule* pMod, String& rText )
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir rText.Erase();
1137cdf0e10cSrcweir if( pMod )
1138cdf0e10cSrcweir pMod->Disassemble( rText );
1139cdf0e10cSrcweir return sal_Bool( rText.Len() != 0 );
1140cdf0e10cSrcweir }
1141cdf0e10cSrcweir
Clear()1142cdf0e10cSrcweir void StarBASIC::Clear()
1143cdf0e10cSrcweir {
1144cdf0e10cSrcweir while( pModules->Count() )
1145cdf0e10cSrcweir pModules->Remove( pModules->Count() - 1 );
1146cdf0e10cSrcweir }
1147cdf0e10cSrcweir
FindModule(const String & rName)1148cdf0e10cSrcweir SbModule* StarBASIC::FindModule( const String& rName )
1149cdf0e10cSrcweir {
1150cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
1151cdf0e10cSrcweir {
1152cdf0e10cSrcweir SbModule* p = (SbModule*) pModules->Get( i );
1153cdf0e10cSrcweir if( p->GetName().EqualsIgnoreCaseAscii( rName ) )
1154cdf0e10cSrcweir return p;
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir return NULL;
1157cdf0e10cSrcweir }
1158cdf0e10cSrcweir
1159cdf0e10cSrcweir
1160cdf0e10cSrcweir struct ClassModuleRunInitItem
1161cdf0e10cSrcweir {
1162cdf0e10cSrcweir SbModule* m_pModule;
1163cdf0e10cSrcweir bool m_bProcessing;
1164cdf0e10cSrcweir bool m_bRunInitDone;
1165cdf0e10cSrcweir //ModuleVector m_vModulesDependingOnThisModule;
1166cdf0e10cSrcweir
ClassModuleRunInitItemClassModuleRunInitItem1167cdf0e10cSrcweir ClassModuleRunInitItem( void )
1168cdf0e10cSrcweir : m_pModule( NULL )
1169cdf0e10cSrcweir , m_bProcessing( false )
1170cdf0e10cSrcweir , m_bRunInitDone( false )
1171cdf0e10cSrcweir {}
ClassModuleRunInitItemClassModuleRunInitItem1172cdf0e10cSrcweir ClassModuleRunInitItem( SbModule* pModule )
1173cdf0e10cSrcweir : m_pModule( pModule )
1174cdf0e10cSrcweir , m_bProcessing( false )
1175cdf0e10cSrcweir , m_bRunInitDone( false )
1176cdf0e10cSrcweir {}
1177cdf0e10cSrcweir };
1178cdf0e10cSrcweir
1179cdf0e10cSrcweir // Derive from has_map type instead of typedef
1180cdf0e10cSrcweir // to allow forward declaration in sbmod.hxx
1181cdf0e10cSrcweir class ModuleInitDependencyMap : public
1182cdf0e10cSrcweir std::hash_map< ::rtl::OUString, ClassModuleRunInitItem,
1183cdf0e10cSrcweir ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > >
1184cdf0e10cSrcweir {};
1185cdf0e10cSrcweir
implProcessModuleRunInit(ModuleInitDependencyMap & rMap,ClassModuleRunInitItem & rItem)1186cdf0e10cSrcweir void SbModule::implProcessModuleRunInit( ModuleInitDependencyMap& rMap, ClassModuleRunInitItem& rItem )
1187cdf0e10cSrcweir {
1188cdf0e10cSrcweir rItem.m_bProcessing = true;
1189cdf0e10cSrcweir
1190cdf0e10cSrcweir //bool bAnyDependencies = true;
1191cdf0e10cSrcweir SbModule* pModule = rItem.m_pModule;
1192cdf0e10cSrcweir if( pModule->pClassData != NULL )
1193cdf0e10cSrcweir {
1194cdf0e10cSrcweir StringVector& rReqTypes = pModule->pClassData->maRequiredTypes;
1195cdf0e10cSrcweir if( rReqTypes.size() > 0 )
1196cdf0e10cSrcweir {
1197cdf0e10cSrcweir for( StringVector::iterator it = rReqTypes.begin() ; it != rReqTypes.end() ; ++it )
1198cdf0e10cSrcweir {
1199cdf0e10cSrcweir String& rStr = *it;
1200cdf0e10cSrcweir
1201cdf0e10cSrcweir // Is required type a class module?
1202cdf0e10cSrcweir ModuleInitDependencyMap::iterator itFind = rMap.find( rStr );
1203cdf0e10cSrcweir if( itFind != rMap.end() )
1204cdf0e10cSrcweir {
1205cdf0e10cSrcweir ClassModuleRunInitItem& rParentItem = itFind->second;
1206cdf0e10cSrcweir if( rParentItem.m_bProcessing )
1207cdf0e10cSrcweir {
1208cdf0e10cSrcweir // TODO: raise error?
1209cdf0e10cSrcweir DBG_ERROR( "Cyclic module dependency detected" );
1210cdf0e10cSrcweir continue;
1211cdf0e10cSrcweir }
1212cdf0e10cSrcweir
1213cdf0e10cSrcweir if( !rParentItem.m_bRunInitDone )
1214cdf0e10cSrcweir implProcessModuleRunInit( rMap, rParentItem );
1215cdf0e10cSrcweir }
1216cdf0e10cSrcweir }
1217cdf0e10cSrcweir }
1218cdf0e10cSrcweir }
1219cdf0e10cSrcweir
1220cdf0e10cSrcweir pModule->RunInit();
1221cdf0e10cSrcweir rItem.m_bRunInitDone = true;
1222cdf0e10cSrcweir rItem.m_bProcessing = false;
1223cdf0e10cSrcweir }
1224cdf0e10cSrcweir
1225cdf0e10cSrcweir // Run Init-Code of all modules (including inserted libraries)
InitAllModules(StarBASIC * pBasicNotToInit)1226cdf0e10cSrcweir void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir ::vos::OGuard guard( Application::GetSolarMutex() );
1229cdf0e10cSrcweir
1230cdf0e10cSrcweir // Init own modules
1231cdf0e10cSrcweir for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
1232cdf0e10cSrcweir {
1233cdf0e10cSrcweir SbModule* pModule = (SbModule*)pModules->Get( nMod );
1234cdf0e10cSrcweir if( !pModule->IsCompiled() )
1235cdf0e10cSrcweir pModule->Compile();
1236cdf0e10cSrcweir }
1237cdf0e10cSrcweir // compile modules first then RunInit ( otherwise there is
1238cdf0e10cSrcweir // can be order dependency, e.g. classmodule A has a member
1239cdf0e10cSrcweir // of of type classmodule B and classmodule B hasn't been compiled yet )
1240cdf0e10cSrcweir
1241cdf0e10cSrcweir // Consider required types to init in right order. Class modules
1242cdf0e10cSrcweir // that are required by other modules have to be initialized first.
1243cdf0e10cSrcweir ModuleInitDependencyMap aMIDMap;
1244cdf0e10cSrcweir for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
1245cdf0e10cSrcweir {
1246cdf0e10cSrcweir SbModule* pModule = (SbModule*)pModules->Get( nMod );
1247cdf0e10cSrcweir String aModuleName = pModule->GetName();
1248cdf0e10cSrcweir if( pModule->isProxyModule() )
1249cdf0e10cSrcweir aMIDMap[aModuleName] = ClassModuleRunInitItem( pModule );
1250cdf0e10cSrcweir }
1251cdf0e10cSrcweir
1252cdf0e10cSrcweir ModuleInitDependencyMap::iterator it;
1253cdf0e10cSrcweir for( it = aMIDMap.begin() ; it != aMIDMap.end(); ++it )
1254cdf0e10cSrcweir {
1255cdf0e10cSrcweir ClassModuleRunInitItem& rItem = it->second;
1256cdf0e10cSrcweir SbModule::implProcessModuleRunInit( aMIDMap, rItem );
1257cdf0e10cSrcweir }
1258cdf0e10cSrcweir
1259cdf0e10cSrcweir // Call RunInit on standard modules
1260cdf0e10cSrcweir for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
1261cdf0e10cSrcweir {
1262cdf0e10cSrcweir SbModule* pModule = (SbModule*)pModules->Get( nMod );
1263cdf0e10cSrcweir if( !pModule->isProxyModule() )
1264cdf0e10cSrcweir pModule->RunInit();
1265cdf0e10cSrcweir }
1266cdf0e10cSrcweir
1267cdf0e10cSrcweir // Check all objects if they are BASIC,
1268cdf0e10cSrcweir // if yes initialize
1269cdf0e10cSrcweir for ( sal_uInt16 nObj = 0; nObj < pObjs->Count(); nObj++ )
1270cdf0e10cSrcweir {
1271cdf0e10cSrcweir SbxVariable* pVar = pObjs->Get( nObj );
1272cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST(StarBASIC,pVar);
1273cdf0e10cSrcweir if( pBasic && pBasic != pBasicNotToInit )
1274cdf0e10cSrcweir pBasic->InitAllModules();
1275cdf0e10cSrcweir }
1276cdf0e10cSrcweir }
1277cdf0e10cSrcweir
1278cdf0e10cSrcweir // #88329 Put modules back to not initialised state to
1279cdf0e10cSrcweir // force reinitialisation at next start
DeInitAllModules(void)1280cdf0e10cSrcweir void StarBASIC::DeInitAllModules( void )
1281cdf0e10cSrcweir {
1282cdf0e10cSrcweir // Deinit own modules
1283cdf0e10cSrcweir for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
1284cdf0e10cSrcweir {
1285cdf0e10cSrcweir SbModule* pModule = (SbModule*)pModules->Get( nMod );
1286cdf0e10cSrcweir if( pModule->pImage && !pModule->isProxyModule() && !pModule->ISA(SbObjModule) )
1287cdf0e10cSrcweir pModule->pImage->bInit = false;
1288cdf0e10cSrcweir }
1289cdf0e10cSrcweir
1290cdf0e10cSrcweir for ( sal_uInt16 nObj = 0; nObj < pObjs->Count(); nObj++ )
1291cdf0e10cSrcweir {
1292cdf0e10cSrcweir SbxVariable* pVar = pObjs->Get( nObj );
1293cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST(StarBASIC,pVar);
1294cdf0e10cSrcweir if( pBasic )
1295cdf0e10cSrcweir pBasic->DeInitAllModules();
1296cdf0e10cSrcweir }
1297cdf0e10cSrcweir }
1298cdf0e10cSrcweir
1299cdf0e10cSrcweir // #43011 For TestTool, to delete global vars
ClearGlobalVars(void)1300cdf0e10cSrcweir void StarBASIC::ClearGlobalVars( void )
1301cdf0e10cSrcweir {
1302cdf0e10cSrcweir SbxArrayRef xProps( GetProperties() );
1303cdf0e10cSrcweir sal_uInt16 nPropCount = xProps->Count();
1304cdf0e10cSrcweir for ( sal_uInt16 nProp = 0 ; nProp < nPropCount ; ++nProp )
1305cdf0e10cSrcweir {
1306cdf0e10cSrcweir SbxBase* pVar = xProps->Get( nProp );
1307cdf0e10cSrcweir pVar->Clear();
1308cdf0e10cSrcweir }
1309cdf0e10cSrcweir SetModified( sal_True );
1310cdf0e10cSrcweir }
1311cdf0e10cSrcweir
1312cdf0e10cSrcweir // This implementation at first searches within the runtime library,
1313cdf0e10cSrcweir // then it looks for an element within one module. This moudle can be
1314cdf0e10cSrcweir // a public var or an entrypoint. If it is not found and we look for a
1315cdf0e10cSrcweir // method and a module with the given name is found the search continues
1316cdf0e10cSrcweir // for entrypoint "Main".
1317cdf0e10cSrcweir // If this fails again a conventional search over objects is performend.
Find(const String & rName,SbxClassType t)1318cdf0e10cSrcweir SbxVariable* StarBASIC::Find( const String& rName, SbxClassType t )
1319cdf0e10cSrcweir {
1320cdf0e10cSrcweir static String aMainStr( RTL_CONSTASCII_USTRINGPARAM("Main") );
1321cdf0e10cSrcweir
1322cdf0e10cSrcweir SbxVariable* pRes = NULL;
1323cdf0e10cSrcweir SbModule* pNamed = NULL;
1324cdf0e10cSrcweir // "Extended" search in Runtime Lib
1325cdf0e10cSrcweir // but only if SbiRuntime has not set the flag
1326cdf0e10cSrcweir if( !bNoRtl )
1327cdf0e10cSrcweir {
1328cdf0e10cSrcweir if( t == SbxCLASS_DONTCARE || t == SbxCLASS_OBJECT )
1329cdf0e10cSrcweir {
1330cdf0e10cSrcweir if( rName.EqualsIgnoreCaseAscii( RTLNAME ) )
1331cdf0e10cSrcweir pRes = pRtl;
1332cdf0e10cSrcweir }
1333cdf0e10cSrcweir if( !pRes )
1334cdf0e10cSrcweir pRes = ((SbiStdObject*) (SbxObject*) pRtl)->Find( rName, t );
1335cdf0e10cSrcweir if( pRes )
1336cdf0e10cSrcweir pRes->SetFlag( SBX_EXTFOUND );
1337cdf0e10cSrcweir }
1338cdf0e10cSrcweir // Search module
1339cdf0e10cSrcweir if( !pRes )
1340cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir SbModule* p = (SbModule*) pModules->Get( i );
1343cdf0e10cSrcweir if( p->IsVisible() )
1344cdf0e10cSrcweir {
1345cdf0e10cSrcweir // Remember modul fpr Main() call
1346cdf0e10cSrcweir // or is the name equal?!?
1347cdf0e10cSrcweir if( p->GetName().EqualsIgnoreCaseAscii( rName ) )
1348cdf0e10cSrcweir {
1349cdf0e10cSrcweir if( t == SbxCLASS_OBJECT || t == SbxCLASS_DONTCARE )
1350cdf0e10cSrcweir {
1351cdf0e10cSrcweir pRes = p; break;
1352cdf0e10cSrcweir }
1353cdf0e10cSrcweir pNamed = p;
1354cdf0e10cSrcweir }
1355cdf0e10cSrcweir // Only variables qualified by the Module Name e.g. Sheet1.foo
1356cdf0e10cSrcweir // should work for Documant && Class type Modules
1357cdf0e10cSrcweir sal_Int32 nType = p->GetModuleType();
1358cdf0e10cSrcweir if ( nType == ModuleType::DOCUMENT || nType == ModuleType::FORM )
1359cdf0e10cSrcweir continue;
1360cdf0e10cSrcweir
1361cdf0e10cSrcweir // otherwise check if the element is available
1362cdf0e10cSrcweir // unset GBLSEARCH-Flag (due to Rekursion)
1363cdf0e10cSrcweir sal_uInt16 nGblFlag = p->GetFlags() & SBX_GBLSEARCH;
1364cdf0e10cSrcweir p->ResetFlag( SBX_GBLSEARCH );
1365cdf0e10cSrcweir pRes = p->Find( rName, t );
1366cdf0e10cSrcweir p->SetFlag( nGblFlag );
1367cdf0e10cSrcweir if( pRes )
1368cdf0e10cSrcweir break;
1369cdf0e10cSrcweir }
1370cdf0e10cSrcweir }
1371cdf0e10cSrcweir if( !pRes && pNamed && ( t == SbxCLASS_METHOD || t == SbxCLASS_DONTCARE ) &&
1372cdf0e10cSrcweir !pNamed->GetName().EqualsIgnoreCaseAscii( aMainStr ) )
1373cdf0e10cSrcweir pRes = pNamed->Find( aMainStr, SbxCLASS_METHOD );
1374cdf0e10cSrcweir if( !pRes )
1375cdf0e10cSrcweir pRes = SbxObject::Find( rName, t );
1376cdf0e10cSrcweir return pRes;
1377cdf0e10cSrcweir }
1378cdf0e10cSrcweir
Call(const String & rName,SbxArray * pParam)1379cdf0e10cSrcweir sal_Bool StarBASIC::Call( const String& rName, SbxArray* pParam )
1380cdf0e10cSrcweir {
1381cdf0e10cSrcweir sal_Bool bRes = SbxObject::Call( rName, pParam );
1382cdf0e10cSrcweir if( !bRes )
1383cdf0e10cSrcweir {
1384cdf0e10cSrcweir SbxError eErr = SbxBase::GetError();
1385cdf0e10cSrcweir SbxBase::ResetError();
1386cdf0e10cSrcweir if( eErr != SbxERR_OK )
1387cdf0e10cSrcweir RTError( (SbError)eErr, 0, 0, 0 );
1388cdf0e10cSrcweir }
1389cdf0e10cSrcweir return bRes;
1390cdf0e10cSrcweir }
1391cdf0e10cSrcweir
1392cdf0e10cSrcweir // Find method via name (e.g. query via BASIC IDE)
FindSBXInCurrentScope(const String & rName)1393cdf0e10cSrcweir SbxBase* StarBASIC::FindSBXInCurrentScope( const String& rName )
1394cdf0e10cSrcweir {
1395cdf0e10cSrcweir if( !pINST )
1396cdf0e10cSrcweir return NULL;
1397cdf0e10cSrcweir if( !pINST->pRun )
1398cdf0e10cSrcweir return NULL;
1399cdf0e10cSrcweir return pINST->pRun->FindElementExtern( rName );
1400cdf0e10cSrcweir }
1401cdf0e10cSrcweir
1402cdf0e10cSrcweir // Preserve old interface
FindVarInCurrentScopy(const String & rName,sal_uInt16 & rStatus)1403cdf0e10cSrcweir SbxVariable* StarBASIC::FindVarInCurrentScopy
1404cdf0e10cSrcweir ( const String& rName, sal_uInt16& rStatus )
1405cdf0e10cSrcweir {
1406cdf0e10cSrcweir rStatus = 1; // Presumption: nothing found
1407cdf0e10cSrcweir SbxVariable* pVar = NULL;
1408cdf0e10cSrcweir SbxBase* pSbx = FindSBXInCurrentScope( rName );
1409cdf0e10cSrcweir if( pSbx )
1410cdf0e10cSrcweir {
1411cdf0e10cSrcweir if( !pSbx->ISA(SbxMethod) && !pSbx->ISA(SbxObject) )
1412cdf0e10cSrcweir pVar = PTR_CAST(SbxVariable,pSbx);
1413cdf0e10cSrcweir }
1414cdf0e10cSrcweir if( pVar )
1415cdf0e10cSrcweir rStatus = 0; // We found something
1416cdf0e10cSrcweir return pVar;
1417cdf0e10cSrcweir }
1418cdf0e10cSrcweir
QuitAndExitApplication()1419cdf0e10cSrcweir void StarBASIC::QuitAndExitApplication()
1420cdf0e10cSrcweir {
1421cdf0e10cSrcweir Stop();
1422cdf0e10cSrcweir bQuit = sal_True;
1423cdf0e10cSrcweir }
1424cdf0e10cSrcweir
Stop()1425cdf0e10cSrcweir void StarBASIC::Stop()
1426cdf0e10cSrcweir {
1427cdf0e10cSrcweir SbiInstance* p = pINST;
1428cdf0e10cSrcweir while( p )
1429cdf0e10cSrcweir {
1430cdf0e10cSrcweir p->Stop();
1431cdf0e10cSrcweir p = p->pNext;
1432cdf0e10cSrcweir }
1433cdf0e10cSrcweir }
1434cdf0e10cSrcweir
IsRunning()1435cdf0e10cSrcweir sal_Bool StarBASIC::IsRunning()
1436cdf0e10cSrcweir {
1437cdf0e10cSrcweir return sal_Bool( pINST != NULL );
1438cdf0e10cSrcweir }
1439cdf0e10cSrcweir
1440cdf0e10cSrcweir /**************************************************************************
1441cdf0e10cSrcweir *
1442cdf0e10cSrcweir * Object factories and others
1443cdf0e10cSrcweir *
1444cdf0e10cSrcweir **************************************************************************/
1445cdf0e10cSrcweir
1446cdf0e10cSrcweir // Activation of an object. There is no need to access active objects
1447cdf0e10cSrcweir // with name via BASIC. If NULL is given, everything is activated.
ActivateObject(const String * pName,sal_Bool bActivate)1448cdf0e10cSrcweir void StarBASIC::ActivateObject( const String* pName, sal_Bool bActivate )
1449cdf0e10cSrcweir {
1450cdf0e10cSrcweir if( pName )
1451cdf0e10cSrcweir {
1452cdf0e10cSrcweir SbxObject* p = (SbxObject*) SbxObject::Find( *pName, SbxCLASS_OBJECT );
1453cdf0e10cSrcweir if( p )
1454cdf0e10cSrcweir {
1455cdf0e10cSrcweir if( bActivate )
1456cdf0e10cSrcweir p->SetFlag( SBX_EXTSEARCH );
1457cdf0e10cSrcweir else
1458cdf0e10cSrcweir p->ResetFlag( SBX_EXTSEARCH );
1459cdf0e10cSrcweir }
1460cdf0e10cSrcweir }
1461cdf0e10cSrcweir else
1462cdf0e10cSrcweir {
1463cdf0e10cSrcweir for( sal_uInt16 i = 0; i < GetObjects()->Count(); i++ )
1464cdf0e10cSrcweir {
1465cdf0e10cSrcweir SbxObject* p = (SbxObject*) GetObjects()->Get( i );
1466cdf0e10cSrcweir if( bActivate )
1467cdf0e10cSrcweir p->SetFlag( SBX_EXTSEARCH );
1468cdf0e10cSrcweir else
1469cdf0e10cSrcweir p->ResetFlag( SBX_EXTSEARCH );
1470cdf0e10cSrcweir }
1471cdf0e10cSrcweir }
1472cdf0e10cSrcweir }
1473cdf0e10cSrcweir
1474cdf0e10cSrcweir /**************************************************************************
1475cdf0e10cSrcweir *
1476cdf0e10cSrcweir * Debugging and error handling
1477cdf0e10cSrcweir *
1478cdf0e10cSrcweir **************************************************************************/
1479cdf0e10cSrcweir
GetActiveMethod(sal_uInt16 nLevel)1480cdf0e10cSrcweir SbMethod* StarBASIC::GetActiveMethod( sal_uInt16 nLevel )
1481cdf0e10cSrcweir {
1482cdf0e10cSrcweir if( pINST )
1483cdf0e10cSrcweir return pINST->GetCaller( nLevel );
1484cdf0e10cSrcweir else
1485cdf0e10cSrcweir return NULL;
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir
GetActiveModule()1488cdf0e10cSrcweir SbModule* StarBASIC::GetActiveModule()
1489cdf0e10cSrcweir {
1490cdf0e10cSrcweir if( pINST && !IsCompilerError() )
1491cdf0e10cSrcweir return pINST->GetActiveModule();
1492cdf0e10cSrcweir else
1493cdf0e10cSrcweir return pCMOD;
1494cdf0e10cSrcweir }
1495cdf0e10cSrcweir
BreakPoint(sal_uInt16 l,sal_uInt16 c1,sal_uInt16 c2)1496cdf0e10cSrcweir sal_uInt16 StarBASIC::BreakPoint( sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 )
1497cdf0e10cSrcweir {
1498cdf0e10cSrcweir SetErrorData( 0, l, c1, c2 );
1499cdf0e10cSrcweir bBreak = sal_True;
1500cdf0e10cSrcweir if( GetSbData()->aBreakHdl.IsSet() )
1501cdf0e10cSrcweir return (sal_uInt16) GetSbData()->aBreakHdl.Call( this );
1502cdf0e10cSrcweir else
1503cdf0e10cSrcweir return BreakHdl();
1504cdf0e10cSrcweir }
1505cdf0e10cSrcweir
StepPoint(sal_uInt16 l,sal_uInt16 c1,sal_uInt16 c2)1506cdf0e10cSrcweir sal_uInt16 StarBASIC::StepPoint( sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 )
1507cdf0e10cSrcweir {
1508cdf0e10cSrcweir SetErrorData( 0, l, c1, c2 );
1509cdf0e10cSrcweir bBreak = sal_False;
1510cdf0e10cSrcweir if( GetSbData()->aBreakHdl.IsSet() )
1511cdf0e10cSrcweir return (sal_uInt16) GetSbData()->aBreakHdl.Call( this );
1512cdf0e10cSrcweir else
1513cdf0e10cSrcweir return BreakHdl();
1514cdf0e10cSrcweir }
1515cdf0e10cSrcweir
BreakHdl()1516cdf0e10cSrcweir sal_uInt16 __EXPORT StarBASIC::BreakHdl()
1517cdf0e10cSrcweir {
1518cdf0e10cSrcweir return (sal_uInt16) ( aBreakHdl.IsSet()
1519cdf0e10cSrcweir ? aBreakHdl.Call( this ) : SbDEBUG_CONTINUE );
1520cdf0e10cSrcweir }
1521cdf0e10cSrcweir
1522cdf0e10cSrcweir // Calls for error handler and break handler
GetLine()1523cdf0e10cSrcweir sal_uInt16 StarBASIC::GetLine() { return GetSbData()->nLine; }
GetCol1()1524cdf0e10cSrcweir sal_uInt16 StarBASIC::GetCol1() { return GetSbData()->nCol1; }
GetCol2()1525cdf0e10cSrcweir sal_uInt16 StarBASIC::GetCol2() { return GetSbData()->nCol2; }
1526cdf0e10cSrcweir
1527cdf0e10cSrcweir // Specific to error handler
GetErrorCode()1528cdf0e10cSrcweir SbError StarBASIC::GetErrorCode() { return GetSbData()->nCode; }
GetErrorText()1529cdf0e10cSrcweir const String& StarBASIC::GetErrorText() { return GetSbData()->aErrMsg; }
IsCompilerError()1530cdf0e10cSrcweir sal_Bool StarBASIC::IsCompilerError() { return GetSbData()->bCompiler; }
SetGlobalLanguageMode(SbLanguageMode eLanguageMode)1531cdf0e10cSrcweir void StarBASIC::SetGlobalLanguageMode( SbLanguageMode eLanguageMode )
1532cdf0e10cSrcweir {
1533cdf0e10cSrcweir GetSbData()->eLanguageMode = eLanguageMode;
1534cdf0e10cSrcweir }
GetGlobalLanguageMode()1535cdf0e10cSrcweir SbLanguageMode StarBASIC::GetGlobalLanguageMode()
1536cdf0e10cSrcweir {
1537cdf0e10cSrcweir return GetSbData()->eLanguageMode;
1538cdf0e10cSrcweir }
1539cdf0e10cSrcweir // Local settings
GetLanguageMode()1540cdf0e10cSrcweir SbLanguageMode StarBASIC::GetLanguageMode()
1541cdf0e10cSrcweir {
1542cdf0e10cSrcweir // Use global settings?
1543cdf0e10cSrcweir if( eLanguageMode == SB_LANG_GLOBAL )
1544cdf0e10cSrcweir return GetSbData()->eLanguageMode;
1545cdf0e10cSrcweir else
1546cdf0e10cSrcweir return eLanguageMode;
1547cdf0e10cSrcweir }
1548cdf0e10cSrcweir
1549cdf0e10cSrcweir // AB: 29.3.96
1550cdf0e10cSrcweir // Das Mapping zwischen alten und neuen Fehlercodes erfolgt, indem die Tabelle
1551cdf0e10cSrcweir // SFX_VB_ErrorTab[] durchsucht wird. Dies ist zwar nicht besonders performant,
1552cdf0e10cSrcweir // verbraucht aber viel weniger Speicher als entsprechende switch-Bloecke.
1553cdf0e10cSrcweir // Die Umrechnung von Fehlercodes muss nicht schnell sein, daher auch keine
1554cdf0e10cSrcweir // binaere Suche bei VB-Error -> SFX-Error.
1555cdf0e10cSrcweir
1556cdf0e10cSrcweir // Neue Fehler-Codes auf alte, Sbx-Kompatible zurueckmappen
GetVBErrorCode(SbError nError)1557cdf0e10cSrcweir sal_uInt16 StarBASIC::GetVBErrorCode( SbError nError )
1558cdf0e10cSrcweir {
1559cdf0e10cSrcweir sal_uInt16 nRet = 0;
1560cdf0e10cSrcweir
1561cdf0e10cSrcweir if( SbiRuntime::isVBAEnabled() )
1562cdf0e10cSrcweir {
1563cdf0e10cSrcweir switch( nError )
1564cdf0e10cSrcweir {
1565cdf0e10cSrcweir case SbERR_BASIC_ARRAY_FIX:
1566cdf0e10cSrcweir return 10;
1567cdf0e10cSrcweir case SbERR_BASIC_STRING_OVERFLOW:
1568cdf0e10cSrcweir return 14;
1569cdf0e10cSrcweir case SbERR_BASIC_EXPR_TOO_COMPLEX:
1570cdf0e10cSrcweir return 16;
1571cdf0e10cSrcweir case SbERR_BASIC_OPER_NOT_PERFORM:
1572cdf0e10cSrcweir return 17;
1573cdf0e10cSrcweir case SbERR_BASIC_TOO_MANY_DLL:
1574cdf0e10cSrcweir return 47;
1575cdf0e10cSrcweir case SbERR_BASIC_LOOP_NOT_INIT:
1576cdf0e10cSrcweir return 92;
1577cdf0e10cSrcweir default:
1578cdf0e10cSrcweir nRet = 0;
1579cdf0e10cSrcweir }
1580cdf0e10cSrcweir }
1581cdf0e10cSrcweir
1582cdf0e10cSrcweir // Suchschleife
1583cdf0e10cSrcweir const SFX_VB_ErrorItem* pErrItem;
1584cdf0e10cSrcweir sal_uInt16 nIndex = 0;
1585cdf0e10cSrcweir do
1586cdf0e10cSrcweir {
1587cdf0e10cSrcweir pErrItem = SFX_VB_ErrorTab + nIndex;
1588cdf0e10cSrcweir if( pErrItem->nErrorSFX == nError )
1589cdf0e10cSrcweir {
1590cdf0e10cSrcweir nRet = pErrItem->nErrorVB;
1591cdf0e10cSrcweir break;
1592cdf0e10cSrcweir }
1593cdf0e10cSrcweir nIndex++;
1594cdf0e10cSrcweir }
1595cdf0e10cSrcweir while( pErrItem->nErrorVB != 0xFFFF ); // bis End-Marke
1596cdf0e10cSrcweir return nRet;
1597cdf0e10cSrcweir }
1598cdf0e10cSrcweir
GetSfxFromVBError(sal_uInt16 nError)1599cdf0e10cSrcweir SbError StarBASIC::GetSfxFromVBError( sal_uInt16 nError )
1600cdf0e10cSrcweir {
1601cdf0e10cSrcweir SbError nRet = 0L;
1602cdf0e10cSrcweir
1603cdf0e10cSrcweir if( SbiRuntime::isVBAEnabled() )
1604cdf0e10cSrcweir {
1605cdf0e10cSrcweir switch( nError )
1606cdf0e10cSrcweir {
1607cdf0e10cSrcweir case 1:
1608cdf0e10cSrcweir case 2:
1609cdf0e10cSrcweir case 4:
1610cdf0e10cSrcweir case 8:
1611cdf0e10cSrcweir case 12:
1612cdf0e10cSrcweir case 73:
1613cdf0e10cSrcweir return 0L;
1614cdf0e10cSrcweir case 10:
1615cdf0e10cSrcweir return SbERR_BASIC_ARRAY_FIX;
1616cdf0e10cSrcweir case 14:
1617cdf0e10cSrcweir return SbERR_BASIC_STRING_OVERFLOW;
1618cdf0e10cSrcweir case 16:
1619cdf0e10cSrcweir return SbERR_BASIC_EXPR_TOO_COMPLEX;
1620cdf0e10cSrcweir case 17:
1621cdf0e10cSrcweir return SbERR_BASIC_OPER_NOT_PERFORM;
1622cdf0e10cSrcweir case 47:
1623cdf0e10cSrcweir return SbERR_BASIC_TOO_MANY_DLL;
1624cdf0e10cSrcweir case 92:
1625cdf0e10cSrcweir return SbERR_BASIC_LOOP_NOT_INIT;
1626cdf0e10cSrcweir default:
1627cdf0e10cSrcweir nRet = 0L;
1628cdf0e10cSrcweir }
1629cdf0e10cSrcweir }
1630cdf0e10cSrcweir const SFX_VB_ErrorItem* pErrItem;
1631cdf0e10cSrcweir sal_uInt16 nIndex = 0;
1632cdf0e10cSrcweir do
1633cdf0e10cSrcweir {
1634cdf0e10cSrcweir pErrItem = SFX_VB_ErrorTab + nIndex;
1635cdf0e10cSrcweir if( pErrItem->nErrorVB == nError )
1636cdf0e10cSrcweir {
1637cdf0e10cSrcweir nRet = pErrItem->nErrorSFX;
1638cdf0e10cSrcweir break;
1639cdf0e10cSrcweir }
1640cdf0e10cSrcweir else if( pErrItem->nErrorVB > nError )
1641cdf0e10cSrcweir break; // kann nicht mehr gefunden werden
1642cdf0e10cSrcweir
1643cdf0e10cSrcweir nIndex++;
1644cdf0e10cSrcweir }
1645cdf0e10cSrcweir while( pErrItem->nErrorVB != 0xFFFF ); // bis End-Marke
1646cdf0e10cSrcweir return nRet;
1647cdf0e10cSrcweir }
1648cdf0e10cSrcweir
1649cdf0e10cSrcweir // Error- / Break-Daten setzen
SetErrorData(SbError nCode,sal_uInt16 nLine,sal_uInt16 nCol1,sal_uInt16 nCol2)1650cdf0e10cSrcweir void StarBASIC::SetErrorData
1651cdf0e10cSrcweir ( SbError nCode, sal_uInt16 nLine, sal_uInt16 nCol1, sal_uInt16 nCol2 )
1652cdf0e10cSrcweir {
1653cdf0e10cSrcweir SbiGlobals& aGlobals = *GetSbData();
1654cdf0e10cSrcweir aGlobals.nCode = nCode;
1655cdf0e10cSrcweir aGlobals.nLine = nLine;
1656cdf0e10cSrcweir aGlobals.nCol1 = nCol1;
1657cdf0e10cSrcweir aGlobals.nCol2 = nCol2;
1658cdf0e10cSrcweir }
1659cdf0e10cSrcweir
1660cdf0e10cSrcweir //----------------------------------------------------------------
1661cdf0e10cSrcweir // Hilfsklasse zum Zugriff auf String SubResourcen einer Resource.
1662cdf0e10cSrcweir // Quelle: sfx2\source\doc\docfile.cxx (TLX)
1663cdf0e10cSrcweir struct BasicStringList_Impl : private Resource
1664cdf0e10cSrcweir {
1665cdf0e10cSrcweir ResId aResId;
1666cdf0e10cSrcweir
BasicStringList_ImplBasicStringList_Impl1667cdf0e10cSrcweir BasicStringList_Impl( ResId& rErrIdP, sal_uInt16 nId)
1668cdf0e10cSrcweir : Resource( rErrIdP ),aResId(nId, *rErrIdP.GetResMgr() ){}
~BasicStringList_ImplBasicStringList_Impl1669cdf0e10cSrcweir ~BasicStringList_Impl() { FreeResource(); }
1670cdf0e10cSrcweir
GetStringBasicStringList_Impl1671cdf0e10cSrcweir String GetString(){ return String( aResId ); }
IsErrorTextAvailableBasicStringList_Impl1672cdf0e10cSrcweir sal_Bool IsErrorTextAvailable( void )
1673cdf0e10cSrcweir { return IsAvailableRes(aResId.SetRT(RSC_STRING)); }
1674cdf0e10cSrcweir };
1675cdf0e10cSrcweir //----------------------------------------------------------------
1676cdf0e10cSrcweir
1677cdf0e10cSrcweir // #60175 Flag, das bei Basic-Fehlern das Anziehen der SFX-Resourcen verhindert
1678cdf0e10cSrcweir static sal_Bool bStaticSuppressSfxResource = sal_False;
1679cdf0e10cSrcweir
StaticSuppressSfxResource(sal_Bool bSuppress)1680cdf0e10cSrcweir void StarBASIC::StaticSuppressSfxResource( sal_Bool bSuppress )
1681cdf0e10cSrcweir {
1682cdf0e10cSrcweir bStaticSuppressSfxResource = bSuppress;
1683cdf0e10cSrcweir }
1684cdf0e10cSrcweir
1685cdf0e10cSrcweir // Hack for #83750, use bStaticSuppressSfxResource as setup flag
runsInSetup(void)1686cdf0e10cSrcweir sal_Bool runsInSetup( void )
1687cdf0e10cSrcweir {
1688cdf0e10cSrcweir return bStaticSuppressSfxResource;
1689cdf0e10cSrcweir }
1690cdf0e10cSrcweir
1691cdf0e10cSrcweir
MakeErrorText(SbError nId,const String & aMsg)1692cdf0e10cSrcweir void StarBASIC::MakeErrorText( SbError nId, const String& aMsg )
1693cdf0e10cSrcweir {
1694cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1695cdf0e10cSrcweir
1696cdf0e10cSrcweir if( bStaticSuppressSfxResource )
1697cdf0e10cSrcweir {
1698cdf0e10cSrcweir GetSbData()->aErrMsg = String( RTL_CONSTASCII_USTRINGPARAM("No resource: Error message not available") );
1699cdf0e10cSrcweir return;
1700cdf0e10cSrcweir }
1701cdf0e10cSrcweir
1702cdf0e10cSrcweir sal_uInt16 nOldID = GetVBErrorCode( nId );
1703cdf0e10cSrcweir
1704cdf0e10cSrcweir // Hilfsklasse instanzieren
1705cdf0e10cSrcweir BasResId aId( RID_BASIC_START );
1706cdf0e10cSrcweir BasicStringList_Impl aMyStringList( aId, sal_uInt16(nId & ERRCODE_RES_MASK) );
1707cdf0e10cSrcweir
1708cdf0e10cSrcweir if( aMyStringList.IsErrorTextAvailable() )
1709cdf0e10cSrcweir {
1710cdf0e10cSrcweir // Merge Message mit Zusatztext
1711cdf0e10cSrcweir String aMsg1 = aMyStringList.GetString();
1712cdf0e10cSrcweir // Argument-Platzhalter durch %s ersetzen
1713cdf0e10cSrcweir String aSrgStr( RTL_CONSTASCII_USTRINGPARAM("$(ARG1)") );
1714cdf0e10cSrcweir sal_uInt16 nResult = aMsg1.Search( aSrgStr );
1715cdf0e10cSrcweir
1716cdf0e10cSrcweir if( nResult != STRING_NOTFOUND )
1717cdf0e10cSrcweir {
1718cdf0e10cSrcweir aMsg1.Erase( nResult, aSrgStr.Len() );
1719cdf0e10cSrcweir aMsg1.Insert( aMsg, nResult );
1720cdf0e10cSrcweir }
1721cdf0e10cSrcweir GetSbData()->aErrMsg = aMsg1;
1722cdf0e10cSrcweir }
1723cdf0e10cSrcweir else if( nOldID != 0 )
1724cdf0e10cSrcweir {
1725cdf0e10cSrcweir String aStdMsg( RTL_CONSTASCII_USTRINGPARAM("Fehler ") );
1726cdf0e10cSrcweir aStdMsg += String::CreateFromInt32( nOldID);
1727cdf0e10cSrcweir aStdMsg += String( RTL_CONSTASCII_USTRINGPARAM(": Kein Fehlertext verfuegbar!") );
1728cdf0e10cSrcweir GetSbData()->aErrMsg = aStdMsg;
1729cdf0e10cSrcweir }
1730cdf0e10cSrcweir else
1731cdf0e10cSrcweir GetSbData()->aErrMsg = String::EmptyString();
1732cdf0e10cSrcweir
1733cdf0e10cSrcweir }
1734cdf0e10cSrcweir
CError(SbError code,const String & rMsg,sal_uInt16 l,sal_uInt16 c1,sal_uInt16 c2)1735cdf0e10cSrcweir sal_Bool StarBASIC::CError
1736cdf0e10cSrcweir ( SbError code, const String& rMsg, sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 )
1737cdf0e10cSrcweir {
1738cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1739cdf0e10cSrcweir
1740cdf0e10cSrcweir // Compiler-Fehler waehrend der Laufzeit -> Programm anhalten
1741cdf0e10cSrcweir if( IsRunning() )
1742cdf0e10cSrcweir {
1743cdf0e10cSrcweir // #109018 Check if running Basic is affected
1744cdf0e10cSrcweir StarBASIC* pStartedBasic = pINST->GetBasic();
1745cdf0e10cSrcweir if( pStartedBasic != this )
1746cdf0e10cSrcweir return sal_False;
1747cdf0e10cSrcweir
1748cdf0e10cSrcweir Stop();
1749cdf0e10cSrcweir }
1750cdf0e10cSrcweir
1751cdf0e10cSrcweir // Flag setzen, damit GlobalRunInit den Fehler mitbekommt
1752cdf0e10cSrcweir GetSbData()->bGlobalInitErr = sal_True;
1753cdf0e10cSrcweir
1754cdf0e10cSrcweir // Fehlertext basteln
1755cdf0e10cSrcweir MakeErrorText( code, rMsg );
1756cdf0e10cSrcweir
1757cdf0e10cSrcweir // Umsetzung des Codes fuer String-Transport in SFX-Error
1758cdf0e10cSrcweir if( rMsg.Len() )
1759cdf0e10cSrcweir code = (sal_uIntPtr)*new StringErrorInfo( code, String(rMsg) );
1760cdf0e10cSrcweir
1761cdf0e10cSrcweir SetErrorData( code, l, c1, c2 );
1762cdf0e10cSrcweir GetSbData()->bCompiler = sal_True;
1763cdf0e10cSrcweir sal_Bool bRet;
1764cdf0e10cSrcweir if( GetSbData()->aErrHdl.IsSet() )
1765cdf0e10cSrcweir bRet = (sal_Bool) GetSbData()->aErrHdl.Call( this );
1766cdf0e10cSrcweir else
1767cdf0e10cSrcweir bRet = ErrorHdl();
1768cdf0e10cSrcweir GetSbData()->bCompiler = sal_False; // nur sal_True fuer Error-Handler
1769cdf0e10cSrcweir return bRet;
1770cdf0e10cSrcweir }
1771cdf0e10cSrcweir
RTError(SbError code,sal_uInt16 l,sal_uInt16 c1,sal_uInt16 c2)1772cdf0e10cSrcweir sal_Bool StarBASIC::RTError
1773cdf0e10cSrcweir ( SbError code, sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 )
1774cdf0e10cSrcweir {
1775cdf0e10cSrcweir return RTError( code, String(), l, c1, c2 );
1776cdf0e10cSrcweir }
1777cdf0e10cSrcweir
RTError(SbError code,const String & rMsg,sal_uInt16 l,sal_uInt16 c1,sal_uInt16 c2)1778cdf0e10cSrcweir sal_Bool StarBASIC::RTError( SbError code, const String& rMsg, sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 )
1779cdf0e10cSrcweir {
1780cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1781cdf0e10cSrcweir
1782cdf0e10cSrcweir SbError c = code;
1783cdf0e10cSrcweir if( (c & ERRCODE_CLASS_MASK) == ERRCODE_CLASS_COMPILER )
1784cdf0e10cSrcweir c = 0;
1785cdf0e10cSrcweir MakeErrorText( c, rMsg );
1786cdf0e10cSrcweir
1787cdf0e10cSrcweir // Umsetzung des Codes fuer String-Transport in SFX-Error
1788cdf0e10cSrcweir if( rMsg.Len() )
1789cdf0e10cSrcweir {
1790cdf0e10cSrcweir // very confusing, even though MakeErrorText sets up the error text
1791cdf0e10cSrcweir // seems that this is not used ( if rMsg already has content )
1792cdf0e10cSrcweir // In the case of VBA MakeErrorText also formats the error to be alittle more
1793cdf0e10cSrcweir // like vba ( adds an error number etc )
1794cdf0e10cSrcweir if ( SbiRuntime::isVBAEnabled() && ( code == SbERR_BASIC_COMPAT ) )
1795cdf0e10cSrcweir {
1796cdf0e10cSrcweir String aTmp = '\'';
1797cdf0e10cSrcweir aTmp += String::CreateFromInt32( SbxErrObject::getUnoErrObject()->getNumber() );
1798cdf0e10cSrcweir aTmp += String( RTL_CONSTASCII_USTRINGPARAM("\'\n") );
1799cdf0e10cSrcweir aTmp += GetSbData()->aErrMsg.Len() ? GetSbData()->aErrMsg : rMsg;
1800cdf0e10cSrcweir code = (sal_uIntPtr)*new StringErrorInfo( code, aTmp );
1801cdf0e10cSrcweir }
1802cdf0e10cSrcweir else
1803cdf0e10cSrcweir code = (sal_uIntPtr)*new StringErrorInfo( code, String(rMsg) );
1804cdf0e10cSrcweir }
1805cdf0e10cSrcweir
1806cdf0e10cSrcweir SetErrorData( code, l, c1, c2 );
1807cdf0e10cSrcweir if( GetSbData()->aErrHdl.IsSet() )
1808cdf0e10cSrcweir return (sal_Bool) GetSbData()->aErrHdl.Call( this );
1809cdf0e10cSrcweir else
1810cdf0e10cSrcweir return ErrorHdl();
1811cdf0e10cSrcweir }
1812cdf0e10cSrcweir
Error(SbError n)1813cdf0e10cSrcweir void StarBASIC::Error( SbError n )
1814cdf0e10cSrcweir {
1815cdf0e10cSrcweir Error( n, String() );
1816cdf0e10cSrcweir }
1817cdf0e10cSrcweir
Error(SbError n,const String & rMsg)1818cdf0e10cSrcweir void StarBASIC::Error( SbError n, const String& rMsg )
1819cdf0e10cSrcweir {
1820cdf0e10cSrcweir if( pINST )
1821cdf0e10cSrcweir pINST->Error( n, rMsg );
1822cdf0e10cSrcweir }
1823cdf0e10cSrcweir
FatalError(SbError n)1824cdf0e10cSrcweir void StarBASIC::FatalError( SbError n )
1825cdf0e10cSrcweir {
1826cdf0e10cSrcweir if( pINST )
1827cdf0e10cSrcweir pINST->FatalError( n );
1828cdf0e10cSrcweir }
1829cdf0e10cSrcweir
FatalError(SbError _errCode,const String & _details)1830cdf0e10cSrcweir void StarBASIC::FatalError( SbError _errCode, const String& _details )
1831cdf0e10cSrcweir {
1832cdf0e10cSrcweir if( pINST )
1833cdf0e10cSrcweir pINST->FatalError( _errCode, _details );
1834cdf0e10cSrcweir }
1835cdf0e10cSrcweir
GetErrBasic()1836cdf0e10cSrcweir SbError StarBASIC::GetErrBasic()
1837cdf0e10cSrcweir {
1838cdf0e10cSrcweir if( pINST )
1839cdf0e10cSrcweir return pINST->GetErr();
1840cdf0e10cSrcweir else
1841cdf0e10cSrcweir return 0;
1842cdf0e10cSrcweir }
1843cdf0e10cSrcweir
1844cdf0e10cSrcweir // #66536 Zusatz-Message fuer RTL-Funktion Error zugreifbar machen
GetErrorMsg()1845cdf0e10cSrcweir String StarBASIC::GetErrorMsg()
1846cdf0e10cSrcweir {
1847cdf0e10cSrcweir if( pINST )
1848cdf0e10cSrcweir return pINST->GetErrorMsg();
1849cdf0e10cSrcweir else
1850cdf0e10cSrcweir return String();
1851cdf0e10cSrcweir }
1852cdf0e10cSrcweir
GetErl()1853cdf0e10cSrcweir sal_uInt16 StarBASIC::GetErl()
1854cdf0e10cSrcweir {
1855cdf0e10cSrcweir if( pINST )
1856cdf0e10cSrcweir return pINST->GetErl();
1857cdf0e10cSrcweir else
1858cdf0e10cSrcweir return 0;
1859cdf0e10cSrcweir }
1860cdf0e10cSrcweir
ErrorHdl()1861cdf0e10cSrcweir sal_Bool __EXPORT StarBASIC::ErrorHdl()
1862cdf0e10cSrcweir {
1863cdf0e10cSrcweir return (sal_Bool) ( aErrorHdl.IsSet()
1864cdf0e10cSrcweir ? aErrorHdl.Call( this ) : sal_False );
1865cdf0e10cSrcweir }
1866cdf0e10cSrcweir
GetGlobalErrorHdl()1867cdf0e10cSrcweir Link StarBASIC::GetGlobalErrorHdl()
1868cdf0e10cSrcweir {
1869cdf0e10cSrcweir return GetSbData()->aErrHdl;
1870cdf0e10cSrcweir }
1871cdf0e10cSrcweir
SetGlobalErrorHdl(const Link & rLink)1872cdf0e10cSrcweir void StarBASIC::SetGlobalErrorHdl( const Link& rLink )
1873cdf0e10cSrcweir {
1874cdf0e10cSrcweir GetSbData()->aErrHdl = rLink;
1875cdf0e10cSrcweir }
1876cdf0e10cSrcweir
1877cdf0e10cSrcweir
GetGlobalBreakHdl()1878cdf0e10cSrcweir Link StarBASIC::GetGlobalBreakHdl()
1879cdf0e10cSrcweir {
1880cdf0e10cSrcweir return GetSbData()->aBreakHdl;
1881cdf0e10cSrcweir }
1882cdf0e10cSrcweir
SetGlobalBreakHdl(const Link & rLink)1883cdf0e10cSrcweir void StarBASIC::SetGlobalBreakHdl( const Link& rLink )
1884cdf0e10cSrcweir {
1885cdf0e10cSrcweir GetSbData()->aBreakHdl = rLink;
1886cdf0e10cSrcweir }
1887cdf0e10cSrcweir
getUnoListeners(void)1888cdf0e10cSrcweir SbxArrayRef StarBASIC::getUnoListeners( void )
1889cdf0e10cSrcweir {
1890cdf0e10cSrcweir if( !xUnoListeners.Is() )
1891cdf0e10cSrcweir xUnoListeners = new SbxArray();
1892cdf0e10cSrcweir return xUnoListeners;
1893cdf0e10cSrcweir }
1894cdf0e10cSrcweir
1895cdf0e10cSrcweir
1896cdf0e10cSrcweir /**************************************************************************
1897cdf0e10cSrcweir *
1898cdf0e10cSrcweir * Laden und Speichern
1899cdf0e10cSrcweir *
1900cdf0e10cSrcweir **************************************************************************/
1901cdf0e10cSrcweir
LoadData(SvStream & r,sal_uInt16 nVer)1902cdf0e10cSrcweir sal_Bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer )
1903cdf0e10cSrcweir {
1904cdf0e10cSrcweir if( !SbxObject::LoadData( r, nVer ) )
1905cdf0e10cSrcweir return sal_False;
1906cdf0e10cSrcweir
1907cdf0e10cSrcweir // #95459 Delete dialogs, otherwise endless recursion
1908cdf0e10cSrcweir // in SbxVarable::GetType() if dialogs are accessed
1909cdf0e10cSrcweir sal_uInt16 nObjCount = pObjs->Count();
1910cdf0e10cSrcweir SbxVariable** ppDeleteTab = new SbxVariable*[ nObjCount ];
1911cdf0e10cSrcweir sal_uInt16 nObj;
1912cdf0e10cSrcweir
1913cdf0e10cSrcweir for( nObj = 0 ; nObj < nObjCount ; nObj++ )
1914cdf0e10cSrcweir {
1915cdf0e10cSrcweir SbxVariable* pVar = pObjs->Get( nObj );
1916cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST( StarBASIC, pVar );
1917cdf0e10cSrcweir ppDeleteTab[nObj] = pBasic ? NULL : pVar;
1918cdf0e10cSrcweir }
1919cdf0e10cSrcweir for( nObj = 0 ; nObj < nObjCount ; nObj++ )
1920cdf0e10cSrcweir {
1921cdf0e10cSrcweir SbxVariable* pVar = ppDeleteTab[nObj];
1922cdf0e10cSrcweir if( pVar )
1923cdf0e10cSrcweir pObjs->Remove( pVar );
1924cdf0e10cSrcweir }
1925cdf0e10cSrcweir delete[] ppDeleteTab;
1926cdf0e10cSrcweir
1927cdf0e10cSrcweir sal_uInt16 nMod;
1928cdf0e10cSrcweir pModules->Clear();
1929cdf0e10cSrcweir r >> nMod;
1930cdf0e10cSrcweir for( sal_uInt16 i = 0; i < nMod; i++ )
1931cdf0e10cSrcweir {
1932cdf0e10cSrcweir SbModule* pMod = (SbModule*) SbxBase::Load( r );
1933cdf0e10cSrcweir if( !pMod )
1934cdf0e10cSrcweir return sal_False;
1935cdf0e10cSrcweir else if( pMod->ISA(SbJScriptModule) )
1936cdf0e10cSrcweir {
1937cdf0e10cSrcweir // Ref zuweisen, damit pMod deleted wird
1938cdf0e10cSrcweir SbModuleRef xRef = pMod;
1939cdf0e10cSrcweir }
1940cdf0e10cSrcweir else
1941cdf0e10cSrcweir {
1942cdf0e10cSrcweir pMod->SetParent( this );
1943cdf0e10cSrcweir pModules->Put( pMod, i );
1944cdf0e10cSrcweir }
1945cdf0e10cSrcweir }
1946cdf0e10cSrcweir // HACK fuer SFX-Mist!
1947cdf0e10cSrcweir SbxVariable* p = Find( String( RTL_CONSTASCII_USTRINGPARAM("FALSE") ), SbxCLASS_PROPERTY );
1948cdf0e10cSrcweir if( p )
1949cdf0e10cSrcweir Remove( p );
1950cdf0e10cSrcweir p = Find( String( RTL_CONSTASCII_USTRINGPARAM("TRUE") ), SbxCLASS_PROPERTY );
1951cdf0e10cSrcweir if( p )
1952cdf0e10cSrcweir Remove( p );
1953cdf0e10cSrcweir // Ende des Hacks!
1954cdf0e10cSrcweir // Suche ueber StarBASIC ist immer global
1955cdf0e10cSrcweir DBG_ASSERT( IsSet( SBX_GBLSEARCH ), "Basic ohne GBLSEARCH geladen" );
1956cdf0e10cSrcweir SetFlag( SBX_GBLSEARCH );
1957cdf0e10cSrcweir return sal_True;
1958cdf0e10cSrcweir }
1959cdf0e10cSrcweir
StoreData(SvStream & r) const1960cdf0e10cSrcweir sal_Bool StarBASIC::StoreData( SvStream& r ) const
1961cdf0e10cSrcweir {
1962cdf0e10cSrcweir if( !SbxObject::StoreData( r ) )
1963cdf0e10cSrcweir return sal_False;
1964cdf0e10cSrcweir r << (sal_uInt16) pModules->Count();
1965cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
1966cdf0e10cSrcweir {
1967cdf0e10cSrcweir SbModule* p = (SbModule*) pModules->Get( i );
1968cdf0e10cSrcweir if( !p->Store( r ) )
1969cdf0e10cSrcweir return sal_False;
1970cdf0e10cSrcweir }
1971cdf0e10cSrcweir return sal_True;
1972cdf0e10cSrcweir }
1973cdf0e10cSrcweir
LoadOldModules(SvStream &)1974cdf0e10cSrcweir sal_Bool StarBASIC::LoadOldModules( SvStream& )
1975cdf0e10cSrcweir {
1976cdf0e10cSrcweir return sal_False;
1977cdf0e10cSrcweir }
1978cdf0e10cSrcweir
GetUNOConstant(const sal_Char * _pAsciiName,::com::sun::star::uno::Any & aOut)1979cdf0e10cSrcweir bool StarBASIC::GetUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::uno::Any& aOut )
1980cdf0e10cSrcweir {
1981cdf0e10cSrcweir bool bRes = false;
1982cdf0e10cSrcweir ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( _pAsciiName ) );
1983cdf0e10cSrcweir SbUnoObject* pGlobs = dynamic_cast<SbUnoObject*>( Find( sVarName, SbxCLASS_DONTCARE ) );
1984cdf0e10cSrcweir if ( pGlobs )
1985cdf0e10cSrcweir {
1986cdf0e10cSrcweir aOut = pGlobs->getUnoAny();
1987cdf0e10cSrcweir bRes = true;
1988cdf0e10cSrcweir }
1989cdf0e10cSrcweir return bRes;
1990cdf0e10cSrcweir }
1991cdf0e10cSrcweir
GetModelFromBasic(SbxObject * pBasic)1992cdf0e10cSrcweir Reference< frame::XModel > StarBASIC::GetModelFromBasic( SbxObject* pBasic )
1993cdf0e10cSrcweir {
1994cdf0e10cSrcweir OSL_PRECOND( pBasic != NULL, "getModelFromBasic: illegal call!" );
1995cdf0e10cSrcweir if ( !pBasic )
1996cdf0e10cSrcweir return NULL;
1997cdf0e10cSrcweir
1998cdf0e10cSrcweir // look for the ThisComponent variable, first in the parent (which
1999cdf0e10cSrcweir // might be the document's Basic), then in the parent's parent (which might be
2000cdf0e10cSrcweir // the application Basic)
2001cdf0e10cSrcweir const ::rtl::OUString sThisComponent( RTL_CONSTASCII_USTRINGPARAM( "ThisComponent" ) );
2002cdf0e10cSrcweir SbxVariable* pThisComponent = NULL;
2003cdf0e10cSrcweir
2004cdf0e10cSrcweir SbxObject* pLookup = pBasic->GetParent();
2005cdf0e10cSrcweir while ( pLookup && !pThisComponent )
2006cdf0e10cSrcweir {
2007cdf0e10cSrcweir pThisComponent = pLookup->Find( sThisComponent, SbxCLASS_OBJECT );
2008cdf0e10cSrcweir pLookup = pLookup->GetParent();
2009cdf0e10cSrcweir }
2010cdf0e10cSrcweir if ( !pThisComponent )
2011cdf0e10cSrcweir {
2012cdf0e10cSrcweir OSL_TRACE("Failed to get ThisComponent");
2013cdf0e10cSrcweir // the application Basic, at the latest, should have this variable
2014cdf0e10cSrcweir return NULL;
2015cdf0e10cSrcweir }
2016cdf0e10cSrcweir
2017cdf0e10cSrcweir Any aThisComponentAny( sbxToUnoValue( pThisComponent ) );
2018cdf0e10cSrcweir Reference< frame::XModel > xModel( aThisComponentAny, UNO_QUERY );
2019cdf0e10cSrcweir if ( !xModel.is() )
2020cdf0e10cSrcweir {
2021cdf0e10cSrcweir // it's no XModel. Okay, ThisComponent nowadays is allowed to be a controller.
2022cdf0e10cSrcweir Reference< frame::XController > xController( aThisComponentAny, UNO_QUERY );
2023cdf0e10cSrcweir if ( xController.is() )
2024cdf0e10cSrcweir xModel = xController->getModel();
2025cdf0e10cSrcweir }
2026cdf0e10cSrcweir
2027cdf0e10cSrcweir if ( !xModel.is() )
2028cdf0e10cSrcweir return NULL;
2029cdf0e10cSrcweir
2030cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
2031cdf0e10cSrcweir OSL_TRACE("Have model ThisComponent points to url %s",
2032cdf0e10cSrcweir ::rtl::OUStringToOString( xModel->getURL(),
2033cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
2034cdf0e10cSrcweir #endif
2035cdf0e10cSrcweir
2036cdf0e10cSrcweir return xModel;
2037cdf0e10cSrcweir }
2038cdf0e10cSrcweir
2039cdf0e10cSrcweir
2040cdf0e10cSrcweir //========================================================================
2041cdf0e10cSrcweir // #118116 Implementation Collection object
2042cdf0e10cSrcweir
2043cdf0e10cSrcweir TYPEINIT1(BasicCollection,SbxObject)
2044cdf0e10cSrcweir
2045cdf0e10cSrcweir static const char pCountStr[] = "Count";
2046cdf0e10cSrcweir static const char pAddStr[] = "Add";
2047cdf0e10cSrcweir static const char pItemStr[] = "Item";
2048cdf0e10cSrcweir static const char pRemoveStr[] = "Remove";
2049cdf0e10cSrcweir static sal_uInt16 nCountHash = 0, nAddHash, nItemHash, nRemoveHash;
2050cdf0e10cSrcweir
2051cdf0e10cSrcweir SbxInfoRef BasicCollection::xAddInfo = NULL;
2052cdf0e10cSrcweir SbxInfoRef BasicCollection::xItemInfo = NULL;
2053cdf0e10cSrcweir
BasicCollection(const XubString & rClass)2054cdf0e10cSrcweir BasicCollection::BasicCollection( const XubString& rClass )
2055cdf0e10cSrcweir : SbxObject( rClass )
2056cdf0e10cSrcweir {
2057cdf0e10cSrcweir if( !nCountHash )
2058cdf0e10cSrcweir {
2059cdf0e10cSrcweir nCountHash = MakeHashCode( String::CreateFromAscii( pCountStr ) );
2060cdf0e10cSrcweir nAddHash = MakeHashCode( String::CreateFromAscii( pAddStr ) );
2061cdf0e10cSrcweir nItemHash = MakeHashCode( String::CreateFromAscii( pItemStr ) );
2062cdf0e10cSrcweir nRemoveHash = MakeHashCode( String::CreateFromAscii( pRemoveStr ) );
2063cdf0e10cSrcweir }
2064cdf0e10cSrcweir Initialize();
2065cdf0e10cSrcweir
2066cdf0e10cSrcweir }
2067cdf0e10cSrcweir
~BasicCollection()2068cdf0e10cSrcweir BasicCollection::~BasicCollection()
2069cdf0e10cSrcweir {}
2070cdf0e10cSrcweir
Clear()2071cdf0e10cSrcweir void BasicCollection::Clear()
2072cdf0e10cSrcweir {
2073cdf0e10cSrcweir SbxObject::Clear();
2074cdf0e10cSrcweir Initialize();
2075cdf0e10cSrcweir }
2076cdf0e10cSrcweir
Initialize()2077cdf0e10cSrcweir void BasicCollection::Initialize()
2078cdf0e10cSrcweir {
2079cdf0e10cSrcweir xItemArray = new SbxArray();
2080cdf0e10cSrcweir SetType( SbxOBJECT );
2081cdf0e10cSrcweir SetFlag( SBX_FIXED );
2082cdf0e10cSrcweir ResetFlag( SBX_WRITE );
2083cdf0e10cSrcweir SbxVariable* p;
2084cdf0e10cSrcweir p = Make( String::CreateFromAscii( pCountStr ), SbxCLASS_PROPERTY, SbxINTEGER );
2085cdf0e10cSrcweir p->ResetFlag( SBX_WRITE );
2086cdf0e10cSrcweir p->SetFlag( SBX_DONTSTORE );
2087cdf0e10cSrcweir p = Make( String::CreateFromAscii( pAddStr ), SbxCLASS_METHOD, SbxEMPTY );
2088cdf0e10cSrcweir p->SetFlag( SBX_DONTSTORE );
2089cdf0e10cSrcweir p = Make( String::CreateFromAscii( pItemStr ), SbxCLASS_METHOD, SbxVARIANT );
2090cdf0e10cSrcweir p->SetFlag( SBX_DONTSTORE );
2091cdf0e10cSrcweir p = Make( String::CreateFromAscii( pRemoveStr ), SbxCLASS_METHOD, SbxEMPTY );
2092cdf0e10cSrcweir p->SetFlag( SBX_DONTSTORE );
2093cdf0e10cSrcweir if ( !xAddInfo.Is() )
2094cdf0e10cSrcweir {
2095cdf0e10cSrcweir xAddInfo = new SbxInfo;
2096cdf0e10cSrcweir xAddInfo->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("Item") ), SbxVARIANT, SBX_READ );
2097cdf0e10cSrcweir xAddInfo->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("Key") ), SbxVARIANT, SBX_READ | SBX_OPTIONAL );
2098cdf0e10cSrcweir xAddInfo->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("Before") ), SbxVARIANT, SBX_READ | SBX_OPTIONAL );
2099cdf0e10cSrcweir xAddInfo->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("After") ), SbxVARIANT, SBX_READ | SBX_OPTIONAL );
2100cdf0e10cSrcweir }
2101cdf0e10cSrcweir if ( !xItemInfo.Is() )
2102cdf0e10cSrcweir {
2103cdf0e10cSrcweir xItemInfo = new SbxInfo;
2104cdf0e10cSrcweir xItemInfo->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("Index") ), SbxVARIANT, SBX_READ | SBX_OPTIONAL);
2105cdf0e10cSrcweir }
2106cdf0e10cSrcweir }
2107cdf0e10cSrcweir
Find(const XubString & rName,SbxClassType t)2108cdf0e10cSrcweir SbxVariable* BasicCollection::Find( const XubString& rName, SbxClassType t )
2109cdf0e10cSrcweir {
2110cdf0e10cSrcweir SbxVariable* pFind = SbxObject::Find( rName, t );
2111cdf0e10cSrcweir return pFind;
2112cdf0e10cSrcweir }
2113cdf0e10cSrcweir
SFX_NOTIFY(SfxBroadcaster & rCst,const TypeId & rId1,const SfxHint & rHint,const TypeId & rId2)2114cdf0e10cSrcweir void BasicCollection::SFX_NOTIFY( SfxBroadcaster& rCst, const TypeId& rId1,
2115cdf0e10cSrcweir const SfxHint& rHint, const TypeId& rId2 )
2116cdf0e10cSrcweir {
2117cdf0e10cSrcweir const SbxHint* p = PTR_CAST(SbxHint,&rHint);
2118cdf0e10cSrcweir if( p )
2119cdf0e10cSrcweir {
2120cdf0e10cSrcweir sal_uIntPtr nId = p->GetId();
2121cdf0e10cSrcweir sal_Bool bRead = sal_Bool( nId == SBX_HINT_DATAWANTED );
2122cdf0e10cSrcweir sal_Bool bWrite = sal_Bool( nId == SBX_HINT_DATACHANGED );
2123cdf0e10cSrcweir sal_Bool bRequestInfo = sal_Bool( nId == SBX_HINT_INFOWANTED );
2124cdf0e10cSrcweir SbxVariable* pVar = p->GetVar();
2125cdf0e10cSrcweir SbxArray* pArg = pVar->GetParameters();
2126cdf0e10cSrcweir XubString aVarName( pVar->GetName() );
2127cdf0e10cSrcweir if( bRead || bWrite )
2128cdf0e10cSrcweir {
2129cdf0e10cSrcweir if( pVar->GetHashCode() == nCountHash
2130cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pCountStr ) )
2131cdf0e10cSrcweir pVar->PutLong( xItemArray->Count32() );
2132cdf0e10cSrcweir else if( pVar->GetHashCode() == nAddHash
2133cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pAddStr ) )
2134cdf0e10cSrcweir CollAdd( pArg );
2135cdf0e10cSrcweir else if( pVar->GetHashCode() == nItemHash
2136cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pItemStr ) )
2137cdf0e10cSrcweir CollItem( pArg );
2138cdf0e10cSrcweir else if( pVar->GetHashCode() == nRemoveHash
2139cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pRemoveStr ) )
2140cdf0e10cSrcweir CollRemove( pArg );
2141cdf0e10cSrcweir else
2142cdf0e10cSrcweir SbxObject::SFX_NOTIFY( rCst, rId1, rHint, rId2 );
2143cdf0e10cSrcweir return;
2144cdf0e10cSrcweir }
2145cdf0e10cSrcweir else if ( bRequestInfo )
2146cdf0e10cSrcweir {
2147cdf0e10cSrcweir if( pVar->GetHashCode() == nAddHash
2148cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pAddStr ) )
2149cdf0e10cSrcweir pVar->SetInfo( xAddInfo );
2150cdf0e10cSrcweir else if( pVar->GetHashCode() == nItemHash
2151cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pItemStr ) )
2152cdf0e10cSrcweir pVar->SetInfo( xItemInfo );
2153cdf0e10cSrcweir }
2154cdf0e10cSrcweir }
2155cdf0e10cSrcweir SbxObject::SFX_NOTIFY( rCst, rId1, rHint, rId2 );
2156cdf0e10cSrcweir }
2157cdf0e10cSrcweir
implGetIndex(SbxVariable * pIndexVar)2158cdf0e10cSrcweir sal_Int32 BasicCollection::implGetIndex( SbxVariable* pIndexVar )
2159cdf0e10cSrcweir {
2160cdf0e10cSrcweir sal_Int32 nIndex = -1;
2161cdf0e10cSrcweir if( pIndexVar->GetType() == SbxSTRING )
2162cdf0e10cSrcweir nIndex = implGetIndexForName( pIndexVar->GetString() );
2163cdf0e10cSrcweir else
2164cdf0e10cSrcweir nIndex = pIndexVar->GetLong() - 1;
2165cdf0e10cSrcweir return nIndex;
2166cdf0e10cSrcweir }
2167cdf0e10cSrcweir
implGetIndexForName(const String & rName)2168cdf0e10cSrcweir sal_Int32 BasicCollection::implGetIndexForName( const String& rName )
2169cdf0e10cSrcweir {
2170cdf0e10cSrcweir sal_Int32 nIndex = -1;
2171cdf0e10cSrcweir sal_Int32 nCount = xItemArray->Count32();
2172cdf0e10cSrcweir sal_Int32 nNameHash = MakeHashCode( rName );
2173cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nCount ; i++ )
2174cdf0e10cSrcweir {
2175cdf0e10cSrcweir SbxVariable* pVar = xItemArray->Get32( i );
2176cdf0e10cSrcweir if( pVar->GetHashCode() == nNameHash &&
2177cdf0e10cSrcweir pVar->GetName().EqualsIgnoreCaseAscii( rName ) )
2178cdf0e10cSrcweir {
2179cdf0e10cSrcweir nIndex = i;
2180cdf0e10cSrcweir break;
2181cdf0e10cSrcweir }
2182cdf0e10cSrcweir }
2183cdf0e10cSrcweir return nIndex;
2184cdf0e10cSrcweir }
2185cdf0e10cSrcweir
CollAdd(SbxArray * pPar_)2186cdf0e10cSrcweir void BasicCollection::CollAdd( SbxArray* pPar_ )
2187cdf0e10cSrcweir {
2188cdf0e10cSrcweir sal_uInt16 nCount = pPar_->Count();
2189cdf0e10cSrcweir if( nCount < 2 || nCount > 5 )
2190cdf0e10cSrcweir {
2191cdf0e10cSrcweir SetError( SbxERR_WRONG_ARGS );
2192cdf0e10cSrcweir return;
2193cdf0e10cSrcweir }
2194cdf0e10cSrcweir
2195cdf0e10cSrcweir SbxVariable* pItem = pPar_->Get(1);
2196cdf0e10cSrcweir if( pItem )
2197cdf0e10cSrcweir {
2198cdf0e10cSrcweir int nNextIndex;
2199cdf0e10cSrcweir if( nCount < 4 )
2200cdf0e10cSrcweir {
2201cdf0e10cSrcweir nNextIndex = xItemArray->Count();
2202cdf0e10cSrcweir }
2203cdf0e10cSrcweir else
2204cdf0e10cSrcweir {
2205cdf0e10cSrcweir SbxVariable* pBefore = pPar_->Get(3);
2206cdf0e10cSrcweir if( nCount == 5 )
2207cdf0e10cSrcweir {
2208cdf0e10cSrcweir if( !( pBefore->IsErr() || ( pBefore->GetType() == SbxEMPTY ) ) )
2209cdf0e10cSrcweir {
2210cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT );
2211cdf0e10cSrcweir return;
2212cdf0e10cSrcweir }
2213cdf0e10cSrcweir SbxVariable* pAfter = pPar_->Get(4);
2214cdf0e10cSrcweir sal_Int32 nAfterIndex = implGetIndex( pAfter );
2215cdf0e10cSrcweir if( nAfterIndex == -1 )
2216cdf0e10cSrcweir {
2217cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT );
2218cdf0e10cSrcweir return;
2219cdf0e10cSrcweir }
2220cdf0e10cSrcweir nNextIndex = nAfterIndex + 1;
2221cdf0e10cSrcweir }
2222cdf0e10cSrcweir else // if( nCount == 4 )
2223cdf0e10cSrcweir {
2224cdf0e10cSrcweir sal_Int32 nBeforeIndex = implGetIndex( pBefore );
2225cdf0e10cSrcweir if( nBeforeIndex == -1 )
2226cdf0e10cSrcweir {
2227cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT );
2228cdf0e10cSrcweir return;
2229cdf0e10cSrcweir }
2230cdf0e10cSrcweir nNextIndex = nBeforeIndex;
2231cdf0e10cSrcweir }
2232cdf0e10cSrcweir }
2233cdf0e10cSrcweir
2234cdf0e10cSrcweir SbxVariableRef pNewItem = new SbxVariable( *pItem );
2235cdf0e10cSrcweir if( nCount >= 3 )
2236cdf0e10cSrcweir {
2237cdf0e10cSrcweir SbxVariable* pKey = pPar_->Get(2);
2238cdf0e10cSrcweir if( !( pKey->IsErr() || ( pKey->GetType() == SbxEMPTY ) ) )
2239cdf0e10cSrcweir {
2240cdf0e10cSrcweir if( pKey->GetType() != SbxSTRING )
2241cdf0e10cSrcweir {
2242cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT );
2243cdf0e10cSrcweir return;
2244cdf0e10cSrcweir }
2245cdf0e10cSrcweir String aKey = pKey->GetString();
2246cdf0e10cSrcweir if( implGetIndexForName( aKey ) != -1 )
2247cdf0e10cSrcweir {
2248cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT );
2249cdf0e10cSrcweir return;
2250cdf0e10cSrcweir }
2251cdf0e10cSrcweir pNewItem->SetName( aKey );
2252cdf0e10cSrcweir }
2253cdf0e10cSrcweir }
2254cdf0e10cSrcweir pNewItem->SetFlag( SBX_READWRITE );
2255cdf0e10cSrcweir xItemArray->Insert32( pNewItem, nNextIndex );
2256cdf0e10cSrcweir }
2257cdf0e10cSrcweir else
2258cdf0e10cSrcweir {
2259cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT );
2260cdf0e10cSrcweir return;
2261cdf0e10cSrcweir }
2262cdf0e10cSrcweir }
2263cdf0e10cSrcweir
CollItem(SbxArray * pPar_)2264cdf0e10cSrcweir void BasicCollection::CollItem( SbxArray* pPar_ )
2265cdf0e10cSrcweir {
2266cdf0e10cSrcweir if( pPar_->Count() != 2 )
2267cdf0e10cSrcweir {
2268cdf0e10cSrcweir SetError( SbxERR_WRONG_ARGS );
2269cdf0e10cSrcweir return;
2270cdf0e10cSrcweir }
2271cdf0e10cSrcweir SbxVariable* pRes = NULL;
2272cdf0e10cSrcweir SbxVariable* p = pPar_->Get( 1 );
2273cdf0e10cSrcweir sal_Int32 nIndex = implGetIndex( p );
2274cdf0e10cSrcweir if( nIndex >= 0 && nIndex < (sal_Int32)xItemArray->Count32() )
2275cdf0e10cSrcweir pRes = xItemArray->Get32( nIndex );
2276cdf0e10cSrcweir if( !pRes )
2277cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT );
2278cdf0e10cSrcweir else
2279cdf0e10cSrcweir *(pPar_->Get(0)) = *pRes;
2280cdf0e10cSrcweir }
2281cdf0e10cSrcweir
CollRemove(SbxArray * pPar_)2282cdf0e10cSrcweir void BasicCollection::CollRemove( SbxArray* pPar_ )
2283cdf0e10cSrcweir {
2284cdf0e10cSrcweir if( pPar_ == NULL || pPar_->Count() != 2 )
2285cdf0e10cSrcweir {
2286cdf0e10cSrcweir SetError( SbxERR_WRONG_ARGS );
2287cdf0e10cSrcweir return;
2288cdf0e10cSrcweir }
2289cdf0e10cSrcweir
2290cdf0e10cSrcweir SbxVariable* p = pPar_->Get( 1 );
2291cdf0e10cSrcweir sal_Int32 nIndex = implGetIndex( p );
2292cdf0e10cSrcweir if( nIndex >= 0 && nIndex < (sal_Int32)xItemArray->Count32() )
2293cdf0e10cSrcweir {
2294cdf0e10cSrcweir xItemArray->Remove32( nIndex );
2295cdf0e10cSrcweir
2296cdf0e10cSrcweir // Correct for stack if necessary
2297cdf0e10cSrcweir SbiInstance* pInst = pINST;
2298cdf0e10cSrcweir SbiRuntime* pRT = pInst ? pInst->pRun : NULL;
2299cdf0e10cSrcweir if( pRT )
2300cdf0e10cSrcweir {
2301cdf0e10cSrcweir SbiForStack* pStack = pRT->FindForStackItemForCollection( this );
2302cdf0e10cSrcweir if( pStack != NULL )
2303cdf0e10cSrcweir {
2304cdf0e10cSrcweir if( pStack->nCurCollectionIndex >= nIndex )
2305cdf0e10cSrcweir --pStack->nCurCollectionIndex;
2306cdf0e10cSrcweir }
2307cdf0e10cSrcweir }
2308cdf0e10cSrcweir }
2309cdf0e10cSrcweir else
2310cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT );
2311cdf0e10cSrcweir }
2312cdf0e10cSrcweir
2313