LibreOffice Module extensions (master) 1
submissionhandler.cxx
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#include <sal/config.h>
21
22#include "submissionhandler.hxx"
23#include "formmetadata.hxx"
24#include "formstrings.hxx"
25#include "handlerhelper.hxx"
26
27#include <com/sun/star/form/FormButtonType.hpp>
28#include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
29#include <com/sun/star/inspection/XObjectInspectorUI.hpp>
30#include <com/sun/star/lang/NullPointerException.hpp>
31#include <tools/debug.hxx>
33
34
35namespace pcr
36{
37
38
39 using namespace ::comphelper;
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::script;
45 using namespace ::com::sun::star::form;
46 using namespace ::com::sun::star::xforms;
47 using namespace ::com::sun::star::container;
48 using namespace ::com::sun::star::inspection;
49
50
51 //= SubmissionHelper
52
53
54 SubmissionHelper::SubmissionHelper( ::osl::Mutex& _rMutex, const Reference< XPropertySet >& _rxIntrospectee, const Reference< frame::XModel >& _rxContextDocument )
55 :EFormsHelper( _rMutex, _rxIntrospectee, _rxContextDocument )
56 {
57 OSL_ENSURE( canTriggerSubmissions( _rxIntrospectee, _rxContextDocument ),
58 "SubmissionHelper::SubmissionHelper: you should not have instantiated me!" );
59 }
60
61
62 bool SubmissionHelper::canTriggerSubmissions( const Reference< XPropertySet >& _rxControlModel,
63 const Reference< frame::XModel >& _rxContextDocument )
64 {
65 if ( !EFormsHelper::isEForm( _rxContextDocument ) )
66 return false;
67
68 try
69 {
70 Reference< submission::XSubmissionSupplier > xSubmissionSupp( _rxControlModel, UNO_QUERY );
71 if ( xSubmissionSupp.is() )
72 return true;
73 }
74 catch( const Exception& )
75 {
76 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "SubmissionHelper::canTriggerSubmissions" );
77 }
78 return false;
79 }
80
81
82 //= SubmissionPropertyHandler
83
84
85 SubmissionPropertyHandler::SubmissionPropertyHandler( const Reference< XComponentContext >& _rxContext )
86 :PropertyHandlerComponent( _rxContext )
87 ,OPropertyChangeListener( m_aMutex )
88 {
89 }
90
91
93 {
95 }
96
97
99 {
100 return "com.sun.star.comp.extensions.SubmissionPropertyHandler";
101 }
102
103
105 {
106 return { "com.sun.star.form.inspection.SubmissionPropertyHandler" };
107 }
108
109
110 Any SAL_CALL SubmissionPropertyHandler::getPropertyValue( const OUString& _rPropertyName )
111 {
112 ::osl::MutexGuard aGuard( m_aMutex );
113 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
114
115 OSL_ENSURE(m_pHelper, "SubmissionPropertyHandler::getPropertyValue: inconsistency!");
116 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
117
118 Any aReturn;
119 try
120 {
121 switch ( nPropId )
122 {
124 {
125 Reference< submission::XSubmissionSupplier > xSubmissionSupp( m_xComponent, UNO_QUERY );
126 OSL_ENSURE( xSubmissionSupp.is(), "SubmissionPropertyHandler::getPropertyValue: this should never happen ..." );
127 // this handler is not intended for components which are no XSubmissionSupplier
128 Reference< submission::XSubmission > xSubmission;
129 if ( xSubmissionSupp.is() )
130 xSubmission = xSubmissionSupp->getSubmission( );
131 aReturn <<= xSubmission;
132 }
133 break;
134
136 {
137 FormButtonType eType = FormButtonType_PUSH;
138 OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_BUTTONTYPE ) >>= eType );
139 if ( ( eType != FormButtonType_PUSH ) && ( eType != FormButtonType_SUBMIT ) )
140 eType = FormButtonType_PUSH;
141 aReturn <<= eType;
142 }
143 break;
144
145 default:
146 OSL_FAIL( "SubmissionPropertyHandler::getPropertyValue: cannot handle this property!" );
147 break;
148 }
149 }
150 catch( const Exception& )
151 {
152 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "SubmissionPropertyHandler::getPropertyValue" );
153 }
154
155 return aReturn;
156 }
157
158
159 void SAL_CALL SubmissionPropertyHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue )
160 {
161 ::osl::MutexGuard aGuard( m_aMutex );
162 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
163
164 OSL_ENSURE(m_pHelper, "SubmissionPropertyHandler::setPropertyValue: inconsistency!");
165 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
166
167 try
168 {
169 switch ( nPropId )
170 {
172 {
173 Reference< submission::XSubmission > xSubmission;
174 OSL_VERIFY( _rValue >>= xSubmission );
175
176 Reference< submission::XSubmissionSupplier > xSubmissionSupp( m_xComponent, UNO_QUERY );
177 OSL_ENSURE( xSubmissionSupp.is(), "SubmissionPropertyHandler::setPropertyValue: this should never happen ..." );
178 // this handler is not intended for components which are no XSubmissionSupplier
179 if ( xSubmissionSupp.is() )
180 {
181 xSubmissionSupp->setSubmission( xSubmission );
183 }
184 }
185 break;
186
188 m_xComponent->setPropertyValue( PROPERTY_BUTTONTYPE, _rValue );
189 break;
190
191 default:
192 OSL_FAIL( "SubmissionPropertyHandler::setPropertyValue: cannot handle this id!" );
193 }
194 }
195 catch( const Exception& )
196 {
197 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "SubmissionPropertyHandler::setPropertyValue" );
198 }
199 }
200
201
203 {
204 ::osl::MutexGuard aGuard( m_aMutex );
205 if (!m_pHelper)
206 return Sequence< OUString >();
207
208 Sequence<OUString> aReturn { PROPERTY_XFORMS_BUTTONTYPE };
209 return aReturn;
210 }
211
212
214 {
215 ::osl::MutexGuard aGuard( m_aMutex );
216 if (!m_pHelper)
217 return Sequence< OUString >();
218
219 Sequence< OUString > aReturn{ PROPERTY_TARGET_URL,
222 return aReturn;
223 }
224
225
227 {
228 if ( m_xPropChangeMultiplexer.is() )
229 {
230 m_xPropChangeMultiplexer->dispose();
232 }
233
235
236 Reference< frame::XModel > xDocument( impl_getContextDocument_nothrow() );
237 DBG_ASSERT( xDocument.is(), "SubmissionPropertyHandler::onNewComponent: no document!" );
238
239 m_pHelper.reset();
240
242 {
243 m_pHelper.reset( new SubmissionHelper( m_aMutex, m_xComponent, xDocument ) );
244
247 }
248 }
249
250
252 {
253 std::vector< Property > aProperties;
254 if (m_pHelper)
255 {
258 }
259 if ( aProperties.empty() )
260 return Sequence< Property >();
262 }
263
264
265 LineDescriptor SAL_CALL SubmissionPropertyHandler::describePropertyLine( const OUString& _rPropertyName,
266 const Reference< XPropertyControlFactory >& _rxControlFactory )
267 {
268 ::osl::MutexGuard aGuard( m_aMutex );
269 if ( !_rxControlFactory.is() )
270 throw NullPointerException();
271 if (!m_pHelper)
272 throw RuntimeException();
273
274 std::vector< OUString > aListEntries;
275 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
276 switch ( nPropId )
277 {
279 m_pHelper->getAllElementUINames(EFormsHelper::Submission, aListEntries, false);
280 break;
281
283 {
284 // available options are nearly the same as for the "normal" button type, but only the
285 // first two options
286 aListEntries = m_pInfoService->getPropertyEnumRepresentations( PROPERTY_ID_BUTTONTYPE );
287 aListEntries.resize( 2 );
288 }
289 break;
290
291 default:
292 OSL_FAIL( "SubmissionPropertyHandler::describePropertyLine: cannot handle this id!" );
293 return LineDescriptor();
294 }
295
296 LineDescriptor aDescriptor;
297 aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory, std::move(aListEntries), false, true );
298 aDescriptor.DisplayName = m_pInfoService->getPropertyTranslation( nPropId );
299 aDescriptor.Category = "General";
300 aDescriptor.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nPropId ) );
301 return aDescriptor;
302 }
303
304
305 void SAL_CALL SubmissionPropertyHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool )
306 {
307 if ( !_rxInspectorUI.is() )
308 throw NullPointerException();
309
310 ::osl::MutexGuard aGuard( m_aMutex );
311 PropertyId nActuatingPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName ) );
312 OSL_PRECOND(m_pHelper,
313 "SubmissionPropertyHandler::actuatingPropertyChanged: inconsistency!");
314 // if we survived impl_getPropertyId_throwRuntime, we should have a helper, since no helper implies no properties
315
316 switch ( nActuatingPropId )
317 {
319 {
320 FormButtonType eType = FormButtonType_PUSH;
321 OSL_VERIFY( _rNewValue >>= eType );
322 _rxInspectorUI->enablePropertyUI( PROPERTY_SUBMISSION_ID, eType == FormButtonType_SUBMIT );
323 }
324 break;
325
326 default:
327 OSL_FAIL( "SubmissionPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
328 }
329 }
330
331
332 Any SAL_CALL SubmissionPropertyHandler::convertToPropertyValue( const OUString& _rPropertyName, const Any& _rControlValue )
333 {
334 ::osl::MutexGuard aGuard( m_aMutex );
335 Any aPropertyValue;
336
337 OSL_ENSURE(
338 m_pHelper,
339 "SubmissionPropertyHandler::convertToPropertyValue: we have no SupportedProperties!");
340 if (!m_pHelper)
341 return aPropertyValue;
342
343 OUString sControlValue;
344 OSL_VERIFY( _rControlValue >>= sControlValue );
345
346 PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
347 switch ( nPropId )
348 {
350 {
351 Reference< XSubmission > xSubmission( m_pHelper->getModelElementFromUIName( EFormsHelper::Submission, sControlValue ), UNO_QUERY );
352 aPropertyValue <<= xSubmission;
353 }
354 break;
355
357 {
360 // TODO/UNOize: make aEnumConversion a member?
361 aEnumConversion->getValueFromDescription( sControlValue, aPropertyValue );
362 }
363 break;
364
365 default:
366 OSL_FAIL( "SubmissionPropertyHandler::convertToPropertyValue: cannot handle this id!" );
367 }
368
369 return aPropertyValue;
370 }
371
372
373 Any SAL_CALL SubmissionPropertyHandler::convertToControlValue( const OUString& _rPropertyName, const Any& _rPropertyValue, const Type& _rControlValueType )
374 {
375 ::osl::MutexGuard aGuard( m_aMutex );
376 Any aControlValue;
377
378 OSL_ENSURE(
379 m_pHelper,
380 "SubmissionPropertyHandler::convertToControlValue: we have no SupportedProperties!");
381 if (!m_pHelper)
382 return aControlValue;
383
384 OSL_ENSURE( _rControlValueType.getTypeClass() == TypeClass_STRING,
385 "SubmissionPropertyHandler::convertToControlValue: all our controls should use strings for value exchange!" );
386
387 PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
388 switch ( nPropId )
389 {
391 {
392 Reference< XPropertySet > xSubmission( _rPropertyValue, UNO_QUERY );
393 if ( xSubmission.is() )
394 aControlValue <<= EFormsHelper::getModelElementUIName( EFormsHelper::Submission, xSubmission );
395 }
396 break;
397
399 {
401 new DefaultEnumRepresentation( *m_pInfoService, _rPropertyValue.getValueType(), PROPERTY_ID_BUTTONTYPE ) );
402 // TODO/UNOize: make aEnumConversion a member?
403 aControlValue <<= aEnumConversion->getDescriptionForValue( _rPropertyValue );
404 }
405 break;
406
407 default:
408 OSL_FAIL( "SubmissionPropertyHandler::convertToControlValue: cannot handle this id!" );
409 }
410
411 return aControlValue;
412 }
413
414
415 void SubmissionPropertyHandler::_propertyChanged( const PropertyChangeEvent& _rEvent )
416 {
417 if ( _rEvent.PropertyName == PROPERTY_BUTTONTYPE )
419 }
420
421
422} // namespace pcr
423
424extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
426 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
427{
428 return cppu::acquire(new pcr::SubmissionPropertyHandler(context));
429}
430
431/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
friend friend class OPropertyChangeMultiplexer
mutable::osl::Mutex m_aMutex
an implementation of the IPropertyEnumRepresentation
static OUString getModelElementUIName(const ModelElementType _eType, const css::uno::Reference< css::beans::XPropertySet > &_rxElement)
retrieves the name of a model's sub-element, as to be shown in the UI
static bool isEForm(const css::uno::Reference< css::frame::XModel > &_rxContextDocument)
determines whether the given document is an eForm
static OUString getHelpURL(std::u16string_view)
Definition: pcrcommon.cxx:47
PropertyHandler implementation which additionally supports XServiceInfo.
static css::uno::Reference< css::inspection::XPropertyControl > createListBoxControl(const css::uno::Reference< css::inspection::XPropertyControlFactory > &_rxControlFactory, std::vector< OUString > &&_rInitialListEntries, bool _bReadOnlyControl, bool _bSorted)
creates an <member scope="css::inspection">PropertyControlType::ListBox</member>-type control and fil...
std::unique_ptr< OPropertyInfoService > m_pInfoService
access to property meta data
virtual void onNewComponent()
called when XPropertyHandler::inspect has been called, and we thus have a new component to inspect
void firePropertyChange(const OUString &_rPropName, PropertyId _nPropId, const css::uno::Any &_rOldValue, const css::uno::Any &_rNewValue)
fires the change in a property value to our listener (if any)
PropertyId impl_getPropertyId_throwUnknownProperty(const OUString &_rPropertyName) const
retrieves the property id for a given property name
css::uno::Reference< css::beans::XPropertySet > m_xComponent
the component we're inspecting
PropertyId impl_getPropertyId_throwRuntime(const OUString &_rPropertyName) const
retrieves the property id for a given property name
void impl_setContextDocumentModified_nothrow() const
marks the context document as modified
css::uno::Reference< css::frame::XModel > impl_getContextDocument_nothrow() const
returns the value of the ContextDocument property in the ComponentContext which was used to create th...
void implAddPropertyDescription(std::vector< css::beans::Property > &_rProperties, const OUString &_rPropertyName, const css::uno::Type &_rType, sal_Int16 _nAttribs=0) const
adds a Property, given by name only, to a given vector of Properties
SubmissionHelper(osl::Mutex &_rMutex, const css::uno::Reference< css::beans::XPropertySet > &_rxIntrospectee, const css::uno::Reference< css::frame::XModel > &_rxContextDocument)
static bool canTriggerSubmissions(const css::uno::Reference< css::beans::XPropertySet > &_rxControlModel, const css::uno::Reference< css::frame::XModel > &_rxContextDocument)
determines whether the given control model is able to trigger submissions
a property handler for any virtual string properties
virtual css::uno::Sequence< css::beans::Property > doDescribeSupportedProperties() const override
virtual css::uno::Any SAL_CALL convertToControlValue(const OUString &_rPropertyName, const css::uno::Any &_rPropertyValue, const css::uno::Type &_rControlValueType) override
virtual css::uno::Any SAL_CALL convertToPropertyValue(const OUString &_rPropertyName, const css::uno::Any &_rControlValue) override
SubmissionPropertyHandler(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
rtl::Reference<::comphelper::OPropertyChangeMultiplexer > m_xPropChangeMultiplexer
virtual void SAL_CALL setPropertyValue(const OUString &_rPropertyName, const css::uno::Any &_rValue) override
std::unique_ptr< SubmissionHelper > m_pHelper
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &_rPropertyName) override
virtual void SAL_CALL actuatingPropertyChanged(const OUString &_rActuatingPropertyName, const css::uno::Any &_rNewValue, const css::uno::Any &_rOldValue, const css::uno::Reference< css::inspection::XObjectInspectorUI > &_rxInspectorUI, sal_Bool) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual ~SubmissionPropertyHandler() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupersededProperties() override
virtual css::uno::Sequence< OUString > SAL_CALL getActuatingProperties() override
virtual void _propertyChanged(const css::beans::PropertyChangeEvent &_rEvent) override
virtual void onNewComponent() override
called when XPropertyHandler::inspect has been called, and we thus have a new component to inspect
virtual css::inspection::LineDescriptor SAL_CALL describePropertyLine(const OUString &_rPropertyName, const css::uno::Reference< css::inspection::XPropertyControlFactory > &_rxControlFactory) override
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
DocumentType eType
#define PROPERTY_ID_SUBMISSION_ID
#define PROPERTY_ID_XFORMS_BUTTONTYPE
#define PROPERTY_ID_BUTTONTYPE
constexpr OUStringLiteral PROPERTY_TARGET_URL
Definition: formstrings.hxx:51
constexpr OUStringLiteral PROPERTY_TARGET_FRAME
Definition: formstrings.hxx:52
constexpr OUStringLiteral PROPERTY_BUTTONTYPE
Definition: formstrings.hxx:58
constexpr OUStringLiteral PROPERTY_XFORMS_BUTTONTYPE
Definition: formstrings.hxx:59
constexpr OUStringLiteral PROPERTY_SUBMISSION_ID
::osl::Mutex m_aMutex
Definition: logger.cxx:98
@ Exception
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Type
a property handler for any virtual string properties
Definition: browserline.cxx:39
sal_Int32 PropertyId
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_propctrlr_SubmissionPropertyHandler_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
unsigned char sal_Bool