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_PROPERTYCOMPOSER_HXX
29 #define EXTENSIONS_SOURCE_PROPCTRLR_PROPERTYCOMPOSER_HXX
30 
31 #include "pcrcommon.hxx"
32 #include "formbrowsertools.hxx"
33 #include "composeduiupdate.hxx"
34 #include "formbrowsertools.hxx"
35 
36 /** === begin UNO includes === **/
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/inspection/XPropertyHandler.hpp>
39 #include <com/sun/star/lang/DisposedException.hpp>
40 /** === end UNO includes === **/
41 #include <cppuhelper/compbase2.hxx>
42 #include <comphelper/broadcasthelper.hxx>
43 #include <comphelper/listenernotification.hxx>
44 
45 #include <vector>
46 #include <set>
47 
48 //........................................................................
49 namespace pcr
50 {
51 //........................................................................
52 
53 	//====================================================================
54 	//= PropertyComposer
55 	//====================================================================
56     typedef ::cppu::WeakComponentImplHelper2    <   ::com::sun::star::inspection::XPropertyHandler
57                                                 ,   ::com::sun::star::beans::XPropertyChangeListener
58                                                 >   PropertyComposer_Base;
59     /** implements an <type>XPropertyHandler</type> which composes it's information
60         from a set of other property handlers
61     */
62     class PropertyComposer  :public PropertyComposer_Base
63                             ,public ::comphelper::OBaseMutex
64                             ,public IPropertyExistenceCheck
65 	{
66     public:
67         typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler > >
68                                                             HandlerArray;
69 
70     private:
71         HandlerArray                                    m_aSlaveHandlers;
72         ::std::auto_ptr< ComposedPropertyUIUpdate >     m_pUIRequestComposer;
73         PropertyChangeListeners                         m_aPropertyListeners;
74         bool                                            m_bSupportedPropertiesAreKnown;
75         PropertyBag                                     m_aSupportedProperties;
76 
77     public:
78         /** constructs an <type>XPropertyHandler</type> which composes it's information from a set
79             of other property handlers
80 
81             @param _rSlaveHandlers
82                 the set of slave handlers to invoke. Must not be <NULL/>
83         */
84         PropertyComposer( const ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler > >& _rSlaveHandlers );
85 
86     public:
87         // XPropertyHandler overridables
88         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);
89         virtual ::com::sun::star::uno::Any          SAL_CALL getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
90         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);
91         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);
92         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);
93         virtual ::com::sun::star::beans::PropertyState
94                                                     SAL_CALL getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
95         virtual void                                SAL_CALL addPropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
96         virtual void                                SAL_CALL removePropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
97         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >
98                                                     SAL_CALL getSupportedProperties() throw (::com::sun::star::uno::RuntimeException);
99         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
100                                                     SAL_CALL getSupersededProperties( ) throw (::com::sun::star::uno::RuntimeException);
101         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
102                                                     SAL_CALL getActuatingProperties( ) throw (::com::sun::star::uno::RuntimeException);
103         virtual ::com::sun::star::inspection::LineDescriptor
104                                                     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);
105         virtual ::sal_Bool                          SAL_CALL isComposable( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
106         virtual ::com::sun::star::inspection::InteractiveSelectionResult
107                                                     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);
108         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);
109 	    virtual sal_Bool                            SAL_CALL suspend( sal_Bool _bSuspend ) throw (::com::sun::star::uno::RuntimeException);
110 
111         // XComponent
112         DECLARE_XCOMPONENT()
113         virtual void                                SAL_CALL disposing();
114 
115         // XPropertyChangeListener
116         virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
117 
118         // XEventListener
119         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
120 
121         // IPropertyExistenceCheck
122         virtual ::sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& _rName ) throw (::com::sun::star::uno::RuntimeException);
123 
124     private:
125         /** ensures that m_pUIRequestComposer exists
126         */
127         void    impl_ensureUIRequestComposer( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI >& _rxInspectorUI );
128 
129         /** checks whether a given property exists in <member>m_aSupportedProperties</member>
130         */
131         bool    impl_isSupportedProperty_nothrow( const ::rtl::OUString& _rPropertyName )
132         {
133             ::com::sun::star::beans::Property aDummy; aDummy.Name = _rPropertyName;
134             return m_aSupportedProperties.find( aDummy ) != m_aSupportedProperties.end();
135         }
136 
137     private:
138         class MethodGuard;
139         friend class MethodGuard;
140         class MethodGuard : public ::osl::MutexGuard
141         {
142         public:
143             MethodGuard( PropertyComposer& _rInstance )
144                 : ::osl::MutexGuard( _rInstance.m_aMutex )
145             {
146                 if ( _rInstance.m_aSlaveHandlers.empty() )
147                     throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *(&_rInstance) );
148             }
149         };
150     };
151 
152 //........................................................................
153 } // namespace pcr
154 //........................................................................
155 
156 #endif // EXTENSIONS_SOURCE_PROPCTRLR_PROPERTYCOMPOSER_HXX
157 
158