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 <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 "basicdllapi.h"
29 // Basic XML Import/Export
30 BASIC_DLLPUBLIC
com::sun::star::uno::Reference
< com::sun::star::script::XStarBasicAccess
>
31 getStarBasicAccess( BasicManager
* pMgr
);
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
44 #define BASERR_REASON_STDLIB 0x0100
46 class BASIC_DLLPUBLIC BasicError
54 BasicError( const BasicError
& rErr
);
55 BasicError( sal_uIntPtr nId
, sal_uInt16 nR
, const OUString
& rErrStr
);
57 sal_uIntPtr
GetErrorId() const { return nErrorId
; }
58 sal_uInt16
GetReason() const { return nReason
; }
59 OUString
GetErrorStr() { return aErrStr
; }
61 void SetErrorId( sal_uIntPtr n
) { nErrorId
= n
; }
62 void SetReason( sal_uInt16 n
) { nReason
= n
; }
63 void SetErrorStr( const OUString
& rStr
) { aErrStr
= rStr
; }
70 namespace basic
{ class BasicManagerCleaner
; }
72 // Library password handling for 5.0 documents
73 class BASIC_DLLPUBLIC OldBasicPassword
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 sal_Bool
hasLibraryPassword( const OUString
& rLibraryName
) = 0;
82 ~OldBasicPassword() {}
85 struct LibraryContainerInfo
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
;
91 LibraryContainerInfo()
92 :mpOldBasicPassword( NULL
)
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
102 : mxScriptCont( xScriptCont
)
103 , mxDialogCont( xDialogCont
)
104 , mpOldBasicPassword( pOldBasicPassword
)
108 struct BasicManagerImpl
;
111 #define LIB_NOTFOUND 0xFFFF
113 class BASIC_DLLPUBLIC BasicManager
: public SfxBroadcaster
115 friend class LibraryContainer_Impl
;
116 friend class StarBasicAccess_Impl
;
117 friend class BasMgrContainerListenerImpl
;
118 friend class ::basic::BasicManagerCleaner
;
122 std::vector
<BasicError
> aErrors
;
125 OUString maStorageName
;
128 BasicManagerImpl
* mpImpl
;
130 BASIC_DLLPRIVATE
void Init();
133 sal_Bool
ImpLoadLibrary( BasicLibInfo
* pLibInfo
) const;
134 sal_Bool
ImpLoadLibrary( BasicLibInfo
* pLibInfo
, SotStorage
* pCurStorage
, sal_Bool bInfosOnly
= sal_False
);
135 void ImpCreateStdLib( StarBASIC
* pParentFromStdLib
);
136 void ImpMgrNotLoaded( const OUString
& rStorageName
);
137 BasicLibInfo
* CreateLibInfo();
138 void LoadBasicManager( SotStorage
& rStorage
, const OUString
& rBaseURL
, sal_Bool bLoadBasics
= sal_True
);
139 void LoadOldBasicManager( SotStorage
& rStorage
);
140 sal_Bool
ImplLoadBasic( SvStream
& rStrm
, StarBASICRef
& rOldBasic
) const;
141 sal_Bool
ImplEncryptStream( SvStream
& rStream
) const;
142 BasicLibInfo
* FindLibInfo( StarBASIC
* pBasic
) const;
143 void CheckModules( StarBASIC
* pBasic
, sal_Bool bReference
) const;
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 );
151 /** deletes the given BasicManager instance
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.
158 static void LegacyDeleteBasicManager( BasicManager
*& _rpManager
);
160 void SetStorageName( const OUString
& rName
) { maStorageName
= rName
; }
161 OUString
GetStorageName() const { return maStorageName
; }
162 void SetName( const OUString
& rName
) { aName
= rName
; }
163 OUString
GetName() const { return aName
; }
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;
171 OUString
GetLibName( sal_uInt16 nLib
);
173 /** announces the library containers which belong to this BasicManager
175 The method will automatically add two global constants, BasicLibraries and DialogLibraries,
178 void SetLibraryContainerInfo( const LibraryContainerInfo
& rInfo
);
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;
185 sal_Bool
LoadLib( sal_uInt16 nLib
);
186 sal_Bool
RemoveLib( sal_uInt16 nLib
, sal_Bool bDelBasicFromStorage
);
188 // Modify-Flag will be reset only during save.
189 sal_Bool
IsBasicModified() const;
191 std::vector
<BasicError
>& GetErrors();
193 /** sets a global constant in the basic library, referring to some UNO object, to a new value.
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.
198 ::com::sun::star::uno::Any
199 SetGlobalUNOConstant( const sal_Char
* _pAsciiName
, const ::com::sun::star::uno::Any
& _rValue
);
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
205 @param _out_rModuleNames
206 takes the names of modules whose size exceeds the legacy limit
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
);
218 BASIC_DLLPRIVATE sal_Bool
IsReference( sal_uInt16 nLib
);
220 BASIC_DLLPRIVATE sal_Bool
SetLibName( sal_uInt16 nLib
, const OUString
& rName
);
222 BASIC_DLLPRIVATE StarBASIC
* GetStdLib() const;
223 BASIC_DLLPRIVATE StarBASIC
* AddLib( SotStorage
& rStorage
, const OUString
& rLibName
, sal_Bool bReference
);
224 BASIC_DLLPRIVATE sal_Bool
RemoveLib( sal_uInt16 nLib
);
225 BASIC_DLLPRIVATE sal_Bool
HasLib( const OUString
& rName
) const;
227 BASIC_DLLPRIVATE StarBASIC
* CreateLibForLibContainer( const OUString
& rLibName
,
228 const com::sun::star::uno::Reference
< com::sun::star::script::XLibraryContainer
>&
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
);
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */