masterfix DEV300: #i10000# build fix
[LibreOffice.git] / extensions / source / propctrlr / formcontroller.cxx
blob1e894452edbec7a6a91eee40de624aecdca438d6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "formcontroller.hxx"
31 #include "pcrcommon.hxx"
32 #include "formstrings.hxx"
33 #include "defaultforminspection.hxx"
34 #ifndef _EXTENSIONS_FORMCTRLR_FORMHELPID_HRC_
35 #include "propctrlr.hrc"
36 #endif
38 /** === begin UNO includes === **/
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #include <com/sun/star/form/XGridColumnFactory.hpp>
41 #include <com/sun/star/form/XForm.hpp>
42 #include <com/sun/star/container/XChild.hpp>
43 /** === end UNO includes === **/
44 #include <cppuhelper/typeprovider.hxx>
45 #include <toolkit/helper/vclunohelper.hxx>
47 //------------------------------------------------------------------------
48 extern "C" void SAL_CALL createRegistryInfo_FormController()
50 ::pcr::OAutoRegistration< ::pcr::FormController > aFormControllerRegistration;
51 ::pcr::OAutoRegistration< ::pcr::DialogController > aDialogControllerRegistration;
54 //........................................................................
55 namespace pcr
57 //........................................................................
59 /** === begin UNO using === **/
60 using ::com::sun::star::uno::Reference;
61 using ::com::sun::star::uno::TypeClass_INTERFACE;
62 using ::com::sun::star::uno::TypeClass_STRING;
63 using ::com::sun::star::uno::XComponentContext;
64 using ::com::sun::star::inspection::XObjectInspectorModel;
65 using ::com::sun::star::uno::RuntimeException;
66 using ::com::sun::star::uno::UNO_QUERY_THROW;
67 using ::com::sun::star::uno::Sequence;
68 using ::com::sun::star::uno::XInterface;
69 using ::com::sun::star::beans::XPropertySetInfo;
70 using ::com::sun::star::beans::XPropertySet;
71 using ::com::sun::star::beans::Property;
72 using ::com::sun::star::uno::Any;
73 using ::com::sun::star::lang::IllegalArgumentException;
74 using ::com::sun::star::uno::Exception;
75 using ::com::sun::star::uno::Type;
76 using ::com::sun::star::util::VetoException;
77 using ::com::sun::star::beans::PropertyVetoException;
78 using ::com::sun::star::uno::UNO_QUERY;
79 using ::com::sun::star::form::XGridColumnFactory;
80 using ::com::sun::star::form::XForm;
81 using ::com::sun::star::container::XChild;
82 using ::com::sun::star::frame::XFrame;
83 using ::com::sun::star::awt::XWindow;
84 /** === end UNO using === **/
86 namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
88 //====================================================================
89 //= FormController
90 //====================================================================
91 //--------------------------------------------------------------------
92 FormController::FormController( const Reference< XComponentContext >& _rxContext, ServiceDescriptor _aServiceDescriptor,
93 bool _bUseFormFormComponentHandlers )
94 :OPropertyBrowserController( _rxContext )
95 ,FormController_PropertyBase1( m_aBHelper )
96 ,m_aServiceDescriptor( _aServiceDescriptor )
98 osl_incrementInterlockedCount( &m_refCount );
100 Reference< XObjectInspectorModel > xModel(
101 *(new DefaultFormComponentInspectorModel( _rxContext, _bUseFormFormComponentHandlers )),
102 UNO_QUERY_THROW
104 setInspectorModel( xModel );
106 osl_decrementInterlockedCount( &m_refCount );
109 //------------------------------------------------------------------------
110 FormController::~FormController()
114 //------------------------------------------------------------------------
115 IMPLEMENT_FORWARD_XINTERFACE2( FormController, OPropertyBrowserController, FormController_PropertyBase1 )
117 //------------------------------------------------------------------------
118 Sequence< Type > SAL_CALL FormController::getTypes( ) throw(RuntimeException)
120 ::cppu::OTypeCollection aTypes(
121 ::getCppuType( static_cast< Reference< XPropertySet >* >(NULL) ),
122 ::getCppuType( static_cast< Reference< XMultiPropertySet >* >(NULL) ),
123 ::getCppuType( static_cast< Reference< XFastPropertySet >* >(NULL) ),
124 OPropertyBrowserController::getTypes());
125 return aTypes.getTypes();
128 //------------------------------------------------------------------------
129 IMPLEMENT_GET_IMPLEMENTATION_ID( FormController )
131 //------------------------------------------------------------------------
132 ::rtl::OUString SAL_CALL FormController::getImplementationName( ) throw(RuntimeException)
134 return m_aServiceDescriptor.GetImplementationName();
137 //------------------------------------------------------------------------
138 Sequence< ::rtl::OUString > SAL_CALL FormController::getSupportedServiceNames( ) throw(RuntimeException)
140 Sequence< ::rtl::OUString > aSupported( m_aServiceDescriptor.GetSupportedServiceNames() );
141 aSupported.realloc( aSupported.getLength() + 1 );
142 aSupported[ aSupported.getLength() - 1 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.inspection.ObjectInspector" ) );
143 return aSupported;
146 //------------------------------------------------------------------------
147 ::rtl::OUString FormController::getImplementationName_static( ) throw(RuntimeException)
149 return ::rtl::OUString::createFromAscii("org.openoffice.comp.extensions.FormController");
152 //------------------------------------------------------------------------
153 Sequence< ::rtl::OUString > FormController::getSupportedServiceNames_static( ) throw(RuntimeException)
155 Sequence< ::rtl::OUString > aSupported(1);
156 aSupported[0] = ::rtl::OUString::createFromAscii( "com.sun.star.form.PropertyBrowserController" );
157 return aSupported;
160 //------------------------------------------------------------------------
161 Reference< XInterface > SAL_CALL FormController::Create(const Reference< XComponentContext >& _rxContext )
163 ServiceDescriptor aService;
164 aService.GetImplementationName = &FormController::getImplementationName_static;
165 aService.GetSupportedServiceNames = &FormController::getSupportedServiceNames_static;
166 return *(new FormController( _rxContext, aService, true ) );
169 //------------------------------------------------------------------------
170 Reference< XPropertySetInfo > SAL_CALL FormController::getPropertySetInfo( ) throw(RuntimeException)
172 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
175 //------------------------------------------------------------------------
176 ::cppu::IPropertyArrayHelper& SAL_CALL FormController::getInfoHelper()
178 return *getArrayHelper();
181 //------------------------------------------------------------------------
182 ::cppu::IPropertyArrayHelper* FormController::createArrayHelper( ) const
184 Sequence< Property > aProps( 2 );
185 aProps[0] = Property(
186 PROPERTY_CURRENTPAGE,
187 OWN_PROPERTY_ID_CURRENTPAGE,
188 ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) ),
189 PropertyAttribute::TRANSIENT
191 aProps[1] = Property(
192 PROPERTY_INTROSPECTEDOBJECT,
193 OWN_PROPERTY_ID_INTROSPECTEDOBJECT,
194 XPropertySet::static_type(),
195 PropertyAttribute::TRANSIENT | PropertyAttribute::CONSTRAINED
197 return new ::cppu::OPropertyArrayHelper( aProps );
200 //------------------------------------------------------------------------
201 sal_Bool SAL_CALL FormController::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw (IllegalArgumentException)
203 switch ( nHandle )
205 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT:
206 if ( rValue.getValueTypeClass() != TypeClass_INTERFACE )
207 throw IllegalArgumentException();
208 break;
209 case OWN_PROPERTY_ID_CURRENTPAGE:
210 if ( rValue.getValueTypeClass() != TypeClass_STRING )
211 throw IllegalArgumentException();
212 break;
215 getFastPropertyValue( rOldValue, nHandle );
216 rConvertedValue = rValue;
217 return sal_True;
220 //------------------------------------------------------------------------
221 void SAL_CALL FormController::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (Exception)
223 switch ( _nHandle )
225 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT:
227 Reference< XObjectInspectorModel > xModel( getInspectorModel() );
228 if ( xModel.is() )
232 m_xCurrentInspectee.set( _rValue, UNO_QUERY );
233 Sequence< Reference< XInterface > > aObjects;
234 if ( m_xCurrentInspectee.is() )
236 aObjects.realloc( 1 );
237 aObjects[0] = m_xCurrentInspectee;
240 Reference< XObjectInspector > xInspector( *this, UNO_QUERY_THROW );
241 xInspector->inspect( aObjects );
243 catch( const VetoException& e )
245 throw PropertyVetoException( e.Message, e.Context );
249 break;
250 case OWN_PROPERTY_ID_CURRENTPAGE:
251 restoreViewData( _rValue );
252 break;
256 //------------------------------------------------------------------------
257 void SAL_CALL FormController::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const
259 switch ( nHandle )
261 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT:
262 rValue <<= m_xCurrentInspectee;
263 break;
265 case OWN_PROPERTY_ID_CURRENTPAGE:
266 rValue = const_cast< FormController* >( this )->getViewData();
267 break;
271 //====================================================================
272 //= DialogController
273 //====================================================================
274 //------------------------------------------------------------------------
275 ::rtl::OUString DialogController::getImplementationName_static( ) throw(RuntimeException)
277 return ::rtl::OUString::createFromAscii("org.openoffice.comp.extensions.DialogController");
280 //------------------------------------------------------------------------
281 Sequence< ::rtl::OUString > DialogController::getSupportedServiceNames_static( ) throw(RuntimeException)
283 Sequence< ::rtl::OUString > aSupported(1);
284 aSupported[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.PropertyBrowserController" );
285 return aSupported;
288 //------------------------------------------------------------------------
289 Reference< XInterface > SAL_CALL DialogController::Create(const Reference< XComponentContext >& _rxContext)
291 ServiceDescriptor aService;
292 aService.GetImplementationName = &DialogController::getImplementationName_static;
293 aService.GetSupportedServiceNames = &DialogController::getSupportedServiceNames_static;
294 return *(new FormController( _rxContext, aService, false ) );
297 //........................................................................
298 } // namespace pcr
299 //........................................................................