Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SVX_SOURCE_INC_FORMCONTROLLING_HXX
21 : #define INCLUDED_SVX_SOURCE_INC_FORMCONTROLLING_HXX
22 :
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>
28 :
29 : #include <cppuhelper/implbase2.hxx>
30 :
31 : #include <vector>
32 :
33 :
34 : namespace svx
35 : {
36 :
37 : class FeatureSlotTranslation
38 : {
39 : public:
40 : /// retrieves the feature id for a given feature URL
41 : static sal_Int32 getControllerFeatureSlotIdForURL( const OUString& _rMainURL );
42 :
43 : /// retrieves the css.form.runtime.FormFeature ID for a given slot ID
44 : static sal_Int16 getFormFeatureForSlotId( sal_Int32 _nSlotId );
45 :
46 : /// retrieves the slot id for a given css.form.runtime.FormFeature ID
47 : static sal_Int32 getSlotIdForFormFeature( sal_Int16 _nFormFeature );
48 : };
49 :
50 5452 : class IControllerFeatureInvalidation
51 : {
52 : public:
53 : /** invalidates the given features
54 :
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
57 : need to be updated
58 :
59 : @param _rFeatures
60 : Ids of the features to be invalidated.
61 : */
62 : virtual void invalidateFeatures( const ::std::vector< sal_Int32 >& _rFeatures ) = 0;
63 :
64 : protected:
65 5450 : ~IControllerFeatureInvalidation() {}
66 : };
67 :
68 : class FormControllerHelper;
69 : /** easier access to an FormControllerHelper instance
70 : */
71 : class ControllerFeatures
72 : {
73 : protected:
74 : IControllerFeatureInvalidation* m_pInvalidationCallback; // necessary as long as m_pImpl is not yet constructed
75 : FormControllerHelper* m_pImpl;
76 :
77 : public:
78 : /** standard ctor
79 :
80 : The instance is not functional until <method>assign</method> is used.
81 :
82 : @param _pInvalidationCallback
83 : the callback for invalidating feature states
84 : */
85 : ControllerFeatures(
86 : IControllerFeatureInvalidation* _pInvalidationCallback
87 : );
88 :
89 : /** constructs the instance from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
90 :
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).
94 :
95 : @param _pInvalidationCallback
96 : the callback for invalidating feature states
97 : */
98 : ControllerFeatures(
99 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController,
100 : IControllerFeatureInvalidation* _pInvalidationCallback
101 : );
102 :
103 : /// dtor
104 : ~ControllerFeatures();
105 :
106 : /// checks whether the instance is properly assigned to a form and/or controller
107 0 : inline bool isAssigned( ) const { return m_pImpl != NULL; }
108 :
109 : /** assign to a controller
110 : */
111 : void assign(
112 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController
113 : );
114 :
115 : /// clears the instance so that it cannot be used afterwards
116 : void dispose();
117 :
118 : // access to the instance which implements the functionality. Not to be used when not assigned
119 12 : inline const FormControllerHelper* operator->() const { return m_pImpl; }
120 0 : inline FormControllerHelper* operator->() { return m_pImpl; }
121 : inline const FormControllerHelper& operator*() const { return *m_pImpl; }
122 : inline FormControllerHelper& operator*() { return *m_pImpl; }
123 : };
124 :
125 :
126 : //= FormControllerHelper
127 :
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.).
132 :
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>
137 : */
138 : class FormControllerHelper : public FormControllerHelper_Base
139 : {
140 : protected:
141 : IControllerFeatureInvalidation* m_pInvalidationCallback;
142 : ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >
143 : m_xFormOperations;
144 :
145 : ::com::sun::star::uno::Any m_aOperationError;
146 :
147 : public:
148 : /** constructs the helper from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
149 :
150 : @param _rxController
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
155 : */
156 : FormControllerHelper(
157 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController,
158 : IControllerFeatureInvalidation* _pInvalidationCallback
159 : );
160 :
161 : // forwards to the XFormOperations implementation
162 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >
163 : getCursor() const;
164 : void getState(
165 : sal_Int32 _nSlotId,
166 : ::com::sun::star::form::runtime::FeatureState& _out_rState
167 : ) const;
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;
175 :
176 : bool canDoFormFilter() const;
177 :
178 : /** disposes this instance.
179 :
180 : After this method has been called, the instance is not functional anymore
181 : */
182 : void dispose();
183 :
184 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >&
185 : getFormOperations() const { return m_xFormOperations; }
186 : protected:
187 : /// dtor
188 : virtual ~FormControllerHelper();
189 :
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;
193 :
194 : // XSQLErrorListener
195 : virtual void SAL_CALL errorOccured( const ::com::sun::star::sdb::SQLErrorEvent& _Event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
196 :
197 : // XEventListener
198 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
199 :
200 : private:
201 : enum FormOperation { EXECUTE, EXECUTE_ARGS, COMMIT_CONTROL, COMMIT_RECORD };
202 :
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 */
207 : ) const;
208 6 : bool impl_operateForm_nothrow( const FormOperation _eWhat ) const
209 : {
210 6 : return impl_operateForm_nothrow( _eWhat, 0, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() );
211 : }
212 : bool impl_operateForm_nothrow( const sal_Int16 _nFeature ) const
213 : {
214 : return impl_operateForm_nothrow( EXECUTE, _nFeature, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() );
215 : }
216 :
217 : private:
218 : FormControllerHelper(); // never implemented
219 : FormControllerHelper( const FormControllerHelper& ); // never implemented
220 : FormControllerHelper& operator=( const FormControllerHelper& ); // never implemented
221 : };
222 :
223 :
224 : } // namespace svx
225 :
226 :
227 : #endif // INCLUDED_SVX_SOURCE_INC_FORMCONTROLLING_HXX
228 :
229 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|