1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_PROPERTYCOMPOSER_HXX
25 #define EXTENSIONS_SOURCE_PROPCTRLR_PROPERTYCOMPOSER_HXX
26 
27 #include "pcrcommon.hxx"
28 #include "formbrowsertools.hxx"
29 #include "composeduiupdate.hxx"
30 #include "formbrowsertools.hxx"
31 
32 /** === begin UNO includes === **/
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/inspection/XPropertyHandler.hpp>
35 #include <com/sun/star/lang/DisposedException.hpp>
36 /** === end UNO includes === **/
37 #include <cppuhelper/compbase2.hxx>
38 #include <comphelper/broadcasthelper.hxx>
39 #include <comphelper/listenernotification.hxx>
40 
41 #include <vector>
42 #include <set>
43 
44 //........................................................................
45 namespace pcr
46 {
47 //........................................................................
48 
49 	//====================================================================
50 	//= PropertyComposer
51 	//====================================================================
52     typedef ::cppu::WeakComponentImplHelper2    <   ::com::sun::star::inspection::XPropertyHandler
53                                                 ,   ::com::sun::star::beans::XPropertyChangeListener
54                                                 >   PropertyComposer_Base;
55     /** implements an <type>XPropertyHandler</type> which composes it's information
56         from a set of other property handlers
57     */
58     class PropertyComposer  :public PropertyComposer_Base
59                             ,public ::comphelper::OBaseMutex
60                             ,public IPropertyExistenceCheck
61 	{
62     public:
63         typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler > >
64                                                             HandlerArray;
65 
66     private:
67         HandlerArray                                    m_aSlaveHandlers;
68         ::std::auto_ptr< ComposedPropertyUIUpdate >     m_pUIRequestComposer;
69         PropertyChangeListeners                         m_aPropertyListeners;
70         bool                                            m_bSupportedPropertiesAreKnown;
71         PropertyBag                                     m_aSupportedProperties;
72 
73     public:
74         /** constructs an <type>XPropertyHandler</type> which composes it's information from a set
75             of other property handlers
76 
77             @param _rSlaveHandlers
78                 the set of slave handlers to invoke. Must not be <NULL/>
79         */
80         PropertyComposer( const ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler > >& _rSlaveHandlers );
81 
82     public:
83         // XPropertyHandler overridables
84         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);
85         virtual ::com::sun::star::uno::Any          SAL_CALL getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
86         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);
87         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);
88         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);
89         virtual ::com::sun::star::beans::PropertyState
90                                                     SAL_CALL getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
91         virtual void                                SAL_CALL addPropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
92         virtual void                                SAL_CALL removePropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
93         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >
94                                                     SAL_CALL getSupportedProperties() throw (::com::sun::star::uno::RuntimeException);
95         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
96                                                     SAL_CALL getSupersededProperties( ) throw (::com::sun::star::uno::RuntimeException);
97         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
98                                                     SAL_CALL getActuatingProperties( ) throw (::com::sun::star::uno::RuntimeException);
99         virtual ::com::sun::star::inspection::LineDescriptor
100                                                     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);
101         virtual ::sal_Bool                          SAL_CALL isComposable( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
102         virtual ::com::sun::star::inspection::InteractiveSelectionResult
103                                                     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);
104         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);
105 	    virtual sal_Bool                            SAL_CALL suspend( sal_Bool _bSuspend ) throw (::com::sun::star::uno::RuntimeException);
106 
107         // XComponent
108         DECLARE_XCOMPONENT()
109         virtual void                                SAL_CALL disposing();
110 
111         // XPropertyChangeListener
112         virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
113 
114         // XEventListener
115         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
116 
117         // IPropertyExistenceCheck
118         virtual ::sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& _rName ) throw (::com::sun::star::uno::RuntimeException);
119 
120     private:
121         /** ensures that m_pUIRequestComposer exists
122         */
123         void    impl_ensureUIRequestComposer( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI >& _rxInspectorUI );
124 
125         /** checks whether a given property exists in <member>m_aSupportedProperties</member>
126         */
impl_isSupportedProperty_nothrow(const::rtl::OUString & _rPropertyName)127         bool    impl_isSupportedProperty_nothrow( const ::rtl::OUString& _rPropertyName )
128         {
129             ::com::sun::star::beans::Property aDummy; aDummy.Name = _rPropertyName;
130             return m_aSupportedProperties.find( aDummy ) != m_aSupportedProperties.end();
131         }
132 
133     private:
134         class MethodGuard;
135         friend class MethodGuard;
136         class MethodGuard : public ::osl::MutexGuard
137         {
138         public:
MethodGuard(PropertyComposer & _rInstance)139             MethodGuard( PropertyComposer& _rInstance )
140                 : ::osl::MutexGuard( _rInstance.m_aMutex )
141             {
142                 if ( _rInstance.m_aSlaveHandlers.empty() )
143                     throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *(&_rInstance) );
144             }
145         };
146     };
147 
148 //........................................................................
149 } // namespace pcr
150 //........................................................................
151 
152 #endif // EXTENSIONS_SOURCE_PROPCTRLR_PROPERTYCOMPOSER_HXX
153 
154