xref: /trunk/main/forms/source/component/clickableimage.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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);
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() { 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);
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 
116         using ::cppu::OPropertySetHelper::getFastPropertyValue;
117 
118         // OPropertyChangeListener
119         virtual void _propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent&);
120 
121         // XPropertyState
122         virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const;
123 
124         // XImageProducer
125         virtual void SAL_CALL addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer );
126         virtual void SAL_CALL removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer );
127         virtual void SAL_CALL startProduction(  );
128 
129         // XSubmissionSupplier
130         virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmission > SAL_CALL getSubmission();
131         virtual void SAL_CALL setSubmission( const ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmission >& _submission );
132 
133         // XServiceInfo
134         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  );
135 
136         // XEventListener
137         using OControlModel::disposing;
138 
139     public:
GuardAccessfrm::OClickableImageBaseModel::GuardAccess140         struct GuardAccess { friend class ImageModelMethodGuard; private: GuardAccess() { } };
getMutex(GuardAccess)141         ::osl::Mutex&   getMutex( GuardAccess ) { return m_aMutex; }
getImageProducer(GuardAccess)142         ImageProducer*  getImageProducer( GuardAccess ) { return m_pProducer; }
143 
144     protected:
145         using OControlModel::getMutex;
146 
147         void implConstruct();
148 
149         // to be called from within the cloning-ctor of your derived class
150         void implInitializeImageURL( );
151     };
152 
153     //==================================================================
154     // ImageModelMethodGuard
155     //==================================================================
156     class ImageModelMethodGuard : public ::osl::MutexGuard
157     {
158     private:
159         typedef ::osl::MutexGuard   GuardBase;
160 
161     public:
ImageModelMethodGuard(OClickableImageBaseModel & _rModel)162         ImageModelMethodGuard( OClickableImageBaseModel& _rModel )
163             :GuardBase( _rModel.getMutex( OClickableImageBaseModel::GuardAccess() ) )
164         {
165             if ( NULL == _rModel.getImageProducer( OClickableImageBaseModel::GuardAccess() ) )
166                 throw ::com::sun::star::lang::DisposedException(
167                     ::rtl::OUString(),
168                     static_cast< ::com::sun::star::form::XImageProducerSupplier* >( &_rModel )
169                 );
170         }
171     };
172 
173     //==================================================================
174     // OClickableImageBaseControl
175     //==================================================================
176     typedef ::cppu::ImplHelper3 <   ::com::sun::star::form::XApproveActionBroadcaster
177                                 ,   ::com::sun::star::form::submission::XSubmission
178                                 ,   ::com::sun::star::frame::XDispatchProviderInterception
179                                 >   OClickableImageBaseControl_BASE;
180 
181     class OClickableImageBaseControl    :public OClickableImageBaseControl_BASE
182                                         ,public OControl
183     {
184         friend class OImageProducerThread_Impl;
185 
186     private:
187         OImageProducerThread_Impl*          m_pThread;
188         ::cppu::OInterfaceContainerHelper   m_aSubmissionVetoListeners;
189         ::std::auto_ptr< ControlFeatureInterception >
190                                             m_pFeatureInterception;
191 
192     protected:
193         ::cppu::OInterfaceContainerHelper m_aApproveActionListeners;
194         ::cppu::OInterfaceContainerHelper m_aActionListeners;
195         ::rtl::OUString m_aActionCommand;
196 
197         // XSubmission
198         virtual void SAL_CALL submit(  );
199         virtual void SAL_CALL submitWithInteraction( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler );
200         virtual void SAL_CALL addSubmissionVetoListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmissionVetoListener >& listener );
201         virtual void SAL_CALL removeSubmissionVetoListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmissionVetoListener >& listener );
202 
203         // XServiceInfo
204         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  );
205 
206         // XEventListener
207         using OControl::disposing;
208 
209     public:
210         OClickableImageBaseControl(
211             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory,
212             const ::rtl::OUString& _aService);
213         virtual ~OClickableImageBaseControl();
214 
215     protected:
216         // UNO Anbindung
217         DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseControl, OControl);
218         virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType);
219 
220         // OComponentHelper
221         virtual void SAL_CALL disposing();
222 
223         // ::com::sun::star::form::XApproveActionBroadcaster
224         virtual void SAL_CALL addApproveActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XApproveActionListener>& _rxListener);
225         virtual void SAL_CALL removeApproveActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XApproveActionListener>& _rxListener);
226 
227         // XDispatchProviderInterception
228         virtual void SAL_CALL registerDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor );
229         virtual void SAL_CALL releaseDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor );
230 
231     protected:
232         virtual void actionPerformed_Impl( sal_Bool bNotifyListener, const ::com::sun::star::awt::MouseEvent& rEvt );
233 
234         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > _getTypes();
235 
236         /** approves the action by calling the approve listeners
237             @return <TRUE/> if and only if the action has <em>not</em> been cancelled by a listener
238         */
239         bool    approveAction( );
240 
241         /** retrieves (and if necessary creates) the image producer thread.
242 
243             Must be called with our mutex locked
244         */
245         OImageProducerThread_Impl* getImageProducerThread();
246 
247     private:
248         void implSubmit(
249             const ::com::sun::star::awt::MouseEvent& _rEvent,
250             const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler
251         );
252     };
253 
254     //==================================================================
255     // OImageProducerThread_Impl
256     //==================================================================
257     class OImageProducerThread_Impl: public OComponentEventThread
258     {
259     protected:
260 
261         // Die folgende Methode wrrd gerufen um das Event unter Beruecksichtigung
262         // seines Typs zu duplizieren
263         virtual ::com::sun::star::lang::EventObject* cloneEvent( const ::com::sun::star::lang::EventObject* _pEvt ) const;
264 
265         // Ein Event bearbeiten. Der Mutex ist dabei nicht gelockt, pCompImpl
266         // bleibt aber in jedem Fall gueltig.
267         virtual void processEvent( ::cppu::OComponentHelper *pCompImpl,
268                                 const ::com::sun::star::lang::EventObject*,
269                                 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>&,
270                                 sal_Bool );
271 
272     public:
OImageProducerThread_Impl(OClickableImageBaseControl * pControl)273         OImageProducerThread_Impl( OClickableImageBaseControl *pControl ) :
274             OComponentEventThread( pControl )
275         {}
276 
addEvent()277         void addEvent() { ::com::sun::star::lang::EventObject aEvt; OComponentEventThread::addEvent( &aEvt ); }
278 
279     protected:
280         using OComponentEventThread::addEvent;
281     };
282 
283 //.........................................................................
284 }   // namespace frm
285 //.........................................................................
286 
287 #endif // FORMS_SOURCE_CLICKABLEIMAGE_HXX
288