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