1 /*************************************************************************
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * Copyright 2000, 2010 Oracle and/or its affiliates.
5  *
6  * OpenOffice.org - a multi-platform office productivity suite
7  *
8  * This file is part of OpenOffice.org.
9  *
10  * OpenOffice.org is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License version 3
12  * only, as published by the Free Software Foundation.
13  *
14  * OpenOffice.org is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License version 3 for more details
18  * (a copy is included in the LICENSE file that accompanied this code).
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with OpenOffice.org.  If not, see
22  * <http://www.openoffice.org/license.html>
23  * for a copy of the LGPLv3 License.
24  *
25 ************************************************************************/
26 
27 // MARKER(update_precomp.py): autogen include statement, do not remove
28 #include "precompiled_svx.hxx"
29 
30 #include "fmservs.hxx"
31 
32 /** === begin UNO includes === **/
33 #include <com/sun/star/form/XFormController.hpp>
34 #include <com/sun/star/form/runtime/XFormController.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 /** === end UNO includes === **/
38 
39 #include <cppuhelper/implbase2.hxx>
40 
41 //........................................................................
42 namespace svxform
43 {
44 //........................................................................
45 
46 	/** === begin UNO using === **/
47 	using ::com::sun::star::uno::Reference;
48 	using ::com::sun::star::uno::XInterface;
49 	using ::com::sun::star::uno::UNO_QUERY;
50 	using ::com::sun::star::uno::UNO_QUERY_THROW;
51 	using ::com::sun::star::uno::UNO_SET_THROW;
52 	using ::com::sun::star::uno::Exception;
53 	using ::com::sun::star::uno::RuntimeException;
54 	using ::com::sun::star::uno::Any;
55 	using ::com::sun::star::uno::makeAny;
56 	using ::com::sun::star::uno::Sequence;
57 	using ::com::sun::star::uno::Type;
58     using ::com::sun::star::lang::XMultiServiceFactory;
59     using ::com::sun::star::awt::XControl;
60     using ::com::sun::star::awt::XTabControllerModel;
61     using ::com::sun::star::awt::XControlContainer;
62     using ::com::sun::star::lang::XServiceInfo;
63 	/** === end UNO using === **/
64 
65     using namespace ::com::sun::star;
66 
67 	//====================================================================
68 	//= LegacyFormController
69 	//====================================================================
70     typedef ::cppu::WeakImplHelper2 <   form::XFormController
71                                     ,   XServiceInfo
72                                     >   LegacyFormController_Base;
73     /** is an implementation of the legacy form controller service, namely css.form.FormController, supporting the
74         css.form.XFormController interface.
75 
76         This legacy API is superseded by css.form.runtime.(X)FormController, and though we migrated all OOo-internal
77         usage of this old API, their might be clients external to OOo still using it (though this is rather unlikely).
78     */
79     class LegacyFormController : public LegacyFormController_Base
80     {
81     public:
82         static Reference< XInterface > Create( const Reference< XMultiServiceFactory >& _rxFactory )
83         {
84             return *( new LegacyFormController( _rxFactory ) );
85         }
86 
87     protected:
88         LegacyFormController( const Reference< XMultiServiceFactory >& _rxFactory )
89             :m_xDelegator( _rxFactory->createInstance( FM_FORM_CONTROLLER ), UNO_QUERY_THROW )
90         {
91         }
92 
93         // form::XFormController
94         virtual Reference< XControl > SAL_CALL getCurrentControl(  ) throw (RuntimeException);
95         virtual void SAL_CALL addActivateListener( const Reference< form::XFormControllerListener >& l ) throw (RuntimeException);
96         virtual void SAL_CALL removeActivateListener( const Reference< form::XFormControllerListener >& l ) throw (RuntimeException);
97 
98         // awt::XTabController
99         virtual void SAL_CALL setModel( const Reference< XTabControllerModel >& Model ) throw (RuntimeException);
100         virtual Reference< XTabControllerModel > SAL_CALL getModel(  ) throw (RuntimeException);
101         virtual void SAL_CALL setContainer( const Reference< XControlContainer >& Container ) throw (RuntimeException);
102         virtual Reference< XControlContainer > SAL_CALL getContainer(  ) throw (RuntimeException);
103         virtual Sequence< Reference< XControl > > SAL_CALL getControls(  ) throw (RuntimeException);
104         virtual void SAL_CALL autoTabOrder(  ) throw (RuntimeException);
105         virtual void SAL_CALL activateTabOrder(  ) throw (RuntimeException);
106         virtual void SAL_CALL activateFirst(  ) throw (RuntimeException);
107         virtual void SAL_CALL activateLast(  ) throw (RuntimeException);
108 
109         // XServiceInfo
110         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
111         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException);
112         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
113 
114     private:
115         const Reference< form::runtime::XFormController >   m_xDelegator;
116     };
117 
118     //--------------------------------------------------------------------
119     Reference< XControl > SAL_CALL LegacyFormController::getCurrentControl(  ) throw (RuntimeException)
120     {
121         return m_xDelegator->getCurrentControl();
122     }
123 
124     //--------------------------------------------------------------------
125     void SAL_CALL LegacyFormController::addActivateListener( const Reference< form::XFormControllerListener >& _listener ) throw (RuntimeException)
126     {
127         m_xDelegator->addActivateListener( _listener );
128     }
129 
130     //--------------------------------------------------------------------
131     void SAL_CALL LegacyFormController::removeActivateListener( const Reference< form::XFormControllerListener >& _listener ) throw (RuntimeException)
132     {
133         m_xDelegator->removeActivateListener( _listener );
134     }
135 
136     //--------------------------------------------------------------------
137     void SAL_CALL LegacyFormController::setModel( const Reference< XTabControllerModel >& _model ) throw (RuntimeException)
138     {
139         m_xDelegator->setModel( _model );
140     }
141 
142     //--------------------------------------------------------------------
143     Reference< XTabControllerModel > SAL_CALL LegacyFormController::getModel(  ) throw (RuntimeException)
144     {
145         return m_xDelegator->getModel();
146     }
147 
148     //--------------------------------------------------------------------
149     void SAL_CALL LegacyFormController::setContainer( const Reference< XControlContainer >& _container ) throw (RuntimeException)
150     {
151         m_xDelegator->setContainer( _container );
152     }
153 
154     //--------------------------------------------------------------------
155     Reference< XControlContainer > SAL_CALL LegacyFormController::getContainer(  ) throw (RuntimeException)
156     {
157         return m_xDelegator->getContainer();
158     }
159 
160     //--------------------------------------------------------------------
161     Sequence< Reference< XControl > > SAL_CALL LegacyFormController::getControls(  ) throw (RuntimeException)
162     {
163         return m_xDelegator->getControls();
164     }
165 
166     //--------------------------------------------------------------------
167     void SAL_CALL LegacyFormController::autoTabOrder(  ) throw (RuntimeException)
168     {
169         m_xDelegator->autoTabOrder();
170     }
171 
172     //--------------------------------------------------------------------
173     void SAL_CALL LegacyFormController::activateTabOrder(  ) throw (RuntimeException)
174     {
175         m_xDelegator->activateTabOrder();
176     }
177 
178     //--------------------------------------------------------------------
179     void SAL_CALL LegacyFormController::activateFirst(  ) throw (RuntimeException)
180     {
181         m_xDelegator->activateFirst();
182     }
183 
184     //--------------------------------------------------------------------
185     void SAL_CALL LegacyFormController::activateLast(  ) throw (RuntimeException)
186     {
187         m_xDelegator->activateLast();
188     }
189 
190     //--------------------------------------------------------------------
191     ::rtl::OUString SAL_CALL LegacyFormController::getImplementationName(  ) throw (RuntimeException)
192     {
193         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.svx.LegacyFormController" ) );
194     }
195 
196     //--------------------------------------------------------------------
197     ::sal_Bool SAL_CALL LegacyFormController::supportsService( const ::rtl::OUString& _serviceName ) throw (RuntimeException)
198     {
199         Sequence< ::rtl::OUString > aServices( getSupportedServiceNames() );
200         const ::rtl::OUString* pServices = aServices.getConstArray();
201         for ( sal_Int32 i = 0; i < aServices.getLength(); ++i, ++pServices )
202             if( pServices->equals( _serviceName ) )
203                 return sal_True;
204         return sal_False;
205     }
206 
207     //--------------------------------------------------------------------
208     Sequence< ::rtl::OUString > SAL_CALL LegacyFormController::getSupportedServiceNames(  ) throw (RuntimeException)
209     {
210         Sequence< ::rtl::OUString > aServices(2);
211         aServices.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.FormController" ) );
212         aServices.getArray()[1] = ::rtl::OUString::createFromAscii("com.sun.star.awt.control.TabController");
213         return aServices;
214     }
215 
216 //........................................................................
217 } // namespace svxform
218 //........................................................................
219 
220 //------------------------------------------------------------------
221 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
222     LegacyFormController_NewInstance_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & _rxORB )
223 {
224     return ::svxform::LegacyFormController::Create( _rxORB );
225 }
226 
227