Bump version to 6.4-15
[LibreOffice.git] / svx / source / inc / formcontrolling.hxx
blobdb72e9114ebba8b7480b4433d920752699e2b4ba
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 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/implbase.hxx>
30 #include <rtl/ref.hxx>
32 #include <vector>
35 namespace svx
38 class FeatureSlotTranslation
40 public:
41 /// retrieves the feature id for a given feature URL
42 static sal_Int32 getControllerFeatureSlotIdForURL( const OUString& _rMainURL );
44 /// retrieves the css.form.runtime.FormFeature ID for a given slot ID
45 static sal_Int16 getFormFeatureForSlotId( sal_Int32 _nSlotId );
47 /// retrieves the slot id for a given css.form.runtime.FormFeature ID
48 static sal_Int32 getSlotIdForFormFeature( sal_Int16 _nFormFeature );
51 class IControllerFeatureInvalidation
53 public:
54 /** invalidates the given features
56 Invalidation means that any user interface representation (such as toolbox buttons), or
57 any dispatches associated with the features in question are potentially out-of-date, and
58 need to be updated
60 @param _rFeatures
61 Ids of the features to be invalidated.
63 virtual void invalidateFeatures( const ::std::vector< sal_Int32 >& _rFeatures ) = 0;
65 protected:
66 ~IControllerFeatureInvalidation() {}
69 class FormControllerHelper;
70 /** easier access to a FormControllerHelper instance
72 class ControllerFeatures final
74 IControllerFeatureInvalidation* const m_pInvalidationCallback; // necessary as long as m_pImpl is not yet constructed
75 rtl::Reference<FormControllerHelper> m_pImpl;
77 public:
78 /** standard ctor
80 The instance is not functional until <method>assign</method> is used.
82 @param _pInvalidationCallback
83 the callback for invalidating feature states
85 ControllerFeatures(
86 IControllerFeatureInvalidation* _pInvalidationCallback
89 /** constructs the instance from a <type scope="css::form::runtime">XFormController<type> instance
91 @param _rxController
92 The form controller which the helper should be responsible for. Must not
93 be <NULL/>, and must have a valid model (form).
95 ControllerFeatures(
96 const css::uno::Reference< css::form::runtime::XFormController >& _rxController
99 /// dtor
100 ~ControllerFeatures();
102 /// checks whether the instance is properly assigned to a form and/or controller
103 bool isAssigned( ) const { return m_pImpl != nullptr; }
105 /** assign to a controller
107 void assign(
108 const css::uno::Reference< css::form::runtime::XFormController >& _rxController
111 /// clears the instance so that it cannot be used afterwards
112 void dispose();
114 // access to the instance which implements the functionality. Not to be used when not assigned
115 const FormControllerHelper* operator->() const { return m_pImpl.get(); }
116 FormControllerHelper* operator->() { return m_pImpl.get(); }
120 //= FormControllerHelper
122 typedef ::cppu::WeakImplHelper < css::form::runtime::XFeatureInvalidation
123 , css::sdb::XSQLErrorListener
124 > FormControllerHelper_Base;
125 /** is a helper class which manages form controller functionality (such as moveNext etc.).
127 <p>The class helps implementing form controller functionality, by providing
128 methods to determine the state of, and execute, various common form features.<br/>
129 A <em>feature</em> is for instance moving the form associated with the controller
130 to a certain position, or reloading the form, and so on.</p>
132 class FormControllerHelper : public FormControllerHelper_Base
134 protected:
135 IControllerFeatureInvalidation* m_pInvalidationCallback;
136 css::uno::Reference< css::form::runtime::XFormOperations >
137 m_xFormOperations;
139 css::uno::Any m_aOperationError;
141 public:
142 /** constructs the helper from a <type scope="css::form::runtime">XFormController<type> instance
144 @param _rxController
145 The form controller which the helper should be responsible for. Must not
146 be <NULL/>, and must have a valid model (form).
147 @param _pInvalidationCallback
148 the callback for invalidating feature states
150 FormControllerHelper(
151 const css::uno::Reference< css::form::runtime::XFormController >& _rxController,
152 IControllerFeatureInvalidation* _pInvalidationCallback
155 // forwards to the XFormOperations implementation
156 css::uno::Reference< css::sdbc::XRowSet >
157 getCursor() const;
158 void getState(
159 sal_Int32 _nSlotId,
160 css::form::runtime::FeatureState& _out_rState
161 ) const;
162 bool isEnabled( sal_Int32 _nSlotId ) const;
163 void execute( sal_Int32 _nSlotId ) const;
164 void execute( sal_Int32 _nSlotId, const OUString& _rParamName, const css::uno::Any& _rParamValue ) const;
165 bool commitCurrentRecord() const;
166 bool commitCurrentControl( ) const;
167 bool isInsertionRow() const;
168 bool isModifiedRow() const;
170 bool canDoFormFilter() const;
172 /** disposes this instance.
174 After this method has been called, the instance is not functional anymore
176 void dispose();
178 protected:
179 /// dtor
180 virtual ~FormControllerHelper() override;
182 // XFeatureInvalidation
183 virtual void SAL_CALL invalidateFeatures( const css::uno::Sequence< ::sal_Int16 >& Features ) override;
184 virtual void SAL_CALL invalidateAllFeatures() override;
186 // XSQLErrorListener
187 virtual void SAL_CALL errorOccured( const css::sdb::SQLErrorEvent& Event ) override;
189 // XEventListener
190 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
192 private:
193 enum FormOperation { EXECUTE, EXECUTE_ARGS, COMMIT_CONTROL, COMMIT_RECORD };
195 bool impl_operateForm_nothrow(
196 const FormOperation _eWhat,
197 const sal_Int16 _nFeature, /* ignore for COMMIT_* */
198 const css::uno::Sequence< css::beans::NamedValue >& _rArguments /* ignore except for EXECUTE_ARGS */
199 ) const;
200 bool impl_operateForm_nothrow( const FormOperation _eWhat ) const
202 return impl_operateForm_nothrow( _eWhat, 0, css::uno::Sequence< css::beans::NamedValue >() );
205 private:
206 FormControllerHelper( const FormControllerHelper& ) = delete;
207 FormControllerHelper& operator=( const FormControllerHelper& ) = delete;
214 #endif // INCLUDED_SVX_SOURCE_INC_FORMCONTROLLING_HXX
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */