bump product version to 5.0.4.1
[LibreOffice.git] / forms / source / component / clickableimage.hxx
blob9337b3cbe061731825dccf791644165cf557a0f7
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 INCLUDED_FORMS_SOURCE_COMPONENT_CLICKABLEIMAGE_HXX
21 #define INCLUDED_FORMS_SOURCE_COMPONENT_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 <com/sun/star/graphic/XGraphicObject.hpp>
37 #include <cppuhelper/implbase3.hxx>
40 class SfxMedium;
43 namespace frm
47 class OImageProducerThread_Impl;
48 class ControlFeatureInterception;
50 // OClickableImageBaseModel
52 typedef ::cppu::ImplHelper3 < ::com::sun::star::form::XImageProducerSupplier
53 , ::com::sun::star::awt::XImageProducer
54 , ::com::sun::star::form::submission::XSubmissionSupplier
55 > OClickableImageBaseModel_Base;
57 class OClickableImageBaseModel :public OClickableImageBaseModel_Base
58 ,public OControlModel
59 ,public OPropertyChangeListener
61 protected:
62 ::com::sun::star::form::FormButtonType m_eButtonType; // Type of the button (push, submit, reset)
63 OUString m_sTargetURL; // URL for the URL button
64 OUString m_sTargetFrame; // TargetFrame to open
66 // ImageProducer stuff
67 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> m_xProducer;
68 // Store the image in a graphic object to make it accesible via graphic cache using graphic ID.
69 ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphicObject > m_xGraphicObject;
70 SfxMedium* m_pMedium; // Download medium
71 ImageProducer* m_pProducer;
72 bool m_bDispatchUrlInternal; // property: is not allowed to set : 1
73 bool m_bDownloading : 1; // Is a download in progress?
74 bool m_bProdStarted : 1;
76 // XSubmission stuff
77 ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmission >
78 m_xSubmissionDelegate;
80 DECL_LINK( DownloadDoneLink, void* );
82 inline ImageProducer* GetImageProducer() { return m_pProducer; }
84 void StartProduction();
85 void SetURL(const OUString& rURL);
86 void DataAvailable();
87 void DownloadDone();
89 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes() SAL_OVERRIDE;
90 inline bool isDispatchUrlInternal() const { return m_bDispatchUrlInternal; }
91 inline void setDispatchUrlInternal(bool _bDispatch) { m_bDispatchUrlInternal = _bDispatch; }
93 public:
94 DECLARE_DEFAULT_XTOR( OClickableImageBaseModel );
96 // UNO Binding
97 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseModel, OControlModel)
98 virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
100 protected:
101 // OComponentHelper
102 virtual void SAL_CALL disposing() SAL_OVERRIDE;
104 // ::com::sun::star::form::XImageProducerSupplier
105 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer> SAL_CALL getImageProducer() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE { return m_xProducer; }
107 // OPropertySetHelper
108 virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const SAL_OVERRIDE;
109 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue) throw (::com::sun::star::uno::Exception, std::exception) SAL_OVERRIDE;
111 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 )
112 throw(::com::sun::star::lang::IllegalArgumentException) SAL_OVERRIDE;
114 using ::cppu::OPropertySetHelper::getFastPropertyValue;
116 // OPropertyChangeListener
117 virtual void _propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent&) throw(::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
119 // XPropertyState
120 virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const SAL_OVERRIDE;
122 // XImageProducer
123 virtual void SAL_CALL addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
124 virtual void SAL_CALL removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
125 virtual void SAL_CALL startProduction( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
127 // XSubmissionSupplier
128 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmission > SAL_CALL getSubmission() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
129 virtual void SAL_CALL setSubmission( const ::com::sun::star::uno::Reference< ::com::sun::star::form::submission::XSubmission >& _submission ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
131 // XServiceInfo
132 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
134 // XEventListener
135 using OControlModel::disposing;
137 public:
138 struct GuardAccess { friend class ImageModelMethodGuard; private: GuardAccess() { } };
139 ::osl::Mutex& getMutex( GuardAccess ) { return m_aMutex; }
140 ImageProducer* getImageProducer( GuardAccess ) { return m_pProducer; }
142 protected:
143 using OControlModel::getMutex;
145 void implConstruct();
147 // to be called from within the cloning-ctor of your derived class
148 void implInitializeImageURL( );
150 DECL_LINK( OnImageImportDone, ::Graphic* );
153 class ImageModelMethodGuard : public ::osl::MutexGuard
155 private:
156 typedef ::osl::MutexGuard GuardBase;
158 public:
159 ImageModelMethodGuard( OClickableImageBaseModel& _rModel )
160 :GuardBase( _rModel.getMutex( OClickableImageBaseModel::GuardAccess() ) )
162 if ( NULL == _rModel.getImageProducer( OClickableImageBaseModel::GuardAccess() ) )
163 throw ::com::sun::star::lang::DisposedException(
164 OUString(),
165 static_cast< ::com::sun::star::form::XImageProducerSupplier* >( &_rModel )
171 // OClickableImageBaseControl
173 typedef ::cppu::ImplHelper3 < ::com::sun::star::form::XApproveActionBroadcaster
174 , ::com::sun::star::form::submission::XSubmission
175 , ::com::sun::star::frame::XDispatchProviderInterception
176 > OClickableImageBaseControl_BASE;
178 class OClickableImageBaseControl :public OClickableImageBaseControl_BASE
179 ,public OControl
181 friend class OImageProducerThread_Impl;
183 private:
184 OImageProducerThread_Impl* m_pThread;
185 ::cppu::OInterfaceContainerHelper m_aSubmissionVetoListeners;
186 ::std::unique_ptr< ControlFeatureInterception >
187 m_pFeatureInterception;
189 protected:
190 ::cppu::OInterfaceContainerHelper m_aApproveActionListeners;
191 ::cppu::OInterfaceContainerHelper m_aActionListeners;
192 OUString m_aActionCommand;
194 // XSubmission
195 virtual void SAL_CALL submit( ) throw (::com::sun::star::util::VetoException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
196 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, std::exception) SAL_OVERRIDE;
197 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, std::exception) SAL_OVERRIDE;
198 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, std::exception) SAL_OVERRIDE;
200 // XServiceInfo
201 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
203 // XEventListener
204 using OControl::disposing;
206 public:
207 OClickableImageBaseControl(
208 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>& _rxFactory,
209 const OUString& _aService);
210 virtual ~OClickableImageBaseControl();
212 protected:
213 // UNO Binding
214 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseControl, OControl)
215 virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
217 // OComponentHelper
218 virtual void SAL_CALL disposing() SAL_OVERRIDE;
220 // ::com::sun::star::form::XApproveActionBroadcaster
221 virtual void SAL_CALL addApproveActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XApproveActionListener>& _rxListener)
222 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
223 virtual void SAL_CALL removeApproveActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XApproveActionListener>& _rxListener)
224 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
226 // XDispatchProviderInterception
227 virtual void SAL_CALL registerDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
228 virtual void SAL_CALL releaseDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
230 protected:
231 virtual void actionPerformed_Impl( bool bNotifyListener, const ::com::sun::star::awt::MouseEvent& rEvt );
233 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > _getTypes() SAL_OVERRIDE;
235 /** approves the action by calling the approve listeners
236 @return <TRUE/> if and only if the action has <em>not</em> been cancelled by a listener
238 bool approveAction( );
240 /** retrieves (and if necessary creates) the image producer thread.
242 Must be called with our mutex locked
244 OImageProducerThread_Impl* getImageProducerThread();
246 private:
247 void implSubmit(
248 const ::com::sun::star::awt::MouseEvent& _rEvent,
249 const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler
253 class OImageProducerThread_Impl: public OComponentEventThread
255 protected:
257 // This method was called to duplicate the Event by taking its type into account
258 virtual ::com::sun::star::lang::EventObject* cloneEvent( const ::com::sun::star::lang::EventObject* _pEvt ) const SAL_OVERRIDE;
260 // Process an Event.
261 // The mutex is not locked, pCompImpl stays valid in any case
262 virtual void processEvent( ::cppu::OComponentHelper *pCompImpl,
263 const ::com::sun::star::lang::EventObject*,
264 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>&,
265 bool ) SAL_OVERRIDE;
267 public:
268 OImageProducerThread_Impl( OClickableImageBaseControl *pControl ) :
269 OComponentEventThread( pControl )
272 void addEvent() { ::com::sun::star::lang::EventObject aEvt; OComponentEventThread::addEvent( &aEvt ); }
274 protected:
275 using OComponentEventThread::addEvent;
279 } // namespace frm
282 #endif // INCLUDED_FORMS_SOURCE_COMPONENT_CLICKABLEIMAGE_HXX
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */