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