Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "inspectormodelbase.hxx"
21 : #include "pcrcommon.hxx"
22 :
23 : #include <com/sun/star/beans/PropertyAttribute.hpp>
24 :
25 : #include <comphelper/propertycontainerhelper.hxx>
26 : #include <cppuhelper/supportsservice.hxx>
27 :
28 :
29 : namespace pcr
30 : {
31 :
32 :
33 : #define MODEL_PROPERTY_ID_HAS_HELP_SECTION 2000
34 : #define MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES 2001
35 : #define MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES 2002
36 : #define MODEL_PROPERTY_ID_IS_READ_ONLY 2003
37 :
38 : using ::com::sun::star::uno::Reference;
39 : using ::com::sun::star::uno::XComponentContext;
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::inspection::PropertyCategoryDescriptor;
47 : using ::com::sun::star::uno::makeAny;
48 : using ::com::sun::star::beans::Property;
49 :
50 : namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
51 :
52 :
53 : //= InspectorModelProperties
54 :
55 : /** helper class for implementing the property set related functionality
56 : of an ImplInspectorModel
57 : */
58 12 : class InspectorModelProperties : public ::comphelper::OPropertyContainerHelper
59 : {
60 : private:
61 : ::osl::Mutex& m_rMutex;
62 : bool m_bHasHelpSection;
63 : sal_Int32 m_nMinHelpTextLines;
64 : sal_Int32 m_nMaxHelpTextLines;
65 : bool m_bIsReadOnly;
66 : ::std::unique_ptr< ::cppu::IPropertyArrayHelper >
67 : m_pPropertyInfo;
68 :
69 : public:
70 : InspectorModelProperties( ::osl::Mutex& _rMutex );
71 :
72 : using ::comphelper::OPropertyContainerHelper::convertFastPropertyValue;
73 : using ::comphelper::OPropertyContainerHelper::setFastPropertyValue;
74 : using ::comphelper::OPropertyContainerHelper::getFastPropertyValue;
75 :
76 : public:
77 4 : inline bool hasHelpSection() const { return m_bHasHelpSection; }
78 0 : inline bool isReadOnly() const { return m_bIsReadOnly; }
79 4 : inline sal_Int32 getMinHelpTextLines() const { return m_nMinHelpTextLines; }
80 4 : inline sal_Int32 getMaxHelpTextLines() const { return m_nMaxHelpTextLines; }
81 :
82 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
83 : getPropertySetInfo();
84 : ::cppu::IPropertyArrayHelper&
85 : getInfoHelper();
86 :
87 : void constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
88 : };
89 :
90 :
91 : //= InspectorModelProperties
92 :
93 :
94 12 : InspectorModelProperties::InspectorModelProperties( ::osl::Mutex& _rMutex )
95 : :m_rMutex( _rMutex )
96 : ,m_bHasHelpSection( false )
97 : ,m_nMinHelpTextLines( 3 )
98 : ,m_nMaxHelpTextLines( 8 )
99 12 : ,m_bIsReadOnly( false )
100 : {
101 : registerProperty(
102 : OUString( "HasHelpSection" ),
103 : MODEL_PROPERTY_ID_HAS_HELP_SECTION,
104 : PropertyAttribute::READONLY,
105 12 : &m_bHasHelpSection, ::getCppuType( &m_bHasHelpSection )
106 12 : );
107 : registerProperty(
108 : OUString( "MinHelpTextLines" ),
109 : MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES,
110 : PropertyAttribute::READONLY,
111 12 : &m_nMinHelpTextLines, ::getCppuType( &m_nMinHelpTextLines )
112 12 : );
113 : registerProperty(
114 : OUString( "MaxHelpTextLines" ),
115 : MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES,
116 : PropertyAttribute::READONLY,
117 12 : &m_nMaxHelpTextLines, ::getCppuType( &m_nMaxHelpTextLines )
118 12 : );
119 : registerProperty(
120 : OUString( "IsReadOnly" ),
121 : MODEL_PROPERTY_ID_IS_READ_ONLY,
122 : PropertyAttribute::BOUND,
123 12 : &m_bIsReadOnly, ::getCppuType( &m_bIsReadOnly )
124 12 : );
125 12 : }
126 :
127 :
128 0 : void InspectorModelProperties::constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
129 : {
130 0 : m_bHasHelpSection = true;
131 0 : m_nMinHelpTextLines = _nMinHelpTextLines;
132 0 : m_nMaxHelpTextLines = _nMaxHelpTextLines;
133 : // no need to notify this, those properties are not bound. Also, the method should
134 : // only be used during construction phase, where we don't expect to have any listeners.
135 0 : }
136 :
137 :
138 24 : ::cppu::IPropertyArrayHelper& InspectorModelProperties::getInfoHelper()
139 : {
140 24 : ::osl::MutexGuard aGuard( m_rMutex );
141 24 : if ( m_pPropertyInfo.get() == NULL )
142 : {
143 8 : Sequence< Property > aProperties;
144 8 : describeProperties( aProperties );
145 :
146 8 : m_pPropertyInfo.reset( new ::cppu::OPropertyArrayHelper( aProperties ) );
147 : }
148 24 : return *m_pPropertyInfo;
149 : }
150 :
151 :
152 0 : Reference< XPropertySetInfo > InspectorModelProperties::getPropertySetInfo()
153 : {
154 0 : return ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
155 : }
156 :
157 :
158 : //= ImplInspectorModel
159 :
160 12 : ImplInspectorModel::ImplInspectorModel()
161 12 : :ImplInspectorModel_PBase( GetBroadcastHelper() )
162 24 : ,m_pProperties( new InspectorModelProperties( m_aMutex ) )
163 : {
164 12 : }
165 :
166 :
167 12 : ImplInspectorModel::~ImplInspectorModel()
168 : {
169 12 : }
170 :
171 :
172 492 : IMPLEMENT_FORWARD_XINTERFACE2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
173 :
174 :
175 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
176 :
177 :
178 0 : Reference< XPropertySetInfo > SAL_CALL ImplInspectorModel::getPropertySetInfo( ) throw (RuntimeException, std::exception)
179 : {
180 0 : return m_pProperties->getPropertySetInfo();
181 : }
182 :
183 :
184 24 : ::cppu::IPropertyArrayHelper& SAL_CALL ImplInspectorModel::getInfoHelper()
185 : {
186 24 : return m_pProperties->getInfoHelper();
187 : }
188 :
189 :
190 0 : sal_Bool SAL_CALL ImplInspectorModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw (IllegalArgumentException)
191 : {
192 0 : return m_pProperties->convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
193 : }
194 :
195 :
196 0 : void SAL_CALL ImplInspectorModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception, std::exception)
197 : {
198 0 : m_pProperties->setFastPropertyValue( nHandle, rValue );
199 0 : }
200 :
201 :
202 0 : void SAL_CALL ImplInspectorModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
203 : {
204 0 : m_pProperties->getFastPropertyValue( rValue, nHandle );
205 0 : }
206 :
207 :
208 4 : sal_Bool SAL_CALL ImplInspectorModel::getHasHelpSection() throw (RuntimeException, std::exception)
209 : {
210 4 : return m_pProperties->hasHelpSection();
211 : }
212 :
213 :
214 4 : ::sal_Int32 SAL_CALL ImplInspectorModel::getMinHelpTextLines() throw (RuntimeException, std::exception)
215 : {
216 4 : return m_pProperties->getMinHelpTextLines();
217 : }
218 :
219 :
220 4 : ::sal_Int32 SAL_CALL ImplInspectorModel::getMaxHelpTextLines() throw (RuntimeException, std::exception)
221 : {
222 4 : return m_pProperties->getMaxHelpTextLines();
223 : }
224 :
225 :
226 0 : sal_Bool SAL_CALL ImplInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException, std::exception)
227 : {
228 0 : return m_pProperties->isReadOnly();
229 : }
230 :
231 :
232 0 : void SAL_CALL ImplInspectorModel::setIsReadOnly( sal_Bool _IsReadOnly ) throw (::com::sun::star::uno::RuntimeException, std::exception)
233 : {
234 0 : setFastPropertyValue( MODEL_PROPERTY_ID_IS_READ_ONLY, makeAny( _IsReadOnly ) );
235 0 : }
236 :
237 0 : sal_Bool SAL_CALL ImplInspectorModel::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
238 : {
239 0 : return cppu::supportsService(this, ServiceName);
240 : }
241 :
242 :
243 0 : void ImplInspectorModel::enableHelpSectionProperties( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
244 : {
245 0 : m_pProperties->constructWithHelpSection( _nMinHelpTextLines, _nMaxHelpTextLines );
246 0 : }
247 :
248 :
249 12 : } // namespace pcr
250 :
251 :
252 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|