bump product version to 4.1.6.2
[LibreOffice.git] / forms / source / component / clickableimage.hxx
blob4ce20fcd0349b6d19d4d465ec165265bba5e8257
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef FORMS_SOURCE_CLICKABLEIMAGE_HXX
21 #define FORMS_SOURCE_CLICKABLEIMAGE_HXX
23 #include "FormComponent.hxx"
24 #include "EventThread.hxx"
25 #include "imgprod.hxx"
26 #include <tools/link.hxx>
27 #include <comphelper/propmultiplex.hxx>
28 #include <com/sun/star/form/XImageProducerSupplier.hpp>
29 #include <com/sun/star/form/FormButtonType.hpp>
30 #include <com/sun/star/form/XApproveActionListener.hpp>
31 #include <com/sun/star/form/XApproveActionBroadcaster.hpp>
32 #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
33 #include <com/sun/star/form/submission/XSubmission.hpp>
34 #include <com/sun/star/frame/XModel.hpp>
35 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
36 #include <cppuhelper/implbase3.hxx>
39 class SfxMedium;
41 //.........................................................................
42 namespace frm
44 //.........................................................................
46 class OImageProducerThread_Impl;
47 class ControlFeatureInterception;
48 //==================================================================
49 // OClickableImageBaseModel
50 //==================================================================
51 typedef ::cppu::ImplHelper3 < ::com::sun::star::form::XImageProducerSupplier
52 , ::com::sun::star::awt::XImageProducer
53 , ::com::sun::star::form::submission::XSubmissionSupplier
54 > OClickableImageBaseModel_Base;
56 class OClickableImageBaseModel :public OClickableImageBaseModel_Base
57 ,public OControlModel
58 ,public OPropertyChangeListener
60 protected:
61 ::com::sun::star::form::FormButtonType m_eButtonType; // Art des Buttons (push,submit,reset)
62 OUString m_sTargetURL; // URL fuer den URL-Button
63 OUString m_sTargetFrame; // TargetFrame zum Oeffnen
65 // ImageProducer stuff
66 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> m_xProducer;
67 SfxMedium* m_pMedium; // Download-Medium
68 ImageProducer* m_pProducer;
69 sal_Bool m_bDispatchUrlInternal; // property: is not allowed to set : 1
70 sal_Bool m_bDownloading : 1; // laeuft ein Download?
71 sal_Bool m_bProdStarted : 1;
73 // XSubmission stuff
74 ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmission >
75 m_xSubmissionDelegate;
77 DECL_STATIC_LINK( OClickableImageBaseModel, DownloadDoneLink, void* );
79 inline ImageProducer* GetImageProducer() { return m_pProducer; }
81 void StartProduction();
82 void SetURL(const OUString& rURL);
83 void DataAvailable();
84 void DownloadDone();
86 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
87 inline sal_Bool isDispatchUrlInternal() const { return m_bDispatchUrlInternal; }
88 inline void setDispatchUrlInternal(sal_Bool _bDispatch) { m_bDispatchUrlInternal = _bDispatch; }
90 public:
91 DECLARE_DEFAULT_XTOR( OClickableImageBaseModel );
93 // UNO Anbindung
94 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseModel, OControlModel);
95 virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException);
97 protected:
98 // OComponentHelper
99 virtual void SAL_CALL disposing();
101 // ::com::sun::star::form::XImageProducerSupplier
102 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> SAL_CALL getImageProducer() throw (::com::sun::star::uno::RuntimeException) { return m_xProducer; }
104 // OPropertySetHelper
105 virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
106 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue) throw (::com::sun::star::uno::Exception);
108 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 )
109 throw(::com::sun::star::lang::IllegalArgumentException);
111 using ::cppu::OPropertySetHelper::getFastPropertyValue;
113 // OPropertyChangeListener
114 virtual void _propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent&) throw(::com::sun::star::uno::RuntimeException);
116 // XPropertyState
117 virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const;
119 // XImageProducer
120 virtual void SAL_CALL addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException);
121 virtual void SAL_CALL removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException);
122 virtual void SAL_CALL startProduction( ) throw (::com::sun::star::uno::RuntimeException);
124 // XSubmissionSupplier
125 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmission > SAL_CALL getSubmission() throw (::com::sun::star::uno::RuntimeException);
126 virtual void SAL_CALL setSubmission( const ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmission >& _submission ) throw (::com::sun::star::uno::RuntimeException);
128 // XServiceInfo
129 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
131 // XEventListener
132 using OControlModel::disposing;
134 public:
135 struct GuardAccess { friend class ImageModelMethodGuard; private: GuardAccess() { } };
136 ::osl::Mutex& getMutex( GuardAccess ) { return m_aMutex; }
137 ImageProducer* getImageProducer( GuardAccess ) { return m_pProducer; }
139 protected:
140 using OControlModel::getMutex;
142 void implConstruct();
144 // to be called from within the cloning-ctor of your derived class
145 void implInitializeImageURL( );
148 //==================================================================
149 // ImageModelMethodGuard
150 //==================================================================
151 class ImageModelMethodGuard : public ::osl::MutexGuard
153 private:
154 typedef ::osl::MutexGuard GuardBase;
156 public:
157 ImageModelMethodGuard( OClickableImageBaseModel& _rModel )
158 :GuardBase( _rModel.getMutex( OClickableImageBaseModel::GuardAccess() ) )
160 if ( NULL == _rModel.getImageProducer( OClickableImageBaseModel::GuardAccess() ) )
161 throw ::com::sun::star::lang::DisposedException(
162 OUString(),
163 static_cast< ::com::sun::star::form::XImageProducerSupplier* >( &_rModel )
168 //==================================================================
169 // OClickableImageBaseControl
170 //==================================================================
171 typedef ::cppu::ImplHelper3 < ::com::sun::star::form::XApproveActionBroadcaster
172 , ::com::sun::star::form::submission::XSubmission
173 , ::com::sun::star::frame::XDispatchProviderInterception
174 > OClickableImageBaseControl_BASE;
176 class OClickableImageBaseControl :public OClickableImageBaseControl_BASE
177 ,public OControl
179 friend class OImageProducerThread_Impl;
181 private:
182 OImageProducerThread_Impl* m_pThread;
183 ::cppu::OInterfaceContainerHelper m_aSubmissionVetoListeners;
184 ::std::auto_ptr< ControlFeatureInterception >
185 m_pFeatureInterception;
187 protected:
188 ::cppu::OInterfaceContainerHelper m_aApproveActionListeners;
189 ::cppu::OInterfaceContainerHelper m_aActionListeners;
190 OUString m_aActionCommand;
192 // XSubmission
193 virtual void SAL_CALL submit( ) throw (::com::sun::star::util::VetoException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
194 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);
195 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);
196 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);
198 // XServiceInfo
199 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
201 // XEventListener
202 using OControl::disposing;
204 public:
205 OClickableImageBaseControl(
206 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory,
207 const OUString& _aService);
208 virtual ~OClickableImageBaseControl();
210 protected:
211 // UNO Anbindung
212 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseControl, OControl);
213 virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException);
215 // OComponentHelper
216 virtual void SAL_CALL disposing();
218 // ::com::sun::star::form::XApproveActionBroadcaster
219 virtual void SAL_CALL addApproveActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XApproveActionListener>& _rxListener)
220 throw(::com::sun::star::uno::RuntimeException);
221 virtual void SAL_CALL removeApproveActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XApproveActionListener>& _rxListener)
222 throw(::com::sun::star::uno::RuntimeException);
224 // XDispatchProviderInterception
225 virtual void SAL_CALL registerDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException);
226 virtual void SAL_CALL releaseDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException);
228 protected:
229 virtual void actionPerformed_Impl( sal_Bool bNotifyListener, const ::com::sun::star::awt::MouseEvent& rEvt );
231 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > _getTypes();
233 /** approves the action by calling the approve listeners
234 @return <TRUE/> if and only if the action has <em>not</em> been cancelled by a listener
236 bool approveAction( );
238 /** retrieves (and if necessary creates) the image producer thread.
240 Must be called with our mutex locked
242 OImageProducerThread_Impl* getImageProducerThread();
244 private:
245 void implSubmit(
246 const ::com::sun::star::awt::MouseEvent& _rEvent,
247 const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler
248 ) SAL_THROW((com::sun::star::util::VetoException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException));
251 //==================================================================
252 // OImageProducerThread_Impl
253 //==================================================================
254 class OImageProducerThread_Impl: public OComponentEventThread
256 protected:
258 // Die folgende Methode wrrd gerufen um das Event unter Beruecksichtigung
259 // seines Typs zu duplizieren
260 virtual ::com::sun::star::lang::EventObject* cloneEvent( const ::com::sun::star::lang::EventObject* _pEvt ) const;
262 // Ein Event bearbeiten. Der Mutex ist dabei nicht gelockt, pCompImpl
263 // bleibt aber in jedem Fall gueltig.
264 virtual void processEvent( ::cppu::OComponentHelper *pCompImpl,
265 const ::com::sun::star::lang::EventObject*,
266 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>&,
267 sal_Bool );
269 public:
270 OImageProducerThread_Impl( OClickableImageBaseControl *pControl ) :
271 OComponentEventThread( pControl )
274 void addEvent() { ::com::sun::star::lang::EventObject aEvt; OComponentEventThread::addEvent( &aEvt ); }
276 protected:
277 using OComponentEventThread::addEvent;
280 //.........................................................................
281 } // namespace frm
282 //.........................................................................
284 #endif // FORMS_SOURCE_CLICKABLEIMAGE_HXX
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */