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 "pcrservices.hxx"
23 #include "inspectormodelbase.hxx"
25 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
26 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #include <cppuhelper/implbase3.hxx>
30 #include <comphelper/broadcasthelper.hxx>
31 #include <comphelper/uno3.hxx>
38 using ::com::sun::star::inspection::XObjectInspectorModel
;
39 using ::com::sun::star::lang::XInitialization
;
40 using ::com::sun::star::lang::XServiceInfo
;
41 using ::com::sun::star::uno::Reference
;
42 using ::com::sun::star::uno::XComponentContext
;
43 using ::com::sun::star::uno::RuntimeException
;
44 using ::com::sun::star::uno::Sequence
;
45 using ::com::sun::star::uno::Any
;
46 using ::com::sun::star::inspection::PropertyCategoryDescriptor
;
47 using ::com::sun::star::uno::Exception
;
48 using ::com::sun::star::uno::XInterface
;
49 using ::com::sun::star::lang::IllegalArgumentException
;
50 using ::com::sun::star::ucb::AlreadyInitializedException
;
51 using ::com::sun::star::beans::XPropertySetInfo
;
52 using ::com::sun::star::uno::makeAny
;
55 //= ObjectInspectorModel
57 class ObjectInspectorModel
: public ImplInspectorModel
60 Sequence
< Any
> m_aFactories
;
63 ObjectInspectorModel();
65 // XObjectInspectorModel
66 virtual Sequence
< Any
> SAL_CALL
getHandlerFactories() throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
67 virtual Sequence
< PropertyCategoryDescriptor
> SAL_CALL
describeCategories( ) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
68 virtual ::sal_Int32 SAL_CALL
getPropertyOrderIndex( const OUString
& PropertyName
) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
71 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) throw (Exception
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
74 virtual OUString SAL_CALL
getImplementationName( ) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
75 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
77 // XServiceInfo - static versions
78 static OUString
getImplementationName_static( ) throw(RuntimeException
);
79 static Sequence
< OUString
> getSupportedServiceNames_static( ) throw(RuntimeException
);
80 static Reference
< XInterface
> SAL_CALL
81 Create(const Reference
< XComponentContext
>&);
85 void createWithHandlerFactories( const Sequence
< Any
>& _rFactories
);
86 void createWithHandlerFactoriesAndHelpSection( const Sequence
< Any
>& _rFactories
, sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
);
89 /** checks a given condition to be <TRUE/>, and throws an IllegalArgumentException if not
91 void impl_verifyArgument_throw( bool _bCondition
, sal_Int16 _nArgumentPosition
);
95 //= ObjectInspectorModel
97 ObjectInspectorModel::ObjectInspectorModel()
103 Sequence
< Any
> SAL_CALL
ObjectInspectorModel::getHandlerFactories() throw (RuntimeException
, std::exception
)
109 Sequence
< PropertyCategoryDescriptor
> SAL_CALL
ObjectInspectorModel::describeCategories( ) throw (RuntimeException
, std::exception
)
111 // no category info provided by this default implementation
112 return Sequence
< PropertyCategoryDescriptor
>( );
116 ::sal_Int32 SAL_CALL
ObjectInspectorModel::getPropertyOrderIndex( const OUString
& /*PropertyName*/ ) throw (RuntimeException
, std::exception
)
118 // no ordering provided by this default implementation
123 void SAL_CALL
ObjectInspectorModel::initialize( const Sequence
< Any
>& _arguments
) throw (Exception
, RuntimeException
, std::exception
)
125 ::osl::MutexGuard
aGuard( m_aMutex
);
126 if ( m_aFactories
.getLength() )
127 throw AlreadyInitializedException();
129 StlSyntaxSequence
< Any
> arguments( _arguments
);
130 if ( arguments
.empty() )
131 { // constructor: "createDefault()"
136 Sequence
< Any
> factories
;
137 impl_verifyArgument_throw( arguments
[0] >>= factories
, 1 );
139 if ( arguments
.size() == 1 )
140 { // constructor: "createWithHandlerFactories( any[] )"
141 createWithHandlerFactories( factories
);
145 sal_Int32
nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
146 if ( arguments
.size() == 3 )
147 { // constructor: "createWithHandlerFactoriesAndHelpSection( any[], long, long )"
148 impl_verifyArgument_throw( arguments
[1] >>= nMinHelpTextLines
, 2 );
149 impl_verifyArgument_throw( arguments
[2] >>= nMaxHelpTextLines
, 3 );
150 createWithHandlerFactoriesAndHelpSection( factories
, nMinHelpTextLines
, nMaxHelpTextLines
);
154 impl_verifyArgument_throw( false, 2 );
158 OUString SAL_CALL
ObjectInspectorModel::getImplementationName( ) throw (RuntimeException
, std::exception
)
160 return getImplementationName_static();
164 Sequence
< OUString
> SAL_CALL
ObjectInspectorModel::getSupportedServiceNames( ) throw (RuntimeException
, std::exception
)
166 return getSupportedServiceNames_static();
170 OUString
ObjectInspectorModel::getImplementationName_static( ) throw(RuntimeException
)
172 return OUString( "org.openoffice.comp.extensions.ObjectInspectorModel" );
176 Sequence
< OUString
> ObjectInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException
)
178 OUString
sService( "com.sun.star.inspection.ObjectInspectorModel" );
179 return Sequence
< OUString
>( &sService
, 1 );
183 Reference
< XInterface
> SAL_CALL
ObjectInspectorModel::Create(const Reference
< XComponentContext
>& /* _rxContext */ )
185 return *( new ObjectInspectorModel() );
189 void ObjectInspectorModel::createDefault()
191 m_aFactories
.realloc( 1 );
192 m_aFactories
[0] <<= OUString( "com.sun.star.inspection.GenericPropertyHandler" );
196 void ObjectInspectorModel::createWithHandlerFactories( const Sequence
< Any
>& _rFactories
)
198 impl_verifyArgument_throw( _rFactories
.getLength() > 0, 1 );
199 m_aFactories
= _rFactories
;
203 void ObjectInspectorModel::createWithHandlerFactoriesAndHelpSection( const Sequence
< Any
>& _rFactories
, sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
)
205 impl_verifyArgument_throw( _rFactories
.getLength() > 0, 1 );
206 impl_verifyArgument_throw( _nMinHelpTextLines
>= 1, 2 );
207 impl_verifyArgument_throw( _nMaxHelpTextLines
>= 1, 3 );
208 impl_verifyArgument_throw( _nMinHelpTextLines
<= _nMaxHelpTextLines
, 2 );
210 m_aFactories
= _rFactories
;
211 enableHelpSectionProperties( _nMinHelpTextLines
, _nMaxHelpTextLines
);
215 void ObjectInspectorModel::impl_verifyArgument_throw( bool _bCondition
, sal_Int16 _nArgumentPosition
)
218 throw IllegalArgumentException( OUString(), *this, _nArgumentPosition
);
226 extern "C" void SAL_CALL
createRegistryInfo_ObjectInspectorModel()
228 ::pcr::OAutoRegistration
< ::pcr::ObjectInspectorModel
> aObjectInspectorModelRegistration
;
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */