1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_extensions.hxx"
26 #include "modulepcr.hxx"
27 #include "pcrcommon.hxx"
28 #include "inspectormodelbase.hxx"
29 
30 /** === begin UNO includes === **/
31 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
32 #include <com/sun/star/lang/IllegalArgumentException.hpp>
33 /** === end UNO includes === **/
34 
35 #include <cppuhelper/implbase3.hxx>
36 
37 #include <comphelper/broadcasthelper.hxx>
38 #include <comphelper/uno3.hxx>
39 
40 //........................................................................
41 namespace pcr
42 {
43 //........................................................................
44 
45     /** === begin UNO using === **/
46     using ::com::sun::star::inspection::XObjectInspectorModel;
47     using ::com::sun::star::lang::XInitialization;
48     using ::com::sun::star::lang::XServiceInfo;
49     using ::com::sun::star::uno::Reference;
50     using ::com::sun::star::uno::XComponentContext;
51     using ::com::sun::star::uno::RuntimeException;
52     using ::com::sun::star::uno::Sequence;
53     using ::com::sun::star::uno::Any;
54     using ::com::sun::star::inspection::PropertyCategoryDescriptor;
55     using ::com::sun::star::uno::Exception;
56     using ::com::sun::star::uno::XInterface;
57     using ::com::sun::star::lang::IllegalArgumentException;
58     using ::com::sun::star::ucb::AlreadyInitializedException;
59     using ::com::sun::star::beans::XPropertySetInfo;
60     using ::com::sun::star::uno::makeAny;
61     /** === end UNO using === **/
62 
63     //====================================================================
64 	//= ObjectInspectorModel
65 	//====================================================================
66     class ObjectInspectorModel : public ImplInspectorModel
67 	{
68     private:
69         Sequence< Any >             m_aFactories;
70 
71     public:
72         ObjectInspectorModel( const Reference< XComponentContext >& _rxContext );
73 
74         // XObjectInspectorModel
75         virtual Sequence< Any > SAL_CALL getHandlerFactories() throw (RuntimeException);
76         virtual Sequence< PropertyCategoryDescriptor > SAL_CALL describeCategories(  ) throw (RuntimeException);
77         virtual ::sal_Int32 SAL_CALL getPropertyOrderIndex( const ::rtl::OUString& PropertyName ) throw (RuntimeException);
78 
79         // XInitialization
80         virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException);
81 
82         // XServiceInfo
83         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
84         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
85 
86         // XServiceInfo - static versions
87 		static ::rtl::OUString getImplementationName_static(  ) throw(RuntimeException);
88 		static Sequence< ::rtl::OUString > getSupportedServiceNames_static(  ) throw(RuntimeException);
89 		static Reference< XInterface > SAL_CALL
90 						Create(const Reference< XComponentContext >&);
91 
92     protected:
93         void    createDefault();
94         void    createWithHandlerFactories( const Sequence< Any >& _rFactories );
95         void    createWithHandlerFactoriesAndHelpSection( const Sequence< Any >& _rFactories, sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
96 
97     private:
98         /** checks a given condition to be <TRUE/>, and throws an IllegalArgumentException if not
99         */
100         void    impl_verifyArgument_throw( bool _bCondition, sal_Int16 _nArgumentPosition );
101 	};
102 
103     //====================================================================
104 	//= ObjectInspectorModel
105 	//====================================================================
ObjectInspectorModel(const Reference<XComponentContext> & _rxContext)106     ObjectInspectorModel::ObjectInspectorModel( const Reference< XComponentContext >& _rxContext )
107         :ImplInspectorModel( _rxContext )
108     {
109     }
110 
111     //--------------------------------------------------------------------
getHandlerFactories()112     Sequence< Any > SAL_CALL ObjectInspectorModel::getHandlerFactories() throw (RuntimeException)
113     {
114         return m_aFactories;
115     }
116 
117     //--------------------------------------------------------------------
describeCategories()118     Sequence< PropertyCategoryDescriptor > SAL_CALL ObjectInspectorModel::describeCategories(  ) throw (RuntimeException)
119     {
120         // no category info provided by this default implementation
121         return Sequence< PropertyCategoryDescriptor >( );
122     }
123 
124     //--------------------------------------------------------------------
getPropertyOrderIndex(const::rtl::OUString &)125     ::sal_Int32 SAL_CALL ObjectInspectorModel::getPropertyOrderIndex( const ::rtl::OUString& /*PropertyName*/ ) throw (RuntimeException)
126     {
127         // no ordering provided by this default implementation
128         return 0;
129     }
130 
131     //--------------------------------------------------------------------
initialize(const Sequence<Any> & _arguments)132     void SAL_CALL ObjectInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException)
133     {
134         ::osl::MutexGuard aGuard( m_aMutex );
135         if ( m_aFactories.getLength() )
136             throw AlreadyInitializedException();
137 
138         StlSyntaxSequence< Any > arguments( _arguments );
139         if ( arguments.empty() )
140         {   // constructor: "createDefault()"
141             createDefault();
142             return;
143         }
144 
145         Sequence< Any > factories;
146         impl_verifyArgument_throw( arguments[0] >>= factories, 1 );
147 
148         if ( arguments.size() == 1 )
149         {   // constructor: "createWithHandlerFactories( any[] )"
150             createWithHandlerFactories( factories );
151             return;
152         }
153 
154         sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
155         if ( arguments.size() == 3 )
156         {   // constructor: "createWithHandlerFactoriesAndHelpSection( any[], long, long )"
157             impl_verifyArgument_throw( arguments[1] >>= nMinHelpTextLines, 2 );
158             impl_verifyArgument_throw( arguments[2] >>= nMaxHelpTextLines, 3 );
159             createWithHandlerFactoriesAndHelpSection( factories, nMinHelpTextLines, nMaxHelpTextLines );
160             return;
161         }
162 
163         impl_verifyArgument_throw( false, 2 );
164     }
165 
166     //--------------------------------------------------------------------
getImplementationName()167     ::rtl::OUString SAL_CALL ObjectInspectorModel::getImplementationName(  ) throw (RuntimeException)
168     {
169         return getImplementationName_static();
170     }
171 
172     //--------------------------------------------------------------------
getSupportedServiceNames()173     Sequence< ::rtl::OUString > SAL_CALL ObjectInspectorModel::getSupportedServiceNames(  ) throw (RuntimeException)
174     {
175         return getSupportedServiceNames_static();
176     }
177 
178     //--------------------------------------------------------------------
getImplementationName_static()179     ::rtl::OUString ObjectInspectorModel::getImplementationName_static(  ) throw(RuntimeException)
180     {
181         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.extensions.ObjectInspectorModel" ) );
182     }
183 
184     //--------------------------------------------------------------------
getSupportedServiceNames_static()185     Sequence< ::rtl::OUString > ObjectInspectorModel::getSupportedServiceNames_static(  ) throw(RuntimeException)
186     {
187         ::rtl::OUString sService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.inspection.ObjectInspectorModel" ) );
188         return Sequence< ::rtl::OUString >( &sService, 1 );
189     }
190 
191     //--------------------------------------------------------------------
Create(const Reference<XComponentContext> & _rxContext)192     Reference< XInterface > SAL_CALL ObjectInspectorModel::Create(const Reference< XComponentContext >& _rxContext )
193     {
194         return *( new ObjectInspectorModel( _rxContext ) );
195     }
196 
197     //--------------------------------------------------------------------
createDefault()198     void ObjectInspectorModel::createDefault()
199     {
200         m_aFactories.realloc( 1 );
201         m_aFactories[0] <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.inspection.GenericPropertyHandler" ) );
202     }
203 
204     //--------------------------------------------------------------------
createWithHandlerFactories(const Sequence<Any> & _rFactories)205     void ObjectInspectorModel::createWithHandlerFactories( const Sequence< Any >& _rFactories )
206     {
207         impl_verifyArgument_throw( _rFactories.getLength() > 0, 1 );
208         m_aFactories = _rFactories;
209     }
210 
211     //--------------------------------------------------------------------
createWithHandlerFactoriesAndHelpSection(const Sequence<Any> & _rFactories,sal_Int32 _nMinHelpTextLines,sal_Int32 _nMaxHelpTextLines)212     void ObjectInspectorModel::createWithHandlerFactoriesAndHelpSection( const Sequence< Any >& _rFactories, sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
213     {
214         impl_verifyArgument_throw( _rFactories.getLength() > 0, 1 );
215         impl_verifyArgument_throw( _nMinHelpTextLines >= 1, 2 );
216         impl_verifyArgument_throw( _nMaxHelpTextLines >= 1, 3 );
217         impl_verifyArgument_throw( _nMinHelpTextLines <= _nMaxHelpTextLines, 2 );
218 
219         m_aFactories = _rFactories;
220         enableHelpSectionProperties( _nMinHelpTextLines, _nMaxHelpTextLines );
221     }
222 
223     //--------------------------------------------------------------------
impl_verifyArgument_throw(bool _bCondition,sal_Int16 _nArgumentPosition)224     void ObjectInspectorModel::impl_verifyArgument_throw( bool _bCondition, sal_Int16 _nArgumentPosition )
225     {
226         if ( !_bCondition )
227             throw IllegalArgumentException( ::rtl::OUString(), *this, _nArgumentPosition );
228     }
229 
230 //........................................................................
231 } // namespace pcr
232 //........................................................................
233 
234 //------------------------------------------------------------------------
createRegistryInfo_ObjectInspectorModel()235 extern "C" void SAL_CALL createRegistryInfo_ObjectInspectorModel()
236 {
237 	::pcr::OAutoRegistration< ::pcr::ObjectInspectorModel > aObjectInspectorModelRegistration;
238 }
239