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 :
27 : //........................................................................
28 : namespace pcr
29 : {
30 : //........................................................................
31 :
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
36 :
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;
48 :
49 : namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
50 :
51 : //====================================================================
52 : //= InspectorModelProperties
53 : //====================================================================
54 : /** helper class for implementing the property set related functionality
55 : of an ImplInspectorModel
56 : */
57 4 : class InspectorModelProperties : public ::comphelper::OPropertyContainerHelper
58 : {
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;
67 :
68 : public:
69 : InspectorModelProperties( ::osl::Mutex& _rMutex );
70 :
71 : using ::comphelper::OPropertyContainerHelper::convertFastPropertyValue;
72 : using ::comphelper::OPropertyContainerHelper::setFastPropertyValue;
73 : using ::comphelper::OPropertyContainerHelper::getFastPropertyValue;
74 :
75 : public:
76 2 : inline sal_Bool hasHelpSection() const { return m_bHasHelpSection; }
77 0 : inline sal_Bool isReadOnly() const { return m_bIsReadOnly; }
78 2 : inline sal_Int32 getMinHelpTextLines() const { return m_nMinHelpTextLines; }
79 2 : inline sal_Int32 getMaxHelpTextLines() const { return m_nMaxHelpTextLines; }
80 :
81 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
82 : getPropertySetInfo();
83 : ::cppu::IPropertyArrayHelper&
84 : getInfoHelper();
85 :
86 : void constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
87 : };
88 :
89 : //====================================================================
90 : //= InspectorModelProperties
91 : //====================================================================
92 : //--------------------------------------------------------------------
93 4 : InspectorModelProperties::InspectorModelProperties( ::osl::Mutex& _rMutex )
94 : :m_rMutex( _rMutex )
95 : ,m_bHasHelpSection( sal_False )
96 : ,m_nMinHelpTextLines( 3 )
97 : ,m_nMaxHelpTextLines( 8 )
98 4 : ,m_bIsReadOnly( sal_False )
99 : {
100 : registerProperty(
101 : OUString( "HasHelpSection" ),
102 : MODEL_PROPERTY_ID_HAS_HELP_SECTION,
103 : PropertyAttribute::READONLY,
104 4 : &m_bHasHelpSection, ::getCppuType( &m_bHasHelpSection )
105 4 : );
106 : registerProperty(
107 : OUString( "MinHelpTextLines" ),
108 : MODEL_PROPERTY_ID_MIN_HELP_TEXT_LINES,
109 : PropertyAttribute::READONLY,
110 4 : &m_nMinHelpTextLines, ::getCppuType( &m_nMinHelpTextLines )
111 4 : );
112 : registerProperty(
113 : OUString( "MaxHelpTextLines" ),
114 : MODEL_PROPERTY_ID_MAX_HELP_TEXT_LINES,
115 : PropertyAttribute::READONLY,
116 4 : &m_nMaxHelpTextLines, ::getCppuType( &m_nMaxHelpTextLines )
117 4 : );
118 : registerProperty(
119 : OUString( "IsReadOnly" ),
120 : MODEL_PROPERTY_ID_IS_READ_ONLY,
121 : PropertyAttribute::BOUND,
122 4 : &m_bIsReadOnly, ::getCppuType( &m_bIsReadOnly )
123 4 : );
124 4 : }
125 :
126 : //--------------------------------------------------------------------
127 0 : void InspectorModelProperties::constructWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
128 : {
129 0 : m_bHasHelpSection = sal_True;
130 0 : m_nMinHelpTextLines = _nMinHelpTextLines;
131 0 : 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.
134 0 : }
135 :
136 : //--------------------------------------------------------------------
137 12 : ::cppu::IPropertyArrayHelper& InspectorModelProperties::getInfoHelper()
138 : {
139 12 : ::osl::MutexGuard aGuard( m_rMutex );
140 12 : if ( m_pPropertyInfo.get() == NULL )
141 : {
142 4 : Sequence< Property > aProperties;
143 4 : describeProperties( aProperties );
144 :
145 4 : m_pPropertyInfo.reset( new ::cppu::OPropertyArrayHelper( aProperties ) );
146 : }
147 12 : return *m_pPropertyInfo;
148 : }
149 :
150 : //--------------------------------------------------------------------
151 0 : Reference< XPropertySetInfo > InspectorModelProperties::getPropertySetInfo()
152 : {
153 0 : return ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
154 : }
155 :
156 : //====================================================================
157 : //= ImplInspectorModel
158 : //====================================================================
159 4 : ImplInspectorModel::ImplInspectorModel()
160 4 : :ImplInspectorModel_PBase( GetBroadcastHelper() )
161 8 : ,m_pProperties( new InspectorModelProperties( m_aMutex ) )
162 : {
163 4 : }
164 :
165 : //--------------------------------------------------------------------
166 4 : ImplInspectorModel::~ImplInspectorModel()
167 : {
168 4 : }
169 :
170 : //--------------------------------------------------------------------
171 218 : IMPLEMENT_FORWARD_XINTERFACE2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
172 :
173 : //--------------------------------------------------------------------
174 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ImplInspectorModel, ImplInspectorModel_Base, ImplInspectorModel_PBase )
175 :
176 : //--------------------------------------------------------------------
177 0 : Reference< XPropertySetInfo > SAL_CALL ImplInspectorModel::getPropertySetInfo( ) throw (RuntimeException)
178 : {
179 0 : return m_pProperties->getPropertySetInfo();
180 : }
181 :
182 : //--------------------------------------------------------------------
183 12 : ::cppu::IPropertyArrayHelper& SAL_CALL ImplInspectorModel::getInfoHelper()
184 : {
185 12 : return m_pProperties->getInfoHelper();
186 : }
187 :
188 : //--------------------------------------------------------------------
189 0 : sal_Bool SAL_CALL ImplInspectorModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw (IllegalArgumentException)
190 : {
191 0 : return m_pProperties->convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
192 : }
193 :
194 : //--------------------------------------------------------------------
195 0 : void SAL_CALL ImplInspectorModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception)
196 : {
197 0 : m_pProperties->setFastPropertyValue( nHandle, rValue );
198 0 : }
199 :
200 : //--------------------------------------------------------------------
201 0 : void SAL_CALL ImplInspectorModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
202 : {
203 0 : m_pProperties->getFastPropertyValue( rValue, nHandle );
204 0 : }
205 :
206 : //--------------------------------------------------------------------
207 2 : ::sal_Bool SAL_CALL ImplInspectorModel::getHasHelpSection() throw (RuntimeException)
208 : {
209 2 : return m_pProperties->hasHelpSection();
210 : }
211 :
212 : //--------------------------------------------------------------------
213 2 : ::sal_Int32 SAL_CALL ImplInspectorModel::getMinHelpTextLines() throw (RuntimeException)
214 : {
215 2 : return m_pProperties->getMinHelpTextLines();
216 : }
217 :
218 : //--------------------------------------------------------------------
219 2 : ::sal_Int32 SAL_CALL ImplInspectorModel::getMaxHelpTextLines() throw (RuntimeException)
220 : {
221 2 : return m_pProperties->getMaxHelpTextLines();
222 : }
223 :
224 : //--------------------------------------------------------------------
225 0 : ::sal_Bool SAL_CALL ImplInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException)
226 : {
227 0 : return m_pProperties->isReadOnly();
228 : }
229 :
230 : //--------------------------------------------------------------------
231 0 : void SAL_CALL ImplInspectorModel::setIsReadOnly( ::sal_Bool _IsReadOnly ) throw (::com::sun::star::uno::RuntimeException)
232 : {
233 0 : setFastPropertyValue( MODEL_PROPERTY_ID_IS_READ_ONLY, makeAny( _IsReadOnly ) );
234 0 : }
235 :
236 : //--------------------------------------------------------------------
237 0 : ::sal_Bool SAL_CALL ImplInspectorModel::supportsService( const OUString& ServiceName ) throw (RuntimeException)
238 : {
239 0 : StlSyntaxSequence< OUString > aSupported( getSupportedServiceNames() );
240 0 : for ( StlSyntaxSequence< OUString >::const_iterator check = aSupported.begin();
241 0 : check != aSupported.end();
242 : ++check
243 : )
244 0 : if ( check->equals( ServiceName ) )
245 0 : return sal_True;
246 :
247 0 : return sal_False;
248 : }
249 :
250 : //--------------------------------------------------------------------
251 0 : void ImplInspectorModel::enableHelpSectionProperties( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
252 : {
253 0 : m_pProperties->constructWithHelpSection( _nMinHelpTextLines, _nMaxHelpTextLines );
254 0 : }
255 :
256 : //........................................................................
257 3 : } // namespace pcr
258 : //........................................................................
259 :
260 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|