1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_BASIC_SBSTAR_HXX
21 #define INCLUDED_BASIC_SBSTAR_HXX
23 #include <basic/sbx.hxx>
24 #include <basic/sbxobj.hxx>
25 #include <rtl/ustring.hxx>
26 #include <osl/mutex.hxx>
27 #include <tools/link.hxx>
29 #include <basic/sbdef.hxx>
30 #include <basic/sberrors.hxx>
31 #include <com/sun/star/script/ModuleInfo.hpp>
32 #include <com/sun/star/frame/XModel.hpp>
33 #include <basic/basicdllapi.h>
35 class SbModule
; // completed module
36 class SbiInstance
; // runtime instance
37 class SbiRuntime
; // currently running procedure
38 class SbiImage
; // compiled image
39 class BasicLibInfo
; // info block for basic manager
44 class BASIC_DLLPUBLIC StarBASIC
: public SbxObject
46 friend class SbiScanner
;
47 friend class SbiExpression
; // Access to RTL
48 friend class SbiInstance
;
49 friend class SbiRuntime
;
50 friend class DocBasicItem
;
52 SbxArrayRef pModules
; // List of all modules
53 SbxObjectRef pRtl
; // Runtime Library
54 SbxArrayRef xUnoListeners
; // Listener handled by CreateUnoListener
57 Link
<StarBASIC
*,bool> aErrorHdl
; // Error handler
58 Link
<StarBASIC
*,sal_uInt16
> aBreakHdl
; // Breakpoint handler
59 bool bNoRtl
; // if true: do not search RTL
60 bool bBreak
; // if true: Break, otherwise Step
63 BasicLibInfo
* pLibInfo
; // Info block for basic manager
66 SbxObjectRef pVBAGlobals
;
67 BASIC_DLLPRIVATE SbxObject
* getVBAGlobals( );
69 BASIC_DLLPRIVATE
void implClearDependingVarsOnDelete( StarBASIC
* pDeletedBasic
);
72 bool CError( SbError
, const OUString
&, sal_Int32
, sal_Int32
, sal_Int32
);
74 BASIC_DLLPRIVATE
bool RTError( SbError
, sal_Int32
, sal_Int32
, sal_Int32
);
75 BASIC_DLLPRIVATE
bool RTError( SbError
, const OUString
& rMsg
, sal_Int32
, sal_Int32
, sal_Int32
);
76 BASIC_DLLPRIVATE sal_uInt16
BreakPoint( sal_Int32 nLine
, sal_Int32 nCol1
, sal_Int32 nCol2
);
77 BASIC_DLLPRIVATE sal_uInt16
StepPoint( sal_Int32 nLine
, sal_Int32 nCol1
, sal_Int32 nCol2
);
78 virtual bool LoadData( SvStream
&, sal_uInt16
) SAL_OVERRIDE
;
79 virtual bool StoreData( SvStream
& ) const SAL_OVERRIDE
;
83 sal_uInt16
BreakHdl();
88 SBX_DECL_PERSIST_NODATA(SBXCR_SBX
,SBXID_BASIC
,1);
91 StarBASIC( StarBASIC
* pParent
= NULL
, bool bIsDocBasic
= false );
93 // #51727 SetModified overridden so that the Modfied-State is
94 // not delivered to Parent.
95 virtual void SetModified( bool ) SAL_OVERRIDE
;
97 void* operator new( size_t );
98 void operator delete( void* );
100 virtual void Insert( SbxVariable
* ) SAL_OVERRIDE
;
101 using SbxObject::Remove
;
102 virtual void Remove( SbxVariable
* ) SAL_OVERRIDE
;
103 virtual void Clear() SAL_OVERRIDE
;
105 BasicLibInfo
* GetLibInfo() { return pLibInfo
; }
106 void SetLibInfo( BasicLibInfo
* p
) { pLibInfo
= p
; }
108 // Compiler-Interface
109 SbModule
* MakeModule( const OUString
& rName
, const OUString
& rSrc
);
110 SbModule
* MakeModule32( const OUString
& rName
, const OUString
& rSrc
);
111 SbModule
* MakeModule32( const OUString
& rName
, const com::sun::star::script::ModuleInfo
& mInfo
, const OUString
& rSrc
);
112 static bool Compile( SbModule
* );
114 static void Error( SbError
);
115 static void Error( SbError
, const OUString
& rMsg
);
116 static void FatalError( SbError
);
117 static void FatalError( SbError
, const OUString
& rMsg
);
118 static bool IsRunning();
119 static SbError
GetErrBasic();
120 // #66536 make additional message accessible by RTL function Error
121 static OUString
GetErrorMsg();
122 static sal_Int32
GetErl();
124 virtual SbxVariable
* Find( const OUString
&, SbxClassType
) SAL_OVERRIDE
;
125 virtual bool Call( const OUString
&, SbxArray
* = NULL
) SAL_OVERRIDE
;
127 SbxArray
* GetModules() { return pModules
; }
128 SbxObject
* GetRtl() { return pRtl
; }
129 SbModule
* FindModule( const OUString
& );
130 // Run init code of all modules (including the inserted Doc-Basics)
131 void InitAllModules( StarBASIC
* pBasicNotToInit
= NULL
);
132 void DeInitAllModules();
133 void ClearAllModuleVars();
135 // Calls for error and break handler
136 static sal_uInt16
GetLine();
137 static sal_uInt16
GetCol1();
138 static sal_uInt16
GetCol2();
139 static void SetErrorData( SbError nCode
, sal_uInt16 nLine
,
140 sal_uInt16 nCol1
, sal_uInt16 nCol2
);
142 // Specific to error handler
143 static void MakeErrorText( SbError
, const OUString
& aMsg
);
144 static const OUString
& GetErrorText();
145 static SbError
GetErrorCode();
146 static bool IsCompilerError();
147 static sal_uInt16
GetVBErrorCode( SbError nError
);
148 static SbError
GetSfxFromVBError( sal_uInt16 nError
);
149 bool IsBreak() const { return bBreak
; }
151 static Link
<StarBASIC
*,bool> GetGlobalErrorHdl();
152 static void SetGlobalErrorHdl( const Link
<StarBASIC
*,bool>& rNewHdl
);
153 Link
<StarBASIC
*,bool> GetErrorHdl() const { return aErrorHdl
; }
154 void SetErrorHdl( const Link
<StarBASIC
*,bool>& r
) { aErrorHdl
= r
; }
156 static void SetGlobalBreakHdl( const Link
<StarBASIC
*,sal_uInt16
>& rNewHdl
);
157 Link
<StarBASIC
*,sal_uInt16
> GetBreakHdl() const { return aBreakHdl
; }
158 void SetBreakHdl( const Link
<StarBASIC
*,sal_uInt16
>& r
) { aBreakHdl
= r
; }
160 SbxArrayRef
getUnoListeners();
162 static SbxBase
* FindSBXInCurrentScope( const OUString
& rName
);
163 static SbMethod
* GetActiveMethod( sal_uInt16 nLevel
= 0 );
164 static SbModule
* GetActiveModule();
165 void SetVBAEnabled( bool bEnabled
);
168 SbxObjectRef
getRTL() { return pRtl
; }
169 bool IsDocBasic() { return bDocBasic
; }
170 SbxVariable
* VBAFind( const OUString
& rName
, SbxClassType t
);
171 bool GetUNOConstant( const sal_Char
* _pAsciiName
, ::com::sun::star::uno::Any
& aOut
);
172 void QuitAndExitApplication();
173 bool IsQuitApplication() { return bQuit
; };
175 static ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
176 GetModelFromBasic( SbxObject
* pBasic
);
178 static void DetachAllDocBasicItems();
181 typedef tools::SvRef
<StarBASIC
> StarBASICRef
;
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */