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 "pcrservices.hxx"
23 #include "formstrings.hxx"
24 #include "defaultforminspection.hxx"
25 #include <propctrlr.h>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/util/VetoException.hpp>
29 #include <cppuhelper/typeprovider.hxx>
32 extern "C" void createRegistryInfo_FormController()
34 ::pcr::OAutoRegistration
< ::pcr::FormController
> aFormControllerRegistration
;
35 ::pcr::OAutoRegistration
< ::pcr::DialogController
> aDialogControllerRegistration
;
43 using ::com::sun::star::uno::Reference
;
44 using ::com::sun::star::uno::TypeClass_INTERFACE
;
45 using ::com::sun::star::uno::TypeClass_STRING
;
46 using ::com::sun::star::uno::XComponentContext
;
47 using ::com::sun::star::inspection::XObjectInspectorModel
;
48 using ::com::sun::star::uno::UNO_QUERY_THROW
;
49 using ::com::sun::star::uno::Sequence
;
50 using ::com::sun::star::uno::XInterface
;
51 using ::com::sun::star::beans::XPropertySetInfo
;
52 using ::com::sun::star::beans::XPropertySet
;
53 using ::com::sun::star::beans::Property
;
54 using ::com::sun::star::uno::Any
;
55 using ::com::sun::star::lang::IllegalArgumentException
;
56 using ::com::sun::star::uno::Type
;
57 using ::com::sun::star::util::VetoException
;
58 using ::com::sun::star::beans::PropertyVetoException
;
59 using ::com::sun::star::uno::UNO_QUERY
;
61 namespace PropertyAttribute
= css::beans::PropertyAttribute
;
67 FormController::FormController( const Reference
< XComponentContext
>& _rxContext
, ServiceDescriptor _aServiceDescriptor
,
68 bool _bUseFormFormComponentHandlers
)
69 :OPropertyBrowserController( _rxContext
)
70 ,FormController_PropertyBase1( m_aBHelper
)
71 ,m_aServiceDescriptor( _aServiceDescriptor
)
73 osl_atomic_increment( &m_refCount
);
75 Reference
< XObjectInspectorModel
> xModel(
76 *(new DefaultFormComponentInspectorModel( _bUseFormFormComponentHandlers
)),
79 setInspectorModel( xModel
);
81 osl_atomic_decrement( &m_refCount
);
85 FormController::~FormController()
90 IMPLEMENT_FORWARD_XINTERFACE2( FormController
, OPropertyBrowserController
, FormController_PropertyBase1
)
93 Sequence
< Type
> SAL_CALL
FormController::getTypes( )
95 ::cppu::OTypeCollection
aTypes(
96 cppu::UnoType
<XPropertySet
>::get(),
97 cppu::UnoType
<XMultiPropertySet
>::get(),
98 cppu::UnoType
<XFastPropertySet
>::get(),
99 OPropertyBrowserController::getTypes());
100 return aTypes
.getTypes();
104 IMPLEMENT_GET_IMPLEMENTATION_ID( FormController
)
107 OUString SAL_CALL
FormController::getImplementationName( )
109 return m_aServiceDescriptor
.GetImplementationName();
113 Sequence
< OUString
> SAL_CALL
FormController::getSupportedServiceNames( )
115 Sequence
< OUString
> aSupported( m_aServiceDescriptor
.GetSupportedServiceNames() );
116 aSupported
.realloc( aSupported
.getLength() + 1 );
117 aSupported
[ aSupported
.getLength() - 1 ] = "com.sun.star.inspection.ObjectInspector";
122 OUString
FormController::getImplementationName_static( )
124 return "org.openoffice.comp.extensions.FormController";
128 Sequence
< OUString
> FormController::getSupportedServiceNames_static( )
130 Sequence
< OUString
> aSupported
{ "com.sun.star.form.PropertyBrowserController" };
135 Reference
< XInterface
> FormController::Create(const Reference
< XComponentContext
>& _rxContext
)
137 ServiceDescriptor aService
;
138 aService
.GetImplementationName
= &FormController::getImplementationName_static
;
139 aService
.GetSupportedServiceNames
= &FormController::getSupportedServiceNames_static
;
140 return *(new FormController( _rxContext
, aService
, true ) );
144 Reference
< XPropertySetInfo
> SAL_CALL
FormController::getPropertySetInfo( )
146 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
150 ::cppu::IPropertyArrayHelper
& SAL_CALL
FormController::getInfoHelper()
152 return *getArrayHelper();
156 ::cppu::IPropertyArrayHelper
* FormController::createArrayHelper( ) const
158 Sequence
< Property
> aProps( 2 );
159 aProps
[0] = Property(
160 PROPERTY_CURRENTPAGE
,
161 OWN_PROPERTY_ID_CURRENTPAGE
,
162 ::cppu::UnoType
<OUString
>::get(),
163 PropertyAttribute::TRANSIENT
165 aProps
[1] = Property(
166 PROPERTY_INTROSPECTEDOBJECT
,
167 OWN_PROPERTY_ID_INTROSPECTEDOBJECT
,
168 cppu::UnoType
<XPropertySet
>::get(),
169 PropertyAttribute::TRANSIENT
| PropertyAttribute::CONSTRAINED
171 return new ::cppu::OPropertyArrayHelper( aProps
);
175 sal_Bool SAL_CALL
FormController::convertFastPropertyValue( Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nHandle
, const Any
& rValue
)
179 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT
:
180 if ( rValue
.getValueTypeClass() != TypeClass_INTERFACE
)
181 throw IllegalArgumentException();
183 case OWN_PROPERTY_ID_CURRENTPAGE
:
184 if ( rValue
.getValueTypeClass() != TypeClass_STRING
)
185 throw IllegalArgumentException();
189 getFastPropertyValue( rOldValue
, nHandle
);
190 rConvertedValue
= rValue
;
195 void SAL_CALL
FormController::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle
, const Any
& _rValue
)
199 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT
:
201 Reference
< XObjectInspectorModel
> xModel( getInspectorModel() );
206 m_xCurrentInspectee
.set( _rValue
, UNO_QUERY
);
207 Sequence
< Reference
< XInterface
> > aObjects
;
208 if ( m_xCurrentInspectee
.is() )
210 aObjects
.realloc( 1 );
211 aObjects
[0] = m_xCurrentInspectee
;
214 Reference
< XObjectInspector
> xInspector( *this, UNO_QUERY_THROW
);
215 xInspector
->inspect( aObjects
);
217 catch( const VetoException
& e
)
219 throw PropertyVetoException( e
.Message
, e
.Context
);
224 case OWN_PROPERTY_ID_CURRENTPAGE
:
225 restoreViewData( _rValue
);
231 void SAL_CALL
FormController::getFastPropertyValue( css::uno::Any
& rValue
, sal_Int32 nHandle
) const
235 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT
:
236 rValue
<<= m_xCurrentInspectee
;
239 case OWN_PROPERTY_ID_CURRENTPAGE
:
240 rValue
= const_cast< FormController
* >( this )->getViewData();
249 OUString
DialogController::getImplementationName_static( )
251 return "org.openoffice.comp.extensions.DialogController";
255 Sequence
< OUString
> DialogController::getSupportedServiceNames_static( )
257 Sequence
< OUString
> aSupported
{ "com.sun.star.awt.PropertyBrowserController" };
262 Reference
< XInterface
> DialogController::Create(const Reference
< XComponentContext
>& _rxContext
)
264 ServiceDescriptor aService
;
265 aService
.GetImplementationName
= &DialogController::getImplementationName_static
;
266 aService
.GetSupportedServiceNames
= &DialogController::getSupportedServiceNames_static
;
267 return *(new FormController( _rxContext
, aService
, false ) );
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */