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