Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / extensions / source / propctrlr / inspectormodelbase.cxx
blob3da1c29f56509d7da49f9ba63e3b399f8d0963b6
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 <memory>
21 #include "inspectormodelbase.hxx"
22 #include "pcrcommon.hxx"
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <comphelper/propertycontainerhelper.hxx>
27 #include <cppuhelper/supportsservice.hxx>
30 namespace pcr
34 #define MODEL_PROPERTY_ID_HAS_HELP_SECTION 2000
35 #define MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES 2001
36 #define MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES 2002
37 #define MODEL_PROPERTY_ID_IS_READ_ONLY 2003
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::beans::XPropertySetInfo;
41 using ::com::sun::star::uno::RuntimeException;
42 using ::com::sun::star::uno::Any;
43 using ::com::sun::star::lang::IllegalArgumentException;
44 using ::com::sun::star::uno::Exception;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::makeAny;
47 using ::com::sun::star::beans::Property;
49 namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
52 //= InspectorModelProperties
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 bool m_bHasHelpSection;
62 sal_Int32 m_nMinHelpTextLines;
63 sal_Int32 m_nMaxHelpTextLines;
64 bool m_bIsReadOnly;
65 std::unique_ptr< ::cppu::IPropertyArrayHelper >
66 m_pPropertyInfo;
68 public:
69 explicit InspectorModelProperties( ::osl::Mutex& _rMutex );
71 using ::comphelper::OPropertyContainerHelper::convertFastPropertyValue;
72 using ::comphelper::OPropertyContainerHelper::setFastPropertyValue;
73 using ::comphelper::OPropertyContainerHelper::getFastPropertyValue;
75 public:
76 bool hasHelpSection() const { return m_bHasHelpSection; }
77 bool isReadOnly() const { return m_bIsReadOnly; }
78 sal_Int32 getMinHelpTextLines() const { return m_nMinHelpTextLines; }
79 sal_Int32 getMaxHelpTextLines() const { return m_nMaxHelpTextLines; }
81 css::uno::Reference< css::beans::XPropertySetInfo >
82 getPropertySetInfo();
83 ::cppu::IPropertyArrayHelper&
84 getInfoHelper();
86 void constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
90 //= InspectorModelProperties
93 InspectorModelProperties::InspectorModelProperties( ::osl::Mutex& _rMutex )
94 :m_rMutex( _rMutex )
95 ,m_bHasHelpSection( false )
96 ,m_nMinHelpTextLines( 3 )
97 ,m_nMaxHelpTextLines( 8 )
98 ,m_bIsReadOnly( false )
100 registerProperty(
101 "HasHelpSection",
102 MODEL_PROPERTY_ID_HAS_HELP_SECTION,
103 PropertyAttribute::READONLY,
104 &m_bHasHelpSection, cppu::UnoType<decltype(m_bHasHelpSection)>::get()
106 registerProperty(
107 "MinHelpTextLines",
108 MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES,
109 PropertyAttribute::READONLY,
110 &m_nMinHelpTextLines, cppu::UnoType<decltype(m_nMinHelpTextLines)>::get()
112 registerProperty(
113 "MaxHelpTextLines",
114 MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES,
115 PropertyAttribute::READONLY,
116 &m_nMaxHelpTextLines, cppu::UnoType<decltype(m_nMaxHelpTextLines)>::get()
118 registerProperty(
119 "IsReadOnly",
120 MODEL_PROPERTY_ID_IS_READ_ONLY,
121 PropertyAttribute::BOUND,
122 &m_bIsReadOnly, cppu::UnoType<decltype(m_bIsReadOnly)>::get()
127 void InspectorModelProperties::constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
129 m_bHasHelpSection = 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.
137 ::cppu::IPropertyArrayHelper& InspectorModelProperties::getInfoHelper()
139 ::osl::MutexGuard aGuard( m_rMutex );
140 if ( m_pPropertyInfo.get() == nullptr )
142 Sequence< Property > aProperties;
143 describeProperties( aProperties );
145 m_pPropertyInfo.reset( new ::cppu::OPropertyArrayHelper( aProperties ) );
147 return *m_pPropertyInfo;
151 Reference< XPropertySetInfo > InspectorModelProperties::getPropertySetInfo()
153 return ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
157 //= ImplInspectorModel
159 ImplInspectorModel::ImplInspectorModel()
160 :ImplInspectorModel_PBase( GetBroadcastHelper() )
161 ,m_pProperties( new InspectorModelProperties( m_aMutex ) )
166 ImplInspectorModel::~ImplInspectorModel()
171 IMPLEMENT_FORWARD_XINTERFACE2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
174 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
177 Reference< XPropertySetInfo > SAL_CALL ImplInspectorModel::getPropertySetInfo( )
179 return m_pProperties->getPropertySetInfo();
183 ::cppu::IPropertyArrayHelper& SAL_CALL ImplInspectorModel::getInfoHelper()
185 return m_pProperties->getInfoHelper();
189 sal_Bool SAL_CALL ImplInspectorModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue )
191 return m_pProperties->convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
195 void SAL_CALL ImplInspectorModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue )
197 m_pProperties->setFastPropertyValue( nHandle, rValue );
201 void SAL_CALL ImplInspectorModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
203 m_pProperties->getFastPropertyValue( rValue, nHandle );
207 sal_Bool SAL_CALL ImplInspectorModel::getHasHelpSection()
209 return m_pProperties->hasHelpSection();
213 ::sal_Int32 SAL_CALL ImplInspectorModel::getMinHelpTextLines()
215 return m_pProperties->getMinHelpTextLines();
219 ::sal_Int32 SAL_CALL ImplInspectorModel::getMaxHelpTextLines()
221 return m_pProperties->getMaxHelpTextLines();
225 sal_Bool SAL_CALL ImplInspectorModel::getIsReadOnly()
227 return m_pProperties->isReadOnly();
231 void SAL_CALL ImplInspectorModel::setIsReadOnly( sal_Bool IsReadOnly )
233 setFastPropertyValue( MODEL_PROPERTY_ID_IS_READ_ONLY, makeAny( IsReadOnly ) );
236 sal_Bool SAL_CALL ImplInspectorModel::supportsService( const OUString& ServiceName )
238 return cppu::supportsService(this, ServiceName);
242 void ImplInspectorModel::enableHelpSectionProperties( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
244 m_pProperties->constructWithHelpSection( _nMinHelpTextLines, _nMaxHelpTextLines );
248 } // namespace pcr
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */