bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / propctrlr / inspectormodelbase.cxx
blobf66847387499905dc4a4080c7561a2d035407a72
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::Any;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::makeAny;
44 using ::com::sun::star::beans::Property;
46 namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
49 //= InspectorModelProperties
51 /** helper class for implementing the property set related functionality
52 of an ImplInspectorModel
54 class InspectorModelProperties : public ::comphelper::OPropertyContainerHelper
56 private:
57 ::osl::Mutex& m_rMutex;
58 bool m_bHasHelpSection;
59 sal_Int32 m_nMinHelpTextLines;
60 sal_Int32 m_nMaxHelpTextLines;
61 bool m_bIsReadOnly;
62 std::unique_ptr< ::cppu::IPropertyArrayHelper >
63 m_pPropertyInfo;
65 public:
66 explicit InspectorModelProperties( ::osl::Mutex& _rMutex );
68 using ::comphelper::OPropertyContainerHelper::convertFastPropertyValue;
69 using ::comphelper::OPropertyContainerHelper::setFastPropertyValue;
70 using ::comphelper::OPropertyContainerHelper::getFastPropertyValue;
72 public:
73 bool hasHelpSection() const { return m_bHasHelpSection; }
74 bool isReadOnly() const { return m_bIsReadOnly; }
75 sal_Int32 getMinHelpTextLines() const { return m_nMinHelpTextLines; }
76 sal_Int32 getMaxHelpTextLines() const { return m_nMaxHelpTextLines; }
78 css::uno::Reference< css::beans::XPropertySetInfo >
79 getPropertySetInfo();
80 ::cppu::IPropertyArrayHelper&
81 getInfoHelper();
83 void constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
87 //= InspectorModelProperties
90 InspectorModelProperties::InspectorModelProperties( ::osl::Mutex& _rMutex )
91 :m_rMutex( _rMutex )
92 ,m_bHasHelpSection( false )
93 ,m_nMinHelpTextLines( 3 )
94 ,m_nMaxHelpTextLines( 8 )
95 ,m_bIsReadOnly( false )
97 registerProperty(
98 "HasHelpSection",
99 MODEL_PROPERTY_ID_HAS_HELP_SECTION,
100 PropertyAttribute::READONLY,
101 &m_bHasHelpSection, cppu::UnoType<decltype(m_bHasHelpSection)>::get()
103 registerProperty(
104 "MinHelpTextLines",
105 MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES,
106 PropertyAttribute::READONLY,
107 &m_nMinHelpTextLines, cppu::UnoType<decltype(m_nMinHelpTextLines)>::get()
109 registerProperty(
110 "MaxHelpTextLines",
111 MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES,
112 PropertyAttribute::READONLY,
113 &m_nMaxHelpTextLines, cppu::UnoType<decltype(m_nMaxHelpTextLines)>::get()
115 registerProperty(
116 "IsReadOnly",
117 MODEL_PROPERTY_ID_IS_READ_ONLY,
118 PropertyAttribute::BOUND,
119 &m_bIsReadOnly, cppu::UnoType<decltype(m_bIsReadOnly)>::get()
124 void InspectorModelProperties::constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
126 m_bHasHelpSection = true;
127 m_nMinHelpTextLines = _nMinHelpTextLines;
128 m_nMaxHelpTextLines = _nMaxHelpTextLines;
129 // no need to notify this, those properties are not bound. Also, the method should
130 // only be used during construction phase, where we don't expect to have any listeners.
134 ::cppu::IPropertyArrayHelper& InspectorModelProperties::getInfoHelper()
136 ::osl::MutexGuard aGuard( m_rMutex );
137 if (m_pPropertyInfo == nullptr)
139 Sequence< Property > aProperties;
140 describeProperties( aProperties );
142 m_pPropertyInfo.reset( new ::cppu::OPropertyArrayHelper( aProperties ) );
144 return *m_pPropertyInfo;
148 Reference< XPropertySetInfo > InspectorModelProperties::getPropertySetInfo()
150 return ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
154 //= ImplInspectorModel
156 ImplInspectorModel::ImplInspectorModel()
157 :ImplInspectorModel_PBase( GetBroadcastHelper() )
158 ,m_pProperties( new InspectorModelProperties( m_aMutex ) )
163 ImplInspectorModel::~ImplInspectorModel()
168 IMPLEMENT_FORWARD_XINTERFACE2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
171 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
174 Reference< XPropertySetInfo > SAL_CALL ImplInspectorModel::getPropertySetInfo( )
176 return m_pProperties->getPropertySetInfo();
180 ::cppu::IPropertyArrayHelper& SAL_CALL ImplInspectorModel::getInfoHelper()
182 return m_pProperties->getInfoHelper();
186 sal_Bool SAL_CALL ImplInspectorModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue )
188 return m_pProperties->convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
192 void SAL_CALL ImplInspectorModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue )
194 m_pProperties->setFastPropertyValue( nHandle, rValue );
198 void SAL_CALL ImplInspectorModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
200 m_pProperties->getFastPropertyValue( rValue, nHandle );
204 sal_Bool SAL_CALL ImplInspectorModel::getHasHelpSection()
206 return m_pProperties->hasHelpSection();
210 ::sal_Int32 SAL_CALL ImplInspectorModel::getMinHelpTextLines()
212 return m_pProperties->getMinHelpTextLines();
216 ::sal_Int32 SAL_CALL ImplInspectorModel::getMaxHelpTextLines()
218 return m_pProperties->getMaxHelpTextLines();
222 sal_Bool SAL_CALL ImplInspectorModel::getIsReadOnly()
224 return m_pProperties->isReadOnly();
228 void SAL_CALL ImplInspectorModel::setIsReadOnly( sal_Bool IsReadOnly )
230 setFastPropertyValue( MODEL_PROPERTY_ID_IS_READ_ONLY, makeAny( IsReadOnly ) );
233 sal_Bool SAL_CALL ImplInspectorModel::supportsService( const OUString& ServiceName )
235 return cppu::supportsService(this, ServiceName);
239 void ImplInspectorModel::enableHelpSectionProperties( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
241 m_pProperties->constructWithHelpSection( _nMinHelpTextLines, _nMaxHelpTextLines );
245 } // namespace pcr
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */