xref: /trunk/main/extensions/source/propctrlr/formcontroller.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
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
37 
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>
46 
47 //------------------------------------------------------------------------
48 extern "C" void SAL_CALL createRegistryInfo_FormController()
49 {
50     ::pcr::OAutoRegistration< ::pcr::FormController > aFormControllerRegistration;
51     ::pcr::OAutoRegistration< ::pcr::DialogController > aDialogControllerRegistration;
52 }
53 
54 //........................................................................
55 namespace pcr
56 {
57 //........................................................................
58 
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 === **/
85 
86     namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
87 
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 )
97     {
98         osl_incrementInterlockedCount( &m_refCount );
99         {
100             Reference< XObjectInspectorModel > xModel(
101                 *(new DefaultFormComponentInspectorModel( _rxContext, _bUseFormFormComponentHandlers )),
102                 UNO_QUERY_THROW
103             );
104             setInspectorModel( xModel );
105         }
106         osl_decrementInterlockedCount( &m_refCount );
107     }
108 
109     //------------------------------------------------------------------------
110     FormController::~FormController()
111     {
112     }
113 
114     //------------------------------------------------------------------------
115     IMPLEMENT_FORWARD_XINTERFACE2( FormController, OPropertyBrowserController, FormController_PropertyBase1 )
116 
117     //------------------------------------------------------------------------
118     Sequence< Type > SAL_CALL FormController::getTypes(  ) throw(RuntimeException)
119     {
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();
126     }
127 
128     //------------------------------------------------------------------------
129     IMPLEMENT_GET_IMPLEMENTATION_ID( FormController )
130 
131     //------------------------------------------------------------------------
132     ::rtl::OUString SAL_CALL FormController::getImplementationName(  ) throw(RuntimeException)
133     {
134         return m_aServiceDescriptor.GetImplementationName();
135     }
136 
137     //------------------------------------------------------------------------
138     Sequence< ::rtl::OUString > SAL_CALL FormController::getSupportedServiceNames(  ) throw(RuntimeException)
139     {
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;
144     }
145 
146     //------------------------------------------------------------------------
147     ::rtl::OUString FormController::getImplementationName_static(  ) throw(RuntimeException)
148     {
149         return ::rtl::OUString::createFromAscii("org.openoffice.comp.extensions.FormController");
150     }
151 
152     //------------------------------------------------------------------------
153     Sequence< ::rtl::OUString > FormController::getSupportedServiceNames_static(  ) throw(RuntimeException)
154     {
155         Sequence< ::rtl::OUString > aSupported(1);
156         aSupported[0] = ::rtl::OUString::createFromAscii( "com.sun.star.form.PropertyBrowserController" );
157         return aSupported;
158     }
159 
160     //------------------------------------------------------------------------
161     Reference< XInterface > SAL_CALL FormController::Create(const Reference< XComponentContext >& _rxContext )
162     {
163         ServiceDescriptor aService;
164         aService.GetImplementationName = &FormController::getImplementationName_static;
165         aService.GetSupportedServiceNames = &FormController::getSupportedServiceNames_static;
166         return *(new FormController( _rxContext, aService, true ) );
167     }
168 
169     //------------------------------------------------------------------------
170     Reference< XPropertySetInfo > SAL_CALL FormController::getPropertySetInfo(  ) throw(RuntimeException)
171     {
172         return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
173     }
174 
175     //------------------------------------------------------------------------
176     ::cppu::IPropertyArrayHelper& SAL_CALL FormController::getInfoHelper()
177     {
178         return *getArrayHelper();
179     }
180 
181     //------------------------------------------------------------------------
182     ::cppu::IPropertyArrayHelper* FormController::createArrayHelper( ) const
183     {
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
190         );
191         aProps[1] = Property(
192             PROPERTY_INTROSPECTEDOBJECT,
193             OWN_PROPERTY_ID_INTROSPECTEDOBJECT,
194             XPropertySet::static_type(),
195             PropertyAttribute::TRANSIENT | PropertyAttribute::CONSTRAINED
196         );
197         return new ::cppu::OPropertyArrayHelper( aProps );
198     }
199 
200     //------------------------------------------------------------------------
201     sal_Bool SAL_CALL FormController::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw (IllegalArgumentException)
202     {
203         switch ( nHandle )
204         {
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;
213         }
214 
215         getFastPropertyValue( rOldValue, nHandle );
216         rConvertedValue = rValue;
217         return sal_True;
218     }
219 
220     //------------------------------------------------------------------------
221     void SAL_CALL FormController::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (Exception)
222     {
223         switch ( _nHandle )
224         {
225         case OWN_PROPERTY_ID_INTROSPECTEDOBJECT:
226         {
227             Reference< XObjectInspectorModel > xModel( getInspectorModel() );
228             if ( xModel.is() )
229             {
230                 try
231                 {
232                     m_xCurrentInspectee.set( _rValue, UNO_QUERY );
233                     Sequence< Reference< XInterface > > aObjects;
234                     if ( m_xCurrentInspectee.is() )
235                     {
236                         aObjects.realloc( 1 );
237                         aObjects[0] = m_xCurrentInspectee;
238                     }
239 
240                     Reference< XObjectInspector > xInspector( *this, UNO_QUERY_THROW );
241                     xInspector->inspect( aObjects );
242                 }
243                 catch( const VetoException& e )
244                 {
245                     throw PropertyVetoException( e.Message, e.Context );
246                 }
247             }
248         }
249         break;
250         case OWN_PROPERTY_ID_CURRENTPAGE:
251             restoreViewData( _rValue );
252             break;
253         }
254     }
255 
256     //------------------------------------------------------------------------
257     void SAL_CALL FormController::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const
258     {
259         switch ( nHandle )
260         {
261         case OWN_PROPERTY_ID_INTROSPECTEDOBJECT:
262             rValue <<= m_xCurrentInspectee;
263             break;
264 
265         case OWN_PROPERTY_ID_CURRENTPAGE:
266             rValue = const_cast< FormController* >( this )->getViewData();
267             break;
268         }
269     }
270 
271     //====================================================================
272     //= DialogController
273     //====================================================================
274     //------------------------------------------------------------------------
275     ::rtl::OUString DialogController::getImplementationName_static(  ) throw(RuntimeException)
276     {
277         return ::rtl::OUString::createFromAscii("org.openoffice.comp.extensions.DialogController");
278     }
279 
280     //------------------------------------------------------------------------
281     Sequence< ::rtl::OUString > DialogController::getSupportedServiceNames_static(  ) throw(RuntimeException)
282     {
283         Sequence< ::rtl::OUString > aSupported(1);
284         aSupported[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.PropertyBrowserController" );
285         return aSupported;
286     }
287 
288     //------------------------------------------------------------------------
289     Reference< XInterface > SAL_CALL DialogController::Create(const Reference< XComponentContext >& _rxContext)
290     {
291         ServiceDescriptor aService;
292         aService.GetImplementationName = &DialogController::getImplementationName_static;
293         aService.GetSupportedServiceNames = &DialogController::getSupportedServiceNames_static;
294         return *(new FormController( _rxContext, aService, false ) );
295     }
296 
297 //........................................................................
298 } // namespace pcr
299 //........................................................................
300