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