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