1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: formcontrolling.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SVX_FORMCONTROLLING_HXX
32 #define SVX_FORMCONTROLLING_HXX
34 #include <com/sun/star/form/XFormController.hpp>
35 #include <com/sun/star/form/XForm.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/form/runtime/FeatureState.hpp>
38 #include <com/sun/star/form/runtime/XFormOperations.hpp>
39 #include <com/sun/star/sdb/XSQLErrorListener.hpp>
41 #include <cppuhelper/implbase2.hxx>
42 #include <comphelper/componentcontext.hxx>
46 //........................................................................
49 //........................................................................
51 //====================================================================
52 //= FeatureSlotTranslation
53 //====================================================================
54 class FeatureSlotTranslation
57 /// retrieves the feature id for a given feature URL
58 static sal_Int32
getControllerFeatureSlotIdForURL( const ::rtl::OUString
& _rMainURL
);
60 /// retrieves the feature URL for a given feature id
61 static ::rtl::OUString
getControllerFeatureURLForSlotId( sal_Int32 _nSlotId
);
63 /// determines whether the given URL is a controller feature URL
64 static sal_Bool
isFeatureURL( const ::rtl::OUString
& _rMainURL
);
66 /// retrieves the css.form.runtime.FormFeature ID for a given slot ID
67 static sal_Int16
getFormFeatureForSlotId( sal_Int32 _nSlotId
);
69 /// retrieves the slot id for a given css.form.runtime.FormFeature ID
70 static sal_Int32
getSlotIdForFormFeature( sal_Int16 _nFormFeature
);
73 //====================================================================
74 //= IControllerFeatureInvalidation
75 //====================================================================
76 class IControllerFeatureInvalidation
79 /** invalidates the given features
81 Invalidation means that any user interface representation (such as toolbox buttons), or
82 any dispatches associated with the features in question are potentially out-of-date, and
86 Ids of the features to be invalidated.
88 virtual void invalidateFeatures( const ::std::vector
< sal_Int32
>& _rFeatures
) = 0;
91 //====================================================================
92 //= ControllerFeatures
93 //====================================================================
94 class FormControllerHelper
;
95 /** easier access to an FormControllerHelper instance
97 class ControllerFeatures
100 ::comphelper::ComponentContext m_aContext
;
101 IControllerFeatureInvalidation
* m_pInvalidationCallback
; // necessary as long as m_pImpl is not yet constructed
102 FormControllerHelper
* m_pImpl
;
107 The instance is not functional until <method>assign</method> is used.
110 a multi service factory for creating various needed components
112 @param _pInvalidationCallback
113 the callback for invalidating feature states
116 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxORB
,
117 IControllerFeatureInvalidation
* _pInvalidationCallback
120 /** constructs the instance from a <type scope="com::sun::star::form">XFormController<type> instance
123 a multi service factory for creating various needed components
126 The form controller which the helper should be responsible for. Must not
127 be <NULL/>, and must have a valid model (form).
129 @param _pInvalidationCallback
130 the callback for invalidating feature states
133 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxORB
,
134 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
>& _rxController
,
135 IControllerFeatureInvalidation
* _pInvalidationCallback
138 /** constructs the helper form a <type scope="com::sun::star::form">XForm<type> instance
140 Any functionality which depends on a controller will not be available.
143 a multi service factory for creating various needed components
146 The form which the helper should be responsible for. Must not be <NULL/>.
148 @param _pInvalidationCallback
149 the callback for invalidating feature states
152 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxORB
,
153 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XForm
>& _rxForm
,
154 IControllerFeatureInvalidation
* _pInvalidationCallback
158 ~ControllerFeatures();
160 /// checks whether the instance is properly assigned to a form and/or controller
161 inline bool isAssigned( ) const { return m_pImpl
!= NULL
; }
163 /** assign to a controller
166 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
>& _rxController
169 /** assign to a controller
172 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XForm
>& _rxForm
175 /// clears the instance so that it cannot be used afterwards
178 // access to the instance which implements the functionality. Not to be used when not assigned
179 inline const FormControllerHelper
* operator->() const { return m_pImpl
; }
180 inline FormControllerHelper
* operator->() { return m_pImpl
; }
181 inline const FormControllerHelper
& operator*() const { return *m_pImpl
; }
182 inline FormControllerHelper
& operator*() { return *m_pImpl
; }
185 //====================================================================
186 //= FormControllerHelper
187 //====================================================================
188 typedef ::cppu::WeakImplHelper2
< ::com::sun::star::form::runtime::XFeatureInvalidation
189 , ::com::sun::star::sdb::XSQLErrorListener
190 > FormControllerHelper_Base
;
191 /** is a helper class which manages form controller functionality (such as moveNext etc.).
193 <p>The class helps implementing form controller functionality, by providing
194 methods to determine the state of, and execute, various common form features.<br/>
195 A <em>feature</em> is for instance moving the form associated with the controller
196 to a certain position, or reloading the form, and so on.</p>
198 class FormControllerHelper
: public FormControllerHelper_Base
201 ::comphelper::ComponentContext m_aContext
;
202 IControllerFeatureInvalidation
* m_pInvalidationCallback
;
203 ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormOperations
>
206 ::com::sun::star::uno::Any m_aOperationError
;
209 /** constructs the helper from a <type scope="com::sun::star::form">XFormController<type> instance
212 the context the component lives in
214 The form controller which the helper should be responsible for. Must not
215 be <NULL/>, and must have a valid model (form).
216 @param _pInvalidationCallback
217 the callback for invalidating feature states
219 FormControllerHelper(
220 const ::comphelper::ComponentContext
& _rContext
,
221 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormController
>& _rxController
,
222 IControllerFeatureInvalidation
* _pInvalidationCallback
225 /** constructs the helper form a <type scope="com::sun::star::form">XForm<type> instance
227 Any functionality which depends on a controller will not be available.
230 the context the component lives in
232 The form which the helper should be responsible for. Must not be <NULL/>.
233 @param _pInvalidationCallback
234 the callback for invalidating feature states
236 FormControllerHelper(
237 const ::comphelper::ComponentContext
& _rContext
,
238 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XForm
>& _rxForm
,
239 IControllerFeatureInvalidation
* _pInvalidationCallback
242 // forwards to the XFormOperations implementation
243 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
>
247 ::com::sun::star::form::runtime::FeatureState
& _out_rState
249 sal_Bool
isEnabled( sal_Int32 _nSlotId
) const;
250 void execute( sal_Int32 _nSlotId
) const;
251 void execute( sal_Int32 _nSlotId
, const ::rtl::OUString
& _rParamName
, const ::com::sun::star::uno::Any
& _rParamValue
) const;
252 sal_Bool
commitCurrentRecord() const;
253 sal_Bool
commitCurrentControl( ) const;
254 sal_Bool
isInsertionRow() const;
255 sal_Bool
isModifiedRow() const;
257 bool moveLeft( ) const;
258 bool moveRight( ) const;
260 bool canDoFormFilter() const;
262 /** disposes this instance.
264 After this method has been called, the instance is not functional anymore
268 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormOperations
>&
269 getFormOperations() const { return m_xFormOperations
; }
272 ~FormControllerHelper();
274 // XFeatureInvalidation
275 virtual void SAL_CALL
invalidateFeatures( const ::com::sun::star::uno::Sequence
< ::sal_Int16
>& Features
) throw (::com::sun::star::uno::RuntimeException
);
276 virtual void SAL_CALL
invalidateAllFeatures() throw (::com::sun::star::uno::RuntimeException
);
279 virtual void SAL_CALL
errorOccured( const ::com::sun::star::sdb::SQLErrorEvent
& _Event
) throw (::com::sun::star::uno::RuntimeException
);
282 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
);
285 enum FormOperation
{ EXECUTE
, EXECUTE_ARGS
, COMMIT_CONTROL
, COMMIT_RECORD
};
287 bool impl_operateForm_nothrow(
288 const FormOperation _eWhat
,
289 const sal_Int16 _nFeature
, /* ignore for COMMIT_* */
290 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>& _rArguments
/* ignore except for EXECUTE_ARGS */
292 bool impl_operateForm_nothrow( const FormOperation _eWhat
) const
294 return impl_operateForm_nothrow( _eWhat
, 0, ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>() );
296 bool impl_operateForm_nothrow( const sal_Int16 _nFeature
) const
298 return impl_operateForm_nothrow( EXECUTE
, _nFeature
, ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>() );
302 FormControllerHelper(); // never implemented
303 FormControllerHelper( const FormControllerHelper
& ); // never implemented
304 FormControllerHelper
& operator=( const FormControllerHelper
& ); // never implemented
307 //........................................................................
309 //........................................................................
311 #endif // SVX_FORMCONTROLLING_HXX