tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / forms / source / component / clickableimage.hxx
blob2ec7b921224b97f471cc179abe45f9b4a93b0704
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 #pragma once
22 #include <memory>
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>
41 class SfxMedium;
42 class SfxObjectShell;
44 namespace frm
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
58 ,public OControlModel
59 ,public OPropertyChangeListener
61 protected:
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;
74 // XSubmission stuff
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);
84 void DataAvailable();
86 css::uno::Sequence< css::uno::Type> _getTypes() override;
87 bool isDispatchUrlInternal() const { return m_bDispatchUrlInternal; }
88 void setDispatchUrlInternal(bool _bDispatch) { m_bDispatchUrlInternal = _bDispatch; }
90 public:
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;
104 // UNO Binding
105 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseModel, OControlModel)
106 virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type& _rType) override;
108 protected:
109 // OComponentHelper
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;
126 // XPropertyState
127 virtual css::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const override;
129 // XImageProducer
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;
138 // XServiceInfo
139 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
141 // XEventListener
142 using OControlModel::disposing;
144 public:
145 struct GuardAccess { friend class ImageModelMethodGuard; private: GuardAccess() { } };
146 ::osl::Mutex& getMutex( GuardAccess ) { return m_aMutex; }
147 ImageProducer* getImageProducer( GuardAccess ) { return m_xProducer.get(); }
149 protected:
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
164 public:
165 explicit ImageModelMethodGuard( OClickableImageBaseModel& _rModel )
166 : ::osl::MutexGuard( _rModel.getMutex( OClickableImageBaseModel::GuardAccess() ) )
168 if ( nullptr == _rModel.getImageProducer( OClickableImageBaseModel::GuardAccess() ) )
169 throw css::lang::DisposedException(
170 OUString(),
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
185 ,public OControl
187 friend class OImageProducerThread_Impl;
189 private:
190 rtl::Reference<OImageProducerThread_Impl> m_pThread;
191 ::comphelper::OInterfaceContainerHelper3<css::form::submission::XSubmissionVetoListener>
192 m_aSubmissionVetoListeners;
193 ControlFeatureInterception m_aFeatureInterception;
195 protected:
196 ::comphelper::OInterfaceContainerHelper3<css::form::XApproveActionListener> m_aApproveActionListeners;
197 ::comphelper::OInterfaceContainerHelper3<css::awt::XActionListener> m_aActionListeners;
198 OUString m_aActionCommand;
200 // XSubmission
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;
206 // XServiceInfo
207 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
209 // XEventListener
210 using OControl::disposing;
212 public:
213 OClickableImageBaseControl(
214 const css::uno::Reference< css::uno::XComponentContext>& _rxFactory,
215 const OUString& _aService);
216 virtual ~OClickableImageBaseControl() override;
218 protected:
219 // UNO Binding
220 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseControl, OControl)
221 virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type& _rType) override;
223 // OComponentHelper
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;
234 protected:
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();
250 private:
251 void implSubmit(
252 const css::awt::MouseEvent& _rEvent,
253 const css::uno::Reference< css::task::XInteractionHandler >& aHandler
257 class OImageProducerThread_Impl: public OComponentEventThread
259 protected:
261 // Process an Event.
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>&,
266 bool ) override;
268 public:
269 explicit OImageProducerThread_Impl( OClickableImageBaseControl *pControl ) :
270 OComponentEventThread( pControl )
273 void addEvent() { OComponentEventThread::addEvent( std::make_unique<css::lang::EventObject>() ); }
275 protected:
276 using OComponentEventThread::addEvent;
280 } // namespace frm
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */