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