1*2a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2a97ec55SAndrew Rist  * distributed with this work for additional information
6*2a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
9*2a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2a97ec55SAndrew Rist  *
11*2a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2a97ec55SAndrew Rist  *
13*2a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2a97ec55SAndrew Rist  * software distributed under the License is distributed on an
15*2a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2a97ec55SAndrew Rist  * specific language governing permissions and limitations
18*2a97ec55SAndrew Rist  * under the License.
19*2a97ec55SAndrew Rist  *
20*2a97ec55SAndrew Rist  *************************************************************/
21*2a97ec55SAndrew Rist 
22*2a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir #include "propertyhandler.hxx"
27cdf0e10cSrcweir #include "formmetadata.hxx"
28cdf0e10cSrcweir #include "formbrowsertools.hxx"
29cdf0e10cSrcweir #include "handlerhelper.hxx"
30cdf0e10cSrcweir #include "formstrings.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir /** === begin UNO includes === **/
33cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
34cdf0e10cSrcweir #include <com/sun/star/lang/NullPointerException.hpp>
35cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
36cdf0e10cSrcweir /** === end UNO includes === **/
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <tools/debug.hxx>
39cdf0e10cSrcweir #include <unotools/confignode.hxx>
40cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
41cdf0e10cSrcweir #include <unotools/syslocale.hxx>
42cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <algorithm>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir //........................................................................
47cdf0e10cSrcweir namespace pcr
48cdf0e10cSrcweir {
49cdf0e10cSrcweir //........................................................................
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
52cdf0e10cSrcweir     using namespace ::com::sun::star::awt;
53cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
54cdf0e10cSrcweir     using namespace ::com::sun::star::script;
55cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
56cdf0e10cSrcweir     using namespace ::com::sun::star::util;
57cdf0e10cSrcweir     using namespace ::com::sun::star::frame;
58cdf0e10cSrcweir     using namespace ::com::sun::star::inspection;
59cdf0e10cSrcweir     using namespace ::comphelper;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     //====================================================================
62cdf0e10cSrcweir     //= PropertyHandler
63cdf0e10cSrcweir     //====================================================================
DBG_NAME(PropertyHandler)64cdf0e10cSrcweir     DBG_NAME( PropertyHandler )
65cdf0e10cSrcweir     //--------------------------------------------------------------------
66cdf0e10cSrcweir     PropertyHandler::PropertyHandler( const Reference< XComponentContext >& _rxContext )
67cdf0e10cSrcweir         :PropertyHandler_Base( m_aMutex )
68cdf0e10cSrcweir         ,m_bSupportedPropertiesAreKnown( false )
69cdf0e10cSrcweir         ,m_aPropertyListeners( m_aMutex )
70cdf0e10cSrcweir         ,m_aContext( _rxContext )
71cdf0e10cSrcweir         ,m_pInfoService  ( new OPropertyInfoService )
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         DBG_CTOR( PropertyHandler, NULL );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 		m_xTypeConverter = Reference< XTypeConverter >(
76cdf0e10cSrcweir 			m_aContext.createComponent( "com.sun.star.script.Converter" ),
77cdf0e10cSrcweir 			UNO_QUERY_THROW
78cdf0e10cSrcweir 		);
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     //--------------------------------------------------------------------
~PropertyHandler()82cdf0e10cSrcweir     PropertyHandler::~PropertyHandler()
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir         DBG_DTOR( PropertyHandler, NULL );
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     //--------------------------------------------------------------------
inspect(const Reference<XInterface> & _rxIntrospectee)88cdf0e10cSrcweir     void SAL_CALL PropertyHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException)
89cdf0e10cSrcweir     {
90cdf0e10cSrcweir         if ( !_rxIntrospectee.is() )
91cdf0e10cSrcweir             throw NullPointerException();
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         Reference< XPropertySet > xNewComponent( _rxIntrospectee, UNO_QUERY );
96cdf0e10cSrcweir         if ( xNewComponent == m_xComponent )
97cdf0e10cSrcweir             return;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         // remove all old property change listeners
100cdf0e10cSrcweir         ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > removeListener = m_aPropertyListeners.createIterator();
101cdf0e10cSrcweir         ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > readdListener = m_aPropertyListeners.createIterator();  // will copy the container as needed
102cdf0e10cSrcweir         while ( removeListener->hasMoreElements() )
103cdf0e10cSrcweir             removePropertyChangeListener( static_cast< XPropertyChangeListener* >( removeListener->next() ) );
104cdf0e10cSrcweir         OSL_ENSURE( m_aPropertyListeners.empty(), "PropertyHandler::inspect: derived classes are expected to forward the removePropertyChangeListener call to their base class (me)!" );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         // remember the new component, and give derived classes the chance to react on it
107cdf0e10cSrcweir         m_xComponent = xNewComponent;
108cdf0e10cSrcweir         onNewComponent();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         // add the listeners, again
111cdf0e10cSrcweir         while ( readdListener->hasMoreElements() )
112cdf0e10cSrcweir             addPropertyChangeListener( static_cast< XPropertyChangeListener* >( readdListener->next() ) );
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     //--------------------------------------------------------------------
onNewComponent()116cdf0e10cSrcweir     void PropertyHandler::onNewComponent()
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         if ( m_xComponent.is() )
119cdf0e10cSrcweir             m_xComponentPropertyInfo = m_xComponent->getPropertySetInfo();
120cdf0e10cSrcweir         else
121cdf0e10cSrcweir             m_xComponentPropertyInfo.clear();
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         m_bSupportedPropertiesAreKnown = false;
124cdf0e10cSrcweir         m_aSupportedProperties.realloc( 0 );
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     //--------------------------------------------------------------------
getSupportedProperties()128cdf0e10cSrcweir     Sequence< Property > SAL_CALL PropertyHandler::getSupportedProperties() throw (RuntimeException)
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
131cdf0e10cSrcweir         if ( !m_bSupportedPropertiesAreKnown )
132cdf0e10cSrcweir         {
133cdf0e10cSrcweir             m_aSupportedProperties = doDescribeSupportedProperties();
134cdf0e10cSrcweir             m_bSupportedPropertiesAreKnown = true;
135cdf0e10cSrcweir         }
136cdf0e10cSrcweir         return (Sequence< Property >)m_aSupportedProperties;
137cdf0e10cSrcweir     }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     //--------------------------------------------------------------------
getSupersededProperties()140cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL PropertyHandler::getSupersededProperties( ) throw (RuntimeException)
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         return Sequence< ::rtl::OUString >();
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     //--------------------------------------------------------------------
getActuatingProperties()146cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL PropertyHandler::getActuatingProperties( ) throw (RuntimeException)
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir         return Sequence< ::rtl::OUString >();
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     //--------------------------------------------------------------------
convertToPropertyValue(const::rtl::OUString & _rPropertyName,const Any & _rControlValue)152cdf0e10cSrcweir     Any SAL_CALL PropertyHandler::convertToPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException)
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
155cdf0e10cSrcweir         PropertyId nPropId = m_pInfoService->getPropertyId( _rPropertyName );
156cdf0e10cSrcweir         Property aProperty( impl_getPropertyFromName_throw( _rPropertyName ) );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         Any aPropertyValue;
159cdf0e10cSrcweir         if ( !_rControlValue.hasValue() )
160cdf0e10cSrcweir             // NULL is converted to NULL
161cdf0e10cSrcweir             return aPropertyValue;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         if ( ( m_pInfoService->getPropertyUIFlags( nPropId ) & PROP_FLAG_ENUM ) != 0 )
164cdf0e10cSrcweir         {
165cdf0e10cSrcweir             ::rtl::OUString sControlValue;
166cdf0e10cSrcweir             OSL_VERIFY( _rControlValue >>= sControlValue );
167cdf0e10cSrcweir             ::rtl::Reference< IPropertyEnumRepresentation > aEnumConversion(
168cdf0e10cSrcweir                 new DefaultEnumRepresentation( *m_pInfoService, aProperty.Type, nPropId ) );
169cdf0e10cSrcweir             // TODO/UNOize: cache those converters?
170cdf0e10cSrcweir             aEnumConversion->getValueFromDescription( sControlValue, aPropertyValue );
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir         else
173cdf0e10cSrcweir             aPropertyValue = PropertyHandlerHelper::convertToPropertyValue(
174cdf0e10cSrcweir                 m_aContext.getContext(),m_xTypeConverter, aProperty, _rControlValue );
175cdf0e10cSrcweir         return aPropertyValue;
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     //--------------------------------------------------------------------
convertToControlValue(const::rtl::OUString & _rPropertyName,const Any & _rPropertyValue,const Type & _rControlValueType)179cdf0e10cSrcweir     Any SAL_CALL PropertyHandler::convertToControlValue( const ::rtl::OUString& _rPropertyName, const Any& _rPropertyValue, const Type& _rControlValueType ) throw (UnknownPropertyException, RuntimeException)
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
182cdf0e10cSrcweir         PropertyId nPropId = m_pInfoService->getPropertyId( _rPropertyName );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         if ( ( m_pInfoService->getPropertyUIFlags( nPropId ) & PROP_FLAG_ENUM ) != 0 )
185cdf0e10cSrcweir         {
186cdf0e10cSrcweir             DBG_ASSERT( _rControlValueType.getTypeClass() == TypeClass_STRING, "PropertyHandler::convertToControlValue: ENUM, but not STRING?" );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             ::rtl::Reference< IPropertyEnumRepresentation > aEnumConversion(
189cdf0e10cSrcweir                 new DefaultEnumRepresentation( *m_pInfoService, _rPropertyValue.getValueType(), nPropId ) );
190cdf0e10cSrcweir             // TODO/UNOize: cache those converters?
191cdf0e10cSrcweir             return makeAny( aEnumConversion->getDescriptionForValue( _rPropertyValue ) );
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir         return PropertyHandlerHelper::convertToControlValue(
195cdf0e10cSrcweir             m_aContext.getContext(),m_xTypeConverter, _rPropertyValue, _rControlValueType );
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     //--------------------------------------------------------------------
getPropertyState(const::rtl::OUString &)199cdf0e10cSrcweir     PropertyState SAL_CALL PropertyHandler::getPropertyState( const ::rtl::OUString& /*_rPropertyName*/ ) throw (UnknownPropertyException, RuntimeException)
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         return PropertyState_DIRECT_VALUE;
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     //--------------------------------------------------------------------
describePropertyLine(const::rtl::OUString & _rPropertyName,const Reference<XPropertyControlFactory> & _rxControlFactory)205cdf0e10cSrcweir     LineDescriptor SAL_CALL PropertyHandler::describePropertyLine( const ::rtl::OUString& _rPropertyName,
206cdf0e10cSrcweir         const Reference< XPropertyControlFactory >& _rxControlFactory )
207cdf0e10cSrcweir         throw (UnknownPropertyException, NullPointerException, RuntimeException)
208cdf0e10cSrcweir     {
209cdf0e10cSrcweir         if ( !_rxControlFactory.is() )
210cdf0e10cSrcweir             throw NullPointerException();
211cdf0e10cSrcweir 
212cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
213cdf0e10cSrcweir         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
214cdf0e10cSrcweir         const Property& rProperty( impl_getPropertyFromId_throw( nPropId ) );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir         LineDescriptor aDescriptor;
217cdf0e10cSrcweir         if ( ( m_pInfoService->getPropertyUIFlags( nPropId ) & PROP_FLAG_ENUM ) != 0 )
218cdf0e10cSrcweir         {
219cdf0e10cSrcweir             aDescriptor.Control = PropertyHandlerHelper::createListBoxControl(
220cdf0e10cSrcweir                 _rxControlFactory, m_pInfoService->getPropertyEnumRepresentations( nPropId ),
221cdf0e10cSrcweir                 PropertyHandlerHelper::requiresReadOnlyControl( rProperty.Attributes ), sal_False );
222cdf0e10cSrcweir         }
223cdf0e10cSrcweir         else
224cdf0e10cSrcweir             PropertyHandlerHelper::describePropertyLine( rProperty, aDescriptor, _rxControlFactory );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir         aDescriptor.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nPropId ) );
227cdf0e10cSrcweir         aDescriptor.DisplayName = m_pInfoService->getPropertyTranslation( nPropId );
228cdf0e10cSrcweir 
229cdf0e10cSrcweir         if ( ( m_pInfoService->getPropertyUIFlags( nPropId ) & PROP_FLAG_DATA_PROPERTY ) != 0 )
230cdf0e10cSrcweir             aDescriptor.Category = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Data" ) );
231cdf0e10cSrcweir         else
232cdf0e10cSrcweir             aDescriptor.Category = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "General" ) );
233cdf0e10cSrcweir         return aDescriptor;
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     //--------------------------------------------------------------------
isComposable(const::rtl::OUString & _rPropertyName)237cdf0e10cSrcweir     ::sal_Bool SAL_CALL PropertyHandler::isComposable( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
238cdf0e10cSrcweir     {
239cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
240cdf0e10cSrcweir         return m_pInfoService->isComposeable( _rPropertyName );
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     //--------------------------------------------------------------------
onInteractivePropertySelection(const::rtl::OUString &,sal_Bool,Any &,const Reference<XObjectInspectorUI> &)244cdf0e10cSrcweir     InteractiveSelectionResult SAL_CALL PropertyHandler::onInteractivePropertySelection( const ::rtl::OUString& /*_rPropertyName*/, sal_Bool /*_bPrimary*/, Any& /*_rData*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/ ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
245cdf0e10cSrcweir     {
246cdf0e10cSrcweir         DBG_ERROR( "PropertyHandler::onInteractivePropertySelection: not implemented!" );
247cdf0e10cSrcweir         return InteractiveSelectionResult_Cancelled;
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir     //--------------------------------------------------------------------
actuatingPropertyChanged(const::rtl::OUString &,const Any &,const Any &,const Reference<XObjectInspectorUI> &,sal_Bool)251cdf0e10cSrcweir     void SAL_CALL PropertyHandler::actuatingPropertyChanged( const ::rtl::OUString& /*_rActuatingPropertyName*/, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/, sal_Bool /*_bFirstTimeInit*/ ) throw (NullPointerException, RuntimeException)
252cdf0e10cSrcweir     {
253cdf0e10cSrcweir         DBG_ERROR( "PropertyHandler::actuatingPropertyChanged: not implemented!" );
254cdf0e10cSrcweir     }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     //--------------------------------------------------------------------
addPropertyChangeListener(const Reference<XPropertyChangeListener> & _rxListener)257cdf0e10cSrcweir     void SAL_CALL PropertyHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException)
258cdf0e10cSrcweir     {
259cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
260cdf0e10cSrcweir         if ( !_rxListener.is() )
261cdf0e10cSrcweir             throw NullPointerException();
262cdf0e10cSrcweir         m_aPropertyListeners.addListener( _rxListener );
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     //--------------------------------------------------------------------
removePropertyChangeListener(const Reference<XPropertyChangeListener> & _rxListener)266cdf0e10cSrcweir     void SAL_CALL PropertyHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException)
267cdf0e10cSrcweir     {
268cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
269cdf0e10cSrcweir         m_aPropertyListeners.removeListener( _rxListener );
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     //--------------------------------------------------------------------
suspend(sal_Bool)273cdf0e10cSrcweir     sal_Bool SAL_CALL PropertyHandler::suspend( sal_Bool /*_bSuspend*/ ) throw (RuntimeException)
274cdf0e10cSrcweir     {
275cdf0e10cSrcweir         return sal_True;
276cdf0e10cSrcweir     }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     //--------------------------------------------------------------------
IMPLEMENT_FORWARD_XCOMPONENT(PropertyHandler,PropertyHandler_Base)279cdf0e10cSrcweir     IMPLEMENT_FORWARD_XCOMPONENT( PropertyHandler, PropertyHandler_Base )
280cdf0e10cSrcweir     //--------------------------------------------------------------------
281cdf0e10cSrcweir     void SAL_CALL PropertyHandler::disposing()
282cdf0e10cSrcweir     {
283cdf0e10cSrcweir         m_xComponent.clear();
284cdf0e10cSrcweir         m_aPropertyListeners.clear();
285cdf0e10cSrcweir         m_xTypeConverter.clear();
286cdf0e10cSrcweir         m_aSupportedProperties.realloc( 0 );
287cdf0e10cSrcweir     }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir     //--------------------------------------------------------------------
firePropertyChange(const::rtl::OUString & _rPropName,PropertyId _nPropId,const Any & _rOldValue,const Any & _rNewValue)290cdf0e10cSrcweir     void PropertyHandler::firePropertyChange( const ::rtl::OUString& _rPropName, PropertyId _nPropId, const Any& _rOldValue, const Any& _rNewValue ) SAL_THROW(())
291cdf0e10cSrcweir     {
292cdf0e10cSrcweir         PropertyChangeEvent aEvent;
293cdf0e10cSrcweir         aEvent.Source = m_xComponent;
294cdf0e10cSrcweir         aEvent.PropertyHandle = _nPropId;
295cdf0e10cSrcweir         aEvent.PropertyName = _rPropName;
296cdf0e10cSrcweir         aEvent.OldValue = _rOldValue;
297cdf0e10cSrcweir         aEvent.NewValue = _rNewValue;
298cdf0e10cSrcweir         m_aPropertyListeners.notify( aEvent, &XPropertyChangeListener::propertyChange );
299cdf0e10cSrcweir     }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir     //--------------------------------------------------------------------
impl_getPropertyFromId_nothrow(PropertyId _nPropId) const302cdf0e10cSrcweir     const Property* PropertyHandler::impl_getPropertyFromId_nothrow( PropertyId _nPropId ) const
303cdf0e10cSrcweir     {
304cdf0e10cSrcweir         const_cast< PropertyHandler* >( this )->getSupportedProperties();
305cdf0e10cSrcweir         const Property* pFound = ::std::find_if( m_aSupportedProperties.begin(), m_aSupportedProperties.end(),
306cdf0e10cSrcweir             FindPropertyByHandle( _nPropId )
307cdf0e10cSrcweir         );
308cdf0e10cSrcweir         if ( pFound != m_aSupportedProperties.end() )
309cdf0e10cSrcweir             return &(*pFound);
310cdf0e10cSrcweir         return NULL;
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir     //--------------------------------------------------------------------
impl_getPropertyFromId_throw(PropertyId _nPropId) const314cdf0e10cSrcweir     const Property& PropertyHandler::impl_getPropertyFromId_throw( PropertyId _nPropId ) const
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         const Property* pProperty = impl_getPropertyFromId_nothrow( _nPropId );
317cdf0e10cSrcweir         if ( !pProperty )
318cdf0e10cSrcweir             throw UnknownPropertyException();
319cdf0e10cSrcweir 
320cdf0e10cSrcweir         return *pProperty;
321cdf0e10cSrcweir     }
322cdf0e10cSrcweir 
323cdf0e10cSrcweir     //--------------------------------------------------------------------
impl_getPropertyFromName_throw(const::rtl::OUString & _rPropertyName) const324cdf0e10cSrcweir     const Property& PropertyHandler::impl_getPropertyFromName_throw( const ::rtl::OUString& _rPropertyName ) const
325cdf0e10cSrcweir     {
326cdf0e10cSrcweir         const_cast< PropertyHandler* >( this )->getSupportedProperties();
327cdf0e10cSrcweir         StlSyntaxSequence< Property >::const_iterator pFound = ::std::find_if( m_aSupportedProperties.begin(), m_aSupportedProperties.end(),
328cdf0e10cSrcweir             FindPropertyByName( _rPropertyName )
329cdf0e10cSrcweir         );
330cdf0e10cSrcweir         if ( pFound == m_aSupportedProperties.end() )
331cdf0e10cSrcweir             throw UnknownPropertyException();
332cdf0e10cSrcweir 
333cdf0e10cSrcweir         return *pFound;
334cdf0e10cSrcweir     }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     //--------------------------------------------------------------------
implAddPropertyDescription(::std::vector<Property> & _rProperties,const::rtl::OUString & _rPropertyName,const Type & _rType,sal_Int16 _nAttribs) const337cdf0e10cSrcweir     void PropertyHandler::implAddPropertyDescription( ::std::vector< Property >& _rProperties, const ::rtl::OUString& _rPropertyName, const Type& _rType, sal_Int16 _nAttribs ) const
338cdf0e10cSrcweir     {
339cdf0e10cSrcweir         _rProperties.push_back( Property(
340cdf0e10cSrcweir             _rPropertyName,
341cdf0e10cSrcweir             m_pInfoService->getPropertyId( _rPropertyName ),
342cdf0e10cSrcweir             _rType,
343cdf0e10cSrcweir             _nAttribs
344cdf0e10cSrcweir         ) );
345cdf0e10cSrcweir     }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     //------------------------------------------------------------------------
impl_getDefaultDialogParent_nothrow() const348cdf0e10cSrcweir     Window* PropertyHandler::impl_getDefaultDialogParent_nothrow() const
349cdf0e10cSrcweir     {
350cdf0e10cSrcweir         return PropertyHandlerHelper::getDialogParentWindow( m_aContext );
351cdf0e10cSrcweir     }
352cdf0e10cSrcweir 
353cdf0e10cSrcweir     //------------------------------------------------------------------------
impl_getPropertyId_throw(const::rtl::OUString & _rPropertyName) const354cdf0e10cSrcweir     PropertyId PropertyHandler::impl_getPropertyId_throw( const ::rtl::OUString& _rPropertyName ) const
355cdf0e10cSrcweir     {
356cdf0e10cSrcweir         PropertyId nPropId = m_pInfoService->getPropertyId( _rPropertyName );
357cdf0e10cSrcweir         if ( nPropId == -1 )
358cdf0e10cSrcweir             throw UnknownPropertyException();
359cdf0e10cSrcweir         return nPropId;
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     //------------------------------------------------------------------------
impl_setContextDocumentModified_nothrow() const363cdf0e10cSrcweir     void PropertyHandler::impl_setContextDocumentModified_nothrow() const
364cdf0e10cSrcweir     {
365cdf0e10cSrcweir         Reference< XModifiable > xModifiable( impl_getContextDocument_nothrow(), UNO_QUERY );
366cdf0e10cSrcweir         if ( xModifiable.is() )
367cdf0e10cSrcweir 			xModifiable->setModified( sal_True );
368cdf0e10cSrcweir     }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     //------------------------------------------------------------------------
impl_componentHasProperty_throw(const::rtl::OUString & _rPropName) const371cdf0e10cSrcweir     bool PropertyHandler::impl_componentHasProperty_throw( const ::rtl::OUString& _rPropName ) const
372cdf0e10cSrcweir     {
373cdf0e10cSrcweir         return m_xComponentPropertyInfo.is() && m_xComponentPropertyInfo->hasPropertyByName( _rPropName );
374cdf0e10cSrcweir     }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 	//--------------------------------------------------------------------
impl_getDocumentMeasurementUnit_throw() const377cdf0e10cSrcweir     sal_Int16 PropertyHandler::impl_getDocumentMeasurementUnit_throw() const
378cdf0e10cSrcweir     {
379cdf0e10cSrcweir         FieldUnit eUnit = FUNIT_NONE;
380cdf0e10cSrcweir 
381cdf0e10cSrcweir         Reference< XServiceInfo > xDocumentSI( impl_getContextDocument_nothrow(), UNO_QUERY );
382cdf0e10cSrcweir         OSL_ENSURE( xDocumentSI.is(), "PropertyHandlerHelper::impl_getDocumentMeasurementUnit_throw: No context document - where do I live?" );
383cdf0e10cSrcweir         if ( xDocumentSI.is() )
384cdf0e10cSrcweir         {
385cdf0e10cSrcweir             // determine the application type we live in
386cdf0e10cSrcweir             ::rtl::OUString sConfigurationLocation;
387cdf0e10cSrcweir             ::rtl::OUString sConfigurationProperty;
388cdf0e10cSrcweir             if ( xDocumentSI->supportsService( SERVICE_WEB_DOCUMENT ) )
389cdf0e10cSrcweir             {   // writer
390cdf0e10cSrcweir                 sConfigurationLocation = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.WriterWeb/Layout/Other" ) );
391cdf0e10cSrcweir                 sConfigurationProperty = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MeasureUnit" ) );
392cdf0e10cSrcweir             }
393cdf0e10cSrcweir             else if ( xDocumentSI->supportsService( SERVICE_TEXT_DOCUMENT ) )
394cdf0e10cSrcweir             {   // writer
395cdf0e10cSrcweir                 sConfigurationLocation = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Writer/Layout/Other" ) );
396cdf0e10cSrcweir                 sConfigurationProperty = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MeasureUnit" ) );
397cdf0e10cSrcweir             }
398cdf0e10cSrcweir             else if ( xDocumentSI->supportsService( SERVICE_SPREADSHEET_DOCUMENT ) )
399cdf0e10cSrcweir             {   // calc
400cdf0e10cSrcweir                 sConfigurationLocation = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Calc/Layout/Other/MeasureUnit" ) );
401cdf0e10cSrcweir                 sConfigurationProperty = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Metric" ) );
402cdf0e10cSrcweir             }
403cdf0e10cSrcweir             else if ( xDocumentSI->supportsService( SERVICE_DRAWING_DOCUMENT ) )
404cdf0e10cSrcweir             {
405cdf0e10cSrcweir                 sConfigurationLocation = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Draw/Layout/Other/MeasureUnit" ) );
406cdf0e10cSrcweir                 sConfigurationProperty = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Metric" ) );
407cdf0e10cSrcweir             }
408cdf0e10cSrcweir             else if ( xDocumentSI->supportsService( SERVICE_PRESENTATION_DOCUMENT ) )
409cdf0e10cSrcweir             {
410cdf0e10cSrcweir                 sConfigurationLocation = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Impress/Layout/Other/MeasureUnit" ) );
411cdf0e10cSrcweir                 sConfigurationProperty = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Metric" ) );
412cdf0e10cSrcweir             }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir             // read the measurement unit from the configuration
415cdf0e10cSrcweir             if ( sConfigurationLocation.getLength() && sConfigurationProperty.getLength() )
416cdf0e10cSrcweir             {
417cdf0e10cSrcweir                 ::utl::OConfigurationTreeRoot aConfigTree( ::utl::OConfigurationTreeRoot::createWithServiceFactory(
418cdf0e10cSrcweir                     m_aContext.getLegacyServiceFactory(), sConfigurationLocation, -1, ::utl::OConfigurationTreeRoot::CM_READONLY ) );
419cdf0e10cSrcweir                 sal_Int32 nUnitAsInt = (sal_Int32)FUNIT_NONE;
420cdf0e10cSrcweir                 aConfigTree.getNodeValue( sConfigurationProperty ) >>= nUnitAsInt;
421cdf0e10cSrcweir 
422cdf0e10cSrcweir                 // if this denotes a valid (and accepted) unit, then use it
423cdf0e10cSrcweir                 if  ( ( nUnitAsInt > FUNIT_NONE ) && ( nUnitAsInt <= FUNIT_100TH_MM ) )
424cdf0e10cSrcweir                     eUnit = static_cast< FieldUnit >( nUnitAsInt );
425cdf0e10cSrcweir             }
426cdf0e10cSrcweir         }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         if ( FUNIT_NONE == eUnit )
429cdf0e10cSrcweir         {
430cdf0e10cSrcweir             MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
431cdf0e10cSrcweir             eUnit = MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH;
432cdf0e10cSrcweir         }
433cdf0e10cSrcweir 
434cdf0e10cSrcweir         return VCLUnoHelper::ConvertToMeasurementUnit( eUnit, 1 );
435cdf0e10cSrcweir     }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     //====================================================================
438cdf0e10cSrcweir 	//= PropertyHandlerComponent
439cdf0e10cSrcweir 	//====================================================================
440cdf0e10cSrcweir     //------------------------------------------------------------------------
PropertyHandlerComponent(const Reference<XComponentContext> & _rxContext)441cdf0e10cSrcweir     PropertyHandlerComponent::PropertyHandlerComponent( const Reference< XComponentContext >& _rxContext )
442cdf0e10cSrcweir         :PropertyHandler( _rxContext )
443cdf0e10cSrcweir     {
444cdf0e10cSrcweir     }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir     //--------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(PropertyHandlerComponent,PropertyHandler,PropertyHandlerComponent_Base)447cdf0e10cSrcweir     IMPLEMENT_FORWARD_XINTERFACE2( PropertyHandlerComponent, PropertyHandler, PropertyHandlerComponent_Base )
448cdf0e10cSrcweir     IMPLEMENT_FORWARD_XTYPEPROVIDER2( PropertyHandlerComponent, PropertyHandler, PropertyHandlerComponent_Base )
449cdf0e10cSrcweir 
450cdf0e10cSrcweir     //--------------------------------------------------------------------
451cdf0e10cSrcweir     ::sal_Bool SAL_CALL PropertyHandlerComponent::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException)
452cdf0e10cSrcweir     {
453cdf0e10cSrcweir         StlSyntaxSequence< ::rtl::OUString > aAllServices( getSupportedServiceNames() );
454cdf0e10cSrcweir         return ::std::find( aAllServices.begin(), aAllServices.end(), ServiceName ) != aAllServices.end();
455cdf0e10cSrcweir     }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir //........................................................................
458cdf0e10cSrcweir }   // namespace pcr
459cdf0e10cSrcweir //........................................................................
460cdf0e10cSrcweir 
461