update dev300-m58
[ooovba.git] / extensions / source / propctrlr / inspectormodelbase.cxx
blob01d26adada1f46e6b25935d706a156894cf81612
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: inspectormodelbase.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "inspectormodelbase.hxx"
34 #include "pcrcommon.hxx"
36 /** === begin UNO includes === **/
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 /** === end UNO includes === **/
40 #include <comphelper/propertycontainerhelper.hxx>
42 //........................................................................
43 namespace pcr
45 //........................................................................
47 #define MODEL_PROPERTY_ID_HAS_HELP_SECTION 2000
48 #define MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES 2001
49 #define MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES 2002
50 #define MODEL_PROPERTY_ID_IS_READ_ONLY 2003
52 /** === begin UNO using === **/
53 using ::com::sun::star::uno::Reference;
54 using ::com::sun::star::uno::XComponentContext;
55 using ::com::sun::star::beans::XPropertySetInfo;
56 using ::com::sun::star::uno::RuntimeException;
57 using ::com::sun::star::uno::Any;
58 using ::com::sun::star::lang::IllegalArgumentException;
59 using ::com::sun::star::uno::Exception;
60 using ::com::sun::star::uno::Sequence;
61 using ::com::sun::star::inspection::PropertyCategoryDescriptor;
62 using ::com::sun::star::uno::makeAny;
63 using ::com::sun::star::beans::Property;
64 /** === end UNO using === **/
65 namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
67 //====================================================================
68 //= InspectorModelProperties
69 //====================================================================
70 /** helper class for implementing the property set related functionality
71 of an ImplInspectorModel
73 class InspectorModelProperties : public ::comphelper::OPropertyContainerHelper
75 private:
76 ::osl::Mutex& m_rMutex;
77 sal_Bool m_bHasHelpSection;
78 sal_Int32 m_nMinHelpTextLines;
79 sal_Int32 m_nMaxHelpTextLines;
80 sal_Bool m_bIsReadOnly;
81 ::std::auto_ptr< ::cppu::IPropertyArrayHelper >
82 m_pPropertyInfo;
84 public:
85 InspectorModelProperties( ::osl::Mutex& _rMutex );
87 using ::comphelper::OPropertyContainerHelper::convertFastPropertyValue;
88 using ::comphelper::OPropertyContainerHelper::setFastPropertyValue;
89 using ::comphelper::OPropertyContainerHelper::getFastPropertyValue;
91 public:
92 inline sal_Bool hasHelpSection() const { return m_bHasHelpSection; }
93 inline sal_Bool isReadOnly() const { return m_bIsReadOnly; }
94 inline sal_Int32 getMinHelpTextLines() const { return m_nMinHelpTextLines; }
95 inline sal_Int32 getMaxHelpTextLines() const { return m_nMaxHelpTextLines; }
97 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
98 getPropertySetInfo();
99 ::cppu::IPropertyArrayHelper&
100 getInfoHelper();
102 void constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
105 //====================================================================
106 //= InspectorModelProperties
107 //====================================================================
108 //--------------------------------------------------------------------
109 InspectorModelProperties::InspectorModelProperties( ::osl::Mutex& _rMutex )
110 :m_rMutex( _rMutex )
111 ,m_bHasHelpSection( sal_False )
112 ,m_nMinHelpTextLines( 3 )
113 ,m_nMaxHelpTextLines( 8 )
114 ,m_bIsReadOnly( sal_False )
116 registerProperty(
117 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasHelpSection" ) ),
118 MODEL_PROPERTY_ID_HAS_HELP_SECTION,
119 PropertyAttribute::READONLY,
120 &m_bHasHelpSection, ::getCppuType( &m_bHasHelpSection )
122 registerProperty(
123 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MinHelpTextLines" ) ),
124 MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES,
125 PropertyAttribute::READONLY,
126 &m_nMinHelpTextLines, ::getCppuType( &m_nMinHelpTextLines )
128 registerProperty(
129 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxHelpTextLines" ) ),
130 MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES,
131 PropertyAttribute::READONLY,
132 &m_nMaxHelpTextLines, ::getCppuType( &m_nMaxHelpTextLines )
134 registerProperty(
135 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ),
136 MODEL_PROPERTY_ID_IS_READ_ONLY,
137 PropertyAttribute::BOUND,
138 &m_bIsReadOnly, ::getCppuType( &m_bIsReadOnly )
142 //--------------------------------------------------------------------
143 void InspectorModelProperties::constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
145 m_bHasHelpSection = sal_True;
146 m_nMinHelpTextLines = _nMinHelpTextLines;
147 m_nMaxHelpTextLines = _nMaxHelpTextLines;
148 // no need to notify this, those properties are not bound. Also, the method should
149 // only be used during construction phase, where we don't expect to have any listeners.
152 //--------------------------------------------------------------------
153 ::cppu::IPropertyArrayHelper& InspectorModelProperties::getInfoHelper()
155 ::osl::MutexGuard aGuard( m_rMutex );
156 if ( m_pPropertyInfo.get() == NULL )
158 Sequence< Property > aProperties;
159 describeProperties( aProperties );
161 m_pPropertyInfo.reset( new ::cppu::OPropertyArrayHelper( aProperties ) );
163 return *m_pPropertyInfo;
166 //--------------------------------------------------------------------
167 Reference< XPropertySetInfo > InspectorModelProperties::getPropertySetInfo()
169 return ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
172 //====================================================================
173 //= ImplInspectorModel
174 //====================================================================
175 ImplInspectorModel::ImplInspectorModel( const Reference< XComponentContext >& _rxContext )
176 :ImplInspectorModel_PBase( GetBroadcastHelper() )
177 ,m_aContext( _rxContext )
178 ,m_pProperties( new InspectorModelProperties( m_aMutex ) )
182 //--------------------------------------------------------------------
183 ImplInspectorModel::~ImplInspectorModel()
187 //--------------------------------------------------------------------
188 IMPLEMENT_FORWARD_XINTERFACE2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
190 //--------------------------------------------------------------------
191 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
193 //--------------------------------------------------------------------
194 Reference< XPropertySetInfo > SAL_CALL ImplInspectorModel::getPropertySetInfo( ) throw (RuntimeException)
196 return m_pProperties->getPropertySetInfo();
199 //--------------------------------------------------------------------
200 ::cppu::IPropertyArrayHelper& SAL_CALL ImplInspectorModel::getInfoHelper()
202 return m_pProperties->getInfoHelper();
205 //--------------------------------------------------------------------
206 sal_Bool SAL_CALL ImplInspectorModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw (IllegalArgumentException)
208 return m_pProperties->convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
211 //--------------------------------------------------------------------
212 void SAL_CALL ImplInspectorModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception)
214 m_pProperties->setFastPropertyValue( nHandle, rValue );
217 //--------------------------------------------------------------------
218 void SAL_CALL ImplInspectorModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
220 m_pProperties->getFastPropertyValue( rValue, nHandle );
223 //--------------------------------------------------------------------
224 ::sal_Bool SAL_CALL ImplInspectorModel::getHasHelpSection() throw (RuntimeException)
226 return m_pProperties->hasHelpSection();
229 //--------------------------------------------------------------------
230 ::sal_Int32 SAL_CALL ImplInspectorModel::getMinHelpTextLines() throw (RuntimeException)
232 return m_pProperties->getMinHelpTextLines();
235 //--------------------------------------------------------------------
236 ::sal_Int32 SAL_CALL ImplInspectorModel::getMaxHelpTextLines() throw (RuntimeException)
238 return m_pProperties->getMaxHelpTextLines();
241 //--------------------------------------------------------------------
242 ::sal_Bool SAL_CALL ImplInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException)
244 return m_pProperties->isReadOnly();
247 //--------------------------------------------------------------------
248 void SAL_CALL ImplInspectorModel::setIsReadOnly( ::sal_Bool _IsReadOnly ) throw (::com::sun::star::uno::RuntimeException)
250 setFastPropertyValue( MODEL_PROPERTY_ID_IS_READ_ONLY, makeAny( _IsReadOnly ) );
253 //--------------------------------------------------------------------
254 ::sal_Bool SAL_CALL ImplInspectorModel::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException)
256 StlSyntaxSequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
257 for ( StlSyntaxSequence< ::rtl::OUString >::const_iterator check = aSupported.begin();
258 check != aSupported.end();
259 ++check
261 if ( check->equals( ServiceName ) )
262 return sal_True;
264 return sal_False;
267 //--------------------------------------------------------------------
268 void ImplInspectorModel::enableHelpSectionProperties( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
270 m_pProperties->constructWithHelpSection( _nMinHelpTextLines, _nMaxHelpTextLines );
273 //........................................................................
274 } // namespace pcr
275 //........................................................................