12a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
32a97ec55SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
42a97ec55SAndrew Rist * or more contributor license agreements. See the NOTICE file
52a97ec55SAndrew Rist * distributed with this work for additional information
62a97ec55SAndrew Rist * regarding copyright ownership. The ASF licenses this file
72a97ec55SAndrew Rist * to you under the Apache License, Version 2.0 (the
82a97ec55SAndrew Rist * "License"); you may not use this file except in compliance
92a97ec55SAndrew Rist * with the License. You may obtain a copy of the License at
102a97ec55SAndrew Rist *
112a97ec55SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
122a97ec55SAndrew Rist *
132a97ec55SAndrew Rist * Unless required by applicable law or agreed to in writing,
142a97ec55SAndrew Rist * software distributed under the License is distributed on an
152a97ec55SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162a97ec55SAndrew Rist * KIND, either express or implied. See the License for the
172a97ec55SAndrew Rist * specific language governing permissions and limitations
182a97ec55SAndrew Rist * under the License.
192a97ec55SAndrew Rist *
202a97ec55SAndrew Rist *************************************************************/
212a97ec55SAndrew Rist
222a97ec55SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir #include "eformspropertyhandler.hxx"
27cdf0e10cSrcweir #include "formstrings.hxx"
28cdf0e10cSrcweir #include "formmetadata.hxx"
29cdf0e10cSrcweir #include "propctrlr.hrc"
30cdf0e10cSrcweir #include "formbrowsertools.hxx"
31cdf0e10cSrcweir #include "eformshelper.hxx"
32cdf0e10cSrcweir #include "handlerhelper.hxx"
33cdf0e10cSrcweir
34cdf0e10cSrcweir /** === begin UNO includes === **/
35cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
36cdf0e10cSrcweir #include <com/sun/star/inspection/PropertyControlType.hpp>
37cdf0e10cSrcweir #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
38cdf0e10cSrcweir /** === end UNO includes === **/
39cdf0e10cSrcweir #include <tools/debug.hxx>
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include <functional>
42cdf0e10cSrcweir
43cdf0e10cSrcweir //------------------------------------------------------------------------
createRegistryInfo_EFormsPropertyHandler()44cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_EFormsPropertyHandler()
45cdf0e10cSrcweir {
46cdf0e10cSrcweir ::pcr::EFormsPropertyHandler::registerImplementation();
47cdf0e10cSrcweir }
48cdf0e10cSrcweir
49cdf0e10cSrcweir //........................................................................
50cdf0e10cSrcweir namespace pcr
51cdf0e10cSrcweir {
52cdf0e10cSrcweir //........................................................................
53cdf0e10cSrcweir
54cdf0e10cSrcweir using namespace ::com::sun::star;
55cdf0e10cSrcweir using namespace ::com::sun::star::uno;
56cdf0e10cSrcweir using namespace ::com::sun::star::lang;
57cdf0e10cSrcweir using namespace ::com::sun::star::beans;
58cdf0e10cSrcweir using namespace ::com::sun::star::xforms;
59cdf0e10cSrcweir using namespace ::com::sun::star::script;
60cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
61cdf0e10cSrcweir using namespace ::com::sun::star::form::binding;
62cdf0e10cSrcweir using namespace ::com::sun::star::inspection;
63cdf0e10cSrcweir
64cdf0e10cSrcweir //====================================================================
65cdf0e10cSrcweir //= EFormsPropertyHandler
66cdf0e10cSrcweir //====================================================================
DBG_NAME(EFormsPropertyHandler)67cdf0e10cSrcweir DBG_NAME( EFormsPropertyHandler )
68cdf0e10cSrcweir //--------------------------------------------------------------------
69cdf0e10cSrcweir EFormsPropertyHandler::EFormsPropertyHandler( const Reference< XComponentContext >& _rxContext )
70cdf0e10cSrcweir :EFormsPropertyHandler_Base( _rxContext )
71cdf0e10cSrcweir ,m_bSimulatingModelChange( false )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir DBG_CTOR( EFormsPropertyHandler, NULL );
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
76cdf0e10cSrcweir //--------------------------------------------------------------------
~EFormsPropertyHandler()77cdf0e10cSrcweir EFormsPropertyHandler::~EFormsPropertyHandler( )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir DBG_DTOR( EFormsPropertyHandler, NULL );
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir //--------------------------------------------------------------------
getImplementationName_static()83cdf0e10cSrcweir ::rtl::OUString SAL_CALL EFormsPropertyHandler::getImplementationName_static( ) throw (RuntimeException)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.EFormsPropertyHandler" ) );
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir //--------------------------------------------------------------------
getSupportedServiceNames_static()89cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EFormsPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported( 1 );
92cdf0e10cSrcweir aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.XMLFormsPropertyHandler" ) );
93cdf0e10cSrcweir return aSupported;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir //--------------------------------------------------------------------
getModelNamePropertyValue() const97cdf0e10cSrcweir ::rtl::OUString EFormsPropertyHandler::getModelNamePropertyValue() const
98cdf0e10cSrcweir {
99cdf0e10cSrcweir ::rtl::OUString sModelName = m_pHelper->getCurrentFormModelName();
100cdf0e10cSrcweir if ( !sModelName.getLength() )
101cdf0e10cSrcweir sModelName = m_sBindingLessModelName;
102cdf0e10cSrcweir return sModelName;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
105cdf0e10cSrcweir //--------------------------------------------------------------------
getPropertyValue(const::rtl::OUString & _rPropertyName)106cdf0e10cSrcweir Any SAL_CALL EFormsPropertyHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
109cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
110cdf0e10cSrcweir
111cdf0e10cSrcweir OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::getPropertyValue: we don't have any SupportedProperties!" );
112cdf0e10cSrcweir // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
113cdf0e10cSrcweir
114cdf0e10cSrcweir Any aReturn;
115cdf0e10cSrcweir try
116cdf0e10cSrcweir {
117cdf0e10cSrcweir switch ( nPropId )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir case PROPERTY_ID_LIST_BINDING:
120cdf0e10cSrcweir aReturn <<= m_pHelper->getCurrentListSourceBinding();
121cdf0e10cSrcweir break;
122cdf0e10cSrcweir
123cdf0e10cSrcweir case PROPERTY_ID_XML_DATA_MODEL:
124cdf0e10cSrcweir aReturn <<= getModelNamePropertyValue();
125cdf0e10cSrcweir break;
126cdf0e10cSrcweir
127cdf0e10cSrcweir case PROPERTY_ID_BINDING_NAME:
128cdf0e10cSrcweir aReturn <<= m_pHelper->getCurrentBindingName();
129cdf0e10cSrcweir break;
130cdf0e10cSrcweir
131cdf0e10cSrcweir case PROPERTY_ID_BIND_EXPRESSION:
132cdf0e10cSrcweir case PROPERTY_ID_XSD_CONSTRAINT:
133cdf0e10cSrcweir case PROPERTY_ID_XSD_CALCULATION:
134cdf0e10cSrcweir case PROPERTY_ID_XSD_REQUIRED:
135cdf0e10cSrcweir case PROPERTY_ID_XSD_RELEVANT:
136cdf0e10cSrcweir case PROPERTY_ID_XSD_READONLY:
137cdf0e10cSrcweir {
138cdf0e10cSrcweir Reference< XPropertySet > xBindingProps( m_pHelper->getCurrentBinding() );
139cdf0e10cSrcweir if ( xBindingProps.is() )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir aReturn = xBindingProps->getPropertyValue( _rPropertyName );
142cdf0e10cSrcweir DBG_ASSERT( aReturn.getValueType().equals( ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) ) ),
143cdf0e10cSrcweir "EFormsPropertyHandler::getPropertyValue: invalid BindingExpression value type!" );
144cdf0e10cSrcweir }
145cdf0e10cSrcweir else
146cdf0e10cSrcweir aReturn <<= ::rtl::OUString();
147cdf0e10cSrcweir }
148cdf0e10cSrcweir break;
149cdf0e10cSrcweir
150cdf0e10cSrcweir default:
151cdf0e10cSrcweir DBG_ERROR( "EFormsPropertyHandler::getPropertyValue: cannot handle this property!" );
152cdf0e10cSrcweir break;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir }
155cdf0e10cSrcweir catch( const Exception& )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
158cdf0e10cSrcweir ::rtl::OString sMessage( "EFormsPropertyHandler::getPropertyValue: caught an exception!" );
159cdf0e10cSrcweir sMessage += "\n(have been asked for the \"";
160cdf0e10cSrcweir sMessage += ::rtl::OString( _rPropertyName.getStr(), _rPropertyName.getLength(), RTL_TEXTENCODING_ASCII_US );
161cdf0e10cSrcweir sMessage += "\" property.)";
162cdf0e10cSrcweir OSL_ENSURE( sal_False, sMessage.getStr() );
163cdf0e10cSrcweir #endif
164cdf0e10cSrcweir }
165cdf0e10cSrcweir return aReturn;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
168cdf0e10cSrcweir //--------------------------------------------------------------------
setPropertyValue(const::rtl::OUString & _rPropertyName,const Any & _rValue)169cdf0e10cSrcweir void SAL_CALL EFormsPropertyHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
172cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
173cdf0e10cSrcweir
174cdf0e10cSrcweir OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::setPropertyValue: we don't have any SupportedProperties!" );
175cdf0e10cSrcweir // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
176cdf0e10cSrcweir
177cdf0e10cSrcweir try
178cdf0e10cSrcweir {
179cdf0e10cSrcweir Any aOldValue = getPropertyValue( _rPropertyName );
180cdf0e10cSrcweir
181cdf0e10cSrcweir switch ( nPropId )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir case PROPERTY_ID_LIST_BINDING:
184cdf0e10cSrcweir {
185cdf0e10cSrcweir Reference< XListEntrySource > xSource;
186cdf0e10cSrcweir OSL_VERIFY( _rValue >>= xSource );
187cdf0e10cSrcweir m_pHelper->setListSourceBinding( xSource );
188cdf0e10cSrcweir }
189cdf0e10cSrcweir break;
190cdf0e10cSrcweir
191cdf0e10cSrcweir case PROPERTY_ID_XML_DATA_MODEL:
192cdf0e10cSrcweir {
193cdf0e10cSrcweir OSL_VERIFY( _rValue >>= m_sBindingLessModelName );
194cdf0e10cSrcweir
195cdf0e10cSrcweir // if the model changed, reset the binding to NULL
196cdf0e10cSrcweir if ( m_pHelper->getCurrentFormModelName() != m_sBindingLessModelName )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir ::rtl::OUString sOldBindingName = m_pHelper->getCurrentBindingName();
199cdf0e10cSrcweir m_pHelper->setBinding( NULL );
200cdf0e10cSrcweir firePropertyChange( PROPERTY_BINDING_NAME, PROPERTY_ID_BINDING_NAME,
201cdf0e10cSrcweir makeAny( sOldBindingName ), makeAny( ::rtl::OUString() ) );
202cdf0e10cSrcweir }
203cdf0e10cSrcweir }
204cdf0e10cSrcweir break;
205cdf0e10cSrcweir
206cdf0e10cSrcweir case PROPERTY_ID_BINDING_NAME:
207cdf0e10cSrcweir {
208cdf0e10cSrcweir ::rtl::OUString sNewBindingName;
209cdf0e10cSrcweir OSL_VERIFY( _rValue >>= sNewBindingName );
210cdf0e10cSrcweir
211cdf0e10cSrcweir bool bPreviouslyEmptyModel = !m_pHelper->getCurrentFormModel().is();
212cdf0e10cSrcweir
213cdf0e10cSrcweir Reference< XPropertySet > xNewBinding;
214cdf0e10cSrcweir if ( sNewBindingName.getLength() )
215cdf0e10cSrcweir // obtain the binding with this name, for the current model
216cdf0e10cSrcweir xNewBinding = m_pHelper->getOrCreateBindingForModel( getModelNamePropertyValue(), sNewBindingName );
217cdf0e10cSrcweir
218cdf0e10cSrcweir m_pHelper->setBinding( xNewBinding );
219cdf0e10cSrcweir
220cdf0e10cSrcweir if ( bPreviouslyEmptyModel )
221cdf0e10cSrcweir { // simulate a property change for the model property
222cdf0e10cSrcweir // This is because we "simulate" the Model property by remembering the
223cdf0e10cSrcweir // value ourself. Other instances might, however, not know this value,
224cdf0e10cSrcweir // but prefer to retrieve it somewhere else - e.g. from the EFormsHelper
225cdf0e10cSrcweir //
226cdf0e10cSrcweir // The really correct solution would be if *all* property handlers
227cdf0e10cSrcweir // obtain a "current property value" for *all* properties from a central
228cdf0e10cSrcweir // instance. Then, handler A could ask it for the value of property
229cdf0e10cSrcweir // X, and this request would be re-routed to handler B, which ultimately
230cdf0e10cSrcweir // knows the current value.
231cdf0e10cSrcweir // However, there's no such mechanism in place currently.
232cdf0e10cSrcweir m_bSimulatingModelChange = true;
233cdf0e10cSrcweir firePropertyChange( PROPERTY_XML_DATA_MODEL, PROPERTY_ID_XML_DATA_MODEL,
234cdf0e10cSrcweir makeAny( ::rtl::OUString() ), makeAny( getModelNamePropertyValue() ) );
235cdf0e10cSrcweir m_bSimulatingModelChange = false;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir }
238cdf0e10cSrcweir break;
239cdf0e10cSrcweir
240cdf0e10cSrcweir case PROPERTY_ID_BIND_EXPRESSION:
241cdf0e10cSrcweir {
242cdf0e10cSrcweir Reference< XPropertySet > xBinding( m_pHelper->getCurrentBinding() );
243cdf0e10cSrcweir OSL_ENSURE( xBinding.is(), "You should not reach this without an active binding!" );
244cdf0e10cSrcweir if ( xBinding.is() )
245cdf0e10cSrcweir xBinding->setPropertyValue( PROPERTY_BIND_EXPRESSION, _rValue );
246cdf0e10cSrcweir }
247cdf0e10cSrcweir break;
248cdf0e10cSrcweir
249cdf0e10cSrcweir case PROPERTY_ID_XSD_REQUIRED:
250cdf0e10cSrcweir case PROPERTY_ID_XSD_RELEVANT:
251cdf0e10cSrcweir case PROPERTY_ID_XSD_READONLY:
252cdf0e10cSrcweir case PROPERTY_ID_XSD_CONSTRAINT:
253cdf0e10cSrcweir case PROPERTY_ID_XSD_CALCULATION:
254cdf0e10cSrcweir {
255cdf0e10cSrcweir Reference< XPropertySet > xBindingProps( m_pHelper->getCurrentBinding() );
256cdf0e10cSrcweir DBG_ASSERT( xBindingProps.is(), "EFormsPropertyHandler::setPropertyValue: how can I set a property if there's no binding?" );
257cdf0e10cSrcweir if ( xBindingProps.is() )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir DBG_ASSERT( _rValue.getValueType().equals( ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) ) ),
260cdf0e10cSrcweir "EFormsPropertyHandler::setPropertyValue: invalid value type!" );
261cdf0e10cSrcweir xBindingProps->setPropertyValue( _rPropertyName, _rValue );
262cdf0e10cSrcweir }
263cdf0e10cSrcweir }
264cdf0e10cSrcweir break;
265cdf0e10cSrcweir
266cdf0e10cSrcweir default:
267cdf0e10cSrcweir DBG_ERROR( "EFormsPropertyHandler::setPropertyValue: cannot handle this property!" );
268cdf0e10cSrcweir break;
269cdf0e10cSrcweir }
270cdf0e10cSrcweir
271cdf0e10cSrcweir impl_setContextDocumentModified_nothrow();
272cdf0e10cSrcweir
273cdf0e10cSrcweir Any aNewValue( getPropertyValue( _rPropertyName ) );
274cdf0e10cSrcweir firePropertyChange( _rPropertyName, nPropId, aOldValue, aNewValue );
275cdf0e10cSrcweir }
276cdf0e10cSrcweir catch( const Exception& )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsPropertyHandler::setPropertyValue: caught an exception!" );
279cdf0e10cSrcweir }
280cdf0e10cSrcweir }
281cdf0e10cSrcweir
282cdf0e10cSrcweir //--------------------------------------------------------------------
onNewComponent()283cdf0e10cSrcweir void EFormsPropertyHandler::onNewComponent()
284cdf0e10cSrcweir {
285cdf0e10cSrcweir EFormsPropertyHandler_Base::onNewComponent();
286cdf0e10cSrcweir
287cdf0e10cSrcweir Reference< frame::XModel > xDocument( impl_getContextDocument_nothrow() );
288cdf0e10cSrcweir DBG_ASSERT( xDocument.is(), "EFormsPropertyHandler::onNewComponent: no document!" );
289cdf0e10cSrcweir if ( EFormsHelper::isEForm( xDocument ) )
290cdf0e10cSrcweir m_pHelper.reset( new EFormsHelper( m_aMutex, m_xComponent, xDocument ) );
291cdf0e10cSrcweir else
292*3d762826SHerbert Dürr m_pHelper.reset();
293cdf0e10cSrcweir }
294cdf0e10cSrcweir
295cdf0e10cSrcweir //--------------------------------------------------------------------
doDescribeSupportedProperties() const296cdf0e10cSrcweir Sequence< Property > SAL_CALL EFormsPropertyHandler::doDescribeSupportedProperties() const
297cdf0e10cSrcweir {
298cdf0e10cSrcweir ::std::vector< Property > aProperties;
299cdf0e10cSrcweir
300cdf0e10cSrcweir if ( m_pHelper.get() )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir if ( m_pHelper->canBindToAnyDataType() )
303cdf0e10cSrcweir {
304cdf0e10cSrcweir aProperties.reserve( 7 );
305cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XML_DATA_MODEL );
306cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_BINDING_NAME );
307cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_BIND_EXPRESSION );
308cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XSD_REQUIRED );
309cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XSD_RELEVANT );
310cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XSD_READONLY );
311cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XSD_CONSTRAINT );
312cdf0e10cSrcweir addStringPropertyDescription( aProperties, PROPERTY_XSD_CALCULATION );
313cdf0e10cSrcweir }
314cdf0e10cSrcweir if ( m_pHelper->isListEntrySink() )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir implAddPropertyDescription( aProperties, PROPERTY_LIST_BINDING,
317cdf0e10cSrcweir ::getCppuType( static_cast< Reference< XListEntrySource > * >( NULL ) ) );
318cdf0e10cSrcweir }
319cdf0e10cSrcweir }
320cdf0e10cSrcweir
321cdf0e10cSrcweir if ( aProperties.empty() )
322cdf0e10cSrcweir return Sequence< Property >();
323cdf0e10cSrcweir return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
324cdf0e10cSrcweir }
325cdf0e10cSrcweir
326cdf0e10cSrcweir //--------------------------------------------------------------------
convertToPropertyValue(const::rtl::OUString & _rPropertyName,const Any & _rControlValue)327cdf0e10cSrcweir Any SAL_CALL EFormsPropertyHandler::convertToPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException)
328cdf0e10cSrcweir {
329cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
330cdf0e10cSrcweir Any aReturn;
331cdf0e10cSrcweir
332cdf0e10cSrcweir OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::convertToPropertyValue: we have no SupportedProperties!" );
333cdf0e10cSrcweir if ( !m_pHelper.get() )
334cdf0e10cSrcweir return aReturn;
335cdf0e10cSrcweir
336cdf0e10cSrcweir PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
337cdf0e10cSrcweir
338cdf0e10cSrcweir ::rtl::OUString sControlValue;
339cdf0e10cSrcweir switch ( nPropId )
340cdf0e10cSrcweir {
341cdf0e10cSrcweir case PROPERTY_ID_LIST_BINDING:
342cdf0e10cSrcweir {
343cdf0e10cSrcweir OSL_VERIFY( _rControlValue >>= sControlValue );
344cdf0e10cSrcweir Reference< XListEntrySource > xListSource( m_pHelper->getModelElementFromUIName( EFormsHelper::Binding, sControlValue ), UNO_QUERY );
345cdf0e10cSrcweir OSL_ENSURE( xListSource.is() || !m_pHelper->getModelElementFromUIName( EFormsHelper::Binding, sControlValue ).is(),
346cdf0e10cSrcweir "EFormsPropertyHandler::convertToPropertyValue: there's a binding which is no ListEntrySource!" );
347cdf0e10cSrcweir aReturn <<= xListSource;
348cdf0e10cSrcweir }
349cdf0e10cSrcweir break;
350cdf0e10cSrcweir
351cdf0e10cSrcweir default:
352cdf0e10cSrcweir aReturn = EFormsPropertyHandler_Base::convertToPropertyValue( _rPropertyName, _rControlValue );
353cdf0e10cSrcweir break;
354cdf0e10cSrcweir }
355cdf0e10cSrcweir
356cdf0e10cSrcweir return aReturn;
357cdf0e10cSrcweir }
358cdf0e10cSrcweir
359cdf0e10cSrcweir //--------------------------------------------------------------------
convertToControlValue(const::rtl::OUString & _rPropertyName,const Any & _rPropertyValue,const Type & _rControlValueType)360cdf0e10cSrcweir Any SAL_CALL EFormsPropertyHandler::convertToControlValue( const ::rtl::OUString& _rPropertyName, const Any& _rPropertyValue, const Type& _rControlValueType ) throw (UnknownPropertyException, RuntimeException)
361cdf0e10cSrcweir {
362cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
363cdf0e10cSrcweir Any aReturn;
364cdf0e10cSrcweir
365cdf0e10cSrcweir OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::convertToControlValue: we have no SupportedProperties!" );
366cdf0e10cSrcweir if ( !m_pHelper.get() )
367cdf0e10cSrcweir return aReturn;
368cdf0e10cSrcweir
369cdf0e10cSrcweir PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
370cdf0e10cSrcweir
371cdf0e10cSrcweir OSL_ENSURE( _rControlValueType.getTypeClass() == TypeClass_STRING,
372cdf0e10cSrcweir "EFormsPropertyHandler::convertToControlValue: all our controls should use strings for value exchange!" );
373cdf0e10cSrcweir
374cdf0e10cSrcweir switch ( nPropId )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir case PROPERTY_ID_LIST_BINDING:
377cdf0e10cSrcweir {
378cdf0e10cSrcweir Reference< XPropertySet > xListSourceBinding( _rPropertyValue, UNO_QUERY );
379cdf0e10cSrcweir if ( xListSourceBinding.is() )
380cdf0e10cSrcweir aReturn <<= m_pHelper->getModelElementUIName( EFormsHelper::Binding, xListSourceBinding );
381cdf0e10cSrcweir }
382cdf0e10cSrcweir break;
383cdf0e10cSrcweir
384cdf0e10cSrcweir default:
385cdf0e10cSrcweir aReturn = EFormsPropertyHandler_Base::convertToControlValue( _rPropertyName, _rPropertyValue, _rControlValueType );
386cdf0e10cSrcweir break;
387cdf0e10cSrcweir }
388cdf0e10cSrcweir
389cdf0e10cSrcweir return aReturn;
390cdf0e10cSrcweir }
391cdf0e10cSrcweir
392cdf0e10cSrcweir //--------------------------------------------------------------------
getActuatingProperties()393cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EFormsPropertyHandler::getActuatingProperties( ) throw (RuntimeException)
394cdf0e10cSrcweir {
395cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
396cdf0e10cSrcweir if ( !m_pHelper.get() )
397cdf0e10cSrcweir return Sequence< ::rtl::OUString >();
398cdf0e10cSrcweir
399cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aInterestedInActuations( 2 );
400cdf0e10cSrcweir aInterestedInActuations[ 0 ] = PROPERTY_XML_DATA_MODEL;
401cdf0e10cSrcweir aInterestedInActuations[ 1 ] = PROPERTY_BINDING_NAME;
402cdf0e10cSrcweir return Sequence< ::rtl::OUString >( &(*aInterestedInActuations.begin()), aInterestedInActuations.size() );
403cdf0e10cSrcweir }
404cdf0e10cSrcweir
405cdf0e10cSrcweir //--------------------------------------------------------------------
getSupersededProperties()406cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EFormsPropertyHandler::getSupersededProperties( ) throw (RuntimeException)
407cdf0e10cSrcweir {
408cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
409cdf0e10cSrcweir if ( !m_pHelper.get() )
410cdf0e10cSrcweir return Sequence< ::rtl::OUString >();
411cdf0e10cSrcweir
412cdf0e10cSrcweir Sequence< ::rtl::OUString > aReturn( 1 );
413cdf0e10cSrcweir aReturn[ 0 ] = PROPERTY_INPUT_REQUIRED;
414cdf0e10cSrcweir return aReturn;
415cdf0e10cSrcweir }
416cdf0e10cSrcweir
417cdf0e10cSrcweir //--------------------------------------------------------------------
describePropertyLine(const::rtl::OUString & _rPropertyName,const Reference<XPropertyControlFactory> & _rxControlFactory)418cdf0e10cSrcweir LineDescriptor SAL_CALL EFormsPropertyHandler::describePropertyLine( const ::rtl::OUString& _rPropertyName,
419cdf0e10cSrcweir const Reference< XPropertyControlFactory >& _rxControlFactory )
420cdf0e10cSrcweir throw (UnknownPropertyException, NullPointerException, RuntimeException)
421cdf0e10cSrcweir {
422cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
423cdf0e10cSrcweir if ( !_rxControlFactory.is() )
424cdf0e10cSrcweir throw NullPointerException();
425cdf0e10cSrcweir if ( !m_pHelper.get() )
426cdf0e10cSrcweir throw RuntimeException();
427cdf0e10cSrcweir
428cdf0e10cSrcweir LineDescriptor aDescriptor;
429cdf0e10cSrcweir sal_Int16 nControlType = PropertyControlType::TextField;
430cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aListEntries;
431cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
432cdf0e10cSrcweir switch ( nPropId )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir case PROPERTY_ID_LIST_BINDING:
435cdf0e10cSrcweir nControlType = PropertyControlType::ListBox;
436cdf0e10cSrcweir const_cast< EFormsHelper* >( m_pHelper.get() )->getAllElementUINames( EFormsHelper::Binding, aListEntries, true );
437cdf0e10cSrcweir break;
438cdf0e10cSrcweir
439cdf0e10cSrcweir case PROPERTY_ID_XML_DATA_MODEL:
440cdf0e10cSrcweir nControlType = PropertyControlType::ListBox;
441cdf0e10cSrcweir m_pHelper->getFormModelNames( aListEntries );
442cdf0e10cSrcweir break;
443cdf0e10cSrcweir
444cdf0e10cSrcweir case PROPERTY_ID_BINDING_NAME:
445cdf0e10cSrcweir {
446cdf0e10cSrcweir nControlType = PropertyControlType::ComboBox;
447cdf0e10cSrcweir ::rtl::OUString sCurrentModel( getModelNamePropertyValue() );
448cdf0e10cSrcweir if ( sCurrentModel.getLength() )
449cdf0e10cSrcweir m_pHelper->getBindingNames( sCurrentModel, aListEntries );
450cdf0e10cSrcweir }
451cdf0e10cSrcweir break;
452cdf0e10cSrcweir
453cdf0e10cSrcweir case PROPERTY_ID_BIND_EXPRESSION: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_BIND_EXPRESSION); break;
454cdf0e10cSrcweir case PROPERTY_ID_XSD_REQUIRED: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_XSD_REQUIRED); break;
455cdf0e10cSrcweir case PROPERTY_ID_XSD_RELEVANT: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_XSD_RELEVANT); break;
456cdf0e10cSrcweir case PROPERTY_ID_XSD_READONLY: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_XSD_READONLY); break;
457cdf0e10cSrcweir case PROPERTY_ID_XSD_CONSTRAINT: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_XSD_CONSTRAINT); break;
458cdf0e10cSrcweir case PROPERTY_ID_XSD_CALCULATION: aDescriptor.PrimaryButtonId = rtl::OUString::createFromAscii(UID_PROP_DLG_XSD_CALCULATION); break;
459cdf0e10cSrcweir
460cdf0e10cSrcweir default:
461cdf0e10cSrcweir DBG_ERROR( "EFormsPropertyHandler::describePropertyLine: cannot handle this property!" );
462cdf0e10cSrcweir break;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir
465cdf0e10cSrcweir switch ( nControlType )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir case PropertyControlType::ListBox:
468cdf0e10cSrcweir aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory, aListEntries, sal_False, sal_True );
469cdf0e10cSrcweir break;
470cdf0e10cSrcweir case PropertyControlType::ComboBox:
471cdf0e10cSrcweir aDescriptor.Control = PropertyHandlerHelper::createComboBoxControl( _rxControlFactory, aListEntries, sal_False, sal_True );
472cdf0e10cSrcweir break;
473cdf0e10cSrcweir default:
474cdf0e10cSrcweir aDescriptor.Control = _rxControlFactory->createPropertyControl( nControlType, sal_False );
475cdf0e10cSrcweir break;
476cdf0e10cSrcweir }
477cdf0e10cSrcweir
478cdf0e10cSrcweir aDescriptor.DisplayName = m_pInfoService->getPropertyTranslation( nPropId );
479cdf0e10cSrcweir aDescriptor.Category = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Data" ) );
480cdf0e10cSrcweir aDescriptor.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nPropId ) );
481cdf0e10cSrcweir return aDescriptor;
482cdf0e10cSrcweir }
483cdf0e10cSrcweir
484cdf0e10cSrcweir //--------------------------------------------------------------------
onInteractivePropertySelection(const::rtl::OUString & _rPropertyName,sal_Bool,Any & _rData,const Reference<XObjectInspectorUI> & _rxInspectorUI)485cdf0e10cSrcweir InteractiveSelectionResult SAL_CALL EFormsPropertyHandler::onInteractivePropertySelection( const ::rtl::OUString& _rPropertyName, sal_Bool /*_bPrimary*/, Any& _rData, const Reference< XObjectInspectorUI >& _rxInspectorUI ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
486cdf0e10cSrcweir {
487cdf0e10cSrcweir if ( !_rxInspectorUI.is() )
488cdf0e10cSrcweir throw NullPointerException();
489cdf0e10cSrcweir
490cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
491cdf0e10cSrcweir OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::onInteractivePropertySelection: we do not have any SupportedProperties!" );
492cdf0e10cSrcweir if ( !m_pHelper.get() )
493cdf0e10cSrcweir return InteractiveSelectionResult_Cancelled;
494cdf0e10cSrcweir
495cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
496cdf0e10cSrcweir (void)nPropId;
497cdf0e10cSrcweir OSL_ENSURE( ( PROPERTY_ID_BINDING_NAME == nPropId )
498cdf0e10cSrcweir || ( PROPERTY_ID_BIND_EXPRESSION == nPropId )
499cdf0e10cSrcweir || ( PROPERTY_ID_XSD_REQUIRED == nPropId )
500cdf0e10cSrcweir || ( PROPERTY_ID_XSD_RELEVANT == nPropId )
501cdf0e10cSrcweir || ( PROPERTY_ID_XSD_READONLY == nPropId )
502cdf0e10cSrcweir || ( PROPERTY_ID_XSD_CONSTRAINT == nPropId )
503cdf0e10cSrcweir || ( PROPERTY_ID_XSD_CALCULATION == nPropId ), "EFormsPropertyHandler::onInteractivePropertySelection: unexpected!" );
504cdf0e10cSrcweir
505cdf0e10cSrcweir try
506cdf0e10cSrcweir {
507cdf0e10cSrcweir Reference< XExecutableDialog > xDialog;
508cdf0e10cSrcweir m_aContext.createComponent( "com.sun.star.xforms.ui.dialogs.AddCondition", xDialog );
509cdf0e10cSrcweir Reference< XPropertySet > xDialogProps( xDialog, UNO_QUERY_THROW );
510cdf0e10cSrcweir
511cdf0e10cSrcweir // the model for the dialog to work with
512cdf0e10cSrcweir Reference< xforms::XModel > xModel( m_pHelper->getCurrentFormModel() );
513cdf0e10cSrcweir // the binding for the dialog to work with
514cdf0e10cSrcweir Reference< XPropertySet > xBinding( m_pHelper->getCurrentBinding() );
515cdf0e10cSrcweir // the aspect of the binding which the dialog should modify
516cdf0e10cSrcweir ::rtl::OUString sFacetName( _rPropertyName );
517cdf0e10cSrcweir
518cdf0e10cSrcweir OSL_ENSURE( xModel.is() && xBinding.is() && sFacetName.getLength(),
519cdf0e10cSrcweir "EFormsPropertyHandler::onInteractivePropertySelection: something is missing for the dialog initialization!" );
520cdf0e10cSrcweir if ( !( xModel.is() && xBinding.is() && sFacetName.getLength() ) )
521cdf0e10cSrcweir return InteractiveSelectionResult_Cancelled;
522cdf0e10cSrcweir
523cdf0e10cSrcweir xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FormModel" ) ), makeAny( xModel ) );
524cdf0e10cSrcweir xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Binding" ) ), makeAny( xBinding ) );
525cdf0e10cSrcweir xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FacetName" ) ), makeAny( sFacetName ) );
526cdf0e10cSrcweir
527cdf0e10cSrcweir if ( !xDialog->execute() )
528cdf0e10cSrcweir // cancelled
529cdf0e10cSrcweir return InteractiveSelectionResult_Cancelled;
530cdf0e10cSrcweir
531cdf0e10cSrcweir _rData = xDialogProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ConditionValue" ) ) );
532cdf0e10cSrcweir return InteractiveSelectionResult_ObtainedValue;
533cdf0e10cSrcweir }
534cdf0e10cSrcweir catch( const Exception& )
535cdf0e10cSrcweir {
536cdf0e10cSrcweir OSL_ENSURE( sal_False, "EFormsPropertyHandler::onInteractivePropertySelection: caught an exception!" );
537cdf0e10cSrcweir }
538cdf0e10cSrcweir
539cdf0e10cSrcweir // something went wrong here ...(but has been asserted already)
540cdf0e10cSrcweir return InteractiveSelectionResult_Cancelled;
541cdf0e10cSrcweir }
542cdf0e10cSrcweir
543cdf0e10cSrcweir //--------------------------------------------------------------------
addPropertyChangeListener(const Reference<XPropertyChangeListener> & _rxListener)544cdf0e10cSrcweir void SAL_CALL EFormsPropertyHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException)
545cdf0e10cSrcweir {
546cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
547cdf0e10cSrcweir EFormsPropertyHandler_Base::addPropertyChangeListener( _rxListener );
548cdf0e10cSrcweir if ( m_pHelper.get() )
549cdf0e10cSrcweir m_pHelper->registerBindingListener( _rxListener );
550cdf0e10cSrcweir }
551cdf0e10cSrcweir
552cdf0e10cSrcweir //--------------------------------------------------------------------
removePropertyChangeListener(const Reference<XPropertyChangeListener> & _rxListener)553cdf0e10cSrcweir void SAL_CALL EFormsPropertyHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException)
554cdf0e10cSrcweir {
555cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
556cdf0e10cSrcweir if ( m_pHelper.get() )
557cdf0e10cSrcweir m_pHelper->revokeBindingListener( _rxListener );
558cdf0e10cSrcweir EFormsPropertyHandler_Base::removePropertyChangeListener( _rxListener );
559cdf0e10cSrcweir }
560cdf0e10cSrcweir
561cdf0e10cSrcweir //--------------------------------------------------------------------
actuatingPropertyChanged(const::rtl::OUString & _rActuatingPropertyName,const Any & _rNewValue,const Any &,const Reference<XObjectInspectorUI> & _rxInspectorUI,sal_Bool)562cdf0e10cSrcweir void SAL_CALL EFormsPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool ) throw (NullPointerException, RuntimeException)
563cdf0e10cSrcweir {
564cdf0e10cSrcweir if ( !_rxInspectorUI.is() )
565cdf0e10cSrcweir throw NullPointerException();
566cdf0e10cSrcweir
567cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
568cdf0e10cSrcweir PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
569cdf0e10cSrcweir OSL_PRECOND( m_pHelper.get(), "EFormsPropertyHandler::actuatingPropertyChanged: inconsistentcy!" );
570cdf0e10cSrcweir // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
571cdf0e10cSrcweir
572cdf0e10cSrcweir DBG_ASSERT( _rxInspectorUI.is(), "EFormsPropertyHandler::actuatingPropertyChanged: invalid callback!" );
573cdf0e10cSrcweir if ( !_rxInspectorUI.is() )
574cdf0e10cSrcweir return;
575cdf0e10cSrcweir
576cdf0e10cSrcweir switch ( nActuatingPropId )
577cdf0e10cSrcweir {
578cdf0e10cSrcweir case PROPERTY_ID_XML_DATA_MODEL:
579cdf0e10cSrcweir {
580cdf0e10cSrcweir if ( m_bSimulatingModelChange )
581cdf0e10cSrcweir break;
582cdf0e10cSrcweir ::rtl::OUString sDataModelName;
583cdf0e10cSrcweir OSL_VERIFY( _rNewValue >>= sDataModelName );
584cdf0e10cSrcweir sal_Bool bBoundToSomeModel = 0 != sDataModelName.getLength();
585cdf0e10cSrcweir _rxInspectorUI->rebuildPropertyUI( PROPERTY_BINDING_NAME );
586cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_BINDING_NAME, bBoundToSomeModel );
587cdf0e10cSrcweir }
588cdf0e10cSrcweir // NO break
589cdf0e10cSrcweir
590cdf0e10cSrcweir case PROPERTY_ID_BINDING_NAME:
591cdf0e10cSrcweir {
592cdf0e10cSrcweir sal_Bool bHaveABinding = ( m_pHelper->getCurrentBindingName().getLength() > 0 );
593cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_BIND_EXPRESSION, bHaveABinding );
594cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_REQUIRED, bHaveABinding );
595cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_RELEVANT, bHaveABinding );
596cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_READONLY, bHaveABinding );
597cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_CONSTRAINT, bHaveABinding );
598cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_CALCULATION, bHaveABinding );
599cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_DATA_TYPE, bHaveABinding );
600cdf0e10cSrcweir }
601cdf0e10cSrcweir break;
602cdf0e10cSrcweir
603cdf0e10cSrcweir default:
604cdf0e10cSrcweir DBG_ERROR( "EFormsPropertyHandler::actuatingPropertyChanged: cannot handle this property!" );
605cdf0e10cSrcweir break;
606cdf0e10cSrcweir }
607cdf0e10cSrcweir }
608cdf0e10cSrcweir
609cdf0e10cSrcweir //........................................................................
610cdf0e10cSrcweir } // namespace pcr
611cdf0e10cSrcweir //........................................................................
612cdf0e10cSrcweir
613