27#include <com/sun/star/lang/NullPointerException.hpp>
28#include <com/sun/star/util/XModifiable.hpp>
29#include <com/sun/star/script/Converter.hpp>
57 ,m_bSupportedPropertiesAreKnown( false )
60 ,m_pInfoService ( new OPropertyInfoService )
63 m_xTypeConverter = Converter::create(_rxContext);
66 PropertyHandler::~PropertyHandler()
72 if ( !_rxIntrospectee.is() )
73 throw NullPointerException();
75 ::osl::MutexGuard aGuard(
m_aMutex );
77 Reference< XPropertySet > xNewComponent( _rxIntrospectee, UNO_QUERY );
78 if ( xNewComponent == m_xComponent )
86 OSL_ENSURE( m_aPropertyListeners.getLength() == 0,
"PropertyHandler::inspect: derived classes are expected to forward the removePropertyChangeListener call to their base class (me)!" );
89 m_xComponent = xNewComponent;
94 addPropertyChangeListener( readdListener.
next() );
97 void PropertyHandler::onNewComponent()
99 if ( m_xComponent.is() )
100 m_xComponentPropertyInfo = m_xComponent->getPropertySetInfo();
102 m_xComponentPropertyInfo.clear();
104 m_bSupportedPropertiesAreKnown =
false;
105 m_aSupportedProperties.realloc( 0 );
108 Sequence< Property > SAL_CALL PropertyHandler::getSupportedProperties()
110 ::osl::MutexGuard aGuard(
m_aMutex );
111 if ( !m_bSupportedPropertiesAreKnown )
114 m_bSupportedPropertiesAreKnown =
true;
116 return m_aSupportedProperties;
119 Sequence< OUString > SAL_CALL PropertyHandler::getSupersededProperties( )
121 return Sequence< OUString >();
124 Sequence< OUString > SAL_CALL PropertyHandler::getActuatingProperties( )
126 return Sequence< OUString >();
129 Any SAL_CALL PropertyHandler::convertToPropertyValue(
const OUString& _rPropertyName,
const Any& _rControlValue )
131 ::osl::MutexGuard aGuard(
m_aMutex );
132 PropertyId nPropId = m_pInfoService->getPropertyId( _rPropertyName );
133 Property aProperty( impl_getPropertyFromName_throw( _rPropertyName ) );
136 if ( !_rControlValue.hasValue() )
138 return aPropertyValue;
140 if ( ( m_pInfoService->getPropertyUIFlags( nPropId ) &
PROP_FLAG_ENUM ) != 0 )
142 OUString sControlValue;
143 OSL_VERIFY( _rControlValue >>= sControlValue );
147 aEnumConversion->getValueFromDescription( sControlValue, aPropertyValue );
150 aPropertyValue = PropertyHandlerHelper::convertToPropertyValue(
151 m_xContext, m_xTypeConverter, aProperty, _rControlValue );
152 return aPropertyValue;
155 Any SAL_CALL PropertyHandler::convertToControlValue(
const OUString& _rPropertyName,
const Any& _rPropertyValue,
const Type& _rControlValueType )
157 ::osl::MutexGuard aGuard(
m_aMutex );
158 PropertyId nPropId = m_pInfoService->getPropertyId( _rPropertyName );
160 if ( ( m_pInfoService->getPropertyUIFlags( nPropId ) &
PROP_FLAG_ENUM ) != 0 )
162 DBG_ASSERT( _rControlValueType.getTypeClass() == TypeClass_STRING,
"PropertyHandler::convertToControlValue: ENUM, but not STRING?" );
167 return Any( aEnumConversion->getDescriptionForValue( _rPropertyValue ) );
170 return PropertyHandlerHelper::convertToControlValue(
171 m_xContext, m_xTypeConverter, _rPropertyValue, _rControlValueType );
174 PropertyState SAL_CALL PropertyHandler::getPropertyState(
const OUString& )
176 return PropertyState_DIRECT_VALUE;
179 LineDescriptor SAL_CALL PropertyHandler::describePropertyLine(
const OUString& _rPropertyName,
180 const Reference< XPropertyControlFactory >& _rxControlFactory )
182 if ( !_rxControlFactory.is() )
183 throw NullPointerException();
185 ::osl::MutexGuard aGuard(
m_aMutex );
186 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
187 const Property& rProperty( impl_getPropertyFromId_throw( nPropId ) );
189 LineDescriptor aDescriptor;
190 if ( ( m_pInfoService->getPropertyUIFlags( nPropId ) &
PROP_FLAG_ENUM ) != 0 )
192 aDescriptor.Control = PropertyHandlerHelper::createListBoxControl(
193 _rxControlFactory, m_pInfoService->getPropertyEnumRepresentations( nPropId ),
194 PropertyHandlerHelper::requiresReadOnlyControl( rProperty.Attributes ),
false );
197 PropertyHandlerHelper::describePropertyLine( rProperty, aDescriptor, _rxControlFactory );
199 aDescriptor.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nPropId ) );
200 aDescriptor.DisplayName = m_pInfoService->getPropertyTranslation( nPropId );
203 aDescriptor.Category =
"Data";
205 aDescriptor.Category =
"General";
209 sal_Bool SAL_CALL PropertyHandler::isComposable(
const OUString& _rPropertyName )
211 ::osl::MutexGuard aGuard(
m_aMutex );
212 return m_pInfoService->isComposeable( _rPropertyName );
215 InteractiveSelectionResult SAL_CALL PropertyHandler::onInteractivePropertySelection(
const OUString& ,
sal_Bool , Any& ,
const Reference< XObjectInspectorUI >& )
217 OSL_FAIL(
"PropertyHandler::onInteractivePropertySelection: not implemented!" );
218 return InteractiveSelectionResult_Cancelled;
221 void SAL_CALL PropertyHandler::actuatingPropertyChanged(
const OUString& ,
const Any& ,
const Any& ,
const Reference< XObjectInspectorUI >& ,
sal_Bool )
223 OSL_FAIL(
"PropertyHandler::actuatingPropertyChanged: not implemented!" );
226 void SAL_CALL PropertyHandler::addPropertyChangeListener(
const Reference< XPropertyChangeListener >& _rxListener )
228 ::osl::MutexGuard aGuard(
m_aMutex );
229 if ( !_rxListener.is() )
230 throw NullPointerException();
231 m_aPropertyListeners.addInterface( _rxListener );
234 void SAL_CALL PropertyHandler::removePropertyChangeListener(
const Reference< XPropertyChangeListener >& _rxListener )
236 ::osl::MutexGuard aGuard(
m_aMutex );
237 m_aPropertyListeners.removeInterface( _rxListener );
249 m_xComponent.clear();
250 m_aPropertyListeners.clear();
251 m_xTypeConverter.clear();
252 m_aSupportedProperties.realloc( 0 );
255 void PropertyHandler::firePropertyChange(
const OUString& _rPropName,
PropertyId _nPropId,
const Any& _rOldValue,
const Any& _rNewValue )
257 PropertyChangeEvent
aEvent;
258 aEvent.Source = m_xComponent;
259 aEvent.PropertyHandle = _nPropId;
260 aEvent.PropertyName = _rPropName;
261 aEvent.OldValue = _rOldValue;
262 aEvent.NewValue = _rNewValue;
263 m_aPropertyListeners.notifyEach( &XPropertyChangeListener::propertyChange,
aEvent );
269 const Property* pFound = std::find_if( m_aSupportedProperties.begin(), m_aSupportedProperties.end(),
272 if ( pFound != m_aSupportedProperties.end() )
279 const Property* pProperty = impl_getPropertyFromId_nothrow( _nPropId );
281 throw UnknownPropertyException();
286 const Property& PropertyHandler::impl_getPropertyFromName_throw(
const OUString& _rPropertyName )
const
292 if ( pFound == m_aSupportedProperties.
end() )
293 throw UnknownPropertyException(_rPropertyName);
298 void PropertyHandler::implAddPropertyDescription( std::vector< Property >& _rProperties,
const OUString& _rPropertyName,
const Type& _rType, sal_Int16 _nAttribs )
const
302 m_pInfoService->getPropertyId( _rPropertyName ),
308 weld::Window* PropertyHandler::impl_getDefaultDialogFrame_nothrow()
const
310 return PropertyHandlerHelper::getDialogParentFrame(
m_xContext);
313 PropertyId PropertyHandler::impl_getPropertyId_throwUnknownProperty(
const OUString& _rPropertyName )
const
315 PropertyId nPropId = m_pInfoService->getPropertyId( _rPropertyName );
317 throw UnknownPropertyException(_rPropertyName);
321 PropertyId PropertyHandler::impl_getPropertyId_throwRuntime(
const OUString& _rPropertyName )
const
323 PropertyId nPropId = m_pInfoService->getPropertyId( _rPropertyName );
329 PropertyId PropertyHandler::impl_getPropertyId_nothrow(
const OUString& _rPropertyName )
const
331 return m_pInfoService->getPropertyId( _rPropertyName );
334 void PropertyHandler::impl_setContextDocumentModified_nothrow()
const
336 Reference< XModifiable > xModifiable( impl_getContextDocument_nothrow(), UNO_QUERY );
337 if ( xModifiable.is() )
338 xModifiable->setModified(
true );
341 bool PropertyHandler::impl_componentHasProperty_throw(
const OUString& _rPropName )
const
343 return m_xComponentPropertyInfo.is() && m_xComponentPropertyInfo->hasPropertyByName( _rPropName );
346 sal_Int16 PropertyHandler::impl_getDocumentMeasurementUnit_throw()
const
350 Reference< XServiceInfo > xDocumentSI( impl_getContextDocument_nothrow(), UNO_QUERY );
351 OSL_ENSURE( xDocumentSI.is(),
"PropertyHandlerHelper::impl_getDocumentMeasurementUnit_throw: No context document - where do I live?" );
352 if ( xDocumentSI.is() )
355 OUString sConfigurationLocation;
356 OUString sConfigurationProperty;
359 sConfigurationLocation =
"/org.openoffice.Office.WriterWeb/Layout/Other";
360 sConfigurationProperty =
"MeasureUnit";
364 sConfigurationLocation =
"/org.openoffice.Office.Writer/Layout/Other";
365 sConfigurationProperty =
"MeasureUnit";
369 sConfigurationLocation =
"/org.openoffice.Office.Calc/Layout/Other/MeasureUnit";
370 sConfigurationProperty =
"Metric";
374 sConfigurationLocation =
"/org.openoffice.Office.Draw/Layout/Other/MeasureUnit";
375 sConfigurationProperty =
"Metric";
379 sConfigurationLocation =
"/org.openoffice.Office.Impress/Layout/Other/MeasureUnit";
380 sConfigurationProperty =
"Metric";
384 if ( !(sConfigurationLocation.isEmpty() || sConfigurationProperty.isEmpty()) )
388 sal_Int32 nUnitAsInt = sal_Int32(FieldUnit::NONE);
389 aConfigTree.
getNodeValue( sConfigurationProperty ) >>= nUnitAsInt;
392 if ( ( nUnitAsInt > sal_Int32(FieldUnit::NONE) ) && ( nUnitAsInt <= sal_Int32(FieldUnit::MM_100TH) ) )
393 eUnit =
static_cast< FieldUnit >( nUnitAsInt );
397 if ( FieldUnit::NONE == eUnit )
400 eUnit = MeasurementSystem::Metric == eSystem ? FieldUnit::CM : FieldUnit::INCH;
406 PropertyHandlerComponent::PropertyHandlerComponent(
const Reference< XComponentContext >& _rxContext )
MeasurementSystem getMeasurementSystemEnum() const
const LocaleDataWrapper & GetLocaleData() const
static sal_Int16 ConvertToMeasurementUnit(FieldUnit _nFieldUnit, sal_Int16 _rFieldToUNOValueFactor)
bool hasMoreElements() const
css::uno::Reference< ListenerT > const & next()
an implementation of the IPropertyEnumRepresentation
PropertyHandler implementation which additionally supports XServiceInfo.
the base class for property handlers
PropertyHandler(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
const_iterator end() const
const ELEMENT * const_iterator
css::uno::Any getNodeValue(const OUString &_rPath) const noexcept
static OConfigurationTreeRoot createWithComponentContext(const css::uno::Reference< css::uno::XComponentContext > &_rxContext, const OUString &_rPath, sal_Int32 _nDepth=-1, CREATION_MODE _eMode=CM_UPDATABLE)
#define DBG_ASSERT(sCon, aError)
Reference< XComponentContext > m_xContext
void removeListener(const InterfaceRef &xObject, const css::uno::Reference< css::lang::XEventListener > &xListener)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
a property handler for any virtual string properties
::cppu::WeakComponentImplHelper< css::inspection::XPropertyHandler > PropertyHandler_Base
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
#define IMPLEMENT_FORWARD_XCOMPONENT(classname, baseclass)