1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_GENERICPROPERTYHANDLER_HXX
29 #define EXTENSIONS_SOURCE_PROPCTRLR_GENERICPROPERTYHANDLER_HXX
30 
31 #include "propertyhandler.hxx"
32 #include "pcrcommontypes.hxx"
33 #include "pcrcommon.hxx"
34 #include "pcrcomponentcontext.hxx"
35 
36 /** === begin UNO includes === **/
37 #include <com/sun/star/beans/XPropertyState.hpp>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/beans/XIntrospectionAccess.hpp>
40 /** === end UNO includes === **/
41 #include <cppuhelper/compbase2.hxx>
42 #include <cppuhelper/interfacecontainer.hxx>
43 #include <rtl/ref.hxx>
44 
45 #include <map>
46 
47 //........................................................................
48 namespace pcr
49 {
50 //........................................................................
51 
52     struct TypeLess : ::std::binary_function< ::com::sun::star::uno::Type, ::com::sun::star::uno::Type, bool >
53     {
54         bool operator()( const ::com::sun::star::uno::Type& _rLHS, const ::com::sun::star::uno::Type& _rRHS ) const
55         {
56             return _rLHS.getTypeName() < _rRHS.getTypeName();
57         }
58     };
59 
60     class IPropertyInfoService;
61     class IPropertyEnumRepresentation;
62 	//====================================================================
63 	//= GenericPropertyHandler
64 	//====================================================================
65     typedef ::cppu::WeakComponentImplHelper2    <   ::com::sun::star::inspection::XPropertyHandler
66                                                 ,   ::com::sun::star::lang::XServiceInfo
67                                                 >   GenericPropertyHandler_Base;
68 	class GenericPropertyHandler : public GenericPropertyHandler_Base
69 	{
70     private:
71         mutable ::osl::Mutex    m_aMutex;
72 
73     private:
74         /// the service factory for creating services
75         ComponentContext                                                                    m_aContext;
76         /// need this to keep alive as long as m_xComponent lives
77         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess >   m_xComponentIntrospectionAccess;
78         /// the properties of the object we're handling
79         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >           m_xComponent;
80         /// cached interface of ->m_xComponent
81         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >         m_xPropertyState;
82         /// type converter, needed on various occasions
83         ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter >        m_xTypeConverter;
84         /// cache of our supported properties
85         PropertyMap                                                                         m_aProperties;
86         /// property change listeners
87         ::cppu::OInterfaceContainerHelper                                                   m_aPropertyListeners;
88         ::std::map< ::com::sun::star::uno::Type, ::rtl::Reference< IPropertyEnumRepresentation >, TypeLess >
89                                                                                             m_aEnumConverters;
90 
91         /// has ->m_aProperties been initialized?
92         bool    m_bPropertyMapInitialized : 1;
93 
94     public:
95         // XServiceInfo - static versions
96         static ::rtl::OUString SAL_CALL getImplementationName_static(  ) throw (::com::sun::star::uno::RuntimeException);
97         static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static(  ) throw (::com::sun::star::uno::RuntimeException);
98         static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > Create( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
99 
100     protected:
101         GenericPropertyHandler(
102             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext
103         );
104 
105         ~GenericPropertyHandler();
106 
107     protected:
108         // XPropertyHandler overridables
109         virtual void                                                SAL_CALL inspect( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxIntrospectee ) throw (::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException);
110         virtual ::com::sun::star::uno::Any                          SAL_CALL getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
111         virtual void                                                SAL_CALL setPropertyValue( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
112         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);
113         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);
114         virtual ::com::sun::star::beans::PropertyState              SAL_CALL getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
115         virtual void                                                SAL_CALL addPropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
116         virtual void                                                SAL_CALL removePropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
117         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >
118                                                                     SAL_CALL getSupportedProperties() throw (::com::sun::star::uno::RuntimeException);
119         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
120                                                                     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::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);
123         virtual ::sal_Bool                                          SAL_CALL isComposable( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
124         virtual ::com::sun::star::inspection::InteractiveSelectionResult
125                                                                     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);
126         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);
127 	    virtual sal_Bool                                            SAL_CALL suspend( sal_Bool _bSuspend ) throw (::com::sun::star::uno::RuntimeException);
128 
129         // XComponent
130         DECLARE_XCOMPONENT()
131         virtual void                                                SAL_CALL disposing();
132 
133         // XServiceInfo
134         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
135         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
136         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
137 
138     private:
139         /** ensures that ->m_aProperties is initialized
140             @precond
141                 our mutex is locked
142         */
143         void    impl_ensurePropertyMap();
144 
145         /** retrieves the enum converter for the given ENUM type
146         */
147         ::rtl::Reference< IPropertyEnumRepresentation >
148                 impl_getEnumConverter( const ::com::sun::star::uno::Type& _rEnumType );
149 
150     private:
151         GenericPropertyHandler();                                           // never implemented
152         GenericPropertyHandler( const GenericPropertyHandler& );            // never implemented
153         GenericPropertyHandler& operator=( const GenericPropertyHandler& ); // never implemented
154     };
155 
156 //........................................................................
157 } // namespace pcr
158 //........................................................................
159 
160 #endif // EXTENSIONS_SOURCE_PROPCTRLR_GENERICPROPERTYHANDLER_HXX
161 
162