tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / extensions / source / propctrlr / xsdvalidationpropertyhandler.cxx
blob5e65bc727b64e69cb9e496bd03ce45667e1390ba
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "xsdvalidationpropertyhandler.hxx"
23 #include "formstrings.hxx"
24 #include "formmetadata.hxx"
25 #include "xsddatatypes.hxx"
26 #include "modulepcr.hxx"
27 #include <strings.hrc>
28 #include <propctrlr.h>
29 #include "newdatatype.hxx"
30 #include "xsdvalidationhelper.hxx"
31 #include "pcrcommon.hxx"
32 #include "handlerhelper.hxx"
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/lang/NullPointerException.hpp>
36 #include <com/sun/star/xsd/WhiteSpaceTreatment.hpp>
37 #include <com/sun/star/xsd/DataTypeClass.hpp>
38 #include <com/sun/star/inspection/PropertyControlType.hpp>
39 #include <com/sun/star/beans/Optional.hpp>
40 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
41 #include <com/sun/star/inspection/PropertyLineElement.hpp>
42 #include <vcl/svapp.hxx>
43 #include <vcl/weld.hxx>
44 #include <tools/debug.hxx>
45 #include <sal/macros.h>
47 #include <algorithm>
48 #include <limits>
51 namespace pcr
55 using namespace ::com::sun::star;
56 using namespace ::com::sun::star::uno;
57 using namespace ::com::sun::star::lang;
58 using namespace ::com::sun::star::beans;
59 using namespace ::com::sun::star::xsd;
60 using namespace ::com::sun::star::inspection;
62 using ::com::sun::star::beans::PropertyAttribute::MAYBEVOID;
65 //= XSDValidationPropertyHandler
67 XSDValidationPropertyHandler::XSDValidationPropertyHandler( const Reference< XComponentContext >& _rxContext )
68 :PropertyHandlerComponent( _rxContext )
73 XSDValidationPropertyHandler::~XSDValidationPropertyHandler()
78 OUString XSDValidationPropertyHandler::getImplementationName( )
80 return u"com.sun.star.comp.extensions.XSDValidationPropertyHandler"_ustr;
84 Sequence< OUString > XSDValidationPropertyHandler::getSupportedServiceNames( )
86 return{ u"com.sun.star.form.inspection.XSDValidationPropertyHandler"_ustr };
90 Any SAL_CALL XSDValidationPropertyHandler::getPropertyValue( const OUString& _rPropertyName )
92 ::osl::MutexGuard aGuard( m_aMutex );
93 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
95 OSL_ENSURE(m_pHelper, "XSDValidationPropertyHandler::getPropertyValue: inconsistency!");
96 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
98 Any aReturn;
99 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
100 switch ( nPropId )
102 // common facets
103 case PROPERTY_ID_XSD_DATA_TYPE: aReturn = pType.is() ? pType->getFacet( PROPERTY_NAME ) : Any( OUString() ); break;
104 case PROPERTY_ID_XSD_WHITESPACES:aReturn = pType.is() ? pType->getFacet( PROPERTY_XSD_WHITESPACES ) : Any( WhiteSpaceTreatment::Preserve ); break;
105 case PROPERTY_ID_XSD_PATTERN: aReturn = pType.is() ? pType->getFacet( PROPERTY_XSD_PATTERN ) : Any( OUString() ); break;
107 // all other properties are simply forwarded, if they exist at the given type
108 default:
110 if ( pType.is() && pType->hasFacet( _rPropertyName ) )
111 aReturn = pType->getFacet( _rPropertyName );
113 break;
116 return aReturn;
120 void SAL_CALL XSDValidationPropertyHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue )
122 ::osl::MutexGuard aGuard( m_aMutex );
123 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
125 OSL_ENSURE(m_pHelper, "XSDValidationPropertyHandler::getPropertyValue: inconsistency!");
126 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
128 if ( PROPERTY_ID_XSD_DATA_TYPE == nPropId )
130 OUString sTypeName;
131 OSL_VERIFY( _rValue >>= sTypeName );
132 m_pHelper->setValidatingDataTypeByName( sTypeName );
133 impl_setContextDocumentModified_nothrow();
134 return;
137 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
138 if ( !pType.is() )
140 OSL_FAIL( "XSDValidationPropertyHandler::setPropertyValue: you're trying to set a type facet, without a current type!" );
141 return;
144 pType->setFacet( _rPropertyName, _rValue );
145 impl_setContextDocumentModified_nothrow();
149 void XSDValidationPropertyHandler::onNewComponent()
151 PropertyHandlerComponent::onNewComponent();
153 Reference< frame::XModel > xDocument( impl_getContextDocument_nothrow() );
154 DBG_ASSERT( xDocument.is(), "XSDValidationPropertyHandler::onNewComponent: no document!" );
155 if ( EFormsHelper::isEForm( xDocument ) )
156 m_pHelper.reset( new XSDValidationHelper( m_aMutex, m_xComponent, xDocument ) );
157 else
158 m_pHelper.reset();
162 Sequence< Property > XSDValidationPropertyHandler::doDescribeSupportedProperties() const
164 std::vector< Property > aProperties;
166 if (m_pHelper)
168 bool bAllowBinding = m_pHelper->canBindToAnyDataType();
170 if ( bAllowBinding )
172 aProperties.reserve( 28 );
174 addStringPropertyDescription( aProperties, PROPERTY_XSD_DATA_TYPE );
175 addInt16PropertyDescription ( aProperties, PROPERTY_XSD_WHITESPACES );
176 addStringPropertyDescription( aProperties, PROPERTY_XSD_PATTERN );
178 // string facets
179 addInt32PropertyDescription( aProperties, PROPERTY_XSD_LENGTH, MAYBEVOID );
180 addInt32PropertyDescription( aProperties, PROPERTY_XSD_MIN_LENGTH, MAYBEVOID );
181 addInt32PropertyDescription( aProperties, PROPERTY_XSD_MAX_LENGTH, MAYBEVOID );
183 // decimal facets
184 addInt32PropertyDescription( aProperties, PROPERTY_XSD_TOTAL_DIGITS, MAYBEVOID );
185 addInt32PropertyDescription( aProperties, PROPERTY_XSD_FRACTION_DIGITS, MAYBEVOID );
187 // facets for different types
188 addInt16PropertyDescription( aProperties, PROPERTY_XSD_MAX_INCLUSIVE_INT, MAYBEVOID );
189 addInt16PropertyDescription( aProperties, PROPERTY_XSD_MAX_EXCLUSIVE_INT, MAYBEVOID );
190 addInt16PropertyDescription( aProperties, PROPERTY_XSD_MIN_INCLUSIVE_INT, MAYBEVOID );
191 addInt16PropertyDescription( aProperties, PROPERTY_XSD_MIN_EXCLUSIVE_INT, MAYBEVOID );
192 addDoublePropertyDescription( aProperties, PROPERTY_XSD_MAX_INCLUSIVE_DOUBLE, MAYBEVOID );
193 addDoublePropertyDescription( aProperties, PROPERTY_XSD_MAX_EXCLUSIVE_DOUBLE, MAYBEVOID );
194 addDoublePropertyDescription( aProperties, PROPERTY_XSD_MIN_INCLUSIVE_DOUBLE, MAYBEVOID );
195 addDoublePropertyDescription( aProperties, PROPERTY_XSD_MIN_EXCLUSIVE_DOUBLE, MAYBEVOID );
196 addDatePropertyDescription( aProperties, PROPERTY_XSD_MAX_INCLUSIVE_DATE, MAYBEVOID );
197 addDatePropertyDescription( aProperties, PROPERTY_XSD_MAX_EXCLUSIVE_DATE, MAYBEVOID );
198 addDatePropertyDescription( aProperties, PROPERTY_XSD_MIN_INCLUSIVE_DATE, MAYBEVOID );
199 addDatePropertyDescription( aProperties, PROPERTY_XSD_MIN_EXCLUSIVE_DATE, MAYBEVOID );
200 addTimePropertyDescription( aProperties, PROPERTY_XSD_MAX_INCLUSIVE_TIME, MAYBEVOID );
201 addTimePropertyDescription( aProperties, PROPERTY_XSD_MAX_EXCLUSIVE_TIME, MAYBEVOID );
202 addTimePropertyDescription( aProperties, PROPERTY_XSD_MIN_INCLUSIVE_TIME, MAYBEVOID );
203 addTimePropertyDescription( aProperties, PROPERTY_XSD_MIN_EXCLUSIVE_TIME, MAYBEVOID );
204 addDateTimePropertyDescription( aProperties, PROPERTY_XSD_MAX_INCLUSIVE_DATE_TIME, MAYBEVOID );
205 addDateTimePropertyDescription( aProperties, PROPERTY_XSD_MAX_EXCLUSIVE_DATE_TIME, MAYBEVOID );
206 addDateTimePropertyDescription( aProperties, PROPERTY_XSD_MIN_INCLUSIVE_DATE_TIME, MAYBEVOID );
207 addDateTimePropertyDescription( aProperties, PROPERTY_XSD_MIN_EXCLUSIVE_DATE_TIME, MAYBEVOID );
211 return comphelper::containerToSequence( aProperties );
215 Sequence< OUString > SAL_CALL XSDValidationPropertyHandler::getSupersededProperties( )
217 ::osl::MutexGuard aGuard( m_aMutex );
219 std::vector< OUString > aSuperfluous;
220 if (m_pHelper)
222 aSuperfluous.push_back( PROPERTY_CONTROLSOURCE );
223 aSuperfluous.push_back( PROPERTY_EMPTY_IS_NULL );
224 aSuperfluous.push_back( PROPERTY_FILTERPROPOSAL );
225 aSuperfluous.push_back( PROPERTY_LISTSOURCETYPE );
226 aSuperfluous.push_back( PROPERTY_LISTSOURCE );
227 aSuperfluous.push_back( PROPERTY_BOUNDCOLUMN );
229 bool bAllowBinding = m_pHelper->canBindToAnyDataType();
231 if ( bAllowBinding )
233 aSuperfluous.push_back( PROPERTY_MAXTEXTLEN );
234 aSuperfluous.push_back( PROPERTY_VALUEMIN );
235 aSuperfluous.push_back( PROPERTY_VALUEMAX );
236 aSuperfluous.push_back( PROPERTY_DECIMAL_ACCURACY );
237 aSuperfluous.push_back( PROPERTY_TIMEMIN );
238 aSuperfluous.push_back( PROPERTY_TIMEMAX );
239 aSuperfluous.push_back( PROPERTY_DATEMIN );
240 aSuperfluous.push_back( PROPERTY_DATEMAX );
241 aSuperfluous.push_back( PROPERTY_EFFECTIVE_MIN );
242 aSuperfluous.push_back( PROPERTY_EFFECTIVE_MAX );
246 return comphelper::containerToSequence( aSuperfluous );
250 Sequence< OUString > SAL_CALL XSDValidationPropertyHandler::getActuatingProperties( )
252 ::osl::MutexGuard aGuard( m_aMutex );
253 std::vector< OUString > aInterestedInActuations;
254 if (m_pHelper)
256 aInterestedInActuations.push_back( PROPERTY_XSD_DATA_TYPE );
257 aInterestedInActuations.push_back( PROPERTY_XML_DATA_MODEL );
259 return comphelper::containerToSequence( aInterestedInActuations );
263 namespace
265 void showPropertyUI( const Reference< XObjectInspectorUI >& _rxInspectorUI, const OUString& _rPropertyName, bool _bShow )
267 if ( _bShow )
268 _rxInspectorUI->showPropertyUI( _rPropertyName );
269 else
270 _rxInspectorUI->hidePropertyUI( _rPropertyName );
275 LineDescriptor SAL_CALL XSDValidationPropertyHandler::describePropertyLine( const OUString& _rPropertyName,
276 const Reference< XPropertyControlFactory >& _rxControlFactory )
278 ::osl::MutexGuard aGuard( m_aMutex );
279 if ( !_rxControlFactory.is() )
280 throw NullPointerException();
281 if (!m_pHelper)
282 throw RuntimeException();
284 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
286 LineDescriptor aDescriptor;
287 if ( nPropId != PROPERTY_ID_XSD_DATA_TYPE )
288 aDescriptor.IndentLevel = 1;
290 // collect some information about the to-be-created control
291 sal_Int16 nControlType = PropertyControlType::TextField;
292 std::vector< OUString > aListEntries;
293 Optional< double > aMinValue( false, 0 );
294 Optional< double > aMaxValue( false, 0 );
296 switch ( nPropId )
298 case PROPERTY_ID_XSD_DATA_TYPE:
299 nControlType = PropertyControlType::ListBox;
301 implGetAvailableDataTypeNames( aListEntries );
303 aDescriptor.PrimaryButtonId = UID_PROP_ADD_DATA_TYPE;
304 aDescriptor.SecondaryButtonId = UID_PROP_REMOVE_DATA_TYPE;
305 aDescriptor.HasPrimaryButton = aDescriptor.HasSecondaryButton = true;
306 aDescriptor.PrimaryButtonImageURL = "private:graphicrepository/extensions/res/buttonplus.png";
307 aDescriptor.SecondaryButtonImageURL = "private:graphicrepository/extensions/res/buttonminus.png";
308 break;
310 case PROPERTY_ID_XSD_WHITESPACES:
312 nControlType = PropertyControlType::ListBox;
313 aListEntries = m_pInfoService->getPropertyEnumRepresentations( PROPERTY_ID_XSD_WHITESPACES );
315 break;
317 case PROPERTY_ID_XSD_PATTERN:
318 nControlType = PropertyControlType::TextField;
319 break;
321 case PROPERTY_ID_XSD_LENGTH:
322 case PROPERTY_ID_XSD_MIN_LENGTH:
323 case PROPERTY_ID_XSD_MAX_LENGTH:
324 nControlType = PropertyControlType::NumericField;
325 break;
327 case PROPERTY_ID_XSD_TOTAL_DIGITS:
328 case PROPERTY_ID_XSD_FRACTION_DIGITS:
329 nControlType = PropertyControlType::NumericField;
330 break;
332 case PROPERTY_ID_XSD_MAX_INCLUSIVE_INT:
333 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_INT:
334 case PROPERTY_ID_XSD_MIN_INCLUSIVE_INT:
335 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_INT:
337 nControlType = PropertyControlType::NumericField;
339 // handle limits for various 'INT' types according to
340 // their actual semantics (year, month, day)
342 ::rtl::Reference< XSDDataType > xDataType( m_pHelper->getValidatingDataType() );
343 sal_Int16 nTypeClass = xDataType.is() ? xDataType->classify() : DataTypeClass::STRING;
345 aMinValue.IsPresent = aMaxValue.IsPresent = true;
346 aMinValue.Value = DataTypeClass::gYear == nTypeClass ? 0 : 1;
347 aMaxValue.Value = std::numeric_limits< sal_Int32 >::max();
348 if ( DataTypeClass::gMonth == nTypeClass )
349 aMaxValue.Value = 12;
350 else if ( DataTypeClass::gDay == nTypeClass )
351 aMaxValue.Value = 31;
353 break;
355 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DOUBLE:
356 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DOUBLE:
357 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DOUBLE:
358 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DOUBLE:
359 nControlType = PropertyControlType::NumericField;
360 // TODO/eForms: do we have "auto-digits"?
361 break;
363 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DATE:
364 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DATE:
365 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DATE:
366 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DATE:
367 nControlType = PropertyControlType::DateField;
368 break;
370 case PROPERTY_ID_XSD_MAX_INCLUSIVE_TIME:
371 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_TIME:
372 case PROPERTY_ID_XSD_MIN_INCLUSIVE_TIME:
373 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_TIME:
374 nControlType = PropertyControlType::TimeField;
375 break;
377 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DATE_TIME:
378 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DATE_TIME:
379 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DATE_TIME:
380 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DATE_TIME:
381 nControlType = PropertyControlType::DateTimeField;
382 break;
384 default:
385 OSL_FAIL( "XSDValidationPropertyHandler::describePropertyLine: cannot handle this property!" );
386 break;
389 switch ( nControlType )
391 case PropertyControlType::ListBox:
392 aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory, std::move(aListEntries), false, false );
393 break;
394 case PropertyControlType::NumericField:
395 aDescriptor.Control = PropertyHandlerHelper::createNumericControl( _rxControlFactory, 0, aMinValue, aMaxValue );
396 break;
397 default:
398 aDescriptor.Control = _rxControlFactory->createPropertyControl( nControlType, false );
399 break;
402 aDescriptor.Category = "Data";
403 aDescriptor.DisplayName = m_pInfoService->getPropertyTranslation( nPropId );
404 aDescriptor.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nPropId ) );
406 return aDescriptor;
410 InteractiveSelectionResult SAL_CALL XSDValidationPropertyHandler::onInteractivePropertySelection( const OUString& _rPropertyName, sal_Bool _bPrimary, Any& /*_rData*/, const Reference< XObjectInspectorUI >& _rxInspectorUI )
412 if ( !_rxInspectorUI.is() )
413 throw NullPointerException();
415 ::osl::MutexGuard aGuard( m_aMutex );
416 OSL_ENSURE(m_pHelper, "XSDValidationPropertyHandler::onInteractivePropertySelection: we "
417 "don't have any SupportedProperties!");
418 if (!m_pHelper)
419 return InteractiveSelectionResult_Cancelled;
421 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
423 switch ( nPropId )
425 case PROPERTY_ID_XSD_DATA_TYPE:
427 if ( _bPrimary )
429 OUString sNewDataTypeName;
430 if ( implPrepareCloneDataCurrentType( sNewDataTypeName ) )
432 implDoCloneCurrentDataType( sNewDataTypeName );
433 return InteractiveSelectionResult_Success;
436 else
437 return implPrepareRemoveCurrentDataType() && implDoRemoveCurrentDataType() ? InteractiveSelectionResult_Success : InteractiveSelectionResult_Cancelled;
439 break;
441 default:
442 OSL_FAIL( "XSDValidationPropertyHandler::onInteractivePropertySelection: unexpected property to build a dedicated UI!" );
443 break;
445 return InteractiveSelectionResult_Cancelled;
449 void SAL_CALL XSDValidationPropertyHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener )
451 ::osl::MutexGuard aGuard( m_aMutex );
452 PropertyHandlerComponent::addPropertyChangeListener( _rxListener );
453 if (m_pHelper)
454 m_pHelper->registerBindingListener( _rxListener );
458 void SAL_CALL XSDValidationPropertyHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener )
460 ::osl::MutexGuard aGuard( m_aMutex );
461 if (m_pHelper)
462 m_pHelper->revokeBindingListener( _rxListener );
463 PropertyHandlerComponent::removePropertyChangeListener( _rxListener );
467 bool XSDValidationPropertyHandler::implPrepareCloneDataCurrentType( OUString& _rNewName )
469 OSL_PRECOND(
470 m_pHelper,
471 "XSDValidationPropertyHandler::implPrepareCloneDataCurrentType: this will crash!");
473 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
474 if ( !pType.is() )
476 OSL_FAIL( "XSDValidationPropertyHandler::implPrepareCloneDataCurrentType: invalid current data type!" );
477 return false;
480 std::vector< OUString > aExistentNames;
481 m_pHelper->getAvailableDataTypeNames( aExistentNames );
483 NewDataTypeDialog aDialog( nullptr, pType->getName(), aExistentNames ); // TODO/eForms: proper parent
484 if (aDialog.run() != RET_OK)
485 return false;
487 _rNewName = aDialog.GetName();
488 return true;
492 void XSDValidationPropertyHandler::implDoCloneCurrentDataType( const OUString& _rNewName )
494 OSL_PRECOND(m_pHelper,
495 "XSDValidationPropertyHandler::implDoCloneCurrentDataType: this will crash!");
497 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
498 if ( !pType.is() )
499 return;
501 if ( !m_pHelper->cloneDataType( pType, _rNewName ) )
502 return;
504 m_pHelper->setValidatingDataTypeByName( _rNewName );
507 bool XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType()
509 OSL_PRECOND(
510 m_pHelper,
511 "XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType: this will crash!");
513 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
514 if ( !pType.is() )
516 OSL_FAIL( "XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType: invalid current data type!" );
517 return false;
520 // confirmation message
521 OUString sConfirmation( PcrRes( RID_STR_CONFIRM_DELETE_DATA_TYPE ) );
522 sConfirmation = sConfirmation.replaceFirst( "#type#", pType->getName() );
524 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(nullptr, // TODO/eForms: proper parent
525 VclMessageType::Question, VclButtonsType::YesNo,
526 sConfirmation));
527 return xQueryBox->run() == RET_YES;
530 bool XSDValidationPropertyHandler::implDoRemoveCurrentDataType()
532 OSL_PRECOND(m_pHelper,
533 "XSDValidationPropertyHandler::implDoRemoveCurrentDataType: this will crash!");
535 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
536 if ( !pType.is() )
537 return false;
539 // set a new data type at the binding, which is the "basic" type for the one
540 // we are going to delete
541 // (do this before the actual deletion, so the old type is still valid for property change
542 // notifications)
543 m_pHelper->setValidatingDataTypeByName( m_pHelper->getBasicTypeNameForClass( pType->classify() ) );
544 // now remove the type
545 m_pHelper->removeDataTypeFromRepository( pType->getName() );
547 return true;
551 void SAL_CALL XSDValidationPropertyHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& _rOldValue, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool _bFirstTimeInit )
553 if ( !_rxInspectorUI.is() )
554 throw NullPointerException();
556 ::osl::MutexGuard aGuard( m_aMutex );
557 PropertyId nActuatingPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName ) );
558 if (!m_pHelper)
559 throw RuntimeException();
560 // if we survived impl_getPropertyId_throwRuntime, we should have a helper, since no helper implies no properties
562 switch ( nActuatingPropId )
564 case PROPERTY_ID_XSD_DATA_TYPE:
566 ::rtl::Reference< XSDDataType > xDataType( m_pHelper->getValidatingDataType() );
568 // is removal of this type possible?
569 bool bIsBasicType = xDataType.is() && xDataType->isBasicType();
570 _rxInspectorUI->enablePropertyUIElements( PROPERTY_XSD_DATA_TYPE, PropertyLineElement::PrimaryButton, xDataType.is() );
571 _rxInspectorUI->enablePropertyUIElements( PROPERTY_XSD_DATA_TYPE, PropertyLineElement::SecondaryButton, xDataType.is() && !bIsBasicType );
574 // show the facets which are available at the data type
575 OUString aFacets[] = {
576 PROPERTY_XSD_WHITESPACES, PROPERTY_XSD_PATTERN,
577 PROPERTY_XSD_LENGTH, PROPERTY_XSD_MIN_LENGTH, PROPERTY_XSD_MAX_LENGTH, PROPERTY_XSD_TOTAL_DIGITS,
578 PROPERTY_XSD_FRACTION_DIGITS,
579 PROPERTY_XSD_MAX_INCLUSIVE_INT,
580 PROPERTY_XSD_MAX_EXCLUSIVE_INT,
581 PROPERTY_XSD_MIN_INCLUSIVE_INT,
582 PROPERTY_XSD_MIN_EXCLUSIVE_INT,
583 PROPERTY_XSD_MAX_INCLUSIVE_DOUBLE,
584 PROPERTY_XSD_MAX_EXCLUSIVE_DOUBLE,
585 PROPERTY_XSD_MIN_INCLUSIVE_DOUBLE,
586 PROPERTY_XSD_MIN_EXCLUSIVE_DOUBLE,
587 PROPERTY_XSD_MAX_INCLUSIVE_DATE,
588 PROPERTY_XSD_MAX_EXCLUSIVE_DATE,
589 PROPERTY_XSD_MIN_INCLUSIVE_DATE,
590 PROPERTY_XSD_MIN_EXCLUSIVE_DATE,
591 PROPERTY_XSD_MAX_INCLUSIVE_TIME,
592 PROPERTY_XSD_MAX_EXCLUSIVE_TIME,
593 PROPERTY_XSD_MIN_INCLUSIVE_TIME,
594 PROPERTY_XSD_MIN_EXCLUSIVE_TIME,
595 PROPERTY_XSD_MAX_INCLUSIVE_DATE_TIME,
596 PROPERTY_XSD_MAX_EXCLUSIVE_DATE_TIME,
597 PROPERTY_XSD_MIN_INCLUSIVE_DATE_TIME,
598 PROPERTY_XSD_MIN_EXCLUSIVE_DATE_TIME
601 size_t i=0;
602 const OUString* pLoop = nullptr;
603 for ( i = 0, pLoop = aFacets;
604 i < SAL_N_ELEMENTS( aFacets );
605 ++i, ++pLoop
608 showPropertyUI( _rxInspectorUI, *pLoop, xDataType.is() && xDataType->hasFacet( *pLoop ) );
609 _rxInspectorUI->enablePropertyUI( *pLoop, !bIsBasicType );
612 break;
614 case PROPERTY_ID_XML_DATA_MODEL:
616 // The data type which the current binding works with may not be present in the
617 // new model. Thus, transfer it.
618 OUString sOldModelName; _rOldValue >>= sOldModelName;
619 OUString sNewModelName; _rNewValue >>= sNewModelName;
620 OUString sDataType = m_pHelper->getValidatingDataTypeName();
621 m_pHelper->copyDataType( sOldModelName, sNewModelName, sDataType );
623 // the list of available data types depends on the chosen model, so update this
624 if ( !_bFirstTimeInit )
625 _rxInspectorUI->rebuildPropertyUI( PROPERTY_XSD_DATA_TYPE );
627 break;
629 default:
630 OSL_FAIL( "XSDValidationPropertyHandler::actuatingPropertyChanged: cannot handle this property!" );
631 return;
634 // in both cases, we need to care for the current value of the XSD_DATA_TYPE property,
635 // and update the FormatKey of the formatted field we're inspecting (if any)
636 if ( !_bFirstTimeInit && m_pHelper->isInspectingFormattedField() )
637 m_pHelper->findDefaultFormatForIntrospectee();
641 void XSDValidationPropertyHandler::implGetAvailableDataTypeNames( std::vector< OUString >& /* [out] */ _rNames ) const
643 OSL_PRECOND(
644 m_pHelper,
645 "XSDValidationPropertyHandler::implGetAvailableDataTypeNames: this will crash!");
646 // start with *all* types which are available at the model
647 std::vector< OUString > aAllTypes;
648 m_pHelper->getAvailableDataTypeNames( aAllTypes );
649 _rNames.clear();
650 _rNames.reserve( aAllTypes.size() );
652 // then allow only those which are "compatible" with our control
653 for (auto const& dataType : aAllTypes)
655 ::rtl::Reference< XSDDataType > pType = m_pHelper->getDataTypeByName(dataType);
656 if ( pType.is() && m_pHelper->canBindToDataType( pType->classify() ) )
657 _rNames.push_back(dataType);
662 } // namespace pcr
664 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
665 extensions_propctrlr_XSDValidationPropertyHandler_get_implementation(
666 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
668 return cppu::acquire(new pcr::XSDValidationPropertyHandler(context));
671 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */