diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /include/basic | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/basic')
-rw-r--r-- | include/basic/basicdllapi.h | 23 | ||||
-rw-r--r-- | include/basic/basicmanagerrepository.hxx | 138 | ||||
-rw-r--r-- | include/basic/basmgr.hxx | 208 | ||||
-rw-r--r-- | include/basic/basrdll.hxx | 43 | ||||
-rw-r--r-- | include/basic/codecompletecache.hxx | 93 | ||||
-rw-r--r-- | include/basic/modsizeexceeded.hxx | 67 | ||||
-rw-r--r-- | include/basic/sbdef.hxx | 79 | ||||
-rw-r--r-- | include/basic/sberrors.hxx | 176 | ||||
-rw-r--r-- | include/basic/sbmeth.hxx | 88 | ||||
-rw-r--r-- | include/basic/sbmod.hxx | 168 | ||||
-rw-r--r-- | include/basic/sbstar.hxx | 158 | ||||
-rw-r--r-- | include/basic/sbuno.hxx | 47 | ||||
-rw-r--r-- | include/basic/sbx.hxx | 210 | ||||
-rw-r--r-- | include/basic/sbxcore.hxx | 137 | ||||
-rw-r--r-- | include/basic/sbxdef.hxx | 219 | ||||
-rw-r--r-- | include/basic/sbxmeth.hxx | 44 | ||||
-rw-r--r-- | include/basic/sbxobj.hxx | 87 | ||||
-rw-r--r-- | include/basic/sbxvar.hxx | 336 | ||||
-rw-r--r-- | include/basic/vbahelper.hxx | 94 |
19 files changed, 2415 insertions, 0 deletions
diff --git a/include/basic/basicdllapi.h b/include/basic/basicdllapi.h new file mode 100644 index 0000000000..90b1f78616 --- /dev/null +++ b/include/basic/basicdllapi.h @@ -0,0 +1,23 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef INCLUDED_BASIC_BASICDLLAPI_H +#define INCLUDED_BASIC_BASICDLLAPI_H + +#include <sal/types.h> + +#if defined(BASIC_DLLIMPLEMENTATION) +#define BASIC_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define BASIC_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif +#define BASIC_DLLPRIVATE SAL_DLLPRIVATE + +#endif // INCLUDED_BASIC_BASICDLLAPI_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/basicmanagerrepository.hxx b/include/basic/basicmanagerrepository.hxx new file mode 100644 index 0000000000..e9e906685e --- /dev/null +++ b/include/basic/basicmanagerrepository.hxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_BASICMANAGERREPOSITORY_HXX +#define INCLUDED_BASIC_BASICMANAGERREPOSITORY_HXX + +#include <basic/basicdllapi.h> + +namespace com::sun::star::frame { class XModel; } +namespace com::sun::star::uno { template <typename > class Reference; } + +class BasicManager; + + +namespace basic +{ + + + //= BasicManagerRepository + + /** specifies a callback for instances which are interested in BasicManagers + created by the BasicManagerRepository. + */ + class BASIC_DLLPUBLIC SAL_NO_VTABLE BasicManagerCreationListener + { + public: + /** is called when a BasicManager has been created + + @param _rxForDocument + denotes the document for which the BasicManager has been created. If this is <NULL/>, + then the BasicManager is the application-wide BasicManager. + + @param _pBasicManager + denotes the BasicManager which has been created. The listener might for instance + decide to add global variables to it, or otherwise initialize it. + */ + virtual void onBasicManagerCreated( + const css::uno::Reference< css::frame::XModel >& _rxForDocument, + BasicManager& _rBasicManager + ) = 0; + + protected: + ~BasicManagerCreationListener() {} + }; + + + //= BasicManagerRepository + + class BASIC_DLLPUBLIC BasicManagerRepository + { + public: + /** returns the BasicManager belonging to the given document + + If the BasicManager does not yet exist, it is created. In this case, if the application's + BasicManager does not yet exist, it is also created. This is necessary since + the application's BasicManager acts as parent for all document's BasicManagers. + + If you're interested in this case - the implicit creation of the application's BasicManager -, + then you need to register as BasicManagerCreationListener. + + @param _rxDocumentModel + denotes the document model whose BasicManager is to be retrieved. Must not be <NULL/>. + The document should support the XDocumentPropertiesSupplier + interface, for retrieving + its title, which is needed in some error conditions. + Also it <em>must</em> support the XStorageBasedDocument interface, since we + must be able to retrieve the document's storage. If this interface is <em>not</em> + supported, creating a new BasicManager will certainly fail. + + @return + the BasicManager for this model. + + @attention + The returned BasicManager instances is owned by the repository. In particular, + you are not allowed to delete it. Instead, the given model is observed: As soon + as it's closed, the associated BasicManager is deleted. + */ + static BasicManager* getDocumentBasicManager( + const css::uno::Reference< css::frame::XModel >& _rxDocumentModel + ); + + /** returns the application-wide BasicManager + + @attention + If the BasicManager is newly created, then it is still owned by the repository. + In particular, you are not allowed to delete it. Instead, call resetApplicationBasicManager + to release the BasicManager. + */ + static BasicManager* getApplicationBasicManager(); + + /** resets the application-wide BasicManager to <NULL/> + */ + static void resetApplicationBasicManager(); + + /** registers a BasicManagerCreationListener instance which is notified whenever + the repository creates a BasicManager instance. + + Note that this listener is <em>not</em> called when somebody else + creates BasicManager instances. + + If the same listener is registered multiple times, it is also notified + multiple times, and needs to be revoked once for each registration. + */ + static void registerCreationListener( + BasicManagerCreationListener& _rListener + ); + + /** revokes a BasicManagerCreationListener instance which has previously + been registered to be notified about created BasicManager instances. + */ + static void revokeCreationListener( + BasicManagerCreationListener& _rListener + ); + }; + + +} // namespace basic + + +#endif // INCLUDED_BASIC_BASICMANAGERREPOSITORY_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/basmgr.hxx b/include/basic/basmgr.hxx new file mode 100644 index 0000000000..1ef4f77cf1 --- /dev/null +++ b/include/basic/basmgr.hxx @@ -0,0 +1,208 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_BASIC_BASMGR_HXX +#define INCLUDED_BASIC_BASMGR_HXX + +#include <utility> +#include <comphelper/errcode.hxx> +#include <svl/SfxBroadcaster.hxx> +#include <basic/sbstar.hxx> +#include <basic/basicdllapi.h> +#include <memory> +#include <string_view> +#include <vector> + +namespace basic { class SfxScriptLibraryContainer; } +namespace com::sun::star::script { class XLibraryContainer; } +namespace com::sun::star::script { class XPersistentLibraryContainer; } +namespace com::sun::star::script { class XStarBasicAccess; } + +class BasicManager; + +// Basic XML Import/Export +BASIC_DLLPUBLIC css::uno::Reference< css::script::XStarBasicAccess > + getStarBasicAccess( BasicManager* pMgr ); + +class SotStorage; + +enum class BasicErrorReason +{ + OPENLIBSTORAGE = 0x0002, + OPENMGRSTREAM = 0x0004, + OPENLIBSTREAM = 0x0008, + LIBNOTFOUND = 0x0010, + STORAGENOTFOUND = 0x0020, + BASICLOADERROR = 0x0040, + STDLIB = 0x0100 +}; + +class BasicError +{ +private: + ErrCodeMsg nErrorId; + BasicErrorReason nReason; + +public: + BasicError( const BasicError& rErr ); + BasicError( ErrCodeMsg nId, BasicErrorReason nR ); + + ErrCodeMsg const & GetErrorId() const { return nErrorId; } +}; + +class BasicLibInfo; + +namespace basic { class ImplRepository; } + +struct LibraryContainerInfo +{ + css::uno::Reference< css::script::XPersistentLibraryContainer > mxScriptCont; + css::uno::Reference< css::script::XPersistentLibraryContainer > mxDialogCont; + basic::SfxScriptLibraryContainer* mpOldBasicPassword; + + LibraryContainerInfo() + :mpOldBasicPassword( nullptr ) + { + } + + LibraryContainerInfo + ( + css::uno::Reference< css::script::XPersistentLibraryContainer > xScriptCont, + css::uno::Reference< css::script::XPersistentLibraryContainer > xDialogCont, + basic::SfxScriptLibraryContainer* pOldBasicPassword + ) + : mxScriptCont(std::move( xScriptCont )) + , mxDialogCont(std::move( xDialogCont )) + , mpOldBasicPassword( pOldBasicPassword ) + {} +}; + +#define LIB_NOTFOUND 0xFFFF + +class BASIC_DLLPUBLIC BasicManager final : public SfxBroadcaster +{ + friend class LibraryContainer_Impl; + friend class StarBasicAccess_Impl; + friend class BasMgrContainerListenerImpl; + friend class ::basic::ImplRepository; + +private: + std::vector<BasicError> aErrors; + + OUString aName; + OUString maStorageName; + bool mbDocMgr; + + LibraryContainerInfo maContainerInfo; + std::vector<std::unique_ptr<BasicLibInfo>> maLibs; + OUString aBasicLibPath; + + bool ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStorage ); + void ImpCreateStdLib( StarBASIC* pParentFromStdLib ); + void ImpMgrNotLoaded( const OUString& rStorageName ); + BasicLibInfo* CreateLibInfo(); + void LoadBasicManager( SotStorage& rStorage, std::u16string_view rBaseURL ); + void LoadOldBasicManager( SotStorage& rStorage ); + bool ImplLoadBasic( SvStream& rStrm, StarBASICRef& rOldBasic ) const; + static bool ImplEncryptStream( SvStream& rStream ); + BasicLibInfo* FindLibInfo( StarBASIC const * pBasic ); + static void CheckModules( StarBASIC* pBasic, bool bReference ); + +public: + BasicManager( SotStorage& rStorage, std::u16string_view rBaseURL, StarBASIC* pParentFromStdLib = nullptr, OUString const * pLibPath = nullptr, bool bDocMgr = false ); + BasicManager( StarBASIC* pStdLib, OUString const * pLibPath = nullptr, bool bDocMgr = false ); + + virtual ~BasicManager() override; + + void SetStorageName( const OUString& rName ) { maStorageName = rName; } + const OUString& GetStorageName() const { return maStorageName; } + void SetName( const OUString& rName ) { aName = rName; } + const OUString& GetName() const { return aName; } + + + sal_uInt16 GetLibCount() const; + StarBASIC* GetLib( sal_uInt16 nLib ) const; + StarBASIC* GetLib( std::u16string_view rName ) const; + sal_uInt16 GetLibId( std::u16string_view rName ) const; + + OUString GetLibName( sal_uInt16 nLib ); + + /** announces the library containers which belong to this BasicManager + + The method will automatically add two global constants, BasicLibraries and DialogLibraries, + to the BasicManager. + */ + void SetLibraryContainerInfo( const LibraryContainerInfo& rInfo ); + + const css::uno::Reference< css::script::XPersistentLibraryContainer >& + GetDialogLibraryContainer() const; + const css::uno::Reference< css::script::XPersistentLibraryContainer >& + GetScriptLibraryContainer() const; + + bool LoadLib( sal_uInt16 nLib ); + bool RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage ); + + // Modify-Flag will be reset only during save. + bool IsBasicModified() const; + + std::vector<BasicError>& GetErrors() { return aErrors;} + + /** sets a global constant in the basic library, referring to some UNO object, to a new value. + + If a constant with this name already existed before, its value is changed, and the old constant is + returned in pOldValue. If it does not yet exist, it is newly created, and inserted into the basic library. + */ + void SetGlobalUNOConstant( const OUString& rName, const css::uno::Any& _rValue, css::uno::Any* pOldValue = nullptr ); + + /** 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. */ + bool GetGlobalUNOConstant( const OUString& rName, css::uno::Any& aOut ); + /** determines whether there are password-protected modules whose size exceeds the + B_IMG_VERSION_12 module size + @param _out_rModuleNames + takes the names of modules whose size exceeds the B_IMG_VERSION_12 limit + */ + bool ImgVersion12PsswdBinaryLimitExceeded( std::vector< OUString >& _out_rModuleNames ); + bool HasExeCode( std::u16string_view ); + /// determines whether the Basic Manager has a given macro, given by fully qualified name + bool HasMacro( OUString const& i_fullyQualifiedName ) const; + /// executes a given macro + ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, SbxArray* i_arguments, SbxValue* i_retValue ); + /// executes a given macro + ErrCode ExecuteMacro( OUString const& i_fullyQualifiedName, std::u16string_view i_commaSeparatedArgs, SbxValue* i_retValue ); + +private: + BASIC_DLLPRIVATE bool IsReference( sal_uInt16 nLib ); + + BASIC_DLLPRIVATE StarBASIC* GetStdLib() const; + BASIC_DLLPRIVATE StarBASIC* AddLib( SotStorage& rStorage, const OUString& rLibName, bool bReference ); + BASIC_DLLPRIVATE void RemoveLib( sal_uInt16 nLib ); + BASIC_DLLPRIVATE bool HasLib( std::u16string_view rName ) const; + + BASIC_DLLPRIVATE StarBASIC* CreateLibForLibContainer( const OUString& rLibName, + const css::uno::Reference< css::script::XLibraryContainer >& xScriptCont ); + // For XML import/export: + BASIC_DLLPRIVATE StarBASIC* CreateLib( const OUString& rLibName ); + BASIC_DLLPRIVATE StarBASIC* CreateLib( const OUString& rLibName, const OUString& Password, + const OUString& LinkTargetURL ); + BasicManager& operator=(BasicManager const &) = delete; //MSVC2015 workaround + BasicManager( BasicManager const&) = delete; //MSVC2015 workaround +}; + +#endif // INCLUDED_BASIC_BASMGR_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/basrdll.hxx b/include/basic/basrdll.hxx new file mode 100644 index 0000000000..2748bf3fd3 --- /dev/null +++ b/include/basic/basrdll.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_BASRDLL_HXX +#define INCLUDED_BASIC_BASRDLL_HXX + +#include <basic/basicdllapi.h> +#include <tools/ref.hxx> + +class BASIC_DLLPUBLIC BasicDLL +{ +private: + tools::SvRef<SvRefBase> m_xImpl; + +public: + BasicDLL(); + ~BasicDLL(); + + static void BasicBreak(); + + static void EnableBreak(bool bEnable); + static void SetDebugMode(bool bDebugMode); +}; + +#endif // INCLUDED_BASIC_BASRDLL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/codecompletecache.hxx b/include/basic/codecompletecache.hxx new file mode 100644 index 0000000000..2c6c0873fc --- /dev/null +++ b/include/basic/codecompletecache.hxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_CODECOMPLETECACHE_HXX +#define INCLUDED_BASIC_CODECOMPLETECACHE_HXX + +#include <config_options.h> +#include <basic/basicdllapi.h> +#include <rtl/ustring.hxx> +#include <unordered_map> + +typedef std::unordered_map< OUString, OUString > CodeCompleteVarTypes; +/* variable name, type */ +typedef std::unordered_map< OUString, CodeCompleteVarTypes > CodeCompleteVarScopes; +/* procedure, CodeCompleteVarTypes */ + +class BASIC_DLLPUBLIC CodeCompleteOptions +{ +/* + * class to store basic code completion + * options + * */ +private: + bool bIsCodeCompleteOn; + bool bIsProcedureAutoCompleteOn; + bool bIsAutoCloseQuotesOn; + bool bIsAutoCloseParenthesisOn; + bool bIsAutoCorrectOn; + bool bExtendedTypeDeclarationOn; + +public: + CodeCompleteOptions(); + + static bool IsCodeCompleteOn(); + static void SetCodeCompleteOn( bool b ); + + static bool IsExtendedTypeDeclaration(); + static void SetExtendedTypeDeclaration( bool b ); + + static bool IsProcedureAutoCompleteOn(); + static void SetProcedureAutoCompleteOn( bool b ); + + static bool IsAutoCloseQuotesOn(); + static void SetAutoCloseQuotesOn( bool b ); + + static bool IsAutoCloseParenthesisOn(); + static void SetAutoCloseParenthesisOn( bool b ); + + static bool IsAutoCorrectOn(); + static void SetAutoCorrectOn( bool b ); +}; + +class UNLESS_MERGELIBS(BASIC_DLLPUBLIC) CodeCompleteDataCache final +{ +/* + * cache to store data for + * code completion + * */ +private: + CodeCompleteVarScopes aVarScopes; + CodeCompleteVarTypes aGlobalVars; + +public: + CodeCompleteDataCache(){} + + friend BASIC_DLLPUBLIC std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache); + + void InsertGlobalVar( const OUString& sVarName, const OUString& sVarType ); + void InsertLocalVar( const OUString& sProcName, const OUString& sVarName, const OUString& sVarType ); + OUString GetVarType( std::u16string_view sVarName ) const; + OUString GetCorrectCaseVarName( std::u16string_view sVarName, std::u16string_view sActProcName ) const; + void Clear(); +}; + +#endif // INCLUDED_BASIC_CODECOMPLETECACHE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/modsizeexceeded.hxx b/include/basic/modsizeexceeded.hxx new file mode 100644 index 0000000000..e2a32f9542 --- /dev/null +++ b/include/basic/modsizeexceeded.hxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_MODSIZEEXCEEDED_HXX +#define INCLUDED_BASIC_MODSIZEEXCEEDED_HXX + +#include <config_options.h> +#include <com/sun/star/task/XInteractionRequest.hpp> +#include <cppuhelper/implbase.hxx> +#include <basic/basicdllapi.h> +#include <comphelper/interaction.hxx> +#include <rtl/ref.hxx> +#include <vector> + +namespace com::sun::star::task { class XInteractionContinuation; } + +#if defined(_MSC_VER) && !defined(__clang__) +// MSVC automatically applies dllexport to template instantiations if they are a base class +// of a dllexport class, and this template instantiation is a case of that. If we don't +// dllimport here, MSVC will complain about duplicate symbols in a mergelibs build. +template class __declspec(dllimport) cppu::WeakImplHelper< css::task::XInteractionRequest >; +#endif + +class UNLESS_MERGELIBS(BASIC_DLLPUBLIC) ModuleSizeExceeded final : public cppu::WeakImplHelper< css::task::XInteractionRequest > +{ +// C++ interface +public: + ModuleSizeExceeded( const std::vector<OUString>& sModules ); + + bool isAbort() const; + bool isApprove() const; + +// UNO interface +public: + virtual css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL getContinuations() override { return m_lContinuations; } + css::uno::Any SAL_CALL getRequest() override + { + return m_aRequest; + } + +// member +private: + css::uno::Any m_aRequest; + css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > m_lContinuations; + rtl::Reference< comphelper::OInteractionAbort > m_xAbort; + rtl::Reference< comphelper::OInteractionApprove> m_xApprove; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sbdef.hxx b/include/basic/sbdef.hxx new file mode 100644 index 0000000000..d864ed8de7 --- /dev/null +++ b/include/basic/sbdef.hxx @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_SBDEF_HXX +#define INCLUDED_BASIC_SBDEF_HXX + +#include <basic/sbxdef.hxx> +#include <rtl/ustring.hxx> +#include <basic/basicdllapi.h> +#include <o3tl/typed_flags_set.hxx> +#include <unotools/resmgr.hxx> + +class ErrCode; + +// Returns type name for Basic type, array flag is ignored +// implementation: basic/source/runtime/methods.cxx +BASIC_DLLPUBLIC OUString getBasicTypeName( SbxDataType eType ); + +// Returns type name for Basic objects, especially +// important for SbUnoObj instances +// implementation: basic/source/classes/sbunoobj.cxx +class SbxObject; +BASIC_DLLPUBLIC OUString getBasicObjectTypeName( SbxObject* pObj ); + +// Allows Basic IDE to set watch mode to suppress errors +// implementation: basic/source/runtime/runtime.cxx +BASIC_DLLPUBLIC void setBasicWatchMode( bool bOn ); + +// Debug Flags: +enum class BasicDebugFlags { + NONE = 0x0000, + Break = 0x0001, // Break-Callback + StepInto = 0x0002, // Single Step-Callback + StepOver = 0x0004, // Additional flag Step Over + Continue = 0x0008, // Do not change flags + StepOut = 0x0010, // Leave Sub +}; +namespace o3tl { + template<> struct typed_flags<BasicDebugFlags> : is_typed_flags<BasicDebugFlags, 0x001f> {}; +} + +#define SBXID_BASIC 0x6273 // sb: StarBASIC +#define SBXID_BASICMOD 0x6d62 // bm: StarBASIC Module +#define SBXID_BASICPROP 0x7262 // pr: StarBASIC Property +#define SBXID_BASICMETHOD 0x6d65 // me: StarBASIC Method +#define SBXID_JSCRIPTMOD 0x6a62 // jm: JavaScript Module +#define SBXID_JSCRIPTMETH 0x6a64 // jm: JavaScript Module + +enum class PropertyMode +{ + NONE, + Get, + Let, + Set +}; + +BASIC_DLLPUBLIC extern std::pair<TranslateId, ErrCode> const RID_BASIC_START[]; +BASIC_DLLPUBLIC std::locale BasResLocale(); +OUString BasResId(TranslateId pId); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sberrors.hxx b/include/basic/sberrors.hxx new file mode 100644 index 0000000000..d630b0747a --- /dev/null +++ b/include/basic/sberrors.hxx @@ -0,0 +1,176 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_SBERRORS_HXX +#define INCLUDED_BASIC_SBERRORS_HXX + +#include <comphelper/errcode.hxx> + +#define ERRCODE_BASIC_SYNTAX ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 1) // unspecified syntax error +#define ERRCODE_BASIC_BAD_ARGUMENT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::NotSupported, 2) // Invalid procedure call +#define ERRCODE_BASIC_MATH_OVERFLOW ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Sbx, 3) // overflow +#define ERRCODE_BASIC_OUT_OF_RANGE ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Sbx, 4) // Invalid array index / Subscript out of range +#define ERRCODE_BASIC_ZERODIV ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Sbx, 5) // Division by zero +#define ERRCODE_BASIC_CONVERSION ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Sbx, 6) // wrong data type +#define ERRCODE_BASIC_BAD_PARAMETER ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 7) // invalid Parameter +#define ERRCODE_BASIC_PROC_UNDEFINED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 8) // Sub or Function not defined +#define ERRCODE_BASIC_INTERNAL_ERROR ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Unknown, 9) // generic object error +#define ERRCODE_BASIC_NO_OBJECT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 10) // Object variable not set +#define ERRCODE_BASIC_CANNOT_LOAD ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Create, 11) // Can't load module +#define ERRCODE_BASIC_BAD_INDEX ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Sbx, 12) // Invalid object index +#define ERRCODE_BASIC_NO_ACTIVE_OBJECT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Access, 13) // No active view or document +#define ERRCODE_BASIC_BAD_PROP_VALUE ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 14) // Bad property value +#define ERRCODE_BASIC_PROP_READONLY ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Read, 15) // Property is read only +#define ERRCODE_BASIC_PROP_WRITEONLY ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Write, 16) // Property is write only +#define ERRCODE_BASIC_INVALID_OBJECT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Access, 17) // Invalid object reference +#define ERRCODE_BASIC_NO_METHOD ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 18) // Property or Method unknown +#define ERRCODE_BASIC_INVALID_USAGE_OBJECT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Access, 19) // Invalid object usage +#define ERRCODE_BASIC_NO_OLE ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Access, 20) // Class does not support OLE +#define ERRCODE_BASIC_BAD_METHOD ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 21) // Method not supported +#define ERRCODE_BASIC_OLE_ERROR ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 22) // OLE Automation Error +#define ERRCODE_BASIC_BAD_ACTION ErrCode( ErrCodeArea::Sbx, ErrCodeClass::NotSupported, 23) // Object doesn't support this action +#define ERRCODE_BASIC_NO_NAMED_ARGS ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 24) // Object doesn't support named args +#define ERRCODE_BASIC_BAD_LOCALE ErrCode( ErrCodeArea::Sbx, ErrCodeClass::NotSupported, 25) // Object doesn't support current locale setting +#define ERRCODE_BASIC_NAMED_NOT_FOUND ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 26) // Named argument not found +#define ERRCODE_BASIC_NOT_OPTIONAL ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 27) // Argument not optional +#define ERRCODE_BASIC_WRONG_ARGS ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Sbx, 28) // Invalid number of arguments +#define ERRCODE_BASIC_NOT_A_COLL ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 29) // Object not a collection + +#define ERRCODE_BASIC_NO_GOSUB ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 30 ) // Return without Gosub +#define ERRCODE_BASIC_REDO_FROM_START ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 31 ) // Redo form start (SB internal) +#define ERRCODE_BASIC_NO_MEMORY ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 32 ) // Out of memory +#define ERRCODE_BASIC_ALREADY_DIM ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 33 ) // Array already dimensioned +#define ERRCODE_BASIC_DUPLICATE_DEF ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 34 ) // Duplicate definition +#define ERRCODE_BASIC_VAR_UNDEFINED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 35 ) // Variable undefined (SB) +#define ERRCODE_BASIC_USER_ABORT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 36 ) // User interrupt occurred +#define ERRCODE_BASIC_BAD_RESUME ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 37 ) // Resume without error +#define ERRCODE_BASIC_STACK_OVERFLOW ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 38 ) // Out of stack space +#define ERRCODE_BASIC_BAD_DLL_LOAD ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 39 ) // Error in loading DLL +#define ERRCODE_BASIC_BAD_DLL_CALL ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 40 ) // Bad DLL calling convention +#define ERRCODE_BASIC_BAD_CHANNEL ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 41 ) // Bad file name or number +#define ERRCODE_BASIC_FILE_NOT_FOUND ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 42 ) // File not found +#define ERRCODE_BASIC_BAD_FILE_MODE ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 43 ) // Bad file mode +#define ERRCODE_BASIC_FILE_ALREADY_OPEN ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 44 ) // File already open +#define ERRCODE_BASIC_IO_ERROR ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 45 ) // Device I/O error +#define ERRCODE_BASIC_FILE_EXISTS ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 46 ) // File already exists +#define ERRCODE_BASIC_BAD_RECORD_LENGTH ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 47 ) // bad record length +#define ERRCODE_BASIC_DISK_FULL ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 48 ) // disk full +#define ERRCODE_BASIC_READ_PAST_EOF ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 49 ) // Input past end of file +#define ERRCODE_BASIC_BAD_RECORD_NUMBER ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 50 ) // Bad record number +#define ERRCODE_BASIC_TOO_MANY_FILES ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 51 ) // Too many files +#define ERRCODE_BASIC_NO_DEVICE ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 52 ) // Device not available +#define ERRCODE_BASIC_ACCESS_DENIED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 53 ) // Permission denied +#define ERRCODE_BASIC_NOT_READY ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 54 ) // Disk not ready +#define ERRCODE_BASIC_NOT_IMPLEMENTED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 55 ) // Feature not implemented +#define ERRCODE_BASIC_DIFFERENT_DRIVE ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 56 ) // No rename with different drive +#define ERRCODE_BASIC_ACCESS_ERROR ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 57 ) // Path/File access error +#define ERRCODE_BASIC_PATH_NOT_FOUND ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 58 ) // Path not found +#define ERRCODE_BASIC_BAD_PATTERN ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 59 ) // Invalid pattern string +#define ERRCODE_BASIC_IS_NULL ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 60 ) // Invalid use of Null + +#define ERRCODE_BASIC_DDE_ERROR ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 61 ) +#define ERRCODE_BASIC_DDE_WAITINGACK ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 62 ) +#define ERRCODE_BASIC_DDE_OUTOFCHANNELS ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 63 ) +#define ERRCODE_BASIC_DDE_NO_RESPONSE ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 64 ) +#define ERRCODE_BASIC_DDE_MULT_RESPONSES ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 65 ) +#define ERRCODE_BASIC_DDE_CHANNEL_LOCKED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 66 ) +#define ERRCODE_BASIC_DDE_NOTPROCESSED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 67 ) +#define ERRCODE_BASIC_DDE_TIMEOUT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 68 ) +#define ERRCODE_BASIC_DDE_USER_INTERRUPT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 69 ) +#define ERRCODE_BASIC_DDE_BUSY ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 70 ) +#define ERRCODE_BASIC_DDE_NO_DATA ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 71 ) +#define ERRCODE_BASIC_DDE_WRONG_DATA_FORMAT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 72 ) +#define ERRCODE_BASIC_DDE_PARTNER_QUIT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 73 ) +#define ERRCODE_BASIC_DDE_CONV_CLOSED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 74 ) +#define ERRCODE_BASIC_DDE_NO_CHANNEL ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 75 ) +#define ERRCODE_BASIC_DDE_INVALID_LINK ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 76 ) +#define ERRCODE_BASIC_DDE_QUEUE_OVERFLOW ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 77 ) +#define ERRCODE_BASIC_DDE_LINK_ALREADY_EST ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 78 ) +#define ERRCODE_BASIC_DDE_LINK_INV_TOPIC ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 79 ) +#define ERRCODE_BASIC_DDE_DLL_NOT_FOUND ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 80 ) + +#define ERRCODE_BASIC_NEEDS_OBJECT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 81 ) // Object required +#define ERRCODE_BASIC_BAD_ORDINAL ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 82 ) // Invalid ordinal +#define ERRCODE_BASIC_DLLPROC_NOT_FOUND ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 83 ) // Specified DLL function not found +#define ERRCODE_BASIC_BAD_CLIPBD_FORMAT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 84 ) // Invalid clipboard format + +#define ERRCODE_BASIC_PROPERTY_NOT_FOUND ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 85 ) // Class not have property +#define ERRCODE_BASIC_METHOD_NOT_FOUND ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 86 ) // Class does not have method +#define ERRCODE_BASIC_ARG_MISSING ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 87 ) // Missing required argument +#define ERRCODE_BASIC_BAD_NUMBER_OF_ARGS ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 88 ) // Bad number of arguments +#define ERRCODE_BASIC_METHOD_FAILED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 89 ) // Method failed +#define ERRCODE_BASIC_SETPROP_FAILED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 90 ) // Unable to set property +#define ERRCODE_BASIC_GETPROP_FAILED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 91 ) // Unable to get property + +// Compiler Errors (do not occur at runtime) +// These IDs can shift at any time + +#define ERRCODE_BASIC_UNEXPECTED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 92 ) // Unexpected symbol: xx +#define ERRCODE_BASIC_EXPECTED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 93 ) // Expected: xx +#define ERRCODE_BASIC_SYMBOL_EXPECTED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 94 ) // Symbol expected +#define ERRCODE_BASIC_VAR_EXPECTED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 95 ) // Variable expected +#define ERRCODE_BASIC_LABEL_EXPECTED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 96 ) // Label expected +#define ERRCODE_BASIC_LVALUE_EXPECTED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 97 ) // Lvalue expected +#define ERRCODE_BASIC_VAR_DEFINED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 98 ) // Variable xxx already defined +#define ERRCODE_BASIC_PROC_DEFINED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 99 ) // Procedure xx already defined +#define ERRCODE_BASIC_LABEL_DEFINED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 100 ) // Label xxx already defined +#define ERRCODE_BASIC_UNDEF_VAR ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 101 ) // Variable xx undefined +#define ERRCODE_BASIC_UNDEF_ARRAY ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 102 ) // Array or function xx undefined +#define ERRCODE_BASIC_UNDEF_PROC ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 103 ) // Procedure xxx undefined +#define ERRCODE_BASIC_UNDEF_LABEL ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 104 ) // Label xxx undefined +#define ERRCODE_BASIC_UNDEF_TYPE ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 105 ) // Unknown user defined type xxx +#define ERRCODE_BASIC_BAD_EXIT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 106 ) // Exit XXX expected +#define ERRCODE_BASIC_BAD_BLOCK ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 107 ) // Unterminated statement block: missing XX +#define ERRCODE_BASIC_BAD_BRACKETS ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 108 ) // Parentheses do not match +#define ERRCODE_BASIC_BAD_DECLARATION ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 109 ) // Symbol xx defined differently +#define ERRCODE_BASIC_BAD_PARAMETERS ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 110 ) // Parameters do not match +#define ERRCODE_BASIC_BAD_CHAR_IN_NUMBER ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 111 ) // Bad character in number +#define ERRCODE_BASIC_MUST_HAVE_DIMS ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 112 ) // Array needs dimensioning +#define ERRCODE_BASIC_NO_IF ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 113 ) // Else/Endif without If +#define ERRCODE_BASIC_NOT_IN_SUBR ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 114 ) // xxx not allowed within a sub +#define ERRCODE_BASIC_NOT_IN_MAIN ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 115 ) // xxx not allowed outside a sub +#define ERRCODE_BASIC_WRONG_DIMS ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 116 ) // Dimensions do not match +#define ERRCODE_BASIC_BAD_OPTION ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 117 ) // Unknown option: xxx +#define ERRCODE_BASIC_CONSTANT_REDECLARED ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 118 ) // Constant xx redeclared +#define ERRCODE_BASIC_PROG_TOO_LARGE ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 119 ) // Program is too large +#define ERRCODE_BASIC_NO_STRINGS_ARRAYS ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 120 ) +#define ERRCODE_BASIC_EXCEPTION ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 121 ) + +#define ERRCODE_BASMGR_STDLIBOPEN ErrCode( ErrCodeArea::Sbx, 122) +#define ERRCODE_BASMGR_STDLIBSAVE ErrCode( ErrCodeArea::Sbx, 123) +#define ERRCODE_BASMGR_LIBLOAD ErrCode( ErrCodeArea::Sbx, 124) +#define ERRCODE_BASMGR_LIBCREATE ErrCode( ErrCodeArea::Sbx, 125) +#define ERRCODE_BASMGR_LIBSAVE ErrCode( ErrCodeArea::Sbx, 126) +#define ERRCODE_BASMGR_LIBDEL ErrCode( ErrCodeArea::Sbx, 127) +#define ERRCODE_BASMGR_MGROPEN ErrCode( ErrCodeArea::Sbx, 128) +#define ERRCODE_BASMGR_MGRSAVE ErrCode( ErrCodeArea::Sbx, 129) +#define ERRCODE_BASMGR_REMOVELIB ErrCode( ErrCodeArea::Sbx, 130) +#define ERRCODE_BASMGR_UNLOADLIB ErrCode( ErrCodeArea::Sbx, 131) + +#define ERRCODE_BASIC_COMPAT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 132 ) +#define ERRCODE_BASIC_ARRAY_FIX ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 133 ) // This array is fixed +#define ERRCODE_BASIC_STRING_OVERFLOW ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 134 ) // Out of string space +#define ERRCODE_BASIC_EXPR_TOO_COMPLEX ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 135 ) // Expression too complex +#define ERRCODE_BASIC_OPER_NOT_PERFORM ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 136 ) // Can't perform requested operation +#define ERRCODE_BASIC_TOO_MANY_DLL ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 137 ) // Too many dll application clients +#define ERRCODE_BASIC_LOOP_NOT_INIT ErrCode( ErrCodeArea::Sbx, ErrCodeClass::Compiler, 138 ) // For loop not initialized + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sbmeth.hxx b/include/basic/sbmeth.hxx new file mode 100644 index 0000000000..50a0186d4a --- /dev/null +++ b/include/basic/sbmeth.hxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_SBMETH_HXX +#define INCLUDED_BASIC_SBMETH_HXX + +#include <comphelper/errcode.hxx> +#include <basic/sbxmeth.hxx> +#include <basic/sbdef.hxx> +#include <basic/basicdllapi.h> + +class SbModule; + +class BASIC_DLLPUBLIC SbMethod : public SbxMethod +{ + friend class SbiRuntime; + friend class SbiFactory; + friend class SbModule; + friend class SbClassModuleObject; + friend class SbiCodeGen; + friend class SbJScriptMethod; + friend class SbIfaceMapperMethod; + + SbxVariable* mCaller; // caller + SbModule* pMod; + BasicDebugFlags nDebugFlags; + sal_uInt16 nLine1, nLine2; + sal_uInt32 nStart; + bool bInvalid; + SbxArrayRef refStatics; + BASIC_DLLPRIVATE SbMethod( const OUString&, SbxDataType, SbModule* ); + BASIC_DLLPRIVATE SbMethod( const SbMethod& ); + virtual bool LoadData( SvStream&, sal_uInt16 ) override; + virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override; + virtual ~SbMethod() override; + +public: + SBX_DECL_PERSIST_NODATA(SBXID_BASICMETHOD,2); + virtual SbxInfo* GetInfo() override; + SbxArray* GetStatics(); + void ClearStatics(); + SbModule* GetModule() { return pMod; } + BasicDebugFlags GetDebugFlags() const { return nDebugFlags; } + void SetDebugFlags( BasicDebugFlags n ) { nDebugFlags = n; } + void GetLineRange( sal_uInt16&, sal_uInt16& ); + + // Interface to execute a method from the applications + ErrCode Call( SbxValue* pRet, SbxVariable* pCaller = nullptr ); + virtual void Broadcast( SfxHintId nHintId ) override; +}; + +typedef tools::SvRef<SbMethod> SbMethodRef; + +class SbIfaceMapperMethod final : public SbMethod +{ + friend class SbiRuntime; + + SbMethodRef mxImplMeth; + +public: + SbIfaceMapperMethod( const OUString& rName, SbMethod* pImplMeth ) + : SbMethod( rName, pImplMeth->GetType(), nullptr ) + , mxImplMeth( pImplMeth ) + {} + virtual ~SbIfaceMapperMethod() override; + SbMethod* getImplMethod() + { return mxImplMeth.get(); } +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sbmod.hxx b/include/basic/sbmod.hxx new file mode 100644 index 0000000000..5c369b441f --- /dev/null +++ b/include/basic/sbmod.hxx @@ -0,0 +1,168 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_SBMOD_HXX +#define INCLUDED_BASIC_SBMOD_HXX + +#include <config_options.h> +#include <basic/sbdef.hxx> +#include <basic/sbxobj.hxx> +#include <basic/sbxdef.hxx> +#include <basic/sbx.hxx> +#include <rtl/ustring.hxx> +#include <vector> +#include <deque> +#include <basic/basicdllapi.h> +#include <com/sun/star/uno/Reference.hxx> + +namespace com::sun::star::script { class XInvocation; } + +class SbMethod; +class SbProperty; +typedef std::deque< sal_uInt16 > SbiBreakpoints; +class SbiImage; +class SbClassModuleObject; +class CodeCompleteDataCache; +class SbUnoObject; + +class ModuleInitDependencyMap; +struct ClassModuleRunInitItem; +struct SbClassData; + +class BASIC_DLLPUBLIC SbModule : public SbxObject +{ + friend class SbiCodeGen; + friend class SbMethod; + friend class SbiRuntime; + friend class StarBASIC; + friend class SbClassModuleObject; + + std::vector< OUString > mModuleVariableNames; + + BASIC_DLLPRIVATE static void implClearIfVarDependsOnDeletedBasic( SbxVariable* pVar, StarBASIC* pDeletedBasic ); + + SbModule(const SbModule&) = delete; + SbModule& operator=(const SbModule&) = delete; +protected: + css::uno::Reference< css::script::XInvocation > mxWrapper; + OUString aOUSource; + OUString aComment; + std::unique_ptr<SbiImage> pImage; // the Image + SbiBreakpoints* pBreaks; // Breakpoints + std::unique_ptr<SbClassData> pClassData; + bool mbVBASupport; // Option VBASupport + bool mbCompat; // Option Compatible + sal_Int32 mnType; + tools::SvRef<SbUnoObject> pDocObject; // an impl object ( used by Document Modules ) + bool bIsProxyModule; + + SAL_DLLPRIVATE static void implProcessModuleRunInit( ModuleInitDependencyMap& rMap, ClassModuleRunInitItem& rItem ); + SAL_DLLPRIVATE void StartDefinitions(); + SAL_DLLPRIVATE SbMethod* GetMethod( const OUString&, SbxDataType ); + SAL_DLLPRIVATE SbProperty* GetProperty( const OUString&, SbxDataType ); + SAL_DLLPRIVATE void GetProcedureProperty( const OUString&, SbxDataType ); + SAL_DLLPRIVATE void GetIfaceMapperMethod( const OUString&, SbMethod* ); + SAL_DLLPRIVATE void EndDefinitions( bool=false ); + SAL_DLLPRIVATE void Run( SbMethod* ); + SAL_DLLPRIVATE void RunInit(); + SAL_DLLPRIVATE void ClearPrivateVars(); + SAL_DLLPRIVATE void ClearVarsDependingOnDeletedBasic( StarBASIC* pDeletedBasic ); + SAL_DLLPRIVATE void GlobalRunInit( bool bBasicStart ); // for all modules + SAL_DLLPRIVATE void GlobalRunDeInit(); + SAL_DLLPRIVATE const sal_uInt8* FindNextStmnt( const sal_uInt8*, sal_uInt16&, sal_uInt16& ) const; + SAL_DLLPRIVATE const sal_uInt8* FindNextStmnt( const sal_uInt8*, sal_uInt16&, sal_uInt16&, + bool bFollowJumps, const SbiImage* pImg=nullptr ) const; + SAL_DLLPRIVATE virtual bool LoadData( SvStream&, sal_uInt16 ) override; + SAL_DLLPRIVATE virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override; + SAL_DLLPRIVATE virtual bool LoadCompleted() override; + SAL_DLLPRIVATE virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; + SAL_DLLPRIVATE void handleProcedureProperties( SfxBroadcaster& rBC, const SfxHint& rHint ); + virtual ~SbModule() override; + bool IsOptionCompatible() const override { return mbCompat; } + +public: + SBX_DECL_PERSIST_NODATA(SBXID_BASICMOD,2); + SbModule( const OUString&, bool bVBASupport = false ); + SAL_DLLPRIVATE virtual void SetParent( SbxObject* ) override; + SAL_DLLPRIVATE virtual void Clear() override; + + SAL_DLLPRIVATE virtual SbxVariable* Find( const OUString&, SbxClassType ) override; + + const OUString& GetSource32() const { return aOUSource;} + void SetSource32( const OUString& r ); + + bool Compile(); + bool IsCompiled() const; + SAL_DLLPRIVATE const SbxObject* FindType( const OUString& aTypeName ) const; + + SAL_DLLPRIVATE bool IsBreakable( sal_uInt16 nLine ) const; + SAL_DLLPRIVATE bool IsBP( sal_uInt16 nLine ) const; + bool SetBP( sal_uInt16 nLine ); + bool ClearBP( sal_uInt16 nLine ); + void ClearAllBP(); + + // Store only image, no source (needed for new password protection) + SAL_DLLPRIVATE void StoreBinaryData( SvStream& ); + SAL_DLLPRIVATE void LoadBinaryData( SvStream& ); + SAL_DLLPRIVATE bool ExceedsImgVersion12ModuleSize(); + SAL_DLLPRIVATE void fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg = nullptr ) const; + SAL_DLLPRIVATE bool HasExeCode(); + bool IsVBASupport() const { return mbVBASupport; } + SAL_DLLPRIVATE void SetVBASupport( bool bSupport ); + sal_Int32 GetModuleType() const { return mnType; } + void SetModuleType( sal_Int32 nType ) { mnType = nType; } + bool isProxyModule() const { return bIsProxyModule; } + SAL_DLLPRIVATE void AddVarName( const OUString& aName ); + SAL_DLLPRIVATE void RemoveVars(); + css::uno::Reference< css::script::XInvocation > const & GetUnoModule(); + bool createCOMWrapperForIface( css::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject ); + void GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache); + const SbxArrayRef& GetMethods() const { return pMethods;} + SbMethod* FindMethod( const OUString&, SbxClassType ); + static OUString GetKeywordCase( std::u16string_view sKeyword ); +}; + +typedef tools::SvRef<SbModule> SbModuleRef; +typedef std::vector<SbModuleRef> SbModules; + +// Object class for instances of class modules +class UNLESS_MERGELIBS(BASIC_DLLPUBLIC) SbClassModuleObject final : public SbModule +{ + SbModule* mpClassModule; + bool mbInitializeEventDone; + +public: + SbClassModuleObject( SbModule* pClassModule ); + virtual ~SbClassModuleObject() override; + + // Overridden to support NameAccess etc. + virtual SbxVariable* Find( const OUString&, SbxClassType ) override; + + virtual void Notify( SfxBroadcaster&, const SfxHint& rHint ) override; + + SbModule* getClassModule() + { return mpClassModule; } + + void triggerInitializeEvent(); + void triggerTerminateEvent(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sbstar.hxx b/include/basic/sbstar.hxx new file mode 100644 index 0000000000..599f14aa4b --- /dev/null +++ b/include/basic/sbstar.hxx @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_SBSTAR_HXX +#define INCLUDED_BASIC_SBSTAR_HXX + +#include <basic/sbx.hxx> +#include <basic/sbxobj.hxx> +#include <basic/sbmod.hxx> +#include <rtl/ustring.hxx> +#include <tools/link.hxx> +#include <comphelper/errcode.hxx> + +#include <basic/sbdef.hxx> +#include <basic/basicdllapi.h> + +namespace com::sun::star::frame { class XModel; } +namespace com::sun::star::script { struct ModuleInfo; } + +class SbMethod; + +class BASIC_DLLPUBLIC StarBASIC final : public SbxObject +{ + friend class SbiScanner; + friend class SbiExpression; // Access to RTL + friend class SbiInstance; // runtime instance + friend class SbiRuntime; // currently running procedure + friend class DocBasicItem; + + SbModules pModules; // List of all modules + SbxObjectRef pRtl; // Runtime Library + SbxArrayRef xUnoListeners; // Listener handled by CreateUnoListener + + // Handler-Support: + Link<StarBASIC*,bool> aErrorHdl; // Error handler + Link<StarBASIC*,BasicDebugFlags> aBreakHdl; // Breakpoint handler + bool bNoRtl; // if true: do not search RTL + bool bBreak; // if true: Break, otherwise Step + bool bDocBasic; + bool bVBAEnabled; + bool bQuit; + + SbxObjectRef pVBAGlobals; + + BASIC_DLLPRIVATE void implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic ); + bool CError( ErrCode, const OUString&, sal_Int32, sal_Int32, sal_Int32 ); + BASIC_DLLPRIVATE bool RTError( ErrCode, const OUString& rMsg, sal_Int32, sal_Int32, sal_Int32 ); + BASIC_DLLPRIVATE BasicDebugFlags BreakPoint( sal_Int32 nLine, sal_Int32 nCol1, sal_Int32 nCol2 ); + BASIC_DLLPRIVATE BasicDebugFlags StepPoint( sal_Int32 nLine, sal_Int32 nCol1, sal_Int32 nCol2 ); + virtual bool LoadData( SvStream&, sal_uInt16 ) override; + virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override; + bool ErrorHdl(); + BasicDebugFlags BreakHdl(); + virtual ~StarBASIC() override; + +public: + + SBX_DECL_PERSIST_NODATA(SBXID_BASIC,1); + + StarBASIC( StarBASIC* pParent = nullptr, bool bIsDocBasic = false ); + + // #51727 SetModified overridden so that the Modified-State is + // not delivered to Parent. + virtual void SetModified( bool ) override; + + virtual void Insert( SbxVariable* ) override; + using SbxObject::Remove; + virtual void Remove( SbxVariable* ) override; + virtual void Clear() override; + + // Compiler-Interface + SbModule* MakeModule( const OUString& rName, const OUString& rSrc ); + SbModule* MakeModule( const OUString& rName, const css::script::ModuleInfo& mInfo, const OUString& rSrc ); + static void Stop(); + static void Error( ErrCode, const OUString& rMsg = {} ); + static void FatalError( ErrCode ); + static void FatalError( ErrCode, const OUString& rMsg ); + static bool IsRunning(); + static ErrCode GetErrBasic(); + // #66536 make additional message accessible by RTL function Error + static OUString GetErrorMsg(); + static sal_Int32 GetErl(); + + virtual SbxVariable* Find( const OUString&, SbxClassType ) override; + virtual bool Call( const OUString&, SbxArray* = nullptr ) override; + + SbModules& GetModules() { return pModules; } + SbxObject* GetRtl() { return pRtl.get(); } + SbModule* FindModule( std::u16string_view ); + // Run init code of all modules (including the inserted Doc-Basics) + void InitAllModules( StarBASIC const * pBasicNotToInit = nullptr ); + void DeInitAllModules(); + void ClearAllModuleVars(); + + // Calls for error and break handler + static sal_uInt16 GetLine(); + static sal_uInt16 GetCol1(); + static sal_uInt16 GetCol2(); + static void SetErrorData( const ErrCodeMsg& nCode, sal_uInt16 nLine, + sal_uInt16 nCol1, sal_uInt16 nCol2 ); + + // Specific to error handler + static void MakeErrorText( ErrCode, std::u16string_view aMsg ); + static const OUString& GetErrorText(); + static ErrCodeMsg const & GetErrorCode(); + static sal_uInt16 GetVBErrorCode( ErrCode nError ); + static ErrCode GetSfxFromVBError( sal_uInt16 nError ); + bool IsBreak() const { return bBreak; } + + static Link<StarBASIC*,bool> const & GetGlobalErrorHdl(); + static void SetGlobalErrorHdl( const Link<StarBASIC*,bool>& rNewHdl ); + + static void SetGlobalBreakHdl( const Link<StarBASIC*,BasicDebugFlags>& rNewHdl ); + + SbxArrayRef const & getUnoListeners(); + + static SbxBase* FindSBXInCurrentScope( const OUString& rName ); + static SbMethod* GetActiveMethod( sal_uInt16 nLevel = 0 ); + static SbModule* GetActiveModule(); + void SetVBAEnabled( bool bEnabled ); + bool isVBAEnabled() const; + + const SbxObjectRef& getRTL() const { return pRtl; } + bool IsDocBasic() const { return bDocBasic; } + SbxVariable* VBAFind( const OUString& rName, SbxClassType t ); + bool GetUNOConstant( const OUString& rName, css::uno::Any& aOut ); + void QuitAndExitApplication(); + bool IsQuitApplication() const { return bQuit; }; + + SbxObject* getVBAGlobals( ); + + static css::uno::Reference< css::frame::XModel > + GetModelFromBasic( SbxObject* pBasic ); + + static void DetachAllDocBasicItems(); +}; + +typedef tools::SvRef<StarBASIC> StarBASICRef; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sbuno.hxx b/include/basic/sbuno.hxx new file mode 100644 index 0000000000..4c53215d9c --- /dev/null +++ b/include/basic/sbuno.hxx @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_SBUNO_HXX +#define INCLUDED_BASIC_SBUNO_HXX + +#include <com/sun/star/uno/Type.hxx> +#include <basic/sbxvar.hxx> +#include <basic/basicdllapi.h> + +namespace com::sun::star::uno { class Any; } +namespace com::sun::star::beans { struct Property; } + +class SbxObject; + +// Returns a SbxObject that wraps a Uno Interface +// Implementation in basic/source/classes/sbunoobj.cxx +BASIC_DLLPUBLIC SbxObjectRef GetSbUnoObject( const OUString& aName, const css::uno::Any& aUnoObj_ ); + +// Force creation of all properties for debugging +BASIC_DLLPUBLIC void createAllObjectProperties( SbxObject* pObj ); +BASIC_DLLPUBLIC void SetSbUnoObjectDfltPropName( SbxObject* pObj ); + +BASIC_DLLPUBLIC css::uno::Any sbxToUnoValue( const SbxValue* pVar ); +css::uno::Any sbxToUnoValue( const SbxValue* pVar, const css::uno::Type& rType, css::beans::Property const * pUnoProperty = nullptr ); + +BASIC_DLLPUBLIC void unoToSbxValue( SbxVariable* pVar, const css::uno::Any& aValue ); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sbx.hxx b/include/basic/sbx.hxx new file mode 100644 index 0000000000..eb90072323 --- /dev/null +++ b/include/basic/sbx.hxx @@ -0,0 +1,210 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <config_options.h> +#include <tools/ref.hxx> +#include <svl/hint.hxx> + +#include <basic/sbxdef.hxx> +#include <basic/sbxobj.hxx> +#include <basic/basicdllapi.h> + +#include <utility> +#include <vector> +#include <memory> + +class SvStream; + +class SfxBroadcaster; + +// Parameter information +struct SbxParamInfo +{ + const OUString aName; // Name of the parameter + SbxDataType eType; // Data type + SbxFlagBits nFlags; // Flag-Bits + sal_uInt32 nUserData; // IDs etc. + SbxParamInfo( OUString s, SbxDataType t, SbxFlagBits n ) + : aName(std::move( s )), eType( t ), nFlags( n ), nUserData( 0 ) {} +}; + +typedef std::vector<std::unique_ptr<SbxParamInfo>> SbxParams; + +class UNLESS_MERGELIBS(BASIC_DLLPUBLIC) SbxInfo final : public SvRefBase +{ + friend class SbxVariable; + friend class SbMethod; + + OUString aComment; + OUString aHelpFile; + sal_uInt32 nHelpId; + SbxParams m_Params; + + SbxInfo(SbxInfo const&) = delete; + void operator=(SbxInfo const&) = delete; + + void LoadData( SvStream&, sal_uInt16 ); + void StoreData( SvStream& ) const; + virtual ~SbxInfo() override; +public: + SbxInfo(); + SbxInfo( OUString , sal_uInt32 ); + + void AddParam( const OUString&, SbxDataType, SbxFlagBits=SbxFlagBits::Read ); + const SbxParamInfo* GetParam( sal_uInt16 n ) const; // index starts with 1! + const OUString& GetComment() const { return aComment; } + const OUString& GetHelpFile() const { return aHelpFile; } + sal_uInt32 GetHelpId() const { return nHelpId; } + + void SetComment( const OUString& r ) { aComment = r; } +}; + +class BASIC_DLLPUBLIC SbxHint final : public SfxHint +{ + SbxVariable* pVar; +public: + SbxHint( SfxHintId n, SbxVariable* v ) : SfxHint( n ), pVar( v ) {} + SbxVariable* GetVar() const { return pVar; } +}; + +// SbxArray is an unidimensional, dynamic Array +// The variables convert from SbxVariablen. Put()/Insert() into the +// declared datatype, if they are not SbxVARIANT. + +struct SbxVarEntry; + +class BASIC_DLLPUBLIC SbxArray : public SbxBase +{ +// #100883 Method to set method directly to parameter array + friend class SbMethod; + friend class SbClassModuleObject; + friend SbxObjectRef cloneTypeObjectImpl( const SbxObject& rTypeObj ); + BASIC_DLLPRIVATE void PutDirect( SbxVariable* pVar, sal_uInt32 nIdx ); + + std::vector<SbxVarEntry> mVarEntries; // The variables + SbxDataType eType; // Data type of the array + +protected: + virtual ~SbxArray() override; + virtual bool LoadData( SvStream&, sal_uInt16 ) override; + virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override; + +public: + SBX_DECL_PERSIST_NODATA(SBXID_ARRAY,1); + SbxArray( SbxDataType=SbxVARIANT ); + SbxArray( const SbxArray& ) = delete; + SbxArray& operator=( const SbxArray& ); + virtual void Clear() override; + sal_uInt32 Count() const; + virtual SbxDataType GetType() const override; + SbxVariableRef& GetRef(sal_uInt32); + SbxVariable* Get(sal_uInt32); + void Put(SbxVariable*, sal_uInt32); + void Insert(SbxVariable*, sal_uInt32); + void Remove( sal_uInt32 ); + void Remove( SbxVariable const * ); + void Merge( SbxArray* ); + OUString GetAlias(sal_uInt32); + void PutAlias(const OUString&, sal_uInt32); + SbxVariable* Find( const OUString&, SbxClassType ); +}; + +// SbxDimArray is an array that can dimensioned using BASIC conventions. +struct SbxDim { // an array-dimension: + sal_Int32 nLbound, nUbound; // Limitations + sal_Int32 nSize; // Number of elements +}; + +class BASIC_DLLPUBLIC SbxDimArray final : public SbxArray +{ + std::vector<SbxDim> m_vDimensions; // Dimension table + BASIC_DLLPRIVATE void AddDimImpl(sal_Int32, sal_Int32, bool bAllowSize0); + bool mbHasFixedSize; + + sal_uInt32 Offset(const sal_Int32*); + sal_uInt32 Offset(SbxArray*); + virtual bool LoadData( SvStream&, sal_uInt16 ) override; + virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override; + virtual ~SbxDimArray() override; +public: + SBX_DECL_PERSIST_NODATA(SBXID_DIMARRAY,1); + SbxDimArray( SbxDataType=SbxVARIANT ); + SbxDimArray( const SbxDimArray& ) = delete; + SbxDimArray& operator=( const SbxDimArray& ); + virtual void Clear() override; + SbxVariable* Get( SbxArray* ); + + using SbxArray::GetRef; + using SbxArray::Get; + SbxVariable* Get(const sal_Int32*); + using SbxArray::Put; + void Put(SbxVariable*, const sal_Int32*); + sal_Int32 GetDims() const { return m_vDimensions.size(); } + void AddDim(sal_Int32, sal_Int32); + void unoAddDim(sal_Int32, sal_Int32); + bool GetDim(sal_Int32, sal_Int32&, sal_Int32&) const; + bool hasFixedSize() const { return mbHasFixedSize; }; + void setHasFixedSize( bool bHasFixedSize ) {mbHasFixedSize = bHasFixedSize; }; +}; + +class SbxCollection : public SbxObject +{ + void Initialize(); +protected: + virtual ~SbxCollection() override; + virtual bool LoadData( SvStream&, sal_uInt16 ) override; + virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; + // Overridable methods (why not pure virtual?): + virtual void CollAdd( SbxArray* pPar ); + void CollItem( SbxArray* pPar ); + virtual void CollRemove( SbxArray* pPar ); + +public: + SBX_DECL_PERSIST_NODATA(SBXID_COLLECTION,1); + SbxCollection(); + SbxCollection( const SbxCollection& ); + SbxCollection& operator=( const SbxCollection& ); + virtual SbxVariable* Find( const OUString&, SbxClassType ) override; + virtual void Clear() override; +}; + +class SbxStdCollection final : public SbxCollection +{ + OUString aElemClass; + bool bAddRemoveOk; + virtual ~SbxStdCollection() override; + virtual bool LoadData( SvStream&, sal_uInt16 ) override; + virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override; + virtual void CollAdd( SbxArray* pPar ) override; + virtual void CollRemove( SbxArray* pPar ) override; +public: + SBX_DECL_PERSIST_NODATA(SBXID_FIXCOLLECTION,1); + SbxStdCollection(); + SbxStdCollection( const SbxStdCollection& ); + SbxStdCollection& operator=( const SbxStdCollection& ); + virtual void Insert( SbxVariable* ) override; +}; + +typedef tools::SvRef<SbxArray> SbxArrayRef; +typedef tools::SvRef<SbxInfo> SbxInfoRef; +typedef tools::SvRef<SbxDimArray> SbxDimArrayRef; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sbxcore.hxx b/include/basic/sbxcore.hxx new file mode 100644 index 0000000000..2fc27cf86e --- /dev/null +++ b/include/basic/sbxcore.hxx @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_SBXCORE_HXX +#define INCLUDED_BASIC_SBXCORE_HXX + +#include <basic/basicdllapi.h> +#include <basic/sbxdef.hxx> +#include <rtl/ustring.hxx> +#include <tools/ref.hxx> + +class SvStream; +class ErrCode; + +// The following Macro defines four (five) necessary methods within a +// SBX object. LoadPrivateData() and StorePrivateData() must be implemented. +// They are necessary for loading/storing the data of derived classes. +// Load() and Store() must not be overridden. + +// This version of the Macros does not define Load/StorePrivateData()-methods +#define SBX_DECL_PERSIST_NODATA( nSbxId, nVer ) \ + virtual sal_uInt16 GetVersion() const override { return nVer; } \ + virtual sal_uInt16 GetSbxId() const override { return nSbxId; } + +class SbxFactory; +class SbxObject; +class SbxBase; + +typedef tools::SvRef<SbxBase> SbxBaseRef; +typedef tools::SvRef<SbxObject> SbxObjectRef; + +class BASIC_DLLPUBLIC SbxBase : virtual public SvRefBase +{ + virtual bool LoadData( SvStream&, sal_uInt16 ) = 0; + virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const = 0; +protected: + SbxFlagBits nFlags; // Flag-Bits + + SbxBase(); + SbxBase( const SbxBase& ); + SbxBase& operator=( const SbxBase& ); + virtual ~SbxBase() override; + + virtual sal_uInt16 GetVersion() const = 0; + virtual sal_uInt16 GetSbxId() const = 0; + +public: + inline void SetFlags( SbxFlagBits n ); + inline SbxFlagBits GetFlags() const; + inline void SetFlag( SbxFlagBits n ); + inline void ResetFlag( SbxFlagBits n ); + inline bool IsSet( SbxFlagBits n ) const; + inline bool IsReset( SbxFlagBits n ) const; + inline bool CanRead() const; + inline bool CanWrite() const; + inline bool IsModified() const; + inline bool IsHidden() const; + inline bool IsVisible() const; + + virtual bool IsFixed() const; + virtual void SetModified( bool ); + + virtual SbxDataType GetType() const; + + virtual void Clear() = 0; + + static SbxBaseRef Load( SvStream& ); + std::pair<bool, sal_uInt32> Store( SvStream& ); + virtual bool LoadCompleted(); + + static ErrCode const & GetError(); + static OUString const& GetErrorMsg(); + static void SetError( ErrCode ); + static void SetError(ErrCode, const OUString&); + static bool IsError(); + static void ResetError(); + + // Set the factory for Load/Store/Create + static void AddFactory( SbxFactory* ); + static void RemoveFactory( SbxFactory const * ); + + static SbxBaseRef Create( sal_uInt16, sal_uInt32 ); + static SbxObjectRef CreateObject( const OUString& ); +}; + +inline void SbxBase::SetFlags( SbxFlagBits n ) +{ nFlags = n; } + +inline SbxFlagBits SbxBase::GetFlags() const +{ return nFlags; } + +inline void SbxBase::SetFlag( SbxFlagBits n ) +{ nFlags |= n; } + +inline void SbxBase::ResetFlag( SbxFlagBits n ) +{ nFlags &= ~n; } + +inline bool SbxBase::IsSet( SbxFlagBits n ) const +{ return ( nFlags & n ) != SbxFlagBits::NONE; } + +inline bool SbxBase::IsReset( SbxFlagBits n ) const +{ return ( nFlags & n ) == SbxFlagBits::NONE; } + +inline bool SbxBase::CanRead() const +{ return IsSet( SbxFlagBits::Read ); } + +inline bool SbxBase::CanWrite() const +{ return IsSet( SbxFlagBits::Write ); } + +inline bool SbxBase::IsModified() const +{ return IsSet( SbxFlagBits::Modified ); } + +inline bool SbxBase::IsHidden() const +{ return IsSet( SbxFlagBits::Hidden ); } + +inline bool SbxBase::IsVisible() const +{ return IsReset( SbxFlagBits::Invisible ); } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sbxdef.hxx b/include/basic/sbxdef.hxx new file mode 100644 index 0000000000..e85f1a2096 --- /dev/null +++ b/include/basic/sbxdef.hxx @@ -0,0 +1,219 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#ifndef INCLUDED_BASIC_SBXDEF_HXX +#define INCLUDED_BASIC_SBXDEF_HXX + +#include <o3tl/typed_flags_set.hxx> +#include <sal/types.h> + +enum class SbxClassType { // SBX-class-IDs (order is important!) + DontCare = 1, // don't care (search, not 0 due to StarBASIC) + Array, // Array of SbxVariables + Value, // simple value + Variable, // Variable (from here there is Broadcaster) + Method, // Method (Function or Sub) + Property, // Property + Object // Object +}; + +enum SbxDataType { + SbxEMPTY = 0, // * Uninitialized + SbxNULL = 1, // * Contains no valid data + SbxINTEGER = 2, // * Integer (sal_Int16) + SbxLONG = 3, // * Long integer (sal_Int32) + SbxSINGLE = 4, // * Single-precision floating point number (float) + SbxDOUBLE = 5, // * Double-precision floating point number (double) + SbxCURRENCY = 6, // Currency (sal_Int64) + SbxDATE = 7, // * Date (double) + SbxSTRING = 8, // * String (StarView) + SbxOBJECT = 9, // * SbxBase object pointer + SbxERROR = 10, // * Error (sal_uInt16) + SbxBOOL = 11, // * Boolean (0 or -1) + + SbxVARIANT = 12, // * Display for variant datatype + SbxDATAOBJECT = 13, // * Common data object w/o ref count + + SbxCHAR = 16, // * signed char + SbxBYTE = 17, // * unsigned char + SbxUSHORT = 18, // * unsigned short (sal_uInt16) + SbxULONG = 19, // * unsigned long (sal_uInt32) + + SbxINT = 22, // * signed machine-dependent int + SbxUINT = 23, // * unsigned machine-dependent int + + SbxVOID = 24, // * no value (= SbxEMPTY) + SbxHRESULT = 25, // HRESULT + SbxPOINTER = 26, // generic pointer + SbxDIMARRAY = 27, // dimensioned array + SbxCARRAY = 28, // C style array + SbxUSERDEF = 29, // user defined + SbxLPSTR = 30, // * null terminated string + + SbxLPWSTR = 31, // wide null terminated string + SbxCoreSTRING = 32, // from 1997-4-10 for GetCoreString(), only for converting< + + SbxWSTRING = 33, // from 2000-10-4 Reimplemented for backwards compatibility (#78919) + SbxWCHAR = 34, // from 2000-10-4 Reimplemented for backwards compatibility (#78919) + SbxSALINT64 = 35, // for currency internal, signed 64-bit int and UNO hyper + SbxSALUINT64= 36, // for currency internal, unsigned 64-bit int and UNO unsigned hyper + SbxDECIMAL = 37, // for UNO/automation Decimal + + SbxVECTOR = 0x1000, // simple counted array + SbxARRAY = 0x2000, // array + SbxBYREF = 0x4000, // access by reference + + // tdf#79426, tdf#125180 + SbxMISSING = 0x8000, // Parameter is missing +}; + +const sal_uInt32 SBX_TYPE_WITH_EVENTS_FLAG = 0x10000; +const sal_uInt32 SBX_TYPE_DIM_AS_NEW_FLAG = 0x20000; +const sal_uInt32 SBX_FIXED_LEN_STRING_FLAG = 0x10000; // same value as above as no conflict possible +const sal_uInt32 SBX_TYPE_VAR_TO_DIM_FLAG = 0x40000; + +enum SbxOperator { + // Arithmetical: + SbxEXP, // this ^ var + SbxMUL, // this * var + SbxDIV, // this / var + SbxMOD, // this MOD var (max INT32!) + SbxPLUS, // this + var + SbxMINUS, // this - var + SbxNEG, // -this (var is ignored) + SbxIDIV, // this / var (both operands max. sal_Int32!) + // Boolean operators (max sal_Int32!): + // Boolean operators (TODO deprecate this limit: max INT32!) + SbxAND, // this & var + SbxOR, // this | var + SbxXOR, // this ^ var + SbxEQV, // ~this ^ var + SbxIMP, // ~this | var + SbxNOT, // ~this (var is ignored) + + // String concatenation: + SbxCAT, // this & var (VBA: this + var) + + // Comparisons: + SbxEQ, // this = var + SbxNE, // this <> var + SbxLT, // this < var + SbxGT, // this > var + SbxLE, // this <= var + SbxGE // this >= var +}; + +enum class SbxNameType { // Type of the questioned name of a variable + NONE, // plain name + CaseInsensitive, // plain name - case insensitive + ShortTypes, // Name%(A%,B$) +}; + + +// Flag-Bits: +enum class SbxFlagBits { + NONE = 0x0000, + Read = 0x0001, // Read permission + Write = 0x0002, // Write permission + ReadWrite = 0x0003, // Read/Write permission + DontStore = 0x0004, // Don't store object + Modified = 0x0008, // Object was changed + Fixed = 0x0010, // Fixed data type (SbxVariable) + Const = 0x0020, // Definition of const value + Optional = 0x0040, // Parameter is optional + Hidden = 0x0080, // Element is invisible + Invisible = 0x0100, // Element is not found by Find() + ExtSearch = 0x0200, // Object is searched completely + ExtFound = 0x0400, // Variable was found through extended search + GlobalSearch = 0x0800, // Global search via Parents + Reserved = 0x1000, // reserved + Private = 0x1000, // #110004, #112015, cannot conflict with SbxFlagBits::Reserved + NoBroadcast = 0x2000, // No broadcast on Get/Put + Reference = 0x4000, // Parameter is Reference (DLL-call) + NoModify = 0x8000, // SetModified is suppressed + WithEvents = 0x0080, // Same value as unused SbxFlagBits::Hidden + DimAsNew = 0x0800, // Same value as SbxFlagBits::GlobalSearch, cannot conflict as one + // is used for objects, the other for variables only + VarToDim = 0x2000, // Same value as SbxFlagBits::NoBroadcast, cannot conflict as + // used for variables without broadcaster only +}; +namespace o3tl +{ + template<> struct typed_flags<SbxFlagBits> : is_typed_flags<SbxFlagBits, 0xffff> {}; +} + +// List of all creators for Load/Store + +constexpr auto SBXCR_SBX = 0x20584253; // SBX(blank) + +// List of predefined SBX-IDs. New SBX-IDs must be precisely defined so that +// they are unique within the Stream and appropriate Factory. + +constexpr auto SBXID_VALUE = 0x4E4E; // NN: SbxValue +constexpr auto SBXID_VARIABLE = 0x4156; // VA: SbxVariable +constexpr auto SBXID_ARRAY = 0x5241; // AR: SbxArray +constexpr auto SBXID_DIMARRAY = 0x4944; // DI: SbxDimArray +constexpr auto SBXID_OBJECT = 0x424F; // OB: SbxObject +constexpr auto SBXID_COLLECTION = 0x4F43; // CO: SbxCollection +constexpr auto SBXID_FIXCOLLECTION = 0x4346; // FC: SbxStdCollection +constexpr auto SBXID_METHOD = 0x454D; // ME: SbxMethod +constexpr auto SBXID_PROPERTY = 0x5250; // PR: SbxProperty + +// StarBASIC restricts the base data type to different intervals. +// These intervals are fixed to create 'portability and independent +// of the implementation. Only type double is greedy and takes +// what it gets. + +constexpr auto SbxMAXCHAR = u'\xFFFF'; +constexpr auto SbxMINCHAR = 0; +constexpr auto SbxMAXBYTE = 255; +constexpr auto SbxMAXINT = 32767; +constexpr auto SbxMININT = -32768; +constexpr sal_uInt16 SbxMAXUINT = 65535; +constexpr auto SbxMAXLNG = 2147483647; +constexpr sal_Int32 SbxMINLNG = -2147483647-1; +constexpr sal_uInt32 SbxMAXULNG = 0xffffffff; + + // Currency stored as SbxSALINT64 == sal_Int64 + // value range limits are ~(2^63 - 1)/10000 + // fixed precision has 4 digits right of decimal pt +constexpr auto CURRENCY_FACTOR = 10000; +constexpr auto CURRENCY_FACTOR_SQUARE = 100000000; + +// TODO effective MAX/MINCURR limits: +// true value ( 922337203685477.5807) is too precise for correct comparison to 64bit double +constexpr auto SbxMAXCURR = 922337203685477.5807; +constexpr auto SbxMINCURR = -922337203685477.5808; + +constexpr auto SbxMAXSNG = 3.402823e+38; +constexpr auto SbxMINSNG = -3.402823e+38; +constexpr auto SbxMAXSNG2 = 1.175494351e-38; +constexpr auto SbxMINSNG2 = -1.175494351e-38; + +// Max valid offset index of a Sbx-Array (due to 64K limit) +constexpr auto SBX_MAXINDEX = 0x3FF0; +constexpr auto SBX_MAXINDEX32 = SbxMAXLNG; + +// The numeric values of sal_True and FALSE +enum SbxBOOL { SbxFALSE = 0, SbxTRUE = -1 }; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sbxmeth.hxx b/include/basic/sbxmeth.hxx new file mode 100644 index 0000000000..23ec6a00e5 --- /dev/null +++ b/include/basic/sbxmeth.hxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_SBXMETH_HXX +#define INCLUDED_BASIC_SBXMETH_HXX + +#include <basic/sbxvar.hxx> +#include <basic/basicdllapi.h> + +class BASIC_DLLPUBLIC SbxMethod : public SbxVariable +{ + bool mbIsRuntimeFunction; + SbxDataType mbRuntimeFunctionReturnType; +public: + SBX_DECL_PERSIST_NODATA(SBXID_METHOD,1); + SbxMethod( const OUString& r, SbxDataType t, bool bIsRuntimeFunction=false ); + SbxMethod( const SbxMethod& r ); + virtual ~SbxMethod() override; + SbxMethod& operator=( const SbxMethod& r ) { SbxVariable::operator=( r ); return *this; } + virtual SbxClassType GetClass() const override; + bool IsRuntimeFunction() const { return mbIsRuntimeFunction; } + SbxDataType GetRuntimeFunctionReturnType() const{ return mbRuntimeFunctionReturnType; } + virtual void Clear() override; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sbxobj.hxx b/include/basic/sbxobj.hxx new file mode 100644 index 0000000000..d9fd229c1d --- /dev/null +++ b/include/basic/sbxobj.hxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_SBXOBJ_HXX +#define INCLUDED_BASIC_SBXOBJ_HXX + +#include <svl/lstner.hxx> +#include <basic/sbxvar.hxx> +#include <basic/basicdllapi.h> + + +class SbxProperty; + +class BASIC_DLLPUBLIC SbxObject : public SbxVariable, public SfxListener +{ + BASIC_DLLPRIVATE SbxArray* FindVar( SbxVariable const *, sal_uInt32& ); +protected: + SbxArrayRef pMethods; // Methods + SbxArrayRef pProps; // Properties + SbxArrayRef pObjs; // Objects + SbxProperty* pDfltProp; // Default-Property + OUString aClassName; // Classname + OUString aDfltPropName; + virtual bool LoadData( SvStream&, sal_uInt16 ) override; + virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override; + virtual ~SbxObject() override; + virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; + virtual bool IsOptionCompatible() const; // Module's Option Compatible + +public: + SBX_DECL_PERSIST_NODATA(SBXID_OBJECT,1); + SbxObject( const OUString& rClassname ); + SbxObject( const SbxObject& ); + SbxObject& operator=( const SbxObject& ); + virtual SbxDataType GetType() const override; + virtual SbxClassType GetClass() const override; + virtual void Clear() override; + + virtual bool IsClass( const OUString& ) const; + const OUString& GetClassName() const { return aClassName; } + void SetClassName( const OUString &rNew ) { aClassName = rNew; } + // Default-Property + SbxProperty* GetDfltProperty(); + void SetDfltProperty( const OUString& r ); + // Search for an element + virtual SbxVariable* Find( const OUString&, SbxClassType ); + SbxVariable* FindQualified( const OUString&, SbxClassType ); + // Quick-Call-Interface for Methods + virtual bool Call( const OUString&, SbxArray* = nullptr ); + // Execution of DDE-Commands + SbxVariable* Execute( const OUString& ); + // Manage elements + SbxVariable* Make( const OUString&, SbxClassType, SbxDataType, bool bIsRuntimeFunction = false ); + virtual void Insert( SbxVariable* ); + // AB 23.4.1997, Optimization, Insertion without check for duplicate Entries and + // without Broadcasts, only used in SO2/auto.cxx + void QuickInsert( SbxVariable* ); + void Remove( const OUString&, SbxClassType ); + virtual void Remove( SbxVariable* ); + + // Direct access on arrays + SbxArray* GetMethods() { return pMethods.get(); } + SbxArray* GetProperties() { return pProps.get(); } + SbxArray* GetObjects() { return pObjs.get(); } + // Debugging + void Dump( SvStream&, bool bDumpAll ); +}; + +#endif // INCLUDED_BASIC_SBXOBJ_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/sbxvar.hxx b/include/basic/sbxvar.hxx new file mode 100644 index 0000000000..1b0372f82c --- /dev/null +++ b/include/basic/sbxvar.hxx @@ -0,0 +1,336 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_SBXVAR_HXX +#define INCLUDED_BASIC_SBXVAR_HXX + +#include <rtl/character.hxx> +#include <rtl/ustring.hxx> +#include <basic/sbxcore.hxx> +#include <basic/basicdllapi.h> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <algorithm> +#include <cstddef> +#include <cstring> +#include <memory> + + +namespace com::sun::star::bridge::oleautomation { struct Decimal; } + +class SbxDecimal; +enum class SfxHintId; + +struct SbxValues +{ + union { + sal_uInt8 nByte; + sal_uInt16 nUShort; + sal_Unicode nChar; + sal_Int16 nInteger; + sal_uInt32 nULong; + sal_Int32 nLong; + unsigned int nUInt; + int nInt; + sal_uInt64 uInt64; + sal_Int64 nInt64; + + float nSingle; + double nDouble; + + OUString* pOUString; + SbxDecimal* pDecimal; + + SbxBase* pObj; + + sal_uInt8* pByte; + sal_uInt16* pUShort; + sal_Unicode* pChar; + sal_Int16* pInteger; + sal_uInt32* pULong; + sal_Int32* pLong; + sal_uInt64* puInt64; + sal_Int64* pnInt64; + + float* pSingle; + double* pDouble; + + void* pData; + }; + SbxDataType eType; + + SbxValues(): pData( nullptr ), eType(SbxEMPTY) {} + SbxValues( SbxDataType e ): pData( nullptr ), eType(e) {} + SbxValues( double _nDouble ): nDouble( _nDouble ), eType(SbxDOUBLE) {} + + void clear(SbxDataType type) { + // A hacky way of zeroing the union value corresponding to the given type (even though the + // relevant zero value need not be represented by all-zero bits, in general) without evoking + // GCC 8 -Wclass-memaccess or loplugin:classmemaccess, and without having to turn the + // anonymous union into a non-anonymous one: + auto const p = static_cast<void *>(this); + std::memset(p, 0, offsetof(SbxValues, eType)); + eType = type; + } +}; + +class BASIC_DLLPUBLIC SbxValue : public SbxBase +{ + // #55226 Transport additional infos + BASIC_DLLPRIVATE SbxValue* TheRealValue( bool bObjInObjError ) const; +protected: + SbxValues aData; // Data + OUString aPic; // Picture-String + OUString aToolString; // tool string copy + + virtual void Broadcast( SfxHintId ); // Broadcast-Call + virtual ~SbxValue() override; + virtual bool LoadData( SvStream&, sal_uInt16 ) override; + virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override; +public: + SBX_DECL_PERSIST_NODATA(SBXID_VALUE,1); + SbxValue(); + SbxValue( SbxDataType ); + SbxValue( const SbxValue& ); + SbxValue& operator=( const SbxValue& ); + virtual void Clear() override; + virtual bool IsFixed() const override; + + bool IsInteger() const { return GetType() == SbxINTEGER ; } + bool IsLong() const { return GetType() == SbxLONG ; } + bool IsDouble() const { return GetType() == SbxDOUBLE ; } + bool IsString() const { return GetType() == SbxSTRING ; } + bool IsCurrency() const { return GetType() == SbxCURRENCY ; } + bool IsObject() const { return GetType() == SbxOBJECT ; } + bool IsBool() const { return GetType() == SbxBOOL ; } + bool IsErr() const { return GetType() == SbxERROR ; } + bool IsEmpty() const { return GetType() == SbxEMPTY ; } + bool IsNull() const { return GetType() == SbxNULL ; } + bool IsNumeric() const; + bool IsNumericRTL() const; // #41692 Interface for Basic + bool ImpIsNumeric( bool bOnlyIntntl ) const; // Implementation + + virtual SbxDataType GetType() const override; + SbxDataType GetFullType() const { return aData.eType;} + bool SetType( SbxDataType ); + + bool Get( SbxValues& ) const; + const SbxValues& GetValues_Impl() const { return aData; } + bool Put( const SbxValues& ); + + SbxValues * data() { return &aData; } + + sal_Unicode GetChar() const { return Get(SbxCHAR).nChar; } + sal_Int16 GetInteger() const { return Get(SbxINTEGER).nInteger; } + sal_Int32 GetLong() const { return Get(SbxLONG).nLong; } + sal_Int64 GetInt64() const { return Get(SbxSALINT64).nInt64; } + sal_uInt64 GetUInt64() const { return Get(SbxSALUINT64).uInt64; } + + sal_Int64 GetCurrency() const { return Get(SbxCURRENCY).nInt64; } + SbxDecimal* GetDecimal() const { return Get(SbxDECIMAL).pDecimal; } + + float GetSingle() const { return Get(SbxSINGLE).nSingle; } + double GetDouble() const { return Get(SbxDOUBLE).nDouble; } + double GetDate() const { return Get(SbxDATE).nDouble; } + + bool GetBool() const { return Get(SbxBOOL).nUShort != 0; } + const OUString& GetCoreString() const; + OUString GetOUString() const; + + SbxBase* GetObject() const { return Get(SbxOBJECT).pObj; } + sal_uInt8 GetByte() const { return Get(SbxBYTE).nByte; } + sal_uInt16 GetUShort() const { return Get(SbxUSHORT).nUShort; } + sal_uInt32 GetULong() const { return Get(SbxULONG).nULong; } + + bool PutInteger( sal_Int16 ); + bool PutLong( sal_Int32 ); + bool PutSingle( float ); + bool PutDouble( double ); + void PutDate( double ); + bool PutBool( bool ); + void PutErr( sal_uInt16 ); + void PutStringExt( const OUString& ); // with extended analysis (International, "sal_True"/"sal_False") + bool PutInt64( sal_Int64 ); + bool PutUInt64( sal_uInt64 ); + bool PutString( const OUString& ); + bool PutChar( sal_Unicode ); + bool PutByte( sal_uInt8 ); + bool PutUShort( sal_uInt16 ); + bool PutULong( sal_uInt32 ); + bool PutEmpty(); + void PutNull(); + + // Special methods + void PutDecimal( css::bridge::oleautomation::Decimal const & rAutomationDec ); + bool PutDecimal( SbxDecimal* pDecimal ); // This function is needed for Windows build, don't remove + void fillAutomationDecimal( css::bridge::oleautomation::Decimal& rAutomationDec ) const; + bool PutCurrency( sal_Int64 ); + // Interface for CDbl in Basic + static ErrCode ScanNumIntnl( const OUString& rSrc, double& nVal, bool bSingle = false ); + + bool PutObject( SbxBase* ); + + bool Convert( SbxDataType ); + bool Compute( SbxOperator, const SbxValue& ); + bool Compare( SbxOperator, const SbxValue& ) const; + bool Scan( const OUString&, sal_uInt16* ); + void Format( OUString&, const OUString* = nullptr ) const; + + // The following operators are defined for easier handling. + // TODO: Ensure error conditions (overflow, conversions) + // are taken into consideration in Compute and Compare + + inline bool operator <=( const SbxValue& ) const; + inline bool operator >=( const SbxValue& ) const; + + inline SbxValue& operator *=( const SbxValue& ); + inline SbxValue& operator /=( const SbxValue& ); + inline SbxValue& operator +=( const SbxValue& ); + inline SbxValue& operator -=( const SbxValue& ); + +private: + SbxValues Get(SbxDataType t) const; +}; + +inline bool SbxValue::operator<=( const SbxValue& r ) const +{ return Compare( SbxLE, r ); } + +inline bool SbxValue::operator>=( const SbxValue& r ) const +{ return Compare( SbxGE, r ); } + +inline SbxValue& SbxValue::operator*=( const SbxValue& r ) +{ Compute( SbxMUL, r ); return *this; } + +inline SbxValue& SbxValue::operator/=( const SbxValue& r ) +{ Compute( SbxDIV, r ); return *this; } + +inline SbxValue& SbxValue::operator+=( const SbxValue& r ) +{ Compute( SbxPLUS, r ); return *this; } + +inline SbxValue& SbxValue::operator-=( const SbxValue& r ) +{ Compute( SbxMINUS, r ); return *this; } + +class SbxArray; +class SbxInfo; + +typedef tools::SvRef<SbxArray> SbxArrayRef; + +typedef tools::SvRef<SbxInfo> SbxInfoRef; + +class SfxBroadcaster; + +class SbxVariableImpl; +class StarBASIC; + +class BASIC_DLLPUBLIC SbxVariable : public SbxValue +{ + friend class SbMethod; + + OUString m_aDeclareClassName; + css::uno::Reference< css::uno::XInterface > m_xComListener; + StarBASIC* m_pComListenerParentBasic = nullptr; + std::unique_ptr<SfxBroadcaster> mpBroadcaster; // Broadcaster, if needed + OUString maName; // Name, if available + mutable OUString maNameCI; // Name, case insensitive - cached for fast comparison + SbxArrayRef mpPar; // Parameter-Array, if set + sal_uInt16 nHash = 0; // Hash-ID for search + +protected: + SbxInfoRef pInfo; // Probably called information + sal_uInt32 nUserData= 0; // User data for Call() + SbxObject* pParent = nullptr; // Currently attached object + virtual ~SbxVariable() override; + virtual bool LoadData( SvStream&, sal_uInt16 ) override; + virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override; +public: + SBX_DECL_PERSIST_NODATA(SBXID_VARIABLE,2); + SbxVariable(); + SbxVariable( SbxDataType ); + SbxVariable( const SbxVariable& ); + SbxVariable& operator=( const SbxVariable& ); + + void Dump( SvStream&, bool bDumpAll ); + + void SetName( const OUString& ); + const OUString& GetName( SbxNameType = SbxNameType::NONE ) const; + sal_uInt16 GetHashCode() const { return nHash; } + static OUString NameToCaseInsensitiveName(const OUString& rName); + + virtual void SetModified( bool ) override; + + sal_uInt32 GetUserData() const { return nUserData; } + void SetUserData( sal_uInt32 n ) { nUserData = n; } + + virtual SbxDataType GetType() const override; + virtual SbxClassType GetClass() const; + + // Parameter-Interface + virtual SbxInfo* GetInfo(); + void SetInfo( SbxInfo* p ); + void SetParameters( SbxArray* p ); + SbxArray* GetParameters() const; + + // Sfx-Broadcasting-Support: + // Due to data reduction and better DLL-hierarchy currently via casting + SfxBroadcaster& GetBroadcaster(); + bool IsBroadcaster() const { return mpBroadcaster != nullptr; } + virtual void Broadcast( SfxHintId nHintId ) override; + + const SbxObject* GetParent() const { return pParent; } + SbxObject* GetParent() { return pParent;} + virtual void SetParent( SbxObject* ); + + const OUString& GetDeclareClassName() const; + void SetDeclareClassName( const OUString& ); + void SetComListener( const css::uno::Reference< css::uno::XInterface >& xComListener, + StarBASIC* pParentBasic ); + void ClearComListener(); + + // Create a simple hashcode: the first six characters are evaluated. + static constexpr sal_uInt16 MakeHashCode(std::u16string_view aName) + { + sal_uInt16 n = 0; + const auto first6 = aName.substr(0, 6); + for (const auto& c : first6) + { + if (!rtl::isAscii(c)) + continue; // Just skip it to let non-ASCII strings have some hash variance + n = static_cast<sal_uInt16>((n << 3) + rtl::toAsciiUpperCase(c)); + } + return n; + } +}; + +typedef tools::SvRef<SbxObject> SbxObjectRef; +typedef tools::SvRef<SbxVariable> SbxVariableRef; + +//tdf#59222 SbxEnsureParentVariable is a SbxVariable which keeps a reference to +//its parent, ensuring it always exists while this SbxVariable exists +class SbxEnsureParentVariable final : public SbxVariable +{ + SbxObjectRef xParent; +public: + SbxEnsureParentVariable(const SbxVariable& r); + virtual void SetParent(SbxObject* p) override; +}; + +#endif // INCLUDED_BASIC_SBXVAR_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basic/vbahelper.hxx b/include/basic/vbahelper.hxx new file mode 100644 index 0000000000..8d18b66b1d --- /dev/null +++ b/include/basic/vbahelper.hxx @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASIC_VBAHELPER_HXX +#define INCLUDED_BASIC_VBAHELPER_HXX + +#include <rtl/ustring.hxx> +#include <basic/basicdllapi.h> + +namespace com::sun::star::frame { class XModel; } +namespace com::sun::star::uno { template <typename > class Reference; } + +namespace basic::vba { + +/* This header contains public helper functions for VBA used from this module + and from other VBA implementation modules such as vbahelper. + */ + + +/** Locks or unlocks the controllers of all documents that have the same type + as the specified document. + + First, the global module manager (com.sun.star.frame.ModuleManager) is + asked for the type of the passed model, and all open documents with the + same type will be locked or unlocked. + + @param rxModel + A document model determining the type of the documents to be locked or + unlocked. + + @param bLockControllers + Passing true will lock all controllers, passing false will unlock them. + */ +BASIC_DLLPUBLIC void lockControllersOfAllDocuments( + const css::uno::Reference< css::frame::XModel >& rxModel, + bool bLockControllers ); + + +/** Enables or disables the container windows of all controllers of all + documents that have the same type as the specified document. + + First, the global module manager (com.sun.star.frame.ModuleManager) is + asked for the type of the passed model, and the container windows of all + open documents with the same type will be enabled or disabled. + + @param rxModel + A document model determining the type of the documents to be enabled or + disabled. + + @param bEnableWindows + Passing true will enable all container windows of all controllers, + passing false will disable them. + */ +BASIC_DLLPUBLIC void enableContainerWindowsOfAllDocuments( + const css::uno::Reference< css::frame::XModel >& rxModel, + bool bEnableWindows ); + + +/** Registers the passed path as working directory for the application the + passed document belongs to. + + @param rxModel + A document model determining the type of the application whose working + directory has been changed. + + @param rPath + The new working directory. + */ +BASIC_DLLPUBLIC void registerCurrentDirectory( + const css::uno::Reference< css::frame::XModel >& rxModel, + const OUString& rPath ); + + +} // namespace basic::vba + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |