Bump for 3.6-28
[LibreOffice.git] / extensions / source / propctrlr / propertyhandler.hxx
blob1fffc177b82f225d56f32a0ed41343d72c9c7128
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_PROPERTYHANDLER_HXX
30 #define EXTENSIONS_SOURCE_PROPCTRLR_PROPERTYHANDLER_HXX
32 #include "pcrcomponentcontext.hxx"
33 #include "pcrcommon.hxx"
34 #include "modulepcr.hxx"
36 /** === begin UNO includes === **/
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <com/sun/star/beans/PropertyState.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/beans/Property.hpp>
41 #include <com/sun/star/script/XTypeConverter.hpp>
42 #include <com/sun/star/frame/XModel.hpp>
43 #include <com/sun/star/uno/Sequence.hxx>
44 #include <com/sun/star/uno/Any.hxx>
45 #include <com/sun/star/util/Date.hpp>
46 #include <com/sun/star/util/Time.hpp>
47 #include <com/sun/star/util/DateTime.hpp>
48 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
49 #include <com/sun/star/inspection/XPropertyHandler.hpp>
50 #include <com/sun/star/lang/XServiceInfo.hpp>
51 /** === end UNO includes === **/
52 #include <osl/interlck.h>
53 #include <cppuhelper/compbase1.hxx>
54 #include <cppuhelper/implbase1.hxx>
55 #include <comphelper/uno3.hxx>
57 #include <memory>
58 #include <vector>
60 namespace com { namespace sun { namespace star {
61 namespace inspection {
62 struct LineDescriptor;
63 class XPropertyControlFactory;
65 } } }
67 class Window;
68 //........................................................................
69 namespace pcr
71 //........................................................................
73 typedef sal_Int32 PropertyId;
75 //====================================================================
76 //= PropertyHandler
77 //====================================================================
78 class OPropertyInfoService;
79 typedef ::cppu::WeakComponentImplHelper1 < ::com::sun::star::inspection::XPropertyHandler
80 > PropertyHandler_Base;
81 /** the base class for property handlers
83 class PropertyHandler : public PropertyHandler_Base
85 private:
86 /// cache for getSupportedProperties
87 mutable StlSyntaxSequence< ::com::sun::star::beans::Property >
88 m_aSupportedProperties;
89 mutable bool m_bSupportedPropertiesAreKnown;
91 /// helper which ensures that we can access resources as long as the instance lives
92 PcrClient m_aEnsureResAccess;
94 private:
95 /// the property listener which has been registered
96 PropertyChangeListeners m_aPropertyListeners;
98 protected:
99 mutable ::osl::Mutex m_aMutex;
100 /// the context in which the instance was created
101 ComponentContext m_aContext;
102 /// the component we're inspecting
103 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xComponent;
104 /// info about our component's properties
105 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > m_xComponentPropertyInfo;
106 /// type converter, needed on various occasions
107 ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter > m_xTypeConverter;
108 /// access to property meta data
109 ::std::auto_ptr< OPropertyInfoService > m_pInfoService;
111 protected:
112 PropertyHandler(
113 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext
115 ~PropertyHandler();
117 // default implementations for XPropertyHandler
118 virtual void SAL_CALL inspect( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxIntrospectee ) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::NullPointerException);
119 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL getSupportedProperties() throw (::com::sun::star::uno::RuntimeException);
120 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupersededProperties( ) throw (::com::sun::star::uno::RuntimeException);
121 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getActuatingProperties( ) throw (::com::sun::star::uno::RuntimeException);
122 virtual ::com::sun::star::uno::Any SAL_CALL convertToPropertyValue( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rControlValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
123 virtual ::com::sun::star::uno::Any SAL_CALL convertToControlValue( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rPropertyValue, const ::com::sun::star::uno::Type& _rControlValueType ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
124 virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
125 virtual ::com::sun::star::inspection::LineDescriptor SAL_CALL describePropertyLine( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException);
126 virtual ::sal_Bool SAL_CALL isComposable( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
127 virtual ::com::sun::star::inspection::InteractiveSelectionResult SAL_CALL onInteractivePropertySelection( const ::rtl::OUString& _rPropertyName, sal_Bool _bPrimary, ::com::sun::star::uno::Any& _rData, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI >& _rxInspectorUI ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException);
128 virtual void SAL_CALL actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const ::com::sun::star::uno::Any& _rNewValue, const ::com::sun::star::uno::Any& _rOldValue, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI >& _rxInspectorUI, sal_Bool _bFirstTimeInit ) throw (::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException);
129 virtual void SAL_CALL addPropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
130 virtual void SAL_CALL removePropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
131 virtual sal_Bool SAL_CALL suspend( sal_Bool _bSuspend ) throw (::com::sun::star::uno::RuntimeException);
133 // XComponent
134 DECLARE_XCOMPONENT()
135 virtual void SAL_CALL disposing();
137 // own overridables
138 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >
139 SAL_CALL doDescribeSupportedProperties() const = 0;
141 /// called when XPropertyHandler::inspect has been called, and we thus have a new component to inspect
142 virtual void onNewComponent();
144 protected:
145 /** fires the change in a property value to our listener (if any)
146 @see addPropertyChangeListener
148 void firePropertyChange( const ::rtl::OUString& _rPropName, PropertyId _nPropId,
149 const ::com::sun::star::uno::Any& _rOldValue, const ::com::sun::star::uno::Any& _rNewValue ) SAL_THROW(());
151 /** retrieves a window which can be used as parent for dialogs
153 Window* impl_getDefaultDialogParent_nothrow() const;
155 /** retrieves the property id for a given property name
156 @throw com::sun::star::beans::UnknownPropertyException
157 if the property name is not known to our ->m_pInfoService
159 PropertyId impl_getPropertyId_throw( const ::rtl::OUString& _rPropertyName ) const;
161 //-------------------------------------------------------------------------------
162 // helper for implementing doDescribeSupportedProperties
163 /** adds a description for the given string property to the given property vector
164 Most probably to be called from within getSupportedProperties
166 inline void addStringPropertyDescription(
167 ::std::vector< ::com::sun::star::beans::Property >& _rProperties,
168 const ::rtl::OUString& _rPropertyName,
169 sal_Int16 _nAttribs = 0
170 ) const;
172 /** adds a description for the given int32 property to the given property vector
174 inline void addInt32PropertyDescription(
175 ::std::vector< ::com::sun::star::beans::Property >& _rProperties,
176 const ::rtl::OUString& _rPropertyName,
177 sal_Int16 _nAttribs = 0
178 ) const;
180 /** adds a description for the given int16 property to the given property vector
182 inline void addInt16PropertyDescription(
183 ::std::vector< ::com::sun::star::beans::Property >& _rProperties,
184 const ::rtl::OUString& _rPropertyName,
185 sal_Int16 _nAttribs = 0
186 ) const;
188 /** adds a description for the given double property to the given property vector
190 inline void addDoublePropertyDescription(
191 ::std::vector< ::com::sun::star::beans::Property >& _rProperties,
192 const ::rtl::OUString& _rPropertyName,
193 sal_Int16 _nAttribs = 0
194 ) const;
196 /** adds a description for the given date property to the given property vector
198 inline void addDatePropertyDescription(
199 ::std::vector< ::com::sun::star::beans::Property >& _rProperties,
200 const ::rtl::OUString& _rPropertyName,
201 sal_Int16 _nAttribs = 0
202 ) const;
204 /** adds a description for the given time property to the given property vector
206 inline void addTimePropertyDescription(
207 ::std::vector< ::com::sun::star::beans::Property >& _rProperties,
208 const ::rtl::OUString& _rPropertyName,
209 sal_Int16 _nAttribs = 0
210 ) const;
212 /** adds a description for the given DateTime property to the given property vector
214 inline void addDateTimePropertyDescription(
215 ::std::vector< ::com::sun::star::beans::Property >& _rProperties,
216 const ::rtl::OUString& _rPropertyName,
217 sal_Int16 _nAttribs = 0
218 ) const;
220 /// adds a Property, given by name only, to a given vector of Properties
221 void implAddPropertyDescription(
222 ::std::vector< ::com::sun::star::beans::Property >& _rProperties,
223 const ::rtl::OUString& _rPropertyName,
224 const ::com::sun::star::uno::Type& _rType,
225 sal_Int16 _nAttribs = 0
226 ) const;
228 //-------------------------------------------------------------------------------
229 // helper for accessing and maintaining meta data about our supported properties
231 /** retrieves a property given by handle
233 @return
234 a pointer to the descriptor for the given properties, if it is one of our
235 supported properties, <NULL/> else.
237 @see doDescribeSupportedProperties
238 @see impl_getPropertyFromId_throw
240 const ::com::sun::star::beans::Property*
241 impl_getPropertyFromId_nothrow( PropertyId _nPropId ) const;
243 /** retrieves a property given by handle
245 @throws UnknownPropertyException
246 if the handler does not support a property with the given handle
248 @seealso doDescribeSupportedProperties
249 @see impl_getPropertyFromId_nothrow
251 const ::com::sun::star::beans::Property&
252 impl_getPropertyFromId_throw( PropertyId _nPropId ) const;
254 /** determines whether a given property id is part of our supported properties
255 @see getSupportedProperties
256 @see doDescribeSupportedProperties
258 inline bool impl_isSupportedProperty_nothrow( PropertyId _nPropId ) const
260 return impl_getPropertyFromId_nothrow( _nPropId ) != NULL;
263 /** retrieves a property given by name
265 @throws UnknownPropertyException
266 if the handler does not support a property with the given name
268 @seealso doDescribeSupportedProperties
270 const ::com::sun::star::beans::Property&
271 impl_getPropertyFromName_throw( const ::rtl::OUString& _rPropertyName ) const;
273 /** get the name of a property given by handle
275 inline ::rtl::OUString
276 impl_getPropertyNameFromId_nothrow( PropertyId _nPropId ) const;
278 /** returns the value of the ContextDocument property in the ComponentContext which was used to create
279 this handler.
281 inline ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
282 impl_getContextDocument_nothrow() const
284 return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >(
285 m_aContext.getContextValueByAsciiName( "ContextDocument" ), ::com::sun::star::uno::UNO_QUERY );
288 /** marks the context document as modified
290 @see impl_getContextDocument_nothrow
292 void impl_setContextDocumentModified_nothrow() const;
294 /// determines whether our component has a given property
295 bool impl_componentHasProperty_throw( const ::rtl::OUString& _rPropName ) const;
297 /** determines the default measure unit for the document in which our component lives
299 sal_Int16 impl_getDocumentMeasurementUnit_throw() const;
301 private:
302 PropertyHandler(); // never implemented
303 PropertyHandler( const PropertyHandler& ); // never implemented
304 PropertyHandler& operator=( const PropertyHandler& ); // never implemented
307 //--------------------------------------------------------------------
308 inline void PropertyHandler::addStringPropertyDescription( ::std::vector< ::com::sun::star::beans::Property >& _rProperties, const ::rtl::OUString& _rPropertyName, sal_Int16 _nAttribs ) const
310 implAddPropertyDescription( _rProperties, _rPropertyName, ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) ), _nAttribs );
313 inline void PropertyHandler::addInt32PropertyDescription( ::std::vector< ::com::sun::star::beans::Property >& _rProperties, const ::rtl::OUString& _rPropertyName, sal_Int16 _nAttribs ) const
315 implAddPropertyDescription( _rProperties, _rPropertyName, ::getCppuType( static_cast< sal_Int32* >( NULL ) ), _nAttribs );
318 inline void PropertyHandler::addInt16PropertyDescription( ::std::vector< ::com::sun::star::beans::Property >& _rProperties, const ::rtl::OUString& _rPropertyName, sal_Int16 _nAttribs ) const
320 implAddPropertyDescription( _rProperties, _rPropertyName, ::getCppuType( static_cast< sal_Int16* >( NULL ) ), _nAttribs );
323 inline void PropertyHandler::addDoublePropertyDescription( ::std::vector< ::com::sun::star::beans::Property >& _rProperties, const ::rtl::OUString& _rPropertyName, sal_Int16 _nAttribs ) const
325 implAddPropertyDescription( _rProperties, _rPropertyName, ::getCppuType( static_cast< double* >( NULL ) ), _nAttribs );
328 inline void PropertyHandler::addDatePropertyDescription( ::std::vector< ::com::sun::star::beans::Property >& _rProperties, const ::rtl::OUString& _rPropertyName, sal_Int16 _nAttribs ) const
330 implAddPropertyDescription( _rProperties, _rPropertyName, ::getCppuType( static_cast< com::sun::star::util::Date* >( NULL ) ), _nAttribs );
333 inline void PropertyHandler::addTimePropertyDescription( ::std::vector< ::com::sun::star::beans::Property >& _rProperties, const ::rtl::OUString& _rPropertyName, sal_Int16 _nAttribs ) const
335 implAddPropertyDescription( _rProperties, _rPropertyName, ::getCppuType( static_cast< com::sun::star::util::Time* >( NULL ) ), _nAttribs );
338 inline void PropertyHandler::addDateTimePropertyDescription( ::std::vector< ::com::sun::star::beans::Property >& _rProperties, const ::rtl::OUString& _rPropertyName, sal_Int16 _nAttribs ) const
340 implAddPropertyDescription( _rProperties, _rPropertyName, ::getCppuType( static_cast< com::sun::star::util::DateTime* >( NULL ) ), _nAttribs );
343 inline ::rtl::OUString PropertyHandler::impl_getPropertyNameFromId_nothrow( PropertyId _nPropId ) const
345 const ::com::sun::star::beans::Property* pProp = impl_getPropertyFromId_nothrow( _nPropId );
346 return pProp ? pProp->Name : ::rtl::OUString();
349 //====================================================================
350 //= PropertyHandlerComponent
351 //====================================================================
352 typedef ::cppu::ImplHelper1 < ::com::sun::star::lang::XServiceInfo
353 > PropertyHandlerComponent_Base;
354 /** PropertyHandler implementation which additionally supports XServiceInfo
356 class PropertyHandlerComponent :public PropertyHandler
357 ,public PropertyHandlerComponent_Base
359 protected:
360 PropertyHandlerComponent(
361 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext
364 DECLARE_XINTERFACE()
365 DECLARE_XTYPEPROVIDER()
367 // XServiceInfo
368 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) = 0;
369 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
370 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException) = 0;
373 //====================================================================
374 //= HandlerComponentBase
375 //====================================================================
376 /** a PropertyHandlerComponent implementation which routes XServiceInfo::getImplementationName and
377 XServiceInfo::getSupportedServiceNames to static versions of those methods, which are part of
378 the derived class.
380 Additionally, a method <member>Create</member> is provided which takes a component context, and returns a new
381 instance of the derived class. This <member>Create</member> is used to register the implementation
382 of the derived class at the <type>PcrModule</type>.
384 Well, every time we're talking about derived class, we in fact mean the template argument of
385 <type>HandlerComponentBase</type>. But usually this equals your derived class:
386 <pre>
387 class MyHandler;
388 typedef HandlerComponentBase< MyHandler > MyHandler_Base;
389 class MyHandler : MyHandler_Base
392 public:
393 static ::rtl::OUString SAL_CALL getImplementationName_static( ) throw (::com::sun::star::uno::RuntimeException);
394 static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static( ) throw (::com::sun::star::uno::RuntimeException);
396 </pre>
398 template < class HANDLER >
399 class HandlerComponentBase : public PropertyHandlerComponent
401 protected:
402 HandlerComponentBase( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext )
403 :PropertyHandlerComponent( _rxContext )
407 protected:
408 // XServiceInfo
409 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
410 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
411 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
413 public:
414 /** registers the implementation of HANDLER at the <type>PcrModule</type>
416 static void registerImplementation();
419 //--------------------------------------------------------------------
420 template < class HANDLER >
421 ::rtl::OUString SAL_CALL HandlerComponentBase< HANDLER >::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException)
423 return HANDLER::getImplementationName_static();
426 //--------------------------------------------------------------------
427 template < class HANDLER >
428 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL HandlerComponentBase< HANDLER >::getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException)
430 return HANDLER::getSupportedServiceNames_static();
433 //--------------------------------------------------------------------
434 template < class HANDLER >
435 void HandlerComponentBase< HANDLER >::registerImplementation()
437 PcrModule::getInstance().registerImplementation(
438 HANDLER::getImplementationName_static(),
439 HANDLER::getSupportedServiceNames_static(),
440 HANDLER::Create
444 //--------------------------------------------------------------------
445 template < class HANDLER >
446 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL HandlerComponentBase< HANDLER >::Create( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext )
448 return *( new HANDLER( _rxContext ) );
451 //........................................................................
452 } // namespace pcr
453 //........................................................................
455 #endif // EXTENSIONS_SOURCE_PROPCTRLR_PROPERTYHANDLER_HXX
457 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */