1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef FORMS_SOURCE_CLICKABLEIMAGE_HXX 29*cdf0e10cSrcweir #define FORMS_SOURCE_CLICKABLEIMAGE_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "FormComponent.hxx" 32*cdf0e10cSrcweir #include "EventThread.hxx" 33*cdf0e10cSrcweir #include "imgprod.hxx" 34*cdf0e10cSrcweir #include <tools/link.hxx> 35*cdf0e10cSrcweir #include <comphelper/propmultiplex.hxx> 36*cdf0e10cSrcweir #include <com/sun/star/form/XImageProducerSupplier.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/form/FormButtonType.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/form/XApproveActionListener.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/form/XApproveActionBroadcaster.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/form/submission/XSubmissionSupplier.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/form/submission/XSubmission.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp> 44*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir class SfxMedium; 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir //......................................................................... 50*cdf0e10cSrcweir namespace frm 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir //......................................................................... 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir class OImageProducerThread_Impl; 55*cdf0e10cSrcweir class ControlFeatureInterception; 56*cdf0e10cSrcweir //================================================================== 57*cdf0e10cSrcweir // OClickableImageBaseModel 58*cdf0e10cSrcweir //================================================================== 59*cdf0e10cSrcweir typedef ::cppu::ImplHelper3 < ::com::sun::star::form::XImageProducerSupplier 60*cdf0e10cSrcweir , ::com::sun::star::awt::XImageProducer 61*cdf0e10cSrcweir , ::com::sun::star::form::submission::XSubmissionSupplier 62*cdf0e10cSrcweir > OClickableImageBaseModel_Base; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir class OClickableImageBaseModel :public OClickableImageBaseModel_Base 65*cdf0e10cSrcweir ,public OControlModel 66*cdf0e10cSrcweir ,public OPropertyChangeListener 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir protected: 69*cdf0e10cSrcweir ::com::sun::star::form::FormButtonType m_eButtonType; // Art des Buttons (push,submit,reset) 70*cdf0e10cSrcweir ::rtl::OUString m_sTargetURL; // URL fuer den URL-Button 71*cdf0e10cSrcweir ::rtl::OUString m_sTargetFrame; // TargetFrame zum Oeffnen 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir // ImageProducer stuff 74*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> m_xProducer; 75*cdf0e10cSrcweir SfxMedium* m_pMedium; // Download-Medium 76*cdf0e10cSrcweir ImageProducer* m_pProducer; 77*cdf0e10cSrcweir sal_Bool m_bDispatchUrlInternal; // property: is not allowed to set : 1 78*cdf0e10cSrcweir sal_Bool m_bDownloading : 1; // laeuft ein Download? 79*cdf0e10cSrcweir sal_Bool m_bProdStarted : 1; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // XSubmission stuff 82*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmission > 83*cdf0e10cSrcweir m_xSubmissionDelegate; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir DECL_STATIC_LINK( OClickableImageBaseModel, DataAvailableLink, void* ); 87*cdf0e10cSrcweir DECL_STATIC_LINK( OClickableImageBaseModel, DownloadDoneLink, void* ); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir inline ImageProducer* GetImageProducer() { return m_pProducer; } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir void StartProduction(); 92*cdf0e10cSrcweir void SetURL(const ::rtl::OUString& rURL); 93*cdf0e10cSrcweir void DataAvailable(); 94*cdf0e10cSrcweir void DownloadDone(); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes(); 97*cdf0e10cSrcweir inline sal_Bool isDispatchUrlInternal() const { return m_bDispatchUrlInternal; } 98*cdf0e10cSrcweir inline void setDispatchUrlInternal(sal_Bool _bDispatch) { m_bDispatchUrlInternal = _bDispatch; } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir public: 101*cdf0e10cSrcweir DECLARE_DEFAULT_XTOR( OClickableImageBaseModel ); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir // UNO Anbindung 104*cdf0e10cSrcweir DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseModel, OControlModel); 105*cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir protected: 108*cdf0e10cSrcweir // OComponentHelper 109*cdf0e10cSrcweir virtual void SAL_CALL disposing(); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // ::com::sun::star::form::XImageProducerSupplier 112*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> SAL_CALL getImageProducer() throw (::com::sun::star::uno::RuntimeException) { return m_xProducer; } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // OPropertySetHelper 115*cdf0e10cSrcweir virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const; 116*cdf0e10cSrcweir virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue) throw (::com::sun::star::uno::Exception); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir virtual sal_Bool SAL_CALL convertFastPropertyValue(::com::sun::star::uno::Any& rConvertedValue, ::com::sun::star::uno::Any& rOldValue, sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) 119*cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir using ::cppu::OPropertySetHelper::getFastPropertyValue; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir // OPropertyChangeListener 124*cdf0e10cSrcweir virtual void _propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent&) throw(::com::sun::star::uno::RuntimeException); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir // XPropertyState 127*cdf0e10cSrcweir virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const; 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // XImageProducer 130*cdf0e10cSrcweir virtual void SAL_CALL addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException); 131*cdf0e10cSrcweir virtual void SAL_CALL removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException); 132*cdf0e10cSrcweir virtual void SAL_CALL startProduction( ) throw (::com::sun::star::uno::RuntimeException); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // XSubmissionSupplier 135*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmission > SAL_CALL getSubmission() throw (::com::sun::star::uno::RuntimeException); 136*cdf0e10cSrcweir virtual void SAL_CALL setSubmission( const ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmission >& _submission ) throw (::com::sun::star::uno::RuntimeException); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // XServiceInfo 139*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // XEventListener 142*cdf0e10cSrcweir using OControlModel::disposing; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir public: 145*cdf0e10cSrcweir struct GuardAccess { friend class ImageModelMethodGuard; private: GuardAccess() { } }; 146*cdf0e10cSrcweir ::osl::Mutex& getMutex( GuardAccess ) { return m_aMutex; } 147*cdf0e10cSrcweir ImageProducer* getImageProducer( GuardAccess ) { return m_pProducer; } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir protected: 150*cdf0e10cSrcweir using OControlModel::getMutex; 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir void implConstruct(); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // to be called from within the cloning-ctor of your derived class 155*cdf0e10cSrcweir void implInitializeImageURL( ); 156*cdf0e10cSrcweir }; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir //================================================================== 159*cdf0e10cSrcweir // ImageModelMethodGuard 160*cdf0e10cSrcweir //================================================================== 161*cdf0e10cSrcweir class ImageModelMethodGuard : public ::osl::MutexGuard 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir private: 164*cdf0e10cSrcweir typedef ::osl::MutexGuard GuardBase; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir public: 167*cdf0e10cSrcweir ImageModelMethodGuard( OClickableImageBaseModel& _rModel ) 168*cdf0e10cSrcweir :GuardBase( _rModel.getMutex( OClickableImageBaseModel::GuardAccess() ) ) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir if ( NULL == _rModel.getImageProducer( OClickableImageBaseModel::GuardAccess() ) ) 171*cdf0e10cSrcweir throw ::com::sun::star::lang::DisposedException( 172*cdf0e10cSrcweir ::rtl::OUString(), 173*cdf0e10cSrcweir static_cast< ::com::sun::star::form::XImageProducerSupplier* >( &_rModel ) 174*cdf0e10cSrcweir ); 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir }; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir //================================================================== 179*cdf0e10cSrcweir // OClickableImageBaseControl 180*cdf0e10cSrcweir //================================================================== 181*cdf0e10cSrcweir typedef ::cppu::ImplHelper3 < ::com::sun::star::form::XApproveActionBroadcaster 182*cdf0e10cSrcweir , ::com::sun::star::form::submission::XSubmission 183*cdf0e10cSrcweir , ::com::sun::star::frame::XDispatchProviderInterception 184*cdf0e10cSrcweir > OClickableImageBaseControl_BASE; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir class OClickableImageBaseControl :public OClickableImageBaseControl_BASE 187*cdf0e10cSrcweir ,public OControl 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir friend class OImageProducerThread_Impl; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir private: 192*cdf0e10cSrcweir OImageProducerThread_Impl* m_pThread; 193*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper m_aSubmissionVetoListeners; 194*cdf0e10cSrcweir ::std::auto_ptr< ControlFeatureInterception > 195*cdf0e10cSrcweir m_pFeatureInterception; 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir protected: 198*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper m_aApproveActionListeners; 199*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper m_aActionListeners; 200*cdf0e10cSrcweir ::rtl::OUString m_aActionCommand; 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir // XSubmission 203*cdf0e10cSrcweir virtual void SAL_CALL submit( ) throw (::com::sun::star::util::VetoException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 204*cdf0e10cSrcweir virtual void SAL_CALL submitWithInteraction( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler ) throw (::com::sun::star::util::VetoException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 205*cdf0e10cSrcweir virtual void SAL_CALL addSubmissionVetoListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmissionVetoListener >& listener ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); 206*cdf0e10cSrcweir virtual void SAL_CALL removeSubmissionVetoListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmissionVetoListener >& listener ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir // XServiceInfo 209*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir // XEventListener 212*cdf0e10cSrcweir using OControl::disposing; 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir public: 215*cdf0e10cSrcweir OClickableImageBaseControl( 216*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory, 217*cdf0e10cSrcweir const ::rtl::OUString& _aService); 218*cdf0e10cSrcweir virtual ~OClickableImageBaseControl(); 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir protected: 221*cdf0e10cSrcweir // UNO Anbindung 222*cdf0e10cSrcweir DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseControl, OControl); 223*cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir // OComponentHelper 226*cdf0e10cSrcweir virtual void SAL_CALL disposing(); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir // ::com::sun::star::form::XApproveActionBroadcaster 229*cdf0e10cSrcweir virtual void SAL_CALL addApproveActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XApproveActionListener>& _rxListener) 230*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 231*cdf0e10cSrcweir virtual void SAL_CALL removeApproveActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XApproveActionListener>& _rxListener) 232*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir // XDispatchProviderInterception 235*cdf0e10cSrcweir virtual void SAL_CALL registerDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException); 236*cdf0e10cSrcweir virtual void SAL_CALL releaseDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException); 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir protected: 239*cdf0e10cSrcweir virtual void actionPerformed_Impl( sal_Bool bNotifyListener, const ::com::sun::star::awt::MouseEvent& rEvt ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > _getTypes(); 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir /** approves the action by calling the approve listeners 244*cdf0e10cSrcweir @return <TRUE/> if and only if the action has <em>not</em> been cancelled by a listener 245*cdf0e10cSrcweir */ 246*cdf0e10cSrcweir bool approveAction( ); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir /** retrieves (and if necessary creates) the image producer thread. 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir Must be called with our mutex locked 251*cdf0e10cSrcweir */ 252*cdf0e10cSrcweir OImageProducerThread_Impl* getImageProducerThread(); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir private: 255*cdf0e10cSrcweir void implSubmit( 256*cdf0e10cSrcweir const ::com::sun::star::awt::MouseEvent& _rEvent, 257*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler 258*cdf0e10cSrcweir ) SAL_THROW((com::sun::star::util::VetoException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)); 259*cdf0e10cSrcweir }; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir //================================================================== 262*cdf0e10cSrcweir // OImageProducerThread_Impl 263*cdf0e10cSrcweir //================================================================== 264*cdf0e10cSrcweir class OImageProducerThread_Impl: public OComponentEventThread 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir protected: 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir // Die folgende Methode wrrd gerufen um das Event unter Beruecksichtigung 269*cdf0e10cSrcweir // seines Typs zu duplizieren 270*cdf0e10cSrcweir virtual ::com::sun::star::lang::EventObject* cloneEvent( const ::com::sun::star::lang::EventObject* _pEvt ) const; 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir // Ein Event bearbeiten. Der Mutex ist dabei nicht gelockt, pCompImpl 273*cdf0e10cSrcweir // bleibt aber in jedem Fall gueltig. 274*cdf0e10cSrcweir virtual void processEvent( ::cppu::OComponentHelper *pCompImpl, 275*cdf0e10cSrcweir const ::com::sun::star::lang::EventObject*, 276*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>&, 277*cdf0e10cSrcweir sal_Bool ); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir public: 280*cdf0e10cSrcweir OImageProducerThread_Impl( OClickableImageBaseControl *pControl ) : 281*cdf0e10cSrcweir OComponentEventThread( pControl ) 282*cdf0e10cSrcweir {} 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir void addEvent() { ::com::sun::star::lang::EventObject aEvt; OComponentEventThread::addEvent( &aEvt ); } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir protected: 287*cdf0e10cSrcweir using OComponentEventThread::addEvent; 288*cdf0e10cSrcweir }; 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir //......................................................................... 291*cdf0e10cSrcweir } // namespace frm 292*cdf0e10cSrcweir //......................................................................... 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir #endif // FORMS_SOURCE_CLICKABLEIMAGE_HXX 295*cdf0e10cSrcweir 296