1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
41 //.........................................................................
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
58 ,public OPropertyChangeListener
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;
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
);
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
; }
91 DECLARE_DEFAULT_XTOR( OClickableImageBaseModel
);
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
);
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
);
117 virtual ::com::sun::star::uno::Any
getPropertyDefaultByHandle( sal_Int32 nHandle
) const;
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
);
129 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException
);
132 using OControlModel::disposing
;
135 struct GuardAccess
{ friend class ImageModelMethodGuard
; private: GuardAccess() { } };
136 ::osl::Mutex
& getMutex( GuardAccess
) { return m_aMutex
; }
137 ImageProducer
* getImageProducer( GuardAccess
) { return m_pProducer
; }
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
154 typedef ::osl::MutexGuard GuardBase
;
157 ImageModelMethodGuard( OClickableImageBaseModel
& _rModel
)
158 :GuardBase( _rModel
.getMutex( OClickableImageBaseModel::GuardAccess() ) )
160 if ( NULL
== _rModel
.getImageProducer( OClickableImageBaseModel::GuardAccess() ) )
161 throw ::com::sun::star::lang::DisposedException(
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
179 friend class OImageProducerThread_Impl
;
182 OImageProducerThread_Impl
* m_pThread
;
183 ::cppu::OInterfaceContainerHelper m_aSubmissionVetoListeners
;
184 ::std::auto_ptr
< ControlFeatureInterception
>
185 m_pFeatureInterception
;
188 ::cppu::OInterfaceContainerHelper m_aApproveActionListeners
;
189 ::cppu::OInterfaceContainerHelper m_aActionListeners
;
190 OUString m_aActionCommand
;
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
);
199 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException
);
202 using OControl::disposing
;
205 OClickableImageBaseControl(
206 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
,
207 const OUString
& _aService
);
208 virtual ~OClickableImageBaseControl();
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
);
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
);
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();
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
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
>&,
270 OImageProducerThread_Impl( OClickableImageBaseControl
*pControl
) :
271 OComponentEventThread( pControl
)
274 void addEvent() { ::com::sun::star::lang::EventObject aEvt
; OComponentEventThread::addEvent( &aEvt
); }
277 using OComponentEventThread::addEvent
;
280 //.........................................................................
282 //.........................................................................
284 #endif // FORMS_SOURCE_CLICKABLEIMAGE_HXX
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */