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 .
23 #include <FormComponent.hxx>
24 #include "EventThread.hxx"
25 #include "imgprod.hxx"
26 #include <controlfeatureinterception.hxx>
27 #include <tools/link.hxx>
28 #include <comphelper/interfacecontainer3.hxx>
29 #include <comphelper/propmultiplex.hxx>
30 #include <com/sun/star/awt/XActionListener.hpp>
31 #include <com/sun/star/form/XImageProducerSupplier.hpp>
32 #include <com/sun/star/form/FormButtonType.hpp>
33 #include <com/sun/star/form/XApproveActionListener.hpp>
34 #include <com/sun/star/form/XApproveActionBroadcaster.hpp>
35 #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
36 #include <com/sun/star/form/submission/XSubmission.hpp>
37 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
38 #include <com/sun/star/graphic/XGraphicObject.hpp>
39 #include <cppuhelper/implbase3.hxx>
48 class OImageProducerThread_Impl
;
50 // OClickableImageBaseModel
52 typedef ::cppu::ImplHelper3
< css::form::XImageProducerSupplier
53 , css::awt::XImageProducer
54 , css::form::submission::XSubmissionSupplier
55 > OClickableImageBaseModel_Base
;
57 class OClickableImageBaseModel
:public OClickableImageBaseModel_Base
59 ,public OPropertyChangeListener
62 css::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 // Store the image in a graphic object to make it accessible via graphic cache using graphic ID.
68 css::uno::Reference
< css::graphic::XGraphicObject
> m_xGraphicObject
;
69 std::unique_ptr
<SfxMedium
> m_pMedium
; // Download medium
70 rtl::Reference
<ImageProducer
> m_xProducer
;
71 bool m_bDispatchUrlInternal
; // property: is not allowed to set : 1
72 bool m_bProdStarted
: 1;
75 css::uno::Reference
< css::form::submission::XSubmission
>
76 m_xSubmissionDelegate
;
78 DECL_LINK( DownloadDoneLink
, void*, void );
80 ImageProducer
* GetImageProducer() { return m_xProducer
.get(); }
82 void StartProduction();
83 void SetURL(const OUString
& rURL
);
86 css::uno::Sequence
< css::uno::Type
> _getTypes() override
;
87 bool isDispatchUrlInternal() const { return m_bDispatchUrlInternal
; }
88 void setDispatchUrlInternal(bool _bDispatch
) { m_bDispatchUrlInternal
= _bDispatch
; }
91 OClickableImageBaseModel(
92 const css::uno::Reference
< css::uno::XComponentContext
>& _rxFactory
,
93 const OUString
& _rUnoControlModelTypeName
,
94 const OUString
& _rDefault
97 OClickableImageBaseModel (
98 const OClickableImageBaseModel
* _pOriginal
,
99 const css::uno::Reference
< css::uno::XComponentContext
>& _rxFactory
102 virtual ~OClickableImageBaseModel() override
;
105 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseModel
, OControlModel
)
106 virtual css::uno::Any SAL_CALL
queryAggregation(const css::uno::Type
& _rType
) override
;
110 virtual void SAL_CALL
disposing() override
;
112 // css::form::XImageProducerSupplier
113 virtual css::uno::Reference
< css::awt::XImageProducer
> SAL_CALL
getImageProducer() override
{ return m_xProducer
; }
115 // OPropertySetHelper
116 virtual void SAL_CALL
getFastPropertyValue(css::uno::Any
& rValue
, sal_Int32 nHandle
) const override
;
117 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
119 virtual sal_Bool SAL_CALL
convertFastPropertyValue(css::uno::Any
& rConvertedValue
, css::uno::Any
& rOldValue
, sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
121 using ::cppu::OPropertySetHelper::getFastPropertyValue
;
123 // OPropertyChangeListener
124 virtual void _propertyChanged(const css::beans::PropertyChangeEvent
&) override
;
127 virtual css::uno::Any
getPropertyDefaultByHandle( sal_Int32 nHandle
) const override
;
130 virtual void SAL_CALL
addConsumer( const css::uno::Reference
< css::awt::XImageConsumer
>& xConsumer
) override
;
131 virtual void SAL_CALL
removeConsumer( const css::uno::Reference
< css::awt::XImageConsumer
>& xConsumer
) override
;
132 virtual void SAL_CALL
startProduction( ) override
;
134 // XSubmissionSupplier
135 virtual css::uno::Reference
< css::form::submission::XSubmission
> SAL_CALL
getSubmission() override
;
136 virtual void SAL_CALL
setSubmission( const css::uno::Reference
< css::form::submission::XSubmission
>& _submission
) override
;
139 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
142 using OControlModel::disposing
;
145 struct GuardAccess
{ friend class ImageModelMethodGuard
; private: GuardAccess() { } };
146 ::osl::Mutex
& getMutex( GuardAccess
) { return m_aMutex
; }
147 ImageProducer
* getImageProducer( GuardAccess
) { return m_xProducer
.get(); }
150 using OControlModel::getMutex
;
152 void implConstruct();
154 // to be called from within the cloning-ctor of your derived class
155 void implInitializeImageURL( );
157 SfxObjectShell
* GetObjectShell();
159 DECL_LINK( OnImageImportDone
, ::Graphic
*, void );
162 class ImageModelMethodGuard
: public ::osl::MutexGuard
165 explicit ImageModelMethodGuard( OClickableImageBaseModel
& _rModel
)
166 : ::osl::MutexGuard( _rModel
.getMutex( OClickableImageBaseModel::GuardAccess() ) )
168 if ( nullptr == _rModel
.getImageProducer( OClickableImageBaseModel::GuardAccess() ) )
169 throw css::lang::DisposedException(
171 static_cast< css::form::XImageProducerSupplier
* >( &_rModel
)
177 // OClickableImageBaseControl
179 typedef ::cppu::ImplHelper3
< css::form::XApproveActionBroadcaster
180 , css::form::submission::XSubmission
181 , css::frame::XDispatchProviderInterception
182 > OClickableImageBaseControl_BASE
;
184 class OClickableImageBaseControl
:public OClickableImageBaseControl_BASE
187 friend class OImageProducerThread_Impl
;
190 rtl::Reference
<OImageProducerThread_Impl
> m_pThread
;
191 ::comphelper::OInterfaceContainerHelper3
<css::form::submission::XSubmissionVetoListener
>
192 m_aSubmissionVetoListeners
;
193 ControlFeatureInterception m_aFeatureInterception
;
196 ::comphelper::OInterfaceContainerHelper3
<css::form::XApproveActionListener
> m_aApproveActionListeners
;
197 ::comphelper::OInterfaceContainerHelper3
<css::awt::XActionListener
> m_aActionListeners
;
198 OUString m_aActionCommand
;
201 virtual void SAL_CALL
submit( ) override
;
202 virtual void SAL_CALL
submitWithInteraction( const css::uno::Reference
< css::task::XInteractionHandler
>& aHandler
) override
;
203 virtual void SAL_CALL
addSubmissionVetoListener( const css::uno::Reference
< css::form::submission::XSubmissionVetoListener
>& listener
) override
;
204 virtual void SAL_CALL
removeSubmissionVetoListener( const css::uno::Reference
< css::form::submission::XSubmissionVetoListener
>& listener
) override
;
207 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
210 using OControl::disposing
;
213 OClickableImageBaseControl(
214 const css::uno::Reference
< css::uno::XComponentContext
>& _rxFactory
,
215 const OUString
& _aService
);
216 virtual ~OClickableImageBaseControl() override
;
220 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseControl
, OControl
)
221 virtual css::uno::Any SAL_CALL
queryAggregation(const css::uno::Type
& _rType
) override
;
224 virtual void SAL_CALL
disposing() override
;
226 // css::form::XApproveActionBroadcaster
227 virtual void SAL_CALL
addApproveActionListener(const css::uno::Reference
< css::form::XApproveActionListener
>& _rxListener
) override
;
228 virtual void SAL_CALL
removeApproveActionListener(const css::uno::Reference
< css::form::XApproveActionListener
>& _rxListener
) override
;
230 // XDispatchProviderInterception
231 virtual void SAL_CALL
registerDispatchProviderInterceptor( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& Interceptor
) override
;
232 virtual void SAL_CALL
releaseDispatchProviderInterceptor( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& Interceptor
) override
;
235 virtual void actionPerformed_Impl( bool bNotifyListener
, const css::awt::MouseEvent
& rEvt
);
237 css::uno::Sequence
< css::uno::Type
> _getTypes() override
;
239 /** approves the action by calling the approve listeners
240 @return <TRUE/> if and only if the action has <em>not</em> been cancelled by a listener
242 bool approveAction( );
244 /** retrieves (and if necessary creates) the image producer thread.
246 Must be called with our mutex locked
248 OImageProducerThread_Impl
* getImageProducerThread();
252 const css::awt::MouseEvent
& _rEvent
,
253 const css::uno::Reference
< css::task::XInteractionHandler
>& aHandler
257 class OImageProducerThread_Impl
: public OComponentEventThread
262 // The mutex is not locked, pCompImpl stays valid in any case
263 virtual void processEvent( ::cppu::OComponentHelper
*pCompImpl
,
264 const css::lang::EventObject
*,
265 const css::uno::Reference
< css::awt::XControl
>&,
269 explicit OImageProducerThread_Impl( OClickableImageBaseControl
*pControl
) :
270 OComponentEventThread( pControl
)
273 void addEvent() { OComponentEventThread::addEvent( std::make_unique
<css::lang::EventObject
>() ); }
276 using OComponentEventThread::addEvent
;
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */