bump product version to 4.1.6.2
[LibreOffice.git] / forms / source / runtime / formoperations.hxx
bloba518c3d3119130cf10eb5f60eadaf9949d9343ed
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 FORMS_FORMOPERATIONS_HXX
21 #define FORMS_FORMOPERATIONS_HXX
23 #include <com/sun/star/form/runtime/XFormOperations.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/form/XForm.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/form/XLoadable.hpp>
28 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
29 #include <com/sun/star/util/XModifyListener.hpp>
30 #include <com/sun/star/container/XIndexAccess.hpp>
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
34 #include <comphelper/componentcontext.hxx>
36 #include <cppuhelper/basemutex.hxx>
37 #include <cppuhelper/compbase6.hxx>
39 //........................................................................
40 namespace frm
42 //........................................................................
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;
55 class FormOperations :public ::cppu::BaseMutex
56 ,public FormOperations_Base
58 public:
59 class MethodGuard;
61 private:
62 ::comphelper::ComponentContext m_aContext;
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;
73 bool m_bInitializedParser;
74 bool m_bActiveControlModified;
75 bool m_bConstructed;
76 #ifdef DBG_UTIL
77 mutable long
78 m_nMethodNestingLevel;
79 #endif
81 public:
82 FormOperations( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxContext );
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 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
88 Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
90 struct MethodAccess { friend class MethodGuard; private: MethodAccess() { } };
92 inline void enterMethod( MethodAccess ) const
94 m_aMutex.acquire();
95 impl_checkDisposed_throw();
96 #ifdef DBG_UTIL
97 ++m_nMethodNestingLevel;
98 #endif
101 inline void leaveMethod( MethodAccess ) const
103 m_aMutex.release();
104 #ifdef DBG_UTIL
105 --m_nMethodNestingLevel;
106 #endif
109 protected:
110 virtual ~FormOperations();
112 // XInitialization
113 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);
115 // XServiceInfo
116 virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
117 virtual ::sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
118 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
120 // XFormOperations
121 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > SAL_CALL getCursor() throw (::com::sun::star::uno::RuntimeException);
122 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate > SAL_CALL getUpdateCursor() throw (::com::sun::star::uno::RuntimeException);
123 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > SAL_CALL getController() throw (::com::sun::star::uno::RuntimeException);
124 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFeatureInvalidation > SAL_CALL getFeatureInvalidation() throw (::com::sun::star::uno::RuntimeException);
125 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);
126 virtual ::com::sun::star::form::runtime::FeatureState SAL_CALL getState(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException);
127 virtual ::sal_Bool SAL_CALL isEnabled(::sal_Int16 Feature) throw (::com::sun::star::uno::RuntimeException);
128 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);
129 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);
130 virtual ::sal_Bool SAL_CALL commitCurrentRecord(::sal_Bool & RecordInserted) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::sdbc::SQLException);
131 virtual ::sal_Bool SAL_CALL commitCurrentControl() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::sdbc::SQLException);
132 virtual ::sal_Bool SAL_CALL isInsertionRow() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::WrappedTargetException);
133 virtual ::sal_Bool SAL_CALL isModifiedRow() throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::WrappedTargetException);
135 // XRowSetListener
136 virtual void SAL_CALL cursorMoved( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
137 virtual void SAL_CALL rowChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
138 virtual void SAL_CALL rowSetChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
140 // XModifyListener
141 virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException );
143 // XPropertyChangeListener
144 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
146 // XEventListener
147 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
149 // XComponent/OComponentHelper
150 virtual void SAL_CALL disposing();
152 private:
153 // service constructors
154 void createWithFormController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController );
155 void createWithForm( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm );
157 /** determines whether or not we're already disposed
159 inline bool impl_isDisposed_nothrow() const { return !m_xCursor.is(); }
161 /** checks whether the instance is already disposed, and throws an exception if so
163 void impl_checkDisposed_throw() const;
165 /** initializes the instance after m_xController has been set
166 @precond
167 m_xController is not <NULL/>
169 void impl_initFromController_throw();
171 /** initializes the instance after m_xCursor has been set
172 @precond
173 m_xCursor is not <NULL/>
175 void impl_initFromForm_throw();
177 /// invalidate the full palette of features which we know
178 void impl_invalidateAllSupportedFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
180 /** invalidate the features which depend on the "modified" state of the current control
181 of our controller
183 void impl_invalidateModifyDependentFeatures_nothrow( MethodGuard& _rClearForCallback ) const;
185 /** ensures that our parse is initialized, or at least that we attempted to do so
186 @precond
187 we're not disposed
189 void impl_ensureInitializedParser_nothrow();
191 /// disposes our parser, if we have one
192 void impl_disposeParser_nothrow();
194 /** determines whether our cursor can be moved left
195 @precond hasCursor()
197 bool impl_canMoveLeft_throw() const;
199 /** determines whether our cursor can be moved right
200 @precond hasCursor()
202 bool impl_canMoveRight_throw() const;
204 /// determines whether we're positioned on the insertion row
205 bool impl_isInsertionRow_throw() const;
207 /// retrieves the RowCount property of the form
208 sal_Int32 impl_getRowCount_throw() const;
210 /// retrieves the RowCountFinal property of the form
211 bool impl_isRowCountFinal_throw() const;
213 /// retrieves the IsModified property of the form
214 bool impl_isModifiedRow_throw() const;
216 /// determines whether we can parse the query of our form
217 bool impl_isParseable_throw() const;
219 /// determines if we have an active filter or order condition
220 bool impl_hasFilterOrOrder_throw() const;
222 /// determines whether our form is in "insert-only" mode
223 bool impl_isInsertOnlyForm_throw() const;
225 /** retrieces the column to which the current control of our controller is bound
226 @precond
227 m_xController.is()
229 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
230 impl_getCurrentBoundField_nothrow( ) const;
232 /** returns the control model of the current control
234 If the current control is a grid control, then the returned model is the
235 model of the current <em>column</em> in the grid.
237 @precond
238 m_xController.is()
240 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >
241 impl_getCurrentControlModel_throw() const;
243 /// determines if we have a valid cursor
244 inline bool impl_hasCursor_nothrow() const { return m_xCursorProperties.is(); }
246 /** determines the model position from a grid control column's view position
248 A grid control can have columns which are currently hidden, so the index of a
249 column in the view is not necessarily the same as its index in the model.
251 sal_Int16 impl_gridView2ModelPos_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxColumns, sal_Int16 _nViewPos ) const;
253 /** moves our cursor one position to the left, caring for different possible
254 cursor states.
256 Before the movement is done, the current row is saved, if necessary.
258 @precond
259 canMoveLeft()
261 bool impl_moveLeft_throw() const;
263 /** moves our cursor one position to the right, caring for different possible
264 cursor states.
266 Before the movement is done, the current row is saved, if necessary.
268 @precond
269 canMoveRight()
271 bool impl_moveRight_throw( ) const;
273 /** impl-version of commitCurrentRecord, which can be called without caring for
274 an output parameter, and within const-contexts
276 @precond
277 our mutex is locked
279 bool impl_commitCurrentRecord_throw( sal_Bool* _pRecordInserted = NULL ) const;
281 /** impl-version of commitCurrentControl, which can be called in const-contexts
283 @precond
284 our mutex is locked
286 bool impl_commitCurrentControl_throw() const;
288 /// resets all control models in our own form
289 void impl_resetAllControls_nothrow() const;
291 /// executes the "auto sort ascending" and "auto sort descending" features
292 void impl_executeAutoSort_throw( bool _bUp ) const;
294 /// executes the "auto filter" feature
295 void impl_executeAutoFilter_throw( ) const;
297 /// executes the interactive sort resp. filter feature
298 void impl_executeFilterOrSort_throw( bool _bFilter ) const;
300 private:
301 /** calls a (member) function, catches SQLExceptions, extends them with additional context information,
302 and rethrows them
304 @param f
305 a fuctionoid with no arguments to do the work
306 @param _nErrorResourceId
307 the id of the resources string to use as error message
309 template < typename FunctObj >
310 void impl_doActionInSQLContext_throw( FunctObj f, sal_uInt16 _nErrorResourceId ) const;
312 // functionoid to call appendOrderByColumn
313 class impl_appendOrderByColumn_throw
315 public:
316 impl_appendOrderByColumn_throw(const FormOperations *pFO,
317 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField,
318 bool bUp)
319 : m_pFO(pFO)
320 , m_xField(xField)
321 , m_bUp(bUp)
324 void operator()() { m_pFO->m_xParser->appendOrderByColumn(m_xField, m_bUp); }
325 private:
326 const FormOperations *m_pFO;
327 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xField;
328 bool m_bUp;
331 // functionoid to call appendFilterByColumn
332 class impl_appendFilterByColumn_throw
334 public:
335 impl_appendFilterByColumn_throw(const FormOperations *pFO,
336 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xField)
337 : m_pFO(pFO)
338 , m_xField(xField)
341 void operator()() { m_pFO->m_xParser->appendFilterByColumn( m_xField, sal_True, ::com::sun::star::sdb::SQLFilterOperator::EQUAL ); }
342 private:
343 const FormOperations *m_pFO;
344 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xField;
347 private:
348 FormOperations(); // never implemented
349 FormOperations( const FormOperations& ); // never implemented
350 FormOperations& operator=( const FormOperations& ); // never implemented
352 public:
353 class MethodGuard
355 FormOperations& m_rOwner;
356 bool m_bCleared;
358 public:
359 inline MethodGuard( FormOperations& _rOwner )
360 :m_rOwner( _rOwner )
361 ,m_bCleared( false )
363 m_rOwner.enterMethod( FormOperations::MethodAccess() );
366 inline ~MethodGuard()
368 clear();
371 inline void clear()
373 if ( !m_bCleared )
374 m_rOwner.leaveMethod( FormOperations::MethodAccess() );
375 m_bCleared = true;
380 //........................................................................
381 } // namespace frm
382 //........................................................................
384 #endif // FORMS_FORMOPERATIONS_HXX
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */