Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SVX_FORMCONTROLLING_HXX
30 : : #define SVX_FORMCONTROLLING_HXX
31 : :
32 : : #include <com/sun/star/form/runtime/XFormController.hpp>
33 : : #include <com/sun/star/form/XForm.hpp>
34 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 : : #include <com/sun/star/form/runtime/FeatureState.hpp>
36 : : #include <com/sun/star/form/runtime/XFormOperations.hpp>
37 : : #include <com/sun/star/sdb/XSQLErrorListener.hpp>
38 : :
39 : : #include <cppuhelper/implbase2.hxx>
40 : : #include <comphelper/componentcontext.hxx>
41 : :
42 : : #include <vector>
43 : :
44 : : //........................................................................
45 : : namespace svx
46 : : {
47 : : //........................................................................
48 : :
49 : : //====================================================================
50 : : //= FeatureSlotTranslation
51 : : //====================================================================
52 : : class FeatureSlotTranslation
53 : : {
54 : : public:
55 : : /// retrieves the feature id for a given feature URL
56 : : static sal_Int32 getControllerFeatureSlotIdForURL( const ::rtl::OUString& _rMainURL );
57 : :
58 : : /// retrieves the css.form.runtime.FormFeature ID for a given slot ID
59 : : static sal_Int16 getFormFeatureForSlotId( sal_Int32 _nSlotId );
60 : :
61 : : /// retrieves the slot id for a given css.form.runtime.FormFeature ID
62 : : static sal_Int32 getSlotIdForFormFeature( sal_Int16 _nFormFeature );
63 : : };
64 : :
65 : : //====================================================================
66 : : //= IControllerFeatureInvalidation
67 : : //====================================================================
68 : 1669 : class IControllerFeatureInvalidation
69 : : {
70 : : public:
71 : : /** invalidates the given features
72 : :
73 : : Invalidation means that any user interface representation (such as toolbox buttons), or
74 : : any dispatches associated with the features in question are potentially out-of-date, and
75 : : need to be updated
76 : :
77 : : @param _rFeatures
78 : : Ids of the features to be invalidated.
79 : : */
80 : : virtual void invalidateFeatures( const ::std::vector< sal_Int32 >& _rFeatures ) = 0;
81 : :
82 : : protected:
83 : 1578 : ~IControllerFeatureInvalidation() {}
84 : : };
85 : :
86 : : //====================================================================
87 : : //= ControllerFeatures
88 : : //====================================================================
89 : : class FormControllerHelper;
90 : : /** easier access to an FormControllerHelper instance
91 : : */
92 : : class ControllerFeatures
93 : : {
94 : : protected:
95 : : ::comphelper::ComponentContext m_aContext;
96 : : IControllerFeatureInvalidation* m_pInvalidationCallback; // necessary as long as m_pImpl is not yet constructed
97 : : FormControllerHelper* m_pImpl;
98 : :
99 : : public:
100 : : /** standard ctor
101 : :
102 : : The instance is not functional until <method>assign</method> is used.
103 : :
104 : : @param _rxORB
105 : : a multi service factory for creating various needed components
106 : :
107 : : @param _pInvalidationCallback
108 : : the callback for invalidating feature states
109 : : */
110 : : ControllerFeatures(
111 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
112 : : IControllerFeatureInvalidation* _pInvalidationCallback
113 : : );
114 : :
115 : : /** constructs the instance from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
116 : :
117 : : @param _rxORB
118 : : a multi service factory for creating various needed components
119 : :
120 : : @param _rxController
121 : : The form controller which the helper should be responsible for. Must not
122 : : be <NULL/>, and must have a valid model (form).
123 : :
124 : : @param _pInvalidationCallback
125 : : the callback for invalidating feature states
126 : : */
127 : : ControllerFeatures(
128 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
129 : : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController,
130 : : IControllerFeatureInvalidation* _pInvalidationCallback
131 : : );
132 : :
133 : : /// dtor
134 : : ~ControllerFeatures();
135 : :
136 : : /// checks whether the instance is properly assigned to a form and/or controller
137 : 0 : inline bool isAssigned( ) const { return m_pImpl != NULL; }
138 : :
139 : : /** assign to a controller
140 : : */
141 : : void assign(
142 : : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController
143 : : );
144 : :
145 : : /// clears the instance so that it cannot be used afterwards
146 : : void dispose();
147 : :
148 : : // access to the instance which implements the functionality. Not to be used when not assigned
149 : 12 : inline const FormControllerHelper* operator->() const { return m_pImpl; }
150 : 0 : inline FormControllerHelper* operator->() { return m_pImpl; }
151 : : inline const FormControllerHelper& operator*() const { return *m_pImpl; }
152 : : inline FormControllerHelper& operator*() { return *m_pImpl; }
153 : : };
154 : :
155 : : //====================================================================
156 : : //= FormControllerHelper
157 : : //====================================================================
158 : : typedef ::cppu::WeakImplHelper2 < ::com::sun::star::form::runtime::XFeatureInvalidation
159 : : , ::com::sun::star::sdb::XSQLErrorListener
160 : : > FormControllerHelper_Base;
161 : : /** is a helper class which manages form controller functionality (such as moveNext etc.).
162 : :
163 : : <p>The class helps implementing form controller functionality, by providing
164 : : methods to determine the state of, and execute, various common form features.<br/>
165 : : A <em>feature</em> is for instance moving the form associated with the controller
166 : : to a certain position, or reloading the form, and so on.</p>
167 : : */
168 : : class FormControllerHelper : public FormControllerHelper_Base
169 : : {
170 : : protected:
171 : : ::comphelper::ComponentContext m_aContext;
172 : : IControllerFeatureInvalidation* m_pInvalidationCallback;
173 : : ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >
174 : : m_xFormOperations;
175 : :
176 : : ::com::sun::star::uno::Any m_aOperationError;
177 : :
178 : : public:
179 : : /** constructs the helper from a <type scope="com::sun::star::form::runtime">XFormController<type> instance
180 : :
181 : : @param _rContext
182 : : the context the component lives in
183 : : @param _rxController
184 : : The form controller which the helper should be responsible for. Must not
185 : : be <NULL/>, and must have a valid model (form).
186 : : @param _pInvalidationCallback
187 : : the callback for invalidating feature states
188 : : */
189 : : FormControllerHelper(
190 : : const ::comphelper::ComponentContext& _rContext,
191 : : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController,
192 : : IControllerFeatureInvalidation* _pInvalidationCallback
193 : : );
194 : :
195 : : // forwards to the XFormOperations implementation
196 : : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >
197 : : getCursor() const;
198 : : void getState(
199 : : sal_Int32 _nSlotId,
200 : : ::com::sun::star::form::runtime::FeatureState& _out_rState
201 : : ) const;
202 : : sal_Bool isEnabled( sal_Int32 _nSlotId ) const;
203 : : void execute( sal_Int32 _nSlotId ) const;
204 : : void execute( sal_Int32 _nSlotId, const ::rtl::OUString& _rParamName, const ::com::sun::star::uno::Any& _rParamValue ) const;
205 : : sal_Bool commitCurrentRecord() const;
206 : : sal_Bool commitCurrentControl( ) const;
207 : : sal_Bool isInsertionRow() const;
208 : : sal_Bool isModifiedRow() const;
209 : :
210 : : bool canDoFormFilter() const;
211 : :
212 : : /** disposes this instance.
213 : :
214 : : After this method has been called, the instance is not functional anymore
215 : : */
216 : : void dispose();
217 : :
218 : : const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >&
219 : : getFormOperations() const { return m_xFormOperations; }
220 : : protected:
221 : : /// dtor
222 : : ~FormControllerHelper();
223 : :
224 : : // XFeatureInvalidation
225 : : virtual void SAL_CALL invalidateFeatures( const ::com::sun::star::uno::Sequence< ::sal_Int16 >& Features ) throw (::com::sun::star::uno::RuntimeException);
226 : : virtual void SAL_CALL invalidateAllFeatures() throw (::com::sun::star::uno::RuntimeException);
227 : :
228 : : // XSQLErrorListener
229 : : virtual void SAL_CALL errorOccured( const ::com::sun::star::sdb::SQLErrorEvent& _Event ) throw (::com::sun::star::uno::RuntimeException);
230 : :
231 : : // XEventListener
232 : : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
233 : :
234 : : private:
235 : : enum FormOperation { EXECUTE, EXECUTE_ARGS, COMMIT_CONTROL, COMMIT_RECORD };
236 : :
237 : : bool impl_operateForm_nothrow(
238 : : const FormOperation _eWhat,
239 : : const sal_Int16 _nFeature, /* ignore for COMMIT_* */
240 : : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rArguments /* ignore except for EXECUTE_ARGS */
241 : : ) const;
242 : 6 : bool impl_operateForm_nothrow( const FormOperation _eWhat ) const
243 : : {
244 [ + - ]: 6 : return impl_operateForm_nothrow( _eWhat, 0, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() );
245 : : }
246 : : bool impl_operateForm_nothrow( const sal_Int16 _nFeature ) const
247 : : {
248 : : return impl_operateForm_nothrow( EXECUTE, _nFeature, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() );
249 : : }
250 : :
251 : : private:
252 : : FormControllerHelper(); // never implemented
253 : : FormControllerHelper( const FormControllerHelper& ); // never implemented
254 : : FormControllerHelper& operator=( const FormControllerHelper& ); // never implemented
255 : : };
256 : :
257 : : //........................................................................
258 : : } // namespace svx
259 : : //........................................................................
260 : :
261 : : #endif // SVX_FORMCONTROLLING_HXX
262 : :
263 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|