bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / propctrlr / inspectormodelbase.cxx
blobd8ebe0780ec008bd6124f1183dd56772af6ddca9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "inspectormodelbase.hxx"
21 #include "pcrcommon.hxx"
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <comphelper/propertycontainerhelper.hxx>
27 //........................................................................
28 namespace pcr
30 //........................................................................
32 #define MODEL_PROPERTY_ID_HAS_HELP_SECTION 2000
33 #define MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES 2001
34 #define MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES 2002
35 #define MODEL_PROPERTY_ID_IS_READ_ONLY 2003
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::uno::XComponentContext;
39 using ::com::sun::star::beans::XPropertySetInfo;
40 using ::com::sun::star::uno::RuntimeException;
41 using ::com::sun::star::uno::Any;
42 using ::com::sun::star::lang::IllegalArgumentException;
43 using ::com::sun::star::uno::Exception;
44 using ::com::sun::star::uno::Sequence;
45 using ::com::sun::star::inspection::PropertyCategoryDescriptor;
46 using ::com::sun::star::uno::makeAny;
47 using ::com::sun::star::beans::Property;
49 namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
51 //====================================================================
52 //= InspectorModelProperties
53 //====================================================================
54 /** helper class for implementing the property set related functionality
55 of an ImplInspectorModel
57 class InspectorModelProperties : public ::comphelper::OPropertyContainerHelper
59 private:
60 ::osl::Mutex& m_rMutex;
61 sal_Bool m_bHasHelpSection;
62 sal_Int32 m_nMinHelpTextLines;
63 sal_Int32 m_nMaxHelpTextLines;
64 sal_Bool m_bIsReadOnly;
65 ::std::auto_ptr< ::cppu::IPropertyArrayHelper >
66 m_pPropertyInfo;
68 public:
69 InspectorModelProperties( ::osl::Mutex& _rMutex );
71 using ::comphelper::OPropertyContainerHelper::convertFastPropertyValue;
72 using ::comphelper::OPropertyContainerHelper::setFastPropertyValue;
73 using ::comphelper::OPropertyContainerHelper::getFastPropertyValue;
75 public:
76 inline sal_Bool hasHelpSection() const { return m_bHasHelpSection; }
77 inline sal_Bool isReadOnly() const { return m_bIsReadOnly; }
78 inline sal_Int32 getMinHelpTextLines() const { return m_nMinHelpTextLines; }
79 inline sal_Int32 getMaxHelpTextLines() const { return m_nMaxHelpTextLines; }
81 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
82 getPropertySetInfo();
83 ::cppu::IPropertyArrayHelper&
84 getInfoHelper();
86 void constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
89 //====================================================================
90 //= InspectorModelProperties
91 //====================================================================
92 //--------------------------------------------------------------------
93 InspectorModelProperties::InspectorModelProperties( ::osl::Mutex& _rMutex )
94 :m_rMutex( _rMutex )
95 ,m_bHasHelpSection( sal_False )
96 ,m_nMinHelpTextLines( 3 )
97 ,m_nMaxHelpTextLines( 8 )
98 ,m_bIsReadOnly( sal_False )
100 registerProperty(
101 OUString( "HasHelpSection" ),
102 MODEL_PROPERTY_ID_HAS_HELP_SECTION,
103 PropertyAttribute::READONLY,
104 &m_bHasHelpSection, ::getCppuType( &m_bHasHelpSection )
106 registerProperty(
107 OUString( "MinHelpTextLines" ),
108 MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES,
109 PropertyAttribute::READONLY,
110 &m_nMinHelpTextLines, ::getCppuType( &m_nMinHelpTextLines )
112 registerProperty(
113 OUString( "MaxHelpTextLines" ),
114 MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES,
115 PropertyAttribute::READONLY,
116 &m_nMaxHelpTextLines, ::getCppuType( &m_nMaxHelpTextLines )
118 registerProperty(
119 OUString( "IsReadOnly" ),
120 MODEL_PROPERTY_ID_IS_READ_ONLY,
121 PropertyAttribute::BOUND,
122 &m_bIsReadOnly, ::getCppuType( &m_bIsReadOnly )
126 //--------------------------------------------------------------------
127 void InspectorModelProperties::constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
129 m_bHasHelpSection = sal_True;
130 m_nMinHelpTextLines = _nMinHelpTextLines;
131 m_nMaxHelpTextLines = _nMaxHelpTextLines;
132 // no need to notify this, those properties are not bound. Also, the method should
133 // only be used during construction phase, where we don't expect to have any listeners.
136 //--------------------------------------------------------------------
137 ::cppu::IPropertyArrayHelper& InspectorModelProperties::getInfoHelper()
139 ::osl::MutexGuard aGuard( m_rMutex );
140 if ( m_pPropertyInfo.get() == NULL )
142 Sequence< Property > aProperties;
143 describeProperties( aProperties );
145 m_pPropertyInfo.reset( new ::cppu::OPropertyArrayHelper( aProperties ) );
147 return *m_pPropertyInfo;
150 //--------------------------------------------------------------------
151 Reference< XPropertySetInfo > InspectorModelProperties::getPropertySetInfo()
153 return ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
156 //====================================================================
157 //= ImplInspectorModel
158 //====================================================================
159 ImplInspectorModel::ImplInspectorModel( const Reference< XComponentContext >& _rxContext )
160 :ImplInspectorModel_PBase( GetBroadcastHelper() )
161 ,m_aContext( _rxContext )
162 ,m_pProperties( new InspectorModelProperties( m_aMutex ) )
166 //--------------------------------------------------------------------
167 ImplInspectorModel::~ImplInspectorModel()
171 //--------------------------------------------------------------------
172 IMPLEMENT_FORWARD_XINTERFACE2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
174 //--------------------------------------------------------------------
175 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
177 //--------------------------------------------------------------------
178 Reference< XPropertySetInfo > SAL_CALL ImplInspectorModel::getPropertySetInfo( ) throw (RuntimeException)
180 return m_pProperties->getPropertySetInfo();
183 //--------------------------------------------------------------------
184 ::cppu::IPropertyArrayHelper& SAL_CALL ImplInspectorModel::getInfoHelper()
186 return m_pProperties->getInfoHelper();
189 //--------------------------------------------------------------------
190 sal_Bool SAL_CALL ImplInspectorModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw (IllegalArgumentException)
192 return m_pProperties->convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
195 //--------------------------------------------------------------------
196 void SAL_CALL ImplInspectorModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception)
198 m_pProperties->setFastPropertyValue( nHandle, rValue );
201 //--------------------------------------------------------------------
202 void SAL_CALL ImplInspectorModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
204 m_pProperties->getFastPropertyValue( rValue, nHandle );
207 //--------------------------------------------------------------------
208 ::sal_Bool SAL_CALL ImplInspectorModel::getHasHelpSection() throw (RuntimeException)
210 return m_pProperties->hasHelpSection();
213 //--------------------------------------------------------------------
214 ::sal_Int32 SAL_CALL ImplInspectorModel::getMinHelpTextLines() throw (RuntimeException)
216 return m_pProperties->getMinHelpTextLines();
219 //--------------------------------------------------------------------
220 ::sal_Int32 SAL_CALL ImplInspectorModel::getMaxHelpTextLines() throw (RuntimeException)
222 return m_pProperties->getMaxHelpTextLines();
225 //--------------------------------------------------------------------
226 ::sal_Bool SAL_CALL ImplInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException)
228 return m_pProperties->isReadOnly();
231 //--------------------------------------------------------------------
232 void SAL_CALL ImplInspectorModel::setIsReadOnly( ::sal_Bool _IsReadOnly ) throw (::com::sun::star::uno::RuntimeException)
234 setFastPropertyValue( MODEL_PROPERTY_ID_IS_READ_ONLY, makeAny( _IsReadOnly ) );
237 //--------------------------------------------------------------------
238 ::sal_Bool SAL_CALL ImplInspectorModel::supportsService( const OUString& ServiceName ) throw (RuntimeException)
240 StlSyntaxSequence< OUString > aSupported( getSupportedServiceNames() );
241 for ( StlSyntaxSequence< OUString >::const_iterator check = aSupported.begin();
242 check != aSupported.end();
243 ++check
245 if ( check->equals( ServiceName ) )
246 return sal_True;
248 return sal_False;
251 //--------------------------------------------------------------------
252 void ImplInspectorModel::enableHelpSectionProperties( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
254 m_pProperties->constructWithHelpSection( _nMinHelpTextLines, _nMaxHelpTextLines );
257 //........................................................................
258 } // namespace pcr
259 //........................................................................
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */