xref: /trunk/main/svx/source/inc/formcontrolling.hxx (revision 3334a7e6)
1*3334a7e6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3334a7e6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3334a7e6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3334a7e6SAndrew Rist  * distributed with this work for additional information
6*3334a7e6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3334a7e6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3334a7e6SAndrew Rist  * "License"); you may not use this file except in compliance
9*3334a7e6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3334a7e6SAndrew Rist  *
11*3334a7e6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3334a7e6SAndrew Rist  *
13*3334a7e6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3334a7e6SAndrew Rist  * software distributed under the License is distributed on an
15*3334a7e6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3334a7e6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3334a7e6SAndrew Rist  * specific language governing permissions and limitations
18*3334a7e6SAndrew Rist  * under the License.
19*3334a7e6SAndrew Rist  *
20*3334a7e6SAndrew Rist  *************************************************************/
21*3334a7e6SAndrew Rist 
22*3334a7e6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SVX_FORMCONTROLLING_HXX
25cdf0e10cSrcweir #define SVX_FORMCONTROLLING_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/form/runtime/XFormController.hpp>
28cdf0e10cSrcweir #include <com/sun/star/form/XForm.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/form/runtime/FeatureState.hpp>
31cdf0e10cSrcweir #include <com/sun/star/form/runtime/XFormOperations.hpp>
32cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLErrorListener.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
35cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <vector>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //........................................................................
40cdf0e10cSrcweir namespace svx
41cdf0e10cSrcweir {
42cdf0e10cSrcweir //........................................................................
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     //====================================================================
45cdf0e10cSrcweir     //= FeatureSlotTranslation
46cdf0e10cSrcweir     //====================================================================
47cdf0e10cSrcweir     class FeatureSlotTranslation
48cdf0e10cSrcweir     {
49cdf0e10cSrcweir     public:
50cdf0e10cSrcweir         /// retrieves the feature id for a given feature URL
51cdf0e10cSrcweir         static  sal_Int32       getControllerFeatureSlotIdForURL( const ::rtl::OUString& _rMainURL );
52cdf0e10cSrcweir 
53cdf0e10cSrcweir         /// retrieves the feature URL for a given feature id
54cdf0e10cSrcweir         static ::rtl::OUString  getControllerFeatureURLForSlotId( sal_Int32 _nSlotId );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir         /// determines whether the given URL is a controller feature URL
57cdf0e10cSrcweir         static sal_Bool         isFeatureURL( const ::rtl::OUString& _rMainURL );
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         /// retrieves the css.form.runtime.FormFeature ID for a given slot ID
60cdf0e10cSrcweir         static  sal_Int16       getFormFeatureForSlotId( sal_Int32 _nSlotId );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir         /// retrieves the slot id for a given css.form.runtime.FormFeature ID
63cdf0e10cSrcweir         static  sal_Int32       getSlotIdForFormFeature( sal_Int16 _nFormFeature );
64cdf0e10cSrcweir     };
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     //====================================================================
67cdf0e10cSrcweir     //= IControllerFeatureInvalidation
68cdf0e10cSrcweir     //====================================================================
69cdf0e10cSrcweir     class IControllerFeatureInvalidation
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir     public:
72cdf0e10cSrcweir         /** invalidates the given features
73cdf0e10cSrcweir 
74cdf0e10cSrcweir             Invalidation means that any user interface representation (such as toolbox buttons), or
75cdf0e10cSrcweir             any dispatches associated with the features in question are potentially out-of-date, and
76cdf0e10cSrcweir             need to be updated
77cdf0e10cSrcweir 
78cdf0e10cSrcweir             @param _rFeatures
79cdf0e10cSrcweir                 Ids of the features to be invalidated.
80cdf0e10cSrcweir         */
81cdf0e10cSrcweir         virtual void invalidateFeatures( const ::std::vector< sal_Int32 >& _rFeatures ) = 0;
82cdf0e10cSrcweir     };
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     //====================================================================
85cdf0e10cSrcweir     //= ControllerFeatures
86cdf0e10cSrcweir     //====================================================================
87cdf0e10cSrcweir     class FormControllerHelper;
88cdf0e10cSrcweir     /** easier access to an FormControllerHelper instance
89cdf0e10cSrcweir     */
90cdf0e10cSrcweir     class ControllerFeatures
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir     protected:
93cdf0e10cSrcweir         ::comphelper::ComponentContext  m_aContext;
94cdf0e10cSrcweir         IControllerFeatureInvalidation* m_pInvalidationCallback;    // necessary as long as m_pImpl is not yet constructed
95cdf0e10cSrcweir         FormControllerHelper*           m_pImpl;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     public:
98cdf0e10cSrcweir         /** standard ctor
99cdf0e10cSrcweir 
100cdf0e10cSrcweir             The instance is not functional until <method>assign</method> is used.
101cdf0e10cSrcweir 
102cdf0e10cSrcweir             @param _rxORB
103cdf0e10cSrcweir                 a multi service factory for creating various needed components
104cdf0e10cSrcweir 
105cdf0e10cSrcweir             @param _pInvalidationCallback
106cdf0e10cSrcweir                 the callback for invalidating feature states
107cdf0e10cSrcweir         */
108cdf0e10cSrcweir         ControllerFeatures(
109cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
110cdf0e10cSrcweir             IControllerFeatureInvalidation* _pInvalidationCallback
111cdf0e10cSrcweir         );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         /** constructs the instance from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
114cdf0e10cSrcweir 
115cdf0e10cSrcweir             @param _rxORB
116cdf0e10cSrcweir                 a multi service factory for creating various needed components
117cdf0e10cSrcweir 
118cdf0e10cSrcweir             @param _rxController
119cdf0e10cSrcweir                 The form controller which the helper should be responsible for. Must not
120cdf0e10cSrcweir                 be <NULL/>, and must have a valid model (form).
121cdf0e10cSrcweir 
122cdf0e10cSrcweir             @param _pInvalidationCallback
123cdf0e10cSrcweir                 the callback for invalidating feature states
124cdf0e10cSrcweir         */
125cdf0e10cSrcweir         ControllerFeatures(
126cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
127cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController,
128cdf0e10cSrcweir             IControllerFeatureInvalidation* _pInvalidationCallback
129cdf0e10cSrcweir         );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         /** constructs the helper form a <type scope="com::sun::star::form">XForm<type> instance
132cdf0e10cSrcweir 
133cdf0e10cSrcweir             Any functionality which depends on a controller will not be available.
134cdf0e10cSrcweir 
135cdf0e10cSrcweir             @param _rxORB
136cdf0e10cSrcweir                 a multi service factory for creating various needed components
137cdf0e10cSrcweir 
138cdf0e10cSrcweir             @param _rxForm
139cdf0e10cSrcweir                 The form which the helper should be responsible for. Must not be <NULL/>.
140cdf0e10cSrcweir 
141cdf0e10cSrcweir             @param _pInvalidationCallback
142cdf0e10cSrcweir                 the callback for invalidating feature states
143cdf0e10cSrcweir         */
144cdf0e10cSrcweir         ControllerFeatures(
145cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
146cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm,
147cdf0e10cSrcweir             IControllerFeatureInvalidation* _pInvalidationCallback
148cdf0e10cSrcweir         );
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         /// dtor
151cdf0e10cSrcweir         ~ControllerFeatures();
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         /// checks whether the instance is properly assigned to a form and/or controller
isAssigned() const154cdf0e10cSrcweir         inline bool isAssigned( ) const { return m_pImpl != NULL; }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         /** assign to a controller
157cdf0e10cSrcweir         */
158cdf0e10cSrcweir         void assign(
159cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController
160cdf0e10cSrcweir         );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         /** assign to a controller
163cdf0e10cSrcweir         */
164cdf0e10cSrcweir         void assign(
165cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm
166cdf0e10cSrcweir         );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         /// clears the instance so that it cannot be used afterwards
169cdf0e10cSrcweir         void dispose();
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         // access to the instance which implements the functionality. Not to be used when not assigned
operator ->() const172cdf0e10cSrcweir         inline const FormControllerHelper* operator->() const { return m_pImpl; }
operator ->()173cdf0e10cSrcweir         inline       FormControllerHelper* operator->()       { return m_pImpl; }
operator *() const174cdf0e10cSrcweir         inline const FormControllerHelper& operator*() const  { return *m_pImpl; }
operator *()175cdf0e10cSrcweir         inline       FormControllerHelper& operator*()        { return *m_pImpl; }
176cdf0e10cSrcweir     };
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     //====================================================================
179cdf0e10cSrcweir     //= FormControllerHelper
180cdf0e10cSrcweir     //====================================================================
181cdf0e10cSrcweir     typedef ::cppu::WeakImplHelper2 <   ::com::sun::star::form::runtime::XFeatureInvalidation
182cdf0e10cSrcweir                                     ,   ::com::sun::star::sdb::XSQLErrorListener
183cdf0e10cSrcweir                                     >   FormControllerHelper_Base;
184cdf0e10cSrcweir     /** is a helper class which manages form controller functionality (such as moveNext etc.).
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         <p>The class helps implementing form controller functionality, by providing
187cdf0e10cSrcweir         methods to determine the state of, and execute, various common form features.<br/>
188cdf0e10cSrcweir         A <em>feature</em> is for instance moving the form associated with the controller
189cdf0e10cSrcweir         to a certain position, or reloading the form, and so on.</p>
190cdf0e10cSrcweir     */
191cdf0e10cSrcweir     class FormControllerHelper : public FormControllerHelper_Base
192cdf0e10cSrcweir     {
193cdf0e10cSrcweir     protected:
194cdf0e10cSrcweir         ::comphelper::ComponentContext  m_aContext;
195cdf0e10cSrcweir         IControllerFeatureInvalidation* m_pInvalidationCallback;
196cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >
197cdf0e10cSrcweir                                         m_xFormOperations;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir         ::com::sun::star::uno::Any      m_aOperationError;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     public:
202cdf0e10cSrcweir         /** constructs the helper from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
203cdf0e10cSrcweir 
204cdf0e10cSrcweir             @param _rContext
205cdf0e10cSrcweir                 the context the component lives in
206cdf0e10cSrcweir             @param _rxController
207cdf0e10cSrcweir                 The form controller which the helper should be responsible for. Must not
208cdf0e10cSrcweir                 be <NULL/>, and must have a valid model (form).
209cdf0e10cSrcweir             @param _pInvalidationCallback
210cdf0e10cSrcweir                 the callback for invalidating feature states
211cdf0e10cSrcweir         */
212cdf0e10cSrcweir         FormControllerHelper(
213cdf0e10cSrcweir             const ::comphelper::ComponentContext& _rContext,
214cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController,
215cdf0e10cSrcweir             IControllerFeatureInvalidation* _pInvalidationCallback
216cdf0e10cSrcweir         );
217cdf0e10cSrcweir 
218cdf0e10cSrcweir         /** constructs the helper form a <type scope="com::sun::star::form">XForm<type> instance
219cdf0e10cSrcweir 
220cdf0e10cSrcweir             Any functionality which depends on a controller will not be available.
221cdf0e10cSrcweir 
222cdf0e10cSrcweir             @param _rContext
223cdf0e10cSrcweir                 the context the component lives in
224cdf0e10cSrcweir             @param _rxForm
225cdf0e10cSrcweir                 The form which the helper should be responsible for. Must not be <NULL/>.
226cdf0e10cSrcweir             @param _pInvalidationCallback
227cdf0e10cSrcweir                 the callback for invalidating feature states
228cdf0e10cSrcweir         */
229cdf0e10cSrcweir         FormControllerHelper(
230cdf0e10cSrcweir             const ::comphelper::ComponentContext& _rContext,
231cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm,
232cdf0e10cSrcweir             IControllerFeatureInvalidation* _pInvalidationCallback
233cdf0e10cSrcweir         );
234cdf0e10cSrcweir 
235cdf0e10cSrcweir         // forwards to the XFormOperations implementation
236cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >
237cdf0e10cSrcweir                     getCursor() const;
238cdf0e10cSrcweir         void        getState(
239cdf0e10cSrcweir                         sal_Int32 _nSlotId,
240cdf0e10cSrcweir                         ::com::sun::star::form::runtime::FeatureState& _out_rState
241cdf0e10cSrcweir                     ) const;
242cdf0e10cSrcweir         sal_Bool    isEnabled( sal_Int32 _nSlotId ) const;
243cdf0e10cSrcweir         void        execute( sal_Int32 _nSlotId ) const;
244cdf0e10cSrcweir         void        execute( sal_Int32 _nSlotId, const ::rtl::OUString& _rParamName, const ::com::sun::star::uno::Any& _rParamValue ) const;
245cdf0e10cSrcweir         sal_Bool    commitCurrentRecord() const;
246cdf0e10cSrcweir         sal_Bool    commitCurrentControl( ) const;
247cdf0e10cSrcweir         sal_Bool    isInsertionRow() const;
248cdf0e10cSrcweir         sal_Bool    isModifiedRow() const;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir         bool        moveLeft( ) const;
251cdf0e10cSrcweir         bool        moveRight( ) const;
252cdf0e10cSrcweir 
253cdf0e10cSrcweir         bool        canDoFormFilter() const;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir         /** disposes this instance.
256cdf0e10cSrcweir 
257cdf0e10cSrcweir             After this method has been called, the instance is not functional anymore
258cdf0e10cSrcweir         */
259cdf0e10cSrcweir         void        dispose();
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >&
getFormOperations() const262cdf0e10cSrcweir                     getFormOperations() const { return m_xFormOperations; }
263cdf0e10cSrcweir     protected:
264cdf0e10cSrcweir         /// dtor
265cdf0e10cSrcweir         ~FormControllerHelper();
266cdf0e10cSrcweir 
267cdf0e10cSrcweir         // XFeatureInvalidation
268cdf0e10cSrcweir         virtual void SAL_CALL invalidateFeatures( const ::com::sun::star::uno::Sequence< ::sal_Int16 >& Features ) throw (::com::sun::star::uno::RuntimeException);
269cdf0e10cSrcweir         virtual void SAL_CALL invalidateAllFeatures() throw (::com::sun::star::uno::RuntimeException);
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         // XSQLErrorListener
272cdf0e10cSrcweir         virtual void SAL_CALL errorOccured( const ::com::sun::star::sdb::SQLErrorEvent& _Event ) throw (::com::sun::star::uno::RuntimeException);
273cdf0e10cSrcweir 
274cdf0e10cSrcweir         // XEventListener
275cdf0e10cSrcweir         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
276cdf0e10cSrcweir 
277cdf0e10cSrcweir     private:
278cdf0e10cSrcweir         enum FormOperation { EXECUTE, EXECUTE_ARGS, COMMIT_CONTROL, COMMIT_RECORD };
279cdf0e10cSrcweir 
280cdf0e10cSrcweir         bool    impl_operateForm_nothrow(
281cdf0e10cSrcweir                     const FormOperation _eWhat,
282cdf0e10cSrcweir                     const sal_Int16 _nFeature,  /* ignore for COMMIT_* */
283cdf0e10cSrcweir                     const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rArguments /* ignore except for EXECUTE_ARGS */
284cdf0e10cSrcweir                 ) const;
impl_operateForm_nothrow(const FormOperation _eWhat) const285cdf0e10cSrcweir         bool    impl_operateForm_nothrow( const FormOperation _eWhat ) const
286cdf0e10cSrcweir         {
287cdf0e10cSrcweir             return impl_operateForm_nothrow( _eWhat, 0, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() );
288cdf0e10cSrcweir         }
impl_operateForm_nothrow(const sal_Int16 _nFeature) const289cdf0e10cSrcweir         bool    impl_operateForm_nothrow( const sal_Int16 _nFeature ) const
290cdf0e10cSrcweir         {
291cdf0e10cSrcweir             return impl_operateForm_nothrow( EXECUTE, _nFeature, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() );
292cdf0e10cSrcweir         }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     private:
295cdf0e10cSrcweir         FormControllerHelper();                                         // never implemented
296cdf0e10cSrcweir         FormControllerHelper( const FormControllerHelper& );            // never implemented
297cdf0e10cSrcweir         FormControllerHelper& operator=( const FormControllerHelper& ); // never implemented
298cdf0e10cSrcweir     };
299cdf0e10cSrcweir 
300cdf0e10cSrcweir //........................................................................
301cdf0e10cSrcweir }   // namespace svx
302cdf0e10cSrcweir //........................................................................
303cdf0e10cSrcweir 
304cdf0e10cSrcweir #endif // SVX_FORMCONTROLLING_HXX
305