1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: clickableimage.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef FORMS_SOURCE_CLICKABLEIMAGE_HXX
32 #define FORMS_SOURCE_CLICKABLEIMAGE_HXX
34 #include "FormComponent.hxx"
35 #include "EventThread.hxx"
36 #include "imgprod.hxx"
37 #include <tools/link.hxx>
38 #include <comphelper/propmultiplex.hxx>
39 #include <com/sun/star/form/XImageProducerSupplier.hpp>
40 #include <com/sun/star/form/FormButtonType.hpp>
41 #include <com/sun/star/form/XApproveActionListener.hpp>
42 #include <com/sun/star/form/XApproveActionBroadcaster.hpp>
43 #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
44 #include <com/sun/star/form/submission/XSubmission.hpp>
45 #include <com/sun/star/frame/XModel.hpp>
46 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
47 #include <cppuhelper/implbase3.hxx>
52 //.........................................................................
55 //.........................................................................
57 class OImageProducerThread_Impl
;
58 class ControlFeatureInterception
;
59 //==================================================================
60 // OClickableImageBaseModel
61 //==================================================================
62 typedef ::cppu::ImplHelper3
< ::com::sun::star::form::XImageProducerSupplier
63 , ::com::sun::star::awt::XImageProducer
64 , ::com::sun::star::form::submission::XSubmissionSupplier
65 > OClickableImageBaseModel_Base
;
67 class OClickableImageBaseModel
:public OClickableImageBaseModel_Base
69 ,public OPropertyChangeListener
72 ::com::sun::star::form::FormButtonType m_eButtonType
; // Art des Buttons (push,submit,reset)
73 ::rtl::OUString m_sTargetURL
; // URL fuer den URL-Button
74 ::rtl::OUString m_sTargetFrame
; // TargetFrame zum Oeffnen
76 // ImageProducer stuff
77 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XImageProducer
> m_xProducer
;
78 SfxMedium
* m_pMedium
; // Download-Medium
79 ImageProducer
* m_pProducer
;
80 sal_Bool m_bDispatchUrlInternal
; // property: is not allowed to set : 1
81 sal_Bool m_bDownloading
: 1; // laeuft ein Download?
82 sal_Bool m_bProdStarted
: 1;
85 ::com::sun::star::uno::Reference
< ::com::sun::star::form::submission::XSubmission
>
86 m_xSubmissionDelegate
;
89 DECL_STATIC_LINK( OClickableImageBaseModel
, DataAvailableLink
, void* );
90 DECL_STATIC_LINK( OClickableImageBaseModel
, DownloadDoneLink
, void* );
92 inline ImageProducer
* GetImageProducer() { return m_pProducer
; }
94 void StartProduction();
95 void SetURL(const ::rtl::OUString
& rURL
);
99 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> _getTypes();
100 inline sal_Bool
isDispatchUrlInternal() const { return m_bDispatchUrlInternal
; }
101 inline void setDispatchUrlInternal(sal_Bool _bDispatch
) { m_bDispatchUrlInternal
= _bDispatch
; }
104 DECLARE_DEFAULT_XTOR( OClickableImageBaseModel
);
107 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseModel
, OControlModel
);
108 virtual ::com::sun::star::uno::Any SAL_CALL
queryAggregation(const ::com::sun::star::uno::Type
& _rType
) throw(::com::sun::star::uno::RuntimeException
);
112 virtual void SAL_CALL
disposing();
114 // ::com::sun::star::form::XImageProducerSupplier
115 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XImageProducer
> SAL_CALL
getImageProducer() throw (::com::sun::star::uno::RuntimeException
) { return m_xProducer
; }
117 // OPropertySetHelper
118 virtual void SAL_CALL
getFastPropertyValue(::com::sun::star::uno::Any
& rValue
, sal_Int32 nHandle
) const;
119 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
, const ::com::sun::star::uno::Any
& rValue
) throw (::com::sun::star::uno::Exception
);
121 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
)
122 throw(::com::sun::star::lang::IllegalArgumentException
);
124 using ::cppu::OPropertySetHelper::getFastPropertyValue
;
126 // OPropertyChangeListener
127 virtual void _propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent
&) throw(::com::sun::star::uno::RuntimeException
);
130 virtual ::com::sun::star::uno::Any
getPropertyDefaultByHandle( sal_Int32 nHandle
) const;
133 virtual void SAL_CALL
addConsumer( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XImageConsumer
>& xConsumer
) throw (::com::sun::star::uno::RuntimeException
);
134 virtual void SAL_CALL
removeConsumer( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XImageConsumer
>& xConsumer
) throw (::com::sun::star::uno::RuntimeException
);
135 virtual void SAL_CALL
startProduction( ) throw (::com::sun::star::uno::RuntimeException
);
137 // XSubmissionSupplier
138 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::form::submission::XSubmission
> SAL_CALL
getSubmission() throw (::com::sun::star::uno::RuntimeException
);
139 virtual void SAL_CALL
setSubmission( const ::com::sun::star::uno::Reference
< ::com::sun::star::form::submission::XSubmission
>& _submission
) throw (::com::sun::star::uno::RuntimeException
);
142 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException
);
145 using OControlModel::disposing
;
148 struct GuardAccess
{ friend class ImageModelMethodGuard
; private: GuardAccess() { } };
149 ::osl::Mutex
& getMutex( GuardAccess
) { return m_aMutex
; }
150 ImageProducer
* getImageProducer( GuardAccess
) { return m_pProducer
; }
153 using OControlModel::getMutex
;
155 void implConstruct();
157 // to be called from within the cloning-ctor of your derived class
158 void implInitializeImageURL( );
161 //==================================================================
162 // ImageModelMethodGuard
163 //==================================================================
164 class ImageModelMethodGuard
: public ::osl::MutexGuard
167 typedef ::osl::MutexGuard GuardBase
;
170 ImageModelMethodGuard( OClickableImageBaseModel
& _rModel
)
171 :GuardBase( _rModel
.getMutex( OClickableImageBaseModel::GuardAccess() ) )
173 if ( NULL
== _rModel
.getImageProducer( OClickableImageBaseModel::GuardAccess() ) )
174 throw ::com::sun::star::lang::DisposedException(
176 static_cast< ::com::sun::star::form::XImageProducerSupplier
* >( &_rModel
)
181 //==================================================================
182 // OClickableImageBaseControl
183 //==================================================================
184 typedef ::cppu::ImplHelper3
< ::com::sun::star::form::XApproveActionBroadcaster
185 , ::com::sun::star::form::submission::XSubmission
186 , ::com::sun::star::frame::XDispatchProviderInterception
187 > OClickableImageBaseControl_BASE
;
189 class OClickableImageBaseControl
:public OClickableImageBaseControl_BASE
192 friend class OImageProducerThread_Impl
;
195 OImageProducerThread_Impl
* m_pThread
;
196 ::cppu::OInterfaceContainerHelper m_aSubmissionVetoListeners
;
197 ::std::auto_ptr
< ControlFeatureInterception
>
198 m_pFeatureInterception
;
201 ::cppu::OInterfaceContainerHelper m_aApproveActionListeners
;
202 ::cppu::OInterfaceContainerHelper m_aActionListeners
;
203 ::rtl::OUString m_aActionCommand
;
206 virtual void SAL_CALL
submit( ) throw (::com::sun::star::util::VetoException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
207 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
);
208 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
);
209 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
);
212 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException
);
215 using OControl::disposing
;
218 OClickableImageBaseControl(
219 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
,
220 const ::rtl::OUString
& _aService
);
221 virtual ~OClickableImageBaseControl();
225 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseControl
, OControl
);
226 virtual ::com::sun::star::uno::Any SAL_CALL
queryAggregation(const ::com::sun::star::uno::Type
& _rType
) throw(::com::sun::star::uno::RuntimeException
);
229 virtual void SAL_CALL
disposing();
231 // ::com::sun::star::form::XApproveActionBroadcaster
232 virtual void SAL_CALL
addApproveActionListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XApproveActionListener
>& _rxListener
)
233 throw(::com::sun::star::uno::RuntimeException
);
234 virtual void SAL_CALL
removeApproveActionListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XApproveActionListener
>& _rxListener
)
235 throw(::com::sun::star::uno::RuntimeException
);
237 // XDispatchProviderInterception
238 virtual void SAL_CALL
registerDispatchProviderInterceptor( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProviderInterceptor
>& Interceptor
) throw (::com::sun::star::uno::RuntimeException
);
239 virtual void SAL_CALL
releaseDispatchProviderInterceptor( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProviderInterceptor
>& Interceptor
) throw (::com::sun::star::uno::RuntimeException
);
242 virtual void actionPerformed_Impl( sal_Bool bNotifyListener
, const ::com::sun::star::awt::MouseEvent
& rEvt
);
244 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> _getTypes();
246 /** approves the action by calling the approve listeners
247 @return <TRUE/> if and only if the action has <em>not</em> been cancelled by a listener
249 bool approveAction( );
251 /** retrieves (and if necessary creates) the image producer thread.
253 Must be called with our mutex locked
255 OImageProducerThread_Impl
* getImageProducerThread();
259 const ::com::sun::star::awt::MouseEvent
& _rEvent
,
260 const ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionHandler
>& aHandler
261 ) SAL_THROW((com::sun::star::util::VetoException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
));
264 //==================================================================
265 // OImageProducerThread_Impl
266 //==================================================================
267 class OImageProducerThread_Impl
: public OComponentEventThread
271 // Die folgende Methode wrrd gerufen um das Event unter Beruecksichtigung
272 // seines Typs zu duplizieren
273 virtual ::com::sun::star::lang::EventObject
* cloneEvent( const ::com::sun::star::lang::EventObject
* _pEvt
) const;
275 // Ein Event bearbeiten. Der Mutex ist dabei nicht gelockt, pCompImpl
276 // bleibt aber in jedem Fall gueltig.
277 virtual void processEvent( ::cppu::OComponentHelper
*pCompImpl
,
278 const ::com::sun::star::lang::EventObject
*,
279 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
>&,
283 OImageProducerThread_Impl( OClickableImageBaseControl
*pControl
) :
284 OComponentEventThread( pControl
)
287 void addEvent() { ::com::sun::star::lang::EventObject aEvt
; OComponentEventThread::addEvent( &aEvt
); }
290 using OComponentEventThread::addEvent
;
293 //.........................................................................
295 //.........................................................................
297 #endif // FORMS_SOURCE_CLICKABLEIMAGE_HXX