diff options
author | Frank Schönheit <fs@openoffice.org> | 2001-12-18 13:13:58 +0000 |
---|---|---|
committer | Frank Schönheit <fs@openoffice.org> | 2001-12-18 13:13:58 +0000 |
commit | d7c8d84afe3b68865f60c0b93956be2d9d847f73 (patch) | |
tree | 98742b201ef78c2769982193512d9af2654cfe37 /svx | |
parent | 34f6d73eef33f8fe358e274821e7eb8b181584b6 (diff) |
#95867# +containsActiveCode
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/form/fmmodel.cxx | 21 | ||||
-rw-r--r-- | svx/source/form/fmpage.cxx | 33 | ||||
-rw-r--r-- | svx/source/form/fmpgeimp.cxx | 80 | ||||
-rw-r--r-- | svx/source/inc/fmpgeimp.hxx | 8 |
4 files changed, 134 insertions, 8 deletions
diff --git a/svx/source/form/fmmodel.cxx b/svx/source/form/fmmodel.cxx index 4f0ef191030d..9bfee316d977 100644 --- a/svx/source/form/fmmodel.cxx +++ b/svx/source/form/fmmodel.cxx @@ -2,9 +2,9 @@ * * $RCSfile: fmmodel.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: oj $ $Date: 2001-11-15 08:38:30 $ + * last change: $Author: fs $ $Date: 2001-12-18 14:12:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -419,6 +419,23 @@ void FmFormModel::SetAutoControlFocus( sal_Bool _bAutoControlFocus ) } //------------------------------------------------------------------------ +sal_Bool FmFormModel::containsActiveCode( const String& _rScriptType ) const +{ + sal_Bool bContainsActiveCode = sal_False; + + // loop through all our pages + USHORT nPageCount = GetPageCount( ); + for ( USHORT i=0; i<nPageCount && !bContainsActiveCode; ++i ) + { + const FmFormPage* pPage = PTR_CAST( FmFormPage, GetPage( i ) ); + if ( pPage && pPage->containsActiveCode( _rScriptType ) ) + bContainsActiveCode = sal_True; + } + + return bContainsActiveCode; +} + +//------------------------------------------------------------------------ void FmFormModel::SetObjectShell( SfxObjectShell* pShell ) { #ifndef SVX_LIGHT diff --git a/svx/source/form/fmpage.cxx b/svx/source/form/fmpage.cxx index 0b30f9868ccd..bc5ae8a55fe5 100644 --- a/svx/source/form/fmpage.cxx +++ b/svx/source/form/fmpage.cxx @@ -2,9 +2,9 @@ * * $RCSfile: fmpage.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: fs $ $Date: 2001-10-15 10:27:12 $ + * last change: $Author: fs $ $Date: 2001-12-18 14:12:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -151,6 +151,9 @@ using namespace ::svxform; #endif +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::container; + #ifndef _COMPHELPER_PROPERTY_HXX_ #include <comphelper/property.hxx> #endif @@ -320,6 +323,32 @@ const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContai } //------------------------------------------------------------------ +sal_Bool FmFormPage::containsActiveCode( const String& _rScriptType ) const +{ + sal_Bool bContains = sal_False; + try + { + Reference< XIndexAccess > xForms( pImpl->getForms(), UNO_QUERY ); + DBG_ASSERT( xForms.is(), "FmFormPage::containsActiveCode: invalid forms collection!" ); + if ( xForms.is() ) + { + bContains = pImpl->containsActiveCode( xForms, _rScriptType ); + } + else + // be on the safe side: If we can't check this, assume there is active (potential dangerous) code + bContains = pImpl->getForms().is(); + // (if and only if there is a forms collection) + } + catch( const Exception& ) + { + DBG_ERROR( "FmFormPage::containsActiveCode: caught an exception!" ); + // be on the safe side: If we can't check this, assume there is active (potential dangerous) code + bContains = sal_True; + } + return bContains; +} + +//------------------------------------------------------------------ sal_Bool FmFormPage::RequestHelp( Window* pWindow, SdrView* pView, const HelpEvent& rEvt ) { diff --git a/svx/source/form/fmpgeimp.cxx b/svx/source/form/fmpgeimp.cxx index c6c6c1690b67..fbfe55bba602 100644 --- a/svx/source/form/fmpgeimp.cxx +++ b/svx/source/form/fmpgeimp.cxx @@ -2,9 +2,9 @@ * * $RCSfile: fmpgeimp.cxx,v $ * - * $Revision: 1.12 $ + * $Revision: 1.13 $ * - * last change: $Author: fs $ $Date: 2001-10-16 15:46:51 $ + * last change: $Author: fs $ $Date: 2001-12-18 14:13:58 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -94,6 +94,9 @@ #ifndef _COM_SUN_STAR_IO_XMARKABLESTREAM_HPP_ #include <com/sun/star/io/XMarkableStream.hpp> #endif +#ifndef _COM_SUN_STAR_SCRIPT_XEVENTATTACHERMANAGER_HPP_ +#include <com/sun/star/script/XEventAttacherManager.hpp> +#endif #ifndef _SFX_OBJSH_HXX #include <sfx2/objsh.hxx> @@ -165,6 +168,8 @@ #include <connectivity/dbtools.hxx> #endif +#include <algorithm> + using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdbc; @@ -172,6 +177,7 @@ using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::container; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::form; +using namespace ::com::sun::star::script; using namespace ::svxform; DBG_NAME(FmFormPageImpl); @@ -803,6 +809,76 @@ void FmFormPageImpl::read(const Reference< ::com::sun::star::io::XObjectInputStr } //------------------------------------------------------------------------------ +namespace svxform +{ + struct CheckEventType : public ::std::unary_function< ScriptEventDescriptor, sal_Bool > + { + const ::rtl::OUString& m_rScriptType; + CheckEventType( const ::rtl::OUString& _rScriptType ) : m_rScriptType( _rScriptType ) { } + + sal_Bool operator() ( const ScriptEventDescriptor& _rDescriptor ) + { + return _rDescriptor.ScriptType.equals( m_rScriptType ); + } + }; +} + +//------------------------------------------------------------------------------ +sal_Bool FmFormPageImpl::containsActiveCode( const Reference< XIndexAccess >& _rxContainer, const String& _rScriptType ) const +{ + DBG_ASSERT( _rxContainer.is(), "FmFormPageImpl::containsActiveCode: invalid container!" ); + if ( !_rxContainer.is() ) + return sal_False; + + sal_Bool bContains = sal_False; + try + { + ::rtl::OUString sScriptType( _rScriptType ); + // faster usage .... + + sal_Int32 nChildCount = _rxContainer->getCount(); + + // first, try if the container itself handles script events for it's children + Reference< XEventAttacherManager > xEvents( _rxContainer, UNO_QUERY ); + if ( xEvents.is() ) + { // yes, it does -> check them + for ( sal_Int32 i = 0; ( i < nChildCount ) && !bContains; ++i ) + { + Sequence< ScriptEventDescriptor > aScripts = xEvents->getScriptEvents( i ); + const ScriptEventDescriptor* pEvents = aScripts.getConstArray(); + const ScriptEventDescriptor* pEventsEnd = pEvents + aScripts.getLength(); + const ScriptEventDescriptor* pFirstFound = ::std::find_if( + pEvents, + pEventsEnd, + CheckEventType( sScriptType ) + ); + if ( pFirstFound != pEventsEnd ) + bContains = sal_True; + } + } + + if ( !bContains ) + { // step down only if not already found such a script .... + Reference< XIndexAccess > xChild; + for ( sal_Int32 i=0; ( i < nChildCount ) && !bContains; ++i ) + { + if ( _rxContainer->getByIndex( i ) >>= xChild ) + { // the child is a container, again + bContains = containsActiveCode( xChild, _rScriptType ); + } + } + } + } + catch( const Exception& ) + { + DBG_ERROR( "FmFormPageImpl::containsActiveCode: caught an exception!" ); + // be on the safe side: If we can't check this, assume there is active (potential dangerous) code + bContains = sal_True; + } + return bContains; +} + +//------------------------------------------------------------------------------ void FmFormPageImpl::fillList(FmObjectList& rList, const SdrObjList& rObjList, sal_Bool bConnected) const { SdrObjListIter aIter(rObjList); diff --git a/svx/source/inc/fmpgeimp.hxx b/svx/source/inc/fmpgeimp.hxx index c9d7ed343616..ec0a6747de5e 100644 --- a/svx/source/inc/fmpgeimp.hxx +++ b/svx/source/inc/fmpgeimp.hxx @@ -2,9 +2,9 @@ * * $RCSfile: fmpgeimp.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: oj $ $Date: 2000-11-15 14:55:12 $ + * last change: $Author: fs $ $Date: 2001-12-18 14:09:54 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -128,6 +128,10 @@ protected: void Init(); + sal_Bool containsActiveCode( + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxContainer, + const String& _rScriptType ) const; + public: // nur wichtig fuer den DesignMode void setCurForm(::com::sun::star::uno::Reference< ::com::sun::star::form::XForm> xForm); |