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 <comphelper/errcode.hxx>
23 #include <svl/SfxBroadcaster.hxx>
24 #include <basic/sbstar.hxx>
25 #include <basic/basicdllapi.h>
27 #include <string_view>
30 namespace basic
{ class SfxScriptLibraryContainer
; }
31 namespace com::sun::star::script
{ class XLibraryContainer
; }
32 namespace com::sun::star::script
{ class XPersistentLibraryContainer
; }
33 namespace com::sun::star::script
{ class XStarBasicAccess
; }
37 // Basic XML Import/Export
38 BASIC_DLLPUBLIC
css::uno::Reference
< css::script::XStarBasicAccess
>
39 getStarBasicAccess( BasicManager
* pMgr
);
49 BasicError( const BasicError
& rErr
);
50 BasicError( ErrCodeMsg nId
);
52 ErrCodeMsg
const & GetErrorId() const { return nErrorId
; }
57 namespace basic
{ class ImplRepository
; }
59 struct LibraryContainerInfo
61 css::uno::Reference
< css::script::XPersistentLibraryContainer
> mxScriptCont
;
62 css::uno::Reference
< css::script::XPersistentLibraryContainer
> mxDialogCont
;
63 basic::SfxScriptLibraryContainer
* mpOldBasicPassword
;
65 LibraryContainerInfo()
66 :mpOldBasicPassword( nullptr )
72 css::uno::Reference
< css::script::XPersistentLibraryContainer
> xScriptCont
,
73 css::uno::Reference
< css::script::XPersistentLibraryContainer
> xDialogCont
,
74 basic::SfxScriptLibraryContainer
* pOldBasicPassword
76 : mxScriptCont(std::move( xScriptCont
))
77 , mxDialogCont(std::move( xDialogCont
))
78 , mpOldBasicPassword( pOldBasicPassword
)
82 #define LIB_NOTFOUND 0xFFFF
84 class BASIC_DLLPUBLIC BasicManager final
: public SfxBroadcaster
86 friend class LibraryContainer_Impl
;
87 friend class StarBasicAccess_Impl
;
88 friend class BasMgrContainerListenerImpl
;
89 friend class ::basic::ImplRepository
;
92 std::vector
<BasicError
> aErrors
;
95 OUString maStorageName
;
98 LibraryContainerInfo maContainerInfo
;
99 std::vector
<std::unique_ptr
<BasicLibInfo
>> maLibs
;
100 OUString aBasicLibPath
;
102 bool ImpLoadLibrary( BasicLibInfo
* pLibInfo
, SotStorage
* pCurStorage
);
103 void ImpCreateStdLib( StarBASIC
* pParentFromStdLib
);
104 void ImpMgrNotLoaded( const OUString
& rStorageName
);
105 BasicLibInfo
* CreateLibInfo();
106 void LoadBasicManager( SotStorage
& rStorage
, std::u16string_view rBaseURL
);
107 void LoadOldBasicManager( SotStorage
& rStorage
);
108 bool ImplLoadBasic( SvStream
& rStrm
, StarBASICRef
& rOldBasic
) const;
109 static bool ImplEncryptStream( SvStream
& rStream
);
110 BasicLibInfo
* FindLibInfo( StarBASIC
const * pBasic
);
111 static void CheckModules( StarBASIC
* pBasic
, bool bReference
);
114 BasicManager( SotStorage
& rStorage
, std::u16string_view rBaseURL
, StarBASIC
* pParentFromStdLib
= nullptr, OUString
const * pLibPath
= nullptr, bool bDocMgr
= false );
115 BasicManager( StarBASIC
* pStdLib
, OUString
const * pLibPath
= nullptr, bool bDocMgr
= false );
117 virtual ~BasicManager() override
;
119 void SetStorageName( const OUString
& rName
) { maStorageName
= rName
; }
120 const OUString
& GetStorageName() const { return maStorageName
; }
121 void SetName( const OUString
& rName
) { aName
= rName
; }
122 const OUString
& GetName() const { return aName
; }
125 sal_uInt16
GetLibCount() const;
126 StarBASIC
* GetLib( sal_uInt16 nLib
) const;
127 StarBASIC
* GetLib( std::u16string_view rName
) const;
128 sal_uInt16
GetLibId( std::u16string_view rName
) const;
130 OUString
GetLibName( sal_uInt16 nLib
);
132 /** announces the library containers which belong to this BasicManager
134 The method will automatically add two global constants, BasicLibraries and DialogLibraries,
137 void SetLibraryContainerInfo( const LibraryContainerInfo
& rInfo
);
139 const css::uno::Reference
< css::script::XPersistentLibraryContainer
>&
140 GetDialogLibraryContainer() const;
141 const css::uno::Reference
< css::script::XPersistentLibraryContainer
>&
142 GetScriptLibraryContainer() const;
144 bool LoadLib( sal_uInt16 nLib
);
145 bool RemoveLib( sal_uInt16 nLib
, bool bDelBasicFromStorage
);
147 // Modify-Flag will be reset only during save.
148 bool IsBasicModified() const;
150 std::vector
<BasicError
>& GetErrors() { return aErrors
;}
152 /** sets a global constant in the basic library, referring to some UNO object, to a new value.
154 If a constant with this name already existed before, its value is changed, and the old constant is
155 returned in pOldValue. If it does not yet exist, it is newly created, and inserted into the basic library.
157 void SetGlobalUNOConstant( const OUString
& rName
, const css::uno::Any
& _rValue
, css::uno::Any
* pOldValue
= nullptr );
159 /** 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. */
160 bool GetGlobalUNOConstant( const OUString
& rName
, css::uno::Any
& aOut
);
161 /** determines whether there are password-protected modules whose size exceeds the
162 B_IMG_VERSION_12 module size
163 @param _out_rModuleNames
164 takes the names of modules whose size exceeds the B_IMG_VERSION_12 limit
166 bool ImgVersion12PsswdBinaryLimitExceeded( std::vector
< OUString
>& _out_rModuleNames
);
167 bool HasExeCode( std::u16string_view
);
168 /// determines whether the Basic Manager has a given macro, given by fully qualified name
169 bool HasMacro( OUString
const& i_fullyQualifiedName
) const;
170 /// executes a given macro
171 ErrCode
ExecuteMacro( OUString
const& i_fullyQualifiedName
, SbxArray
* i_arguments
, SbxValue
* i_retValue
);
172 /// executes a given macro
173 ErrCode
ExecuteMacro( OUString
const& i_fullyQualifiedName
, std::u16string_view i_commaSeparatedArgs
, SbxValue
* i_retValue
);
176 BASIC_DLLPRIVATE
bool IsReference( sal_uInt16 nLib
);
178 BASIC_DLLPRIVATE StarBASIC
* GetStdLib() const;
179 BASIC_DLLPRIVATE StarBASIC
* AddLib( SotStorage
& rStorage
, const OUString
& rLibName
, bool bReference
);
180 BASIC_DLLPRIVATE
void RemoveLib( sal_uInt16 nLib
);
181 BASIC_DLLPRIVATE
bool HasLib( std::u16string_view rName
) const;
183 BASIC_DLLPRIVATE StarBASIC
* CreateLibForLibContainer( const OUString
& rLibName
,
184 const css::uno::Reference
< css::script::XLibraryContainer
>& xScriptCont
);
185 // For XML import/export:
186 BASIC_DLLPRIVATE StarBASIC
* CreateLib( const OUString
& rLibName
);
187 BASIC_DLLPRIVATE StarBASIC
* CreateLib( const OUString
& rLibName
, const OUString
& Password
,
188 const OUString
& LinkTargetURL
);
189 BasicManager
& operator=(BasicManager
const &) = delete; //MSVC2015 workaround
190 BasicManager( BasicManager
const&) = delete; //MSVC2015 workaround
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */