Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / basic / basmgr.hxx
blob32710a57bf09c96323cb3105db104e08985c0155
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef INCLUDED_BASIC_BASMGR_HXX
20 #define INCLUDED_BASIC_BASMGR_HXX
22 #include <utility>
23 #include <comphelper/errcode.hxx>
24 #include <svl/SfxBroadcaster.hxx>
25 #include <basic/sbstar.hxx>
26 #include <basic/basicdllapi.h>
27 #include <memory>
28 #include <string_view>
29 #include <vector>
31 namespace basic { class SfxScriptLibraryContainer; }
32 namespace com::sun::star::script { class XLibraryContainer; }
33 namespace com::sun::star::script { class XPersistentLibraryContainer; }
34 namespace com::sun::star::script { class XStarBasicAccess; }
36 class BasicManager;
38 // Basic XML Import/Export
39 BASIC_DLLPUBLIC css::uno::Reference< css::script::XStarBasicAccess >
40 getStarBasicAccess( BasicManager* pMgr );
42 class SotStorage;
44 enum class BasicErrorReason
46 OPENLIBSTORAGE = 0x0002,
47 OPENMGRSTREAM = 0x0004,
48 OPENLIBSTREAM = 0x0008,
49 LIBNOTFOUND = 0x0010,
50 STORAGENOTFOUND = 0x0020,
51 BASICLOADERROR = 0x0040,
52 STDLIB = 0x0100
55 class BasicError
57 private:
58 ErrCode nErrorId;
59 BasicErrorReason nReason;
61 public:
62 BasicError( const BasicError& rErr );
63 BasicError( ErrCode nId, BasicErrorReason nR );
65 ErrCode const & GetErrorId() const { return nErrorId; }
68 class BasicLibInfo;
70 namespace basic { class ImplRepository; }
72 struct LibraryContainerInfo
74 css::uno::Reference< css::script::XPersistentLibraryContainer > mxScriptCont;
75 css::uno::Reference< css::script::XPersistentLibraryContainer > mxDialogCont;
76 basic::SfxScriptLibraryContainer* mpOldBasicPassword;
78 LibraryContainerInfo()
79 :mpOldBasicPassword( nullptr )
83 LibraryContainerInfo
85 css::uno::Reference< css::script::XPersistentLibraryContainer > xScriptCont,
86 css::uno::Reference< css::script::XPersistentLibraryContainer > xDialogCont,
87 basic::SfxScriptLibraryContainer* pOldBasicPassword
89 : mxScriptCont(std::move( xScriptCont ))
90 , mxDialogCont(std::move( xDialogCont ))
91 , mpOldBasicPassword( pOldBasicPassword )
95 #define LIB_NOTFOUND 0xFFFF
97 class BASIC_DLLPUBLIC BasicManager final : public SfxBroadcaster
99 friend class LibraryContainer_Impl;
100 friend class StarBasicAccess_Impl;
101 friend class BasMgrContainerListenerImpl;
102 friend class ::basic::ImplRepository;
104 private:
105 std::vector<BasicError> aErrors;
107 OUString aName;
108 OUString maStorageName;
109 bool mbDocMgr;
111 LibraryContainerInfo maContainerInfo;
112 std::vector<std::unique_ptr<BasicLibInfo>> maLibs;
113 OUString aBasicLibPath;
115 bool ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStorage );
116 void ImpCreateStdLib( StarBASIC* pParentFromStdLib );
117 void ImpMgrNotLoaded( const OUString& rStorageName );
118 BasicLibInfo* CreateLibInfo();
119 void LoadBasicManager( SotStorage& rStorage, std::u16string_view rBaseURL );
120 void LoadOldBasicManager( SotStorage& rStorage );
121 bool ImplLoadBasic( SvStream& rStrm, StarBASICRef& rOldBasic ) const;
122 static bool ImplEncryptStream( SvStream& rStream );
123 BasicLibInfo* FindLibInfo( StarBASIC const * pBasic );
124 static void CheckModules( StarBASIC* pBasic, bool bReference );
126 public:
127 BasicManager( SotStorage& rStorage, std::u16string_view rBaseURL, StarBASIC* pParentFromStdLib = nullptr, OUString const * pLibPath = nullptr, bool bDocMgr = false );
128 BasicManager( StarBASIC* pStdLib, OUString const * pLibPath = nullptr, bool bDocMgr = false );
130 virtual ~BasicManager() override;
132 void SetStorageName( const OUString& rName ) { maStorageName = rName; }
133 const OUString& GetStorageName() const { return maStorageName; }
134 void SetName( const OUString& rName ) { aName = rName; }
135 const OUString& GetName() const { return aName; }
138 sal_uInt16 GetLibCount() const;
139 StarBASIC* GetLib( sal_uInt16 nLib ) const;
140 StarBASIC* GetLib( std::u16string_view rName ) const;
141 sal_uInt16 GetLibId( std::u16string_view rName ) const;
143 OUString GetLibName( sal_uInt16 nLib );
145 /** announces the library containers which belong to this BasicManager
147 The method will automatically add two global constants, BasicLibraries and DialogLibraries,
148 to the BasicManager.
150 void SetLibraryContainerInfo( const LibraryContainerInfo& rInfo );
152 const css::uno::Reference< css::script::XPersistentLibraryContainer >&
153 GetDialogLibraryContainer() const;
154 const css::uno::Reference< css::script::XPersistentLibraryContainer >&
155 GetScriptLibraryContainer() const;
157 bool LoadLib( sal_uInt16 nLib );
158 bool RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage );
160 // Modify-Flag will be reset only during save.
161 bool IsBasicModified() const;
163 std::vector<BasicError>& GetErrors() { return aErrors;}
165 /** sets a global constant in the basic library, referring to some UNO object, to a new value.
167 If a constant with this name already existed before, its value is changed, and the old constant is
168 returned in pOldValue. If it does not yet exist, it is newly created, and inserted into the basic library.
170 void SetGlobalUNOConstant( const OUString& rName, const css::uno::Any& _rValue, css::uno::Any* pOldValue = nullptr );
172 /** retrieves a global constant in the basic library, referring to some UNO object, returns true if a value is found ( value is in aOut ) false otherwise. */
173 bool GetGlobalUNOConstant( const OUString& rName, css::uno::Any& aOut );
174 /** determines whether there are password-protected modules whose size exceeds the
175 legacy module size
176 @param _out_rModuleNames
177 takes the names of modules whose size exceeds the legacy limit
179 bool LegacyPsswdBinaryLimitExceeded( std::vector< OUString >& _out_rModuleNames );
180 bool HasExeCode( std::u16string_view );
181 /// determines whether the Basic Manager has a given macro, given by fully qualified name
182 bool HasMacro( OUString const& i_fullyQualifiedName ) const;
183 /// executes a given macro
184 ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, SbxArray* i_arguments, SbxValue* i_retValue );
185 /// executes a given macro
186 ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, std::u16string_view i_commaSeparatedArgs, SbxValue* i_retValue );
188 private:
189 BASIC_DLLPRIVATE bool IsReference( sal_uInt16 nLib );
191 BASIC_DLLPRIVATE StarBASIC* GetStdLib() const;
192 BASIC_DLLPRIVATE StarBASIC* AddLib( SotStorage& rStorage, const OUString& rLibName, bool bReference );
193 BASIC_DLLPRIVATE void RemoveLib( sal_uInt16 nLib );
194 BASIC_DLLPRIVATE bool HasLib( std::u16string_view rName ) const;
196 BASIC_DLLPRIVATE StarBASIC* CreateLibForLibContainer( const OUString& rLibName,
197 const css::uno::Reference< css::script::XLibraryContainer >& xScriptCont );
198 // For XML import/export:
199 BASIC_DLLPRIVATE StarBASIC* CreateLib( const OUString& rLibName );
200 BASIC_DLLPRIVATE StarBASIC* CreateLib( const OUString& rLibName, const OUString& Password,
201 const OUString& LinkTargetURL );
202 BasicManager& operator=(BasicManager const &) = delete; //MSVC2015 workaround
203 BasicManager( BasicManager const&) = delete; //MSVC2015 workaround
206 #endif // INCLUDED_BASIC_BASMGR_HXX
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */