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 .
22 #include <basic/sbx.hxx>
23 #include <basic/sbxobj.hxx>
24 #include <basic/sbmod.hxx>
25 #include <rtl/ustring.hxx>
26 #include <tools/link.hxx>
27 #include <comphelper/errcode.hxx>
29 #include <basic/sbdef.hxx>
30 #include <basic/basicdllapi.h>
32 namespace com::sun::star::frame
{ class XModel
; }
33 namespace com::sun::star::script
{ struct ModuleInfo
; }
37 class BASIC_DLLPUBLIC StarBASIC final
: public SbxObject
39 friend class SbiScanner
;
40 friend class SbiExpression
; // Access to RTL
41 friend class SbiInstance
; // runtime instance
42 friend class SbiRuntime
; // currently running procedure
43 friend class DocBasicItem
;
45 SbModules pModules
; // List of all modules
46 SbxObjectRef pRtl
; // Runtime Library
47 SbxArrayRef xUnoListeners
; // Listener handled by CreateUnoListener
50 Link
<StarBASIC
*,bool> aErrorHdl
; // Error handler
51 Link
<StarBASIC
*,BasicDebugFlags
> aBreakHdl
; // Breakpoint handler
52 bool bNoRtl
; // if true: do not search RTL
53 bool bBreak
; // if true: Break, otherwise Step
58 SbxObjectRef pVBAGlobals
;
60 BASIC_DLLPRIVATE
void implClearDependingVarsOnDelete( StarBASIC
* pDeletedBasic
);
61 bool CError( ErrCode
, const OUString
&, sal_Int32
, sal_Int32
, sal_Int32
);
62 BASIC_DLLPRIVATE
bool RTError( ErrCode
, const OUString
& rMsg
, sal_Int32
, sal_Int32
, sal_Int32
);
63 BASIC_DLLPRIVATE BasicDebugFlags
BreakPoint( sal_Int32 nLine
, sal_Int32 nCol1
, sal_Int32 nCol2
);
64 BASIC_DLLPRIVATE BasicDebugFlags
StepPoint( sal_Int32 nLine
, sal_Int32 nCol1
, sal_Int32 nCol2
);
65 virtual bool LoadData( SvStream
&, sal_uInt16
) override
;
66 virtual std::pair
<bool, sal_uInt32
> StoreData( SvStream
& ) const override
;
68 BasicDebugFlags
BreakHdl();
69 virtual ~StarBASIC() override
;
73 SBX_DECL_PERSIST_NODATA(SBXID_BASIC
,1);
75 StarBASIC( StarBASIC
* pParent
= nullptr, bool bIsDocBasic
= false );
77 // #51727 SetModified overridden so that the Modified-State is
78 // not delivered to Parent.
79 virtual void SetModified( bool ) override
;
81 virtual void Insert( SbxVariable
* ) override
;
82 using SbxObject::Remove
;
83 virtual void Remove( SbxVariable
* ) override
;
84 virtual void Clear() override
;
87 SbModule
* MakeModule( const OUString
& rName
, const OUString
& rSrc
);
88 SbModule
* MakeModule( const OUString
& rName
, const css::script::ModuleInfo
& mInfo
, const OUString
& rSrc
);
90 static void Error( ErrCode
, const OUString
& rMsg
= {} );
91 static void FatalError( ErrCode
);
92 static void FatalError( ErrCode
, const OUString
& rMsg
);
93 static bool IsRunning();
94 static ErrCode
GetErrBasic();
95 // #66536 make additional message accessible by RTL function Error
96 static const OUString
& GetErrorMsg();
97 static sal_Int32
GetErl();
99 virtual SbxVariable
* Find( const OUString
&, SbxClassType
) override
;
100 virtual bool Call( const OUString
&, SbxArray
* = nullptr ) override
;
102 SbModules
& GetModules() { return pModules
; }
103 SbxObject
* GetRtl() { return pRtl
.get(); }
104 SbModule
* FindModule( std::u16string_view
);
105 // Run init code of all modules (including the inserted Doc-Basics)
106 void InitAllModules( StarBASIC
const * pBasicNotToInit
= nullptr );
107 void DeInitAllModules();
108 void ClearAllModuleVars();
110 // Calls for error and break handler
111 static sal_uInt16
GetLine();
112 static sal_uInt16
GetCol1();
113 static sal_uInt16
GetCol2();
114 static void SetErrorData( const ErrCodeMsg
& nCode
, sal_uInt16 nLine
,
115 sal_uInt16 nCol1
, sal_uInt16 nCol2
);
117 // Specific to error handler
118 static void MakeErrorText( ErrCode
, std::u16string_view aMsg
);
119 static const OUString
& GetErrorText();
120 static ErrCodeMsg
const & GetErrorCode();
121 static sal_uInt16
GetVBErrorCode( ErrCode nError
);
122 static ErrCode
GetSfxFromVBError( sal_uInt16 nError
);
123 bool IsBreak() const { return bBreak
; }
125 static Link
<StarBASIC
*,bool> const & GetGlobalErrorHdl();
126 static void SetGlobalErrorHdl( const Link
<StarBASIC
*,bool>& rNewHdl
);
128 static void SetGlobalBreakHdl( const Link
<StarBASIC
*,BasicDebugFlags
>& rNewHdl
);
130 SbxArrayRef
const & getUnoListeners();
132 static SbxBase
* FindSBXInCurrentScope( const OUString
& rName
);
133 static SbMethod
* GetActiveMethod( sal_uInt16 nLevel
= 0 );
134 static SbModule
* GetActiveModule();
135 void SetVBAEnabled( bool bEnabled
);
136 bool isVBAEnabled() const;
138 const SbxObjectRef
& getRTL() const { return pRtl
; }
139 bool IsDocBasic() const { return bDocBasic
; }
140 SbxVariable
* VBAFind( const OUString
& rName
, SbxClassType t
);
141 bool GetUNOConstant( const OUString
& rName
, css::uno::Any
& aOut
);
142 void QuitAndExitApplication();
143 bool IsQuitApplication() const { return bQuit
; };
145 SbxObject
* getVBAGlobals( );
147 static css::uno::Reference
< css::frame::XModel
>
148 GetModelFromBasic( SbxObject
* pBasic
);
150 static void DetachAllDocBasicItems();
153 typedef tools::SvRef
<StarBASIC
> StarBASICRef
;
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */