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 "inspectormodelbase.hxx"
27cdf0e10cSrcweir #include "pcrcommon.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir /** === begin UNO includes === **/
30cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
31cdf0e10cSrcweir /** === end UNO includes === **/
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <comphelper/propertycontainerhelper.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //........................................................................
36cdf0e10cSrcweir namespace pcr
37cdf0e10cSrcweir {
38cdf0e10cSrcweir //........................................................................
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #define MODEL_PROPERTY_ID_HAS_HELP_SECTION      2000
41cdf0e10cSrcweir #define MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES   2001
42cdf0e10cSrcweir #define MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES   2002
43cdf0e10cSrcweir #define MODEL_PROPERTY_ID_IS_READ_ONLY          2003
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	/** === begin UNO using === **/
46cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
47cdf0e10cSrcweir     using ::com::sun::star::uno::XComponentContext;
48cdf0e10cSrcweir     using ::com::sun::star::beans::XPropertySetInfo;
49cdf0e10cSrcweir     using ::com::sun::star::uno::RuntimeException;
50cdf0e10cSrcweir     using ::com::sun::star::uno::Any;
51cdf0e10cSrcweir     using ::com::sun::star::lang::IllegalArgumentException;
52cdf0e10cSrcweir     using ::com::sun::star::uno::Exception;
53cdf0e10cSrcweir     using ::com::sun::star::uno::Sequence;
54cdf0e10cSrcweir     using ::com::sun::star::inspection::PropertyCategoryDescriptor;
55cdf0e10cSrcweir     using ::com::sun::star::uno::makeAny;
56cdf0e10cSrcweir     using ::com::sun::star::beans::Property;
57cdf0e10cSrcweir 	/** === end UNO using === **/
58cdf0e10cSrcweir     namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 	//====================================================================
61cdf0e10cSrcweir 	//= InspectorModelProperties
62cdf0e10cSrcweir 	//====================================================================
63cdf0e10cSrcweir     /** helper class for implementing the property set related functionality
64cdf0e10cSrcweir         of an ImplInspectorModel
65cdf0e10cSrcweir     */
66cdf0e10cSrcweir     class InspectorModelProperties : public ::comphelper::OPropertyContainerHelper
67cdf0e10cSrcweir 	{
68cdf0e10cSrcweir     private:
69cdf0e10cSrcweir         ::osl::Mutex&           m_rMutex;
70cdf0e10cSrcweir         sal_Bool                m_bHasHelpSection;
71cdf0e10cSrcweir         sal_Int32               m_nMinHelpTextLines;
72cdf0e10cSrcweir         sal_Int32               m_nMaxHelpTextLines;
73cdf0e10cSrcweir         sal_Bool                m_bIsReadOnly;
74cdf0e10cSrcweir         ::std::auto_ptr< ::cppu::IPropertyArrayHelper >
75cdf0e10cSrcweir                                 m_pPropertyInfo;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     public:
78cdf0e10cSrcweir         InspectorModelProperties( ::osl::Mutex& _rMutex );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         using ::comphelper::OPropertyContainerHelper::convertFastPropertyValue;
81cdf0e10cSrcweir         using ::comphelper::OPropertyContainerHelper::setFastPropertyValue;
82cdf0e10cSrcweir         using ::comphelper::OPropertyContainerHelper::getFastPropertyValue;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     public:
hasHelpSection() const85cdf0e10cSrcweir         inline  sal_Bool    hasHelpSection() const { return m_bHasHelpSection; }
isReadOnly() const86cdf0e10cSrcweir         inline  sal_Bool    isReadOnly() const { return m_bIsReadOnly; }
getMinHelpTextLines() const87cdf0e10cSrcweir         inline  sal_Int32   getMinHelpTextLines() const { return m_nMinHelpTextLines; }
getMaxHelpTextLines() const88cdf0e10cSrcweir         inline  sal_Int32   getMaxHelpTextLines() const { return m_nMaxHelpTextLines; }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
91cdf0e10cSrcweir                             getPropertySetInfo();
92cdf0e10cSrcweir         ::cppu::IPropertyArrayHelper&
93cdf0e10cSrcweir                             getInfoHelper();
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         void    constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
96cdf0e10cSrcweir 	};
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	//====================================================================
99cdf0e10cSrcweir 	//= InspectorModelProperties
100cdf0e10cSrcweir 	//====================================================================
101cdf0e10cSrcweir 	//--------------------------------------------------------------------
InspectorModelProperties(::osl::Mutex & _rMutex)102cdf0e10cSrcweir     InspectorModelProperties::InspectorModelProperties( ::osl::Mutex& _rMutex )
103cdf0e10cSrcweir         :m_rMutex( _rMutex )
104cdf0e10cSrcweir         ,m_bHasHelpSection( sal_False )
105cdf0e10cSrcweir         ,m_nMinHelpTextLines( 3 )
106cdf0e10cSrcweir         ,m_nMaxHelpTextLines( 8 )
107cdf0e10cSrcweir         ,m_bIsReadOnly( sal_False )
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         registerProperty(
110cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasHelpSection" ) ),
111cdf0e10cSrcweir             MODEL_PROPERTY_ID_HAS_HELP_SECTION,
112cdf0e10cSrcweir             PropertyAttribute::READONLY,
113cdf0e10cSrcweir             &m_bHasHelpSection, ::getCppuType( &m_bHasHelpSection )
114cdf0e10cSrcweir         );
115cdf0e10cSrcweir         registerProperty(
116cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MinHelpTextLines" ) ),
117cdf0e10cSrcweir             MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES,
118cdf0e10cSrcweir             PropertyAttribute::READONLY,
119cdf0e10cSrcweir             &m_nMinHelpTextLines, ::getCppuType( &m_nMinHelpTextLines )
120cdf0e10cSrcweir         );
121cdf0e10cSrcweir         registerProperty(
122cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxHelpTextLines" ) ),
123cdf0e10cSrcweir             MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES,
124cdf0e10cSrcweir             PropertyAttribute::READONLY,
125cdf0e10cSrcweir             &m_nMaxHelpTextLines, ::getCppuType( &m_nMaxHelpTextLines )
126cdf0e10cSrcweir         );
127cdf0e10cSrcweir         registerProperty(
128cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ),
129cdf0e10cSrcweir             MODEL_PROPERTY_ID_IS_READ_ONLY,
130cdf0e10cSrcweir             PropertyAttribute::BOUND,
131cdf0e10cSrcweir             &m_bIsReadOnly, ::getCppuType( &m_bIsReadOnly )
132cdf0e10cSrcweir         );
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	//--------------------------------------------------------------------
constructWithHelpSection(sal_Int32 _nMinHelpTextLines,sal_Int32 _nMaxHelpTextLines)136cdf0e10cSrcweir     void InspectorModelProperties::constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir         m_bHasHelpSection = sal_True;
139cdf0e10cSrcweir         m_nMinHelpTextLines = _nMinHelpTextLines;
140cdf0e10cSrcweir         m_nMaxHelpTextLines = _nMaxHelpTextLines;
141cdf0e10cSrcweir         // no need to notify this, those properties are not bound. Also, the method should
142cdf0e10cSrcweir         // only be used during construction phase, where we don't expect to have any listeners.
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	//--------------------------------------------------------------------
getInfoHelper()146cdf0e10cSrcweir     ::cppu::IPropertyArrayHelper& InspectorModelProperties::getInfoHelper()
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_rMutex );
149cdf0e10cSrcweir         if ( m_pPropertyInfo.get() == NULL )
150cdf0e10cSrcweir         {
151cdf0e10cSrcweir             Sequence< Property > aProperties;
152cdf0e10cSrcweir             describeProperties( aProperties );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir             m_pPropertyInfo.reset( new ::cppu::OPropertyArrayHelper( aProperties ) );
155cdf0e10cSrcweir         }
156cdf0e10cSrcweir         return *m_pPropertyInfo;
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	//--------------------------------------------------------------------
getPropertySetInfo()160cdf0e10cSrcweir     Reference< XPropertySetInfo > InspectorModelProperties::getPropertySetInfo()
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir         return ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     //====================================================================
166cdf0e10cSrcweir 	//= ImplInspectorModel
167cdf0e10cSrcweir 	//====================================================================
ImplInspectorModel(const Reference<XComponentContext> & _rxContext)168cdf0e10cSrcweir     ImplInspectorModel::ImplInspectorModel( const Reference< XComponentContext >& _rxContext )
169cdf0e10cSrcweir         :ImplInspectorModel_PBase( GetBroadcastHelper() )
170cdf0e10cSrcweir         ,m_aContext( _rxContext )
171cdf0e10cSrcweir         ,m_pProperties( new InspectorModelProperties( m_aMutex ) )
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir     }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     //--------------------------------------------------------------------
~ImplInspectorModel()176cdf0e10cSrcweir     ImplInspectorModel::~ImplInspectorModel()
177cdf0e10cSrcweir     {
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     //--------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(ImplInspectorModel,ImplInspectorModel_Base,ImplInspectorModel_PBase)181cdf0e10cSrcweir     IMPLEMENT_FORWARD_XINTERFACE2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     //--------------------------------------------------------------------
184cdf0e10cSrcweir     IMPLEMENT_FORWARD_XTYPEPROVIDER2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     //--------------------------------------------------------------------
187cdf0e10cSrcweir     Reference< XPropertySetInfo > SAL_CALL ImplInspectorModel::getPropertySetInfo(  ) throw (RuntimeException)
188cdf0e10cSrcweir     {
189cdf0e10cSrcweir         return m_pProperties->getPropertySetInfo();
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     //--------------------------------------------------------------------
getInfoHelper()193cdf0e10cSrcweir     ::cppu::IPropertyArrayHelper& SAL_CALL ImplInspectorModel::getInfoHelper()
194cdf0e10cSrcweir     {
195cdf0e10cSrcweir         return m_pProperties->getInfoHelper();
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     //--------------------------------------------------------------------
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nHandle,const Any & rValue)199cdf0e10cSrcweir     sal_Bool SAL_CALL ImplInspectorModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw (IllegalArgumentException)
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         return m_pProperties->convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     //--------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)205cdf0e10cSrcweir     void SAL_CALL ImplInspectorModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception)
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         m_pProperties->setFastPropertyValue( nHandle, rValue );
208cdf0e10cSrcweir     }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir     //--------------------------------------------------------------------
getFastPropertyValue(Any & rValue,sal_Int32 nHandle) const211cdf0e10cSrcweir     void SAL_CALL ImplInspectorModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
212cdf0e10cSrcweir     {
213cdf0e10cSrcweir         m_pProperties->getFastPropertyValue( rValue, nHandle );
214cdf0e10cSrcweir     }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     //--------------------------------------------------------------------
getHasHelpSection()217cdf0e10cSrcweir     ::sal_Bool SAL_CALL ImplInspectorModel::getHasHelpSection() throw (RuntimeException)
218cdf0e10cSrcweir     {
219cdf0e10cSrcweir         return m_pProperties->hasHelpSection();
220cdf0e10cSrcweir     }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     //--------------------------------------------------------------------
getMinHelpTextLines()223cdf0e10cSrcweir     ::sal_Int32 SAL_CALL ImplInspectorModel::getMinHelpTextLines() throw (RuntimeException)
224cdf0e10cSrcweir     {
225cdf0e10cSrcweir         return m_pProperties->getMinHelpTextLines();
226cdf0e10cSrcweir     }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     //--------------------------------------------------------------------
getMaxHelpTextLines()229cdf0e10cSrcweir     ::sal_Int32 SAL_CALL ImplInspectorModel::getMaxHelpTextLines() throw (RuntimeException)
230cdf0e10cSrcweir     {
231cdf0e10cSrcweir         return m_pProperties->getMaxHelpTextLines();
232cdf0e10cSrcweir     }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     //--------------------------------------------------------------------
getIsReadOnly()235cdf0e10cSrcweir     ::sal_Bool SAL_CALL ImplInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException)
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         return m_pProperties->isReadOnly();
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     //--------------------------------------------------------------------
setIsReadOnly(::sal_Bool _IsReadOnly)241cdf0e10cSrcweir     void SAL_CALL ImplInspectorModel::setIsReadOnly( ::sal_Bool _IsReadOnly ) throw (::com::sun::star::uno::RuntimeException)
242cdf0e10cSrcweir     {
243cdf0e10cSrcweir         setFastPropertyValue( MODEL_PROPERTY_ID_IS_READ_ONLY, makeAny( _IsReadOnly ) );
244cdf0e10cSrcweir     }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     //--------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)247cdf0e10cSrcweir     ::sal_Bool SAL_CALL ImplInspectorModel::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException)
248cdf0e10cSrcweir     {
249cdf0e10cSrcweir 		StlSyntaxSequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
250cdf0e10cSrcweir         for (   StlSyntaxSequence< ::rtl::OUString >::const_iterator check = aSupported.begin();
251cdf0e10cSrcweir                 check != aSupported.end();
252cdf0e10cSrcweir                 ++check
253cdf0e10cSrcweir             )
254cdf0e10cSrcweir             if ( check->equals( ServiceName ) )
255cdf0e10cSrcweir                 return sal_True;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir         return sal_False;
258cdf0e10cSrcweir     }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir     //--------------------------------------------------------------------
enableHelpSectionProperties(sal_Int32 _nMinHelpTextLines,sal_Int32 _nMaxHelpTextLines)261cdf0e10cSrcweir     void ImplInspectorModel::enableHelpSectionProperties( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir         m_pProperties->constructWithHelpSection( _nMinHelpTextLines, _nMaxHelpTextLines );
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir //........................................................................
267cdf0e10cSrcweir } // namespace pcr
268cdf0e10cSrcweir //........................................................................
269