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_FORMS_SOURCE_RUNTIME_FORMOPERATIONS_HXX
21 : #define INCLUDED_FORMS_SOURCE_RUNTIME_FORMOPERATIONS_HXX
22 :
23 : #include <com/sun/star/form/runtime/XFormOperations.hpp>
24 : #include <com/sun/star/lang/XServiceInfo.hpp>
25 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 : #include <com/sun/star/form/XForm.hpp>
27 : #include <com/sun/star/beans/XPropertySet.hpp>
28 : #include <com/sun/star/form/XLoadable.hpp>
29 : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
30 : #include <com/sun/star/util/XModifyListener.hpp>
31 : #include <com/sun/star/container/XIndexAccess.hpp>
32 : #include <com/sun/star/lang/XInitialization.hpp>
33 : #include <com/sun/star/sdb/SQLFilterOperator.hpp>
34 : #include <com/sun/star/uno/XComponentContext.hpp>
35 :
36 : #include <cppuhelper/basemutex.hxx>
37 : #include <cppuhelper/compbase6.hxx>
38 :
39 :
40 : namespace frm
41 : {
42 :
43 :
44 :
45 : //= FormOperations
46 :
47 : typedef ::cppu::WeakComponentImplHelper6 < ::com::sun::star::form::runtime::XFormOperations
48 : , ::com::sun::star::lang::XInitialization
49 : , ::com::sun::star::lang::XServiceInfo
50 : , ::com::sun::star::beans::XPropertyChangeListener
51 : , ::com::sun::star::util::XModifyListener
52 : , ::com::sun::star::sdbc::XRowSetListener
53 : > FormOperations_Base;
54 :
55 : class FormOperations :public ::cppu::BaseMutex
56 : ,public FormOperations_Base
57 : {
58 : public:
59 : class MethodGuard;
60 :
61 : private:
62 : css::uno::Reference<css::uno::XComponentContext> m_xContext;
63 : ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > m_xController;
64 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xCursor;
65 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate > m_xUpdateCursor;
66 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xCursorProperties;
67 : ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable > m_xLoadableForm;
68 : ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFeatureInvalidation >
69 : m_xFeatureInvalidation;
70 : mutable ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >
71 : m_xParser;
72 :
73 : bool m_bInitializedParser;
74 : bool m_bActiveControlModified;
75 : bool m_bConstructed;
76 : #ifdef DBG_UTIL
77 : mutable long
78 : m_nMethodNestingLevel;
79 : #endif
80 :
81 : public:
82 : FormOperations( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
83 :
84 : // XServiceInfo - static versions
85 : static OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException);
86 : static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException);
87 :
88 198 : struct MethodAccess { friend class MethodGuard; private: MethodAccess() { } };
89 :
90 99 : inline void enterMethod( MethodAccess ) const
91 : {
92 99 : m_aMutex.acquire();
93 99 : impl_checkDisposed_throw();
94 : #ifdef DBG_UTIL
95 : ++m_nMethodNestingLevel;
96 : #endif
97 99 : }
98 :
99 99 : inline void leaveMethod( MethodAccess ) const
100 : {
101 99 : m_aMutex.release();
102 : #ifdef DBG_UTIL
103 : --m_nMethodNestingLevel;
104 : #endif
105 99 : }
106 :
107 : protected:
108 : virtual ~FormOperations();
109 :
110 : // XInitialization
111 : virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
112 :
113 : // XServiceInfo
114 : virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
115 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
116 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
117 :
118 : // XFormOperations
119 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > SAL_CALL getCursor() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
120 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate > SAL_CALL getUpdateCursor() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
121 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > SAL_CALL getController() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
122 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFeatureInvalidation > SAL_CALL getFeatureInvalidation() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
123 : virtual void SAL_CALL setFeatureInvalidation(const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFeatureInvalidation > & the_value) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
124 : virtual ::com::sun::star::form::runtime::FeatureState SAL_CALL getState(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
125 : virtual sal_Bool SAL_CALL isEnabled(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
126 : virtual void SAL_CALL execute(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::WrappedTargetException, std::exception) SAL_OVERRIDE;
127 : virtual void SAL_CALL executeWithArguments(::sal_Int16 Feature, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Arguments) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::WrappedTargetException, std::exception) SAL_OVERRIDE;
128 : virtual sal_Bool SAL_CALL commitCurrentRecord(sal_Bool & RecordInserted) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::sdbc::SQLException, std::exception) SAL_OVERRIDE;
129 : virtual sal_Bool SAL_CALL commitCurrentControl() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::sdbc::SQLException, std::exception) SAL_OVERRIDE;
130 : virtual sal_Bool SAL_CALL isInsertionRow() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::WrappedTargetException, std::exception) SAL_OVERRIDE;
131 : virtual sal_Bool SAL_CALL isModifiedRow() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::WrappedTargetException, std::exception) SAL_OVERRIDE;
132 :
133 : // XRowSetListener
134 : virtual void SAL_CALL cursorMoved( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
135 : virtual void SAL_CALL rowChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
136 : virtual void SAL_CALL rowSetChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
137 :
138 : // XModifyListener
139 : virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
140 :
141 : // XPropertyChangeListener
142 : virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 :
144 : // XEventListener
145 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
146 :
147 : // XComponent/OComponentHelper
148 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
149 :
150 : private:
151 : // service constructors
152 : void createWithFormController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController );
153 : void createWithForm( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm );
154 :
155 : /** determines whether or not we're already disposed
156 : */
157 99 : inline bool impl_isDisposed_nothrow() const { return !m_xCursor.is(); }
158 :
159 : /** checks whether the instance is already disposed, and throws an exception if so
160 : */
161 : void impl_checkDisposed_throw() const;
162 :
163 : /** initializes the instance after m_xController has been set
164 : @precond
165 : m_xController is not <NULL/>
166 : */
167 : void impl_initFromController_throw();
168 :
169 : /** initializes the instance after m_xCursor has been set
170 : @precond
171 : m_xCursor is not <NULL/>
172 : */
173 : void impl_initFromForm_throw();
174 :
175 : /// invalidate the full palette of features which we know
176 : void impl_invalidateAllSupportedFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
177 :
178 : /** invalidate the features which depend on the "modified" state of the current control
179 : of our controller
180 : */
181 : void impl_invalidateModifyDependentFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
182 :
183 : /** ensures that our parse is initialized, or at least that we attempted to do so
184 : @precond
185 : we're not disposed
186 : */
187 : void impl_ensureInitializedParser_nothrow();
188 :
189 : /// disposes our parser, if we have one
190 : void impl_disposeParser_nothrow();
191 :
192 : /** determines whether our cursor can be moved left
193 : @precond hasCursor()
194 : */
195 : bool impl_canMoveLeft_throw() const;
196 :
197 : /** determines whether our cursor can be moved right
198 : @precond hasCursor()
199 : */
200 : bool impl_canMoveRight_throw() const;
201 :
202 : /// determines whether we're positioned on the insertion row
203 : bool impl_isInsertionRow_throw() const;
204 :
205 : /// retrieves the RowCount property of the form
206 : sal_Int32 impl_getRowCount_throw() const;
207 :
208 : /// retrieves the RowCountFinal property of the form
209 : bool impl_isRowCountFinal_throw() const;
210 :
211 : /// retrieves the IsModified property of the form
212 : bool impl_isModifiedRow_throw() const;
213 :
214 : /// determines whether we can parse the query of our form
215 : bool impl_isParseable_throw() const;
216 :
217 : /// determines if we have an active filter or order condition
218 : bool impl_hasFilterOrOrder_throw() const;
219 :
220 : /// determines whether our form is in "insert-only" mode
221 : bool impl_isInsertOnlyForm_throw() const;
222 :
223 : /** retrieces the column to which the current control of our controller is bound
224 : @precond
225 : m_xController.is()
226 : */
227 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
228 : impl_getCurrentBoundField_nothrow( ) const;
229 :
230 : /** returns the control model of the current control
231 :
232 : If the current control is a grid control, then the returned model is the
233 : model of the current <em>column</em> in the grid.
234 :
235 : @precond
236 : m_xController.is()
237 : */
238 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >
239 : impl_getCurrentControlModel_throw() const;
240 :
241 : /// determines if we have a valid cursor
242 0 : inline bool impl_hasCursor_nothrow() const { return m_xCursorProperties.is(); }
243 :
244 : /** determines the model position from a grid control column's view position
245 :
246 : A grid control can have columns which are currently hidden, so the index of a
247 : column in the view is not necessarily the same as its index in the model.
248 : */
249 : static sal_Int16 impl_gridView2ModelPos_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxColumns, sal_Int16 _nViewPos );
250 :
251 : /** moves our cursor one position to the left, caring for different possible
252 : cursor states.
253 :
254 : Before the movement is done, the current row is saved, if necessary.
255 :
256 : @precond
257 : canMoveLeft()
258 : */
259 : bool impl_moveLeft_throw() const;
260 :
261 : /** moves our cursor one position to the right, caring for different possible
262 : cursor states.
263 :
264 : Before the movement is done, the current row is saved, if necessary.
265 :
266 : @precond
267 : canMoveRight()
268 : */
269 : bool impl_moveRight_throw( ) const;
270 :
271 : /** impl-version of commitCurrentRecord, which can be called without caring for
272 : an output parameter, and within const-contexts
273 :
274 : @precond
275 : our mutex is locked
276 : */
277 : bool impl_commitCurrentRecord_throw( sal_Bool* _pRecordInserted = NULL ) const;
278 :
279 : /** impl-version of commitCurrentControl, which can be called in const-contexts
280 :
281 : @precond
282 : our mutex is locked
283 : */
284 : bool impl_commitCurrentControl_throw() const;
285 :
286 : /// resets all control models in our own form
287 : void impl_resetAllControls_nothrow() const;
288 :
289 : /// executes the "auto sort ascending" and "auto sort descending" features
290 : void impl_executeAutoSort_throw( bool _bUp ) const;
291 :
292 : /// executes the "auto filter" feature
293 : void impl_executeAutoFilter_throw( ) const;
294 :
295 : /// executes the interactive sort resp. filter feature
296 : void impl_executeFilterOrSort_throw( bool _bFilter ) const;
297 :
298 : private:
299 : /** calls a (member) function, catches SQLExceptions, extends them with additional context information,
300 : and rethrows them
301 :
302 : @param f
303 : a fuctionoid with no arguments to do the work
304 : @param _nErrorResourceId
305 : the id of the resources string to use as error message
306 : */
307 : template < typename FunctObj >
308 : void impl_doActionInSQLContext_throw( FunctObj f, sal_uInt16 _nErrorResourceId ) const;
309 :
310 : // functionoid to call appendOrderByColumn
311 0 : class impl_appendOrderByColumn_throw
312 : {
313 : public:
314 0 : impl_appendOrderByColumn_throw(const FormOperations *pFO,
315 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField,
316 : bool bUp)
317 : : m_pFO(pFO)
318 : , m_xField(xField)
319 0 : , m_bUp(bUp)
320 0 : {};
321 :
322 0 : void operator()() { m_pFO->m_xParser->appendOrderByColumn(m_xField, m_bUp); }
323 : private:
324 : const FormOperations *m_pFO;
325 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xField;
326 : bool m_bUp;
327 : };
328 :
329 : // functionoid to call appendFilterByColumn
330 0 : class impl_appendFilterByColumn_throw
331 : {
332 : public:
333 0 : impl_appendFilterByColumn_throw(const FormOperations *pFO,
334 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField)
335 : : m_pFO(pFO)
336 0 : , m_xField(xField)
337 0 : {};
338 :
339 0 : void operator()() { m_pFO->m_xParser->appendFilterByColumn( m_xField, sal_True, ::com::sun::star::sdb::SQLFilterOperator::EQUAL ); }
340 : private:
341 : const FormOperations *m_pFO;
342 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xField;
343 : };
344 :
345 : private:
346 : FormOperations( const FormOperations& ) SAL_DELETED_FUNCTION;
347 : FormOperations& operator=( const FormOperations& ) SAL_DELETED_FUNCTION;
348 :
349 : public:
350 : class MethodGuard
351 : {
352 : FormOperations& m_rOwner;
353 : bool m_bCleared;
354 :
355 : public:
356 99 : inline MethodGuard( FormOperations& _rOwner )
357 : :m_rOwner( _rOwner )
358 99 : ,m_bCleared( false )
359 : {
360 99 : m_rOwner.enterMethod( FormOperations::MethodAccess() );
361 99 : }
362 :
363 99 : inline ~MethodGuard()
364 : {
365 99 : clear();
366 99 : }
367 :
368 99 : inline void clear()
369 : {
370 99 : if ( !m_bCleared )
371 99 : m_rOwner.leaveMethod( FormOperations::MethodAccess() );
372 99 : m_bCleared = true;
373 99 : }
374 : };
375 : };
376 :
377 :
378 : } // namespace frm
379 :
380 :
381 : #endif // INCLUDED_FORMS_SOURCE_RUNTIME_FORMOPERATIONS_HXX
382 :
383 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|