bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / inc / formcontrolling.hxx
blob065a7c0939216a1c05861e99b04f3a1c97d5957d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 SVX_FORMCONTROLLING_HXX
21 #define SVX_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>
31 #include <vector>
33 //........................................................................
34 namespace svx
36 //........................................................................
38 //====================================================================
39 //= FeatureSlotTranslation
40 //====================================================================
41 class FeatureSlotTranslation
43 public:
44 /// retrieves the feature id for a given feature URL
45 static sal_Int32 getControllerFeatureSlotIdForURL( const OUString& _rMainURL );
47 /// retrieves the css.form.runtime.FormFeature ID for a given slot ID
48 static sal_Int16 getFormFeatureForSlotId( sal_Int32 _nSlotId );
50 /// retrieves the slot id for a given css.form.runtime.FormFeature ID
51 static sal_Int32 getSlotIdForFormFeature( sal_Int16 _nFormFeature );
54 //====================================================================
55 //= IControllerFeatureInvalidation
56 //====================================================================
57 class IControllerFeatureInvalidation
59 public:
60 /** invalidates the given features
62 Invalidation means that any user interface representation (such as toolbox buttons), or
63 any dispatches associated with the features in question are potentially out-of-date, and
64 need to be updated
66 @param _rFeatures
67 Ids of the features to be invalidated.
69 virtual void invalidateFeatures( const ::std::vector< sal_Int32 >& _rFeatures ) = 0;
71 protected:
72 ~IControllerFeatureInvalidation() {}
75 //====================================================================
76 //= ControllerFeatures
77 //====================================================================
78 class FormControllerHelper;
79 /** easier access to an FormControllerHelper instance
81 class ControllerFeatures
83 protected:
84 IControllerFeatureInvalidation* m_pInvalidationCallback; // necessary as long as m_pImpl is not yet constructed
85 FormControllerHelper* m_pImpl;
87 public:
88 /** standard ctor
90 The instance is not functional until <method>assign</method> is used.
92 @param _pInvalidationCallback
93 the callback for invalidating feature states
95 ControllerFeatures(
96 IControllerFeatureInvalidation* _pInvalidationCallback
99 /** constructs the instance from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
101 @param _rxController
102 The form controller which the helper should be responsible for. Must not
103 be <NULL/>, and must have a valid model (form).
105 @param _pInvalidationCallback
106 the callback for invalidating feature states
108 ControllerFeatures(
109 const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController,
110 IControllerFeatureInvalidation* _pInvalidationCallback
113 /// dtor
114 ~ControllerFeatures();
116 /// checks whether the instance is properly assigned to a form and/or controller
117 inline bool isAssigned( ) const { return m_pImpl != NULL; }
119 /** assign to a controller
121 void assign(
122 const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController
125 /// clears the instance so that it cannot be used afterwards
126 void dispose();
128 // access to the instance which implements the functionality. Not to be used when not assigned
129 inline const FormControllerHelper* operator->() const { return m_pImpl; }
130 inline FormControllerHelper* operator->() { return m_pImpl; }
131 inline const FormControllerHelper& operator*() const { return *m_pImpl; }
132 inline FormControllerHelper& operator*() { return *m_pImpl; }
135 //====================================================================
136 //= FormControllerHelper
137 //====================================================================
138 typedef ::cppu::WeakImplHelper2 < ::com::sun::star::form::runtime::XFeatureInvalidation
139 , ::com::sun::star::sdb::XSQLErrorListener
140 > FormControllerHelper_Base;
141 /** is a helper class which manages form controller functionality (such as moveNext etc.).
143 <p>The class helps implementing form controller functionality, by providing
144 methods to determine the state of, and execute, various common form features.<br/>
145 A <em>feature</em> is for instance moving the form associated with the controller
146 to a certain position, or reloading the form, and so on.</p>
148 class FormControllerHelper : public FormControllerHelper_Base
150 protected:
151 IControllerFeatureInvalidation* m_pInvalidationCallback;
152 ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >
153 m_xFormOperations;
155 ::com::sun::star::uno::Any m_aOperationError;
157 public:
158 /** constructs the helper from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
160 @param _rxController
161 The form controller which the helper should be responsible for. Must not
162 be <NULL/>, and must have a valid model (form).
163 @param _pInvalidationCallback
164 the callback for invalidating feature states
166 FormControllerHelper(
167 const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController,
168 IControllerFeatureInvalidation* _pInvalidationCallback
171 // forwards to the XFormOperations implementation
172 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >
173 getCursor() const;
174 void getState(
175 sal_Int32 _nSlotId,
176 ::com::sun::star::form::runtime::FeatureState& _out_rState
177 ) const;
178 sal_Bool isEnabled( sal_Int32 _nSlotId ) const;
179 void execute( sal_Int32 _nSlotId ) const;
180 void execute( sal_Int32 _nSlotId, const OUString& _rParamName, const ::com::sun::star::uno::Any& _rParamValue ) const;
181 sal_Bool commitCurrentRecord() const;
182 sal_Bool commitCurrentControl( ) const;
183 sal_Bool isInsertionRow() const;
184 sal_Bool isModifiedRow() const;
186 bool canDoFormFilter() const;
188 /** disposes this instance.
190 After this method has been called, the instance is not functional anymore
192 void dispose();
194 const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >&
195 getFormOperations() const { return m_xFormOperations; }
196 protected:
197 /// dtor
198 ~FormControllerHelper();
200 // XFeatureInvalidation
201 virtual void SAL_CALL invalidateFeatures( const ::com::sun::star::uno::Sequence< ::sal_Int16 >& Features ) throw (::com::sun::star::uno::RuntimeException);
202 virtual void SAL_CALL invalidateAllFeatures() throw (::com::sun::star::uno::RuntimeException);
204 // XSQLErrorListener
205 virtual void SAL_CALL errorOccured( const ::com::sun::star::sdb::SQLErrorEvent& _Event ) throw (::com::sun::star::uno::RuntimeException);
207 // XEventListener
208 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
210 private:
211 enum FormOperation { EXECUTE, EXECUTE_ARGS, COMMIT_CONTROL, COMMIT_RECORD };
213 bool impl_operateForm_nothrow(
214 const FormOperation _eWhat,
215 const sal_Int16 _nFeature, /* ignore for COMMIT_* */
216 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rArguments /* ignore except for EXECUTE_ARGS */
217 ) const;
218 bool impl_operateForm_nothrow( const FormOperation _eWhat ) const
220 return impl_operateForm_nothrow( _eWhat, 0, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() );
222 bool impl_operateForm_nothrow( const sal_Int16 _nFeature ) const
224 return impl_operateForm_nothrow( EXECUTE, _nFeature, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() );
227 private:
228 FormControllerHelper(); // never implemented
229 FormControllerHelper( const FormControllerHelper& ); // never implemented
230 FormControllerHelper& operator=( const FormControllerHelper& ); // never implemented
233 //........................................................................
234 } // namespace svx
235 //........................................................................
237 #endif // SVX_FORMCONTROLLING_HXX
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */