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 "formcontroller.hxx"
21 #include "pcrcommon.hxx"
22 #include "formstrings.hxx"
23 #include "defaultforminspection.hxx"
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/util/VetoException.hpp>
27 #include <cppuhelper/typeprovider.hxx>
35 using ::com::sun::star::uno::Reference
;
36 using ::com::sun::star::uno::TypeClass_INTERFACE
;
37 using ::com::sun::star::uno::TypeClass_STRING
;
38 using ::com::sun::star::uno::XComponentContext
;
39 using ::com::sun::star::inspection::XObjectInspectorModel
;
40 using ::com::sun::star::uno::UNO_QUERY_THROW
;
41 using ::com::sun::star::uno::Sequence
;
42 using ::com::sun::star::uno::XInterface
;
43 using ::com::sun::star::beans::XPropertySetInfo
;
44 using ::com::sun::star::beans::XPropertySet
;
45 using ::com::sun::star::beans::Property
;
46 using ::com::sun::star::uno::Any
;
47 using ::com::sun::star::lang::IllegalArgumentException
;
48 using ::com::sun::star::uno::Type
;
49 using ::com::sun::star::util::VetoException
;
50 using ::com::sun::star::beans::PropertyVetoException
;
51 using ::com::sun::star::uno::UNO_QUERY
;
53 namespace PropertyAttribute
= css::beans::PropertyAttribute
;
59 FormController::FormController( const Reference
< XComponentContext
>& _rxContext
,
60 OUString sImplementationName
,
61 const css::uno::Sequence
<OUString
>& aSupportedServiceNames
,
62 bool _bUseFormFormComponentHandlers
)
63 :OPropertyBrowserController( _rxContext
)
64 ,FormController_PropertyBase1( m_aBHelper
)
65 ,m_sImplementationName(std::move( sImplementationName
))
66 ,m_aSupportedServiceNames( aSupportedServiceNames
)
68 osl_atomic_increment( &m_refCount
);
70 Reference
< XObjectInspectorModel
> xModel(
71 *(new DefaultFormComponentInspectorModel( _bUseFormFormComponentHandlers
)),
74 setInspectorModel( xModel
);
76 osl_atomic_decrement( &m_refCount
);
80 FormController::~FormController()
85 IMPLEMENT_FORWARD_XINTERFACE2( FormController
, OPropertyBrowserController
, FormController_PropertyBase1
)
88 Sequence
< Type
> SAL_CALL
FormController::getTypes( )
90 ::cppu::OTypeCollection
aTypes(
91 cppu::UnoType
<XPropertySet
>::get(),
92 cppu::UnoType
<XMultiPropertySet
>::get(),
93 cppu::UnoType
<XFastPropertySet
>::get(),
94 OPropertyBrowserController::getTypes());
95 return aTypes
.getTypes();
99 IMPLEMENT_GET_IMPLEMENTATION_ID( FormController
)
102 OUString SAL_CALL
FormController::getImplementationName( )
104 return m_sImplementationName
;
108 Sequence
< OUString
> SAL_CALL
FormController::getSupportedServiceNames( )
110 Sequence
< OUString
> aSupported( m_aSupportedServiceNames
);
111 aSupported
.realloc( aSupported
.getLength() + 1 );
112 aSupported
.getArray()[ aSupported
.getLength() - 1 ] = "com.sun.star.inspection.ObjectInspector";
117 Reference
< XPropertySetInfo
> SAL_CALL
FormController::getPropertySetInfo( )
119 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
123 ::cppu::IPropertyArrayHelper
& SAL_CALL
FormController::getInfoHelper()
125 return *getArrayHelper();
129 ::cppu::IPropertyArrayHelper
* FormController::createArrayHelper( ) const
131 Sequence
< Property
> aProps
{
133 PROPERTY_CURRENTPAGE
,
134 static_cast<sal_Int32
>(OwnPropertyId::CURRENTPAGE
),
135 ::cppu::UnoType
<OUString
>::get(),
136 PropertyAttribute::TRANSIENT
139 PROPERTY_INTROSPECTEDOBJECT
,
140 static_cast<sal_Int32
>(OwnPropertyId::INTROSPECTEDOBJECT
),
141 cppu::UnoType
<XPropertySet
>::get(),
142 PropertyAttribute::TRANSIENT
| PropertyAttribute::CONSTRAINED
145 return new ::cppu::OPropertyArrayHelper( aProps
);
149 sal_Bool SAL_CALL
FormController::convertFastPropertyValue( Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nHandle
, const Any
& rValue
)
151 switch ( static_cast<OwnPropertyId
>(nHandle
) )
153 case OwnPropertyId::INTROSPECTEDOBJECT
:
154 if ( rValue
.getValueTypeClass() != TypeClass_INTERFACE
)
155 throw IllegalArgumentException();
157 case OwnPropertyId::CURRENTPAGE
:
158 if ( rValue
.getValueTypeClass() != TypeClass_STRING
)
159 throw IllegalArgumentException();
165 getFastPropertyValue( rOldValue
, nHandle
);
166 rConvertedValue
= rValue
;
171 void SAL_CALL
FormController::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle
, const Any
& _rValue
)
173 switch ( static_cast<OwnPropertyId
>(_nHandle
) )
175 case OwnPropertyId::INTROSPECTEDOBJECT
:
177 Reference
< XObjectInspectorModel
> xModel( getInspectorModel() );
182 m_xCurrentInspectee
.set( _rValue
, UNO_QUERY
);
183 Sequence
< Reference
< XInterface
> > aObjects
;
184 if ( m_xCurrentInspectee
.is() )
186 aObjects
= { m_xCurrentInspectee
};
189 Reference
< XObjectInspector
> xInspector( *this, UNO_QUERY_THROW
);
190 xInspector
->inspect( aObjects
);
192 catch( const VetoException
& e
)
194 throw PropertyVetoException( e
.Message
, e
.Context
);
199 case OwnPropertyId::CURRENTPAGE
:
200 restoreViewData( _rValue
);
208 void SAL_CALL
FormController::getFastPropertyValue( css::uno::Any
& rValue
, sal_Int32 nHandle
) const
210 switch ( static_cast<OwnPropertyId
>(nHandle
) )
212 case OwnPropertyId::INTROSPECTEDOBJECT
:
213 rValue
<<= m_xCurrentInspectee
;
216 case OwnPropertyId::CURRENTPAGE
:
217 rValue
= const_cast< FormController
* >( this )->getViewData();
228 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
229 extensions_propctrlr_FormController_get_implementation(
230 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
232 return cppu::acquire(new pcr::FormController( context
,
233 u
"org.openoffice.comp.extensions.FormController"_ustr
,
234 { u
"com.sun.star.form.PropertyBrowserController"_ustr
},
238 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
239 extensions_propctrlr_DialogController_get_implementation(
240 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
242 return cppu::acquire(new pcr::FormController( context
,
243 u
"org.openoffice.comp.extensions.DialogController"_ustr
,
244 { u
"com.sun.star.awt.PropertyBrowserController"_ustr
},
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */