1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: formcontroller.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "formcontroller.hxx"
34 #include "pcrcommon.hxx"
35 #include "formstrings.hxx"
36 #include "defaultforminspection.hxx"
37 #ifndef _EXTENSIONS_FORMCTRLR_FORMHELPID_HRC_
38 #include "formhelpid.hrc"
41 /** === begin UNO includes === **/
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include <com/sun/star/form/XGridColumnFactory.hpp>
44 #include <com/sun/star/form/XForm.hpp>
45 #include <com/sun/star/container/XChild.hpp>
46 /** === end UNO includes === **/
47 #include <cppuhelper/typeprovider.hxx>
48 #include <toolkit/helper/vclunohelper.hxx>
50 //------------------------------------------------------------------------
51 extern "C" void SAL_CALL
createRegistryInfo_FormController()
53 ::pcr::OAutoRegistration
< ::pcr::FormController
> aFormControllerRegistration
;
54 ::pcr::OAutoRegistration
< ::pcr::DialogController
> aDialogControllerRegistration
;
57 //........................................................................
60 //........................................................................
62 /** === begin UNO using === **/
63 using ::com::sun::star::uno::Reference
;
64 using ::com::sun::star::uno::TypeClass_INTERFACE
;
65 using ::com::sun::star::uno::TypeClass_STRING
;
66 using ::com::sun::star::uno::XComponentContext
;
67 using ::com::sun::star::inspection::XObjectInspectorModel
;
68 using ::com::sun::star::uno::RuntimeException
;
69 using ::com::sun::star::uno::UNO_QUERY_THROW
;
70 using ::com::sun::star::uno::Sequence
;
71 using ::com::sun::star::uno::XInterface
;
72 using ::com::sun::star::beans::XPropertySetInfo
;
73 using ::com::sun::star::beans::XPropertySet
;
74 using ::com::sun::star::beans::Property
;
75 using ::com::sun::star::uno::Any
;
76 using ::com::sun::star::lang::IllegalArgumentException
;
77 using ::com::sun::star::uno::Exception
;
78 using ::com::sun::star::uno::Type
;
79 using ::com::sun::star::util::VetoException
;
80 using ::com::sun::star::beans::PropertyVetoException
;
81 using ::com::sun::star::uno::UNO_QUERY
;
82 using ::com::sun::star::form::XGridColumnFactory
;
83 using ::com::sun::star::form::XForm
;
84 using ::com::sun::star::container::XChild
;
85 using ::com::sun::star::frame::XFrame
;
86 using ::com::sun::star::awt::XWindow
;
87 /** === end UNO using === **/
89 namespace PropertyAttribute
= ::com::sun::star::beans::PropertyAttribute
;
91 //====================================================================
93 //====================================================================
94 //--------------------------------------------------------------------
95 FormController::FormController( const Reference
< XComponentContext
>& _rxContext
, ServiceDescriptor _aServiceDescriptor
,
96 bool _bUseFormFormComponentHandlers
)
97 :OPropertyBrowserController( _rxContext
)
98 ,FormController_PropertyBase1( m_aBHelper
)
99 ,m_aServiceDescriptor( _aServiceDescriptor
)
101 osl_incrementInterlockedCount( &m_refCount
);
103 Reference
< XObjectInspectorModel
> xModel(
104 *(new DefaultFormComponentInspectorModel( _rxContext
, _bUseFormFormComponentHandlers
)),
107 setInspectorModel( xModel
);
109 osl_decrementInterlockedCount( &m_refCount
);
112 //------------------------------------------------------------------------
113 FormController::~FormController()
117 //------------------------------------------------------------------------
118 IMPLEMENT_FORWARD_XINTERFACE2( FormController
, OPropertyBrowserController
, FormController_PropertyBase1
)
120 //------------------------------------------------------------------------
121 Sequence
< Type
> SAL_CALL
FormController::getTypes( ) throw(RuntimeException
)
123 ::cppu::OTypeCollection
aTypes(
124 ::getCppuType( static_cast< Reference
< XPropertySet
>* >(NULL
) ),
125 ::getCppuType( static_cast< Reference
< XMultiPropertySet
>* >(NULL
) ),
126 ::getCppuType( static_cast< Reference
< XFastPropertySet
>* >(NULL
) ),
127 OPropertyBrowserController::getTypes());
128 return aTypes
.getTypes();
131 //------------------------------------------------------------------------
132 IMPLEMENT_GET_IMPLEMENTATION_ID( FormController
)
134 //------------------------------------------------------------------------
135 ::rtl::OUString SAL_CALL
FormController::getImplementationName( ) throw(RuntimeException
)
137 return m_aServiceDescriptor
.GetImplementationName();
140 //------------------------------------------------------------------------
141 Sequence
< ::rtl::OUString
> SAL_CALL
FormController::getSupportedServiceNames( ) throw(RuntimeException
)
143 Sequence
< ::rtl::OUString
> aSupported( m_aServiceDescriptor
.GetSupportedServiceNames() );
144 aSupported
.realloc( aSupported
.getLength() + 1 );
145 aSupported
[ aSupported
.getLength() - 1 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.inspection.ObjectInspector" ) );
149 //------------------------------------------------------------------------
150 ::rtl::OUString
FormController::getImplementationName_static( ) throw(RuntimeException
)
152 return ::rtl::OUString::createFromAscii("org.openoffice.comp.extensions.FormController");
155 //------------------------------------------------------------------------
156 Sequence
< ::rtl::OUString
> FormController::getSupportedServiceNames_static( ) throw(RuntimeException
)
158 Sequence
< ::rtl::OUString
> aSupported(1);
159 aSupported
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.form.PropertyBrowserController" );
163 //------------------------------------------------------------------------
164 Reference
< XInterface
> SAL_CALL
FormController::Create(const Reference
< XComponentContext
>& _rxContext
)
166 ServiceDescriptor aService
;
167 aService
.GetImplementationName
= &FormController::getImplementationName_static
;
168 aService
.GetSupportedServiceNames
= &FormController::getSupportedServiceNames_static
;
169 return *(new FormController( _rxContext
, aService
, true ) );
172 //------------------------------------------------------------------------
173 Reference
< XPropertySetInfo
> SAL_CALL
FormController::getPropertySetInfo( ) throw(RuntimeException
)
175 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
178 //------------------------------------------------------------------------
179 ::cppu::IPropertyArrayHelper
& SAL_CALL
FormController::getInfoHelper()
181 return *getArrayHelper();
184 //------------------------------------------------------------------------
185 ::cppu::IPropertyArrayHelper
* FormController::createArrayHelper( ) const
187 Sequence
< Property
> aProps( 2 );
188 aProps
[0] = Property(
189 PROPERTY_CURRENTPAGE
,
190 OWN_PROPERTY_ID_CURRENTPAGE
,
191 ::getCppuType( static_cast< ::rtl::OUString
* >( NULL
) ),
192 PropertyAttribute::TRANSIENT
194 aProps
[1] = Property(
195 PROPERTY_INTROSPECTEDOBJECT
,
196 OWN_PROPERTY_ID_INTROSPECTEDOBJECT
,
197 XPropertySet::static_type(),
198 PropertyAttribute::TRANSIENT
| PropertyAttribute::CONSTRAINED
200 return new ::cppu::OPropertyArrayHelper( aProps
);
203 //------------------------------------------------------------------------
204 sal_Bool SAL_CALL
FormController::convertFastPropertyValue( Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nHandle
, const Any
& rValue
) throw (IllegalArgumentException
)
208 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT
:
209 if ( rValue
.getValueTypeClass() != TypeClass_INTERFACE
)
210 throw IllegalArgumentException();
212 case OWN_PROPERTY_ID_CURRENTPAGE
:
213 if ( rValue
.getValueTypeClass() != TypeClass_STRING
)
214 throw IllegalArgumentException();
218 getFastPropertyValue( rOldValue
, nHandle
);
219 rConvertedValue
= rValue
;
223 //------------------------------------------------------------------------
224 void SAL_CALL
FormController::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle
, const Any
& _rValue
) throw (Exception
)
228 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT
:
230 Reference
< XObjectInspectorModel
> xModel( getInspectorModel() );
235 m_xCurrentInspectee
.set( _rValue
, UNO_QUERY
);
236 Sequence
< Reference
< XInterface
> > aObjects
;
237 if ( m_xCurrentInspectee
.is() )
239 aObjects
.realloc( 1 );
240 aObjects
[0] = m_xCurrentInspectee
;
243 Reference
< XObjectInspector
> xInspector( *this, UNO_QUERY_THROW
);
244 xInspector
->inspect( aObjects
);
246 catch( const VetoException
& e
)
248 throw PropertyVetoException( e
.Message
, e
.Context
);
253 case OWN_PROPERTY_ID_CURRENTPAGE
:
254 restoreViewData( _rValue
);
259 //------------------------------------------------------------------------
260 void SAL_CALL
FormController::getFastPropertyValue( ::com::sun::star::uno::Any
& rValue
, sal_Int32 nHandle
) const
264 case OWN_PROPERTY_ID_INTROSPECTEDOBJECT
:
265 rValue
<<= m_xCurrentInspectee
;
268 case OWN_PROPERTY_ID_CURRENTPAGE
:
269 rValue
= const_cast< FormController
* >( this )->getViewData();
274 //====================================================================
276 //====================================================================
277 //------------------------------------------------------------------------
278 ::rtl::OUString
DialogController::getImplementationName_static( ) throw(RuntimeException
)
280 return ::rtl::OUString::createFromAscii("org.openoffice.comp.extensions.DialogController");
283 //------------------------------------------------------------------------
284 Sequence
< ::rtl::OUString
> DialogController::getSupportedServiceNames_static( ) throw(RuntimeException
)
286 Sequence
< ::rtl::OUString
> aSupported(1);
287 aSupported
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.PropertyBrowserController" );
291 //------------------------------------------------------------------------
292 Reference
< XInterface
> SAL_CALL
DialogController::Create(const Reference
< XComponentContext
>& _rxContext
)
294 ServiceDescriptor aService
;
295 aService
.GetImplementationName
= &DialogController::getImplementationName_static
;
296 aService
.GetSupportedServiceNames
= &DialogController::getSupportedServiceNames_static
;
297 return *(new FormController( _rxContext
, aService
, false ) );
300 //........................................................................
302 //........................................................................