1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include "formcontroller.hxx"
21 #include "pcrcommon.hxx"
22 #include "pcrservices.hxx"
23 #include "formstrings.hxx"
24 #include "defaultforminspection.hxx"
25 #include <propctrlr.h>
26 
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/util/VetoException.hpp>
29 #include <cppuhelper/typeprovider.hxx>
30 
31 
createRegistryInfo_FormController()32 extern "C" void createRegistryInfo_FormController()
33 {
34     ::pcr::OAutoRegistration< ::pcr::FormController > aFormControllerRegistration;
35     ::pcr::OAutoRegistration< ::pcr::DialogController > aDialogControllerRegistration;
36 }
37 
38 
39 namespace pcr
40 {
41 
42 
43     using ::com::sun::star::uno::Reference;
44     using ::com::sun::star::uno::TypeClass_INTERFACE;
45     using ::com::sun::star::uno::TypeClass_STRING;
46     using ::com::sun::star::uno::XComponentContext;
47     using ::com::sun::star::inspection::XObjectInspectorModel;
48     using ::com::sun::star::uno::UNO_QUERY_THROW;
49     using ::com::sun::star::uno::Sequence;
50     using ::com::sun::star::uno::XInterface;
51     using ::com::sun::star::beans::XPropertySetInfo;
52     using ::com::sun::star::beans::XPropertySet;
53     using ::com::sun::star::beans::Property;
54     using ::com::sun::star::uno::Any;
55     using ::com::sun::star::lang::IllegalArgumentException;
56     using ::com::sun::star::uno::Type;
57     using ::com::sun::star::util::VetoException;
58     using ::com::sun::star::beans::PropertyVetoException;
59     using ::com::sun::star::uno::UNO_QUERY;
60 
61     namespace PropertyAttribute = css::beans::PropertyAttribute;
62 
63 
64     //= FormController
65 
66 
FormController(const Reference<XComponentContext> & _rxContext,ServiceDescriptor _aServiceDescriptor,bool _bUseFormFormComponentHandlers)67     FormController::FormController( const Reference< XComponentContext >& _rxContext, ServiceDescriptor _aServiceDescriptor,
68             bool _bUseFormFormComponentHandlers )
69         :OPropertyBrowserController( _rxContext )
70         ,FormController_PropertyBase1( m_aBHelper )
71         ,m_aServiceDescriptor( _aServiceDescriptor )
72     {
73         osl_atomic_increment( &m_refCount );
74         {
75             Reference< XObjectInspectorModel > xModel(
76                 *(new DefaultFormComponentInspectorModel( _bUseFormFormComponentHandlers )),
77                 UNO_QUERY_THROW
78             );
79             setInspectorModel( xModel );
80         }
81         osl_atomic_decrement( &m_refCount );
82     }
83 
84 
~FormController()85     FormController::~FormController()
86     {
87     }
88 
89 
IMPLEMENT_FORWARD_XINTERFACE2(FormController,OPropertyBrowserController,FormController_PropertyBase1)90     IMPLEMENT_FORWARD_XINTERFACE2( FormController, OPropertyBrowserController, FormController_PropertyBase1 )
91 
92 
93     Sequence< Type > SAL_CALL FormController::getTypes(  )
94     {
95         ::cppu::OTypeCollection aTypes(
96             cppu::UnoType<XPropertySet>::get(),
97             cppu::UnoType<XMultiPropertySet>::get(),
98             cppu::UnoType<XFastPropertySet>::get(),
99             OPropertyBrowserController::getTypes());
100         return aTypes.getTypes();
101     }
102 
103 
IMPLEMENT_GET_IMPLEMENTATION_ID(FormController)104     IMPLEMENT_GET_IMPLEMENTATION_ID( FormController )
105 
106 
107     OUString SAL_CALL FormController::getImplementationName(  )
108     {
109         return m_aServiceDescriptor.GetImplementationName();
110     }
111 
112 
getSupportedServiceNames()113     Sequence< OUString > SAL_CALL FormController::getSupportedServiceNames(  )
114     {
115         Sequence< OUString > aSupported( m_aServiceDescriptor.GetSupportedServiceNames() );
116         aSupported.realloc( aSupported.getLength() + 1 );
117         aSupported[ aSupported.getLength() - 1 ] = "com.sun.star.inspection.ObjectInspector";
118         return aSupported;
119     }
120 
121 
getImplementationName_static()122     OUString FormController::getImplementationName_static(  )
123     {
124         return "org.openoffice.comp.extensions.FormController";
125     }
126 
127 
getSupportedServiceNames_static()128     Sequence< OUString > FormController::getSupportedServiceNames_static(  )
129     {
130         Sequence< OUString > aSupported { "com.sun.star.form.PropertyBrowserController" };
131         return aSupported;
132     }
133 
134 
Create(const Reference<XComponentContext> & _rxContext)135     Reference< XInterface > FormController::Create(const Reference< XComponentContext >& _rxContext )
136     {
137         ServiceDescriptor aService;
138         aService.GetImplementationName = &FormController::getImplementationName_static;
139         aService.GetSupportedServiceNames = &FormController::getSupportedServiceNames_static;
140         return *(new FormController( _rxContext, aService, true ) );
141     }
142 
143 
getPropertySetInfo()144     Reference< XPropertySetInfo > SAL_CALL FormController::getPropertySetInfo(  )
145     {
146         return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
147     }
148 
149 
getInfoHelper()150     ::cppu::IPropertyArrayHelper& SAL_CALL FormController::getInfoHelper()
151     {
152         return *getArrayHelper();
153     }
154 
155 
createArrayHelper() const156     ::cppu::IPropertyArrayHelper* FormController::createArrayHelper( ) const
157     {
158         Sequence< Property > aProps( 2 );
159         aProps[0] = Property(
160             PROPERTY_CURRENTPAGE,
161             OWN_PROPERTY_ID_CURRENTPAGE,
162             ::cppu::UnoType<OUString>::get(),
163             PropertyAttribute::TRANSIENT
164         );
165         aProps[1] = Property(
166             PROPERTY_INTROSPECTEDOBJECT,
167             OWN_PROPERTY_ID_INTROSPECTEDOBJECT,
168             cppu::UnoType<XPropertySet>::get(),
169             PropertyAttribute::TRANSIENT | PropertyAttribute::CONSTRAINED
170         );
171         return new ::cppu::OPropertyArrayHelper( aProps );
172     }
173 
174 
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nHandle,const Any & rValue)175     sal_Bool SAL_CALL FormController::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue )
176     {
177         switch ( nHandle )
178         {
179         case OWN_PROPERTY_ID_INTROSPECTEDOBJECT:
180             if ( rValue.getValueTypeClass() != TypeClass_INTERFACE )
181                 throw IllegalArgumentException();
182             break;
183         case OWN_PROPERTY_ID_CURRENTPAGE:
184             if ( rValue.getValueTypeClass() != TypeClass_STRING )
185                 throw IllegalArgumentException();
186             break;
187         }
188 
189         getFastPropertyValue( rOldValue, nHandle );
190         rConvertedValue = rValue;
191         return true;
192     }
193 
194 
setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle,const Any & _rValue)195     void SAL_CALL FormController::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue)
196     {
197         switch ( _nHandle )
198         {
199         case OWN_PROPERTY_ID_INTROSPECTEDOBJECT:
200         {
201             Reference< XObjectInspectorModel > xModel( getInspectorModel() );
202             if ( xModel.is() )
203             {
204                 try
205                 {
206                     m_xCurrentInspectee.set( _rValue, UNO_QUERY );
207                     Sequence< Reference< XInterface > > aObjects;
208                     if ( m_xCurrentInspectee.is() )
209                     {
210                         aObjects.realloc( 1 );
211                         aObjects[0] = m_xCurrentInspectee;
212                     }
213 
214                     Reference< XObjectInspector > xInspector( *this, UNO_QUERY_THROW );
215                     xInspector->inspect( aObjects );
216                 }
217                 catch( const VetoException& e )
218                 {
219                     throw PropertyVetoException( e.Message, e.Context );
220                 }
221             }
222         }
223         break;
224         case OWN_PROPERTY_ID_CURRENTPAGE:
225             restoreViewData( _rValue );
226             break;
227         }
228     }
229 
230 
getFastPropertyValue(css::uno::Any & rValue,sal_Int32 nHandle) const231     void SAL_CALL FormController::getFastPropertyValue( css::uno::Any& rValue, sal_Int32 nHandle ) const
232     {
233         switch ( nHandle )
234         {
235         case OWN_PROPERTY_ID_INTROSPECTEDOBJECT:
236             rValue <<= m_xCurrentInspectee;
237             break;
238 
239         case OWN_PROPERTY_ID_CURRENTPAGE:
240             rValue = const_cast< FormController* >( this )->getViewData();
241             break;
242         }
243     }
244 
245 
246     //= DialogController
247 
248 
getImplementationName_static()249     OUString DialogController::getImplementationName_static(  )
250     {
251         return "org.openoffice.comp.extensions.DialogController";
252     }
253 
254 
getSupportedServiceNames_static()255     Sequence< OUString > DialogController::getSupportedServiceNames_static(  )
256     {
257         Sequence< OUString > aSupported { "com.sun.star.awt.PropertyBrowserController" };
258         return aSupported;
259     }
260 
261 
Create(const Reference<XComponentContext> & _rxContext)262     Reference< XInterface > DialogController::Create(const Reference< XComponentContext >& _rxContext)
263     {
264         ServiceDescriptor aService;
265         aService.GetImplementationName = &DialogController::getImplementationName_static;
266         aService.GetSupportedServiceNames = &DialogController::getSupportedServiceNames_static;
267         return *(new FormController( _rxContext, aService, false ) );
268     }
269 
270 
271 } // namespace pcr
272 
273 
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
275