1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "inspectormodelbase.hxx"
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <comphelper/propertycontainerhelper.hxx>
26 #include <cppuhelper/supportsservice.hxx>
33 enum class ModelPropertyId
35 HAS_HELP_SECTION
= 2000,
36 MIN_HELP_TEXT_LINES
= 2001,
37 MAX_HELP_TEXT_LINES
= 2002,
41 using ::com::sun::star::uno::Reference
;
42 using ::com::sun::star::beans::XPropertySetInfo
;
43 using ::com::sun::star::uno::Any
;
44 using ::com::sun::star::uno::Sequence
;
45 using ::com::sun::star::beans::Property
;
47 namespace PropertyAttribute
= ::com::sun::star::beans::PropertyAttribute
;
50 //= InspectorModelProperties
52 /** helper class for implementing the property set related functionality
53 of an ImplInspectorModel
55 class InspectorModelProperties
: public ::comphelper::OPropertyContainerHelper
58 ::osl::Mutex
& m_rMutex
;
59 bool m_bHasHelpSection
;
60 sal_Int32 m_nMinHelpTextLines
;
61 sal_Int32 m_nMaxHelpTextLines
;
63 std::unique_ptr
< ::cppu::IPropertyArrayHelper
>
67 explicit InspectorModelProperties( ::osl::Mutex
& _rMutex
);
69 using ::comphelper::OPropertyContainerHelper::convertFastPropertyValue
;
70 using ::comphelper::OPropertyContainerHelper::setFastPropertyValue
;
71 using ::comphelper::OPropertyContainerHelper::getFastPropertyValue
;
74 bool hasHelpSection() const { return m_bHasHelpSection
; }
75 bool isReadOnly() const { return m_bIsReadOnly
; }
76 sal_Int32
getMinHelpTextLines() const { return m_nMinHelpTextLines
; }
77 sal_Int32
getMaxHelpTextLines() const { return m_nMaxHelpTextLines
; }
79 css::uno::Reference
< css::beans::XPropertySetInfo
>
81 ::cppu::IPropertyArrayHelper
&
84 void constructWithHelpSection( sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
);
88 //= InspectorModelProperties
91 InspectorModelProperties::InspectorModelProperties( ::osl::Mutex
& _rMutex
)
93 ,m_bHasHelpSection( false )
94 ,m_nMinHelpTextLines( 3 )
95 ,m_nMaxHelpTextLines( 8 )
96 ,m_bIsReadOnly( false )
99 u
"HasHelpSection"_ustr
,
100 static_cast<sal_Int32
>(ModelPropertyId::HAS_HELP_SECTION
),
101 PropertyAttribute::READONLY
,
102 &m_bHasHelpSection
, cppu::UnoType
<decltype(m_bHasHelpSection
)>::get()
105 u
"MinHelpTextLines"_ustr
,
106 static_cast<sal_Int32
>(ModelPropertyId::MIN_HELP_TEXT_LINES
),
107 PropertyAttribute::READONLY
,
108 &m_nMinHelpTextLines
, cppu::UnoType
<decltype(m_nMinHelpTextLines
)>::get()
111 u
"MaxHelpTextLines"_ustr
,
112 static_cast<sal_Int32
>(ModelPropertyId::MAX_HELP_TEXT_LINES
),
113 PropertyAttribute::READONLY
,
114 &m_nMaxHelpTextLines
, cppu::UnoType
<decltype(m_nMaxHelpTextLines
)>::get()
118 static_cast<sal_Int32
>(ModelPropertyId::IS_READ_ONLY
),
119 PropertyAttribute::BOUND
,
120 &m_bIsReadOnly
, cppu::UnoType
<decltype(m_bIsReadOnly
)>::get()
125 void InspectorModelProperties::constructWithHelpSection( sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
)
127 m_bHasHelpSection
= true;
128 m_nMinHelpTextLines
= _nMinHelpTextLines
;
129 m_nMaxHelpTextLines
= _nMaxHelpTextLines
;
130 // no need to notify this, those properties are not bound. Also, the method should
131 // only be used during construction phase, where we don't expect to have any listeners.
135 ::cppu::IPropertyArrayHelper
& InspectorModelProperties::getInfoHelper()
137 ::osl::MutexGuard
aGuard( m_rMutex
);
138 if (m_pPropertyInfo
== nullptr)
140 Sequence
< Property
> aProperties
;
141 describeProperties( aProperties
);
143 m_pPropertyInfo
.reset( new ::cppu::OPropertyArrayHelper( aProperties
) );
145 return *m_pPropertyInfo
;
149 Reference
< XPropertySetInfo
> InspectorModelProperties::getPropertySetInfo()
151 return ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
155 //= ImplInspectorModel
157 ImplInspectorModel::ImplInspectorModel()
158 :ImplInspectorModel_PBase( GetBroadcastHelper() )
159 ,m_pProperties( new InspectorModelProperties( m_aMutex
) )
164 ImplInspectorModel::~ImplInspectorModel()
169 IMPLEMENT_FORWARD_XINTERFACE2( ImplInspectorModel
, ImplInspectorModel_Base
, ImplInspectorModel_PBase
)
172 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ImplInspectorModel
, ImplInspectorModel_Base
, ImplInspectorModel_PBase
)
175 Reference
< XPropertySetInfo
> SAL_CALL
ImplInspectorModel::getPropertySetInfo( )
177 return m_pProperties
->getPropertySetInfo();
181 ::cppu::IPropertyArrayHelper
& SAL_CALL
ImplInspectorModel::getInfoHelper()
183 return m_pProperties
->getInfoHelper();
187 sal_Bool SAL_CALL
ImplInspectorModel::convertFastPropertyValue( Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nHandle
, const Any
& rValue
)
189 return m_pProperties
->convertFastPropertyValue( rConvertedValue
, rOldValue
, nHandle
, rValue
);
193 void SAL_CALL
ImplInspectorModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const Any
& rValue
)
195 m_pProperties
->setFastPropertyValue( nHandle
, rValue
);
199 void SAL_CALL
ImplInspectorModel::getFastPropertyValue( Any
& rValue
, sal_Int32 nHandle
) const
201 m_pProperties
->getFastPropertyValue( rValue
, nHandle
);
205 sal_Bool SAL_CALL
ImplInspectorModel::getHasHelpSection()
207 return m_pProperties
->hasHelpSection();
211 ::sal_Int32 SAL_CALL
ImplInspectorModel::getMinHelpTextLines()
213 return m_pProperties
->getMinHelpTextLines();
217 ::sal_Int32 SAL_CALL
ImplInspectorModel::getMaxHelpTextLines()
219 return m_pProperties
->getMaxHelpTextLines();
223 sal_Bool SAL_CALL
ImplInspectorModel::getIsReadOnly()
225 return m_pProperties
->isReadOnly();
229 void SAL_CALL
ImplInspectorModel::setIsReadOnly( sal_Bool IsReadOnly
)
231 setFastPropertyValue( static_cast<sal_Int32
>(ModelPropertyId::IS_READ_ONLY
), Any( IsReadOnly
) );
234 sal_Bool SAL_CALL
ImplInspectorModel::supportsService( const OUString
& ServiceName
)
236 return cppu::supportsService(this, ServiceName
);
240 void ImplInspectorModel::enableHelpSectionProperties( sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
)
242 m_pProperties
->constructWithHelpSection( _nMinHelpTextLines
, _nMaxHelpTextLines
);
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */