LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / forms / source / component / clickableimage.hxx
blobe7bd4094bc4dc2c2d3033b76fe8f00267e696bbb
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 <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/XDispatchProviderInterception.hpp>
35 #include <com/sun/star/graphic/XGraphicObject.hpp>
36 #include <cppuhelper/implbase3.hxx>
38 class SfxMedium;
39 class SfxObjectShell;
41 namespace frm
45 class OImageProducerThread_Impl;
46 class ControlFeatureInterception;
48 // OClickableImageBaseModel
50 typedef ::cppu::ImplHelper3 < css::form::XImageProducerSupplier
51 , css::awt::XImageProducer
52 , css::form::submission::XSubmissionSupplier
53 > OClickableImageBaseModel_Base;
55 class OClickableImageBaseModel :public OClickableImageBaseModel_Base
56 ,public OControlModel
57 ,public OPropertyChangeListener
59 protected:
60 css::form::FormButtonType m_eButtonType; // Type of the button (push, submit, reset)
61 OUString m_sTargetURL; // URL for the URL button
62 OUString m_sTargetFrame; // TargetFrame to open
64 // ImageProducer stuff
65 // Store the image in a graphic object to make it accessible via graphic cache using graphic ID.
66 css::uno::Reference< css::graphic::XGraphicObject > m_xGraphicObject;
67 std::unique_ptr<SfxMedium> m_pMedium; // Download medium
68 rtl::Reference<ImageProducer> m_xProducer;
69 bool m_bDispatchUrlInternal; // property: is not allowed to set : 1
70 bool m_bProdStarted : 1;
72 // XSubmission stuff
73 css::uno::Reference< css::form::submission::XSubmission >
74 m_xSubmissionDelegate;
76 DECL_LINK( DownloadDoneLink, void*, void );
78 ImageProducer* GetImageProducer() { return m_xProducer.get(); }
80 void StartProduction();
81 void SetURL(const OUString& rURL);
82 void DataAvailable();
84 css::uno::Sequence< css::uno::Type> _getTypes() override;
85 bool isDispatchUrlInternal() const { return m_bDispatchUrlInternal; }
86 void setDispatchUrlInternal(bool _bDispatch) { m_bDispatchUrlInternal = _bDispatch; }
88 public:
89 OClickableImageBaseModel(
90 const css::uno::Reference< css::uno::XComponentContext>& _rxFactory,
91 const OUString& _rUnoControlModelTypeName,
92 const OUString& _rDefault
95 OClickableImageBaseModel (
96 const OClickableImageBaseModel* _pOriginal,
97 const css::uno::Reference< css::uno::XComponentContext>& _rxFactory
100 virtual ~OClickableImageBaseModel() override;
102 // UNO Binding
103 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseModel, OControlModel)
104 virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type& _rType) override;
106 protected:
107 // OComponentHelper
108 virtual void SAL_CALL disposing() override;
110 // css::form::XImageProducerSupplier
111 virtual css::uno::Reference< css::awt::XImageProducer> SAL_CALL getImageProducer() override { return m_xProducer; }
113 // OPropertySetHelper
114 virtual void SAL_CALL getFastPropertyValue(css::uno::Any& rValue, sal_Int32 nHandle ) const override;
115 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any& rValue) override;
117 virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any& rConvertedValue, css::uno::Any& rOldValue, sal_Int32 nHandle, const css::uno::Any& rValue ) override;
119 using ::cppu::OPropertySetHelper::getFastPropertyValue;
121 // OPropertyChangeListener
122 virtual void _propertyChanged(const css::beans::PropertyChangeEvent&) override;
124 // XPropertyState
125 virtual css::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const override;
127 // XImageProducer
128 virtual void SAL_CALL addConsumer( const css::uno::Reference< css::awt::XImageConsumer >& xConsumer ) override;
129 virtual void SAL_CALL removeConsumer( const css::uno::Reference< css::awt::XImageConsumer >& xConsumer ) override;
130 virtual void SAL_CALL startProduction( ) override;
132 // XSubmissionSupplier
133 virtual css::uno::Reference< css::form::submission::XSubmission > SAL_CALL getSubmission() override;
134 virtual void SAL_CALL setSubmission( const css::uno::Reference< css::form::submission::XSubmission >& _submission ) override;
136 // XServiceInfo
137 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
139 // XEventListener
140 using OControlModel::disposing;
142 public:
143 struct GuardAccess { friend class ImageModelMethodGuard; private: GuardAccess() { } };
144 ::osl::Mutex& getMutex( GuardAccess ) { return m_aMutex; }
145 ImageProducer* getImageProducer( GuardAccess ) { return m_xProducer.get(); }
147 protected:
148 using OControlModel::getMutex;
150 void implConstruct();
152 // to be called from within the cloning-ctor of your derived class
153 void implInitializeImageURL( );
155 SfxObjectShell* GetObjectShell();
157 DECL_LINK( OnImageImportDone, ::Graphic*, void );
160 class ImageModelMethodGuard : public ::osl::MutexGuard
162 public:
163 explicit ImageModelMethodGuard( OClickableImageBaseModel& _rModel )
164 : ::osl::MutexGuard( _rModel.getMutex( OClickableImageBaseModel::GuardAccess() ) )
166 if ( nullptr == _rModel.getImageProducer( OClickableImageBaseModel::GuardAccess() ) )
167 throw css::lang::DisposedException(
168 OUString(),
169 static_cast< css::form::XImageProducerSupplier* >( &_rModel )
175 // OClickableImageBaseControl
177 typedef ::cppu::ImplHelper3 < css::form::XApproveActionBroadcaster
178 , css::form::submission::XSubmission
179 , css::frame::XDispatchProviderInterception
180 > OClickableImageBaseControl_BASE;
182 class OClickableImageBaseControl :public OClickableImageBaseControl_BASE
183 ,public OControl
185 friend class OImageProducerThread_Impl;
187 private:
188 rtl::Reference<OImageProducerThread_Impl> m_pThread;
189 ::comphelper::OInterfaceContainerHelper2 m_aSubmissionVetoListeners;
190 ::std::unique_ptr< ControlFeatureInterception >
191 m_pFeatureInterception;
193 protected:
194 ::comphelper::OInterfaceContainerHelper2 m_aApproveActionListeners;
195 ::comphelper::OInterfaceContainerHelper2 m_aActionListeners;
196 OUString m_aActionCommand;
198 // XSubmission
199 virtual void SAL_CALL submit( ) override;
200 virtual void SAL_CALL submitWithInteraction( const css::uno::Reference< css::task::XInteractionHandler >& aHandler ) override;
201 virtual void SAL_CALL addSubmissionVetoListener( const css::uno::Reference< css::form::submission::XSubmissionVetoListener >& listener ) override;
202 virtual void SAL_CALL removeSubmissionVetoListener( const css::uno::Reference< css::form::submission::XSubmissionVetoListener >& listener ) override;
204 // XServiceInfo
205 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
207 // XEventListener
208 using OControl::disposing;
210 public:
211 OClickableImageBaseControl(
212 const css::uno::Reference< css::uno::XComponentContext>& _rxFactory,
213 const OUString& _aService);
214 virtual ~OClickableImageBaseControl() override;
216 protected:
217 // UNO Binding
218 DECLARE_UNO3_AGG_DEFAULTS(OClickableImageBaseControl, OControl)
219 virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type& _rType) override;
221 // OComponentHelper
222 virtual void SAL_CALL disposing() override;
224 // css::form::XApproveActionBroadcaster
225 virtual void SAL_CALL addApproveActionListener(const css::uno::Reference< css::form::XApproveActionListener>& _rxListener) override;
226 virtual void SAL_CALL removeApproveActionListener(const css::uno::Reference< css::form::XApproveActionListener>& _rxListener) override;
228 // XDispatchProviderInterception
229 virtual void SAL_CALL registerDispatchProviderInterceptor( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& Interceptor ) override;
230 virtual void SAL_CALL releaseDispatchProviderInterceptor( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& Interceptor ) override;
232 protected:
233 virtual void actionPerformed_Impl( bool bNotifyListener, const css::awt::MouseEvent& rEvt );
235 css::uno::Sequence< css::uno::Type > _getTypes() override;
237 /** approves the action by calling the approve listeners
238 @return <TRUE/> if and only if the action has <em>not</em> been cancelled by a listener
240 bool approveAction( );
242 /** retrieves (and if necessary creates) the image producer thread.
244 Must be called with our mutex locked
246 OImageProducerThread_Impl* getImageProducerThread();
248 private:
249 void implSubmit(
250 const css::awt::MouseEvent& _rEvent,
251 const css::uno::Reference< css::task::XInteractionHandler >& aHandler
255 class OImageProducerThread_Impl: public OComponentEventThread
257 protected:
259 // Process an Event.
260 // The mutex is not locked, pCompImpl stays valid in any case
261 virtual void processEvent( ::cppu::OComponentHelper *pCompImpl,
262 const css::lang::EventObject*,
263 const css::uno::Reference< css::awt::XControl>&,
264 bool ) override;
266 public:
267 explicit OImageProducerThread_Impl( OClickableImageBaseControl *pControl ) :
268 OComponentEventThread( pControl )
271 void addEvent() { OComponentEventThread::addEvent( std::make_unique<css::lang::EventObject>() ); }
273 protected:
274 using OComponentEventThread::addEvent;
278 } // namespace frm
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */