merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / propctrlr / objectinspectormodel.cxx
bloba436fea5c2008099844630604f7bde78721602cc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objectinspectormodel.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "modulepcr.hxx"
34 #include "pcrcommon.hxx"
35 #include "inspectormodelbase.hxx"
37 /** === begin UNO includes === **/
38 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
39 #include <com/sun/star/lang/IllegalArgumentException.hpp>
40 /** === end UNO includes === **/
42 #include <cppuhelper/implbase3.hxx>
44 #include <comphelper/broadcasthelper.hxx>
45 #include <comphelper/uno3.hxx>
47 //........................................................................
48 namespace pcr
50 //........................................................................
52 /** === begin UNO using === **/
53 using ::com::sun::star::inspection::XObjectInspectorModel;
54 using ::com::sun::star::lang::XInitialization;
55 using ::com::sun::star::lang::XServiceInfo;
56 using ::com::sun::star::uno::Reference;
57 using ::com::sun::star::uno::XComponentContext;
58 using ::com::sun::star::uno::RuntimeException;
59 using ::com::sun::star::uno::Sequence;
60 using ::com::sun::star::uno::Any;
61 using ::com::sun::star::inspection::PropertyCategoryDescriptor;
62 using ::com::sun::star::uno::Exception;
63 using ::com::sun::star::uno::XInterface;
64 using ::com::sun::star::lang::IllegalArgumentException;
65 using ::com::sun::star::ucb::AlreadyInitializedException;
66 using ::com::sun::star::beans::XPropertySetInfo;
67 using ::com::sun::star::uno::makeAny;
68 /** === end UNO using === **/
70 //====================================================================
71 //= ObjectInspectorModel
72 //====================================================================
73 class ObjectInspectorModel : public ImplInspectorModel
75 private:
76 Sequence< Any > m_aFactories;
78 public:
79 ObjectInspectorModel( const Reference< XComponentContext >& _rxContext );
81 // XObjectInspectorModel
82 virtual Sequence< Any > SAL_CALL getHandlerFactories() throw (RuntimeException);
83 virtual Sequence< PropertyCategoryDescriptor > SAL_CALL describeCategories( ) throw (RuntimeException);
84 virtual ::sal_Int32 SAL_CALL getPropertyOrderIndex( const ::rtl::OUString& PropertyName ) throw (RuntimeException);
86 // XInitialization
87 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException);
89 // XServiceInfo
90 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (RuntimeException);
91 virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException);
93 // XServiceInfo - static versions
94 static ::rtl::OUString getImplementationName_static( ) throw(RuntimeException);
95 static Sequence< ::rtl::OUString > getSupportedServiceNames_static( ) throw(RuntimeException);
96 static Reference< XInterface > SAL_CALL
97 Create(const Reference< XComponentContext >&);
99 protected:
100 void createDefault();
101 void createWithHandlerFactories( const Sequence< Any >& _rFactories );
102 void createWithHandlerFactoriesAndHelpSection( const Sequence< Any >& _rFactories, sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
104 private:
105 /** checks a given condition to be <TRUE/>, and throws an IllegalArgumentException if not
107 void impl_verifyArgument_throw( bool _bCondition, sal_Int16 _nArgumentPosition );
110 //====================================================================
111 //= ObjectInspectorModel
112 //====================================================================
113 ObjectInspectorModel::ObjectInspectorModel( const Reference< XComponentContext >& _rxContext )
114 :ImplInspectorModel( _rxContext )
118 //--------------------------------------------------------------------
119 Sequence< Any > SAL_CALL ObjectInspectorModel::getHandlerFactories() throw (RuntimeException)
121 return m_aFactories;
124 //--------------------------------------------------------------------
125 Sequence< PropertyCategoryDescriptor > SAL_CALL ObjectInspectorModel::describeCategories( ) throw (RuntimeException)
127 // no category info provided by this default implementation
128 return Sequence< PropertyCategoryDescriptor >( );
131 //--------------------------------------------------------------------
132 ::sal_Int32 SAL_CALL ObjectInspectorModel::getPropertyOrderIndex( const ::rtl::OUString& /*PropertyName*/ ) throw (RuntimeException)
134 // no ordering provided by this default implementation
135 return 0;
138 //--------------------------------------------------------------------
139 void SAL_CALL ObjectInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException)
141 ::osl::MutexGuard aGuard( m_aMutex );
142 if ( m_aFactories.getLength() )
143 throw AlreadyInitializedException();
145 StlSyntaxSequence< Any > arguments( _arguments );
146 if ( arguments.empty() )
147 { // constructor: "createDefault()"
148 createDefault();
149 return;
152 Sequence< Any > factories;
153 impl_verifyArgument_throw( arguments[0] >>= factories, 1 );
155 if ( arguments.size() == 1 )
156 { // constructor: "createWithHandlerFactories( any[] )"
157 createWithHandlerFactories( factories );
158 return;
161 sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
162 if ( arguments.size() == 3 )
163 { // constructor: "createWithHandlerFactoriesAndHelpSection( any[], long, long )"
164 impl_verifyArgument_throw( arguments[1] >>= nMinHelpTextLines, 2 );
165 impl_verifyArgument_throw( arguments[2] >>= nMaxHelpTextLines, 3 );
166 createWithHandlerFactoriesAndHelpSection( factories, nMinHelpTextLines, nMaxHelpTextLines );
167 return;
170 impl_verifyArgument_throw( false, 2 );
173 //--------------------------------------------------------------------
174 ::rtl::OUString SAL_CALL ObjectInspectorModel::getImplementationName( ) throw (RuntimeException)
176 return getImplementationName_static();
179 //--------------------------------------------------------------------
180 Sequence< ::rtl::OUString > SAL_CALL ObjectInspectorModel::getSupportedServiceNames( ) throw (RuntimeException)
182 return getSupportedServiceNames_static();
185 //--------------------------------------------------------------------
186 ::rtl::OUString ObjectInspectorModel::getImplementationName_static( ) throw(RuntimeException)
188 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.extensions.ObjectInspectorModel" ) );
191 //--------------------------------------------------------------------
192 Sequence< ::rtl::OUString > ObjectInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException)
194 ::rtl::OUString sService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.inspection.ObjectInspectorModel" ) );
195 return Sequence< ::rtl::OUString >( &sService, 1 );
198 //--------------------------------------------------------------------
199 Reference< XInterface > SAL_CALL ObjectInspectorModel::Create(const Reference< XComponentContext >& _rxContext )
201 return *( new ObjectInspectorModel( _rxContext ) );
204 //--------------------------------------------------------------------
205 void ObjectInspectorModel::createDefault()
207 m_aFactories.realloc( 1 );
208 m_aFactories[0] <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.inspection.GenericPropertyHandler" ) );
211 //--------------------------------------------------------------------
212 void ObjectInspectorModel::createWithHandlerFactories( const Sequence< Any >& _rFactories )
214 impl_verifyArgument_throw( _rFactories.getLength() > 0, 1 );
215 m_aFactories = _rFactories;
218 //--------------------------------------------------------------------
219 void ObjectInspectorModel::createWithHandlerFactoriesAndHelpSection( const Sequence< Any >& _rFactories, sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
221 impl_verifyArgument_throw( _rFactories.getLength() > 0, 1 );
222 impl_verifyArgument_throw( _nMinHelpTextLines >= 1, 2 );
223 impl_verifyArgument_throw( _nMaxHelpTextLines >= 1, 3 );
224 impl_verifyArgument_throw( _nMinHelpTextLines <= _nMaxHelpTextLines, 2 );
226 m_aFactories = _rFactories;
227 enableHelpSectionProperties( _nMinHelpTextLines, _nMaxHelpTextLines );
230 //--------------------------------------------------------------------
231 void ObjectInspectorModel::impl_verifyArgument_throw( bool _bCondition, sal_Int16 _nArgumentPosition )
233 if ( !_bCondition )
234 throw IllegalArgumentException( ::rtl::OUString(), *this, _nArgumentPosition );
237 //........................................................................
238 } // namespace pcr
239 //........................................................................
241 //------------------------------------------------------------------------
242 extern "C" void SAL_CALL createRegistryInfo_ObjectInspectorModel()
244 ::pcr::OAutoRegistration< ::pcr::ObjectInspectorModel > aObjectInspectorModelRegistration;