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 "modulepcr.hxx"
21 : #include "pcrcommon.hxx"
22 : #include "pcrservices.hxx"
23 : #include "inspectormodelbase.hxx"
24 :
25 : #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
26 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 :
28 : #include <cppuhelper/implbase3.hxx>
29 :
30 : #include <comphelper/broadcasthelper.hxx>
31 : #include <comphelper/uno3.hxx>
32 :
33 :
34 : namespace pcr
35 : {
36 :
37 :
38 : using ::com::sun::star::inspection::XObjectInspectorModel;
39 : using ::com::sun::star::lang::XInitialization;
40 : using ::com::sun::star::lang::XServiceInfo;
41 : using ::com::sun::star::uno::Reference;
42 : using ::com::sun::star::uno::XComponentContext;
43 : using ::com::sun::star::uno::RuntimeException;
44 : using ::com::sun::star::uno::Sequence;
45 : using ::com::sun::star::uno::Any;
46 : using ::com::sun::star::inspection::PropertyCategoryDescriptor;
47 : using ::com::sun::star::uno::Exception;
48 : using ::com::sun::star::uno::XInterface;
49 : using ::com::sun::star::lang::IllegalArgumentException;
50 : using ::com::sun::star::ucb::AlreadyInitializedException;
51 : using ::com::sun::star::beans::XPropertySetInfo;
52 : using ::com::sun::star::uno::makeAny;
53 :
54 :
55 : //= ObjectInspectorModel
56 :
57 20 : class ObjectInspectorModel : public ImplInspectorModel
58 : {
59 : private:
60 : Sequence< Any > m_aFactories;
61 :
62 : public:
63 : ObjectInspectorModel();
64 :
65 : // XObjectInspectorModel
66 : virtual Sequence< Any > SAL_CALL getHandlerFactories() throw (RuntimeException, std::exception) SAL_OVERRIDE;
67 : virtual Sequence< PropertyCategoryDescriptor > SAL_CALL describeCategories( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
68 : virtual ::sal_Int32 SAL_CALL getPropertyOrderIndex( const OUString& PropertyName ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
69 :
70 : // XInitialization
71 : virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException, std::exception) SAL_OVERRIDE;
72 :
73 : // XServiceInfo
74 : virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
75 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
76 :
77 : // XServiceInfo - static versions
78 : static OUString getImplementationName_static( ) throw(RuntimeException);
79 : static Sequence< OUString > getSupportedServiceNames_static( ) throw(RuntimeException);
80 : static Reference< XInterface > SAL_CALL
81 : Create(const Reference< XComponentContext >&);
82 :
83 : protected:
84 : void createDefault();
85 : void createWithHandlerFactories( const Sequence< Any >& _rFactories );
86 : void createWithHandlerFactoriesAndHelpSection( const Sequence< Any >& _rFactories, sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
87 :
88 : private:
89 : /** checks a given condition to be <TRUE/>, and throws an IllegalArgumentException if not
90 : */
91 : void impl_verifyArgument_throw( bool _bCondition, sal_Int16 _nArgumentPosition );
92 : };
93 :
94 :
95 : //= ObjectInspectorModel
96 :
97 10 : ObjectInspectorModel::ObjectInspectorModel()
98 10 : :ImplInspectorModel()
99 : {
100 10 : }
101 :
102 :
103 12 : Sequence< Any > SAL_CALL ObjectInspectorModel::getHandlerFactories() throw (RuntimeException, std::exception)
104 : {
105 12 : return m_aFactories;
106 : }
107 :
108 :
109 4 : Sequence< PropertyCategoryDescriptor > SAL_CALL ObjectInspectorModel::describeCategories( ) throw (RuntimeException, std::exception)
110 : {
111 : // no category info provided by this default implementation
112 4 : return Sequence< PropertyCategoryDescriptor >( );
113 : }
114 :
115 :
116 0 : ::sal_Int32 SAL_CALL ObjectInspectorModel::getPropertyOrderIndex( const OUString& /*PropertyName*/ ) throw (RuntimeException, std::exception)
117 : {
118 : // no ordering provided by this default implementation
119 0 : return 0;
120 : }
121 :
122 :
123 6 : void SAL_CALL ObjectInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException, std::exception)
124 : {
125 6 : ::osl::MutexGuard aGuard( m_aMutex );
126 6 : if ( m_aFactories.getLength() )
127 0 : throw AlreadyInitializedException();
128 :
129 6 : StlSyntaxSequence< Any > arguments( _arguments );
130 6 : if ( arguments.empty() )
131 : { // constructor: "createDefault()"
132 6 : createDefault();
133 6 : return;
134 : }
135 :
136 0 : Sequence< Any > factories;
137 0 : impl_verifyArgument_throw( arguments[0] >>= factories, 1 );
138 :
139 0 : if ( arguments.size() == 1 )
140 : { // constructor: "createWithHandlerFactories( any[] )"
141 0 : createWithHandlerFactories( factories );
142 0 : return;
143 : }
144 :
145 0 : sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
146 0 : if ( arguments.size() == 3 )
147 : { // constructor: "createWithHandlerFactoriesAndHelpSection( any[], long, long )"
148 0 : impl_verifyArgument_throw( arguments[1] >>= nMinHelpTextLines, 2 );
149 0 : impl_verifyArgument_throw( arguments[2] >>= nMaxHelpTextLines, 3 );
150 0 : createWithHandlerFactoriesAndHelpSection( factories, nMinHelpTextLines, nMaxHelpTextLines );
151 0 : return;
152 : }
153 :
154 0 : impl_verifyArgument_throw( false, 2 );
155 : }
156 :
157 :
158 0 : OUString SAL_CALL ObjectInspectorModel::getImplementationName( ) throw (RuntimeException, std::exception)
159 : {
160 0 : return getImplementationName_static();
161 : }
162 :
163 :
164 0 : Sequence< OUString > SAL_CALL ObjectInspectorModel::getSupportedServiceNames( ) throw (RuntimeException, std::exception)
165 : {
166 0 : return getSupportedServiceNames_static();
167 : }
168 :
169 :
170 4 : OUString ObjectInspectorModel::getImplementationName_static( ) throw(RuntimeException)
171 : {
172 4 : return OUString( "org.openoffice.comp.extensions.ObjectInspectorModel" );
173 : }
174 :
175 :
176 4 : Sequence< OUString > ObjectInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException)
177 : {
178 4 : OUString sService( "com.sun.star.inspection.ObjectInspectorModel" );
179 4 : return Sequence< OUString >( &sService, 1 );
180 : }
181 :
182 :
183 10 : Reference< XInterface > SAL_CALL ObjectInspectorModel::Create(const Reference< XComponentContext >& /* _rxContext */ )
184 : {
185 10 : return *( new ObjectInspectorModel() );
186 : }
187 :
188 :
189 6 : void ObjectInspectorModel::createDefault()
190 : {
191 6 : m_aFactories.realloc( 1 );
192 6 : m_aFactories[0] <<= OUString( "com.sun.star.inspection.GenericPropertyHandler" );
193 6 : }
194 :
195 :
196 0 : void ObjectInspectorModel::createWithHandlerFactories( const Sequence< Any >& _rFactories )
197 : {
198 0 : impl_verifyArgument_throw( _rFactories.getLength() > 0, 1 );
199 0 : m_aFactories = _rFactories;
200 0 : }
201 :
202 :
203 0 : void ObjectInspectorModel::createWithHandlerFactoriesAndHelpSection( const Sequence< Any >& _rFactories, sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
204 : {
205 0 : impl_verifyArgument_throw( _rFactories.getLength() > 0, 1 );
206 0 : impl_verifyArgument_throw( _nMinHelpTextLines >= 1, 2 );
207 0 : impl_verifyArgument_throw( _nMaxHelpTextLines >= 1, 3 );
208 0 : impl_verifyArgument_throw( _nMinHelpTextLines <= _nMaxHelpTextLines, 2 );
209 :
210 0 : m_aFactories = _rFactories;
211 0 : enableHelpSectionProperties( _nMinHelpTextLines, _nMaxHelpTextLines );
212 0 : }
213 :
214 :
215 0 : void ObjectInspectorModel::impl_verifyArgument_throw( bool _bCondition, sal_Int16 _nArgumentPosition )
216 : {
217 0 : if ( !_bCondition )
218 0 : throw IllegalArgumentException( OUString(), *this, _nArgumentPosition );
219 0 : }
220 :
221 :
222 : } // namespace pcr
223 :
224 :
225 :
226 4 : extern "C" void SAL_CALL createRegistryInfo_ObjectInspectorModel()
227 : {
228 4 : ::pcr::OAutoRegistration< ::pcr::ObjectInspectorModel > aObjectInspectorModelRegistration;
229 16 : }
230 :
231 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|