Bump version to 6.4-15
[LibreOffice.git] / include / basic / basmgr.hxx
blob64e4ac597df71a9c105b82747178c25af1be05f9
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 <vcl/errcode.hxx>
23 #include <svl/SfxBroadcaster.hxx>
24 #include <basic/sbstar.hxx>
25 #include <basic/basicdllapi.h>
26 #include <memory>
27 #include <vector>
29 namespace com::sun::star::script { class XLibraryContainer; }
30 namespace com::sun::star::script { class XPersistentLibraryContainer; }
31 namespace com::sun::star::script { class XStarBasicAccess; }
33 class BasicManager;
35 // Basic XML Import/Export
36 BASIC_DLLPUBLIC css::uno::Reference< css::script::XStarBasicAccess >
37 getStarBasicAccess( BasicManager* pMgr );
39 class SotStorage;
41 enum class BasicErrorReason
43 OPENLIBSTORAGE = 0x0002,
44 OPENMGRSTREAM = 0x0004,
45 OPENLIBSTREAM = 0x0008,
46 LIBNOTFOUND = 0x0010,
47 STORAGENOTFOUND = 0x0020,
48 BASICLOADERROR = 0x0040,
49 STDLIB = 0x0100
52 class BasicError
54 private:
55 ErrCode nErrorId;
56 BasicErrorReason nReason;
58 public:
59 BasicError( const BasicError& rErr );
60 BasicError( ErrCode nId, BasicErrorReason nR );
62 ErrCode const & GetErrorId() const { return nErrorId; }
65 class BasicLibInfo;
67 namespace basic { class ImplRepository; }
69 // Library password handling for 5.0 documents
70 class BASIC_DLLPUBLIC OldBasicPassword
72 public:
73 virtual void setLibraryPassword( const OUString& rLibraryName, const OUString& rPassword ) = 0;
75 protected:
76 ~OldBasicPassword() {}
79 struct LibraryContainerInfo
81 css::uno::Reference< css::script::XPersistentLibraryContainer > mxScriptCont;
82 css::uno::Reference< css::script::XPersistentLibraryContainer > mxDialogCont;
83 OldBasicPassword* mpOldBasicPassword;
85 LibraryContainerInfo()
86 :mpOldBasicPassword( nullptr )
90 LibraryContainerInfo
92 css::uno::Reference< css::script::XPersistentLibraryContainer > const & xScriptCont,
93 css::uno::Reference< css::script::XPersistentLibraryContainer > const & xDialogCont,
94 OldBasicPassword* pOldBasicPassword
96 : mxScriptCont( xScriptCont )
97 , mxDialogCont( xDialogCont )
98 , mpOldBasicPassword( pOldBasicPassword )
102 struct BasicManagerImpl;
105 #define LIB_NOTFOUND 0xFFFF
107 class BASIC_DLLPUBLIC BasicManager : public SfxBroadcaster
109 friend class LibraryContainer_Impl;
110 friend class StarBasicAccess_Impl;
111 friend class BasMgrContainerListenerImpl;
112 friend class ::basic::ImplRepository;
114 private:
115 std::vector<BasicError> aErrors;
117 OUString aName;
118 OUString maStorageName;
119 bool mbDocMgr;
121 std::unique_ptr<BasicManagerImpl> mpImpl;
123 BASIC_DLLPRIVATE void Init();
125 protected:
126 bool ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStorage );
127 void ImpCreateStdLib( StarBASIC* pParentFromStdLib );
128 void ImpMgrNotLoaded( const OUString& rStorageName );
129 BasicLibInfo* CreateLibInfo();
130 void LoadBasicManager( SotStorage& rStorage, const OUString& rBaseURL );
131 void LoadOldBasicManager( SotStorage& rStorage );
132 bool ImplLoadBasic( SvStream& rStrm, StarBASICRef& rOldBasic ) const;
133 static bool ImplEncryptStream( SvStream& rStream );
134 BasicLibInfo* FindLibInfo( StarBASIC const * pBasic );
135 static void CheckModules( StarBASIC* pBasic, bool bReference );
137 public:
138 BasicManager( SotStorage& rStorage, const OUString& rBaseURL, StarBASIC* pParentFromStdLib = nullptr, OUString const * pLibPath = nullptr, bool bDocMgr = false );
139 BasicManager( StarBASIC* pStdLib, OUString const * pLibPath = nullptr, bool bDocMgr = false );
140 virtual ~BasicManager() override;
142 void SetStorageName( const OUString& rName ) { maStorageName = rName; }
143 const OUString& GetStorageName() const { return maStorageName; }
144 void SetName( const OUString& rName ) { aName = rName; }
145 const OUString& GetName() const { return aName; }
148 sal_uInt16 GetLibCount() const;
149 StarBASIC* GetLib( sal_uInt16 nLib ) const;
150 StarBASIC* GetLib( const OUString& rName ) const;
151 sal_uInt16 GetLibId( const OUString& rName ) const;
153 OUString GetLibName( sal_uInt16 nLib );
155 /** announces the library containers which belong to this BasicManager
157 The method will automatically add two global constants, BasicLibraries and DialogLibraries,
158 to the BasicManager.
160 void SetLibraryContainerInfo( const LibraryContainerInfo& rInfo );
162 const css::uno::Reference< css::script::XPersistentLibraryContainer >&
163 GetDialogLibraryContainer() const;
164 const css::uno::Reference< css::script::XPersistentLibraryContainer >&
165 GetScriptLibraryContainer() const;
167 bool LoadLib( sal_uInt16 nLib );
168 bool RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage );
170 // Modify-Flag will be reset only during save.
171 bool IsBasicModified() const;
173 std::vector<BasicError>& GetErrors() { return aErrors;}
175 /** sets a global constant in the basic library, referring to some UNO object, to a new value.
177 If a constant with this name already existed before, its value is changed, and the old constant is
178 returned. If it does not yet exist, it is newly created, and inserted into the basic library.
180 css::uno::Any
181 SetGlobalUNOConstant( const OUString& rName, const css::uno::Any& _rValue );
183 /** 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. */
184 bool GetGlobalUNOConstant( const OUString& rName, css::uno::Any& aOut );
185 /** determines whether there are password-protected modules whose size exceeds the
186 legacy module size
187 @param _out_rModuleNames
188 takes the names of modules whose size exceeds the legacy limit
190 bool LegacyPsswdBinaryLimitExceeded( std::vector< OUString >& _out_rModuleNames );
191 bool HasExeCode( const OUString& );
192 /// determines whether the Basic Manager has a given macro, given by fully qualified name
193 bool HasMacro( OUString const& i_fullyQualifiedName ) const;
194 /// executes a given macro
195 ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, SbxArray* i_arguments, SbxValue* i_retValue );
196 /// executes a given macro
197 ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, OUString const& i_commaSeparatedArgs, SbxValue* i_retValue );
199 private:
200 BASIC_DLLPRIVATE bool IsReference( sal_uInt16 nLib );
202 BASIC_DLLPRIVATE StarBASIC* GetStdLib() const;
203 BASIC_DLLPRIVATE StarBASIC* AddLib( SotStorage& rStorage, const OUString& rLibName, bool bReference );
204 BASIC_DLLPRIVATE void RemoveLib( sal_uInt16 nLib );
205 BASIC_DLLPRIVATE bool HasLib( const OUString& rName ) const;
207 BASIC_DLLPRIVATE StarBASIC* CreateLibForLibContainer( const OUString& rLibName,
208 const css::uno::Reference< css::script::XLibraryContainer >& xScriptCont );
209 // For XML import/export:
210 BASIC_DLLPRIVATE StarBASIC* CreateLib( const OUString& rLibName );
211 BASIC_DLLPRIVATE StarBASIC* CreateLib( const OUString& rLibName, const OUString& Password,
212 const OUString& LinkTargetURL );
215 #endif // INCLUDED_BASIC_BASMGR_HXX
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */