1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "inspectormodelbase.hxx"
31 #include "pcrcommon.hxx"
33 /** === begin UNO includes === **/
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 /** === end UNO includes === **/
37 #include <comphelper/propertycontainerhelper.hxx>
39 //........................................................................
42 //........................................................................
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
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
;
64 //====================================================================
65 //= InspectorModelProperties
66 //====================================================================
67 /** helper class for implementing the property set related functionality
68 of an ImplInspectorModel
70 class InspectorModelProperties
: public ::comphelper::OPropertyContainerHelper
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
>
82 InspectorModelProperties( ::osl::Mutex
& _rMutex
);
84 using ::comphelper::OPropertyContainerHelper::convertFastPropertyValue
;
85 using ::comphelper::OPropertyContainerHelper::setFastPropertyValue
;
86 using ::comphelper::OPropertyContainerHelper::getFastPropertyValue
;
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
; }
94 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
>
96 ::cppu::IPropertyArrayHelper
&
99 void constructWithHelpSection( sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
);
102 //====================================================================
103 //= InspectorModelProperties
104 //====================================================================
105 //--------------------------------------------------------------------
106 InspectorModelProperties::InspectorModelProperties( ::osl::Mutex
& _rMutex
)
108 ,m_bHasHelpSection( sal_False
)
109 ,m_nMinHelpTextLines( 3 )
110 ,m_nMaxHelpTextLines( 8 )
111 ,m_bIsReadOnly( sal_False
)
114 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasHelpSection" ) ),
115 MODEL_PROPERTY_ID_HAS_HELP_SECTION
,
116 PropertyAttribute::READONLY
,
117 &m_bHasHelpSection
, ::getCppuType( &m_bHasHelpSection
)
120 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MinHelpTextLines" ) ),
121 MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES
,
122 PropertyAttribute::READONLY
,
123 &m_nMinHelpTextLines
, ::getCppuType( &m_nMinHelpTextLines
)
126 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxHelpTextLines" ) ),
127 MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES
,
128 PropertyAttribute::READONLY
,
129 &m_nMaxHelpTextLines
, ::getCppuType( &m_nMaxHelpTextLines
)
132 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ),
133 MODEL_PROPERTY_ID_IS_READ_ONLY
,
134 PropertyAttribute::BOUND
,
135 &m_bIsReadOnly
, ::getCppuType( &m_bIsReadOnly
)
139 //--------------------------------------------------------------------
140 void InspectorModelProperties::constructWithHelpSection( sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
)
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.
149 //--------------------------------------------------------------------
150 ::cppu::IPropertyArrayHelper
& InspectorModelProperties::getInfoHelper()
152 ::osl::MutexGuard
aGuard( m_rMutex
);
153 if ( m_pPropertyInfo
.get() == NULL
)
155 Sequence
< Property
> aProperties
;
156 describeProperties( aProperties
);
158 m_pPropertyInfo
.reset( new ::cppu::OPropertyArrayHelper( aProperties
) );
160 return *m_pPropertyInfo
;
163 //--------------------------------------------------------------------
164 Reference
< XPropertySetInfo
> InspectorModelProperties::getPropertySetInfo()
166 return ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
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
) )
179 //--------------------------------------------------------------------
180 ImplInspectorModel::~ImplInspectorModel()
184 //--------------------------------------------------------------------
185 IMPLEMENT_FORWARD_XINTERFACE2( ImplInspectorModel
, ImplInspectorModel_Base
, ImplInspectorModel_PBase
)
187 //--------------------------------------------------------------------
188 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ImplInspectorModel
, ImplInspectorModel_Base
, ImplInspectorModel_PBase
)
190 //--------------------------------------------------------------------
191 Reference
< XPropertySetInfo
> SAL_CALL
ImplInspectorModel::getPropertySetInfo( ) throw (RuntimeException
)
193 return m_pProperties
->getPropertySetInfo();
196 //--------------------------------------------------------------------
197 ::cppu::IPropertyArrayHelper
& SAL_CALL
ImplInspectorModel::getInfoHelper()
199 return m_pProperties
->getInfoHelper();
202 //--------------------------------------------------------------------
203 sal_Bool SAL_CALL
ImplInspectorModel::convertFastPropertyValue( Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nHandle
, const Any
& rValue
) throw (IllegalArgumentException
)
205 return m_pProperties
->convertFastPropertyValue( rConvertedValue
, rOldValue
, nHandle
, rValue
);
208 //--------------------------------------------------------------------
209 void SAL_CALL
ImplInspectorModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const Any
& rValue
) throw (Exception
)
211 m_pProperties
->setFastPropertyValue( nHandle
, rValue
);
214 //--------------------------------------------------------------------
215 void SAL_CALL
ImplInspectorModel::getFastPropertyValue( Any
& rValue
, sal_Int32 nHandle
) const
217 m_pProperties
->getFastPropertyValue( rValue
, nHandle
);
220 //--------------------------------------------------------------------
221 ::sal_Bool SAL_CALL
ImplInspectorModel::getHasHelpSection() throw (RuntimeException
)
223 return m_pProperties
->hasHelpSection();
226 //--------------------------------------------------------------------
227 ::sal_Int32 SAL_CALL
ImplInspectorModel::getMinHelpTextLines() throw (RuntimeException
)
229 return m_pProperties
->getMinHelpTextLines();
232 //--------------------------------------------------------------------
233 ::sal_Int32 SAL_CALL
ImplInspectorModel::getMaxHelpTextLines() throw (RuntimeException
)
235 return m_pProperties
->getMaxHelpTextLines();
238 //--------------------------------------------------------------------
239 ::sal_Bool SAL_CALL
ImplInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException
)
241 return m_pProperties
->isReadOnly();
244 //--------------------------------------------------------------------
245 void SAL_CALL
ImplInspectorModel::setIsReadOnly( ::sal_Bool _IsReadOnly
) throw (::com::sun::star::uno::RuntimeException
)
247 setFastPropertyValue( MODEL_PROPERTY_ID_IS_READ_ONLY
, makeAny( _IsReadOnly
) );
250 //--------------------------------------------------------------------
251 ::sal_Bool SAL_CALL
ImplInspectorModel::supportsService( const ::rtl::OUString
& ServiceName
) throw (RuntimeException
)
253 StlSyntaxSequence
< ::rtl::OUString
> aSupported( getSupportedServiceNames() );
254 for ( StlSyntaxSequence
< ::rtl::OUString
>::const_iterator check
= aSupported
.begin();
255 check
!= aSupported
.end();
258 if ( check
->equals( ServiceName
) )
264 //--------------------------------------------------------------------
265 void ImplInspectorModel::enableHelpSectionProperties( sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
)
267 m_pProperties
->constructWithHelpSection( _nMinHelpTextLines
, _nMaxHelpTextLines
);
270 //........................................................................
272 //........................................................................