update credits
[LibreOffice.git] / extensions / source / propctrlr / formcontroller.cxx
blob732c639aab5f87494aacd17dadb8b20b55e0fabd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
24 #include "propctrlr.hrc"
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/form/XGridColumnFactory.hpp>
28 #include <com/sun/star/form/XForm.hpp>
29 #include <com/sun/star/container/XChild.hpp>
30 #include <cppuhelper/typeprovider.hxx>
31 #include <toolkit/helper/vclunohelper.hxx>
33 //------------------------------------------------------------------------
34 extern "C" void SAL_CALL createRegistryInfo_FormController()
36 ::pcr::OAutoRegistration< ::pcr::FormController > aFormControllerRegistration;
37 ::pcr::OAutoRegistration< ::pcr::DialogController > aDialogControllerRegistration;
40 //........................................................................
41 namespace pcr
43 //........................................................................
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::TypeClass_INTERFACE;
47 using ::com::sun::star::uno::TypeClass_STRING;
48 using ::com::sun::star::uno::XComponentContext;
49 using ::com::sun::star::inspection::XObjectInspectorModel;
50 using ::com::sun::star::uno::RuntimeException;
51 using ::com::sun::star::uno::UNO_QUERY_THROW;
52 using ::com::sun::star::uno::Sequence;
53 using ::com::sun::star::uno::XInterface;
54 using ::com::sun::star::beans::XPropertySetInfo;
55 using ::com::sun::star::beans::XPropertySet;
56 using ::com::sun::star::beans::Property;
57 using ::com::sun::star::uno::Any;
58 using ::com::sun::star::lang::IllegalArgumentException;
59 using ::com::sun::star::uno::Exception;
60 using ::com::sun::star::uno::Type;
61 using ::com::sun::star::util::VetoException;
62 using ::com::sun::star::beans::PropertyVetoException;
63 using ::com::sun::star::uno::UNO_QUERY;
64 using ::com::sun::star::form::XGridColumnFactory;
65 using ::com::sun::star::form::XForm;
66 using ::com::sun::star::container::XChild;
67 using ::com::sun::star::frame::XFrame;
68 using ::com::sun::star::awt::XWindow;
70 namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
72 //====================================================================
73 //= FormController
74 //====================================================================
75 //--------------------------------------------------------------------
76 FormController::FormController( const Reference< XComponentContext >& _rxContext, ServiceDescriptor _aServiceDescriptor,
77 bool _bUseFormFormComponentHandlers )
78 :OPropertyBrowserController( _rxContext )
79 ,FormController_PropertyBase1( m_aBHelper )
80 ,m_aServiceDescriptor( _aServiceDescriptor )
82 osl_atomic_increment( &m_refCount );
84 Reference< XObjectInspectorModel > xModel(
85 *(new DefaultFormComponentInspectorModel( _rxContext, _bUseFormFormComponentHandlers )),
86 UNO_QUERY_THROW
88 setInspectorModel( xModel );
90 osl_atomic_decrement( &m_refCount );
93 //------------------------------------------------------------------------
94 FormController::~FormController()
98 //------------------------------------------------------------------------
99 IMPLEMENT_FORWARD_XINTERFACE2( FormController, OPropertyBrowserController, FormController_PropertyBase1 )
101 //------------------------------------------------------------------------
102 Sequence< Type > SAL_CALL FormController::getTypes( ) throw(RuntimeException)
104 ::cppu::OTypeCollection aTypes(
105 ::getCppuType( static_cast< Reference< XPropertySet >* >(NULL) ),
106 ::getCppuType( static_cast< Reference< XMultiPropertySet >* >(NULL) ),
107 ::getCppuType( static_cast< Reference< XFastPropertySet >* >(NULL) ),
108 OPropertyBrowserController::getTypes());
109 return aTypes.getTypes();
112 //------------------------------------------------------------------------
113 IMPLEMENT_GET_IMPLEMENTATION_ID( FormController )
115 //------------------------------------------------------------------------
116 OUString SAL_CALL FormController::getImplementationName( ) throw(RuntimeException)
118 return m_aServiceDescriptor.GetImplementationName();
121 //------------------------------------------------------------------------
122 Sequence< OUString > SAL_CALL FormController::getSupportedServiceNames( ) throw(RuntimeException)
124 Sequence< OUString > aSupported( m_aServiceDescriptor.GetSupportedServiceNames() );
125 aSupported.realloc( aSupported.getLength() + 1 );
126 aSupported[ aSupported.getLength() - 1 ] = OUString( "com.sun.star.inspection.ObjectInspector" );
127 return aSupported;
130 //------------------------------------------------------------------------
131 OUString FormController::getImplementationName_static( ) throw(RuntimeException)
133 return OUString("org.openoffice.comp.extensions.FormController");
136 //------------------------------------------------------------------------
137 Sequence< OUString > FormController::getSupportedServiceNames_static( ) throw(RuntimeException)
139 Sequence< OUString > aSupported(1);
140 aSupported[0] = OUString("com.sun.star.form.PropertyBrowserController");
141 return aSupported;
144 //------------------------------------------------------------------------
145 Reference< XInterface > SAL_CALL FormController::Create(const Reference< XComponentContext >& _rxContext )
147 ServiceDescriptor aService;
148 aService.GetImplementationName = &FormController::getImplementationName_static;
149 aService.GetSupportedServiceNames = &FormController::getSupportedServiceNames_static;
150 return *(new FormController( _rxContext, aService, true ) );
153 //------------------------------------------------------------------------
154 Reference< XPropertySetInfo > SAL_CALL FormController::getPropertySetInfo( ) throw(RuntimeException)
156 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
159 //------------------------------------------------------------------------
160 ::cppu::IPropertyArrayHelper& SAL_CALL FormController::getInfoHelper()
162 return *getArrayHelper();
165 //------------------------------------------------------------------------
166 ::cppu::IPropertyArrayHelper* FormController::createArrayHelper( ) const
168 Sequence< Property > aProps( 2 );
169 aProps[0] = Property(
170 PROPERTY_CURRENTPAGE,
171 OWN_PROPERTY_ID_CURRENTPAGE,
172 ::getCppuType( static_cast< OUString* >( NULL ) ),
173 PropertyAttribute::TRANSIENT
175 aProps[1] = Property(
176 PROPERTY_INTROSPECTEDOBJECT,
177 OWN_PROPERTY_ID_INTROSPECTEDOBJECT,
178 XPropertySet::static_type(),
179 PropertyAttribute::TRANSIENT | PropertyAttribute::CONSTRAINED
181 return new ::cppu::OPropertyArrayHelper( aProps );
184 //------------------------------------------------------------------------
185 sal_Bool SAL_CALL FormController::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw (IllegalArgumentException)
187 switch ( nHandle )
189 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT:
190 if ( rValue.getValueTypeClass() != TypeClass_INTERFACE )
191 throw IllegalArgumentException();
192 break;
193 case OWN_PROPERTY_ID_CURRENTPAGE:
194 if ( rValue.getValueTypeClass() != TypeClass_STRING )
195 throw IllegalArgumentException();
196 break;
199 getFastPropertyValue( rOldValue, nHandle );
200 rConvertedValue = rValue;
201 return sal_True;
204 //------------------------------------------------------------------------
205 void SAL_CALL FormController::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (Exception)
207 switch ( _nHandle )
209 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT:
211 Reference< XObjectInspectorModel > xModel( getInspectorModel() );
212 if ( xModel.is() )
216 m_xCurrentInspectee.set( _rValue, UNO_QUERY );
217 Sequence< Reference< XInterface > > aObjects;
218 if ( m_xCurrentInspectee.is() )
220 aObjects.realloc( 1 );
221 aObjects[0] = m_xCurrentInspectee;
224 Reference< XObjectInspector > xInspector( *this, UNO_QUERY_THROW );
225 xInspector->inspect( aObjects );
227 catch( const VetoException& e )
229 throw PropertyVetoException( e.Message, e.Context );
233 break;
234 case OWN_PROPERTY_ID_CURRENTPAGE:
235 restoreViewData( _rValue );
236 break;
240 //------------------------------------------------------------------------
241 void SAL_CALL FormController::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const
243 switch ( nHandle )
245 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT:
246 rValue <<= m_xCurrentInspectee;
247 break;
249 case OWN_PROPERTY_ID_CURRENTPAGE:
250 rValue = const_cast< FormController* >( this )->getViewData();
251 break;
255 //====================================================================
256 //= DialogController
257 //====================================================================
258 //------------------------------------------------------------------------
259 OUString DialogController::getImplementationName_static( ) throw(RuntimeException)
261 return OUString("org.openoffice.comp.extensions.DialogController");
264 //------------------------------------------------------------------------
265 Sequence< OUString > DialogController::getSupportedServiceNames_static( ) throw(RuntimeException)
267 Sequence< OUString > aSupported(1);
268 aSupported[0] = OUString("com.sun.star.awt.PropertyBrowserController");
269 return aSupported;
272 //------------------------------------------------------------------------
273 Reference< XInterface > SAL_CALL DialogController::Create(const Reference< XComponentContext >& _rxContext)
275 ServiceDescriptor aService;
276 aService.GetImplementationName = &DialogController::getImplementationName_static;
277 aService.GetSupportedServiceNames = &DialogController::getSupportedServiceNames_static;
278 return *(new FormController( _rxContext, aService, false ) );
281 //........................................................................
282 } // namespace pcr
283 //........................................................................
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */