LibreOffice Module basic (master) 1
basmgr.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#ifndef INCLUDED_BASIC_BASMGR_HXX
20#define INCLUDED_BASIC_BASMGR_HXX
21
22#include <utility>
25#include <basic/sbstar.hxx>
26#include <basic/basicdllapi.h>
27#include <memory>
28#include <string_view>
29#include <vector>
30
31namespace basic { class SfxScriptLibraryContainer; }
32namespace com::sun::star::script { class XLibraryContainer; }
33namespace com::sun::star::script { class XPersistentLibraryContainer; }
34namespace com::sun::star::script { class XStarBasicAccess; }
35
36class BasicManager;
37
38// Basic XML Import/Export
39BASIC_DLLPUBLIC css::uno::Reference< css::script::XStarBasicAccess >
41
42class SotStorage;
43
45{
46 OPENLIBSTORAGE = 0x0002,
47 OPENMGRSTREAM = 0x0004,
48 OPENLIBSTREAM = 0x0008,
49 LIBNOTFOUND = 0x0010,
50 STORAGENOTFOUND = 0x0020,
51 BASICLOADERROR = 0x0040,
52 STDLIB = 0x0100
53};
54
56{
57private:
60
61public:
62 BasicError( const BasicError& rErr );
64
65 ErrCode const & GetErrorId() const { return nErrorId; }
66};
67
68class BasicLibInfo;
69
70namespace basic { class ImplRepository; }
71
73{
74 css::uno::Reference< css::script::XPersistentLibraryContainer > mxScriptCont;
75 css::uno::Reference< css::script::XPersistentLibraryContainer > mxDialogCont;
77
79 :mpOldBasicPassword( nullptr )
80 {
81 }
82
84 (
85 css::uno::Reference< css::script::XPersistentLibraryContainer > xScriptCont,
86 css::uno::Reference< css::script::XPersistentLibraryContainer > xDialogCont,
87 basic::SfxScriptLibraryContainer* pOldBasicPassword
88 )
89 : mxScriptCont(std::move( xScriptCont ))
90 , mxDialogCont(std::move( xDialogCont ))
91 , mpOldBasicPassword( pOldBasicPassword )
92 {}
93};
94
95#define LIB_NOTFOUND 0xFFFF
96
98{
102 friend class ::basic::ImplRepository;
103
104private:
105 std::vector<BasicError> aErrors;
106
107 OUString aName;
110
112 std::vector<std::unique_ptr<BasicLibInfo>> maLibs;
114
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 );
125
126public:
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 );
129
130 virtual ~BasicManager() override;
131
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; }
136
137
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;
142
143 OUString GetLibName( sal_uInt16 nLib );
144
150 void SetLibraryContainerInfo( const LibraryContainerInfo& rInfo );
151
152 const css::uno::Reference< css::script::XPersistentLibraryContainer >&
153 GetDialogLibraryContainer() const;
154 const css::uno::Reference< css::script::XPersistentLibraryContainer >&
155 GetScriptLibraryContainer() const;
156
157 bool LoadLib( sal_uInt16 nLib );
158 bool RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage );
159
160 // Modify-Flag will be reset only during save.
161 bool IsBasicModified() const;
162
163 std::vector<BasicError>& GetErrors() { return aErrors;}
164
170 void SetGlobalUNOConstant( const OUString& rName, const css::uno::Any& _rValue, css::uno::Any* pOldValue = nullptr );
171
173 bool GetGlobalUNOConstant( const OUString& rName, css::uno::Any& aOut );
179 bool ImgVersion12PsswdBinaryLimitExceeded( std::vector< OUString >& _out_rModuleNames );
180 bool HasExeCode( std::u16string_view );
182 bool HasMacro( OUString const& i_fullyQualifiedName ) const;
184 ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, SbxArray* i_arguments, SbxValue* i_retValue );
186 ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, std::u16string_view i_commaSeparatedArgs, SbxValue* i_retValue );
187
188private:
189 BASIC_DLLPRIVATE bool IsReference( sal_uInt16 nLib );
190
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;
195
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
204};
205
206#endif // INCLUDED_BASIC_BASMGR_HXX
207
208/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define BASIC_DLLPRIVATE
Definition: basicdllapi.h:19
#define BASIC_DLLPUBLIC
Definition: basicdllapi.h:17
BasicErrorReason
Definition: basmgr.hxx:45
BASIC_DLLPUBLIC css::uno::Reference< css::script::XStarBasicAccess > getStarBasicAccess(BasicManager *pMgr)
Definition: basmgr.cxx:2112
ErrCode nErrorId
Definition: basmgr.hxx:58
BasicErrorReason nReason
Definition: basmgr.hxx:59
BasicError(const BasicError &rErr)
Definition: basmgr.cxx:309
ErrCode const & GetErrorId() const
Definition: basmgr.hxx:65
std::vector< BasicError > & GetErrors()
Definition: basmgr.hxx:163
const OUString & GetStorageName() const
Definition: basmgr.hxx:133
BasicManager(BasicManager const &)=delete
BasicManager & operator=(BasicManager const &)=delete
void SetName(const OUString &rName)
Definition: basmgr.hxx:134
OUString aBasicLibPath
Definition: basmgr.hxx:113
OUString maStorageName
Definition: basmgr.hxx:108
const OUString & GetName() const
Definition: basmgr.hxx:135
bool mbDocMgr
Definition: basmgr.hxx:109
LibraryContainerInfo maContainerInfo
Definition: basmgr.hxx:111
std::vector< BasicError > aErrors
Definition: basmgr.hxx:105
void SetStorageName(const OUString &rName)
Definition: basmgr.hxx:132
OUString aName
Definition: basmgr.hxx:107
std::vector< std::unique_ptr< BasicLibInfo > > maLibs
Definition: basmgr.hxx:112
Definition: sbx.hxx:95
OUString aName
css::uno::Reference< css::script::XPersistentLibraryContainer > mxDialogCont
Definition: basmgr.hxx:75
LibraryContainerInfo(css::uno::Reference< css::script::XPersistentLibraryContainer > xScriptCont, css::uno::Reference< css::script::XPersistentLibraryContainer > xDialogCont, basic::SfxScriptLibraryContainer *pOldBasicPassword)
Definition: basmgr.hxx:84
basic::SfxScriptLibraryContainer * mpOldBasicPassword
Definition: basmgr.hxx:76
css::uno::Reference< css::script::XPersistentLibraryContainer > mxScriptCont
Definition: basmgr.hxx:74