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