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 "pcrservices.hxx"
23 #include "submissionhandler.hxx"
24 #include "formmetadata.hxx"
25 #include "formstrings.hxx"
26 #include "handlerhelper.hxx"
28 #include <com/sun/star/form/FormButtonType.hpp>
29 #include <com/sun/star/container/XNamed.hpp>
30 #include <com/sun/star/container/XIndexAccess.hpp>
31 #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
32 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
33 #include <com/sun/star/lang/NullPointerException.hpp>
34 #include <tools/debug.hxx>
35 #include <rtl/ustrbuf.hxx>
38 extern "C" void createRegistryInfo_SubmissionPropertyHandler()
40 ::pcr::SubmissionPropertyHandler::registerImplementation();
48 using namespace ::comphelper
;
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::lang
;
52 using namespace ::com::sun::star::beans
;
53 using namespace ::com::sun::star::script
;
54 using namespace ::com::sun::star::form
;
55 using namespace ::com::sun::star::xforms
;
56 using namespace ::com::sun::star::container
;
57 using namespace ::com::sun::star::inspection
;
63 SubmissionHelper::SubmissionHelper( ::osl::Mutex
& _rMutex
, const Reference
< XPropertySet
>& _rxIntrospectee
, const Reference
< frame::XModel
>& _rxContextDocument
)
64 :EFormsHelper( _rMutex
, _rxIntrospectee
, _rxContextDocument
)
66 OSL_ENSURE( canTriggerSubmissions( _rxIntrospectee
, _rxContextDocument
),
67 "SubmissionHelper::SubmissionHelper: you should not have instantiated me!" );
71 bool SubmissionHelper::canTriggerSubmissions( const Reference
< XPropertySet
>& _rxControlModel
,
72 const Reference
< frame::XModel
>& _rxContextDocument
)
74 if ( !EFormsHelper::isEForm( _rxContextDocument
) )
79 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( _rxControlModel
, UNO_QUERY
);
80 if ( xSubmissionSupp
.is() )
83 catch( const Exception
& )
85 OSL_FAIL( "SubmissionHelper::canTriggerSubmissions: caught an exception!" );
91 //= SubmissionPropertyHandler
94 SubmissionPropertyHandler::SubmissionPropertyHandler( const Reference
< XComponentContext
>& _rxContext
)
95 :EditPropertyHandler_Base( _rxContext
)
96 ,OPropertyChangeListener( m_aMutex
)
101 SubmissionPropertyHandler::~SubmissionPropertyHandler( )
107 OUString
SubmissionPropertyHandler::getImplementationName_static( )
109 return OUString( "com.sun.star.comp.extensions.SubmissionPropertyHandler" );
113 Sequence
< OUString
> SubmissionPropertyHandler::getSupportedServiceNames_static( )
115 Sequence
<OUString
> aSupported
{ "com.sun.star.form.inspection.SubmissionPropertyHandler" };
120 Any SAL_CALL
SubmissionPropertyHandler::getPropertyValue( const OUString
& _rPropertyName
)
122 ::osl::MutexGuard
aGuard( m_aMutex
);
123 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
125 OSL_ENSURE(m_pHelper
, "SubmissionPropertyHandler::getPropertyValue: inconsistency!");
126 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
133 case PROPERTY_ID_SUBMISSION_ID
:
135 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( m_xComponent
, UNO_QUERY
);
136 OSL_ENSURE( xSubmissionSupp
.is(), "SubmissionPropertyHandler::getPropertyValue: this should never happen ..." );
137 // this handler is not intended for components which are no XSubmissionSupplier
138 Reference
< submission::XSubmission
> xSubmission
;
139 if ( xSubmissionSupp
.is() )
140 xSubmission
= xSubmissionSupp
->getSubmission( );
141 aReturn
<<= xSubmission
;
145 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
147 FormButtonType eType
= FormButtonType_PUSH
;
148 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_BUTTONTYPE
) >>= eType
);
149 if ( ( eType
!= FormButtonType_PUSH
) && ( eType
!= FormButtonType_SUBMIT
) )
150 eType
= FormButtonType_PUSH
;
156 OSL_FAIL( "SubmissionPropertyHandler::getPropertyValue: cannot handle this property!" );
160 catch( const Exception
& )
162 OSL_FAIL( "SubmissionPropertyHandler::getPropertyValue: caught an exception!" );
169 void SAL_CALL
SubmissionPropertyHandler::setPropertyValue( const OUString
& _rPropertyName
, const Any
& _rValue
)
171 ::osl::MutexGuard
aGuard( m_aMutex
);
172 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
174 OSL_ENSURE(m_pHelper
, "SubmissionPropertyHandler::setPropertyValue: inconsistency!");
175 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
181 case PROPERTY_ID_SUBMISSION_ID
:
183 Reference
< submission::XSubmission
> xSubmission
;
184 OSL_VERIFY( _rValue
>>= xSubmission
);
186 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( m_xComponent
, UNO_QUERY
);
187 OSL_ENSURE( xSubmissionSupp
.is(), "SubmissionPropertyHandler::setPropertyValue: this should never happen ..." );
188 // this handler is not intended for components which are no XSubmissionSupplier
189 if ( xSubmissionSupp
.is() )
191 xSubmissionSupp
->setSubmission( xSubmission
);
192 impl_setContextDocumentModified_nothrow();
197 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
198 m_xComponent
->setPropertyValue( PROPERTY_BUTTONTYPE
, _rValue
);
202 OSL_FAIL( "SubmissionPropertyHandler::setPropertyValue: cannot handle this id!" );
205 catch( const Exception
& )
207 OSL_FAIL( "SubmissionPropertyHandler::setPropertyValue: caught an exception!" );
212 Sequence
< OUString
> SAL_CALL
SubmissionPropertyHandler::getActuatingProperties( )
214 ::osl::MutexGuard
aGuard( m_aMutex
);
216 return Sequence
< OUString
>();
218 Sequence
<OUString
> aReturn
{ PROPERTY_XFORMS_BUTTONTYPE
};
223 Sequence
< OUString
> SAL_CALL
SubmissionPropertyHandler::getSupersededProperties( )
225 ::osl::MutexGuard
aGuard( m_aMutex
);
227 return Sequence
< OUString
>();
229 Sequence
< OUString
> aReturn( 3 );
230 aReturn
[ 0 ] = PROPERTY_TARGET_URL
;
231 aReturn
[ 1 ] = PROPERTY_TARGET_FRAME
;
232 aReturn
[ 2 ] = PROPERTY_BUTTONTYPE
;
237 void SubmissionPropertyHandler::onNewComponent()
239 if ( m_xPropChangeMultiplexer
.is() )
241 m_xPropChangeMultiplexer
->dispose();
242 m_xPropChangeMultiplexer
.clear();
245 EditPropertyHandler_Base::onNewComponent();
247 Reference
< frame::XModel
> xDocument( impl_getContextDocument_nothrow() );
248 DBG_ASSERT( xDocument
.is(), "SubmissionPropertyHandler::onNewComponent: no document!" );
252 if ( SubmissionHelper::canTriggerSubmissions( m_xComponent
, xDocument
) )
254 m_pHelper
.reset( new SubmissionHelper( m_aMutex
, m_xComponent
, xDocument
) );
256 m_xPropChangeMultiplexer
= new OPropertyChangeMultiplexer( this, m_xComponent
);
257 m_xPropChangeMultiplexer
->addProperty( PROPERTY_BUTTONTYPE
);
262 Sequence
< Property
> SubmissionPropertyHandler::doDescribeSupportedProperties() const
264 std::vector
< Property
> aProperties
;
267 implAddPropertyDescription( aProperties
, PROPERTY_SUBMISSION_ID
, cppu::UnoType
<submission::XSubmission
>::get() );
268 implAddPropertyDescription( aProperties
, PROPERTY_XFORMS_BUTTONTYPE
, ::cppu::UnoType
<FormButtonType
>::get() );
270 if ( aProperties
.empty() )
271 return Sequence
< Property
>();
272 return comphelper::containerToSequence(aProperties
);
276 LineDescriptor SAL_CALL
SubmissionPropertyHandler::describePropertyLine( const OUString
& _rPropertyName
,
277 const Reference
< XPropertyControlFactory
>& _rxControlFactory
)
279 ::osl::MutexGuard
aGuard( m_aMutex
);
280 if ( !_rxControlFactory
.is() )
281 throw NullPointerException();
283 throw RuntimeException();
285 std::vector
< OUString
> aListEntries
;
286 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
289 case PROPERTY_ID_SUBMISSION_ID
:
290 m_pHelper
->getAllElementUINames(EFormsHelper::Submission
, aListEntries
, false);
293 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
295 // available options are nearly the same as for the "normal" button type, but only the
297 aListEntries
= m_pInfoService
->getPropertyEnumRepresentations( PROPERTY_ID_BUTTONTYPE
);
298 aListEntries
.resize( 2 );
303 OSL_FAIL( "SubmissionPropertyHandler::describePropertyLine: cannot handle this id!" );
304 return LineDescriptor();
307 LineDescriptor aDescriptor
;
308 aDescriptor
.Control
= PropertyHandlerHelper::createListBoxControl( _rxControlFactory
, aListEntries
, false, true );
309 aDescriptor
.DisplayName
= m_pInfoService
->getPropertyTranslation( nPropId
);
310 aDescriptor
.Category
= "General";
311 aDescriptor
.HelpURL
= HelpIdUrl::getHelpURL( m_pInfoService
->getPropertyHelpId( nPropId
) );
316 void SAL_CALL
SubmissionPropertyHandler::actuatingPropertyChanged( const OUString
& _rActuatingPropertyName
, const Any
& _rNewValue
, const Any
& /*_rOldValue*/, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool
)
318 if ( !_rxInspectorUI
.is() )
319 throw NullPointerException();
321 ::osl::MutexGuard
aGuard( m_aMutex
);
322 PropertyId
nActuatingPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName
) );
323 OSL_PRECOND(m_pHelper
,
324 "SubmissionPropertyHandler::actuatingPropertyChanged: inconsistentcy!");
325 // if we survived impl_getPropertyId_throwRuntime, we should have a helper, since no helper implies no properties
327 switch ( nActuatingPropId
)
329 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
331 FormButtonType eType
= FormButtonType_PUSH
;
332 OSL_VERIFY( _rNewValue
>>= eType
);
333 _rxInspectorUI
->enablePropertyUI( PROPERTY_SUBMISSION_ID
, eType
== FormButtonType_SUBMIT
);
338 OSL_FAIL( "SubmissionPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
343 Any SAL_CALL
SubmissionPropertyHandler::convertToPropertyValue( const OUString
& _rPropertyName
, const Any
& _rControlValue
)
345 ::osl::MutexGuard
aGuard( m_aMutex
);
350 "SubmissionPropertyHandler::convertToPropertyValue: we have no SupportedProperties!");
352 return aPropertyValue
;
354 OUString sControlValue
;
355 OSL_VERIFY( _rControlValue
>>= sControlValue
);
357 PropertyId
nPropId( m_pInfoService
->getPropertyId( _rPropertyName
) );
360 case PROPERTY_ID_SUBMISSION_ID
:
362 Reference
< XSubmission
> xSubmission( m_pHelper
->getModelElementFromUIName( EFormsHelper::Submission
, sControlValue
), UNO_QUERY
);
363 aPropertyValue
<<= xSubmission
;
367 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
369 ::rtl::Reference
< IPropertyEnumRepresentation
> aEnumConversion(
370 new DefaultEnumRepresentation( *m_pInfoService
, ::cppu::UnoType
<FormButtonType
>::get(), PROPERTY_ID_BUTTONTYPE
) );
371 // TODO/UNOize: make aEnumConversion a member?
372 aEnumConversion
->getValueFromDescription( sControlValue
, aPropertyValue
);
377 OSL_FAIL( "SubmissionPropertyHandler::convertToPropertyValue: cannot handle this id!" );
380 return aPropertyValue
;
384 Any SAL_CALL
SubmissionPropertyHandler::convertToControlValue( const OUString
& _rPropertyName
, const Any
& _rPropertyValue
, const Type
& _rControlValueType
)
386 ::osl::MutexGuard
aGuard( m_aMutex
);
391 "SubmissionPropertyHandler::convertToControlValue: we have no SupportedProperties!");
393 return aControlValue
;
395 OSL_ENSURE( _rControlValueType
.getTypeClass() == TypeClass_STRING
,
396 "SubmissionPropertyHandler::convertToControlValue: all our controls should use strings for value exchange!" );
398 PropertyId
nPropId( m_pInfoService
->getPropertyId( _rPropertyName
) );
401 case PROPERTY_ID_SUBMISSION_ID
:
403 Reference
< XPropertySet
> xSubmission( _rPropertyValue
, UNO_QUERY
);
404 if ( xSubmission
.is() )
405 aControlValue
<<= EFormsHelper::getModelElementUIName( EFormsHelper::Submission
, xSubmission
);
409 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
411 ::rtl::Reference
< IPropertyEnumRepresentation
> aEnumConversion(
412 new DefaultEnumRepresentation( *m_pInfoService
, _rPropertyValue
.getValueType(), PROPERTY_ID_BUTTONTYPE
) );
413 // TODO/UNOize: make aEnumConversion a member?
414 aControlValue
<<= aEnumConversion
->getDescriptionForValue( _rPropertyValue
);
419 OSL_FAIL( "SubmissionPropertyHandler::convertToControlValue: cannot handle this id!" );
422 return aControlValue
;
426 void SubmissionPropertyHandler::_propertyChanged( const PropertyChangeEvent
& _rEvent
)
428 if ( _rEvent
.PropertyName
== PROPERTY_BUTTONTYPE
)
429 firePropertyChange( PROPERTY_XFORMS_BUTTONTYPE
, PROPERTY_ID_XFORMS_BUTTONTYPE
, _rEvent
.OldValue
, _rEvent
.NewValue
);
436 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */