1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVX_SOURCE_INC_FORMCONTROLLING_HXX
21 #define INCLUDED_SVX_SOURCE_INC_FORMCONTROLLING_HXX
23 #include <com/sun/star/form/runtime/XFormController.hpp>
24 #include <com/sun/star/form/XForm.hpp>
25 #include <com/sun/star/form/runtime/FeatureState.hpp>
26 #include <com/sun/star/form/runtime/XFormOperations.hpp>
27 #include <com/sun/star/sdb/XSQLErrorListener.hpp>
29 #include <cppuhelper/implbase2.hxx>
37 class FeatureSlotTranslation
40 /// retrieves the feature id for a given feature URL
41 static sal_Int32
getControllerFeatureSlotIdForURL( const OUString
& _rMainURL
);
43 /// retrieves the css.form.runtime.FormFeature ID for a given slot ID
44 static sal_Int16
getFormFeatureForSlotId( sal_Int32 _nSlotId
);
46 /// retrieves the slot id for a given css.form.runtime.FormFeature ID
47 static sal_Int32
getSlotIdForFormFeature( sal_Int16 _nFormFeature
);
50 class IControllerFeatureInvalidation
53 /** invalidates the given features
55 Invalidation means that any user interface representation (such as toolbox buttons), or
56 any dispatches associated with the features in question are potentially out-of-date, and
60 Ids of the features to be invalidated.
62 virtual void invalidateFeatures( const ::std::vector
< sal_Int32
>& _rFeatures
) = 0;
65 ~IControllerFeatureInvalidation() {}
68 class FormControllerHelper
;
69 /** easier access to an FormControllerHelper instance
71 class ControllerFeatures
74 IControllerFeatureInvalidation
* m_pInvalidationCallback
; // necessary as long as m_pImpl is not yet constructed
75 FormControllerHelper
* m_pImpl
;
80 The instance is not functional until <method>assign</method> is used.
82 @param _pInvalidationCallback
83 the callback for invalidating feature states
86 IControllerFeatureInvalidation
* _pInvalidationCallback
89 /** constructs the instance from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
92 The form controller which the helper should be responsible for. Must not
93 be <NULL/>, and must have a valid model (form).
95 @param _pInvalidationCallback
96 the callback for invalidating feature states
99 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormController
>& _rxController
,
100 IControllerFeatureInvalidation
* _pInvalidationCallback
104 ~ControllerFeatures();
106 /// checks whether the instance is properly assigned to a form and/or controller
107 inline bool isAssigned( ) const { return m_pImpl
!= NULL
; }
109 /** assign to a controller
112 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormController
>& _rxController
115 /// clears the instance so that it cannot be used afterwards
118 // access to the instance which implements the functionality. Not to be used when not assigned
119 inline const FormControllerHelper
* operator->() const { return m_pImpl
; }
120 inline FormControllerHelper
* operator->() { return m_pImpl
; }
121 inline const FormControllerHelper
& operator*() const { return *m_pImpl
; }
122 inline FormControllerHelper
& operator*() { return *m_pImpl
; }
126 //= FormControllerHelper
128 typedef ::cppu::WeakImplHelper2
< ::com::sun::star::form::runtime::XFeatureInvalidation
129 , ::com::sun::star::sdb::XSQLErrorListener
130 > FormControllerHelper_Base
;
131 /** is a helper class which manages form controller functionality (such as moveNext etc.).
133 <p>The class helps implementing form controller functionality, by providing
134 methods to determine the state of, and execute, various common form features.<br/>
135 A <em>feature</em> is for instance moving the form associated with the controller
136 to a certain position, or reloading the form, and so on.</p>
138 class FormControllerHelper
: public FormControllerHelper_Base
141 IControllerFeatureInvalidation
* m_pInvalidationCallback
;
142 ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormOperations
>
145 ::com::sun::star::uno::Any m_aOperationError
;
148 /** constructs the helper from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
151 The form controller which the helper should be responsible for. Must not
152 be <NULL/>, and must have a valid model (form).
153 @param _pInvalidationCallback
154 the callback for invalidating feature states
156 FormControllerHelper(
157 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormController
>& _rxController
,
158 IControllerFeatureInvalidation
* _pInvalidationCallback
161 // forwards to the XFormOperations implementation
162 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
>
166 ::com::sun::star::form::runtime::FeatureState
& _out_rState
168 bool isEnabled( sal_Int32 _nSlotId
) const;
169 void execute( sal_Int32 _nSlotId
) const;
170 void execute( sal_Int32 _nSlotId
, const OUString
& _rParamName
, const ::com::sun::star::uno::Any
& _rParamValue
) const;
171 bool commitCurrentRecord() const;
172 bool commitCurrentControl( ) const;
173 bool isInsertionRow() const;
174 bool isModifiedRow() const;
176 bool canDoFormFilter() const;
178 /** disposes this instance.
180 After this method has been called, the instance is not functional anymore
184 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormOperations
>&
185 getFormOperations() const { return m_xFormOperations
; }
188 virtual ~FormControllerHelper();
190 // XFeatureInvalidation
191 virtual void SAL_CALL
invalidateFeatures( const ::com::sun::star::uno::Sequence
< ::sal_Int16
>& Features
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
192 virtual void SAL_CALL
invalidateAllFeatures() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
195 virtual void SAL_CALL
errorOccured( const ::com::sun::star::sdb::SQLErrorEvent
& _Event
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
198 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
201 enum FormOperation
{ EXECUTE
, EXECUTE_ARGS
, COMMIT_CONTROL
, COMMIT_RECORD
};
203 bool impl_operateForm_nothrow(
204 const FormOperation _eWhat
,
205 const sal_Int16 _nFeature
, /* ignore for COMMIT_* */
206 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>& _rArguments
/* ignore except for EXECUTE_ARGS */
208 bool impl_operateForm_nothrow( const FormOperation _eWhat
) const
210 return impl_operateForm_nothrow( _eWhat
, 0, ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>() );
212 bool impl_operateForm_nothrow( const sal_Int16 _nFeature
) const
214 return impl_operateForm_nothrow( EXECUTE
, _nFeature
, ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>() );
218 FormControllerHelper( const FormControllerHelper
& ) SAL_DELETED_FUNCTION
;
219 FormControllerHelper
& operator=( const FormControllerHelper
& ) SAL_DELETED_FUNCTION
;
226 #endif // INCLUDED_SVX_SOURCE_INC_FORMCONTROLLING_HXX
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */