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 "pcrcommon.hxx"
21 #include "inspectormodelbase.hxx"
23 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
32 using ::com::sun::star::uno::XComponentContext
;
33 using ::com::sun::star::uno::Sequence
;
34 using ::com::sun::star::uno::Any
;
35 using ::com::sun::star::inspection::PropertyCategoryDescriptor
;
36 using ::com::sun::star::uno::XInterface
;
37 using ::com::sun::star::lang::IllegalArgumentException
;
38 using ::com::sun::star::ucb::AlreadyInitializedException
;
41 //= ObjectInspectorModel
45 class ObjectInspectorModel
: public ImplInspectorModel
48 Sequence
< Any
> m_aFactories
;
51 ObjectInspectorModel();
53 // XObjectInspectorModel
54 virtual Sequence
< Any
> SAL_CALL
getHandlerFactories() override
;
55 virtual Sequence
< PropertyCategoryDescriptor
> SAL_CALL
describeCategories( ) override
;
56 virtual ::sal_Int32 SAL_CALL
getPropertyOrderIndex( const OUString
& PropertyName
) override
;
59 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) override
;
62 virtual OUString SAL_CALL
getImplementationName( ) override
;
63 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
67 void createWithHandlerFactories( const Sequence
< Any
>& _rFactories
);
68 void createWithHandlerFactoriesAndHelpSection( const Sequence
< Any
>& _rFactories
, sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
);
71 /** checks a given condition to be <TRUE/>, and throws an IllegalArgumentException if not
73 void impl_verifyArgument_throw( bool _bCondition
, sal_Int16 _nArgumentPosition
);
78 //= ObjectInspectorModel
80 ObjectInspectorModel::ObjectInspectorModel()
85 Sequence
< Any
> SAL_CALL
ObjectInspectorModel::getHandlerFactories()
91 Sequence
< PropertyCategoryDescriptor
> SAL_CALL
ObjectInspectorModel::describeCategories( )
93 // no category info provided by this default implementation
94 return Sequence
< PropertyCategoryDescriptor
>( );
98 ::sal_Int32 SAL_CALL
ObjectInspectorModel::getPropertyOrderIndex( const OUString
& /*PropertyName*/ )
100 // no ordering provided by this default implementation
105 void SAL_CALL
ObjectInspectorModel::initialize( const Sequence
< Any
>& _arguments
)
107 ::osl::MutexGuard
aGuard( m_aMutex
);
108 if ( m_aFactories
.hasElements() )
109 throw AlreadyInitializedException();
111 StlSyntaxSequence
< Any
> arguments( _arguments
);
112 if ( arguments
.empty() )
113 { // constructor: "createDefault()"
118 Sequence
< Any
> factories
;
119 impl_verifyArgument_throw( arguments
[0] >>= factories
, 1 );
121 if ( arguments
.size() == 1 )
122 { // constructor: "createWithHandlerFactories( any[] )"
123 createWithHandlerFactories( factories
);
127 if ( arguments
.size() == 3 )
128 { // constructor: "createWithHandlerFactoriesAndHelpSection( any[], long, long )"
129 sal_Int32
nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
130 impl_verifyArgument_throw( arguments
[1] >>= nMinHelpTextLines
, 2 );
131 impl_verifyArgument_throw( arguments
[2] >>= nMaxHelpTextLines
, 3 );
132 createWithHandlerFactoriesAndHelpSection( factories
, nMinHelpTextLines
, nMaxHelpTextLines
);
136 impl_verifyArgument_throw( false, 2 );
140 OUString SAL_CALL
ObjectInspectorModel::getImplementationName( )
142 return u
"org.openoffice.comp.extensions.ObjectInspectorModel"_ustr
;
146 Sequence
< OUString
> SAL_CALL
ObjectInspectorModel::getSupportedServiceNames( )
148 return { u
"com.sun.star.inspection.ObjectInspectorModel"_ustr
};
152 void ObjectInspectorModel::createDefault()
154 m_aFactories
= { Any(u
"com.sun.star.inspection.GenericPropertyHandler"_ustr
) };
158 void ObjectInspectorModel::createWithHandlerFactories( const Sequence
< Any
>& _rFactories
)
160 impl_verifyArgument_throw( _rFactories
.hasElements(), 1 );
161 m_aFactories
= _rFactories
;
165 void ObjectInspectorModel::createWithHandlerFactoriesAndHelpSection( const Sequence
< Any
>& _rFactories
, sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
)
167 impl_verifyArgument_throw( _rFactories
.hasElements(), 1 );
168 impl_verifyArgument_throw( _nMinHelpTextLines
>= 1, 2 );
169 impl_verifyArgument_throw( _nMaxHelpTextLines
>= 1, 3 );
170 impl_verifyArgument_throw( _nMinHelpTextLines
<= _nMaxHelpTextLines
, 2 );
172 m_aFactories
= _rFactories
;
173 enableHelpSectionProperties( _nMinHelpTextLines
, _nMaxHelpTextLines
);
177 void ObjectInspectorModel::impl_verifyArgument_throw( bool _bCondition
, sal_Int16 _nArgumentPosition
)
180 throw IllegalArgumentException( OUString(), *this, _nArgumentPosition
);
186 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
187 extensions_propctrlr_ObjectInspectorModel_get_implementation(
188 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
190 return cppu::acquire(new pcr::ObjectInspectorModel());
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */