xref: /aoo41x/main/basic/inc/basic/sbstar.hxx (revision 234bd5c5)
1*234bd5c5SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*234bd5c5SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*234bd5c5SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*234bd5c5SAndrew Rist  * distributed with this work for additional information
6*234bd5c5SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*234bd5c5SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*234bd5c5SAndrew Rist  * "License"); you may not use this file except in compliance
9*234bd5c5SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*234bd5c5SAndrew Rist  *
11*234bd5c5SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*234bd5c5SAndrew Rist  *
13*234bd5c5SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*234bd5c5SAndrew Rist  * software distributed under the License is distributed on an
15*234bd5c5SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*234bd5c5SAndrew Rist  * KIND, either express or implied.  See the License for the
17*234bd5c5SAndrew Rist  * specific language governing permissions and limitations
18*234bd5c5SAndrew Rist  * under the License.
19*234bd5c5SAndrew Rist  *
20*234bd5c5SAndrew Rist  *************************************************************/
21*234bd5c5SAndrew Rist 
22*234bd5c5SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _SB_SBSTAR_HXX
25cdf0e10cSrcweir #define _SB_SBSTAR_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <basic/sbx.hxx>
28cdf0e10cSrcweir #include <basic/sbxobj.hxx>
29cdf0e10cSrcweir #ifndef _RTL_USTRING_HXX
30cdf0e10cSrcweir #include <rtl/ustring.hxx>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include <osl/mutex.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <basic/sbdef.hxx>
35cdf0e10cSrcweir #include <basic/sberrors.hxx>
36cdf0e10cSrcweir #include <com/sun/star/script/ModuleInfo.hpp>
37cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir class SbModule;                     // completed module
40cdf0e10cSrcweir class SbiInstance;                  // runtime instance
41cdf0e10cSrcweir class SbiRuntime;                   // currently running procedure
42cdf0e10cSrcweir class SbiImage;                     // compiled image
43cdf0e10cSrcweir class BasicLibInfo;                 // info block for basic manager
44cdf0e10cSrcweir class SbTextPortions;
45cdf0e10cSrcweir class SbMethod;
46cdf0e10cSrcweir class BasicManager;
47cdf0e10cSrcweir class DocBasicItem;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir class StarBASICImpl;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir class StarBASIC : public SbxObject
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	friend class SbiScanner;
54cdf0e10cSrcweir 	friend class SbiExpression; // Access to RTL
55cdf0e10cSrcweir 	friend class SbiInstance;
56cdf0e10cSrcweir 	friend class SbiRuntime;
57cdf0e10cSrcweir 	friend class DocBasicItem;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	StarBASICImpl*	mpStarBASICImpl;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	SbxArrayRef		pModules;               // List of all modules
62cdf0e10cSrcweir 	SbxObjectRef	pRtl;				// Runtime Library
63cdf0e10cSrcweir 	SbxArrayRef		xUnoListeners;          // Listener handled by CreateUnoListener
64cdf0e10cSrcweir 
65cdf0e10cSrcweir    // Handler-Support:
66cdf0e10cSrcweir 	Link			aErrorHdl;              // Error handler
67cdf0e10cSrcweir 	Link			aBreakHdl;              // Breakpoint handler
68cdf0e10cSrcweir 	sal_Bool			bNoRtl;                 // if sal_True: do not search RTL
69cdf0e10cSrcweir 	sal_Bool			bBreak;                 // if sal_True: Break, otherwise Step
70cdf0e10cSrcweir 	sal_Bool			bDocBasic;
71cdf0e10cSrcweir 	sal_Bool			bVBAEnabled;
72cdf0e10cSrcweir 	BasicLibInfo*	pLibInfo;			// Info block for basic manager
73cdf0e10cSrcweir 	SbLanguageMode	eLanguageMode;		// LanguageMode of the basic object
74cdf0e10cSrcweir 	sal_Bool			bQuit;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	SbxObjectRef pVBAGlobals;
77cdf0e10cSrcweir 	SbxObject* getVBAGlobals( );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	void implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir protected:
82cdf0e10cSrcweir 	sal_Bool 			CError( SbError, const String&, xub_StrLen, xub_StrLen, xub_StrLen );
83cdf0e10cSrcweir private:
84cdf0e10cSrcweir 	sal_Bool 			RTError( SbError, xub_StrLen, xub_StrLen, xub_StrLen );
85cdf0e10cSrcweir 	sal_Bool 			RTError( SbError, const String& rMsg, xub_StrLen, xub_StrLen, xub_StrLen );
86cdf0e10cSrcweir 	sal_uInt16 			BreakPoint( xub_StrLen nLine, xub_StrLen nCol1, xub_StrLen nCol2 );
87cdf0e10cSrcweir 	sal_uInt16 			StepPoint( xub_StrLen nLine, xub_StrLen nCol1, xub_StrLen nCol2 );
88cdf0e10cSrcweir 	virtual sal_Bool LoadData( SvStream&, sal_uInt16 );
89cdf0e10cSrcweir 	virtual sal_Bool StoreData( SvStream& ) const;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir protected:
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	virtual	sal_Bool  	ErrorHdl();
94cdf0e10cSrcweir 	virtual	sal_uInt16	BreakHdl();
95cdf0e10cSrcweir 	virtual ~StarBASIC();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir public:
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_BASIC,1);
100cdf0e10cSrcweir 	TYPEINFO();
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	StarBASIC( StarBASIC* pParent = NULL, sal_Bool bIsDocBasic = sal_False );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	// #51727 SetModified overridden so that the Modfied-State is
105cdf0e10cSrcweir         // not delivered to Parent.
106cdf0e10cSrcweir 	virtual void SetModified( sal_Bool );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	void* operator 	new( size_t );
109cdf0e10cSrcweir 	void operator 	delete( void* );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	virtual void    Insert( SbxVariable* );
112cdf0e10cSrcweir 	using SbxObject::Remove;
113cdf0e10cSrcweir 	virtual void    Remove( SbxVariable* );
114cdf0e10cSrcweir 	virtual void	Clear();
115cdf0e10cSrcweir 
GetLibInfo()116cdf0e10cSrcweir 	BasicLibInfo*	GetLibInfo()					{ return pLibInfo;	}
SetLibInfo(BasicLibInfo * p)117cdf0e10cSrcweir 	void			SetLibInfo( BasicLibInfo* p )   { pLibInfo = p;		}
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	// Compiler-Interface
120cdf0e10cSrcweir 	SbModule*   	MakeModule( const String& rName, const String& rSrc );
121cdf0e10cSrcweir     SbModule*   	MakeModule32( const String& rName, const ::rtl::OUString& rSrc );
122cdf0e10cSrcweir     SbModule*       MakeModule32( const String& rName, const com::sun::star::script::ModuleInfo& mInfo, const ::rtl::OUString& rSrc );
123cdf0e10cSrcweir 	sal_Bool			Compile( SbModule* );
124cdf0e10cSrcweir 	sal_Bool 			Disassemble( SbModule*, String& rText );
125cdf0e10cSrcweir 	static void 	Stop();
126cdf0e10cSrcweir 	static void 	Error( SbError );
127cdf0e10cSrcweir 	static void 	Error( SbError, const String& rMsg );
128cdf0e10cSrcweir 	static void 	FatalError( SbError );
129cdf0e10cSrcweir 	static void 	FatalError( SbError, const String& rMsg );
130cdf0e10cSrcweir 	static sal_Bool 	IsRunning();
131cdf0e10cSrcweir 	static SbError 	GetErrBasic();
132cdf0e10cSrcweir 	// #66536 make additional message accessible by RTL function Error
133cdf0e10cSrcweir 	static String	GetErrorMsg();
134cdf0e10cSrcweir 	static xub_StrLen GetErl();
135cdf0e10cSrcweir 	// Highlighting
136cdf0e10cSrcweir 	void 			Highlight( const String& rSrc, SbTextPortions& rList );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	virtual SbxVariable* Find( const String&, SbxClassType );
139cdf0e10cSrcweir 	virtual sal_Bool Call( const String&, SbxArray* = NULL );
140cdf0e10cSrcweir 
GetModules()141cdf0e10cSrcweir 	SbxArray*		GetModules() { return pModules; }
GetRtl()142cdf0e10cSrcweir 	SbxObject*		GetRtl()	 { return pRtl;		}
143cdf0e10cSrcweir 	SbModule*		FindModule( const String& );
144cdf0e10cSrcweir 	// Run init code of all modules (including the inserted Doc-Basics)
145cdf0e10cSrcweir 	void			InitAllModules( StarBASIC* pBasicNotToInit = NULL );
146cdf0e10cSrcweir 	void			DeInitAllModules( void );
147cdf0e10cSrcweir 	void			ClearAllModuleVars( void );
148cdf0e10cSrcweir 	void			ActivateObject( const String*, sal_Bool );
149cdf0e10cSrcweir 	sal_Bool 			LoadOldModules( SvStream& );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	// #43011 For TestTool; deletes global vars
152cdf0e10cSrcweir 	void			ClearGlobalVars( void );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	// Calls for error and break handler
155cdf0e10cSrcweir 	static sal_uInt16	GetLine();
156cdf0e10cSrcweir 	static sal_uInt16	GetCol1();
157cdf0e10cSrcweir 	static sal_uInt16	GetCol2();
158cdf0e10cSrcweir 	static void		SetErrorData( SbError nCode, sal_uInt16 nLine,
159cdf0e10cSrcweir 								  sal_uInt16 nCol1, sal_uInt16 nCol2 );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	// Specific to error handler
162cdf0e10cSrcweir 	static void		MakeErrorText( SbError, const String& aMsg );
163cdf0e10cSrcweir 	static const	String&	GetErrorText();
164cdf0e10cSrcweir 	static SbError	GetErrorCode();
165cdf0e10cSrcweir 	static sal_Bool		IsCompilerError();
166cdf0e10cSrcweir 	static sal_uInt16	GetVBErrorCode( SbError nError );
167cdf0e10cSrcweir 	static SbError	GetSfxFromVBError( sal_uInt16 nError );
168cdf0e10cSrcweir 	static void		SetGlobalLanguageMode( SbLanguageMode eLangMode );
169cdf0e10cSrcweir 	static SbLanguageMode GetGlobalLanguageMode();
170cdf0e10cSrcweir 	// Local settings
SetLanguageMode(SbLanguageMode eLangMode)171cdf0e10cSrcweir 	void SetLanguageMode( SbLanguageMode eLangMode )
172cdf0e10cSrcweir 		{ eLanguageMode = eLangMode; }
173cdf0e10cSrcweir 	SbLanguageMode GetLanguageMode();
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	// Specific for break handler
IsBreak() const176cdf0e10cSrcweir 	sal_Bool   			IsBreak() const				{ return bBreak; }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	static Link 	GetGlobalErrorHdl();
179cdf0e10cSrcweir 	static void 	SetGlobalErrorHdl( const Link& rNewHdl );
GetErrorHdl() const180cdf0e10cSrcweir 	Link 			GetErrorHdl() const { return aErrorHdl; }
SetErrorHdl(const Link & r)181cdf0e10cSrcweir 	void 			SetErrorHdl( const Link& r ) { aErrorHdl = r; }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	static Link 	GetGlobalBreakHdl();
184cdf0e10cSrcweir 	static void 	SetGlobalBreakHdl( const Link& rNewHdl );
GetBreakHdl() const185cdf0e10cSrcweir 	Link 			GetBreakHdl() const { return aBreakHdl; }
SetBreakHdl(const Link & r)186cdf0e10cSrcweir 	void 			SetBreakHdl( const Link& r ) { aBreakHdl = r; }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     SbxArrayRef		getUnoListeners( void );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	static SbxBase*	FindSBXInCurrentScope( const String& rName );
191cdf0e10cSrcweir 	static SbxVariable*	FindVarInCurrentScopy
192cdf0e10cSrcweir 					( const String& rName, sal_uInt16& rStatus );
193cdf0e10cSrcweir 	static SbMethod* GetActiveMethod( sal_uInt16 nLevel = 0 );
194cdf0e10cSrcweir 	static SbModule* GetActiveModule();
195cdf0e10cSrcweir 	void SetVBAEnabled( sal_Bool bEnabled );
196cdf0e10cSrcweir 	sal_Bool isVBAEnabled();
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	// #60175 sal_True: SFX-Resource is not displayed on basic errors
199cdf0e10cSrcweir 	static void StaticSuppressSfxResource( sal_Bool bSuppress );
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	// #91147 sal_True: Reschedule is enabled (default>, sal_False: No reschedule
202cdf0e10cSrcweir 	static void StaticEnableReschedule( sal_Bool bReschedule );
203cdf0e10cSrcweir 
getRTL(void)204cdf0e10cSrcweir 	SbxObjectRef getRTL( void ) { return pRtl; }
IsDocBasic()205cdf0e10cSrcweir 	sal_Bool IsDocBasic() { return bDocBasic; }
206cdf0e10cSrcweir 	SbxVariable* VBAFind( const String& rName, SbxClassType t );
207cdf0e10cSrcweir 	bool GetUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::uno::Any& aOut );
208cdf0e10cSrcweir 	void QuitAndExitApplication();
IsQuitApplication()209cdf0e10cSrcweir 	sal_Bool IsQuitApplication() { return bQuit; };
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     static ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
212cdf0e10cSrcweir         GetModelFromBasic( SbxObject* pBasic );
213cdf0e10cSrcweir };
214cdf0e10cSrcweir 
215cdf0e10cSrcweir #ifndef __SB_SBSTARBASICREF_HXX
216cdf0e10cSrcweir #define __SB_SBSTARBASICREF_HXX
217cdf0e10cSrcweir 
218cdf0e10cSrcweir SV_DECL_IMPL_REF(StarBASIC)
219cdf0e10cSrcweir 
220cdf0e10cSrcweir #endif
221cdf0e10cSrcweir 
222cdf0e10cSrcweir #endif
223cdf0e10cSrcweir 
224