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