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