summaryrefslogtreecommitdiffstats
path: root/include/basic/sbstar.hxx
blob: 7ff6a138123ef8857da5e3f3f09ae4b9e07ca559 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_BASIC_SBSTAR_HXX
#define INCLUDED_BASIC_SBSTAR_HXX

#include <basic/sbx.hxx>
#include <basic/sbxobj.hxx>
#include <basic/sbmod.hxx>
#include <rtl/ustring.hxx>
#include <tools/link.hxx>

#include <basic/sbdef.hxx>
#include <basic/basicdllapi.h>

namespace com::sun::star::frame { class XModel; }
namespace com::sun::star::script { struct ModuleInfo; }

class SbMethod;

class BASIC_DLLPUBLIC StarBASIC : public SbxObject
{
    friend class SbiScanner;
    friend class SbiExpression; // Access to RTL
    friend class SbiInstance;   // runtime instance
    friend class SbiRuntime;    // currently running procedure
    friend class DocBasicItem;

    SbModules       pModules;               // List of all modules
    SbxObjectRef    pRtl;               // Runtime Library
    SbxArrayRef     xUnoListeners;          // Listener handled by CreateUnoListener

   // Handler-Support:
    Link<StarBASIC*,bool>            aErrorHdl;              // Error handler
    Link<StarBASIC*,BasicDebugFlags> aBreakHdl;              // Breakpoint handler
    bool            bNoRtl;                 // if true: do not search RTL
    bool            bBreak;                 // if true: Break, otherwise Step
    bool            bDocBasic;
    bool            bVBAEnabled;
    bool            bQuit;

    SbxObjectRef pVBAGlobals;

    BASIC_DLLPRIVATE void implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic );

protected:
    bool                                CError( ErrCode, const OUString&, sal_Int32, sal_Int32, sal_Int32 );
private:
    BASIC_DLLPRIVATE bool               RTError( ErrCode, const OUString& rMsg, sal_Int32, sal_Int32, sal_Int32 );
    BASIC_DLLPRIVATE BasicDebugFlags    BreakPoint( sal_Int32 nLine, sal_Int32 nCol1, sal_Int32 nCol2 );
    BASIC_DLLPRIVATE BasicDebugFlags    StepPoint( sal_Int32 nLine, sal_Int32 nCol1, sal_Int32 nCol2 );
    virtual bool LoadData( SvStream&, sal_uInt16 ) override;
    virtual bool StoreData( SvStream& ) const override;

protected:
    bool             ErrorHdl();
    BasicDebugFlags  BreakHdl();
    virtual ~StarBASIC() override;

public:

    SBX_DECL_PERSIST_NODATA(SBXID_BASIC,1);

    StarBASIC( StarBASIC* pParent = nullptr, bool bIsDocBasic = false );

    // #51727 SetModified overridden so that the Modified-State is
        // not delivered to Parent.
    virtual void SetModified( bool ) override;

    virtual void    Insert( SbxVariable* ) override;
    using SbxObject::Remove;
    virtual void    Remove( SbxVariable* ) override;
    virtual void    Clear() override;

    // Compiler-Interface
    SbModule*       MakeModule( const OUString& rName, const OUString& rSrc );
    SbModule*       MakeModule( const OUString& rName, const css::script::ModuleInfo& mInfo, const OUString& rSrc );
    static void     Stop();
    static void     Error( ErrCode );
    static void     Error( ErrCode, const OUString& rMsg );
    static void     FatalError( ErrCode );
    static void     FatalError( ErrCode, const OUString& rMsg );
    static bool     IsRunning();
    static ErrCode  GetErrBasic();
    // #66536 make additional message accessible by RTL function Error
    static OUString GetErrorMsg();
    static sal_Int32 GetErl();

    virtual SbxVariable* Find( const OUString&, SbxClassType ) override;
    virtual bool Call( const OUString&, SbxArray* = nullptr ) override;

    SbModules&      GetModules() { return pModules; }
    SbxObject*      GetRtl()     { return pRtl.get();     }
    SbModule*       FindModule( const OUString& );
    // Run init code of all modules (including the inserted Doc-Basics)
    void            InitAllModules( StarBASIC const * pBasicNotToInit = nullptr );
    void            DeInitAllModules();
    void            ClearAllModuleVars();

    // Calls for error and break handler
    static sal_uInt16 GetLine();
    static sal_uInt16 GetCol1();
    static sal_uInt16 GetCol2();
    static void     SetErrorData( ErrCode nCode, sal_uInt16 nLine,
                                  sal_uInt16 nCol1, sal_uInt16 nCol2 );

    // Specific to error handler
    static void     MakeErrorText( ErrCode, const OUString& aMsg );
    static const    OUString& GetErrorText();
    static ErrCode const & GetErrorCode();
    static sal_uInt16 GetVBErrorCode( ErrCode nError );
    static ErrCode  GetSfxFromVBError( sal_uInt16 nError );
    bool            IsBreak() const             { return bBreak; }

    static Link<StarBASIC*,bool> const & GetGlobalErrorHdl();
    static void     SetGlobalErrorHdl( const Link<StarBASIC*,bool>& rNewHdl );

    static void     SetGlobalBreakHdl( const Link<StarBASIC*,BasicDebugFlags>& rNewHdl );

    SbxArrayRef const & getUnoListeners();

    static SbxBase* FindSBXInCurrentScope( const OUString& rName );
    static SbMethod* GetActiveMethod( sal_uInt16 nLevel = 0 );
    static SbModule* GetActiveModule();
    void SetVBAEnabled( bool bEnabled );
    bool isVBAEnabled() const;

    const SbxObjectRef& getRTL() const { return pRtl; }
    bool IsDocBasic() const { return bDocBasic; }
    SbxVariable* VBAFind( const OUString& rName, SbxClassType t );
    bool GetUNOConstant( const OUString& rName, css::uno::Any& aOut );
    void QuitAndExitApplication();
    bool IsQuitApplication() const { return bQuit; };

    SbxObject* getVBAGlobals( );

    static css::uno::Reference< css::frame::XModel >
        GetModelFromBasic( SbxObject* pBasic );

    static void DetachAllDocBasicItems();
};

typedef tools::SvRef<StarBASIC> StarBASICRef;

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */