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