Line data Source code
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 <svl/brdcst.hxx>
23 : #include <basic/sbstar.hxx>
24 : #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp>
25 : #include <com/sun/star/script/XStarBasicAccess.hpp>
26 : #include <basic/basicdllapi.h>
27 : #include <vector>
28 :
29 : // Basic XML Import/Export
30 : BASIC_DLLPUBLIC com::sun::star::uno::Reference< com::sun::star::script::XStarBasicAccess >
31 : getStarBasicAccess( BasicManager* pMgr );
32 :
33 : class SotStorage;
34 :
35 : #define BASERR_REASON_OPENSTORAGE 0x0001
36 : #define BASERR_REASON_OPENLIBSTORAGE 0x0002
37 : #define BASERR_REASON_OPENMGRSTREAM 0x0004
38 : #define BASERR_REASON_OPENLIBSTREAM 0x0008
39 : #define BASERR_REASON_LIBNOTFOUND 0x0010
40 : #define BASERR_REASON_STORAGENOTFOUND 0x0020
41 : #define BASERR_REASON_BASICLOADERROR 0x0040
42 : #define BASERR_REASON_NOSTORAGENAME 0x0080
43 :
44 : #define BASERR_REASON_STDLIB 0x0100
45 :
46 0 : class BASIC_DLLPUBLIC BasicError
47 : {
48 : private:
49 : sal_uInt64 nErrorId;
50 : sal_uInt16 nReason;
51 : OUString aErrStr;
52 :
53 : public:
54 : BasicError( const BasicError& rErr );
55 : BasicError( sal_uInt64 nId, sal_uInt16 nR, const OUString& rErrStr );
56 :
57 0 : sal_uInt64 GetErrorId() const { return nErrorId; }
58 : sal_uInt16 GetReason() const { return nReason; }
59 : OUString GetErrorStr() { return aErrStr; }
60 :
61 : void SetErrorId( sal_uInt64 n ) { nErrorId = n; }
62 : void SetReason( sal_uInt16 n ) { nReason = n; }
63 : void SetErrorStr( const OUString& rStr) { aErrStr = rStr; }
64 : };
65 :
66 : class BasicLibs;
67 : class ErrorManager;
68 : class BasicLibInfo;
69 :
70 : namespace basic { class BasicManagerCleaner; }
71 :
72 : // Library password handling for 5.0 documents
73 0 : class BASIC_DLLPUBLIC OldBasicPassword
74 : {
75 : public:
76 : virtual void setLibraryPassword( const OUString& rLibraryName, const OUString& rPassword ) = 0;
77 : virtual OUString getLibraryPassword( const OUString& rLibraryName ) = 0;
78 : virtual void clearLibraryPassword( const OUString& rLibraryName ) = 0;
79 : virtual bool hasLibraryPassword( const OUString& rLibraryName ) = 0;
80 :
81 : protected:
82 0 : ~OldBasicPassword() {}
83 : };
84 :
85 0 : struct LibraryContainerInfo
86 : {
87 : ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > mxScriptCont;
88 : ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > mxDialogCont;
89 : OldBasicPassword* mpOldBasicPassword;
90 :
91 0 : LibraryContainerInfo()
92 0 : :mpOldBasicPassword( NULL )
93 : {
94 0 : }
95 :
96 0 : LibraryContainerInfo
97 : (
98 : com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > xScriptCont,
99 : com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > xDialogCont,
100 : OldBasicPassword* pOldBasicPassword
101 : )
102 : : mxScriptCont( xScriptCont )
103 : , mxDialogCont( xDialogCont )
104 0 : , mpOldBasicPassword( pOldBasicPassword )
105 0 : {}
106 : };
107 :
108 : struct BasicManagerImpl;
109 :
110 :
111 : #define LIB_NOTFOUND 0xFFFF
112 :
113 : class BASIC_DLLPUBLIC BasicManager : public SfxBroadcaster
114 : {
115 : friend class LibraryContainer_Impl;
116 : friend class StarBasicAccess_Impl;
117 : friend class BasMgrContainerListenerImpl;
118 : friend class ::basic::BasicManagerCleaner;
119 :
120 : private:
121 : BasicLibs* pLibs;
122 : std::vector<BasicError> aErrors;
123 :
124 : OUString aName;
125 : OUString maStorageName;
126 : bool mbDocMgr;
127 :
128 : BasicManagerImpl* mpImpl;
129 :
130 : BASIC_DLLPRIVATE void Init();
131 :
132 : protected:
133 : bool ImpLoadLibrary( BasicLibInfo* pLibInfo ) const;
134 : bool ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStorage, bool bInfosOnly = false );
135 : void ImpCreateStdLib( StarBASIC* pParentFromStdLib );
136 : void ImpMgrNotLoaded( const OUString& rStorageName );
137 : BasicLibInfo* CreateLibInfo();
138 : void LoadBasicManager( SotStorage& rStorage, const OUString& rBaseURL, bool bLoadBasics = true );
139 : void LoadOldBasicManager( SotStorage& rStorage );
140 : bool ImplLoadBasic( SvStream& rStrm, StarBASICRef& rOldBasic ) const;
141 : bool ImplEncryptStream( SvStream& rStream ) const;
142 : BasicLibInfo* FindLibInfo( StarBASIC* pBasic ) const;
143 : void CheckModules( StarBASIC* pBasic, bool bReference ) const;
144 : virtual ~BasicManager();
145 :
146 : public:
147 : TYPEINFO_OVERRIDE();
148 : BasicManager( SotStorage& rStorage, const OUString& rBaseURL, StarBASIC* pParentFromStdLib = NULL, OUString* pLibPath = NULL, bool bDocMgr = false );
149 : BasicManager( StarBASIC* pStdLib, OUString* pLibPath = NULL, bool bDocMgr = false );
150 :
151 : /** deletes the given BasicManager instance
152 :
153 : This method is necessary since normally, BasicManager instances are owned by the BasicManagerRepository,
154 : and expected to be deleted by the repository only. However, there exists quite some legacy code,
155 : which needs to explicitly delete a BasicManager itself. This code must not use the (protected)
156 : destructor, but LegacyDeleteBasicManager.
157 : */
158 : static void LegacyDeleteBasicManager( BasicManager*& _rpManager );
159 :
160 0 : void SetStorageName( const OUString& rName ) { maStorageName = rName; }
161 0 : OUString GetStorageName() const { return maStorageName; }
162 0 : void SetName( const OUString& rName ) { aName = rName; }
163 0 : OUString GetName() const { return aName; }
164 :
165 :
166 : sal_uInt16 GetLibCount() const;
167 : StarBASIC* GetLib( sal_uInt16 nLib ) const;
168 : StarBASIC* GetLib( const OUString& rName ) const;
169 : sal_uInt16 GetLibId( const OUString& rName ) const;
170 :
171 : OUString GetLibName( sal_uInt16 nLib );
172 :
173 : /** announces the library containers which belong to this BasicManager
174 :
175 : The method will automatically add two global constants, BasicLibraries and DialogLibraries,
176 : to the BasicManager.
177 : */
178 : void SetLibraryContainerInfo( const LibraryContainerInfo& rInfo );
179 :
180 : const ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer >&
181 : GetDialogLibraryContainer() const;
182 : const ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer >&
183 : GetScriptLibraryContainer() const;
184 :
185 : bool LoadLib( sal_uInt16 nLib );
186 : bool RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage );
187 :
188 : // Modify-Flag will be reset only during save.
189 : bool IsBasicModified() const;
190 :
191 : std::vector<BasicError>& GetErrors();
192 :
193 : /** sets a global constant in the basic library, referring to some UNO object, to a new value.
194 :
195 : If a constant with this name already existed before, its value is changed, and the old constant is
196 : returned. If it does not yet exist, it is newly created, and inserted into the basic library.
197 : */
198 : ::com::sun::star::uno::Any
199 : SetGlobalUNOConstant( const sal_Char* _pAsciiName, const ::com::sun::star::uno::Any& _rValue );
200 :
201 : /** 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. */
202 : bool GetGlobalUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::uno::Any& aOut );
203 : /** determines whether there are password-protected modules whose size exceedes the
204 : legacy module size
205 : @param _out_rModuleNames
206 : takes the names of modules whose size exceeds the legacy limit
207 : */
208 : bool LegacyPsswdBinaryLimitExceeded( ::com::sun::star::uno::Sequence< OUString >& _out_rModuleNames );
209 : bool HasExeCode( const OUString& );
210 : /// determines whether the Basic Manager has a given macro, given by fully qualified name
211 : bool HasMacro( OUString const& i_fullyQualifiedName ) const;
212 : /// executes a given macro
213 : ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, SbxArray* i_arguments, SbxValue* i_retValue );
214 : /// executes a given macro
215 : ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, OUString const& i_commaSeparatedArgs, SbxValue* i_retValue );
216 :
217 : private:
218 : BASIC_DLLPRIVATE bool IsReference( sal_uInt16 nLib );
219 :
220 : BASIC_DLLPRIVATE bool SetLibName( sal_uInt16 nLib, const OUString& rName );
221 :
222 : BASIC_DLLPRIVATE StarBASIC* GetStdLib() const;
223 : BASIC_DLLPRIVATE StarBASIC* AddLib( SotStorage& rStorage, const OUString& rLibName, bool bReference );
224 : BASIC_DLLPRIVATE bool RemoveLib( sal_uInt16 nLib );
225 : BASIC_DLLPRIVATE bool HasLib( const OUString& rName ) const;
226 :
227 : BASIC_DLLPRIVATE StarBASIC* CreateLibForLibContainer( const OUString& rLibName,
228 : const com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer >&
229 : xScriptCont );
230 : // For XML import/export:
231 : BASIC_DLLPRIVATE StarBASIC* CreateLib( const OUString& rLibName );
232 : BASIC_DLLPRIVATE StarBASIC* CreateLib( const OUString& rLibName, const OUString& Password,
233 : const OUString& LinkTargetURL );
234 : };
235 :
236 : #endif // INCLUDED_BASIC_BASMGR_HXX
237 :
238 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|