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.hrc"
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/form/XGridColumnFactory.hpp>
29 #include <com/sun/star/form/XForm.hpp>
30 #include <com/sun/star/container/XChild.hpp>
31 #include <cppuhelper/typeprovider.hxx>
32 #include <toolkit/helper/vclunohelper.hxx>
35 extern "C" void SAL_CALL
createRegistryInfo_FormController()
37 ::pcr::OAutoRegistration
< ::pcr::FormController
> aFormControllerRegistration
;
38 ::pcr::OAutoRegistration
< ::pcr::DialogController
> aDialogControllerRegistration
;
46 using ::com::sun::star::uno::Reference
;
47 using ::com::sun::star::uno::TypeClass_INTERFACE
;
48 using ::com::sun::star::uno::TypeClass_STRING
;
49 using ::com::sun::star::uno::XComponentContext
;
50 using ::com::sun::star::inspection::XObjectInspectorModel
;
51 using ::com::sun::star::uno::RuntimeException
;
52 using ::com::sun::star::uno::UNO_QUERY_THROW
;
53 using ::com::sun::star::uno::Sequence
;
54 using ::com::sun::star::uno::XInterface
;
55 using ::com::sun::star::beans::XPropertySetInfo
;
56 using ::com::sun::star::beans::XPropertySet
;
57 using ::com::sun::star::beans::Property
;
58 using ::com::sun::star::uno::Any
;
59 using ::com::sun::star::lang::IllegalArgumentException
;
60 using ::com::sun::star::uno::Exception
;
61 using ::com::sun::star::uno::Type
;
62 using ::com::sun::star::util::VetoException
;
63 using ::com::sun::star::beans::PropertyVetoException
;
64 using ::com::sun::star::uno::UNO_QUERY
;
65 using ::com::sun::star::form::XGridColumnFactory
;
66 using ::com::sun::star::form::XForm
;
67 using ::com::sun::star::container::XChild
;
68 using ::com::sun::star::frame::XFrame
;
69 using ::com::sun::star::awt::XWindow
;
71 namespace PropertyAttribute
= ::com::sun::star::beans::PropertyAttribute
;
77 FormController::FormController( const Reference
< XComponentContext
>& _rxContext
, ServiceDescriptor _aServiceDescriptor
,
78 bool _bUseFormFormComponentHandlers
)
79 :OPropertyBrowserController( _rxContext
)
80 ,FormController_PropertyBase1( m_aBHelper
)
81 ,m_aServiceDescriptor( _aServiceDescriptor
)
83 osl_atomic_increment( &m_refCount
);
85 Reference
< XObjectInspectorModel
> xModel(
86 *(new DefaultFormComponentInspectorModel( _bUseFormFormComponentHandlers
)),
89 setInspectorModel( xModel
);
91 osl_atomic_decrement( &m_refCount
);
95 FormController::~FormController()
100 IMPLEMENT_FORWARD_XINTERFACE2( FormController
, OPropertyBrowserController
, FormController_PropertyBase1
)
103 Sequence
< Type
> SAL_CALL
FormController::getTypes( ) throw(RuntimeException
, std::exception
)
105 ::cppu::OTypeCollection
aTypes(
106 cppu::UnoType
<XPropertySet
>::get(),
107 cppu::UnoType
<XMultiPropertySet
>::get(),
108 cppu::UnoType
<XFastPropertySet
>::get(),
109 OPropertyBrowserController::getTypes());
110 return aTypes
.getTypes();
114 IMPLEMENT_GET_IMPLEMENTATION_ID( FormController
)
117 OUString SAL_CALL
FormController::getImplementationName( ) throw(RuntimeException
, std::exception
)
119 return m_aServiceDescriptor
.GetImplementationName();
123 Sequence
< OUString
> SAL_CALL
FormController::getSupportedServiceNames( ) throw(RuntimeException
, std::exception
)
125 Sequence
< OUString
> aSupported( m_aServiceDescriptor
.GetSupportedServiceNames() );
126 aSupported
.realloc( aSupported
.getLength() + 1 );
127 aSupported
[ aSupported
.getLength() - 1 ] = "com.sun.star.inspection.ObjectInspector";
132 OUString
FormController::getImplementationName_static( ) throw(RuntimeException
)
134 return OUString("org.openoffice.comp.extensions.FormController");
138 Sequence
< OUString
> FormController::getSupportedServiceNames_static( ) throw(RuntimeException
)
140 Sequence
< OUString
> aSupported(1);
141 aSupported
[0] = "com.sun.star.form.PropertyBrowserController";
146 Reference
< XInterface
> SAL_CALL
FormController::Create(const Reference
< XComponentContext
>& _rxContext
)
148 ServiceDescriptor aService
;
149 aService
.GetImplementationName
= &FormController::getImplementationName_static
;
150 aService
.GetSupportedServiceNames
= &FormController::getSupportedServiceNames_static
;
151 return *(new FormController( _rxContext
, aService
, true ) );
155 Reference
< XPropertySetInfo
> SAL_CALL
FormController::getPropertySetInfo( ) throw(RuntimeException
, std::exception
)
157 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
161 ::cppu::IPropertyArrayHelper
& SAL_CALL
FormController::getInfoHelper()
163 return *getArrayHelper();
167 ::cppu::IPropertyArrayHelper
* FormController::createArrayHelper( ) const
169 Sequence
< Property
> aProps( 2 );
170 aProps
[0] = Property(
171 PROPERTY_CURRENTPAGE
,
172 OWN_PROPERTY_ID_CURRENTPAGE
,
173 ::cppu::UnoType
<OUString
>::get(),
174 PropertyAttribute::TRANSIENT
176 aProps
[1] = Property(
177 PROPERTY_INTROSPECTEDOBJECT
,
178 OWN_PROPERTY_ID_INTROSPECTEDOBJECT
,
179 cppu::UnoType
<XPropertySet
>::get(),
180 PropertyAttribute::TRANSIENT
| PropertyAttribute::CONSTRAINED
182 return new ::cppu::OPropertyArrayHelper( aProps
);
186 sal_Bool SAL_CALL
FormController::convertFastPropertyValue( Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nHandle
, const Any
& rValue
) throw (IllegalArgumentException
)
190 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT
:
191 if ( rValue
.getValueTypeClass() != TypeClass_INTERFACE
)
192 throw IllegalArgumentException();
194 case OWN_PROPERTY_ID_CURRENTPAGE
:
195 if ( rValue
.getValueTypeClass() != TypeClass_STRING
)
196 throw IllegalArgumentException();
200 getFastPropertyValue( rOldValue
, nHandle
);
201 rConvertedValue
= rValue
;
206 void SAL_CALL
FormController::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle
, const Any
& _rValue
) throw (Exception
, std::exception
)
210 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT
:
212 Reference
< XObjectInspectorModel
> xModel( getInspectorModel() );
217 m_xCurrentInspectee
.set( _rValue
, UNO_QUERY
);
218 Sequence
< Reference
< XInterface
> > aObjects
;
219 if ( m_xCurrentInspectee
.is() )
221 aObjects
.realloc( 1 );
222 aObjects
[0] = m_xCurrentInspectee
;
225 Reference
< XObjectInspector
> xInspector( *this, UNO_QUERY_THROW
);
226 xInspector
->inspect( aObjects
);
228 catch( const VetoException
& e
)
230 throw PropertyVetoException( e
.Message
, e
.Context
);
235 case OWN_PROPERTY_ID_CURRENTPAGE
:
236 restoreViewData( _rValue
);
242 void SAL_CALL
FormController::getFastPropertyValue( ::com::sun::star::uno::Any
& rValue
, sal_Int32 nHandle
) const
246 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT
:
247 rValue
<<= m_xCurrentInspectee
;
250 case OWN_PROPERTY_ID_CURRENTPAGE
:
251 rValue
= const_cast< FormController
* >( this )->getViewData();
260 OUString
DialogController::getImplementationName_static( ) throw(RuntimeException
)
262 return OUString("org.openoffice.comp.extensions.DialogController");
266 Sequence
< OUString
> DialogController::getSupportedServiceNames_static( ) throw(RuntimeException
)
268 Sequence
< OUString
> aSupported(1);
269 aSupported
[0] = "com.sun.star.awt.PropertyBrowserController";
274 Reference
< XInterface
> SAL_CALL
DialogController::Create(const Reference
< XComponentContext
>& _rxContext
)
276 ServiceDescriptor aService
;
277 aService
.GetImplementationName
= &DialogController::getImplementationName_static
;
278 aService
.GetSupportedServiceNames
= &DialogController::getSupportedServiceNames_static
;
279 return *(new FormController( _rxContext
, aService
, false ) );
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */