LibreOffice Module forms (master) 1
clickableimage.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <memory>
23#include <FormComponent.hxx>
24#include "EventThread.hxx"
25#include "imgprod.hxx"
27#include <tools/link.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>
40
41class SfxMedium;
42class SfxObjectShell;
43
44namespace frm
45{
46
47
48 class OImageProducerThread_Impl;
49
50 // OClickableImageBaseModel
51
52 typedef ::cppu::ImplHelper3 < css::form::XImageProducerSupplier
53 , css::awt::XImageProducer
54 , css::form::submission::XSubmissionSupplier
56
58 ,public OControlModel
60 {
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
65
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
71 bool m_bDispatchUrlInternal; // property: is not allowed to set : 1
73
74 // XSubmission stuff
75 css::uno::Reference< css::form::submission::XSubmission >
77
78 DECL_LINK( DownloadDoneLink, void*, void );
79
81
82 void StartProduction();
83 void SetURL(const OUString& rURL);
84 void DataAvailable();
85
86 css::uno::Sequence< css::uno::Type> _getTypes() override;
88 void setDispatchUrlInternal(bool _bDispatch) { m_bDispatchUrlInternal = _bDispatch; }
89
90 public:
92 const css::uno::Reference< css::uno::XComponentContext>& _rxFactory,
93 const OUString& _rUnoControlModelTypeName,
94 const OUString& _rDefault
95 );
96
98 const OClickableImageBaseModel* _pOriginal,
99 const css::uno::Reference< css::uno::XComponentContext>& _rxFactory
100 );
101
102 virtual ~OClickableImageBaseModel() override;
103
104 // UNO Binding
106 virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type& _rType) override;
107
108 protected:
109 // OComponentHelper
110 virtual void SAL_CALL disposing() override;
111
112 // css::form::XImageProducerSupplier
113 virtual css::uno::Reference< css::awt::XImageProducer> SAL_CALL getImageProducer() override { return m_xProducer; }
114
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;
118
119 virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any& rConvertedValue, css::uno::Any& rOldValue, sal_Int32 nHandle, const css::uno::Any& rValue ) override;
120
121 using ::cppu::OPropertySetHelper::getFastPropertyValue;
122
123 // OPropertyChangeListener
124 virtual void _propertyChanged(const css::beans::PropertyChangeEvent&) override;
125
126 // XPropertyState
127 virtual css::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const override;
128
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;
133
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;
137
138 // XServiceInfo
139 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
140
141 // XEventListener
143
144 public:
145 struct GuardAccess { friend class ImageModelMethodGuard; private: GuardAccess() { } };
146 ::osl::Mutex& getMutex( GuardAccess ) { return m_aMutex; }
148
149 protected:
151
152 void implConstruct();
153
154 // to be called from within the cloning-ctor of your derived class
156
158
159 DECL_LINK( OnImageImportDone, ::Graphic*, void );
160 };
161
162 class ImageModelMethodGuard : public ::osl::MutexGuard
163 {
164 public:
166 : ::osl::MutexGuard( _rModel.getMutex( OClickableImageBaseModel::GuardAccess() ) )
167 {
168 if ( nullptr == _rModel.getImageProducer( OClickableImageBaseModel::GuardAccess() ) )
169 throw css::lang::DisposedException(
170 OUString(),
171 static_cast< css::form::XImageProducerSupplier* >( &_rModel )
172 );
173 }
174 };
175
176
177 // OClickableImageBaseControl
178
179 typedef ::cppu::ImplHelper3 < css::form::XApproveActionBroadcaster
180 , css::form::submission::XSubmission
181 , css::frame::XDispatchProviderInterception
183
185 ,public OControl
186 {
188
189 private:
194
195 protected:
199
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;
205
206 // XServiceInfo
207 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
208
209 // XEventListener
211
212 public:
214 const css::uno::Reference< css::uno::XComponentContext>& _rxFactory,
215 const OUString& _aService);
216 virtual ~OClickableImageBaseControl() override;
217
218 protected:
219 // UNO Binding
221 virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type& _rType) override;
222
223 // OComponentHelper
224 virtual void SAL_CALL disposing() override;
225
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;
229
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;
233
234 protected:
235 virtual void actionPerformed_Impl( bool bNotifyListener, const css::awt::MouseEvent& rEvt );
236
237 css::uno::Sequence< css::uno::Type > _getTypes() override;
238
242 bool approveAction( );
243
249
250 private:
251 void implSubmit(
252 const css::awt::MouseEvent& _rEvent,
253 const css::uno::Reference< css::task::XInteractionHandler >& aHandler
254 );
255 };
256
258 {
259 protected:
260
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;
267
268 public:
270 OComponentEventThread( pControl )
271 {}
272
273 void addEvent() { OComponentEventThread::addEvent( std::make_unique<css::lang::EventObject>() ); }
274
275 protected:
277 };
278
279
280} // namespace frm
281
282/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
helper class for controls which allow some of their features to be intercepted by external instances
ImageModelMethodGuard(OClickableImageBaseModel &_rModel)
void implSubmit(const css::awt::MouseEvent &_rEvent, const css::uno::Reference< css::task::XInteractionHandler > &aHandler)
virtual void SAL_CALL addSubmissionVetoListener(const css::uno::Reference< css::form::submission::XSubmissionVetoListener > &listener) override
OClickableImageBaseControl(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory, const OUString &_aService)
virtual void SAL_CALL submit() override
virtual void SAL_CALL removeSubmissionVetoListener(const css::uno::Reference< css::form::submission::XSubmissionVetoListener > &listener) override
::comphelper::OInterfaceContainerHelper3< css::form::submission::XSubmissionVetoListener > m_aSubmissionVetoListeners
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
virtual void SAL_CALL addApproveActionListener(const css::uno::Reference< css::form::XApproveActionListener > &_rxListener) override
bool approveAction()
approves the action by calling the approve listeners
virtual void SAL_CALL releaseDispatchProviderInterceptor(const css::uno::Reference< css::frame::XDispatchProviderInterceptor > &Interceptor) override
OImageProducerThread_Impl * getImageProducerThread()
retrieves (and if necessary creates) the image producer thread.
virtual void SAL_CALL submitWithInteraction(const css::uno::Reference< css::task::XInteractionHandler > &aHandler) override
virtual void actionPerformed_Impl(bool bNotifyListener, const css::awt::MouseEvent &rEvt)
virtual ~OClickableImageBaseControl() override
virtual void SAL_CALL removeApproveActionListener(const css::uno::Reference< css::form::XApproveActionListener > &_rxListener) override
rtl::Reference< OImageProducerThread_Impl > m_pThread
::comphelper::OInterfaceContainerHelper3< css::awt::XActionListener > m_aActionListeners
::comphelper::OInterfaceContainerHelper3< css::form::XApproveActionListener > m_aApproveActionListeners
css::uno::Sequence< css::uno::Type > _getTypes() override
virtual void SAL_CALL registerDispatchProviderInterceptor(const css::uno::Reference< css::frame::XDispatchProviderInterceptor > &Interceptor) override
virtual void SAL_CALL disposing() override
ControlFeatureInterception m_aFeatureInterception
virtual css::uno::Reference< css::awt::XImageProducer > SAL_CALL getImageProducer() override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual css::uno::Any getPropertyDefaultByHandle(sal_Int32 nHandle) const override
ImageProducer * GetImageProducer()
virtual void SAL_CALL startProduction() override
OClickableImageBaseModel(const OClickableImageBaseModel *_pOriginal, const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
std::unique_ptr< SfxMedium > m_pMedium
void SetURL(const OUString &rURL)
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
ImageProducer * getImageProducer(GuardAccess)
virtual void SAL_CALL removeConsumer(const css::uno::Reference< css::awt::XImageConsumer > &xConsumer) override
css::form::FormButtonType m_eButtonType
DECL_LINK(DownloadDoneLink, void *, void)
virtual void SAL_CALL setSubmission(const css::uno::Reference< css::form::submission::XSubmission > &_submission) override
virtual void SAL_CALL addConsumer(const css::uno::Reference< css::awt::XImageConsumer > &xConsumer) override
virtual void SAL_CALL disposing() override
css::uno::Reference< css::graphic::XGraphicObject > m_xGraphicObject
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
SfxObjectShell * GetObjectShell()
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual css::uno::Reference< css::form::submission::XSubmission > SAL_CALL getSubmission() override
rtl::Reference< ImageProducer > m_xProducer
DECL_LINK(OnImageImportDone, ::Graphic *, void)
css::uno::Reference< css::form::submission::XSubmission > m_xSubmissionDelegate
virtual void _propertyChanged(const css::beans::PropertyChangeEvent &) override
OClickableImageBaseModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory, const OUString &_rUnoControlModelTypeName, const OUString &_rDefault)
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
::osl::Mutex & getMutex(GuardAccess)
css::uno::Sequence< css::uno::Type > _getTypes() override
virtual ~OClickableImageBaseModel() override
void setDispatchUrlInternal(bool _bDispatch)
void addEvent(std::unique_ptr< css::lang::EventObject > _pEvt)
virtual ::osl::Mutex & getMutex() override
::osl::Mutex m_aMutex
virtual void SAL_CALL disposing() override
virtual void SAL_CALL disposing() override
virtual void processEvent(::cppu::OComponentHelper *pCompImpl, const css::lang::EventObject *, const css::uno::Reference< css::awt::XControl > &, bool) override
OImageProducerThread_Impl(OClickableImageBaseControl *pControl)
::osl::Mutex & getMutex()
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
::cppu::ImplHelper3< css::form::XApproveActionBroadcaster, css::form::submission::XSubmission, css::frame::XDispatchProviderInterception > OClickableImageBaseControl_BASE
::cppu::ImplHelper3< css::form::XImageProducerSupplier, css::awt::XImageProducer, css::form::submission::XSubmissionSupplier > OClickableImageBaseModel_Base
unsigned char sal_Bool
#define DECLARE_UNO3_AGG_DEFAULTS(classname, baseclass)