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