1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "modulepcr.hxx"
31 #include "pcrcommon.hxx"
32 #include "inspectormodelbase.hxx"
33 
34 /** === begin UNO includes === **/
35 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
36 #include <com/sun/star/lang/IllegalArgumentException.hpp>
37 /** === end UNO includes === **/
38 
39 #include <cppuhelper/implbase3.hxx>
40 
41 #include <comphelper/broadcasthelper.hxx>
42 #include <comphelper/uno3.hxx>
43 
44 //........................................................................
45 namespace pcr
46 {
47 //........................................................................
48 
49     /** === begin UNO using === **/
50     using ::com::sun::star::inspection::XObjectInspectorModel;
51     using ::com::sun::star::lang::XInitialization;
52     using ::com::sun::star::lang::XServiceInfo;
53     using ::com::sun::star::uno::Reference;
54     using ::com::sun::star::uno::XComponentContext;
55     using ::com::sun::star::uno::RuntimeException;
56     using ::com::sun::star::uno::Sequence;
57     using ::com::sun::star::uno::Any;
58     using ::com::sun::star::inspection::PropertyCategoryDescriptor;
59     using ::com::sun::star::uno::Exception;
60     using ::com::sun::star::uno::XInterface;
61     using ::com::sun::star::lang::IllegalArgumentException;
62     using ::com::sun::star::ucb::AlreadyInitializedException;
63     using ::com::sun::star::beans::XPropertySetInfo;
64     using ::com::sun::star::uno::makeAny;
65     /** === end UNO using === **/
66 
67     //====================================================================
68 	//= ObjectInspectorModel
69 	//====================================================================
70     class ObjectInspectorModel : public ImplInspectorModel
71 	{
72     private:
73         Sequence< Any >             m_aFactories;
74 
75     public:
76         ObjectInspectorModel( const Reference< XComponentContext >& _rxContext );
77 
78         // XObjectInspectorModel
79         virtual Sequence< Any > SAL_CALL getHandlerFactories() throw (RuntimeException);
80         virtual Sequence< PropertyCategoryDescriptor > SAL_CALL describeCategories(  ) throw (RuntimeException);
81         virtual ::sal_Int32 SAL_CALL getPropertyOrderIndex( const ::rtl::OUString& PropertyName ) throw (RuntimeException);
82 
83         // XInitialization
84         virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException);
85 
86         // XServiceInfo
87         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
88         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
89 
90         // XServiceInfo - static versions
91 		static ::rtl::OUString getImplementationName_static(  ) throw(RuntimeException);
92 		static Sequence< ::rtl::OUString > getSupportedServiceNames_static(  ) throw(RuntimeException);
93 		static Reference< XInterface > SAL_CALL
94 						Create(const Reference< XComponentContext >&);
95 
96     protected:
97         void    createDefault();
98         void    createWithHandlerFactories( const Sequence< Any >& _rFactories );
99         void    createWithHandlerFactoriesAndHelpSection( const Sequence< Any >& _rFactories, sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
100 
101     private:
102         /** checks a given condition to be <TRUE/>, and throws an IllegalArgumentException if not
103         */
104         void    impl_verifyArgument_throw( bool _bCondition, sal_Int16 _nArgumentPosition );
105 	};
106 
107     //====================================================================
108 	//= ObjectInspectorModel
109 	//====================================================================
110     ObjectInspectorModel::ObjectInspectorModel( const Reference< XComponentContext >& _rxContext )
111         :ImplInspectorModel( _rxContext )
112     {
113     }
114 
115     //--------------------------------------------------------------------
116     Sequence< Any > SAL_CALL ObjectInspectorModel::getHandlerFactories() throw (RuntimeException)
117     {
118         return m_aFactories;
119     }
120 
121     //--------------------------------------------------------------------
122     Sequence< PropertyCategoryDescriptor > SAL_CALL ObjectInspectorModel::describeCategories(  ) throw (RuntimeException)
123     {
124         // no category info provided by this default implementation
125         return Sequence< PropertyCategoryDescriptor >( );
126     }
127 
128     //--------------------------------------------------------------------
129     ::sal_Int32 SAL_CALL ObjectInspectorModel::getPropertyOrderIndex( const ::rtl::OUString& /*PropertyName*/ ) throw (RuntimeException)
130     {
131         // no ordering provided by this default implementation
132         return 0;
133     }
134 
135     //--------------------------------------------------------------------
136     void SAL_CALL ObjectInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException)
137     {
138         ::osl::MutexGuard aGuard( m_aMutex );
139         if ( m_aFactories.getLength() )
140             throw AlreadyInitializedException();
141 
142         StlSyntaxSequence< Any > arguments( _arguments );
143         if ( arguments.empty() )
144         {   // constructor: "createDefault()"
145             createDefault();
146             return;
147         }
148 
149         Sequence< Any > factories;
150         impl_verifyArgument_throw( arguments[0] >>= factories, 1 );
151 
152         if ( arguments.size() == 1 )
153         {   // constructor: "createWithHandlerFactories( any[] )"
154             createWithHandlerFactories( factories );
155             return;
156         }
157 
158         sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
159         if ( arguments.size() == 3 )
160         {   // constructor: "createWithHandlerFactoriesAndHelpSection( any[], long, long )"
161             impl_verifyArgument_throw( arguments[1] >>= nMinHelpTextLines, 2 );
162             impl_verifyArgument_throw( arguments[2] >>= nMaxHelpTextLines, 3 );
163             createWithHandlerFactoriesAndHelpSection( factories, nMinHelpTextLines, nMaxHelpTextLines );
164             return;
165         }
166 
167         impl_verifyArgument_throw( false, 2 );
168     }
169 
170     //--------------------------------------------------------------------
171     ::rtl::OUString SAL_CALL ObjectInspectorModel::getImplementationName(  ) throw (RuntimeException)
172     {
173         return getImplementationName_static();
174     }
175 
176     //--------------------------------------------------------------------
177     Sequence< ::rtl::OUString > SAL_CALL ObjectInspectorModel::getSupportedServiceNames(  ) throw (RuntimeException)
178     {
179         return getSupportedServiceNames_static();
180     }
181 
182     //--------------------------------------------------------------------
183     ::rtl::OUString ObjectInspectorModel::getImplementationName_static(  ) throw(RuntimeException)
184     {
185         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.extensions.ObjectInspectorModel" ) );
186     }
187 
188     //--------------------------------------------------------------------
189     Sequence< ::rtl::OUString > ObjectInspectorModel::getSupportedServiceNames_static(  ) throw(RuntimeException)
190     {
191         ::rtl::OUString sService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.inspection.ObjectInspectorModel" ) );
192         return Sequence< ::rtl::OUString >( &sService, 1 );
193     }
194 
195     //--------------------------------------------------------------------
196     Reference< XInterface > SAL_CALL ObjectInspectorModel::Create(const Reference< XComponentContext >& _rxContext )
197     {
198         return *( new ObjectInspectorModel( _rxContext ) );
199     }
200 
201     //--------------------------------------------------------------------
202     void ObjectInspectorModel::createDefault()
203     {
204         m_aFactories.realloc( 1 );
205         m_aFactories[0] <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.inspection.GenericPropertyHandler" ) );
206     }
207 
208     //--------------------------------------------------------------------
209     void ObjectInspectorModel::createWithHandlerFactories( const Sequence< Any >& _rFactories )
210     {
211         impl_verifyArgument_throw( _rFactories.getLength() > 0, 1 );
212         m_aFactories = _rFactories;
213     }
214 
215     //--------------------------------------------------------------------
216     void ObjectInspectorModel::createWithHandlerFactoriesAndHelpSection( const Sequence< Any >& _rFactories, sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
217     {
218         impl_verifyArgument_throw( _rFactories.getLength() > 0, 1 );
219         impl_verifyArgument_throw( _nMinHelpTextLines >= 1, 2 );
220         impl_verifyArgument_throw( _nMaxHelpTextLines >= 1, 3 );
221         impl_verifyArgument_throw( _nMinHelpTextLines <= _nMaxHelpTextLines, 2 );
222 
223         m_aFactories = _rFactories;
224         enableHelpSectionProperties( _nMinHelpTextLines, _nMaxHelpTextLines );
225     }
226 
227     //--------------------------------------------------------------------
228     void ObjectInspectorModel::impl_verifyArgument_throw( bool _bCondition, sal_Int16 _nArgumentPosition )
229     {
230         if ( !_bCondition )
231             throw IllegalArgumentException( ::rtl::OUString(), *this, _nArgumentPosition );
232     }
233 
234 //........................................................................
235 } // namespace pcr
236 //........................................................................
237 
238 //------------------------------------------------------------------------
239 extern "C" void SAL_CALL createRegistryInfo_ObjectInspectorModel()
240 {
241 	::pcr::OAutoRegistration< ::pcr::ObjectInspectorModel > aObjectInspectorModelRegistration;
242 }
243