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 .
20 #include <sal/config.h>
22 #include "submissionhandler.hxx"
23 #include "formmetadata.hxx"
24 #include "formstrings.hxx"
25 #include "handlerhelper.hxx"
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>
32 #include <comphelper/diagnose_ex.hxx>
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::form
;
45 using namespace ::com::sun::star::xforms
;
46 using namespace ::com::sun::star::inspection
;
52 SubmissionHelper::SubmissionHelper( ::osl::Mutex
& _rMutex
, const Reference
< XPropertySet
>& _rxIntrospectee
, const Reference
< frame::XModel
>& _rxContextDocument
)
53 :EFormsHelper( _rMutex
, _rxIntrospectee
, _rxContextDocument
)
55 OSL_ENSURE( canTriggerSubmissions( _rxIntrospectee
, _rxContextDocument
),
56 "SubmissionHelper::SubmissionHelper: you should not have instantiated me!" );
60 bool SubmissionHelper::canTriggerSubmissions( const Reference
< XPropertySet
>& _rxControlModel
,
61 const Reference
< frame::XModel
>& _rxContextDocument
)
63 if ( !EFormsHelper::isEForm( _rxContextDocument
) )
68 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( _rxControlModel
, UNO_QUERY
);
69 if ( xSubmissionSupp
.is() )
72 catch( const Exception
& )
74 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "SubmissionHelper::canTriggerSubmissions" );
80 //= SubmissionPropertyHandler
83 SubmissionPropertyHandler::SubmissionPropertyHandler( const Reference
< XComponentContext
>& _rxContext
)
84 :PropertyHandlerComponent( _rxContext
)
85 ,OPropertyChangeListener()
90 SubmissionPropertyHandler::~SubmissionPropertyHandler( )
96 OUString
SubmissionPropertyHandler::getImplementationName( )
98 return u
"com.sun.star.comp.extensions.SubmissionPropertyHandler"_ustr
;
102 Sequence
< OUString
> SubmissionPropertyHandler::getSupportedServiceNames( )
104 return { u
"com.sun.star.form.inspection.SubmissionPropertyHandler"_ustr
};
108 Any SAL_CALL
SubmissionPropertyHandler::getPropertyValue( const OUString
& _rPropertyName
)
110 ::osl::MutexGuard
aGuard( m_aMutex
);
111 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
113 OSL_ENSURE(m_pHelper
, "SubmissionPropertyHandler::getPropertyValue: inconsistency!");
114 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
121 case PROPERTY_ID_SUBMISSION_ID
:
123 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( m_xComponent
, UNO_QUERY
);
124 OSL_ENSURE( xSubmissionSupp
.is(), "SubmissionPropertyHandler::getPropertyValue: this should never happen ..." );
125 // this handler is not intended for components which are no XSubmissionSupplier
126 Reference
< submission::XSubmission
> xSubmission
;
127 if ( xSubmissionSupp
.is() )
128 xSubmission
= xSubmissionSupp
->getSubmission( );
129 aReturn
<<= xSubmission
;
133 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
135 FormButtonType eType
= FormButtonType_PUSH
;
136 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_BUTTONTYPE
) >>= eType
);
137 if ( ( eType
!= FormButtonType_PUSH
) && ( eType
!= FormButtonType_SUBMIT
) )
138 eType
= FormButtonType_PUSH
;
144 OSL_FAIL( "SubmissionPropertyHandler::getPropertyValue: cannot handle this property!" );
148 catch( const Exception
& )
150 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "SubmissionPropertyHandler::getPropertyValue" );
157 void SAL_CALL
SubmissionPropertyHandler::setPropertyValue( const OUString
& _rPropertyName
, const Any
& _rValue
)
159 ::osl::MutexGuard
aGuard( m_aMutex
);
160 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
162 OSL_ENSURE(m_pHelper
, "SubmissionPropertyHandler::setPropertyValue: inconsistency!");
163 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
169 case PROPERTY_ID_SUBMISSION_ID
:
171 Reference
< submission::XSubmission
> xSubmission
;
172 OSL_VERIFY( _rValue
>>= xSubmission
);
174 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( m_xComponent
, UNO_QUERY
);
175 OSL_ENSURE( xSubmissionSupp
.is(), "SubmissionPropertyHandler::setPropertyValue: this should never happen ..." );
176 // this handler is not intended for components which are no XSubmissionSupplier
177 if ( xSubmissionSupp
.is() )
179 xSubmissionSupp
->setSubmission( xSubmission
);
180 impl_setContextDocumentModified_nothrow();
185 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
186 m_xComponent
->setPropertyValue( PROPERTY_BUTTONTYPE
, _rValue
);
190 OSL_FAIL( "SubmissionPropertyHandler::setPropertyValue: cannot handle this id!" );
193 catch( const Exception
& )
195 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "SubmissionPropertyHandler::setPropertyValue" );
200 Sequence
< OUString
> SAL_CALL
SubmissionPropertyHandler::getActuatingProperties( )
202 ::osl::MutexGuard
aGuard( m_aMutex
);
204 return Sequence
< OUString
>();
206 Sequence
<OUString
> aReturn
{ PROPERTY_XFORMS_BUTTONTYPE
};
211 Sequence
< OUString
> SAL_CALL
SubmissionPropertyHandler::getSupersededProperties( )
213 ::osl::MutexGuard
aGuard( m_aMutex
);
215 return Sequence
< OUString
>();
217 Sequence
< OUString
> aReturn
{ PROPERTY_TARGET_URL
,
218 PROPERTY_TARGET_FRAME
,
219 PROPERTY_BUTTONTYPE
};
224 void SubmissionPropertyHandler::onNewComponent()
226 if ( m_xPropChangeMultiplexer
.is() )
228 m_xPropChangeMultiplexer
->dispose();
229 m_xPropChangeMultiplexer
.clear();
232 PropertyHandlerComponent::onNewComponent();
234 Reference
< frame::XModel
> xDocument( impl_getContextDocument_nothrow() );
235 DBG_ASSERT( xDocument
.is(), "SubmissionPropertyHandler::onNewComponent: no document!" );
239 if ( SubmissionHelper::canTriggerSubmissions( m_xComponent
, xDocument
) )
241 m_pHelper
.reset( new SubmissionHelper( m_aMutex
, m_xComponent
, xDocument
) );
243 m_xPropChangeMultiplexer
= new OPropertyChangeMultiplexer( this, m_xComponent
);
244 m_xPropChangeMultiplexer
->addProperty( PROPERTY_BUTTONTYPE
);
249 Sequence
< Property
> SubmissionPropertyHandler::doDescribeSupportedProperties() const
251 std::vector
< Property
> aProperties
;
254 implAddPropertyDescription( aProperties
, PROPERTY_SUBMISSION_ID
, cppu::UnoType
<submission::XSubmission
>::get() );
255 implAddPropertyDescription( aProperties
, PROPERTY_XFORMS_BUTTONTYPE
, ::cppu::UnoType
<FormButtonType
>::get() );
257 if ( aProperties
.empty() )
258 return Sequence
< Property
>();
259 return comphelper::containerToSequence(aProperties
);
263 LineDescriptor SAL_CALL
SubmissionPropertyHandler::describePropertyLine( const OUString
& _rPropertyName
,
264 const Reference
< XPropertyControlFactory
>& _rxControlFactory
)
266 ::osl::MutexGuard
aGuard( m_aMutex
);
267 if ( !_rxControlFactory
.is() )
268 throw NullPointerException();
270 throw RuntimeException();
272 std::vector
< OUString
> aListEntries
;
273 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
276 case PROPERTY_ID_SUBMISSION_ID
:
277 m_pHelper
->getAllElementUINames(EFormsHelper::Submission
, aListEntries
, false);
280 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
282 // available options are nearly the same as for the "normal" button type, but only the
284 aListEntries
= m_pInfoService
->getPropertyEnumRepresentations( PROPERTY_ID_BUTTONTYPE
);
285 aListEntries
.resize( 2 );
290 OSL_FAIL( "SubmissionPropertyHandler::describePropertyLine: cannot handle this id!" );
291 return LineDescriptor();
294 LineDescriptor aDescriptor
;
295 aDescriptor
.Control
= PropertyHandlerHelper::createListBoxControl( _rxControlFactory
, std::move(aListEntries
), false, true );
296 aDescriptor
.DisplayName
= m_pInfoService
->getPropertyTranslation( nPropId
);
297 aDescriptor
.Category
= "General";
298 aDescriptor
.HelpURL
= HelpIdUrl::getHelpURL( m_pInfoService
->getPropertyHelpId( nPropId
) );
303 void SAL_CALL
SubmissionPropertyHandler::actuatingPropertyChanged( const OUString
& _rActuatingPropertyName
, const Any
& _rNewValue
, const Any
& /*_rOldValue*/, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool
)
305 if ( !_rxInspectorUI
.is() )
306 throw NullPointerException();
308 ::osl::MutexGuard
aGuard( m_aMutex
);
309 PropertyId
nActuatingPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName
) );
310 OSL_PRECOND(m_pHelper
,
311 "SubmissionPropertyHandler::actuatingPropertyChanged: inconsistency!");
312 // if we survived impl_getPropertyId_throwRuntime, we should have a helper, since no helper implies no properties
314 switch ( nActuatingPropId
)
316 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
318 FormButtonType eType
= FormButtonType_PUSH
;
319 OSL_VERIFY( _rNewValue
>>= eType
);
320 _rxInspectorUI
->enablePropertyUI( PROPERTY_SUBMISSION_ID
, eType
== FormButtonType_SUBMIT
);
325 OSL_FAIL( "SubmissionPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
330 Any SAL_CALL
SubmissionPropertyHandler::convertToPropertyValue( const OUString
& _rPropertyName
, const Any
& _rControlValue
)
332 ::osl::MutexGuard
aGuard( m_aMutex
);
337 "SubmissionPropertyHandler::convertToPropertyValue: we have no SupportedProperties!");
339 return aPropertyValue
;
341 OUString sControlValue
;
342 OSL_VERIFY( _rControlValue
>>= sControlValue
);
344 PropertyId
nPropId( m_pInfoService
->getPropertyId( _rPropertyName
) );
347 case PROPERTY_ID_SUBMISSION_ID
:
349 Reference
< XSubmission
> xSubmission( m_pHelper
->getModelElementFromUIName( EFormsHelper::Submission
, sControlValue
), UNO_QUERY
);
350 aPropertyValue
<<= xSubmission
;
354 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
356 ::rtl::Reference
< IPropertyEnumRepresentation
> aEnumConversion(
357 new DefaultEnumRepresentation( *m_pInfoService
, ::cppu::UnoType
<FormButtonType
>::get(), PROPERTY_ID_BUTTONTYPE
) );
358 // TODO/UNOize: make aEnumConversion a member?
359 aEnumConversion
->getValueFromDescription( sControlValue
, aPropertyValue
);
364 OSL_FAIL( "SubmissionPropertyHandler::convertToPropertyValue: cannot handle this id!" );
367 return aPropertyValue
;
371 Any SAL_CALL
SubmissionPropertyHandler::convertToControlValue( const OUString
& _rPropertyName
, const Any
& _rPropertyValue
, const Type
& _rControlValueType
)
373 ::osl::MutexGuard
aGuard( m_aMutex
);
378 "SubmissionPropertyHandler::convertToControlValue: we have no SupportedProperties!");
380 return aControlValue
;
382 OSL_ENSURE( _rControlValueType
.getTypeClass() == TypeClass_STRING
,
383 "SubmissionPropertyHandler::convertToControlValue: all our controls should use strings for value exchange!" );
385 PropertyId
nPropId( m_pInfoService
->getPropertyId( _rPropertyName
) );
388 case PROPERTY_ID_SUBMISSION_ID
:
390 Reference
< XPropertySet
> xSubmission( _rPropertyValue
, UNO_QUERY
);
391 if ( xSubmission
.is() )
392 aControlValue
<<= EFormsHelper::getModelElementUIName( EFormsHelper::Submission
, xSubmission
);
396 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
398 ::rtl::Reference
< IPropertyEnumRepresentation
> aEnumConversion(
399 new DefaultEnumRepresentation( *m_pInfoService
, _rPropertyValue
.getValueType(), PROPERTY_ID_BUTTONTYPE
) );
400 // TODO/UNOize: make aEnumConversion a member?
401 aControlValue
<<= aEnumConversion
->getDescriptionForValue( _rPropertyValue
);
406 OSL_FAIL( "SubmissionPropertyHandler::convertToControlValue: cannot handle this id!" );
409 return aControlValue
;
413 void SubmissionPropertyHandler::_propertyChanged( const PropertyChangeEvent
& _rEvent
)
415 if ( _rEvent
.PropertyName
== PROPERTY_BUTTONTYPE
)
416 firePropertyChange( PROPERTY_XFORMS_BUTTONTYPE
, PROPERTY_ID_XFORMS_BUTTONTYPE
, _rEvent
.OldValue
, _rEvent
.NewValue
);
422 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
423 extensions_propctrlr_SubmissionPropertyHandler_get_implementation(
424 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
426 return cppu::acquire(new pcr::SubmissionPropertyHandler(context
));
429 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */