1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 // 28 #ifndef _BASMGR_HXX 29 #define _BASMGR_HXX 30 31 #include <tools/string.hxx> 32 #include <svl/brdcst.hxx> 33 #include <basic/sbstar.hxx> 34 #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp> 35 #include <com/sun/star/script/XStarBasicAccess.hpp> 36 37 38 // Basic XML Import/Export 39 com::sun::star::uno::Reference< com::sun::star::script::XStarBasicAccess > 40 getStarBasicAccess( BasicManager* pMgr ); 41 42 43 44 class SotStorage; 45 46 #define BASERR_ID_STDLIBOPEN ERRCODE_BASMGR_STDLIBOPEN 47 #define BASERR_ID_STDLIBSAVE ERRCODE_BASMGR_STDLIBSAVE 48 #define BASERR_ID_LIBLOAD ERRCODE_BASMGR_LIBLOAD 49 #define BASERR_ID_LIBCREATE ERRCODE_BASMGR_LIBCREATE 50 #define BASERR_ID_LIBSAVE ERRCODE_BASMGR_LIBSAVE 51 #define BASERR_ID_LIBDEL ERRCODE_BASMGR_LIBDEL 52 #define BASERR_ID_MGROPEN ERRCODE_BASMGR_MGROPEN 53 #define BASERR_ID_MGRSAVE ERRCODE_BASMGR_MGRSAVE 54 #define BASERR_ID_REMOVELIB ERRCODE_BASMGR_REMOVELIB 55 #define BASERR_ID_UNLOADLIB ERRCODE_BASMGR_UNLOADLIB 56 57 #define BASERR_REASON_OPENSTORAGE 0x0001 58 #define BASERR_REASON_OPENLIBSTORAGE 0x0002 59 #define BASERR_REASON_OPENMGRSTREAM 0x0004 60 #define BASERR_REASON_OPENLIBSTREAM 0x0008 61 #define BASERR_REASON_LIBNOTFOUND 0x0010 62 #define BASERR_REASON_STORAGENOTFOUND 0x0020 63 #define BASERR_REASON_BASICLOADERROR 0x0040 64 #define BASERR_REASON_NOSTORAGENAME 0x0080 65 66 #define BASERR_REASON_STDLIB 0x0100 67 68 class BasicError 69 { 70 private: 71 sal_uIntPtr nErrorId; 72 sal_uInt16 nReason; 73 String aErrStr; 74 75 public: 76 BasicError(); 77 BasicError( const BasicError& rErr ); 78 BasicError( sal_uIntPtr nId, sal_uInt16 nR, const String& rErrStr ); 79 80 sal_uIntPtr GetErrorId() const { return nErrorId; } 81 sal_uInt16 GetReason() const { return nReason; } 82 String GetErrorStr() { return aErrStr; } 83 84 void SetErrorId( sal_uIntPtr n ) { nErrorId = n; } 85 void SetReason( sal_uInt16 n ) { nReason = n; } 86 void SetErrorStr( const String& rStr) { aErrStr = rStr; } 87 }; 88 89 90 // 91 92 class BasicLibs; 93 class ErrorManager; 94 class BasicLibInfo; 95 class BasicErrorManager; 96 namespace basic { class BasicManagerCleaner; } 97 98 // Library password handling for 5.0 documents 99 class OldBasicPassword 100 { 101 public: 102 virtual void setLibraryPassword( const String& rLibraryName, const String& rPassword ) = 0; 103 virtual String getLibraryPassword( const String& rLibraryName ) = 0; 104 virtual void clearLibraryPassword( const String& rLibraryName ) = 0; 105 virtual sal_Bool hasLibraryPassword( const String& rLibraryName ) = 0; 106 }; 107 108 struct LibraryContainerInfo 109 { 110 ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > mxScriptCont; 111 ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > mxDialogCont; 112 OldBasicPassword* mpOldBasicPassword; 113 114 LibraryContainerInfo() 115 :mpOldBasicPassword( NULL ) 116 { 117 } 118 119 LibraryContainerInfo 120 ( 121 com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > xScriptCont, 122 com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > xDialogCont, 123 OldBasicPassword* pOldBasicPassword 124 ) 125 : mxScriptCont( xScriptCont ) 126 , mxDialogCont( xDialogCont ) 127 , mpOldBasicPassword( pOldBasicPassword ) 128 {} 129 }; 130 131 struct BasicManagerImpl; 132 133 134 #define LIB_NOTFOUND 0xFFFF 135 136 class BasicManager : public SfxBroadcaster 137 { 138 friend class LibraryContainer_Impl; 139 friend class StarBasicAccess_Impl; 140 friend class BasMgrContainerListenerImpl; 141 friend class ::basic::BasicManagerCleaner; 142 143 private: 144 BasicLibs* pLibs; 145 BasicErrorManager* pErrorMgr; 146 147 String aName; 148 String maStorageName; 149 sal_Bool bBasMgrModified; 150 sal_Bool mbDocMgr; 151 152 BasicManagerImpl* mpImpl; 153 154 void Init(); 155 156 protected: 157 sal_Bool ImpLoadLibary( BasicLibInfo* pLibInfo ) const; 158 sal_Bool ImpLoadLibary( BasicLibInfo* pLibInfo, SotStorage* pCurStorage, sal_Bool bInfosOnly = sal_False ) const; 159 void ImpCreateStdLib( StarBASIC* pParentFromStdLib ); 160 void ImpMgrNotLoaded( const String& rStorageName ); 161 BasicLibInfo* CreateLibInfo(); 162 void LoadBasicManager( SotStorage& rStorage, const String& rBaseURL, sal_Bool bLoadBasics = sal_True ); 163 void LoadOldBasicManager( SotStorage& rStorage ); 164 sal_Bool ImplLoadBasic( SvStream& rStrm, StarBASICRef& rOldBasic ) const; 165 sal_Bool ImplEncryptStream( SvStream& rStream ) const; 166 BasicLibInfo* FindLibInfo( StarBASIC* pBasic ) const; 167 void CheckModules( StarBASIC* pBasic, sal_Bool bReference ) const; 168 void SetFlagToAllLibs( short nFlag, sal_Bool bSet ) const; 169 BasicManager(); // Nur zum anpassen von Pfaden bei 'Speichern unter'. 170 ~BasicManager(); 171 172 public: 173 TYPEINFO(); 174 BasicManager( SotStorage& rStorage, const String& rBaseURL, StarBASIC* pParentFromStdLib = NULL, String* pLibPath = NULL, sal_Bool bDocMgr = sal_False ); 175 BasicManager( StarBASIC* pStdLib, String* pLibPath = NULL, sal_Bool bDocMgr = sal_False ); 176 177 /** deletes the given BasicManager instance 178 179 This method is necessary since normally, BasicManager instances are owned by the BasicManagerRepository, 180 and expected to be deleted by the repository only. However, there exists quite some legacy code, 181 which needs to explicitly delete a BasicManager itself. This code must not use the (protected) 182 destructor, but LegacyDeleteBasicManager. 183 */ 184 static void LegacyDeleteBasicManager( BasicManager*& _rpManager ); 185 186 void SetStorageName( const String& rName ) { maStorageName = rName; } 187 String GetStorageName() const { return maStorageName; } 188 void SetName( const String& rName ) { aName = rName; } 189 String GetName() const { return aName; } 190 191 192 sal_uInt16 GetLibCount() const; 193 StarBASIC* GetLib( sal_uInt16 nLib ) const; 194 StarBASIC* GetLib( const String& rName ) const; 195 sal_uInt16 GetLibId( const String& rName ) const; 196 197 String GetLibName( sal_uInt16 nLib ); 198 199 /** announces the library containers which belong to this BasicManager 200 201 The method will automatically add two global constants, BasicLibraries and DialogLibraries, 202 to the BasicManager. 203 */ 204 void SetLibraryContainerInfo( const LibraryContainerInfo& rInfo ); 205 206 const ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer >& 207 GetDialogLibraryContainer() const; 208 const ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer >& 209 GetScriptLibraryContainer() const; 210 211 sal_Bool LoadLib( sal_uInt16 nLib ); 212 sal_Bool RemoveLib( sal_uInt16 nLib, sal_Bool bDelBasicFromStorage ); 213 214 // Modify-Flag wird nur beim Speichern zurueckgesetzt. 215 sal_Bool IsModified() const; 216 sal_Bool IsBasicModified() const; 217 218 sal_Bool HasErrors(); 219 void ClearErrors(); 220 BasicError* GetFirstError(); 221 BasicError* GetNextError(); 222 223 /** sets a global constant in the basic library, referring to some UNO object, to a new value. 224 225 If a constant with this name already existed before, its value is changed, and the old constant is 226 returned. If it does not yet exist, it is newly created, and inserted into the basic library. 227 */ 228 ::com::sun::star::uno::Any 229 SetGlobalUNOConstant( const sal_Char* _pAsciiName, const ::com::sun::star::uno::Any& _rValue ); 230 231 /** 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. */ 232 bool GetGlobalUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::uno::Any& aOut ); 233 /** determines whether there are password-protected modules whose size exceedes the 234 legacy module size 235 @param _out_rModuleNames 236 takes the names of modules whose size exceeds the legacy limit 237 */ 238 bool LegacyPsswdBinaryLimitExceeded( ::com::sun::star::uno::Sequence< rtl::OUString >& _out_rModuleNames ); 239 240 /// determines whether the Basic Manager has a given macro, given by fully qualified name 241 bool HasMacro( String const& i_fullyQualifiedName ) const; 242 /// executes a given macro 243 ErrCode ExecuteMacro( String const& i_fullyQualifiedName, SbxArray* i_arguments, SbxValue* i_retValue ); 244 /// executes a given macro 245 ErrCode ExecuteMacro( String const& i_fullyQualifiedName, String const& i_commaSeparatedArgs, SbxValue* i_retValue ); 246 247 private: 248 sal_Bool IsReference( sal_uInt16 nLib ); 249 250 sal_Bool SetLibName( sal_uInt16 nLib, const String& rName ); 251 252 StarBASIC* GetStdLib() const; 253 StarBASIC* AddLib( SotStorage& rStorage, const String& rLibName, sal_Bool bReference ); 254 sal_Bool RemoveLib( sal_uInt16 nLib ); 255 sal_Bool HasLib( const String& rName ) const; 256 257 StarBASIC* CreateLibForLibContainer( const String& rLibName, 258 const com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer >& 259 xScriptCont ); 260 // For XML import/export: 261 StarBASIC* CreateLib( const String& rLibName ); 262 StarBASIC* CreateLib( const String& rLibName, const String& Password, 263 const String& LinkTargetURL ); 264 }; 265 266 void SetAppBasicManager( BasicManager* pBasMgr ); 267 268 #endif //_BASMGR_HXX 269