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