1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "modulepcr.hxx"
21 #include "pcrcommon.hxx"
22 #include "inspectormodelbase.hxx"
24 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 #include <cppuhelper/implbase3.hxx>
29 #include <comphelper/broadcasthelper.hxx>
30 #include <comphelper/uno3.hxx>
32 //........................................................................
35 //........................................................................
37 using ::com::sun::star::inspection::XObjectInspectorModel
;
38 using ::com::sun::star::lang::XInitialization
;
39 using ::com::sun::star::lang::XServiceInfo
;
40 using ::com::sun::star::uno::Reference
;
41 using ::com::sun::star::uno::XComponentContext
;
42 using ::com::sun::star::uno::RuntimeException
;
43 using ::com::sun::star::uno::Sequence
;
44 using ::com::sun::star::uno::Any
;
45 using ::com::sun::star::inspection::PropertyCategoryDescriptor
;
46 using ::com::sun::star::uno::Exception
;
47 using ::com::sun::star::uno::XInterface
;
48 using ::com::sun::star::lang::IllegalArgumentException
;
49 using ::com::sun::star::ucb::AlreadyInitializedException
;
50 using ::com::sun::star::beans::XPropertySetInfo
;
51 using ::com::sun::star::uno::makeAny
;
53 //====================================================================
54 //= ObjectInspectorModel
55 //====================================================================
56 class ObjectInspectorModel
: public ImplInspectorModel
59 Sequence
< Any
> m_aFactories
;
62 ObjectInspectorModel( const Reference
< XComponentContext
>& _rxContext
);
64 // XObjectInspectorModel
65 virtual Sequence
< Any
> SAL_CALL
getHandlerFactories() throw (RuntimeException
);
66 virtual Sequence
< PropertyCategoryDescriptor
> SAL_CALL
describeCategories( ) throw (RuntimeException
);
67 virtual ::sal_Int32 SAL_CALL
getPropertyOrderIndex( const OUString
& PropertyName
) throw (RuntimeException
);
70 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) throw (Exception
, RuntimeException
);
73 virtual OUString SAL_CALL
getImplementationName( ) throw (RuntimeException
);
74 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (RuntimeException
);
76 // XServiceInfo - static versions
77 static OUString
getImplementationName_static( ) throw(RuntimeException
);
78 static Sequence
< OUString
> getSupportedServiceNames_static( ) throw(RuntimeException
);
79 static Reference
< XInterface
> SAL_CALL
80 Create(const Reference
< XComponentContext
>&);
84 void createWithHandlerFactories( const Sequence
< Any
>& _rFactories
);
85 void createWithHandlerFactoriesAndHelpSection( const Sequence
< Any
>& _rFactories
, sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
);
88 /** checks a given condition to be <TRUE/>, and throws an IllegalArgumentException if not
90 void impl_verifyArgument_throw( bool _bCondition
, sal_Int16 _nArgumentPosition
);
93 //====================================================================
94 //= ObjectInspectorModel
95 //====================================================================
96 ObjectInspectorModel::ObjectInspectorModel( const Reference
< XComponentContext
>& _rxContext
)
97 :ImplInspectorModel( _rxContext
)
101 //--------------------------------------------------------------------
102 Sequence
< Any
> SAL_CALL
ObjectInspectorModel::getHandlerFactories() throw (RuntimeException
)
107 //--------------------------------------------------------------------
108 Sequence
< PropertyCategoryDescriptor
> SAL_CALL
ObjectInspectorModel::describeCategories( ) throw (RuntimeException
)
110 // no category info provided by this default implementation
111 return Sequence
< PropertyCategoryDescriptor
>( );
114 //--------------------------------------------------------------------
115 ::sal_Int32 SAL_CALL
ObjectInspectorModel::getPropertyOrderIndex( const OUString
& /*PropertyName*/ ) throw (RuntimeException
)
117 // no ordering provided by this default implementation
121 //--------------------------------------------------------------------
122 void SAL_CALL
ObjectInspectorModel::initialize( const Sequence
< Any
>& _arguments
) throw (Exception
, RuntimeException
)
124 ::osl::MutexGuard
aGuard( m_aMutex
);
125 if ( m_aFactories
.getLength() )
126 throw AlreadyInitializedException();
128 StlSyntaxSequence
< Any
> arguments( _arguments
);
129 if ( arguments
.empty() )
130 { // constructor: "createDefault()"
135 Sequence
< Any
> factories
;
136 impl_verifyArgument_throw( arguments
[0] >>= factories
, 1 );
138 if ( arguments
.size() == 1 )
139 { // constructor: "createWithHandlerFactories( any[] )"
140 createWithHandlerFactories( factories
);
144 sal_Int32
nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
145 if ( arguments
.size() == 3 )
146 { // constructor: "createWithHandlerFactoriesAndHelpSection( any[], long, long )"
147 impl_verifyArgument_throw( arguments
[1] >>= nMinHelpTextLines
, 2 );
148 impl_verifyArgument_throw( arguments
[2] >>= nMaxHelpTextLines
, 3 );
149 createWithHandlerFactoriesAndHelpSection( factories
, nMinHelpTextLines
, nMaxHelpTextLines
);
153 impl_verifyArgument_throw( false, 2 );
156 //--------------------------------------------------------------------
157 OUString SAL_CALL
ObjectInspectorModel::getImplementationName( ) throw (RuntimeException
)
159 return getImplementationName_static();
162 //--------------------------------------------------------------------
163 Sequence
< OUString
> SAL_CALL
ObjectInspectorModel::getSupportedServiceNames( ) throw (RuntimeException
)
165 return getSupportedServiceNames_static();
168 //--------------------------------------------------------------------
169 OUString
ObjectInspectorModel::getImplementationName_static( ) throw(RuntimeException
)
171 return OUString( "org.openoffice.comp.extensions.ObjectInspectorModel" );
174 //--------------------------------------------------------------------
175 Sequence
< OUString
> ObjectInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException
)
177 OUString
sService( "com.sun.star.inspection.ObjectInspectorModel" );
178 return Sequence
< OUString
>( &sService
, 1 );
181 //--------------------------------------------------------------------
182 Reference
< XInterface
> SAL_CALL
ObjectInspectorModel::Create(const Reference
< XComponentContext
>& _rxContext
)
184 return *( new ObjectInspectorModel( _rxContext
) );
187 //--------------------------------------------------------------------
188 void ObjectInspectorModel::createDefault()
190 m_aFactories
.realloc( 1 );
191 m_aFactories
[0] <<= OUString( "com.sun.star.inspection.GenericPropertyHandler" );
194 //--------------------------------------------------------------------
195 void ObjectInspectorModel::createWithHandlerFactories( const Sequence
< Any
>& _rFactories
)
197 impl_verifyArgument_throw( _rFactories
.getLength() > 0, 1 );
198 m_aFactories
= _rFactories
;
201 //--------------------------------------------------------------------
202 void ObjectInspectorModel::createWithHandlerFactoriesAndHelpSection( const Sequence
< Any
>& _rFactories
, sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
)
204 impl_verifyArgument_throw( _rFactories
.getLength() > 0, 1 );
205 impl_verifyArgument_throw( _nMinHelpTextLines
>= 1, 2 );
206 impl_verifyArgument_throw( _nMaxHelpTextLines
>= 1, 3 );
207 impl_verifyArgument_throw( _nMinHelpTextLines
<= _nMaxHelpTextLines
, 2 );
209 m_aFactories
= _rFactories
;
210 enableHelpSectionProperties( _nMinHelpTextLines
, _nMaxHelpTextLines
);
213 //--------------------------------------------------------------------
214 void ObjectInspectorModel::impl_verifyArgument_throw( bool _bCondition
, sal_Int16 _nArgumentPosition
)
217 throw IllegalArgumentException( OUString(), *this, _nArgumentPosition
);
220 //........................................................................
222 //........................................................................
224 //------------------------------------------------------------------------
225 extern "C" void SAL_CALL
createRegistryInfo_ObjectInspectorModel()
227 ::pcr::OAutoRegistration
< ::pcr::ObjectInspectorModel
> aObjectInspectorModelRegistration
;
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */